Whamcloud - gitweb
LU-8955 nodemap: add SELinux policy info to nodemap
[fs/lustre-release.git] / lustre / mgs / mgs_handler.c
index dc13c3d..096c27e 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2010, 2016, Intel Corporation.
+ * Copyright (c) 2010, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -130,7 +130,7 @@ static int mgs_set_info(struct tgt_session_info *tsi)
            !str_starts_with(s + 1, "lov.stripeoffset="))
                RETURN(-EINVAL);
 
-       /* Construct lustre_cfg structure to pass to function mgs_setparam */
+       /* Construct lustre_cfg structure to pass to function mgs_set_param */
        lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL);
        lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param);
        OBD_ALLOC(lcfg, lustre_cfg_len(mgi->mgi_bufs.lcfg_bufcount,
@@ -139,12 +139,10 @@ static int mgs_set_info(struct tgt_session_info *tsi)
                RETURN(-ENOMEM);
        lustre_cfg_init(lcfg, LCFG_PARAM, &mgi->mgi_bufs);
 
-       rc = mgs_setparam(tsi->tsi_env, exp2mgs_dev(tsi->tsi_exp), lcfg,
-                         mgi->mgi_fsname);
+       rc = mgs_set_param(tsi->tsi_env, exp2mgs_dev(tsi->tsi_exp), lcfg);
        if (rc) {
-               LCONSOLE_WARN("%s: Unable to set parameter %s for %s: %d\n",
-                             tgt_name(tsi->tsi_tgt), msp->mgs_param,
-                             mgi->mgi_fsname, rc);
+               LCONSOLE_WARN("%s: Unable to set parameter %s: %d\n",
+                             tgt_name(tsi->tsi_tgt), msp->mgs_param, rc);
                GOTO(out_cfg, rc);
        }
 
@@ -272,7 +270,7 @@ void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type)
 
        if (!rc) {
                LASSERT(cp != NULL);
-               rc = ldlm_cli_enqueue_local(mgs->mgs_obd->obd_namespace,
+               rc = ldlm_cli_enqueue_local(NULL, mgs->mgs_obd->obd_namespace,
                                            &res_id, LDLM_PLAIN, NULL, LCK_EX,
                                            &flags, ldlm_blocking_ast, cp,
                                            NULL, fsdb, 0, LVB_T_NONE, NULL,
@@ -440,8 +438,7 @@ static int mgs_target_reg(struct tgt_session_info *tsi)
        if (mti->mti_flags & LDD_F_NEED_INDEX)
                mti->mti_flags |= LDD_F_WRITECONF;
 
-       if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPGRADE14 |
-                               LDD_F_UPDATE))) {
+       if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPDATE))) {
                /* We're just here as a startup ping. */
                CDEBUG(D_MGS, "Server %s is running on %s\n",
                       mti->mti_svname, obd_export_nid2str(tsi->tsi_exp));
@@ -501,8 +498,6 @@ static int mgs_target_reg(struct tgt_session_info *tsi)
                }
 
                mti->mti_flags |= LDD_F_UPDATE;
-               /* Erased logs means start from scratch. */
-               mti->mti_flags &= ~LDD_F_UPGRADE14;
        }
 
        rc = mgs_find_or_make_fsdb(tsi->tsi_env, mgs, mti->mti_fsname, &c_fsdb);
@@ -512,19 +507,13 @@ static int mgs_target_reg(struct tgt_session_info *tsi)
                GOTO(out_norevoke, rc);
        }
 
-        /*
-         * Log writing contention is handled by the fsdb_mutex.
-         *
-         * It should be alright if someone was reading while we were
-         * updating the logs - if we revoke at the end they will just update
-         * from where they left off.
-         */
-
-        if (mti->mti_flags & LDD_F_UPGRADE14) {
-               CERROR("Can't upgrade from 1.4 (%d)\n", rc);
-               GOTO(out, rc);
-       }
-
+       /*
+        * Log writing contention is handled by the fsdb_mutex.
+        *
+        * It should be alright if someone was reading while we were
+        * updating the logs - if we revoke at the end they will just update
+        * from where they left off.
+        */
         if (mti->mti_flags & LDD_F_UPDATE) {
                 CDEBUG(D_MGS, "updating %s, index=%d\n", mti->mti_svname,
                        mti->mti_stripe_index);
@@ -538,10 +527,9 @@ static int mgs_target_reg(struct tgt_session_info *tsi)
                         GOTO(out, rc);
                 }
 
