linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tahsin Erdogan <tahsin@google.com>
To: Andreas Dilger <adilger@dilger.ca>,
	"Darrick J . Wong" <darrick.wong@oracle.com>,
	Jan Kara <jack@suse.cz>, Theodore Ts'o <tytso@mit.edu>,
	linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Tahsin Erdogan <tahsin@google.com>
Subject: [PATCH 29/32] ext4: reserve space for xattr entries/names
Date: Wed, 21 Jun 2017 18:49:36 -0700	[thread overview]
Message-ID: <20170622014939.3592-6-tahsin@google.com> (raw)
In-Reply-To: <20170622014939.3592-1-tahsin@google.com>

New ea_inode feature allows putting large xattr values into external
inodes. struct ext4_xattr_entry and the attribute name however have to
remain in the inode extra space or external attribute block. Once that
space is exhausted, no further entries can be added. Some of that space
could also be used by values that fit in there at the time of addition.

So, a single xattr entry whose value barely fits in the external block
could prevent further entries being added.

To mitigate the problem, this patch introduces a notion of reserve in
the
external attribute block that cannot be used by value data. This reserve
is enforced when ea_inode feature is enabled. The amount of reserve is
arbitrarily chosen to be min(block_size/8, 1024). The table below shows
how much space is reserved for each block size and the guaranteed
mininum
number of entries that can be placed in the external attribute block.

block size     reserved bytes  entries (name length = 16)
 1k            128              3
 2k            256              7
 4k            512             15
 8k            1024            31
16k            1024            31
32k            1024            31
64k            1024            31

Signed-off-by: Tahsin Erdogan <tahsin@google.com>
---
 fs/ext4/xattr.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index a3f8bf4558f3..835b3dca5b65 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1446,6 +1446,12 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,
 	return 0;
 }
 
+/*
+ * Reserve min(block_size/8, 1024) bytes for xattr entries/names if ea_inode
+ * feature is enabled.
+ */
+#define EXT4_XATTR_BLOCK_RESERVE(inode)	min(i_blocksize(inode)/8, 1024U)
+
 static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
 				struct ext4_xattr_search *s,
 				handle_t *handle, struct inode *inode)
@@ -1505,6 +1511,20 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
 			ret = -ENOSPC;
 			goto out;
 		}
+
+		/*
+		 * If storing the value in an external inode is an option,
+		 * reserve space for xattr entries/names in the external
+		 * attribute block so that a long value does not occupy the
+		 * whole space and prevent futher entries being added.
+		 */
+		if (ext4_has_feature_ea_inode(inode->i_sb) && new_size &&
+		    (s->end - s->base) == i_blocksize(inode) &&
+		    (min_offs + old_size - new_size) <
+					EXT4_XATTR_BLOCK_RESERVE(inode)) {
+			ret = -ENOSPC;
+			goto out;
+		}
 	}
 
 	/*
-- 
2.13.1.611.g7e3b11ae1-goog

  parent reply	other threads:[~2017-06-22  1:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22  1:49 [PATCH 24/32] ext2, ext4: make mb block cache names more explicit Tahsin Erdogan
2017-06-22  1:49 ` [PATCH 25/32] ext4: add ext4_is_quota_file() Tahsin Erdogan
2017-06-22 15:39   ` Theodore Ts'o
2017-06-22  1:49 ` [PATCH 26/32] ext4: cleanup transaction restarts during inode deletion Tahsin Erdogan
2017-06-22 15:43   ` Theodore Ts'o
2017-06-22  1:49 ` [PATCH 27/32] ext4: xattr inode deduplication Tahsin Erdogan
2017-06-22 15:45   ` Theodore Ts'o
2017-06-22  1:49 ` [PATCH 28/32] quota: add get_inode_usage callback to transfer multi-inode charges Tahsin Erdogan
2017-06-22 15:47   ` Theodore Ts'o
2017-06-22  1:49 ` Tahsin Erdogan [this message]
2017-06-22 15:49   ` [PATCH 29/32] ext4: reserve space for xattr entries/names Theodore Ts'o
2017-06-22  1:49 ` [PATCH 30/32] ext4: eliminate xattr entry e_hash recalculation for removes Tahsin Erdogan
2017-06-22 15:52   ` Theodore Ts'o
2017-06-22  1:49 ` [PATCH 31/32] ext4: strong binding of xattr inode references Tahsin Erdogan
2017-06-22 15:54   ` Theodore Ts'o
2017-06-22  1:49 ` [PATCH 32/32] ext4: add nombcache mount option Tahsin Erdogan
2017-06-22 16:00   ` Theodore Ts'o
2017-06-22 15:30 ` [PATCH 24/32] ext2, ext4: make mb block cache names more explicit Theodore Ts'o
  -- strict thread matches above, loose matches on Subject: below --
2017-06-21 21:21 [PATCH 01/32] ext4: xattr-in-inode support Tahsin Erdogan
2017-06-21 21:21 ` [PATCH 29/32] ext4: reserve space for xattr entries/names Tahsin Erdogan

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=20170622014939.3592-6-tahsin@google.com \
    --to=tahsin@google.com \
    --cc=adilger@dilger.ca \
    --cc=darrick.wong@oracle.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@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).