Author: mav
Date: Tue Aug 13 19:23:45 2019
New Revision: 350996
URL: https://svnweb.freebsd.org/changeset/base/350996

Log:
  MFC kernel part of r350523, r350524, r350961:
  Add IOCTL to translate nvdX into nvmeY and NSID.
  
  While very useful by itself, it also makes `nvmecontrol` not depend on
  hardcoded device names parsing, that in its turn makes simple to take
  nvdX (and potentially any other) device names as arguments.
  
  Also added IOCTL bypass from nvdX to respective nvmeYnsZ makes them
  interchangeable for management purposes.

Modified:
  stable/11/sys/dev/nvme/nvme.h
  stable/11/sys/dev/nvme/nvme_ctrlr.c
  stable/11/sys/dev/nvme/nvme_ns.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/nvme/nvme.h
==============================================================================
--- stable/11/sys/dev/nvme/nvme.h       Tue Aug 13 19:17:44 2019        
(r350995)
+++ stable/11/sys/dev/nvme/nvme.h       Tue Aug 13 19:23:45 2019        
(r350996)
@@ -37,6 +37,7 @@
 
 #define        NVME_PASSTHROUGH_CMD            _IOWR('n', 0, struct 
nvme_pt_command)
 #define        NVME_RESET_CONTROLLER           _IO('n', 1)
+#define        NVME_GET_NSID                   _IOR('n', 2, struct 
nvme_get_nsid)
 
 #define        NVME_IO_TEST                    _IOWR('n', 100, struct 
nvme_io_test)
 #define        NVME_BIO_TEST                   _IOWR('n', 101, struct 
nvme_io_test)
@@ -1047,6 +1048,11 @@ struct nvme_pt_command {
        struct mtx *            driver_lock;
 };
 
+struct nvme_get_nsid {
+       char            cdev[SPECNAMELEN + 1];
+       uint32_t        nsid;
+};
+
 #define nvme_completion_is_error(cpl)                                  \
        ((cpl)->status.sc != 0 || (cpl)->status.sct != 0)
 
@@ -1055,6 +1061,7 @@ void      nvme_strvis(uint8_t *dst, const uint8_t *src, 
int
 #ifdef _KERNEL
 
 struct bio;
+struct thread;
 
 struct nvme_namespace;
 struct nvme_controller;
@@ -1137,6 +1144,8 @@ uint32_t  nvme_ns_get_stripesize(struct nvme_namespace 
 
 int    nvme_ns_bio_process(struct nvme_namespace *ns, struct bio *bp,
                            nvme_cb_fn_t cb_fn);
+int    nvme_ns_ioctl_process(struct nvme_namespace *ns, u_long cmd,
+    caddr_t arg, int flag, struct thread *td);
 
 /*
  * Command building helper functions -- shared with CAM

Modified: stable/11/sys/dev/nvme/nvme_ctrlr.c
==============================================================================
--- stable/11/sys/dev/nvme/nvme_ctrlr.c Tue Aug 13 19:17:44 2019        
(r350995)
+++ stable/11/sys/dev/nvme/nvme_ctrlr.c Tue Aug 13 19:23:45 2019        
(r350996)
@@ -1047,6 +1047,14 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_
                pt = (struct nvme_pt_command *)arg;
                return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, pt->cmd.nsid,
                    1 /* is_user_buffer */, 1 /* is_admin_cmd */));
+       case NVME_GET_NSID:
+       {
+               struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg;
+               strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev),
+                   sizeof(gnsid->cdev));
+               gnsid->nsid = 0;
+               break;
+       }
        default:
                return (ENOTTY);
        }

Modified: stable/11/sys/dev/nvme/nvme_ns.c
==============================================================================
--- stable/11/sys/dev/nvme/nvme_ns.c    Tue Aug 13 19:17:44 2019        
(r350995)
+++ stable/11/sys/dev/nvme/nvme_ns.c    Tue Aug 13 19:23:45 2019        
(r350996)
@@ -80,6 +80,14 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t a
                pt = (struct nvme_pt_command *)arg;
                return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, ns->id, 
                    1 /* is_user_buffer */, 0 /* is_admin_cmd */));
+       case NVME_GET_NSID:
+       {
+               struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg;
+               strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev),
+                   sizeof(gnsid->cdev));
+               gnsid->nsid = ns->id;
+               break;
+       }
        case DIOCGMEDIASIZE:
                *(off_t *)arg = (off_t)nvme_ns_get_size(ns);
                break;
@@ -466,6 +474,13 @@ nvme_ns_bio_process(struct nvme_namespace *ns, struct 
        }
 
        return (err);
+}
+
+int
+nvme_ns_ioctl_process(struct nvme_namespace *ns, u_long cmd, caddr_t arg,
+    int flag, struct thread *td)
+{
+       return (nvme_ns_ioctl(ns->cdev, cmd, arg, flag, td));
 }
 
 int
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to