spa.c (219089) | spa.c (228103) |
---|---|
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 --- 7 unchanged lines hidden (view full) --- 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 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 --- 7 unchanged lines hidden (view full) --- 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
24 * Copyright (c) 2011 by Delphix. All rights reserved. |
|
24 */ 25 26/* 27 * This file contains all the routines used when modifying on-disk SPA state. 28 * This includes opening, importing, destroying, exporting a pool, and syncing a 29 * pool. 30 */ 31 --- 175 unchanged lines hidden (view full) --- 207 src = ZPROP_SRC_DEFAULT; 208 else 209 src = ZPROP_SRC_LOCAL; 210 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL, version, src); 211 } 212 213 spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src); 214 | 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 */ 32 --- 175 unchanged lines hidden (view full) --- 208 src = ZPROP_SRC_DEFAULT; 209 else 210 src = ZPROP_SRC_LOCAL; 211 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL, version, src); 212 } 213 214 spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src); 215 |
216 if (spa->spa_comment != NULL) { 217 spa_prop_add_list(*nvp, ZPOOL_PROP_COMMENT, spa->spa_comment, 218 0, ZPROP_SRC_LOCAL); 219 } 220 |
|
215 if (spa->spa_root != NULL) 216 spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root, 217 0, ZPROP_SRC_LOCAL); 218 219 if ((dp = list_head(&spa->spa_config_list)) != NULL) { 220 if (dp->scd_path == NULL) { 221 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, 222 "none", 0, ZPROP_SRC_LOCAL); --- 123 unchanged lines hidden (view full) --- 346 uint64_t objnum; 347 348 elem = NULL; 349 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { 350 zpool_prop_t prop; 351 char *propname, *strval; 352 uint64_t intval; 353 objset_t *os; | 221 if (spa->spa_root != NULL) 222 spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root, 223 0, ZPROP_SRC_LOCAL); 224 225 if ((dp = list_head(&spa->spa_config_list)) != NULL) { 226 if (dp->scd_path == NULL) { 227 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, 228 "none", 0, ZPROP_SRC_LOCAL); --- 123 unchanged lines hidden (view full) --- 352 uint64_t objnum; 353 354 elem = NULL; 355 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { 356 zpool_prop_t prop; 357 char *propname, *strval; 358 uint64_t intval; 359 objset_t *os; |
354 char *slash; | 360 char *slash, *check; |
355 356 propname = nvpair_name(elem); 357 358 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) 359 return (EINVAL); 360 361 switch (prop) { 362 case ZPOOL_PROP_VERSION: --- 103 unchanged lines hidden (view full) --- 466 slash = strrchr(strval, '/'); 467 ASSERT(slash != NULL); 468 469 if (slash[1] == '\0' || strcmp(slash, "/.") == 0 || 470 strcmp(slash, "/..") == 0) 471 error = EINVAL; 472 break; 473 | 361 362 propname = nvpair_name(elem); 363 364 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) 365 return (EINVAL); 366 367 switch (prop) { 368 case ZPOOL_PROP_VERSION: --- 103 unchanged lines hidden (view full) --- 472 slash = strrchr(strval, '/'); 473 ASSERT(slash != NULL); 474 475 if (slash[1] == '\0' || strcmp(slash, "/.") == 0 || 476 strcmp(slash, "/..") == 0) 477 error = EINVAL; 478 break; 479 |
480 case ZPOOL_PROP_COMMENT: 481 if ((error = nvpair_value_string(elem, &strval)) != 0) 482 break; 483 for (check = strval; *check != '\0'; check++) { 484 /* 485 * The kernel doesn't have an easy isprint() 486 * check. For this kernel check, we merely 487 * check ASCII apart from DEL. Fix this if 488 * there is an easy-to-use kernel isprint(). 489 */ 490 if (*check >= 0x7f) { 491 error = EINVAL; 492 break; 493 } 494 check++; 495 } 496 if (strlen(strval) > ZPROP_MAX_COMMENT) 497 error = E2BIG; 498 break; 499 |
|
474 case ZPOOL_PROP_DEDUPDITTO: 475 if (spa_version(spa) < SPA_VERSION_DEDUP) 476 error = ENOTSUP; 477 else 478 error = nvpair_value_uint64(elem, &intval); 479 if (error == 0 && 480 intval != 0 && intval < ZIO_DEDUPDITTO_MIN) 481 error = EINVAL; --- 85 unchanged lines hidden (view full) --- 567 VERIFY(zap_remove(spa->spa_meta_objset, 568 spa->spa_pool_props_object, 569 zpool_prop_to_name(ZPOOL_PROP_BOOTFS), tx) == 0); 570 spa->spa_bootfs = 0; 571 } 572} 573 574/* | 500 case ZPOOL_PROP_DEDUPDITTO: 501 if (spa_version(spa) < SPA_VERSION_DEDUP) 502 error = ENOTSUP; 503 else 504 error = nvpair_value_uint64(elem, &intval); 505 if (error == 0 && 506 intval != 0 && intval < ZIO_DEDUPDITTO_MIN) 507 error = EINVAL; --- 85 unchanged lines hidden (view full) --- 593 VERIFY(zap_remove(spa->spa_meta_objset, 594 spa->spa_pool_props_object, 595 zpool_prop_to_name(ZPOOL_PROP_BOOTFS), tx) == 0); 596 spa->spa_bootfs = 0; 597 } 598} 599 600/* |
601 * Change the GUID for the pool. This is done so that we can later 602 * re-import a pool built from a clone of our own vdevs. We will modify 603 * the root vdev's guid, our own pool guid, and then mark all of our 604 * vdevs dirty. Note that we must make sure that all our vdevs are 605 * online when we do this, or else any vdevs that weren't present 606 * would be orphaned from our pool. We are also going to issue a 607 * sysevent to update any watchers. 608 */ 609int 610spa_change_guid(spa_t *spa) 611{ 612 uint64_t oldguid, newguid; 613 uint64_t txg; 614 615 if (!(spa_mode_global & FWRITE)) 616 return (EROFS); 617 618 txg = spa_vdev_enter(spa); 619 620 if (spa->spa_root_vdev->vdev_state != VDEV_STATE_HEALTHY) 621 return (spa_vdev_exit(spa, NULL, txg, ENXIO)); 622 623 oldguid = spa_guid(spa); 624 newguid = spa_generate_guid(NULL); 625 ASSERT3U(oldguid, !=, newguid); 626 627 spa->spa_root_vdev->vdev_guid = newguid; 628 spa->spa_root_vdev->vdev_guid_sum += (newguid - oldguid); 629 630 vdev_config_dirty(spa->spa_root_vdev); 631 632 spa_event_notify(spa, NULL, ESC_ZFS_POOL_REGUID); 633 634 return (spa_vdev_exit(spa, NULL, txg, 0)); 635} 636 637/* |
|
575 * ========================================================================== 576 * SPA state manipulation (open/create/destroy/import/export) 577 * ========================================================================== 578 */ 579 580static int 581spa_error_entry_compare(const void *a, const void *b) 582{ --- 437 unchanged lines hidden (view full) --- 1020 if (spa->spa_l2cache.sav_config) { 1021 nvlist_free(spa->spa_l2cache.sav_config); 1022 spa->spa_l2cache.sav_config = NULL; 1023 } 1024 spa->spa_l2cache.sav_count = 0; 1025 1026 spa->spa_async_suspended = 0; 1027 | 638 * ========================================================================== 639 * SPA state manipulation (open/create/destroy/import/export) 640 * ========================================================================== 641 */ 642 643static int 644spa_error_entry_compare(const void *a, const void *b) 645{ --- 437 unchanged lines hidden (view full) --- 1083 if (spa->spa_l2cache.sav_config) { 1084 nvlist_free(spa->spa_l2cache.sav_config); 1085 spa->spa_l2cache.sav_config = NULL; 1086 } 1087 spa->spa_l2cache.sav_count = 0; 1088 1089 spa->spa_async_suspended = 0; 1090 |
1091 if (spa->spa_comment != NULL) { 1092 spa_strfree(spa->spa_comment); 1093 spa->spa_comment = NULL; 1094 } 1095 |
|
1028 spa_config_exit(spa, SCL_ALL, FTAG); 1029} 1030 1031/* 1032 * Load (or re-load) the current list of vdevs describing the active spares for 1033 * this pool. When this is called, we have some form of basic information in 1034 * 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and 1035 * then re-generate a more complete list including status information. --- 701 unchanged lines hidden (view full) --- 1737} 1738 1739static int 1740spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type, 1741 boolean_t mosconfig) 1742{ 1743 nvlist_t *config = spa->spa_config; 1744 char *ereport = FM_EREPORT_ZFS_POOL; | 1096 spa_config_exit(spa, SCL_ALL, FTAG); 1097} 1098 1099/* 1100 * Load (or re-load) the current list of vdevs describing the active spares for 1101 * this pool. When this is called, we have some form of basic information in 1102 * 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and 1103 * then re-generate a more complete list including status information. --- 701 unchanged lines hidden (view full) --- 1805} 1806 1807static int 1808spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type, 1809 boolean_t mosconfig) 1810{ 1811 nvlist_t *config = spa->spa_config; 1812 char *ereport = FM_EREPORT_ZFS_POOL; |
1813 char *comment; |
|
1745 int error; 1746 uint64_t pool_guid; 1747 nvlist_t *nvl; 1748 1749 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) 1750 return (EINVAL); 1751 | 1814 int error; 1815 uint64_t pool_guid; 1816 nvlist_t *nvl; 1817 1818 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) 1819 return (EINVAL); 1820 |
1821 ASSERT(spa->spa_comment == NULL); 1822 if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0) 1823 spa->spa_comment = spa_strdup(comment); 1824 |
|
1752 /* 1753 * Versioning wasn't explicitly added to the label until later, so if 1754 * it's not present treat it as the initial version. 1755 */ 1756 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, 1757 &spa->spa_ubsync.ub_version) != 0) 1758 spa->spa_ubsync.ub_version = SPA_VERSION_INITIAL; 1759 1760 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, 1761 &spa->spa_config_txg); 1762 1763 if ((state == SPA_LOAD_IMPORT || state == SPA_LOAD_TRYIMPORT) && 1764 spa_guid_exists(pool_guid, 0)) { 1765 error = EEXIST; 1766 } else { | 1825 /* 1826 * Versioning wasn't explicitly added to the label until later, so if 1827 * it's not present treat it as the initial version. 1828 */ 1829 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, 1830 &spa->spa_ubsync.ub_version) != 0) 1831 spa->spa_ubsync.ub_version = SPA_VERSION_INITIAL; 1832 1833 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, 1834 &spa->spa_config_txg); 1835 1836 if ((state == SPA_LOAD_IMPORT || state == SPA_LOAD_TRYIMPORT) && 1837 spa_guid_exists(pool_guid, 0)) { 1838 error = EEXIST; 1839 } else { |
1767 spa->spa_load_guid = pool_guid; | 1840 spa->spa_config_guid = pool_guid; |
1768 1769 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_SPLIT, 1770 &nvl) == 0) { 1771 VERIFY(nvlist_dup(nvl, &spa->spa_config_splitting, 1772 KM_SLEEP) == 0); 1773 } 1774 1775 gethrestime(&spa->spa_loaded_ts); --- 3599 unchanged lines hidden (view full) --- 5375 5376 case ZPOOL_PROP_READONLY: 5377 case ZPOOL_PROP_CACHEFILE: 5378 /* 5379 * 'readonly' and 'cachefile' are also non-persisitent 5380 * properties. 5381 */ 5382 break; | 1841 1842 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_SPLIT, 1843 &nvl) == 0) { 1844 VERIFY(nvlist_dup(nvl, &spa->spa_config_splitting, 1845 KM_SLEEP) == 0); 1846 } 1847 1848 gethrestime(&spa->spa_loaded_ts); --- 3599 unchanged lines hidden (view full) --- 5448 5449 case ZPOOL_PROP_READONLY: 5450 case ZPOOL_PROP_CACHEFILE: 5451 /* 5452 * 'readonly' and 'cachefile' are also non-persisitent 5453 * properties. 5454 */ 5455 break; |
5456 case ZPOOL_PROP_COMMENT: 5457 VERIFY(nvpair_value_string(elem, &strval) == 0); 5458 if (spa->spa_comment != NULL) 5459 spa_strfree(spa->spa_comment); 5460 spa->spa_comment = spa_strdup(strval); 5461 /* 5462 * We need to dirty the configuration on all the vdevs 5463 * so that their labels get updated. It's unnecessary 5464 * to do this for pool creation since the vdev's 5465 * configuratoin has already been dirtied. 5466 */ 5467 if (tx->tx_txg != TXG_INITIAL) 5468 vdev_config_dirty(spa->spa_root_vdev); 5469 break; |
|
5383 default: 5384 /* 5385 * Set pool property values in the poolprops mos object. 5386 */ 5387 if (spa->spa_pool_props_object == 0) { 5388 VERIFY((spa->spa_pool_props_object = 5389 zap_create(mos, DMU_OT_POOL_PROPS, 5390 DMU_OT_NONE, 0, tx)) > 0); --- 540 unchanged lines hidden --- | 5470 default: 5471 /* 5472 * Set pool property values in the poolprops mos object. 5473 */ 5474 if (spa->spa_pool_props_object == 0) { 5475 VERIFY((spa->spa_pool_props_object = 5476 zap_create(mos, DMU_OT_POOL_PROPS, 5477 DMU_OT_NONE, 0, tx)) > 0); --- 540 unchanged lines hidden --- |