diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-03-02 19:21:04 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-03-02 19:36:21 +0100 |
commit | 4cee5eede280b7fd48c18a1942616c4ac896a554 (patch) | |
tree | 2cbf9dda7f441c39148dee0162a0ddd7e4df9fc8 /src | |
parent | journal: fix Inappropriate ioctl for device on ext4 (diff) | |
download | systemd-4cee5eede280b7fd48c18a1942616c4ac896a554.tar.xz systemd-4cee5eede280b7fd48c18a1942616c4ac896a554.zip |
machined: also set up /var/lib/machines as btrfs, if "machinectl set-limit" is called
Diffstat (limited to 'src')
-rw-r--r-- | src/import/importd.c | 4 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 6 | ||||
-rw-r--r-- | src/shared/machine-pool.c | 14 | ||||
-rw-r--r-- | src/shared/machine-pool.h | 2 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/import/importd.c b/src/import/importd.c index a6447e1fdd..8a6a8c8ed1 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -689,7 +689,7 @@ static int method_pull_tar_or_raw(sd_bus *bus, sd_bus_message *msg, void *userda if (v < 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown verification mode %s", verify); - r = setup_machine_directory(error); + r = setup_machine_directory((uint64_t) -1, error); if (r < 0) return r; @@ -784,7 +784,7 @@ static int method_pull_dkr(sd_bus *bus, sd_bus_message *msg, void *userdata, sd_ if (v != IMPORT_VERIFY_NO) return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "DKR does not support verification."); - r = setup_machine_directory(error); + r = setup_machine_directory((uint64_t) -1, error); if (r < 0) return r; diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 0b57a62fd4..5ab40b0410 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -31,6 +31,7 @@ #include "cgroup-util.h" #include "btrfs-util.h" #include "machine-image.h" +#include "machine-pool.h" #include "image-dbus.h" #include "machined.h" #include "machine-dbus.h" @@ -799,6 +800,11 @@ static int method_set_pool_limit(sd_bus *bus, sd_bus_message *message, void *use if (r == 0) return 1; /* Will call us back */ + /* Set up the machine directory if necessary */ + r = setup_machine_directory(limit, error); + if (r < 0) + return r; + r = btrfs_resize_loopback("/var/lib/machines", limit); if (r < 0 && r != -ENODEV) return sd_bus_error_set_errnof(error, r, "Failed to adjust loopback limit: %m"); diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 7b17395d21..b74252dbc8 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -47,7 +47,7 @@ static int check_btrfs(void) { return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC); } -static int setup_machine_raw(sd_bus_error *error) { +static int setup_machine_raw(uint64_t size, sd_bus_error *error) { _cleanup_free_ char *tmp = NULL; _cleanup_close_ int fd = -1; struct statvfs ss; @@ -91,7 +91,7 @@ static int setup_machine_raw(sd_bus_error *error) { goto fail; } - if (ftruncate(fd, VAR_LIB_MACHINES_SIZE_START) < 0) { + if (ftruncate(fd, size) < 0) { r = sd_bus_error_set_errnof(error, errno, "Failed to enlarge /var/lib/machines.raw: %m"); goto fail; } @@ -160,7 +160,7 @@ fail: return r; } -int setup_machine_directory(sd_bus_error *error) { +int setup_machine_directory(uint64_t size, sd_bus_error *error) { _cleanup_release_lock_file_ LockFile lock_file = LOCK_FILE_INIT; struct loop_info64 info = { .lo_flags = LO_FLAGS_AUTOCLEAR, @@ -171,6 +171,12 @@ int setup_machine_directory(sd_bus_error *error) { bool tmpdir_made = false, mntdir_made = false, mntdir_mounted = false; int r, nr = -1; + /* btrfs cannot handle file systems < 16M, hence use this as minimum */ + if (size == (uint64_t) -1) + size = VAR_LIB_MACHINES_SIZE_START; + else if (size < 16*1024*1024) + size = 16*1024*1024; + /* Make sure we only set the directory up once at a time */ r = make_lock_file("/run/systemd/machines.lock", LOCK_EX, &lock_file); if (r < 0) @@ -193,7 +199,7 @@ int setup_machine_directory(sd_bus_error *error) { dir_is_empty("/var/lib/machines") == 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "/var/lib/machines is not a btrfs file system. Operation is not supported on legacy file systems."); - fd = setup_machine_raw(error); + fd = setup_machine_raw(size, error); if (fd < 0) return fd; diff --git a/src/shared/machine-pool.h b/src/shared/machine-pool.h index 5f7bc281eb..9c9849f618 100644 --- a/src/shared/machine-pool.h +++ b/src/shared/machine-pool.h @@ -23,4 +23,4 @@ #include "sd-bus.h" -int setup_machine_directory(sd_bus_error *error); +int setup_machine_directory(uint64_t size, sd_bus_error *error); |