Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp398987pxb; Thu, 9 Sep 2021 03:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+44LwQjdWA9PGgDyTCfyxm6SgQ50ddMsQ5GcWRxCAYi2AuenqtTNWDL9BLHWHlL2Ymtk2 X-Received: by 2002:a17:906:249a:: with SMTP id e26mr2573782ejb.221.1631183694110; Thu, 09 Sep 2021 03:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631183694; cv=none; d=google.com; s=arc-20160816; b=W+9MwfA/nkhSHir4AwfeJD/HE5LrMzeGNSYgVlCofghiHEDG/++iVvv6fF1K3GLEnJ Ic+TD/4+BXNcz9w8tfZCdlieHQL7t55+fUVUVlQ+lvIov+gUkvhAFE11rusyd7BI0JtI yGd6Qc0lbniQX1ojbM5IJvbN4eMUfjruIWCO3ewr4h3DkubfBzaUK7NJIQt2/5pJeWW4 TbOONT5kY5HUtahj2DCDlX9u8o+9w1/mNN3zrXUzYUxHO+GFxTYnAZgjM3WO4LEj+Syf H0Y8LerAJ+4ewCHGHIrTLXzty4Ttyt0yU9T/Pq96HuRdPhCu/XWru4vQiGc3vvRrbitS YaIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=+PPfPZ/vyA7kRm7LtesplHagTfP12DiHosfGgqo5nmM=; b=wo68XGwn6y+gJ5kBdTUPpuEP3aOX6nDiaJszZ6p4JSEm3h2ssdimXSWZr9zFevx4dl ZlJCzbOnW6oGQ8pufjA9X0oAlcxb0YBH4UhtwfJziR99RFUqXW5cca0Xpar4fNJOrZar SjtWHSvTgaf5izbw8UvUjxAuVlGsnheoEQ5U0MDAQNAPSjtBR96ffuy1DReMqymtvwHS hDlhlYoe9lbLP8w0dScJP70bhMGVBeG5bCP7LUeP2lCd+DhK8PeOnalJlYm5CygdpRYZ gOrsVQCo9vUKpQK/p5+ljNzfXBJKy+ty+726NuzV0Djy+TkHpoAH68hEkR1Jp5bUpbR+ H8hg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=auristor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si2118790edb.495.2021.09.09.03.34.19; Thu, 09 Sep 2021 03:34:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=auristor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234049AbhIIKcR (ORCPT + 99 others); Thu, 9 Sep 2021 06:32:17 -0400 Received: from mail-ed1-f49.google.com ([209.85.208.49]:42960 "EHLO mail-ed1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234057AbhIIKcQ (ORCPT ); Thu, 9 Sep 2021 06:32:16 -0400 Received: by mail-ed1-f49.google.com with SMTP id z19so1964088edi.9; Thu, 09 Sep 2021 03:31:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+PPfPZ/vyA7kRm7LtesplHagTfP12DiHosfGgqo5nmM=; b=zOXk0Kfra5W2OMCIU0Npx3j7u5w6ztPkB7e9nEQSuxE1+cp/Fc+zcq+seWSwcEc8U5 r8XBwVxXX4fE0JvsgzwZd58r82QOsZ4iHoS8LrsiXaL0giUc4zid1ZNDThTrWLJohHoe 3/U3QvgbaDQc1yNS/aQbUIkpSB+N8p7LrciNKKmRF/i/8BjV3tZ6Ys14vOSfW9AGPV/Z xrhRvSmi7SnyM2MJOXAPv0EDnWVvjezPp7AwYka7ATpYJoV6fEKMPTW/tCA84pPl8q/A nXvsjaPgJ2X3eLpsdLA01XlCUOT9QT22+DKRxXbFGByVhWo9IICs74BWPPmMhLGgA1NK cbvg== X-Gm-Message-State: AOAM530a2emNXOTyYZCG+gOT3rD66ZTotR5vJEdgOQZb6KrwL9DB/33B PkdYixg/MizrVTrN1YZLYYVtev2A7ZFSDQ== X-Received: by 2002:a05:6402:1913:: with SMTP id e19mr2443428edz.9.1631183466499; Thu, 09 Sep 2021 03:31:06 -0700 (PDT) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com. [209.85.221.51]) by smtp.gmail.com with ESMTPSA id o12sm834389edv.19.2021.09.09.03.31.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Sep 2021 03:31:06 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id d6so1803105wrc.11; Thu, 09 Sep 2021 03:31:06 -0700 (PDT) X-Received: by 2002:adf:e349:: with SMTP id n9mr2715415wrj.326.1631183466040; Thu, 09 Sep 2021 03:31:06 -0700 (PDT) MIME-Version: 1.0 References: <163113612442.352844.11162345591911691150.stgit@warthog.procyon.org.uk> In-Reply-To: <163113612442.352844.11162345591911691150.stgit@warthog.procyon.org.uk> From: Marc Dionne Date: Thu, 9 Sep 2021 07:30:50 -0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] afs: Fix updating of i_blocks on file/dir extension To: David Howells Cc: Markus Suvanto , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 8, 2021 at 6:22 PM David Howells wrote: > > 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: 31143d5d515ece617ffccb7df5ff75e4d1dfa120 ("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 > cc: linux-afs@lists.infradead.org > --- > > 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 126daf9969db..8fcffea2daf5 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 c97618855b46..12b2bdae6d1a 100644 > --- a/fs/afs/internal.h > +++ b/fs/afs/internal.h > @@ -1595,6 +1595,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 32a764c24284..2dfe3b3a53d6 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); > } > > > > > _______________________________________________ > linux-afs mailing list > http://lists.infradead.org/mailman/listinfo/linux-afs Reviewed-by: Marc Dionne Marc