lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e0a93440-8f38-46e1-a77f-6a0125ab8cb5@oracle.com>
Date: Fri, 23 Aug 2024 11:41:07 +0100
From: John Garry <john.g.garry@...cle.com>
To: "Darrick J. Wong" <djwong@...nel.org>
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 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)
{
	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().


John


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