From: jeffm@suse.com
To: linux-btrfs@vger.kernel.org
Cc: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 04/18] btrfs-progs: btrfs-list: add rb_entry helpers for root_info
Date: Wed, 16 May 2018 17:38:37 -0400 [thread overview]
Message-ID: <20180516213851.10196-5-jeffm@suse.com> (raw)
In-Reply-To: <20180516213851.10196-1-jeffm@suse.com>
From: Jeff Mahoney <jeffm@suse.com>
We use rb_entry all over the place for the root_info pointers. Add
a helper to make the code more readable.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
btrfs-list.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/btrfs-list.c b/btrfs-list.c
index e01c5899..90c98be1 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -44,6 +44,16 @@ struct root_lookup {
struct rb_root root;
};
+static inline struct root_info *to_root_info(struct rb_node *node)
+{
+ return rb_entry(node, struct root_info, rb_node);
+}
+
+static inline struct root_info *to_root_info_sorted(struct rb_node *node)
+{
+ return rb_entry(node, struct root_info, sort_node);
+}
+
static struct {
char *name;
char *column_name;
@@ -309,7 +319,7 @@ static int sort_tree_insert(struct root_lookup *sort_tree,
while (*p) {
parent = *p;
- curr = rb_entry(parent, struct root_info, sort_node);
+ curr = to_root_info_sorted(parent);
ret = sort_comp(ins, curr, comp_set);
if (ret < 0)
@@ -340,7 +350,7 @@ static int root_tree_insert(struct root_lookup *root_tree,
while(*p) {
parent = *p;
- curr = rb_entry(parent, struct root_info, rb_node);
+ curr = to_root_info(parent);
ret = comp_entry_with_rootid(ins, curr, 0);
if (ret < 0)
@@ -371,7 +381,7 @@ static struct root_info *root_tree_search(struct root_lookup *root_tree,
tmp.root_id = root_id;
while(n) {
- entry = rb_entry(n, struct root_info, rb_node);
+ entry = to_root_info(n);
ret = comp_entry_with_rootid(&tmp, entry, 0);
if (ret < 0)
@@ -528,7 +538,7 @@ static void free_root_info(struct rb_node *node)
{
struct root_info *ri;
- ri = rb_entry(node, struct root_info, rb_node);
+ ri = to_root_info(node);
free(ri->name);
free(ri->path);
free(ri->full_path);
@@ -1268,7 +1278,7 @@ static void filter_and_sort_subvol(struct root_lookup *all_subvols,
n = rb_last(&all_subvols->root);
while (n) {
- entry = rb_entry(n, struct root_info, rb_node);
+ entry = to_root_info(n);
ret = resolve_root(all_subvols, entry, top_id);
if (ret == -ENOENT) {
@@ -1300,7 +1310,7 @@ static int list_subvol_fill_paths(int fd, struct root_lookup *root_lookup)
while (n) {
struct root_info *entry;
int ret;
- entry = rb_entry(n, struct root_info, rb_node);
+ entry = to_root_info(n);
ret = lookup_ino_path(fd, entry);
if (ret && ret != -ENOENT)
return ret;
@@ -1467,7 +1477,7 @@ static void print_all_subvol_info(struct root_lookup *sorted_tree,
n = rb_first(&sorted_tree->root);
while (n) {
- entry = rb_entry(n, struct root_info, sort_node);
+ entry = to_root_info_sorted(n);
/* The toplevel subvolume is not listed by default */
if (entry->root_id == BTRFS_FS_TREE_OBJECTID)
@@ -1558,7 +1568,7 @@ int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri)
return ret;
rbn = rb_first(&rl.root);
- ri = rb_entry(rbn, struct root_info, rb_node);
+ ri = to_root_info(rbn);
if (ri->root_id != BTRFS_FS_TREE_OBJECTID)
return -ENOENT;
@@ -1590,7 +1600,7 @@ int btrfs_get_subvol(int fd, struct root_info *the_ri)
rbn = rb_first(&rl.root);
while(rbn) {
- ri = rb_entry(rbn, struct root_info, rb_node);
+ ri = to_root_info(rbn);
rr = resolve_root(&rl, ri, root_id);
if (rr == -ENOENT) {
ret = -ENOENT;
@@ -1814,7 +1824,7 @@ char *btrfs_list_path_for_root(int fd, u64 root)
while (n) {
struct root_info *entry;
- entry = rb_entry(n, struct root_info, rb_node);
+ entry = to_root_info(n);
ret = resolve_root(&root_lookup, entry, top_id);
if (ret == -ENOENT && entry->root_id == root) {
ret_path = NULL;
--
2.15.1
next prev parent reply other threads:[~2018-05-16 21:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-16 21:38 [PATCH v3 00/18] btrfs-progs: qgroups-usability jeffm
2018-05-16 21:38 ` [PATCH 01/18] btrfs-progs: quota: Add -W option to rescan to wait without starting rescan jeffm
2018-05-16 21:38 ` [PATCH 02/18] btrfs-progs: qgroups: fix misleading index check jeffm
2018-05-16 21:38 ` [PATCH 03/18] btrfs-progs: constify pathnames passed as arguments jeffm
2018-05-16 21:38 ` jeffm [this message]
2018-05-16 21:38 ` [PATCH 05/18] btrfs-progs: qgroups: add pathname to show output jeffm
2018-05-18 4:55 ` Misono Tomohiro
2018-05-16 21:38 ` [PATCH 06/18] btrfs-progs: qgroups: introduce and use info and limit structures jeffm
2018-05-16 21:38 ` [PATCH 07/18] btrfs-progs: qgroups: introduce btrfs_qgroup_query jeffm
2018-05-16 21:38 ` [PATCH 08/18] btrfs-progs: subvolume: add quota info to btrfs sub show jeffm
2018-05-16 21:38 ` [PATCH 09/18] btrfs-progs: help: convert ints used as bools to bool jeffm
2018-05-16 21:38 ` [PATCH 10/18] btrfs-progs: reorder placement of help declarations for send/receive jeffm
2018-05-16 21:38 ` [PATCH 11/18] btrfs-progs: filesystem balance: split out special handling jeffm
2018-05-16 21:38 ` [PATCH 12/18] btrfs-progs: use cmd_struct as command entry point jeffm
2018-05-16 21:38 ` [PATCH 13/18] btrfs-progs: pass cmd_struct to command callback function jeffm
2018-05-16 21:38 ` [PATCH 14/18] btrfs-progs: pass cmd_struct to clean_args_no_options{,_relaxed} jeffm
2018-05-16 21:38 ` [PATCH 15/18] btrfs-progs: pass cmd_struct to usage() jeffm
2018-05-16 21:38 ` [PATCH 16/18] btrfs-progs: add support for output formats jeffm
2018-05-16 21:38 ` [PATCH 17/18] btrfs-progs: handle command groups directly for common case jeffm
2018-05-16 21:38 ` [PATCH 18/18] btrfs-progs: qgroups: don't print dead qgroups jeffm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180516213851.10196-5-jeffm@suse.com \
--to=jeffm@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).