Re:Re: Re: [PATCH 1/6] ntfs: mark the record dirtied by a resident write at iomap begin

From: dd

Date: Tue Dec 01 2026 - 02:46:57 EST






At 2026-12-01 12:19:31, "Hyunchul Lee" <hyc.lee@xxxxxxxxx> wrote:
>On Thu, Nov 26, 2026 at 05:31:35PM +0800, dd wrote:
>>
>>
>>
>>
>> At 2026-11-26 16:45:06, "Hyunchul Lee" <hyc.lee@xxxxxxxxx> wrote:
>> >Hi Hongling,
>> >
>> >>
>> >> + /*
>> >> + * The record holding a resident attribute can be an extent record.
>> >> + * Mark the record the lookup found dirty here, while the search
>> >> + * context still points at it. The writeout of the record cannot
>> >> + * overtake the inline copy: it is serialized by the mrec_lock held
>> >> + * until iomap_end.
>> >> + */
>> >> + mark_mft_record_dirty(ctx->ntfs_ino);
>> >> +
>> >
>> >If the write fails before the data is copied into the resident
>> >attribute, the MFT record is still marked dirty and may be written back
>> >even if its contents have not changed.
>> >
>>
>> That can happen, but it is harmless. The mark only sets I_DIRTY_DATASYNC
>> on the base vfs inode (__mark_mft_record_dirty()), and the record is
>> written out by __ntfs_write_inode(), which takes the base mrec_lock
>> before touching any record. The write path holds that lock until
>> iomap_end, so the writeback cannot see the record mid-copy: in the
>> failed-write case it writes one record with unchanged contents, in a
>> write that is already failing. The base record already gets the same
>> treatment: ntfs_write_iomap_end_resident() marks it dirty regardless of
>> how much was copied.
>>
>> Deferring the mark to iomap_end would have to carry the inode of the
>> record there: begin releases the search context before returning, and
>> iomap_end only sees the base inode.
>>
>> Thanks for the review.
>
>What I am concerned about is the writeback of an unchanged extent record
>on the failure path. mark_mft_record_dirty() sets NI_Dirty before any
>data has been copied.

>
You are right, and my previous reply answered a different question:
the spurious writeback of an unchanged record is worth avoiding by
itself, race or no race.


>I also think carrying the extent record inode is not difficult.>iomap_begin() can store it in iomap->private.

>
Agreed. v5 does that: iomap_end() marks the extent record dirty only
after bytes are copied into it. The base record is still marked
unconditionally, since the write's timestamp update modifies it.


Thanks.>>
>> --
>> Hongling
>> >> a = ctx->attr;
>> >> /* The total length of the attribute value. */
>> >> attr_len = le32_to_cpu(a->data.resident.value_length);
>> >> --
>> >> 2.25.1
>> >>
>> >
>> >--
>> >Thanks,
>> >Hyunchul
>
>--
>Thanks,
>Hyunchul