0

I am working on a testing tool for nvme-cli(written in c and can run on linux).

For SSD validation purpose, i was actually looking for a custom command(For e.g. I/O command, write and then read the same and finally compare if both the data are same)

For read the ioctl() function is used as shown in the below code.

struct nvme_user_io io = {
    .opcode     = opcode,
    .flags      = 0,
    .control    = control,
    .nblocks    = nblocks,
    .rsvd       = 0,
    .metadata   = (__u64)(uintptr_t) metadata,
    .addr       = (__u64)(uintptr_t) data,
    .slba       = slba,
    .dsmgmt     = dsmgmt,
    .reftag     = reftag,
    .appmask    = appmask,
    .apptag     = apptag,
};
err = ioctl(fd, NVME_IOCTL_SUBMIT_IO, &io);

Can I to where exactly the control of execution goes in order to understand the read.

Also I want to have another command that looks like

err = ioctl(fd,NVME_IOCTL_WRITE_AND_COMPARE_IO, &io);

so that I can internally do a write, then read the same location and finally compare the both data to ensure that the disk contains only the data that I wanted to write.

Since I am new to this nvme/ioctl(), if there is any mistakes please correct me.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Arjun G S
  • 23
  • 13
  • Simple `grep`ing for `NVME_IOCTL_SUBMIT_IO`: given ioctl request is processed in [drivers/nvme/host/core.c](https://elixir.free-electrons.com/linux/latest/source/drivers/nvme/host/core.c#L1042). – Tsyvarev Dec 14 '17 at 07:08
  • @Tsyvarev, Is that I can have a new command by adding a case called NVME_IOCTL_WRITE_AND_COMPARE_IO instead of `case NVME_IOCTL_SUBMIT_IO: return nvme_submit_io(ns, (void __user *)arg);` I dont know if it works. Actually i didn't understand how `ioctl()` function invokes `nvme_ioctl()` I don't know if its a silly question, but since i am new to this, i didn't understand. – Arjun G S Dec 14 '17 at 09:45
  • In short, `nvme_ioctl()` is assigned to the block device, which descriptor you pass to `ioctl()` call in user space. For detailed description read about block devices in linux kernel and writting drivers for them. If you just want to add support for new type of ioctl request, simply do that in `nvme_ioctl` function. – Tsyvarev Dec 14 '17 at 11:58

1 Answers1

0

nvme_io() is a main command handler that accepts as a parameter the NVMe opcode that you want to send to your device. According to the standard, you have separate commands (opcodes) for read, write and compare. You could either send those commands separately, or add a vendor specific command to calculate what you need.

Ora
  • 66
  • 5
  • For SSD validation purpose we are building a tool, I need to write a random pattern to the disk, read it and then compare if the data written in the disk is same as what we actually wanted to write. Since we are writing random pattern we need a custom command which internally sends a write and then read the same. finally we can check the buffer contents to check if we have both the contents same – Arjun G S Dec 18 '17 at 04:36
  • @ArjunGS what do you mean by "internally"? You can run a program that for every block creates a random pattern, saves it, sends it, reads it back and compares it. If you need to do it internally to the disk, you need to implement the code on the SSD device and then you can send your custom command. Maybe the SSD already supports such a command. – Ora Dec 18 '17 at 22:28
  • What I wanted to do is to add a new command to nvme-cli, Write-compare, which does a write,read and then compare. But with `ioctl()` we couldn't do repeat with threading, reason being we need to specify different Submission queue ID which cannot be done by `ioctl()`. SO we want to add something to driver module to that. – Arjun G S Dec 19 '17 at 04:30