X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmgs%2Fmgs_llog.c;h=726262f80bd8f44fca7629113d922e4ccdc76f51;hp=9b1877f427a84094ca173dff71f7e4119695198c;hb=9db2fa9133b15a99a1d5a04914964a015de32367;hpb=06d7b25e75d46b935e7cecb255f02794a751813e diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 9b1877f..726262f 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -71,6 +71,7 @@ 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 +108,8 @@ int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs, } /* filter out ".bak" files */ - /* sizeof(".bak") - 1 == 3 */ - if (key_sz >= 3 && - !memcmp(".bak", key + key_sz - 3, 3)) { + if (key_sz >= suffix_len && + !memcmp(".bak", key + key_sz - suffix_len, suffix_len)) { CDEBUG(D_MGS, "Skipping backup file %.*s\n", key_sz, key); goto next; @@ -191,7 +191,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 +211,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)); @@ -969,18 +971,23 @@ out_pop: RETURN(rc); } +enum replace_state { + REPLACE_COPY = 0, + REPLACE_SKIP, + REPLACE_DONE, + REPLACE_UUID, + REPLACE_SETUP +}; + /** This structure is passed to mgs_replace_handler */ struct mgs_replace_data { /* Nids are replaced for this target device */ struct mgs_target_info target; /* Temporary modified llog */ struct llog_handle *temp_llh; - /* Flag is set if in target block*/ - int in_target_device; - /* Nids already added. Just skip (multiple nids) */ - int device_nids_added; - /* Flag is set if this block should not be copied */ - int skip_it; + enum replace_state state; + char *failover; + char *nodeuuid; }; /** @@ -1006,13 +1013,13 @@ static int check_markers(struct lustre_cfg *lcfg, and can be restored if needed */ if ((marker->cm_flags & (CM_SKIP | CM_START)) == (CM_SKIP | CM_START)) { - mrd->skip_it = 1; + mrd->state = REPLACE_SKIP; return 1; } if ((marker->cm_flags & (CM_SKIP | CM_END)) == (CM_SKIP | CM_END)) { - mrd->skip_it = 0; + mrd->state = REPLACE_COPY; return 1; } @@ -1020,10 +1027,10 @@ static int check_markers(struct lustre_cfg *lcfg, LASSERT(!(marker->cm_flags & CM_START) || !(marker->cm_flags & CM_END)); if (marker->cm_flags & CM_START) { - mrd->in_target_device = 1; - mrd->device_nids_added = 0; + mrd->state = REPLACE_UUID; + mrd->failover = NULL; } else if (marker->cm_flags & CM_END) - mrd->in_target_device = 0; + mrd->state = REPLACE_COPY; } } @@ -1109,38 +1116,56 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, int nids_added = 0; lnet_nid_t nid; char *ptr; - int rc; + int rc = 0; - if (lcfg->lcfg_command == LCFG_ADD_UUID) { + if (mrd->state == REPLACE_UUID && + lcfg->lcfg_command == LCFG_ADD_UUID) { /* LCFG_ADD_UUID command found. Let's skip original command and add passed nids */ ptr = mrd->target.mti_params; while (class_parse_nid(ptr, &nid, &ptr) == 0) { + if (!mrd->nodeuuid) { + rc = name_create(&mrd->nodeuuid, + libcfs_nid2str(nid), ""); + if (rc) { + CERROR("Can't create uuid for " + "nid %s, device %s\n", + libcfs_nid2str(nid), + mrd->target.mti_svname); + return rc; + } + } CDEBUG(D_MGS, "add nid %s with uuid %s, " "device %s\n", libcfs_nid2str(nid), mrd->target.mti_params, - mrd->target.mti_svname); + mrd->nodeuuid); rc = record_add_uuid(env, mrd->temp_llh, nid, - mrd->target.mti_params); + mrd->nodeuuid); if (!rc) nids_added++; + + if (*ptr == ':') { + mrd->failover = ptr; + break; + } } if (nids_added == 0) { CERROR("No new nids were added, nid %s with uuid %s, " "device %s\n", libcfs_nid2str(nid), - mrd->target.mti_params, + mrd->nodeuuid ? mrd->nodeuuid : "NULL", mrd->target.mti_svname); - RETURN(-ENXIO); + name_destroy(&mrd->nodeuuid); + return -ENXIO; } else { - mrd->device_nids_added = 1; + mrd->state = REPLACE_SETUP; } return nids_added; } - if (mrd->device_nids_added && lcfg->lcfg_command == LCFG_SETUP) { + if (mrd->state == REPLACE_SETUP && lcfg->lcfg_command == LCFG_SETUP) { /* LCFG_SETUP command found. UUID should be changed */ rc = record_setup(env, mrd->temp_llh, @@ -1148,13 +1173,55 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, lustre_cfg_string(lcfg, 0), /* s1 is not changed */ lustre_cfg_string(lcfg, 1), - /* new uuid should be - the full nidlist */ - mrd->target.mti_params, + mrd->nodeuuid, /* s3 is not changed */ lustre_cfg_string(lcfg, 3), /* s4 is not changed */ lustre_cfg_string(lcfg, 4)); + + name_destroy(&mrd->nodeuuid); + if (rc) + return rc; + + if (mrd->failover) { + ptr = mrd->failover; + while (class_parse_nid(ptr, &nid, &ptr) == 0) { + if (mrd->nodeuuid == NULL) { + rc = name_create(&mrd->nodeuuid, + libcfs_nid2str(nid), + ""); + if (rc) + return rc; + } + + CDEBUG(D_MGS, "add nid %s for failover %s\n", + libcfs_nid2str(nid), mrd->nodeuuid); + rc = record_add_uuid(env, mrd->temp_llh, nid, + mrd->nodeuuid); + if (rc) { + name_destroy(&mrd->nodeuuid); + return rc; + } + if (*ptr == ':') { + rc = record_add_conn(env, + mrd->temp_llh, + lustre_cfg_string(lcfg, 0), + mrd->nodeuuid); + name_destroy(&mrd->nodeuuid); + if (rc) + return rc; + } + } + if (mrd->nodeuuid) { + rc = record_add_conn(env, mrd->temp_llh, + lustre_cfg_string(lcfg, 0), + mrd->nodeuuid); + name_destroy(&mrd->nodeuuid); + if (rc) + return rc; + } + } + mrd->state = REPLACE_DONE; return rc ? rc : 1; } @@ -1200,20 +1267,24 @@ static int mgs_replace_nids_handler(const struct lu_env *env, } rc = check_markers(lcfg, mrd); - if (rc || mrd->skip_it) + if (rc || mrd->state == REPLACE_SKIP) GOTO(skip_out, rc = 0); /* Write to new log all commands outside target device block */ - if (!mrd->in_target_device) + if (mrd->state == REPLACE_COPY) GOTO(copy_out, rc = 0); - /* Skip all other LCFG_ADD_UUID and LCFG_ADD_CONN records - (failover nids) for this target, assuming that if then - primary is changing then so is the failover */ - if (mrd->device_nids_added && + if (mrd->state == REPLACE_DONE && (lcfg->lcfg_command == LCFG_ADD_UUID || - lcfg->lcfg_command == LCFG_ADD_CONN)) + lcfg->lcfg_command == LCFG_ADD_CONN)) { + if (!mrd->failover) + CWARN("Previous failover is deleted, but new one is " + "not set. This means you configure system " + "without failover or passed wrong replace_nids " + "command parameters. Device %s, passed nids %s\n", + mrd->target.mti_svname, mrd->target.mti_params); GOTO(skip_out, rc = 0); + } rc = process_command(env, lcfg, mrd); if (rc < 0) @@ -1463,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); } /** @@ -1520,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) { @@ -1533,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) @@ -1597,9 +1675,9 @@ static int mgs_clear_config_handler(const struct lu_env *env, marker = lustre_cfg_buf(lcfg, 1); if (marker->cm_flags & CM_SKIP) { if (marker->cm_flags & CM_START) - mrd->skip_it = 1; + mrd->state = REPLACE_SKIP; if (marker->cm_flags & CM_END) - mrd->skip_it = 0; + mrd->state = REPLACE_COPY; /* SKIP section started or finished */ CDEBUG(D_MGS, "Skip idx=%d, rc=%d, len=%d, " "cmd %x %s %s\n", rec->lrh_index, rc, @@ -1609,7 +1687,7 @@ static int mgs_clear_config_handler(const struct lu_env *env, RETURN(0); } } else { - if (mrd->skip_it) { + if (mrd->state == REPLACE_SKIP) { /* record enclosed between SKIP markers, skip it */ CDEBUG(D_MGS, "Skip idx=%d, rc=%d, len=%d, " "cmd %x %s %s\n", rec->lrh_index, rc, @@ -2651,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); @@ -2682,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); @@ -2704,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); } @@ -3210,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) @@ -3290,7 +3368,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; @@ -3314,6 +3399,7 @@ static int mgs_write_log_sys(const struct lu_env *env, } } *ptr = sep; +out_rec_free: lustre_cfg_rec_free(lcr); return rc; } @@ -3830,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); @@ -3922,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 @@ -4418,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; } @@ -4622,6 +4702,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]; @@ -5164,9 +5245,9 @@ 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; char *ptr; param += len + 1; @@ -5181,8 +5262,30 @@ static int mgs_set_param2(const struct lu_env *env, struct mgs_device *mgs, snprintf(mti->mti_svname, sizeof(mti->mti_svname), "%.*s", (int)len, param); - obdname2fsname(mti->mti_svname, mti->mti_fsname, - sizeof(mti->mti_fsname)); + mutex_lock(&mgs->mgs_mutex); + if (unlikely(list_empty(&mgs->mgs_fs_db_list))) { + mutex_unlock(&mgs->mgs_mutex); + GOTO(out, rc = -ENODEV); + } + + list_for_each(tmp, &mgs->mgs_fs_db_list) { + fsdb = list_entry(tmp, struct fs_db, fsdb_list); + if (fsdb->fsdb_has_lproc_entry && + strcmp(fsdb->fsdb_name, "params") != 0 && + strstr(param, fsdb->fsdb_name)) { + snprintf(mti->mti_svname, + sizeof(mti->mti_svname), "%s", + fsdb->fsdb_name); + break; + } + fsdb = NULL; + } + + if (!fsdb) { + snprintf(mti->mti_svname, sizeof(mti->mti_svname), + "general"); + } + mutex_unlock(&mgs->mgs_mutex); } else { snprintf(mti->mti_svname, sizeof(mti->mti_svname), "general"); } @@ -5294,13 +5397,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); @@ -5321,11 +5424,15 @@ 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: @@ -5347,15 +5454,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: @@ -5385,6 +5498,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; }