[Devel] [PATCH hci-8.1 2/7] drivers/md/dm-qcow2: check MD_DIRTY and md->wbd under lock in perform_rw_mapped()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Nov 5 00:35:09 MSK 2026


I won't apply this version, please send v2 with the changes below.

On Thu, 29 Oct 2026 17:03:41 +0300, Andrey Zhadchenko wrote:
> -	if (rw == WRITE && (md->status & MD_DIRTY) &&
> -	    test_bit(index_in_page, md->wbd->changed_indexes)) {
> +	if (rw == WRITE) {
>  		spin_lock_irqsave(&qcow2->md_pages_lock, flags);
> -		md->wbd->nr_submitted++;
> -		qio->data = md->wbd;
> +		if ((md->status & MD_DIRTY) &&
> +		    test_bit(index_in_page, md->wbd->changed_indexes)) {
> +			md->wbd->nr_submitted++;
> +			qio->data = md->wbd;
> +		}
>  		spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);

Item 1 of the cover letter reply: under this lock, when MD_WRITEBACK
is set and the index is in changed_indexes, park the qio on
md->wait_list, as parse_l2() does. Do not attach it to a wbd under
writeback: after a failed writeback complete_wbd() frees the wbd.

Why: the lock makes this check consistent, but parse_l2() decided
under an earlier lock hold that the write need not wait. With the fast
path of patch 5:

  main kwork                      fast worker
  allocates cluster X,
  L2 page DIRTY
                                  parse_l2(): write to X, page DIRTY,
                                  not delayed, unlock
  submit_metadata_writeback():
  DIRTY -> WRITEBACK
                                  perform_rw_mapped(): no MD_DIRTY,
                                  qio->data = NULL, submit

The write is acked as soon as its data is written. A FLUSH after it
finds QLIST_COMPLETED_WB empty and does only vfs_fsync(), it does not
wait for the L2 write in flight. A crash then loses a write that was
acked and flushed. If the L2 write fails instead, the entry is reverted
and X freed while the write already returned success. The base is safe
only because parse, submit and the DIRTY -> WRITEBACK switch happen in
one do_qcow2_work() pass.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list