X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmachine-image.c;h=25689ca93cba91042ab0f9eec37520d7b7b54912;hb=76917807eb50ccde58901e8bec7ed3d408d1cc22;hp=36b64e1fab8fec9cf0f6db88157f78c1509cd52a;hpb=b6b1849830f5e4a6065c3b0c993668e500c954d3;p=elogind.git diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 36b64e1fa..25689ca93 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -20,6 +20,7 @@ ***/ #include +#include #include #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; }