9102 zfs should be able to initialize storage devices
The first access to a disk block can incur a performance penalty on some platforms (e.g. AWS's EBS, VMware VMDKs). Therefore it is recommended that volumes be "thick provisioned", where supported by the platform (VMware). Thick provisioning is time consuming and often is ignored. If the thick provision step is omitted, customers will see suboptimal performance until we have written to all parts of the LUN. ZFS should be able to initialize any unused storage to remove any first-write penalty that exists. illumos/illumos-gate@094e47e980 Reviewed by: John Wren Kennedy <john.kennedy@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com> Reviewed by: Prakash Surya <prakash.surya@delphix.com> Approved by: Richard Lowe <richlowe@richlowe.net>
This commit is contained in:
parent
86b3990c6e
commit
59ef839e67
@ -84,6 +84,7 @@ static int zpool_do_detach(int, char **);
|
||||
static int zpool_do_replace(int, char **);
|
||||
static int zpool_do_split(int, char **);
|
||||
|
||||
static int zpool_do_initialize(int, char **);
|
||||
static int zpool_do_scrub(int, char **);
|
||||
|
||||
static int zpool_do_import(int, char **);
|
||||
@ -133,6 +134,7 @@ typedef enum {
|
||||
HELP_ONLINE,
|
||||
HELP_REPLACE,
|
||||
HELP_REMOVE,
|
||||
HELP_INITIALIZE,
|
||||
HELP_SCRUB,
|
||||
HELP_STATUS,
|
||||
HELP_UPGRADE,
|
||||
@ -184,6 +186,7 @@ static zpool_command_t command_table[] = {
|
||||
{ "replace", zpool_do_replace, HELP_REPLACE },
|
||||
{ "split", zpool_do_split, HELP_SPLIT },
|
||||
{ NULL },
|
||||
{ "initialize", zpool_do_initialize, HELP_INITIALIZE },
|
||||
{ "scrub", zpool_do_scrub, HELP_SCRUB },
|
||||
{ NULL },
|
||||
{ "import", zpool_do_import, HELP_IMPORT },
|
||||
@ -257,6 +260,8 @@ get_usage(zpool_help_t idx)
|
||||
return (gettext("\tremove [-nps] <pool> <device> ...\n"));
|
||||
case HELP_REOPEN:
|
||||
return (gettext("\treopen <pool>\n"));
|
||||
case HELP_INITIALIZE:
|
||||
return (gettext("\tinitialize [-cs] <pool> [<device> ...]\n"));
|
||||
case HELP_SCRUB:
|
||||
return (gettext("\tscrub [-s | -p] <pool> ...\n"));
|
||||
case HELP_STATUS:
|
||||
@ -1589,6 +1594,43 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
|
||||
"resilvering" : "repairing");
|
||||
}
|
||||
|
||||
if ((vs->vs_initialize_state == VDEV_INITIALIZE_ACTIVE ||
|
||||
vs->vs_initialize_state == VDEV_INITIALIZE_SUSPENDED ||
|
||||
vs->vs_initialize_state == VDEV_INITIALIZE_COMPLETE) &&
|
||||
!vs->vs_scan_removing) {
|
||||
char zbuf[1024];
|
||||
char tbuf[256];
|
||||
struct tm zaction_ts;
|
||||
|
||||
time_t t = vs->vs_initialize_action_time;
|
||||
int initialize_pct = 100;
|
||||
if (vs->vs_initialize_state != VDEV_INITIALIZE_COMPLETE) {
|
||||
initialize_pct = (vs->vs_initialize_bytes_done * 100 /
|
||||
(vs->vs_initialize_bytes_est + 1));
|
||||
}
|
||||
|
||||
(void) localtime_r(&t, &zaction_ts);
|
||||
(void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
|
||||
|
||||
switch (vs->vs_initialize_state) {
|
||||
case VDEV_INITIALIZE_SUSPENDED:
|
||||
(void) snprintf(zbuf, sizeof (zbuf),
|
||||
", suspended, started at %s", tbuf);
|
||||
break;
|
||||
case VDEV_INITIALIZE_ACTIVE:
|
||||
(void) snprintf(zbuf, sizeof (zbuf),
|
||||
", started at %s", tbuf);
|
||||
break;
|
||||
case VDEV_INITIALIZE_COMPLETE:
|
||||
(void) snprintf(zbuf, sizeof (zbuf),
|
||||
", completed at %s", tbuf);
|
||||
break;
|
||||
}
|
||||
|
||||
(void) printf(gettext(" (%d%% initialized%s)"),
|
||||
initialize_pct, zbuf);
|
||||
}
|
||||
|
||||
(void) printf("\n");
|
||||
|
||||
for (c = 0; c < children; c++) {
|
||||
@ -4165,6 +4207,119 @@ zpool_do_scrub(int argc, char **argv)
|
||||
return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
|
||||
}
|
||||
|
||||
static void
|
||||
zpool_collect_leaves(zpool_handle_t *zhp, nvlist_t *nvroot, nvlist_t *res)
|
||||
{
|
||||
uint_t children = 0;
|
||||
nvlist_t **child;
|
||||
uint_t i;
|
||||
|
||||
(void) nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
|
||||
&child, &children);
|
||||
|
||||
if (children == 0) {
|
||||
char *path = zpool_vdev_name(g_zfs, zhp, nvroot, B_FALSE);
|
||||
fnvlist_add_boolean(res, path);
|
||||
free(path);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < children; i++) {
|
||||
zpool_collect_leaves(zhp, child[i], res);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* zpool initialize [-cs] <pool> [<vdev> ...]
|
||||
* Initialize all unused blocks in the specified vdevs, or all vdevs in the pool
|
||||
* if none specified.
|
||||
*
|
||||
* -c Cancel. Ends active initializing.
|
||||
* -s Suspend. Initializing can then be restarted with no flags.
|
||||
*/
|
||||
int
|
||||
zpool_do_initialize(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
char *poolname;
|
||||
zpool_handle_t *zhp;
|
||||
nvlist_t *vdevs;
|
||||
int err = 0;
|
||||
|
||||
struct option long_options[] = {
|
||||
{"cancel", no_argument, NULL, 'c'},
|
||||
{"suspend", no_argument, NULL, 's'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
pool_initialize_func_t cmd_type = POOL_INITIALIZE_DO;
|
||||
while ((c = getopt_long(argc, argv, "cs", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
if (cmd_type != POOL_INITIALIZE_DO) {
|
||||
(void) fprintf(stderr, gettext("-c cannot be "
|
||||
"combined with other options\n"));
|
||||
usage(B_FALSE);
|
||||
}
|
||||
cmd_type = POOL_INITIALIZE_CANCEL;
|
||||
break;
|
||||
case 's':
|
||||
if (cmd_type != POOL_INITIALIZE_DO) {
|
||||
(void) fprintf(stderr, gettext("-s cannot be "
|
||||
"combined with other options\n"));
|
||||
usage(B_FALSE);
|
||||
}
|
||||
cmd_type = POOL_INITIALIZE_SUSPEND;
|
||||
break;
|
||||
case '?':
|
||||
if (optopt != 0) {
|
||||
(void) fprintf(stderr,
|
||||
gettext("invalid option '%c'\n"), optopt);
|
||||
} else {
|
||||
(void) fprintf(stderr,
|
||||
gettext("invalid option '%s'\n"),
|
||||
argv[optind - 1]);
|
||||
}
|
||||
usage(B_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1) {
|
||||
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
||||
usage(B_FALSE);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
poolname = argv[0];
|
||||
zhp = zpool_open(g_zfs, poolname);
|
||||
if (zhp == NULL)
|
||||
return (-1);
|
||||
|
||||
vdevs = fnvlist_alloc();
|
||||
if (argc == 1) {
|
||||
/* no individual leaf vdevs specified, so add them all */
|
||||
nvlist_t *config = zpool_get_config(zhp, NULL);
|
||||
nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
|
||||
ZPOOL_CONFIG_VDEV_TREE);
|
||||
zpool_collect_leaves(zhp, nvroot, vdevs);
|
||||
} else {
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
fnvlist_add_boolean(vdevs, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
err = zpool_initialize(zhp, cmd_type, vdevs);
|
||||
|
||||
fnvlist_free(vdevs);
|
||||
zpool_close(zhp);
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
typedef struct status_cbdata {
|
||||
int cb_count;
|
||||
boolean_t cb_allpools;
|
||||
|
@ -103,6 +103,7 @@
|
||||
#include <sys/zil_impl.h>
|
||||
#include <sys/vdev_impl.h>
|
||||
#include <sys/vdev_file.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
#include <sys/spa_impl.h>
|
||||
#include <sys/metaslab_impl.h>
|
||||
#include <sys/dsl_prop.h>
|
||||
@ -346,6 +347,7 @@ ztest_func_t ztest_spa_upgrade;
|
||||
ztest_func_t ztest_device_removal;
|
||||
ztest_func_t ztest_remap_blocks;
|
||||
ztest_func_t ztest_spa_checkpoint_create_discard;
|
||||
ztest_func_t ztest_initialize;
|
||||
|
||||
uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */
|
||||
uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */
|
||||
@ -389,7 +391,8 @@ ztest_info_t ztest_info[] = {
|
||||
&ztest_opts.zo_vdevtime },
|
||||
{ ztest_device_removal, 1, &zopt_sometimes },
|
||||
{ ztest_remap_blocks, 1, &zopt_sometimes },
|
||||
{ ztest_spa_checkpoint_create_discard, 1, &zopt_rarely }
|
||||
{ ztest_spa_checkpoint_create_discard, 1, &zopt_rarely },
|
||||
{ ztest_initialize, 1, &zopt_sometimes }
|
||||
};
|
||||
|
||||
#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
|
||||
@ -5470,6 +5473,97 @@ ztest_spa_rename(ztest_ds_t *zd, uint64_t id)
|
||||
rw_exit(&ztest_name_lock);
|
||||
}
|
||||
|
||||
static vdev_t *
|
||||
ztest_random_concrete_vdev_leaf(vdev_t *vd)
|
||||
{
|
||||
if (vd == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (vd->vdev_children == 0)
|
||||
return (vd);
|
||||
|
||||
vdev_t *eligible[vd->vdev_children];
|
||||
int eligible_idx = 0, i;
|
||||
for (i = 0; i < vd->vdev_children; i++) {
|
||||
vdev_t *cvd = vd->vdev_child[i];
|
||||
if (cvd->vdev_top->vdev_removing)
|
||||
continue;
|
||||
if (cvd->vdev_children > 0 ||
|
||||
(vdev_is_concrete(cvd) && !cvd->vdev_detached)) {
|
||||
eligible[eligible_idx++] = cvd;
|
||||
}
|
||||
}
|
||||
VERIFY(eligible_idx > 0);
|
||||
|
||||
uint64_t child_no = ztest_random(eligible_idx);
|
||||
return (ztest_random_concrete_vdev_leaf(eligible[child_no]));
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
ztest_initialize(ztest_ds_t *zd, uint64_t id)
|
||||
{
|
||||
spa_t *spa = ztest_spa;
|
||||
int error = 0;
|
||||
|
||||
mutex_enter(&ztest_vdev_lock);
|
||||
|
||||
spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
|
||||
|
||||
/* Random leaf vdev */
|
||||
vdev_t *rand_vd = ztest_random_concrete_vdev_leaf(spa->spa_root_vdev);
|
||||
if (rand_vd == NULL) {
|
||||
spa_config_exit(spa, SCL_VDEV, FTAG);
|
||||
mutex_exit(&ztest_vdev_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The random vdev we've selected may change as soon as we
|
||||
* drop the spa_config_lock. We create local copies of things
|
||||
* we're interested in.
|
||||
*/
|
||||
uint64_t guid = rand_vd->vdev_guid;
|
||||
char *path = strdup(rand_vd->vdev_path);
|
||||
boolean_t active = rand_vd->vdev_initialize_thread != NULL;
|
||||
|
||||
zfs_dbgmsg("vd %p, guid %llu", rand_vd, guid);
|
||||
spa_config_exit(spa, SCL_VDEV, FTAG);
|
||||
|
||||
uint64_t cmd = ztest_random(POOL_INITIALIZE_FUNCS);
|
||||
error = spa_vdev_initialize(spa, guid, cmd);
|
||||
switch (cmd) {
|
||||
case POOL_INITIALIZE_CANCEL:
|
||||
if (ztest_opts.zo_verbose >= 4) {
|
||||
(void) printf("Cancel initialize %s", path);
|
||||
if (!active)
|
||||
(void) printf(" failed (no initialize active)");
|
||||
(void) printf("\n");
|
||||
}
|
||||
break;
|
||||
case POOL_INITIALIZE_DO:
|
||||
if (ztest_opts.zo_verbose >= 4) {
|
||||
(void) printf("Start initialize %s", path);
|
||||
if (active && error == 0)
|
||||
(void) printf(" failed (already active)");
|
||||
else if (error != 0)
|
||||
(void) printf(" failed (error %d)", error);
|
||||
(void) printf("\n");
|
||||
}
|
||||
break;
|
||||
case POOL_INITIALIZE_SUSPEND:
|
||||
if (ztest_opts.zo_verbose >= 4) {
|
||||
(void) printf("Suspend initialize %s", path);
|
||||
if (!active)
|
||||
(void) printf(" failed (no initialize active)");
|
||||
(void) printf("\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
free(path);
|
||||
mutex_exit(&ztest_vdev_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify pool integrity by running zdb.
|
||||
*/
|
||||
|
@ -136,6 +136,9 @@ typedef enum zfs_error {
|
||||
EZFS_NO_CHECKPOINT, /* pool has no checkpoint */
|
||||
EZFS_DEVRM_IN_PROGRESS, /* a device is currently being removed */
|
||||
EZFS_VDEV_TOO_BIG, /* a device is too big to be used */
|
||||
EZFS_TOOMANY, /* argument list too long */
|
||||
EZFS_INITIALIZING, /* currently initializing */
|
||||
EZFS_NO_INITIALIZE, /* no active initialize */
|
||||
EZFS_UNKNOWN
|
||||
} zfs_error_t;
|
||||
|
||||
@ -260,6 +263,8 @@ typedef struct splitflags {
|
||||
* Functions to manipulate pool and vdev state
|
||||
*/
|
||||
extern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
|
||||
extern int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
|
||||
nvlist_t *);
|
||||
extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
|
||||
extern int zpool_reguid(zpool_handle_t *);
|
||||
extern int zpool_reopen(zpool_handle_t *);
|
||||
|
@ -1969,6 +1969,100 @@ zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func, pool_scrub_cmd_t cmd)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
xlate_init_err(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case ENODEV:
|
||||
return (EZFS_NODEVICE);
|
||||
case EINVAL:
|
||||
case EROFS:
|
||||
return (EZFS_BADDEV);
|
||||
case EBUSY:
|
||||
return (EZFS_INITIALIZING);
|
||||
case ESRCH:
|
||||
return (EZFS_NO_INITIALIZE);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*
|
||||
* Begin, suspend, or cancel the initialization (initializing of all free
|
||||
* blocks) for the given vdevs in the given pool.
|
||||
*/
|
||||
int
|
||||
zpool_initialize(zpool_handle_t *zhp, pool_initialize_func_t cmd_type,
|
||||
nvlist_t *vds)
|
||||
{
|
||||
char msg[1024];
|
||||
libzfs_handle_t *hdl = zhp->zpool_hdl;
|
||||
|
||||
nvlist_t *errlist;
|
||||
|
||||
/* translate vdev names to guids */
|
||||
nvlist_t *vdev_guids = fnvlist_alloc();
|
||||
nvlist_t *guids_to_paths = fnvlist_alloc();
|
||||
boolean_t spare, cache;
|
||||
nvlist_t *tgt;
|
||||
nvpair_t *elem;
|
||||
|
||||
for (elem = nvlist_next_nvpair(vds, NULL); elem != NULL;
|
||||
elem = nvlist_next_nvpair(vds, elem)) {
|
||||
char *vd_path = nvpair_name(elem);
|
||||
tgt = zpool_find_vdev(zhp, vd_path, &spare, &cache, NULL);
|
||||
|
||||
if ((tgt == NULL) || cache || spare) {
|
||||
(void) snprintf(msg, sizeof (msg),
|
||||
dgettext(TEXT_DOMAIN, "cannot initialize '%s'"),
|
||||
vd_path);
|
||||
int err = (tgt == NULL) ? EZFS_NODEVICE :
|
||||
(spare ? EZFS_ISSPARE : EZFS_ISL2CACHE);
|
||||
fnvlist_free(vdev_guids);
|
||||
fnvlist_free(guids_to_paths);
|
||||
return (zfs_error(hdl, err, msg));
|
||||
}
|
||||
|
||||
uint64_t guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
|
||||
fnvlist_add_uint64(vdev_guids, vd_path, guid);
|
||||
|
||||
(void) snprintf(msg, sizeof (msg), "%llu", guid);
|
||||
fnvlist_add_string(guids_to_paths, msg, vd_path);
|
||||
}
|
||||
|
||||
int err = lzc_initialize(zhp->zpool_name, cmd_type, vdev_guids,
|
||||
&errlist);
|
||||
fnvlist_free(vdev_guids);
|
||||
|
||||
if (err == 0) {
|
||||
fnvlist_free(guids_to_paths);
|
||||
return (0);
|
||||
}
|
||||
|
||||
nvlist_t *vd_errlist = NULL;
|
||||
if (errlist != NULL) {
|
||||
vd_errlist = fnvlist_lookup_nvlist(errlist,
|
||||
ZPOOL_INITIALIZE_VDEVS);
|
||||
}
|
||||
|
||||
(void) snprintf(msg, sizeof (msg),
|
||||
dgettext(TEXT_DOMAIN, "operation failed"));
|
||||
|
||||
for (elem = nvlist_next_nvpair(vd_errlist, NULL); elem != NULL;
|
||||
elem = nvlist_next_nvpair(vd_errlist, elem)) {
|
||||
int64_t vd_error = xlate_init_err(fnvpair_value_int64(elem));
|
||||
char *path = fnvlist_lookup_string(guids_to_paths,
|
||||
nvpair_name(elem));
|
||||
(void) zfs_error_fmt(hdl, vd_error, "cannot initialize '%s'",
|
||||
path);
|
||||
}
|
||||
|
||||
fnvlist_free(guids_to_paths);
|
||||
if (vd_errlist != NULL)
|
||||
return (-1);
|
||||
|
||||
return (zpool_standard_error(hdl, err, msg));
|
||||
}
|
||||
|
||||
/*
|
||||
* This provides a very minimal check whether a given string is likely a
|
||||
* c#t#d# style string. Users of this are expected to do their own
|
||||
|
@ -249,6 +249,13 @@ libzfs_error_description(libzfs_handle_t *hdl)
|
||||
return (dgettext(TEXT_DOMAIN, "device removal in progress"));
|
||||
case EZFS_VDEV_TOO_BIG:
|
||||
return (dgettext(TEXT_DOMAIN, "device exceeds supported size"));
|
||||
case EZFS_TOOMANY:
|
||||
return (dgettext(TEXT_DOMAIN, "argument list too long"));
|
||||
case EZFS_INITIALIZING:
|
||||
return (dgettext(TEXT_DOMAIN, "currently initializing"));
|
||||
case EZFS_NO_INITIALIZE:
|
||||
return (dgettext(TEXT_DOMAIN, "there is no active "
|
||||
"initialization"));
|
||||
case EZFS_UNKNOWN:
|
||||
return (dgettext(TEXT_DOMAIN, "unknown error"));
|
||||
default:
|
||||
|
@ -1038,3 +1038,40 @@ lzc_channel_program_nosync(const char *pool, const char *program,
|
||||
return (lzc_channel_program_impl(pool, program, B_FALSE, timeout,
|
||||
memlimit, argnvl, outnvl));
|
||||
}
|
||||
|
||||
/*
|
||||
* Changes initializing state.
|
||||
*
|
||||
* vdevs should be a list of (<key>, guid) where guid is a uint64 vdev GUID.
|
||||
* The key is ignored.
|
||||
*
|
||||
* If there are errors related to vdev arguments, per-vdev errors are returned
|
||||
* in an nvlist with the key "vdevs". Each error is a (guid, errno) pair where
|
||||
* guid is stringified with PRIu64, and errno is one of the following as
|
||||
* an int64_t:
|
||||
* - ENODEV if the device was not found
|
||||
* - EINVAL if the devices is not a leaf or is not concrete (e.g. missing)
|
||||
* - EROFS if the device is not writeable
|
||||
* - EBUSY start requested but the device is already being initialized
|
||||
* - ESRCH cancel/suspend requested but device is not being initialized
|
||||
*
|
||||
* If the errlist is empty, then return value will be:
|
||||
* - EINVAL if one or more arguments was invalid
|
||||
* - Other spa_open failures
|
||||
* - 0 if the operation succeeded
|
||||
*/
|
||||
int
|
||||
lzc_initialize(const char *poolname, pool_initialize_func_t cmd_type,
|
||||
nvlist_t *vdevs, nvlist_t **errlist)
|
||||
{
|
||||
int error;
|
||||
nvlist_t *args = fnvlist_alloc();
|
||||
fnvlist_add_uint64(args, ZPOOL_INITIALIZE_COMMAND, (uint64_t)cmd_type);
|
||||
fnvlist_add_nvlist(args, ZPOOL_INITIALIZE_VDEVS, vdevs);
|
||||
|
||||
error = lzc_ioctl(ZFS_IOC_POOL_INITIALIZE, poolname, args, errlist);
|
||||
|
||||
fnvlist_free(args);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include <libnvpair.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fs/zfs.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -56,6 +58,8 @@ int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **);
|
||||
int lzc_bookmark(nvlist_t *, nvlist_t **);
|
||||
int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **);
|
||||
int lzc_destroy_bookmarks(nvlist_t *, nvlist_t **);
|
||||
int lzc_initialize(const char *, pool_initialize_func_t, nvlist_t *,
|
||||
nvlist_t **);
|
||||
|
||||
int lzc_snaprange_space(const char *, const char *, uint64_t *);
|
||||
|
||||
|
@ -105,6 +105,11 @@
|
||||
.Ar pool Ns | Ns Ar id
|
||||
.Op Ar newpool
|
||||
.Nm
|
||||
.Cm initialize
|
||||
.Op Fl cs
|
||||
.Ar pool
|
||||
.Op Ar device Ns ...
|
||||
.Nm
|
||||
.Cm iostat
|
||||
.Op Fl v
|
||||
.Op Fl T Sy u Ns | Ns Sy d
|
||||
@ -1336,6 +1341,32 @@ to fully rewind.
|
||||
.El
|
||||
.It Xo
|
||||
.Nm
|
||||
.Cm initialize
|
||||
.Op Fl cs
|
||||
.Ar pool
|
||||
.Op Ar device Ns ...
|
||||
.Xc
|
||||
Begins initializing by writing to all unallocated regions on the specified
|
||||
devices, or all eligible devices in the pool if no individual devices are
|
||||
specified.
|
||||
Only leaf data or log devices may be initialized.
|
||||
.Bl -tag -width Ds
|
||||
.It Fl c, -cancel
|
||||
Cancel initializing on the specified devices, or all eligible devices if none
|
||||
are specified.
|
||||
If one or more target devices are invalid or are not currently being
|
||||
initialized, the command will fail and no cancellation will occur on any device.
|
||||
.It Fl s -suspend
|
||||
Suspend initializing on the specified devices, or all eligible devices if none
|
||||
are specified.
|
||||
If one or more target devices are invalid or are not currently being
|
||||
initialized, the command will fail and no suspension will occur on any device.
|
||||
Initializing can then be resumed by running
|
||||
.Nm zpool Cm initialize
|
||||
with no flags on the relevant target devices.
|
||||
.El
|
||||
.It Xo
|
||||
.Nm
|
||||
.Cm iostat
|
||||
.Op Fl v
|
||||
.Op Fl T Sy u Ns | Ns Sy d
|
||||
|
@ -1398,6 +1398,7 @@ ZFS_COMMON_OBJS += \
|
||||
vdev.o \
|
||||
vdev_cache.o \
|
||||
vdev_file.o \
|
||||
vdev_initialize.o \
|
||||
vdev_label.o \
|
||||
vdev_mirror.o \
|
||||
vdev_missing.o \
|
||||
|
@ -635,6 +635,8 @@ metaslab_group_create(metaslab_class_t *mc, vdev_t *vd, int allocators)
|
||||
|
||||
mg = kmem_zalloc(sizeof (metaslab_group_t), KM_SLEEP);
|
||||
mutex_init(&mg->mg_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&mg->mg_ms_initialize_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
cv_init(&mg->mg_ms_initialize_cv, NULL, CV_DEFAULT, NULL);
|
||||
mg->mg_primaries = kmem_zalloc(allocators * sizeof (metaslab_t *),
|
||||
KM_SLEEP);
|
||||
mg->mg_secondaries = kmem_zalloc(allocators * sizeof (metaslab_t *),
|
||||
@ -681,6 +683,8 @@ metaslab_group_destroy(metaslab_group_t *mg)
|
||||
kmem_free(mg->mg_secondaries, mg->mg_allocators *
|
||||
sizeof (metaslab_t *));
|
||||
mutex_destroy(&mg->mg_lock);
|
||||
mutex_destroy(&mg->mg_ms_initialize_lock);
|
||||
cv_destroy(&mg->mg_ms_initialize_cv);
|
||||
|
||||
for (int i = 0; i < mg->mg_allocators; i++) {
|
||||
refcount_destroy(&mg->mg_alloc_queue_depth[i]);
|
||||
@ -1541,6 +1545,7 @@ metaslab_init(metaslab_group_t *mg, uint64_t id, uint64_t object, uint64_t txg,
|
||||
mutex_init(&ms->ms_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&ms->ms_sync_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
cv_init(&ms->ms_load_cv, NULL, CV_DEFAULT, NULL);
|
||||
|
||||
ms->ms_id = id;
|
||||
ms->ms_start = id << vd->vdev_ms_shift;
|
||||
ms->ms_size = 1ULL << vd->vdev_ms_shift;
|
||||
@ -2717,6 +2722,7 @@ metaslab_sync_done(metaslab_t *msp, uint64_t txg)
|
||||
* from it in 'metaslab_unload_delay' txgs, then unload it.
|
||||
*/
|
||||
if (msp->ms_loaded &&
|
||||
msp->ms_initializing == 0 &&
|
||||
msp->ms_selected_txg + metaslab_unload_delay < txg) {
|
||||
for (int t = 1; t < TXG_CONCURRENT_STATES; t++) {
|
||||
VERIFY0(range_tree_space(
|
||||
@ -2966,6 +2972,7 @@ metaslab_block_alloc(metaslab_t *msp, uint64_t size, uint64_t txg)
|
||||
metaslab_class_t *mc = msp->ms_group->mg_class;
|
||||
|
||||
VERIFY(!msp->ms_condensing);
|
||||
VERIFY0(msp->ms_initializing);
|
||||
|
||||
start = mc->mc_ops->msop_alloc(msp, size);
|
||||
if (start != -1ULL) {
|
||||
@ -3026,9 +3033,10 @@ find_valid_metaslab(metaslab_group_t *mg, uint64_t activation_weight,
|
||||
}
|
||||
|
||||
/*
|
||||
* If the selected metaslab is condensing, skip it.
|
||||
* If the selected metaslab is condensing or being
|
||||
* initialized, skip it.
|
||||
*/
|
||||
if (msp->ms_condensing)
|
||||
if (msp->ms_condensing || msp->ms_initializing > 0)
|
||||
continue;
|
||||
|
||||
*was_active = msp->ms_allocator != -1;
|
||||
@ -3193,7 +3201,9 @@ metaslab_group_alloc_normal(metaslab_group_t *mg, zio_alloc_list_t *zal,
|
||||
/*
|
||||
* If this metaslab is currently condensing then pick again as
|
||||
* we can't manipulate this metaslab until it's committed
|
||||
* to disk.
|
||||
* to disk. If this metaslab is being initialized, we shouldn't
|
||||
* allocate from it since the allocated region might be
|
||||
* overwritten after allocation.
|
||||
*/
|
||||
if (msp->ms_condensing) {
|
||||
metaslab_trace_add(zal, mg, msp, asize, d,
|
||||
@ -3202,6 +3212,13 @@ metaslab_group_alloc_normal(metaslab_group_t *mg, zio_alloc_list_t *zal,
|
||||
~METASLAB_ACTIVE_MASK);
|
||||
mutex_exit(&msp->ms_lock);
|
||||
continue;
|
||||
} else if (msp->ms_initializing > 0) {
|
||||
metaslab_trace_add(zal, mg, msp, asize, d,
|
||||
TRACE_INITIALIZING, allocator);
|
||||
metaslab_passivate(msp, msp->ms_weight &
|
||||
~METASLAB_ACTIVE_MASK);
|
||||
mutex_exit(&msp->ms_lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
offset = metaslab_block_alloc(msp, asize, txg);
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include <sys/vdev_removal.h>
|
||||
#include <sys/vdev_indirect_mapping.h>
|
||||
#include <sys/vdev_indirect_births.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
#include <sys/metaslab.h>
|
||||
#include <sys/metaslab_impl.h>
|
||||
#include <sys/uberblock_impl.h>
|
||||
@ -413,8 +414,9 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp)
|
||||
|
||||
dp = spa_get_dsl(spa);
|
||||
dsl_pool_config_enter(dp, FTAG);
|
||||
if (err = dsl_dataset_hold_obj(dp,
|
||||
za.za_first_integer, FTAG, &ds)) {
|
||||
err = dsl_dataset_hold_obj(dp,
|
||||
za.za_first_integer, FTAG, &ds);
|
||||
if (err != 0) {
|
||||
dsl_pool_config_exit(dp, FTAG);
|
||||
break;
|
||||
}
|
||||
@ -569,7 +571,8 @@ spa_prop_validate(spa_t *spa, nvlist_t *props)
|
||||
break;
|
||||
}
|
||||
|
||||
if (error = dmu_objset_hold(strval, FTAG, &os))
|
||||
error = dmu_objset_hold(strval, FTAG, &os);
|
||||
if (error != 0)
|
||||
break;
|
||||
|
||||
/*
|
||||
@ -1155,8 +1158,10 @@ spa_activate(spa_t *spa, int mode)
|
||||
spa_create_zio_taskqs(spa);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < TXG_SIZE; i++)
|
||||
spa->spa_txg_zio[i] = zio_root(spa, NULL, NULL, 0);
|
||||
for (size_t i = 0; i < TXG_SIZE; i++) {
|
||||
spa->spa_txg_zio[i] = zio_root(spa, NULL, NULL,
|
||||
ZIO_FLAG_CANFAIL);
|
||||
}
|
||||
|
||||
list_create(&spa->spa_config_dirty_list, sizeof (vdev_t),
|
||||
offsetof(vdev_t, vdev_config_dirty_node));
|
||||
@ -1315,6 +1320,11 @@ spa_unload(spa_t *spa)
|
||||
*/
|
||||
spa_async_suspend(spa);
|
||||
|
||||
if (spa->spa_root_vdev) {
|
||||
vdev_initialize_stop_all(spa->spa_root_vdev,
|
||||
VDEV_INITIALIZE_ACTIVE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop syncing.
|
||||
*/
|
||||
@ -1330,10 +1340,10 @@ spa_unload(spa_t *spa)
|
||||
* calling taskq_wait(mg_taskq).
|
||||
*/
|
||||
if (spa->spa_root_vdev != NULL) {
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
|
||||
for (int c = 0; c < spa->spa_root_vdev->vdev_children; c++)
|
||||
vdev_metaslab_fini(spa->spa_root_vdev->vdev_child[c]);
|
||||
spa_config_exit(spa, SCL_ALL, FTAG);
|
||||
spa_config_exit(spa, SCL_ALL, spa);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1367,7 +1377,7 @@ spa_unload(spa_t *spa)
|
||||
|
||||
bpobj_close(&spa->spa_deferred_bpobj);
|
||||
|
||||
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
|
||||
spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
|
||||
|
||||
/*
|
||||
* Close all vdevs.
|
||||
@ -1429,7 +1439,7 @@ spa_unload(spa_t *spa)
|
||||
spa->spa_comment = NULL;
|
||||
}
|
||||
|
||||
spa_config_exit(spa, SCL_ALL, FTAG);
|
||||
spa_config_exit(spa, SCL_ALL, spa);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3866,6 +3876,10 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, char **ereport)
|
||||
spa_restart_removal(spa);
|
||||
|
||||
spa_spawn_aux_threads(spa);
|
||||
|
||||
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
|
||||
vdev_initialize_restart(spa->spa_root_vdev);
|
||||
spa_config_exit(spa, SCL_CONFIG, FTAG);
|
||||
}
|
||||
|
||||
spa_load_note(spa, "LOADED");
|
||||
@ -5347,6 +5361,7 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig,
|
||||
* in which case we can modify its state.
|
||||
*/
|
||||
if (spa->spa_state != POOL_STATE_UNINITIALIZED && spa->spa_sync_on) {
|
||||
|
||||
/*
|
||||
* Objsets may be open only because they're dirty, so we
|
||||
* have to force it to sync before checking spa_refcnt.
|
||||
@ -5380,6 +5395,18 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig,
|
||||
return (SET_ERROR(EXDEV));
|
||||
}
|
||||
|
||||
/*
|
||||
* We're about to export or destroy this pool. Make sure
|
||||
* we stop all initializtion activity here before we
|
||||
* set the spa_final_txg. This will ensure that all
|
||||
* dirty data resulting from the initialization is
|
||||
* committed to disk before we unload the pool.
|
||||
*/
|
||||
if (spa->spa_root_vdev != NULL) {
|
||||
vdev_initialize_stop_all(spa->spa_root_vdev,
|
||||
VDEV_INITIALIZE_ACTIVE);
|
||||
}
|
||||
|
||||
/*
|
||||
* We want this to be reflected on every label,
|
||||
* so mark them all dirty. spa_unload() will do the
|
||||
@ -6070,6 +6097,86 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
spa_vdev_initialize(spa_t *spa, uint64_t guid, uint64_t cmd_type)
|
||||
{
|
||||
/*
|
||||
* We hold the namespace lock through the whole function
|
||||
* to prevent any changes to the pool while we're starting or
|
||||
* stopping initialization. The config and state locks are held so that
|
||||
* we can properly assess the vdev state before we commit to
|
||||
* the initializing operation.
|
||||
*/
|
||||
mutex_enter(&spa_namespace_lock);
|
||||
spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER);
|
||||
|
||||
/* Look up vdev and ensure it's a leaf. */
|
||||
vdev_t *vd = spa_lookup_by_guid(spa, guid, B_FALSE);
|
||||
if (vd == NULL || vd->vdev_detached) {
|
||||
spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(ENODEV));
|
||||
} else if (!vd->vdev_ops->vdev_op_leaf || !vdev_is_concrete(vd)) {
|
||||
spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(EINVAL));
|
||||
} else if (!vdev_writeable(vd)) {
|
||||
spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(EROFS));
|
||||
}
|
||||
mutex_enter(&vd->vdev_initialize_lock);
|
||||
spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
|
||||
|
||||
/*
|
||||
* When we activate an initialize action we check to see
|
||||
* if the vdev_initialize_thread is NULL. We do this instead
|
||||
* of using the vdev_initialize_state since there might be
|
||||
* a previous initialization process which has completed but
|
||||
* the thread is not exited.
|
||||
*/
|
||||
if (cmd_type == POOL_INITIALIZE_DO &&
|
||||
(vd->vdev_initialize_thread != NULL ||
|
||||
vd->vdev_top->vdev_removing)) {
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(EBUSY));
|
||||
} else if (cmd_type == POOL_INITIALIZE_CANCEL &&
|
||||
(vd->vdev_initialize_state != VDEV_INITIALIZE_ACTIVE &&
|
||||
vd->vdev_initialize_state != VDEV_INITIALIZE_SUSPENDED)) {
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(ESRCH));
|
||||
} else if (cmd_type == POOL_INITIALIZE_SUSPEND &&
|
||||
vd->vdev_initialize_state != VDEV_INITIALIZE_ACTIVE) {
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
return (SET_ERROR(ESRCH));
|
||||
}
|
||||
|
||||
switch (cmd_type) {
|
||||
case POOL_INITIALIZE_DO:
|
||||
vdev_initialize(vd);
|
||||
break;
|
||||
case POOL_INITIALIZE_CANCEL:
|
||||
vdev_initialize_stop(vd, VDEV_INITIALIZE_CANCELED);
|
||||
break;
|
||||
case POOL_INITIALIZE_SUSPEND:
|
||||
vdev_initialize_stop(vd, VDEV_INITIALIZE_SUSPENDED);
|
||||
break;
|
||||
default:
|
||||
panic("invalid cmd_type %llu", (unsigned long long)cmd_type);
|
||||
}
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
|
||||
/* Sync out the initializing state */
|
||||
txg_wait_synced(spa->spa_dsl_pool, 0);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Split a set of devices from their mirrors, and create a new pool from them.
|
||||
*/
|
||||
@ -6277,6 +6384,19 @@ spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
spa_activate(newspa, spa_mode_global);
|
||||
spa_async_suspend(newspa);
|
||||
|
||||
for (c = 0; c < children; c++) {
|
||||
if (vml[c] != NULL) {
|
||||
/*
|
||||
* Temporarily stop the initializing activity. We set
|
||||
* the state to ACTIVE so that we know to resume
|
||||
* the initializing once the split has completed.
|
||||
*/
|
||||
mutex_enter(&vml[c]->vdev_initialize_lock);
|
||||
vdev_initialize_stop(vml[c], VDEV_INITIALIZE_ACTIVE);
|
||||
mutex_exit(&vml[c]->vdev_initialize_lock);
|
||||
}
|
||||
}
|
||||
|
||||
newspa->spa_config_source = SPA_CONFIG_SRC_SPLIT;
|
||||
|
||||
/* create the new pool from the disks of the original pool */
|
||||
@ -6364,6 +6484,10 @@ spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
if (vml[c] != NULL)
|
||||
vml[c]->vdev_offline = B_FALSE;
|
||||
}
|
||||
|
||||
/* restart initializing disks as necessary */
|
||||
spa_async_request(spa, SPA_ASYNC_INITIALIZE_RESTART);
|
||||
|
||||
vdev_reopen(spa->spa_root_vdev);
|
||||
|
||||
nvlist_free(spa->spa_config_splitting);
|
||||
@ -6739,6 +6863,14 @@ spa_async_thread(void *arg)
|
||||
if (tasks & SPA_ASYNC_RESILVER)
|
||||
dsl_resilver_restart(spa->spa_dsl_pool, 0);
|
||||
|
||||
if (tasks & SPA_ASYNC_INITIALIZE_RESTART) {
|
||||
mutex_enter(&spa_namespace_lock);
|
||||
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
|
||||
vdev_initialize_restart(spa->spa_root_vdev);
|
||||
spa_config_exit(spa, SCL_CONFIG, FTAG);
|
||||
mutex_exit(&spa_namespace_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Let the world know that we're done.
|
||||
*/
|
||||
@ -7384,8 +7516,9 @@ spa_sync(spa_t *spa, uint64_t txg)
|
||||
* Wait for i/os issued in open context that need to complete
|
||||
* before this txg syncs.
|
||||
*/
|
||||
VERIFY0(zio_wait(spa->spa_txg_zio[txg & TXG_MASK]));
|
||||
spa->spa_txg_zio[txg & TXG_MASK] = zio_root(spa, NULL, NULL, 0);
|
||||
(void) zio_wait(spa->spa_txg_zio[txg & TXG_MASK]);
|
||||
spa->spa_txg_zio[txg & TXG_MASK] = zio_root(spa, NULL, NULL,
|
||||
ZIO_FLAG_CANFAIL);
|
||||
|
||||
/*
|
||||
* Lock out configuration changes.
|
||||
@ -7674,7 +7807,8 @@ spa_sync(spa_t *spa, uint64_t txg)
|
||||
/*
|
||||
* Update usable space statistics.
|
||||
*/
|
||||
while (vd = txg_list_remove(&spa->spa_vdev_txg_list, TXG_CLEAN(txg)))
|
||||
while ((vd = txg_list_remove(&spa->spa_vdev_txg_list, TXG_CLEAN(txg)))
|
||||
!= NULL)
|
||||
vdev_sync_done(vd, txg);
|
||||
|
||||
spa_update_dspace(spa);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <sys/zap.h>
|
||||
#include <sys/zil.h>
|
||||
#include <sys/vdev_impl.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
#include <sys/metaslab.h>
|
||||
#include <sys/uberblock_impl.h>
|
||||
#include <sys/txg.h>
|
||||
@ -1196,6 +1197,12 @@ spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error, char *tag)
|
||||
|
||||
if (vd != NULL) {
|
||||
ASSERT(!vd->vdev_detached || vd->vdev_dtl_sm == NULL);
|
||||
if (vd->vdev_ops->vdev_op_leaf) {
|
||||
mutex_enter(&vd->vdev_initialize_lock);
|
||||
vdev_initialize_stop(vd, VDEV_INITIALIZE_CANCELED);
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
}
|
||||
|
||||
spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
|
||||
vdev_free(vd);
|
||||
spa_config_exit(spa, SCL_ALL, spa);
|
||||
|
@ -68,7 +68,8 @@ typedef enum trace_alloc_type {
|
||||
TRACE_GROUP_FAILURE = -5ULL,
|
||||
TRACE_ENOSPC = -6ULL,
|
||||
TRACE_CONDENSING = -7ULL,
|
||||
TRACE_VDEV_ERROR = -8ULL
|
||||
TRACE_VDEV_ERROR = -8ULL,
|
||||
TRACE_INITIALIZING = -9ULL
|
||||
} trace_alloc_type_t;
|
||||
|
||||
#define METASLAB_WEIGHT_PRIMARY (1ULL << 63)
|
||||
@ -270,6 +271,11 @@ struct metaslab_group {
|
||||
uint64_t mg_failed_allocations;
|
||||
uint64_t mg_fragmentation;
|
||||
uint64_t mg_histogram[RANGE_TREE_HISTOGRAM_SIZE];
|
||||
|
||||
int mg_ms_initializing;
|
||||
boolean_t mg_initialize_updating;
|
||||
kmutex_t mg_ms_initialize_lock;
|
||||
kcondvar_t mg_ms_initialize_cv;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -360,6 +366,8 @@ struct metaslab {
|
||||
boolean_t ms_condense_wanted;
|
||||
uint64_t ms_condense_checked_txg;
|
||||
|
||||
uint64_t ms_initializing; /* leaves initializing this ms */
|
||||
|
||||
/*
|
||||
* We must hold both ms_lock and ms_group->mg_lock in order to
|
||||
* modify ms_loaded.
|
||||
|
@ -650,6 +650,7 @@ extern int spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps);
|
||||
#define SPA_ASYNC_AUTOEXPAND 0x20
|
||||
#define SPA_ASYNC_REMOVE_DONE 0x40
|
||||
#define SPA_ASYNC_REMOVE_STOP 0x80
|
||||
#define SPA_ASYNC_INITIALIZE_RESTART 0x100
|
||||
|
||||
/*
|
||||
* Controls the behavior of spa_vdev_remove().
|
||||
@ -665,6 +666,7 @@ extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
|
||||
int replace_done);
|
||||
extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
|
||||
extern boolean_t spa_vdev_remove_active(spa_t *spa);
|
||||
extern int spa_vdev_initialize(spa_t *spa, uint64_t guid, uint64_t cmd_type);
|
||||
extern int spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath);
|
||||
extern int spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru);
|
||||
extern int spa_vdev_split_mirror(spa_t *spa, char *newname, nvlist_t *config,
|
||||
|
@ -79,6 +79,12 @@ typedef void vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd,
|
||||
uint64_t offset, uint64_t size, void *arg);
|
||||
typedef void vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size,
|
||||
vdev_remap_cb_t callback, void *arg);
|
||||
/*
|
||||
* Given a target vdev, translates the logical range "in" to the physical
|
||||
* range "res"
|
||||
*/
|
||||
typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg_t *in,
|
||||
range_seg_t *res);
|
||||
|
||||
typedef struct vdev_ops {
|
||||
vdev_open_func_t *vdev_op_open;
|
||||
@ -90,6 +96,11 @@ typedef struct vdev_ops {
|
||||
vdev_hold_func_t *vdev_op_hold;
|
||||
vdev_rele_func_t *vdev_op_rele;
|
||||
vdev_remap_func_t *vdev_op_remap;
|
||||
/*
|
||||
* For translating ranges from non-leaf vdevs (e.g. raidz) to leaves.
|
||||
* Used when initializing vdevs. Isn't used by leaf ops.
|
||||
*/
|
||||
vdev_xlation_func_t *vdev_op_xlate;
|
||||
char vdev_op_type[16];
|
||||
boolean_t vdev_op_leaf;
|
||||
} vdev_ops_t;
|
||||
@ -231,6 +242,24 @@ struct vdev {
|
||||
|
||||
/* pool checkpoint related */
|
||||
space_map_t *vdev_checkpoint_sm; /* contains reserved blocks */
|
||||
|
||||
boolean_t vdev_initialize_exit_wanted;
|
||||
vdev_initializing_state_t vdev_initialize_state;
|
||||
kthread_t *vdev_initialize_thread;
|
||||
/* Protects vdev_initialize_thread and vdev_initialize_state. */
|
||||
kmutex_t vdev_initialize_lock;
|
||||
kcondvar_t vdev_initialize_cv;
|
||||
uint64_t vdev_initialize_offset[TXG_SIZE];
|
||||
uint64_t vdev_initialize_last_offset;
|
||||
range_tree_t *vdev_initialize_tree; /* valid while initializing */
|
||||
uint64_t vdev_initialize_bytes_est;
|
||||
uint64_t vdev_initialize_bytes_done;
|
||||
time_t vdev_initialize_action_time; /* start and end time */
|
||||
|
||||
/* for limiting outstanding I/Os */
|
||||
kmutex_t vdev_initialize_io_lock;
|
||||
kcondvar_t vdev_initialize_io_cv;
|
||||
uint64_t vdev_initialize_inflight;
|
||||
|
||||
/*
|
||||
* Values stored in the config for an indirect or removing vdev.
|
||||
@ -434,6 +463,8 @@ extern vdev_ops_t vdev_indirect_ops;
|
||||
/*
|
||||
* Common size functions
|
||||
*/
|
||||
extern void vdev_default_xlate(vdev_t *vd, const range_seg_t *in,
|
||||
range_seg_t *out);
|
||||
extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize);
|
||||
extern uint64_t vdev_get_min_asize(vdev_t *vd);
|
||||
extern void vdev_set_min_asize(vdev_t *vd);
|
||||
|
@ -13,7 +13,7 @@
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2014 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2014, 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
#ifndef _ZIO_PRIORITY_H
|
||||
#define _ZIO_PRIORITY_H
|
||||
@ -29,6 +29,7 @@ typedef enum zio_priority {
|
||||
ZIO_PRIORITY_ASYNC_WRITE, /* spa_sync() */
|
||||
ZIO_PRIORITY_SCRUB, /* asynchronous scrub/resilver reads */
|
||||
ZIO_PRIORITY_REMOVAL, /* reads/writes for vdev removal */
|
||||
ZIO_PRIORITY_INITIALIZING, /* initializing I/O */
|
||||
ZIO_PRIORITY_NUM_QUEUEABLE,
|
||||
|
||||
ZIO_PRIORITY_NOW /* non-queued i/os (e.g. free) */
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include <sys/zil.h>
|
||||
#include <sys/dsl_scan.h>
|
||||
#include <sys/abd.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
|
||||
/*
|
||||
* Virtual device management.
|
||||
@ -183,6 +184,14 @@ vdev_getops(const char *type)
|
||||
return (ops);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
vdev_default_xlate(vdev_t *vd, const range_seg_t *in, range_seg_t *res)
|
||||
{
|
||||
res->rs_start = in->rs_start;
|
||||
res->rs_end = in->rs_end;
|
||||
}
|
||||
|
||||
/*
|
||||
* Default asize function: return the MAX of psize with the asize of
|
||||
* all children. This is what's used by anything other than RAID-Z.
|
||||
@ -453,6 +462,11 @@ vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, vdev_ops_t *ops)
|
||||
mutex_init(&vd->vdev_stat_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&vd->vdev_probe_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&vd->vdev_queue_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&vd->vdev_initialize_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
mutex_init(&vd->vdev_initialize_io_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
cv_init(&vd->vdev_initialize_cv, NULL, CV_DEFAULT, NULL);
|
||||
cv_init(&vd->vdev_initialize_io_cv, NULL, CV_DEFAULT, NULL);
|
||||
|
||||
for (int t = 0; t < DTL_TYPES; t++) {
|
||||
vd->vdev_dtl[t] = range_tree_create(NULL, NULL);
|
||||
}
|
||||
@ -725,6 +739,7 @@ void
|
||||
vdev_free(vdev_t *vd)
|
||||
{
|
||||
spa_t *spa = vd->vdev_spa;
|
||||
ASSERT3P(vd->vdev_initialize_thread, ==, NULL);
|
||||
|
||||
/*
|
||||
* vdev_free() implies closing the vdev first. This is simpler than
|
||||
@ -743,6 +758,7 @@ vdev_free(vdev_t *vd)
|
||||
|
||||
ASSERT(vd->vdev_child == NULL);
|
||||
ASSERT(vd->vdev_guid_sum == vd->vdev_guid);
|
||||
ASSERT(vd->vdev_initialize_thread == NULL);
|
||||
|
||||
/*
|
||||
* Discard allocation state.
|
||||
@ -815,6 +831,10 @@ vdev_free(vdev_t *vd)
|
||||
mutex_destroy(&vd->vdev_dtl_lock);
|
||||
mutex_destroy(&vd->vdev_stat_lock);
|
||||
mutex_destroy(&vd->vdev_probe_lock);
|
||||
mutex_destroy(&vd->vdev_initialize_lock);
|
||||
mutex_destroy(&vd->vdev_initialize_io_lock);
|
||||
cv_destroy(&vd->vdev_initialize_io_cv);
|
||||
cv_destroy(&vd->vdev_initialize_cv);
|
||||
|
||||
if (vd == spa->spa_root_vdev)
|
||||
spa->spa_root_vdev = NULL;
|
||||
@ -2841,7 +2861,8 @@ vdev_sync_done(vdev_t *vd, uint64_t txg)
|
||||
|
||||
ASSERT(vdev_is_concrete(vd));
|
||||
|
||||
while (msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
|
||||
while ((msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
|
||||
!= NULL)
|
||||
metaslab_sync_done(msp, txg);
|
||||
|
||||
if (reassess)
|
||||
@ -3067,6 +3088,15 @@ vdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
|
||||
spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE);
|
||||
}
|
||||
|
||||
/* Restart initializing if necessary */
|
||||
mutex_enter(&vd->vdev_initialize_lock);
|
||||
if (vdev_writeable(vd) &&
|
||||
vd->vdev_initialize_thread == NULL &&
|
||||
vd->vdev_initialize_state == VDEV_INITIALIZE_ACTIVE) {
|
||||
(void) vdev_initialize(vd);
|
||||
}
|
||||
mutex_exit(&vd->vdev_initialize_lock);
|
||||
|
||||
if (wasoffline ||
|
||||
(oldstate < VDEV_STATE_DEGRADED &&
|
||||
vd->vdev_state >= VDEV_STATE_DEGRADED))
|
||||
@ -3361,8 +3391,18 @@ vdev_get_stats(vdev_t *vd, vdev_stat_t *vs)
|
||||
vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
|
||||
vs->vs_state = vd->vdev_state;
|
||||
vs->vs_rsize = vdev_get_min_asize(vd);
|
||||
if (vd->vdev_ops->vdev_op_leaf)
|
||||
if (vd->vdev_ops->vdev_op_leaf) {
|
||||
vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
|
||||
/*
|
||||
* Report intializing progress. Since we don't have the
|
||||
* initializing locks held, this is only an estimate (although a
|
||||
* fairly accurate one).
|
||||
*/
|
||||
vs->vs_initialize_bytes_done = vd->vdev_initialize_bytes_done;
|
||||
vs->vs_initialize_bytes_est = vd->vdev_initialize_bytes_est;
|
||||
vs->vs_initialize_state = vd->vdev_initialize_state;
|
||||
vs->vs_initialize_action_time = vd->vdev_initialize_action_time;
|
||||
}
|
||||
/*
|
||||
* Report expandable space on top-level, non-auxillary devices only.
|
||||
* The expandable space is reported in terms of metaslab sized units
|
||||
|
@ -840,6 +840,7 @@ vdev_ops_t vdev_disk_ops = {
|
||||
vdev_disk_hold,
|
||||
vdev_disk_rele,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_DISK, /* name of this vdev type */
|
||||
B_TRUE /* leaf vdev */
|
||||
};
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2015 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2011, 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/zfs_context.h>
|
||||
@ -263,6 +263,7 @@ vdev_ops_t vdev_file_ops = {
|
||||
vdev_file_hold,
|
||||
vdev_file_rele,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_FILE, /* name of this vdev type */
|
||||
B_TRUE /* leaf vdev */
|
||||
};
|
||||
@ -282,6 +283,7 @@ vdev_ops_t vdev_disk_ops = {
|
||||
vdev_file_hold,
|
||||
vdev_file_rele,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_DISK, /* name of this vdev type */
|
||||
B_TRUE /* leaf vdev */
|
||||
};
|
||||
|
@ -1628,6 +1628,7 @@ vdev_ops_t vdev_indirect_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
vdev_indirect_remap,
|
||||
NULL,
|
||||
VDEV_TYPE_INDIRECT, /* name of this vdev type */
|
||||
B_FALSE /* leaf vdev */
|
||||
};
|
||||
|
@ -564,6 +564,7 @@ vdev_ops_t vdev_mirror_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_MIRROR, /* name of this vdev type */
|
||||
B_FALSE /* not a leaf vdev */
|
||||
};
|
||||
@ -578,6 +579,7 @@ vdev_ops_t vdev_replacing_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_REPLACING, /* name of this vdev type */
|
||||
B_FALSE /* not a leaf vdev */
|
||||
};
|
||||
@ -592,6 +594,7 @@ vdev_ops_t vdev_spare_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
vdev_default_xlate,
|
||||
VDEV_TYPE_SPARE, /* name of this vdev type */
|
||||
B_FALSE /* not a leaf vdev */
|
||||
};
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -89,6 +89,7 @@ vdev_ops_t vdev_missing_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
VDEV_TYPE_MISSING, /* name of this vdev type */
|
||||
B_TRUE /* leaf vdev */
|
||||
};
|
||||
@ -103,6 +104,7 @@ vdev_ops_t vdev_hole_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
VDEV_TYPE_HOLE, /* name of this vdev type */
|
||||
B_TRUE /* leaf vdev */
|
||||
};
|
||||
|
@ -150,6 +150,8 @@ uint32_t zfs_vdev_scrub_min_active = 1;
|
||||
uint32_t zfs_vdev_scrub_max_active = 2;
|
||||
uint32_t zfs_vdev_removal_min_active = 1;
|
||||
uint32_t zfs_vdev_removal_max_active = 2;
|
||||
uint32_t zfs_vdev_initializing_min_active = 1;
|
||||
uint32_t zfs_vdev_initializing_max_active = 1;
|
||||
|
||||
/*
|
||||
* When the pool has less than zfs_vdev_async_write_active_min_dirty_percent
|
||||
@ -407,6 +409,8 @@ vdev_queue_class_min_active(zio_priority_t p)
|
||||
return (zfs_vdev_scrub_min_active);
|
||||
case ZIO_PRIORITY_REMOVAL:
|
||||
return (zfs_vdev_removal_min_active);
|
||||
case ZIO_PRIORITY_INITIALIZING:
|
||||
return (zfs_vdev_initializing_min_active);
|
||||
default:
|
||||
panic("invalid priority %u", p);
|
||||
return (0);
|
||||
@ -468,6 +472,8 @@ vdev_queue_class_max_active(spa_t *spa, zio_priority_t p)
|
||||
return (zfs_vdev_scrub_max_active);
|
||||
case ZIO_PRIORITY_REMOVAL:
|
||||
return (zfs_vdev_removal_max_active);
|
||||
case ZIO_PRIORITY_INITIALIZING:
|
||||
return (zfs_vdev_initializing_max_active);
|
||||
default:
|
||||
panic("invalid priority %u", p);
|
||||
return (0);
|
||||
@ -688,8 +694,8 @@ vdev_queue_io_to_issue(vdev_queue_t *vq)
|
||||
}
|
||||
|
||||
/*
|
||||
* For LBA-ordered queues (async / scrub), issue the i/o which follows
|
||||
* the most recently issued i/o in LBA (offset) order.
|
||||
* For LBA-ordered queues (async / scrub / initializing), issue the
|
||||
* i/o which follows the most recently issued i/o in LBA (offset) order.
|
||||
*
|
||||
* For FIFO queues (sync), issue the i/o with the lowest timestamp.
|
||||
*/
|
||||
@ -745,13 +751,15 @@ vdev_queue_io(zio_t *zio)
|
||||
if (zio->io_priority != ZIO_PRIORITY_SYNC_READ &&
|
||||
zio->io_priority != ZIO_PRIORITY_ASYNC_READ &&
|
||||
zio->io_priority != ZIO_PRIORITY_SCRUB &&
|
||||
zio->io_priority != ZIO_PRIORITY_REMOVAL)
|
||||
zio->io_priority != ZIO_PRIORITY_REMOVAL &&
|
||||
zio->io_priority != ZIO_PRIORITY_INITIALIZING)
|
||||
zio->io_priority = ZIO_PRIORITY_ASYNC_READ;
|
||||
} else {
|
||||
ASSERT(zio->io_type == ZIO_TYPE_WRITE);
|
||||
if (zio->io_priority != ZIO_PRIORITY_SYNC_WRITE &&
|
||||
zio->io_priority != ZIO_PRIORITY_ASYNC_WRITE &&
|
||||
zio->io_priority != ZIO_PRIORITY_REMOVAL)
|
||||
zio->io_priority != ZIO_PRIORITY_REMOVAL &&
|
||||
zio->io_priority != ZIO_PRIORITY_INITIALIZING)
|
||||
zio->io_priority = ZIO_PRIORITY_ASYNC_WRITE;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,10 @@
|
||||
#include <sys/fs/zfs.h>
|
||||
#include <sys/fm/fs/zfs.h>
|
||||
|
||||
#ifdef ZFS_DEBUG
|
||||
#include <sys/vdev_initialize.h> /* vdev_xlate testing */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Virtual device vector for RAID-Z.
|
||||
*
|
||||
@ -1884,6 +1888,39 @@ vdev_raidz_child_done(zio_t *zio)
|
||||
rc->rc_skipped = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
vdev_raidz_io_verify(zio_t *zio, raidz_map_t *rm, int col)
|
||||
{
|
||||
#ifdef ZFS_DEBUG
|
||||
vdev_t *vd = zio->io_vd;
|
||||
vdev_t *tvd = vd->vdev_top;
|
||||
|
||||
range_seg_t logical_rs, physical_rs;
|
||||
logical_rs.rs_start = zio->io_offset;
|
||||
logical_rs.rs_end = logical_rs.rs_start +
|
||||
vdev_raidz_asize(zio->io_vd, zio->io_size);
|
||||
|
||||
raidz_col_t *rc = &rm->rm_col[col];
|
||||
vdev_t *cvd = vd->vdev_child[rc->rc_devidx];
|
||||
|
||||
vdev_xlate(cvd, &logical_rs, &physical_rs);
|
||||
ASSERT3U(rc->rc_offset, ==, physical_rs.rs_start);
|
||||
ASSERT3U(rc->rc_offset, <, physical_rs.rs_end);
|
||||
/*
|
||||
* It would be nice to assert that rs_end is equal
|
||||
* to rc_offset + rc_size but there might be an
|
||||
* optional I/O at the end that is not accounted in
|
||||
* rc_size.
|
||||
*/
|
||||
if (physical_rs.rs_end > rc->rc_offset + rc->rc_size) {
|
||||
ASSERT3U(physical_rs.rs_end, ==, rc->rc_offset +
|
||||
rc->rc_size + (1 << tvd->vdev_ashift));
|
||||
} else {
|
||||
ASSERT3U(physical_rs.rs_end, ==, rc->rc_offset + rc->rc_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Start an IO operation on a RAIDZ VDev
|
||||
*
|
||||
@ -1926,6 +1963,12 @@ vdev_raidz_io_start(zio_t *zio)
|
||||
for (c = 0; c < rm->rm_cols; c++) {
|
||||
rc = &rm->rm_col[c];
|
||||
cvd = vd->vdev_child[rc->rc_devidx];
|
||||
|
||||
/*
|
||||
* Verify physical to logical translation.
|
||||
*/
|
||||
vdev_raidz_io_verify(zio, rm, c);
|
||||
|
||||
zio_nowait(zio_vdev_child_io(zio, NULL, cvd,
|
||||
rc->rc_offset, rc->rc_abd, rc->rc_size,
|
||||
zio->io_type, zio->io_priority, 0,
|
||||
@ -2555,6 +2598,37 @@ vdev_raidz_state_change(vdev_t *vd, int faulted, int degraded)
|
||||
vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
vdev_raidz_xlate(vdev_t *cvd, const range_seg_t *in, range_seg_t *res)
|
||||
{
|
||||
vdev_t *raidvd = cvd->vdev_parent;
|
||||
ASSERT(raidvd->vdev_ops == &vdev_raidz_ops);
|
||||
|
||||
uint64_t width = raidvd->vdev_children;
|
||||
uint64_t tgt_col = cvd->vdev_id;
|
||||
uint64_t ashift = raidvd->vdev_top->vdev_ashift;
|
||||
|
||||
/* make sure the offsets are block-aligned */
|
||||
ASSERT0(in->rs_start % (1 << ashift));
|
||||
ASSERT0(in->rs_end % (1 << ashift));
|
||||
uint64_t b_start = in->rs_start >> ashift;
|
||||
uint64_t b_end = in->rs_end >> ashift;
|
||||
|
||||
uint64_t start_row = 0;
|
||||
if (b_start > tgt_col) /* avoid underflow */
|
||||
start_row = ((b_start - tgt_col - 1) / width) + 1;
|
||||
|
||||
uint64_t end_row = 0;
|
||||
if (b_end > tgt_col)
|
||||
end_row = ((b_end - tgt_col - 1) / width) + 1;
|
||||
|
||||
res->rs_start = start_row << ashift;
|
||||
res->rs_end = end_row << ashift;
|
||||
|
||||
ASSERT3U(res->rs_start, <=, in->rs_start);
|
||||
ASSERT3U(res->rs_end - res->rs_start, <=, in->rs_end - in->rs_start);
|
||||
}
|
||||
|
||||
vdev_ops_t vdev_raidz_ops = {
|
||||
vdev_raidz_open,
|
||||
vdev_raidz_close,
|
||||
@ -2565,6 +2639,7 @@ vdev_ops_t vdev_raidz_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
vdev_raidz_xlate,
|
||||
VDEV_TYPE_RAIDZ, /* name of this vdev type */
|
||||
B_FALSE /* not a leaf vdev */
|
||||
};
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <sys/vdev_indirect_births.h>
|
||||
#include <sys/vdev_indirect_mapping.h>
|
||||
#include <sys/abd.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
|
||||
/*
|
||||
* This file contains the necessary logic to remove vdevs from a
|
||||
@ -1021,6 +1022,7 @@ vdev_remove_complete(spa_t *spa)
|
||||
txg_wait_synced(spa->spa_dsl_pool, 0);
|
||||
txg = spa_vdev_enter(spa);
|
||||
vdev_t *vd = vdev_lookup_top(spa, spa->spa_vdev_removal->svr_vdev_id);
|
||||
ASSERT3P(vd->vdev_initialize_thread, ==, NULL);
|
||||
|
||||
sysevent_t *ev = spa_event_create(spa, vd, NULL,
|
||||
ESC_ZFS_VDEV_REMOVE_DEV);
|
||||
@ -1659,6 +1661,9 @@ spa_vdev_remove_log(vdev_t *vd, uint64_t *txg)
|
||||
/* Make sure these changes are sync'ed */
|
||||
spa_vdev_config_exit(spa, NULL, *txg, 0, FTAG);
|
||||
|
||||
/* Stop initializing */
|
||||
(void) vdev_initialize_stop_all(vd, VDEV_INITIALIZE_CANCELED);
|
||||
|
||||
*txg = spa_vdev_config_enter(spa);
|
||||
|
||||
sysevent_t *ev = spa_event_create(spa, vd, NULL,
|
||||
@ -1819,6 +1824,13 @@ spa_vdev_remove_top(vdev_t *vd, uint64_t *txg)
|
||||
*/
|
||||
error = spa_reset_logs(spa);
|
||||
|
||||
/*
|
||||
* We stop any initializing that is currently in progress but leave
|
||||
* the state as "active". This will allow the initializing to resume
|
||||
* if the removal is canceled sometime later.
|
||||
*/
|
||||
vdev_initialize_stop_all(vd, VDEV_INITIALIZE_ACTIVE);
|
||||
|
||||
*txg = spa_vdev_config_enter(spa);
|
||||
|
||||
/*
|
||||
@ -1830,6 +1842,7 @@ spa_vdev_remove_top(vdev_t *vd, uint64_t *txg)
|
||||
|
||||
if (error != 0) {
|
||||
metaslab_group_activate(mg);
|
||||
spa_async_request(spa, SPA_ASYNC_INITIALIZE_RESTART);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/zfs_context.h>
|
||||
@ -149,6 +149,7 @@ vdev_ops_t vdev_root_ops = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
VDEV_TYPE_ROOT, /* name of this vdev type */
|
||||
B_FALSE /* not a leaf vdev */
|
||||
};
|
||||
|
@ -189,6 +189,8 @@
|
||||
#include <sys/zcp.h>
|
||||
#include <sys/zio_checksum.h>
|
||||
#include <sys/vdev_removal.h>
|
||||
#include <sys/vdev_impl.h>
|
||||
#include <sys/vdev_initialize.h>
|
||||
|
||||
#include "zfs_namecheck.h"
|
||||
#include "zfs_prop.h"
|
||||
@ -3706,6 +3708,80 @@ zfs_ioc_destroy(zfs_cmd_t *zc)
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*
|
||||
* innvl: {
|
||||
* vdevs: {
|
||||
* guid 1, guid 2, ...
|
||||
* },
|
||||
* func: POOL_INITIALIZE_{CANCEL|DO|SUSPEND}
|
||||
* }
|
||||
*
|
||||
* outnvl: {
|
||||
* [func: EINVAL (if provided command type didn't make sense)],
|
||||
* [vdevs: {
|
||||
* guid1: errno, (see function body for possible errnos)
|
||||
* ...
|
||||
* }]
|
||||
* }
|
||||
*
|
||||
*/
|
||||
static int
|
||||
zfs_ioc_pool_initialize(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
{
|
||||
spa_t *spa;
|
||||
int error;
|
||||
|
||||
error = spa_open(poolname, &spa, FTAG);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
uint64_t cmd_type;
|
||||
if (nvlist_lookup_uint64(innvl, ZPOOL_INITIALIZE_COMMAND,
|
||||
&cmd_type) != 0) {
|
||||
spa_close(spa, FTAG);
|
||||
return (SET_ERROR(EINVAL));
|
||||
}
|
||||
if (!(cmd_type == POOL_INITIALIZE_CANCEL ||
|
||||
cmd_type == POOL_INITIALIZE_DO ||
|
||||
cmd_type == POOL_INITIALIZE_SUSPEND)) {
|
||||
spa_close(spa, FTAG);
|
||||
return (SET_ERROR(EINVAL));
|
||||
}
|
||||
|
||||
nvlist_t *vdev_guids;
|
||||
if (nvlist_lookup_nvlist(innvl, ZPOOL_INITIALIZE_VDEVS,
|
||||
&vdev_guids) != 0) {
|
||||
spa_close(spa, FTAG);
|
||||
return (SET_ERROR(EINVAL));
|
||||
}
|
||||
|
||||
nvlist_t *vdev_errlist = fnvlist_alloc();
|
||||
int total_errors = 0;
|
||||
|
||||
for (nvpair_t *pair = nvlist_next_nvpair(vdev_guids, NULL);
|
||||
pair != NULL; pair = nvlist_next_nvpair(vdev_guids, pair)) {
|
||||
uint64_t vdev_guid = fnvpair_value_uint64(pair);
|
||||
|
||||
error = spa_vdev_initialize(spa, vdev_guid, cmd_type);
|
||||
if (error != 0) {
|
||||
char guid_as_str[MAXNAMELEN];
|
||||
|
||||
(void) snprintf(guid_as_str, sizeof (guid_as_str),
|
||||
"%llu", (unsigned long long)vdev_guid);
|
||||
fnvlist_add_int64(vdev_errlist, guid_as_str, error);
|
||||
total_errors++;
|
||||
}
|
||||
}
|
||||
if (fnvlist_size(vdev_errlist) > 0) {
|
||||
fnvlist_add_nvlist(outnvl, ZPOOL_INITIALIZE_VDEVS,
|
||||
vdev_errlist);
|
||||
}
|
||||
fnvlist_free(vdev_errlist);
|
||||
|
||||
spa_close(spa, FTAG);
|
||||
return (total_errors > 0 ? EINVAL : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* fsname is name of dataset to rollback (to most recent snapshot)
|
||||
*
|
||||
@ -5869,6 +5945,10 @@ zfs_ioctl_init(void)
|
||||
zfs_secpolicy_config, POOL_NAME,
|
||||
POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
|
||||
|
||||
zfs_ioctl_register("initialize", ZFS_IOC_POOL_INITIALIZE,
|
||||
zfs_ioc_pool_initialize, zfs_secpolicy_config, POOL_NAME,
|
||||
POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
|
||||
|
||||
/* IOCTLS that use the legacy function signature */
|
||||
|
||||
zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
|
||||
|
@ -626,6 +626,13 @@ typedef struct zpool_load_policy {
|
||||
#define VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
|
||||
"com.delphix:pool_checkpoint_sm"
|
||||
|
||||
#define VDEV_LEAF_ZAP_INITIALIZE_LAST_OFFSET \
|
||||
"com.delphix:next_offset_to_initialize"
|
||||
#define VDEV_LEAF_ZAP_INITIALIZE_STATE \
|
||||
"com.delphix:vdev_initialize_state"
|
||||
#define VDEV_LEAF_ZAP_INITIALIZE_ACTION_TIME \
|
||||
"com.delphix:vdev_initialize_action_time"
|
||||
|
||||
/*
|
||||
* This is needed in userland to report the minimum necessary device size.
|
||||
*
|
||||
@ -723,6 +730,15 @@ typedef enum pool_scrub_cmd {
|
||||
POOL_SCRUB_FLAGS_END
|
||||
} pool_scrub_cmd_t;
|
||||
|
||||
/*
|
||||
* Initialize functions.
|
||||
*/
|
||||
typedef enum pool_initialize_func {
|
||||
POOL_INITIALIZE_DO,
|
||||
POOL_INITIALIZE_CANCEL,
|
||||
POOL_INITIALIZE_SUSPEND,
|
||||
POOL_INITIALIZE_FUNCS
|
||||
} pool_initialize_func_t;
|
||||
|
||||
/*
|
||||
* ZIO types. Needed to interpret vdev statistics below.
|
||||
@ -796,6 +812,14 @@ typedef struct pool_checkpoint_stat {
|
||||
uint64_t pcs_space; /* checkpointed space */
|
||||
} pool_checkpoint_stat_t;
|
||||
|
||||
typedef enum {
|
||||
VDEV_INITIALIZE_NONE,
|
||||
VDEV_INITIALIZE_ACTIVE,
|
||||
VDEV_INITIALIZE_CANCELED,
|
||||
VDEV_INITIALIZE_SUSPENDED,
|
||||
VDEV_INITIALIZE_COMPLETE
|
||||
} vdev_initializing_state_t;
|
||||
|
||||
/*
|
||||
* Vdev statistics. Note: all fields should be 64-bit because this
|
||||
* is passed between kernel and userland as an nvlist uint64 array.
|
||||
@ -814,10 +838,15 @@ typedef struct vdev_stat {
|
||||
uint64_t vs_read_errors; /* read errors */
|
||||
uint64_t vs_write_errors; /* write errors */
|
||||
uint64_t vs_checksum_errors; /* checksum errors */
|
||||
uint64_t vs_initialize_errors; /* initializing errors */
|
||||
uint64_t vs_self_healed; /* self-healed bytes */
|
||||
uint64_t vs_scan_removing; /* removing? */
|
||||
uint64_t vs_scan_processed; /* scan processed bytes */
|
||||
uint64_t vs_fragmentation; /* device fragmentation */
|
||||
uint64_t vs_initialize_bytes_done; /* bytes initialized */
|
||||
uint64_t vs_initialize_bytes_est; /* total bytes to initialize */
|
||||
uint64_t vs_initialize_state; /* vdev_initialzing_state_t */
|
||||
uint64_t vs_initialize_action_time; /* time_t */
|
||||
uint64_t vs_checkpoint_space; /* checkpoint-consumed space */
|
||||
} vdev_stat_t;
|
||||
|
||||
@ -945,6 +974,7 @@ typedef enum zfs_ioc {
|
||||
ZFS_IOC_REMAP,
|
||||
ZFS_IOC_POOL_CHECKPOINT,
|
||||
ZFS_IOC_POOL_DISCARD_CHECKPOINT,
|
||||
ZFS_IOC_POOL_INITIALIZE,
|
||||
ZFS_IOC_LAST
|
||||
} zfs_ioc_t;
|
||||
|
||||
@ -1007,6 +1037,12 @@ typedef enum {
|
||||
#define ZPOOL_HIST_DSID "dsid"
|
||||
#define ZPOOL_HIST_ERRNO "errno"
|
||||
|
||||
/*
|
||||
* The following are names used when invoking ZFS_IOC_POOL_INITIALIZE.
|
||||
*/
|
||||
#define ZPOOL_INITIALIZE_COMMAND "initialize_command"
|
||||
#define ZPOOL_INITIALIZE_VDEVS "initialize_vdevs"
|
||||
|
||||
/*
|
||||
* Flags for ZFS_IOC_VDEV_SET_STATE
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user