From: Nikolay Borisov <nborisov@suse.com>
To: dsterb@suse.cz
Cc: linux-btrfs@vger.kernel.org, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH v2] btrfs: Remove BUG_ON from run_delalloc_nocow
Date: Thu, 22 Aug 2019 17:24:20 +0300 [thread overview]
Message-ID: <20190822142420.1126-1-nborisov@suse.com> (raw)
In-Reply-To: <20190821155517.GB2752@twin.jikos.cz>
Correctly handle failure cases when adding an ordered extents in case
of REGULAR or PREALLOC extents.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/inode.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 161439122a29..c8fe17cd8cb6 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1314,6 +1314,8 @@ static noinline int run_delalloc_nocow(struct inode *inode,
bool check_prev = true;
const bool freespace_inode = btrfs_is_free_space_inode(BTRFS_I(inode));
u64 ino = btrfs_ino(BTRFS_I(inode));
+ bool nocow = false;
+ u64 disk_bytenr = 0;
path = btrfs_alloc_path();
if (!path) {
@@ -1333,12 +1335,12 @@ static noinline int run_delalloc_nocow(struct inode *inode,
struct extent_buffer *leaf;
u64 extent_end;
u64 extent_offset;
- u64 disk_bytenr = 0;
u64 num_bytes = 0;
u64 disk_num_bytes;
u64 ram_bytes;
int extent_type;
- bool nocow = false;
+
+ nocow = false;
ret = btrfs_lookup_file_extent(NULL, root, path, ino,
cur_offset, 0);
@@ -1572,16 +1574,25 @@ static noinline int run_delalloc_nocow(struct inode *inode,
disk_bytenr, num_bytes,
num_bytes,
BTRFS_ORDERED_PREALLOC);
+ if (ret) {
+ btrfs_drop_extent_cache(BTRFS_I(inode),
+ cur_offset,
+ cur_offset + num_bytes - 1,
+ 0);
+ goto error;
+ }
} else {
ret = btrfs_add_ordered_extent(inode, cur_offset,
disk_bytenr, num_bytes,
num_bytes,
BTRFS_ORDERED_NOCOW);
+ if (ret)
+ goto error;
}
if (nocow)
btrfs_dec_nocow_writers(fs_info, disk_bytenr);
- BUG_ON(ret); /* -ENOMEM */
+ nocow = false;
if (root->root_key.objectid ==
BTRFS_DATA_RELOC_TREE_OBJECTID)
@@ -1626,6 +1637,9 @@ static noinline int run_delalloc_nocow(struct inode *inode,
}
error:
+ if (nocow)
+ btrfs_dec_nocow_writers(fs_info, disk_bytenr);
+
if (ret && cur_offset < end)
extent_clear_unlock_delalloc(inode, cur_offset, end,
locked_page, EXTENT_LOCKED |
--
2.17.1
next prev parent reply other threads:[~2019-08-22 14:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-05 14:47 [PATCH 0/6] Refactor nocow path Nikolay Borisov
2019-08-05 14:47 ` [PATCH 1/6] btrfs: Refactor run_delalloc_nocow Nikolay Borisov
2019-08-21 7:42 ` [PATCH v2 1/2] " Nikolay Borisov
2019-08-21 15:03 ` David Sterba
2019-08-05 14:47 ` [PATCH 2/6] btrfs: Improve comments around nocow path Nikolay Borisov
2019-08-06 10:09 ` Filipe Manana
2019-08-07 8:16 ` Nikolay Borisov
2019-08-07 8:26 ` Filipe Manana
2019-08-21 7:42 ` [PATCH v2 2/2] " Nikolay Borisov
2019-08-21 15:10 ` David Sterba
2019-08-05 14:47 ` [PATCH 3/6] btrfs: Simplify run_delalloc_nocow Nikolay Borisov
2019-08-06 9:01 ` Johannes Thumshirn
2019-08-05 14:47 ` [PATCH 4/6] btrfs: Streamline code in run_delalloc_nocow in case of inline extents Nikolay Borisov
2019-08-21 15:17 ` David Sterba
2019-08-05 14:47 ` [PATCH 5/6] btrfs: Simplify extent type check Nikolay Borisov
2019-08-06 10:14 ` Filipe Manana
2019-08-21 15:40 ` David Sterba
2019-08-21 23:47 ` Qu Wenruo
2019-08-22 5:58 ` Nikolay Borisov
2019-08-22 14:25 ` [PATCH] btrfs: Streamline code in run_delalloc_nocow Nikolay Borisov
2019-08-23 17:27 ` David Sterba
2019-08-05 14:47 ` [PATCH 6/6] btrfs: Remove BUG_ON from run_delalloc_nocow Nikolay Borisov
2019-08-06 10:34 ` Filipe Manana
2019-08-07 8:18 ` Nikolay Borisov
2019-08-21 15:55 ` David Sterba
2019-08-22 14:24 ` Nikolay Borisov [this message]
2019-08-23 17:28 ` [PATCH v2] " David Sterba
2019-08-19 16:42 ` [PATCH 0/6] Refactor nocow path David Sterba
2019-08-21 15:59 ` 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=20190822142420.1126-1-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=dsterb@suse.cz \
--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).