Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4150113pxb; Mon, 27 Sep 2021 10:24:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxEUUKDbP0fmFd9AKf2zVcSqeDbsRJPKHA1rjNj7OUTT/wvPxuTuKkRQRdrHAeljzLgkRz X-Received: by 2002:a63:e74b:: with SMTP id j11mr709076pgk.322.1632763471165; Mon, 27 Sep 2021 10:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632763471; cv=none; d=google.com; s=arc-20160816; b=dDizSW5L+8Bq/ooGNIDugAyw3lDHZA6s1xGMTE5G5k/XmsRHh/jzK7XiDX2zgHcfzG Zci566DmMKJMSr1C7/ifHumLbnWWD4xtD8kYPEUBveqroYCJc8HOMHyS6du3hcKE9KuF wvp1I6gsJ/KtQEdAJTpjOlZ/zBgpZ4JDyiFp7YAF+cWTP0rH0RRJ51UlzaIwV4e4Qn// OLJHOwhKvxL7vcRHfwMZLvZcOvzGTE6rdlgFoN3cF5hR6C0WHdtFIFNJDi+PqKjxxZJe BlcZkRMmANopzhyV7gsjV4Tfqzt7oHJFaTEad7avfV3WWHLKxL2VjmfPPlrHaIMgBwDW BE3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ScCGMzGXMSDFuWp/agT8sdOnQFk/0UGS5TsrlviaZjY=; b=VTvICvqTOQz6wzXjjW/yu8YK/Y84s3w1qWPaK/I5o9L2Fc/JvuuLR86X0jAHBR8qLN 2WnUncA5QNzEEYQEcfc9eFPKVK3aZqJouSzo9u3yRDCeNNjJhsrbXeRePZt515x6bngP gKmpJnNrMEGjlKRTshfn4GXFIyoKvOPAotaJewoxDb0fM3BH2VthTlPP29YqEtK17SrF 18klTd0KZiSfdysn/pByx4Enh9jvEKNyONJFQECRn7QeANq36viCt7ecveYWtyxi5kC0 G7rxWrZPRJSBKMpe6E0TgW+TmgrwkxdY1HYxEvgl8NO2R7E9RGvNuBJQXrNkl41JJZH4 T22Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xsR+phKA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ij27si7627025plb.350.2021.09.27.10.24.17; Mon, 27 Sep 2021 10:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xsR+phKA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237435AbhI0RXR (ORCPT + 99 others); Mon, 27 Sep 2021 13:23:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:37506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236326AbhI0RUF (ORCPT ); Mon, 27 Sep 2021 13:20:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C66E613A1; Mon, 27 Sep 2021 17:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762790; bh=V1XRCNnsokINEUhpOK8ajzGyWuEa2f0wXZ5FZ178hug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xsR+phKAYtAhJ/NBEAeP/8nT3YmZVAq1E5udvLGe+MQNiVoFyoOg8bmk1lCIu9f/O 7iiI7f+EhcesZzMjJHHUhAwkENRVSw1Ul0ulrZkH3la1CNDxm6F+XF5rc6pzVLMEMg 4LaywavzQl90GUNykPUu0i71zGLE4TmkogZBVXJQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Markus Suvanto , David Howells , Marc Dionne , linux-afs@lists.infradead.org, Sasha Levin Subject: [PATCH 5.14 051/162] afs: Fix updating of i_blocks on file/dir extension Date: Mon, 27 Sep 2021 19:01:37 +0200 Message-Id: <20210927170235.260421911@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170233.453060397@linuxfoundation.org> References: <20210927170233.453060397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 9d37e1cab2a9d2cee2737973fa455e6f89eee46a ] When an afs file or directory is modified locally such that the total file size is extended, i_blocks needs to be recalculated too. Fix this by making afs_write_end() and afs_edit_dir_add() call afs_set_i_size() rather than setting inode->i_size directly as that also recalculates inode->i_blocks. This can be tested by creating and writing into directories and files and then examining them with du. Without this change, directories show a 4 blocks (they start out at 2048 bytes) and files show 0 blocks; with this change, they should show a number of blocks proportional to the file size rounded up to 1024. Fixes: 31143d5d515e ("AFS: implement basic file write support") Fixes: 63a4681ff39c ("afs: Locally edit directory data for mkdir/create/unlink/...") Reported-by: Markus Suvanto Signed-off-by: David Howells Reviewed-by: Marc Dionne Tested-by: Markus Suvanto cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/163113612442.352844.11162345591911691150.stgit@warthog.procyon.org.uk/ Signed-off-by: Sasha Levin --- fs/afs/dir_edit.c | 4 ++-- fs/afs/inode.c | 10 ---------- fs/afs/internal.h | 10 ++++++++++ fs/afs/write.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index f4600c1353ad..540b9fc96824 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -263,7 +263,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode, if (b == nr_blocks) { _debug("init %u", b); afs_edit_init_block(meta, block, b); - i_size_write(&vnode->vfs_inode, (b + 1) * AFS_DIR_BLOCK_SIZE); + afs_set_i_size(vnode, (b + 1) * AFS_DIR_BLOCK_SIZE); } /* Only lower dir pages have a counter in the header. */ @@ -296,7 +296,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode, new_directory: afs_edit_init_block(meta, meta, 0); i_size = AFS_DIR_BLOCK_SIZE; - i_size_write(&vnode->vfs_inode, i_size); + afs_set_i_size(vnode, i_size); slot = AFS_DIR_RESV_BLOCKS0; page = page0; block = meta; diff --git a/fs/afs/inode.c b/fs/afs/inode.c index 80b6c8d967d5..c18cbc69fa58 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -53,16 +53,6 @@ static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *paren dump_stack(); } -/* - * Set the file size and block count. Estimate the number of 512 bytes blocks - * used, rounded up to nearest 1K for consistency with other AFS clients. - */ -static void afs_set_i_size(struct afs_vnode *vnode, u64 size) -{ - i_size_write(&vnode->vfs_inode, size); - vnode->vfs_inode.i_blocks = ((size + 1023) >> 10) << 1; -} - /* * Initialise an inode from the vnode status. */ diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 928408888054..345494881f65 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -1586,6 +1586,16 @@ static inline void afs_update_dentry_version(struct afs_operation *op, (void *)(unsigned long)dir_vp->scb.status.data_version; } +/* + * Set the file size and block count. Estimate the number of 512 bytes blocks + * used, rounded up to nearest 1K for consistency with other AFS clients. + */ +static inline void afs_set_i_size(struct afs_vnode *vnode, u64 size) +{ + i_size_write(&vnode->vfs_inode, size); + vnode->vfs_inode.i_blocks = ((size + 1023) >> 10) << 1; +} + /* * Check for a conflicting operation on a directory that we just unlinked from. * If someone managed to sneak a link or an unlink in on the file we just diff --git a/fs/afs/write.c b/fs/afs/write.c index 66b235266893..e86f5a245514 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -137,7 +137,7 @@ int afs_write_end(struct file *file, struct address_space *mapping, write_seqlock(&vnode->cb_lock); i_size = i_size_read(&vnode->vfs_inode); if (maybe_i_size > i_size) - i_size_write(&vnode->vfs_inode, maybe_i_size); + afs_set_i_size(vnode, maybe_i_size); write_sequnlock(&vnode->cb_lock); } -- 2.33.0