Re: [PATCH v6 10/13] xfs: iomap COW-based atomic write support

From: Christoph Hellwig
Date: Thu Mar 20 2025 - 01:29:55 EST


On Wed, Mar 19, 2025 at 10:24:55AM +0000, John Garry wrote:
> it seems to work ok, cheers

Better test it very well, this was really just intended as a sketch..

>> + count_fsb = end_fsb - offset_fsb;
>> + resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb,
>> + xfs_get_cowextsz_hint(ip));
>> + xfs_iunlock(ip, XFS_ILOCK_EXCL);
>> +
>> + error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write,
>> + XFS_DIOSTRAT_SPACE_RES(mp, resaligned), 0, false, &tp);
>> if (error)
>> return error;
>> - error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
>> - &nimaps, 0);
>> - if (error)
>> - goto out_unlock;
>> + if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &cmap))
>> + cmap.br_startoff = end_fsb;
>
> Do we really need this logic?
>
> offset_fsb does not change, and logically cmap.br_startoff == end_fsb
> already, right?

Afte unlocking and relocking the ilock the extent layout could have
changed.