Whamcloud - gitweb
LU-5397 obdclass: optimize busy loop wait
[fs/lustre-release.git] / lustre / obdclass / obd_config.c
index 83465e2..3914193 100644 (file)
 #ifdef __KERNEL__
 #include <obd_class.h>
 #include <linux/string.h>
+#include <lustre_disk.h>
 #else
 #include <liblustre.h>
 #include <string.h>
 #include <obd_class.h>
 #include <obd.h>
 #endif
+#include <lustre_ioctl.h>
 #include <lustre_log.h>
 #include <lprocfs_status.h>
 #include <lustre_param.h>
@@ -410,8 +412,9 @@ int class_attach(struct lustre_cfg *lcfg)
        CFS_INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
        CFS_INIT_LIST_HEAD(&obd->obd_final_req_queue);
        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;
 
@@ -423,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);
@@ -628,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++)
@@ -756,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);
         }
 }
@@ -1469,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
@@ -1514,6 +1538,8 @@ int class_config_llog_handler(const struct lu_env *env,
                         if (marker->cm_flags & CM_START) {
                                 /* all previous flags off */
                                 clli->cfg_flags = CFG_F_MARKER;
+                               server_name2index(marker->cm_tgtname,
+                                                 &clli->cfg_lwp_idx, NULL);
                                 if (marker->cm_flags & CM_SKIP) {
                                         clli->cfg_flags |= CFG_F_SKIP;
                                         CDEBUG(D_CONFIG, "SKIP #%d\n",
@@ -1649,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;
@@ -1909,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;