Changeset View
Changeset View
Standalone View
Standalone View
cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
| Show First 20 Lines • Show All 1,229 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 = "dataset#b1,b2,...,bN" | |||||
| // fill nvl with (string,boolean) pairs where string = dataset#bi | |||||
mahrens: Use `/*` for multi-line comment. | |||||
| static int | static int | ||||
| bookmark_spec_to_nvl(const char *input, nvlist_t *nvl) | |||||
| { | |||||
| char *input_cpy, *ds, *next, *bm, *pount; | |||||
mahrensUnsubmitted Done Inline Actionspount is not used mahrens: `pount` is not used | |||||
| int n; | |||||
| char scratch[ZFS_MAX_DATASET_NAME_LEN]; | |||||
| input_cpy = next = strdup(input); | |||||
mahrensUnsubmitted 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); | |||||
| } | |||||
| if ((ds = strsep(&next, "#")) == NULL) { | |||||
mahrensUnsubmitted 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. | |||||
| (void) fprintf(stderr, "invalid bookmark list: " | |||||
| "expected '#' delimiting dataset and bookmark\n"); | |||||
| goto eout; | |||||
| } | |||||
| while ((bm = strsep(&next, ",")) != NULL) { | |||||
| n = snprintf(scratch, sizeof(scratch), "%s#%s", ds, bm); | |||||
mahrensUnsubmitted Done Inline Actionsyou can declare n and scratch inside the loop mahrens: you can declare `n` and `scratch` inside the loop | |||||
| 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); | |||||
| } | |||||
| 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; | ||||
| 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); | |||||
| } | |||||
| nvpair_t *cur = NULL; | |||||
| const char *name; | |||||
| while ((cur = nvlist_next_nvpair(nvl, cur)) != NULL) { | |||||
| name = nvpair_name(cur); | |||||
mahrensUnsubmitted 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]); | cur = NULL; | ||||
| 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 "); | |||||
| 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); | |||||
me_cschwarz.comAuthorUnsubmitted 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.