All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Chandan Babu R <chandan.babu@oracle.com>
Cc: linux-xfs@vger.kernel.org, djwong@kernel.org
Subject: Re: [PATCH V3 08/12] xfs: Promote xfs_extnum_t and xfs_aextnum_t to 64 and 32-bits respectively
Date: Wed, 29 Sep 2021 09:08:22 +1000	[thread overview]
Message-ID: <20210928230822.GK2361455@dread.disaster.area> (raw)
In-Reply-To: <874ka51168.fsf@debian-BULLSEYE-live-builder-AMD64>

On Tue, Sep 28, 2021 at 03:17:59PM +0530, Chandan Babu R wrote:
> On 28 Sep 2021 at 06:17, Dave Chinner wrote:
> > On Thu, Sep 16, 2021 at 03:36:43PM +0530, Chandan Babu R wrote:
> >> A future commit will introduce a 64-bit on-disk data extent counter and a
> >> 32-bit on-disk attr extent counter. This commit promotes xfs_extnum_t and
> >> xfs_aextnum_t to 64 and 32-bits in order to correctly handle in-core versions
> >> of these quantities.
> >> 
> >> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> >> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
> >
> > So while I was auditing extent lengths w.r.t. the last patch f the
> > series, I noticed that xfs_extnum_t is used in the struct
> > xfs_log_dinode and so changing the size of these types changes the
> > layout of this structure:
> >
> > /*
> >  * Define the format of the inode core that is logged. This structure must be
> >  * kept identical to struct xfs_dinode except for the endianness annotations.
> >  */
> > struct xfs_log_dinode {
> > ....
> >         xfs_rfsblock_t  di_nblocks;     /* # of direct & btree blocks used */
> >         xfs_extlen_t    di_extsize;     /* basic/minimum extent size for file */
> >         xfs_extnum_t    di_nextents;    /* number of extents in data fork */
> >         xfs_aextnum_t   di_anextents;   /* number of extents in attribute fork*/
> > ....
> >
> > Which means this:
> >
> >> -typedef int32_t		xfs_extnum_t;	/* # of extents in a file */
> >> -typedef int16_t		xfs_aextnum_t;	/* # extents in an attribute fork */
> >> +typedef uint64_t	xfs_extnum_t;	/* # of extents in a file */
> >> +typedef uint32_t	xfs_aextnum_t;	/* # extents in an attribute fork */
> >
> > creates an incompatible log format change that will cause silent
> > inode corruption during log recovery if inodes logged with this
> > change are replayed on an older kernel without this change. It's not
> > just the type size change that matters here - it also changes the
> > implicit padding in this structure because xfs_extlen_t is a 32 bit
> > object and so:
> >
> > Old					New
> > 64 bit object (di_nblocks)		64 bit object (di_nblocks)
> > 32 bit object (di_extsize)		32 bit object (di_extsize)
> > 					32 bit pad (implicit)
> > 32 bit object (di_nextents)		64 bit object (di_nextents)
> > 16 bit object (di_anextents)		32 bit ojecct (di_anextents
> > 8 bit object (di_forkoff)		8 bit object (di_forkoff)
> > 8 bit object (di_aformat)		8 bit object (di_aformat)
> > 					16 bit pad (implicit)
> > 32 bit object (di_dmevmask)		32 bit object (di_dmevmask)
> >
> >
> > That's quite the layout change, and that's something we must not do
> > without a feature bit being set. hence I think we need to rev the
> > struct xfs_log_dinode version for large extent count support, too,
> > so that the struct xfs_log_dinode does not change size for
> > filesystems without the large extent count feature.
> 
> Actually, the current patch replaces the data types xfs_extnum_t and
> xfs_aextnum_t inside "struct xfs_log_dinode" with the basic integral types
> uint32_t and uint16_t respectively. The patch "xfs: Extend per-inode extent
> counter widths" which arrives later in the series adds the new field
> di_nextents64 to "struct xfs_log_dinode" and uint64_t is used as its data
> type.

Arggh.

Perhaps now you might see why I really don't like naming things by
size and having the contents of those fields based on context? It
is so easy to miss things like when the wrong variable or type is
used for a given context because the code itself gives you no hint
as to what the correct usage it.

I suspect part of the problem I'm had here is that the change of
the type in the xfs_log_dinode is done in a -variable rename- patch
that names variables by size, not in the patch that -actually
changes the variable size-.

IOWs, the type change in the xfs_log_dinode should
either be in this patch where the log_dinode structure shape would
change, or in it's own standalone patch with a description that says
"we need to avoid changing the on-disk structure shape".

Making sure that the on-disk format changes (or things that avoid
them!) are clear and explicit in a patchset is critical as these are
things we really need to get right.

I missed the per-inode extent size flag for a similar reason - it
was buried in a larger patch that made lots of different
modifications to support the on-disk extent count format change, so
it wasn't clearly defined/called out as a separate on-disk format
change necessary for correct functioning.

> So in a scenario where we have a filesystem which does not have support for
> 64-bit extent counters and a kernel which does not support 64-bit extent
> counters is replaying a log created by a kernel supporting 64-bit extent
> counters, the contents of the 16-bit and 32-bit extent counter fields should
> be replayed correctly into xfs_inode's attr and data fork extent counters
> respectively. The contents of the 64-bit extent counter (whose value will be
> zero) in the logged inode will be replayed back into di_pad2[] field of the
> inode.

I think that's correct, because the superblock bit will prevent
mount on old kernels that don't support the 64 bit extent counter
and so the zeroes in di_pad2 won't get overwritten incorrectly.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2021-09-28 23:08 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16 10:06 [PATCH V3 00/12] xfs: Extend per-inode extent counters Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 01/12] xfs: Move extent count limits to xfs_format.h Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 02/12] xfs: Introduce xfs_iext_max_nextents() helper Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 03/12] xfs: Rename MAXEXTNUM, MAXAEXTNUM to XFS_IFORK_EXTCNT_MAXS32, XFS_IFORK_EXTCNT_MAXS16 Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 04/12] xfs: Use xfs_extnum_t instead of basic data types Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 05/12] xfs: Introduce xfs_dfork_nextents() helper Chandan Babu R
2021-09-27 22:46   ` Dave Chinner
2021-09-28  9:46     ` Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 06/12] xfs: xfs_dfork_nextents: Return extent count via an out argument Chandan Babu R
2021-09-30  1:19   ` Dave Chinner
2021-09-16 10:06 ` [PATCH V3 07/12] xfs: Rename inode's extent counter fields based on their width Chandan Babu R
2021-09-27 23:46   ` Dave Chinner
2021-09-28  4:04     ` Dave Chinner
2021-09-29 17:03       ` Chandan Babu R
2021-09-30  0:40         ` Dave Chinner
2021-09-30  4:31           ` Dave Chinner
2021-09-30  7:30             ` Chandan Babu R
2021-09-30 22:55               ` Dave Chinner
2021-10-07 10:52                 ` Chandan Babu R
2021-10-10 21:49                   ` Dave Chinner
2021-10-13 14:44                     ` Chandan Babu R
2021-10-14  2:00                       ` Dave Chinner
2021-10-14 10:07                         ` Chandan Babu R
2021-10-21 10:27                       ` Chandan Babu R
2021-09-28  9:47     ` Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 08/12] xfs: Promote xfs_extnum_t and xfs_aextnum_t to 64 and 32-bits respectively Chandan Babu R
2021-09-28  0:47   ` Dave Chinner
2021-09-28  9:47     ` Chandan Babu R
2021-09-28 23:08       ` Dave Chinner [this message]
2021-09-29 17:04         ` Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 09/12] xfs: Enable bulkstat ioctl to support 64-bit per-inode extent counters Chandan Babu R
2021-09-27 23:06   ` Dave Chinner
2021-09-28  9:49     ` Chandan Babu R
2021-09-28 23:39       ` Dave Chinner
2021-09-29 17:04         ` Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 10/12] xfs: Extend per-inode extent counter widths Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 11/12] xfs: Add XFS_SB_FEAT_INCOMPAT_NREXT64 to XFS_SB_FEAT_INCOMPAT_ALL Chandan Babu R
2021-09-16 10:06 ` [PATCH V3 12/12] xfs: Define max extent length based on on-disk format definition Chandan Babu R
2021-09-28  0:33   ` Dave Chinner
2021-09-28 10:07     ` Chandan Babu R
2021-09-18  0:03 ` [PATCH V3 00/12] xfs: Extend per-inode extent counters Darrick J. Wong
2021-09-18  3:36   ` [External] : " Chandan Babu R

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=20210928230822.GK2361455@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=chandan.babu@oracle.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.