364 int err;
365 zfs_handle_t *zhp;
366 zfs_handle_t *clone;
367 nvlist_t *props = NULL;
368
369 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL)
370 return (Z_NO_ENTRY);
371
372 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name);
373
374 /*
375 * We turn off zfs SHARENFS and SHARESMB properties on the
376 * zoneroot dataset in order to prevent the GZ from sharing
377 * NGZ data by accident.
378 */
379 if ((nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) ||
380 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARENFS),
381 "off") != 0) ||
382 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARESMB),
383 "off") != 0)) {
384 if (props != NULL)
385 nvlist_free(props);
386 (void) fprintf(stderr, gettext("could not create ZFS clone "
387 "%s: out of memory\n"), zonepath);
388 return (Z_ERR);
389 }
390
391 err = zfs_clone(zhp, zonepath, props);
392 zfs_close(zhp);
393
394 nvlist_free(props);
395
396 if (err != 0)
397 return (Z_ERR);
398
399 /* create the mountpoint if necessary */
400 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_DATASET)) == NULL)
401 return (Z_ERR);
402
403 /*
404 * The clone has been created so we need to print a diagnostic
971
972 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK)
973 return;
974
975 /* Check if the dataset already exists. */
976 if ((zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_DATASET)) != NULL) {
977 zfs_close(zhp);
978 return;
979 }
980
981 /*
982 * We turn off zfs SHARENFS and SHARESMB properties on the
983 * zoneroot dataset in order to prevent the GZ from sharing
984 * NGZ data by accident.
985 */
986 if ((nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) ||
987 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARENFS),
988 "off") != 0) ||
989 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARESMB),
990 "off") != 0)) {
991 if (props != NULL)
992 nvlist_free(props);
993 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
994 "out of memory\n"), zfs_name);
995 }
996
997 if (zfs_create(g_zfs, zfs_name, ZFS_TYPE_FILESYSTEM, props) != 0 ||
998 (zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_DATASET)) == NULL) {
999 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
1000 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
1001 nvlist_free(props);
1002 return;
1003 }
1004
1005 nvlist_free(props);
1006
1007 if (zfs_mount(zhp, NULL, 0) != 0) {
1008 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: "
1009 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
1010 (void) zfs_destroy(zhp, B_FALSE);
1011 } else {
|
364 int err;
365 zfs_handle_t *zhp;
366 zfs_handle_t *clone;
367 nvlist_t *props = NULL;
368
369 if ((zhp = zfs_open(g_zfs, snapshot_name, ZFS_TYPE_SNAPSHOT)) == NULL)
370 return (Z_NO_ENTRY);
371
372 (void) printf(gettext("Cloning snapshot %s\n"), snapshot_name);
373
374 /*
375 * We turn off zfs SHARENFS and SHARESMB properties on the
376 * zoneroot dataset in order to prevent the GZ from sharing
377 * NGZ data by accident.
378 */
379 if ((nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) ||
380 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARENFS),
381 "off") != 0) ||
382 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARESMB),
383 "off") != 0)) {
384 nvlist_free(props);
385 (void) fprintf(stderr, gettext("could not create ZFS clone "
386 "%s: out of memory\n"), zonepath);
387 return (Z_ERR);
388 }
389
390 err = zfs_clone(zhp, zonepath, props);
391 zfs_close(zhp);
392
393 nvlist_free(props);
394
395 if (err != 0)
396 return (Z_ERR);
397
398 /* create the mountpoint if necessary */
399 if ((clone = zfs_open(g_zfs, zonepath, ZFS_TYPE_DATASET)) == NULL)
400 return (Z_ERR);
401
402 /*
403 * The clone has been created so we need to print a diagnostic
970
971 if (path2name(zonepath, zfs_name, sizeof (zfs_name)) != Z_OK)
972 return;
973
974 /* Check if the dataset already exists. */
975 if ((zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_DATASET)) != NULL) {
976 zfs_close(zhp);
977 return;
978 }
979
980 /*
981 * We turn off zfs SHARENFS and SHARESMB properties on the
982 * zoneroot dataset in order to prevent the GZ from sharing
983 * NGZ data by accident.
984 */
985 if ((nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) ||
986 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARENFS),
987 "off") != 0) ||
988 (nvlist_add_string(props, zfs_prop_to_name(ZFS_PROP_SHARESMB),
989 "off") != 0)) {
990 nvlist_free(props);
991 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
992 "out of memory\n"), zfs_name);
993 }
994
995 if (zfs_create(g_zfs, zfs_name, ZFS_TYPE_FILESYSTEM, props) != 0 ||
996 (zhp = zfs_open(g_zfs, zfs_name, ZFS_TYPE_DATASET)) == NULL) {
997 (void) fprintf(stderr, gettext("cannot create ZFS dataset %s: "
998 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
999 nvlist_free(props);
1000 return;
1001 }
1002
1003 nvlist_free(props);
1004
1005 if (zfs_mount(zhp, NULL, 0) != 0) {
1006 (void) fprintf(stderr, gettext("cannot mount ZFS dataset %s: "
1007 "%s\n"), zfs_name, libzfs_error_description(g_zfs));
1008 (void) zfs_destroy(zhp, B_FALSE);
1009 } else {
|