X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmgs%2Fmgs_llog.c;h=726262f80bd8f44fca7629113d922e4ccdc76f51;hp=841afcdc4cb3201a02974e5195672a7e4ed2414e;hb=9db2fa9133b15a99a1d5a04914964a015de32367;hpb=f843facff59226d3788d855d1d6948523ab8d944 diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 841afcd..726262f 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -1534,12 +1534,15 @@ static int only_mgs_is_running(struct obd_device *mgs_obd) return (num_devices <= 3) && (num_exports == 0); } -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]; - sprintf(mdt_index, "-MDT%04x", i); - return name_create(logname, fsname, mdt_index); + if (mdt_idx > INDEX_MAP_MAX_VALUE) + return -E2BIG; + + snprintf(postfix, sizeof(postfix), "-MDT%04x", mdt_idx); + return name_create(logname, fsname, postfix); } /** @@ -1591,7 +1594,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) { @@ -1604,7 +1609,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) @@ -2722,13 +2729,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); @@ -2753,17 +2761,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); @@ -2775,7 +2783,7 @@ out_end: out_lod: name_destroy(&lovname); out_free: - OBD_FREE(uuid, sizeof(struct obd_uuid)); + OBD_FREE_PTR(uuid); RETURN(rc); } @@ -3281,8 +3289,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) @@ -3909,16 +3916,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); @@ -4001,18 +4008,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 @@ -4497,8 +4498,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; }