Whamcloud - gitweb
LU-13606 lnet: Allow router to forward to healthier NID
[fs/lustre-release.git] / lustre / quota / qmt_dev.c
index 8512035..f785ac9 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012 Intel, Inc.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann.lombardi@intel.com>
@@ -45,7 +45,7 @@
  * The QMT device is currently set up by the MDT and should probably be moved
  * to a separate target in the future. Meanwhile, the MDT forwards all quota
  * requests to the QMT via a list of request handlers (see struct qmt_handlers
- * in lquota.h). The QMT also borrows the LDLM namespace from the MDT.
+ * in lustre_quota.h). The QMT also borrows the LDLM namespace from the MDT.
  *
  * To bring up a QMT device, the following steps must be completed:
  *
  * mdt_quota_init() for more details.
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #define DEBUG_SUBSYSTEM S_LQUOTA
 
 #include <obd_class.h>
@@ -110,6 +106,15 @@ static struct lu_device *qmt_device_fini(const struct lu_env *env,
                qmt->qmt_proc = NULL;
        }
 
+       /* stop rebalance thread */
+       if (!qmt->qmt_child->dd_rdonly)
+               qmt_stop_reba_thread(qmt);
+
+       if (qmt->qmt_root) {
+               dt_object_put(env, qmt->qmt_root);
+               qmt->qmt_root = NULL;
+       }
+
        /* disconnect from OSD */
        if (qmt->qmt_child_exp != NULL) {
                obd_disconnect(qmt->qmt_child_exp);
@@ -117,12 +122,9 @@ static struct lu_device *qmt_device_fini(const struct lu_env *env,
                qmt->qmt_child = NULL;
        }
 
-       /* release reference on MDT namespace */
-       if (ld->ld_obd->obd_namespace != NULL) {
-               ldlm_namespace_put(ld->ld_obd->obd_namespace);
-               ld->ld_obd->obd_namespace = NULL;
-               qmt->qmt_ns = NULL;
-       }
+       /* clear references to MDT namespace */
+       ld->ld_obd->obd_namespace = NULL;
+       qmt->qmt_ns = NULL;
 
        RETURN(NULL);
 }
@@ -206,12 +208,17 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt,
        struct lu_device        *ld = qmt2lu_dev(qmt);
        struct obd_device       *obd, *mdt_obd;
        struct obd_type         *type;
+       char                    *svname = lustre_cfg_string(cfg, 0);
        int                      rc;
        ENTRY;
 
+       if (svname == NULL)
+               RETURN(-EINVAL);
+
        /* record who i am, it might be useful ... */
-       strncpy(qmt->qmt_svname, lustre_cfg_string(cfg, 0),
-               sizeof(qmt->qmt_svname) - 1);
+       rc = strlcpy(qmt->qmt_svname, svname, sizeof(qmt->qmt_svname));
+       if (rc >= sizeof(qmt->qmt_svname))
+               RETURN(-E2BIG);
 
        /* look-up the obd_device associated with the qmt */
        obd = class_name2obd(qmt->qmt_svname);
@@ -227,10 +234,9 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt,
        if (mdt_obd == NULL)
                RETURN(-ENOENT);
 
-       /* grab reference on MDT namespace. kind of a hack until we have our
-        * own namespace & service threads */
+       /* borrow  MDT namespace. kind of a hack until we have our own namespace
+        * & service threads */
        LASSERT(mdt_obd->obd_namespace != NULL);
-       ldlm_namespace_get(mdt_obd->obd_namespace);
        obd->obd_namespace = mdt_obd->obd_namespace;
        qmt->qmt_ns = obd->obd_namespace;
 
@@ -239,11 +245,26 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt,
        if (rc)
                GOTO(out, rc);
 
+       /* set up and start rebalance thread */
+       INIT_LIST_HEAD(&qmt->qmt_reba_list);
+       spin_lock_init(&qmt->qmt_reba_lock);
+       if (!qmt->qmt_child->dd_rdonly) {
+               rc = qmt_start_reba_thread(qmt);
+               if (rc) {
+                       CERROR("%s: failed to start rebalance thread (%d)\n",
+                              qmt->qmt_svname, rc);
+                       GOTO(out, rc);
+               }
+       }
+
        /* at the moment there is no linkage between lu_type and obd_type, so
         * we lookup obd_type this way */
        type = class_search_type(LUSTRE_QMT_NAME);
        LASSERT(type != NULL);
 
+       /* put reference taken by class_search_type */
+       kobject_put(&type->typ_kobj);
+
        /* register proc directory associated with this qmt */
        qmt->qmt_proc = lprocfs_register(qmt->qmt_svname, type->typ_procroot,
                                         NULL, NULL);
@@ -258,6 +279,7 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt,
        rc = qmt_pool_init(env, qmt);
        if (rc)
                GOTO(out, rc);
+
        EXIT;
 out:
        if (rc)
@@ -401,10 +423,14 @@ static int qmt_device_obd_disconnect(struct obd_export *exp)
 /*
  * obd device operations associated with the master target.
  */
-struct obd_ops qmt_obd_ops = {
+static const struct obd_ops qmt_obd_ops = {
        .o_owner        = THIS_MODULE,
        .o_connect      = qmt_device_obd_connect,
        .o_disconnect   = qmt_device_obd_disconnect,
+       .o_pool_new     = qmt_pool_new,
+       .o_pool_rem     = qmt_pool_rem,
+       .o_pool_add     = qmt_pool_add,
+       .o_pool_del     = qmt_pool_del,
 };
 
 /*
@@ -437,10 +463,9 @@ static int qmt_device_prepare(const struct lu_env *env,
                RETURN(rc);
        }
 
+       qmt->qmt_root = qmt_root;
        /* initialize on-disk indexes associated with each pool */
-       rc = qmt_pool_prepare(env, qmt, qmt_root);
-
-       lu_object_put(env, &qmt_root->do_lu);
+       rc = qmt_pool_prepare(env, qmt, qmt_root, NULL);
        RETURN(rc);
 }
 
@@ -459,8 +484,8 @@ int qmt_glb_init(void)
        int rc;
        ENTRY;
 
-       rc = class_register_type(&qmt_obd_ops, NULL, NULL, LUSTRE_QMT_NAME,
-                                &qmt_device_type);
+       rc = class_register_type(&qmt_obd_ops, NULL, true, NULL,
+                                LUSTRE_QMT_NAME, &qmt_device_type);
        RETURN(rc);
 }