Whamcloud - gitweb
LU-8857 config: refactor sptlrpc config process 19/24119/4
authorLai Siyao <lai.siyao@intel.com>
Sun, 4 Dec 2016 14:26:24 +0000 (22:26 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 14 Mar 2017 02:58:30 +0000 (02:58 +0000)
MDT/OFD may access config llog directly, e.g. accessing sptlrpc
local copy, but this config context is not initialized, these code
existed before, but maybe got lost in server code refactor before.
But after reviewing code this is not necessary, target doesn't
need to access sptlrpc config directly, but leave it the same as
other configs, that is, let MGC to handle.

Besides, ofd_set_info_hdl() doesn't need to handle KEY_SPTLRPC_CONF
because this key is handled in o_set_info_async only.

As a side effect, remove obsolete function lustre_rename().

Signed-off-by: Lai Siyao <lai.siyao@intel.com>
Change-Id: If0937cf6e5e03bc84f883131bbf63326e847e701
Reviewed-on: https://review.whamcloud.com/24119
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lu_target.h
lustre/include/lustre_sec.h
lustre/mdt/mdt_handler.c
lustre/mgc/mgc_request.c
lustre/ofd/ofd_dev.c
lustre/ofd/ofd_obd.c
lustre/ptlrpc/ptlrpc_internal.h
lustre/ptlrpc/sec_config.c
lustre/ptlrpc/sec_ctx.c
lustre/target/tgt_handler.c

index c527b61..cc6a4e3 100644 (file)
@@ -364,7 +364,7 @@ char *tgt_name(struct lu_target *tgt);
 void tgt_counter_incr(struct obd_export *exp, int opcode);
 int tgt_connect_check_sptlrpc(struct ptlrpc_request *req,
                              struct obd_export *exp);
-int tgt_adapt_sptlrpc_conf(struct lu_target *tgt, int initial);
+int tgt_adapt_sptlrpc_conf(struct lu_target *tgt);
 int tgt_connect(struct tgt_session_info *tsi);
 int tgt_disconnect(struct tgt_session_info *uti);
 int tgt_obd_ping(struct tgt_session_info *tsi);
index 1aaab85..8d49d38 100644 (file)
@@ -47,6 +47,7 @@ struct ptlrpc_request;
 struct ptlrpc_reply_state;
 struct ptlrpc_bulk_desc;
 struct brw_page;
+struct lu_env;
 /* Linux specific */
 struct key;
 struct seq_file;
@@ -386,8 +387,7 @@ void sptlrpc_conf_log_update_begin(const char *logname);
 void sptlrpc_conf_log_update_end(const char *logname);
 void sptlrpc_conf_client_adapt(struct obd_device *obd);
 int  sptlrpc_conf_target_get_rules(struct obd_device *obd,
-                                   struct sptlrpc_rule_set *rset,
-                                   int initial);
+                                  struct sptlrpc_rule_set *rset);
 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
                                   enum lustre_sec_part from,
                                   lnet_nid_t nid,
index 7463c7d..e71e12f 100644 (file)
@@ -4729,7 +4729,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
        if (rc)
                GOTO(err_tgt, rc);
 
-       tgt_adapt_sptlrpc_conf(&m->mdt_lut, 1);
+       tgt_adapt_sptlrpc_conf(&m->mdt_lut);
 
         next = m->mdt_child;
         rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
@@ -5060,7 +5060,7 @@ static int mdt_obd_set_info_async(const struct lu_env *env,
        ENTRY;
 
        if (KEY_IS(KEY_SPTLRPC_CONF)) {
-               rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp), 0);
+               rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp));
                RETURN(rc);
        }
 
index da1c3ce..12a8751 100644 (file)
@@ -1901,7 +1901,6 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
        struct client_obd       *cli = &mgc->u.cli;
        struct lustre_sb_info   *lsi = NULL;
        int                      rc = 0;
-       bool                     sptlrpc_started = false;
        struct lu_env           *env;
 
        ENTRY;
@@ -1909,13 +1908,6 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
        LASSERT(cld);
        LASSERT(mutex_is_locked(&cld->cld_lock));
 
-       /*
-        * local copy of sptlrpc log is controlled elsewhere, don't try to
-        * read it up here.
-        */
-       if (cld_is_sptlrpc(cld) && local_only)
-               RETURN(0);
-
        if (cld->cld_cfg.cfg_sb)
                lsi = s2lsi(cld->cld_cfg.cfg_sb);
 
