diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-08 19:15:49 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-01-08 23:13:45 +0100 |
commit | f2068bcce01db31cdc9422f44185f3b49c04d2ce (patch) | |
tree | fd5f6ddf9b0c36e9deb24252267d5ecce0cb2fe3 /src/shared | |
parent | e45fc5e738b0b7700e8b4f3c4b25c58a49b44b27 (diff) |
machined: when cloning a raw disk image, also set the NOCOW flag
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/copy.c | 9 | ||||
-rw-r--r-- | src/shared/copy.h | 4 | ||||
-rw-r--r-- | src/shared/machine-image.c | 9 |
3 files changed, 16 insertions, 6 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c index 3df636704c..b681f6f109 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -359,7 +359,7 @@ int copy_file_fd(const char *from, int fdt, bool try_reflink) { return r; } -int copy_file(const char *from, const char *to, int flags, mode_t mode) { +int copy_file(const char *from, const char *to, int flags, mode_t mode, int chattr_flags) { int fdt, r; assert(from); @@ -371,6 +371,9 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) { return -errno; } + if (chattr_flags != 0) + (void) chattr_fd(fdt, true, chattr_flags); + r = copy_file_fd(from, fdt, true); if (r < 0) { close(fdt); @@ -386,7 +389,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) { return 0; } -int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace) { +int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, int chattr_flags) { _cleanup_free_ char *t; int r; @@ -397,7 +400,7 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace if (r < 0) return r; - r = copy_file(from, t, O_NOFOLLOW|O_EXCL, mode); + r = copy_file(from, t, O_NOFOLLOW|O_EXCL, mode, chattr_flags); if (r < 0) return r; diff --git a/src/shared/copy.h b/src/shared/copy.h index 58159a02cc..e4e3079120 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -25,8 +25,8 @@ #include <sys/types.h> int copy_file_fd(const char *from, int to, bool try_reflink); -int copy_file(const char *from, const char *to, int flags, mode_t mode); -int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace); +int copy_file(const char *from, const char *to, int flags, mode_t mode, int chattr_flags); +int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, int chattr_flags); int copy_tree(const char *from, const char *to, bool merge); int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge); int copy_directory_fd(int dirfd, const char *to, bool merge); diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 36b64e1fab..25689ca93c 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -20,6 +20,7 @@ ***/ #include <sys/statfs.h> +#include <linux/fs.h> #include <fcntl.h> #include "strv.h" @@ -440,7 +441,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) { case IMAGE_GPT: new_path = strappenda("/var/lib/container/", new_name, ".gpt"); - r = copy_file_atomic(i->path, new_path, read_only ? 0444 : 0644, false); + r = copy_file_atomic(i->path, new_path, read_only ? 0444 : 0644, false, FS_NOCOW_FL); break; default: @@ -477,6 +478,12 @@ int image_read_only(Image *i, bool b) { if (chmod(i->path, (st.st_mode & 0444) | (b ? 0000 : 0200)) < 0) return -errno; + + /* If the images is now read-only, it's a good time to + * defrag it, given that no write patterns will + * fragment it again. */ + if (b) + (void) btrfs_defrag(i->path); break; } |