btrfs: make btrfs_subvol_snapshot() parameters a flags field
This commit is contained in:
parent
d9e2daaf3d
commit
e9bc1871b9
|
@ -294,7 +294,7 @@ int tar_export_start(TarExport *e, const char *path, int fd, ImportCompressType
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
/* Let's try to make a snapshot, if we can, so that the export is atomic */
|
/* Let's try to make a snapshot, if we can, so that the export is atomic */
|
||||||
r = btrfs_subvol_snapshot_fd(sfd, e->temp_path, true, false);
|
r = btrfs_subvol_snapshot_fd(sfd, e->temp_path, BTRFS_SNAPSHOT_READ_ONLY);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_debug_errno(r, "Couldn't create snapshot %s of %s, not exporting atomically: %m", e->temp_path, path);
|
log_debug_errno(r, "Couldn't create snapshot %s of %s, not exporting atomically: %m", e->temp_path, path);
|
||||||
free(e->temp_path);
|
free(e->temp_path);
|
||||||
|
|
|
@ -127,7 +127,7 @@ int pull_make_local_copy(const char *final, const char *image_root, const char *
|
||||||
if (force_local)
|
if (force_local)
|
||||||
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
|
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
|
||||||
|
|
||||||
r = btrfs_subvol_snapshot(final, p, false, false);
|
r = btrfs_subvol_snapshot(final, p, 0);
|
||||||
if (r == -ENOTTY) {
|
if (r == -ENOTTY) {
|
||||||
r = copy_tree(final, p, false);
|
r = copy_tree(final, p, false);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -486,7 +486,7 @@ static int dkr_pull_job_on_open_disk(PullJob *j) {
|
||||||
const char *base_path;
|
const char *base_path;
|
||||||
|
|
||||||
base_path = strjoina(i->image_root, "/.dkr-", base);
|
base_path = strjoina(i->image_root, "/.dkr-", base);
|
||||||
r = btrfs_subvol_snapshot(base_path, i->temp_path, false, true);
|
r = btrfs_subvol_snapshot(base_path, i->temp_path, BTRFS_SNAPSHOT_FALLBACK_COPY);
|
||||||
} else
|
} else
|
||||||
r = btrfs_subvol_make(i->temp_path);
|
r = btrfs_subvol_make(i->temp_path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -3761,7 +3761,7 @@ int main(int argc, char *argv[]) {
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
|
r = btrfs_subvol_snapshot(arg_directory, np, (arg_read_only ? BTRFS_SNAPSHOT_READ_ONLY : 0) | BTRFS_SNAPSHOT_FALLBACK_COPY);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
|
log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -3785,7 +3785,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_template) {
|
if (arg_template) {
|
||||||
r = btrfs_subvol_snapshot(arg_template, arg_directory, arg_read_only, true);
|
r = btrfs_subvol_snapshot(arg_template, arg_directory, (arg_read_only ? BTRFS_SNAPSHOT_READ_ONLY : 0) | BTRFS_SNAPSHOT_FALLBACK_COPY);
|
||||||
if (r == -EEXIST) {
|
if (r == -EEXIST) {
|
||||||
if (!arg_quiet)
|
if (!arg_quiet)
|
||||||
log_info("Directory %s already exists, not populating from template %s.", arg_directory, arg_template);
|
log_info("Directory %s already exists, not populating from template %s.", arg_directory, arg_template);
|
||||||
|
|
|
@ -101,9 +101,9 @@ int btrfs_is_snapshot(int fd) {
|
||||||
return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
|
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 = {
|
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;
|
_cleanup_close_ int new_fd = -1;
|
||||||
const char *subvolume;
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
if (!fallback_copy)
|
if (!(flags & BTRFS_SNAPSHOT_FALLBACK_COPY))
|
||||||
return -EISDIR;
|
return -EISDIR;
|
||||||
|
|
||||||
r = btrfs_subvol_make(new_path);
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_only) {
|
if (flags & BTRFS_SNAPSHOT_READ_ONLY) {
|
||||||
r = btrfs_subvol_set_read_only(new_path, true);
|
r = btrfs_subvol_set_read_only(new_path, true);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
btrfs_subvol_remove(new_path, false);
|
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;
|
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;
|
_cleanup_close_ int old_fd = -1;
|
||||||
|
|
||||||
assert(old_path);
|
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)
|
if (old_fd < 0)
|
||||||
return -errno;
|
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) {
|
int btrfs_subvol_make(const char *path) {
|
||||||
|
|
|
@ -43,13 +43,18 @@ typedef struct BtrfsQuotaInfo {
|
||||||
uint64_t exclusive_max;
|
uint64_t exclusive_max;
|
||||||
} BtrfsQuotaInfo;
|
} BtrfsQuotaInfo;
|
||||||
|
|
||||||
|
typedef enum BtrfsSnapshotFlags {
|
||||||
|
BTRFS_SNAPSHOT_FALLBACK_COPY = 1,
|
||||||
|
BTRFS_SNAPSHOT_READ_ONLY = 2,
|
||||||
|
} BtrfsSnapshotFlags;
|
||||||
|
|
||||||
int btrfs_is_snapshot(int fd);
|
int btrfs_is_snapshot(int fd);
|
||||||
|
|
||||||
int btrfs_subvol_make(const char *path);
|
int btrfs_subvol_make(const char *path);
|
||||||
int btrfs_subvol_make_label(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_fd(int old_fd, const char *new_path, BtrfsSnapshotFlags flags);
|
||||||
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);
|
||||||
|
|
||||||
int btrfs_subvol_set_read_only_fd(int fd, bool b);
|
int btrfs_subvol_set_read_only_fd(int fd, bool b);
|
||||||
int btrfs_subvol_set_read_only(const char *path, bool b);
|
int btrfs_subvol_set_read_only(const char *path, bool b);
|
||||||
|
|
|
@ -491,7 +491,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
|
||||||
case IMAGE_DIRECTORY:
|
case IMAGE_DIRECTORY:
|
||||||
new_path = strjoina("/var/lib/machines/", new_name);
|
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;
|
break;
|
||||||
|
|
||||||
case IMAGE_RAW:
|
case IMAGE_RAW:
|
||||||
|
|
|
@ -72,11 +72,11 @@ int main(int argc, char *argv[]) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to write file: %m");
|
log_error_errno(r, "Failed to write file: %m");
|
||||||
|
|
||||||
r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", false, false);
|
r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to make snapshot: %m");
|
log_error_errno(r, "Failed to make snapshot: %m");
|
||||||
|
|
||||||
r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", true, false);
|
r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", BTRFS_SNAPSHOT_READ_ONLY);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to make snapshot: %m");
|
log_error_errno(r, "Failed to make snapshot: %m");
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to remove subvolume: %m");
|
log_error_errno(r, "Failed to remove subvolume: %m");
|
||||||
|
|
||||||
r = btrfs_subvol_snapshot("/etc", "/etc2", true, true);
|
r = btrfs_subvol_snapshot("/etc", "/etc2", BTRFS_SNAPSHOT_READ_ONLY|BTRFS_SNAPSHOT_FALLBACK_COPY);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to make snapshot: %m");
|
log_error_errno(r, "Failed to make snapshot: %m");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue