0

I am writing a module in which I am accessing the nvme device using major and minor number.

The code for the function is

src_disk = get_gendisk(MKDEV(si->src_major, si->src_minor), &part);
my_nvme_ns = (struct nvme_ns *)src_disk->private_data;

for (i = 0; i <= 15; i++)
{
    printk(KERN_CONT "%02x", my_nvme_ns->head.ids.nvme_ns_ids.nguid[i]);
}

Now, when I try to acces my_nvme_ns, it fails with error

error: dereferencing pointer to incomplete type ‘struct nvme_ns’
         printk(KERN_CONT "%02x", my_nvme_ns->head.ids.nvme_ns_ids.nguid[i]);

I have included all the relevant files, including

#include <linux/nvme.h>
#include <linux/nvme_ioctl.h>
#include <linux/types.h>

Using kernel 5.0.0

what am I missing here?

Haris
  • 12,120
  • 6
  • 43
  • 70
  • Please, add kernel version into the question post. – Tsyvarev Oct 07 '19 at 11:42
  • 1
    E.g. in Linux kernel version 5.3.4 `my_nvme_ns` structure is defined in [drivers/nvme/host/nvme.h](https://elixir.bootlin.com/linux/v5.3.4/source/drivers/nvme/host/nvme.h#L333). This header is local to the driver and cannot (should not) be accessed outside. – Tsyvarev Oct 07 '19 at 11:48
  • 1
    You simple trying to utilize wrong API. You have to found the one for in-kernel use (outside of the NVMe framework). – 0andriy Oct 07 '19 at 18:35
  • @Tsyvarev, true.. In 5.0.0 also, its in the same file. So does that mean, I will not be able to manipulate those structures for a particular namespace from my module? – Haris Oct 07 '19 at 22:07
  • @Tsyvarev what will be my alternate here? – Haris Oct 07 '19 at 22:08
  • "what will be my alternate here?" - It depends what do you **actually** want to do with nvme device. Note, that Linux kernel programming is intended mostly for providing different "drivers". If you just want to get information about some driver, then use ioctl or other interfaces provided for user-space application. – Tsyvarev Oct 07 '19 at 22:58
  • @Tsyvarev, I want more than just to get information.. I wanted to modify it at will, through the kernel module.. – Haris Oct 08 '19 at 03:08
  • @0andriy, I could not find anything else.. Do you happen to know? – Haris Oct 08 '19 at 03:09

0 Answers0