X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fosp%2Fosp_sync.c;h=4d266fc826d1fdbd3c24c7b422b1d473ecb9fd32;hb=700e5cfa5b698091582f6232437e53d0c84baf2a;hp=298626d5b8715b8e977b77f8c474f9b03559941c;hpb=294e507d34de0d7990ec507334f71ff1d1a7db01;p=fs%2Flustre-release.git diff --git a/lustre/osp/osp_sync.c b/lustre/osp/osp_sync.c index 298626d..4d266fc 100644 --- a/lustre/osp/osp_sync.c +++ b/lustre/osp/osp_sync.c @@ -44,6 +44,7 @@ #define DEBUG_SUBSYSTEM S_MDS #include +#include #include "osp_internal.h" static int osp_sync_id_traction_init(struct osp_device *d); @@ -93,16 +94,40 @@ static void osp_sync_remove_from_tracker(struct osp_device *d); #define OSP_JOB_MAGIC 0x26112005 +/** + * Return status: whether OSP thread should keep running + * + * \param[in] d OSP device + * + * \retval 1 should keep running + * \retval 0 should stop + */ static inline int osp_sync_running(struct osp_device *d) { return !!(d->opd_syn_thread.t_flags & SVC_RUNNING); } +/** + * Check status: whether OSP thread has stopped + * + * \param[in] d OSP device + * + * \retval 0 still running + * \retval 1 stopped + */ static inline int osp_sync_stopped(struct osp_device *d) { return !!(d->opd_syn_thread.t_flags & SVC_STOPPED); } +/* + ** Check for new changes to sync + * + * \param[in] d OSP device + * + * \retval 1 there are changes + * \retval 0 there are no changes + */ static inline int osp_sync_has_new_job(struct osp_device *d) { return ((d->opd_syn_last_processed_id < d->opd_syn_last_used_id) && @@ -115,11 +140,27 @@ static inline int osp_sync_low_in_progress(struct osp_device *d) return d->opd_syn_rpc_in_progress < d->opd_syn_max_rpc_in_progress; } +/** + * Check for room in the network pipe to OST + * + * \param[in] d OSP device + * + * \retval 1 there is room + * \retval 0 no room, the pipe is full + */ static inline int osp_sync_low_in_flight(struct osp_device *d) { return d->opd_syn_rpc_in_flight < d->opd_syn_max_rpc_in_flight; } +/** + * Wake up check for the main sync thread + * + * \param[in] d OSP device + * + * \retval 1 time to wake up + * \retval 0 no need to wake up + */ static inline int osp_sync_has_work(struct osp_device *d) { /* has new/old changes and low in-progress? */ @@ -128,7 +169,7 @@ static inline int osp_sync_has_work(struct osp_device *d) return 1; /* has remotely committed? */ - if (!cfs_list_empty(&d->opd_syn_committed_there)) + if (!list_empty(&d->opd_syn_committed_there)) return 1; return 0; @@ -146,11 +187,27 @@ void __osp_sync_check_for_work(struct osp_device *d) osp_sync_check_for_work(d); } +/** + * Check and return ready-for-new status. + * + * The thread processing llog record uses this function to check whether + * it's time to take another record and process it. The number of conditions + * must be met: the connection should be ready, RPCs in flight not exceeding + * the limit, the record is committed locally, etc (see the lines below). + * + * \param[in] d OSP device + * \param[in] rec next llog record to process + * + * \retval 0 not ready + * \retval 1 ready + */ static inline int osp_sync_can_process_new(struct osp_device *d, struct llog_rec_hdr *rec) { LASSERT(d); + if (unlikely(atomic_read(&d->opd_syn_barrier) > 0)) + return 0; if (!osp_sync_low_in_progress(d)) return 0; if (!osp_sync_low_in_flight(d)) @@ -166,6 +223,21 @@ static inline int osp_sync_can_process_new(struct osp_device *d, return 0; } +/** + * Declare intention to add a new change. + * + * With regard to OSD API, we have to declare any changes ahead. In this + * case we declare an intention to add a llog record representing the + * change on the local storage. + * + * \param[in] env LU environment provided by the caller + * \param[in] o OSP object + * \param[in] type type of change: MDS_UNLINK64_REC or MDS_SETATTR64_REC + * \param[in] th transaction handle (local) + * + * \retval 0 on success + * \retval negative negated errno on error + */ int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o, llog_op_type type, struct thandle *th) { @@ -203,6 +275,27 @@ int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o, RETURN(rc); } +/** + * Generate a llog record for a given change. + * + * Generates a llog record for the change passed. The change can be of two + * types: unlink and setattr. The record gets an ID which later will be + * used to track commit status of the change. For unlink changes, the caller + * can supply a starting FID and the count of the objects to destroy. For + * setattr the caller should apply attributes to apply. + * + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + * \param[in] fid fid of the object the change should be applied to + * \param[in] type type of change: MDS_UNLINK64_REC or MDS_SETATTR64_REC + * \param[in] count count of objects to destroy + * \param[in] th transaction handle (local) + * \param[in] attr attributes for setattr + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_add_rec(const struct lu_env *env, struct osp_device *d, const struct lu_fid *fid, llog_op_type type, int count, struct thandle *th, @@ -235,6 +328,9 @@ static int osp_sync_add_rec(const struct lu_env *env, struct osp_device *d, LASSERT(attr); osi->osi_setattr.lsr_uid = attr->la_uid; osi->osi_setattr.lsr_gid = attr->la_gid; + osi->osi_setattr.lsr_valid = + ((attr->la_valid & LA_UID) ? OBD_MD_FLUID : 0) | + ((attr->la_valid & LA_GID) ? OBD_MD_FLGID : 0); break; default: LBUG(); @@ -250,7 +346,7 @@ static int osp_sync_add_rec(const struct lu_env *env, struct osp_device *d, if (ctxt == NULL) RETURN(-ENOMEM); rc = llog_add(env, ctxt->loc_handle, &osi->osi_hdr, &osi->osi_cookie, - NULL, th); + th); llog_ctxt_put(ctxt); CDEBUG(D_OTHER, "%s: new record "DOSTID":%lu/%lu: %d\n", @@ -298,14 +394,18 @@ int osp_sync_gap(const struct lu_env *env, struct osp_device *d, * subsequent commit callback (at the most) */ -/* - * called for each atomic on-disk change (not once per transaction batch) - * and goes over the list - * XXX: should be optimized? - */ - /** - * called for each RPC reported committed + * ptlrpc commit callback. + * + * The callback is called by PTLRPC when a RPC is reported committed by the + * target (OST). We register the callback for the every RPC applying a change + * from the llog. This way we know then the llog records can be cancelled. + * Notice the callback can be called when OSP is finishing. We can detect this + * checking that actual transno in the request is less or equal of known + * committed transno (see osp_sync_process_committed() for the details). + * XXX: this is pretty expensive and can be improved later using batching. + * + * \param[in] req request */ static void osp_sync_request_commit_cb(struct ptlrpc_request *req) { @@ -321,18 +421,35 @@ static void osp_sync_request_commit_cb(struct ptlrpc_request *req) LASSERT(d); LASSERT(req->rq_svc_thread == (void *) OSP_JOB_MAGIC); - LASSERT(cfs_list_empty(&req->rq_exp_list)); + LASSERT(list_empty(&req->rq_exp_list)); ptlrpc_request_addref(req); spin_lock(&d->opd_syn_lock); - cfs_list_add(&req->rq_exp_list, &d->opd_syn_committed_there); + list_add(&req->rq_exp_list, &d->opd_syn_committed_there); spin_unlock(&d->opd_syn_lock); /* XXX: some batching wouldn't hurt */ wake_up(&d->opd_syn_waitq); } +/** + * RPC interpretation callback. + * + * The callback is called by ptlrpc when RPC is replied. Now we have to decide + * whether we should: + * - put request on a special list to wait until it's committed by the target, + * if the request is succesful + * - schedule llog record cancel if no target object is found + * - try later (essentially after reboot) in case of unexpected error + * + * \param[in] env LU environment provided by the caller + * \param[in] req request replied + * \param[in] aa callback data + * \param[in] rc result of RPC + * + * \retval 0 always + */ static int osp_sync_interpret(const struct lu_env *env, struct ptlrpc_request *req, void *aa, int rc) { @@ -354,12 +471,12 @@ static int osp_sync_interpret(const struct lu_env *env, * but object doesn't exist anymore - cancell llog record */ LASSERT(req->rq_transno == 0); - LASSERT(cfs_list_empty(&req->rq_exp_list)); + LASSERT(list_empty(&req->rq_exp_list)); ptlrpc_request_addref(req); spin_lock(&d->opd_syn_lock); - cfs_list_add(&req->rq_exp_list, &d->opd_syn_committed_there); + list_add(&req->rq_exp_list, &d->opd_syn_committed_there); spin_unlock(&d->opd_syn_lock); wake_up(&d->opd_syn_waitq); @@ -398,6 +515,8 @@ static int osp_sync_interpret(const struct lu_env *env, spin_lock(&d->opd_syn_lock); d->opd_syn_rpc_in_flight--; spin_unlock(&d->opd_syn_lock); + if (unlikely(atomic_read(&d->opd_syn_barrier) > 0)) + wake_up(&d->opd_syn_barrier_waitq); CDEBUG(D_OTHER, "%s: %d in flight, %d in progress\n", d->opd_obd->obd_name, d->opd_syn_rpc_in_flight, d->opd_syn_rpc_in_progress); @@ -408,8 +527,12 @@ static int osp_sync_interpret(const struct lu_env *env, } /* - * the function walks through list of committed locally changes - * and send them to RPC until the pipe is full + ** Add request to ptlrpc queue. + * + * This is just a tiny helper function to put the request on the sending list + * + * \param[in] d OSP device + * \param[in] req request */ static void osp_sync_send_new_rpc(struct osp_device *d, struct ptlrpc_request *req) @@ -420,6 +543,24 @@ static void osp_sync_send_new_rpc(struct osp_device *d, ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1); } + +/** + * Allocate and prepare RPC for a new change. + * + * The function allocates and initializes an RPC which will be sent soon to + * apply the change to the target OST. The request is initialized from the + * llog record passed. Notice only the fields common to all type of changes + * are initialized. + * + * \param[in] d OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] h llog record + * \param[in] op type of the change + * \param[in] format request format to be used + * + * \retval pointer new request on success + * \retval ERR_PTR(errno) on error + */ static struct ptlrpc_request *osp_sync_new_job(struct osp_device *d, struct llog_handle *llh, struct llog_rec_hdr *h, @@ -455,7 +596,7 @@ static struct ptlrpc_request *osp_sync_new_job(struct osp_device *d, body->oa.o_lcookie.lgc_lgl = llh->lgh_id; body->oa.o_lcookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT; body->oa.o_lcookie.lgc_index = h->lrh_index; - CFS_INIT_LIST_HEAD(&req->rq_exp_list); + INIT_LIST_HEAD(&req->rq_exp_list); req->rq_svc_thread = (void *) OSP_JOB_MAGIC; req->rq_interpret_reply = osp_sync_interpret; @@ -467,6 +608,19 @@ static struct ptlrpc_request *osp_sync_new_job(struct osp_device *d, return req; } +/** + * Generate a request for setattr change. + * + * The function prepares a new RPC, initializes it with setattr specific + * bits and send the RPC. + * + * \param[in] d OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] h llog record + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_new_setattr_job(struct osp_device *d, struct llog_handle *llh, struct llog_rec_hdr *h) @@ -478,6 +632,16 @@ static int osp_sync_new_setattr_job(struct osp_device *d, ENTRY; LASSERT(h->lrh_type == MDS_SETATTR64_REC); + /* lsr_valid can only be 0 or have OBD_MD_{FLUID,FLGID} set, + * so no bits other than these should be set. */ + if ((rec->lsr_valid & ~(OBD_MD_FLUID | OBD_MD_FLGID)) != 0) { + CERROR("%s: invalid setattr record, lsr_valid:"LPU64"\n", + d->opd_obd->obd_name, rec->lsr_valid); + /* return 0 so that sync thread can continue processing + * other records. */ + RETURN(0); + } + req = osp_sync_new_job(d, llh, h, OST_SETATTR, &RQF_OST_SETATTR); if (IS_ERR(req)) RETURN(PTR_ERR(req)); @@ -487,14 +651,33 @@ static int osp_sync_new_setattr_job(struct osp_device *d, body->oa.o_oi = rec->lsr_oi; body->oa.o_uid = rec->lsr_uid; body->oa.o_gid = rec->lsr_gid; - body->oa.o_valid = OBD_MD_FLGROUP | OBD_MD_FLID | - OBD_MD_FLUID | OBD_MD_FLGID; + body->oa.o_valid = OBD_MD_FLGROUP | OBD_MD_FLID; + /* old setattr record (prior 2.6.0) doesn't have 'valid' stored, + * we assume that both UID and GID are valid in that case. */ + if (rec->lsr_valid == 0) + body->oa.o_valid |= (OBD_MD_FLUID | OBD_MD_FLGID); + else + body->oa.o_valid |= rec->lsr_valid; osp_sync_send_new_rpc(d, req); - RETURN(0); + RETURN(1); } -/* Old records may be in old format, so we handle that too */ +/** + * Generate a request for unlink change. + * + * The function prepares a new RPC, initializes it with unlink(destroy) + * specific bits and sends the RPC. The function is used to handle + * llog_unlink_rec which were used in the older versions of Lustre. + * Current version uses llog_unlink_rec64. + * + * \param[in] d OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] h llog record + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_new_unlink_job(struct osp_device *d, struct llog_handle *llh, struct llog_rec_hdr *h) @@ -520,9 +703,25 @@ static int osp_sync_new_unlink_job(struct osp_device *d, body->oa.o_valid |= OBD_MD_FLOBJCOUNT; osp_sync_send_new_rpc(d, req); - RETURN(0); + RETURN(1); } +/** + * Prepare OUT-based object destroy RPC. + * + * The function allocates a new RPC with OUT format. Then initializes the RPC + * to contain OUT_DESTROY update against the object specified in the llog + * record provided by the caller. + * + * \param[in] env LU environment provided by the caller + * \param[in] osp OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] h llog record + * \param[out] reqp request prepared + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_prep_unlink_update_req(const struct lu_env *env, struct osp_device *osp, struct llog_handle *llh, @@ -532,25 +731,25 @@ static int osp_prep_unlink_update_req(const struct lu_env *env, struct llog_unlink64_rec *rec = (struct llog_unlink64_rec *)h; struct dt_update_request *update = NULL; struct ptlrpc_request *req; - const char *buf; struct llog_cookie lcookie; - int size; + const void *buf; + __u16 size; int rc; ENTRY; - update = out_create_update_req(&osp->opd_dt_dev); + update = dt_update_request_create(&osp->opd_dt_dev); if (IS_ERR(update)) RETURN(PTR_ERR(update)); /* This can only happens for unlink slave directory, so decrease * ref for ".." and "." */ - rc = out_insert_update(env, update, OUT_REF_DEL, &rec->lur_fid, 0, - NULL, NULL); + rc = out_update_pack(env, &update->dur_buf, OUT_REF_DEL, &rec->lur_fid, + 0, NULL, NULL, 0); if (rc != 0) GOTO(out, rc); - rc = out_insert_update(env, update, OUT_REF_DEL, &rec->lur_fid, 0, - NULL, NULL); + rc = out_update_pack(env, &update->dur_buf, OUT_REF_DEL, &rec->lur_fid, + 0, NULL, NULL, 0); if (rc != 0) GOTO(out, rc); @@ -558,15 +757,15 @@ static int osp_prep_unlink_update_req(const struct lu_env *env, lcookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT; lcookie.lgc_index = h->lrh_index; size = sizeof(lcookie); - buf = (const char *)&lcookie; + buf = &lcookie; - rc = out_insert_update(env, update, OUT_DESTROY, &rec->lur_fid, 1, - &size, &buf); + rc = out_update_pack(env, &update->dur_buf, OUT_DESTROY, &rec->lur_fid, + 1, &size, &buf, 0); if (rc != 0) GOTO(out, rc); rc = out_prep_update_req(env, osp->opd_obd->u.cli.cl_import, - update->dur_req, &req); + update->dur_buf.ub_req, &req); if (rc != 0) GOTO(out, rc); @@ -581,11 +780,30 @@ static int osp_prep_unlink_update_req(const struct lu_env *env, *reqp = req; out: if (update != NULL) - out_destroy_update_req(update); + dt_update_request_destroy(update); RETURN(rc); } +/** + * Generate a request for unlink change. + * + * The function prepares a new RPC, initializes it with unlink(destroy) + * specific bits and sends the RPC. Depending on the target (MDT or OST) + * two different protocols are used. For MDT we use OUT (basically OSD API + * updates transferred via a network). For OST we still use the old + * protocol (OBD?), originally for compatibility. Later we can start to + * use OUT for OST as well, this will allow batching and better code + * unification. + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] h llog record + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_new_unlink64_job(const struct lu_env *env, struct osp_device *d, struct llog_handle *llh, @@ -620,9 +838,28 @@ static int osp_sync_new_unlink64_job(const struct lu_env *env, OBD_MD_FLOBJCOUNT; } osp_sync_send_new_rpc(d, req); - RETURN(0); + RETURN(1); } +/** + * Process llog records. + * + * This function is called to process the llog records committed locally. + * In the recovery model used by OSP we can apply a change to a remote + * target once corresponding transaction (like posix unlink) is committed + * locally so can't revert. + * Depending on the llog record type, a given handler is called that is + * responsible for preparing and sending the RPC to apply the change. + * Special record type LLOG_GEN_REC marking a reboot is cancelled right away. + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + * \param[in] llh llog handle where the record is stored + * \param[in] rec llog record + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_process_record(const struct lu_env *env, struct osp_device *d, struct llog_handle *llh, @@ -680,10 +917,10 @@ static int osp_sync_process_record(const struct lu_env *env, CERROR("%s: unknown record type: %x\n", d->opd_obd->obd_name, rec->lrh_type); /* we should continue processing */ - return 0; } - if (likely(rc == 0)) { + /* rc > 0 means sync RPC being added to the queue */ + if (likely(rc > 0)) { spin_lock(&d->opd_syn_lock); if (d->opd_syn_prev_done) { LASSERT(d->opd_syn_changes > 0); @@ -692,8 +929,10 @@ static int osp_sync_process_record(const struct lu_env *env, * NOTE: it's possible to meet same id if * OST stores few stripes of same file */ - if (rec->lrh_id > d->opd_syn_last_processed_id) + if (rec->lrh_id > d->opd_syn_last_processed_id) { d->opd_syn_last_processed_id = rec->lrh_id; + wake_up(&d->opd_syn_barrier_waitq); + } d->opd_syn_changes--; } @@ -701,6 +940,7 @@ static int osp_sync_process_record(const struct lu_env *env, d->opd_obd->obd_name, d->opd_syn_rpc_in_flight, d->opd_syn_rpc_in_progress); spin_unlock(&d->opd_syn_lock); + rc = 0; } else { spin_lock(&d->opd_syn_lock); d->opd_syn_rpc_in_flight--; @@ -713,6 +953,16 @@ static int osp_sync_process_record(const struct lu_env *env, return rc; } +/** + * Cancel llog records for the committed changes. + * + * The function walks through the list of the committed RPCs and cancels + * corresponding llog records. see osp_sync_request_commit_cb() for the + * details. + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + */ static void osp_sync_process_committed(const struct lu_env *env, struct osp_device *d) { @@ -722,12 +972,12 @@ static void osp_sync_process_committed(const struct lu_env *env, struct ptlrpc_request *req, *tmp; struct llog_ctxt *ctxt; struct llog_handle *llh; - cfs_list_t list; + struct list_head list; int rc, done = 0; ENTRY; - if (cfs_list_empty(&d->opd_syn_committed_there)) + if (list_empty(&d->opd_syn_committed_there)) return; /* @@ -752,17 +1002,17 @@ static void osp_sync_process_committed(const struct lu_env *env, llh = ctxt->loc_handle; LASSERT(llh); - CFS_INIT_LIST_HEAD(&list); + INIT_LIST_HEAD(&list); spin_lock(&d->opd_syn_lock); - cfs_list_splice(&d->opd_syn_committed_there, &list); - CFS_INIT_LIST_HEAD(&d->opd_syn_committed_there); + list_splice(&d->opd_syn_committed_there, &list); + INIT_LIST_HEAD(&d->opd_syn_committed_there); spin_unlock(&d->opd_syn_lock); - cfs_list_for_each_entry_safe(req, tmp, &list, rq_exp_list) { + list_for_each_entry_safe(req, tmp, &list, rq_exp_list) { struct llog_cookie *lcookie = NULL; LASSERT(req->rq_svc_thread == (void *) OSP_JOB_MAGIC); - cfs_list_del_init(&req->rq_exp_list); + list_del_init(&req->rq_exp_list); if (d->opd_connect_mdt) { struct object_update_request *ureq; @@ -820,8 +1070,21 @@ static void osp_sync_process_committed(const struct lu_env *env, EXIT; } -/* - * this is where most of queues processing happens +/** + * The core of the syncing mechanism. + * + * This is a callback called by the llog processing function. Essentially it + * suspends llog processing until there is a record to process (it's supposed + * to be committed locally). The function handles RPCs committed by the target + * and cancels corresponding llog records. + * + * \param[in] env LU environment provided by the caller + * \param[in] llh llog handle we're processing + * \param[in] rec current llog record + * \param[in] data callback data containing a pointer to the device + * + * \retval 0 to ask the caller (llog_process()) to continue + * \retval LLOG_PROC_BREAK to ask the caller to break */ static int osp_sync_process_queues(const struct lu_env *env, struct llog_handle *llh, @@ -847,7 +1110,8 @@ static int osp_sync_process_queues(const struct lu_env *env, if (osp_sync_can_process_new(d, rec)) { if (llh == NULL) { /* ask llog for another record */ - CDEBUG(D_HA, "%lu changes, %u in progress, %u in flight\n", + CDEBUG(D_HA, "%lu changes, %u in progress," + " %u in flight\n", d->opd_syn_changes, d->opd_syn_rpc_in_progress, d->opd_syn_rpc_in_flight); @@ -884,13 +1148,15 @@ static int osp_sync_process_queues(const struct lu_env *env, l_wait_event(d->opd_syn_waitq, !osp_sync_running(d) || osp_sync_can_process_new(d, rec) || - !cfs_list_empty(&d->opd_syn_committed_there), + !list_empty(&d->opd_syn_committed_there), &lwi); } while (1); } -/* - * this thread runs llog_cat_process() scanner calling our callback +/** + * OSP sync thread. + * + * This thread runs llog_cat_process() scanner calling our callback * to process llog records. in the callback we implement tricky * state machine as we don't want to start scanning of the llog again * and again, also we don't want to process too many records and send @@ -898,9 +1164,14 @@ static int osp_sync_process_queues(const struct lu_env *env, * being synced to OST) the callback can suspend awaiting for some * new conditions, like syncs completed. * - * in order to process llog records left by previous boots and to allow + * In order to process llog records left by previous boots and to allow * llog_process_thread() to find something (otherwise it'd just exit * immediately) we add a special GENERATATION record on each boot. + * + * \param[in] _arg a pointer to thread's arguments + * + * \retval 0 on success + * \retval negative negated errno on error */ static int osp_sync_thread(void *_arg) { @@ -966,7 +1237,7 @@ static int osp_sync_thread(void *_arg) LASSERTF(count < 10, "%s: %d %d %sempty\n", d->opd_obd->obd_name, d->opd_syn_rpc_in_progress, d->opd_syn_rpc_in_flight, - cfs_list_empty(&d->opd_syn_committed_there) ? "" :"!"); + list_empty(&d->opd_syn_committed_there) ? "" : "!"); } @@ -979,7 +1250,7 @@ out: "%s: %d %d %sempty\n", d->opd_obd->obd_name, d->opd_syn_rpc_in_progress, d->opd_syn_rpc_in_flight, - cfs_list_empty(&d->opd_syn_committed_there) ? "" : "!"); + list_empty(&d->opd_syn_committed_there) ? "" : "!"); thread->t_flags = SVC_STOPPED; @@ -990,6 +1261,20 @@ out: RETURN(0); } +/** + * Initialize llog. + * + * Initializes the llog. Specific llog to be used depends on the type of the + * target OSP represents (OST or MDT). The function adds appends a new llog + * record to mark the place where the records associated with this boot + * start. + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_llog_init(const struct lu_env *env, struct osp_device *d) { struct osp_thread_info *osi = osp_env_info(env); @@ -1077,8 +1362,7 @@ static int osp_sync_llog_init(const struct lu_env *env, struct osp_device *d) memcpy(&osi->osi_gen.lgr_gen, &d->opd_syn_generation, sizeof(osi->osi_gen.lgr_gen)); - rc = llog_cat_add(env, lgh, &osi->osi_gen.lgr_hdr, &osi->osi_cookie, - NULL); + rc = llog_cat_add(env, lgh, &osi->osi_gen.lgr_hdr, &osi->osi_cookie); if (rc < 0) GOTO(out_close, rc); llog_ctxt_put(ctxt); @@ -1090,6 +1374,15 @@ out_cleanup: RETURN(rc); } +/** + * Cleanup llog used for syncing. + * + * Closes and cleanups the llog. The function is called when the device is + * shutting down. + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + */ static void osp_sync_llog_fini(const struct lu_env *env, struct osp_device *d) { struct llog_ctxt *ctxt; @@ -1100,12 +1393,22 @@ static void osp_sync_llog_fini(const struct lu_env *env, struct osp_device *d) llog_cleanup(env, ctxt); } -/* - * initializes sync component of OSP +/** + * Initialization of the sync component of OSP. + * + * Initializes the llog and starts a new thread to handle the changes to + * the remote target (OST or MDT). + * + * \param[in] env LU environment provided by the caller + * \param[in] d OSP device + * + * \retval 0 on success + * \retval negative negated errno on error */ int osp_sync_init(const struct lu_env *env, struct osp_device *d) { struct l_wait_info lwi = { 0 }; + struct task_struct *task; int rc; ENTRY; @@ -1131,13 +1434,15 @@ int osp_sync_init(const struct lu_env *env, struct osp_device *d) d->opd_syn_max_rpc_in_progress = OSP_MAX_IN_PROGRESS; spin_lock_init(&d->opd_syn_lock); init_waitqueue_head(&d->opd_syn_waitq); + init_waitqueue_head(&d->opd_syn_barrier_waitq); init_waitqueue_head(&d->opd_syn_thread.t_ctl_waitq); - CFS_INIT_LIST_HEAD(&d->opd_syn_committed_there); + INIT_LIST_HEAD(&d->opd_syn_committed_there); - rc = PTR_ERR(kthread_run(osp_sync_thread, d, - "osp-syn-%u-%u", d->opd_index, d->opd_group)); - if (IS_ERR_VALUE(rc)) { - CERROR("%s: can't start sync thread: rc = %d\n", + task = kthread_run(osp_sync_thread, d, "osp-syn-%u-%u", + d->opd_index, d->opd_group); + if (IS_ERR(task)) { + rc = PTR_ERR(task); + CERROR("%s: cannot start sync thread: rc = %d\n", d->opd_obd->obd_name, rc); GOTO(err_llog, rc); } @@ -1153,6 +1458,15 @@ err_id: return rc; } +/** + * Stop the syncing thread. + * + * Asks the syncing thread to stop and wait until it's stopped. + * + * \param[in] d OSP device + * + * \retval 0 + */ int osp_sync_fini(struct osp_device *d) { struct ptlrpc_thread *thread = &d->opd_syn_thread; @@ -1173,8 +1487,18 @@ int osp_sync_fini(struct osp_device *d) } static DEFINE_MUTEX(osp_id_tracker_sem); -static CFS_LIST_HEAD(osp_id_tracker_list); +static struct list_head osp_id_tracker_list = + LIST_HEAD_INIT(osp_id_tracker_list); +/** + * OSD commit callback. + * + * The function is used as a local OSD commit callback to track the highest + * committed llog record id. see osp_sync_id_traction_init() for the details. + * + * \param[in] th local transaction handle committed + * \param[in] cookie commit callback data (our private structure) + */ static void osp_sync_tracker_commit_cb(struct thandle *th, void *cookie) { struct osp_id_tracker *tr = cookie; @@ -1193,8 +1517,8 @@ static void osp_sync_tracker_commit_cb(struct thandle *th, void *cookie) tr->otr_committed_id, txn->oti_current_id); tr->otr_committed_id = txn->oti_current_id; - cfs_list_for_each_entry(d, &tr->otr_wakeup_list, - opd_syn_ontrack) { + list_for_each_entry(d, &tr->otr_wakeup_list, + opd_syn_ontrack) { d->opd_syn_last_committed_id = tr->otr_committed_id; wake_up(&d->opd_syn_waitq); } @@ -1202,6 +1526,25 @@ static void osp_sync_tracker_commit_cb(struct thandle *th, void *cookie) spin_unlock(&tr->otr_lock); } +/** + * Initialize commit tracking mechanism. + * + * Some setups may have thousands of OSTs and each will be represented by OSP. + * Meaning order of magnitute many more changes to apply every second. In order + * to keep the number of commit callbacks low this mechanism was introduced. + * The mechanism is very similar to transno used by MDT service: it's an single + * ID stream which can be assigned by any OSP to its llog records. The tricky + * part is that ID is stored in per-transaction data and re-used by all the OSPs + * involved in that transaction. Then all these OSPs are woken up utilizing a single OSD commit callback. + * + * The function initializes the data used by the tracker described above. + * A singler tracker per OSD device is created. + * + * \param[in] d OSP device + * + * \retval 0 on success + * \retval negative negated errno on error + */ static int osp_sync_id_traction_init(struct osp_device *d) { struct osp_id_tracker *tr, *found = NULL; @@ -1210,10 +1553,10 @@ static int osp_sync_id_traction_init(struct osp_device *d) LASSERT(d); LASSERT(d->opd_storage); LASSERT(d->opd_syn_tracker == NULL); - CFS_INIT_LIST_HEAD(&d->opd_syn_ontrack); + INIT_LIST_HEAD(&d->opd_syn_ontrack); mutex_lock(&osp_id_tracker_sem); - cfs_list_for_each_entry(tr, &osp_id_tracker_list, otr_list) { + list_for_each_entry(tr, &osp_id_tracker_list, otr_list) { if (tr->otr_dev == d->opd_storage) { LASSERT(atomic_read(&tr->otr_refcount)); atomic_inc(&tr->otr_refcount); @@ -1233,8 +1576,8 @@ static int osp_sync_id_traction_init(struct osp_device *d) tr->otr_next_id = 1; tr->otr_committed_id = 0; atomic_set(&tr->otr_refcount, 1); - CFS_INIT_LIST_HEAD(&tr->otr_wakeup_list); - cfs_list_add(&tr->otr_list, &osp_id_tracker_list); + INIT_LIST_HEAD(&tr->otr_wakeup_list); + list_add(&tr->otr_list, &osp_id_tracker_list); tr->otr_tx_cb.dtc_txn_commit = osp_sync_tracker_commit_cb; tr->otr_tx_cb.dtc_cookie = tr; @@ -1248,6 +1591,14 @@ static int osp_sync_id_traction_init(struct osp_device *d) return rc; } +/** + * Release commit tracker. + * + * Decrease a refcounter on the tracker used by the given OSP device \a d. + * If no more users left, then the tracker is released. + * + * \param[in] d OSP device + */ static void osp_sync_id_traction_fini(struct osp_device *d) { struct osp_id_tracker *tr; @@ -1266,8 +1617,8 @@ static void osp_sync_id_traction_fini(struct osp_device *d) mutex_lock(&osp_id_tracker_sem); if (atomic_dec_and_test(&tr->otr_refcount)) { dt_txn_callback_del(d->opd_storage, &tr->otr_tx_cb); - LASSERT(cfs_list_empty(&tr->otr_wakeup_list)); - cfs_list_del(&tr->otr_list); + LASSERT(list_empty(&tr->otr_wakeup_list)); + list_del(&tr->otr_list); OBD_FREE_PTR(tr); d->opd_syn_tracker = NULL; } @@ -1276,8 +1627,18 @@ static void osp_sync_id_traction_fini(struct osp_device *d) EXIT; } -/* - * generates id for the tracker +/** + * Generate a new ID on a tracker. + * + * Generates a new ID using the tracker associated with the given OSP device + * \a d, if the given ID \a id is non-zero. Unconditially adds OSP device to + * the wakeup list, so OSP won't miss when a transaction using the ID is + * committed. Notice ID is 32bit, but llog doesn't support >2^32 records anyway. + * + * \param[in] d OSP device + * \param[in] id 0 or ID generated previously + * + * \retval ID the caller should use */ static __u32 osp_sync_id_get(struct osp_device *d, __u32 id) { @@ -1300,14 +1661,23 @@ static __u32 osp_sync_id_get(struct osp_device *d, __u32 id) id = tr->otr_next_id++; if (id > d->opd_syn_last_used_id) d->opd_syn_last_used_id = id; - if (cfs_list_empty(&d->opd_syn_ontrack)) - cfs_list_add(&d->opd_syn_ontrack, &tr->otr_wakeup_list); + if (list_empty(&d->opd_syn_ontrack)) + list_add(&d->opd_syn_ontrack, &tr->otr_wakeup_list); spin_unlock(&tr->otr_lock); CDEBUG(D_OTHER, "new id %u\n", (unsigned) id); return id; } +/** + * Stop to propagate commit status to OSP. + * + * If the OSP does not have any llog records she's waiting to commit, then + * it is possible to unsubscribe from wakeups from the tracking using this + * method. + * + * \param[in] d OSP device not willing to wakeup + */ static void osp_sync_remove_from_tracker(struct osp_device *d) { struct osp_id_tracker *tr; @@ -1315,11 +1685,11 @@ static void osp_sync_remove_from_tracker(struct osp_device *d) tr = d->opd_syn_tracker; LASSERT(tr); - if (cfs_list_empty(&d->opd_syn_ontrack)) + if (list_empty(&d->opd_syn_ontrack)) return; spin_lock(&tr->otr_lock); - cfs_list_del_init(&d->opd_syn_ontrack); + list_del_init(&d->opd_syn_ontrack); spin_unlock(&tr->otr_lock); }