@@ -1966,22 +1958,11 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
                        GOTO(out_pop, rc = -EIO);
        }
 
-       if (cld_is_sptlrpc(cld)) {
-               sptlrpc_conf_log_update_begin(cld->cld_logname);
-               sptlrpc_started = true;
-       }
-
        /* logname and instance info should be the same, so use our
         * copy of the instance for the update.  The cfg_last_idx will
         * be updated here. */
        rc = class_config_parse_llog(env, ctxt, cld->cld_logname,
                                     &cld->cld_cfg);
-       EXIT;
-
-out_pop:
-       __llog_ctxt_put(env, ctxt);
-       if (lctxt)
-               __llog_ctxt_put(env, lctxt);
 
        /*
         * update settings on existing OBDs. doing it inside
@@ -1989,13 +1970,16 @@ out_pop:
         * in parallel.
         * the logname must be <fsname>-sptlrpc
         */
-       if (sptlrpc_started) {
-               LASSERT(cld_is_sptlrpc(cld));
-               sptlrpc_conf_log_update_end(cld->cld_logname);
+       if (rc == 0 && cld_is_sptlrpc(cld))
                class_notify_sptlrpc_conf(cld->cld_logname,
                                          strlen(cld->cld_logname) -
                                          strlen("-sptlrpc"));
-       }
+       EXIT;
+
+out_pop:
+       __llog_ctxt_put(env, ctxt);
+       if (lctxt)
+               __llog_ctxt_put(env, lctxt);
 
        lu_env_fini(env);
 out_free:
index 137a05d..4bd5029 100644 (file)
@@ -76,6 +76,7 @@
 #include <lustre_dlm.h>
 #include <lustre_quota.h>
 #include <lustre_nodemap.h>
+#include <lustre_log.h>
 
 #include "ofd_internal.h"
 
@@ -943,8 +944,6 @@ static int ofd_set_info_hdl(struct tgt_session_info *tsi)
                if (vallen > 0)
                        obd_export_evict_by_nid(tsi->tsi_exp->exp_obd, val);
                rc = 0;
-       } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
-               rc = tgt_adapt_sptlrpc_conf(tsi->tsi_tgt, 0);
        } else {
                CERROR("%s: Unsupported key %s\n",
                       tgt_name(tsi->tsi_tgt), (char *)key);
@@ -3048,7 +3047,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
        if (rc != 0)
                GOTO(err_fini_nm, rc);
 
-       tgt_adapt_sptlrpc_conf(&m->ofd_lut, 1);
+       tgt_adapt_sptlrpc_conf(&m->ofd_lut);
 
        RETURN(0);
 
index 2134233..a0d1787 100644 (file)
@@ -630,7 +630,7 @@ static int ofd_set_info_async(const struct lu_env *env, struct obd_export *exp,
        }
 
        if (KEY_IS(KEY_SPTLRPC_CONF)) {
-               rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp), 0);
+               rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp));
        } else {
                CERROR("%s: Unsupported key %s\n",
                       exp->exp_obd->obd_name, (char*)key);
index bcd5a79..1dbc82d 100644 (file)
@@ -304,11 +304,6 @@ void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
 int  sptlrpc_conf_init(void);
 void sptlrpc_conf_fini(void);
 
-struct dentry;
-struct vfsmount;
-int lustre_rename(struct dentry *dir, struct vfsmount *mnt, char *old_name,
-                 char *new_name);
-
 /* sec.c */
 int  sptlrpc_init(void);
 void sptlrpc_fini(void);
index 2407f9d..43003b0 100644 (file)
@@ -934,281 +934,47 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd)
 }
 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
 
