Skip to content

Commit b715f3d

Browse files
committed
nvme: allow mmap_registers from block device
Below commands that use mmap_registers failed since a31081a (v2.9) nvme show-regs /dev/nvme0n1 nvme effects-log /dev/nvme0n1 Signed-off-by: Steven Seungcheol Lee <[email protected]>
1 parent 62208bb commit b715f3d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

nvme.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5555,14 +5555,24 @@ static int nvme_get_properties(int fd, void **pbar, struct get_reg_config *cfg)
55555555
static void *mmap_registers(struct nvme_dev *dev, bool writable)
55565556
{
55575557
char path[512];
5558+
char link_path[512] = {0};
55585559
void *membase;
55595560
int fd;
55605561
int prot = PROT_READ;
55615562

55625563
if (writable)
55635564
prot |= PROT_WRITE;
55645565

5565-
sprintf(path, "/sys/class/nvme/%s/device/resource0", dev->name);
5566+
if (is_blkdev(dev)) {
5567+
sprintf(path, "/sys/block/%s/device", dev->name);
5568+
if (readlink(path, link_path, sizeof(link_path)) != -1) {
5569+
sprintf(path, "/sys/class/nvme/%s/device/resource0",
5570+
basename(link_path));
5571+
}
5572+
} else {
5573+
sprintf(path, "/sys/class/nvme/%s/device/resource0", dev->name);
5574+
}
5575+
55665576
fd = open(path, writable ? O_RDWR : O_RDONLY);
55675577
if (fd < 0) {
55685578
if (log_level >= LOG_INFO)

0 commit comments

Comments
 (0)