-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Introduce zfs rewrite subcommand #17246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,6 +37,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <assert.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <ctype.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <sys/debug.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <dirent.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <errno.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <getopt.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <libgen.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -121,6 +122,7 @@ static int zfs_do_change_key(int argc, char **argv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int zfs_do_project(int argc, char **argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int zfs_do_version(int argc, char **argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int zfs_do_redact(int argc, char **argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int zfs_do_rewrite(int argc, char **argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int zfs_do_wait(int argc, char **argv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#ifdef __FreeBSD__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -193,6 +195,7 @@ typedef enum { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_CHANGE_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_REDACT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_REWRITE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_JAIL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_UNJAIL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HELP_WAIT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -227,7 +230,7 @@ static zfs_command_t command_table[] = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "promote", zfs_do_promote, HELP_PROMOTE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "rename", zfs_do_rename, HELP_RENAME }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "bookmark", zfs_do_bookmark, HELP_BOOKMARK }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "program", zfs_do_channel_program, HELP_CHANNEL_PROGRAM }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "diff", zfs_do_diff, HELP_DIFF }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "list", zfs_do_list, HELP_LIST }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -249,27 +252,31 @@ static zfs_command_t command_table[] = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "send", zfs_do_send, HELP_SEND }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "receive", zfs_do_receive, HELP_RECEIVE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "redact", zfs_do_redact, HELP_REDACT }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "allow", zfs_do_allow, HELP_ALLOW }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "unallow", zfs_do_unallow, HELP_UNALLOW }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "hold", zfs_do_hold, HELP_HOLD }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "holds", zfs_do_holds, HELP_HOLDS }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "release", zfs_do_release, HELP_RELEASE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "diff", zfs_do_diff, HELP_DIFF }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "load-key", zfs_do_load_key, HELP_LOAD_KEY }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "unload-key", zfs_do_unload_key, HELP_UNLOAD_KEY }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "change-key", zfs_do_change_key, HELP_CHANGE_KEY }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "redact", zfs_do_redact, HELP_REDACT }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "program", zfs_do_channel_program, HELP_CHANNEL_PROGRAM }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "rewrite", zfs_do_rewrite, HELP_REWRITE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "wait", zfs_do_wait, HELP_WAIT }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#ifdef __FreeBSD__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "jail", zfs_do_jail, HELP_JAIL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "unjail", zfs_do_unjail, HELP_UNJAIL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#ifdef __linux__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ NULL }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "zone", zfs_do_zone, HELP_ZONE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ "unzone", zfs_do_unzone, HELP_UNZONE }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -432,6 +439,9 @@ get_usage(zfs_help_t idx) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case HELP_REDACT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (gettext("\tredact <snapshot> <bookmark> " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"<redaction_snapshot> ...\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case HELP_REWRITE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (gettext("\trewrite [-rvx] [-o <offset>] [-l <length>] " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"<directory|file ...>\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case HELP_JAIL: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (gettext("\tjail <jailid|jailname> <filesystem>\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case HELP_UNJAIL: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -9016,6 +9026,192 @@ zfs_do_project(int argc, char **argv) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_rewrite_file(const char *path, boolean_t verbose, zfs_rewrite_args_t *args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int fd, ret = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fd = open(path, O_WRONLY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fd < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = errno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("failed to open %s: %s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, strerror(errno)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (ioctl(fd, ZFS_IOC_REWRITE, args) < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = errno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("failed to rewrite %s: %s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, strerror(errno)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
printf("%s\n", path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
close(fd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_rewrite_dir(const char *path, boolean_t verbose, boolean_t xdev, dev_t dev, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_rewrite_args_t *args, nvlist_t *dirs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct dirent *ent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DIR *dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int ret = 0, err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dir = opendir(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (dir == NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (errno == ENOENT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = errno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("failed to opendir %s: %s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, strerror(errno)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
size_t plen = strlen(path) + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
while ((ent = readdir(dir)) != NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
char *fullname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct stat st; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (ent->d_type != DT_REG && ent->d_type != DT_DIR) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (strcmp(ent->d_name, ".") == 0 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
strcmp(ent->d_name, "..") == 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (plen + strlen(ent->d_name) >= PATH_MAX) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("path too long %s/%s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, ent->d_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = ENAMETOOLONG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (asprintf(&fullname, "%s/%s", path, ent->d_name) == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gettext("failed to allocate memory\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = ENOMEM; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (xdev) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (stat(fullname, &st) < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = errno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gettext("failed to stat %s: %s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fullname, strerror(errno)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(fullname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (st.st_dev != dev) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(fullname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (ent->d_type == DT_REG) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = zfs_rewrite_file(fullname, verbose, args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about hard links, and tracking them to avoid not rewriting the object twice, but it's kind of a colossal pita to do a good job of, so probably not worth it. But I said it at least! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { /* DT_DIR */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fnvlist_add_uint64(dirs, fullname, dev); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
free(fullname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we break the loop for certain kinds of errors from rewrite, like |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
closedir(dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_rewrite_path(const char *path, boolean_t verbose, boolean_t recurse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean_t xdev, zfs_rewrite_args_t *args, nvlist_t *dirs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct stat st; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int ret = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (stat(path, &st) < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = errno; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("failed to stat %s: %s\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, strerror(errno)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (S_ISREG(st.st_mode)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = zfs_rewrite_file(path, verbose, args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (S_ISDIR(st.st_mode) && recurse) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = zfs_rewrite_dir(path, verbose, xdev, st.st_dev, args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+9135
to
+9147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I messed with this a bit, and came up with:
Suggested change
That is:
The symlink thing I think is important; at least, it surprised me that it worked at all (rewrote the target), and not being the same as directory mode bothered me. The other two are just niceties. I did think about also limiting to things not on ZFS, because it is strange to me that a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_do_rewrite(int argc, char **argv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int ret = 0, err, c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean_t recurse = B_FALSE, verbose = B_FALSE, xdev = B_FALSE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (argc < 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usage(B_FALSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_rewrite_args_t args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
memset(&args, 0, sizeof (args)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
while ((c = getopt(argc, argv, "l:o:rvx")) != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch (c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case 'l': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args.len = strtoll(optarg, NULL, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case 'o': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args.off = strtoll(optarg, NULL, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case 'r': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
recurse = B_TRUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case 'v': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
verbose = B_TRUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case 'x': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
xdev = B_TRUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, gettext("invalid option '%c'\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
optopt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usage(B_FALSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
argv += optind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
argc -= optind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (argc == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(void) fprintf(stderr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gettext("missing file or directory target(s)\n")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usage(B_FALSE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nvlist_t *dirs = fnvlist_alloc(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (int i = 0; i < argc; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = zfs_rewrite_path(argv[i], verbose, recurse, xdev, &args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nvpair_t *dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
while ((dir = nvlist_next_nvpair(dirs, NULL)) != NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = zfs_rewrite_dir(nvpair_name(dir), verbose, xdev, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fnvpair_value_uint64(dir), &args, dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ret = err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fnvlist_remove_nvpair(dirs, dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fnvlist_free(dirs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return (ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zfs_do_wait(int argc, char **argv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.\" SPDX-License-Identifier: CDDL-1.0 | ||
.\" | ||
.\" CDDL HEADER START | ||
.\" | ||
.\" The contents of this file are subject to the terms of the | ||
.\" Common Development and Distribution License (the "License"). | ||
.\" You may not use this file except in compliance with the License. | ||
.\" | ||
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
.\" or https://opensource.org/licenses/CDDL-1.0. | ||
.\" See the License for the specific language governing permissions | ||
.\" and limitations under the License. | ||
.\" | ||
.\" When distributing Covered Code, include this CDDL HEADER in each | ||
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
.\" If applicable, add the following below this CDDL HEADER, with the | ||
.\" fields enclosed by brackets "[]" replaced with your own identifying | ||
.\" information: Portions Copyright [yyyy] [name of copyright owner] | ||
.\" | ||
.\" CDDL HEADER END | ||
.\" | ||
.\" Copyright (c) 2025 iXsystems, Inc. | ||
.\" | ||
.Dd May 6, 2025 | ||
.Dt ZFS-REWRITE 8 | ||
.Os | ||
. | ||
.Sh NAME | ||
.Nm zfs-rewrite | ||
.Nd rewrite specified files without modification | ||
.Sh SYNOPSIS | ||
.Nm zfs | ||
.Cm rewrite | ||
.Oo Fl rvx Ns Oc | ||
.Op Fl l Ar length | ||
.Op Fl o Ar offset | ||
.Ar file Ns | Ns Ar directory Ns … | ||
. | ||
.Sh DESCRIPTION | ||
Rewrite blocks of specified | ||
.Ar file | ||
as is without modification at a new location and possibly with new | ||
properties, such as checksum, compression, dedup, copies, etc, | ||
as if they were atomically read and written back. | ||
.Bl -tag -width "-r" | ||
.It Fl l Ar length | ||
Rewrite at most this number of bytes. | ||
.It Fl o Ar offset | ||
Start at this offset in bytes. | ||
.It Fl r | ||
Recurse into directories. | ||
.It Fl v | ||
Print names of all successfully rewritten files. | ||
.It Fl x | ||
Don't cross file system mount points when recursing. | ||
.El | ||
.Sh NOTES | ||
Rewrite of cloned blocks and blocks that are part of any snapshots, | ||
same as some property changes may increase pool space usage. | ||
Holes that were never written or were previously zero-compressed are | ||
not rewritten and will remain holes even if compression is disabled. | ||
.Pp | ||
Rewritten blocks will be seen as modified in next snapshot and as such | ||
included into the incremental | ||
.Nm zfs Cm send | ||
stream. | ||
.Pp | ||
If a | ||
.Fl l | ||
or | ||
.Fl o | ||
value request a rewrite to regions past the end of the file, then those | ||
regions are silently ignored, and no error is reported. | ||
. | ||
.Sh SEE ALSO | ||
.Xr zfsprops 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd print this before the call to
ioctl()
, so the operator can see where it's up to, particularly if it takes a while, or if they ctrl-c it.