Whamcloud - gitweb
LU-5496 ldlm: reconstruct proper flags on enqueue resend
[fs/lustre-release.git] / lustre / mgs / mgs_handler.c
index 7c6b315..7e196fb 100644 (file)
@@ -45,6 +45,7 @@
 
 #include <obd_class.h>
 #include <lprocfs_status.h>
+#include <lustre_ioctl.h>
 #include <lustre_param.h>
 
 #include "mgs_internal.h"
@@ -59,6 +60,7 @@ static int mgs_connect(struct tgt_session_info *tsi)
 
        ENTRY;
 
+       CFS_FAIL_TIMEOUT(OBD_FAIL_MGS_CONNECT_NET, cfs_fail_val);
        rc = tgt_connect(tsi);
        if (rc)
                RETURN(rc);
@@ -143,8 +145,7 @@ static int mgs_completion_ast_generic(struct ldlm_lock *lock, __u64 flags,
 {
        ENTRY;
 
-       if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
-                      LDLM_FL_BLOCK_CONV))) {
+       if (!(flags & LDLM_FL_BLOCKED_MASK)) {
                struct fs_db *fsdb;
 
                /* l_ast_data is used as a marker to avoid cancel ldlm lock
@@ -538,11 +539,14 @@ static int mgs_llog_open(struct tgt_session_info *tsi)
        logname = req_capsule_client_get(tsi->tsi_pill, &RMF_NAME);
        if (logname) {
                char *ptr = strchr(logname, '-');
-               int   len = (int)(ptr - logname);
+               int   len = (ptr != NULL) ? (int)(ptr - logname) : 0;
 
                if (ptr == NULL || len >= sizeof(mgi->mgi_fsname)) {
-                       LCONSOLE_WARN("%s: non-config logname received: %s\n",
-                                     tgt_name(tsi->tsi_tgt), logname);
+                       if (strcmp(logname, PARAMS_FILENAME) != 0)
+                               LCONSOLE_WARN("%s: non-config logname "
+                                             "received: %s\n",
+                                             tgt_name(tsi->tsi_tgt),
+                                             logname);
                        /* not error, this can be llog test name */
                } else {
                        strncpy(mgi->mgi_fsname, logname, len);
@@ -573,7 +577,7 @@ static inline int mgs_init_export(struct obd_export *exp)
 
        /* init mgs_export_data for fsc */
        spin_lock_init(&data->med_lock);
-       CFS_INIT_LIST_HEAD(&data->med_clients);
+       INIT_LIST_HEAD(&data->med_clients);
 
        spin_lock(&exp->exp_lock);
        exp->exp_connecting = 1;
@@ -629,9 +633,15 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
        lnet_nid_t              nid;
        const char              *nodemap_name = NULL;
        const char              *nidstr = NULL;
+       const char              *client_idstr = NULL;
+       const char              *idtype_str = NULL;
        char                    *param = NULL;
+       char                    fs_idstr[16];
        int                     rc = 0;
+       __u32                   client_id;
+       __u32                   fs_id;
        __u32                   cmd;
+       int                     idtype;
 
        ENTRY;
 
@@ -654,6 +664,15 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
        cmd = lcfg->lcfg_command;
 
        switch (cmd) {
+       case LCFG_NODEMAP_ACTIVATE:
+               if (lcfg->lcfg_bufcount != 2)
+                       GOTO(out_lcfg, rc = -EINVAL);
+               param = lustre_cfg_string(lcfg, 1);
+               if (strcmp(param, "1") == 0)
+                               nodemap_activate(1);
+               else
+                               nodemap_activate(0);
+               break;
        case LCFG_NODEMAP_ADD:
        case LCFG_NODEMAP_DEL:
                if (lcfg->lcfg_bufcount != 2)
@@ -672,8 +691,39 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
                                 strlen(nodemap->nm_name)) != 0)
                        GOTO(out_lcfg, rc = -EFAULT);
                break;
+       case LCFG_NODEMAP_TEST_ID:
+               if (lcfg->lcfg_bufcount != 4)
+                       GOTO(out_lcfg, rc = -EINVAL);
+               nidstr = lustre_cfg_string(lcfg, 1);
+               idtype_str = lustre_cfg_string(lcfg, 2);
+               client_idstr = lustre_cfg_string(lcfg, 3);
+
+               nid = libcfs_str2nid(nidstr);
+               nodemap = nodemap_classify_nid(nid);
+               client_id = simple_strtoul(client_idstr, NULL, 10);
+
+               if (strcmp(idtype_str, "uid") == 0)
+                       idtype = NODEMAP_UID;
+               else
+                       idtype = NODEMAP_GID;
+
+               fs_id = nodemap_map_id(nodemap, idtype, NODEMAP_CLIENT_TO_FS,
+                                      client_id);
+
+               if (data->ioc_plen1 < sizeof(fs_idstr))
+                       GOTO(out_lcfg, rc = -EINVAL);
+
+               snprintf(fs_idstr, sizeof(fs_idstr), "%u", fs_id);
+               if (copy_to_user(data->ioc_pbuf1, fs_idstr,
+                                sizeof(fs_idstr)) != 0)
+                       GOTO(out_lcfg, rc = -EINVAL);
+               break;
        case LCFG_NODEMAP_ADD_RANGE:
        case LCFG_NODEMAP_DEL_RANGE:
+       case LCFG_NODEMAP_ADD_UIDMAP:
+       case LCFG_NODEMAP_DEL_UIDMAP:
+       case LCFG_NODEMAP_ADD_GIDMAP:
+       case LCFG_NODEMAP_DEL_GIDMAP:
                if (lcfg->lcfg_bufcount != 3)
                        GOTO(out_lcfg, rc = -EINVAL);
                nodemap_name = lustre_cfg_string(lcfg, 1);
@@ -690,7 +740,6 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
                param = lustre_cfg_string(lcfg, 3);
                rc = mgs_nodemap_cmd(env, mgs, cmd, nodemap_name, param);
                break;
-
        default:
                rc = -ENOTTY;
        }
