+ RETURN(rc);
+}
+
+/* add new mdc to already existent MDS */
+static int mgs_write_log_mdc_to_mdt(struct obd_device *obd, struct fs_db *fsdb,
+ struct mgs_target_info *mti, char *logname)
+{
+ struct llog_handle *llh = NULL;
+ char *nodeuuid, *mdcname, *mdcuuid, *mdtuuid;
+ int idx = mti->mti_stripe_index;
+ char index[9];
+ int i, rc;
+
+ ENTRY;
+ if (mgs_log_is_empty(obd, mti->mti_svname)) {
+ CERROR("log is empty! Logical error\n");
+ RETURN (-EINVAL);
+ }
+
+ CDEBUG(D_MGS, "adding mdc index %d to %s\n", idx, logname);
+
+ name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+ snprintf(index, sizeof(index), "-mdc%04x", idx);
+ name_create(&mdcname, logname, index);
+ name_create(&mdcuuid, mdcname, "_UUID");
+ name_create(&mdtuuid, logname, "_UUID");
+
+ rc = record_start_log(obd, &llh, logname);
+ rc = record_marker(obd, llh, fsdb, CM_START, mti->mti_svname, "add mdc");
+ for (i = 0; i < mti->mti_nid_count; i++) {
+ CDEBUG(D_MGS, "add nid %s for mdt\n",
+ libcfs_nid2str(mti->mti_nids[i]));
+ rc = record_add_uuid(obd, llh, mti->mti_nids[i], nodeuuid);
+ }
+ rc = record_attach(obd, llh, mdcname, LUSTRE_MDC_NAME, mdcuuid);
+ rc = record_setup(obd, llh, mdcname, mti->mti_uuid, nodeuuid, 0, 0);
+ rc = mgs_write_log_failnids(obd, mti, llh, mdcname);
+ snprintf(index, sizeof(index), "%d", idx);
+
+ rc = record_mdc_add(obd, llh, logname, mdcuuid, mti->mti_uuid,
+ index, "1");
+ rc = record_marker(obd, llh, fsdb, CM_END, mti->mti_svname, "add mdc");
+ rc = record_end_log(obd, &llh);
+
+ name_destroy(&mdcuuid);
+ name_destroy(&mdcname);
+ name_destroy(&nodeuuid);
+ name_destroy(&mdtuuid);
+ RETURN(rc);
+}
+
+static int mgs_write_log_mdt0(struct obd_device *obd, struct fs_db *fsdb,
+ struct mgs_target_info *mti)
+{
+ char *log = mti->mti_svname;
+ struct llog_handle *llh = NULL;
+ char *uuid, *lovname;
+ char mdt_index[5];
+ char *ptr = mti->mti_params;
+ int rc = 0, failout = 0;
+ ENTRY;
+
+ OBD_ALLOC(uuid, sizeof(struct obd_uuid));
+ if (uuid == NULL)
+ RETURN(-ENOMEM);
+
+ if (class_find_param(ptr, PARAM_FAILMODE, &ptr) == 0)
+ failout = (strncmp(ptr, "failout", 7) == 0);
+
+ name_create(&lovname, log, "-mdtlov");
+ if (mgs_log_is_empty(obd, log))
+ rc = mgs_write_log_lov(obd, fsdb, mti, log, lovname);
+
+ sprintf(uuid, "%s_UUID", log);
+ sprintf(mdt_index,"%d",mti->mti_stripe_index);
+
+ /* add MDT itself */
+ rc = record_start_log(obd, &llh, log);
+ if (rc)
+ GOTO(out, rc);
+
+ /* FIXME this whole fn should be a single journal transaction */
+ rc = record_marker(obd, llh, fsdb, CM_START, log, "add mdt");
+ rc = record_attach(obd, llh, log, LUSTRE_MDT_NAME, uuid);
+ rc = record_mount_opt(obd, llh, log, lovname, NULL);
+ rc = record_setup(obd, llh, log, uuid, mdt_index, lovname,
+ failout ? "n" : "f");
+ rc = record_marker(obd, llh, fsdb, CM_END, log, "add mdt");
+ rc = record_end_log(obd, &llh);
+out:
+ name_destroy(&lovname);
+ OBD_FREE(uuid, sizeof(struct obd_uuid));
+ RETURN(rc);
+}
+
+/* envelope method for all layers log */
+static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *fsdb,
+ struct mgs_target_info *mti)
+{
+ struct llog_handle *llh = NULL;
+ char *cliname;
+ struct temp_comp comp = { 0 };
+ char mdt_index[9];
+ int rc, i = 0;
+ ENTRY;
+
+ CDEBUG(D_MGS, "writing new mdt %s\n", mti->mti_svname);
+
+#if 0
+ /* COMPAT_146 */
+ if (mti->mti_flags & LDD_F_UPGRADE14) {
+ /* We're starting with an old uuid. Assume old name for lov
+ as well since the lov entry already exists in the log. */
+ CDEBUG(D_MGS, "old mds uuid %s\n", mti->mti_uuid);
+ if (strncmp(mti->mti_uuid, fsdb->fsdb_mdtlov + 4,
+ strlen(fsdb->fsdb_mdtlov) - 4) != 0) {
+ CERROR("old mds uuid %s doesn't match log %s (%s)\n",
+ mti->mti_uuid, fsdb->fsdb_mdtlov,
+ fsdb->fsdb_mdtlov + 4);
+ RETURN(-EINVAL);
+ }
+ }
+ /* end COMPAT_146 */
+#endif
+ if (mti->mti_uuid[0] == '\0') {
+ /* Make up our own uuid */
+ snprintf(mti->mti_uuid, sizeof(mti->mti_uuid),
+ "%s_UUID", mti->mti_svname);
+ }
+
+ /* add mdt */
+ rc = mgs_write_log_mdt0(obd, fsdb, mti);
+
+ /* Append the mdt info to the client log */
+ name_create(&cliname, mti->mti_fsname, "-client");
+
+ if (mgs_log_is_empty(obd, cliname)) {
+ /* Start client log */
+ rc = mgs_write_log_lov(obd, fsdb, mti, cliname,
+ fsdb->fsdb_clilov);
+ rc = mgs_write_log_lmv(obd, fsdb, mti, cliname,
+ fsdb->fsdb_clilmv);
+ }
+
+ /*
+ #09 L add_uuid nid=uml1@tcp(0x20000c0a80201) 0: 1:uml1_UUID
+ #10 L attach 0:MDC_uml1_mdsA_MNT_client 1:mdc 2:1d834_MNT_client_03f
+ #11 L setup 0:MDC_uml1_mdsA_MNT_client 1:mdsA_UUID 2:uml1_UUID
+ #12 L add_uuid nid=uml2@tcp(0x20000c0a80202) 0: 1:uml2_UUID
+ #13 L add_conn 0:MDC_uml1_mdsA_MNT_client 1:uml2_UUID
+ #14 L mount_option 0: 1:client 2:lov1 3:MDC_uml1_mdsA_MNT_client
+ */
+
+#if 0
+ /* COMPAT_146 */
+ if (mti->mti_flags & LDD_F_UPGRADE14) {
+ rc = record_start_log(obd, &llh, cliname);
+ if (rc)
+ GOTO(out, rc);
+
+ rc = record_marker(obd, llh, fsdb, CM_START,
+ mti->mti_svname,"add mdc");
+
+ /* Old client log already has MDC entry, but needs mount opt
+ for new client name (lustre-client) */
+ /* FIXME Old MDT log already has an old mount opt
+ which we should remove (currently handled by
+ class_del_profiles()) */
+ rc = record_mount_opt(obd, llh, cliname, fsdb->fsdb_clilov,
+ fsdb->fsdb_mdc);
+ /* end COMPAT_146 */
+
+ rc = record_marker(obd, llh, fsdb, CM_END,
+ mti->mti_svname, "add mdc");
+ } else
+#endif
+ {
+ /* copy client info about lov/lmv */
+ comp.comp_mti = mti;
+ comp.comp_fsdb = fsdb;
+
+ rc = mgs_steal_llog_for_mdt_from_client(obd, cliname,
+ &comp);
+
+ rc = mgs_write_log_mdc_to_lmv(obd, fsdb, mti, cliname,
+ fsdb->fsdb_clilmv);
+ /* add mountopts */
+ rc = record_start_log(obd, &llh, cliname);
+ if (rc)
+ GOTO(out, rc);
+
+ rc = record_marker(obd, llh, fsdb, CM_START, cliname,
+ "mount opts");
+ rc = record_mount_opt(obd, llh, cliname, fsdb->fsdb_clilov,
+ fsdb->fsdb_clilmv);
+ rc = record_marker(obd, llh, fsdb, CM_END, cliname,
+ "mount opts");
+ }
+
+ rc = record_end_log(obd, &llh);
+out: