]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
import: when downloading images, create a subtree quota group for them
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Oct 2015 17:45:44 +0000 (19:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Oct 2015 23:59:25 +0000 (01:59 +0200)
src/import/import-tar.c
src/import/pull-dkr.c
src/import/pull-tar.c
src/shared/import-util.c
src/shared/import-util.h

index d2bfb3023841e755c217fe8318ce6c8cd19a7548..5c288d438efb837499ae20b26a7b361422e864b7 100644 (file)
@@ -235,6 +235,8 @@ static int tar_import_fork_tar(TarImport *i) {
                         return log_error_errno(errno, "Failed to create directory %s: %m", i->temp_path);
         } else if (r < 0)
                 return log_error_errno(errno, "Failed to create subvolume %s: %m", i->temp_path);
+        else
+                (void) import_assign_pool_quota_and_warn(i->temp_path);
 
         i->tar_fd = import_fork_tar_x(i->temp_path, &i->tar_pid);
         if (i->tar_fd < 0)
index b77f3e47f12802f1757a2c25269a11f3f074681c..84211d282b616bc76bfcae924bddd317952a21a9 100644 (file)
@@ -543,6 +543,8 @@ static int dkr_pull_job_on_open_disk(PullJob *j) {
         if (r < 0)
                 return log_error_errno(r, "Failed to make btrfs subvolume %s: %m", i->temp_path);
 
+        (void) import_assign_pool_quota_and_warn(i->temp_path);
+
         j->disk_fd = import_fork_tar_x(i->temp_path, &i->tar_pid);
         if (j->disk_fd < 0)
                 return j->disk_fd;
index 563765d83d1b3cc25f7a521998e9e2efba55a09a..b81838217224820b224c4ff187106c4e62179ed9 100644 (file)
@@ -410,6 +410,8 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) {
                         return log_error_errno(errno, "Failed to create directory %s: %m", i->temp_path);
         } else if (r < 0)
                 return log_error_errno(errno, "Failed to create subvolume %s: %m", i->temp_path);
+        else
+                (void) import_assign_pool_quota_and_warn(i->temp_path);
 
         j->disk_fd = import_fork_tar_x(i->temp_path, &i->tar_pid);
         if (j->disk_fd < 0)
index 001a8a37e81667746af704a7d38ff2c44300e04a..56388d5dd60b699893286d03eaecbcfd8f30a25d 100644 (file)
@@ -19,6 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "btrfs-util.h"
 #include "util.h"
 #include "import-util.h"
 
@@ -201,3 +202,29 @@ bool dkr_id_is_valid(const char *id) {
 
         return true;
 }
+
+int import_assign_pool_quota_and_warn(const char *path) {
+        int r;
+
+        r = btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
+        if (r == -ENOTTY)  {
+                log_debug_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines, as directory is not on btrfs or not a subvolume. Ignoring.");
+                return 0;
+        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
+        if (r > 0)
+                log_info("Set up default quota hierarchy for /var/lib/machines.");
+
+        r = btrfs_subvol_auto_qgroup(path, 0, true);
+        if (r == -ENOTTY) {
+                log_debug_errno(r, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path);
+                return 0;
+        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to set up default quota hierarchy for %s: %m", path);
+        if (r > 0)
+                log_info("Set up default quota hierarchy for %s.", path);
+
+        return 0;
+}
index 7bf7d4ca406e4e8e523b6e976e3cbf037c713816..9120a5119f47739b42586670b0217a054455c0f4 100644 (file)
@@ -47,3 +47,5 @@ bool dkr_id_is_valid(const char *id);
 bool dkr_ref_is_valid(const char *ref);
 bool dkr_digest_is_valid(const char *digest);
 #define dkr_tag_is_valid(tag) filename_is_valid(tag)
+
+int import_assign_pool_quota_and_warn(const char *path);