-
-static void rule2string(struct sptlrpc_rule *r, char *buf, int buflen)
-{
-       char     dirbuf[8];
-       char     net[LNET_NIDSTR_SIZE] = "default";
-       char    *ptr = buf;
-
-       if (r->sr_netid != LNET_NIDNET(LNET_NID_ANY))
-               libcfs_net2str_r(r->sr_netid, net, sizeof(net));
-
-        if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
-                dirbuf[0] = '\0';
-        else
-                snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
-                         sptlrpc_part2name(r->sr_from),
-                         sptlrpc_part2name(r->sr_to));
-
-        ptr += snprintf(buf, buflen, "srpc.flavor.%s%s=", net, dirbuf);
-
-        sptlrpc_flavor2name(&r->sr_flvr, ptr, buflen - (ptr - buf));
-        buf[buflen - 1] = '\0';
-}
-
-static int sptlrpc_record_rule_set(struct llog_handle *llh,
-                                   char *target,
-                                   struct sptlrpc_rule_set *rset)
-{
-       struct llog_cfg_rec     *lcr;
-       struct lustre_cfg_bufs   bufs;
-       char                     param[48];
-       int                      i, rc;
-
-       for (i = 0; i < rset->srs_nrule; i++) {
-               rule2string(&rset->srs_rules[i], param, sizeof(param));
-
-               lustre_cfg_bufs_reset(&bufs, NULL);
-               lustre_cfg_bufs_set_string(&bufs, 1, target);
-               lustre_cfg_bufs_set_string(&bufs, 2, param);
-               lcr = lustre_cfg_rec_new(LCFG_SPTLRPC_CONF, &bufs);
-               if (lcr == NULL)
-                       return -ENOMEM;
-               rc = llog_write(NULL, llh, &lcr->lcr_hdr, LLOG_NEXT_IDX);
-               lustre_cfg_rec_free(lcr);
-               if (rc)
-                       return rc;
-       }
-       return 0;
-}
-
-static int sptlrpc_record_rules(struct llog_handle *llh,
-                                struct sptlrpc_conf *conf)
-{
-        struct sptlrpc_conf_tgt *conf_tgt;
-
-        sptlrpc_record_rule_set(llh, conf->sc_fsname, &conf->sc_rset);
-
-       list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
-                sptlrpc_record_rule_set(llh, conf_tgt->sct_name,
-                                        &conf_tgt->sct_rset);
-        }
-        return 0;
-}
-
-#define LOG_SPTLRPC_TMP "sptlrpc.tmp"
-#define LOG_SPTLRPC     "sptlrpc"
-
-static
-int sptlrpc_target_local_copy_conf(struct obd_device *obd,
-                                   struct sptlrpc_conf *conf)
-{
-        struct llog_handle   *llh = NULL;
-        struct llog_ctxt     *ctxt;
-        struct lvfs_run_ctxt  saved;
-        struct dentry        *dentry;
-        int                   rc;
-        ENTRY;
-
-       ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-       if (ctxt == NULL)
-               RETURN(-EINVAL);
-
-       push_ctxt(&saved, &obd->obd_lvfs_ctxt);
-
-       dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, current->fs->pwd.dentry,
-                                   strlen(MOUNT_CONFIGS_DIR));
-        if (IS_ERR(dentry)) {
-                rc = PTR_ERR(dentry);
-                CERROR("cannot lookup %s directory: rc = %d\n",
-                       MOUNT_CONFIGS_DIR, rc);
-                GOTO(out_ctx, rc);
-        }
-
-        /* erase the old tmp log */
-       rc = llog_erase(NULL, ctxt, NULL, LOG_SPTLRPC_TMP);
-       if (rc < 0 && rc != -ENOENT) {
-               CERROR("%s: cannot erase temporary sptlrpc log: rc = %d\n",
-                      obd->obd_name, rc);
-               GOTO(out_dput, rc);
-       }
-
-       /* write temporary log */
-       rc = llog_open_create(NULL, ctxt, &llh, NULL, LOG_SPTLRPC_TMP);
-       if (rc)
-               GOTO(out_dput, rc);
-       rc = llog_init_handle(NULL, llh, LLOG_F_IS_PLAIN, NULL);
-        if (rc)
-                GOTO(out_close, rc);
-
-        rc = sptlrpc_record_rules(llh, conf);
-
-out_close:
-       llog_close(NULL, llh);
-       if (rc == 0)
-               rc = lustre_rename(dentry, obd->obd_lvfs_ctxt.pwdmnt,
-                                  LOG_SPTLRPC_TMP, LOG_SPTLRPC);
-out_dput:
-       dput(dentry);
-out_ctx:
-       pop_ctxt(&saved, &obd->obd_lvfs_ctxt);
-       llog_ctxt_put(ctxt);
-       CDEBUG(D_SEC, "target %s: write local sptlrpc conf: rc = %d\n",
-               obd->obd_name, rc);
-       RETURN(rc);
-}
-
-static int local_read_handler(const struct lu_env *env,
-                             struct llog_handle *llh,
-                             struct llog_rec_hdr *rec, void *data)
-{
-        struct sptlrpc_conf  *conf = (struct sptlrpc_conf *) data;
-        struct lustre_cfg    *lcfg = (struct lustre_cfg *)(rec + 1);
-        int                   cfg_len, rc;
-        ENTRY;
-
-        if (rec->lrh_type != OBD_CFG_REC) {
-                CERROR("unhandled lrh_type: %#x\n", rec->lrh_type);
-                RETURN(-EINVAL);
-        }
-
-        cfg_len = rec->lrh_len - sizeof(struct llog_rec_hdr) -
-                  sizeof(struct llog_rec_tail);
-
-        rc = lustre_cfg_sanity_check(lcfg, cfg_len);
-        if (rc) {
-                CERROR("Insane cfg\n");
-                RETURN(rc);
-        }
-
-        if (lcfg->lcfg_command != LCFG_SPTLRPC_CONF) {
-                CERROR("invalid command (%x)\n", lcfg->lcfg_command);
-                RETURN(-EINVAL);
-        }
-
-        RETURN(__sptlrpc_process_config(lcfg, conf));
-}
-
-static
-int sptlrpc_target_local_read_conf(struct obd_device *obd,
-                                   struct sptlrpc_conf *conf)
-{
-        struct llog_handle    *llh = NULL;
-        struct llog_ctxt      *ctxt;
-        struct lvfs_run_ctxt   saved;
-        int                    rc;
-        ENTRY;
-
-        LASSERT(conf->sc_updated == 0 && conf->sc_local == 0);
-
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-        if (ctxt == NULL) {
-                CERROR("missing llog context\n");
-                RETURN(-EINVAL);
-        }
-
-       push_ctxt(&saved, &obd->obd_lvfs_ctxt);
-
-       rc = llog_open(NULL, ctxt, &llh, NULL, LOG_SPTLRPC, LLOG_OPEN_EXISTS);
-       if (rc < 0) {
-               if (rc == -ENOENT)
-                       rc = 0;
-               GOTO(out_pop, rc);
-       }
-
-       rc = llog_init_handle(NULL, llh, LLOG_F_IS_PLAIN, NULL);
-        if (rc)
-                GOTO(out_close, rc);
-
-        if (llog_get_size(llh) <= 1) {
-                CDEBUG(D_SEC, "no local sptlrpc copy found\n");
-                GOTO(out_close, rc = 0);
-        }
-
-       rc = llog_process(NULL, llh, local_read_handler, (void *)conf, NULL);
-
-        if (rc == 0) {
-                conf->sc_local = 1;
-        } else {
-                sptlrpc_conf_free_rsets(conf);
-        }
-
-out_close:
-       llog_close(NULL, llh);
-out_pop:
-       pop_ctxt(&saved, &obd->obd_lvfs_ctxt);
-       llog_ctxt_put(ctxt);
-       CDEBUG(D_SEC, "target %s: read local sptlrpc conf: rc = %d\n",
-               obd->obd_name, rc);
-       RETURN(rc);
-}
-
-
 /**
  * called by target devices, extract sptlrpc rules which applies to
  * this target, to be used for future rpc flavor checking.
  */
 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
