path: root/btrfs-list.h
diff options
authorMiao Xie <>2012-09-18 14:51:49 +0800
committerroot <root@localhost.localdomain>2012-10-04 16:26:32 -0400
commit162df1e30c7c0492ae9fb551d74452e643f5fea2 (patch)
treee57d3bb0c42efd150124a37d8adbe7632f0c649b /btrfs-list.h
parent7cb1cf754229062ea412aa651a0f750ce42c113d (diff)
Btrfs-progs: restructure list_subvolumes
The current code of list_subvols() has very bad scalability, if we want to add new filter conditions or new sort methods, we have to modify lots of code. Beside that, the most code of list_snapshots() is similar to list_subvols(), So I restructure list_subvols(), and split the subvolume filter function, the subvolume sort function and the output function from list_subvols(). In order to implement it, we defined some importtant structures: struct btrfs_list_filter { btrfs_list_filter_func filter_func; void *data; }; struct btrfs_list_comparer { btrfs_list_comp_func comp_func; int is_descending; }; struct { char *name; char *column_name; int need_print; } btrfs_list_columns[]; If we want to add a new filter condition, we can choose a suitable filter function, or implement a new filter function[1], and add it into a set of the filters, and then pass the filter set into list_subvols(). We also can mix several filters (just add those filters into the set, and pass the set into list_subvols()) if the users specify two or more filter conditions. The subvolume sort function is similar to the subvolume filter function. The differentiation is the order of comparers in the array which is passed into list_subvols() show us the priority of the sort methods. The output function is different with the above two functions, we define a array to manage all the columns that can be outputed, and use a member variant (->need_print) to control the output of the relative column. Some columns are outputed by default. But we can change it according to the requirement of the users. After appling this patch, we needn't implement a independent list_snapshots() function, just pass a filter function which is used to identify the snapshot into list_subvols(). [1]: If we implement new filter functions or compare functions, we must add them into the array all_filter_funcs or the array all_comp_funcs, and modify the relative enum variants(btrfs_list_filter_enum, btrfs_list_comp_enum). Signed-off-by: Miao Xie <>
Diffstat (limited to 'btrfs-list.h')
1 files changed, 71 insertions, 4 deletions
diff --git a/btrfs-list.h b/btrfs-list.h
index b4a7f30f..11f12156 100644
--- a/btrfs-list.h
+++ b/btrfs-list.h
@@ -16,7 +16,74 @@
* Boston, MA 021110-1307, USA.
-int list_subvols(int fd, int print_parent, int get_default, int print_uuid);
-int list_snapshots(int fd, int print_parent, int order, int print_uuid);
-int find_updated_files(int fd, u64 root_id, u64 oldest_gen);
-char *path_for_root(int fd, u64 root);
+#include "kerncompat.h"
+struct root_info;
+typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
+typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
+ int);
+struct btrfs_list_filter {
+ btrfs_list_filter_func filter_func;
+ u64 data;
+struct btrfs_list_comparer {
+ btrfs_list_comp_func comp_func;
+ int is_descending;
+struct btrfs_list_filter_set {
+ int total;
+ int nfilters;
+ struct btrfs_list_filter filters[0];
+struct btrfs_list_comparer_set {
+ int total;
+ int ncomps;
+ struct btrfs_list_comparer comps[0];
+enum btrfs_list_column_enum {
+enum btrfs_list_filter_enum {
+enum btrfs_list_comp_enum {
+void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
+struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
+void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set);
+int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
+ enum btrfs_list_filter_enum filter, u64 data);
+struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
+void btrfs_list_free_comparer_set(struct btrfs_list_comparer_set *comp_set);
+int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
+ enum btrfs_list_comp_enum comparer,
+ int is_descending);
+int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
+ struct btrfs_list_comparer_set *comp_set);
+int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
+int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
+char *btrfs_list_path_for_root(int fd, u64 root);