mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-28 03:49:38 +03:00
Allow bookmark short name in 'zfs bookmark'
This lets users create a bookmark from the command line by its name only, without the need to specify the dataset path which is extacted from the snapshot parameter. These commands are now equivalent: zfs bookmark poolname/fs@snap poolname/fs#bookmark zfs bookmark @snap poolname/fs#bookmark zfs bookmark poolname/fs@snap \#bookmark Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: loli10K <ezomori.nozomu@gmail.com> Closes #3665 Closes #6027
This commit is contained in:
parent
3e67c38c34
commit
587e228a6f
@ -6864,6 +6864,7 @@ static int
|
|||||||
zfs_do_bookmark(int argc, char **argv)
|
zfs_do_bookmark(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char snapname[ZFS_MAX_DATASET_NAME_LEN];
|
char snapname[ZFS_MAX_DATASET_NAME_LEN];
|
||||||
|
char bookname[ZFS_MAX_DATASET_NAME_LEN];
|
||||||
zfs_handle_t *zhp;
|
zfs_handle_t *zhp;
|
||||||
nvlist_t *nvl;
|
nvlist_t *nvl;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -6894,7 +6895,7 @@ zfs_do_bookmark(int argc, char **argv)
|
|||||||
|
|
||||||
if (strchr(argv[1], '#') == NULL) {
|
if (strchr(argv[1], '#') == NULL) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
gettext("invalid bookmark name '%s' -- "
|
gettext("invalid bookmark name '%s': "
|
||||||
"must contain a '#'\n"), argv[1]);
|
"must contain a '#'\n"), argv[1]);
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
@ -6910,6 +6911,18 @@ zfs_do_bookmark(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
(void) strlcpy(snapname, argv[0], sizeof (snapname));
|
(void) strlcpy(snapname, argv[0], sizeof (snapname));
|
||||||
}
|
}
|
||||||
|
if (argv[1][0] == '#') {
|
||||||
|
/*
|
||||||
|
* Bookmark name begins with #.
|
||||||
|
* Default to same fs as snapshot.
|
||||||
|
*/
|
||||||
|
(void) strlcpy(bookname, argv[0], sizeof (bookname));
|
||||||
|
*strchr(bookname, '@') = '\0';
|
||||||
|
(void) strlcat(bookname, argv[1], sizeof (bookname));
|
||||||
|
} else {
|
||||||
|
(void) strlcpy(bookname, argv[1], sizeof (bookname));
|
||||||
|
}
|
||||||
|
|
||||||
zhp = zfs_open(g_zfs, snapname, ZFS_TYPE_SNAPSHOT);
|
zhp = zfs_open(g_zfs, snapname, ZFS_TYPE_SNAPSHOT);
|
||||||
if (zhp == NULL)
|
if (zhp == NULL)
|
||||||
goto usage;
|
goto usage;
|
||||||
@ -6917,7 +6930,7 @@ zfs_do_bookmark(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
nvl = fnvlist_alloc();
|
nvl = fnvlist_alloc();
|
||||||
fnvlist_add_string(nvl, argv[1], snapname);
|
fnvlist_add_string(nvl, bookname, snapname);
|
||||||
ret = lzc_bookmark(nvl, NULL);
|
ret = lzc_bookmark(nvl, NULL);
|
||||||
fnvlist_free(nvl);
|
fnvlist_free(nvl);
|
||||||
|
|
||||||
@ -6927,7 +6940,7 @@ zfs_do_bookmark(int argc, char **argv)
|
|||||||
|
|
||||||
(void) snprintf(errbuf, sizeof (errbuf),
|
(void) snprintf(errbuf, sizeof (errbuf),
|
||||||
dgettext(TEXT_DOMAIN,
|
dgettext(TEXT_DOMAIN,
|
||||||
"cannot create bookmark '%s'"), argv[1]);
|
"cannot create bookmark '%s'"), bookname);
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case EXDEV:
|
case EXDEV:
|
||||||
@ -6945,6 +6958,9 @@ zfs_do_bookmark(int argc, char **argv)
|
|||||||
case ENOSPC:
|
case ENOSPC:
|
||||||
err_msg = "out of space";
|
err_msg = "out of space";
|
||||||
break;
|
break;
|
||||||
|
case ENOENT:
|
||||||
|
err_msg = "dataset does not exist";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
err_msg = "unknown error";
|
err_msg = "unknown error";
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user