Print this page
XXXX Check for uninitialized kernel statistics


1190 
1191         if (ksp->ks_flags & KSTAT_FLAG_DORMANT) {
1192 
1193                 /*
1194                  * We are reactivating a dormant kstat.  Initialize the
1195                  * caller's underlying data to the value it had when the
1196                  * kstat went dormant, and mark the kstat as active.
1197                  * Grab the provider's kstat lock if it's not already held.
1198                  */
1199                 kmutex_t *lp = ksp->ks_lock;
1200                 if (lp != NULL && MUTEX_NOT_HELD(lp)) {
1201                         mutex_enter(lp);
1202                         (void) KSTAT_UPDATE(ksp, KSTAT_WRITE);
1203                         mutex_exit(lp);
1204                 } else {
1205                         (void) KSTAT_UPDATE(ksp, KSTAT_WRITE);
1206                 }
1207                 ksp->ks_flags &= ~KSTAT_FLAG_DORMANT;
1208         }
1209 






































1210         /*
1211          * Now that the kstat is active, make it visible to the kstat driver.
1212          */
1213         ksp->ks_flags &= ~KSTAT_FLAG_INVALID;
1214         kstat_rele(ksp);
1215 }
1216 
1217 /*
1218  * Remove a kstat from the system.  Or, if it's a persistent kstat,
1219  * just update the data and mark it as dormant.
1220  */
1221 void
1222 kstat_delete(kstat_t *ksp)
1223 {
1224         kmutex_t *lp;
1225         ekstat_t *e = (ekstat_t *)ksp;
1226         zoneid_t zoneid;
1227         kstat_zone_t *kz;
1228 
1229         ASSERT(ksp != NULL);




1190 
1191         if (ksp->ks_flags & KSTAT_FLAG_DORMANT) {
1192 
1193                 /*
1194                  * We are reactivating a dormant kstat.  Initialize the
1195                  * caller's underlying data to the value it had when the
1196                  * kstat went dormant, and mark the kstat as active.
1197                  * Grab the provider's kstat lock if it's not already held.
1198                  */
1199                 kmutex_t *lp = ksp->ks_lock;
1200                 if (lp != NULL && MUTEX_NOT_HELD(lp)) {
1201                         mutex_enter(lp);
1202                         (void) KSTAT_UPDATE(ksp, KSTAT_WRITE);
1203                         mutex_exit(lp);
1204                 } else {
1205                         (void) KSTAT_UPDATE(ksp, KSTAT_WRITE);
1206                 }
1207                 ksp->ks_flags &= ~KSTAT_FLAG_DORMANT;
1208         }
1209 
1210 #ifdef DEBUG
1211         /*
1212          * Search for uninitialized kstats.
1213          */
1214         switch (ksp->ks_type) {
1215         case KSTAT_TYPE_NAMED: {
1216                 uint_t i;
1217                 kstat_named_t *knp = KSTAT_NAMED_PTR(ksp);
1218 
1219                 for (i = 0; i < ksp->ks_ndata; i++, knp++) {
1220                         if (knp->data_type > KSTAT_DATA_STRING) {
1221                                 cmn_err(CE_WARN,
1222                                     "kstat_install('%s', %d, '%s'): "
1223                                     "invalid data type",
1224                                     ksp->ks_module, ksp->ks_instance,
1225                                     ksp->ks_name);
1226                         }
1227 
1228                         /*
1229                          * If the name of this kstat is empty
1230                          * we assume it is uninitialized.
1231                          */
1232                         if (knp->name[0] == '\0') {
1233                                 cmn_err(CE_WARN,
1234                                     "kstat_install('%s', %d, '%s'): "
1235                                     "uninitialized kstat",
1236                                     ksp->ks_module, ksp->ks_instance,
1237                                     ksp->ks_name);
1238                         }
1239                 }
1240 
1241                 break;
1242         }
1243         default:
1244                 break;
1245         }
1246 #endif
1247 
1248         /*
1249          * Now that the kstat is active, make it visible to the kstat driver.
1250          */
1251         ksp->ks_flags &= ~KSTAT_FLAG_INVALID;
1252         kstat_rele(ksp);
1253 }
1254 
1255 /*
1256  * Remove a kstat from the system.  Or, if it's a persistent kstat,
1257  * just update the data and mark it as dormant.
1258  */
1259 void
1260 kstat_delete(kstat_t *ksp)
1261 {
1262         kmutex_t *lp;
1263         ekstat_t *e = (ekstat_t *)ksp;
1264         zoneid_t zoneid;
1265         kstat_zone_t *kz;
1266 
1267         ASSERT(ksp != NULL);