linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: Re: [PATCH 2/7] sd: implement ->get_unique_id
Date: Thu, 14 Oct 2021 09:30:51 +0200	[thread overview]
Message-ID: <0a7d87ef-fff2-6a63-8edd-604ad8868dbd@suse.de> (raw)
In-Reply-To: <20211012120445.861860-3-hch@lst.de>

On 10/12/21 2:04 PM, Christoph Hellwig wrote:
> Add the method to query for a uniqueue ID of a given type by looking
> it up in the cached device identification VPD page.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/scsi/sd.c | 37 +++++++++++++++++++++++++++++++++++++
>   1 file changed, 37 insertions(+)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index d8f6add416c0a..ea1489d3e8497 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1757,6 +1757,42 @@ static void sd_rescan(struct device *dev)
>   	sd_revalidate_disk(sdkp->disk);
>   }
>   
> +static int sd_get_unique_id(struct gendisk *disk, u8 id[16], u8 type)
> +{
> +	struct scsi_device *sdev = scsi_disk(disk)->device;
> +	const struct scsi_vpd *vpd;
> +	const unsigned char *d;
> +	int len = -ENXIO;
> +
> +	rcu_read_lock();
> +	vpd = rcu_dereference(sdev->vpd_pg83);
> +	if (!vpd)
> +		goto out_unlock;
> +
> +	len = -EINVAL;
> +	for (d = vpd->data + 4; d < vpd->data + vpd->len; d += d[3] + 4) {
> +		/* we only care about designators with LU association */
> +		if (((d[1] >> 4) & 0x3) != 0x00)
> +			continue;
> +		if ((d[1] & 0xf) != type)
> +			continue;
> +
> +		/*
> +		 * Only exit early if a 16-byte descriptor was found.  Otherwise
> +		 * keep looking as one with more entropy might still show up.
> +		 */
> +		len = d[3];
> +		if (len != 8 && len != 12 && len != 16)
> +			continue;
> +		memcpy(id, d + 4, len);
> +		if (len == 16)
> +			break;
> +	}
> +out_unlock:
> +	rcu_read_unlock();
> +	return len;
> +}
> +
>   static char sd_pr_type(enum pr_type type)
>   {
>   	switch (type) {
> @@ -1861,6 +1897,7 @@ static const struct block_device_operations sd_fops = {
>   	.check_events		= sd_check_events,
>   	.unlock_native_capacity	= sd_unlock_native_capacity,
>   	.report_zones		= sd_zbc_report_zones,
> +	.get_unique_id		= sd_get_unique_id,
>   	.pr_ops			= &sd_pr_ops,
>   };
>   
> 
Errm.

What's wrong with scsi_vpd_lun_id() ?

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

  parent reply	other threads:[~2021-10-14  7:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12 12:04 remove QUEUE_FLAG_SCSI_PASSTHROUGH Christoph Hellwig
2021-10-12 12:04 ` [PATCH 1/7] block: add a ->get_unique_id method Christoph Hellwig
2021-10-12 17:03   ` Bart Van Assche
2021-10-14  7:31   ` Hannes Reinecke
2021-10-12 12:04 ` [PATCH 2/7] sd: implement ->get_unique_id Christoph Hellwig
2021-10-12 13:13   ` Keith Busch
2021-10-14  7:30   ` Hannes Reinecke [this message]
2021-10-14  8:01     ` Christoph Hellwig
2021-10-14  8:03       ` Christoph Hellwig
2021-10-12 12:04 ` [PATCH 3/7] nfsd/blocklayout: use ->get_unique_id instead of sending SCSI commands Christoph Hellwig
2021-10-12 13:06   ` J. Bruce Fields
2021-10-14  7:32   ` Hannes Reinecke
2021-10-12 12:04 ` [PATCH 4/7] bsg-lib: initialize the bsg_job in bsg_transport_sg_io_fn Christoph Hellwig
2021-10-14  7:33   ` Hannes Reinecke
2021-10-12 12:04 ` [PATCH 5/7] scsi: add a scsi_alloc_request helper Christoph Hellwig
2021-10-14  7:37   ` Hannes Reinecke
2021-10-12 12:04 ` [PATCH 6/7] block: remove the initialize_rq_fn blk_mq_ops method Christoph Hellwig
2021-10-14  7:38   ` Hannes Reinecke
2021-10-12 12:04 ` [PATCH 7/7] block: remove QUEUE_FLAG_SCSI_PASSTHROUGH Christoph Hellwig
2021-10-14  7:38   ` Hannes Reinecke
2021-10-19  7:54 remove QUEUE_FLAG_SCSI_PASSTHROUGH v2 Christoph Hellwig
2021-10-19  7:54 ` [PATCH 2/7] sd: implement ->get_unique_id Christoph Hellwig
2021-10-21  6:06 remove QUEUE_FLAG_SCSI_PASSTHROUGH v3 Christoph Hellwig
2021-10-21  6:06 ` [PATCH 2/7] sd: implement ->get_unique_id Christoph Hellwig
2021-10-21 13:34   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a7d87ef-fff2-6a63-8edd-604ad8868dbd@suse.de \
    --to=hare@suse.de \
    --cc=axboe@kernel.dk \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).