Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / ost / ost_handler.c
index a39381f..ab72698 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #define DEBUG_SUBSYSTEM S_OST
 
 #include <linux/module.h>
-#include <obd_ost.h>
 #include <lustre_dlm.h>
 #include <lprocfs_status.h>
+#include <obd_class.h>
 #include "ost_internal.h"
 
+int oss_max_threads = 512;
+module_param(oss_max_threads, int, 0444);
+MODULE_PARM_DESC(oss_max_threads, "maximum number of OSS service threads");
+
 static int oss_num_threads;
-CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
-                "number of OSS service threads to start");
+module_param(oss_num_threads, int, 0444);
+MODULE_PARM_DESC(oss_num_threads, "number of OSS service threads to start");
 
-static int ost_num_threads;
-CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
-                "number of OST service threads to start (deprecated)");
+static unsigned int oss_cpu_bind = 1;
+module_param(oss_cpu_bind, uint, 0444);
+MODULE_PARM_DESC(oss_cpu_bind,
+                "bind OSS service threads to particular CPU partitions");
 
 static int oss_num_create_threads;
-CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
-                "number of OSS create threads to start");
+module_param(oss_num_create_threads, int, 0444);
+MODULE_PARM_DESC(oss_num_create_threads, "number of OSS create threads to start");
+
+static unsigned int oss_create_cpu_bind = 1;
+module_param(oss_create_cpu_bind, uint, 0444);
+MODULE_PARM_DESC(oss_create_cpu_bind,
+                "bind OSS create threads to particular CPU partitions");
 
 static char *oss_cpts;
-CFS_MODULE_PARM(oss_cpts, "s", charp, 0444,
-               "CPU partitions OSS threads should run on");
+module_param(oss_cpts, charp, 0444);
+MODULE_PARM_DESC(oss_cpts, "CPU partitions OSS threads should run on");
 
 static char *oss_io_cpts;
-CFS_MODULE_PARM(oss_io_cpts, "s", charp, 0444,
-               "CPU partitions OSS IO threads should run on");
+module_param(oss_io_cpts, charp, 0444);
+MODULE_PARM_DESC(oss_io_cpts, "CPU partitions OSS IO threads should run on");
 
 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
 
 static struct cfs_cpt_table    *ost_io_cptable;
 
-#ifdef LPROCFS
-LPROC_SEQ_FOPS_RO_TYPE(ost, uuid);
-
-static struct lprocfs_seq_vars lprocfs_ost_obd_vars[] = {
-       { "uuid",       &ost_uuid_fops  },
-       { 0 }
-};
-#endif /* LPROCFS */
-
 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
 {
@@ -89,14 +86,10 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
        int rc;
        ENTRY;
 
-        rc = cfs_cleanup_group_info();
-        if (rc)
-                RETURN(rc);
+       rc = lprocfs_obd_setup(obd, true);
+       if (rc)
+               return rc;
 
-#ifdef LPROCFS
-       obd->obd_vars = lprocfs_ost_obd_vars;
-       lprocfs_seq_obd_setup(obd);
-#endif
        mutex_init(&ost->ost_health_mutex);
 
        svc_conf = (typeof(svc_conf)) {
@@ -115,13 +108,14 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .tc_thr_factor          = OSS_THR_FACTOR,
                        .tc_nthrs_init          = OSS_NTHRS_INIT,
                        .tc_nthrs_base          = OSS_NTHRS_BASE,
-                       .tc_nthrs_max           = OSS_NTHRS_MAX,
+                       .tc_nthrs_max           = oss_max_threads,
                        .tc_nthrs_user          = oss_num_threads,
-                       .tc_cpu_affinity        = 1,
+                       .tc_cpu_bind            = oss_cpu_bind,
                        .tc_ctx_tags            = LCT_DT_THREAD,
                },
                .psc_cpt                = {
                        .cc_pattern             = oss_cpts,
+                       .cc_affinity            = true,
                },
                .psc_ops                = {
                        .so_req_handler         = tgt_request_handle,
@@ -130,7 +124,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                },
        };
        ost->ost_service = ptlrpc_register_service(&svc_conf,
-                                                  obd->obd_proc_entry);
+                                                  &obd->obd_kset,
+                                                  obd->obd_debugfs_entry);
        if (IS_ERR(ost->ost_service)) {
                rc = PTR_ERR(ost->ost_service);
                CERROR("failed to start service: %d\n", rc);
@@ -156,11 +151,12 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .tc_nthrs_base          = OSS_CR_NTHRS_BASE,
                        .tc_nthrs_max           = OSS_CR_NTHRS_MAX,
                        .tc_nthrs_user          = oss_num_create_threads,
-                       .tc_cpu_affinity        = 1,
+                       .tc_cpu_bind            = oss_create_cpu_bind,
                        .tc_ctx_tags            = LCT_DT_THREAD,
                },
                .psc_cpt                = {
                        .cc_pattern             = oss_cpts,
+                       .cc_affinity            = true,
                },
                .psc_ops                = {
                        .so_req_handler         = tgt_request_handle,
@@ -168,14 +164,15 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                },
        };
        ost->ost_create_service = ptlrpc_register_service(&svc_conf,
-                                                         obd->obd_proc_entry);
+                                                         &obd->obd_kset,
+                                                         obd->obd_debugfs_entry);
        if (IS_ERR(ost->ost_create_service)) {
                rc = PTR_ERR(ost->ost_create_service);
                CERROR("failed to start OST create service: %d\n", rc);
                GOTO(out_service, rc);
         }
 
