405 { |
405 { |
406 int res = Z_OK; |
406 int res = Z_OK; |
407 int err; |
407 int err; |
408 zfs_handle_t *zhp; |
408 zfs_handle_t *zhp; |
409 zfs_handle_t *clone; |
409 zfs_handle_t *clone; |
|
410 nvlist_t *props = NULL; |
410 |
411 |
411 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL) |
412 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL) |
412 return (Z_NO_ENTRY); |
413 return (Z_NO_ENTRY); |
413 |
414 |
414 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name); |
415 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name); |
415 |
416 |
416 err = zfs_clone(zhp, zonepath); |
417 if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0 || |
417 zfs_close(zhp); |
418 nvlist_add_boolean_value(props, |
|
419 zfs_prop_to_name(ZFS_PROP_SHARENFS), B_FALSE) != 0) { |
|
420 nvlist_free(props); |
|
421 (void) fprintf(stderr, gettext("could not create ZFS clone " |
|
422 "%s: out of memory\n"), zonepath); |
|
423 return (Z_ERR); |
|
424 } |
|
425 |
|
426 err = zfs_clone(zhp, zonepath, props); |
|
427 zfs_close(zhp); |
|
428 |
|
429 nvlist_free(props); |
|
430 |
418 if (err != 0) |
431 if (err != 0) |
419 return (Z_ERR); |
432 return (Z_ERR); |
420 |
433 |
421 /* create the mountpoint if necessary */ |
434 /* create the mountpoint if necessary */ |
422 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_ANY)) == NULL) |
435 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_ANY)) == NULL) |
429 if (zfs_mount(clone, NULL, 0) != 0) { |
442 if (zfs_mount(clone, NULL, 0) != 0) { |
430 (void) fprintf(stderr, gettext("could not mount ZFS clone " |
443 (void) fprintf(stderr, gettext("could not mount ZFS clone " |
431 "%s\n"), zfs_get_name(clone)); |
444 "%s\n"), zfs_get_name(clone)); |
432 res = Z_ERR; |
445 res = Z_ERR; |
433 |
446 |
434 } else { |
447 } else if (clean_out_clone() != Z_OK) { |
435 if (zfs_prop_set(clone, ZFS_PROP_SHARENFS, "off") != 0) { |
448 (void) fprintf(stderr, gettext("could not remove the " |
436 /* we won't consider this a failure */ |
449 "software inventory from ZFS clone %s\n"), |
437 (void) fprintf(stderr, gettext("could not turn off the " |
450 zfs_get_name(clone)); |
438 "'sharenfs' property on ZFS clone %s\n"), |
451 res = Z_ERR; |
439 zfs_get_name(clone)); |
|
440 } |
|
441 |
|
442 if (clean_out_clone() != Z_OK) { |
|
443 (void) fprintf(stderr, gettext("could not remove the " |
|
444 "software inventory from ZFS clone %s\n"), |
|
445 zfs_get_name(clone)); |
|
446 res = Z_ERR; |
|
447 } |
|
448 } |
452 } |
449 |
453 |
450 zfs_close(clone); |
454 zfs_close(clone); |
451 return (res); |
455 return (res); |
452 } |
456 } |
698 void |
702 void |
699 create_zfs_zonepath(char *zonepath) |
703 create_zfs_zonepath(char *zonepath) |
700 { |
704 { |
701 zfs_handle_t *zhp; |
705 zfs_handle_t *zhp; |
702 char zfs_name[MAXPATHLEN]; |
706 char zfs_name[MAXPATHLEN]; |
|
707 nvlist_t *props = NULL; |
703 |
708 |
704 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK) |
709 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK) |
705 return; |
710 return; |
706 |
711 |
707 if (zfs_create(g_zfs, zfs_name, ZFS_TYPE_FILESYSTEM, NULL, NULL) != 0 || |
712 if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0 || |
|
713 nvlist_add_boolean_value(props, zfs_prop_to_name(ZFS_PROP_SHARENFS), |
|
714 B_FALSE) != 0) { |
|
715 nvlist_free(props); |
|
716 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: " |
|
717 "out of memory\n"), zfs_name); |
|
718 } |
|
719 |
|
720 if (zfs_create(g_zfs, zfs_name, ZFS_TYPE_FILESYSTEM, props) != 0 || |
708 (zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_ANY)) == NULL) { |
721 (zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_ANY)) == NULL) { |
709 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: " |
722 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: " |
710 "%s\n"), zfs_name, libzfs_error_description(g_zfs)); |
723 "%s\n"), zfs_name, libzfs_error_description(g_zfs)); |
|
724 nvlist_free(props); |
711 return; |
725 return; |
712 } |
726 } |
|
727 |
|
728 nvlist_free(props); |
713 |
729 |
714 if (zfs_mount(zhp, NULL, 0) != 0) { |
730 if (zfs_mount(zhp, NULL, 0) != 0) { |
715 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: " |
731 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: " |
716 "%s\n"), zfs_name, libzfs_error_description(g_zfs)); |
732 "%s\n"), zfs_name, libzfs_error_description(g_zfs)); |
717 (void) zfs_destroy(zhp); |
733 (void) zfs_destroy(zhp); |
718 } else if (zfs_prop_set(zhp, ZFS_PROP_SHARENFS, "off") != 0) { |
|
719 (void) fprintf(stderr, gettext("file system %s successfully " |
|
720 "created,\nbut could not turn off the 'sharenfs' " |
|
721 "property\n"), zfs_name); |
|
722 } else { |
734 } else { |
723 if (chmod(zonepath, S_IRWXU) != 0) { |
735 if (chmod(zonepath, S_IRWXU) != 0) { |
724 (void) fprintf(stderr, gettext("file system %s " |
736 (void) fprintf(stderr, gettext("file system %s " |
725 "successfully created, but chmod %o failed: %s\n"), |
737 "successfully created, but chmod %o failed: %s\n"), |
726 zfs_name, S_IRWXU, strerror(errno)); |
738 zfs_name, S_IRWXU, strerror(errno)); |
847 zfs_handle_t *zhp; |
859 zfs_handle_t *zhp; |
848 |
860 |
849 if ((zhp = mount2zhandle(zonepath)) == NULL) |
861 if ((zhp = mount2zhandle(zonepath)) == NULL) |
850 return (Z_ERR); |
862 return (Z_ERR); |
851 |
863 |
852 if (zfs_prop_set(zhp, ZFS_PROP_MOUNTPOINT, new_zonepath) == 0) { |
864 if (zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT), |
|
865 new_zonepath) == 0) { |
853 /* |
866 /* |
854 * Clean up the old mount point. We ignore any failure since |
867 * Clean up the old mount point. We ignore any failure since |
855 * the zone is already successfully mounted on the new path. |
868 * the zone is already successfully mounted on the new path. |
856 */ |
869 */ |
857 (void) rmdir(zonepath); |
870 (void) rmdir(zonepath); |