Skip to content

Commit 21eaf38

Browse files
Steven Hartlandalek-p
Steven Hartland
authored andcommitted
NEX-1456 Part 2, port FreeBSD patch - new zfs recv options support
1 parent 8cf7d50 commit 21eaf38

File tree

8 files changed

+287
-60
lines changed

8 files changed

+287
-60
lines changed

usr/src/cmd/ndmpd/ndmp/ndmpd_zfs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
*/
3939
/* Copyright (c) 2007, The Storage Networking Industry Association. */
4040
/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
41+
/*
42+
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
43+
*/
4144

4245
#include <sys/types.h>
4346
#include <sys/param.h>
@@ -916,7 +919,7 @@ ndmpd_zfs_restore_recv_write(ndmpd_zfs_args_t *ndmpd_zfs_args)
916919
flags.force = B_TRUE;
917920

918921
err = zfs_receive(ndmpd_zfs_args->nz_zlibh, ndmpd_zfs_args->nz_dataset,
919-
&flags, ndmpd_zfs_args->nz_pipe_fd[PIPE_ZFS], NULL);
922+
&flags, ndmpd_zfs_args->nz_pipe_fd[PIPE_ZFS], NULL, NULL, NULL);
920923

921924
if (err && !session->ns_data.dd_abort)
922925
NDMPD_ZFS_LOG_ZERR(ndmpd_zfs_args, "zfs_receive: %d", err);