-                mti->mti_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE |
-                                    LDD_F_NEED_INDEX | LDD_F_WRITECONF |
-                                    LDD_F_UPGRADE14);
-                mti->mti_flags |= LDD_F_REWRITE_LDD;
+               mti->mti_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE |
+                                   LDD_F_NEED_INDEX | LDD_F_WRITECONF);
+               mti->mti_flags |= LDD_F_REWRITE_LDD;
         }
 
 out:
@@ -762,7 +750,7 @@ static int mgs_extract_fs_pool(char *arg, char *fsname, char *poolname)
                return -EINVAL;
 
        /* or too long */
-       if (len > MTI_NAME_MAXLEN)
+       if (len > LUSTRE_MAXFSNAME)
                return -ENAMETOOLONG;
 
        strncpy(fsname, arg, len);
@@ -874,6 +862,7 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
        case LCFG_NODEMAP_ADD_GIDMAP:
        case LCFG_NODEMAP_DEL_GIDMAP:
        case LCFG_NODEMAP_SET_FILESET:
+       case LCFG_NODEMAP_SET_SEPOL:
                if (lcfg->lcfg_bufcount != 3)
                        GOTO(out_lcfg, rc = -EINVAL);
                nodemap_name = lustre_cfg_string(lcfg, 1);
@@ -886,6 +875,7 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env,
        case LCFG_NODEMAP_SQUASH_UID:
        case LCFG_NODEMAP_SQUASH_GID:
        case LCFG_NODEMAP_MAP_MODE:
+       case LCFG_NODEMAP_AUDIT_MODE:
                if (lcfg->lcfg_bufcount != 4)
                        GOTO(out_lcfg, rc = -EINVAL);
                nodemap_name = lustre_cfg_string(lcfg, 1);
