chiark / gitweb /
sd-device: initialize variable
[elogind.git] / src / machine / machined-dbus.c
index 0b57a62fd4e96793f864f161c915b901480c4ad4..4d7409321b26b9efeb0a932b923ccdcf13f5ed3b 100644 (file)
@@ -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"
@@ -75,7 +76,7 @@ static int property_get_pool_usage(
                 BtrfsQuotaInfo q;
 
                 if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
-                        usage = q.referred;
+                        usage = q.referenced;
         }
 
         if (stat("/var/lib/machines.raw", &st) >= 0) {
@@ -111,7 +112,7 @@ static int property_get_pool_limit(
                 BtrfsQuotaInfo q;
 
                 if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
-                        size = q.referred_max;
+                        size = q.referenced_max;
         }
 
         if (stat("/var/lib/machines.raw", &st) >= 0) {
@@ -799,14 +800,21 @@ static int method_set_pool_limit(sd_bus *bus, sd_bus_message *message, void *use
         if (r == 0)
                 return 1; /* Will call us back */
 
-        r = btrfs_resize_loopback("/var/lib/machines", limit);
-        if (r < 0 && r != -ENODEV)
+        /* 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, false);
+        if (r == -ENOTTY)
+                return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
+        if (r < 0 && r != -ENODEV) /* ignore ENODEV, as that's what is returned if the file system is not on loopback */
                 return sd_bus_error_set_errnof(error, r, "Failed to adjust loopback limit: %m");
 
         r = btrfs_quota_limit("/var/lib/machines", limit);
         if (r == -ENOTTY)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
-        else if (r < 0)
+        if (r < 0)
                 return sd_bus_error_set_errnof(error, r, "Failed to adjust quota limit: %m");
 
         return sd_bus_reply_method_return(message, NULL);