From patchwork Wed Jun 14 17:23:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 9787059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 45BAE602D9 for ; Wed, 14 Jun 2017 17:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BF0427E5A for ; Wed, 14 Jun 2017 17:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 208BA283A6; Wed, 14 Jun 2017 17:23:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC0F927E5A for ; Wed, 14 Jun 2017 17:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752845AbdFNRXl (ORCPT ); Wed, 14 Jun 2017 13:23:41 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34969 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752720AbdFNRXh (ORCPT ); Wed, 14 Jun 2017 13:23:37 -0400 Received: by mail-pf0-f175.google.com with SMTP id l89so3413923pfi.2 for ; Wed, 14 Jun 2017 10:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=s8F/1VYaiNCeLoGPmo0PhG8EOubs9iwL3jJ1XNrI6Ns=; b=BLItv08XsC2NUdqsS3OCLsJOqMgiyJqUSGKu7JEp/T9RhN1aHFP+DLneCtkQ7eSNbR TmRZdIHjZjITKMdBzaZ3wLvdjBNNTfqBe0549SNXD4UmpenYrPzNnDc3lX1mqdBpVMjl e1Gs4YGYAfIGjl9LkHBtXiSAiEPZD90Xd3Rwl7TeWojzPT0FLOGyOr7nhZl8zk/febZo V68vQSbJXtFHpAmzPLw3/xjCfHD/QYPDgsHNiutS+2IHMFWSSz/7ITLpRzSk8iFOq/GM QpV94asJbCGddKlKhhGV1PPBdm4sscoaiJg2CMJw5cOOvYIQBRuCMmv8HG/4x1BBWZjm APjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s8F/1VYaiNCeLoGPmo0PhG8EOubs9iwL3jJ1XNrI6Ns=; b=nrPu+xK2+yfy8UM+vpihHOPD3ZLt0B+YBNOLk/uV+IukMbV7vF7jmobEpIb+z0zoXz B0yIPO/wOUa9Wcc5ZZFKHUHnPCtiurvUsJI3qFuRmLebCACl1BYma3pRF6WQcl4VA2NM 8i/Y4PAZF4DV585ScK+uAT/ee4QNKQvINoXnIOefi0NLrR1bDNAJq6ZpKhywlUUPu3T6 Ux32i6BkhjaoBNofkI6Ug4uw/3cdDQfHklEKGimOPyiJY7ubXJeuLDlmeMplGmebwxIZ oTXsuTNMEw4iU4hiOJAaHa+U7TexAVnRlLZzfvEfnWsDz3bSxQ0a1ewVZZGjFMcsy81u rXhw== X-Gm-Message-State: AKS2vOzsrKSi1kCFFWfDpPyTvc3JMJ3R0z0MCrG+WEQ0W0VcZeCBPr++ vCsU+I/h0eJR0jTf X-Received: by 10.98.152.134 with SMTP id d6mr1022818pfk.167.1497461011604; Wed, 14 Jun 2017 10:23:31 -0700 (PDT) Received: from tahsin1.svl.corp.google.com ([100.123.230.167]) by smtp.gmail.com with ESMTPSA id i17sm1154677pgn.60.2017.06.14.10.23.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 10:23:31 -0700 (PDT) From: Tahsin Erdogan To: "Darrick J . Wong" , Jan Kara , Theodore Ts'o , Andreas Dilger , Dave Kleikamp , Alexander Viro , Mark Fasheh , Joel Becker , Jens Axboe , Deepa Dinamani , Mike Christie , Fabian Frederick , linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com, reiserfs-devel@vger.kernel.org, Tahsin Erdogan Subject: [PATCH 29/31] ext4: reserve space for xattr entries/names Date: Wed, 14 Jun 2017 10:23:26 -0700 Message-Id: <20170614172326.18670-1-tahsin@google.com> X-Mailer: git-send-email 2.13.1.508.gb3defc5cc-goog Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- fs/ext4/xattr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 3ad1fc62cbf0..c9579d220a0c 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1428,6 +1428,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) @@ -1487,6 +1493,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; + } } /*