Print this page
OS-90 Kernel should generate events when device gets retired / unretired.
re #13613 rb4516 Tunables needs volatile keyword

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/modctl.c
          +++ new/usr/src/uts/common/os/modctl.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * modctl system call for loadable module support.
  28   29   */
  29   30  
  30   31  #include <sys/param.h>
  31   32  #include <sys/user.h>
  32   33  #include <sys/systm.h>
  33   34  #include <sys/exec.h>
↓ open down ↓ 23 lines elided ↑ open up ↑
  57   58  #include <sys/kobj.h>
  58   59  #include <sys/devops.h>
  59   60  #include <sys/autoconf.h>
  60   61  #include <sys/hwconf.h>
  61   62  #include <sys/callb.h>
  62   63  #include <sys/debug.h>
  63   64  #include <sys/cpuvar.h>
  64   65  #include <sys/sysmacros.h>
  65   66  #include <sys/sysevent.h>
  66   67  #include <sys/sysevent_impl.h>
       68 +#include <sys/sysevent/eventdefs.h>
       69 +#include <sys/sysevent/dev.h>
  67   70  #include <sys/instance.h>
  68   71  #include <sys/modhash.h>
  69   72  #include <sys/modhash_impl.h>
  70   73  #include <sys/dacf_impl.h>
  71   74  #include <sys/vfs.h>
  72   75  #include <sys/pathname.h>
  73   76  #include <sys/console.h>
  74   77  #include <sys/policy.h>
  75   78  #include <ipp/ipp_impl.h>
  76   79  #include <sys/fs/dv_node.h>
↓ open down ↓ 48 lines elided ↑ open up ↑
 125  128  kthread_id_t    mod_aul_thread;
 126  129  
 127  130  int             modunload_wait;
 128  131  kmutex_t        modunload_wait_mutex;
 129  132  kcondvar_t      modunload_wait_cv;
 130  133  int             modunload_active_count;
 131  134  int             modunload_disable_count;
 132  135  
 133  136  int     isminiroot;             /* set if running as miniroot */
 134  137  int     modrootloaded;          /* set after root driver and fs are loaded */
 135      -int     moddebug = 0x0;         /* debug flags for module writers */
      138 +volatile int moddebug = 0x0;    /* debug flags for module writers */
 136  139  int     swaploaded;             /* set after swap driver and fs are loaded */
 137  140  int     bop_io_quiesced = 0;    /* set when BOP I/O can no longer be used */
 138  141  int     last_module_id;
 139  142  clock_t mod_uninstall_interval = 0;
 140  143  int     mod_uninstall_pass_max = 6;
 141  144  int     mod_uninstall_ref_zero; /* # modules that went mod_ref == 0 */
 142  145  int     mod_uninstall_pass_exc; /* mod_uninstall_all left new stuff */
 143  146  
 144  147  int     ddi_modclose_unload = 1;        /* 0 -> just decrement reference */
 145  148  
↓ open down ↓ 814 lines elided ↑ open up ↑
 960  963  
 961  964          for (i = 0, p = constraints; i < n; i++, p += strlen(p) + 1) {
 962  965                  array[i] = i_ddi_strdup(p, KM_SLEEP);
 963  966          }
 964  967          array[n] = NULL;
 965  968  
 966  969          kmem_free(constraints, len);
 967  970  
 968  971          return (array);
 969  972  }
      973 +
      974 +static void
      975 +publish_retire_event(char *path, int retire)
      976 +{
      977 +        sysevent_t *ev;
      978 +        sysevent_id_t eid;
      979 +        sysevent_value_t se_val;
      980 +        sysevent_attr_list_t *ev_attr_list = NULL;
      981 +
      982 +        ev = sysevent_alloc(EC_DEV_STATUS,
      983 +            retire ? ESC_DEV_RETIRE : ESC_DEV_UNRETIRE, EC_DEVFS, SE_SLEEP);
      984 +        if (ev == NULL) {
      985 +                goto fail;
      986 +        }
      987 +
      988 +        se_val.value_type = SE_DATA_TYPE_STRING;
      989 +        se_val.value.sv_string = path;
      990 +
      991 +        if (sysevent_add_attr(&ev_attr_list, DEV_PHYS_PATH,
      992 +            &se_val, SE_SLEEP) != 0) {
      993 +                goto fail;
      994 +        }
      995 +
      996 +        if (sysevent_attach_attributes(ev, ev_attr_list) != 0) {
      997 +                goto fail;
      998 +        }
      999 +
     1000 +        if (log_sysevent(ev, SE_SLEEP, &eid) != 0) {
     1001 +                goto fail;
     1002 +        }
     1003 +
     1004 +        sysevent_free(ev);
     1005 +        return;
     1006 +
     1007 +fail:
     1008 +
     1009 +        cmn_err(CE_WARN, "failed to log device %s event for %s",
     1010 +            retire ? "retire" : "unretire", path);
     1011 +
     1012 +        if (ev_attr_list != NULL) {
     1013 +                sysevent_free_attr(ev_attr_list);
     1014 +        }
     1015 +
     1016 +        sysevent_free(ev);
     1017 +}
     1018 +
 970 1019  /*ARGSUSED*/
 971 1020  static int
 972 1021  modctl_retire(char *path, char *uconstraints, size_t ulen)
 973 1022  {
 974 1023          char    *pathbuf;
 975 1024          char    *devpath;
 976 1025          size_t  pathsz;
 977 1026          int     retval;
 978 1027          char    *constraints;
 979 1028          char    **cons_array;
↓ open down ↓ 60 lines elided ↑ open up ↑
1040 1089          retval = e_ddi_retire_persist(devpath);
1041 1090          if (retval != 0) {
1042 1091                  cmn_err(CE_WARN, "Failed to persist device retire: error %d: "
1043 1092                      "%s", retval, devpath);
1044 1093                  kmem_free(devpath, strlen(devpath) + 1);
1045 1094                  return (retval);
1046 1095          }
1047 1096          if (moddebug & MODDEBUG_RETIRE)
1048 1097                  cmn_err(CE_NOTE, "Persisted retire of device: %s", devpath);
1049 1098  
     1099 +        /* Issue sysevent. */
     1100 +        publish_retire_event(devpath, 1);
     1101 +
1050 1102          kmem_free(devpath, strlen(devpath) + 1);
1051 1103          return (0);
1052 1104  }
1053 1105  
1054 1106  static int
1055 1107  modctl_is_retired(char *path, int *statep)
1056 1108  {
1057 1109          char    *pathbuf;
1058 1110          char    *devpath;
1059 1111          size_t  pathsz;
↓ open down ↓ 77 lines elided ↑ open up ↑
1137 1189                  kmem_free(devpath, strlen(devpath) + 1);
1138 1190                  return (0);
1139 1191          }
1140 1192  
1141 1193          retval = e_ddi_unretire_device(devpath);
1142 1194          if (retval != 0) {
1143 1195                  cmn_err(CE_WARN, "cannot unretire device: error %d, path %s\n",
1144 1196                      retval, devpath);
1145 1197          }
1146 1198  
     1199 +        /* Issue sysevent. */
     1200 +        publish_retire_event(devpath, 0);
     1201 +
1147 1202          kmem_free(devpath, strlen(devpath) + 1);
1148 1203  
1149 1204          return (retval);
1150 1205  }
1151 1206  
1152 1207  static int
1153 1208  modctl_getname(char *uname, uint_t ulen, int *umajorp)
1154 1209  {
1155 1210          char *name;
1156 1211          major_t major;
↓ open down ↓ 3678 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX