From 01dcca794a4f546ec2ec109d0b2eb27204e7b16e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 6 Apr 2015 11:47:25 +0200 Subject: [PATCH] btrfs: make btrfs_subvol_snapshot() parameters a flags field --- src/shared/btrfs-util.c | 12 ++++++------ src/shared/btrfs-util.h | 9 +++++++-- src/shared/machine-image.c | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index fc795cb18..34ebaece0 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -101,9 +101,9 @@ int btrfs_is_snapshot(int fd) { return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC); } -int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, bool read_only, bool fallback_copy) { +int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, BtrfsSnapshotFlags flags) { struct btrfs_ioctl_vol_args_v2 args = { - .flags = read_only ? BTRFS_SUBVOL_RDONLY : 0, + .flags = flags & BTRFS_SNAPSHOT_READ_ONLY ? BTRFS_SUBVOL_RDONLY : 0, }; _cleanup_close_ int new_fd = -1; const char *subvolume; @@ -115,7 +115,7 @@ int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, bool read_only, b if (r < 0) return r; if (r == 0) { - if (!fallback_copy) + if (!(flags & BTRFS_SNAPSHOT_FALLBACK_COPY)) return -EISDIR; r = btrfs_subvol_make(new_path); @@ -128,7 +128,7 @@ int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, bool read_only, b return r; } - if (read_only) { + if (flags & BTRFS_SNAPSHOT_READ_ONLY) { r = btrfs_subvol_set_read_only(new_path, true); if (r < 0) { btrfs_subvol_remove(new_path, false); @@ -156,7 +156,7 @@ int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, bool read_only, b return 0; } -int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy) { +int btrfs_subvol_snapshot(const char *old_path, const char *new_path, BtrfsSnapshotFlags flags) { _cleanup_close_ int old_fd = -1; assert(old_path); @@ -166,7 +166,7 @@ int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_ if (old_fd < 0) return -errno; - return btrfs_subvol_snapshot_fd(old_fd, new_path, read_only, fallback_copy); + return btrfs_subvol_snapshot_fd(old_fd, new_path, flags); } int btrfs_subvol_make(const char *path) { diff --git a/src/shared/btrfs-util.h b/src/shared/btrfs-util.h index 06ecc11b4..e3ad98750 100644 --- a/src/shared/btrfs-util.h +++ b/src/shared/btrfs-util.h @@ -43,13 +43,18 @@ typedef struct BtrfsQuotaInfo { uint64_t exclusive_max; } BtrfsQuotaInfo; +typedef enum BtrfsSnapshotFlags { + BTRFS_SNAPSHOT_FALLBACK_COPY = 1, + BTRFS_SNAPSHOT_READ_ONLY = 2, +} BtrfsSnapshotFlags; + int btrfs_is_snapshot(int fd); int btrfs_subvol_make(const char *path); int btrfs_subvol_make_label(const char *path); -int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, bool read_only, bool fallback_copy); -int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy); +int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, BtrfsSnapshotFlags flags); +int btrfs_subvol_snapshot(const char *old_path, const char *new_path, BtrfsSnapshotFlags flags); int btrfs_subvol_set_read_only_fd(int fd, bool b); int btrfs_subvol_set_read_only(const char *path, bool b); diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index fb72123f1..ebe5a130f 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -491,7 +491,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) { case IMAGE_DIRECTORY: new_path = strjoina("/var/lib/machines/", new_name); - r = btrfs_subvol_snapshot(i->path, new_path, read_only, true); + r = btrfs_subvol_snapshot(i->path, new_path, (read_only ? BTRFS_SNAPSHOT_READ_ONLY : 0) | BTRFS_SNAPSHOT_FALLBACK_COPY); break; case IMAGE_RAW: -- 2.30.2