Print this page
8264 want support for promoting datasets in libzfs_core


  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
  25  * Portions Copyright 2011 Martin Matuska
  26  * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
  27  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
  29  * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
  30  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
  31  * Copyright (c) 2013 Steven Hartland. All rights reserved.
  32  * Copyright (c) 2014 Integros [integros.com]
  33  * Copyright 2016 Toomas Soome <tsoome@me.com>

  34  */
  35 
  36 /*
  37  * ZFS ioctls.
  38  *
  39  * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
  40  * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
  41  *
  42  * There are two ways that we handle ioctls: the legacy way where almost
  43  * all of the logic is in the ioctl callback, and the new way where most
  44  * of the marshalling is handled in the common entry point, zfsdev_ioctl().
  45  *
  46  * Non-legacy ioctls should be registered by calling
  47  * zfs_ioctl_register() from zfs_ioctl_init().  The ioctl is invoked
  48  * from userland by lzc_ioctl().
  49  *
  50  * The registration arguments are as follows:
  51  *
  52  * const char *name
  53  *   The name of the ioctl.  This is used for history logging.  If the


4685 
4686         spa_vdev_state_enter(spa, SCL_NONE);
4687 
4688         /*
4689          * If a resilver is already in progress then set the
4690          * spa_scrub_reopen flag to B_TRUE so that we don't restart
4691          * the scan as a side effect of the reopen. Otherwise, let
4692          * vdev_open() decided if a resilver is required.
4693          */
4694         spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
4695         vdev_reopen(spa->spa_root_vdev);
4696         spa->spa_scrub_reopen = B_FALSE;
4697 
4698         (void) spa_vdev_state_exit(spa, NULL, 0);
4699         spa_close(spa, FTAG);
4700         return (0);
4701 }
4702 /*
4703  * inputs:
4704  * zc_name      name of filesystem
4705  * zc_value     name of origin snapshot
4706  *
4707  * outputs:
4708  * zc_string    name of conflicting snapshot, if there is one
4709  */
4710 static int
4711 zfs_ioc_promote(zfs_cmd_t *zc)
4712 {



4713         char *cp;

4714 





























4715         /*
4716          * We don't need to unmount *all* the origin fs's snapshots, but
4717          * it's easier.
4718          */
4719         cp = strchr(zc->zc_value, '@');
4720         if (cp)
4721                 *cp = '\0';
4722         (void) dmu_objset_find(zc->zc_value,
4723             zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
4724         return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
4725 }
4726 
4727 /*
4728  * Retrieve a single {user|group}{used|quota}@... property.
4729  *
4730  * inputs:
4731  * zc_name      name of filesystem
4732  * zc_objset_type zfs_userquota_prop_t
4733  * zc_value     domain name (eg. "S-1-234-567-89")
4734  * zc_guid      RID/UID/GID
4735  *
4736  * outputs:
4737  * zc_cookie    property value
4738  */
4739 static int
4740 zfs_ioc_userspace_one(zfs_cmd_t *zc)
4741 {
4742         zfsvfs_t *zfsvfs;




  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
  25  * Portions Copyright 2011 Martin Matuska
  26  * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
  27  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
  29  * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
  30  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
  31  * Copyright (c) 2013 Steven Hartland. All rights reserved.
  32  * Copyright (c) 2014 Integros [integros.com]
  33  * Copyright 2016 Toomas Soome <tsoome@me.com>
  34  * Copyright 2017 RackTop Systems.
  35  */
  36 
  37 /*
  38  * ZFS ioctls.
  39  *
  40  * This file handles the ioctls to /dev/zfs, used for configuring ZFS storage
  41  * pools and filesystems, e.g. with /sbin/zfs and /sbin/zpool.
  42  *
  43  * There are two ways that we handle ioctls: the legacy way where almost
  44  * all of the logic is in the ioctl callback, and the new way where most
  45  * of the marshalling is handled in the common entry point, zfsdev_ioctl().
  46  *
  47  * Non-legacy ioctls should be registered by calling
  48  * zfs_ioctl_register() from zfs_ioctl_init().  The ioctl is invoked
  49  * from userland by lzc_ioctl().
  50  *
  51  * The registration arguments are as follows:
  52  *
  53  * const char *name
  54  *   The name of the ioctl.  This is used for history logging.  If the


4686 
4687         spa_vdev_state_enter(spa, SCL_NONE);
4688 
4689         /*
4690          * If a resilver is already in progress then set the
4691          * spa_scrub_reopen flag to B_TRUE so that we don't restart
4692          * the scan as a side effect of the reopen. Otherwise, let
4693          * vdev_open() decided if a resilver is required.
4694          */
4695         spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
4696         vdev_reopen(spa->spa_root_vdev);
4697         spa->spa_scrub_reopen = B_FALSE;
4698 
4699         (void) spa_vdev_state_exit(spa, NULL, 0);
4700         spa_close(spa, FTAG);
4701         return (0);
4702 }
4703 /*
4704  * inputs:
4705  * zc_name      name of filesystem

4706  *
4707  * outputs:
4708  * zc_string    name of conflicting snapshot, if there is one
4709  */
4710 static int
4711 zfs_ioc_promote(zfs_cmd_t *zc)
4712 {
4713         dsl_pool_t *dp;
4714         dsl_dataset_t *ds, *ods;
4715         char origin[ZFS_MAX_DATASET_NAME_LEN];
4716         char *cp;
4717         int error;
4718 
4719         error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
4720         if (error != 0)
4721                 return (error);
4722 
4723         error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
4724         if (error != 0) {
4725                 dsl_pool_rele(dp, FTAG);
4726                 return (error);
4727         }
4728 
4729         if (!dsl_dir_is_clone(ds->ds_dir)) {
4730                 dsl_dataset_rele(ds, FTAG);
4731                 dsl_pool_rele(dp, FTAG);
4732                 return (SET_ERROR(EINVAL));
4733         }
4734 
4735         error = dsl_dataset_hold_obj(dp,
4736             dsl_dir_phys(ds->ds_dir)->dd_origin_obj, FTAG, &ods);
4737         if (error != 0) {
4738                 dsl_dataset_rele(ds, FTAG);
4739                 dsl_pool_rele(dp, FTAG);
4740                 return (error);
4741         }
4742 
4743         dsl_dataset_name(ods, origin);
4744         dsl_dataset_rele(ods, FTAG);
4745         dsl_dataset_rele(ds, FTAG);
4746         dsl_pool_rele(dp, FTAG);
4747 
4748         /*
4749          * We don't need to unmount *all* the origin fs's snapshots, but
4750          * it's easier.
4751          */
4752         cp = strchr(origin, '@');
4753         if (cp)
4754                 *cp = '\0';
4755         (void) dmu_objset_find(origin,
4756             zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
4757         return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
4758 }
4759 
4760 /*
4761  * Retrieve a single {user|group}{used|quota}@... property.
4762  *
4763  * inputs:
4764  * zc_name      name of filesystem
4765  * zc_objset_type zfs_userquota_prop_t
4766  * zc_value     domain name (eg. "S-1-234-567-89")
4767  * zc_guid      RID/UID/GID
4768  *
4769  * outputs:
4770  * zc_cookie    property value
4771  */
4772 static int
4773 zfs_ioc_userspace_one(zfs_cmd_t *zc)
4774 {
4775         zfsvfs_t *zfsvfs;