}
server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
+ if (server_fld == NULL)
+ RETURN(-EIO);
+
fld_range_set_type(&range, *type);
rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
if (rc != 0)
/* Slab for OSD object allocation */
struct kmem_cache *lod_object_kmem;
+/* Slab for dt_txn_callback */
+struct kmem_cache *lod_txn_callback_kmem;
static struct lu_kmem_descr lod_caches[] = {
{
.ckd_cache = &lod_object_kmem,
.ckd_size = sizeof(struct lod_object)
},
{
+ .ckd_cache = &lod_txn_callback_kmem,
+ .ckd_name = "lod_txn_callback",
+ .ckd_size = sizeof(struct dt_txn_callback)
+ },
+ {
.ckd_cache = NULL
}
};
}
/**
- * Cleanup table of target's descriptors.
+ * Process the config log for all sub device.
*
* The function goes through all the targets in the given table
* and apply given configuration command on to the targets.
__u32 lrd_idx;
};
+
+/**
+ * process update recovery record
+ *
+ * Add the update recovery recode to the update recovery list in
+ * lod_recovery_data. Then the recovery thread (target_recovery_thread)
+ * will redo these updates.
+ *
+ * \param[in]env execution environment
+ * \param[in]llh log handle of update record
+ * \param[in]rec update record to be replayed
+ * \param[in]data update recovery data which holds the necessary
+ * arguments for recovery (see struct lod_recovery_data)
+ *
+ * \retval 0 if the record is processed successfully.
+ * \retval negative errno if the record processing fails.
+ */
+static int lod_process_recovery_updates(const struct lu_env *env,
+ struct llog_handle *llh,
+ struct llog_rec_hdr *rec,
+ void *data)
+{
+ struct lod_recovery_data *lrd = data;
+ struct llog_cookie *cookie = &lod_env_info(env)->lti_cookie;
+ struct lu_target *lut;
+ __u32 index = 0;
+ ENTRY;
+
+ if (lrd->lrd_ltd == NULL) {
+ int rc;
+
+ rc = lodname2mdt_index(lod2obd(lrd->lrd_lod)->obd_name, &index);
+ if (rc != 0)
+ return rc;
+ } else {
+ index = lrd->lrd_ltd->ltd_index;
+ }
+
+ if (rec->lrh_len !=
+ llog_update_record_size((struct llog_update_record *)rec)) {
+ CERROR("%s broken update record! index %u "DOSTID":%u : rc = %d\n",
+ lod2obd(lrd->lrd_lod)->obd_name, index,
+ POSTID(&llh->lgh_id.lgl_oi), rec->lrh_index, -EIO);
+ return -EIO;
+ }
+
+ cookie->lgc_lgl = llh->lgh_id;
+ cookie->lgc_index = rec->lrh_index;
+ cookie->lgc_subsys = LLOG_UPDATELOG_ORIG_CTXT;
+
+ CDEBUG(D_HA, "%s: process recovery updates "DOSTID":%u\n",
+ lod2obd(lrd->lrd_lod)->obd_name,
+ POSTID(&llh->lgh_id.lgl_oi), rec->lrh_index);
+ lut = lod2lu_dev(lrd->lrd_lod)->ld_site->ls_tgt;
+
+ return insert_update_records_to_replay_list(lut->lut_tdtd,
+ (struct llog_update_record *)rec,
+ cookie, index);
+}
+
/**
* recovery thread for update log
*
struct lod_device *lod = lrd->lrd_lod;
struct dt_device *dt;
struct ptlrpc_thread *thread = lrd->lrd_thread;
+ struct llog_ctxt *ctxt;
struct lu_env env;
int rc;
ENTRY;
if (rc != 0)
GOTO(out, rc);
- /* XXX do recovery in the following patches */
+ /* Process the recovery record */
+ ctxt = llog_get_context(dt->dd_lu_dev.ld_obd, LLOG_UPDATELOG_ORIG_CTXT);
+ LASSERT(ctxt != NULL);
+ LASSERT(ctxt->loc_handle != NULL);
+
+ rc = llog_cat_process(&env, ctxt->loc_handle,
+ lod_process_recovery_updates, lrd, 0, 0);
+ llog_ctxt_put(ctxt);
+
+ if (rc < 0) {
+ CERROR("%s getting update log failed: rc = %d\n",
+ dt->dd_lu_dev.ld_obd->obd_name, rc);
+ GOTO(out, rc);
+ }
+
+ CDEBUG(D_HA, "%s retrieve update log: rc = %d\n",
+ dt->dd_lu_dev.ld_obd->obd_name, rc);
+
+ if (lrd->lrd_ltd == NULL)
+ lod->lod_child_got_update_log = 1;
+ else
+ lrd->lrd_ltd->ltd_got_update_log = 1;
+
+ if (lod->lod_child_got_update_log) {
+ struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
+ struct lod_tgt_desc *tgt = NULL;
+ bool all_got_log = true;
+ int i;
+
+ cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
+ tgt = LTD_TGT(ltd, i);
+ if (!tgt->ltd_got_update_log) {
+ all_got_log = false;
+ break;
+ }
+ }
+
+ if (all_got_log) {
+ struct lu_target *lut;
+
+ lut = lod2lu_dev(lod)->ld_site->ls_tgt;
+ CDEBUG(D_HA, "%s got update logs from all MDTs.\n",
+ lut->lut_obd->obd_name);
+ lut->lut_tdtd->tdtd_replay_ready = 1;
+ wake_up(&lut->lut_obd->obd_next_transno_waitq);
+ }
+ }
out:
OBD_FREE_PTR(lrd);
}
/**
+ * finish sub llog context
+ *
+ * Stop update recovery thread for the sub device, then cleanup the
+ * correspondent llog ctxt.
+ *
+ * \param[in] env execution environment
+ * \param[in] lod lod device to do update recovery
+ * \param[in] thread recovery thread on this sub device
+ */
+void lod_sub_fini_llog(const struct lu_env *env,
+ struct dt_device *dt, struct ptlrpc_thread *thread)
+{
+ struct obd_device *obd;
+ struct llog_ctxt *ctxt;
+ ENTRY;
+
+ obd = dt->dd_lu_dev.ld_obd;
+ CDEBUG(D_INFO, "%s: finish sub llog\n", obd->obd_name);
+ /* Stop recovery thread first */
+ if (thread != NULL && thread->t_flags & SVC_RUNNING) {
+ thread->t_flags = SVC_STOPPING;
+ wake_up(&thread->t_ctl_waitq);
+ wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
+ }
+
+ ctxt = llog_get_context(obd, LLOG_UPDATELOG_ORIG_CTXT);
+ if (ctxt == NULL)
+ RETURN_EXIT;
+
+ if (ctxt->loc_handle != NULL)
+ llog_cat_close(env, ctxt->loc_handle);
+
+ llog_cleanup(env, ctxt);
+
+ RETURN_EXIT;
+}
+
+/**
* Extract MDT target index from a device name.
*
* a helper function to extract index from the given device name
struct l_wait_info lwi = { 0 };
struct lod_tgt_desc *sub_ltd = NULL;
__u32 index;
+ __u32 master_index;
int rc;
ENTRY;
+ rc = lodname2mdt_index(lod2obd(lod)->obd_name, &master_index);
+ if (rc != 0)
+ RETURN(rc);
+
OBD_ALLOC_PTR(lrd);
if (lrd == NULL)
RETURN(-ENOMEM);
if (lod->lod_child == dt) {
thread = &lod->lod_child_recovery_thread;
- rc = lodname2mdt_index(lod2obd(lod)->obd_name, &index);
- if (rc != 0) {
- OBD_FREE_PTR(lrd);
- RETURN(rc);
- }
+ index = master_index;
} else {
struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
struct lod_tgt_desc *tgt = NULL;
unsigned int i;
- mutex_lock(<d->ltd_mutex);
cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
tgt = LTD_TGT(ltd, i);
if (tgt->ltd_tgt == dt) {
break;
}
}
- mutex_unlock(<d->ltd_mutex);
- OBD_ALLOC_PTR(tgt->ltd_recovery_thread);
- if (tgt->ltd_recovery_thread == NULL) {
- OBD_FREE_PTR(lrd);
- RETURN(-ENOMEM);
- }
- thread = tgt->ltd_recovery_thread;
+ LASSERT(sub_ltd != NULL);
+ OBD_ALLOC_PTR(sub_ltd->ltd_recovery_thread);
+ if (sub_ltd->ltd_recovery_thread == NULL)
+ GOTO(free_lrd, rc = -ENOMEM);
+
+ thread = sub_ltd->ltd_recovery_thread;
}
+ CDEBUG(D_INFO, "%s init sub log %s\n", lod2obd(lod)->obd_name,
+ dt->dd_lu_dev.ld_obd->obd_name);
lrd->lrd_lod = lod;
lrd->lrd_ltd = sub_ltd;
lrd->lrd_thread = thread;
if (rc < 0) {
CERROR("%s: cannot setup updatelog llog: rc = %d\n",
obd->obd_name, rc);
- OBD_FREE_PTR(lrd);
- RETURN(rc);
+ GOTO(free_thread, rc);
}
/* Start the recovery thread */
- task = kthread_run(lod_sub_recovery_thread, lrd, "lod_recov_%04x",
- index);
+ task = kthread_run(lod_sub_recovery_thread, lrd, "lod%04x_rec%04x",
+ master_index, index);
if (IS_ERR(task)) {
rc = PTR_ERR(task);
- OBD_FREE_PTR(lrd);
CERROR("%s: cannot start recovery thread: rc = %d\n",
obd->obd_name, rc);
GOTO(out_llog, rc);
l_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING ||
thread->t_flags & SVC_STOPPED, &lwi);
-out_llog:
- if (rc != 0)
- lod_sub_fini_llog(env, dt, thread);
-
- RETURN(rc);
-}
-
-/**
- * finish sub llog context
- *
- * Stop update recovery thread for the sub device, then cleanup the
- * correspondent llog ctxt.
- *
- * \param[in] env execution environment
- * \param[in] dt dt device(lod) to do update recovery
- * \param[in] thread recovery thread on this sub device
- */
-void lod_sub_fini_llog(const struct lu_env *env,
- struct dt_device *dt, struct ptlrpc_thread *thread)
-{
- struct obd_device *obd;
- struct llog_ctxt *ctxt;
- CDEBUG(D_INFO, "%s: finish sub llog\n", dt->dd_lu_dev.ld_obd->obd_name);
- /* Stop recovery thread first */
- if (thread != NULL && thread->t_flags & SVC_RUNNING) {
- thread->t_flags = SVC_STOPPING;
- wake_up(&thread->t_ctl_waitq);
- wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_STOPPED);
+ RETURN(0);
+out_llog:
+ lod_sub_fini_llog(env, dt, thread);
+free_thread:
+ if (lod->lod_child != dt) {
+ OBD_FREE_PTR(sub_ltd->ltd_recovery_thread);
+ sub_ltd->ltd_recovery_thread = NULL;
}
-
- obd = dt->dd_lu_dev.ld_obd;
- ctxt = llog_get_context(obd, LLOG_UPDATELOG_ORIG_CTXT);
- if (ctxt == NULL)
- return;
-
- if (ctxt->loc_handle != NULL)
- llog_cat_close(env, ctxt->loc_handle);
-
- llog_cleanup(env, ctxt);
+free_lrd:
+ OBD_FREE_PTR(lrd);
+ RETURN(rc);
}
/**
* \param[in] env execution environment
* \param[in] lod lod device to do update recovery
*/
-void lod_sub_fini_all_llogs(const struct lu_env *env, struct lod_device *lod)
+static void lod_sub_fini_all_llogs(const struct lu_env *env,
+ struct lod_device *lod)
{
struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
unsigned int i;
/* Stop the update log commit cancel threads and finish master
* llog ctxt */
- lod_sub_fini_llog(env, lod->lod_child, &lod->lod_child_recovery_thread);
-
+ lod_sub_fini_llog(env, lod->lod_child,
+ &lod->lod_child_recovery_thread);
lod_getref(ltd);
cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
struct lod_tgt_desc *tgt;
}
/**
+ * Prepare distribute txn
+ *
+ * Prepare distribute txn structure for LOD
+ *
+ * \param[in] env execution environment
+ * \param[in] lod_device LOD device
+ *
+ * \retval 0 if preparation succeeds.
+ * \retval negative errno if preparation fails.
+ */
+static int lod_prepare_distribute_txn(const struct lu_env *env,
+ struct lod_device *lod)
+{
+ struct target_distribute_txn_data *tdtd;
+ struct lu_target *lut;
+ int rc;
+ ENTRY;
+
+ /* Init update recovery data */
+ OBD_ALLOC_PTR(tdtd);
+ if (tdtd == NULL)
+ RETURN(-ENOMEM);
+
+ lut = lod2lu_dev(lod)->ld_site->ls_tgt;
+
+ rc = distribute_txn_init(env, lut, tdtd,
+ lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id);
+
+ if (rc < 0) {
+ CERROR("%s: cannot init distribute txn: rc = %d\n",
+ lod2obd(lod)->obd_name, rc);
+ OBD_FREE_PTR(tdtd);
+ RETURN(rc);
+ }
+
+ tdtd->tdtd_dt = &lod->lod_dt_dev;
+ INIT_LIST_HEAD(&tdtd->tdtd_replay_list);
+ spin_lock_init(&tdtd->tdtd_replay_list_lock);
+ tdtd->tdtd_replay_handler = distribute_txn_replay_handle;
+ tdtd->tdtd_replay_ready = 0;
+
+ lut->lut_tdtd = tdtd;
+
+ RETURN(0);
+}
+
+/**
+ * Finish distribute txn
+ *
+ * Release the resource holding by distribute txn, i.e. stop distribute
+ * txn thread.
+ *
+ * \param[in] env execution environment
+ * \param[in] lod lod device
+ */
+static void lod_fini_distribute_txn(const struct lu_env *env,
+ struct lod_device *lod)
+{
+ struct lu_target *lut;
+
+ lut = lod2lu_dev(lod)->ld_site->ls_tgt;
+ if (lut->lut_tdtd == NULL)
+ return;
+
+ distribute_txn_fini(env, lut->lut_tdtd);
+
+ OBD_FREE_PTR(lut->lut_tdtd);
+ lut->lut_tdtd = NULL;
+}
+
+/**
* Implementation of lu_device_operations::ldo_process_config() for LOD
*
* The method is called by the configuration subsystem during setup,
CDEBUG(D_HA, "%s: can't process %u: %d\n",
lod2obd(lod)->obd_name, lcfg->lcfg_command, rc);
+ lod_fini_distribute_txn(env, lod);
lod_sub_fini_all_llogs(env, lod);
break;
}
if (IS_ERR(root))
RETURN(PTR_ERR(root));
+ /* Create update log object */
index = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
lu_update_log_fid(fid, index);
- /* Create update log object */
dto = local_file_find_or_create_with_fid(env, lod->lod_child,
fid, root,
lod_update_log_name,
lu_object_put(env, &dto->do_lu);
+ rc = lod_prepare_distribute_txn(env, lod);
+ if (rc != 0)
+ GOTO(out_put, rc);
+
rc = lod_sub_init_llogs(env, lod);
- if (rc < 0)
+ if (rc != 0)
GOTO(out_put, rc);
out_put:
struct lu_device *next = &lod->lod_child->dd_lu_dev;
ENTRY;
- LASSERT(atomic_read(&lu->ld_ref) == 0);
+ LASSERTF(atomic_read(&lu->ld_ref) == 0, "lu is %p\n", lu);
dt_device_fini(&lod->lod_dt_dev);
OBD_FREE_PTR(lod);
RETURN(next);