libzfs_pool.c (207672) | libzfs_pool.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#include <sys/types.h> 28#include <sys/stat.h> 29#include <assert.h> 30#include <ctype.h> 31#include <errno.h> --- 12 unchanged lines hidden (view full) --- 44#include <umem.h> 45 46#include "zfs_namecheck.h" 47#include "zfs_prop.h" 48#include "libzfs_impl.h" 49 50static int read_efi_label(nvlist_t *config, diskaddr_t *sb); 51 | 24 * Use is subject to license terms. 25 */ 26 27#include <sys/types.h> 28#include <sys/stat.h> 29#include <assert.h> 30#include <ctype.h> 31#include <errno.h> --- 12 unchanged lines hidden (view full) --- 44#include <umem.h> 45 46#include "zfs_namecheck.h" 47#include "zfs_prop.h" 48#include "libzfs_impl.h" 49 50static int read_efi_label(nvlist_t *config, diskaddr_t *sb); 51 |
52#if defined(__i386) || defined(__amd64) 53#define BOOTCMD "installgrub(1M)" 54#else 55#define BOOTCMD "installboot(1M)" 56#endif 57 |
|
52/* 53 * ==================================================================== 54 * zpool property functions 55 * ==================================================================== 56 */ 57 58static int 59zpool_get_all_props(zpool_handle_t *zhp) --- 146 unchanged lines hidden (view full) --- 206 uint64_t intval; 207 const char *strval; 208 zprop_source_t src = ZPROP_SRC_NONE; 209 nvlist_t *nvroot; 210 vdev_stat_t *vs; 211 uint_t vsc; 212 213 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) { | 58/* 59 * ==================================================================== 60 * zpool property functions 61 * ==================================================================== 62 */ 63 64static int 65zpool_get_all_props(zpool_handle_t *zhp) --- 146 unchanged lines hidden (view full) --- 212 uint64_t intval; 213 const char *strval; 214 zprop_source_t src = ZPROP_SRC_NONE; 215 nvlist_t *nvroot; 216 vdev_stat_t *vs; 217 uint_t vsc; 218 219 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) { |
214 if (prop == ZPOOL_PROP_NAME) | 220 switch (prop) { 221 case ZPOOL_PROP_NAME: |
215 (void) strlcpy(buf, zpool_get_name(zhp), len); | 222 (void) strlcpy(buf, zpool_get_name(zhp), len); |
216 else if (prop == ZPOOL_PROP_HEALTH) | 223 break; 224 225 case ZPOOL_PROP_HEALTH: |
217 (void) strlcpy(buf, "FAULTED", len); | 226 (void) strlcpy(buf, "FAULTED", len); |
218 else | 227 break; 228 229 case ZPOOL_PROP_GUID: 230 intval = zpool_get_prop_int(zhp, prop, &src); 231 (void) snprintf(buf, len, "%llu", intval); 232 break; 233 234 case ZPOOL_PROP_ALTROOT: 235 case ZPOOL_PROP_CACHEFILE: 236 if (zhp->zpool_props != NULL || 237 zpool_get_all_props(zhp) == 0) { 238 (void) strlcpy(buf, 239 zpool_get_prop_string(zhp, prop, &src), 240 len); 241 if (srctype != NULL) 242 *srctype = src; 243 return (0); 244 } 245 /* FALLTHROUGH */ 246 default: |
219 (void) strlcpy(buf, "-", len); | 247 (void) strlcpy(buf, "-", len); |
248 break; 249 } 250 251 if (srctype != NULL) 252 *srctype = src; |
|
220 return (0); 221 } 222 223 if (zhp->zpool_props == NULL && zpool_get_all_props(zhp) && 224 prop != ZPOOL_PROP_NAME) 225 return (-1); 226 227 switch (zpool_prop_get_type(prop)) { --- 44 unchanged lines hidden (view full) --- 272 } 273 274 if (srctype) 275 *srctype = src; 276 277 return (0); 278} 279 | 253 return (0); 254 } 255 256 if (zhp->zpool_props == NULL && zpool_get_all_props(zhp) && 257 prop != ZPOOL_PROP_NAME) 258 return (-1); 259 260 switch (zpool_prop_get_type(prop)) { --- 44 unchanged lines hidden (view full) --- 305 } 306 307 if (srctype) 308 *srctype = src; 309 310 return (0); 311} 312 |
313static boolean_t 314pool_is_bootable(zpool_handle_t *zhp) 315{ 316 char bootfs[ZPOOL_MAXNAMELEN]; 317 318 return (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs, 319 sizeof (bootfs), NULL) == 0 && strncmp(bootfs, "-", 320 sizeof (bootfs)) != 0); 321} 322 323 |
|
280/* 281 * Check if the bootfs name has the same pool name as it is set to. 282 * Assuming bootfs is a valid dataset name. 283 */ 284static boolean_t 285bootfs_name_valid(const char *pool, char *bootfs) 286{ 287 int len = strlen(pool); 288 289 if (!zfs_name_valid(bootfs, ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT)) 290 return (B_FALSE); 291 292 if (strncmp(pool, bootfs, len) == 0 && 293 (bootfs[len] == '/' || bootfs[len] == '\0')) 294 return (B_TRUE); 295 296 return (B_FALSE); 297} 298 | 324/* 325 * Check if the bootfs name has the same pool name as it is set to. 326 * Assuming bootfs is a valid dataset name. 327 */ 328static boolean_t 329bootfs_name_valid(const char *pool, char *bootfs) 330{ 331 int len = strlen(pool); 332 333 if (!zfs_name_valid(bootfs, ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT)) 334 return (B_FALSE); 335 336 if (strncmp(pool, bootfs, len) == 0 && 337 (bootfs[len] == '/' || bootfs[len] == '\0')) 338 return (B_TRUE); 339 340 return (B_FALSE); 341} 342 |
299#if defined(sun) | |
300/* 301 * Inspect the configuration to determine if any of the devices contain 302 * an EFI label. 303 */ 304static boolean_t 305pool_uses_efi(nvlist_t *config) 306{ | 343/* 344 * Inspect the configuration to determine if any of the devices contain 345 * an EFI label. 346 */ 347static boolean_t 348pool_uses_efi(nvlist_t *config) 349{ |
350#ifdef sun |
|
307 nvlist_t **child; 308 uint_t c, children; 309 310 if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN, 311 &child, &children) != 0) 312 return (read_efi_label(config, NULL) >= 0); 313 314 for (c = 0; c < children; c++) { 315 if (pool_uses_efi(child[c])) 316 return (B_TRUE); 317 } | 351 nvlist_t **child; 352 uint_t c, children; 353 354 if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN, 355 &child, &children) != 0) 356 return (read_efi_label(config, NULL) >= 0); 357 358 for (c = 0; c < children; c++) { 359 if (pool_uses_efi(child[c])) 360 return (B_TRUE); 361 } |
362#endif /* sun */ |
|
318 return (B_FALSE); 319} | 363 return (B_FALSE); 364} |
320#endif | |
321 322/* 323 * Given an nvlist of zpool properties to be set, validate that they are 324 * correct, and parse any numeric properties (index, boolean, etc) if they are 325 * specified as strings. 326 */ 327static nvlist_t * 328zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, --- 185 unchanged lines hidden (view full) --- 514 nvlist_t *nvl = NULL; 515 nvlist_t *realprops; 516 uint64_t version; 517 518 (void) snprintf(errbuf, sizeof (errbuf), 519 dgettext(TEXT_DOMAIN, "cannot set property for '%s'"), 520 zhp->zpool_name); 521 | 365 366/* 367 * Given an nvlist of zpool properties to be set, validate that they are 368 * correct, and parse any numeric properties (index, boolean, etc) if they are 369 * specified as strings. 370 */ 371static nvlist_t * 372zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname, --- 185 unchanged lines hidden (view full) --- 558 nvlist_t *nvl = NULL; 559 nvlist_t *realprops; 560 uint64_t version; 561 562 (void) snprintf(errbuf, sizeof (errbuf), 563 dgettext(TEXT_DOMAIN, "cannot set property for '%s'"), 564 zhp->zpool_name); 565 |
522 if (zhp->zpool_props == NULL && zpool_get_all_props(zhp)) 523 return (zfs_error(zhp->zpool_hdl, EZFS_POOLPROPS, errbuf)); 524 | |
525 if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) 526 return (no_memory(zhp->zpool_hdl)); 527 528 if (nvlist_add_string(nvl, propname, propval) != 0) { 529 nvlist_free(nvl); 530 return (no_memory(zhp->zpool_hdl)); 531 } 532 --- 474 unchanged lines hidden (view full) --- 1007 SPA_VERSION_SPARES && 1008 nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 1009 &spares, &nspares) == 0) { 1010 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " 1011 "upgraded to add hot spares")); 1012 return (zfs_error(hdl, EZFS_BADVERSION, msg)); 1013 } 1014 | 566 if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) 567 return (no_memory(zhp->zpool_hdl)); 568 569 if (nvlist_add_string(nvl, propname, propval) != 0) { 570 nvlist_free(nvl); 571 return (no_memory(zhp->zpool_hdl)); 572 } 573 --- 474 unchanged lines hidden (view full) --- 1048 SPA_VERSION_SPARES && 1049 nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 1050 &spares, &nspares) == 0) { 1051 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " 1052 "upgraded to add hot spares")); 1053 return (zfs_error(hdl, EZFS_BADVERSION, msg)); 1054 } 1055 |
1056 if (pool_is_bootable(zhp) && nvlist_lookup_nvlist_array(nvroot, 1057 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0) { 1058 uint64_t s; 1059 1060 for (s = 0; s < nspares; s++) { 1061 char *path; 1062 1063 if (nvlist_lookup_string(spares[s], ZPOOL_CONFIG_PATH, 1064 &path) == 0 && pool_uses_efi(spares[s])) { 1065 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1066 "device '%s' contains an EFI label and " 1067 "cannot be used on root pools."), 1068 zpool_vdev_name(hdl, NULL, spares[s])); 1069 return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg)); 1070 } 1071 } 1072 } 1073 |
|
1015 if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) < 1016 SPA_VERSION_L2CACHE && 1017 nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, 1018 &l2cache, &nl2cache) == 0) { 1019 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " 1020 "upgraded to add cache devices")); 1021 return (zfs_error(hdl, EZFS_BADVERSION, msg)); 1022 } --- 136 unchanged lines hidden (view full) --- 1159 if (altroot != NULL) { 1160 if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { 1161 return (zfs_error_fmt(hdl, EZFS_NOMEM, 1162 dgettext(TEXT_DOMAIN, "cannot import '%s'"), 1163 newname)); 1164 } 1165 1166 if (nvlist_add_string(props, | 1074 if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) < 1075 SPA_VERSION_L2CACHE && 1076 nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, 1077 &l2cache, &nl2cache) == 0) { 1078 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be " 1079 "upgraded to add cache devices")); 1080 return (zfs_error(hdl, EZFS_BADVERSION, msg)); 1081 } --- 136 unchanged lines hidden (view full) --- 1218 if (altroot != NULL) { 1219 if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { 1220 return (zfs_error_fmt(hdl, EZFS_NOMEM, 1221 dgettext(TEXT_DOMAIN, "cannot import '%s'"), 1222 newname)); 1223 } 1224 1225 if (nvlist_add_string(props, |
1167 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0) { | 1226 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0 || 1227 nvlist_add_string(props, 1228 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), "none") != 0) { |
1168 nvlist_free(props); 1169 return (zfs_error_fmt(hdl, EZFS_NOMEM, 1170 dgettext(TEXT_DOMAIN, "cannot import '%s'"), 1171 newname)); 1172 } 1173 } 1174 1175 ret = zpool_import_props(hdl, config, newname, props, B_FALSE); --- 272 unchanged lines hidden (view full) --- 1448 1449/* 1450 * Get phys_path for a root pool 1451 * Return 0 on success; non-zeron on failure. 1452 */ 1453int 1454zpool_get_physpath(zpool_handle_t *zhp, char *physpath) 1455{ | 1229 nvlist_free(props); 1230 return (zfs_error_fmt(hdl, EZFS_NOMEM, 1231 dgettext(TEXT_DOMAIN, "cannot import '%s'"), 1232 newname)); 1233 } 1234 } 1235 1236 ret = zpool_import_props(hdl, config, newname, props, B_FALSE); --- 272 unchanged lines hidden (view full) --- 1509 1510/* 1511 * Get phys_path for a root pool 1512 * Return 0 on success; non-zeron on failure. 1513 */ 1514int 1515zpool_get_physpath(zpool_handle_t *zhp, char *physpath) 1516{ |
1456 char bootfs[ZPOOL_MAXNAMELEN]; | |
1457 nvlist_t *vdev_root; 1458 nvlist_t **child; 1459 uint_t count; 1460 int i; 1461 1462 /* 1463 * Make sure this is a root pool, as phys_path doesn't mean 1464 * anything to a non-root pool. 1465 */ | 1517 nvlist_t *vdev_root; 1518 nvlist_t **child; 1519 uint_t count; 1520 int i; 1521 1522 /* 1523 * Make sure this is a root pool, as phys_path doesn't mean 1524 * anything to a non-root pool. 1525 */ |
1466 if (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs, 1467 sizeof (bootfs), NULL) != 0) | 1526 if (!pool_is_bootable(zhp)) |
1468 return (-1); 1469 1470 verify(nvlist_lookup_nvlist(zhp->zpool_config, 1471 ZPOOL_CONFIG_VDEV_TREE, &vdev_root) == 0); 1472 1473 if (nvlist_lookup_nvlist_array(vdev_root, ZPOOL_CONFIG_CHILDREN, 1474 &child, &count) != 0) 1475 return (-2); --- 257 unchanged lines hidden (view full) --- 1733 nvlist_t *tgt; 1734 boolean_t avail_spare, l2cache, islog; 1735 uint64_t val; 1736 char *path, *newname; 1737 nvlist_t **child; 1738 uint_t children; 1739 nvlist_t *config_root; 1740 libzfs_handle_t *hdl = zhp->zpool_hdl; | 1527 return (-1); 1528 1529 verify(nvlist_lookup_nvlist(zhp->zpool_config, 1530 ZPOOL_CONFIG_VDEV_TREE, &vdev_root) == 0); 1531 1532 if (nvlist_lookup_nvlist_array(vdev_root, ZPOOL_CONFIG_CHILDREN, 1533 &child, &count) != 0) 1534 return (-2); --- 257 unchanged lines hidden (view full) --- 1792 nvlist_t *tgt; 1793 boolean_t avail_spare, l2cache, islog; 1794 uint64_t val; 1795 char *path, *newname; 1796 nvlist_t **child; 1797 uint_t children; 1798 nvlist_t *config_root; 1799 libzfs_handle_t *hdl = zhp->zpool_hdl; |
1800 boolean_t rootpool = pool_is_bootable(zhp); |
|
1741 1742 if (replacing) 1743 (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, 1744 "cannot replace %s with %s"), old_disk, new_disk); 1745 else 1746 (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, 1747 "cannot attach %s to %s"), new_disk, old_disk); 1748 | 1801 1802 if (replacing) 1803 (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, 1804 "cannot replace %s with %s"), old_disk, new_disk); 1805 else 1806 (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, 1807 "cannot attach %s to %s"), new_disk, old_disk); 1808 |
1809 /* 1810 * If this is a root pool, make sure that we're not attaching an 1811 * EFI labeled device. 1812 */ 1813 if (rootpool && pool_uses_efi(nvroot)) { 1814 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1815 "EFI labeled devices are not supported on root pools.")); 1816 return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg)); 1817 } 1818 |
|
1749 (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); 1750 if ((tgt = zpool_find_vdev(zhp, old_disk, &avail_spare, &l2cache, 1751 &islog)) == 0) 1752 return (zfs_error(hdl, EZFS_NODEVICE, msg)); 1753 1754 if (avail_spare) 1755 return (zfs_error(hdl, EZFS_ISSPARE, msg)); 1756 --- 50 unchanged lines hidden (view full) --- 1807 1808 if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0) 1809 return (-1); 1810 1811 ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ATTACH, &zc); 1812 1813 zcmd_free_nvlists(&zc); 1814 | 1819 (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); 1820 if ((tgt = zpool_find_vdev(zhp, old_disk, &avail_spare, &l2cache, 1821 &islog)) == 0) 1822 return (zfs_error(hdl, EZFS_NODEVICE, msg)); 1823 1824 if (avail_spare) 1825 return (zfs_error(hdl, EZFS_ISSPARE, msg)); 1826 --- 50 unchanged lines hidden (view full) --- 1877 1878 if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0) 1879 return (-1); 1880 1881 ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ATTACH, &zc); 1882 1883 zcmd_free_nvlists(&zc); 1884 |
1815 if (ret == 0) | 1885 if (ret == 0) { 1886 if (rootpool) { 1887 /* 1888 * XXX - This should be removed once we can 1889 * automatically install the bootblocks on the 1890 * newly attached disk. 1891 */ 1892 (void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Please " 1893 "be sure to invoke %s to make '%s' bootable.\n"), 1894 BOOTCMD, new_disk); 1895 } |
1816 return (0); | 1896 return (0); |
1897 } |
|
1817 1818 switch (errno) { 1819 case ENOTSUP: 1820 /* 1821 * Can't attach to or replace this type of vdev. 1822 */ 1823 if (replacing) { 1824 if (islog) --- 994 unchanged lines hidden (view full) --- 2819 2820 /* prepare an error message just in case */ 2821 (void) snprintf(errbuf, sizeof (errbuf), 2822 dgettext(TEXT_DOMAIN, "cannot label '%s'"), name); 2823 2824 if (zhp) { 2825 nvlist_t *nvroot; 2826 | 1898 1899 switch (errno) { 1900 case ENOTSUP: 1901 /* 1902 * Can't attach to or replace this type of vdev. 1903 */ 1904 if (replacing) { 1905 if (islog) --- 994 unchanged lines hidden (view full) --- 2900 2901 /* prepare an error message just in case */ 2902 (void) snprintf(errbuf, sizeof (errbuf), 2903 dgettext(TEXT_DOMAIN, "cannot label '%s'"), name); 2904 2905 if (zhp) { 2906 nvlist_t *nvroot; 2907 |
2908 if (pool_is_bootable(zhp)) { 2909 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 2910 "EFI labeled devices are not supported on root " 2911 "pools.")); 2912 return (zfs_error(hdl, EZFS_POOL_NOTSUP, errbuf)); 2913 } 2914 |
|
2827 verify(nvlist_lookup_nvlist(zhp->zpool_config, 2828 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 2829 2830 if (zhp->zpool_start_block == 0) 2831 start_block = find_start_block(nvroot); 2832 else 2833 start_block = zhp->zpool_start_block; 2834 zhp->zpool_start_block = start_block; --- 187 unchanged lines hidden --- | 2915 verify(nvlist_lookup_nvlist(zhp->zpool_config, 2916 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); 2917 2918 if (zhp->zpool_start_block == 0) 2919 start_block = find_start_block(nvroot); 2920 else 2921 start_block = zhp->zpool_start_block; 2922 zhp->zpool_start_block = start_block; --- 187 unchanged lines hidden --- |