aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-04-08 18:15:57 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-09 19:36:30 +0200
commit76a9be2e72e6634f4ca4b68dd2a9e00e6f48f26a (patch)
tree87c388073c7389bc4bf634cad50cc0f57a00c1bb /cmds-subvolume.c
parentc9f885ec8963be55983caeeb63ff6cd71ded3f52 (diff)
downloadbtrfs-progs-76a9be2e72e6634f4ca4b68dd2a9e00e6f48f26a.tar.gz
btrfs-progs-76a9be2e72e6634f4ca4b68dd2a9e00e6f48f26a.tar.xz
btrfs-progs-76a9be2e72e6634f4ca4b68dd2a9e00e6f48f26a.zip
btrfs-progs: add helper to wait for subvolume cleaning
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c110
1 files changed, 61 insertions, 49 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 5591e45..dfc3f1f 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -36,6 +36,66 @@
#include "btrfs-list.h"
#include "utils.h"
+static int is_subvolume_cleaned(int fd, u64 subvolid)
+{
+ int ret;
+ struct btrfs_ioctl_search_args args;
+ struct btrfs_ioctl_search_key *sk = &args.key;
+
+ sk->tree_id = BTRFS_ROOT_TREE_OBJECTID;
+ sk->min_objectid = subvolid;
+ sk->max_objectid = subvolid;
+ sk->min_type = BTRFS_ROOT_ITEM_KEY;
+ sk->max_type = BTRFS_ROOT_ITEM_KEY;
+ sk->min_offset = 0;
+ sk->max_offset = (u64)-1;
+ sk->min_transid = 0;
+ sk->max_transid = (u64)-1;
+ sk->nr_items = 1;
+
+ ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
+ if (ret < 0)
+ return -errno;
+
+ if (sk->nr_items == 0)
+ return 1;
+
+ return 0;
+}
+
+static int wait_for_subvolume_cleaning(int fd, int count, u64 *ids,
+ int sleep_interval)
+{
+ int ret = 0;
+ int remaining;
+ int i;
+
+ remaining = count;
+ while (1) {
+ for (i = 0; i < count; i++) {
+ if (!ids[i])
+ continue;
+ ret = is_subvolume_cleaned(fd, ids[i]);
+ if (ret < 0) {
+ fprintf(stderr,
+ "ERROR: can't perform the search - %s\n",
+ strerror(-ret));
+ goto out;
+ }
+ if (ret) {
+ printf("Subvolume id %llu is gone\n", ids[i]);
+ ids[i] = 0;
+ remaining--;
+ }
+ }
+ if (!remaining)
+ break;
+ sleep(sleep_interval);
+ }
+out:
+ return ret;
+}
+
static const char * const subvolume_cmd_group_usage[] = {
"btrfs subvolume <command> <args>",
NULL
@@ -1036,33 +1096,6 @@ static const char * const cmd_subvol_sync_usage[] = {
NULL
};
-static int is_subvolume_cleaned(int fd, u64 subvolid)
-{
- int ret;
- struct btrfs_ioctl_search_args args;
- struct btrfs_ioctl_search_key *sk = &args.key;
-
- sk->tree_id = BTRFS_ROOT_TREE_OBJECTID;
- sk->min_objectid = subvolid;
- sk->max_objectid = subvolid;
- sk->min_type = BTRFS_ROOT_ITEM_KEY;
- sk->max_type = BTRFS_ROOT_ITEM_KEY;
- sk->min_offset = 0;
- sk->max_offset = (u64)-1;
- sk->min_transid = 0;
- sk->max_transid = (u64)-1;
- sk->nr_items = 1;
-
- ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
- if (ret < 0)
- return -errno;
-
- if (sk->nr_items == 0)
- return 1;
-
- return 0;
-}
-
#if 0
/*
* If we're looking for any dead subvolume, take a shortcut and look
@@ -1212,7 +1245,6 @@ static int cmd_subvol_sync(int argc, char **argv)
DIR *dirstream = NULL;
u64 *ids = NULL;
int id_count;
- int remaining;
int sleep_interval = 1;
optind = 1;
@@ -1303,27 +1335,7 @@ static int cmd_subvol_sync(int argc, char **argv)
}
}
- remaining = id_count;
- while (1) {
- for (i = 0; i < id_count; i++) {
- if (!ids[i])
- continue;
- ret = is_subvolume_cleaned(fd, ids[i]);
- if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search - %s\n",
- strerror(-ret));
- goto out;
- }
- if (ret) {
- printf("Subvolume id %llu is gone\n", ids[i]);
- ids[i] = 0;
- remaining--;
- }
- }
- if (!remaining)
- break;
- sleep(sleep_interval);
- }
+ ret = wait_for_subvolume_cleaning(fd, id_count, ids, sleep_interval);
out:
free(ids);