X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmachine-image.c;h=25689ca93cba91042ab0f9eec37520d7b7b54912;hb=7f76961982e03d4d5f781e7e7113fc7eff970f82;hp=7c041fab7624315d3a7e31b39c73fab7fd5f67ea;hpb=ebd93cb684806ac0f352139e69ac8f53eb49f5e4;p=elogind.git diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 7c041fab7..25689ca93 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -20,6 +20,7 @@ ***/ #include +#include #include #include "strv.h" @@ -71,6 +72,8 @@ static int image_new( i->read_only = read_only; i->crtime = crtime; i->mtime = mtime; + i->size = i->size_exclusive = (uint64_t) -1; + i->limit = i->limit_exclusive = (uint64_t) -1; i->name = strdup(pretty); if (!i->name) @@ -138,6 +141,7 @@ static int image_make( if (F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC)) { BtrfsSubvolInfo info; + BtrfsQuotaInfo quota; /* It's a btrfs subvolume */ @@ -156,6 +160,15 @@ static int image_make( if (r < 0) return r; + r = btrfs_subvol_get_quota_fd(fd, "a); + if (r >= 0) { + (*ret)->size = quota.referred; + (*ret)->size_exclusive = quota.exclusive; + + (*ret)->limit = quota.referred_max; + (*ret)->limit_exclusive = quota.exclusive_max; + } + return 1; } } @@ -199,6 +212,9 @@ static int image_make( if (r < 0) return r; + (*ret)->size = (*ret)->size_exclusive = st.st_blocks * 512; + (*ret)->limit = (*ret)->limit_exclusive = st.st_size; + return 1; } @@ -425,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: @@ -462,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; }