chiark / gitweb /
importd: enable btrfs quota in /var/lib/machines, if necessary
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Feb 2015 17:43:37 +0000 (18:43 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 24 Feb 2015 17:46:49 +0000 (18:46 +0100)
src/import/importd.c
src/shared/btrfs-util.c
src/shared/btrfs-util.h

index 25d9ab2e7110ce9139c09c3af6be6c256568ff92..f315212685c5b5bb67fca025791d567df0056b63 100644 (file)
@@ -792,6 +792,11 @@ static int setup_machine_directory(sd_bus_error *error) {
                 return sd_bus_error_set_errnof(error, r, "Failed to determine whether /var/lib/machines is located on btrfs: %m");
         if (r > 0) {
                 (void) btrfs_subvol_make_label("/var/lib/machines");
                 return sd_bus_error_set_errnof(error, r, "Failed to determine whether /var/lib/machines is located on btrfs: %m");
         if (r > 0) {
                 (void) btrfs_subvol_make_label("/var/lib/machines");
+
+                r = btrfs_quota_enable("/var/lib/machines", true);
+                if (r < 0)
+                        log_warning_errno(r, "Failed to enable quota, ignoring: %m");
+
                 return 0;
         }
 
                 return 0;
         }
 
@@ -858,6 +863,10 @@ static int setup_machine_directory(sd_bus_error *error) {
         }
         mntdir_mounted = true;
 
         }
         mntdir_mounted = true;
 
+        r = btrfs_quota_enable(mntdir, true);
+        if (r < 0)
+                log_warning_errno(r, "Failed to enable quota, ignoring: %m");
+
         if (chmod(mntdir, 0700) < 0) {
                 r = sd_bus_error_set_errnof(error, errno, "Failed to fix owner: %m");
                 goto fail;
         if (chmod(mntdir, 0700) < 0) {
                 r = sd_bus_error_set_errnof(error, errno, "Failed to fix owner: %m");
                 goto fail;
index 2a70dfea451a4bf2ee6ece3d3c1d05cfcac4b1c7..980963b74880149a507582b2a30afa46eba0ce80 100644 (file)
@@ -646,3 +646,26 @@ int btrfs_defrag(const char *p) {
 
         return btrfs_defrag_fd(fd);
 }
 
         return btrfs_defrag_fd(fd);
 }
+
+int btrfs_quota_enable_fd(int fd, bool b) {
+        struct btrfs_ioctl_quota_ctl_args args = {
+                .cmd = b ? BTRFS_QUOTA_CTL_ENABLE : BTRFS_QUOTA_CTL_DISABLE,
+        };
+
+        assert(fd >= 0);
+
+        if (ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args) < 0)
+                return -errno;
+
+        return 0;
+}
+
+int btrfs_quota_enable(const char *path, bool b) {
+        _cleanup_close_ int fd = -1;
+
+        fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+        if (fd < 0)
+                return -errno;
+
+        return btrfs_quota_enable_fd(fd, b);
+}
index 1b9c142e5cb27b750bc1c8410c979dd5ff34799b..93c3f13ed54f78056a68fff6743de5e89b0ff72c 100644 (file)
@@ -64,3 +64,6 @@ int btrfs_get_block_device(const char *path, dev_t *dev);
 
 int btrfs_defrag_fd(int fd);
 int btrfs_defrag(const char *p);
 
 int btrfs_defrag_fd(int fd);
 int btrfs_defrag(const char *p);
+
+int btrfs_quota_enable_fd(int fd, bool b);
+int btrfs_quota_enable(const char *path, bool b);