[systemd-commits] 2 commits - src/nspawn src/shared
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Apr 22 07:59:55 PDT 2015
src/nspawn/nspawn.c | 3 ++-
src/shared/btrfs-util.c | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 38 insertions(+), 3 deletions(-)
New commits:
commit aee327b8169670986f6a48acbd5ffe1355bfcf27
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 22 16:56:51 2015 +0200
nspawn: don't inherit read-only flag from disk image if --ephemeral is used
When --ephemeral is used there's no need to keep the image read-only, so
let's not do that then.
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 1a9b3be..f43ffd9 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3607,7 +3607,8 @@ static int determine_names(void) {
if (r < 0)
return log_error_errno(r, "Invalid image directory: %m");
- arg_read_only = arg_read_only || i->read_only;
+ if (!arg_ephemeral)
+ arg_read_only = arg_read_only || i->read_only;
} else
arg_directory = get_current_dir_name();
commit ffb296b2c28c32cccff512e90a1696eaf0c23708
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Apr 22 16:52:53 2015 +0200
btrfs-util: fix creating recursive read-only snapshots
When creating recursive read-only snapshots we need to mark the snapshot
writable immediately before creating subsnapshots within it, otherwise
the operation for it will fail.
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c
index ac1907d..3ed14dc 100644
--- a/src/shared/btrfs-util.c
+++ b/src/shared/btrfs-util.c
@@ -948,6 +948,7 @@ static int subvol_snapshot_children(int old_fd, int new_fd, const char *subvolum
.fd = old_fd,
};
int r;
+ _cleanup_close_ int subvolume_fd = -1;
assert(old_fd >= 0);
assert(new_fd >= 0);
@@ -1028,14 +1029,47 @@ static int subvol_snapshot_children(int old_fd, int new_fd, const char *subvolum
if (new_child_fd < 0)
return -errno;
+ if (flags & BTRFS_SNAPSHOT_READ_ONLY) {
+ /* If the snapshot is read-only we
+ * need to mark it writable
+ * temporarily, to put the subsnapshot
+ * into place. */
+
+ if (subvolume_fd < 0) {
+ subvolume_fd = openat(new_fd, subvolume, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
+ if (subvolume_fd < 0)
+ return -errno;
+ }
+
+ r = btrfs_subvol_set_read_only_fd(subvolume_fd, false);
+ if (r < 0)
+ return r;
+ }
+
/* When btrfs clones the subvolumes, child
* subvolumes appear as directories. Remove
* them, so that we can create a new snapshot
* in their place */
- if (unlinkat(new_child_fd, p, AT_REMOVEDIR) < 0)
- return -errno;
+ if (unlinkat(new_child_fd, p, AT_REMOVEDIR) < 0) {
+ int k = -errno;
+
+ if (flags & BTRFS_SNAPSHOT_READ_ONLY)
+ (void) btrfs_subvol_set_read_only_fd(subvolume_fd, true);
+
+ return k;
+ }
r = subvol_snapshot_children(old_child_fd, new_child_fd, p, sh->objectid, flags & ~BTRFS_SNAPSHOT_FALLBACK_COPY);
+
+ /* Restore the readonly flag */
+ if (flags & BTRFS_SNAPSHOT_READ_ONLY) {
+ int k;
+
+ k = btrfs_subvol_set_read_only_fd(subvolume_fd, true);
+ if (r >= 0 && k < 0)
+ return k;
+ }
+
if (r < 0)
return r;
}
More information about the systemd-commits
mailing list