-                                  struct sptlrpc_rule_set *rset,
-                                  int initial)
-{
-        struct sptlrpc_conf      *conf;
-        struct sptlrpc_conf_tgt  *conf_tgt;
-        enum lustre_sec_part      sp_dst;
-        char                      fsname[MTI_NAME_MAXLEN];
-        int                       rc = 0;
-        ENTRY;
-
-        if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
-                sp_dst = LUSTRE_SP_MDT;
-        } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
-                sp_dst = LUSTRE_SP_OST;
-        } else {
-                CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
-                RETURN(-EINVAL);
-        }
-        CDEBUG(D_SEC, "get rules for target %s\n", obd->obd_uuid.uuid);
+                                 struct sptlrpc_rule_set *rset)
+{
+       struct sptlrpc_conf *conf;
+       struct sptlrpc_conf_tgt *conf_tgt;
+       enum lustre_sec_part sp_dst;
+       char fsname[MTI_NAME_MAXLEN];
+       int rc = 0;
+       ENTRY;
+
+       if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
+               sp_dst = LUSTRE_SP_MDT;
+       } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
+               sp_dst = LUSTRE_SP_OST;
+       } else {
+               CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
+               RETURN(-EINVAL);
+       }
 
-        target2fsname(obd->obd_uuid.uuid, fsname, sizeof(fsname));
+       target2fsname(obd->obd_uuid.uuid, fsname, sizeof(fsname));
 
        mutex_lock(&sptlrpc_conf_lock);