-       mask = cfs_cpt_table->ctb_nodemask;
+       mask = cfs_cpt_nodemask(cfs_cpt_table, CFS_CPT_ANY);
        /* event CPT feature is disabled in libcfs level by set partition
         * number to 1, we still want to set node affinity for io service */
        if (cfs_cpt_number(cfs_cpt_table) == 1 && nodes_weight(*mask) > 1) {
@@ -217,15 +214,16 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .tc_thr_factor          = OSS_THR_FACTOR,
                        .tc_nthrs_init          = OSS_NTHRS_INIT,
                        .tc_nthrs_base          = OSS_NTHRS_BASE,
-                       .tc_nthrs_max           = OSS_NTHRS_MAX,
+                       .tc_nthrs_max           = oss_max_threads,
                        .tc_nthrs_user          = oss_num_threads,
-                       .tc_cpu_affinity        = 1,
+                       .tc_cpu_bind            = oss_cpu_bind,
                        .tc_ctx_tags            = LCT_DT_THREAD,
                },
                .psc_cpt                = {
                        .cc_cptable             = ost_io_cptable,
                        .cc_pattern             = ost_io_cptable == NULL ?
                                                  oss_io_cpts : NULL,
+                       .cc_affinity            = true,
                },
                .psc_ops                = {
                        .so_thr_init            = tgt_io_thread_init,
@@ -236,7 +234,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                },
        };
        ost->ost_io_service = ptlrpc_register_service(&svc_conf,
-                                                     obd->obd_proc_entry);
+                                                     &obd->obd_kset,
+                                                     obd->obd_debugfs_entry);
        if (IS_ERR(ost->ost_io_service)) {
                rc = PTR_ERR(ost->ost_io_service);
                CERROR("failed to start OST I/O service: %d\n", rc);
@@ -263,12 +262,13 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .tc_nthrs_base          = OSS_CR_NTHRS_BASE,
                        .tc_nthrs_max           = OSS_CR_NTHRS_MAX,
                        .tc_nthrs_user          = oss_num_create_threads,
-                       .tc_cpu_affinity        = 1,
+                       .tc_cpu_bind            = oss_create_cpu_bind,
                        .tc_ctx_tags            = LCT_DT_THREAD,
                },
 
                .psc_cpt                = {
-                       .cc_pattern          = oss_cpts,
+                       .cc_pattern             = oss_cpts,
+                       .cc_affinity            = true,
                },
                .psc_ops                = {
                        .so_req_handler         = tgt_request_handle,
@@ -277,7 +277,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                },
        };
        ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
-                                                     obd->obd_proc_entry);
+                                                      &obd->obd_kset,
+                                                      obd->obd_debugfs_entry);
        if (IS_ERR(ost->ost_seq_service)) {
                rc = PTR_ERR(ost->ost_seq_service);
                CERROR("failed to start OST seq service: %d\n", rc);
@@ -309,12 +310,13 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .tc_nthrs_base          = OSS_CR_NTHRS_BASE,
                        .tc_nthrs_max           = OSS_CR_NTHRS_MAX,
                        .tc_nthrs_user          = oss_num_create_threads,
-                       .tc_cpu_affinity        = 1,
+                       .tc_cpu_bind            = oss_create_cpu_bind,
                        .tc_ctx_tags            = LCT_MD_THREAD |
                                                  LCT_DT_THREAD,
                },
                .psc_cpt                = {
                        .cc_pattern             = oss_cpts,
+                       .cc_affinity            = true,
                },
                .psc_ops                = {
                        .so_req_handler         = tgt_request_handle,
@@ -323,7 +325,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                },
        };
        ost->ost_out_service = ptlrpc_register_service(&svc_conf,
-                                                      obd->obd_proc_entry);
+                                                      &obd->obd_kset,
+                                                      obd->obd_debugfs_entry);
        if (IS_ERR(ost->ost_out_service)) {
                rc = PTR_ERR(ost->ost_out_service);
                CERROR("failed to start out service: %d\n", rc);
@@ -331,53 +334,10 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                GOTO(out_seq, rc);
        }
 
