Whamcloud - gitweb
LU-12854 nodemap: allow boolean value for audit_mode
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index 5fa816d..b6fb67f 100644 (file)
@@ -71,7 +71,6 @@ int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
        struct mgs_direntry *de;
        char *key;
        int rc, key_sz;
-       size_t suffix_len = sizeof(".bak") - 1;
 
        INIT_LIST_HEAD(log_list);
 
@@ -107,9 +106,8 @@ int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
                                goto next;
                }
 
-               /* filter out ".bak" files */
-               if (key_sz >= suffix_len &&
-                   !memcmp(".bak", key + key_sz - suffix_len, suffix_len)) {
+               /* filter out backup files */
+               if (lu_name_is_backup_file(key, key_sz, NULL)) {
                        CDEBUG(D_MGS, "Skipping backup file %.*s\n",
                               key_sz, key);
                        goto next;
@@ -191,7 +189,7 @@ static int mgs_fsdb_handler(const struct lu_env *env, struct llog_handle *llh,
         int cfg_len = rec->lrh_len;
         char *cfg_buf = (char*) (rec + 1);
         struct lustre_cfg *lcfg;
-        __u32 index;
+       u32 index;
         int rc = 0;
         ENTRY;
 
@@ -211,12 +209,14 @@ static int mgs_fsdb_handler(const struct lu_env *env, struct llog_handle *llh,
         CDEBUG(D_INFO, "cmd %x %s %s\n", lcfg->lcfg_command,
                lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1));
 
-        /* Figure out ost indicies */
-        /* lov_modify_tgts add 0:lov1  1:ost1_UUID  2(index):0  3(gen):1 */
-        if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD ||
-            lcfg->lcfg_command == LCFG_LOV_DEL_OBD) {
-                index = simple_strtoul(lustre_cfg_string(lcfg, 2),
-                                       NULL, 10);
+       /* Figure out ost indicies */
+       /* lov_modify_tgts add 0:lov1  1:ost1_UUID  2(index):0  3(gen):1 */
+       if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD ||
+           lcfg->lcfg_command == LCFG_LOV_DEL_OBD) {
+               rc = kstrtouint(lustre_cfg_string(lcfg, 2), 10, &index);
+               if (rc)
+                       RETURN(rc);
+
                 CDEBUG(D_MGS, "OST index for %s is %u (%s)\n",
                        lustre_cfg_string(lcfg, 1), index,
                        lustre_cfg_string(lcfg, 2));
@@ -1513,31 +1513,32 @@ static int only_mgs_is_running(struct obd_device *mgs_obd)
                /* skip self export */
                if (exp == mgs_obd->obd_self_export)
                        continue;
-               if (exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS)
-                       continue;
 
                ++num_exports;
 
-               CERROR("%s: node %s still connected during replace_nids "
-                      "connect_flags:%llx\n",
-                      mgs_obd->obd_name,
-                      libcfs_nid2str(exp->exp_nid_stats->nid),
-                      exp_connect_flags(exp));
-
+               if (num_exports > 1)
+                       CERROR("%s: node %s still connected during replace_nids connect_flags:%llx\n",
+                              mgs_obd->obd_name,
+                              libcfs_nid2str(exp->exp_nid_stats->nid),
+                              exp_connect_flags(exp));
        }
        spin_unlock(&mgs_obd->obd_dev_lock);
 
-       /* osd, MGS and MGC + self_export
-          (wc -l /proc/fs/lustre/devices <= 2) && (non self exports == 0) */
-       return (num_devices <= 3) && (num_exports == 0);
+       /* osd, MGS and MGC + MGC export (nosvc starts MGC)
+        *  (wc -l /proc/fs/lustre/devices <= 3) && (non self exports == 1)
+        */
+       return (num_devices <= 3) && (num_exports <= 1);
 }
 
-static int name_create_mdt(char **logname, char *fsname, int i)
+static int name_create_mdt(char **logname, char *fsname, int mdt_idx)
 {
-       char mdt_index[9];
+       char postfix[9];
+
+       if (mdt_idx > INDEX_MAP_MAX_VALUE)
+               return -E2BIG;
 
-       sprintf(mdt_index, "-MDT%04x", i);
-       return name_create(logname, fsname, mdt_index);
+       snprintf(postfix, sizeof(postfix), "-MDT%04x", mdt_idx);
+       return name_create(logname, fsname, postfix);
 }
 
 /**
@@ -1589,7 +1590,9 @@ int mgs_replace_nids(const struct lu_env *env,
        }
 
        /* Process client llogs */
-       name_create(&logname, fsname, "-client");
+       rc = name_create(&logname, fsname, "-client");
+       if (rc)
+               GOTO(out, rc);
        rc = mgs_replace_nids_log(env, mgs_obd, logname, devname, nids);
        name_destroy(&logname);
        if (rc) {
@@ -1602,7 +1605,9 @@ int mgs_replace_nids(const struct lu_env *env,
        for (i = 0; i < INDEX_MAP_SIZE * 8; i++) {
                if (!test_bit(i, fsdb->fsdb_mdt_index_map))
                        continue;
-               name_create_mdt(&logname, fsname, i);
+               rc = name_create_mdt(&logname, fsname, i);
+               if (rc)
+                       GOTO(out, rc);
                rc = mgs_replace_nids_log(env, mgs_obd, logname, devname, nids);
                name_destroy(&logname);
                if (rc)
@@ -2720,13 +2725,14 @@ static int mgs_write_log_mdt0(const struct lu_env *env,
 {
         char *log = mti->mti_svname;
         struct llog_handle *llh = NULL;
-        char *uuid, *lovname;
+       struct obd_uuid *uuid;
+       char *lovname;
         char mdt_index[6];
         char *ptr = mti->mti_params;
         int rc = 0, failout = 0;
         ENTRY;
 
-        OBD_ALLOC(uuid, sizeof(struct obd_uuid));
+       OBD_ALLOC_PTR(uuid);
         if (uuid == NULL)
                 RETURN(-ENOMEM);
 
@@ -2751,17 +2757,17 @@ static int mgs_write_log_mdt0(const struct lu_env *env,
        /* add MDT itself */
 
         /* FIXME this whole fn should be a single journal transaction */
-       sprintf(uuid, "%s_UUID", log);
+       sprintf(uuid->uuid, "%s_UUID", log);
        rc = record_marker(env, llh, fsdb, CM_START, log, "add mdt");
        if (rc)
                GOTO(out_lod, rc);
-       rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid);
+       rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid->uuid);
        if (rc)
                GOTO(out_end, rc);
        rc = record_mount_opt(env, llh, log, lovname, NULL);
        if (rc)
                GOTO(out_end, rc);
-       rc = record_setup(env, llh, log, uuid, mdt_index, lovname,
+       rc = record_setup(env, llh, log, uuid->uuid, mdt_index, lovname,
                         failout ? "n" : "f");
        if (rc)
                GOTO(out_end, rc);
@@ -2773,7 +2779,7 @@ out_end:
 out_lod:
        name_destroy(&lovname);
 out_free:
-        OBD_FREE(uuid, sizeof(struct obd_uuid));
+        OBD_FREE_PTR(uuid);
         RETURN(rc);
 }
 
@@ -3279,8 +3285,7 @@ static int mgs_wlp_lcfg(const struct lu_env *env,
        int rc, del;
 
        /* Erase any old settings of this same parameter */
-       memcpy(comment, ptr, MTI_NAME_MAXLEN);
-       comment[MTI_NAME_MAXLEN - 1] = 0;
+       strlcpy(comment, ptr, sizeof(comment));
        /* But don't try to match the value. */
        tmp = strchr(comment, '=');
        if (tmp != NULL)
@@ -3359,7 +3364,14 @@ static int mgs_write_log_sys(const struct lu_env *env,
                return -ENOMEM;
 
        lcfg = &lcr->lcr_cfg;
-       lcfg->lcfg_num = convert ? simple_strtoul(tmp, NULL, 0) : 0;
+       if (convert) {
+               rc = kstrtouint(tmp, 0, &lcfg->lcfg_num);
+               if (rc)
+                       GOTO(out_rec_free, rc);
+       } else {
+               lcfg->lcfg_num = 0;
+       }
+
        /* truncate the comment to the parameter name */
        ptr = tmp - 1;
        sep = *ptr;
@@ -3383,6 +3395,7 @@ static int mgs_write_log_sys(const struct lu_env *env,
                }
        }
        *ptr = sep;
+out_rec_free:
        lustre_cfg_rec_free(lcr);
        return rc;
 }
@@ -3899,16 +3912,16 @@ static int mgs_write_log_param(const struct lu_env *env,
        if (class_match_param(ptr, PARAM_NETWORK, NULL) == 0)
                GOTO(end, rc);
 
-        /* Processed in mgs_write_log_ost */
-        if (class_match_param(ptr, PARAM_FAILMODE, NULL) == 0) {
-                if (mti->mti_flags & LDD_F_PARAM) {
-                        LCONSOLE_ERROR_MSG(0x169, "%s can only be "
-                                           "changed with tunefs.lustre"
-                                           "and --writeconf\n", ptr);
-                        rc = -EPERM;
-                }
-                GOTO(end, rc);
-        }
+       /* Processed in mgs_write_log_ost */
+       if (class_match_param(ptr, PARAM_FAILMODE, NULL) == 0) {
+               if (mti->mti_flags & LDD_F_PARAM) {
+                       LCONSOLE_ERROR_MSG(0x169,
+                                          "%s can only be changed with tunefs.lustre and --writeconf\n",
+                                          ptr);
+                       rc = -EPERM;
+               }
+               GOTO(end, rc);
+       }
 
         if (class_match_param(ptr, PARAM_SRPC, NULL) == 0) {
                rc = mgs_srpc_set_param(env, mgs, fsdb, mti, ptr);
@@ -3991,18 +4004,12 @@ static int mgs_write_log_param(const struct lu_env *env,
                }
 active_err:
                if (rc < 0) {
-                       LCONSOLE_ERROR_MSG(0x145, "Couldn't find %s in"
-                                          "log (%d). No permanent "
-                                          "changes were made to the "
-                                          "config log.\n",
+                       LCONSOLE_ERROR_MSG(0x145,
+                                          "Couldn't find %s in log (%d). No permanent changes were made to the config log.\n",
                                           mti->mti_svname, rc);
                        if (test_bit(FSDB_OLDLOG14, &fsdb->fsdb_flags))
-                               LCONSOLE_ERROR_MSG(0x146, "This may be"
-                                                  " because the log"
-                                                  "is in the old 1.4"
-                                                  "style. Consider "
-                                                  " --writeconf to "
-                                                  "update the logs.\n");
+                               LCONSOLE_ERROR_MSG(0x146,
+                                                  "This may be because the log is in the old 1.4 style. Consider --writeconf to update the logs.\n");
                        GOTO(end, rc);
                }
                /* Fall through to osc/mdc proc for deactivating live
@@ -4487,8 +4494,8 @@ int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
                list_del_init(&dirent->mde_list);
                suffix = strrchr(dirent->mde_name, '-');
                if (suffix != NULL) {
-                       l = snprintf(out, remains, "config_log: %s\n",
-                                    dirent->mde_name);
+                       l = scnprintf(out, remains, "config_log: %s\n",
+                                     dirent->mde_name);
                        out += l;
                        remains -= l;
                }
@@ -4691,6 +4698,7 @@ static int mgs_lcfg_fork_handler(const struct lu_env *env,
                        } /* else case fall through */
                } /* else case fall through */
        }
+       /* fallthrough */
        default: {
                for (i = 1; i < cnt; i++) {
                        o_buflen = o_lcfg->lcfg_buflens[i];
@@ -5233,7 +5241,6 @@ static int mgs_set_param2(const struct lu_env *env, struct mgs_device *mgs,
            sizeof(mti->mti_params))
                GOTO(out, rc = -E2BIG);
 
-       /* obdname2fsname reports devname as an obd device */
        len = strcspn(param, ".=");
        if (len && param[len] != '=') {
                struct list_head *tmp;
@@ -5386,13 +5393,13 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
                    enum lcfg_command_type cmd, const char *nodemap_name,
                    char *param)
 {
-       lnet_nid_t      nid[2];
-       __u32           idmap[2];
-       bool            bool_switch;
-       __u32           int_id;
-       int             rc = 0;
-       ENTRY;
+       lnet_nid_t nid[2];
+       u32 idmap[2];
+       bool bool_switch;
+       u32 int_id;
+       int rc = 0;
 
+       ENTRY;
        switch (cmd) {
        case LCFG_NODEMAP_ADD:
                rc = nodemap_add(nodemap_name);
@@ -5413,15 +5420,19 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
                rc = nodemap_del_range(nodemap_name, nid);
                break;
        case LCFG_NODEMAP_ADMIN:
-               bool_switch = simple_strtoul(param, NULL, 10);
+               rc = kstrtobool(param, &bool_switch);
+               if (rc)
+                       break;
                rc = nodemap_set_allow_root(nodemap_name, bool_switch);
                break;
        case LCFG_NODEMAP_DENY_UNKNOWN:
-               bool_switch = simple_strtoul(param, NULL, 10);
+               rc = kstrtobool(param, &bool_switch);
+               if (rc)
+                       break;
                rc = nodemap_set_deny_unknown(nodemap_name, bool_switch);
                break;
        case LCFG_NODEMAP_AUDIT_MODE:
-               rc = kstrtoul(param, 10, (unsigned long *)&bool_switch);
+               rc = kstrtobool(param, &bool_switch);
                if (rc == 0)
                        rc = nodemap_set_audit_mode(nodemap_name, bool_switch);
                break;
@@ -5439,15 +5450,21 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
                        rc = -EINVAL;
                break;
        case LCFG_NODEMAP_TRUSTED:
-               bool_switch = simple_strtoul(param, NULL, 10);
+               rc = kstrtobool(param, &bool_switch);
+               if (rc)
+                       break;
                rc = nodemap_set_trust_client_ids(nodemap_name, bool_switch);
                break;
        case LCFG_NODEMAP_SQUASH_UID:
-               int_id = simple_strtoul(param, NULL, 10);
+               rc = kstrtouint(param, 10, &int_id);
+               if (rc)
+                       break;
                rc = nodemap_set_squash_uid(nodemap_name, int_id);
                break;
        case LCFG_NODEMAP_SQUASH_GID:
-               int_id = simple_strtoul(param, NULL, 10);
+               rc = kstrtouint(param, 10, &int_id);
+               if (rc)
+                       break;
                rc = nodemap_set_squash_gid(nodemap_name, int_id);
                break;
        case LCFG_NODEMAP_ADD_UIDMAP:
@@ -5477,6 +5494,9 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
        case LCFG_NODEMAP_SET_FILESET:
                rc = nodemap_set_fileset(nodemap_name, param);
                break;
+       case LCFG_NODEMAP_SET_SEPOL:
+               rc = nodemap_set_sepol(nodemap_name, param);
+               break;
        default:
                rc = -EINVAL;
        }