Skip to content

Commit 18f03a0

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
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: Christoph Hellwig <[email protected]> Acked-by: Chuck Lever <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent f227345 commit 18f03a0

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

drivers/nvme/host/core.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,32 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
22852285
return ret;
22862286
}
22872287

2288+
int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
2289+
enum blk_unique_id type)
2290+
{
2291+
struct nvme_ns_ids *ids = &ns->head->ids;
2292+
2293+
if (type != BLK_UID_EUI64)
2294+
return -EINVAL;
2295+
2296+
if (memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) {
2297+
memcpy(id, &ids->nguid, sizeof(ids->nguid));
2298+
return sizeof(ids->nguid);
2299+
}
2300+
if (memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) {
2301+
memcpy(id, &ids->eui64, sizeof(ids->eui64));
2302+
return sizeof(ids->eui64);
2303+
}
2304+
2305+
return -EINVAL;
2306+
}
2307+
2308+
static int nvme_get_unique_id(struct gendisk *disk, u8 id[16],
2309+
enum blk_unique_id type)
2310+
{
2311+
return nvme_ns_get_unique_id(disk->private_data, id, type);
2312+
}
2313+
22882314
#ifdef CONFIG_BLK_SED_OPAL
22892315
static int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
22902316
bool send)
@@ -2340,6 +2366,7 @@ const struct block_device_operations nvme_bdev_ops = {
23402366
.open = nvme_open,
23412367
.release = nvme_release,
23422368
.getgeo = nvme_getgeo,
2369+
.get_unique_id = nvme_get_unique_id,
23432370
.report_zones = nvme_report_zones,
23442371
.pr_ops = &nvme_pr_ops,
23452372
};

drivers/nvme/host/multipath.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,21 @@ static void nvme_ns_head_release(struct gendisk *disk)
488488
nvme_put_ns_head(disk->private_data);
489489
}
490490

491+
static int nvme_ns_head_get_unique_id(struct gendisk *disk, u8 id[16],
492+
enum blk_unique_id type)
493+
{
494+
struct nvme_ns_head *head = disk->private_data;
495+
struct nvme_ns *ns;
496+
int srcu_idx, ret = -EWOULDBLOCK;
497+
498+
srcu_idx = srcu_read_lock(&head->srcu);
499+
ns = nvme_find_path(head);
500+
if (ns)
501+
ret = nvme_ns_get_unique_id(ns, id, type);
502+
srcu_read_unlock(&head->srcu, srcu_idx);
503+
return ret;
504+
}
505+
491506
#ifdef CONFIG_BLK_DEV_ZONED
492507
static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector,
493508
unsigned int nr_zones, report_zones_cb cb, void *data)
@@ -515,6 +530,7 @@ const struct block_device_operations nvme_ns_head_ops = {
515530
.ioctl = nvme_ns_head_ioctl,
516531
.compat_ioctl = blkdev_compat_ptr_ioctl,
517532
.getgeo = nvme_getgeo,
533+
.get_unique_id = nvme_ns_head_get_unique_id,
518534
.report_zones = nvme_ns_head_report_zones,
519535
.pr_ops = &nvme_pr_ops,
520536
};

drivers/nvme/host/nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,9 @@ static inline bool nvme_disk_is_ns_head(struct gendisk *disk)
10591059
}
10601060
#endif /* CONFIG_NVME_MULTIPATH */
10611061

1062+
int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
1063+
enum blk_unique_id type);
1064+
10621065
struct nvme_zone_info {
10631066
u64 zone_size;
10641067
unsigned int max_open_zones;

0 commit comments

Comments
 (0)