[Devel] [RFC PATCH vz9 v6 60/62] dm-ploop: sync when suspended or stopping

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Fri Dec 13 15:59:53 MSK 2024



On 12/5/24 22:56, Alexander Atanasov wrote:
> On suspended or stopped sync delta.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-91821
> Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
> ---
>   drivers/md/dm-ploop-target.c | 21 +++++++++++++++++++--
>   1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
> index 66a0d4655fd1..4e5800657bf6 100644
> --- a/drivers/md/dm-ploop-target.c
> +++ b/drivers/md/dm-ploop-target.c
> @@ -61,7 +61,8 @@ void ploop_call_rw_iter(struct file *file, loff_t pos, unsigned rw,
>   	init_sync_kiocb(iocb, file);
>   	iocb->ki_pos = pos;
>   	iocb->ki_complete = ploop_aio_complete;
> -	if (pio->bi_op & REQ_FUA)
> +	iocb->ki_flags |= IOCB_ALLOC_CACHE;

If this change is a part of the patch, there should be some explanation

> +	if (rw == WRITE && pio->bi_op & REQ_FUA)
>   		iocb->ki_flags |= IOCB_DSYNC;
>   
>   	atomic_set(&pio->aio_ref, 2);
> @@ -193,7 +194,8 @@ static void ploop_destroy(struct ploop *ploop)
>   			}
>   		}
>   
> -		kthread_stop(ploop->kt_worker->task);	/* waits for the thread to stop */
> +		/* waits for the thread to stop */
> +		kthread_stop(ploop->kt_worker->task);
>   
>   		WARN_ON(!llist_empty(&ploop->pios[PLOOP_LIST_PREPARE]));
>   		WARN_ON(!llist_empty(&ploop->llresubmit_pios));
> @@ -207,6 +209,8 @@ static void ploop_destroy(struct ploop *ploop)
>   		percpu_ref_exit(&ploop->inflight_bios_ref[i]);
>   	/* Nobody uses it after destroy_workqueue() */
>   	while (ploop->nr_deltas-- > 0) {
> +		vfs_fsync(ploop->deltas[ploop->nr_deltas].file, 1);
> +
>   		if (ploop->deltas[ploop->nr_deltas].file)
>   			fput(ploop->deltas[ploop->nr_deltas].file);
>   		for (i = 0; i < ploop->nkt_runners; i++) {
> @@ -286,10 +290,15 @@ static int ploop_check_top_delta(struct ploop *ploop, struct file *file)
>   	if (!page)
>   		goto out;
>   
> +
>   	ret = ploop_rw_page_sync(READ, file, 0, page);
>   	if (ret < 0)
>   		goto out;
>   
> +
> +	/* flush dirty pages before changing direct IO */
> +	vfs_fsync(file, 1);
> +
>   	ret = ploop_setup_metadata(ploop, page);
>   	if (ret)
>   		goto out;
> @@ -351,6 +360,9 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
>   				goto err_fput;
>   		}
>   
> +		/* switch to direct io here */
> +		vfs_fsync(file, 0);
> +
>   		ret = ploop_add_delta(ploop, i, file, is_raw);
>   		if (ret < 0)
>   			goto err_fput;
> @@ -671,11 +683,16 @@ static void ploop_presuspend(struct dm_target *ti)
>   	 * For pending enospc requests. Otherwise,
>   	 * we may never be able to suspend this target.
>   	 */
> +	/* All flushes are done as one */
>   	ploop_set_wants_suspend(ti, true);
>   	flush_work(&ploop->event_work);
>   	del_timer_sync(&ploop->enospc_timer);
> +	wait_event_interruptible(ploop->dispatcher_wq_data,
> +			(!atomic_read(&ploop->kt_worker->inflight_pios)));
> +	vfs_fsync(ploop_top_delta(ploop)->file, 0);
>   	ploop_enospc_timer(&ploop->enospc_timer);
>   }
> +
>   static void ploop_presuspend_undo(struct dm_target *ti)
>   {
>   	ploop_set_wants_suspend(ti, false);


More information about the Devel mailing list