@@ -1018,9 +1008,8 @@ static int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
         switch (cmd) {
 
-        case OBD_IOC_PARAM: {
-               struct mgs_thread_info *mgi = mgs_env_info(&env);
-                struct lustre_cfg *lcfg;
+       case OBD_IOC_PARAM: {
+               struct lustre_cfg *lcfg;
 
                if (data->ioc_type != LUSTRE_CFG_TYPE) {
                        CERROR("%s: unknown cfg record type: %d\n",
@@ -1037,7 +1026,7 @@ static int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 if (lcfg->lcfg_bufcount < 1)
                         GOTO(out_free, rc = -EINVAL);
 
-               rc = mgs_setparam(&env, mgs, lcfg, mgi->mgi_fsname);
+               rc = mgs_set_param(&env, mgs, lcfg);
                if (rc)
                        CERROR("%s: setparam err: rc = %d\n",
                               exp->exp_obd->obd_name, rc);
@@ -1048,32 +1037,37 @@ out_free:
 
        case OBD_IOC_REPLACE_NIDS: {
                if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
-                       CERROR("No device name specified!\n");
                        rc = -EINVAL;
+                       CERROR("%s: no device or fsname specified: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
                        break;
                }
 
-               if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
-                       CERROR("Device name is not NUL terminated!\n");
-                       rc = -EINVAL;
+               if (data->ioc_inllen1 > MTI_NAME_MAXLEN) {
+                       rc = -EOVERFLOW;
+                       CERROR("%s: device or fsname is too long: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
                        break;
                }
 
-               if (data->ioc_plen1 > MTI_NAME_MAXLEN) {
-                       CERROR("Device name is too long\n");
-                       rc = -EOVERFLOW;
+               if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
+                       rc = -EINVAL;
+                       CERROR("%s: device or fsname is not NUL terminated: "
+                              "rc = %d\n", exp->exp_obd->obd_name, rc);
                        break;
                }
 
                if (!data->ioc_inllen2 || !data->ioc_inlbuf2) {
-                       CERROR("No NIDs were specified!\n");
                        rc = -EINVAL;
+                       CERROR("%s: no NIDs specified: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
                        break;
                }
 
                if (data->ioc_inlbuf2[data->ioc_inllen2 - 1] != 0) {
-                       CERROR("NID list is not NUL terminated!\n");
                        rc = -EINVAL;
+                       CERROR("%s: NID list is not NUL terminated: "
+                              "rc = %d\n", exp->exp_obd->obd_name, rc);
                        break;
                }
 
@@ -1087,6 +1081,37 @@ out_free:
                break;
        }
 
+       case OBD_IOC_CLEAR_CONFIGS: {
+               if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
+                       rc = -EINVAL;
+                       CERROR("%s: no device or fsname specified: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
+                       break;
+               }
+
+               if (data->ioc_inllen1 > MTI_NAME_MAXLEN) {
+                       rc = -EOVERFLOW;
+                       CERROR("%s: device or fsname is too long: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
+                       break;
+               }
+
+               if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
+                       rc = -EINVAL;
+                       CERROR("%s: device or fsname is not NUL terminated: "
+                              "rc = %d\n", exp->exp_obd->obd_name, rc);
+                       break;
+               }
+
+               /* remove records marked SKIP from config logs */
+               rc = mgs_clear_configs(&env, mgs, data->ioc_inlbuf1);
+               if (rc)
+                       CERROR("%s: error clearing config log: rc = %d\n",
+                              exp->exp_obd->obd_name, rc);
+
+               break;
+       }
+
        case OBD_IOC_POOL:
                rc = mgs_iocontrol_pool(&env, mgs, data);
                break;
@@ -1210,7 +1235,6 @@ static struct tgt_handler mgs_llog_handlers[] = {
 TGT_LLOG_HDL    (0,    LLOG_ORIGIN_HANDLE_CREATE,      mgs_llog_open),
 TGT_LLOG_HDL    (0,    LLOG_ORIGIN_HANDLE_NEXT_BLOCK,  tgt_llog_next_block),
 TGT_LLOG_HDL    (0,    LLOG_ORIGIN_HANDLE_READ_HEADER, tgt_llog_read_header),
-TGT_LLOG_HDL_VAR(0,    LLOG_ORIGIN_HANDLE_CLOSE,       tgt_llog_close),
 TGT_LLOG_HDL    (0,    LLOG_ORIGIN_HANDLE_PREV_BLOCK,  tgt_llog_prev_block),
 };
 
@@ -1367,8 +1391,8 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
        };
 
        /* Start the service threads */
-       mgs->mgs_service = ptlrpc_register_service(&conf, mgs->mgs_kset,
-                                                  obd->obd_proc_entry);
+       mgs->mgs_service = ptlrpc_register_service(&conf, &obd->obd_kset,
+                                                  obd->obd_debugfs_entry);
        if (IS_ERR(mgs->mgs_service)) {
                rc = PTR_ERR(mgs->mgs_service);
                CERROR("failed to start mgs service: %d\n", rc);
@@ -1403,7 +1427,7 @@ err_ns:
 err_ops:
        lu_site_purge(env, mgs2lu_dev(mgs)->ld_site, ~0);
        if (!cfs_hash_is_empty(mgs2lu_dev(mgs)->ld_site->ls_obj_hash)) {
-               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
+               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_OTHER, NULL);
                lu_site_print(env, mgs2lu_dev(mgs)->ld_site, &msgdata,
                                lu_cdebug_printer);
        }
@@ -1579,7 +1603,7 @@ static struct lu_device *mgs_device_fini(const struct lu_env *env,
 
        lu_site_purge(env, d->ld_site, ~0);
        if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
-               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
+               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_OTHER, NULL);
                lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
        }
 
@@ -1618,28 +1642,16 @@ static struct lu_device_type mgs_device_type = {
        .ldt_ctx_tags   = LCT_MG_THREAD
 };
 
-static int mgs_obd_connect(const struct lu_env *env, struct obd_export **exp,
-                          struct obd_device *obd, struct obd_uuid *cluuid,
-                          struct obd_connect_data *data, void *localdata)
+static int mgs_obd_reconnect(const struct lu_env *env, struct obd_export *exp,
+                            struct obd_device *obd, struct obd_uuid *cluuid,
+                            struct obd_connect_data *data, void *localdata)
 {
-       struct obd_export       *lexp;
-       struct lustre_handle     conn = {
-               .cookie = 0,
-       };
-       int                      rc;
-
        ENTRY;
 
        if (exp == NULL || obd == NULL || cluuid == NULL)
                RETURN(-EINVAL);
 
-       rc = class_connect(&conn, obd, cluuid);
-       if (rc)
-               RETURN(rc);
-
-       lexp = class_conn2export(&conn);
-       if (lexp == NULL)
-               RETURN(-EFAULT);
+       tgt_counter_incr(exp, LPROC_MGS_CONNECT);
 
        if (data != NULL) {
                data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
@@ -1647,43 +1659,48 @@ static int mgs_obd_connect(const struct lu_env *env, struct obd_export **exp,
                if (data->ocd_connect_flags & OBD_CONNECT_FLAGS2)
                        data->ocd_connect_flags2 &= MGS_CONNECT_SUPPORTED2;
 
+               exp->exp_connect_data = *data;
                data->ocd_version = LUSTRE_VERSION_CODE;
-               lexp->exp_connect_data = *data;
        }
 
-       tgt_counter_incr(lexp, LPROC_MGS_CONNECT);
-
-       rc = mgs_export_stats_init(obd, lexp, localdata);
-       if (rc)
-               class_disconnect(lexp);
-       else
-               *exp = lexp;
-
-       RETURN(rc);
+       RETURN(mgs_export_stats_init(obd, exp, localdata));
 }
 
-static int mgs_obd_reconnect(const struct lu_env *env, struct obd_export *exp,
-                            struct obd_device *obd, struct obd_uuid *cluuid,
-                            struct obd_connect_data *data, void *localdata)
+static int mgs_obd_connect(const struct lu_env *env, struct obd_export **exp,
+                          struct obd_device *obd, struct obd_uuid *cluuid,
+                          struct obd_connect_data *data, void *localdata)
 {
+       struct obd_export       *lexp;
+       struct lustre_handle     conn = {
+               .cookie = 0,
+       };
+       int                      rc;
+
        ENTRY;
 
        if (exp == NULL || obd == NULL || cluuid == NULL)
                RETURN(-EINVAL);
 
-       tgt_counter_incr(exp, LPROC_MGS_CONNECT);
+       rc = class_connect(&conn, obd, cluuid);
+       if (rc)
+               RETURN(rc);
 
-       if (data != NULL) {
-               data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
+       lexp = class_conn2export(&conn);
+       if (lexp == NULL)
+               RETURN(-EFAULT);
 
-               if (data->ocd_connect_flags & OBD_CONNECT_FLAGS2)
-                       data->ocd_connect_flags2 &= MGS_CONNECT_SUPPORTED2;
+       rc = mgs_obd_reconnect(env, lexp, obd, cluuid, data, localdata);
+       if (rc)
+               GOTO(out_disconnect, rc);
 
-               data->ocd_version = LUSTRE_VERSION_CODE;
-               exp->exp_connect_data = *data;
-       }
+       *exp = lexp;
 
-       RETURN(mgs_export_stats_init(obd, exp, localdata));
+       RETURN(rc);
+
+out_disconnect:
+       class_disconnect(lexp);
+
+       return rc;
 }
 
 static int mgs_obd_disconnect(struct obd_export *exp)