Skip to content

btrfs-progs: subvolume: use BTRFS_IOC_SUBVOL_SYNC_WAIT for sync #989

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

Open
wants to merge 15 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/btrfs-filesystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defragment [options] <file>|<dir> [<file>|<dir>...]
compression. See also section *EXAMPLES*.

-L|--level <level>
Since kernel 6.14 the compresison can also take the level parameter which will be used
Since kernel 6.15 the compresison can also take the level parameter which will be used
only for the defragmentation and overrides the eventual mount option compression level.
Valid levels depend on the compression algorithms: *zlib*
1..9, *lzo* does not have any levels, *zstd* the standard levels 1..15 and also the
Expand Down
35 changes: 35 additions & 0 deletions Documentation/mkfs.btrfs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,41 @@ OPTIONS
:file:`hardlink1` and :file:`hardlink2` because :file:`hardlink3` will
be inside a new subvolume.

--inode-flags <flags>:<path>
Specify that *path* to have inode *flags*, other than the default one (which
implies data COW and data checksum). The option *--rootdir* must also be
specified. This option can be specified multiple times.

The supported flag(s) are:

* *nodatacow*: disable data COW, implies *nodatasum* for regular files.
* *nodatasum*: disable data checksum only.

*flags* can be separated by comma (*,*).

Children inodes will inherit the flags from their parent inodes, like the
following case:

.. code-block:: none

rootdir/
|- file1
|- file2
|- dir/
|- file3

In that case, if *--inode-flags nodatacow:dir* is specified, both
:file:`dir` and :file:`file3` will have the *nodatacow* flag.

And this option also works with *--subvol* option, but the inode flag of
each subvolume is independent and will not inherit from the parent directory.
(The same as the kernel behavior.)

.. note::
Both *--inode-flags* and *--subvol* options are memory hungry,
will consume at least 8KiB for each option. Please keep the
usage of both options to minimum.

--shrink
Shrink the filesystem to its minimal size, only works with *--rootdir* option.

Expand Down
36 changes: 34 additions & 2 deletions cmds/subvolume.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ static int wait_for_subvolume_cleaning(int fd, size_t count, uint64_t *ids,
return 0;
}

static int wait_for_subvolume_sync(int fd, size_t count, uint64_t *ids) {
int i, ret;
struct btrfs_ioctl_subvol_wait arg;

for (i=0; i<count; ++i) {
arg.subvolid = ids[i];
arg.mode = BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE;

ret = ioctl(fd, BTRFS_IOC_SUBVOL_SYNC_WAIT, &arg);

if (ret && errno != ENOENT)
return -errno;
}
return 0;
}

static const char * const subvolume_cmd_group_usage[] = {
"btrfs subvolume <command> <args>",
NULL
Expand Down Expand Up @@ -1726,9 +1742,12 @@ static const char * const cmd_subvolume_sync_usage[] = {
"after deletion.",
"If no subvolume id is given, wait until all current deletion requests",
"are completed, but do not wait for subvolumes deleted meanwhile.",
"The status of subvolume ids is checked periodically.",
"The status of subvolume IDs is first checked by attempting to wait"
"via ioctl. If the ioctl is not supported or fails, the status is checked"
"periodically as a fallback.",
"",
OPTLINE("-s <N>", "sleep N seconds between checks (default: 1)"),
OPTLINE("-p", "use periodic checking instead of waiting via ioctl"),
NULL
};

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

optind = 0;
while (1) {
Expand All @@ -1757,6 +1777,9 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
goto out;
}
break;
case 'p':
periodic = true;
break;
default:
usage_unknown_option(cmd, argv);
}
Expand Down Expand Up @@ -1814,7 +1837,16 @@ static int cmd_subvolume_sync(const struct cmd_struct *cmd, int argc, char **arg
}
}

ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
if (periodic) {
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
} else {
ret = wait_for_subvolume_sync(fd, id_count, ids);
if (ret) {
if (ret == -ENOTTY)
error("subvolume sync ioctl not supported in this kernel version, 6.13 and newer is required");
ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
}
}

out:
free(ids);
Expand Down
Loading