-       /* Index read service */
-       memset(&svc_conf, 0, sizeof(svc_conf));
-       svc_conf = (typeof(svc_conf)) {
-               .psc_name               = "ost_idx_read",
-               .psc_watchdog_factor    = OSS_SERVICE_WATCHDOG_FACTOR,
-               .psc_buf                = {
-                       .bc_nbufs               = OST_NBUFS,
-                       .bc_buf_size            = OST_BUFSIZE,
-                       .bc_req_max_size        = OST_MAXREQSIZE,
-                       .bc_rep_max_size        = OST_MAXREPSIZE,
-                       .bc_req_portal          = OST_IDX_PORTAL,
-                       .bc_rep_portal          = OSC_REPLY_PORTAL,
-               },
-               .psc_thr                = {
-                       .tc_thr_name            = "ll_ost_idx",
-                       .tc_thr_factor          = OSS_CR_THR_FACTOR,
-                       .tc_nthrs_init          = OSS_CR_NTHRS_INIT,
-                       .tc_nthrs_base          = OSS_CR_NTHRS_BASE,
-                       .tc_nthrs_max           = OSS_CR_NTHRS_MAX,
-                       .tc_nthrs_user          = oss_num_create_threads,
-                       .tc_cpu_affinity        = 1,
-                       .tc_ctx_tags            = LCT_DT_THREAD,
-               },
-               .psc_cpt                = {
-                       .cc_pattern             = oss_cpts,
-               },
-               .psc_ops                = {
-                       .so_req_handler         = tgt_request_handle,
-                       .so_req_printer         = target_print_req,
-               },
-       };
-       ost->ost_idx_service = ptlrpc_register_service(&svc_conf,
-                                                      obd->obd_proc_entry);
-       if (IS_ERR(ost->ost_idx_service)) {
-               rc = PTR_ERR(ost->ost_idx_service);
-               CERROR("failed to start OST index read service: rc = %d\n", rc);
-               ost->ost_idx_service = NULL;
-               GOTO(out_out, rc);
-       }
-
        ping_evictor_start();
 
        RETURN(0);
 
-out_out:
-       ptlrpc_unregister_service(ost->ost_out_service);
-       ost->ost_out_service = NULL;
 out_seq:
        ptlrpc_unregister_service(ost->ost_seq_service);
        ost->ost_seq_service = NULL;
@@ -391,7 +351,7 @@ out_service:
         ptlrpc_unregister_service(ost->ost_service);
         ost->ost_service = NULL;
 out_lprocfs:
-        lprocfs_obd_cleanup(obd);
+       lprocfs_obd_cleanup(obd);
         RETURN(rc);
 }
 
@@ -412,14 +372,12 @@ static int ost_cleanup(struct obd_device *obd)
        ptlrpc_unregister_service(ost->ost_io_service);
        ptlrpc_unregister_service(ost->ost_seq_service);
        ptlrpc_unregister_service(ost->ost_out_service);
-       ptlrpc_unregister_service(ost->ost_idx_service);
 
        ost->ost_service = NULL;
        ost->ost_create_service = NULL;
        ost->ost_io_service = NULL;
        ost->ost_seq_service = NULL;
        ost->ost_out_service = NULL;
-       ost->ost_idx_service = NULL;
 
        mutex_unlock(&ost->ost_health_mutex);
 
@@ -435,23 +393,17 @@ static int ost_cleanup(struct obd_device *obd)
 
 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
 {
-        struct ost_obd *ost = &obd->u.ost;
-        int rc = 0;
+       struct ost_obd *ost = &obd->u.ost;
+       int rc = 0;
 
        mutex_lock(&ost->ost_health_mutex);
-        rc |= ptlrpc_service_health_check(ost->ost_service);
-        rc |= ptlrpc_service_health_check(ost->ost_create_service);
-        rc |= ptlrpc_service_health_check(ost->ost_io_service);
+       rc |= ptlrpc_service_health_check(ost->ost_service);
+       rc |= ptlrpc_service_health_check(ost->ost_create_service);
+       rc |= ptlrpc_service_health_check(ost->ost_io_service);
+       rc |= ptlrpc_service_health_check(ost->ost_seq_service);
        mutex_unlock(&ost->ost_health_mutex);
 
-        /*
-         * health_check to return 0 on healthy
-         * and 1 on unhealthy.
-         */
-        if( rc != 0)
-                rc = 1;
-
-        return rc;
+       return rc != 0 ? 1 : 0;
 }
 
 /* use obd ops to offer management infrastructure */
@@ -469,29 +421,20 @@ static int __init ost_init(void)
 
        ENTRY;
 
-       rc = class_register_type(&ost_obd_ops, NULL, NULL,
-#ifndef HAVE_ONLY_PROCFS_SEQ
-                               NULL,
-#endif
-                               LUSTRE_OSS_NAME, NULL);
-
-        if (ost_num_threads != 0 && oss_num_threads == 0) {
-                LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
-                              "use oss_num_threads instead or unset both for "
-                              "dynamic thread startup\n");
-                oss_num_threads = ost_num_threads;
-        }
+       rc = class_register_type(&ost_obd_ops, NULL, false, NULL,
+                                LUSTRE_OSS_NAME, NULL);
 
         RETURN(rc);
 }
 
-static void /*__exit*/ ost_exit(void)
+static void __exit ost_exit(void)
 {
        class_unregister_type(LUSTRE_OSS_NAME);
 }
 
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre Object Storage Target (OST)");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
 MODULE_LICENSE("GPL");
 
 module_init(ost_init);