Skip to content

Commit

Permalink
btrfs-progs: remove support for BTRFS_SUBVOL_CREATE_ASYNC
Browse files Browse the repository at this point in the history
Kernel has removed support for this feature in 5.7 so let's remove
support from progs as well.

Signed-off-by: Nikolay Borisov <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
lorddoskias authored and kdave committed Oct 6, 2021
1 parent 85e102f commit 451db51
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 72 deletions.
8 changes: 5 additions & 3 deletions ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ BUILD_ASSERT(sizeof(struct btrfs_ioctl_vol_args) == 4096);

#define BTRFS_DEVICE_PATH_NAME_MAX 1024

#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
/*
* Obsolete since 5.15, functionality removed in kernel 5.7:
* BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
*/
#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
#define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)

#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
(BTRFS_SUBVOL_CREATE_ASYNC | \
BTRFS_SUBVOL_RDONLY | \
(BTRFS_SUBVOL_RDONLY | \
BTRFS_SUBVOL_QGROUP_INHERIT | \
BTRFS_DEVICE_SPEC_BY_ID | \
BTRFS_SUBVOL_SPEC_BY_ID)
Expand Down
14 changes: 3 additions & 11 deletions libbtrfsutil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ The equivalent `btrfs-progs` command is `btrfs subvolume list`.
#### Creation

`btrfs_util_create_subvolume()` creates a new subvolume at the given path. The
subvolume can be created asynchronously and inherit from quota groups
(qgroups).
subvolume can inherit from quota groups (qgroups).

Qgroups to inherit are specified with a `struct btrfs_util_qgroup_inherit`,
which is created by `btrfs_util_create_qgroup_inherit()` and freed by
Expand All @@ -262,10 +261,6 @@ method and a `groups` member, which is a list of ints.
```c
btrfs_util_create_subvolume("/subvol2", 0, NULL, NULL);

uint64_t async_transid;
btrfs_util_create_subvolume("/subvol2", 0, &async_transid, NULL);
btrfs_util_wait_sync("/", async_transid);

struct btrfs_util_qgroup_inherit *qgroups;
btrfs_util_create_qgroup_inherit(0, &qgroups);
btrfs_util_qgroup_inherit_add_group(&qgroups, 256);
Expand All @@ -276,9 +271,6 @@ btrfs_util_destroy_qgroup_inherit(qgroups);
```python
btrfsutil.create_subvolume('/subvol2')
async_transid = btrfsutil.create_subvolume('/subvol2', async_=True)
btrfsutil.wait_sync('/', async_transid)
qgroups = btrfsutil.QgroupInherit()
qgroups.add_group(256)
btrfsutil.create_subvolume('/subvol2', qgroup_inherit=qgroups)
Expand All @@ -292,8 +284,8 @@ The equivalent `btrfs-progs` command is `btrfs subvolume create`.
#### Snapshotting

Snapshots are created with `btrfs_util_create_snapshot()`, which takes a source
path, a destination path, and flags. It can also be asynchronous and inherit
from quota groups; see [subvolume creation](#Creation).
path, a destination path, and flags. It can also inherit from quota groups;
see [subvolume creation](#Creation).

Snapshot creation can be recursive, in which case subvolumes underneath the
subvolume being snapshotted will also be snapshotted onto the same location in
Expand Down
8 changes: 5 additions & 3 deletions libbtrfsutil/btrfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ struct btrfs_ioctl_vol_args {
#define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)

#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
(BTRFS_SUBVOL_CREATE_ASYNC | \
BTRFS_SUBVOL_RDONLY | \
(BTRFS_SUBVOL_RDONLY | \
BTRFS_SUBVOL_QGROUP_INHERIT | \
BTRFS_DEVICE_SPEC_BY_ID | \
BTRFS_SUBVOL_SPEC_BY_ID)
Expand Down Expand Up @@ -103,7 +102,10 @@ struct btrfs_ioctl_qgroup_limit_args {
* - BTRFS_IOC_SUBVOL_GETFLAGS
* - BTRFS_IOC_SUBVOL_SETFLAGS
*/
#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
/*
* Obsolete since 5.15, functionality removed in kernel 5.7:
* BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
*/
#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)

Expand Down
23 changes: 9 additions & 14 deletions libbtrfsutil/btrfsutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,13 @@ struct btrfs_util_qgroup_inherit;
* btrfs_util_create_subvolume() - Create a new subvolume.
* @path: Where to create the subvolume.
* @flags: Must be zero.
* @async_transid: If not NULL, create the subvolume asynchronously (i.e.,
* without waiting for it to commit it to disk) and return the transaction ID
* that it was created in. This transaction ID can be waited on with
* btrfs_util_wait_sync().
* @unused: No longer used (since 5.15)
* @qgroup_inherit: Qgroups to inherit from, or NULL.
*
* Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
*/
enum btrfs_util_error btrfs_util_create_subvolume(const char *path, int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit);

/**
Expand All @@ -385,15 +382,15 @@ enum btrfs_util_error btrfs_util_create_subvolume(const char *path, int flags,
* should be created.
* @name: Name of the subvolume to create.
* @flags: See btrfs_util_create_subvolume().
* @async_transid: See btrfs_util_create_subvolume().
* @unused: See btrfs_util_create_subvolume().
* @qgroup_inherit: See btrfs_util_create_subvolume().
*
* Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
*/
enum btrfs_util_error btrfs_util_create_subvolume_fd(int parent_fd,
const char *name,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit);

/**
Expand All @@ -418,24 +415,22 @@ enum btrfs_util_error btrfs_util_create_subvolume_fd(int parent_fd,
* @source: Path of the existing subvolume to snapshot.
* @path: Where to create the snapshot.
* @flags: Bitmask of BTRFS_UTIL_CREATE_SNAPSHOT_* flags.
* @async_transid: See btrfs_util_create_subvolume(). If
* %BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE was in @flags, then this will contain
* the largest transaction ID of all created subvolumes.
* @unused: See btrfs_util_create_subvolume().
* @qgroup_inherit: See btrfs_util_create_subvolume().
*
* Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
*/
enum btrfs_util_error btrfs_util_create_snapshot(const char *source,
const char *path, int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit);

/**
* btrfs_util_create_snapshot_fd() - See btrfs_util_create_snapshot().
*/
enum btrfs_util_error btrfs_util_create_snapshot_fd(int fd, const char *path,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit);

/**
Expand All @@ -446,13 +441,13 @@ enum btrfs_util_error btrfs_util_create_snapshot_fd(int fd, const char *path,
* be created.
* @name: Name of the snapshot to create.
* @flags: See btrfs_util_create_snapshot().
* @async_transid: See btrfs_util_create_snapshot().
* @unused: See btrfs_util_create_snapshot().
* @qgroup_inherit: See btrfs_util_create_snapshot().
*/
enum btrfs_util_error btrfs_util_create_snapshot_fd2(int fd, int parent_fd,
const char *name,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit);

/**
Expand Down
6 changes: 2 additions & 4 deletions libbtrfsutil/python/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ static PyMethodDef btrfsutil_methods[] = {
"Create a new subvolume.\n\n"
"Arguments:\n"
"path -- string, bytes, or path-like object\n"
"async_ -- create the subvolume without waiting for it to commit to\n"
"disk and return the transaction ID\n"
"async_ -- no longer used\n"
"qgroup_inherit -- optional QgroupInherit object of qgroups to\n"
"inherit from"},
{"create_snapshot", (PyCFunction)create_snapshot,
Expand All @@ -251,8 +250,7 @@ static PyMethodDef btrfsutil_methods[] = {
"path -- string, bytes, or path-like object\n"
"recursive -- also snapshot child subvolumes\n"
"read_only -- create a read-only snapshot\n"
"async_ -- create the subvolume without waiting for it to commit to\n"
"disk and return the transaction ID\n"
"async_ -- no longer used\n"
"qgroup_inherit -- optional QgroupInherit object of qgroups to\n"
"inherit from"},
{"delete_subvolume", (PyCFunction)delete_subvolume,
Expand Down
12 changes: 2 additions & 10 deletions libbtrfsutil/python/tests/test_subvolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ def test_create_subvolume(self):
btrfsutil.create_subvolume(subvol + '6//')
self.assertTrue(btrfsutil.is_subvolume(subvol + '6'))

transid = btrfsutil.create_subvolume(subvol + '7', async_=True)
self.assertTrue(btrfsutil.is_subvolume(subvol + '7'))
self.assertGreater(transid, 0)

# Test creating subvolumes under '/' in a chroot.
pid = os.fork()
if pid == 0:
Expand Down Expand Up @@ -308,12 +304,8 @@ def test_create_snapshot(self):
btrfsutil.create_snapshot(subvol, snapshot + '2', recursive=True)
self.assertTrue(os.path.exists(os.path.join(snapshot + '2', 'nested/more_nested/nested_dir')))

transid = btrfsutil.create_snapshot(subvol, snapshot + '3', recursive=True, async_=True)
self.assertTrue(os.path.exists(os.path.join(snapshot + '3', 'nested/more_nested/nested_dir')))
self.assertGreater(transid, 0)

btrfsutil.create_snapshot(subvol, snapshot + '4', read_only=True)
self.assertTrue(btrfsutil.get_subvolume_read_only(snapshot + '4'))
btrfsutil.create_snapshot(subvol, snapshot + '3', read_only=True)
self.assertTrue(btrfsutil.get_subvolume_read_only(snapshot + '3'))

def test_delete_subvolume(self):
subvol = os.path.join(self.mountpoint, 'subvol')
Expand Down
38 changes: 11 additions & 27 deletions libbtrfsutil/subvolume.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ static enum btrfs_util_error openat_parent_and_name(int dirfd, const char *path,

PUBLIC enum btrfs_util_error btrfs_util_create_subvolume(const char *path,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit)
{
char name[BTRFS_SUBVOL_NAME_MAX + 1];
Expand All @@ -696,15 +696,15 @@ PUBLIC enum btrfs_util_error btrfs_util_create_subvolume(const char *path,
return err;

err = btrfs_util_create_subvolume_fd(parent_fd, name, flags,
async_transid, qgroup_inherit);
unused, qgroup_inherit);
SAVE_ERRNO_AND_CLOSE(parent_fd);
return err;
}

PUBLIC enum btrfs_util_error btrfs_util_create_subvolume_fd(int parent_fd,
const char *name,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit)
{
struct btrfs_ioctl_vol_args_v2 args = {};
Expand All @@ -716,8 +716,6 @@ PUBLIC enum btrfs_util_error btrfs_util_create_subvolume_fd(int parent_fd,
return BTRFS_UTIL_ERROR_INVALID_ARGUMENT;
}

if (async_transid)
args.flags |= BTRFS_SUBVOL_CREATE_ASYNC;
if (qgroup_inherit) {
args.flags |= BTRFS_SUBVOL_QGROUP_INHERIT;
args.qgroup_inherit = (struct btrfs_qgroup_inherit *)qgroup_inherit;
Expand All @@ -738,9 +736,6 @@ PUBLIC enum btrfs_util_error btrfs_util_create_subvolume_fd(int parent_fd,
if (ret == -1)
return BTRFS_UTIL_ERROR_SUBVOL_CREATE_FAILED;

if (async_transid)
*async_transid = args.transid;

return BTRFS_UTIL_OK;
}

Expand Down Expand Up @@ -1022,8 +1017,7 @@ PUBLIC enum btrfs_util_error btrfs_util_create_subvolume_iterator_fd(int fd,
}

static enum btrfs_util_error snapshot_subvolume_children(int fd, int parent_fd,
const char *name,
uint64_t *async_transid)
const char *name)
{
struct btrfs_util_subvolume_iterator *iter;
enum btrfs_util_error err;
Expand All @@ -1041,7 +1035,6 @@ static enum btrfs_util_error snapshot_subvolume_children(int fd, int parent_fd,
char child_name[BTRFS_SUBVOL_NAME_MAX + 1];
char *child_path;
int child_fd, new_parent_fd;
uint64_t tmp_transid;

err = btrfs_util_subvolume_iterator_next(iter, &child_path,
NULL);
Expand Down Expand Up @@ -1076,14 +1069,11 @@ static enum btrfs_util_error snapshot_subvolume_children(int fd, int parent_fd,

err = btrfs_util_create_snapshot_fd2(child_fd, new_parent_fd,
child_name, 0,
async_transid ? &tmp_transid : NULL,
NULL);
NULL, NULL);
SAVE_ERRNO_AND_CLOSE(child_fd);
SAVE_ERRNO_AND_CLOSE(new_parent_fd);
if (err)
break;
if (async_transid && tmp_transid > *async_transid)
*async_transid = tmp_transid;
}

btrfs_util_destroy_subvolume_iterator(iter);
Expand All @@ -1095,7 +1085,7 @@ static enum btrfs_util_error snapshot_subvolume_children(int fd, int parent_fd,
PUBLIC enum btrfs_util_error btrfs_util_create_snapshot(const char *source,
const char *path,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit)
{
enum btrfs_util_error err;
Expand All @@ -1105,7 +1095,7 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot(const char *source,
if (fd == -1)
return BTRFS_UTIL_ERROR_OPEN_FAILED;

err = btrfs_util_create_snapshot_fd(fd, path, flags, async_transid,
err = btrfs_util_create_snapshot_fd(fd, path, flags, unused,
qgroup_inherit);
SAVE_ERRNO_AND_CLOSE(fd);
return err;
Expand All @@ -1114,7 +1104,7 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot(const char *source,
PUBLIC enum btrfs_util_error btrfs_util_create_snapshot_fd(int fd,
const char *path,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit)
{
char name[BTRFS_SUBVOL_NAME_MAX + 1];
Expand All @@ -1127,7 +1117,7 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot_fd(int fd,
return err;

err = btrfs_util_create_snapshot_fd2(fd, parent_fd, name, flags,
async_transid, qgroup_inherit);
unused, qgroup_inherit);
SAVE_ERRNO_AND_CLOSE(parent_fd);
return err;
}
Expand All @@ -1136,7 +1126,7 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot_fd2(int fd,
int parent_fd,
const char *name,
int flags,
uint64_t *async_transid,
uint64_t *unused,
struct btrfs_util_qgroup_inherit *qgroup_inherit)
{
struct btrfs_ioctl_vol_args_v2 args = {.fd = fd};
Expand All @@ -1153,8 +1143,6 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot_fd2(int fd,

if (flags & BTRFS_UTIL_CREATE_SNAPSHOT_READ_ONLY)
args.flags |= BTRFS_SUBVOL_RDONLY;
if (async_transid)
args.flags |= BTRFS_SUBVOL_CREATE_ASYNC;
if (qgroup_inherit) {
args.flags |= BTRFS_SUBVOL_QGROUP_INHERIT;
args.qgroup_inherit = (struct btrfs_qgroup_inherit *)qgroup_inherit;
Expand All @@ -1175,12 +1163,8 @@ PUBLIC enum btrfs_util_error btrfs_util_create_snapshot_fd2(int fd,
if (ret == -1)
return BTRFS_UTIL_ERROR_SUBVOL_CREATE_FAILED;

if (async_transid)
*async_transid = args.transid;

if (flags & BTRFS_UTIL_CREATE_SNAPSHOT_RECURSIVE) {
err = snapshot_subvolume_children(fd, parent_fd, name,
async_transid);
err = snapshot_subvolume_children(fd, parent_fd, name);
if (err)
return err;
}
Expand Down

0 comments on commit 451db51

Please sign in to comment.