spa.c (208683) | spa.c (209962) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 6 unchanged lines hidden (view full) --- 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 6 unchanged lines hidden (view full) --- 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* |
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. | 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. 25 */ 26 27/* 28 * This file contains all the routines used when modifying on-disk SPA state. 29 * This includes opening, importing, destroying, exporting a pool, and syncing a 30 * pool. 31 */ --- 33 unchanged lines hidden (view full) --- 65/* Check hostid on import? */ 66static int check_hostid = 1; 67 68SYSCTL_DECL(_vfs_zfs); 69TUNABLE_INT("vfs.zfs.check_hostid", &check_hostid); 70SYSCTL_INT(_vfs_zfs, OID_AUTO, check_hostid, CTLFLAG_RW, &check_hostid, 0, 71 "Check hostid on import?"); 72 | 24 * Use is subject to license terms. 25 */ 26 27/* 28 * This file contains all the routines used when modifying on-disk SPA state. 29 * This includes opening, importing, destroying, exporting a pool, and syncing a 30 * pool. 31 */ --- 33 unchanged lines hidden (view full) --- 65/* Check hostid on import? */ 66static int check_hostid = 1; 67 68SYSCTL_DECL(_vfs_zfs); 69TUNABLE_INT("vfs.zfs.check_hostid", &check_hostid); 70SYSCTL_INT(_vfs_zfs, OID_AUTO, check_hostid, CTLFLAG_RW, &check_hostid, 0, 71 "Check hostid on import?"); 72 |
73int zio_taskq_threads[ZIO_TYPES][ZIO_TASKQ_TYPES] = { 74 /* ISSUE INTR */ 75 { 1, 1 }, /* ZIO_TYPE_NULL */ 76 { 1, 8 }, /* ZIO_TYPE_READ */ 77 { 8, 1 }, /* ZIO_TYPE_WRITE */ 78 { 1, 1 }, /* ZIO_TYPE_FREE */ 79 { 1, 1 }, /* ZIO_TYPE_CLAIM */ 80 { 1, 1 }, /* ZIO_TYPE_IOCTL */ | 73enum zti_modes { 74 zti_mode_fixed, /* value is # of threads (min 1) */ 75 zti_mode_online_percent, /* value is % of online CPUs */ 76 zti_mode_tune, /* fill from zio_taskq_tune_* */ 77 zti_nmodes |
81}; 82 | 78}; 79 |
80#define ZTI_THREAD_FIX(n) { zti_mode_fixed, (n) } 81#define ZTI_THREAD_PCT(n) { zti_mode_online_percent, (n) } 82#define ZTI_THREAD_TUNE { zti_mode_tune, 0 } 83 84#define ZTI_THREAD_ONE ZTI_THREAD_FIX(1) 85 86typedef struct zio_taskq_info { 87 const char *zti_name; 88 struct { 89 enum zti_modes zti_mode; 90 uint_t zti_value; 91 } zti_nthreads[ZIO_TASKQ_TYPES]; 92} zio_taskq_info_t; 93 94static const char *const zio_taskq_types[ZIO_TASKQ_TYPES] = { 95 "issue", "intr" 96}; 97 98const zio_taskq_info_t zio_taskqs[ZIO_TYPES] = { 99 /* ISSUE INTR */ 100 { "spa_zio_null", { ZTI_THREAD_ONE, ZTI_THREAD_ONE } }, 101 { "spa_zio_read", { ZTI_THREAD_FIX(8), ZTI_THREAD_TUNE } }, 102 { "spa_zio_write", { ZTI_THREAD_TUNE, ZTI_THREAD_FIX(8) } }, 103 { "spa_zio_free", { ZTI_THREAD_ONE, ZTI_THREAD_ONE } }, 104 { "spa_zio_claim", { ZTI_THREAD_ONE, ZTI_THREAD_ONE } }, 105 { "spa_zio_ioctl", { ZTI_THREAD_ONE, ZTI_THREAD_ONE } }, 106}; 107 108enum zti_modes zio_taskq_tune_mode = zti_mode_online_percent; 109uint_t zio_taskq_tune_value = 80; /* #threads = 80% of # online CPUs */ 110 |
|
83static void spa_sync_props(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx); 84static boolean_t spa_has_active_shared_spare(spa_t *spa); 85 86/* 87 * ========================================================================== 88 * SPA properties routines 89 * ========================================================================== 90 */ --- 21 unchanged lines hidden (view full) --- 112} 113 114/* 115 * Get property values from the spa configuration. 116 */ 117static void 118spa_prop_get_config(spa_t *spa, nvlist_t **nvp) 119{ | 111static void spa_sync_props(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx); 112static boolean_t spa_has_active_shared_spare(spa_t *spa); 113 114/* 115 * ========================================================================== 116 * SPA properties routines 117 * ========================================================================== 118 */ --- 21 unchanged lines hidden (view full) --- 140} 141 142/* 143 * Get property values from the spa configuration. 144 */ 145static void 146spa_prop_get_config(spa_t *spa, nvlist_t **nvp) 147{ |
120 uint64_t size = spa_get_space(spa); 121 uint64_t used = spa_get_alloc(spa); | 148 uint64_t size; 149 uint64_t used; |
122 uint64_t cap, version; 123 zprop_source_t src = ZPROP_SRC_NONE; 124 spa_config_dirent_t *dp; 125 126 ASSERT(MUTEX_HELD(&spa->spa_props_lock)); 127 | 150 uint64_t cap, version; 151 zprop_source_t src = ZPROP_SRC_NONE; 152 spa_config_dirent_t *dp; 153 154 ASSERT(MUTEX_HELD(&spa->spa_props_lock)); 155 |
128 /* 129 * readonly properties 130 */ 131 spa_prop_add_list(*nvp, ZPOOL_PROP_NAME, spa_name(spa), 0, src); 132 spa_prop_add_list(*nvp, ZPOOL_PROP_SIZE, NULL, size, src); 133 spa_prop_add_list(*nvp, ZPOOL_PROP_USED, NULL, used, src); 134 spa_prop_add_list(*nvp, ZPOOL_PROP_AVAILABLE, NULL, size - used, src); | 156 if (spa->spa_root_vdev != NULL) { 157 size = spa_get_space(spa); 158 used = spa_get_alloc(spa); 159 spa_prop_add_list(*nvp, ZPOOL_PROP_NAME, spa_name(spa), 0, src); 160 spa_prop_add_list(*nvp, ZPOOL_PROP_SIZE, NULL, size, src); 161 spa_prop_add_list(*nvp, ZPOOL_PROP_USED, NULL, used, src); 162 spa_prop_add_list(*nvp, ZPOOL_PROP_AVAILABLE, NULL, 163 size - used, src); |
135 | 164 |
136 cap = (size == 0) ? 0 : (used * 100 / size); 137 spa_prop_add_list(*nvp, ZPOOL_PROP_CAPACITY, NULL, cap, src); | 165 cap = (size == 0) ? 0 : (used * 100 / size); 166 spa_prop_add_list(*nvp, ZPOOL_PROP_CAPACITY, NULL, cap, src); |
138 | 167 |
139 spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src); 140 spa_prop_add_list(*nvp, ZPOOL_PROP_HEALTH, NULL, 141 spa->spa_root_vdev->vdev_state, src); | 168 spa_prop_add_list(*nvp, ZPOOL_PROP_HEALTH, NULL, 169 spa->spa_root_vdev->vdev_state, src); |
142 | 170 |
143 /* 144 * settable properties that are not stored in the pool property object. 145 */ 146 version = spa_version(spa); 147 if (version == zpool_prop_default_numeric(ZPOOL_PROP_VERSION)) 148 src = ZPROP_SRC_DEFAULT; 149 else 150 src = ZPROP_SRC_LOCAL; 151 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL, version, src); | 171 version = spa_version(spa); 172 if (version == zpool_prop_default_numeric(ZPOOL_PROP_VERSION)) 173 src = ZPROP_SRC_DEFAULT; 174 else 175 src = ZPROP_SRC_LOCAL; 176 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL, version, src); 177 } |
152 | 178 |
179 spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src); 180 |
|
153 if (spa->spa_root != NULL) 154 spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root, 155 0, ZPROP_SRC_LOCAL); 156 157 if ((dp = list_head(&spa->spa_config_list)) != NULL) { 158 if (dp->scd_path == NULL) { 159 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, 160 "none", 0, ZPROP_SRC_LOCAL); --- 147 unchanged lines hidden (view full) --- 308 case ZPOOL_PROP_AUTOREPLACE: 309 case ZPOOL_PROP_LISTSNAPS: 310 error = nvpair_value_uint64(elem, &intval); 311 if (!error && intval > 1) 312 error = EINVAL; 313 break; 314 315 case ZPOOL_PROP_BOOTFS: | 181 if (spa->spa_root != NULL) 182 spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root, 183 0, ZPROP_SRC_LOCAL); 184 185 if ((dp = list_head(&spa->spa_config_list)) != NULL) { 186 if (dp->scd_path == NULL) { 187 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, 188 "none", 0, ZPROP_SRC_LOCAL); --- 147 unchanged lines hidden (view full) --- 336 case ZPOOL_PROP_AUTOREPLACE: 337 case ZPOOL_PROP_LISTSNAPS: 338 error = nvpair_value_uint64(elem, &intval); 339 if (!error && intval > 1) 340 error = EINVAL; 341 break; 342 343 case ZPOOL_PROP_BOOTFS: |
344 /* 345 * If the pool version is less than SPA_VERSION_BOOTFS, 346 * or the pool is still being created (version == 0), 347 * the bootfs property cannot be set. 348 */ |
|
316 if (spa_version(spa) < SPA_VERSION_BOOTFS) { 317 error = ENOTSUP; 318 break; 319 } 320 321 /* 322 * Make sure the vdev config is bootable 323 */ --- 90 unchanged lines hidden (view full) --- 414 error = nvlist_add_uint64(props, 415 zpool_prop_to_name(ZPOOL_PROP_BOOTFS), objnum); 416 } 417 } 418 419 return (error); 420} 421 | 349 if (spa_version(spa) < SPA_VERSION_BOOTFS) { 350 error = ENOTSUP; 351 break; 352 } 353 354 /* 355 * Make sure the vdev config is bootable 356 */ --- 90 unchanged lines hidden (view full) --- 447 error = nvlist_add_uint64(props, 448 zpool_prop_to_name(ZPOOL_PROP_BOOTFS), objnum); 449 } 450 } 451 452 return (error); 453} 454 |
455void 456spa_configfile_set(spa_t *spa, nvlist_t *nvp, boolean_t need_sync) 457{ 458 char *cachefile; 459 spa_config_dirent_t *dp; 460 461 if (nvlist_lookup_string(nvp, zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), 462 &cachefile) != 0) 463 return; 464 465 dp = kmem_alloc(sizeof (spa_config_dirent_t), 466 KM_SLEEP); 467 468 if (cachefile[0] == '\0') 469 dp->scd_path = spa_strdup(spa_config_path); 470 else if (strcmp(cachefile, "none") == 0) 471 dp->scd_path = NULL; 472 else 473 dp->scd_path = spa_strdup(cachefile); 474 475 list_insert_head(&spa->spa_config_list, dp); 476 if (need_sync) 477 spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE); 478} 479 |
|
422int 423spa_prop_set(spa_t *spa, nvlist_t *nvp) 424{ 425 int error; | 480int 481spa_prop_set(spa_t *spa, nvlist_t *nvp) 482{ 483 int error; |
484 nvpair_t *elem; 485 boolean_t need_sync = B_FALSE; 486 zpool_prop_t prop; |
|
426 427 if ((error = spa_prop_validate(spa, nvp)) != 0) 428 return (error); 429 | 487 488 if ((error = spa_prop_validate(spa, nvp)) != 0) 489 return (error); 490 |
430 return (dsl_sync_task_do(spa_get_dsl(spa), NULL, spa_sync_props, 431 spa, nvp, 3)); | 491 elem = NULL; 492 while ((elem = nvlist_next_nvpair(nvp, elem)) != NULL) { 493 if ((prop = zpool_name_to_prop( 494 nvpair_name(elem))) == ZPROP_INVAL) 495 return (EINVAL); 496 497 if (prop == ZPOOL_PROP_CACHEFILE || prop == ZPOOL_PROP_ALTROOT) 498 continue; 499 500 need_sync = B_TRUE; 501 break; 502 } 503 504 if (need_sync) 505 return (dsl_sync_task_do(spa_get_dsl(spa), NULL, spa_sync_props, 506 spa, nvp, 3)); 507 else 508 return (0); |
432} 433 434/* 435 * If the bootfs property value is dsobj, clear it. 436 */ 437void 438spa_prop_clear_bootfs(spa_t *spa, uint64_t dsobj, dmu_tx_t *tx) 439{ --- 48 unchanged lines hidden (view full) --- 488 spa_error_entry_compare, sizeof (spa_error_entry_t), 489 offsetof(spa_error_entry_t, se_avl)); 490} 491 492/* 493 * Activate an uninitialized pool. 494 */ 495static void | 509} 510 511/* 512 * If the bootfs property value is dsobj, clear it. 513 */ 514void 515spa_prop_clear_bootfs(spa_t *spa, uint64_t dsobj, dmu_tx_t *tx) 516{ --- 48 unchanged lines hidden (view full) --- 565 spa_error_entry_compare, sizeof (spa_error_entry_t), 566 offsetof(spa_error_entry_t, se_avl)); 567} 568 569/* 570 * Activate an uninitialized pool. 571 */ 572static void |
496spa_activate(spa_t *spa) | 573spa_activate(spa_t *spa, int mode) |
497{ | 574{ |
498 | |
499 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED); 500 501 spa->spa_state = POOL_STATE_ACTIVE; | 575 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED); 576 577 spa->spa_state = POOL_STATE_ACTIVE; |
578 spa->spa_mode = mode; |
|
502 | 579 |
503 spa->spa_normal_class = metaslab_class_create(); 504 spa->spa_log_class = metaslab_class_create(); | 580 spa->spa_normal_class = metaslab_class_create(zfs_metaslab_ops); 581 spa->spa_log_class = metaslab_class_create(zfs_metaslab_ops); |
505 506 for (int t = 0; t < ZIO_TYPES; t++) { | 582 583 for (int t = 0; t < ZIO_TYPES; t++) { |
584 const zio_taskq_info_t *ztip = &zio_taskqs[t]; |
|
507 for (int q = 0; q < ZIO_TASKQ_TYPES; q++) { | 585 for (int q = 0; q < ZIO_TASKQ_TYPES; q++) { |
508 spa->spa_zio_taskq[t][q] = taskq_create("spa_zio", 509 zio_taskq_threads[t][q], maxclsyspri, 50, 510 INT_MAX, TASKQ_PREPOPULATE); | 586 enum zti_modes mode = ztip->zti_nthreads[q].zti_mode; 587 uint_t value = ztip->zti_nthreads[q].zti_value; 588 char name[32]; 589 590 (void) snprintf(name, sizeof (name), 591 "%s_%s", ztip->zti_name, zio_taskq_types[q]); 592 593 if (mode == zti_mode_tune) { 594 mode = zio_taskq_tune_mode; 595 value = zio_taskq_tune_value; 596 if (mode == zti_mode_tune) 597 mode = zti_mode_online_percent; 598 } 599 600 switch (mode) { 601 case zti_mode_fixed: 602 ASSERT3U(value, >=, 1); 603 value = MAX(value, 1); 604 605 spa->spa_zio_taskq[t][q] = taskq_create(name, 606 value, maxclsyspri, 50, INT_MAX, 607 TASKQ_PREPOPULATE); 608 break; 609 610 case zti_mode_online_percent: 611 spa->spa_zio_taskq[t][q] = taskq_create(name, 612 value, maxclsyspri, 50, INT_MAX, 613 TASKQ_PREPOPULATE | TASKQ_THREADS_CPU_PCT); 614 break; 615 616 case zti_mode_tune: 617 default: 618 panic("unrecognized mode for " 619 "zio_taskqs[%u]->zti_nthreads[%u] (%u:%u) " 620 "in spa_activate()", 621 t, q, mode, value); 622 break; 623 } |
511 } 512 } 513 514 list_create(&spa->spa_config_dirty_list, sizeof (vdev_t), 515 offsetof(vdev_t, vdev_config_dirty_node)); 516 list_create(&spa->spa_state_dirty_list, sizeof (vdev_t), 517 offsetof(vdev_t, vdev_state_dirty_node)); 518 --- 12 unchanged lines hidden (view full) --- 531 * Opposite of spa_activate(). 532 */ 533static void 534spa_deactivate(spa_t *spa) 535{ 536 ASSERT(spa->spa_sync_on == B_FALSE); 537 ASSERT(spa->spa_dsl_pool == NULL); 538 ASSERT(spa->spa_root_vdev == NULL); | 624 } 625 } 626 627 list_create(&spa->spa_config_dirty_list, sizeof (vdev_t), 628 offsetof(vdev_t, vdev_config_dirty_node)); 629 list_create(&spa->spa_state_dirty_list, sizeof (vdev_t), 630 offsetof(vdev_t, vdev_state_dirty_node)); 631 --- 12 unchanged lines hidden (view full) --- 644 * Opposite of spa_activate(). 645 */ 646static void 647spa_deactivate(spa_t *spa) 648{ 649 ASSERT(spa->spa_sync_on == B_FALSE); 650 ASSERT(spa->spa_dsl_pool == NULL); 651 ASSERT(spa->spa_root_vdev == NULL); |
539 | 652 ASSERT(spa->spa_async_zio_root == NULL); |
540 ASSERT(spa->spa_state != POOL_STATE_UNINITIALIZED); 541 542 txg_list_destroy(&spa->spa_vdev_txg_list); 543 544 list_destroy(&spa->spa_config_dirty_list); 545 list_destroy(&spa->spa_state_dirty_list); 546 547 for (int t = 0; t < ZIO_TYPES; t++) { --- 89 unchanged lines hidden (view full) --- 637 if (spa->spa_sync_on) { 638 txg_sync_stop(spa->spa_dsl_pool); 639 spa->spa_sync_on = B_FALSE; 640 } 641 642 /* 643 * Wait for any outstanding async I/O to complete. 644 */ | 653 ASSERT(spa->spa_state != POOL_STATE_UNINITIALIZED); 654 655 txg_list_destroy(&spa->spa_vdev_txg_list); 656 657 list_destroy(&spa->spa_config_dirty_list); 658 list_destroy(&spa->spa_state_dirty_list); 659 660 for (int t = 0; t < ZIO_TYPES; t++) { --- 89 unchanged lines hidden (view full) --- 750 if (spa->spa_sync_on) { 751 txg_sync_stop(spa->spa_dsl_pool); 752 spa->spa_sync_on = B_FALSE; 753 } 754 755 /* 756 * Wait for any outstanding async I/O to complete. 757 */ |
645 mutex_enter(&spa->spa_async_root_lock); 646 while (spa->spa_async_root_count != 0) 647 cv_wait(&spa->spa_async_root_cv, &spa->spa_async_root_lock); 648 mutex_exit(&spa->spa_async_root_lock); | 758 if (spa->spa_async_zio_root != NULL) { 759 (void) zio_wait(spa->spa_async_zio_root); 760 spa->spa_async_zio_root = NULL; 761 } |
649 650 /* | 762 763 /* |
651 * Drop and purge level 2 cache 652 */ 653 spa_l2cache_drop(spa); 654 655 /* | |
656 * Close the dsl pool. 657 */ 658 if (spa->spa_dsl_pool) { 659 dsl_pool_close(spa->spa_dsl_pool); 660 spa->spa_dsl_pool = NULL; 661 } 662 | 764 * Close the dsl pool. 765 */ 766 if (spa->spa_dsl_pool) { 767 dsl_pool_close(spa->spa_dsl_pool); 768 spa->spa_dsl_pool = NULL; 769 } 770 |
771 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 772 |
|
663 /* | 773 /* |
774 * Drop and purge level 2 cache 775 */ 776 spa_l2cache_drop(spa); 777 778 /* |
|
664 * Close all vdevs. 665 */ 666 if (spa->spa_root_vdev) 667 vdev_free(spa->spa_root_vdev); 668 ASSERT(spa->spa_root_vdev == NULL); 669 670 for (i = 0; i < spa->spa_spares.sav_count; i++) 671 vdev_free(spa->spa_spares.sav_vdevs[i]); --- 17 unchanged lines hidden (view full) --- 689 } 690 if (spa->spa_l2cache.sav_config) { 691 nvlist_free(spa->spa_l2cache.sav_config); 692 spa->spa_l2cache.sav_config = NULL; 693 } 694 spa->spa_l2cache.sav_count = 0; 695 696 spa->spa_async_suspended = 0; | 779 * Close all vdevs. 780 */ 781 if (spa->spa_root_vdev) 782 vdev_free(spa->spa_root_vdev); 783 ASSERT(spa->spa_root_vdev == NULL); 784 785 for (i = 0; i < spa->spa_spares.sav_count; i++) 786 vdev_free(spa->spa_spares.sav_vdevs[i]); --- 17 unchanged lines hidden (view full) --- 804 } 805 if (spa->spa_l2cache.sav_config) { 806 nvlist_free(spa->spa_l2cache.sav_config); 807 spa->spa_l2cache.sav_config = NULL; 808 } 809 spa->spa_l2cache.sav_count = 0; 810 811 spa->spa_async_suspended = 0; |
812 813 spa_config_exit(spa, SCL_ALL, FTAG); |
|
697} 698 699/* 700 * Load (or re-load) the current list of vdevs describing the active spares for 701 * this pool. When this is called, we have some form of basic information in 702 * 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and 703 * then re-generate a more complete list including status information. 704 */ --- 73 unchanged lines hidden (view full) --- 778 * the rarity of this scenario, and the extra complexity 779 * it adds, we ignore the possibility. 780 */ 781 if (!vdev_is_dead(tvd)) 782 spa_spare_activate(tvd); 783 } 784 785 vd->vdev_top = vd; | 814} 815 816/* 817 * Load (or re-load) the current list of vdevs describing the active spares for 818 * this pool. When this is called, we have some form of basic information in 819 * 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and 820 * then re-generate a more complete list including status information. 821 */ --- 73 unchanged lines hidden (view full) --- 895 * the rarity of this scenario, and the extra complexity 896 * it adds, we ignore the possibility. 897 */ 898 if (!vdev_is_dead(tvd)) 899 spa_spare_activate(tvd); 900 } 901 902 vd->vdev_top = vd; |
903 vd->vdev_aux = &spa->spa_spares; |
|
786 787 if (vdev_open(vd) != 0) 788 continue; 789 790 if (vdev_validate_aux(vd) == 0) 791 spa_spare_add(vd); 792 } 793 --- 106 unchanged lines hidden (view full) --- 900 /* 901 * Purge vdevs that were dropped 902 */ 903 for (i = 0; i < oldnvdevs; i++) { 904 uint64_t pool; 905 906 vd = oldvdevs[i]; 907 if (vd != NULL) { | 904 905 if (vdev_open(vd) != 0) 906 continue; 907 908 if (vdev_validate_aux(vd) == 0) 909 spa_spare_add(vd); 910 } 911 --- 106 unchanged lines hidden (view full) --- 1018 /* 1019 * Purge vdevs that were dropped 1020 */ 1021 for (i = 0; i < oldnvdevs; i++) { 1022 uint64_t pool; 1023 1024 vd = oldvdevs[i]; 1025 if (vd != NULL) { |
908 if ((spa_mode & FWRITE) && 909 spa_l2cache_exists(vd->vdev_guid, &pool) && 910 pool != 0ULL && 911 l2arc_vdev_present(vd)) { | 1026 if (spa_l2cache_exists(vd->vdev_guid, &pool) && 1027 pool != 0ULL && l2arc_vdev_present(vd)) |
912 l2arc_remove_vdev(vd); | 1028 l2arc_remove_vdev(vd); |
913 } | |
914 (void) vdev_close(vd); 915 spa_l2cache_remove(vd); 916 } 917 } 918 919 if (oldvdevs) 920 kmem_free(oldvdevs, oldnvdevs * sizeof (void *)); 921 --- 32 unchanged lines hidden (view full) --- 954 int error; 955 *value = NULL; 956 957 VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); 958 nvsize = *(uint64_t *)db->db_data; 959 dmu_buf_rele(db, FTAG); 960 961 packed = kmem_alloc(nvsize, KM_SLEEP); | 1029 (void) vdev_close(vd); 1030 spa_l2cache_remove(vd); 1031 } 1032 } 1033 1034 if (oldvdevs) 1035 kmem_free(oldvdevs, oldnvdevs * sizeof (void *)); 1036 --- 32 unchanged lines hidden (view full) --- 1069 int error; 1070 *value = NULL; 1071 1072 VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); 1073 nvsize = *(uint64_t *)db->db_data; 1074 dmu_buf_rele(db, FTAG); 1075 1076 packed = kmem_alloc(nvsize, KM_SLEEP); |
962 error = dmu_read(spa->spa_meta_objset, obj, 0, nvsize, packed); | 1077 error = dmu_read(spa->spa_meta_objset, obj, 0, nvsize, packed, 1078 DMU_READ_PREFETCH); |
963 if (error == 0) 964 error = nvlist_unpack(packed, nvsize, value, 0); 965 kmem_free(packed, nvsize); 966 967 return (error); 968} 969 970/* --- 50 unchanged lines hidden (view full) --- 1021 int error = 0; 1022 nvlist_t *nvroot = NULL; 1023 vdev_t *rvd; 1024 uberblock_t *ub = &spa->spa_uberblock; 1025 uint64_t config_cache_txg = spa->spa_config_txg; 1026 uint64_t pool_guid; 1027 uint64_t version; 1028 uint64_t autoreplace = 0; | 1079 if (error == 0) 1080 error = nvlist_unpack(packed, nvsize, value, 0); 1081 kmem_free(packed, nvsize); 1082 1083 return (error); 1084} 1085 1086/* --- 50 unchanged lines hidden (view full) --- 1137 int error = 0; 1138 nvlist_t *nvroot = NULL; 1139 vdev_t *rvd; 1140 uberblock_t *ub = &spa->spa_uberblock; 1141 uint64_t config_cache_txg = spa->spa_config_txg; 1142 uint64_t pool_guid; 1143 uint64_t version; 1144 uint64_t autoreplace = 0; |
1145 int orig_mode = spa->spa_mode; |
|
1029 char *ereport = FM_EREPORT_ZFS_POOL; 1030 | 1146 char *ereport = FM_EREPORT_ZFS_POOL; 1147 |
1148 /* 1149 * If this is an untrusted config, access the pool in read-only mode. 1150 * This prevents things like resilvering recently removed devices. 1151 */ 1152 if (!mosconfig) 1153 spa->spa_mode = FREAD; 1154 |
|
1031 ASSERT(MUTEX_HELD(&spa_namespace_lock)); 1032 1033 spa->spa_load_state = state; 1034 1035 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) || 1036 nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) { 1037 error = EINVAL; 1038 goto out; --- 13 unchanged lines hidden (view full) --- 1052 spa_guid_exists(pool_guid, 0)) { 1053 error = EEXIST; 1054 goto out; 1055 } 1056 1057 spa->spa_load_guid = pool_guid; 1058 1059 /* | 1155 ASSERT(MUTEX_HELD(&spa_namespace_lock)); 1156 1157 spa->spa_load_state = state; 1158 1159 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) || 1160 nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) { 1161 error = EINVAL; 1162 goto out; --- 13 unchanged lines hidden (view full) --- 1176 spa_guid_exists(pool_guid, 0)) { 1177 error = EEXIST; 1178 goto out; 1179 } 1180 1181 spa->spa_load_guid = pool_guid; 1182 1183 /* |
1184 * Create "The Godfather" zio to hold all async IOs 1185 */ 1186 spa->spa_async_zio_root = zio_root(spa, NULL, NULL, 1187 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_GODFATHER); 1188 1189 /* |
|
1060 * Parse the configuration into a vdev tree. We explicitly set the 1061 * value that will be returned by spa_version() since parsing the 1062 * configuration requires knowing the version number. 1063 */ 1064 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1065 spa->spa_ubsync.ub_version = version; 1066 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_LOAD); 1067 spa_config_exit(spa, SCL_ALL, FTAG); --- 9 unchanged lines hidden (view full) --- 1077 */ 1078 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1079 error = vdev_open(rvd); 1080 spa_config_exit(spa, SCL_ALL, FTAG); 1081 if (error != 0) 1082 goto out; 1083 1084 /* | 1190 * Parse the configuration into a vdev tree. We explicitly set the 1191 * value that will be returned by spa_version() since parsing the 1192 * configuration requires knowing the version number. 1193 */ 1194 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1195 spa->spa_ubsync.ub_version = version; 1196 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_LOAD); 1197 spa_config_exit(spa, SCL_ALL, FTAG); --- 9 unchanged lines hidden (view full) --- 1207 */ 1208 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1209 error = vdev_open(rvd); 1210 spa_config_exit(spa, SCL_ALL, FTAG); 1211 if (error != 0) 1212 goto out; 1213 1214 /* |
1085 * Validate the labels for all leaf vdevs. We need to grab the config 1086 * lock because all label I/O is done with ZIO_FLAG_CONFIG_WRITER. | 1215 * We need to validate the vdev labels against the configuration that 1216 * we have in hand, which is dependent on the setting of mosconfig. If 1217 * mosconfig is true then we're validating the vdev labels based on 1218 * that config. Otherwise, we're validating against the cached config 1219 * (zpool.cache) that was read when we loaded the zfs module, and then 1220 * later we will recursively call spa_load() and validate against 1221 * the vdev config. |
1087 */ 1088 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1089 error = vdev_validate(rvd); 1090 spa_config_exit(spa, SCL_ALL, FTAG); | 1222 */ 1223 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1224 error = vdev_validate(rvd); 1225 spa_config_exit(spa, SCL_ALL, FTAG); |
1091 | |
1092 if (error != 0) 1093 goto out; 1094 1095 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { 1096 error = ENXIO; 1097 goto out; 1098 } 1099 --- 87 unchanged lines hidden (view full) --- 1187 error = EBADF; 1188 goto out; 1189 } 1190 } 1191 1192 spa_config_set(spa, newconfig); 1193 spa_unload(spa); 1194 spa_deactivate(spa); | 1226 if (error != 0) 1227 goto out; 1228 1229 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { 1230 error = ENXIO; 1231 goto out; 1232 } 1233 --- 87 unchanged lines hidden (view full) --- 1321 error = EBADF; 1322 goto out; 1323 } 1324 } 1325 1326 spa_config_set(spa, newconfig); 1327 spa_unload(spa); 1328 spa_deactivate(spa); |
1195 spa_activate(spa); | 1329 spa_activate(spa, orig_mode); |
1196 1197 return (spa_load(spa, newconfig, state, B_TRUE)); 1198 } 1199 1200 if (zap_lookup(spa->spa_meta_objset, 1201 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, 1202 sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj) != 0) { 1203 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, --- 175 unchanged lines hidden (view full) --- 1379 * Check the state of the root vdev. If it can't be opened, it 1380 * indicates one or more toplevel vdevs are faulted. 1381 */ 1382 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { 1383 error = ENXIO; 1384 goto out; 1385 } 1386 | 1330 1331 return (spa_load(spa, newconfig, state, B_TRUE)); 1332 } 1333 1334 if (zap_lookup(spa->spa_meta_objset, 1335 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, 1336 sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj) != 0) { 1337 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, --- 175 unchanged lines hidden (view full) --- 1513 * Check the state of the root vdev. If it can't be opened, it 1514 * indicates one or more toplevel vdevs are faulted. 1515 */ 1516 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { 1517 error = ENXIO; 1518 goto out; 1519 } 1520 |
1387 if ((spa_mode & FWRITE) && state != SPA_LOAD_TRYIMPORT) { | 1521 if (spa_writeable(spa)) { |
1388 dmu_tx_t *tx; 1389 int need_update = B_FALSE; | 1522 dmu_tx_t *tx; 1523 int need_update = B_FALSE; |
1390 int c; | |
1391 | 1524 |
1525 ASSERT(state != SPA_LOAD_TRYIMPORT); 1526 |
|
1392 /* 1393 * Claim log blocks that haven't been committed yet. 1394 * This must all happen in a single txg. 1395 */ 1396 tx = dmu_tx_create_assigned(spa_get_dsl(spa), 1397 spa_first_txg(spa)); 1398 (void) dmu_objset_find(spa_name(spa), 1399 zil_claim, tx, DS_FIND_CHILDREN); --- 5 unchanged lines hidden (view full) --- 1405 /* 1406 * Wait for all claims to sync. 1407 */ 1408 txg_wait_synced(spa->spa_dsl_pool, 0); 1409 1410 /* 1411 * If the config cache is stale, or we have uninitialized 1412 * metaslabs (see spa_vdev_add()), then update the config. | 1527 /* 1528 * Claim log blocks that haven't been committed yet. 1529 * This must all happen in a single txg. 1530 */ 1531 tx = dmu_tx_create_assigned(spa_get_dsl(spa), 1532 spa_first_txg(spa)); 1533 (void) dmu_objset_find(spa_name(spa), 1534 zil_claim, tx, DS_FIND_CHILDREN); --- 5 unchanged lines hidden (view full) --- 1540 /* 1541 * Wait for all claims to sync. 1542 */ 1543 txg_wait_synced(spa->spa_dsl_pool, 0); 1544 1545 /* 1546 * If the config cache is stale, or we have uninitialized 1547 * metaslabs (see spa_vdev_add()), then update the config. |
1548 * 1549 * If spa_load_verbatim is true, trust the current 1550 * in-core spa_config and update the disk labels. |
|
1413 */ 1414 if (config_cache_txg != spa->spa_config_txg || | 1551 */ 1552 if (config_cache_txg != spa->spa_config_txg || |
1415 state == SPA_LOAD_IMPORT) | 1553 state == SPA_LOAD_IMPORT || spa->spa_load_verbatim) |
1416 need_update = B_TRUE; 1417 | 1554 need_update = B_TRUE; 1555 |
1418 for (c = 0; c < rvd->vdev_children; c++) | 1556 for (int c = 0; c < rvd->vdev_children; c++) |
1419 if (rvd->vdev_child[c]->vdev_ms_array == 0) 1420 need_update = B_TRUE; 1421 1422 /* 1423 * Update the config cache asychronously in case we're the 1424 * root pool, in which case the config cache isn't writable yet. 1425 */ 1426 if (need_update) --- 51 unchanged lines hidden (view full) --- 1478 1479 if ((spa = spa_lookup(pool)) == NULL) { 1480 if (locked) 1481 mutex_exit(&spa_namespace_lock); 1482 return (ENOENT); 1483 } 1484 if (spa->spa_state == POOL_STATE_UNINITIALIZED) { 1485 | 1557 if (rvd->vdev_child[c]->vdev_ms_array == 0) 1558 need_update = B_TRUE; 1559 1560 /* 1561 * Update the config cache asychronously in case we're the 1562 * root pool, in which case the config cache isn't writable yet. 1563 */ 1564 if (need_update) --- 51 unchanged lines hidden (view full) --- 1616 1617 if ((spa = spa_lookup(pool)) == NULL) { 1618 if (locked) 1619 mutex_exit(&spa_namespace_lock); 1620 return (ENOENT); 1621 } 1622 if (spa->spa_state == POOL_STATE_UNINITIALIZED) { 1623 |
1486 spa_activate(spa); | 1624 spa_activate(spa, spa_mode_global); |
1487 1488 error = spa_load(spa, spa->spa_config, SPA_LOAD_OPEN, B_FALSE); 1489 1490 if (error == EBADF) { 1491 /* 1492 * If vdev_validate() returns failure (indicated by 1493 * EBADF), it indicates that one of the vdevs indicates 1494 * that the pool has been exported or destroyed. If --- 86 unchanged lines hidden (view full) --- 1581 nvlist_t **spares; 1582 uint_t i, nspares; 1583 nvlist_t *nvroot; 1584 uint64_t guid; 1585 vdev_stat_t *vs; 1586 uint_t vsc; 1587 uint64_t pool; 1588 | 1625 1626 error = spa_load(spa, spa->spa_config, SPA_LOAD_OPEN, B_FALSE); 1627 1628 if (error == EBADF) { 1629 /* 1630 * If vdev_validate() returns failure (indicated by 1631 * EBADF), it indicates that one of the vdevs indicates 1632 * that the pool has been exported or destroyed. If --- 86 unchanged lines hidden (view full) --- 1719 nvlist_t **spares; 1720 uint_t i, nspares; 1721 nvlist_t *nvroot; 1722 uint64_t guid; 1723 vdev_stat_t *vs; 1724 uint_t vsc; 1725 uint64_t pool; 1726 |
1727 ASSERT(spa_config_held(spa, SCL_CONFIG, RW_READER)); 1728 |
|
1589 if (spa->spa_spares.sav_count == 0) 1590 return; 1591 1592 VERIFY(nvlist_lookup_nvlist(config, 1593 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 1594 VERIFY(nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, 1595 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); 1596 if (nspares != 0) { --- 31 unchanged lines hidden (view full) --- 1628 nvlist_t **l2cache; 1629 uint_t i, j, nl2cache; 1630 nvlist_t *nvroot; 1631 uint64_t guid; 1632 vdev_t *vd; 1633 vdev_stat_t *vs; 1634 uint_t vsc; 1635 | 1729 if (spa->spa_spares.sav_count == 0) 1730 return; 1731 1732 VERIFY(nvlist_lookup_nvlist(config, 1733 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 1734 VERIFY(nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, 1735 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); 1736 if (nspares != 0) { --- 31 unchanged lines hidden (view full) --- 1768 nvlist_t **l2cache; 1769 uint_t i, j, nl2cache; 1770 nvlist_t *nvroot; 1771 uint64_t guid; 1772 vdev_t *vd; 1773 vdev_stat_t *vs; 1774 uint_t vsc; 1775 |
1776 ASSERT(spa_config_held(spa, SCL_CONFIG, RW_READER)); 1777 |
|
1636 if (spa->spa_l2cache.sav_count == 0) 1637 return; 1638 | 1778 if (spa->spa_l2cache.sav_count == 0) 1779 return; 1780 |
1639 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); 1640 | |
1641 VERIFY(nvlist_lookup_nvlist(config, 1642 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 1643 VERIFY(nvlist_lookup_nvlist_array(spa->spa_l2cache.sav_config, 1644 ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); 1645 if (nl2cache != 0) { 1646 VERIFY(nvlist_add_nvlist_array(nvroot, 1647 ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); 1648 VERIFY(nvlist_lookup_nvlist_array(nvroot, --- 17 unchanged lines hidden (view full) --- 1666 } 1667 ASSERT(vd != NULL); 1668 1669 VERIFY(nvlist_lookup_uint64_array(l2cache[i], 1670 ZPOOL_CONFIG_STATS, (uint64_t **)&vs, &vsc) == 0); 1671 vdev_get_stats(vd, vs); 1672 } 1673 } | 1781 VERIFY(nvlist_lookup_nvlist(config, 1782 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 1783 VERIFY(nvlist_lookup_nvlist_array(spa->spa_l2cache.sav_config, 1784 ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); 1785 if (nl2cache != 0) { 1786 VERIFY(nvlist_add_nvlist_array(nvroot, 1787 ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); 1788 VERIFY(nvlist_lookup_nvlist_array(nvroot, --- 17 unchanged lines hidden (view full) --- 1806 } 1807 ASSERT(vd != NULL); 1808 1809 VERIFY(nvlist_lookup_uint64_array(l2cache[i], 1810 ZPOOL_CONFIG_STATS, (uint64_t **)&vs, &vsc) == 0); 1811 vdev_get_stats(vd, vs); 1812 } 1813 } |
1674 1675 spa_config_exit(spa, SCL_CONFIG, FTAG); | |
1676} 1677 1678int 1679spa_get_stats(const char *name, nvlist_t **config, char *altroot, size_t buflen) 1680{ 1681 int error; 1682 spa_t *spa; 1683 1684 *config = NULL; 1685 error = spa_open_common(name, &spa, FTAG, config); 1686 | 1814} 1815 1816int 1817spa_get_stats(const char *name, nvlist_t **config, char *altroot, size_t buflen) 1818{ 1819 int error; 1820 spa_t *spa; 1821 1822 *config = NULL; 1823 error = spa_open_common(name, &spa, FTAG, config); 1824 |
1687 if (spa && *config != NULL) { 1688 VERIFY(nvlist_add_uint64(*config, ZPOOL_CONFIG_ERRCOUNT, 1689 spa_get_errlog_size(spa)) == 0); | 1825 if (spa != NULL) { 1826 /* 1827 * This still leaves a window of inconsistency where the spares 1828 * or l2cache devices could change and the config would be 1829 * self-inconsistent. 1830 */ 1831 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); |
1690 | 1832 |
1691 if (spa_suspended(spa)) | 1833 if (*config != NULL) { |
1692 VERIFY(nvlist_add_uint64(*config, | 1834 VERIFY(nvlist_add_uint64(*config, |
1693 ZPOOL_CONFIG_SUSPENDED, spa->spa_failmode) == 0); | 1835 ZPOOL_CONFIG_ERRCOUNT, 1836 spa_get_errlog_size(spa)) == 0); |
1694 | 1837 |
1695 spa_add_spares(spa, *config); 1696 spa_add_l2cache(spa, *config); | 1838 if (spa_suspended(spa)) 1839 VERIFY(nvlist_add_uint64(*config, 1840 ZPOOL_CONFIG_SUSPENDED, 1841 spa->spa_failmode) == 0); 1842 1843 spa_add_spares(spa, *config); 1844 spa_add_l2cache(spa, *config); 1845 } |
1697 } 1698 1699 /* 1700 * We want to get the alternate root even for faulted pools, so we cheat 1701 * and call spa_lookup() directly. 1702 */ 1703 if (altroot) { 1704 if (spa == NULL) { --- 5 unchanged lines hidden (view full) --- 1710 altroot[0] = '\0'; 1711 spa = NULL; 1712 mutex_exit(&spa_namespace_lock); 1713 } else { 1714 spa_altroot(spa, altroot, buflen); 1715 } 1716 } 1717 | 1846 } 1847 1848 /* 1849 * We want to get the alternate root even for faulted pools, so we cheat 1850 * and call spa_lookup() directly. 1851 */ 1852 if (altroot) { 1853 if (spa == NULL) { --- 5 unchanged lines hidden (view full) --- 1859 altroot[0] = '\0'; 1860 spa = NULL; 1861 mutex_exit(&spa_namespace_lock); 1862 } else { 1863 spa_altroot(spa, altroot, buflen); 1864 } 1865 } 1866 |
1718 if (spa != NULL) | 1867 if (spa != NULL) { 1868 spa_config_exit(spa, SCL_CONFIG, FTAG); |
1719 spa_close(spa, FTAG); | 1869 spa_close(spa, FTAG); |
1870 } |
|
1720 1721 return (error); 1722} 1723 1724/* 1725 * Validate that the auxiliary device array is well formed. We must have an 1726 * array of nvlists, each which describes a valid leaf vdev. If this is an 1727 * import (mode is VDEV_ALLOC_SPARE), then we allow corrupted spares to be --- 154 unchanged lines hidden (view full) --- 1882 spa_aux_vdev_t *sav = &spa->spa_l2cache; 1883 1884 for (i = 0; i < sav->sav_count; i++) { 1885 uint64_t pool; 1886 1887 vd = sav->sav_vdevs[i]; 1888 ASSERT(vd != NULL); 1889 | 1871 1872 return (error); 1873} 1874 1875/* 1876 * Validate that the auxiliary device array is well formed. We must have an 1877 * array of nvlists, each which describes a valid leaf vdev. If this is an 1878 * import (mode is VDEV_ALLOC_SPARE), then we allow corrupted spares to be --- 154 unchanged lines hidden (view full) --- 2033 spa_aux_vdev_t *sav = &spa->spa_l2cache; 2034 2035 for (i = 0; i < sav->sav_count; i++) { 2036 uint64_t pool; 2037 2038 vd = sav->sav_vdevs[i]; 2039 ASSERT(vd != NULL); 2040 |
1890 if ((spa_mode & FWRITE) && 1891 spa_l2cache_exists(vd->vdev_guid, &pool) && pool != 0ULL && 1892 l2arc_vdev_present(vd)) { | 2041 if (spa_l2cache_exists(vd->vdev_guid, &pool) && 2042 pool != 0ULL && l2arc_vdev_present(vd)) |
1893 l2arc_remove_vdev(vd); | 2043 l2arc_remove_vdev(vd); |
1894 } | |
1895 if (vd->vdev_isl2cache) 1896 spa_l2cache_remove(vd); 1897 vdev_clear_stats(vd); 1898 (void) vdev_close(vd); 1899 } 1900} 1901 1902/* --- 24 unchanged lines hidden (view full) --- 1927 } 1928 1929 /* 1930 * Allocate a new spa_t structure. 1931 */ 1932 (void) nvlist_lookup_string(props, 1933 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); 1934 spa = spa_add(pool, altroot); | 2044 if (vd->vdev_isl2cache) 2045 spa_l2cache_remove(vd); 2046 vdev_clear_stats(vd); 2047 (void) vdev_close(vd); 2048 } 2049} 2050 2051/* --- 24 unchanged lines hidden (view full) --- 2076 } 2077 2078 /* 2079 * Allocate a new spa_t structure. 2080 */ 2081 (void) nvlist_lookup_string(props, 2082 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); 2083 spa = spa_add(pool, altroot); |
1935 spa_activate(spa); | 2084 spa_activate(spa, spa_mode_global); |
1936 1937 spa->spa_uberblock.ub_txg = txg - 1; 1938 1939 if (props && (error = spa_prop_validate(spa, props))) { | 2085 2086 spa->spa_uberblock.ub_txg = txg - 1; 2087 2088 if (props && (error = spa_prop_validate(spa, props))) { |
1940 spa_unload(spa); | |
1941 spa_deactivate(spa); 1942 spa_remove(spa); 1943 mutex_exit(&spa_namespace_lock); 1944 return (error); 1945 } 1946 1947 if (nvlist_lookup_uint64(props, zpool_prop_to_name(ZPOOL_PROP_VERSION), 1948 &version) != 0) 1949 version = SPA_VERSION; 1950 ASSERT(version <= SPA_VERSION); 1951 spa->spa_uberblock.ub_version = version; 1952 spa->spa_ubsync = spa->spa_uberblock; 1953 1954 /* | 2089 spa_deactivate(spa); 2090 spa_remove(spa); 2091 mutex_exit(&spa_namespace_lock); 2092 return (error); 2093 } 2094 2095 if (nvlist_lookup_uint64(props, zpool_prop_to_name(ZPOOL_PROP_VERSION), 2096 &version) != 0) 2097 version = SPA_VERSION; 2098 ASSERT(version <= SPA_VERSION); 2099 spa->spa_uberblock.ub_version = version; 2100 spa->spa_ubsync = spa->spa_uberblock; 2101 2102 /* |
2103 * Create "The Godfather" zio to hold all async IOs 2104 */ 2105 spa->spa_async_zio_root = zio_root(spa, NULL, NULL, 2106 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_GODFATHER); 2107 2108 /* |
|
1955 * Create the root vdev. 1956 */ 1957 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 1958 1959 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_ADD); 1960 1961 ASSERT(error != 0 || rvd != NULL); 1962 ASSERT(error != 0 || spa->spa_root_vdev == rvd); --- 101 unchanged lines hidden (view full) --- 2064 spa_history_create_obj(spa, tx); 2065 2066 /* 2067 * Set pool properties. 2068 */ 2069 spa->spa_bootfs = zpool_prop_default_numeric(ZPOOL_PROP_BOOTFS); 2070 spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION); 2071 spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE); | 2109 * Create the root vdev. 2110 */ 2111 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2112 2113 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_ADD); 2114 2115 ASSERT(error != 0 || rvd != NULL); 2116 ASSERT(error != 0 || spa->spa_root_vdev == rvd); --- 101 unchanged lines hidden (view full) --- 2218 spa_history_create_obj(spa, tx); 2219 2220 /* 2221 * Set pool properties. 2222 */ 2223 spa->spa_bootfs = zpool_prop_default_numeric(ZPOOL_PROP_BOOTFS); 2224 spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION); 2225 spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE); |
2072 if (props) | 2226 if (props != NULL) { 2227 spa_configfile_set(spa, props, B_FALSE); |
2073 spa_sync_props(spa, props, CRED(), tx); | 2228 spa_sync_props(spa, props, CRED(), tx); |
2229 } |
|
2074 2075 dmu_tx_commit(tx); 2076 2077 spa->spa_sync_on = B_TRUE; 2078 txg_sync_start(spa->spa_dsl_pool); 2079 2080 /* 2081 * We explicitly wait for the first transaction to complete so that our --- 8 unchanged lines hidden (view full) --- 2090 2091 spa->spa_minref = refcount_count(&spa->spa_refcount); 2092 2093 mutex_exit(&spa_namespace_lock); 2094 2095 return (0); 2096} 2097 | 2230 2231 dmu_tx_commit(tx); 2232 2233 spa->spa_sync_on = B_TRUE; 2234 txg_sync_start(spa->spa_dsl_pool); 2235 2236 /* 2237 * We explicitly wait for the first transaction to complete so that our --- 8 unchanged lines hidden (view full) --- 2246 2247 spa->spa_minref = refcount_count(&spa->spa_refcount); 2248 2249 mutex_exit(&spa_namespace_lock); 2250 2251 return (0); 2252} 2253 |
2098/* 2099 * Import the given pool into the system. We set up the necessary spa_t and 2100 * then call spa_load() to do the dirty work. 2101 */ 2102static int 2103spa_import_common(const char *pool, nvlist_t *config, nvlist_t *props, 2104 boolean_t isroot, boolean_t allowfaulted) 2105{ 2106 spa_t *spa; 2107 char *altroot = NULL; 2108 int error, loaderr; 2109 nvlist_t *nvroot; 2110 nvlist_t **spares, **l2cache; 2111 uint_t nspares, nl2cache; 2112 2113 /* 2114 * If a pool with this name exists, return failure. 2115 */ 2116 mutex_enter(&spa_namespace_lock); 2117 if (spa_lookup(pool) != NULL) { 2118 mutex_exit(&spa_namespace_lock); 2119 return (EEXIST); 2120 } 2121 2122 /* 2123 * Create and initialize the spa structure. 2124 */ 2125 (void) nvlist_lookup_string(props, 2126 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); 2127 spa = spa_add(pool, altroot); 2128 spa_activate(spa); 2129 2130 if (allowfaulted) 2131 spa->spa_import_faulted = B_TRUE; 2132 spa->spa_is_root = isroot; 2133 2134 /* 2135 * Pass off the heavy lifting to spa_load(). 2136 * Pass TRUE for mosconfig (unless this is a root pool) because 2137 * the user-supplied config is actually the one to trust when 2138 * doing an import. 2139 */ 2140 loaderr = error = spa_load(spa, config, SPA_LOAD_IMPORT, !isroot); 2141 2142 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2143 /* 2144 * Toss any existing sparelist, as it doesn't have any validity anymore, 2145 * and conflicts with spa_has_spare(). 2146 */ 2147 if (!isroot && spa->spa_spares.sav_config) { 2148 nvlist_free(spa->spa_spares.sav_config); 2149 spa->spa_spares.sav_config = NULL; 2150 spa_load_spares(spa); 2151 } 2152 if (!isroot && spa->spa_l2cache.sav_config) { 2153 nvlist_free(spa->spa_l2cache.sav_config); 2154 spa->spa_l2cache.sav_config = NULL; 2155 spa_load_l2cache(spa); 2156 } 2157 2158 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, 2159 &nvroot) == 0); 2160 if (error == 0) 2161 error = spa_validate_aux(spa, nvroot, -1ULL, VDEV_ALLOC_SPARE); 2162 if (error == 0) 2163 error = spa_validate_aux(spa, nvroot, -1ULL, 2164 VDEV_ALLOC_L2CACHE); 2165 spa_config_exit(spa, SCL_ALL, FTAG); 2166 2167 if (error != 0 || (props && (error = spa_prop_set(spa, props)))) { 2168 if (loaderr != 0 && loaderr != EINVAL && allowfaulted) { 2169 /* 2170 * If we failed to load the pool, but 'allowfaulted' is 2171 * set, then manually set the config as if the config 2172 * passed in was specified in the cache file. 2173 */ 2174 error = 0; 2175 spa->spa_import_faulted = B_FALSE; 2176 if (spa->spa_config == NULL) 2177 spa->spa_config = spa_config_generate(spa, 2178 NULL, -1ULL, B_TRUE); 2179 spa_unload(spa); 2180 spa_deactivate(spa); 2181 spa_config_sync(spa, B_FALSE, B_TRUE); 2182 } else { 2183 spa_unload(spa); 2184 spa_deactivate(spa); 2185 spa_remove(spa); 2186 } 2187 mutex_exit(&spa_namespace_lock); 2188 return (error); 2189 } 2190 2191 /* 2192 * Override any spares and level 2 cache devices as specified by 2193 * the user, as these may have correct device names/devids, etc. 2194 */ 2195 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 2196 &spares, &nspares) == 0) { 2197 if (spa->spa_spares.sav_config) 2198 VERIFY(nvlist_remove(spa->spa_spares.sav_config, 2199 ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0); 2200 else 2201 VERIFY(nvlist_alloc(&spa->spa_spares.sav_config, 2202 NV_UNIQUE_NAME, KM_SLEEP) == 0); 2203 VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config, 2204 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); 2205 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2206 spa_load_spares(spa); 2207 spa_config_exit(spa, SCL_ALL, FTAG); 2208 spa->spa_spares.sav_sync = B_TRUE; 2209 } 2210 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, 2211 &l2cache, &nl2cache) == 0) { 2212 if (spa->spa_l2cache.sav_config) 2213 VERIFY(nvlist_remove(spa->spa_l2cache.sav_config, 2214 ZPOOL_CONFIG_L2CACHE, DATA_TYPE_NVLIST_ARRAY) == 0); 2215 else 2216 VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config, 2217 NV_UNIQUE_NAME, KM_SLEEP) == 0); 2218 VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config, 2219 ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); 2220 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2221 spa_load_l2cache(spa); 2222 spa_config_exit(spa, SCL_ALL, FTAG); 2223 spa->spa_l2cache.sav_sync = B_TRUE; 2224 } 2225 2226 if (spa_mode & FWRITE) { 2227 /* 2228 * Update the config cache to include the newly-imported pool. 2229 */ 2230 spa_config_update_common(spa, SPA_CONFIG_UPDATE_POOL, isroot); 2231 } 2232 2233 spa->spa_import_faulted = B_FALSE; 2234 mutex_exit(&spa_namespace_lock); 2235 2236 return (0); 2237} 2238 2239#if defined(sun) | 2254#ifdef sun |
2240#ifdef _KERNEL 2241/* 2242 * Build a "root" vdev for a top level vdev read in from a rootpool 2243 * device label. 2244 */ 2245static void 2246spa_build_rootpool_config(nvlist_t *config) 2247{ --- 119 unchanged lines hidden (view full) --- 2367 * Go thru vdevs in the mirror to see if the given device 2368 * has the most recent txg. Only the device with the most 2369 * recent txg has valid information and should be booted. 2370 */ 2371 for (c = 0; c < children; c++) { 2372 char *cdevid, *cpath; 2373 uint64_t tmptxg; 2374 | 2255#ifdef _KERNEL 2256/* 2257 * Build a "root" vdev for a top level vdev read in from a rootpool 2258 * device label. 2259 */ 2260static void 2261spa_build_rootpool_config(nvlist_t *config) 2262{ --- 119 unchanged lines hidden (view full) --- 2382 * Go thru vdevs in the mirror to see if the given device 2383 * has the most recent txg. Only the device with the most 2384 * recent txg has valid information and should be booted. 2385 */ 2386 for (c = 0; c < children; c++) { 2387 char *cdevid, *cpath; 2388 uint64_t tmptxg; 2389 |
2390 cpath = NULL; 2391 cdevid = NULL; |
|
2375 if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_PHYS_PATH, | 2392 if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_PHYS_PATH, |
2376 &cpath) != 0) | 2393 &cpath) != 0 && nvlist_lookup_string(child[c], 2394 ZPOOL_CONFIG_DEVID, &cdevid) != 0) |
2377 return (EINVAL); | 2395 return (EINVAL); |
2378 if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_DEVID, 2379 &cdevid) != 0) 2380 return (EINVAL); | |
2381 if ((spa_check_rootconf(cpath, cdevid, NULL, 2382 &tmptxg) == 0) && (tmptxg > txg)) { 2383 txg = tmptxg; 2384 VERIFY(nvlist_lookup_string(child[c], 2385 ZPOOL_CONFIG_PATH, &bootpath) == 0); 2386 } 2387 } 2388 --- 20 unchanged lines hidden (view full) --- 2409 * "/pci@1f,0/ide@d/disk@0,0:a" 2410 */ 2411int 2412spa_import_rootpool(char *devpath, char *devid) 2413{ 2414 nvlist_t *conf = NULL; 2415 char *pname; 2416 int error; | 2396 if ((spa_check_rootconf(cpath, cdevid, NULL, 2397 &tmptxg) == 0) && (tmptxg > txg)) { 2398 txg = tmptxg; 2399 VERIFY(nvlist_lookup_string(child[c], 2400 ZPOOL_CONFIG_PATH, &bootpath) == 0); 2401 } 2402 } 2403 --- 20 unchanged lines hidden (view full) --- 2424 * "/pci@1f,0/ide@d/disk@0,0:a" 2425 */ 2426int 2427spa_import_rootpool(char *devpath, char *devid) 2428{ 2429 nvlist_t *conf = NULL; 2430 char *pname; 2431 int error; |
2432 spa_t *spa; |
|
2417 2418 /* 2419 * Get the vdev pathname and configuation from the most 2420 * recently updated vdev (highest txg). 2421 */ 2422 if (error = spa_get_rootconf(devpath, devid, &conf)) 2423 goto msg_out; 2424 2425 /* 2426 * Add type "root" vdev to the config. 2427 */ 2428 spa_build_rootpool_config(conf); 2429 2430 VERIFY(nvlist_lookup_string(conf, ZPOOL_CONFIG_POOL_NAME, &pname) == 0); 2431 | 2433 2434 /* 2435 * Get the vdev pathname and configuation from the most 2436 * recently updated vdev (highest txg). 2437 */ 2438 if (error = spa_get_rootconf(devpath, devid, &conf)) 2439 goto msg_out; 2440 2441 /* 2442 * Add type "root" vdev to the config. 2443 */ 2444 spa_build_rootpool_config(conf); 2445 2446 VERIFY(nvlist_lookup_string(conf, ZPOOL_CONFIG_POOL_NAME, &pname) == 0); 2447 |
2432 /* 2433 * We specify 'allowfaulted' for this to be treated like spa_open() 2434 * instead of spa_import(). This prevents us from marking vdevs as 2435 * persistently unavailable, and generates FMA ereports as if it were a 2436 * pool open, not import. 2437 */ 2438 error = spa_import_common(pname, conf, NULL, B_TRUE, B_TRUE); 2439 if (error == EEXIST) 2440 error = 0; | 2448 mutex_enter(&spa_namespace_lock); 2449 if ((spa = spa_lookup(pname)) != NULL) { 2450 /* 2451 * Remove the existing root pool from the namespace so that we 2452 * can replace it with the correct config we just read in. 2453 */ 2454 spa_remove(spa); 2455 } |
2441 | 2456 |
2457 spa = spa_add(pname, NULL); 2458 spa->spa_is_root = B_TRUE; 2459 spa->spa_load_verbatim = B_TRUE; 2460 2461 VERIFY(nvlist_dup(conf, &spa->spa_config, 0) == 0); 2462 mutex_exit(&spa_namespace_lock); 2463 |
|
2442 nvlist_free(conf); | 2464 nvlist_free(conf); |
2443 return (error); | 2465 return (0); |
2444 2445msg_out: 2446 cmn_err(CE_NOTE, "\n" 2447 " *************************************************** \n" 2448 " * This device is not bootable! * \n" 2449 " * It is either offlined or detached or faulted. * \n" 2450 " * Please try to boot from a different device. * \n" 2451 " *************************************************** "); 2452 2453 return (error); 2454} 2455#endif | 2466 2467msg_out: 2468 cmn_err(CE_NOTE, "\n" 2469 " *************************************************** \n" 2470 " * This device is not bootable! * \n" 2471 " * It is either offlined or detached or faulted. * \n" 2472 " * Please try to boot from a different device. * \n" 2473 " *************************************************** "); 2474 2475 return (error); 2476} 2477#endif |
2456#endif | 2478#endif /* sun */ |
2457 2458/* | 2479 2480/* |
2459 * Import a non-root pool into the system. | 2481 * Take a pool and insert it into the namespace as if it had been loaded at 2482 * boot. |
2460 */ 2461int | 2483 */ 2484int |
2462spa_import(const char *pool, nvlist_t *config, nvlist_t *props) | 2485spa_import_verbatim(const char *pool, nvlist_t *config, nvlist_t *props) |
2463{ | 2486{ |
2464 return (spa_import_common(pool, config, props, B_FALSE, B_FALSE)); | 2487 spa_t *spa; 2488 char *altroot = NULL; 2489 2490 mutex_enter(&spa_namespace_lock); 2491 if (spa_lookup(pool) != NULL) { 2492 mutex_exit(&spa_namespace_lock); 2493 return (EEXIST); 2494 } 2495 2496 (void) nvlist_lookup_string(props, 2497 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); 2498 spa = spa_add(pool, altroot); 2499 2500 spa->spa_load_verbatim = B_TRUE; 2501 2502 VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0); 2503 2504 if (props != NULL) 2505 spa_configfile_set(spa, props, B_FALSE); 2506 2507 spa_config_sync(spa, B_FALSE, B_TRUE); 2508 2509 mutex_exit(&spa_namespace_lock); 2510 2511 return (0); |
2465} 2466 | 2512} 2513 |
2514/* 2515 * Import a non-root pool into the system. 2516 */ |
|
2467int | 2517int |
2468spa_import_faulted(const char *pool, nvlist_t *config, nvlist_t *props) | 2518spa_import(const char *pool, nvlist_t *config, nvlist_t *props) |
2469{ | 2519{ |
2470 return (spa_import_common(pool, config, props, B_FALSE, B_TRUE)); 2471} | 2520 spa_t *spa; 2521 char *altroot = NULL; 2522 int error; 2523 nvlist_t *nvroot; 2524 nvlist_t **spares, **l2cache; 2525 uint_t nspares, nl2cache; |
2472 | 2526 |
2527 /* 2528 * If a pool with this name exists, return failure. 2529 */ 2530 mutex_enter(&spa_namespace_lock); 2531 if ((spa = spa_lookup(pool)) != NULL) { 2532 mutex_exit(&spa_namespace_lock); 2533 return (EEXIST); 2534 } |
|
2473 | 2535 |
2536 /* 2537 * Create and initialize the spa structure. 2538 */ 2539 (void) nvlist_lookup_string(props, 2540 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); 2541 spa = spa_add(pool, altroot); 2542 spa_activate(spa, spa_mode_global); 2543 2544 /* 2545 * Don't start async tasks until we know everything is healthy. 2546 */ 2547 spa_async_suspend(spa); 2548 2549 /* 2550 * Pass off the heavy lifting to spa_load(). Pass TRUE for mosconfig 2551 * because the user-supplied config is actually the one to trust when 2552 * doing an import. 2553 */ 2554 error = spa_load(spa, config, SPA_LOAD_IMPORT, B_TRUE); 2555 2556 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2557 /* 2558 * Toss any existing sparelist, as it doesn't have any validity 2559 * anymore, and conflicts with spa_has_spare(). 2560 */ 2561 if (spa->spa_spares.sav_config) { 2562 nvlist_free(spa->spa_spares.sav_config); 2563 spa->spa_spares.sav_config = NULL; 2564 spa_load_spares(spa); 2565 } 2566 if (spa->spa_l2cache.sav_config) { 2567 nvlist_free(spa->spa_l2cache.sav_config); 2568 spa->spa_l2cache.sav_config = NULL; 2569 spa_load_l2cache(spa); 2570 } 2571 2572 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, 2573 &nvroot) == 0); 2574 if (error == 0) 2575 error = spa_validate_aux(spa, nvroot, -1ULL, 2576 VDEV_ALLOC_SPARE); 2577 if (error == 0) 2578 error = spa_validate_aux(spa, nvroot, -1ULL, 2579 VDEV_ALLOC_L2CACHE); 2580 spa_config_exit(spa, SCL_ALL, FTAG); 2581 2582 if (props != NULL) 2583 spa_configfile_set(spa, props, B_FALSE); 2584 2585 if (error != 0 || (props && spa_writeable(spa) && 2586 (error = spa_prop_set(spa, props)))) { 2587 spa_unload(spa); 2588 spa_deactivate(spa); 2589 spa_remove(spa); 2590 mutex_exit(&spa_namespace_lock); 2591 return (error); 2592 } 2593 2594 spa_async_resume(spa); 2595 2596 /* 2597 * Override any spares and level 2 cache devices as specified by 2598 * the user, as these may have correct device names/devids, etc. 2599 */ 2600 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 2601 &spares, &nspares) == 0) { 2602 if (spa->spa_spares.sav_config) 2603 VERIFY(nvlist_remove(spa->spa_spares.sav_config, 2604 ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0); 2605 else 2606 VERIFY(nvlist_alloc(&spa->spa_spares.sav_config, 2607 NV_UNIQUE_NAME, KM_SLEEP) == 0); 2608 VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config, 2609 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); 2610 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2611 spa_load_spares(spa); 2612 spa_config_exit(spa, SCL_ALL, FTAG); 2613 spa->spa_spares.sav_sync = B_TRUE; 2614 } 2615 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, 2616 &l2cache, &nl2cache) == 0) { 2617 if (spa->spa_l2cache.sav_config) 2618 VERIFY(nvlist_remove(spa->spa_l2cache.sav_config, 2619 ZPOOL_CONFIG_L2CACHE, DATA_TYPE_NVLIST_ARRAY) == 0); 2620 else 2621 VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config, 2622 NV_UNIQUE_NAME, KM_SLEEP) == 0); 2623 VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config, 2624 ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); 2625 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 2626 spa_load_l2cache(spa); 2627 spa_config_exit(spa, SCL_ALL, FTAG); 2628 spa->spa_l2cache.sav_sync = B_TRUE; 2629 } 2630 2631 if (spa_writeable(spa)) { 2632 /* 2633 * Update the config cache to include the newly-imported pool. 2634 */ 2635 spa_config_update(spa, SPA_CONFIG_UPDATE_POOL); 2636 } 2637 2638 mutex_exit(&spa_namespace_lock); 2639 2640 return (0); 2641} 2642 |
|
2474/* 2475 * This (illegal) pool name is used when temporarily importing a spa_t in order 2476 * to get the vdev stats associated with the imported devices. 2477 */ 2478#define TRYIMPORT_NAME "$import" 2479 2480nvlist_t * 2481spa_tryimport(nvlist_t *tryconfig) --- 10 unchanged lines hidden (view full) --- 2492 if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state)) 2493 return (NULL); 2494 2495 /* 2496 * Create and initialize the spa structure. 2497 */ 2498 mutex_enter(&spa_namespace_lock); 2499 spa = spa_add(TRYIMPORT_NAME, NULL); | 2643/* 2644 * This (illegal) pool name is used when temporarily importing a spa_t in order 2645 * to get the vdev stats associated with the imported devices. 2646 */ 2647#define TRYIMPORT_NAME "$import" 2648 2649nvlist_t * 2650spa_tryimport(nvlist_t *tryconfig) --- 10 unchanged lines hidden (view full) --- 2661 if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state)) 2662 return (NULL); 2663 2664 /* 2665 * Create and initialize the spa structure. 2666 */ 2667 mutex_enter(&spa_namespace_lock); 2668 spa = spa_add(TRYIMPORT_NAME, NULL); |
2500 spa_activate(spa); | 2669 spa_activate(spa, FREAD); |
2501 2502 /* 2503 * Pass off the heavy lifting to spa_load(). 2504 * Pass TRUE for mosconfig because the user-supplied config 2505 * is actually the one to trust when doing an import. 2506 */ 2507 error = spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE); 2508 --- 39 unchanged lines hidden (view full) --- 2548 kmem_free(dsname, MAXPATHLEN); 2549 } 2550 kmem_free(tmpname, MAXPATHLEN); 2551 } 2552 2553 /* 2554 * Add the list of hot spares and level 2 cache devices. 2555 */ | 2670 2671 /* 2672 * Pass off the heavy lifting to spa_load(). 2673 * Pass TRUE for mosconfig because the user-supplied config 2674 * is actually the one to trust when doing an import. 2675 */ 2676 error = spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE); 2677 --- 39 unchanged lines hidden (view full) --- 2717 kmem_free(dsname, MAXPATHLEN); 2718 } 2719 kmem_free(tmpname, MAXPATHLEN); 2720 } 2721 2722 /* 2723 * Add the list of hot spares and level 2 cache devices. 2724 */ |
2725 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); |
|
2556 spa_add_spares(spa, config); 2557 spa_add_l2cache(spa, config); | 2726 spa_add_spares(spa, config); 2727 spa_add_l2cache(spa, config); |
2728 spa_config_exit(spa, SCL_CONFIG, FTAG); |
|
2558 } 2559 2560 spa_unload(spa); 2561 spa_deactivate(spa); 2562 spa_remove(spa); 2563 mutex_exit(&spa_namespace_lock); 2564 2565 return (config); --- 12 unchanged lines hidden (view full) --- 2578spa_export_common(char *pool, int new_state, nvlist_t **oldconfig, 2579 boolean_t force, boolean_t hardforce) 2580{ 2581 spa_t *spa; 2582 2583 if (oldconfig) 2584 *oldconfig = NULL; 2585 | 2729 } 2730 2731 spa_unload(spa); 2732 spa_deactivate(spa); 2733 spa_remove(spa); 2734 mutex_exit(&spa_namespace_lock); 2735 2736 return (config); --- 12 unchanged lines hidden (view full) --- 2749spa_export_common(char *pool, int new_state, nvlist_t **oldconfig, 2750 boolean_t force, boolean_t hardforce) 2751{ 2752 spa_t *spa; 2753 2754 if (oldconfig) 2755 *oldconfig = NULL; 2756 |
2586 if (!(spa_mode & FWRITE)) | 2757 if (!(spa_mode_global & FWRITE)) |
2587 return (EROFS); 2588 2589 mutex_enter(&spa_namespace_lock); 2590 if ((spa = spa_lookup(pool)) == NULL) { 2591 mutex_exit(&spa_namespace_lock); 2592 return (ENOENT); 2593 } 2594 --- 118 unchanged lines hidden (view full) --- 2713 2714/* 2715 * Add a device to a storage pool. 2716 */ 2717int 2718spa_vdev_add(spa_t *spa, nvlist_t *nvroot) 2719{ 2720 uint64_t txg; | 2758 return (EROFS); 2759 2760 mutex_enter(&spa_namespace_lock); 2761 if ((spa = spa_lookup(pool)) == NULL) { 2762 mutex_exit(&spa_namespace_lock); 2763 return (ENOENT); 2764 } 2765 --- 118 unchanged lines hidden (view full) --- 2884 2885/* 2886 * Add a device to a storage pool. 2887 */ 2888int 2889spa_vdev_add(spa_t *spa, nvlist_t *nvroot) 2890{ 2891 uint64_t txg; |
2721 int c, error; | 2892 int error; |
2722 vdev_t *rvd = spa->spa_root_vdev; 2723 vdev_t *vd, *tvd; 2724 nvlist_t **spares, **l2cache; 2725 uint_t nspares, nl2cache; 2726 2727 txg = spa_vdev_enter(spa); 2728 2729 if ((error = spa_config_parse(spa, &vd, nvroot, NULL, 0, --- 22 unchanged lines hidden (view full) --- 2752 * children. Otherwise, vdev_inuse() will blindly overwrite the spare. 2753 */ 2754 if ((error = spa_validate_aux(spa, nvroot, txg, VDEV_ALLOC_ADD)) != 0) 2755 return (spa_vdev_exit(spa, vd, txg, error)); 2756 2757 /* 2758 * Transfer each new top-level vdev from vd to rvd. 2759 */ | 2893 vdev_t *rvd = spa->spa_root_vdev; 2894 vdev_t *vd, *tvd; 2895 nvlist_t **spares, **l2cache; 2896 uint_t nspares, nl2cache; 2897 2898 txg = spa_vdev_enter(spa); 2899 2900 if ((error = spa_config_parse(spa, &vd, nvroot, NULL, 0, --- 22 unchanged lines hidden (view full) --- 2923 * children. Otherwise, vdev_inuse() will blindly overwrite the spare. 2924 */ 2925 if ((error = spa_validate_aux(spa, nvroot, txg, VDEV_ALLOC_ADD)) != 0) 2926 return (spa_vdev_exit(spa, vd, txg, error)); 2927 2928 /* 2929 * Transfer each new top-level vdev from vd to rvd. 2930 */ |
2760 for (c = 0; c < vd->vdev_children; c++) { | 2931 for (int c = 0; c < vd->vdev_children; c++) { |
2761 tvd = vd->vdev_child[c]; 2762 vdev_remove_child(vd, tvd); 2763 tvd->vdev_id = rvd->vdev_children; 2764 vdev_add_child(rvd, tvd); 2765 vdev_config_dirty(tvd); 2766 } 2767 2768 if (nspares != 0) { --- 191 unchanged lines hidden (view full) --- 2960 vdev_config_dirty(tvd); 2961 2962 /* 2963 * Set newvd's DTL to [TXG_INITIAL, open_txg]. It will propagate 2964 * upward when spa_vdev_exit() calls vdev_dtl_reassess(). 2965 */ 2966 open_txg = txg + TXG_CONCURRENT_STATES - 1; 2967 | 2932 tvd = vd->vdev_child[c]; 2933 vdev_remove_child(vd, tvd); 2934 tvd->vdev_id = rvd->vdev_children; 2935 vdev_add_child(rvd, tvd); 2936 vdev_config_dirty(tvd); 2937 } 2938 2939 if (nspares != 0) { --- 191 unchanged lines hidden (view full) --- 3131 vdev_config_dirty(tvd); 3132 3133 /* 3134 * Set newvd's DTL to [TXG_INITIAL, open_txg]. It will propagate 3135 * upward when spa_vdev_exit() calls vdev_dtl_reassess(). 3136 */ 3137 open_txg = txg + TXG_CONCURRENT_STATES - 1; 3138 |
2968 mutex_enter(&newvd->vdev_dtl_lock); 2969 space_map_add(&newvd->vdev_dtl_map, TXG_INITIAL, 2970 open_txg - TXG_INITIAL + 1); 2971 mutex_exit(&newvd->vdev_dtl_lock); | 3139 vdev_dtl_dirty(newvd, DTL_MISSING, 3140 TXG_INITIAL, open_txg - TXG_INITIAL + 1); |
2972 | 3141 |
2973 if (newvd->vdev_isspare) | 3142 if (newvd->vdev_isspare) { |
2974 spa_spare_activate(newvd); | 3143 spa_spare_activate(newvd); |
3144 spa_event_notify(spa, newvd, ESC_ZFS_VDEV_SPARE); 3145 } 3146 |
|
2975 oldvdpath = spa_strdup(oldvd->vdev_path); 2976 newvdpath = spa_strdup(newvd->vdev_path); 2977 newvd_isspare = newvd->vdev_isspare; 2978 2979 /* 2980 * Mark newvd's DTL dirty in this txg. 2981 */ 2982 vdev_dirty(tvd, VDD_DTL, newvd, txg); --- 24 unchanged lines hidden (view full) --- 3007} 3008 3009/* 3010 * Detach a device from a mirror or replacing vdev. 3011 * If 'replace_done' is specified, only detach if the parent 3012 * is a replacing vdev. 3013 */ 3014int | 3147 oldvdpath = spa_strdup(oldvd->vdev_path); 3148 newvdpath = spa_strdup(newvd->vdev_path); 3149 newvd_isspare = newvd->vdev_isspare; 3150 3151 /* 3152 * Mark newvd's DTL dirty in this txg. 3153 */ 3154 vdev_dirty(tvd, VDD_DTL, newvd, txg); --- 24 unchanged lines hidden (view full) --- 3179} 3180 3181/* 3182 * Detach a device from a mirror or replacing vdev. 3183 * If 'replace_done' is specified, only detach if the parent 3184 * is a replacing vdev. 3185 */ 3186int |
3015spa_vdev_detach(spa_t *spa, uint64_t guid, int replace_done) | 3187spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done) |
3016{ 3017 uint64_t txg; | 3188{ 3189 uint64_t txg; |
3018 int c, t, error; | 3190 int error; |
3019 vdev_t *rvd = spa->spa_root_vdev; 3020 vdev_t *vd, *pvd, *cvd, *tvd; 3021 boolean_t unspare = B_FALSE; 3022 uint64_t unspare_guid; 3023 size_t len; 3024 3025 txg = spa_vdev_enter(spa); 3026 3027 vd = spa_lookup_by_guid(spa, guid, B_FALSE); 3028 3029 if (vd == NULL) 3030 return (spa_vdev_exit(spa, NULL, txg, ENODEV)); 3031 3032 if (!vd->vdev_ops->vdev_op_leaf) 3033 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3034 3035 pvd = vd->vdev_parent; 3036 3037 /* | 3191 vdev_t *rvd = spa->spa_root_vdev; 3192 vdev_t *vd, *pvd, *cvd, *tvd; 3193 boolean_t unspare = B_FALSE; 3194 uint64_t unspare_guid; 3195 size_t len; 3196 3197 txg = spa_vdev_enter(spa); 3198 3199 vd = spa_lookup_by_guid(spa, guid, B_FALSE); 3200 3201 if (vd == NULL) 3202 return (spa_vdev_exit(spa, NULL, txg, ENODEV)); 3203 3204 if (!vd->vdev_ops->vdev_op_leaf) 3205 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3206 3207 pvd = vd->vdev_parent; 3208 3209 /* |
3210 * If the parent/child relationship is not as expected, don't do it. 3211 * Consider M(A,R(B,C)) -- that is, a mirror of A with a replacing 3212 * vdev that's replacing B with C. The user's intent in replacing 3213 * is to go from M(A,B) to M(A,C). If the user decides to cancel 3214 * the replace by detaching C, the expected behavior is to end up 3215 * M(A,B). But suppose that right after deciding to detach C, 3216 * the replacement of B completes. We would have M(A,C), and then 3217 * ask to detach C, which would leave us with just A -- not what 3218 * the user wanted. To prevent this, we make sure that the 3219 * parent/child relationship hasn't changed -- in this example, 3220 * that C's parent is still the replacing vdev R. 3221 */ 3222 if (pvd->vdev_guid != pguid && pguid != 0) 3223 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); 3224 3225 /* |
|
3038 * If replace_done is specified, only remove this device if it's 3039 * the first child of a replacing vdev. For the 'spare' vdev, either 3040 * disk can be removed. 3041 */ 3042 if (replace_done) { 3043 if (pvd->vdev_ops == &vdev_replacing_ops) { 3044 if (vd->vdev_id != 0) 3045 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); --- 9 unchanged lines hidden (view full) --- 3055 * Only mirror, replacing, and spare vdevs support detach. 3056 */ 3057 if (pvd->vdev_ops != &vdev_replacing_ops && 3058 pvd->vdev_ops != &vdev_mirror_ops && 3059 pvd->vdev_ops != &vdev_spare_ops) 3060 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3061 3062 /* | 3226 * If replace_done is specified, only remove this device if it's 3227 * the first child of a replacing vdev. For the 'spare' vdev, either 3228 * disk can be removed. 3229 */ 3230 if (replace_done) { 3231 if (pvd->vdev_ops == &vdev_replacing_ops) { 3232 if (vd->vdev_id != 0) 3233 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); --- 9 unchanged lines hidden (view full) --- 3243 * Only mirror, replacing, and spare vdevs support detach. 3244 */ 3245 if (pvd->vdev_ops != &vdev_replacing_ops && 3246 pvd->vdev_ops != &vdev_mirror_ops && 3247 pvd->vdev_ops != &vdev_spare_ops) 3248 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3249 3250 /* |
3063 * If there's only one replica, you can't detach it. | 3251 * If this device has the only valid copy of some data, 3252 * we cannot safely detach it. |
3064 */ | 3253 */ |
3065 if (pvd->vdev_children <= 1) | 3254 if (vdev_dtl_required(vd)) |
3066 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); 3067 | 3255 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); 3256 |
3068 /* 3069 * If all siblings have non-empty DTLs, this device may have the only 3070 * valid copy of the data, which means we cannot safely detach it. 3071 * 3072 * XXX -- as in the vdev_offline() case, we really want a more 3073 * precise DTL check. 3074 */ 3075 for (c = 0; c < pvd->vdev_children; c++) { 3076 uint64_t dirty; | 3257 ASSERT(pvd->vdev_children >= 2); |
3077 | 3258 |
3078 cvd = pvd->vdev_child[c]; 3079 if (cvd == vd) 3080 continue; 3081 if (vdev_is_dead(cvd)) 3082 continue; 3083 mutex_enter(&cvd->vdev_dtl_lock); 3084 dirty = cvd->vdev_dtl_map.sm_space | 3085 cvd->vdev_dtl_scrub.sm_space; 3086 mutex_exit(&cvd->vdev_dtl_lock); 3087 if (!dirty) 3088 break; 3089 } 3090 3091 if (c == pvd->vdev_children) 3092 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); 3093 | |
3094 /* 3095 * If we are detaching the second disk from a replacing vdev, then 3096 * check to see if we changed the original vdev's path to have "/old" 3097 * at the end in spa_vdev_attach(). If so, undo that change now. 3098 */ 3099 if (pvd->vdev_ops == &vdev_replacing_ops && vd->vdev_id == 1 && 3100 pvd->vdev_child[0]->vdev_path != NULL && 3101 pvd->vdev_child[1]->vdev_path != NULL) { --- 8 unchanged lines hidden (view full) --- 3110 } 3111 3112 /* 3113 * If we are detaching the original disk from a spare, then it implies 3114 * that the spare should become a real disk, and be removed from the 3115 * active spare list for the pool. 3116 */ 3117 if (pvd->vdev_ops == &vdev_spare_ops && | 3259 /* 3260 * If we are detaching the second disk from a replacing vdev, then 3261 * check to see if we changed the original vdev's path to have "/old" 3262 * at the end in spa_vdev_attach(). If so, undo that change now. 3263 */ 3264 if (pvd->vdev_ops == &vdev_replacing_ops && vd->vdev_id == 1 && 3265 pvd->vdev_child[0]->vdev_path != NULL && 3266 pvd->vdev_child[1]->vdev_path != NULL) { --- 8 unchanged lines hidden (view full) --- 3275 } 3276 3277 /* 3278 * If we are detaching the original disk from a spare, then it implies 3279 * that the spare should become a real disk, and be removed from the 3280 * active spare list for the pool. 3281 */ 3282 if (pvd->vdev_ops == &vdev_spare_ops && |
3118 vd->vdev_id == 0) | 3283 vd->vdev_id == 0 && pvd->vdev_child[1]->vdev_isspare) |
3119 unspare = B_TRUE; 3120 3121 /* 3122 * Erase the disk labels so the disk can be used for other things. 3123 * This must be done after all other error cases are handled, 3124 * but before we disembowel vd (so we can still do I/O to it). 3125 * But if we can't do it, don't treat the error as fatal -- 3126 * it may be that the unwritability of the disk is the reason --- 9 unchanged lines hidden (view full) --- 3136 3137 /* 3138 * Remember one of the remaining children so we can get tvd below. 3139 */ 3140 cvd = pvd->vdev_child[0]; 3141 3142 /* 3143 * If we need to remove the remaining child from the list of hot spares, | 3284 unspare = B_TRUE; 3285 3286 /* 3287 * Erase the disk labels so the disk can be used for other things. 3288 * This must be done after all other error cases are handled, 3289 * but before we disembowel vd (so we can still do I/O to it). 3290 * But if we can't do it, don't treat the error as fatal -- 3291 * it may be that the unwritability of the disk is the reason --- 9 unchanged lines hidden (view full) --- 3301 3302 /* 3303 * Remember one of the remaining children so we can get tvd below. 3304 */ 3305 cvd = pvd->vdev_child[0]; 3306 3307 /* 3308 * If we need to remove the remaining child from the list of hot spares, |
3144 * do it now, marking the vdev as no longer a spare in the process. We 3145 * must do this before vdev_remove_parent(), because that can change the 3146 * GUID if it creates a new toplevel GUID. | 3309 * do it now, marking the vdev as no longer a spare in the process. 3310 * We must do this before vdev_remove_parent(), because that can 3311 * change the GUID if it creates a new toplevel GUID. For a similar 3312 * reason, we must remove the spare now, in the same txg as the detach; 3313 * otherwise someone could attach a new sibling, change the GUID, and 3314 * the subsequent attempt to spa_vdev_remove(unspare_guid) would fail. |
3147 */ 3148 if (unspare) { 3149 ASSERT(cvd->vdev_isspare); 3150 spa_spare_remove(cvd); 3151 unspare_guid = cvd->vdev_guid; | 3315 */ 3316 if (unspare) { 3317 ASSERT(cvd->vdev_isspare); 3318 spa_spare_remove(cvd); 3319 unspare_guid = cvd->vdev_guid; |
3320 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE); |
|
3152 } 3153 3154 /* 3155 * If the parent mirror/replacing vdev only has one child, 3156 * the parent is no longer needed. Remove it from the tree. 3157 */ 3158 if (pvd->vdev_children == 1) 3159 vdev_remove_parent(cvd); --- 21 unchanged lines hidden (view full) --- 3181 vdev_config_dirty(tvd); 3182 3183 /* 3184 * Mark vd's DTL as dirty in this txg. vdev_dtl_sync() will see that 3185 * vd->vdev_detached is set and free vd's DTL object in syncing context. 3186 * But first make sure we're not on any *other* txg's DTL list, to 3187 * prevent vd from being accessed after it's freed. 3188 */ | 3321 } 3322 3323 /* 3324 * If the parent mirror/replacing vdev only has one child, 3325 * the parent is no longer needed. Remove it from the tree. 3326 */ 3327 if (pvd->vdev_children == 1) 3328 vdev_remove_parent(cvd); --- 21 unchanged lines hidden (view full) --- 3350 vdev_config_dirty(tvd); 3351 3352 /* 3353 * Mark vd's DTL as dirty in this txg. vdev_dtl_sync() will see that 3354 * vd->vdev_detached is set and free vd's DTL object in syncing context. 3355 * But first make sure we're not on any *other* txg's DTL list, to 3356 * prevent vd from being accessed after it's freed. 3357 */ |
3189 for (t = 0; t < TXG_SIZE; t++) | 3358 for (int t = 0; t < TXG_SIZE; t++) |
3190 (void) txg_list_remove_this(&tvd->vdev_dtl_list, vd, t); 3191 vd->vdev_detached = B_TRUE; 3192 vdev_dirty(tvd, VDD_DTL, vd, txg); 3193 3194 spa_event_notify(spa, vd, ESC_ZFS_VDEV_REMOVE); 3195 3196 error = spa_vdev_exit(spa, vd, txg, 0); 3197 3198 /* 3199 * If this was the removal of the original device in a hot spare vdev, 3200 * then we want to go through and remove the device from the hot spare 3201 * list of every other pool. 3202 */ 3203 if (unspare) { | 3359 (void) txg_list_remove_this(&tvd->vdev_dtl_list, vd, t); 3360 vd->vdev_detached = B_TRUE; 3361 vdev_dirty(tvd, VDD_DTL, vd, txg); 3362 3363 spa_event_notify(spa, vd, ESC_ZFS_VDEV_REMOVE); 3364 3365 error = spa_vdev_exit(spa, vd, txg, 0); 3366 3367 /* 3368 * If this was the removal of the original device in a hot spare vdev, 3369 * then we want to go through and remove the device from the hot spare 3370 * list of every other pool. 3371 */ 3372 if (unspare) { |
3373 spa_t *myspa = spa; |
|
3204 spa = NULL; 3205 mutex_enter(&spa_namespace_lock); 3206 while ((spa = spa_next(spa)) != NULL) { 3207 if (spa->spa_state != POOL_STATE_ACTIVE) 3208 continue; | 3374 spa = NULL; 3375 mutex_enter(&spa_namespace_lock); 3376 while ((spa = spa_next(spa)) != NULL) { 3377 if (spa->spa_state != POOL_STATE_ACTIVE) 3378 continue; |
3379 if (spa == myspa) 3380 continue; |
|
3209 spa_open_ref(spa, FTAG); 3210 mutex_exit(&spa_namespace_lock); 3211 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE); 3212 mutex_enter(&spa_namespace_lock); 3213 spa_close(spa, FTAG); 3214 } 3215 mutex_exit(&spa_namespace_lock); 3216 } --- 47 unchanged lines hidden (view full) --- 3264 * spares and level 2 ARC devices. 3265 */ 3266int 3267spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare) 3268{ 3269 vdev_t *vd; 3270 nvlist_t **spares, **l2cache, *nv; 3271 uint_t nspares, nl2cache; | 3381 spa_open_ref(spa, FTAG); 3382 mutex_exit(&spa_namespace_lock); 3383 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE); 3384 mutex_enter(&spa_namespace_lock); 3385 spa_close(spa, FTAG); 3386 } 3387 mutex_exit(&spa_namespace_lock); 3388 } --- 47 unchanged lines hidden (view full) --- 3436 * spares and level 2 ARC devices. 3437 */ 3438int 3439spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare) 3440{ 3441 vdev_t *vd; 3442 nvlist_t **spares, **l2cache, *nv; 3443 uint_t nspares, nl2cache; |
3272 uint64_t txg; | 3444 uint64_t txg = 0; |
3273 int error = 0; | 3445 int error = 0; |
3446 boolean_t locked = MUTEX_HELD(&spa_namespace_lock); |
|
3274 | 3447 |
3275 txg = spa_vdev_enter(spa); | 3448 if (!locked) 3449 txg = spa_vdev_enter(spa); |
3276 3277 vd = spa_lookup_by_guid(spa, guid, B_FALSE); 3278 3279 if (spa->spa_spares.sav_vdevs != NULL && 3280 nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, 3281 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0 && 3282 (nv = spa_nvlist_lookup_by_guid(spares, nspares, guid)) != NULL) { 3283 /* --- 26 unchanged lines hidden (view full) --- 3310 error = ENOTSUP; 3311 } else { 3312 /* 3313 * There is no vdev of any kind with the specified guid. 3314 */ 3315 error = ENOENT; 3316 } 3317 | 3450 3451 vd = spa_lookup_by_guid(spa, guid, B_FALSE); 3452 3453 if (spa->spa_spares.sav_vdevs != NULL && 3454 nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, 3455 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0 && 3456 (nv = spa_nvlist_lookup_by_guid(spares, nspares, guid)) != NULL) { 3457 /* --- 26 unchanged lines hidden (view full) --- 3484 error = ENOTSUP; 3485 } else { 3486 /* 3487 * There is no vdev of any kind with the specified guid. 3488 */ 3489 error = ENOENT; 3490 } 3491 |
3318 return (spa_vdev_exit(spa, NULL, txg, error)); | 3492 if (!locked) 3493 return (spa_vdev_exit(spa, NULL, txg, error)); 3494 3495 return (error); |
3319} 3320 3321/* 3322 * Find any device that's done replacing, or a vdev marked 'unspare' that's 3323 * current spared, so we can detach it. 3324 */ 3325static vdev_t * 3326spa_vdev_resilver_done_hunt(vdev_t *vd) --- 9 unchanged lines hidden (view full) --- 3336 3337 /* 3338 * Check for a completed replacement. 3339 */ 3340 if (vd->vdev_ops == &vdev_replacing_ops && vd->vdev_children == 2) { 3341 oldvd = vd->vdev_child[0]; 3342 newvd = vd->vdev_child[1]; 3343 | 3496} 3497 3498/* 3499 * Find any device that's done replacing, or a vdev marked 'unspare' that's 3500 * current spared, so we can detach it. 3501 */ 3502static vdev_t * 3503spa_vdev_resilver_done_hunt(vdev_t *vd) --- 9 unchanged lines hidden (view full) --- 3513 3514 /* 3515 * Check for a completed replacement. 3516 */ 3517 if (vd->vdev_ops == &vdev_replacing_ops && vd->vdev_children == 2) { 3518 oldvd = vd->vdev_child[0]; 3519 newvd = vd->vdev_child[1]; 3520 |
3344 mutex_enter(&newvd->vdev_dtl_lock); 3345 if (newvd->vdev_dtl_map.sm_space == 0 && 3346 newvd->vdev_dtl_scrub.sm_space == 0) { 3347 mutex_exit(&newvd->vdev_dtl_lock); | 3521 if (vdev_dtl_empty(newvd, DTL_MISSING) && 3522 !vdev_dtl_required(oldvd)) |
3348 return (oldvd); | 3523 return (oldvd); |
3349 } 3350 mutex_exit(&newvd->vdev_dtl_lock); | |
3351 } 3352 3353 /* 3354 * Check for a completed resilver with the 'unspare' flag set. 3355 */ 3356 if (vd->vdev_ops == &vdev_spare_ops && vd->vdev_children == 2) { 3357 newvd = vd->vdev_child[0]; 3358 oldvd = vd->vdev_child[1]; 3359 | 3524 } 3525 3526 /* 3527 * Check for a completed resilver with the 'unspare' flag set. 3528 */ 3529 if (vd->vdev_ops == &vdev_spare_ops && vd->vdev_children == 2) { 3530 newvd = vd->vdev_child[0]; 3531 oldvd = vd->vdev_child[1]; 3532 |
3360 mutex_enter(&newvd->vdev_dtl_lock); | |
3361 if (newvd->vdev_unspare && | 3533 if (newvd->vdev_unspare && |
3362 newvd->vdev_dtl_map.sm_space == 0 && 3363 newvd->vdev_dtl_scrub.sm_space == 0) { | 3534 vdev_dtl_empty(newvd, DTL_MISSING) && 3535 !vdev_dtl_required(oldvd)) { |
3364 newvd->vdev_unspare = 0; | 3536 newvd->vdev_unspare = 0; |
3365 mutex_exit(&newvd->vdev_dtl_lock); | |
3366 return (oldvd); 3367 } | 3537 return (oldvd); 3538 } |
3368 mutex_exit(&newvd->vdev_dtl_lock); | |
3369 } 3370 3371 return (NULL); 3372} 3373 3374static void 3375spa_vdev_resilver_done(spa_t *spa) 3376{ | 3539 } 3540 3541 return (NULL); 3542} 3543 3544static void 3545spa_vdev_resilver_done(spa_t *spa) 3546{ |
3377 vdev_t *vd; 3378 vdev_t *pvd; 3379 uint64_t guid; 3380 uint64_t pguid = 0; | 3547 vdev_t *vd, *pvd, *ppvd; 3548 uint64_t guid, sguid, pguid, ppguid; |
3381 | 3549 |
3382 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); | 3550 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); |
3383 3384 while ((vd = spa_vdev_resilver_done_hunt(spa->spa_root_vdev)) != NULL) { | 3551 3552 while ((vd = spa_vdev_resilver_done_hunt(spa->spa_root_vdev)) != NULL) { |
3553 pvd = vd->vdev_parent; 3554 ppvd = pvd->vdev_parent; |
|
3385 guid = vd->vdev_guid; | 3555 guid = vd->vdev_guid; |
3556 pguid = pvd->vdev_guid; 3557 ppguid = ppvd->vdev_guid; 3558 sguid = 0; |
|
3386 /* 3387 * If we have just finished replacing a hot spared device, then 3388 * we need to detach the parent's first child (the original hot 3389 * spare) as well. 3390 */ | 3559 /* 3560 * If we have just finished replacing a hot spared device, then 3561 * we need to detach the parent's first child (the original hot 3562 * spare) as well. 3563 */ |
3391 pvd = vd->vdev_parent; 3392 if (pvd->vdev_parent->vdev_ops == &vdev_spare_ops && 3393 pvd->vdev_id == 0) { | 3564 if (ppvd->vdev_ops == &vdev_spare_ops && pvd->vdev_id == 0) { |
3394 ASSERT(pvd->vdev_ops == &vdev_replacing_ops); | 3565 ASSERT(pvd->vdev_ops == &vdev_replacing_ops); |
3395 ASSERT(pvd->vdev_parent->vdev_children == 2); 3396 pguid = pvd->vdev_parent->vdev_child[1]->vdev_guid; | 3566 ASSERT(ppvd->vdev_children == 2); 3567 sguid = ppvd->vdev_child[1]->vdev_guid; |
3397 } | 3568 } |
3398 spa_config_exit(spa, SCL_CONFIG, FTAG); 3399 if (spa_vdev_detach(spa, guid, B_TRUE) != 0) | 3569 spa_config_exit(spa, SCL_ALL, FTAG); 3570 if (spa_vdev_detach(spa, guid, pguid, B_TRUE) != 0) |
3400 return; | 3571 return; |
3401 if (pguid != 0 && spa_vdev_detach(spa, pguid, B_TRUE) != 0) | 3572 if (sguid && spa_vdev_detach(spa, sguid, ppguid, B_TRUE) != 0) |
3402 return; | 3573 return; |
3403 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); | 3574 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); |
3404 } 3405 | 3575 } 3576 |
3406 spa_config_exit(spa, SCL_CONFIG, FTAG); | 3577 spa_config_exit(spa, SCL_ALL, FTAG); |
3407} 3408 3409/* | 3578} 3579 3580/* |
3410 * Update the stored path for this vdev. Dirty the vdev configuration, relying 3411 * on spa_vdev_enter/exit() to synchronize the labels and cache. | 3581 * Update the stored path or FRU for this vdev. Dirty the vdev configuration, 3582 * relying on spa_vdev_enter/exit() to synchronize the labels and cache. |
3412 */ 3413int | 3583 */ 3584int |
3414spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath) | 3585spa_vdev_set_common(spa_t *spa, uint64_t guid, const char *value, 3586 boolean_t ispath) |
3415{ 3416 vdev_t *vd; 3417 uint64_t txg; 3418 3419 txg = spa_vdev_enter(spa); 3420 | 3587{ 3588 vdev_t *vd; 3589 uint64_t txg; 3590 3591 txg = spa_vdev_enter(spa); 3592 |
3421 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL) { 3422 /* 3423 * Determine if this is a reference to a hot spare device. If 3424 * it is, update the path manually as there is no associated 3425 * vdev_t that can be synced to disk. 3426 */ 3427 nvlist_t **spares; 3428 uint_t i, nspares; 3429 3430 if (spa->spa_spares.sav_config != NULL) { 3431 VERIFY(nvlist_lookup_nvlist_array( 3432 spa->spa_spares.sav_config, ZPOOL_CONFIG_SPARES, 3433 &spares, &nspares) == 0); 3434 for (i = 0; i < nspares; i++) { 3435 uint64_t theguid; 3436 VERIFY(nvlist_lookup_uint64(spares[i], 3437 ZPOOL_CONFIG_GUID, &theguid) == 0); 3438 if (theguid == guid) { 3439 VERIFY(nvlist_add_string(spares[i], 3440 ZPOOL_CONFIG_PATH, newpath) == 0); 3441 spa_load_spares(spa); 3442 spa->spa_spares.sav_sync = B_TRUE; 3443 return (spa_vdev_exit(spa, NULL, txg, 3444 0)); 3445 } 3446 } 3447 } 3448 | 3593 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL) |
3449 return (spa_vdev_exit(spa, NULL, txg, ENOENT)); | 3594 return (spa_vdev_exit(spa, NULL, txg, ENOENT)); |
3450 } | |
3451 3452 if (!vd->vdev_ops->vdev_op_leaf) 3453 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3454 | 3595 3596 if (!vd->vdev_ops->vdev_op_leaf) 3597 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); 3598 |
3455 spa_strfree(vd->vdev_path); 3456 vd->vdev_path = spa_strdup(newpath); | 3599 if (ispath) { 3600 spa_strfree(vd->vdev_path); 3601 vd->vdev_path = spa_strdup(value); 3602 } else { 3603 if (vd->vdev_fru != NULL) 3604 spa_strfree(vd->vdev_fru); 3605 vd->vdev_fru = spa_strdup(value); 3606 } |
3457 3458 vdev_config_dirty(vd->vdev_top); 3459 3460 return (spa_vdev_exit(spa, NULL, txg, 0)); 3461} 3462 | 3607 3608 vdev_config_dirty(vd->vdev_top); 3609 3610 return (spa_vdev_exit(spa, NULL, txg, 0)); 3611} 3612 |
3613int 3614spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath) 3615{ 3616 return (spa_vdev_set_common(spa, guid, newpath, B_TRUE)); 3617} 3618 3619int 3620spa_vdev_setfru(spa_t *spa, uint64_t guid, const char *newfru) 3621{ 3622 return (spa_vdev_set_common(spa, guid, newfru, B_FALSE)); 3623} 3624 |
|
3463/* 3464 * ========================================================================== 3465 * SPA Scrubbing 3466 * ========================================================================== 3467 */ 3468 3469int 3470spa_scrub(spa_t *spa, pool_scrub_type_t type) --- 34 unchanged lines hidden (view full) --- 3505 */ 3506 3507static void 3508spa_async_remove(spa_t *spa, vdev_t *vd) 3509{ 3510 if (vd->vdev_remove_wanted) { 3511 vd->vdev_remove_wanted = 0; 3512 vdev_set_state(vd, B_FALSE, VDEV_STATE_REMOVED, VDEV_AUX_NONE); | 3625/* 3626 * ========================================================================== 3627 * SPA Scrubbing 3628 * ========================================================================== 3629 */ 3630 3631int 3632spa_scrub(spa_t *spa, pool_scrub_type_t type) --- 34 unchanged lines hidden (view full) --- 3667 */ 3668 3669static void 3670spa_async_remove(spa_t *spa, vdev_t *vd) 3671{ 3672 if (vd->vdev_remove_wanted) { 3673 vd->vdev_remove_wanted = 0; 3674 vdev_set_state(vd, B_FALSE, VDEV_STATE_REMOVED, VDEV_AUX_NONE); |
3513 vdev_clear(spa, vd); | 3675 3676 /* 3677 * We want to clear the stats, but we don't want to do a full 3678 * vdev_clear() as that will cause us to throw away 3679 * degraded/faulted state as well as attempt to reopen the 3680 * device, all of which is a waste. 3681 */ 3682 vd->vdev_stat.vs_read_errors = 0; 3683 vd->vdev_stat.vs_write_errors = 0; 3684 vd->vdev_stat.vs_checksum_errors = 0; 3685 |
3514 vdev_state_dirty(vd->vdev_top); 3515 } 3516 3517 for (int c = 0; c < vd->vdev_children; c++) 3518 spa_async_remove(spa, vd->vdev_child[c]); 3519} 3520 3521static void --- 262 unchanged lines hidden (view full) --- 3784 objset_t *mos = spa->spa_meta_objset; 3785 nvlist_t *nvp = arg2; 3786 nvpair_t *elem; 3787 uint64_t intval; 3788 char *strval; 3789 zpool_prop_t prop; 3790 const char *propname; 3791 zprop_type_t proptype; | 3686 vdev_state_dirty(vd->vdev_top); 3687 } 3688 3689 for (int c = 0; c < vd->vdev_children; c++) 3690 spa_async_remove(spa, vd->vdev_child[c]); 3691} 3692 3693static void --- 262 unchanged lines hidden (view full) --- 3956 objset_t *mos = spa->spa_meta_objset; 3957 nvlist_t *nvp = arg2; 3958 nvpair_t *elem; 3959 uint64_t intval; 3960 char *strval; 3961 zpool_prop_t prop; 3962 const char *propname; 3963 zprop_type_t proptype; |
3792 spa_config_dirent_t *dp; | |
3793 3794 mutex_enter(&spa->spa_props_lock); 3795 3796 elem = NULL; 3797 while ((elem = nvlist_next_nvpair(nvp, elem))) { 3798 switch (prop = zpool_name_to_prop(nvpair_name(elem))) { 3799 case ZPOOL_PROP_VERSION: 3800 /* --- 16 unchanged lines hidden (view full) --- 3817 * 'altroot' is a non-persistent property. It should 3818 * have been set temporarily at creation or import time. 3819 */ 3820 ASSERT(spa->spa_root != NULL); 3821 break; 3822 3823 case ZPOOL_PROP_CACHEFILE: 3824 /* | 3964 3965 mutex_enter(&spa->spa_props_lock); 3966 3967 elem = NULL; 3968 while ((elem = nvlist_next_nvpair(nvp, elem))) { 3969 switch (prop = zpool_name_to_prop(nvpair_name(elem))) { 3970 case ZPOOL_PROP_VERSION: 3971 /* --- 16 unchanged lines hidden (view full) --- 3988 * 'altroot' is a non-persistent property. It should 3989 * have been set temporarily at creation or import time. 3990 */ 3991 ASSERT(spa->spa_root != NULL); 3992 break; 3993 3994 case ZPOOL_PROP_CACHEFILE: 3995 /* |
3825 * 'cachefile' is a non-persistent property, but note 3826 * an async request that the config cache needs to be 3827 * udpated. | 3996 * 'cachefile' is also a non-persisitent property. |
3828 */ | 3997 */ |
3829 VERIFY(nvpair_value_string(elem, &strval) == 0); 3830 3831 dp = kmem_alloc(sizeof (spa_config_dirent_t), KM_SLEEP); 3832 3833 if (strval[0] == '\0') 3834 dp->scd_path = spa_strdup(spa_config_path); 3835 else if (strcmp(strval, "none") == 0) 3836 dp->scd_path = NULL; 3837 else 3838 dp->scd_path = spa_strdup(strval); 3839 3840 list_insert_head(&spa->spa_config_list, dp); 3841 spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE); | |
3842 break; 3843 default: 3844 /* 3845 * Set pool property values in the poolprops mos object. 3846 */ 3847 if (spa->spa_pool_props_object == 0) { 3848 objset_t *mos = spa->spa_meta_objset; 3849 --- 84 unchanged lines hidden (view full) --- 3934 spa->spa_syncing_txg = txg; 3935 spa->spa_sync_pass = 0; 3936 3937 /* 3938 * If there are any pending vdev state changes, convert them 3939 * into config changes that go out with this transaction group. 3940 */ 3941 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); | 3998 break; 3999 default: 4000 /* 4001 * Set pool property values in the poolprops mos object. 4002 */ 4003 if (spa->spa_pool_props_object == 0) { 4004 objset_t *mos = spa->spa_meta_objset; 4005 --- 84 unchanged lines hidden (view full) --- 4090 spa->spa_syncing_txg = txg; 4091 spa->spa_sync_pass = 0; 4092 4093 /* 4094 * If there are any pending vdev state changes, convert them 4095 * into config changes that go out with this transaction group. 4096 */ 4097 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); |
3942 while ((vd = list_head(&spa->spa_state_dirty_list)) != NULL) { 3943 vdev_state_clean(vd); 3944 vdev_config_dirty(vd); | 4098 while (list_head(&spa->spa_state_dirty_list) != NULL) { 4099 /* 4100 * We need the write lock here because, for aux vdevs, 4101 * calling vdev_config_dirty() modifies sav_config. 4102 * This is ugly and will become unnecessary when we 4103 * eliminate the aux vdev wart by integrating all vdevs 4104 * into the root vdev tree. 4105 */ 4106 spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG); 4107 spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_WRITER); 4108 while ((vd = list_head(&spa->spa_state_dirty_list)) != NULL) { 4109 vdev_state_clean(vd); 4110 vdev_config_dirty(vd); 4111 } 4112 spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG); 4113 spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER); |
3945 } 3946 spa_config_exit(spa, SCL_STATE, FTAG); 3947 3948 VERIFY(0 == bplist_open(bpl, mos, spa->spa_sync_bplist_obj)); 3949 3950 tx = dmu_tx_create_assigned(dp, txg); 3951 3952 /* --- 217 unchanged lines hidden (view full) --- 4170 spa_deactivate(spa); 4171 } 4172 spa_remove(spa); 4173 } 4174 mutex_exit(&spa_namespace_lock); 4175} 4176 4177vdev_t * | 4114 } 4115 spa_config_exit(spa, SCL_STATE, FTAG); 4116 4117 VERIFY(0 == bplist_open(bpl, mos, spa->spa_sync_bplist_obj)); 4118 4119 tx = dmu_tx_create_assigned(dp, txg); 4120 4121 /* --- 217 unchanged lines hidden (view full) --- 4339 spa_deactivate(spa); 4340 } 4341 spa_remove(spa); 4342 } 4343 mutex_exit(&spa_namespace_lock); 4344} 4345 4346vdev_t * |
4178spa_lookup_by_guid(spa_t *spa, uint64_t guid, boolean_t l2cache) | 4347spa_lookup_by_guid(spa_t *spa, uint64_t guid, boolean_t aux) |
4179{ 4180 vdev_t *vd; 4181 int i; 4182 4183 if ((vd = vdev_lookup_by_guid(spa->spa_root_vdev, guid)) != NULL) 4184 return (vd); 4185 | 4348{ 4349 vdev_t *vd; 4350 int i; 4351 4352 if ((vd = vdev_lookup_by_guid(spa->spa_root_vdev, guid)) != NULL) 4353 return (vd); 4354 |
4186 if (l2cache) { | 4355 if (aux) { |
4187 for (i = 0; i < spa->spa_l2cache.sav_count; i++) { 4188 vd = spa->spa_l2cache.sav_vdevs[i]; 4189 if (vd->vdev_guid == guid) 4190 return (vd); 4191 } | 4356 for (i = 0; i < spa->spa_l2cache.sav_count; i++) { 4357 vd = spa->spa_l2cache.sav_vdevs[i]; 4358 if (vd->vdev_guid == guid) 4359 return (vd); 4360 } |
4361 4362 for (i = 0; i < spa->spa_spares.sav_count; i++) { 4363 vd = spa->spa_spares.sav_vdevs[i]; 4364 if (vd->vdev_guid == guid) 4365 return (vd); 4366 } |
|
4192 } 4193 4194 return (NULL); 4195} 4196 4197void 4198spa_upgrade(spa_t *spa, uint64_t version) 4199{ --- 118 unchanged lines hidden --- | 4367 } 4368 4369 return (NULL); 4370} 4371 4372void 4373spa_upgrade(spa_t *spa, uint64_t version) 4374{ --- 118 unchanged lines hidden --- |