Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Create a per-device state for iscsi(4), effectively maki...



details:   https://anonhg.NetBSD.org/src/rev/02bf5ff8c67f
branches:  trunk
changeset: 338579:02bf5ff8c67f
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sat May 30 20:09:47 2015 +0000

description:
Create a per-device state for iscsi(4), effectively making it a cloning
device.

diffstat:

 sys/dev/iscsi/iscsi_globals.h |   8 ++++++--
 sys/dev/iscsi/iscsi_ioctl.c   |   5 +++--
 sys/dev/iscsi/iscsi_main.c    |  32 ++++++++++++++++++++++++++------
 sys/sys/file.h                |   4 +++-
 4 files changed, 38 insertions(+), 11 deletions(-)

diffs (140 lines):

diff -r c038f92f80ae -r 02bf5ff8c67f sys/dev/iscsi/iscsi_globals.h
--- a/sys/dev/iscsi/iscsi_globals.h     Sat May 30 19:14:46 2015 +0000
+++ b/sys/dev/iscsi/iscsi_globals.h     Sat May 30 20:09:47 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_globals.h,v 1.12 2015/05/30 18:12:09 joerg Exp $ */
+/*     $NetBSD: iscsi_globals.h,v 1.13 2015/05/30 20:09:47 joerg Exp $ */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -500,6 +500,10 @@
 TAILQ_HEAD(event_handler_list_s, event_handler_s);
 typedef struct event_handler_list_s event_handler_list_t;
 
+/* /dev/iscsi0 state */
+struct iscsifd {
+       char dummy;
+};
 
 /* -------------------------  Global Variables  ----------------------------- */
 
@@ -648,7 +652,7 @@
 uint32_t map_databuf(struct proc *, void **, uint32_t);
 void unmap_databuf(struct proc *, void *, uint32_t);
 #endif
-int iscsiioctl(dev_t, u_long, void *, int, struct lwp *);
+int iscsiioctl(struct file *, u_long, void *);
 
 session_t *find_session(uint32_t);
 connection_t *find_connection(session_t *, uint32_t);
diff -r c038f92f80ae -r 02bf5ff8c67f sys/dev/iscsi/iscsi_ioctl.c
--- a/sys/dev/iscsi/iscsi_ioctl.c       Sat May 30 19:14:46 2015 +0000
+++ b/sys/dev/iscsi/iscsi_ioctl.c       Sat May 30 20:09:47 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_ioctl.c,v 1.11 2015/05/30 18:09:31 joerg Exp $   */
+/*     $NetBSD: iscsi_ioctl.c,v 1.12 2015/05/30 20:09:47 joerg Exp $   */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -1593,8 +1593,9 @@
  */
 
 int
-iscsiioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
+iscsiioctl(struct file *fp, u_long cmd, void *addr)
 {
+       struct lwp *l = curlwp;
 
        DEB(1, ("ISCSI Ioctl cmd = %x\n", (int) cmd));
 
diff -r c038f92f80ae -r 02bf5ff8c67f sys/dev/iscsi/iscsi_main.c
--- a/sys/dev/iscsi/iscsi_main.c        Sat May 30 19:14:46 2015 +0000
+++ b/sys/dev/iscsi/iscsi_main.c        Sat May 30 20:09:47 2015 +0000
@@ -32,6 +32,8 @@
 
 #include <sys/systm.h>
 #include <sys/buf.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
 #include <sys/kmem.h>
 #include <sys/socketvar.h>
 
@@ -83,14 +85,19 @@
 
 
 static dev_type_open(iscsiopen);
-static dev_type_close(iscsiclose);
+static int iscsiclose(struct file *);
+
+static const struct fileops iscsi_fileops = {
+       .fo_ioctl = iscsiioctl,
+       .fo_close = iscsiclose,
+};
 
 struct cdevsw iscsi_cdevsw = {
        .d_open = iscsiopen,
-       .d_close = iscsiclose,
+       .d_close = noclose,
        .d_read = noread,
        .d_write = nowrite,
-       .d_ioctl = iscsiioctl,
+       .d_ioctl = noioctl,
        .d_stop = nostop,
        .d_tty = notty,
        .d_poll = nopoll,
@@ -119,14 +126,27 @@
 int
 iscsiopen(dev_t dev, int flag, int mode, struct lwp *l)
 {
+       struct iscsifd *d;
+       struct file *fp;
+       int error, fd;
 
        DEB(99, ("ISCSI Open\n"));
-       return 0;
+
+       if ((error = fd_allocfile(&fp, &fd)) != 0)
+               return error;
+
+       d = kmem_alloc(sizeof(*d), KM_SLEEP);
+
+       return fd_clone(fp, fd, flag, &iscsi_fileops, d);
 }
 
-int
-iscsiclose(dev_t dev, int flag, int mode, struct lwp *l)
+static int
+iscsiclose(struct file *fp)
 {
+       struct iscsifd *d = fp->f_iscsi;
+
+       kmem_free(d, sizeof(*d));
+       fp->f_iscsi = NULL;
 
        DEB(99, ("ISCSI Close\n"));
        return 0;
diff -r c038f92f80ae -r 02bf5ff8c67f sys/sys/file.h
--- a/sys/sys/file.h    Sat May 30 19:14:46 2015 +0000
+++ b/sys/sys/file.h    Sat May 30 20:09:47 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file.h,v 1.78 2014/12/14 23:48:58 chs Exp $    */
+/*     $NetBSD: file.h,v 1.79 2015/05/30 20:09:47 joerg Exp $  */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -108,6 +108,7 @@
        struct fcrypt *fd_fcrypt;       // DTYPE_CRYPTO is not used
        struct mqueue *fd_mq;           // DTYPE_MQUEUE
        struct ksem *fd_ks;             // DTYPE_SEM
+       struct iscsifd *fd_iscsi;       // DTYPE_MISC (iscsi)
 };
 
 /*
@@ -146,6 +147,7 @@
 #define f_devunit      f_undata.fd_devunit
 #define f_bpf          f_undata.fd_bpf
 #define f_fcrypt       f_undata.fd_fcrypt
+#define f_iscsi                f_undata.fd_iscsi
 #endif
 
 /*



Home | Main Index | Thread Index | Old Index