Changeset View
Changeset View
Standalone View
Standalone View
cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | case HELP_CREATE: | ||||
return (gettext("\tcreate [-pu] [-o property=value] ... " | return (gettext("\tcreate [-pu] [-o property=value] ... " | ||||
"<filesystem>\n" | "<filesystem>\n" | ||||
"\tcreate [-ps] [-b blocksize] [-o property=value] ... " | "\tcreate [-ps] [-b blocksize] [-o property=value] ... " | ||||
"-V <size> <volume>\n")); | "-V <size> <volume>\n")); | ||||
case HELP_DESTROY: | case HELP_DESTROY: | ||||
return (gettext("\tdestroy [-fnpRrv] <filesystem|volume>\n" | return (gettext("\tdestroy [-fnpRrv] <filesystem|volume>\n" | ||||
"\tdestroy [-dnpRrv] " | "\tdestroy [-dnpRrv] " | ||||
"<filesystem|volume>@<snap>[%<snap>][,...]\n" | "<filesystem|volume>@<snap>[%<snap>][,...]\n" | ||||
"\tdestroy <filesystem|volume>#<bookmark>\n")); | "\tdestroy [-nvp] <filesystem|volume>#<bookmark>[,...]\n")); | ||||
case HELP_GET: | case HELP_GET: | ||||
return (gettext("\tget [-rHp] [-d max] " | return (gettext("\tget [-rHp] [-d max] " | ||||
"[-o \"all\" | field[,...]]\n" | "[-o \"all\" | field[,...]]\n" | ||||
"\t [-t type[,...]] [-s source[,...]]\n" | "\t [-t type[,...]] [-s source[,...]]\n" | ||||
"\t <\"all\" | property[,...]> " | "\t <\"all\" | property[,...]> " | ||||
"[filesystem|volume|snapshot|bookmark] ...\n")); | "[filesystem|volume|snapshot|bookmark] ...\n")); | ||||
case HELP_INHERIT: | case HELP_INHERIT: | ||||
return (gettext("\tinherit [-rS] <property> " | return (gettext("\tinherit [-rS] <property> " | ||||
▲ Show 20 Lines • Show All 973 Lines • ▼ Show 20 Lines | gather_snapshots(zfs_handle_t *zhp, void *arg) | ||||
if (cb->cb_recurse) | if (cb->cb_recurse) | ||||
err = zfs_iter_filesystems(zhp, gather_snapshots, cb); | err = zfs_iter_filesystems(zhp, gather_snapshots, cb); | ||||
out: | out: | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
return (err); | return (err); | ||||
} | } | ||||
/* | |||||
* Given an input = "path/to/dataset#b1,b2,...,bN" | |||||
mahrens: Use `/*` for multi-line comment. | |||||
* fill nvl with (string,boolean) pairs where string = path/to/dataset#bi | |||||
*/ | |||||
static int | static int | ||||
bookmark_spec_to_nvl(const char *input, nvlist_t *nvl) | |||||
Done Inline Actionspount is not used mahrens: `pount` is not used | |||||
{ | |||||
char *input_cpy, *ds, *next, *bm; | |||||
input_cpy = next = strdup(input); | |||||
Done Inline ActionsI don't see where this is freed in the normal (non-error) case mahrens: I don't see where this is freed in the normal (non-error) case | |||||
if (!input_cpy) { | |||||
perror("cannot parse bookmark list"); | |||||
return (1); | |||||
} | |||||
ds = strsep(&next, "#"); | |||||
Done Inline Actionspersonally I prefer to avoid side-effects in if statement where reasonably possible. i.e.: ds = strsep(...); if (ds == NULL) { mahrens: personally I prefer to avoid side-effects in `if` statement where reasonably possible. i.e. | |||||
if (ds == NULL) { | |||||
(void) fprintf(stderr, "invalid bookmark list: " | |||||
"expected '#' delimiting dataset and bookmark\n"); | |||||
goto eout; | |||||
} | |||||
while ((bm = strsep(&next, ",")) != NULL) { | |||||
Done Inline Actionsyou can declare n and scratch inside the loop mahrens: you can declare `n` and `scratch` inside the loop | |||||
int n; | |||||
char scratch[ZFS_MAX_DATASET_NAME_LEN]; | |||||
n = snprintf(scratch, sizeof(scratch), "%s#%s", ds, bm); | |||||
if (n >= sizeof(scratch)) { | |||||
(void) fprintf(stderr, "invalid bookmark list: " | |||||
"full bookmark name for '#%s' is too long\n", bm); | |||||
goto eout; | |||||
} | |||||
fnvlist_add_boolean(nvl, scratch); | |||||
} | |||||
free(input_cpy); | |||||
return (0); | |||||
eout: | |||||
free(input_cpy); | |||||
return (1); | |||||
} | |||||
static int | |||||
destroy_clones(destroy_cbdata_t *cb) | destroy_clones(destroy_cbdata_t *cb) | ||||
{ | { | ||||
nvpair_t *pair; | nvpair_t *pair; | ||||
for (pair = nvlist_next_nvpair(cb->cb_nvl, NULL); | for (pair = nvlist_next_nvpair(cb->cb_nvl, NULL); | ||||
pair != NULL; | pair != NULL; | ||||
pair = nvlist_next_nvpair(cb->cb_nvl, pair)) { | pair = nvlist_next_nvpair(cb->cb_nvl, pair)) { | ||||
zfs_handle_t *zhp = zfs_open(g_zfs, nvpair_name(pair), | zfs_handle_t *zhp = zfs_open(g_zfs, nvpair_name(pair), | ||||
ZFS_TYPE_SNAPSHOT); | ZFS_TYPE_SNAPSHOT); | ||||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | if (!cb.cb_dryrun) { | ||||
} | } | ||||
} | } | ||||
if (err != 0) | if (err != 0) | ||||
rv = 1; | rv = 1; | ||||
} else if (pound != NULL) { | } else if (pound != NULL) { | ||||
int err; | int err; | ||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
nvpair_t *cur; | |||||
if (cb.cb_dryrun) { | |||||
(void) fprintf(stderr, | |||||
"dryrun is not supported with bookmark\n"); | |||||
return (-1); | |||||
} | |||||
if (cb.cb_defer_destroy) { | if (cb.cb_defer_destroy) { | ||||
(void) fprintf(stderr, | (void) fprintf(stderr, | ||||
"defer destroy is not supported with bookmark\n"); | "defer destroy is not supported with bookmark\n"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (cb.cb_recurse) { | if (cb.cb_recurse) { | ||||
(void) fprintf(stderr, | (void) fprintf(stderr, | ||||
"recursive is not supported with bookmark\n"); | "recursive is not supported with bookmark\n"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (!zfs_bookmark_exists(argv[0])) { | nvl = fnvlist_alloc(); | ||||
(void) fprintf(stderr, gettext("bookmark '%s' " | err = bookmark_spec_to_nvl(argv[0], nvl); | ||||
"does not exist.\n"), argv[0]); | if (err != 0) { | ||||
return (err); | |||||
} | |||||
cur = NULL; | |||||
while ((cur = nvlist_next_nvpair(nvl, cur)) != NULL) { | |||||
const char *name; | |||||
name = nvpair_name(cur); | |||||
Done Inline Actionsname can be declared inside the loop here mahrens: `name` can be declared inside the loop here | |||||
if (zfs_bookmark_exists(name)) | |||||
continue; | |||||
(void) fprintf(stderr, | |||||
"cannot destroy bookmarks: '%s' does not exist\n", | |||||
name); | |||||
return (1); | return (1); | ||||
} | } | ||||
nvl = fnvlist_alloc(); | if (cb.cb_verbose) { | ||||
fnvlist_add_boolean(nvl, argv[0]); | const char *verb = NULL; | ||||
if (cb.cb_parsable) | |||||
verb = "destroy\t"; | |||||
else if (cb.cb_dryrun) | |||||
verb = gettext("would destroy "); | |||||
else | |||||
verb = gettext("will destroy "); | |||||
cur = NULL; | |||||
while ((cur = nvlist_next_nvpair(nvl, cur)) != NULL) { | |||||
(void) fprintf(stderr, "%s%s\n", | |||||
verb, nvpair_name(cur)); | |||||
} | |||||
} | |||||
if (cb.cb_dryrun) { | |||||
return (0); | |||||
} | |||||
err = lzc_destroy_bookmarks(nvl, NULL); | err = lzc_destroy_bookmarks(nvl, NULL); | ||||
if (err != 0) { | if (err != 0) { | ||||
(void) zfs_standard_error(g_zfs, err, | (void) zfs_standard_error(g_zfs, err, | ||||
"cannot destroy bookmark"); | "cannot destroy bookmarks"); | ||||
} | } | ||||
nvlist_free(cb.cb_nvl); | |||||
Done Inline Actionswe never allocate cb.cb_nvl. also, the local nvl in this scope is not required to be freed because we'll exit right after we return form the function... me_cschwarz.com: we never allocate cb.cb_nvl.
also, the local `nvl` in this scope is not required to be freed… | |||||
return (err); | return (err); | ||||
} else { | } else { | ||||
/* Open the given dataset */ | /* Open the given dataset */ | ||||
if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL) | if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL) | ||||
return (1); | return (1); | ||||
cb.cb_target = zhp; | cb.cb_target = zhp; | ||||
▲ Show 20 Lines • Show All 6,023 Lines • Show Last 20 Lines |
Use /* for multi-line comment.