Commit 18f03a06 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Keith Busch

nvme: implement ->get_unique_id

Implement the get_unique_id method to allow pNFS SCSI layout access to
NVMe namespaces.

This is the server side implementation of RFC 9561 "Using the Parallel
NFS (pNFS) SCSI Layout to Access Non-Volatile Memory Express (NVMe)
Storage Devices".
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChuck Lever <chuck.lever@oracle.com>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent f227345f
...@@ -2285,6 +2285,32 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) ...@@ -2285,6 +2285,32 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
return ret; return ret;
} }
int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
enum blk_unique_id type)
{
struct nvme_ns_ids *ids = &ns->head->ids;
if (type != BLK_UID_EUI64)
return -EINVAL;
if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) {
memcpy(id, &ids->nguid, sizeof(ids->nguid));
return sizeof(ids->nguid);
}
if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) {
memcpy(id, &ids->eui64, sizeof(ids->eui64));
return sizeof(ids->eui64);
}
return -EINVAL;
}
static int nvme_get_unique_id(struct gendisk *disk, u8 id[16],
enum blk_unique_id type)
{
return nvme_ns_get_unique_id(disk->private_data, id, type);
}
#ifdef CONFIG_BLK_SED_OPAL #ifdef CONFIG_BLK_SED_OPAL
static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len, static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
bool send) bool send)
...@@ -2340,6 +2366,7 @@ const struct block_device_operations nvme_bdev_ops = { ...@@ -2340,6 +2366,7 @@ const struct block_device_operations nvme_bdev_ops = {
.open = nvme_open, .open = nvme_open,
.release = nvme_release, .release = nvme_release,
.getgeo = nvme_getgeo, .getgeo = nvme_getgeo,
.get_unique_id = nvme_get_unique_id,
.report_zones = nvme_report_zones, .report_zones = nvme_report_zones,
.pr_ops = &nvme_pr_ops, .pr_ops = &nvme_pr_ops,
}; };
......
...@@ -488,6 +488,21 @@ static void nvme_ns_head_release(struct gendisk *disk) ...@@ -488,6 +488,21 @@ static void nvme_ns_head_release(struct gendisk *disk)
nvme_put_ns_head(disk->private_data); nvme_put_ns_head(disk->private_data);
} }
static int nvme_ns_head_get_unique_id(struct gendisk *disk, u8 id[16],
enum blk_unique_id type)
{
struct nvme_ns_head *head = disk->private_data;
struct nvme_ns *ns;
int srcu_idx, ret = -EWOULDBLOCK;
srcu_idx = srcu_read_lock(&head->srcu);
ns = nvme_find_path(head);
if (ns)
ret = nvme_ns_get_unique_id(ns, id, type);
srcu_read_unlock(&head->srcu, srcu_idx);
return ret;
}
#ifdef CONFIG_BLK_DEV_ZONED #ifdef CONFIG_BLK_DEV_ZONED
static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector, static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data) unsigned int nr_zones, report_zones_cb cb, void *data)
...@@ -515,6 +530,7 @@ const struct block_device_operations nvme_ns_head_ops = { ...@@ -515,6 +530,7 @@ const struct block_device_operations nvme_ns_head_ops = {
.ioctl = nvme_ns_head_ioctl, .ioctl = nvme_ns_head_ioctl,
.compat_ioctl = blkdev_compat_ptr_ioctl, .compat_ioctl = blkdev_compat_ptr_ioctl,
.getgeo = nvme_getgeo, .getgeo = nvme_getgeo,
.get_unique_id = nvme_ns_head_get_unique_id,
.report_zones = nvme_ns_head_report_zones, .report_zones = nvme_ns_head_report_zones,
.pr_ops = &nvme_pr_ops, .pr_ops = &nvme_pr_ops,
}; };
......
...@@ -1059,6 +1059,9 @@ static inline bool nvme_disk_is_ns_head(struct gendisk *disk) ...@@ -1059,6 +1059,9 @@ static inline bool nvme_disk_is_ns_head(struct gendisk *disk)
} }
#endif /* CONFIG_NVME_MULTIPATH */ #endif /* CONFIG_NVME_MULTIPATH */
int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
enum blk_unique_id type);
struct nvme_zone_info { struct nvme_zone_info {
u64 zone_size; u64 zone_size;
unsigned int max_open_zones; unsigned int max_open_zones;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment