chiark / gitweb /
btrfs: add support for recursive btrfs snapshotting
[elogind.git] / src / shared / machine-image.c
index c5808af81efe27dfb13cdf6805f9b3b3318a3d25..0b41860b5d820b5f0240c5087763da7b56fcf09b 100644 (file)
@@ -358,16 +358,18 @@ int image_remove(Image *i) {
         switch (i->type) {
 
         case IMAGE_SUBVOLUME:
-                return btrfs_subvol_remove(i->path);
+                return btrfs_subvol_remove(i->path, true);
 
         case IMAGE_DIRECTORY:
                 /* Allow deletion of read-only directories */
                 (void) chattr_path(i->path, false, FS_IMMUTABLE_FL);
-
-                /* fall through */
+                return rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
 
         case IMAGE_RAW:
-                return rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL);
+                if (unlink(i->path) < 0)
+                        return -errno;
+
+                return 0;
 
         default:
                 return -EOPNOTSUPP;
@@ -489,7 +491,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
         case IMAGE_DIRECTORY:
                 new_path = strjoina("/var/lib/machines/", new_name);
 
-                r = btrfs_subvol_snapshot(i->path, new_path, read_only, true);
+                r = btrfs_subvol_snapshot(i->path, new_path, (read_only ? BTRFS_SNAPSHOT_READ_ONLY : 0) | BTRFS_SNAPSHOT_FALLBACK_COPY | BTRFS_SNAPSHOT_RECURSIVE);
                 break;
 
         case IMAGE_RAW: