summaryrefslogtreecommitdiff
path: root/src/machine/machined-dbus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-02-24 18:23:40 +0100
committerLennart Poettering <lennart@poettering.net>2015-02-24 18:46:49 +0100
commit160e3793adf2da2bd9ae3fe6b8881bb937e6e71b (patch)
tree4edb97b24740ddac09fe3c5140e2af5cb530282f /src/machine/machined-dbus.c
parent3f7f1fad7621f584d9ce024abb313ecbc9bd0e62 (diff)
machined/machinectl: when "machinectl image-status" is used without arguments show statistics about pool
Diffstat (limited to 'src/machine/machined-dbus.c')
-rw-r--r--src/machine/machined-dbus.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 0e5a494f8c..c4f60b5b02 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -29,11 +29,99 @@
#include "bus-util.h"
#include "bus-common-errors.h"
#include "cgroup-util.h"
+#include "btrfs-util.h"
#include "machine-image.h"
#include "image-dbus.h"
#include "machined.h"
#include "machine-dbus.h"
+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) {
+
+ assert(bus);
+ assert(reply);
+
+ return sd_bus_message_append(reply, "s", "/var/lib/machines");
+}
+
+static int property_get_pool_usage(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ _cleanup_close_ int fd = -1;
+ uint64_t usage = (uint64_t) -1;
+ struct stat st;
+
+ assert(bus);
+ assert(reply);
+
+ /* We try to read the quota info from /var/lib/machines, as
+ * well as the usage of the loopback file
+ * /var/lib/machines.raw, and pick the larger value. */
+
+ fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+ if (fd >= 0) {
+ BtrfsQuotaInfo q;
+
+ if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
+ usage = q.referred;
+ }
+
+ if (stat("/var/lib/machines.raw", &st) >= 0) {
+ if (usage == (uint64_t) -1 || st.st_blocks * 512ULL > usage)
+ usage = st.st_blocks * 512ULL;
+ }
+
+ return sd_bus_message_append(reply, "t", usage);
+}
+
+static int property_get_pool_limit(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ _cleanup_close_ int fd = -1;
+ uint64_t size = (uint64_t) -1;
+ struct stat st;
+
+ assert(bus);
+ assert(reply);
+
+ /* We try to read the quota limit from /var/lib/machines, as
+ * well as the size of the loopback file
+ * /var/lib/machines.raw, and pick the smaller value. */
+
+ fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+ if (fd >= 0) {
+ BtrfsQuotaInfo q;
+
+ if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
+ size = q.referred_max;
+ }
+
+ if (stat("/var/lib/machines.raw", &st) >= 0) {
+ if (size == (uint64_t) -1 || (uint64_t) st.st_size < size)
+ size = st.st_size;
+ }
+
+ return sd_bus_message_append(reply, "t", size);
+}
+
static int method_get_machine(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
@@ -690,6 +778,9 @@ static int method_mark_image_read_only(sd_bus *bus, sd_bus_message *message, voi
const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_START(0),
+ SD_BUS_PROPERTY("PoolPath", "s", property_get_pool_path, 0, 0),
+ SD_BUS_PROPERTY("PoolUsage", "t", property_get_pool_usage, 0, 0),
+ SD_BUS_PROPERTY("PoolLimit", "t", property_get_pool_limit, 0, 0),
SD_BUS_METHOD("GetMachine", "s", "o", method_get_machine, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("GetImage", "s", "o", method_get_image, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("GetMachineByPID", "u", "o", method_get_machine_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),