Received: by 10.213.65.68 with SMTP id h4csp465589imn; Fri, 16 Mar 2018 08:34:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELtHBGshC1DymfxrEZlyeFvOLkPuYtGQ/r4mWDxm/B5UhxJmuQPAOP4Fh6c14EuG5ptX4/ZD X-Received: by 10.99.134.193 with SMTP id x184mr1821560pgd.324.1521214480756; Fri, 16 Mar 2018 08:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521214480; cv=none; d=google.com; s=arc-20160816; b=FEyrtuMdqddsoHNeT2GdTA/qHhzXPoRUMDz0Al0c7Smr9fJ8huq76jYZMpHfc+zzkI y497iHRCzNV9j3/6j7gM0LQlrIHydipo1GkZdCcIiU7JtDa2bUZwEhbn2UnabjGvpHES Mkfpv0XwhKzi6EADxssqgsg0YjdgmlNkNgssE+qQx59eg8TAj0Q/vZRDqHwBj8HMk8yR g0GogmTQBKKzpIf0sCut3zBtgrS5ClGLUQzgfbaWOPFFZnLkZn5kFpEQ8BAiNhwxP01Y Kfhx6A6Al12F93kHCim2SuMKfh73+0d5pmvuXbjUix7YdTelCsGlBSs/Nqyc26c8m/yG ZOVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=DShnVNkXXZREQchijAe6hswxI47FKvKob+M7GqFBfOc=; b=a2fq7uGhEWL96i90vs4GdbcIf0TvwKTp9aZnMIgrvBk+rJ78RC1XuNJA5UjtPGgHfh 6jKFR2LTk3VEA/y1t31l0D0qrYdrxvoe+wWaqY2w26+4XSWtWGvdf7+FsHQtSh28D5Sy Z6U5hymP7xNwPn28ptweiW75x/+AQgppRboEbRqE2a7Gws5E7v6AzzxYFExkQz6GjWI1 tL7KYyPjxWOZVuJDDO0Z5F/zf2TE56TCvfz/xzniCIaWaMczou9I8hevnH/rO6Pa5vXU 6sb2otPJicRabnm6Ku45XxbWCpyBMzi0BO1SlZnsy3ShdyDURgvzv8eWrWowN2EhKMfP DO6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si5684503pfl.176.2018.03.16.08.34.26; Fri, 16 Mar 2018 08:34:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933316AbeCPPci (ORCPT + 99 others); Fri, 16 Mar 2018 11:32:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38058 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933573AbeCPPce (ORCPT ); Fri, 16 Mar 2018 11:32:34 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D8B6B1162; Fri, 16 Mar 2018 15:32:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tahsin Erdogan , Theodore Tso , Andreas Dilger , Tommi Rantala Subject: [PATCH 4.9 64/86] ext4: inplace xattr block update fails to deduplicate blocks Date: Fri, 16 Mar 2018 16:23:27 +0100 Message-Id: <20180316152321.687698483@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tahsin Erdogan commit ec00022030da5761518476096626338bd67df57a upstream. When an xattr block has a single reference, block is updated inplace and it is reinserted to the cache. Later, a cache lookup is performed to see whether an existing block has the same contents. This cache lookup will most of the time return the just inserted entry so deduplication is not achieved. Running the following test script will produce two xattr blocks which can be observed in "File ACL: " line of debugfs output: mke2fs -b 1024 -I 128 -F -O extent /dev/sdb 1G mount /dev/sdb /mnt/sdb touch /mnt/sdb/{x,y} setfattr -n user.1 -v aaa /mnt/sdb/x setfattr -n user.2 -v bbb /mnt/sdb/x setfattr -n user.1 -v aaa /mnt/sdb/y setfattr -n user.2 -v bbb /mnt/sdb/y debugfs -R 'stat x' /dev/sdb | cat debugfs -R 'stat y' /dev/sdb | cat This patch defers the reinsertion to the cache so that we can locate other blocks with the same contents. Signed-off-by: Tahsin Erdogan Signed-off-by: Theodore Ts'o Reviewed-by: Andreas Dilger Signed-off-by: Tommi Rantala Signed-off-by: Greg Kroah-Hartman --- fs/ext4/xattr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -837,8 +837,6 @@ ext4_xattr_block_set(handle_t *handle, s if (!IS_LAST_ENTRY(s->first)) ext4_xattr_rehash(header(s->base), s->here); - ext4_xattr_cache_insert(ext4_mb_cache, - bs->bh); } ext4_xattr_block_csum_set(inode, bs->bh); unlock_buffer(bs->bh); @@ -959,6 +957,7 @@ inserted: } else if (bs->bh && s->base == bs->bh->b_data) { /* We were modifying this block in-place. */ ea_bdebug(bs->bh, "keeping this block"); + ext4_xattr_cache_insert(ext4_mb_cache, bs->bh); new_bh = bs->bh; get_bh(new_bh); } else {