Re: [PATCH 8/8] scsi: Introduce ZBC disk I/O scheduler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2017-09-01 at 20:36 +0900, Damien Le Moal wrote:
> +static struct scsi_disk *__zoned_scsi_disk(struct request_queue *q)
> +{
> +       struct scsi_device *sdp;
> +       struct scsi_disk *sdkp;
> +
> +       if (!blk_queue_is_zoned(q)) {
> +               pr_err("zoned: Not a zoned block device\n");
> +               return NULL;
> +       }
> +
> +       sdp = scsi_device_from_queue(q);
> +       if (!sdp) {
> +               pr_err("zoned: Not a SCSI device\n");
> +               return NULL;
> +       }
> +
> +       sdkp = dev_get_drvdata(&sdp->sdev_gendev);
> +       if (WARN_ON(sdkp->disk->queue != q))
> +               return NULL;
> +
> +       return sdkp;
> +}

Hello Damien,

Can reading sdkp->disk->queue cause a kernel crash if sdp does not point at
a SCSI device that is associated with a SCSI disk? How about using something
like the code below to convert a request queue pointer into a SCSI disk
pointer?

static int lookup_disk(struct device *dev, void *data)
{
	struct scsi_disk **sdkp = data;

	if (!*sdkp && dev->class == &sd_disk_class)
		*sdkp = to_scsi_disk(dev);

	return 0;
}

static struct scsi_disk *q_to_sdkp(struct request_queue *q)
{
	struct scsi_device *sdp = scsi_device_from_queue(q);
	struct scsi_disk *sdkp = NULL;

	if (sdp)
		device_for_each_child(&sdp->sdev_gendev, &sdkp, lookup_disk);
	return sdkp;
}

Thanks,

Bart.




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux