218 vdev_stat_t *vs;
219 uint_t vsc;
220
221 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
222 switch (prop) {
223 case ZPOOL_PROP_NAME:
224 (void) strlcpy(buf, zpool_get_name(zhp), len);
225 break;
226
227 case ZPOOL_PROP_HEALTH:
228 (void) strlcpy(buf, "FAULTED", len);
229 break;
230
231 case ZPOOL_PROP_GUID:
232 intval = zpool_get_prop_int(zhp, prop, &src);
233 (void) snprintf(buf, len, "%llu", intval);
234 break;
235
236 case ZPOOL_PROP_ALTROOT:
237 case ZPOOL_PROP_CACHEFILE:
238 if (zhp->zpool_props != NULL ||
239 zpool_get_all_props(zhp) == 0) {
240 (void) strlcpy(buf,
241 zpool_get_prop_string(zhp, prop, &src),
242 len);
243 if (srctype != NULL)
244 *srctype = src;
245 return (0);
246 }
247 /* FALLTHROUGH */
248 default:
249 (void) strlcpy(buf, "-", len);
250 break;
251 }
252
253 if (srctype != NULL)
254 *srctype = src;
255 return (0);
256 }
257
367 return (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs,
368 sizeof (bootfs), NULL) == 0 && strncmp(bootfs, "-",
369 sizeof (bootfs)) != 0);
370 }
371
372
373 /*
374 * Given an nvlist of zpool properties to be set, validate that they are
375 * correct, and parse any numeric properties (index, boolean, etc) if they are
376 * specified as strings.
377 */
378 static nvlist_t *
379 zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
380 nvlist_t *props, uint64_t version, prop_flags_t flags, char *errbuf)
381 {
382 nvpair_t *elem;
383 nvlist_t *retprops;
384 zpool_prop_t prop;
385 char *strval;
386 uint64_t intval;
387 char *slash;
388 struct stat64 statbuf;
389 zpool_handle_t *zhp;
390 nvlist_t *nvroot;
391
392 if (nvlist_alloc(&retprops, NV_UNIQUE_NAME, 0) != 0) {
393 (void) no_memory(hdl);
394 return (NULL);
395 }
396
397 elem = NULL;
398 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
399 const char *propname = nvpair_name(elem);
400
401 /*
402 * Make sure this property is valid and applies to this type.
403 */
404 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
405 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
406 "invalid property '%s'"), propname);
407 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
526 "'%s' is not a valid file"), strval);
527 (void) zfs_error(hdl, EZFS_BADPATH, errbuf);
528 goto error;
529 }
530
531 *slash = '\0';
532
533 if (strval[0] != '\0' &&
534 (stat64(strval, &statbuf) != 0 ||
535 !S_ISDIR(statbuf.st_mode))) {
536 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
537 "'%s' is not a valid directory"),
538 strval);
539 (void) zfs_error(hdl, EZFS_BADPATH, errbuf);
540 goto error;
541 }
542
543 *slash = '/';
544 break;
545
546 case ZPOOL_PROP_READONLY:
547 if (!flags.import) {
548 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
549 "property '%s' can only be set at "
550 "import time"), propname);
551 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
552 goto error;
553 }
554 break;
555 }
556 }
557
558 return (retprops);
559 error:
560 nvlist_free(retprops);
561 return (NULL);
562 }
563
564 /*
565 * Set zpool property : propname=propval.
|
218 vdev_stat_t *vs;
219 uint_t vsc;
220
221 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
222 switch (prop) {
223 case ZPOOL_PROP_NAME:
224 (void) strlcpy(buf, zpool_get_name(zhp), len);
225 break;
226
227 case ZPOOL_PROP_HEALTH:
228 (void) strlcpy(buf, "FAULTED", len);
229 break;
230
231 case ZPOOL_PROP_GUID:
232 intval = zpool_get_prop_int(zhp, prop, &src);
233 (void) snprintf(buf, len, "%llu", intval);
234 break;
235
236 case ZPOOL_PROP_ALTROOT:
237 case ZPOOL_PROP_CACHEFILE:
238 case ZPOOL_PROP_COMMENT:
239 if (zhp->zpool_props != NULL ||
240 zpool_get_all_props(zhp) == 0) {
241 (void) strlcpy(buf,
242 zpool_get_prop_string(zhp, prop, &src),
243 len);
244 if (srctype != NULL)
245 *srctype = src;
246 return (0);
247 }
248 /* FALLTHROUGH */
249 default:
250 (void) strlcpy(buf, "-", len);
251 break;
252 }
253
254 if (srctype != NULL)
255 *srctype = src;
256 return (0);
257 }
258
368 return (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs,
369 sizeof (bootfs), NULL) == 0 && strncmp(bootfs, "-",
370 sizeof (bootfs)) != 0);
371 }
372
373
374 /*
375 * Given an nvlist of zpool properties to be set, validate that they are
376 * correct, and parse any numeric properties (index, boolean, etc) if they are
377 * specified as strings.
378 */
379 static nvlist_t *
380 zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
381 nvlist_t *props, uint64_t version, prop_flags_t flags, char *errbuf)
382 {
383 nvpair_t *elem;
384 nvlist_t *retprops;
385 zpool_prop_t prop;
386 char *strval;
387 uint64_t intval;
388 char *slash, *check;
389 struct stat64 statbuf;
390 zpool_handle_t *zhp;
391 nvlist_t *nvroot;
392
393 if (nvlist_alloc(&retprops, NV_UNIQUE_NAME, 0) != 0) {
394 (void) no_memory(hdl);
395 return (NULL);
396 }
397
398 elem = NULL;
399 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
400 const char *propname = nvpair_name(elem);
401
402 /*
403 * Make sure this property is valid and applies to this type.
404 */
405 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
406 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
407 "invalid property '%s'"), propname);
408 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
527 "'%s' is not a valid file"), strval);
528 (void) zfs_error(hdl, EZFS_BADPATH, errbuf);
529 goto error;
530 }
531
532 *slash = '\0';
533
534 if (strval[0] != '\0' &&
535 (stat64(strval, &statbuf) != 0 ||
536 !S_ISDIR(statbuf.st_mode))) {
537 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
538 "'%s' is not a valid directory"),
539 strval);
540 (void) zfs_error(hdl, EZFS_BADPATH, errbuf);
541 goto error;
542 }
543
544 *slash = '/';
545 break;
546
547 case ZPOOL_PROP_COMMENT:
548 for (check = strval; *check != '\0'; check++) {
549 if (!isprint(*check)) {
550 zfs_error_aux(hdl,
551 dgettext(TEXT_DOMAIN,
552 "comment may only have printable "
553 "characters"));
554 (void) zfs_error(hdl, EZFS_BADPROP,
555 errbuf);
556 goto error;
557 }
558 }
559 if (strlen(strval) > ZPROP_MAX_COMMENT) {
560 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
561 "comment must not exceed %d characters"),
562 ZPROP_MAX_COMMENT);
563 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
564 goto error;
565 }
566 break;
567 case ZPOOL_PROP_READONLY:
568 if (!flags.import) {
569 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
570 "property '%s' can only be set at "
571 "import time"), propname);
572 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
573 goto error;
574 }
575 break;
576 }
577 }
578
579 return (retprops);
580 error:
581 nvlist_free(retprops);
582 return (NULL);
583 }
584
585 /*
586 * Set zpool property : propname=propval.
|