spa.c revision 215198a6ad15cf4832370e2f19247abeb36b951a
* If the pool version is less than SPA_VERSION_BOOTFS, * or the pool is still being created (version == 0), * the bootfs property cannot be set. * Make sure the vdev config is bootable * Must be ZPL, and its property settings * must be supported by GRUB (compression * is not gzip, and large blocks are not used). * This is a special case which only occurs when * the pool has completely failed. This allows * the user to change the in-core failmode property * without syncing it out to disk (I/Os might * currently be blocked). We do this by returning * EIO to the caller (spa_prop_set) to trick it * into thinking we encountered a property validation * The kernel doesn't have an easy isprint() * check. For this kernel check, we merely * check ASCII apart from DEL. Fix this if * there is an easy-to-use kernel isprint(). /* Save time if the version is already set. */ * In addition to the pool directory object, we might * create the pool properties object, the features for * read object, the features for write object, or the * feature descriptions object. * If the bootfs property value is dsobj, clear it. * Change the GUID for the pool. This is done so that we can later * re-import a pool built from a clone of our own vdevs. We will modify * the root vdev's guid, our own pool guid, and then mark all of our * vdevs dirty. Note that we must make sure that all our vdevs are * online when we do this, or else any vdevs that weren't present * would be orphaned from our pool. We are also going to issue a * sysevent to update any watchers. * ========================================================================== * ========================================================================== * Utility function which retrieves copies of the current logs and * re-initializes them in the process. panic(
"unrecognized mode for %s_%s taskq (%u:%u) in " * The write issue taskq can be extremely CPU * intensive. Run it at slightly lower priority * Dispatch a task to the appropriate taskq for the ZFS I/O type and priority. * Note that a type may have multiple discrete taskqs to avoid lock contention * on the taskq itself. In that case we choose which taskq at random by using * the low bits of gethrtime(). /* bind this thread to the requested psrset */ "Couldn't bind process for zfs pool \"%s\" to " * Activate an uninitialized pool. /* Try to create a covering process */ /* Only create a process if we're going to be around a while. */ "Couldn't create process for zfs pool \"%s\"\n",
/* If we didn't create a process, we need to create our taskqs. */ * Opposite of spa_activate(). * If this was part of an import or the open otherwise failed, we may * still have errors left in the queues. Empty them just in case. * We want to make sure spa_thread() has actually exited the ZFS * module, so that the module can't be unloaded out from underneath * Verify a pool configuration, and construct the vdev tree appropriately. This * will create all the necessary vdevs in the appropriate layout, with each vdev * All vdev validation is done by the vdev_alloc() routine. * Opposite of spa_load(). * Wait for any outstanding async I/O to complete. * Drop and purge level 2 cache * Load (or re-load) the current list of vdevs describing the active spares for * this pool. When this is called, we have some form of basic information in * 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and * then re-generate a more complete list including status information. * First, close and free any existing spare vdevs. /* Undo the call to spa_activate() below */ * Construct the array of vdevs, opening them to get status in the * process. For each spare, there is potentially two different vdev_t * structures associated with it: one in the list of spares (used only * for basic validation purposes) and one in the active vdev * configuration (if it's spared in). During this phase we open and * validate each vdev on the spare list. If the vdev also exists in the * active configuration, then we also mark this vdev as an active spare. * We only mark the spare active if we were successfully * able to load the vdev. Otherwise, importing a pool * with a bad active spare would result in strange * behavior, because multiple pool would think the spare * There is a vulnerability here to an equally bizarre * circumstance, where a dead active spare is later * brought back to life (onlined or otherwise). Given * the rarity of this scenario, and the extra complexity * it adds, we ignore the possibility. * Recompute the stashed list of spares, with status information * Load (or re-load) the current list of vdevs describing the active l2cache for * this pool. When this is called, we have some form of basic information in * 'spa_l2cache.sav_config'. We parse this into vdevs, try to open them, and * then re-generate a more complete list including status information. * Devices which are already active have their details maintained, and are * Process new nvlist of vdevs. * Commit this vdev as an l2cache device, * even if it fails to open. * Purge vdevs that were dropped * Recompute the stashed list of l2cache devices, with status * Checks to see if the given vdev could not be opened, in which case we post a * sysevent to notify the autoreplace code that the device has been removed. * Validate the current config against the MOS config * If we're doing a normal import, then build up any additional * diagnostic information about missing devices in this config. * We'll pass this up to the user for further processing. for (
int i = 0; i <
idx; i++)
* Compare the root vdev tree with the information we have * from the MOS config (mrvd). Check each top-level vdev * with the corresponding MOS config top-level (mtvd). * Resolve any "missing" vdevs in the current configuration. * If we find that the MOS config has more accurate information * about the top-level vdev then use that vdev instead. * Device specific actions. * XXX - once we have 'readonly' pool * support we should be able to handle * missing data devices by transitioning * Swap the missing vdev with the data we were * able to obtain from the MOS config. * Load the slog device's state from the MOS * config since it's possible that the label * does not contain the most up-to-date * Per-vdev ZAP info is stored exclusively in the MOS. * Ensure we were able to validate the config. * Check for missing log devices /* need to recheck in case slog has been restored */ * We successfully offlined the log device, sync out the * current txg so that the "stubby" block can be removed * Maximum number of concurrent scrub i/os to create while verifying * a pool while importing it. * Note: normally this routine will not be called if * spa_load_verify_metadata is not set. However, it may be useful * to manually set the flag after the traversal has begun. * Find a value in the pool props object. * Find a value in the pool directory object. * Fix up config after a partly-completed split. This is done with the * ZPOOL_CONFIG_SPLIT nvlist. Both the splitting pool and the split-off * pool have that entry in their config, but only the splitting one contains * a list of all the guids of the vdevs that are being split off. * This function determines what to do with that list: either rejoin * all the disks to the pool, or complete the splitting process. To attempt * the rejoin, each disk that is offlined is marked online again, and * we do a reopen() call. If the vdev label for every disk that was * marked online indicates it was successfully split off (VDEV_AUX_SPLIT_POOL) * then we call vdev_split() on each disk, and complete the split. * Otherwise we leave the config alone, with all the vdevs in place in /* check that the config is complete */ /* attempt to online all the vdevs & validate */ for (i = 0; i <
gcount; i++) {
if (
glist[i] == 0)
/* vdev is hole */ * Don't bother attempting to reopen the disks; /* attempt to re-online it */ /* check each device to see what state it's in */ * If every disk has been moved to the new pool, or if we never * even attempted to look at them, then we split them off for * Versioning wasn't explicitly added to the label until later, so if * it's not present treat it as the initial version. * Don't count references from objsets that are already closed * and are making their way through the eviction process. * Count the number of per-vdev ZAPs associated with all of the vdevs in the * vdev tree rooted in the given vd, and ensure that each ZAP is present in the * spa's per-vdev ZAP list. * Load an existing storage pool, using the pool's builtin spa_config as a * source of configuration information. * If this is an untrusted config, access the pool in read-only mode. * This prevents things like resilvering recently removed devices. * Create "The Godfather" zio to hold all async IOs * Parse the configuration into a vdev tree. We explicitly set the * value that will be returned by spa_version() since parsing the * configuration requires knowing the version number. * Try to open all vdevs, loading each label in the process. * We need to validate the vdev labels against the configuration that * we have in hand, which is dependent on the setting of mosconfig. If * mosconfig is true then we're validating the vdev labels based on * that config. Otherwise, we're validating against the cached config * (zpool.cache) that was read when we loaded the zfs module, and then * later we will recursively call spa_load() and validate against * If we're assembling a new pool that's been split off from an * existing pool, the labels haven't yet been updated so we skip * Find the best uberblock. * If we weren't able to find a single valid uberblock, return failure. * If the pool has an unsupported version we can't open it. * If we weren't able to find what's necessary for reading the * MOS in the label, return failure. * Update our in-core representation with the definitive values * Look through entries in the label nvlist's features_for_read. If * there is a feature listed there which we don't understand then we * If the vdev guid sum doesn't match the uberblock, we have an * incomplete configuration. We first check to see if the pool * is aware of the complete config (i.e ZPOOL_CONFIG_VDEV_CHILDREN). * If it is, defer the vdev_guid_sum check till later so we * can handle missing vdevs. * Initialize internal SPA structures. * If the state is SPA_LOAD_TRYIMPORT, our objective is * twofold: to determine whether the pool is available for * import in read-write mode and (if it is not) whether the * pool is available for import in read-only mode. If the pool * is available for import in read-write mode, it is displayed * as available in userland; if it is not available for import * in read-only mode, it is displayed as unavailable in * userland. If the pool is available for import in read-only * mode but not read-write mode, it is displayed as unavailable * in userland with a special note that the pool is actually * available for open in read-only mode. * As a result, if the state is SPA_LOAD_TRYIMPORT and we are * missing a feature for write, we must first determine whether * the pool can be opened read-only before returning to * userland in order to know whether to display the * Load refcounts for ZFS features from disk into an in-memory * cache during SPA initialization. * We're emulating the system's hostid in userland, so * we can't use zone_get_hostid(). "loaded as it was last accessed by " "another system (host: %s hostid: 0x%lx). " /* Grab the secret checksum salt from the MOS. */ /* Generate a new salt for subsequent use */ * Load the bit that tells us to use the new accounting function * (raid-z deflation). If we have an older pool, this will not * Load the persistent error log. If we have an older pool, this will * Load the history object. If we have an older pool, this * Load the per-vdev ZAP map. If we have an older pool, this will not * be present; in this case, defer its creation to a later time to * avoid dirtying the MOS this early / out of sync context. See * spa_sync_config_object. /* The sentinel is only available in the MOS config. */ * An older version of ZFS overwrote the sentinel value, so * we have orphaned per-vdev ZAPs in the MOS. Defer their * destruction to later; see spa_sync_config_object. * We're assuming that no vdevs have had their ZAPs created * before this. Better be sure of it. * If we're assembling the pool from the split-off vdevs of * an existing pool, we don't want to attach the spares & cache * Load any hot spares for this pool. * Load any level 2 ARC devices for this pool. * If the 'autoreplace' property is set, then post a resource notifying * the ZFS DE that it should not issue any faults for unopenable * devices. We also iterate over the vdevs, and post a sysevent for any * unopenable vdevs so that the normal autoreplace handler can take * For the import case, this is done in spa_import(), because * at this point we're using the spare definitions from * the MOS config, not necessarily from the userland config. * Load the vdev state for all toplevel vdevs. * Propagate the leaf DTLs we just loaded all the way up the tree. * Load the DDTs (dedup tables). * Validate the config, using the MOS config to fill in any * information which might be missing. If we fail to validate * the config then declare the pool unfit for use. If we're * assembling a pool from a split, the log is not transferred * Now that we've validated the config, check the state of the * root vdev. If it can't be opened, it indicates one or * more toplevel vdevs are faulted. * At this point, we know that we can open the pool in * read-only mode but not read-write mode. We now have enough * information and can return to userland. * We've successfully opened the pool, verify that we're ready * to start pushing transactions. * Claim log blocks that haven't been committed yet. * This must all happen in a single txg. * Note: spa_claim_max_txg is updated by spa_claim_notify(), * invoked from zil_claim_log_block()'s i/o done callback. * Price of rollback is that we abandon the log. * Wait for all claims to sync. We sync up to the highest * claimed log block birth time so that claimed log blocks * don't appear to be from the future. spa_claim_max_txg * will have been set for us by either zil_check_log_chain() * (invoked from spa_check_logs()) or zil_claim() above. * If the config cache is stale, or we have uninitialized * metaslabs (see spa_vdev_add()), then update the config. * If this is a verbatim import, trust the current * in-core spa_config and update the disk labels. * Update the config cache asychronously in case we're the * root pool, in which case the config cache isn't writable yet. * Check all DTLs to see if anything needs resilvering. * Log the fact that we booted up (so that we can detect if * we rebooted in the middle of an operation). * Delete any inconsistent datasets. * Clean up any stale temporary dataset userrefs. * If spa_load() fails this function will try loading prior txg's. If * 'state' is SPA_LOAD_RECOVER and one of these loads succeeds the pool * will be rewound to that txg. If 'state' is not SPA_LOAD_RECOVER this * function will not rewind the pool and will return the same error as /* Price of rolling back is discarding txgs, including log */ * If we aren't rolling back save the load info from our first * import attempt so that we can restore it after attempting * Continue as long as we're finding errors, we're still within * the acceptable rewind range, and we're still finding uberblocks /* Store the rewind info as part of the initial load info */ /* Restore the initial load info */ * The import case is identical to an open except that the configuration is sent * down from userland, instead of grabbed from the configuration cache. For the * case of an open, the pool configuration will exist in the * POOL_STATE_UNINITIALIZED state. * The stats information (gen/count/ustats) is used to gather vdev statistics at * the same time open the pool, without having to keep around the spa_t in some * As disgusting as this is, we need to support recursive calls to this * function because dsl_dir_open() is called during spa_load(), and ends * up calling spa_open() again. The real fix is to figure out how to * avoid dsl_dir_open() calling this in the first place. * If vdev_validate() returns failure (indicated by * EBADF), it indicates that one of the vdevs indicates * that the pool has been exported or destroyed. If * this is the case, the config cache is out of sync and * we should remove the pool from the namespace. * We can't open the pool, but we still have useful * information: the state of each vdev after the * attempted vdev_open(). Return this to the user. * If we've recovered the pool, pass back any information we * gathered while doing the load. * Lookup the given spa_t, incrementing the inject count in the process, * preventing it from being exported or destroyed. * Add spares device information to the nvlist. * Go through and find any spares which have since been * repurposed as an active spare. If this is the case, update * their status appropriately. * Add l2cache device information to the nvlist, including vdev stats. * Update level 2 cache device stats. * This still leaves a window of inconsistency where the spares * or l2cache devices could change and the config would be * We want to get the alternate root even for faulted pools, so we cheat * and call spa_lookup() directly. * Validate that the auxiliary device array is well formed. We must have an * array of nvlists, each which describes a valid leaf vdev. If this is an * import (mode is VDEV_ALLOC_SPARE), then we allow corrupted spares to be * specified, as long as they are well-formed. * It's acceptable to have no devs specified. * Make sure the pool is formatted with a version that supports this * Set the pending device list so we correctly handle device in-use for (i = 0; i <
ndev; i++) {
* The L2ARC currently only supports disk devices in * kernel context. For user-level testing, we allow it. * Generate new dev list by concatentating with the for (i = 0; i <
ndevs; i++)
* Generate a new dev list. * Stop and drop level 2 ARC devices * If this pool already exists, return failure. * Allocate a new spa_t structure. * Create "The Godfather" zio to hold all async IOs * Get the list of spares, if specified. * Get the list of level 2 cache devices, if specified. * Create DDTs (dedup tables). * Create the pool config object. /* Newly created pools with the right version are always deflated. */ * Create the deferred-free bpobj. Turn off compression * because sync-to-convergence takes longer if the blocksize * Create the pool's history object. * Generate some random noise for salted checksums to operate on. * We explicitly wait for the first transaction to complete so that our * bean counters are appropriately updated. * Don't count references from objsets that are already closed * and are making their way through the eviction process. * Get the root pool information from the root disk, then import the root pool * during the system boot up time. * Add this top-level vdev to the child array. * Put this pool's top-level vdevs into a root vdev. * Replace the existing vdev_tree with the new root vdev in * this pool's configuration (remove the old, add the new). * Walk the vdev tree and see if we can find a device with "better" * configuration. A configuration is "better" if the label on that * device has a more recent txg. * Do we have a better boot device? * For x86. devpath_list will consist of devid and/or physpath name of * the vdev (e.g. "id1,sd@SSEAGATE..." or "/pci@1f,0/ide@d/disk@0,0:a"). * The GRUB "findroot" command will return the vdev we should boot. * For Sparc, devpath_list consists the physpath name of the booting device * no matter the rootpool is a single device pool or a mirrored pool. * "/pci@1f,0/ide@d/disk@0,0:a" * Read the label from the boot device and generate a configuration. * Remove the existing root pool from the namespace so that we * can replace it with the correct config we just read in. * Build up a vdev tree based on the boot device's label config. * Determine if there is a better boot device. * If the boot device is part of a spare vdev then ensure that * we're booting off the active spare. * Import a non-root pool into the system. * If a pool with this name exists, return failure. * Create and initialize the spa structure. * Verbatim import - Take a pool and insert it into the namespace * as if it had been loaded at boot. * Don't start async tasks until we know everything is healthy. * Pass off the heavy lifting to spa_load(). Pass TRUE for mosconfig * because the user-supplied config is actually the one to trust when * Propagate anything learned while loading the pool and pass it * back to caller (i.e. rewind info, missing devices, etc). * Toss any existing sparelist, as it doesn't have any validity * anymore, and conflicts with spa_has_spare(). * Override any spares and level 2 cache devices as specified by * the user, as these may have correct device names/devids, etc. * Check for any removed devices. * Update the config cache to include the newly-imported pool. * It's possible that the pool was expanded while it was exported. * We kick off an async task to handle this for us. * Create and initialize the spa structure. * Pass off the heavy lifting to spa_load(). * Pass TRUE for mosconfig because the user-supplied config * is actually the one to trust when doing an import. * If 'tryconfig' was at least parsable, return the current config. * If the bootfs property exists on this pool then we * copy it out so that external consumers can tell which * We have to play games with the name since the * pool was opened as TRYIMPORT_NAME. * Add the list of hot spares and level 2 cache devices. * The act of destroying or exporting a pool is very simple. We make sure there * is no more pending I/O and any references to the pool are gone. Then, we * update the pool state and sync all the labels to disk, removing the * configuration from the cache afterwards. If the 'hardforce' flag is set, then * we don't sync the labels or remove the configuration cache. * Put a hold on the pool, drop the namespace lock, stop async tasks, * reacquire the namespace lock, and see if we can export. * The pool will be in core if it's openable, * in which case we can modify its state. * Objsets may be open only because they're dirty, so we * have to force it to sync before checking spa_refcnt. * A pool cannot be exported or destroyed if there are active * references. If we are resetting a pool, allow references by * fault injection handlers. * A pool cannot be exported if it has an active shared spare. * This is to prevent other pools stealing the active spare * from an exported pool. At user's own will, such pool can * We want this to be reflected on every label, * so mark them all dirty. spa_unload() will do the * final sync that pushes these changes out. * Destroy a storage pool. * Similar to spa_export(), this unloads the spa_t without actually removing it * from the namespace in any way. * ========================================================================== * ========================================================================== * Add a device to a storage pool. * We must validate the spares and l2cache devices after checking the * children. Otherwise, vdev_inuse() will blindly overwrite the spare. * Transfer each new top-level vdev from vd to rvd. * Set the vdev id to the first hole, if one exists. * We have to be careful when adding new vdevs to an existing pool. * If other threads start allocating from these vdevs before we * sync the config cache, and we lose power, then upon reboot we may * fail to open the pool because there are DVAs that the config cache * can't translate. Therefore, we first add the vdevs without * initializing metaslabs; sync the config cache (via spa_vdev_exit()); * and then let spa_config_update() initialize the new metaslabs. * spa_load() checks for added-but-not-initialized vdevs, so that * if we lose power at any point in this sequence, the remaining * steps will be completed the next time we load the pool. * Attach a device to a mirror. The arguments are the path to any device * in the mirror, and the nvroot for the new device. If the path specifies * a device that is not mirrored, we automatically insert the mirror vdev. * If 'replacing' is specified, the new device is intended to replace the * existing device; in this case the two devices are made into their own * mirror using the 'replacing' vdev, which is functionally identical to * the mirror vdev (it actually reuses all the same ops) but has a few * extra rules: you can't attach to it after it's been created, and upon * completion of resilvering, the first disk (the one being replaced) * is automatically detached. * Spares can't replace logs * For attach, the only allowable parent is a mirror or the root * Active hot spares can only be replaced by inactive hot * If the source is a hot spare, and the parent isn't already a * spare, then we want to create a new hot spare. Otherwise, we * want to create a replacing vdev. The user is not allowed to * attach to a spared vdev child unless the 'isspare' state is * the same (spare replaces spare, non-spare replaces * Make sure the new device is big enough. * The new device cannot have a higher alignment requirement * than the top-level vdev. * If this is an in-place replacement, update oldvd's path and devid * to make it distinguishable from newvd, and unopenable from now on. /* mark the device being resilvered */ * If the parent is not a mirror, or if we're replacing, insert the new * Extract the new device from its root and add it to pvd. * Set newvd's DTL to [TXG_INITIAL, dtl_max_txg) so that we account * for any dmu_sync-ed blocks. It will propagate upward when * spa_vdev_exit() calls vdev_dtl_reassess(). * Mark newvd's DTL dirty in this txg. * Schedule the resilver to restart in the future. We do this to * ensure that dmu_sync-ed blocks have been stitched into the * Detach a device from a mirror or replacing vdev. * If 'replace_done' is specified, only detach if the parent * If the parent/child relationship is not as expected, don't do it. * Consider M(A,R(B,C)) -- that is, a mirror of A with a replacing * vdev that's replacing B with C. The user's intent in replacing * is to go from M(A,B) to M(A,C). If the user decides to cancel * the replace by detaching C, the expected behavior is to end up * M(A,B). But suppose that right after deciding to detach C, * the replacement of B completes. We would have M(A,C), and then * ask to detach C, which would leave us with just A -- not what * the user wanted. To prevent this, we make sure that the * parent/child relationship hasn't changed -- in this example, * that C's parent is still the replacing vdev R. * Only 'replacing' or 'spare' vdevs can be replaced. * Only mirror, replacing, and spare vdevs support detach. * If this device has the only valid copy of some data, * we cannot safely detach it. * If we are detaching the second disk from a replacing vdev, then * check to see if we changed the original vdev's path to have "/old" * at the end in spa_vdev_attach(). If so, undo that change now. * If we are detaching the original disk from a spare, then it implies * that the spare should become a real disk, and be removed from the * active spare list for the pool. * Erase the disk labels so the disk can be used for other things. * This must be done after all other error cases are handled, * but before we disembowel vd (so we can still do I/O to it). * But if we can't do it, don't treat the error as fatal -- * it may be that the unwritability of the disk is the reason * Remove vd from its parent and compact the parent's children. * Remember one of the remaining children so we can get tvd below. * If we need to remove the remaining child from the list of hot spares, * do it now, marking the vdev as no longer a spare in the process. * We must do this before vdev_remove_parent(), because that can * change the GUID if it creates a new toplevel GUID. For a similar * reason, we must remove the spare now, in the same txg as the detach; * otherwise someone could attach a new sibling, change the GUID, and * the subsequent attempt to spa_vdev_remove(unspare_guid) would fail. * the parent is no longer needed. Remove it from the tree. * We don't set tvd until now because the parent we just removed * may have been the previous top-level vdev. * Reevaluate the parent vdev state. * If the 'autoexpand' property is set on the pool then automatically * try to expand the size of the pool. For example if the device we * just detached was smaller than the others, it may be possible to * add metaslabs (i.e. grow the pool). We need to reopen the vdev * first so that we can obtain the updated sizes of the leaf vdevs. * Mark vd's DTL as dirty in this txg. vdev_dtl_sync() will see that * vd->vdev_detached is set and free vd's DTL object in syncing context. * But first make sure we're not on any *other* txg's DTL list, to * prevent vd from being accessed after it's freed. /* hang on to the spa before we release the lock */ * If this was the removal of the original device in a hot spare vdev, * then we want to go through and remove the device from the hot spare * list of every other pool. /* search the rest of the vdevs for spares to remove */ /* all done with the spa; OK to release */ * Split a set of devices from their mirrors, and create a new pool from them. /* clear the log and flush everything up to now */ /* check new spa name before going any further */ * scan through all the children to ensure they're all mirrors /* first, check to ensure we've got the right child count */ /* don't count the holes & logs as children */ /* next, ensure no spare or cache devices are part of the split */ /* then, loop over each vdev and validate it */ /* which disk is going to be split? */ /* look it up in the spa */ /* make sure there's nothing stopping the split */ /* we need certain info from the top level */ /* transfer per-vdev ZAPs */ /* stop writers from using the disks */ * Temporarily record the splitting vdevs in the spa config. This * will disappear once the config is regenerated. /* configure and create the new pool */ /* add the new pool to the namespace */ /* release the spa config lock, retaining the namespace lock */ /* create the new pool from the disks of the original pool */ /* if that worked, generate a real config for the new pool */ /* finally, update the original pool's config */ /* split is complete; log a history record */ /* if we're not going to mount the filesystems in userland, export */ /* re-online all offlined disks */ for (
int i = 0; i <
count; i++) {
for (
int i = 0, j = 0; i <
count; i++) {
for (
int i = 0; i <
count -
1; i++)
* Evacuate the device. We don't hold the config lock as writer * since we need to do I/O but we do keep the * spa_namespace_lock held. Once this completes the device * should no longer have any blocks allocated on it. * The evacuation succeeded. Remove any remaining MOS metadata * associated with this vdev, and wait for these changes to sync. * Complete the removal by cleaning up the namespace. * Only remove any devices which are empty. * Reassess the health of our root vdev. * Remove a device from the pool - * Removing a device from the vdev namespace requires several steps * and can take a significant amount of time. As a result we use * the spa_vdev_config_[enter/exit] functions which allow us to * grab and release the spa_config_lock while still holding the namespace * lock. During each step the configuration is synced out. * Currently, this supports removing only hot spares, slogs, and level 2 ARC * Only remove the hot spare if it's not currently in use * Cache devices can always be removed. * Stop allocating from this vdev. * Wait for the youngest allocations and frees to sync, * and then wait for the deferral of those frees to finish. * Attempt to evacuate the vdev. * If we couldn't evacuate the vdev, unwind. * Clean up the vdev namespace. * Normal vdevs cannot be removed (yet). * There is no vdev of any kind with the specified guid. * Find any device that's done replacing, or a vdev marked 'unspare' that's * currently spared, so we can detach it. * Check for a completed replacement. We always consider the first * vdev in the list to be the oldest vdev, and the last one to be * the newest (see spa_vdev_attach() for how that works). In * the case where the newest vdev is faulted, we will not automatically * remove it after a resilver completes. This is OK as it will require * user intervention to determine which disk the admin wishes to keep. * Check for a completed resilver with the 'unspare' flag set. * If there are more than two spares attached to a disk, * and those spares are not required, then we want to * attempt to free them up now so that they can be used * by other pools. Once we're back down to a single * disk+spare, we stop removing them. * If we have just finished replacing a hot spared device, then * we need to detach the parent's first child (the original hot * Update the stored path or FRU for this vdev. * ========================================================================== * ========================================================================== * If a resilver was requested, but there is no DTL on a * writeable leaf device, we have nothing to do. * ========================================================================== * SPA async task processing * ========================================================================== * We want to clear the stats, but we don't want to do a full * vdev_clear() as that will cause us to throw away * device, all of which is a waste. * See if the config needs to be updated. * If the pool grew as a result of the config update, * then log an internal history event. "pool '%s' size: %llu(+%llu)",
* See if any devices need to be marked REMOVED. * See if any devices need to be probed. * If any devices are done replacing, detach them. * Let the world know that we're done. * ========================================================================== * ========================================================================== * Note: this simple function is not inlined to make it easier to dtrace the * amount of time spent syncing frees. * Note: this simple function is not inlined to make it easier to dtrace the * amount of time spent syncing deferred frees. * Write full (SPA_CONFIG_BLOCKSIZE) blocks of configuration * information. This avoids the dmu_buf_will_dirty() path and * saves us a pre-read to get data we don't actually care about. * Update the MOS nvlist describing the list of available devices. * spa_validate_aux() will have already made sure this nvlist is * valid and the vdevs are labeled appropriately. * Rebuild spa's all-vdev ZAP from the vdev ZAPs indicated in each vdev_t. * The all-vdev ZAP must be empty. * If the pool is being imported from a pre-per-vdev-ZAP version of ZFS, * its config may not be dirty but we still need to build per-vdev ZAPs. * Similarly, if the pool is being assembled (e.g. after a split), we * need to rebuild the AVZ although the config may not be dirty. /* Make and build the new AVZ */ /* Diff old AVZ with new one */ * ZAP is listed in old AVZ but not in new one; /* Destroy the old AVZ */ /* Replace the old AVZ in the dir obj with the new one */ /* Walk through the AVZ and destroy all listed ZAPs */ /* Destroy and unlink the AVZ itself */ /* Create ZAPs for vdevs that don't have them. */ * If we're upgrading the spa version then make sure that * the config object gets updated with the correct version. * Setting the version is special cased when first creating the pool. * We checked this earlier in spa_prop_validate(). * The version is synced seperatly before other * properties and should be correct by now. * 'altroot' is a non-persistent property. It should * have been set temporarily at creation or import time. * 'readonly' and 'cachefile' are also non-persisitent * We need to dirty the configuration on all the vdevs * so that their labels get updated. It's unnecessary * to do this for pool creation since the vdev's * configuratoin has already been dirtied. * Set pool property values in the poolprops mos object. /* normalize the property name */ * Perform one-time upgrade on-disk changes. spa_version() does not * reflect the new version this txg, so there must be no changes this * txg to anything that the upgrade code depends on after it executes. * Therefore this must be called after dsl_pool_sync() does the sync /* Keeping the origin open increases spa_minref */ /* Keeping the freedir open increases spa_minref */ * LZ4_COMPRESS feature's behaviour was changed to activate_on_enable * when possibility to use lz4 compression for metadata was added * Old pools that have this feature enabled must be upgraded to have * If we haven't written the salt, do so now. Note that the * feature may not be activated yet, but that's fine since * the presence of this ZAP entry is backwards compatible. * Sync the specified transaction group. New blocks may be dirtied as * part of the process, so we iterate until it converges. * Lock out configuration changes. * If there are any pending vdev state changes, convert them * into config changes that go out with this transaction group. * We need the write lock here because, for aux vdevs, * calling vdev_config_dirty() modifies sav_config. * This is ugly and will become unnecessary when we * eliminate the aux vdev wart by integrating all vdevs * into the root vdev tree. * If we are upgrading to SPA_VERSION_RAIDZ_DEFLATE this txg, * set spa_deflate if we have no raid-z vdevs. * Iterate to convergence. * We can not defer frees in pass 1, because * we sync the deferred frees later in pass 1. * Note: We need to check if the MOS is dirty * because we could have marked the MOS dirty * without updating the uberblock (e.g. if we * have sync tasks but no dirty user data). We * need to check the uberblock's rootbp because * it is updated if we have synced out dirty * data (though in this case the MOS will most * likely also be dirty due to second order * effects, we don't want to rely on that here). * Nothing changed on the first pass, * therefore this TXG is a no-op. Avoid * syncing deferred frees, so that we * can keep this TXG as a no-op. * Make sure that the number of ZAPs for all the vdevs matches * the number of ZAPs in the per-vdev ZAP list. This only gets * called if the config is dirty; otherwise there may be * outstanding AVZ operations that weren't completed in * spa_sync_config_object. * Rewrite the vdev configuration (which includes the uberblock) * to commit the transaction group. * If there are no dirty vdevs, we sync the uberblock to a few * random top-level vdevs that are known to be visible in the * config cache (see spa_vdev_add() for a complete description). * If there *are* dirty vdevs, sync the uberblock to all vdevs. * while we're attempting to write the vdev labels. * Clear the dirty config list. * Now that the new config has synced transactionally, * let it become visible to the config cache. * Update usable space statistics. * It had better be the case that we didn't dirty anything * since vdev_config_sync(). * If any async tasks have been requested, kick them off. * Sync all pools. We don't want to hold the namespace lock across these * operations, so we take a reference on the spa_t and drop the lock during the * ========================================================================== * ========================================================================== * Remove all pools in the system. * Remove all cached state. All pools should be closed now, * so every spa in the AVL tree should be unreferenced. * Stop async tasks. The async thread may need to detach * a device that's been replaced, which requires grabbing * spa_namespace_lock, so we must drop it here. * This should only be called for a non-faulted pool, and since a * future version would result in an unopenable pool, this shouldn't be * Check if a pool has an active shared spare device. * Note: reference count of an active spare is 2, as a spare and as a replace * Post a sysevent corresponding to the given event. The 'name' must be one of * filled in from the spa and (optionally) the vdev. This doesn't do anything * in the userland libzpool, as we don't want consumers to misinterpret ztest * or zdb as real changes.