[Devel] [PATCH vz9] dm-ploop: add message to dump BAT page to kernel messages

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Fri Jun 21 13:46:21 MSK 2024


Maybe we also need to print bat_levels here? In case there is more then 
one image inserted

And just to be sure, could you clarify that pages a never deleted 
(unless device is destroyed), so we won't crash after ploop_md_page_find()?

On 5/20/24 13:51, Alexander Atanasov wrote:
> In case we need to debug in memory BAT state add interface
> to dump it to kernel log
> 
> https://virtuozzo.atlassian.net/browse/PSBM-156565
> Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
> ---
>   drivers/md/dm-ploop-cmd.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
> index 71f854c509f82..2fe75198da949 100644
> --- a/drivers/md/dm-ploop-cmd.c
> +++ b/drivers/md/dm-ploop-cmd.c
> @@ -564,6 +564,28 @@ void ploop_free_pio_with_pages(struct ploop *ploop, struct pio *pio)
>   	kfree(pio);
>   }
>   
> +static void hexdump8(unsigned char *buf, unsigned int len)
> +{
> +	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
> +			16, 1,
> +			buf, len, false);
> +}
> +
> +static int ploop_dump_page_nr(struct ploop *ploop, unsigned int page_nr)
> +{
> +	struct md_page *md;
> +	unsigned char *data;
> +
> +	md = ploop_md_page_find(ploop, page_nr);
> +	if (!md)
> +		return -EIO;
> +
> +	data = kmap(md->page);
> +	hexdump8(data, PAGE_SIZE);
> +	kunmap(md->page);
> +	return 0;
> +}
> +
>   /* @new_size is in sectors */
>   /* TODO: we may delegate this to userspace */
>   static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
> @@ -1245,6 +1267,10 @@ int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
>   		if (argc != 1)
>   			goto unlock;
>   		ret = ploop_write_bat_to_file(ploop);
> +	} else if (!strcmp(argv[0], "dump_bat_page")) {
> +		if (argc != 2 || kstrtou64(argv[1], 10, &val) < 0)
> +			goto unlock;
> +		ret = ploop_dump_page_nr(ploop, val);
>   	} else {
>   		ret = -ENOTSUPP;
>   	}

Best regards,
Andrey


More information about the Devel mailing list