spa_history.c revision da165920f9fa0e493db9dba43b0c3771051409dc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/spa_impl.h>
#include <sys/dsl_synctask.h>
#include <sys/dmu_objset.h>
#ifdef _KERNEL
#endif
/*
* Routines to manage the on-disk history log.
*
* The history log is stored as a dmu object containing
* <packed record length, record nvlist> tuples.
*
* Where "record nvlist" is a nvlist containing uint64_ts and strings, and
* "packed record length" is the packed length of the "record nvlist" stored
* as a little endian uint64_t.
*
* The log is implemented as a ring buffer, though the original creation
* of the pool ('zpool create') is never overwritten.
*
* The history log is tracked as object 'spa_t::spa_history'. The bonus buffer
* of 'spa_history' stores the offsets for logging/retrieving history as
* 'spa_history_phys_t'. 'sh_pool_create_len' is the ending offset in bytes of
* where the 'zpool create' record is stored. This allows us to never
* overwrite the original creation of the pool. 'sh_phys_max_off' is the
* physical ending offset in bytes of the log. This tells you the length of
* the buffer. 'sh_eof' is the logical EOF (in bytes). Whenever a record
* is added, 'sh_eof' is incremented by the the size of the record.
* 'sh_eof' is never decremented. 'sh_bof' is the logical BOF (in bytes).
* This is where the consumer should start reading from after reading in
* the 'zpool create' portion of the log.
*
* 'sh_records_lost' keeps track of how many records have been overwritten
* and permanently lost.
*/
/* convert a logical offset to physical */
static uint64_t
{
+ shpp->sh_pool_create_len);
}
void
{
sizeof (spa_history_phys_t), tx);
/*
* Figure out maximum size of history log. We set it at
* 1% of pool size, with a max of 32MB and min of 128KB.
*/
}
/*
* Change 'sh_bof' to the beginning of the next record.
*/
static int
{
int err;
buf)) != 0)
return (err);
return (err);
}
shpp->sh_records_lost++;
return (0);
}
static int
{
int err;
/* see if we need to reset logical BOF */
return (err);
}
}
len -= firstwrite;
if (len > 0) {
/* write out the rest at the beginning of physical file */
}
return (0);
}
static char *
{
#ifdef _KERNEL
#else
return ("global");
#endif
}
/*
* Write out a history event.
*/
static void
{
char *record_packed = NULL;
int ret;
/*
* If we have an older pool that doesn't have a command
* history object, create it now.
*/
if (!spa->spa_history)
/*
* Get the offset of where we need to write via the bonus buffer.
* Update the offset when the write completes.
*/
#ifdef ZFS_DEBUG
{
}
#endif
gethrestime_sec()) == 0);
#ifdef _KERNEL
#endif
history_str) == 0);
} else {
history_str) == 0);
}
NV_ENCODE_XDR, KM_SLEEP) == 0);
/* write out the packed length as little endian */
if (!ret)
}
}
}
/*
* Write out a history event.
*/
int
{
}
/*
* Read out the command history.
*/
int
{
int err;
/*
* If the command history doesn't exist (older pool),
* that's ok, just return ENOENT.
*/
if (!spa->spa_history)
return (ENOENT);
return (err);
#ifdef ZFS_DEBUG
{
}
#endif
/* read in just the zpool create history */
phys_read_off = *offp;
} else {
/*
* Need to reset passed in offset to BOF if the passed in
* offset has since been overwritten.
*/
/*
* Read up to the minimum of what the user passed down or
* the EOF (physical or logical). If we hit physical EOF,
* use 'leftover' to read from the physical BOF.
*/
if (phys_read_off <= phys_eof) {
} else {
}
}
}
/* offset for consumer to use next */
/* tell the consumer how much you actually read */
if (read_len == 0) {
return (0);
}
}
return (err);
}
void
{
char *str;
if (dmu_tx_is_syncing(tx)) {
} else {
}
/* spa_history_log_sync() will free hap and str */
}