Whamcloud - gitweb
LU-3181 mdt: mdt_cross_open should allow open by FID on MDT1
[fs/lustre-release.git] / lustre / ptlrpc / sec_config.c
index 4685289..30ac1ec 100644 (file)
@@ -114,8 +114,7 @@ int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr)
                 return 0;
         }
 
-        strncpy(buf, str, sizeof(buf));
-        buf[sizeof(buf) - 1] = '\0';
+       strlcpy(buf, str, sizeof(buf));
 
         bulk = strchr(buf, '-');
         if (bulk)
@@ -264,15 +263,15 @@ EXPORT_SYMBOL(sptlrpc_rule_set_free);
  */
 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
 {
-        struct sptlrpc_rule *rules;
-        int nslot;
+       struct sptlrpc_rule *rules;
+       int nslot;
 
-        cfs_might_sleep();
+       might_sleep();
 
-        if (rset->srs_nrule < rset->srs_nslot)
-                return 0; 
+       if (rset->srs_nrule < rset->srs_nslot)
+               return 0;
 
-        nslot = rset->srs_nslot + 8;
+       nslot = rset->srs_nslot + 8;
 
         /* better use realloc() if available */
         OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
@@ -321,14 +320,14 @@ static inline int rule_match_net(struct sptlrpc_rule *r1,
 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset, 
                            struct sptlrpc_rule *rule)
 {
-        struct sptlrpc_rule      *p = rset->srs_rules;
-        int                       spec_dir, spec_net;
-        int                       rc, n, match = 0;
+       struct sptlrpc_rule      *p = rset->srs_rules;
+       int                       spec_dir, spec_net;
+       int                       rc, n, match = 0;
 
-        cfs_might_sleep();
+       might_sleep();
 
-        spec_net = rule_spec_net(rule);
-        spec_dir = rule_spec_dir(rule);
+       spec_net = rule_spec_net(rule);
+       spec_dir = rule_spec_dir(rule);
 
         for (n = 0; n < rset->srs_nrule; n++) {
                 p = &rset->srs_rules[n]; 
@@ -461,16 +460,16 @@ static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
                                     enum lustre_sec_part to,
                                     struct sptlrpc_rule_set *rset)
 {
-        struct sptlrpc_rule_set *src[2] = { gen, tgt };
-        struct sptlrpc_rule     *rule;
-        int                      i, n, rc;
+       struct sptlrpc_rule_set *src[2] = { gen, tgt };
+       struct sptlrpc_rule     *rule;
+       int                      i, n, rc;
 
-        cfs_might_sleep();
+       might_sleep();
 
-        /* merge general rules firstly, then target-specific rules */
-        for (i = 0; i < 2; i++) {
-                if (src[i] == NULL)
-                        continue;
+       /* merge general rules firstly, then target-specific rules */
+       for (i = 0; i < 2; i++) {
+               if (src[i] == NULL)
+                       continue;
 
                 for (n = 0; n < src[i]->srs_nrule; n++) {
                         rule = &src[i]->srs_rules[n];
@@ -619,7 +618,11 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
         if (conf == NULL)
                 return NULL;
 
-        strcpy(conf->sc_fsname, fsname);
+       if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
+           sizeof(conf->sc_fsname)) {
+               OBD_FREE_PTR(conf);
+               return NULL;
+       }
         sptlrpc_rule_set_init(&conf->sc_rset);
         CFS_INIT_LIST_HEAD(&conf->sc_tgts);
         cfs_list_add(&conf->sc_list, &sptlrpc_confs);
@@ -751,11 +754,13 @@ void sptlrpc_conf_log_update_begin(const char *logname)
        mutex_lock(&sptlrpc_conf_lock);
 
         conf = sptlrpc_conf_get(fsname, 0);
-        if (conf && conf->sc_local) {
-                LASSERT(conf->sc_updated == 0);
-                sptlrpc_conf_free_rsets(conf);
-        }
-        conf->sc_modified = 0;
+       if (conf) {
+               if (conf->sc_local) {
+                       LASSERT(conf->sc_updated == 0);
+                       sptlrpc_conf_free_rsets(conf);
+               }
+               conf->sc_modified = 0;
+       }
 
        mutex_unlock(&sptlrpc_conf_lock);
 }
@@ -963,32 +968,26 @@ static int sptlrpc_record_rule_set(struct llog_handle *llh,
                                    char *target,
                                    struct sptlrpc_rule_set *rset)
 {
-        struct lustre_cfg_bufs  bufs;
-        struct lustre_cfg      *lcfg;
-        struct llog_rec_hdr     rec;
-        int                     buflen;
-        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);
-                lcfg = lustre_cfg_new(LCFG_SPTLRPC_CONF, &bufs);
-                LASSERT(lcfg);
-
-                buflen = lustre_cfg_len(lcfg->lcfg_bufcount,
-                                        lcfg->lcfg_buflens);
-                rec.lrh_len = llog_data_len(buflen);
-                rec.lrh_type = OBD_CFG_REC;
-               rc = llog_write(NULL, llh, &rec, NULL, 0, (void *)lcfg, -1);
-                if (rc)
-                        CERROR("failed to write a rec: rc = %d\n", rc);
-                lustre_cfg_free(lcfg);
-        }
-        return 0;
+       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,
@@ -1019,11 +1018,11 @@ int sptlrpc_target_local_copy_conf(struct obd_device *obd,
         int                   rc;
         ENTRY;
 
-        ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+       ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
        if (ctxt == NULL)
-                RETURN(-EINVAL);
+               RETURN(-EINVAL);
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &obd->obd_lvfs_ctxt);
 
        dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, current->fs->pwd.dentry,
                                    strlen(MOUNT_CONFIGS_DIR));
@@ -1058,13 +1057,13 @@ out_close:
                rc = lustre_rename(dentry, obd->obd_lvfs_ctxt.pwdmnt,
                                   LOG_SPTLRPC_TMP, LOG_SPTLRPC);
 out_dput:
-        l_dput(dentry);
+       dput(dentry);
 out_ctx:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        llog_ctxt_put(ctxt);
-        CDEBUG(D_SEC, "target %s: write local sptlrpc conf: rc = %d\n",
-               obd->obd_name, rc);
-        RETURN(rc);
+       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,
@@ -1116,7 +1115,7 @@ int sptlrpc_target_local_read_conf(struct obd_device *obd,
                 RETURN(-EINVAL);
         }
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       push_ctxt(&saved, &obd->obd_lvfs_ctxt);
 
        rc = llog_open(NULL, ctxt, &llh, NULL, LOG_SPTLRPC, LLOG_OPEN_EXISTS);
        if (rc < 0) {
@@ -1145,11 +1144,11 @@ int sptlrpc_target_local_read_conf(struct obd_device *obd,
 out_close:
        llog_close(NULL, llh);
 out_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        llog_ctxt_put(ctxt);
-        CDEBUG(D_SEC, "target %s: read local sptlrpc conf: rc = %d\n",
-               obd->obd_name, rc);
-        RETURN(rc);
+       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);
 }
 
 #endif /* __KRENEL__ */