usr/src/cmd/zfs/zfs_main.c

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ get_usage(zfs_help_t idx)
246246
case HELP_PROMOTE:
247247
return (gettext("\tpromote <clone-filesystem>\n"));
248248
case HELP_RECEIVE:
249-
return (gettext("\treceive [-vnFu] <filesystem|volume|"
250-
"snapshot>\n"
251-
"\treceive [-vnFu] [-d | -e] <filesystem>\n"));
249+
return (gettext("\treceive [-vnFu] [-d | -e] "
250+
"[-o <property=value>]... [-x <property>]...\n"
251+
"\t [-l <filesystem|volume>]... <filesystem|volume"
252+
"|snapshot>\n"));
252253
case HELP_RENAME:
253254
return (gettext("\trename [-f] <filesystem|volume|snapshot> "
254255
"<filesystem|volume|snapshot>\n"
@@ -477,10 +478,22 @@ usage(boolean_t requested)
477478
exit(requested ? 0 : 2);
478479
}
479480

481+
/*
482+
* Add parameter to the list if it's not in there already
483+
*/
484+
static void
485+
add_unique_option(nvlist_t *props, char *propname)
486+
{
487+
if (nvlist_lookup_string(props, propname, NULL) != 0) {
488+
if (nvlist_add_boolean(props, propname) != 0) {
489+
nomem();
490+
}
491+
}
492+
}
493+
480494
static int
481-
parseprop(nvlist_t *props)
495+
parseprop(nvlist_t *props, char *propname)
482496
{
483-
char *propname = optarg;
484497
char *propval, *strval;
485498

486499
if ((propval = strchr(propname, '=')) == NULL) {
@@ -509,7 +522,7 @@ parse_depth(char *opt, int *flags)
509522
depth = (int)strtol(opt, &tmp, 0);
510523
if (*tmp) {
511524
(void) fprintf(stderr,
512-
gettext("%s is not an integer\n"), optarg);
525+
gettext("%s is not an integer\n"), opt);
513526
usage(B_FALSE);
514527
}
515528
if (depth < 0) {
@@ -600,7 +613,7 @@ zfs_do_clone(int argc, char **argv)
600613
while ((c = getopt(argc, argv, "o:p")) != -1) {
601614
switch (c) {
602615
case 'o':
603-
if (parseprop(props))
616+
if (parseprop(props, optarg))
604617
return (1);
605618
break;
606619
case 'p':
@@ -747,7 +760,7 @@ zfs_do_create(int argc, char **argv)
747760
nomem();
748761
break;
749762
case 'o':
750-
if (parseprop(props))
763+
if (parseprop(props, optarg))
751764
goto error;
752765
break;
753766
case 's':
@@ -3570,7 +3583,7 @@ zfs_do_snapshot(int argc, char **argv)
35703583
while ((c = getopt(argc, argv, "ro:")) != -1) {
35713584
switch (c) {
35723585
case 'o':
3573-
if (parseprop(props))
3586+
if (parseprop(props, optarg))
35743587
return (1);
35753588
break;
35763589
case 'r':
@@ -3829,10 +3842,15 @@ static int
38293842
zfs_do_receive(int argc, char **argv)
38303843
{
38313844
int c, err;
3845+
nvlist_t *exprops, *limitds;
38323846
recvflags_t flags = { 0 };
3847+
if (nvlist_alloc(&exprops, NV_UNIQUE_NAME, 0) != 0)
3848+
nomem();
3849+
if (nvlist_alloc(&limitds, NV_UNIQUE_NAME, 0) != 0)
3850+
nomem();
38333851

38343852
/* check options */
3835-
while ((c = getopt(argc, argv, ":denuvF")) != -1) {
3853+
while ((c = getopt(argc, argv, ":del:no:uvx:F")) != -1) {
38363854
switch (c) {
38373855
case 'd':
38383856
flags.isprefix = B_TRUE;
@@ -3841,15 +3859,27 @@ zfs_do_receive(int argc, char **argv)
38413859
flags.isprefix = B_TRUE;
38423860
flags.istail = B_TRUE;
38433861
break;
3862+
case 'l':
3863+
add_unique_option(limitds, optarg);
3864+
break;
38443865
case 'n':
38453866
flags.dryrun = B_TRUE;
38463867
break;
3868+
case 'o':
3869+
if (parseprop(exprops, optarg)) {
3870+
err = 1;
3871+
goto recverror;
3872+
}
3873+
break;
38473874
case 'u':
38483875
flags.nomount = B_TRUE;
38493876
break;
38503877
case 'v':
38513878
flags.verbose = B_TRUE;
38523879
break;
3880+
case 'x':
3881+
add_unique_option(exprops, optarg);
3882+
break;
38533883
case 'F':
38543884
flags.force = B_TRUE;
38553885
break;
@@ -3886,7 +3916,12 @@ zfs_do_receive(int argc, char **argv)
38863916
return (1);
38873917
}
38883918

3889-
err = zfs_receive(g_zfs, argv[0], &flags, STDIN_FILENO, NULL);
3919+
err = zfs_receive(g_zfs, argv[0], &flags, STDIN_FILENO, exprops,
3920+
limitds, NULL);
3921+
3922+
recverror:
3923+
nvlist_free(exprops);
3924+
nvlist_free(limitds);
38903925

38913926
return (err != 0);
38923927
}

usr/src/lib/libbe/common/be_create.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
/*
27-
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
27+
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
2828
*/
2929

3030
/*
@@ -2480,7 +2480,8 @@ be_send_fs_callback(zfs_handle_t *zhp, void *data)
24802480
(void) close(srpipe[1]);
24812481

24822482
/* Receive dataset */
2483-
if (zfs_receive(g_zfs, clone_ds, &flags, srpipe[0], NULL) != 0) {
2483+
if (zfs_receive(g_zfs, clone_ds, &flags, srpipe[0], NULL, NULL,
2484+
NULL) != 0) {
24842485
be_print_err(gettext("be_send_fs_callback: failed to "
24852486
"recv dataset (%s)\n"), clone_ds);
24862487
}

usr/src/lib/libzfs/common/libzfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ typedef struct recvflags {
676676
} recvflags_t;
677677

678678
extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t *,
679-
int, avl_tree_t *);
679+
int, nvlist_t *, nvlist_t *, avl_tree_t *);
680680

681681
typedef enum diff_flags {
682682
ZFS_DIFF_PARSEABLE = 0x1,

usr/src/lib/libzfs/common/libzfs_dataset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ parent_name(const char *path, char *buf, size_t buflen)
28162816
* 'zoned' property, which is used to validate property settings when creating
28172817
* new datasets.
28182818
*/
2819-
static int
2819+
int
28202820
check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
28212821
boolean_t accept_ancestor, int *prefixlen)
28222822
{

usr/src/lib/libzfs/common/libzfs_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ int changelist_haszonedchild(prop_changelist_t *);
186186

187187
void remove_mountpoint(zfs_handle_t *);
188188
int create_parents(libzfs_handle_t *, char *, int);
189+
int check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
190+
boolean_t accept_ancestor, int *prefixlen);
189191
boolean_t isa_child_of(const char *dataset, const char *parent);
190192

191193
zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);

0 commit comments

Comments
 (0)