From 6500965277e92858e03c405c0fec74124fec84dd Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Fri, 21 Sep 2012 00:54:08 -0600 Subject: [PATCH] Btrfs-progs: btrfs subvolume delete could delete subvolumes With this user will be able to provide more than one subvolume to delete. eg: btrfs subvolume delete Signed-off-by: Anand Jain Signed-off-by: Chris Mason --- cmds-subvolume.c | 36 ++++++++++++++++++++++++------------ man/btrfs.8.in | 4 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 58e89830..ac39f7bf 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -187,31 +187,34 @@ int test_issubvolume(char *path) } static const char * const cmd_subvol_delete_usage[] = { - "btrfs subvolume delete ", - "Delete a subvolume", + "btrfs subvolume delete [...]", + "Delete subvolume(s)", NULL }; static int cmd_subvol_delete(int argc, char **argv) { - int res, fd, len, e; + int res, fd, len, e, cnt = 1, ret = 0; struct btrfs_ioctl_vol_args args; char *dname, *vname, *cpath; char *path; - if (check_argc_exact(argc, 2)) + if (argc < 2) usage(cmd_subvol_delete_usage); - path = argv[1]; +again: + path = argv[cnt]; res = test_issubvolume(path); if(res<0){ fprintf(stderr, "ERROR: error accessing '%s'\n", path); - return 12; + ret = 12; + goto out; } if(!res){ fprintf(stderr, "ERROR: '%s' is not a subvolume\n", path); - return 13; + ret = 13; + goto out; } cpath = realpath(path, 0); @@ -225,21 +228,24 @@ static int cmd_subvol_delete(int argc, char **argv) strchr(vname, '/') ){ fprintf(stderr, "ERROR: incorrect subvolume name ('%s')\n", vname); - return 14; + ret = 14; + goto out; } len = strlen(vname); if (len == 0 || len >= BTRFS_VOL_NAME_MAX) { fprintf(stderr, "ERROR: snapshot name too long ('%s)\n", vname); - return 14; + ret = 14; + goto out; } fd = open_file_or_dir(dname); if (fd < 0) { close(fd); fprintf(stderr, "ERROR: can't access to '%s'\n", dname); - return 12; + ret = 12; + goto out; } printf("Delete subvolume '%s/%s'\n", dname, vname); @@ -253,10 +259,16 @@ static int cmd_subvol_delete(int argc, char **argv) if(res < 0 ){ fprintf( stderr, "ERROR: cannot delete '%s/%s' - %s\n", dname, vname, strerror(e)); - return 11; + ret = 11; + goto out; } - return 0; +out: + cnt++; + if (cnt < argc) + goto again; + + return ret; } static const char * const cmd_subvol_list_usage[] = { diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 6d6c70af..a8b4e9dc 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -7,7 +7,7 @@ btrfs \- control a btrfs filesystem .SH SYNOPSIS \fBbtrfs\fP \fBsubvolume snapshot\fP\fI [-r] [/]\fP .PP -\fBbtrfs\fP \fBsubvolume delete\fP\fI \fP +\fBbtrfs\fP \fBsubvolume delete\fP\fI [...]\fP .PP \fBbtrfs\fP \fBsubvolume create\fP\fI [/]\fP .PP @@ -98,7 +98,7 @@ subvolume, \fBbtrfs\fR returns an error. If \fI-r\fR is given, the snapshot will be readonly. .TP -\fBsubvolume delete\fR\fI \fR +\fBsubvolume delete\fR\fI [...]\fR Delete the subvolume \fI\fR. If \fI\fR is not a subvolume, \fBbtrfs\fR returns an error. .TP