From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Su Yue <suy.fnst@cn.fujitsu.com>
Subject: [PATCH 06/13] btrfs-progs: lowmem: rename delete_extent_tree_item() to delete_item()
Date: Tue, 18 Dec 2018 18:46:39 +0800 [thread overview]
Message-ID: <20181218104646.29599-7-wqu@suse.com> (raw)
In-Reply-To: <20181218104646.29599-1-wqu@suse.com>
From: Su Yue <suy.fnst@cn.fujitsu.com>
The function can delete items in trees besides extent tree.
Rename and move it for further use.
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[Update comment, solve merge conflicts]
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/mode-lowmem.c | 102 +++++++++++++++++++++++---------------------
1 file changed, 53 insertions(+), 49 deletions(-)
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 20663617d242..c6255334fc07 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -543,6 +543,54 @@ static int end_avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
return ret;
}
+/*
+ * Delete the item @path point to. A wrapper of btrfs_del_item().
+ *
+ * If deleted successfully, @path will point to the previous item of the
+ * deleted item.
+ */
+static int delete_item(struct btrfs_root *root, struct btrfs_path *path)
+{
+ struct btrfs_key key;
+ struct btrfs_trans_handle *trans;
+ int ret = 0;
+
+ ret = avoid_extents_overwrite(root->fs_info);
+ if (ret)
+ return ret;
+ trans = btrfs_start_transaction(root, 1);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ error("fail to start transaction %s", strerror(-ret));
+ goto out;
+ }
+ btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+ btrfs_release_path(path);
+ ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+ if (ret) {
+ ret = -ENOENT;
+ goto out;
+ }
+
+ ret = btrfs_del_item(trans, root, path);
+ if (ret)
+ goto out;
+
+ if (path->slots[0] == 0)
+ btrfs_prev_leaf(root, path);
+ else
+ path->slots[0]--;
+out:
+ btrfs_commit_transaction(trans, root);
+ if (ret)
+ error("failed to delete root %llu item[%llu, %u, %llu]",
+ root->objectid, key.objectid, key.type, key.offset);
+ else
+ printf("Deleted root %llu item[%llu, %u, %llu]\n",
+ root->objectid, key.objectid, key.type, key.offset);
+ return ret;
+}
+
/*
* Wrapper function for btrfs_fix_block_accounting().
*
@@ -4432,50 +4480,6 @@ static int repair_chunk_item(struct btrfs_root *chunk_root,
return err;
}
-static int delete_extent_tree_item(struct btrfs_root *root,
- struct btrfs_path *path)
-{
- struct btrfs_key key;
- struct btrfs_trans_handle *trans;
- int ret = 0;
-
- ret = avoid_extents_overwrite(root->fs_info);
- if (ret)
- return ret;
- trans = btrfs_start_transaction(root, 1);
- if (IS_ERR(trans)) {
- ret = PTR_ERR(trans);
- errno = -ret;
- error("fail to start transaction: %m");
- goto out;
- }
- btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
- btrfs_release_path(path);
- ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
- if (ret) {
- ret = -ENOENT;
- goto out;
- }
-
- ret = btrfs_del_item(trans, root, path);
- if (ret)
- goto out;
-
- if (path->slots[0] == 0)
- btrfs_prev_leaf(root, path);
- else
- path->slots[0]--;
-out:
- btrfs_commit_transaction(trans, root);
- if (ret)
- error("failed to delete root %llu item[%llu, %u, %llu]",
- root->objectid, key.objectid, key.type, key.offset);
- else
- printf("Deleted root %llu item[%llu, %u, %llu]\n",
- root->objectid, key.objectid, key.type, key.offset);
- return ret;
-}
-
/*
* Main entry function to check known items and update related accounting info
*/
@@ -4517,7 +4521,7 @@ again:
ret = check_block_group_item(fs_info, eb, slot);
if (repair &&
ret & REFERENCER_MISSING)
- ret = delete_extent_tree_item(root, path);
+ ret = delete_item(root, path);
err |= ret;
break;
case BTRFS_DEV_ITEM_KEY:
@@ -4548,7 +4552,7 @@ again:
key.objectid, -1);
if (repair &&
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
- ret = delete_extent_tree_item(root, path);
+ ret = delete_item(root, path);
err |= ret;
break;
case BTRFS_EXTENT_DATA_REF_KEY:
@@ -4561,7 +4565,7 @@ again:
btrfs_extent_data_ref_count(eb, dref));
if (repair &&
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
- ret = delete_extent_tree_item(root, path);
+ ret = delete_item(root, path);
err |= ret;
break;
case BTRFS_SHARED_BLOCK_REF_KEY:
@@ -4569,7 +4573,7 @@ again:
key.objectid, -1);
if (repair &&
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
- ret = delete_extent_tree_item(root, path);
+ ret = delete_item(root, path);
err |= ret;
break;
case BTRFS_SHARED_DATA_REF_KEY:
@@ -4577,7 +4581,7 @@ again:
key.objectid);
if (repair &&
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
- ret = delete_extent_tree_item(root, path);
+ ret = delete_item(root, path);
err |= ret;
break;
default:
--
2.20.0
next prev parent reply other threads:[~2018-12-18 10:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-18 10:46 [PATCH 00/13] btrfs-progs: check: Fix Qu Wenruo
2018-12-18 10:46 ` [PATCH 01/13] btrfs-progs: lowmem: fix false alert about the existence of gaps in the check_file_extent Qu Wenruo
2018-12-18 10:46 ` [PATCH 02/13] btrfs-progs: lowmem: add argument path to punch_extent_hole() Qu Wenruo
2018-12-18 10:46 ` [PATCH 03/13] btrfs-progs: lowmem: move nbytes check before isize check Qu Wenruo
2018-12-18 10:46 ` [PATCH 04/13] btrfs-progs: lowmem: fix false alert if extent item has been repaired Qu Wenruo
2018-12-18 10:46 ` [PATCH 05/13] btrfs-progs: lowmem: check unaligned disk_bytenr for extent_data Qu Wenruo
2018-12-18 10:46 ` Qu Wenruo [this message]
2018-12-18 10:46 ` [PATCH 07/13] btrfs-progs: lowmem: delete unaligned bytes extent data under repair Qu Wenruo
2018-12-18 10:46 ` [PATCH 08/13] btrfs-progs: Revert "btrfs-progs: Add repair and report function for orphan file extent." Qu Wenruo
2018-12-18 10:46 ` [PATCH 09/13] btrfs-progs: Revert "btrfs-progs: Record orphan data extent ref to corresponding root." Qu Wenruo
2018-12-18 10:46 ` [PATCH 10/13] btrfs-progs: check: fix wrong @offset used in find_possible_backrefs() Qu Wenruo
2018-12-18 10:46 ` [PATCH 11/13] btrfs-progs: check: Delete file extent item with unaligned disk bytenr Qu Wenruo
2018-12-18 10:46 ` [PATCH 12/13] btrfs-progs: tests: add case for inode lose one file extent Qu Wenruo
2018-12-18 10:46 ` [PATCH 13/13] btrfs-progs: fsck-test: enable lowmem repair for case 001 Qu Wenruo
2018-12-18 11:51 ` [PATCH 00/13] btrfs-progs: check: Fix Su Yue
-- strict thread matches above, loose matches on Subject: below --
2018-10-23 9:41 [PATCH 00/13] btrfs-progs: fixes of file extent in original and lowmem check Su Yue
2018-10-23 9:41 ` [PATCH 06/13] btrfs-progs: lowmem: rename delete_extent_tree_item() to delete_item() Su Yue
2018-10-24 0:15 ` Qu Wenruo
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=20181218104646.29599-7-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=suy.fnst@cn.fujitsu.com \
/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).