Re: [PATCH 15/20] block, blksnap: snapshot image block device

Christoph Hellwig
2022-07-06T13:14:01Z

> +#include <linux/cdrom.h>

What do you need this for?

> +static int new_minor(int *minor, void *ptr)
> +{
> + int ret;
> +
> + idr_preload(GFP_KERNEL);
> + spin_lock(&_minor_lock);
> +
> + ret = idr_alloc(&_minor_idr, ptr, 0, 1 << MINORBITS, GFP_NOWAIT);
> +
> + spin_unlock(&_minor_lock);
> + idr_preload_end();
> +
> + if (ret < 0)
> + return ret;
> +
> + *minor = ret;
> + return 0;
> +}

alloc_disk not automatically allocates minors for you if you don't
set the ->major and ->first_minor fields, which could simply this
a lot.

> +static int snapimage_init_request(struct blk_mq_tag_set *set,
> + struct request *rq, unsigned int hctx_idx,
> + unsigned int numa_node)
> +{
> + struct snapimage_cmd *cmd = blk_mq_rq_to_pdu(rq);
> +
> + kthread_init_work(&cmd->work, snapimage_queue_work);
> + return 0;
> +}

I'm a little confused on why this both has a blk-mq interface and
the new bio filter interface. Whow is going to submit I/O to this
blk-mq interface?

> + //.open = snapimage_open,
> + //.ioctl = snapimage_ioctl,
> + //.release = snapimage_close,

Please don't leave commented out code around.