linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: damenly.su@gmail.com
To: linux-btrfs@vger.kernel.org
Cc: suy.fnst@cn.fujitsu.com
Subject: [PATCH v2 01/13] btrfs-progs: lowmem: add argument path to punch_extent_hole()
Date: Sun,  2 Dec 2018 14:34:24 +0000	[thread overview]
Message-ID: <20181202143424.14892-1-suy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20181023094147.7906-2-suy.fnst@cn.fujitsu.com>

From: Su Yue <suy.fnst@cn.fujitsu.com>

Since repair will do CoW, the outer path may be invalid,
add an argument path to punch_extent_hole().
When punch_extent_hole() returns, path will still point to the item
before calling punch_extent_hole();

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
Changelog:
v2:
  Remove varaiable @ret2.
  Call btrfs_abort_transaction() if failed.
  
---
 check/mode-lowmem.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 1bce44f5658a..3dce4d3b5fc1 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -1710,28 +1710,37 @@ out:
 /*
  * Wrapper function of btrfs_punch_hole.
  *
+ * @path:	will point to the item while calling the function.
+ *
  * Returns 0 means success.
  * Returns not 0 means error.
  */
-static int punch_extent_hole(struct btrfs_root *root, u64 ino, u64 start,
-			     u64 len)
+static int punch_extent_hole(struct btrfs_root *root, struct btrfs_path *path,
+			     u64 ino, u64 start, u64 len)
 {
 	struct btrfs_trans_handle *trans;
-	int ret = 0;
+	struct btrfs_key key;
+	int ret;
 
+	btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
 	trans = btrfs_start_transaction(root, 1);
 	if (IS_ERR(trans))
 		return PTR_ERR(trans);
 
 	ret = btrfs_punch_hole(trans, root, ino, start, len);
-	if (ret)
+	if (ret) {
 		error("failed to add hole [%llu, %llu] in inode [%llu]",
 		      start, len, ino);
-	else
-		printf("Add a hole [%llu, %llu] in inode [%llu]\n", start, len,
-		       ino);
-
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
+	printf("Add a hole [%llu, %llu] in inode [%llu]\n", start, len, ino);
 	btrfs_commit_transaction(trans, root);
+
+	btrfs_release_path(path);
+	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+	if (ret > 0)
+		ret = -ENOENT;
 	return ret;
 }
 
@@ -1963,7 +1972,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
 	/* Check EXTENT_DATA hole */
 	if (!no_holes && *end != fkey.offset) {
 		if (repair)
-			ret = punch_extent_hole(root, fkey.objectid,
+			ret = punch_extent_hole(root, path, fkey.objectid,
 						*end, fkey.offset - *end);
 		if (!repair || ret) {
 			err |= FILE_EXTENT_ERROR;
@@ -2534,7 +2543,7 @@ out:
 
 		if (!nbytes && !no_holes && extent_end < isize) {
 			if (repair)
-				ret = punch_extent_hole(root, inode_id,
+				ret = punch_extent_hole(root, path, inode_id,
 						extent_end, isize - extent_end);
 			if (!repair || ret) {
 				err |= NBYTES_ERROR;
-- 
2.19.1


  parent reply	other threads:[~2018-12-02  6:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 01/13] btrfs-progs: lowmem: add argument path to punch_extent_hole() Su Yue
2018-10-23 10:04   ` Qu Wenruo
2018-10-24  1:18     ` Su Yue
2018-12-02 14:34   ` damenly.su [this message]
2018-10-23  9:41 ` [PATCH 02/13] btrfs-progs: lowmem: move nbytes check before isize check Su Yue
2018-10-23 10:07   ` Qu Wenruo
2018-12-02 14:38   ` [PATCH v2 " damenly.su
2018-10-23  9:41 ` [PATCH 03/13] btrfs-progs: lowmem: fix false alert if extent item has been repaired Su Yue
2018-10-23 10:30   ` Qu Wenruo
2018-10-24  1:27     ` Su Yue
2018-10-24  1:24       ` Qu Wenruo
2018-12-02 14:45   ` [PATCH v2 " damenly.su
2018-10-23  9:41 ` [PATCH 04/13] btrfs-progs: lowmem: fix false alert about the existence of gaps in the check_file_extent Su Yue
2018-10-24  0:13   ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 05/13] btrfs-progs: lowmem: check unaligned disk_bytenr for extent_data Su Yue
2018-10-24  0:13   ` Qu Wenruo
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
2018-10-23  9:41 ` [PATCH 07/13] btrfs-progs: lowmem: delete unaligned bytes extent data under repair Su Yue
2018-10-24  0:16   ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 08/13] btrfs-progs: Revert "btrfs-progs: Add repair and report function for orphan file extent." Su Yue
2018-10-24  0:28   ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 09/13] btrfs-progs: Revert "btrfs-progs: Record orphan data extent ref to corresponding root." Su Yue
2018-10-24  0:29   ` Qu Wenruo
2018-11-07  9:09     ` Su Yanjun <suyj.fnst@cn.fujitsu.com>
2018-11-07  9:14       ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 10/13] btrfs-progs: check: fix bug in find_possible_backrefs Su Yue
2018-10-24  0:34   ` Qu Wenruo
2018-11-07  6:28     ` Su Yanjun <suyj.fnst@cn.fujitsu.com>
2018-11-07  6:40       ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 11/13] btrfs-progs: check: Delete file extent item with unaligned extent backref Su Yue
2018-10-24  0:45   ` Qu Wenruo
2018-11-07  6:21     ` Su Yanjun <suyj.fnst@cn.fujitsu.com>
2018-11-07  6:38       ` Qu Wenruo
2018-11-07  7:04         ` Su Yanjun <suyj.fnst@cn.fujitsu.com>
2018-11-07  7:13           ` Qu Wenruo
2018-10-23  9:41 ` [PATCH 12/13] btrfs-progs: tests: add case for inode lose one file extent Su Yue
2018-10-23  9:41 ` [PATCH 13/13] btrfs-progs: fsck-test: enable lowmem repair for case 001 Su Yue
2018-10-23  9:45 ` [PATCH 00/13] btrfs-progs: fixes of file extent in original and lowmem check 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=20181202143424.14892-1-suy.fnst@cn.fujitsu.com \
    --to=damenly.su@gmail.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).