Skip to content

Commit 5f72fd7

Browse files
committed
btrfs-progs: subvolume: use BTRFS_IOC_SUBVOL_SYNC_WAIT for sync
This patch uses BTRFS_IOC_SUBVOL_SYNC_WAIT ioctl in subvolume sync command before checking periodically and adds an option to not to use sync wait ioctl call and force to check periodically. This patch calls a new function wait_for_subvolume_sync() that calls BTRFS_IOC_SUBVOL_SYNC_WAIT for each subvol. Issue: #953 Signed-off-by: Sidong Yang <[email protected]>
1 parent 2c8f5c7 commit 5f72fd7

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cmds/subvolume.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ static int wait_for_subvolume_cleaning(int fd, size_t count, uint64_t *ids,
122122
return 0;
123123
}
124124

125+
static int wait_for_subvolume_sync(int fd, size_t count, uint64_t *ids) {
126+
int i, ret;
127+
struct btrfs_ioctl_subvol_wait arg;
128+
129+
for (i=0; i<count; ++i) {
130+
arg.subvolid = ids[i];
131+
arg.mode = BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE;
132+
133+
ret = ioctl(fd, BTRFS_IOC_SUBVOL_SYNC_WAIT, &arg);
134+
135+
if (ret && errno != ENOENT)
136+
return -errno;
137+
}
138+
return 0;
139+
}
140+
125141
static const char * const subvolume_cmd_group_usage[] = {
126142
"btrfs subvolume <command> <args>",
127143
NULL
@@ -1729,6 +1745,7 @@ static const char * const cmd_subvolume_sync_usage[] = {
17291745
"The status of subvolume ids is checked periodically.",
17301746
"",
17311747
OPTLINE("-s <N>", "sleep N seconds between checks (default: 1)"),
1748+
OPTLINE("-f", "force to check periodically (default: false)"),
17321749
NULL
17331750
};
17341751

@@ -1740,6 +1757,7 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17401757
size_t id_count, i;
17411758
int sleep_interval = 1;
17421759
enum btrfs_util_error err;
1760+
bool force_to_check = false;
17431761

17441762
optind = 0;
17451763
while (1) {
@@ -1757,6 +1775,8 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17571775
goto out;
17581776
}
17591777
break;
1778+
case 'f':
1779+
force_to_check = true;
17601780
default:
17611781
usage_unknown_option(cmd, argv);
17621782
}
@@ -1814,7 +1834,13 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
18141834
}
18151835
}
18161836

1817-
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1837+
if (force_to_check) {
1838+
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1839+
} else {
1840+
ret = wait_for_subvolume_sync(fd, id_count, ids);
1841+
if (ret)
1842+
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1843+
}
18181844

18191845
out:
18201846
free(ids);

0 commit comments

Comments
 (0)