Whamcloud - gitweb
LU-13609 llog: list all the log files correctly on MGS/MDT
[fs/lustre-release.git] / lustre / mgs / mgs_llog.c
index 45f7678..3025dfb 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;
@@ -1515,23 +1513,21 @@ 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 mdt_idx)
@@ -1594,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) {
@@ -1607,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)
@@ -3285,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)
@@ -3913,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);
@@ -4005,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
@@ -4485,8 +4478,9 @@ int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
 {
        struct list_head         log_list;
        struct mgs_direntry     *dirent, *n;
-       char                    *out, *suffix;
-       int                      l, remains, rc;
+       char                    *out, *suffix, prefix[] = "config_log: ";
+       int                      prefix_len = strlen(prefix);
+       int                      l, remains, start = 0, rc;
 
        ENTRY;
 
@@ -4497,19 +4491,39 @@ int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
 
        out = data->ioc_bulk;
        remains = data->ioc_inllen1;
+       /* OBD_FAIL: fetch the config_log records from the specified one */
+       if (OBD_FAIL_CHECK(OBD_FAIL_CATLIST))
+               data->ioc_count = cfs_fail_val;
+
        list_for_each_entry_safe(dirent, n, &log_list, mde_list) {
                list_del_init(&dirent->mde_list);
                suffix = strrchr(dirent->mde_name, '-');
                if (suffix != NULL) {
-                       l = scnprintf(out, remains, "config_log: %s\n",
+                       l = prefix_len + dirent->mde_len + 1;
+                       if (remains - 1 < 0) {
+                               /* No enough space for this record */
+                               mgs_direntry_free(dirent);
+                               goto out;
+                       }
+                       start++;
+                       if (start < data->ioc_count) {
+                               mgs_direntry_free(dirent);
+                                       continue;
+                       }
+                       l = scnprintf(out, remains, "%s%s\n", prefix,
                                      dirent->mde_name);
                        out += l;
                        remains -= l;
                }
                mgs_direntry_free(dirent);
-               if (remains <= 0)
-                       break;
+               if (remains == 0)
+                       /* Full */
+                       goto out;
        }
+       /* Finished */
+       start = 0;
+out:
+       data->ioc_count = start;
        RETURN(rc);
 }
 
@@ -4927,7 +4941,7 @@ static int mgs_xattr_del(const struct lu_env *env, struct dt_object *obj)
 
        ENTRY;
 
-       dev = container_of0(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
+       dev = container_of(obj->do_lu.lo_dev, struct dt_device, dd_lu_dev);
        th = dt_trans_create(env, dev);
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
@@ -5439,10 +5453,16 @@ int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
                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;
+       case LCFG_NODEMAP_FORBID_ENCRYPT:
+               rc = kstrtobool(param, &bool_switch);
+               if (rc == 0)
+                       rc = nodemap_set_forbid_encryption(nodemap_name,
+                                                          bool_switch);
+               break;
        case LCFG_NODEMAP_MAP_MODE:
                if (strcmp("both", param) == 0)
                        rc = nodemap_set_mapping_mode(nodemap_name,