From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 3/3] btrfs: Use btrfs_find_name_in_backref in backref_in_log
Date: Tue, 27 Aug 2019 14:46:30 +0300 [thread overview]
Message-ID: <20190827114630.2425-4-nborisov@suse.com> (raw)
In-Reply-To: <20190827114630.2425-1-nborisov@suse.com>
By not opencoding btrfs_find_name_in_backref most of the local variables
can be removed, this in turn alleviates stack pressure. Additionally,
backref_in_log is only used as predicate so make it return bool.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/tree-log.c | 57 +++++++++++++--------------------------------
1 file changed, 16 insertions(+), 41 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 7d45a4869bc9..070016e023b8 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -938,60 +938,35 @@ static noinline int inode_in_dir(struct btrfs_root *root,
* want to delete valid links to a file from the subvolume if that
* link is also in the log.
*/
-static noinline int backref_in_log(struct btrfs_root *log,
- struct btrfs_key *key,
- u64 ref_objectid,
- const char *name, int namelen)
+static noinline bool backref_in_log(struct btrfs_root *log,
+ struct btrfs_key *key,
+ u64 ref_objectid,
+ const char *name, int namelen)
{
struct btrfs_path *path;
- struct btrfs_inode_ref *ref;
- unsigned long ptr;
- unsigned long ptr_end;
- unsigned long name_ptr;
- int found_name_len;
- int item_size;
+ bool found = false;
int ret;
- int match = 0;
path = btrfs_alloc_path();
if (!path)
- return -ENOMEM;
+ return false;
ret = btrfs_search_slot(NULL, log, key, path, 0, 0);
if (ret != 0)
goto out;
- ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
-
- if (key->type == BTRFS_INODE_EXTREF_KEY) {
- if (btrfs_find_name_in_ext_backref(path->nodes[0],
- path->slots[0],
- ref_objectid,
- name, namelen))
- match = 1;
-
- goto out;
- }
-
- item_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
- ptr_end = ptr + item_size;
- while (ptr < ptr_end) {
- ref = (struct btrfs_inode_ref *)ptr;
- found_name_len = btrfs_inode_ref_name_len(path->nodes[0], ref);
- if (found_name_len == namelen) {
- name_ptr = (unsigned long)(ref + 1);
- ret = memcmp_extent_buffer(path->nodes[0], name,
- name_ptr, namelen);
- if (ret == 0) {
- match = 1;
- goto out;
- }
- }
- ptr = (unsigned long)(ref + 1) + found_name_len;
- }
+ if (key->type == BTRFS_INODE_EXTREF_KEY)
+ found = !!btrfs_find_name_in_ext_backref(path->nodes[0],
+ path->slots[0],
+ ref_objectid,
+ name, namelen);
+ else
+ found = !!btrfs_find_name_in_backref(path->nodes[0],
+ path->slots[0],
+ name, namelen);
out:
btrfs_free_path(path);
- return match;
+ return found;
}
static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
--
2.17.1
next prev parent reply other threads:[~2019-08-27 11:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 11:46 [PATCH 0/3] Cleanup btrfs_find_name_in* functions Nikolay Borisov
2019-08-27 11:46 ` [PATCH 1/3] btrfs: Make btrfs_find_name_in_backref return btrfs_inode_ref struct Nikolay Borisov
2019-08-27 14:13 ` David Sterba
2019-08-27 15:45 ` David Sterba
2019-08-27 11:46 ` [PATCH 2/3] btrfs: Make btrfs_find_name_in_ext_backref return struct btrfs_inode_extref Nikolay Borisov
2019-08-27 15:53 ` David Sterba
2019-08-27 11:46 ` Nikolay Borisov [this message]
2019-08-27 16:03 ` [PATCH 3/3] btrfs: Use btrfs_find_name_in_backref in backref_in_log David Sterba
2019-08-27 16:04 ` [PATCH 0/3] Cleanup btrfs_find_name_in* functions David Sterba
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=20190827114630.2425-4-nborisov@suse.com \
--to=nborisov@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