Skip to content

Commit

Permalink
bookmark cloning: integrate into dsl_bookmark_create
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Jan 14, 2020
1 parent 5047a0b commit 81582ef
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 373 deletions.
8 changes: 1 addition & 7 deletions cmd/zfs/zfs_main.c
Expand Up @@ -7592,13 +7592,7 @@ zfs_do_bookmark(int argc, char **argv)

nvl = fnvlist_alloc();
fnvlist_add_string(nvl, bookname, source);
if (strchr(source, '@') != NULL) {
ret = lzc_bookmark(nvl, NULL);
} else if (strchr(source, '#') != NULL) {
ret = lzc_bookmark_clone(nvl, NULL);
} else {
abort();
}
ret = lzc_bookmark(nvl, NULL);
fnvlist_free(nvl);

if (ret != 0) {
Expand Down
1 change: 0 additions & 1 deletion include/libzfs_core.h
Expand Up @@ -56,7 +56,6 @@ int lzc_clone(const char *, const char *, nvlist_t *);
int lzc_promote(const char *, char *, int);
int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **);
int lzc_bookmark(nvlist_t *, nvlist_t **);
int lzc_bookmark_clone(nvlist_t *, nvlist_t **);
int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **);
int lzc_get_bookmark_props(const char *, nvlist_t **);
int lzc_destroy_bookmarks(nvlist_t *, nvlist_t **);
Expand Down
10 changes: 1 addition & 9 deletions include/sys/dsl_bookmark.h
Expand Up @@ -117,22 +117,14 @@ typedef struct dsl_bookmark_create_redacted_arg {
void *dbcra_tag;
} dsl_bookmark_create_redacted_arg_t;

typedef struct dsl_bookmark_clone_arg {
nvlist_t *dbcc_bmarks;
nvlist_t *dbcc_errors;
} dsl_bookmark_clone_arg_t;

int dsl_bookmark_create(nvlist_t *, nvlist_t *);
int dsl_bookmark_create_nvl_validate(nvlist_t *);
int dsl_bookmark_create_check(void *arg, dmu_tx_t *tx);
void dsl_bookmark_create_sync(void *arg, dmu_tx_t *tx);

int dsl_bookmark_create_redacted(const char *, const char *, uint64_t,
uint64_t *, void *, redaction_list_t **);

int dsl_bookmark_clone(nvlist_t *, nvlist_t *);
int dsl_bookmark_clone_check(void *arg, dmu_tx_t *tx);
void dsl_bookmark_clone_sync(void *arg, dmu_tx_t *tx);