-
-        conf = sptlrpc_conf_get(fsname, 0);
-        if (conf == NULL) {
-                CERROR("missing sptlrpc config log\n");
-                GOTO(out, rc);
-        }
-
-        if (conf->sc_updated  == 0) {
-                /*
-                 * always read from local copy. here another option is
-                 * if we already have a local copy (read from another
-                 * target device hosted on the same node) we simply use that.
-                 */
-                if (conf->sc_local)
-                        sptlrpc_conf_free_rsets(conf);
-
-                sptlrpc_target_local_read_conf(obd, conf);
-        } else {
-                LASSERT(conf->sc_local == 0);
-
-                /* write a local copy */
-                if (initial || conf->sc_modified)
-                        sptlrpc_target_local_copy_conf(obd, conf);
-                else
-                        CDEBUG(D_SEC, "unchanged, skip updating local copy\n");
-        }
-
-        /* extract rule set for this target */
-        conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
-
-        rc = sptlrpc_rule_set_extract(&conf->sc_rset,
-                                      conf_tgt ? &conf_tgt->sct_rset: NULL,
-                                      LUSTRE_SP_ANY, sp_dst, rset);
-out:
+       conf = sptlrpc_conf_get(fsname, 0);
+       if (conf == NULL) {
+               CERROR("missing sptlrpc config log\n");
+               rc = -EFAULT;
+       } else {
+               /* extract rule set for this target */
+               conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
+
+               rc = sptlrpc_rule_set_extract(&conf->sc_rset,
+                                     conf_tgt ? &conf_tgt->sct_rset : NULL,
+                                     LUSTRE_SP_ANY, sp_dst, rset);
+       }
        mutex_unlock(&sptlrpc_conf_lock);
-        RETURN(rc);
+
+       RETURN(rc);
 }
 
 int  sptlrpc_conf_init(void)
index 1873e7a..c93e87d 100644 (file)
@@ -97,34 +97,3 @@ void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
        current->fs->umask = saved->umask;
 }
 EXPORT_SYMBOL(pop_ctxt);
-
-/* utility to rename a file */
-int lustre_rename(struct dentry *dir, struct vfsmount *mnt,
-                 char *oldname, char *newname)
-{
-       struct dentry *dchild_old, *dchild_new;
-       int err = 0;
-       ENTRY;
-
-       ASSERT_KERNEL_CTXT("kernel doing rename outside kernel context\n");
-       CDEBUG(D_INODE, "renaming file %.*s to %.*s\n",
-              (int)strlen(oldname), oldname, (int)strlen(newname), newname);
-
-       dchild_old = ll_lookup_one_len(oldname, dir, strlen(oldname));
-       if (IS_ERR(dchild_old))
-               RETURN(PTR_ERR(dchild_old));
-
-       if (!dchild_old->d_inode)
-               GOTO(put_old, err = -ENOENT);
-
-       dchild_new = ll_lookup_one_len(newname, dir, strlen(newname));
-       if (IS_ERR(dchild_new))
-               GOTO(put_old, err = PTR_ERR(dchild_new));
-
-       err = ll_vfs_rename(dir->d_inode, dchild_old, dir->d_inode, dchild_new);
-
-       dput(dchild_new);
-put_old:
-       dput(dchild_old);
-       RETURN(err);
-}
index 81aa6f4..d5eb49d 100644 (file)
@@ -893,7 +893,7 @@ int tgt_connect_check_sptlrpc(struct ptlrpc_request *req, struct obd_export *exp
        return rc;
 }
 
-int tgt_adapt_sptlrpc_conf(struct lu_target *tgt, int initial)
+int tgt_adapt_sptlrpc_conf(struct lu_target *tgt)
 {
        struct sptlrpc_rule_set  tmp_rset;
        int                      rc;
@@ -904,7 +904,7 @@ int tgt_adapt_sptlrpc_conf(struct lu_target *tgt, int initial)
        }
 
        sptlrpc_rule_set_init(&tmp_rset);
-       rc = sptlrpc_conf_target_get_rules(tgt->lut_obd, &tmp_rset, initial);
+       rc = sptlrpc_conf_target_get_rules(tgt->lut_obd, &tmp_rset);
        if (rc) {
                CERROR("%s: failed get sptlrpc rules: rc = %d\n",
                       tgt_name(tgt), rc);