X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=module%2Fzfs%2Fspa.c;h=d11f93dbe0b942a07f4c3a63e8ae4e53c9f8a737;hb=48c67dc8f8d822dbd2fec51d5e46cdb445f66814;hp=b6190e4cfafecf914627c191ef794831e2aba51d;hpb=572e285762521df27fe5b026f409ba1a21abb7ac;p=zfs.git diff --git a/module/zfs/spa.c b/module/zfs/spa.c index b6190e4..d11f93d 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -271,8 +271,8 @@ spa_prop_get(spa_t *spa, nvlist_t **nvp) dp = spa_get_dsl(spa); rw_enter(&dp->dp_config_rwlock, RW_READER); - if (err = dsl_dataset_hold_obj(dp, - za.za_first_integer, FTAG, &ds)) { + if ((err = dsl_dataset_hold_obj(dp, + za.za_first_integer, FTAG, &ds))) { rw_exit(&dp->dp_config_rwlock); break; } @@ -334,7 +334,7 @@ spa_prop_validate(spa_t *spa, nvlist_t *props) { nvpair_t *elem; int error = 0, reset_bootfs = 0; - uint64_t objnum; + uint64_t objnum = 0; elem = NULL; while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { @@ -398,7 +398,7 @@ spa_prop_validate(spa_t *spa, nvlist_t *props) break; } - if (error = dmu_objset_hold(strval, FTAG, &os)) + if ((error = dmu_objset_hold(strval,FTAG,&os))) break; /* Must be ZPL and not gzip compressed. */ @@ -471,6 +471,9 @@ spa_prop_validate(spa_t *spa, nvlist_t *props) intval != 0 && intval < ZIO_DEDUPDITTO_MIN) error = EINVAL; break; + + default: + break; } if (error) @@ -653,8 +656,10 @@ spa_taskq_create(spa_t *spa, const char *name, enum zti_modes mode, static void spa_create_zio_taskqs(spa_t *spa) { - for (int t = 0; t < ZIO_TYPES; t++) { - for (int q = 0; q < ZIO_TASKQ_TYPES; q++) { + int t, q; + + for (t = 0; t < ZIO_TYPES; t++) { + for (q = 0; q < ZIO_TASKQ_TYPES; q++) { const zio_taskq_info_t *ztip = &zio_taskqs[t][q]; enum zti_modes mode = ztip->zti_mode; uint_t value = ztip->zti_value; @@ -808,6 +813,8 @@ spa_activate(spa_t *spa, int mode) static void spa_deactivate(spa_t *spa) { + int t, q; + ASSERT(spa->spa_sync_on == B_FALSE); ASSERT(spa->spa_dsl_pool == NULL); ASSERT(spa->spa_root_vdev == NULL); @@ -819,8 +826,8 @@ spa_deactivate(spa_t *spa) list_destroy(&spa->spa_config_dirty_list); list_destroy(&spa->spa_state_dirty_list); - for (int t = 0; t < ZIO_TYPES; t++) { - for (int q = 0; q < ZIO_TASKQ_TYPES; q++) { + for (t = 0; t < ZIO_TYPES; t++) { + for (q = 0; q < ZIO_TASKQ_TYPES; q++) { if (spa->spa_zio_taskq[t][q] != NULL) taskq_destroy(spa->spa_zio_taskq[t][q]); spa->spa_zio_taskq[t][q] = NULL; @@ -883,6 +890,7 @@ spa_config_parse(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, nvlist_t **child; uint_t children; int error; + int c; if ((error = vdev_alloc(spa, vdp, nv, parent, id, atype)) != 0) return (error); @@ -902,7 +910,7 @@ spa_config_parse(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, return (EINVAL); } - for (int c = 0; c < children; c++) { + for (c = 0; c < children; c++) { vdev_t *vd; if ((error = spa_config_parse(spa, &vd, child[c], *vdp, c, atype)) != 0) { @@ -1136,7 +1144,7 @@ spa_load_l2cache(spa_t *spa) uint_t nl2cache; int i, j, oldnvdevs; uint64_t guid; - vdev_t *vd, **oldvdevs, **newvdevs; + vdev_t *vd, **oldvdevs, **newvdevs = NULL; spa_aux_vdev_t *sav = &spa->spa_l2cache; ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL); @@ -1279,7 +1287,9 @@ load_nvlist(spa_t *spa, uint64_t obj, nvlist_t **value) static void spa_check_removed(vdev_t *vd) { - for (int c = 0; c < vd->vdev_children; c++) + int c; + + for (c = 0; c < vd->vdev_children; c++) spa_check_removed(vd->vdev_child[c]); if (vd->vdev_ops->vdev_op_leaf && vdev_is_dead(vd)) { @@ -1296,6 +1306,7 @@ spa_config_valid(spa_t *spa, nvlist_t *config) { vdev_t *mrvd, *rvd = spa->spa_root_vdev; nvlist_t *nv; + int c, i; VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nv) == 0); @@ -1317,7 +1328,7 @@ spa_config_valid(spa_t *spa, nvlist_t *config) KM_SLEEP); VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); - for (int c = 0; c < rvd->vdev_children; c++) { + for (c = 0; c < rvd->vdev_children; c++) { vdev_t *tvd = rvd->vdev_child[c]; vdev_t *mtvd = mrvd->vdev_child[c]; @@ -1334,7 +1345,7 @@ spa_config_valid(spa_t *spa, nvlist_t *config) VERIFY(nvlist_add_nvlist(spa->spa_load_info, ZPOOL_CONFIG_MISSING_DEVICES, nv) == 0); - for (int i = 0; i < idx; i++) + for (i = 0; i < idx; i++) nvlist_free(child[i]); } nvlist_free(nv); @@ -1346,7 +1357,7 @@ spa_config_valid(spa_t *spa, nvlist_t *config) * from the MOS config (mrvd). Check each top-level vdev * with the corresponding MOS config top-level (mtvd). */ - for (int c = 0; c < rvd->vdev_children; c++) { + for (c = 0; c < rvd->vdev_children; c++) { vdev_t *tvd = rvd->vdev_child[c]; vdev_t *mtvd = mrvd->vdev_child[c]; @@ -1417,6 +1428,8 @@ static int spa_check_logs(spa_t *spa) { switch (spa->spa_log_state) { + default: + break; case SPA_LOG_MISSING: /* need to recheck in case slog has been restored */ case SPA_LOG_UNKNOWN: @@ -1435,13 +1448,14 @@ spa_passivate_log(spa_t *spa) { vdev_t *rvd = spa->spa_root_vdev; boolean_t slog_found = B_FALSE; + int c; ASSERT(spa_config_held(spa, SCL_ALLOC, RW_WRITER)); if (!spa_has_slogs(spa)) return (B_FALSE); - for (int c = 0; c < rvd->vdev_children; c++) { + for (c = 0; c < rvd->vdev_children; c++) { vdev_t *tvd = rvd->vdev_child[c]; metaslab_group_t *mg = tvd->vdev_mg; @@ -1458,10 +1472,11 @@ static void spa_activate_log(spa_t *spa) { vdev_t *rvd = spa->spa_root_vdev; + int c; ASSERT(spa_config_held(spa, SCL_ALLOC, RW_WRITER)); - for (int c = 0; c < rvd->vdev_children; c++) { + for (c = 0; c < rvd->vdev_children; c++) { vdev_t *tvd = rvd->vdev_child[c]; metaslab_group_t *mg = tvd->vdev_mg; @@ -1491,7 +1506,9 @@ spa_offline_log(spa_t *spa) static void spa_aux_check_removed(spa_aux_vdev_t *sav) { - for (int i = 0; i < sav->sav_count; i++) + int i; + + for (i = 0; i < sav->sav_count; i++) spa_check_removed(sav->sav_vdevs[i]); } @@ -2154,7 +2171,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, * to start pushing transactions. */ if (state != SPA_LOAD_TRYIMPORT) { - if (error = spa_load_verify(spa)) + if ((error = spa_load_verify(spa))) return (spa_vdev_err(rvd, VDEV_AUX_CORRUPT_DATA, error)); } @@ -2163,6 +2180,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, spa->spa_load_max_txg == UINT64_MAX)) { dmu_tx_t *tx; int need_update = B_FALSE; + int c; ASSERT(state != SPA_LOAD_TRYIMPORT); @@ -2209,7 +2227,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, (spa->spa_import_flags & ZFS_IMPORT_VERBATIM)) need_update = B_TRUE; - for (int c = 0; c < rvd->vdev_children; c++) + for (c = 0; c < rvd->vdev_children; c++) if (rvd->vdev_child[c]->vdev_ms_array == 0) need_update = B_TRUE; @@ -2845,6 +2863,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, nvlist_t **spares, **l2cache; uint_t nspares, nl2cache; uint64_t version, obj; + int c; /* * If this pool already exists, return failure. @@ -2903,7 +2922,7 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, (error = vdev_create(rvd, txg, B_FALSE)) == 0 && (error = spa_validate_aux(spa, nvroot, txg, VDEV_ALLOC_ADD)) == 0) { - for (int c = 0; c < rvd->vdev_children; c++) { + for (c = 0; c < rvd->vdev_children; c++) { vdev_metaslab_set_size(rvd->vdev_child[c]); vdev_expand(rvd->vdev_child[c], txg); } @@ -3103,7 +3122,9 @@ spa_generate_rootconf(char *devpath, char *devid, uint64_t *guid) static void spa_alt_rootvdev(vdev_t *vd, vdev_t **avd, uint64_t *txg) { - for (int c = 0; c < vd->vdev_children; c++) + int c; + + for (c = 0; c < vd->vdev_children; c++) spa_alt_rootvdev(vd->vdev_child[c], avd, txg); if (vd->vdev_ops->vdev_op_leaf) { @@ -3687,6 +3708,7 @@ spa_vdev_add(spa_t *spa, nvlist_t *nvroot) vdev_t *vd, *tvd; nvlist_t **spares, **l2cache; uint_t nspares, nl2cache; + int c; ASSERT(spa_writeable(spa)); @@ -3723,7 +3745,7 @@ spa_vdev_add(spa_t *spa, nvlist_t *nvroot) /* * Transfer each new top-level vdev from vd to rvd. */ - for (int c = 0; c < vd->vdev_children; c++) { + for (c = 0; c < vd->vdev_children; c++) { /* * Set the vdev id to the first hole, if one exists. @@ -3794,7 +3816,7 @@ int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing) { uint64_t txg, dtl_max_txg; - vdev_t *rvd = spa->spa_root_vdev; + ASSERTV(vdev_t *rvd = spa->spa_root_vdev;) vdev_t *oldvd, *newvd, *newrootvd, *pvd, *tvd; vdev_ops_t *pvops; char *oldvdpath, *newvdpath; @@ -3994,11 +4016,12 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done) { uint64_t txg; int error; - vdev_t *rvd = spa->spa_root_vdev; + ASSERTV(vdev_t *rvd = spa->spa_root_vdev;) vdev_t *vd, *pvd, *cvd, *tvd; boolean_t unspare = B_FALSE; - uint64_t unspare_guid; + uint64_t unspare_guid = 0; char *vdpath; + int c, t; ASSERT(spa_writeable(spa)); @@ -4066,7 +4089,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done) vd->vdev_path != NULL) { size_t len = strlen(vd->vdev_path); - for (int c = 0; c < pvd->vdev_children; c++) { + for (c = 0; c < pvd->vdev_children; c++) { cvd = pvd->vdev_child[c]; if (cvd == vd || cvd->vdev_path == NULL) @@ -4174,7 +4197,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done) * prevent vd from being accessed after it's freed. */ vdpath = spa_strdup(vd->vdev_path); - for (int t = 0; t < TXG_SIZE; t++) + for (t = 0; t < TXG_SIZE; t++) (void) txg_list_remove_this(&tvd->vdev_dtl_list, vd, t); vd->vdev_detached = B_TRUE; vdev_dirty(tvd, VDD_DTL, vd, txg); @@ -4509,7 +4532,9 @@ out: static nvlist_t * spa_nvlist_lookup_by_guid(nvlist_t **nvpp, int count, uint64_t target_guid) { - for (int i = 0; i < count; i++) { + int i; + + for (i = 0; i < count; i++) { uint64_t guid; VERIFY(nvlist_lookup_uint64(nvpp[i], ZPOOL_CONFIG_GUID, @@ -4527,11 +4552,12 @@ spa_vdev_remove_aux(nvlist_t *config, char *name, nvlist_t **dev, int count, nvlist_t *dev_to_remove) { nvlist_t **newdev = NULL; + int i, j; if (count > 1) newdev = kmem_alloc((count - 1) * sizeof (void *), KM_SLEEP); - for (int i = 0, j = 0; i < count; i++) { + for (i = 0, j = 0; i < count; i++) { if (dev[i] == dev_to_remove) continue; VERIFY(nvlist_dup(dev[i], &newdev[j++], KM_SLEEP) == 0); @@ -4540,7 +4566,7 @@ spa_vdev_remove_aux(nvlist_t *config, char *name, nvlist_t **dev, int count, VERIFY(nvlist_remove(config, name, DATA_TYPE_NVLIST_ARRAY) == 0); VERIFY(nvlist_add_nvlist_array(config, name, newdev, count - 1) == 0); - for (int i = 0; i < count - 1; i++) + for (i = 0; i < count - 1; i++) nvlist_free(newdev[i]); if (count > 1) @@ -4761,8 +4787,9 @@ static vdev_t * spa_vdev_resilver_done_hunt(vdev_t *vd) { vdev_t *newvd, *oldvd; + int c; - for (int c = 0; c < vd->vdev_children; c++) { + for (c = 0; c < vd->vdev_children; c++) { oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]); if (oldvd != NULL) return (oldvd); @@ -4965,6 +4992,8 @@ spa_scan(spa_t *spa, pool_scan_func_t func) static void spa_async_remove(spa_t *spa, vdev_t *vd) { + int c; + if (vd->vdev_remove_wanted) { vd->vdev_remove_wanted = B_FALSE; vd->vdev_delayed_close = B_FALSE; @@ -4983,19 +5012,21 @@ spa_async_remove(spa_t *spa, vdev_t *vd) vdev_state_dirty(vd->vdev_top); } - for (int c = 0; c < vd->vdev_children; c++) + for (c = 0; c < vd->vdev_children; c++) spa_async_remove(spa, vd->vdev_child[c]); } static void spa_async_probe(spa_t *spa, vdev_t *vd) { + int c; + if (vd->vdev_probe_wanted) { vd->vdev_probe_wanted = B_FALSE; vdev_reopen(vd); /* vdev_open() does the actual probe */ } - for (int c = 0; c < vd->vdev_children; c++) + for (c = 0; c < vd->vdev_children; c++) spa_async_probe(spa, vd->vdev_child[c]); } @@ -5005,11 +5036,12 @@ spa_async_autoexpand(spa_t *spa, vdev_t *vd) sysevent_id_t eid; nvlist_t *attr; char *physpath; + int c; if (!spa->spa_autoexpand) return; - for (int c = 0; c < vd->vdev_children; c++) { + for (c = 0; c < vd->vdev_children; c++) { vdev_t *cvd = vd->vdev_child[c]; spa_async_autoexpand(spa, cvd); } @@ -5033,7 +5065,7 @@ spa_async_autoexpand(spa_t *spa, vdev_t *vd) static void spa_async_thread(spa_t *spa) { - int tasks; + int tasks, i; ASSERT(spa->spa_sync_on); @@ -5072,9 +5104,9 @@ spa_async_thread(spa_t *spa) if (tasks & SPA_ASYNC_REMOVE) { spa_vdev_state_enter(spa, SCL_NONE); spa_async_remove(spa, spa->spa_root_vdev); - for (int i = 0; i < spa->spa_l2cache.sav_count; i++) + for (i = 0; i < spa->spa_l2cache.sav_count; i++) spa_async_remove(spa, spa->spa_l2cache.sav_vdevs[i]); - for (int i = 0; i < spa->spa_spares.sav_count; i++) + for (i = 0; i < spa->spa_spares.sav_count; i++) spa_async_remove(spa, spa->spa_spares.sav_vdevs[i]); (void) spa_vdev_state_exit(spa, NULL, 0); } @@ -5460,6 +5492,7 @@ spa_sync(spa_t *spa, uint64_t txg) vdev_t *vd; dmu_tx_t *tx; int error; + int c; VERIFY(spa_writeable(spa)); @@ -5563,7 +5596,7 @@ spa_sync(spa_t *spa, uint64_t txg) ddt_sync(spa, txg); dsl_scan_sync(dp, tx); - while (vd = txg_list_remove(&spa->spa_vdev_txg_list, txg)) + while ((vd = txg_list_remove(&spa->spa_vdev_txg_list, txg))) vdev_sync(vd, txg); if (pass == 1) @@ -5593,7 +5626,7 @@ spa_sync(spa_t *spa, uint64_t txg) int children = rvd->vdev_children; int c0 = spa_get_random(children); - for (int c = 0; c < children; c++) { + for (c = 0; c < children; c++) { vd = rvd->vdev_child[(c0 + c) % children]; if (vd->vdev_ms_array == 0 || vd->vdev_islog) continue; @@ -5645,7 +5678,7 @@ 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)))) vdev_sync_done(vd, txg); spa_update_dspace(spa);