btrfs-progs: subvol sync: check if the filesystem is writable

The subvolume cleaning is done by polling but it's possible that the
filesystem turns to read-only (as reported), either due to an error
intentionally. In that case the waiting would be indefinite without an
obvious reason.

To fix that check if the filesystem is still writable in each iteration.

Issue: #535
Link: https://github.com/btrfs/fstests/issues/40
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-12-07 17:21:56 +01:00
parent 7e4a235df1
commit 71ad6f2f53
2 changed files with 15 additions and 0 deletions

View file

@ -272,6 +272,8 @@ sync <path> [subvolid...]
deletion. If no subvolume id is given, wait until all current deletion requests
are completed, but do not wait for subvolumes deleted in the meantime.
If the filesystem status changes to read-only then the waiting is interrupted.
``Options``
-s <N>

View file

@ -17,6 +17,7 @@
#include "kerncompat.h"
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@ -78,10 +79,13 @@ static int wait_for_subvolume_cleaning(int fd, size_t count, uint64_t *ids,
size_t i;
enum btrfs_util_error err;
size_t done = 0;
bool statvfs_warned = false;
pr_verbose(LOG_DEFAULT, "Waiting for %zu subvolume%s\n", count,
(count > 1 ? "s" : ""));
while (1) {
struct statvfs st;
int ret;
bool clean = true;
for (i = 0; i < count; i++) {
@ -102,6 +106,15 @@ static int wait_for_subvolume_cleaning(int fd, size_t count, uint64_t *ids,
}
if (clean)
break;
ret = fstatvfs(fd, &st);
if (ret < 0 && !statvfs_warned) {
statvfs_warned = true;
warning("cannot check read-only status of the filesystem: %m");
} else if (st.f_flag & ST_RDONLY) {
warning("filesystem is now read-only");
return 1;
}
sleep(sleep_interval);
}