13 * When distributing Covered Code, include this CDDL HEADER in each
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) 2013, Joyent, Inc. All rights reserved.
25 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
26 * Copyright (c) 2012 DEY Storage Systems, Inc. All rights reserved.
27 * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
28 * Copyright (c) 2013 Martin Matuska. All rights reserved.
29 * Copyright (c) 2013 Steven Hartland. All rights reserved.
30 * Copyright (c) 2014 Integros [integros.com]
31 * Copyright 2016 Nexenta Systems, Inc.
32 * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
33 */
34
35 #include <ctype.h>
36 #include <errno.h>
37 #include <libintl.h>
38 #include <math.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <strings.h>
42 #include <unistd.h>
43 #include <stddef.h>
44 #include <zone.h>
45 #include <fcntl.h>
46 #include <sys/mntent.h>
47 #include <sys/mount.h>
48 #include <priv.h>
49 #include <pwd.h>
50 #include <grp.h>
51 #include <stddef.h>
52 #include <ucred.h>
3611 "source and target pools differ"));
3612 return (zfs_error(zhp->zfs_hdl, EZFS_CROSSTARGET,
3613 errbuf));
3614
3615 default:
3616 return (zfs_standard_error(zhp->zfs_hdl, errno,
3617 errbuf));
3618 }
3619 }
3620
3621 return (ret);
3622 }
3623
3624 /*
3625 * Promotes the given clone fs to be the clone parent.
3626 */
3627 int
3628 zfs_promote(zfs_handle_t *zhp)
3629 {
3630 libzfs_handle_t *hdl = zhp->zfs_hdl;
3631 zfs_cmd_t zc = { 0 };
3632 char parent[MAXPATHLEN];
3633 int ret;
3634 char errbuf[1024];
3635
3636 (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
3637 "cannot promote '%s'"), zhp->zfs_name);
3638
3639 if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
3640 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3641 "snapshots can not be promoted"));
3642 return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3643 }
3644
3645 (void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
3646 if (parent[0] == '\0') {
3647 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3648 "not a cloned filesystem"));
3649 return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3650 }
3651
3652 (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
3653 sizeof (zc.zc_value));
3654 (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
3655 ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc);
3656
3657 if (ret != 0) {
3658 int save_errno = errno;
3659
3660 switch (save_errno) {
3661 case EEXIST:
3662 /* There is a conflicting snapshot name. */
3663 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3664 "conflicting snapshot '%s' from parent '%s'"),
3665 zc.zc_string, parent);
3666 return (zfs_error(hdl, EZFS_EXISTS, errbuf));
3667
3668 default:
3669 return (zfs_standard_error(hdl, save_errno, errbuf));
3670 }
3671 }
3672 return (ret);
3673 }
3674
3675 typedef struct snapdata {
3676 nvlist_t *sd_nvl;
3677 const char *sd_snapname;
3678 } snapdata_t;
3679
3680 static int
3681 zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
3682 {
3683 snapdata_t *sd = arg;
3684 char name[ZFS_MAX_DATASET_NAME_LEN];
3685 int rv = 0;
|
13 * When distributing Covered Code, include this CDDL HEADER in each
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) 2013, Joyent, Inc. All rights reserved.
25 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
26 * Copyright (c) 2012 DEY Storage Systems, Inc. All rights reserved.
27 * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
28 * Copyright (c) 2013 Martin Matuska. All rights reserved.
29 * Copyright (c) 2013 Steven Hartland. All rights reserved.
30 * Copyright (c) 2014 Integros [integros.com]
31 * Copyright 2016 Nexenta Systems, Inc.
32 * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
33 * Copyright 2017 RackTop Systems.
34 */
35
36 #include <ctype.h>
37 #include <errno.h>
38 #include <libintl.h>
39 #include <math.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <strings.h>
43 #include <unistd.h>
44 #include <stddef.h>
45 #include <zone.h>
46 #include <fcntl.h>
47 #include <sys/mntent.h>
48 #include <sys/mount.h>
49 #include <priv.h>
50 #include <pwd.h>
51 #include <grp.h>
52 #include <stddef.h>
53 #include <ucred.h>
3612 "source and target pools differ"));
3613 return (zfs_error(zhp->zfs_hdl, EZFS_CROSSTARGET,
3614 errbuf));
3615
3616 default:
3617 return (zfs_standard_error(zhp->zfs_hdl, errno,
3618 errbuf));
3619 }
3620 }
3621
3622 return (ret);
3623 }
3624
3625 /*
3626 * Promotes the given clone fs to be the clone parent.
3627 */
3628 int
3629 zfs_promote(zfs_handle_t *zhp)
3630 {
3631 libzfs_handle_t *hdl = zhp->zfs_hdl;
3632 char snapname[MAXPATHLEN];
3633 int ret;
3634 char errbuf[1024];
3635
3636 (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
3637 "cannot promote '%s'"), zhp->zfs_name);
3638
3639 if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
3640 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3641 "snapshots can not be promoted"));
3642 return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3643 }
3644
3645 if (zhp->zfs_dmustats.dds_origin[0] == '\0') {
3646 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3647 "not a cloned filesystem"));
3648 return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3649 }
3650
3651 ret = lzc_promote(zhp->zfs_name, snapname, sizeof(snapname));
3652
3653 if (ret != 0) {
3654 int save_errno = errno;
3655
3656 switch (save_errno) {
3657 case EEXIST:
3658 /* There is a conflicting snapshot name. */
3659 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3660 "conflicting snapshot '%s' from parent '%s'"),
3661 snapname, zhp->zfs_dmustats.dds_origin);
3662 return (zfs_error(hdl, EZFS_EXISTS, errbuf));
3663
3664 default:
3665 return (zfs_standard_error(hdl, save_errno, errbuf));
3666 }
3667 }
3668 return (ret);
3669 }
3670
3671 typedef struct snapdata {
3672 nvlist_t *sd_nvl;
3673 const char *sd_snapname;
3674 } snapdata_t;
3675
3676 static int
3677 zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
3678 {
3679 snapdata_t *sd = arg;
3680 char name[ZFS_MAX_DATASET_NAME_LEN];
3681 int rv = 0;
|