Source-Changes-HG archive

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

[src/trunk]: src/sys - Redo all the ioctl compat stuff to use a standard "ioc...



details:   https://anonhg.NetBSD.org/src/rev/c9377f40fa7a
branches:  trunk
changeset: 839021:c9377f40fa7a
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 05 23:28:02 2019 +0000

description:
- Redo all the ioctl compat stuff to use a standard "ioctl" interface,
  and provide methods to the private softc
- Provide a function for constructing a RF_Raid_t from an RF_Config_t
- Factor out the big inline ioctl code into functions

diffstat:

 sys/dev/raidframe/rf_compat32.c     |  115 +++-
 sys/dev/raidframe/rf_compat32.h     |    4 +-
 sys/dev/raidframe/rf_compat50.c     |   32 +-
 sys/dev/raidframe/rf_compat50.h     |    5 +-
 sys/dev/raidframe/rf_compat50_mod.h |   38 -
 sys/dev/raidframe/rf_compat80.c     |  108 ++++-
 sys/dev/raidframe/rf_compat80.h     |   80 +---
 sys/dev/raidframe/rf_compat80_mod.h |   41 -
 sys/dev/raidframe/rf_netbsd.h       |    7 +-
 sys/dev/raidframe/rf_netbsdkintf.c  |  742 ++++++++++++++++-------------------
 sys/kern/compat_stub.c              |    4 +-
 sys/sys/compat_stub.h               |   16 +-
 12 files changed, 549 insertions(+), 643 deletions(-)

diffs (truncated from 1717 to 300 lines):

diff -r 628dd345acf5 -r c9377f40fa7a sys/dev/raidframe/rf_compat32.c
--- a/sys/dev/raidframe/rf_compat32.c   Tue Feb 05 21:50:10 2019 +0000
+++ b/sys/dev/raidframe/rf_compat32.c   Tue Feb 05 23:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_compat32.c,v 1.2 2019/02/03 08:02:24 pgoyette Exp $ */
+/*     $NetBSD: rf_compat32.c,v 1.3 2019/02/05 23:28:02 christos Exp $ */
 
 /*
  * Copyright (c) 2017 Matthew R. Green
@@ -38,6 +38,7 @@
 #include <dev/raidframe/raidframevar.h>
 
 #include "rf_raid.h"
+#include "rf_kintf.h"
 #include "rf_compat32.h"
 
 #include <compat/netbsd32/netbsd32.h>
@@ -77,58 +78,104 @@
           indicate that configuration should not proceed without user
           intervention
         */
-} RF_Config_t32 ;
+} RF_Config_t32;
 
