[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240823155201.GZ865349@frogsfrogsfrogs>
Date: Fri, 23 Aug 2024 08:52:01 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: John Garry <john.g.garry@...cle.com>
Cc: axboe@...nel.dk, brauner@...nel.org, viro@...iv.linux.org.uk,
jack@...e.cz, chandan.babu@...cle.com, dchinner@...hat.com,
hch@....de, linux-block@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org, hare@...e.de,
martin.petersen@...cle.com, catherine.hoang@...cle.com,
kbusch@...nel.org
Subject: Re: [PATCH v5 7/7] xfs: Support setting FMODE_CAN_ATOMIC_WRITE
On Fri, Aug 23, 2024 at 11:41:07AM +0100, John Garry wrote:
> On 22/08/2024 21:44, Darrick J. Wong wrote:
> > > Do you mean that add a new member to xfs_inode to record this? If yes, it
> > > sounds ok, but we need to maintain consistency (of that member) whenever
> > > anything which can affect it changes, which is always a bit painful.
> > I actually meant something more like:
> >
> > static bool
> > xfs_file_open_can_atomicwrite(
> > struct file *file,
> > struct inode *inode)
> > {
> > struct xfs_inode *ip = XFS_I(inode);
> > struct xfs_mount *mp = ip->i_mount;
> > struct xfs_buftarg *target = xfs_inode_buftarg(ip);
> >
> > if (!(file->f_flags & O_DIRECT))
> > return false;
> > if (!xfs_inode_has_atomicwrites(ip))
> > return false;
> > if (mp->m_dalign && (mp->m_dalign % ip->i_extsize))
> > return false;
> > if (mp->m_swidth && (mp->m_swidth % ip->i_extsize))
> > return false;
> > if (mp->m_sb.sb_blocksize < target->bt_bdev_awu_min)
> > return false;
> > if (xfs_inode_alloc_unitsize(ip) > target->bt_bdev_awu_max)
> > return false;
> > return true;
> > }
>
> ok, but we should probably factor out some duplicated code with helpers,
> like:
>
> bool xfs_validate_atomicwrites_extsize(struct xfs_mount *mp, uint32_t
> extsize)
xfs_agblock_t extsize, but other than that this looks right to me.
> {
> if (!is_power_of_2(extsize))
> return false;
>
> /* Required to guarantee data block alignment */
> if (mp->m_sb.sb_agblocks % extsize)
> return false;
>
> /* Requires stripe unit+width be a multiple of extsize */
> if (mp->m_dalign && (mp->m_dalign % extsize))
> return false;
>
> if (mp->m_swidth && (mp->m_swidth % extsize))
> return false;
>
> return true;
> }
>
>
> bool xfs_inode_has_atomicwrites(struct xfs_inode *ip)
> {
> struct xfs_mount *mp = ip->i_mount;
> struct xfs_buftarg *target = xfs_inode_buftarg(ip);
>
> if (!(ip->i_diflags2 & XFS_DIFLAG2_ATOMICWRITES))
> return false;
> if (!xfs_validate_atomicwrites_extsize(mp, ip->i_extsize))
> return false;
> if (mp->m_sb.sb_blocksize < target->bt_bdev_awu_min)
> return false;
> if (xfs_inode_alloc_unitsize(ip) > target->bt_bdev_awu_max)
> return false;
> return true;
> }
>
>
> static bool xfs_file_open_can_atomicwrite(
> struct inode *inode,
> struct file *file)
> {
> struct xfs_inode *ip = XFS_I(inode);
>
> if (!(file->f_flags & O_DIRECT))
> return false;
> return xfs_inode_has_atomicwrites(ip);
> }
>
> Those helpers can be re-used in xfs_inode_validate_atomicwrites() and
> xfs_ioctl_setattr_atomicwrites().
Looks good to me.
--D
>
> John
>
>
Powered by blists - more mailing lists