From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 3/5] btrfs: Embed sector size check into BTRFS_MAX_INLINE_DATA_SIZE()
Date: Fri, 2 Mar 2018 13:22:52 +0800 [thread overview]
Message-ID: <20180302052254.7059-4-wqu@suse.com> (raw)
In-Reply-To: <20180302052254.7059-1-wqu@suse.com>
We have extra sector size check in cow_file_range_inline(), but doesn't
implement it in BTRFS_MAX_INLINE_DATA_SIZE().
The biggest reason is that btrfs_symlink() also uses this macro to check
name length.
In fact such behavior makes max_inline calculation quite confusing, and
cause unexpected large extent for symbol link.
Here we embed sector size check into BTRFS_MAX_INLINE_DATA_SIZE() so
that it will never exceed sector size.
The downside is, for symbol link, we will reduce max symbol link length
from 16K- to 4095, but it won't affect current system using that long
name, but only prevent later creation.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/ctree.h | 5 +++--
fs/btrfs/inode.c | 1 -
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 13c260b525a1..90948096c00f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1297,8 +1297,9 @@ static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info)
(offsetof(struct btrfs_file_extent_item, disk_bytenr))
static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
{
- return BTRFS_MAX_ITEM_SIZE(info) -
- BTRFS_FILE_EXTENT_INLINE_DATA_START;
+ return min_t(u32, info->sectorsize - 1,
+ BTRFS_MAX_ITEM_SIZE(info) -
+ BTRFS_FILE_EXTENT_INLINE_DATA_START);
}
static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 48472509239b..fe2991eeb337 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -299,7 +299,6 @@ static noinline int cow_file_range_inline(struct btrfs_root *root,
if (start > 0 ||
actual_end > fs_info->sectorsize ||
- data_len > BTRFS_MAX_INLINE_DATA_SIZE(fs_info) ||
(!compressed_size &&
(actual_end & (fs_info->sectorsize - 1)) == 0) ||
end + 1 < isize ||
--
2.16.2
next prev parent reply other threads:[~2018-03-02 5:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-02 5:22 [PATCH 0/5] max_inline related enhancement Qu Wenruo
2018-03-02 5:22 ` [PATCH 1/5] btrfs: Parse options after node/sector size initialized Qu Wenruo
2018-03-07 15:20 ` David Sterba
2018-03-02 5:22 ` [PATCH 2/5] btrfs: Always limit inline extent size by uncompressed size Qu Wenruo
2018-03-02 10:46 ` Filipe Manana
2018-03-02 10:54 ` Qu Wenruo
2018-03-02 11:00 ` Filipe Manana
2018-03-02 11:40 ` Qu Wenruo
2018-03-06 11:58 ` David Sterba
2018-03-06 12:08 ` Qu Wenruo
2018-03-02 5:22 ` Qu Wenruo [this message]
2018-03-06 12:34 ` [PATCH 3/5] btrfs: Embed sector size check into BTRFS_MAX_INLINE_DATA_SIZE() David Sterba
2018-03-02 5:22 ` [PATCH 4/5] btrfs: Unify inline extent creation condition for plain and compressed data Qu Wenruo
2018-03-02 5:22 ` [PATCH 5/5] btrfs: Show more accurate max_inline Qu Wenruo
2018-03-02 8:21 ` Misono, Tomohiro
2018-03-02 8:33 ` Nikolay Borisov
2018-03-02 8:34 ` Qu Wenruo
2018-03-02 8:37 ` Nikolay Borisov
2018-03-02 10:57 ` Qu Wenruo
2018-03-02 8:13 ` [PATCH 0/5] max_inline related enhancement Nikolay Borisov
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=20180302052254.7059-4-wqu@suse.com \
--to=wqu@suse.com \
--cc=dsterba@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).