goto next;
}
- /* filter out ".bak" files */
- /* sizeof(".bak") - 1 == 3 */
- if (key_sz >= 3 &&
- !memcmp(".bak", key + key_sz - 3, 3)) {
+ /* 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;
int cfg_len = rec->lrh_len;
char *cfg_buf = (char*) (rec + 1);
struct lustre_cfg *lcfg;
- __u32 index;
+ u32 index;
int rc = 0;
ENTRY;
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));
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;
};
/**
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;
}
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;
}
}
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,
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;
}
}
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)
/* 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);
}
/**
}
/* 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) {
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)
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,
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,
{
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);
/* 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);
out_lod:
name_destroy(&lovname);
out_free:
- OBD_FREE(uuid, sizeof(struct obd_uuid));
+ OBD_FREE_PTR(uuid);
RETURN(rc);
}
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)
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;
}
}
*ptr = sep;
+out_rec_free:
lustre_cfg_rec_free(lcr);
return rc;
}
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);
}
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
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;
}
} /* else case fall through */
} /* else case fall through */
}
+ /* fallthrough */
default: {
for (i = 1; i < cnt; i++) {
o_buflen = o_lcfg->lcfg_buflens[i];
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;
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");
}
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);
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;
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:
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;
}