* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
struct llog_rec_hdr *rec,
void *data)
{
- struct llog_rec_hdr local_rec = *rec;
struct mgs_replace_uuid_lookup *mrul;
struct lustre_cfg *lcfg = REC_DATA(rec);
int cfg_len = REC_DATA_LEN(rec);
RETURN(0);
copy_out:
/* Record is placed in temporary llog as is */
- local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
- rc = llog_write(env, mrul->temp_llh, &local_rec, NULL, 0,
- (void *)lcfg, -1);
+ rc = llog_write(env, mrul->temp_llh, rec, NULL, 0, NULL, -1);
CDEBUG(D_MGS, "Copied idx=%d, rc=%d, len=%d, cmd %x %s %s\n",
rec->lrh_index, rc, rec->lrh_len, lcfg->lcfg_command,
RETURN(rc);
}
-static int mgs_backup_llog(const struct lu_env *env,
- struct obd_device *mgs,
- char *fsname, char *backup)
+static int mgs_log_is_empty(const struct lu_env *env,
+ struct mgs_device *mgs, char *name)
{
- struct obd_uuid *uuid;
- struct llog_handle *orig_llh, *bak_llh;
- struct llog_ctxt *lctxt;
- int rc, rc2;
- ENTRY;
-
- lctxt = llog_get_context(mgs, LLOG_CONFIG_ORIG_CTXT);
- if (!lctxt) {
- CERROR("%s: missing llog context\n", mgs->obd_name);
- GOTO(out, rc = -EINVAL);
- }
-
- /* Make sure there's no old backup log */
- rc = llog_erase(env, lctxt, NULL, backup);
- if (rc < 0 && rc != -ENOENT)
- GOTO(out_put, rc);
-
- /* open backup log */
- rc = llog_open_create(env, lctxt, &bak_llh, NULL, backup);
- if (rc) {
- CERROR("%s: backup logfile open %s: rc = %d\n",
- mgs->obd_name, backup, rc);
- GOTO(out_put, rc);
- }
-
- /* set the log header uuid */
- OBD_ALLOC_PTR(uuid);
- if (uuid == NULL)
- GOTO(out_put, rc = -ENOMEM);
- obd_str2uuid(uuid, backup);
- rc = llog_init_handle(env, bak_llh, LLOG_F_IS_PLAIN, uuid);
- OBD_FREE_PTR(uuid);
- if (rc)
- GOTO(out_close1, rc);
-
- /* open original log */
- rc = llog_open(env, lctxt, &orig_llh, NULL, fsname,
- LLOG_OPEN_EXISTS);
- if (rc < 0) {
- if (rc == -ENOENT)
- rc = 0;
- GOTO(out_close1, rc);
- }
-
- rc = llog_init_handle(env, orig_llh, LLOG_F_IS_PLAIN, NULL);
- if (rc)
- GOTO(out_close2, rc);
+ struct llog_ctxt *ctxt;
+ int rc;
- /* Copy remote log */
- rc = llog_process(env, orig_llh, llog_copy_handler,
- (void *)bak_llh, NULL);
+ ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
+ LASSERT(ctxt != NULL);
-out_close2:
- rc2 = llog_close(env, orig_llh);
- if (!rc)
- rc = rc2;
-out_close1:
- rc2 = llog_close(env, bak_llh);
- if (!rc)
- rc = rc2;
-out_put:
- if (lctxt)
- llog_ctxt_put(lctxt);
-out:
- if (rc)
- CERROR("%s: Failed to backup log %s: rc = %d\n",
- mgs->obd_name, fsname, rc);
- RETURN(rc);
+ rc = llog_is_empty(env, ctxt, name);
+ llog_ctxt_put(ctxt);
+ return rc;
}
-static int mgs_log_is_empty(const struct lu_env *env, struct mgs_device *mgs,
- char *name);
-
static int mgs_replace_nids_log(const struct lu_env *env,
struct obd_device *mgs, struct fs_db *fsdb,
char *logname, char *devname, char *nids)
struct llog_ctxt *ctxt;
struct mgs_replace_uuid_lookup *mrul;
struct mgs_device *mgs_dev = lu2mgs_dev(mgs->obd_lu_dev);
+ static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
char *backup;
int rc, rc2;
ENTRY;
GOTO(out_put, rc = 0);
}
- OBD_ALLOC(backup, strlen(logname) + 5);
+ OBD_ALLOC(backup, strlen(logname) + strlen(".bak") + 1);
if (backup == NULL)
GOTO(out_put, rc = -ENOMEM);
sprintf(backup, "%s.bak", logname);
- rc = mgs_backup_llog(env, mgs, logname, backup);
- if (rc < 0) {
+ rc = llog_backup(env, mgs, ctxt, ctxt, logname, backup);
+ if (rc == 0) {
+ /* Now erase original log file. Connections are not allowed.
+ Backup is already saved */
+ rc = llog_erase(env, ctxt, NULL, logname);
+ if (rc < 0)
+ GOTO(out_free, rc);
+ } else if (rc != -ENOENT) {
CERROR("%s: can't make backup for %s: rc = %d\n",
mgs->obd_name, logname, rc);
GOTO(out_free,rc);
}
- /* Now erase original log file. Connections are not allowed.
- Backup is already saved */
- rc = llog_erase(env, ctxt, NULL, logname);
- if (rc < 0 && rc != -ENOENT)
- GOTO(out_free, rc);
-
/* open local log */
rc = llog_open_create(env, ctxt, &orig_llh, NULL, logname);
if (rc)
GOTO(out_restore, rc);
- rc = llog_init_handle(env, orig_llh, LLOG_F_IS_PLAIN, NULL);
+ rc = llog_init_handle(env, orig_llh, LLOG_F_IS_PLAIN, &cfg_uuid);
if (rc)
GOTO(out_closel, rc);
if (rc) {
CERROR("%s: llog should be restored: rc = %d\n",
mgs->obd_name, rc);
- rc2 = mgs_backup_llog(env, mgs, backup, logname);
+ rc2 = llog_backup(env, mgs, ctxt, ctxt, backup,
+ logname);
if (rc2 < 0)
CERROR("%s: can't restore backup %s: rc = %d\n",
mgs->obd_name, logname, rc2);
}
out_free:
- OBD_FREE(backup, strlen(backup) + 5);
+ OBD_FREE(backup, strlen(backup) + 1);
out_put:
llog_ctxt_put(ctxt);
*/
static int mgs_parse_devname(char *devname, char *fsname, __u32 *index)
{
- char *ptr;
+ int rc;
ENTRY;
/* Extract fsname */
- ptr = strrchr(devname, '-');
-
if (fsname) {
- if (!ptr) {
+ rc = server_name2fsname(devname, fsname, NULL);
+ if (rc < 0) {
CDEBUG(D_MGS, "Device name %s without fsname\n",
devname);
RETURN(-EINVAL);
}
- memset(fsname, 0, MTI_NAME_MAXLEN);
- strncpy(fsname, devname, ptr - devname);
- fsname[MTI_NAME_MAXLEN - 1] = 0;
}
if (index) {
- if (server_name2index(ptr, index, NULL) < 0) {
- CDEBUG(D_MGS, "Device name with wrong index\n");
+ rc = server_name2index(devname, index, NULL);
+ if (rc < 0) {
+ CDEBUG(D_MGS, "Device name %s with wrong index\n",
+ devname);
RETURN(-EINVAL);
}
}
return rc;
}
-static int mgs_log_is_empty(const struct lu_env *env,
- struct mgs_device *mgs, char *name)
-{
- struct llog_handle *llh;
- struct llog_ctxt *ctxt;
- int rc = 0;
-
- ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
- LASSERT(ctxt != NULL);
- rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
- if (rc < 0) {
- if (rc == -ENOENT)
- rc = 0;
- GOTO(out_ctxt, rc);
- }
-
- rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
- if (rc)
- GOTO(out_close, rc);
- rc = llog_get_size(llh);
-
-out_close:
- llog_close(env, llh);
-out_ctxt:
- llog_ctxt_put(ctxt);
- /* header is record 1 */
- return (rc <= 1);
-}
-
/******************** config "macros" *********************/
/* write an lcfg directly into a log (with markers) */
return 0;
}
-static int mgs_steal_llog_handler(const struct lu_env *env,
- struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
+/**
+ * Walk through client config log record and convert the related records
+ * into the target.
+ **/
+static int mgs_steal_client_llog_handler(const struct lu_env *env,
+ struct llog_handle *llh,
+ struct llog_rec_hdr *rec, void *data)
{
struct mgs_device *mgs;
struct obd_device *obd;
lcfg = (struct lustre_cfg *)cfg_buf;
- if (lcfg->lcfg_command == LCFG_MARKER) {
- struct cfg_marker *marker;
- marker = lustre_cfg_buf(lcfg, 1);
- if (!strncmp(marker->cm_comment,"add osc",7) &&
+ if (lcfg->lcfg_command == LCFG_MARKER) {
+ struct cfg_marker *marker;
+ marker = lustre_cfg_buf(lcfg, 1);
+ if (!strncmp(marker->cm_comment, "add osc", 7) &&
(marker->cm_flags & CM_START) &&
!(marker->cm_flags & CM_SKIP)) {
- got_an_osc_or_mdc = 1;
+ got_an_osc_or_mdc = 1;
cplen = strlcpy(tmti->mti_svname, marker->cm_tgtname,
sizeof(tmti->mti_svname));
if (cplen >= sizeof(tmti->mti_svname))
if (rc)
RETURN(rc);
rc = record_marker(env, mdt_llh, fsdb, CM_START,
- mti->mti_svname,"add osc(copied)");
+ mti->mti_svname, "add osc(copied)");
record_end_log(env, &mdt_llh);
- last_step = marker->cm_step;
- RETURN(rc);
- }
- if (!strncmp(marker->cm_comment,"add osc",7) &&
+ last_step = marker->cm_step;
+ RETURN(rc);
+ }
+ if (!strncmp(marker->cm_comment, "add osc", 7) &&
(marker->cm_flags & CM_END) &&
!(marker->cm_flags & CM_SKIP)) {
- LASSERT(last_step == marker->cm_step);
- last_step = -1;
- got_an_osc_or_mdc = 0;
+ LASSERT(last_step == marker->cm_step);
+ last_step = -1;
+ got_an_osc_or_mdc = 0;
+ memset(tmti, 0, sizeof(*tmti));
rc = record_start_log(env, mgs, &mdt_llh,
mti->mti_svname);
if (rc)
RETURN(rc);
rc = record_marker(env, mdt_llh, fsdb, CM_END,
- mti->mti_svname,"add osc(copied)");
+ mti->mti_svname, "add osc(copied)");
record_end_log(env, &mdt_llh);
- RETURN(rc);
- }
- if (!strncmp(marker->cm_comment,"add mdc",7) &&
+ RETURN(rc);
+ }
+ if (!strncmp(marker->cm_comment, "add mdc", 7) &&
(marker->cm_flags & CM_START) &&
!(marker->cm_flags & CM_SKIP)) {
- got_an_osc_or_mdc = 2;
- last_step = marker->cm_step;
- memcpy(tmti->mti_svname, marker->cm_tgtname,
- strlen(marker->cm_tgtname));
+ got_an_osc_or_mdc = 2;
+ last_step = marker->cm_step;
+ memcpy(tmti->mti_svname, marker->cm_tgtname,
+ strlen(marker->cm_tgtname));
- RETURN(rc);
- }
- if (!strncmp(marker->cm_comment,"add mdc",7) &&
+ RETURN(rc);
+ }
+ if (!strncmp(marker->cm_comment, "add mdc", 7) &&
(marker->cm_flags & CM_END) &&
!(marker->cm_flags & CM_SKIP)) {
- LASSERT(last_step == marker->cm_step);
- last_step = -1;
- got_an_osc_or_mdc = 0;
- RETURN(rc);
- }
- }
+ LASSERT(last_step == marker->cm_step);
+ last_step = -1;
+ got_an_osc_or_mdc = 0;
+ memset(tmti, 0, sizeof(*tmti));
+ RETURN(rc);
+ }
+ }
if (got_an_osc_or_mdc == 0 || last_step < 0)
RETURN(rc);
if (rc)
GOTO(out_close, rc);
- rc = llog_process_or_fork(env, loghandle, mgs_steal_llog_handler,
+ rc = llog_process_or_fork(env, loghandle, mgs_steal_client_llog_handler,
(void *)comp, NULL, false);
CDEBUG(D_MGS, "steal llog re = %d\n", rc);
out_close:
/* NB: don't change record order, because upon MDT steal OSC config
* from client, it treats all nids before LCFG_SETUP as target nids
* (multiple interfaces), while nids after as failover node nids.
- * See mgs_steal_llog_handler() LCFG_ADD_UUID.
+ * See mgs_steal_client_llog_handler() LCFG_ADD_UUID.
*/
for (i = 0; i < mti->mti_nid_count; i++) {
CDEBUG(D_MGS, "add nid %s\n", libcfs_nid2str(mti->mti_nids[i]));
get repeat setup instructions for already running
osc's. So don't update the client/mdt logs. */
mti->mti_flags &= ~LDD_F_UPDATE;
+ rc = 0;
}
mutex_lock(&fsdb->fsdb_mutex);
int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
struct lustre_cfg *lcfg, char *fsname)
{
- struct fs_db *fsdb;
- struct mgs_target_info *mti;
+ struct fs_db *fsdb;
+ struct mgs_target_info *mti;
char *devname, *param;
- char *ptr, *tmp;
- __u32 index;
- int rc = 0;
- ENTRY;
+ char *ptr;
+ const char *tmp;
+ __u32 index;
+ int rc = 0;
+ ENTRY;
print_lustre_cfg(lcfg);
OBD_FREE(label, label_sz);
return rc;
}
-
-