Skip to content

Commit a42e3fc

Browse files
SidongYangkdave
authored andcommitted
btrfs-progs: subvol sync: use SUBVOL_SYNC_WAIT ioctl for sync
Use SUBVOL_SYNC_WAIT ioctl for 'btrfs subvolume sync' command before checking periodically and add an option to not 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 Pull-request: #989 Signed-off-by: Sidong Yang <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f1894dc commit a42e3fc

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

cmds/subvolume.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ 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 ret;
127+
struct btrfs_ioctl_subvol_wait arg;
128+
129+
for (int 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+
if (ret < 0 && errno != ENOENT)
135+
return -errno;
136+
}
137+
return 0;
138+
}
139+
125140
static const char * const subvolume_cmd_group_usage[] = {
126141
"btrfs subvolume <command> <args>",
127142
NULL
@@ -1726,9 +1741,12 @@ static const char * const cmd_subvolume_sync_usage[] = {
17261741
"after deletion.",
17271742
"If no subvolume id is given, wait until all current deletion requests",
17281743
"are completed, but do not wait for subvolumes deleted meanwhile.",
1729-
"The status of subvolume ids is checked periodically.",
1744+
"The status of subvolume IDs is first checked by attempting to wait"
1745+
"via ioctl. If the ioctl is not supported or fails, the status is checked"
1746+
"periodically as a fallback.",
17301747
"",
17311748
OPTLINE("-s <N>", "sleep N seconds between checks (default: 1)"),
1749+
OPTLINE("-p", "use periodic checking instead of waiting via ioctl"),
17321750
NULL
17331751
};
17341752

@@ -1740,6 +1758,7 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17401758
size_t id_count, i;
17411759
int sleep_interval = 1;
17421760
enum btrfs_util_error err;
1761+
bool periodic = false;
17431762

17441763
optind = 0;
17451764
while (1) {
@@ -1757,6 +1776,9 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17571776
goto out;
17581777
}
17591778
break;
1779+
case 'p':
1780+
periodic = true;
1781+
break;
17601782
default:
17611783
usage_unknown_option(cmd, argv);
17621784
}
@@ -1814,7 +1836,16 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
18141836
}
18151837
}
18161838

1817-
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1839+
if (periodic) {
1840+
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1841+
} else {
1842+
ret = wait_for_subvolume_sync(fd, id_count, ids);
1843+
if (ret) {
1844+
if (ret == -ENOTTY)
1845+
error("subvolume sync ioctl not supported in this kernel version, 6.13 and newer is required");
1846+
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
1847+
}
1848+
}
18181849

18191850
out:
18201851
free(ids);

0 commit comments

Comments
 (0)