201
201
return (st.st_ino == 256) && S_ISDIR(st.st_mode);
204
static int wait_for_commit(int fd)
208
ret = ioctl(fd, BTRFS_IOC_START_SYNC, NULL);
211
return ioctl(fd, BTRFS_IOC_WAIT_SYNC, NULL);
204
214
static const char * const cmd_subvol_delete_usage[] = {
205
"btrfs subvolume delete <subvolume> [<subvolume>...]",
215
"btrfs subvolume delete [options] <subvolume> [<subvolume>...]",
206
216
"Delete subvolume(s)",
217
"Delete subvolumes from the filesystem. The corresponding directory",
218
"is removed instantly but the data blocks are removed later.",
219
"The deletion does not involve full commit by default due to",
220
"performance reasons (as a consequence, the subvolume may appear again",
221
"after a crash). Use one of the --commit options to wait until the",
222
"operation is safely stored on the media.",
224
"-c|--commit-after wait for transaction commit at the end of the operation",
225
"-C|--commit-each wait for transaction commit after deleting each subvolume",
210
229
static int cmd_subvol_delete(int argc, char **argv)
212
int res, fd, len, e, cnt = 1, ret = 0;
231
int res, len, e, ret = 0;
213
234
struct btrfs_ioctl_vol_args args;
214
235
char *dname, *vname, *cpath;
215
236
char *dupdname = NULL;
216
237
char *dupvname = NULL;
218
239
DIR *dirstream = NULL;
241
struct option long_options[] = {
242
{"commit-after", no_argument, NULL, 'c'}, /* sync mode 1 */
243
{"commit-each", no_argument, NULL, 'C'}, /* sync mode 2 */
251
c = getopt_long(argc, argv, "cC", long_options, NULL);
263
usage(cmd_subvol_delete_usage);
267
if (check_argc_min(argc - optind, 1))
221
268
usage(cmd_subvol_delete_usage);
270
printf("Transaction commit: %s\n",
271
!sync_mode ? "none (default)" :
272
sync_mode == 1 ? "at the end" : "after each");
224
277
path = argv[cnt];
276
329
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
279
close_file_or_dir(fd, dirstream);
282
333
fprintf( stderr, "ERROR: cannot delete '%s/%s' - %s\n",
283
334
dname, vname, strerror(e));
339
if (sync_mode == 1) {
340
res = wait_for_commit(fd);
343
"ERROR: unable to wait for commit after '%s': %s\n",
344
path, strerror(errno));
356
close_file_or_dir(fd, dirstream);
357
/* avoid double free */
363
if (sync_mode == 2 && fd != -1) {
364
res = wait_for_commit(fd);
367
"ERROR: unable to do final sync: %s\n",
372
close_file_or_dir(fd, dirstream);
612
689
fddst = open_file_or_dir(dstdir, &dirstream1);
614
fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
691
fprintf(stderr, "ERROR: can't access '%s'\n", dstdir);
618
695
fd = open_file_or_dir(subvol, &dirstream2);
620
fprintf(stderr, "ERROR: can't access to '%s'\n", dstdir);
697
fprintf(stderr, "ERROR: can't access '%s'\n", dstdir);
743
820
subvolid = argv[1];
746
objectid = (unsigned long long)strtoll(subvolid, NULL, 0);
747
if (errno == ERANGE) {
748
fprintf(stderr, "ERROR: invalid tree id (%s)\n", subvolid);
823
objectid = arg_strtou64(subvolid);
752
825
fd = open_file_or_dir(path, &dirstream);
754
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
827
fprintf(stderr, "ERROR: can't access '%s'\n", path);