machine: Fix hardcoded /var/lib/machines paths
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include "image-varlink.h"
|
||||
#include "io-util.h"
|
||||
#include "json-util.h"
|
||||
#include "machine-pool.h"
|
||||
#include "machined.h"
|
||||
#include "operation.h"
|
||||
#include "process-util.h"
|
||||
@@ -280,7 +279,11 @@ int vl_method_set_pool_limit(sd_varlink *link, sd_json_variant *parameters, sd_v
|
||||
}
|
||||
|
||||
/* Set up the machine directory if necessary */
|
||||
r = setup_machine_directory(/* error = */ NULL, /* use_btrfs_subvol= */ true, /* use_btrfs_quota= */ true);
|
||||
r = image_setup_pool(
|
||||
manager->runtime_scope,
|
||||
IMAGE_MACHINE,
|
||||
/* use_btrfs_subvol= */ true,
|
||||
/* use_btrfs_quota= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+29
-22
@@ -6,9 +6,7 @@
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-get-properties.h"
|
||||
#include "bus-locator.h"
|
||||
#include "bus-message-util.h"
|
||||
#include "bus-object.h"
|
||||
@@ -27,7 +25,6 @@
|
||||
#include "io-util.h"
|
||||
#include "machine.h"
|
||||
#include "machine-dbus.h"
|
||||
#include "machine-pool.h"
|
||||
#include "machined.h"
|
||||
#include "namespace-util.h"
|
||||
#include "operation.h"
|
||||
@@ -39,7 +36,25 @@
|
||||
#include "unit-def.h"
|
||||
#include "user-util.h"
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_pool_path, "s", "/var/lib/machines");
|
||||
static int property_get_pool_path(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_free_ char *poolpath = NULL;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
(void) image_get_pool_path(m->runtime_scope, IMAGE_MACHINE, &poolpath);
|
||||
|
||||
return sd_bus_message_append(reply, "s", strempty(poolpath));
|
||||
}
|
||||
|
||||
static int property_get_pool_usage(
|
||||
sd_bus *bus,
|
||||
@@ -50,19 +65,13 @@ static int property_get_pool_usage(
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
uint64_t usage = UINT64_MAX;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
|
||||
if (fd >= 0) {
|
||||
BtrfsQuotaInfo q;
|
||||
|
||||
if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0)
|
||||
usage = q.referenced;
|
||||
}
|
||||
(void) image_get_pool_usage(m->runtime_scope, IMAGE_MACHINE, &usage);
|
||||
|
||||
return sd_bus_message_append(reply, "t", usage);
|
||||
}
|
||||
@@ -76,19 +85,13 @@ static int property_get_pool_limit(
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
uint64_t size = UINT64_MAX;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
|
||||
if (fd >= 0) {
|
||||
BtrfsQuotaInfo q;
|
||||
|
||||
if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0)
|
||||
size = q.referenced_max;
|
||||
}
|
||||
(void) image_get_pool_limit(m->runtime_scope, IMAGE_MACHINE, &size);
|
||||
|
||||
return sd_bus_message_append(reply, "t", size);
|
||||
}
|
||||
@@ -1077,9 +1080,13 @@ static int method_set_pool_limit(sd_bus_message *message, void *userdata, sd_bus
|
||||
}
|
||||
|
||||
/* Set up the machine directory if necessary */
|
||||
r = setup_machine_directory(error, /* use_btrfs_subvol= */ true, /* use_btrfs_quota= */ true);
|
||||
r = image_setup_pool(
|
||||
m->runtime_scope,
|
||||
IMAGE_MACHINE,
|
||||
/* use_btrfs_subvol= */ true,
|
||||
/* use_btrfs_quota= */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return sd_bus_error_set_errnof(error, r, "Failed to set up machine pool: %m");
|
||||
|
||||
r = image_set_pool_limit(m->runtime_scope, IMAGE_MACHINE, limit);
|
||||
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
|
||||
|
||||
Reference in New Issue
Block a user