int dsl_get_bookmarks(const char *, nvlist_t *, nvlist_t *);
int dsl_get_bookmarks_impl(dsl_dataset_t *, nvlist_t *, nvlist_t *);
int dsl_get_bookmark_props(const char *, const char *, nvlist_t *);
Expand Down
1 change: 0 additions & 1 deletion include/sys/fs/zfs.h
Expand Up @@ -1278,7 +1278,6 @@ typedef enum zfs_ioc {
ZFS_IOC_REDACT, /* 0x5a51 */
ZFS_IOC_GET_BOOKMARK_PROPS, /* 0x5a52 */
ZFS_IOC_WAIT, /* 0x5a53 */
ZFS_IOC_BOOKMARK_CLONE, /* 0x5a54 */

/*
* Linux - 3/64 numbers reserved.
Expand Down
1 change: 1 addition & 0 deletions include/zfs_namecheck.h
Expand Up @@ -57,6 +57,7 @@ int get_dataset_depth(const char *);
int pool_namecheck(const char *, namecheck_err_t *, char *);
int entity_namecheck(const char *, namecheck_err_t *, char *);
int dataset_namecheck(const char *, namecheck_err_t *, char *);
int snapshot_namecheck(const char *, namecheck_err_t *, char *);
int bookmark_namecheck(const char *, namecheck_err_t *, char *);
int dataset_nestcheck(const char *);
int mountpoint_namecheck(const char *, namecheck_err_t *);
Expand Down
45 changes: 7 additions & 38 deletions lib/libzfs_core/libzfs_core.c
Expand Up @@ -1125,11 +1125,13 @@ lzc_rollback_to(const char *fsname, const char *snapname)
}

/*
* Creates bookmarks.
* Creates new bookmarks from existing snapshot or bookmark.
*
* The bookmarks nvlist maps from name of the bookmark (e.g. "pool/fs#bmark") to
* the name of the snapshot (e.g. "pool/fs@snap"). All the bookmarks and
* snapshots must be in the same pool.
* The bookmarks nvlist maps from the full name of the new bookmark to
* the full name of the source snapshot or bookmark.
* All the bookmarks and snapshots must be in the same pool.
* The new bookmarks names must be unique.
* => see function dsl_bookmark_create_nvl_validate
*
* The returned results nvlist will have an entry for each bookmark that failed.
* The value will be the (int32) error code.
Expand All @@ -1144,7 +1146,7 @@ lzc_bookmark(nvlist_t *bookmarks, nvlist_t **errlist)
int error;
char pool[ZFS_MAX_DATASET_NAME_LEN];

/* determine the pool name */
/* determine pool name from first bookmark */
elem = nvlist_next_nvpair(bookmarks, NULL);
if (elem == NULL)
return (0);
Expand All @@ -1156,39 +1158,6 @@ lzc_bookmark(nvlist_t *bookmarks, nvlist_t **errlist)
return (error);
}


/*
* Clones existing bookmarks.
*
* The bookmarks nvlist maps from the full name of the new bookmark to
* the full name of the source bookmark. All of the bookmarks
* must be in the same pool. The new bookmark names must be unique.
*
* The returned results nvlist will have an entry for each bookmark that failed.
* The value will be the (int32) error code.
*
* The return value will be 0 if all bookmarks were created, otherwise it will
* be the errno of an (undetermined) bookmark that failed.
*/
int
lzc_bookmark_clone(nvlist_t *bookmarks, nvlist_t **errlist)
{
nvpair_t *elem;
int error;
char pool[ZFS_MAX_DATASET_NAME_LEN];

/* determine the pool name */
elem = nvlist_next_nvpair(bookmarks, NULL);
if (elem == NULL)
return (0);
(void) strlcpy(pool, nvpair_name(elem), sizeof (pool));
pool[strcspn(pool, "/#")] = '\0';

error = lzc_ioctl(ZFS_IOC_BOOKMARK_CLONE, pool, bookmarks, errlist);

return (error);
}

/*
* Retrieve bookmarks.
*
Expand Down
20 changes: 20 additions & 0 deletions module/zcommon/zfs_namecheck.c
Expand Up @@ -331,6 +331,25 @@ bookmark_namecheck(const char *path, namecheck_err_t *why, char *what)
return (ret);
}

/*
* Assert path is a valid snapshot name
*/
int
snapshot_namecheck(const char *path, namecheck_err_t *why, char *what)
{
int ret = entity_namecheck(path, why, what);

if (ret == 0 && strchr(path, '@') == NULL) {
if (why != NULL) {
*why = NAME_ERR_NO_AT;
*what = '@';
}
return (-1);
}

return (ret);
}

/*
* mountpoint names must be of the following form:
*
Expand Down Expand Up @@ -442,6 +461,7 @@ EXPORT_SYMBOL(entity_namecheck);
EXPORT_SYMBOL(pool_namecheck);
EXPORT_SYMBOL(dataset_namecheck);
EXPORT_SYMBOL(bookmark_namecheck);
EXPORT_SYMBOL(snapshot_namecheck);
EXPORT_SYMBOL(zfs_component_namecheck);
EXPORT_SYMBOL(dataset_nestcheck);
EXPORT_SYMBOL(get_dataset_depth);
Expand Down

0 comments on commit 81582ef

Please sign in to comment.