@@ -1037,6 +1086,7 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
        struct obd_device               *obd;
        struct lustre_mount_info        *lmi;
        struct llog_ctxt                *ctxt;
+       struct fs_db                    *fsdb = NULL;
        int                              rc;
 
        ENTRY;
@@ -1108,6 +1158,14 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
                GOTO(err_llog, rc);
        }
 
+       /* Setup params fsdb and log, so that other servers can make a local
+        * copy successfully when they are mounted. See LU-4783 */
+       rc = mgs_params_fsdb_setup(env, mgs, fsdb);
+       if (rc)
+               /* params fsdb and log can be setup later */
+               CERROR("%s: %s fsdb and log setup failed: rc = %d\n",
+                      obd->obd_name, PARAMS_FILENAME, rc);
+
        ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
                           "mgs_ldlm_client", &obd->obd_ldlm_client);
 
@@ -1151,6 +1209,7 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
        lu_site_purge(env, mgs2lu_dev(mgs)->ld_site, ~0);
        RETURN(0);
 err_lproc:
+       mgs_params_fsdb_cleanup(env, mgs);
        lproc_mgs_cleanup(mgs);
 err_llog:
        ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
@@ -1176,7 +1235,7 @@ err_ops:
        obd_disconnect(mgs->mgs_bottom_exp);
 err_lmi:
        if (lmi)
-               server_put_mount(lustre_cfg_string(lcfg, 0));
+               server_put_mount(lustre_cfg_string(lcfg, 0), true);
        RETURN(rc);
 }
 
@@ -1324,6 +1383,7 @@ static struct lu_device *mgs_device_fini(const struct lu_env *env,
        obd_zombie_barrier();
 
        tgt_fini(env, &mgs->mgs_lut);
+       mgs_params_fsdb_cleanup(env, mgs);
        mgs_cleanup_fsdb_list(mgs);
        lproc_mgs_cleanup(mgs);
 
@@ -1347,7 +1407,7 @@ static struct lu_device *mgs_device_fini(const struct lu_env *env,
        LASSERT(mgs->mgs_bottom_exp);
        obd_disconnect(mgs->mgs_bottom_exp);
 
-       server_put_mount(obd->obd_name);
+       server_put_mount(obd->obd_name, true);
 
        RETURN(NULL);
 }
@@ -1468,14 +1528,8 @@ static struct obd_ops mgs_obd_device_ops = {
 
 static int __init mgs_init(void)
 {
-       struct lprocfs_static_vars lvars;
-
-       lprocfs_mgs_init_vars(&lvars);
-       return class_register_type(&mgs_obd_device_ops, NULL, NULL,
-#ifndef HAVE_ONLY_PROCFS_SEQ
-                                       lvars.module_vars,
-#endif
-                                       LUSTRE_MGS_NAME, &mgs_device_type);
+       return class_register_type(&mgs_obd_device_ops, NULL, true, NULL,
+                                  LUSTRE_MGS_NAME, &mgs_device_type);
 }
 
 static void /*__exit*/ mgs_exit(void)