Skip to content

Commit

Permalink
Add flag
Browse files Browse the repository at this point in the history
Signed-off-by: Umer Saleem <[email protected]>
  • Loading branch information
usaleem-ix committed Sep 9, 2023
1 parent 3753ce4 commit 6afacf5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
52 changes: 35 additions & 17 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4197,9 +4197,9 @@ zfs_do_rollback(int argc, char **argv)
static int
set_callback(zfs_handle_t *zhp, void *data)
{
nvlist_t *props = data;
zprop_set_cbdata_t *cb = data;
int ret = 0;
ret = zfs_prop_set_list(zhp, props);
ret = zfs_prop_set_list(zhp, cb->cb_proplist, cb->cb_flags);

if (ret != 0 || libzfs_errno(g_zfs) != EZFS_SUCCESS) {
switch (libzfs_errno(g_zfs)) {
Expand All @@ -4219,24 +4219,34 @@ set_callback(zfs_handle_t *zhp, void *data)
static int
zfs_do_set(int argc, char **argv)
{
nvlist_t *props = NULL;
zprop_set_cbdata_t cb = { 0 };
int ds_start = -1; /* argv idx of first dataset arg */
int ret = 0;
int i;
int i, c;

/* check for options */
if (argc > 1 && argv[1][0] == '-') {
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
argv[1][1]);
usage(B_FALSE);
/* check options */
while ((c = getopt(argc, argv, "u")) != -1) {
switch (c) {
case 'u':
cb.cb_flags |= ZFS_SET_NOMOUNT;
break;
case '?':
default:
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
usage(B_FALSE);
}
}

argc -= optind;
argv += optind;

/* check number of arguments */
if (argc < 2) {
if (argc < 1) {
(void) fprintf(stderr, gettext("missing arguments\n"));
usage(B_FALSE);
}
if (argc < 3) {
if (argc < 2) {
if (strchr(argv[1], '=') == NULL) {
(void) fprintf(stderr, gettext("missing property=value "
"argument(s)\n"));
Expand All @@ -4248,7 +4258,7 @@ zfs_do_set(int argc, char **argv)
}

/* validate argument order: prop=val args followed by dataset args */
for (i = 1; i < argc; i++) {
for (i = 0; i < argc; i++) {
if (strchr(argv[i], '=') != NULL) {
if (ds_start > 0) {
/* out-of-order prop=val argument */
Expand All @@ -4266,20 +4276,28 @@ zfs_do_set(int argc, char **argv)
}

/* Populate a list of property settings */
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
if (nvlist_alloc(&cb.cb_proplist, NV_UNIQUE_NAME, 0) != 0)
nomem();
for (i = 1; i < ds_start; i++) {
if (!parseprop(props, argv[i])) {
for (i = 0; i < ds_start; i++) {
if (!parseprop(cb.cb_proplist, argv[i])) {
ret = -1;
goto error;
}
}

if ((cb.cb_flags & ZFS_SET_NOMOUNT) &&
!nvlist_exists(cb.cb_proplist, "mountpoint")) {
(void) fprintf(stderr, gettext("-u specified but mountpoint "

Check failure on line 4290 in cmd/zfs/zfs_main.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
"property not found in property list\n"));
ret = -1;
goto error;
}

ret = zfs_for_each(argc - ds_start, argv + ds_start, 0,
ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, props);
ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, &cb);

error:
nvlist_free(props);
nvlist_free(cb.cb_proplist);
return (ret);
}

Expand Down
9 changes: 8 additions & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ _LIBZFS_H nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,

_LIBZFS_H const char *zfs_prop_to_name(zfs_prop_t);
_LIBZFS_H int zfs_prop_set(zfs_handle_t *, const char *, const char *);
_LIBZFS_H int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
_LIBZFS_H int zfs_prop_set_list(zfs_handle_t *, nvlist_t *, int);
_LIBZFS_H int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
zprop_source_t *, char *, size_t, boolean_t);
_LIBZFS_H int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
Expand Down Expand Up @@ -645,6 +645,13 @@ typedef struct zprop_get_cbdata {
vdev_cbdata_t cb_vdevs;
} zprop_get_cbdata_t;

#define ZFS_SET_NOMOUNT 1

Check failure on line 648 in include/libzfs.h

View workflow job for this annotation

GitHub Actions / checkstyle

#define followed by space instead of tab

typedef struct zprop_set_cbdata {
int cb_flags;
nvlist_t *cb_proplist;
} zprop_set_cbdata_t;

_LIBZFS_H void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
const char *, const char *, zprop_source_t, const char *,
const char *);
Expand Down
8 changes: 5 additions & 3 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
goto error;
}

ret = zfs_prop_set_list(zhp, nvl);
ret = zfs_prop_set_list(zhp, nvl, 0);

error:
nvlist_free(nvl);
Expand All @@ -1778,7 +1778,7 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
* given dataset.
*/
int
zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props, int flags)
{
zfs_cmd_t zc = {"\0"};
int ret = -1;
Expand Down Expand Up @@ -1848,7 +1848,9 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
if (prop != ZFS_PROP_CANMOUNT ||
(fnvpair_value_uint64(elem) == ZFS_CANMOUNT_OFF &&
zfs_is_mounted(zhp, NULL))) {
cls[cl_idx] = changelist_gather(zhp, prop, 0, 0);
cls[cl_idx] = changelist_gather(zhp, prop,
((flags & ZFS_SET_NOMOUNT) ? CL_GATHER_DONT_UNMOUNT :

Check failure on line 1852 in lib/libzfs/libzfs_dataset.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
0), 0);
if (cls[cl_idx] == NULL)
goto error;
}
Expand Down

0 comments on commit 6afacf5

Please sign in to comment.