Whamcloud - gitweb
LU-5397 obdclass: optimize busy loop wait
[fs/lustre-release.git] / lustre / obdclass / obd_config.c
index d81a9a7..3914193 100644 (file)
@@ -414,7 +414,7 @@ int class_attach(struct lustre_cfg *lcfg)
        CFS_INIT_LIST_HEAD(&obd->obd_evict_list);
        INIT_LIST_HEAD(&obd->obd_lwp_list);
 
-        llog_group_init(&obd->obd_olg, FID_SEQ_LLOG);
+       llog_group_init(&obd->obd_olg);
 
        obd->obd_conn_inprogress = 0;
 
@@ -426,13 +426,6 @@ int class_attach(struct lustre_cfg *lcfg)
         }
         memcpy(obd->obd_uuid.uuid, uuid, len);
 
-        /* do the attach */
-        if (OBP(obd, attach)) {
-                rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
-                if (rc)
-                        GOTO(out, rc = -EINVAL);
-        }
-
         /* Detach drops this */
        spin_lock(&obd->obd_dev_lock);
        atomic_set(&obd->obd_refcount, 1);
@@ -631,16 +624,12 @@ int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
        }
        /* Leave this on forever */
        obd->obd_stopping = 1;
+       spin_unlock(&obd->obd_dev_lock);
 
        /* wait for already-arrived-connections to finish. */
-       while (obd->obd_conn_inprogress > 0) {
-               spin_unlock(&obd->obd_dev_lock);
-
-               cond_resched();
-
-               spin_lock(&obd->obd_dev_lock);
-       }
-       spin_unlock(&obd->obd_dev_lock);
+       while (obd->obd_conn_inprogress > 0)
+               yield();
+       smp_rmb();
 
         if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
                 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
@@ -759,11 +748,7 @@ void class_decref(struct obd_device *obd, const char *scope, const void *source)
                                 CERROR("Cleanup %s returned %d\n",
                                        obd->obd_name, err);
                 }
-                if (OBP(obd, detach)) {
-                        err = OBP(obd, detach)(obd);
-                        if (err)
-                                CERROR("Detach returned %d\n", err);
-                }
+
                 class_release_dev(obd);
         }
 }
@@ -1472,6 +1457,42 @@ extern int lustre_check_exclusion(struct super_block *sb, char *svname);
 #define lustre_check_exclusion(a,b)  0
 #endif
 
+/*
+ * Supplemental functions for config logs, it allocates lustre_cfg
+ * buffers plus initialized llog record header at the beginning.
+ */
+struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
+{
+       struct llog_cfg_rec     *lcr;
+       int                      reclen;
+
+       ENTRY;
+
+       reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
+       reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
+                sizeof(struct llog_rec_tail);
+
+       OBD_ALLOC(lcr, reclen);
+       if (lcr == NULL)
+               RETURN(NULL);
+
+       lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
+
+       lcr->lcr_hdr.lrh_len = reclen;
+       lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
+
+       RETURN(lcr);
+}
+EXPORT_SYMBOL(lustre_cfg_rec_new);
+
+void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
+{
+       ENTRY;
+       OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
+       EXIT;
+}
+EXPORT_SYMBOL(lustre_cfg_rec_free);
+
 /** Parse a configuration llog, doing various manipulations on them
  * for various reasons, (modifications for compatibility, skip obsolete
  * records, change uuids, etc), then class_process_config() resulting
@@ -1654,6 +1675,8 @@ int class_config_llog_handler(const struct lu_env *env,
                 }
 
                 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
+               if (lcfg_new == NULL)
+                       GOTO(out, rc = -ENOMEM);
 
                 lcfg_new->lcfg_num   = lcfg->lcfg_num;
                 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
@@ -1914,7 +1937,7 @@ int class_config_dump_handler(const struct lu_env *env,
 
        if (rec->lrh_type == OBD_CFG_REC) {
                class_config_parse_rec(rec, outstr, 256);
-               LCONSOLE(D_WARNING, "   %s", outstr);
+               LCONSOLE(D_WARNING, "   %s\n", outstr);
        } else {
                LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
                rc = -EINVAL;