zfs.c (3bb79bece53191f2cf27aa61a72ea1784a7ce700) zfs.c (e9dbad6f263d5570ed7ff5443ec5b958af8c24d7)
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

--- 393 unchanged lines hidden (view full) ---

402 */
403static int
404clone_snap(char *snapshot_name, char *zonepath)
405{
406 int res = Z_OK;
407 int err;
408 zfs_handle_t *zhp;
409 zfs_handle_t *clone;
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

--- 393 unchanged lines hidden (view full) ---

402 */
403static int
404clone_snap(char *snapshot_name, char *zonepath)
405{
406 int res = Z_OK;
407 int err;
408 zfs_handle_t *zhp;
409 zfs_handle_t *clone;
410 nvlist_t *props = NULL;
410
411 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL)
412 return (Z_NO_ENTRY);
413
414 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name);
415
411
412 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL)
413 return (Z_NO_ENTRY);
414
415 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name);
416
416 err = zfs_clone(zhp, zonepath);
417 if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0 ||
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);
417 zfs_close(zhp);
427 zfs_close(zhp);
428
429 nvlist_free(props);
430
418 if (err != 0)
419 return (Z_ERR);
420
421 /* create the mountpoint if necessary */
422 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_ANY)) == NULL)
423 return (Z_ERR);
424
425 /*
426 * The clone has been created so we need to print a diagnostic
427 * message if one of the following steps fails for some reason.
428 */
429 if (zfs_mount(clone, NULL, 0) != 0) {
430 (void) fprintf(stderr, gettext("could not mount ZFS clone "
431 "%s\n"), zfs_get_name(clone));
432 res = Z_ERR;
433
431 if (err != 0)
432 return (Z_ERR);
433
434 /* create the mountpoint if necessary */
435 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_ANY)) == NULL)
436 return (Z_ERR);
437
438 /*
439 * The clone has been created so we need to print a diagnostic
440 * message if one of the following steps fails for some reason.
441 */
442 if (zfs_mount(clone, NULL, 0) != 0) {
443 (void) fprintf(stderr, gettext("could not mount ZFS clone "
444 "%s\n"), zfs_get_name(clone));
445 res = Z_ERR;
446
434 } else {
435 if (zfs_prop_set(clone, ZFS_PROP_SHARENFS, "off") != 0) {
436 /* we won't consider this a failure */
437 (void) fprintf(stderr, gettext("could not turn off the "
438 "'sharenfs' property on ZFS clone %s\n"),
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 }
447 } else if (clean_out_clone() != Z_OK) {
448 (void) fprintf(stderr, gettext("could not remove the "
449 "software inventory from ZFS clone %s\n"),
450 zfs_get_name(clone));
451 res = Z_ERR;
448 }
449
450 zfs_close(clone);
451 return (res);
452}
453
454/*
455 * This function takes a zonepath and attempts to determine what the ZFS

--- 239 unchanged lines hidden (view full) ---

695 * on the zonepath or we don't. The caller doesn't care since a regular
696 * directory is used for the zonepath if no ZFS file system is mounted there.
697 */
698void
699create_zfs_zonepath(char *zonepath)
700{
701 zfs_handle_t *zhp;
702 char zfs_name[MAXPATHLEN];
452 }
453
454 zfs_close(clone);
455 return (res);
456}
457
458/*
459 * This function takes a zonepath and attempts to determine what the ZFS

--- 239 unchanged lines hidden (view full) ---

699 * on the zonepath or we don't. The caller doesn't care since a regular
700 * directory is used for the zonepath if no ZFS file system is mounted there.
701 */
702void
703create_zfs_zonepath(char *zonepath)
704{
705 zfs_handle_t *zhp;
706 char zfs_name[MAXPATHLEN];
707 nvlist_t *props = NULL;
703
704 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK)
705 return;
706
708
709 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK)
710 return;
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) {
709 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
710 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
721 (zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_ANY)) == NULL) {
722 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
723 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
724 nvlist_free(props);
711 return;
712 }
713
725 return;
726 }
727
728 nvlist_free(props);
729
714 if (zfs_mount(zhp, NULL, 0) != 0) {
715 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: "
716 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
717 (void) zfs_destroy(zhp);
730 if (zfs_mount(zhp, NULL, 0) != 0) {
731 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: "
732 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
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 {
723 if (chmod(zonepath, S_IRWXU) != 0) {
724 (void) fprintf(stderr, gettext("file system %s "
725 "successfully created, but chmod %o failed: %s\n"),
726 zfs_name, S_IRWXU, strerror(errno));
727 (void) destroy_zfs(zonepath);
728 } else {
729 (void) printf(gettext("A ZFS file system has been "

--- 114 unchanged lines hidden (view full) ---

844move_zfs(char *zonepath, char *new_zonepath)
845{
846 int ret = Z_ERR;
847 zfs_handle_t *zhp;
848
849 if ((zhp = mount2zhandle(zonepath)) == NULL)
850 return (Z_ERR);
851
734 } else {
735 if (chmod(zonepath, S_IRWXU) != 0) {
736 (void) fprintf(stderr, gettext("file system %s "
737 "successfully created, but chmod %o failed: %s\n"),
738 zfs_name, S_IRWXU, strerror(errno));
739 (void) destroy_zfs(zonepath);
740 } else {
741 (void) printf(gettext("A ZFS file system has been "

--- 114 unchanged lines hidden (view full) ---

856move_zfs(char *zonepath, char *new_zonepath)
857{
858 int ret = Z_ERR;
859 zfs_handle_t *zhp;
860
861 if ((zhp = mount2zhandle(zonepath)) == NULL)
862 return (Z_ERR);
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 /*
854 * Clean up the old mount point. We ignore any failure since
855 * the zone is already successfully mounted on the new path.
856 */
857 (void) rmdir(zonepath);
858 ret = Z_OK;
859 }
860

--- 125 unchanged lines hidden ---
866 /*
867 * Clean up the old mount point. We ignore any failure since
868 * the zone is already successfully mounted on the new path.
869 */
870 (void) rmdir(zonepath);
871 ret = Z_OK;
872 }
873

--- 125 unchanged lines hidden ---