-int
-rf_config_netbsd32(void *data, RF_Config_t *k_cfg)
+static int
+rf_config_netbsd32(struct raid_softc *rs, void *data)
 {
-       RF_Config_t32 *u_cfg = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
-       struct RF_Config_s32 *cfg32;
+       RF_Config_t32 *u_cfg32 = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
+       RF_Config_t *k_cfg;
+       RF_Config_t32 *k_cfg32;
        int rv;
 
-       RF_Malloc(cfg32, sizeof(RF_Config_t), (RF_Config_t32 *));
-       if (cfg32 == NULL)
-               return (ENOMEM);
+       RF_Malloc(k_cfg32, sizeof(RF_Config_t32), (RF_Config_t32 *));
+       if (k_cfg32 == NULL)
+               return ENOMEM;
+
+       rv = copyin(u_cfg32, k_cfg32, sizeof(RF_Config_t32));
+       if (rv) {
+               RF_Free(k_cfg32, sizeof(RF_Config_t32));
+               return ENOMEM;
+       }
 
-       rv = copyin(u_cfg, cfg32, sizeof(RF_Config_t32));
-       if (rv)
-               goto out;
+       RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
+       if (k_cfg == NULL) {
+               RF_Free(k_cfg32, sizeof(RF_Config_t32));
+               RF_Free(k_cfg, sizeof(RF_Config_t));
+       }
+       k_cfg->numCol = k_cfg32->numCol;
+       k_cfg->numSpare = k_cfg32->numSpare;
+       memcpy(k_cfg->devs, k_cfg32->devs, sizeof(k_cfg->devs));
+       memcpy(k_cfg->devnames, k_cfg32->devnames, sizeof(k_cfg->devnames));
+       memcpy(k_cfg->spare_devs, k_cfg32->spare_devs,
+           sizeof(k_cfg->spare_devs));
+       memcpy(k_cfg->spare_names, k_cfg32->spare_names,
+           sizeof(k_cfg->spare_names));
+       k_cfg->sectPerSU = k_cfg32->sectPerSU;
+       k_cfg->SUsPerPU = k_cfg32->SUsPerPU;
+       k_cfg->SUsPerRU = k_cfg32->SUsPerRU;
+       k_cfg->parityConfig = k_cfg32->parityConfig;
+       memcpy(k_cfg->diskQueueType, k_cfg32->diskQueueType,
+           sizeof(k_cfg->diskQueueType));
+       k_cfg->maxOutstandingDiskReqs = k_cfg32->maxOutstandingDiskReqs;
+       memcpy(k_cfg->debugVars, k_cfg32->debugVars, sizeof(k_cfg->debugVars));
+       k_cfg->layoutSpecificSize = k_cfg32->layoutSpecificSize;
+       k_cfg->layoutSpecific = NETBSD32PTR64(k_cfg32->layoutSpecific);
+       k_cfg->force = k_cfg32->force;
 
-       k_cfg->numCol = cfg32->numCol;
-       k_cfg->numSpare = cfg32->numSpare;
-       memcpy(k_cfg->devs, cfg32->devs, sizeof(k_cfg->devs));
-       memcpy(k_cfg->devnames, cfg32->devnames, sizeof(k_cfg->devnames));
-       memcpy(k_cfg->spare_devs, cfg32->spare_devs, sizeof(k_cfg->spare_devs));
-       memcpy(k_cfg->spare_names, cfg32->spare_names, sizeof(k_cfg->spare_names));
-       k_cfg->sectPerSU = cfg32->sectPerSU;
-       k_cfg->SUsPerPU = cfg32->SUsPerPU;
-       k_cfg->SUsPerRU = cfg32->SUsPerRU;
-       k_cfg->parityConfig = cfg32->parityConfig;
-       memcpy(k_cfg->diskQueueType, cfg32->diskQueueType, sizeof(k_cfg->diskQueueType));
-       k_cfg->maxOutstandingDiskReqs = cfg32->maxOutstandingDiskReqs;
-       memcpy(k_cfg->debugVars, cfg32->debugVars, sizeof(k_cfg->debugVars));
-       k_cfg->layoutSpecificSize = cfg32->layoutSpecificSize;
-       k_cfg->layoutSpecific = NETBSD32PTR64(cfg32->layoutSpecific);
-       k_cfg->force = cfg32->force;
+       return rf_construct(rs, k_cfg);
+}
+
+static int
+rf_get_info_netbsd32(RF_Raid_t *raidPtr, void *data)
+{
+       int retcode;
+       void *ucfgp = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
+
+       RF_DeviceConfig_t *d_cfg;
+       RF_Malloc(d_cfg, sizeof(RF_DeviceConfig_t), (RF_DeviceConfig_t *));
+       if (d_cfg == NULL)
+               return ENOMEM;
 
- out:
-       RF_Free(cfg32, sizeof(RF_Config_t32));
-       return rv;
+       retcode = rf_get_info(raidPtr, d_cfg);
+       if (retcode == 0) {
+           retcode = copyout(d_cfg, ucfgp, sizeof(*d_cfg));
+       }
+       RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
+       return retcode;
 }
 
+static int
+raidframe_netbsd32_ioctl(struct raid_softc *rs, u_long cmd, void *data)
+{
+       RF_Raid_t *raidPtr = rf_get_raid(rs);
+ 
+       switch (cmd) {
+       case RAIDFRAME_GET_INFO32:
+               if (!rf_inited(rs) == 0)
+                       return ENXIO;
+               return rf_get_info_netbsd32(raidPtr, data);
+       case RAIDFRAME_CONFIGURE32:
+               return rf_config_netbsd32(rs, data);
+       default:
+               return EPASSTHROUGH;
+       }
+}
+
+
 static void
 raidframe_netbsd32_init(void)
 {
   
-       MODULE_SET_HOOK(raidframe_netbsd32_config_hook, "raid32",
-           rf_config_netbsd32);
+       MODULE_SET_HOOK(raidframe_netbsd32_ioctl_hook, "raid32",
+           raidframe_netbsd32_ioctl);
 }
  
 static void
 raidframe_netbsd32_fini(void)
 {
  
-       MODULE_UNSET_HOOK(raidframe_netbsd32_config_hook);
+       MODULE_UNSET_HOOK(raidframe_netbsd32_ioctl_hook);
 }
 
 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32");
diff -r 628dd345acf5 -r c9377f40fa7a sys/dev/raidframe/rf_compat32.h
--- a/sys/dev/raidframe/rf_compat32.h   Tue Feb 05 21:50:10 2019 +0000
+++ b/sys/dev/raidframe/rf_compat32.h   Tue Feb 05 23:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_compat32.h,v 1.2 2018/01/20 01:32:45 mrg Exp $      */
+/*     $NetBSD: rf_compat32.h,v 1.3 2019/02/05 23:28:02 christos Exp $ */
 
 /*
  * Copyright (c) 2017 Matthew R. Green
@@ -36,6 +36,4 @@
 #define RAIDFRAME_CONFIGURE32         _IOW ('r',  43, netbsd32_pointer_t)      /* configure the driver */
 #define RAIDFRAME_GET_INFO32          _IOWR('r', 42, netbsd32_pointer_t)       /* get configuration */
 
