diff options
author | mm <mm@FreeBSD.org> | 2013-03-19 12:51:18 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2013-03-19 12:51:18 +0000 |
commit | 7c87858955593be19a80e57b7353b09f5587ae9b (patch) | |
tree | 68fb8eac18f4259926de9bd4d4ecba5b46b638c3 /cddl/contrib/opensolaris/lib/libzfs_core/common | |
parent | c94cc27299ba2ab2acf00ca31ec90c92a37b16f7 (diff) | |
parent | 09a831de87c71a9f94f38dbd36b73746467e3182 (diff) | |
download | FreeBSD-src-7c87858955593be19a80e57b7353b09f5587ae9b.zip FreeBSD-src-7c87858955593be19a80e57b7353b09f5587ae9b.tar.gz |
MFV r247580:
Merge synctask code restructuring from vendor.
Modify forward and backward compatibility to support new change.
Illumos ZFS issues:
3464 zfs synctask code needs restructuring
Sponsored by: Hybrid Logic Ltd.
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libzfs_core/common')
3 files changed, 160 insertions, 8 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c index 83d0296..ab23aa1 100644 --- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c +++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c @@ -156,6 +156,7 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name, zc.zc_nvlist_src_size = size; if (resultp != NULL) { + *resultp = NULL; zc.zc_nvlist_dst_size = MAX(size * 2, 128 * 1024); zc.zc_nvlist_dst = (uint64_t)(uintptr_t) malloc(zc.zc_nvlist_dst_size); @@ -196,8 +197,6 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name, if (zc.zc_nvlist_dst_filled) { *resultp = fnvlist_unpack((void *)(uintptr_t)zc.zc_nvlist_dst, zc.zc_nvlist_dst_size); - } else if (resultp != NULL) { - *resultp = NULL; } #ifdef __FreeBSD__ if (zfs_ioctl_version < ZFS_IOCVER_LZC) @@ -256,7 +255,7 @@ lzc_clone(const char *fsname, const char *origin, * The value will be the (int32) error code. * * The return value will be 0 if all snapshots were created, otherwise it will - * be the errno of a (undetermined) snapshot that failed. + * be the errno of a (unspecified) snapshot that failed. */ int lzc_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t **errlist) @@ -305,7 +304,7 @@ lzc_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t **errlist) * The return value will be 0 if all snapshots were destroyed (or marked for * later destruction if 'defer' is set) or didn't exist to begin with. * - * Otherwise the return value will be the errno of a (undetermined) snapshot + * Otherwise the return value will be the errno of a (unspecified) snapshot * that failed, no snapshots will be destroyed, and the errlist will have an * entry for each snapshot that failed. The value in the errlist will be * the (int32) error code. @@ -380,6 +379,101 @@ lzc_exists(const char *dataset) } /* + * Create "user holds" on snapshots. If there is a hold on a snapshot, + * the snapshot can not be destroyed. (However, it can be marked for deletion + * by lzc_destroy_snaps(defer=B_TRUE).) + * + * The keys in the nvlist are snapshot names. + * The snapshots must all be in the same pool. + * The value is the name of the hold (string type). + * + * If cleanup_fd is not -1, it must be the result of open("/dev/zfs", O_EXCL). + * In this case, when the cleanup_fd is closed (including on process + * termination), the holds will be released. If the system is shut down + * uncleanly, the holds will be released when the pool is next opened + * or imported. + * + * The return value will be 0 if all holds were created. Otherwise the return + * value will be the errno of a (unspecified) hold that failed, no holds will + * be created, and the errlist will have an entry for each hold that + * failed (name = snapshot). The value in the errlist will be the error + * code (int32). + */ +int +lzc_hold(nvlist_t *holds, int cleanup_fd, nvlist_t **errlist) +{ + char pool[MAXNAMELEN]; + nvlist_t *args; + nvpair_t *elem; + int error; + + /* determine the pool name */ + elem = nvlist_next_nvpair(holds, NULL); + if (elem == NULL) + return (0); + (void) strlcpy(pool, nvpair_name(elem), sizeof (pool)); + pool[strcspn(pool, "/@")] = '\0'; + + args = fnvlist_alloc(); + fnvlist_add_nvlist(args, "holds", holds); + if (cleanup_fd != -1) + fnvlist_add_int32(args, "cleanup_fd", cleanup_fd); + + error = lzc_ioctl(ZFS_IOC_HOLD, pool, args, errlist); + nvlist_free(args); + return (error); +} + +/* + * Release "user holds" on snapshots. If the snapshot has been marked for + * deferred destroy (by lzc_destroy_snaps(defer=B_TRUE)), it does not have + * any clones, and all the user holds are removed, then the snapshot will be + * destroyed. + * + * The keys in the nvlist are snapshot names. + * The snapshots must all be in the same pool. + * The value is a nvlist whose keys are the holds to remove. + * + * The return value will be 0 if all holds were removed. + * Otherwise the return value will be the errno of a (unspecified) release + * that failed, no holds will be released, and the errlist will have an + * entry for each snapshot that has failed releases (name = snapshot). + * The value in the errlist will be the error code (int32) of a failed release. + */ +int +lzc_release(nvlist_t *holds, nvlist_t **errlist) +{ + char pool[MAXNAMELEN]; + nvpair_t *elem; + + /* determine the pool name */ + elem = nvlist_next_nvpair(holds, NULL); + if (elem == NULL) + return (0); + (void) strlcpy(pool, nvpair_name(elem), sizeof (pool)); + pool[strcspn(pool, "/@")] = '\0'; + + return (lzc_ioctl(ZFS_IOC_RELEASE, pool, holds, errlist)); +} + +/* + * Retrieve list of user holds on the specified snapshot. + * + * On success, *holdsp will be set to a nvlist which the caller must free. + * The keys are the names of the holds, and the value is the creation time + * of the hold (uint64) in seconds since the epoch. + */ +int +lzc_get_holds(const char *snapname, nvlist_t **holdsp) +{ + int error; + nvlist_t *innvl = fnvlist_alloc(); + error = lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, innvl, holdsp); + fnvlist_free(innvl); + return (error); +} + +/* * If fromsnap is NULL, a full (non-incremental) stream will be sent. */ int diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h index c8bfbef..b10098b 100644 --- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h +++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h @@ -47,6 +47,10 @@ int lzc_destroy_snaps(nvlist_t *snaps, boolean_t defer, nvlist_t **errlist); int lzc_snaprange_space(const char *firstsnap, const char *lastsnap, uint64_t *usedp); +int lzc_hold(nvlist_t *holds, int cleanup_fd, nvlist_t **errlist); +int lzc_release(nvlist_t *holds, nvlist_t **errlist); +int lzc_get_holds(const char *snapname, nvlist_t **holdsp); + int lzc_send(const char *snapname, const char *fromsnap, int fd); int lzc_receive(const char *snapname, nvlist_t *props, const char *origin, boolean_t force, int fd); diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core_compat.c b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core_compat.c index c19be1f..a3b872e 100644 --- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core_compat.c +++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core_compat.c @@ -33,10 +33,11 @@ int lzc_compat_pre(zfs_cmd_t *zc, zfs_ioc_t *ioc, nvlist_t **source) { nvlist_t *nvl = NULL; - nvpair_t *pair; - char *buf; + nvpair_t *pair, *hpair; + char *buf, *val; zfs_ioc_t vecnum; uint32_t type32; + int32_t cleanup_fd; int error = 0; int pos; @@ -68,7 +69,7 @@ lzc_compat_pre(zfs_cmd_t *zc, zfs_ioc_t *ioc, nvlist_t **source) strlcpy(zc->zc_name, buf, pos + 1); strlcpy(zc->zc_value, buf + pos + 1, MAXPATHLEN); } else - error = EOPNOTSUPP; + error = EINVAL; /* old kernel cannot create multiple snapshots */ if (!error && nvlist_next_nvpair(nvl, pair) != NULL) error = EOPNOTSUPP; @@ -88,9 +89,62 @@ lzc_compat_pre(zfs_cmd_t *zc, zfs_ioc_t *ioc, nvlist_t **source) buf = nvpair_name(pair); pos = strcspn(buf, "@"); strlcpy(zc->zc_name, buf, pos + 1); - } + } else + error = EINVAL; + /* old kernel cannot atomically destroy multiple snaps */ + if (!error && nvlist_next_nvpair(nvl, pair) != NULL) + error = EOPNOTSUPP; *source = nvl; break; + case ZFS_IOC_HOLD: + nvl = fnvlist_lookup_nvlist(*source, "holds"); + pair = nvlist_next_nvpair(nvl, NULL); + if (pair != NULL) { + buf = nvpair_name(pair); + pos = strcspn(buf, "@"); + strlcpy(zc->zc_name, buf, pos + 1); + strlcpy(zc->zc_value, buf + pos + 1, MAXPATHLEN); + if (nvpair_value_string(pair, &val) == 0) + strlcpy(zc->zc_string, val, MAXNAMELEN); + else + error = EINVAL; + } else + error = EINVAL; + /* old kernel cannot atomically create multiple holds */ + if (!error && nvlist_next_nvpair(nvl, pair) != NULL) + error = EOPNOTSUPP; + nvlist_free(nvl); + if (nvlist_lookup_int32(*source, "cleanup_fd", + &cleanup_fd) == 0) + zc->zc_cleanup_fd = cleanup_fd; + else + zc->zc_cleanup_fd = -1; + break; + case ZFS_IOC_RELEASE: + pair = nvlist_next_nvpair(*source, NULL); + if (pair != NULL) { + buf = nvpair_name(pair); + pos = strcspn(buf, "@"); + strlcpy(zc->zc_name, buf, pos + 1); + strlcpy(zc->zc_value, buf + pos + 1, MAXPATHLEN); + if (nvpair_value_nvlist(pair, &nvl) == 0) { + hpair = nvlist_next_nvpair(nvl, NULL); + if (hpair != NULL) + strlcpy(zc->zc_string, + nvpair_name(hpair), MAXNAMELEN); + else + error = EINVAL; + if (!error && nvlist_next_nvpair(nvl, + hpair) != NULL) + error = EOPNOTSUPP; + } else + error = EINVAL; + } else + error = EINVAL; + /* old kernel cannot atomically release multiple holds */ + if (!error && nvlist_next_nvpair(nvl, pair) != NULL) + error = EOPNOTSUPP; + break; } return (error); |