[Devel] [PATCH RH9 v2 8/8] dm/dm-ploop: add llseek_hole

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Aug 21 20:24:41 MSK 2023


On 16.08.23 12:32, Andrey Zhadchenko wrote:
> Implement find_hole() for dm-ploop target.
> Iterate over clusters until we find hole or data by using
> ploop_bat_entries() which will do all our work
> 
> Feature: dm: implement SEEK_HOLE for dm-qcow2 and dm-ploop
> https://jira.vzint.dev/browse/PSBM-145746
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
> ---
>   drivers/md/dm-ploop-map.c    | 50 ++++++++++++++++++++++++++++++++++++
>   drivers/md/dm-ploop-target.c |  1 +
>   drivers/md/dm-ploop.h        |  1 +
>   3 files changed, 52 insertions(+)
> 
> diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
> index 3f0803cb8e47..6fa146f8fe9a 100644
> --- a/drivers/md/dm-ploop-map.c
> +++ b/drivers/md/dm-ploop-map.c
> @@ -1989,3 +1989,53 @@ int ploop_prepare_reloc_index_wb(struct ploop *ploop,
>   	return err;
>   }
>   ALLOW_ERROR_INJECTION(ploop_prepare_reloc_index_wb, ERRNO);
> +
> +loff_t ploop_llseek_hole(struct dm_target *ti, loff_t offset, int whence)
> +{
> +	struct ploop *ploop = ti->private;
> +	u32 clu, dst_clu;
> +	loff_t result;
> +
> +	clu = SEC_TO_CLU(ploop, to_sector(offset) + ploop->skip_off);
> +
> +	while (clu < ploop->nr_bat_entries) {
> +
> +		/*
> +		 * Assume a locked cluster to have a data.
> +		 * In worst case someone will read zeroes
> +		 */
> +		if (ploop_postpone_if_cluster_locked(ploop, NULL, clu)) {
> +			if (whence & SEEK_DATA)
> +				break;
> +			if (whence & SEEK_HOLE) {
> +				clu++;
> +				continue;
> +			}
> +		}
> +
> +		/*
> +		 * It *may* be possible to speed this up by iterating over clusters
> +		 * in mapped metadata page, but this is a bit problematic
> +		 * since we want to check if cluster is locked
> +		 */
> +		dst_clu = ploop_bat_entries(ploop, clu, NULL, NULL);
> +
> +		if (whence & SEEK_DATA && dst_clu != BAT_ENTRY_NONE)
> +			break;
> +		if (whence & SEEK_HOLE && dst_clu == BAT_ENTRY_NONE)
> +			break;
> +
> +		clu++;
> +	}
> +
> +	result = to_bytes(CLU_TO_SEC(ploop, clu) - ploop->skip_off);
> +	if (result < offset)
> +		result = offset;
> +
> +	if (clu >= ploop->nr_bat_entries) {
> +		if (whence & SEEK_DATA)
> +			result = -ENXIO;

What about SEEK_HOLE error here  ?

-- 
Regards,
Alexander Atanasov



More information about the Devel mailing list