-int rf_config_netbsd32(void *data, RF_Config_t *k_cfg);
-
 #endif /* _RF_NETBSD32_H_ */
diff -r 628dd345acf5 -r c9377f40fa7a sys/dev/raidframe/rf_compat50.c
--- a/sys/dev/raidframe/rf_compat50.c   Tue Feb 05 21:50:10 2019 +0000
+++ b/sys/dev/raidframe/rf_compat50.c   Tue Feb 05 23:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_compat50.c,v 1.7 2019/02/03 08:02:24 pgoyette Exp $ */
+/*     $NetBSD: rf_compat50.c,v 1.8 2019/02/05 23:28:02 christos Exp $ */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -48,7 +48,6 @@
 
 #include "rf_raid.h"
 #include "rf_compat50.h"
-#include "rf_compat50_mod.h"
 #include "rf_debugMem.h"
 
 typedef struct RF_Config50_s {
@@ -105,17 +104,18 @@
         d50->dev = d->dev;
 }
 
-int
-rf_config50(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
+static int
+rf_config50(struct raid_softc *rs, void *data)
 {
        RF_Config50_t *u50_cfg, *k50_cfg;
        RF_Config_t *k_cfg;
+       RF_Raid_t *raidPtr = rf_get_raid(rs);
        size_t i, j;
        int error;
 
        if (raidPtr->valid) {
                /* There is a valid RAID set running on this unit! */
-               printf("raid%d: Device already configured!\n", unit);
+               printf("raid%d: Device already configured!\n", rf_get_unit(rs));
                return EINVAL;
        }
 
@@ -172,11 +172,10 @@
        k_cfg->force = k50_cfg->force;
 
        RF_Free(k50_cfg, sizeof(RF_Config50_t));
-       *k_cfgp = k_cfg;
-       return 0;
+       return rf_construct(rs, k_cfg);
 }
 
-int
+static int
 rf_get_info50(RF_Raid_t *raidPtr, void *data)
 {
        RF_DeviceConfig50_t **ucfgp = data, *d_cfg;
@@ -219,25 +218,22 @@
        return error;
 }
 
-int
-raidframe_ioctl_50(u_long cmd, int initted, RF_Raid_t *raidPtr, int unit,
-    void *data, RF_Config_t **k_cfg)
+static int
+raidframe_ioctl_50(struct raid_softc *rs, u_long cmd, void *data)
 {
-       int error;
+       RF_Raid_t *raidPtr = rf_get_raid(rs);
 
        switch (cmd) {
        case RAIDFRAME_GET_INFO50:
-               if (initted == 0)
+               if (!rf_inited(rs))
                        return ENXIO;
                return rf_get_info50(raidPtr, data);
 
        case RAIDFRAME_CONFIGURE50:
-               error = rf_config50(raidPtr, unit, data, k_cfg);
-               if (error != 0)
-                       return error;
-               return EAGAIN;  /* flag mainline to call generic config */
+               return rf_config50(rs, data);
+       default:
+               return EPASSTHROUGH;
        }
-       return EPASSTHROUGH;
 }
 
 static void
diff -r 628dd345acf5 -r c9377f40fa7a sys/dev/raidframe/rf_compat50.h
--- a/sys/dev/raidframe/rf_compat50.h   Tue Feb 05 21:50:10 2019 +0000
+++ b/sys/dev/raidframe/rf_compat50.h   Tue Feb 05 23:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_compat50.h,v 1.4 2019/01/31 12:31:50 christos Exp $ */
+/*     $NetBSD: rf_compat50.h,v 1.5 2019/02/05 23:28:02 christos Exp $ */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -44,7 +44,4 @@
 #define RAIDFRAME_CONFIGURE50  _IOW ('r',  1, void *)
 #define RAIDFRAME_GET_INFO50   _IOWR('r', 15, void *)
 
-int rf_config50(RF_Raid_t *, int, void *, RF_Config_t **);
-int rf_get_info50(RF_Raid_t *, void *);
-
 #endif /* _RF_COMPAT50_H_ */
diff -r 628dd345acf5 -r c9377f40fa7a sys/dev/raidframe/rf_compat50_mod.h
--- a/sys/dev/raidframe/rf_compat50_mod.h       Tue Feb 05 21:50:10 2019 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/* $NetBSD: rf_compat50_mod.h,v 1.4 2019/02/03 08:02:24 pgoyette Exp $ */
-
-
-/*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Paul Goyette
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR



Home | Main Index | Thread Index | Old Index