From: Mauricio Faria de Oliveira <mfo@canonical.com>
To: linux-ext4@vger.kernel.org, "Theodore Y. Ts'o" <tytso@mit.edu>
Cc: dann frazier <dann.frazier@canonical.com>,
Andreas Dilger <adilger@dilger.ca>, Jan Kara <jack@suse.com>
Subject: [RFC PATCH 10/11] ext4: deduplicate code with error legs in ext4_try_to_write_inline_data()
Date: Thu, 23 Apr 2020 20:37:04 -0300 [thread overview]
Message-ID: <20200423233705.5878-11-mfo@canonical.com> (raw)
In-Reply-To: <20200423233705.5878-1-mfo@canonical.com>
Make the error legs similar to ext4_convert_inline_data_to_extent(),
now that we have even more "unlock_page(); put_page();" statements.
While in there, do similarly for the semaphore and label "convert:".
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
---
fs/ext4/inline.c | 56 +++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 31 deletions(-)
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 9bb85e06854d..3d370b04a740 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -684,9 +684,13 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
handle_t *handle;
struct page *page;
struct ext4_iloc iloc;
+ bool convert = false;
+ bool sem_held = false;
- if (pos + len > ext4_get_max_inline_size(inode))
- goto convert;
+ if (pos + len > ext4_get_max_inline_size(inode)) {
+ convert = true;
+ goto out_convert;
+ }
ret = ext4_get_inode_loc(inode, &iloc);
if (ret)
@@ -717,6 +721,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
put_page(page);
ret = PTR_ERR(handle);
handle = NULL;
+ page = NULL;
goto out;
}
@@ -732,58 +737,47 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
wait_for_stable_page(page);
ret = ext4_prepare_inline_data(handle, inode, pos + len);
- if (ret && ret != -ENOSPC) {
- unlock_page(page);
- put_page(page);
+ if (ret) {
+ /* If don't have space in inline inode, convert it to extent. */
+ convert = (ret == -ENOSPC);
goto out;
}
- /* We don't have space in inline inode, so convert it to extent. */
- if (ret == -ENOSPC) {
- unlock_page(page);
- put_page(page);
- ext4_journal_stop(handle);
- brelse(iloc.bh);
- goto convert;
- }
-
ret = ext4_journal_get_write_access(handle, iloc.bh);
- if (ret) {
- unlock_page(page);
- put_page(page);
+ if (ret)
goto out;
- }
*pagep = page;
down_read(&EXT4_I(inode)->xattr_sem);
+ sem_held = true;
if (!ext4_has_inline_data(inode)) {
ret = 0;
- unlock_page(page);
- put_page(page);
- goto out_up_read;
+ goto out;
}
if (!PageUptodate(page)) {
ret = ext4_read_inline_page(inode, page);
- if (ret < 0) {
- unlock_page(page);
- put_page(page);
- goto out_up_read;
- }
+ if (ret < 0)
+ goto out;
}
ret = 1;
handle = NULL;
-out_up_read:
- up_read(&EXT4_I(inode)->xattr_sem);
out:
+ if (page && (ret != 1)) {
+ unlock_page(page);
+ put_page(page);
+ }
+ if (sem_held)
+ up_read(&EXT4_I(inode)->xattr_sem);
if (handle && (ret != 1))
ext4_journal_stop(handle);
brelse(iloc.bh);
+out_convert:
+ if (convert)
+ return ext4_convert_inline_data_to_extent(mapping,
+ inode, flags);
return ret;
-convert:
- return ext4_convert_inline_data_to_extent(mapping,
- inode, flags);
}
int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
--
2.20.1
next prev parent reply other threads:[~2020-04-23 23:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 23:36 [RFC PATCH 00/11] ext4: data=journal: writeback mmap'ed pagecache Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 01/11] ext4: data=journal: introduce struct/kmem_cache ext4_journalled_wb_page/_cachep Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 02/11] ext4: data=journal: handle page writeback in __ext4_journalled_writepage() Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 03/11] ext4: data=journal: call ext4_force_commit() in ext4_writepages() for msync() Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 04/11] ext4: data=journal: introduce helpers for journalled writeback deadlock Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 05/11] ext4: data=journal: prevent journalled writeback deadlock in __ext4_journalled_writepage() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 06/11] ext4: data=journal: prevent journalled writeback deadlock in ext4_write_begin() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 07/11] ext4: grab page before starting transaction handle in ext4_convert_inline_data_to_extent() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 08/11] ext4: data=journal: prevent journalled writeback deadlock " Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 09/11] ext4: grab page before starting transaction handle in ext4_try_to_write_inline_data() Mauricio Faria de Oliveira
2020-04-23 23:37 ` Mauricio Faria de Oliveira [this message]
2020-04-23 23:37 ` [RFC PATCH 11/11] ext4: data=journal: prevent journalled writeback deadlock " Mauricio Faria de Oliveira
2020-05-15 18:39 ` [RFC PATCH 00/11] ext4: data=journal: writeback mmap'ed pagecache Mauricio Faria de Oliveira
2020-05-17 7:40 ` Andreas Dilger
2020-06-10 13:21 ` Jan Kara
2020-06-10 15:15 ` Mauricio Faria de Oliveira
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=20200423233705.5878-11-mfo@canonical.com \
--to=mfo@canonical.com \
--cc=adilger@dilger.ca \
--cc=dann.frazier@canonical.com \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).