1 789 ahrens /* 2 789 ahrens * CDDL HEADER START 3 789 ahrens * 4 789 ahrens * The contents of this file are subject to the terms of the 5 1544 eschrock * Common Development and Distribution License (the "License"). 6 1544 eschrock * You may not use this file except in compliance with the License. 7 789 ahrens * 8 789 ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 789 ahrens * or http://www.opensolaris.org/os/licensing. 10 789 ahrens * See the License for the specific language governing permissions 11 789 ahrens * and limitations under the License. 12 789 ahrens * 13 789 ahrens * When distributing Covered Code, include this CDDL HEADER in each 14 789 ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 789 ahrens * If applicable, add the following below this CDDL HEADER, with the 16 789 ahrens * fields enclosed by brackets "[]" replaced with your own identifying 17 789 ahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18 789 ahrens * 19 789 ahrens * CDDL HEADER END 20 789 ahrens */ 21 2082 eschrock 22 789 ahrens /* 23 8662 Jordan * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 789 ahrens * Use is subject to license terms. 25 789 ahrens */ 26 789 ahrens 27 789 ahrens #include <sys/spa.h> 28 789 ahrens #include <sys/spa_impl.h> 29 789 ahrens #include <sys/nvpair.h> 30 789 ahrens #include <sys/uio.h> 31 789 ahrens #include <sys/fs/zfs.h> 32 789 ahrens #include <sys/vdev_impl.h> 33 789 ahrens #include <sys/zfs_ioctl.h> 34 3975 ek110237 #include <sys/utsname.h> 35 3975 ek110237 #include <sys/systeminfo.h> 36 3975 ek110237 #include <sys/sunddi.h> 37 1544 eschrock #ifdef _KERNEL 38 1544 eschrock #include <sys/kobj.h> 39 8662 Jordan #include <sys/zone.h> 40 1544 eschrock #endif 41 1544 eschrock 42 789 ahrens /* 43 789 ahrens * Pool configuration repository. 44 789 ahrens * 45 5363 eschrock * Pool configuration is stored as a packed nvlist on the filesystem. By 46 5363 eschrock * default, all pools are stored in /etc/zfs/zpool.cache and loaded on boot 47 5363 eschrock * (when the ZFS module is loaded). Pools can also have the 'cachefile' 48 5363 eschrock * property set that allows them to be stored in an alternate location until 49 5363 eschrock * the control of external software. 50 789 ahrens * 51 5363 eschrock * For each cache file, we have a single nvlist which holds all the 52 5363 eschrock * configuration information. When the module loads, we read this information 53 5363 eschrock * from /etc/zfs/zpool.cache and populate the SPA namespace. This namespace is 54 5363 eschrock * maintained independently in spa.c. Whenever the namespace is modified, or 55 5363 eschrock * the configuration of a pool is changed, we call spa_config_sync(), which 56 5363 eschrock * walks through all the active pools and writes the configuration to disk. 57 789 ahrens */ 58 789 ahrens 59 789 ahrens static uint64_t spa_config_generation = 1; 60 789 ahrens 61 789 ahrens /* 62 789 ahrens * This can be overridden in userland to preserve an alternate namespace for 63 789 ahrens * userland pools when doing testing. 64 789 ahrens */ 65 6643 eschrock const char *spa_config_path = ZPOOL_CACHE; 66 789 ahrens 67 789 ahrens /* 68 789 ahrens * Called when the module is first loaded, this routine loads the configuration 69 789 ahrens * file into the SPA namespace. It does not actually open or load the pools; it 70 789 ahrens * only populates the namespace. 71 789 ahrens */ 72 789 ahrens void 73 789 ahrens spa_config_load(void) 74 789 ahrens { 75 789 ahrens void *buf = NULL; 76 789 ahrens nvlist_t *nvlist, *child; 77 789 ahrens nvpair_t *nvpair; 78 7754 Jeff char *pathname; 79 1544 eschrock struct _buf *file; 80 3912 lling uint64_t fsize; 81 789 ahrens 82 789 ahrens /* 83 789 ahrens * Open the configuration file. 84 789 ahrens */ 85 7754 Jeff pathname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 86 7754 Jeff 87 7754 Jeff (void) snprintf(pathname, MAXPATHLEN, "%s%s", 88 6643 eschrock (rootdir != NULL) ? "./" : "", spa_config_path); 89 1544 eschrock 90 1544 eschrock file = kobj_open_file(pathname); 91 7754 Jeff 92 7754 Jeff kmem_free(pathname, MAXPATHLEN); 93 7754 Jeff 94 1544 eschrock if (file == (struct _buf *)-1) 95 789 ahrens return; 96 1544 eschrock 97 3912 lling if (kobj_get_filesize(file, &fsize) != 0) 98 1544 eschrock goto out; 99 1544 eschrock 100 3912 lling buf = kmem_alloc(fsize, KM_SLEEP); 101 789 ahrens 102 789 ahrens /* 103 789 ahrens * Read the nvlist from the file. 104 789 ahrens */ 105 3912 lling if (kobj_read_file(file, buf, fsize, 0) < 0) 106 789 ahrens goto out; 107 789 ahrens 108 789 ahrens /* 109 789 ahrens * Unpack the nvlist. 110 789 ahrens */ 111 3912 lling if (nvlist_unpack(buf, fsize, &nvlist, KM_SLEEP) != 0) 112 789 ahrens goto out; 113 789 ahrens 114 789 ahrens /* 115 789 ahrens * Iterate over all elements in the nvlist, creating a new spa_t for 116 789 ahrens * each one with the specified configuration. 117 789 ahrens */ 118 789 ahrens mutex_enter(&spa_namespace_lock); 119 789 ahrens nvpair = NULL; 120 789 ahrens while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) { 121 789 ahrens if (nvpair_type(nvpair) != DATA_TYPE_NVLIST) 122 789 ahrens continue; 123 789 ahrens 124 789 ahrens VERIFY(nvpair_value_nvlist(nvpair, &child) == 0); 125 789 ahrens 126 789 ahrens if (spa_lookup(nvpair_name(nvpair)) != NULL) 127 789 ahrens continue; 128 10921 Tim (void) spa_add(nvpair_name(nvpair), child, NULL); 129 789 ahrens } 130 789 ahrens mutex_exit(&spa_namespace_lock); 131 789 ahrens 132 789 ahrens nvlist_free(nvlist); 133 789 ahrens 134 789 ahrens out: 135 789 ahrens if (buf != NULL) 136 3912 lling kmem_free(buf, fsize); 137 789 ahrens 138 1544 eschrock kobj_close_file(file); 139 789 ahrens } 140 789 ahrens 141 6643 eschrock static void 142 6643 eschrock spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl) 143 789 ahrens { 144 789 ahrens size_t buflen; 145 789 ahrens char *buf; 146 789 ahrens vnode_t *vp; 147 789 ahrens int oflags = FWRITE | FTRUNC | FCREAT | FOFFMAX; 148 7754 Jeff char *temp; 149 6643 eschrock 150 6643 eschrock /* 151 6643 eschrock * If the nvlist is empty (NULL), then remove the old cachefile. 152 6643 eschrock */ 153 6643 eschrock if (nvl == NULL) { 154 6643 eschrock (void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE); 155 6643 eschrock return; 156 6643 eschrock } 157 789 ahrens 158 789 ahrens /* 159 789 ahrens * Pack the configuration into a buffer. 160 789 ahrens */ 161 6643 eschrock VERIFY(nvlist_size(nvl, &buflen, NV_ENCODE_XDR) == 0); 162 789 ahrens 163 789 ahrens buf = kmem_alloc(buflen, KM_SLEEP); 164 7754 Jeff temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP); 165 789 ahrens 166 6643 eschrock VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR, 167 1544 eschrock KM_SLEEP) == 0); 168 789 ahrens 169 789 ahrens /* 170 789 ahrens * Write the configuration to disk. We need to do the traditional 171 789 ahrens * 'write to temporary file, sync, move over original' to make sure we 172 789 ahrens * always have a consistent view of the data. 173 789 ahrens */ 174 7754 Jeff (void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path); 175 789 ahrens 176 7754 Jeff if (vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0) == 0) { 177 7754 Jeff if (vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE, 178 7754 Jeff 0, RLIM64_INFINITY, kcred, NULL) == 0 && 179 7754 Jeff VOP_FSYNC(vp, FSYNC, kcred, NULL) == 0) { 180 7754 Jeff (void) vn_rename(temp, dp->scd_path, UIO_SYSSPACE); 181 7754 Jeff } 182 7754 Jeff (void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL); 183 7754 Jeff VN_RELE(vp); 184 789 ahrens } 185 789 ahrens 186 7754 Jeff (void) vn_remove(temp, UIO_SYSSPACE, RMFILE); 187 789 ahrens 188 5363 eschrock kmem_free(buf, buflen); 189 7754 Jeff kmem_free(temp, MAXPATHLEN); 190 5363 eschrock } 191 5363 eschrock 192 5363 eschrock /* 193 6643 eschrock * Synchronize pool configuration to disk. This must be called with the 194 6643 eschrock * namespace lock held. 195 5363 eschrock */ 196 5363 eschrock void 197 6643 eschrock spa_config_sync(spa_t *target, boolean_t removing, boolean_t postsysevent) 198 5363 eschrock { 199 6643 eschrock spa_config_dirent_t *dp, *tdp; 200 6643 eschrock nvlist_t *nvl; 201 5363 eschrock 202 5363 eschrock ASSERT(MUTEX_HELD(&spa_namespace_lock)); 203 8225 George 204 10000 Victor if (rootdir == NULL || !(spa_mode_global & FWRITE)) 205 8225 George return; 206 5363 eschrock 207 6643 eschrock /* 208 6643 eschrock * Iterate over all cachefiles for the pool, past or present. When the 209 6643 eschrock * cachefile is changed, the new one is pushed onto this list, allowing 210 6643 eschrock * us to update previous cachefiles that no longer contain this pool. 211 6643 eschrock */ 212 6643 eschrock for (dp = list_head(&target->spa_config_list); dp != NULL; 213 6643 eschrock dp = list_next(&target->spa_config_list, dp)) { 214 7754 Jeff spa_t *spa = NULL; 215 6643 eschrock if (dp->scd_path == NULL) 216 6643 eschrock continue; 217 6643 eschrock 218 6643 eschrock /* 219 6643 eschrock * Iterate over all pools, adding any matching pools to 'nvl'. 220 6643 eschrock */ 221 6643 eschrock nvl = NULL; 222 6643 eschrock while ((spa = spa_next(spa)) != NULL) { 223 6643 eschrock if (spa == target && removing) 224 6643 eschrock continue; 225 6643 eschrock 226 7754 Jeff mutex_enter(&spa->spa_props_lock); 227 6643 eschrock tdp = list_head(&spa->spa_config_list); 228 7754 Jeff if (spa->spa_config == NULL || 229 7754 Jeff tdp->scd_path == NULL || 230 7754 Jeff strcmp(tdp->scd_path, dp->scd_path) != 0) { 231 7754 Jeff mutex_exit(&spa->spa_props_lock); 232 6643 eschrock continue; 233 7754 Jeff } 234 6643 eschrock 235 6643 eschrock if (nvl == NULL) 236 6643 eschrock VERIFY(nvlist_alloc(&nvl, NV_UNIQUE_NAME, 237 6643 eschrock KM_SLEEP) == 0); 238 6643 eschrock 239 6643 eschrock VERIFY(nvlist_add_nvlist(nvl, spa->spa_name, 240 6643 eschrock spa->spa_config) == 0); 241 7754 Jeff mutex_exit(&spa->spa_props_lock); 242 6643 eschrock } 243 6643 eschrock 244 6643 eschrock spa_config_write(dp, nvl); 245 6643 eschrock nvlist_free(nvl); 246 6643 eschrock } 247 5363 eschrock 248 5363 eschrock /* 249 6643 eschrock * Remove any config entries older than the current one. 250 5363 eschrock */ 251 6643 eschrock dp = list_head(&target->spa_config_list); 252 6643 eschrock while ((tdp = list_next(&target->spa_config_list, dp)) != NULL) { 253 6643 eschrock list_remove(&target->spa_config_list, tdp); 254 6643 eschrock if (tdp->scd_path != NULL) 255 6643 eschrock spa_strfree(tdp->scd_path); 256 6643 eschrock kmem_free(tdp, sizeof (spa_config_dirent_t)); 257 5363 eschrock } 258 5363 eschrock 259 789 ahrens spa_config_generation++; 260 6643 eschrock 261 6643 eschrock if (postsysevent) 262 6643 eschrock spa_event_notify(target, NULL, ESC_ZFS_CONFIG_SYNC); 263 789 ahrens } 264 789 ahrens 265 789 ahrens /* 266 1635 bonwick * Sigh. Inside a local zone, we don't have access to /etc/zfs/zpool.cache, 267 789 ahrens * and we don't want to allow the local zone to see all the pools anyway. 268 789 ahrens * So we have to invent the ZFS_IOC_CONFIG ioctl to grab the configuration 269 789 ahrens * information for all pool visible within the zone. 270 789 ahrens */ 271 789 ahrens nvlist_t * 272 789 ahrens spa_all_configs(uint64_t *generation) 273 789 ahrens { 274 789 ahrens nvlist_t *pools; 275 7754 Jeff spa_t *spa = NULL; 276 789 ahrens 277 789 ahrens if (*generation == spa_config_generation) 278 789 ahrens return (NULL); 279 789 ahrens 280 1544 eschrock VERIFY(nvlist_alloc(&pools, NV_UNIQUE_NAME, KM_SLEEP) == 0); 281 789 ahrens 282 789 ahrens mutex_enter(&spa_namespace_lock); 283 789 ahrens while ((spa = spa_next(spa)) != NULL) { 284 789 ahrens if (INGLOBALZONE(curproc) || 285 789 ahrens zone_dataset_visible(spa_name(spa), NULL)) { 286 7754 Jeff mutex_enter(&spa->spa_props_lock); 287 789 ahrens VERIFY(nvlist_add_nvlist(pools, spa_name(spa), 288 789 ahrens spa->spa_config) == 0); 289 7754 Jeff mutex_exit(&spa->spa_props_lock); 290 789 ahrens } 291 789 ahrens } 292 7754 Jeff *generation = spa_config_generation; 293 789 ahrens mutex_exit(&spa_namespace_lock); 294 789 ahrens 295 789 ahrens return (pools); 296 789 ahrens } 297 789 ahrens 298 789 ahrens void 299 789 ahrens spa_config_set(spa_t *spa, nvlist_t *config) 300 789 ahrens { 301 7754 Jeff mutex_enter(&spa->spa_props_lock); 302 789 ahrens if (spa->spa_config != NULL) 303 789 ahrens nvlist_free(spa->spa_config); 304 789 ahrens spa->spa_config = config; 305 7754 Jeff mutex_exit(&spa->spa_props_lock); 306 789 ahrens } 307 789 ahrens 308 10921 Tim /* Add discovered rewind info, if any to the provided nvlist */ 309 10921 Tim void 310 10921 Tim spa_rewind_data_to_nvlist(spa_t *spa, nvlist_t *tonvl) 311 10921 Tim { 312 10921 Tim int64_t loss = 0; 313 10921 Tim 314 10921 Tim if (tonvl == NULL || spa->spa_load_txg == 0) 315 10921 Tim return; 316 10921 Tim 317 10921 Tim VERIFY(nvlist_add_uint64(tonvl, ZPOOL_CONFIG_LOAD_TIME, 318 10921 Tim spa->spa_load_txg_ts) == 0); 319 10921 Tim if (spa->spa_last_ubsync_txg) 320 10921 Tim loss = spa->spa_last_ubsync_txg_ts - spa->spa_load_txg_ts; 321 10921 Tim VERIFY(nvlist_add_int64(tonvl, ZPOOL_CONFIG_REWIND_TIME, loss) == 0); 322 10921 Tim VERIFY(nvlist_add_uint64(tonvl, ZPOOL_CONFIG_LOAD_DATA_ERRORS, 323 10921 Tim spa->spa_load_data_errors) == 0); 324 10921 Tim } 325 10921 Tim 326 789 ahrens /* 327 789 ahrens * Generate the pool's configuration based on the current in-core state. 328 789 ahrens * We infer whether to generate a complete config or just one top-level config 329 789 ahrens * based on whether vd is the root vdev. 330 789 ahrens */ 331 789 ahrens nvlist_t * 332 789 ahrens spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats) 333 789 ahrens { 334 789 ahrens nvlist_t *config, *nvroot; 335 789 ahrens vdev_t *rvd = spa->spa_root_vdev; 336 3975 ek110237 unsigned long hostid = 0; 337 7754 Jeff boolean_t locked = B_FALSE; 338 789 ahrens 339 7754 Jeff if (vd == NULL) { 340 7754 Jeff vd = rvd; 341 7754 Jeff locked = B_TRUE; 342 7754 Jeff spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER); 343 7754 Jeff } 344 1635 bonwick 345 7754 Jeff ASSERT(spa_config_held(spa, SCL_CONFIG | SCL_STATE, RW_READER) == 346 7754 Jeff (SCL_CONFIG | SCL_STATE)); 347 789 ahrens 348 789 ahrens /* 349 789 ahrens * If txg is -1, report the current value of spa->spa_config_txg. 350 789 ahrens */ 351 789 ahrens if (txg == -1ULL) 352 789 ahrens txg = spa->spa_config_txg; 353 789 ahrens 354 1544 eschrock VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, KM_SLEEP) == 0); 355 789 ahrens 356 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_VERSION, 357 2082 eschrock spa_version(spa)) == 0); 358 789 ahrens VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, 359 789 ahrens spa_name(spa)) == 0); 360 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, 361 789 ahrens spa_state(spa)) == 0); 362 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_TXG, 363 789 ahrens txg) == 0); 364 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_GUID, 365 789 ahrens spa_guid(spa)) == 0); 366 8662 Jordan #ifdef _KERNEL 367 8662 Jordan hostid = zone_get_hostid(NULL); 368 8662 Jordan #else /* _KERNEL */ 369 8662 Jordan /* 370 8662 Jordan * We're emulating the system's hostid in userland, so we can't use 371 8662 Jordan * zone_get_hostid(). 372 8662 Jordan */ 373 3975 ek110237 (void) ddi_strtoul(hw_serial, NULL, 10, &hostid); 374 8662 Jordan #endif /* _KERNEL */ 375 4178 lling if (hostid != 0) { 376 4178 lling VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID, 377 4527 perrin hostid) == 0); 378 4178 lling } 379 3975 ek110237 VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME, 380 3975 ek110237 utsname.nodename) == 0); 381 789 ahrens 382 789 ahrens if (vd != rvd) { 383 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_TOP_GUID, 384 789 ahrens vd->vdev_top->vdev_guid) == 0); 385 789 ahrens VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_GUID, 386 789 ahrens vd->vdev_guid) == 0); 387 2082 eschrock if (vd->vdev_isspare) 388 2082 eschrock VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_IS_SPARE, 389 4527 perrin 1ULL) == 0); 390 4527 perrin if (vd->vdev_islog) 391 4527 perrin VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_IS_LOG, 392 2082 eschrock 1ULL) == 0); 393 789 ahrens vd = vd->vdev_top; /* label contains top config */ 394 789 ahrens } 395 789 ahrens 396 10594 George /* 397 10594 George * Add the top-level config. We even add this on pools which 398 10594 George * don't support holes in the namespace as older pools will 399 10594 George * just ignore it. 400 10594 George */ 401 10594 George vdev_top_config_generate(spa, config); 402 10594 George 403 5450 brendan nvroot = vdev_config_generate(spa, vd, getstats, B_FALSE, B_FALSE); 404 789 ahrens VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot) == 0); 405 789 ahrens nvlist_free(nvroot); 406 789 ahrens 407 11149 George if (getstats && spa_load_state(spa) == SPA_LOAD_NONE) { 408 11149 George ddt_histogram_t *ddh; 409 11149 George ddt_stat_t *dds; 410 11149 George ddt_object_t *ddo; 411 11149 George 412 11149 George ddh = kmem_zalloc(sizeof (ddt_histogram_t), KM_SLEEP); 413 11149 George ddt_get_dedup_histogram(spa, ddh); 414 11149 George VERIFY(nvlist_add_uint64_array(config, 415 11149 George ZPOOL_CONFIG_DDT_HISTOGRAM, 416 11149 George (uint64_t *)ddh, sizeof (*ddh) / sizeof (uint64_t)) == 0); 417 11149 George kmem_free(ddh, sizeof (ddt_histogram_t)); 418 11149 George 419 11149 George ddo = kmem_zalloc(sizeof (ddt_object_t), KM_SLEEP); 420 11149 George ddt_get_dedup_object_stats(spa, ddo); 421 11149 George VERIFY(nvlist_add_uint64_array(config, 422 11149 George ZPOOL_CONFIG_DDT_OBJ_STATS, 423 11149 George (uint64_t *)ddo, sizeof (*ddo) / sizeof (uint64_t)) == 0); 424 11149 George kmem_free(ddo, sizeof (ddt_object_t)); 425 11149 George 426 11149 George dds = kmem_zalloc(sizeof (ddt_stat_t), KM_SLEEP); 427 11149 George ddt_get_dedup_stats(spa, dds); 428 11149 George VERIFY(nvlist_add_uint64_array(config, 429 11149 George ZPOOL_CONFIG_DDT_STATS, 430 11149 George (uint64_t *)dds, sizeof (*dds) / sizeof (uint64_t)) == 0); 431 11149 George kmem_free(dds, sizeof (ddt_stat_t)); 432 11149 George } 433 11149 George 434 10921 Tim spa_rewind_data_to_nvlist(spa, config); 435 10921 Tim 436 7754 Jeff if (locked) 437 7754 Jeff spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG); 438 7754 Jeff 439 789 ahrens return (config); 440 789 ahrens } 441 1635 bonwick 442 1635 bonwick /* 443 6423 gw25295 * Update all disk labels, generate a fresh config based on the current 444 6423 gw25295 * in-core state, and sync the global config cache (do not sync the config 445 6423 gw25295 * cache if this is a booting rootpool). 446 6423 gw25295 */ 447 6423 gw25295 void 448 10100 Lin spa_config_update(spa_t *spa, int what) 449 1635 bonwick { 450 1635 bonwick vdev_t *rvd = spa->spa_root_vdev; 451 1635 bonwick uint64_t txg; 452 1635 bonwick int c; 453 1635 bonwick 454 1635 bonwick ASSERT(MUTEX_HELD(&spa_namespace_lock)); 455 1635 bonwick 456 7754 Jeff spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 457 1635 bonwick txg = spa_last_synced_txg(spa) + 1; 458 1635 bonwick if (what == SPA_CONFIG_UPDATE_POOL) { 459 1635 bonwick vdev_config_dirty(rvd); 460 1635 bonwick } else { 461 1635 bonwick /* 462 1635 bonwick * If we have top-level vdevs that were added but have 463 1635 bonwick * not yet been prepared for allocation, do that now. 464 1635 bonwick * (It's safe now because the config cache is up to date, 465 1635 bonwick * so it will be able to translate the new DVAs.) 466 1635 bonwick * See comments in spa_vdev_add() for full details. 467 1635 bonwick */ 468 1635 bonwick for (c = 0; c < rvd->vdev_children; c++) { 469 1635 bonwick vdev_t *tvd = rvd->vdev_child[c]; 470 9816 George if (tvd->vdev_ms_array == 0) 471 9816 George vdev_metaslab_set_size(tvd); 472 9816 George vdev_expand(tvd, txg); 473 1635 bonwick } 474 1635 bonwick } 475 7754 Jeff spa_config_exit(spa, SCL_ALL, FTAG); 476 1635 bonwick 477 1635 bonwick /* 478 1635 bonwick * Wait for the mosconfig to be regenerated and synced. 479 1635 bonwick */ 480 1635 bonwick txg_wait_synced(spa->spa_dsl_pool, txg); 481 1635 bonwick 482 1635 bonwick /* 483 1635 bonwick * Update the global config cache to reflect the new mosconfig. 484 1635 bonwick */ 485 10100 Lin if (!spa->spa_is_root) 486 6643 eschrock spa_config_sync(spa, B_FALSE, what != SPA_CONFIG_UPDATE_POOL); 487 1635 bonwick 488 1635 bonwick if (what == SPA_CONFIG_UPDATE_POOL) 489 10100 Lin spa_config_update(spa, SPA_CONFIG_UPDATE_VDEVS); 490 1635 bonwick } 491