btrfs: support recursively removing btrfs snapshots

This commit is contained in:
Lennart Poettering
2015-04-06 11:28:16 +02:00
parent 41d1ed059b
commit d9e2daaf3d
17 changed files with 239 additions and 70 deletions
+42 -6
View File
@@ -27,8 +27,7 @@
#include "btrfs-util.h"
int main(int argc, char *argv[]) {
int r;
int fd;
int r, fd;
fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
@@ -81,15 +80,15 @@ int main(int argc, char *argv[]) {
if (r < 0)
log_error_errno(r, "Failed to make snapshot: %m");
r = btrfs_subvol_remove("/xxxtest");
r = btrfs_subvol_remove("/xxxtest", false);
if (r < 0)
log_error_errno(r, "Failed to remove subvolume: %m");
r = btrfs_subvol_remove("/xxxtest2");
r = btrfs_subvol_remove("/xxxtest2", false);
if (r < 0)
log_error_errno(r, "Failed to remove subvolume: %m");
r = btrfs_subvol_remove("/xxxtest3");
r = btrfs_subvol_remove("/xxxtest3", false);
if (r < 0)
log_error_errno(r, "Failed to remove subvolume: %m");
@@ -97,9 +96,46 @@ int main(int argc, char *argv[]) {
if (r < 0)
log_error_errno(r, "Failed to make snapshot: %m");
r = btrfs_subvol_remove("/etc2");
r = btrfs_subvol_remove("/etc2", false);
if (r < 0)
log_error_errno(r, "Failed to remove subvolume: %m");
r = btrfs_subvol_make("/xxxrectest");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
r = btrfs_subvol_make("/xxxrectest/xxxrectest2");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
r = btrfs_subvol_make("/xxxrectest/xxxrectest3");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
r = btrfs_subvol_make("/xxxrectest/xxxrectest3/sub");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
if (mkdir("/xxxrectest/dir", 0755) < 0)
log_error_errno(errno, "Failed to make directory: %m");
r = btrfs_subvol_make("/xxxrectest/dir/xxxrectest4");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
if (mkdir("/xxxrectest/dir/xxxrectest4/dir", 0755) < 0)
log_error_errno(errno, "Failed to make directory: %m");
r = btrfs_subvol_make("/xxxrectest/dir/xxxrectest4/dir/xxxrectest5");
if (r < 0)
log_error_errno(r, "Failed to make subvolume: %m");
if (mkdir("/xxxrectest/mnt", 0755) < 0)
log_error_errno(errno, "Failed to make directory: %m");
r = btrfs_subvol_remove("/xxxrectest", true);
if (r < 0)
log_error_errno(r, "Failed to recursively remove subvolume: %m");
return 0;
}
-1
View File
@@ -19,7 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "hostname-setup.h"
#include "util.h"