Skip to content

Commit 4ab0a2d

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 3da67f1 commit 4ab0a2d

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

cmds/subvolume.c

Lines changed: 34 additions & 2 deletions
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
@@ -1726,9 +1742,12 @@ static const char * const cmd_subvolume_sync_usage[] = {
17261742
"after deletion.",
17271743
"If no subvolume id is given, wait until all current deletion requests",
17281744
"are completed, but do not wait for subvolumes deleted meanwhile.",
1729-
"The status of subvolume ids is checked periodically.",
1745+
"The status of subvolume IDs is first checked by attempting to wait"
1746+
"via ioctl. If the ioctl is not supported or fails, the status is checked"
1747+
"periodically as a fallback.",
17301748
"",
17311749
OPTLINE("-s <N>", "sleep N seconds between checks (default: 1)"),
1750+
OPTLINE("-p", "use periodic checking instead of waiting via ioctl"),
17321751
NULL
17331752
};
17341753

@@ -1740,6 +1759,7 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17401759
size_t id_count, i;
17411760
int sleep_interval = 1;
17421761
enum btrfs_util_error err;
1762+
bool periodic = false;
17431763

17441764
optind = 0;
17451765
while (1) {
@@ -1757,6 +1777,9 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
17571777
goto out;
17581778
}
17591779
break;
1780+
case 'p':
1781+
periodic = true;
1782+
break;
17601783
default:
17611784
usage_unknown_option(cmd, argv);
17621785
}
@@ -1814,7 +1837,16 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
18141837
}
18151838
}
18161839

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

18191851
out:
18201852
free(ids);

0 commit comments

Comments
 (0)