-void mdt_trans_stop(const struct lu_env *env,
- struct mdt_device *mdt, struct thandle *th)
-{
- dt_trans_stop(env, mdt->mdt_bottom, th);
-}
-
-static int mdt_clients_data_init(const struct lu_env *env,
- struct mdt_device *mdt,
- unsigned long last_size)
-{
- struct lr_server_data *lsd = &mdt->mdt_lut.lut_lsd;
- struct lsd_client_data *lcd;
- struct obd_device *obd = mdt2obd_dev(mdt);
- loff_t off;
- int cl_idx;
- int rc = 0;
- ENTRY;
-
- OBD_ALLOC_PTR(lcd);
- if (!lcd)
- RETURN(-ENOMEM);
-
- /* When we do a clean MDS shutdown, we save the last_transno into
- * the header. If we find clients with higher last_transno values
- * then those clients may need recovery done. */
- LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
- for (cl_idx = 0, off = lsd->lsd_client_start;
- off < last_size; cl_idx++) {
- __u64 last_transno;
- struct obd_export *exp;
- struct mdt_thread_info *mti;
-
- off = lsd->lsd_client_start +
- cl_idx * lsd->lsd_client_size;
-
- rc = lut_client_data_read(env, &mdt->mdt_lut, lcd, &off, cl_idx);
- if (rc) {
- CERROR("error reading MDS %s idx %d, off %llu: rc %d\n",
- LAST_RCVD, cl_idx, off, rc);
- rc = 0;
- break; /* read error shouldn't cause startup to fail */
- }
-
- if (lcd->lcd_uuid[0] == '\0') {
- CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
- cl_idx);
- continue;
- }
-
- last_transno = lcd_last_transno(lcd);
-
- /* These exports are cleaned up by mdt_obd_disconnect(), so
- * they need to be set up like real exports as
- * mdt_obd_connect() does.
- */
- CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
- " srv lr: "LPU64" lx: "LPU64"\n", lcd->lcd_uuid, cl_idx,
- last_transno, lsd->lsd_last_transno,
- lcd_last_xid(lcd));
-
- exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
- if (IS_ERR(exp)) {
- if (PTR_ERR(exp) == -EALREADY) {
- /* export already exists, zero out this one */
- CERROR("Duplicate export %s!\n", lcd->lcd_uuid);
- continue;
- }
- GOTO(err_client, rc = PTR_ERR(exp));
- }
-
- mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
- LASSERT(mti != NULL);
- mti->mti_exp = exp;
- /* copy on-disk lcd to the export */
- *exp->exp_target_data.ted_lcd = *lcd;
- rc = lut_client_add(env, exp, cl_idx);
- /* can't fail existing */
- LASSERTF(rc == 0, "rc = %d\n", rc);
- /* VBR: set export last committed version */
- exp->exp_last_committed = last_transno;
- cfs_spin_lock(&exp->exp_lock);
- exp->exp_connecting = 0;
- exp->exp_in_recovery = 0;
- cfs_spin_unlock(&exp->exp_lock);
- obd->obd_max_recoverable_clients++;
- class_export_put(exp);
-
- CDEBUG(D_OTHER, "client at idx %d has last_transno="LPU64"\n",
- cl_idx, last_transno);
- /* protect __u64 value update */
- cfs_spin_lock(&mdt->mdt_lut.lut_translock);
- mdt->mdt_lut.lut_last_transno = max(last_transno,
- mdt->mdt_lut.lut_last_transno);
- cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
- }
-
-err_client:
- OBD_FREE_PTR(lcd);
- RETURN(rc);
-}
-
-static int mdt_server_data_init(const struct lu_env *env,
- struct mdt_device *mdt,
- struct lustre_sb_info *lsi)
-{
- struct lr_server_data *lsd = &mdt->mdt_lut.lut_lsd;
- struct lsd_client_data *lcd = NULL;
- struct obd_device *obd = mdt2obd_dev(mdt);
- struct mdt_thread_info *mti;
- struct dt_object *obj;
- struct lu_attr *la;
- unsigned long last_rcvd_size;
- __u64 mount_count;
- int rc;
- ENTRY;
-
- /* ensure padding in the struct is the correct size */
- CLASSERT(offsetof(struct lr_server_data, lsd_padding) +
- sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
- CLASSERT(offsetof(struct lsd_client_data, lcd_padding) +
- sizeof(lcd->lcd_padding) == LR_CLIENT_SIZE);
-
- mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
- LASSERT(mti != NULL);
- la = &mti->mti_attr.ma_attr;
-
- obj = mdt->mdt_lut.lut_last_rcvd;
- rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
- if (rc)
- RETURN(rc);
-
- last_rcvd_size = (unsigned long)la->la_size;
-
- if (last_rcvd_size == 0) {
- LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
-
- memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,
- sizeof(lsd->lsd_uuid));
- lsd->lsd_last_transno = 0;
- lsd->lsd_mount_count = 0;
- lsd->lsd_server_size = LR_SERVER_SIZE;
- lsd->lsd_client_start = LR_CLIENT_START;
- lsd->lsd_client_size = LR_CLIENT_SIZE;
- lsd->lsd_feature_compat = OBD_COMPAT_MDT;
- lsd->lsd_feature_rocompat = OBD_ROCOMPAT_LOVOBJID;
- lsd->lsd_feature_incompat = OBD_INCOMPAT_MDT |
- OBD_INCOMPAT_COMMON_LR |
- OBD_INCOMPAT_MULTI_OI;
- } else {
- LCONSOLE_WARN("%s: used disk, loading\n", obd->obd_name);
- rc = lut_server_data_read(env, &mdt->mdt_lut);
- if (rc) {
- CERROR("error reading MDS %s: rc %d\n", LAST_RCVD, rc);
- GOTO(out, rc);
- }
- if (strcmp(lsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
- LCONSOLE_ERROR_MSG(0x157, "Trying to start OBD %s using"
- "the wrong disk %s. Were the /dev/ "
- "assignments rearranged?\n",
- obd->obd_uuid.uuid, lsd->lsd_uuid);
- GOTO(out, rc = -EINVAL);
- }
- lsd->lsd_feature_compat |= OBD_COMPAT_MDT;
- lsd->lsd_feature_incompat |= OBD_INCOMPAT_MDT |
- OBD_INCOMPAT_COMMON_LR;
- }
- mount_count = lsd->lsd_mount_count;
-
- if (lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP) {
- CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
- obd->obd_name,
- lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP);
- GOTO(out, rc = -EINVAL);
- }
- if (lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP) {
- CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
- obd->obd_name,
- lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP);
- /* XXX: Do something like remount filesystem read-only */
- GOTO(out, rc = -EINVAL);
- }
- /** Interop: evict all clients at first boot with 1.8 last_rcvd */
- if (!(lsd->lsd_feature_compat & OBD_COMPAT_20)) {
- if (last_rcvd_size > lsd->lsd_client_start) {
- LCONSOLE_WARN("Mounting %s at first time on 1.8 FS, "
- "remove all clients for interop needs\n",
- obd->obd_name);
- rc = lut_truncate_last_rcvd(env, &mdt->mdt_lut,
- lsd->lsd_client_start);
- if (rc)
- GOTO(out, rc);
- last_rcvd_size = lsd->lsd_client_start;
- }
- /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */
- lsd->lsd_feature_compat |= OBD_COMPAT_20;
- }
-
- if (lsi->lsi_flags & LDD_F_IAM_DIR)
- lsd->lsd_feature_incompat |= OBD_INCOMPAT_IAM_DIR;
-
- lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID;
-
- cfs_spin_lock(&mdt->mdt_lut.lut_translock);
- mdt->mdt_lut.lut_last_transno = lsd->lsd_last_transno;
- cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
-
- CDEBUG(D_INODE, "========BEGIN DUMPING LAST_RCVD========\n");
- CDEBUG(D_INODE, "%s: server last_transno: "LPU64"\n",
- obd->obd_name, mdt->mdt_lut.lut_last_transno);
- CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
- obd->obd_name, mount_count + 1);
- CDEBUG(D_INODE, "%s: server data size: %u\n",
- obd->obd_name, lsd->lsd_server_size);
- CDEBUG(D_INODE, "%s: per-client data start: %u\n",
- obd->obd_name, lsd->lsd_client_start);
- CDEBUG(D_INODE, "%s: per-client data size: %u\n",
- obd->obd_name, lsd->lsd_client_size);
- CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
- obd->obd_name, last_rcvd_size);
- CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
- last_rcvd_size <= lsd->lsd_client_start ? 0 :
- (last_rcvd_size - lsd->lsd_client_start) /
- lsd->lsd_client_size);
- CDEBUG(D_INODE, "========END DUMPING LAST_RCVD========\n");
-
- if (!lsd->lsd_server_size || !lsd->lsd_client_start ||
- !lsd->lsd_client_size) {
- CERROR("Bad last_rcvd contents!\n");
- GOTO(out, rc = -EINVAL);
- }
-
- rc = mdt_clients_data_init(env, mdt, last_rcvd_size);
- if (rc)
- GOTO(err_client, rc);
-
- cfs_spin_lock(&mdt->mdt_lut.lut_translock);
- /* obd_last_committed is used for compatibility
- * with other lustre recovery code */
- obd->obd_last_committed = mdt->mdt_lut.lut_last_transno;
- cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
-
- obd->u.obt.obt_mount_count = mount_count + 1;
- obd->u.obt.obt_instance = (__u32)obd->u.obt.obt_mount_count;
- lsd->lsd_mount_count = obd->u.obt.obt_mount_count;
-
- /* save it, so mount count and last_transno is current */
- rc = lut_server_data_update(env, &mdt->mdt_lut, 0);
- if (rc)
- GOTO(err_client, rc);
-
- RETURN(0);
-
-err_client:
- class_disconnect_exports(obd);
-out:
- return rc;
-}
-