X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fptlrpc%2Fservice.c;h=e8e93cffec7208b59f91d98e3da3d6d91c3cb0fd;hp=2199fc1db51476a659d42056fbad87cd5395264c;hb=34f585c993d46e5df403bf92710194652a144bf1;hpb=57e224145f7c390e33c295d95c735934d0c54883 diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 2199fc1..e8e93cf 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -49,21 +49,15 @@ int test_req_buffer_pressure = 0; CFS_MODULE_PARM(test_req_buffer_pressure, "i", int, 0444, "set non-zero to put pressure on request buffer pools"); -unsigned int at_min = 0; CFS_MODULE_PARM(at_min, "i", int, 0644, "Adaptive timeout minimum (sec)"); -unsigned int at_max = 600; -EXPORT_SYMBOL(at_max); CFS_MODULE_PARM(at_max, "i", int, 0644, "Adaptive timeout maximum (sec)"); -unsigned int at_history = 600; CFS_MODULE_PARM(at_history, "i", int, 0644, "Adaptive timeouts remember the slowest event that took place " "within this period (sec)"); -static int at_early_margin = 5; CFS_MODULE_PARM(at_early_margin, "i", int, 0644, "How soon before an RPC deadline to send an early reply"); -static int at_extra = 30; CFS_MODULE_PARM(at_extra, "i", int, 0644, "How much extra time to give with each early reply"); @@ -72,7 +66,7 @@ CFS_MODULE_PARM(at_extra, "i", int, 0644, static int ptlrpc_server_post_idle_rqbds (struct ptlrpc_service *svc); static CFS_LIST_HEAD(ptlrpc_all_services); -spinlock_t ptlrpc_all_services_lock; +cfs_spinlock_t ptlrpc_all_services_lock; static char * ptlrpc_alloc_request_buffer (int size) @@ -117,10 +111,10 @@ ptlrpc_alloc_rqbd (struct ptlrpc_service *svc) return (NULL); } - spin_lock(&svc->srv_lock); - list_add(&rqbd->rqbd_list, &svc->srv_idle_rqbds); + cfs_spin_lock(&svc->srv_lock); + cfs_list_add(&rqbd->rqbd_list, &svc->srv_idle_rqbds); svc->srv_nbufs++; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); return (rqbd); } @@ -131,12 +125,12 @@ ptlrpc_free_rqbd (struct ptlrpc_request_buffer_desc *rqbd) struct ptlrpc_service *svc = rqbd->rqbd_service; LASSERT (rqbd->rqbd_refcount == 0); - LASSERT (list_empty(&rqbd->rqbd_reqs)); + LASSERT (cfs_list_empty(&rqbd->rqbd_reqs)); - spin_lock(&svc->srv_lock); - list_del(&rqbd->rqbd_list); + cfs_spin_lock(&svc->srv_lock); + cfs_list_del(&rqbd->rqbd_list); svc->srv_nbufs--; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_free_request_buffer (rqbd->rqbd_buffer, svc->srv_buf_size); OBD_FREE_PTR(rqbd); @@ -168,8 +162,8 @@ ptlrpc_grow_req_bufs(struct ptlrpc_service *svc) } void -ptlrpc_save_lock (struct ptlrpc_request *req, - struct lustre_handle *lock, int mode, int no_ack) +ptlrpc_save_lock(struct ptlrpc_request *req, + struct lustre_handle *lock, int mode, int no_ack) { struct ptlrpc_reply_state *rs = req->rq_reply_state; int idx; @@ -177,11 +171,15 @@ ptlrpc_save_lock (struct ptlrpc_request *req, LASSERT(rs != NULL); LASSERT(rs->rs_nlocks < RS_MAX_LOCKS); - idx = rs->rs_nlocks++; - rs->rs_locks[idx] = *lock; - rs->rs_modes[idx] = mode; - rs->rs_difficult = 1; - rs->rs_no_ack = !!no_ack; + if (req->rq_export->exp_disconnected) { + ldlm_lock_decref(lock, mode); + } else { + idx = rs->rs_nlocks++; + rs->rs_locks[idx] = *lock; + rs->rs_modes[idx] = mode; + rs->rs_difficult = 1; + rs->rs_no_ack = !!no_ack; + } } #ifdef __KERNEL__ @@ -190,11 +188,11 @@ ptlrpc_save_lock (struct ptlrpc_request *req, #define HRT_STOPPING 1 struct ptlrpc_hr_thread { - spinlock_t hrt_lock; - unsigned long hrt_flags; - cfs_waitq_t hrt_wait; - struct list_head hrt_queue; - struct completion hrt_completion; + cfs_spinlock_t hrt_lock; + unsigned long hrt_flags; + cfs_waitq_t hrt_wait; + cfs_list_t hrt_queue; + cfs_completion_t hrt_completion; }; struct ptlrpc_hr_service { @@ -205,7 +203,7 @@ struct ptlrpc_hr_service { }; struct rs_batch { - struct list_head rsb_replies; + cfs_list_t rsb_replies; struct ptlrpc_service *rsb_svc; unsigned int rsb_n_replies; }; @@ -232,8 +230,24 @@ static void rs_batch_init(struct rs_batch *b) } /** + * Choose an hr thread to dispatch requests to. + */ +static unsigned int get_hr_thread_index(struct ptlrpc_hr_service *hr) +{ + unsigned int idx; + + /* Concurrent modification of hr_index w/o any spinlock + protection is harmless as long as the result fits + [0..(hr_n_threads-1)] range and each thread gets near equal + load. */ + idx = hr->hr_index; + hr->hr_index = (idx >= hr->hr_n_threads - 1) ? 0 : idx + 1; + return idx; +} + +/** * Dispatch all replies accumulated in the batch to one from - * dedicated reply handing threads. + * dedicated reply handling threads. * * \param b batch */ @@ -243,14 +257,12 @@ static void rs_batch_dispatch(struct rs_batch *b) struct ptlrpc_hr_service *hr = ptlrpc_hr; int idx; - idx = hr->hr_index++; - if (hr->hr_index >= hr->hr_n_threads) - hr->hr_index = 0; + idx = get_hr_thread_index(hr); - spin_lock(&hr->hr_threads[idx].hrt_lock); - list_splice_init(&b->rsb_replies, - &hr->hr_threads[idx].hrt_queue); - spin_unlock(&hr->hr_threads[idx].hrt_lock); + cfs_spin_lock(&hr->hr_threads[idx].hrt_lock); + cfs_list_splice_init(&b->rsb_replies, + &hr->hr_threads[idx].hrt_queue); + cfs_spin_unlock(&hr->hr_threads[idx].hrt_lock); cfs_waitq_signal(&hr->hr_threads[idx].hrt_wait); b->rsb_n_replies = 0; } @@ -270,19 +282,20 @@ static void rs_batch_add(struct rs_batch *b, struct ptlrpc_reply_state *rs) if (svc != b->rsb_svc || b->rsb_n_replies >= MAX_SCHEDULED) { if (b->rsb_svc != NULL) { rs_batch_dispatch(b); - spin_unlock(&b->rsb_svc->srv_lock); + cfs_spin_unlock(&b->rsb_svc->srv_lock); } - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); b->rsb_svc = svc; } - spin_lock(&rs->rs_lock); + cfs_spin_lock(&rs->rs_lock); rs->rs_scheduled_ever = 1; if (rs->rs_scheduled == 0) { - list_move(&rs->rs_list, &b->rsb_replies); + cfs_list_move(&rs->rs_list, &b->rsb_replies); rs->rs_scheduled = 1; b->rsb_n_replies++; } - spin_unlock(&rs->rs_lock); + rs->rs_committed = 1; + cfs_spin_unlock(&rs->rs_lock); } /** @@ -296,7 +309,7 @@ static void rs_batch_fini(struct rs_batch *b) { if (b->rsb_svc != 0) { rs_batch_dispatch(b); - spin_unlock(&b->rsb_svc->srv_lock); + cfs_spin_unlock(&b->rsb_svc->srv_lock); } } @@ -318,18 +331,16 @@ void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs) int idx; ENTRY; - LASSERT(list_empty(&rs->rs_list)); + LASSERT(cfs_list_empty(&rs->rs_list)); - idx = hr->hr_index++; - if (hr->hr_index >= hr->hr_n_threads) - hr->hr_index = 0; - spin_lock(&hr->hr_threads[idx].hrt_lock); - list_add_tail(&rs->rs_list, &hr->hr_threads[idx].hrt_queue); - spin_unlock(&hr->hr_threads[idx].hrt_lock); + idx = get_hr_thread_index(hr); + cfs_spin_lock(&hr->hr_threads[idx].hrt_lock); + cfs_list_add_tail(&rs->rs_list, &hr->hr_threads[idx].hrt_queue); + cfs_spin_unlock(&hr->hr_threads[idx].hrt_lock); cfs_waitq_signal(&hr->hr_threads[idx].hrt_wait); EXIT; #else - list_add_tail(&rs->rs_list, &rs->rs_service->srv_reply_queue); + cfs_list_add_tail(&rs->rs_list, &rs->rs_service->srv_reply_queue); #endif } @@ -349,7 +360,7 @@ ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs) } rs->rs_scheduled = 1; - list_del_init(&rs->rs_list); + cfs_list_del_init(&rs->rs_list); ptlrpc_dispatch_difficult_reply(rs); EXIT; } @@ -365,18 +376,18 @@ void ptlrpc_commit_replies(struct obd_export *exp) * to attend to complete them. */ /* CAVEAT EMPTOR: spinlock ordering!!! */ - spin_lock(&exp->exp_uncommitted_replies_lock); - list_for_each_entry_safe(rs, nxt, &exp->exp_uncommitted_replies, - rs_obd_list) { + cfs_spin_lock(&exp->exp_uncommitted_replies_lock); + cfs_list_for_each_entry_safe(rs, nxt, &exp->exp_uncommitted_replies, + rs_obd_list) { LASSERT (rs->rs_difficult); /* VBR: per-export last_committed */ LASSERT(rs->rs_export); if (rs->rs_transno <= exp->exp_last_committed) { - list_del_init(&rs->rs_obd_list); + cfs_list_del_init(&rs->rs_obd_list); rs_batch_add(&batch, rs); } } - spin_unlock(&exp->exp_uncommitted_replies_lock); + cfs_spin_unlock(&exp->exp_uncommitted_replies_lock); rs_batch_fini(&batch); EXIT; } @@ -389,23 +400,23 @@ ptlrpc_server_post_idle_rqbds (struct ptlrpc_service *svc) int posted = 0; for (;;) { - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); - if (list_empty (&svc->srv_idle_rqbds)) { - spin_unlock(&svc->srv_lock); + if (cfs_list_empty (&svc->srv_idle_rqbds)) { + cfs_spin_unlock(&svc->srv_lock); return (posted); } - rqbd = list_entry(svc->srv_idle_rqbds.next, - struct ptlrpc_request_buffer_desc, - rqbd_list); - list_del (&rqbd->rqbd_list); + rqbd = cfs_list_entry(svc->srv_idle_rqbds.next, + struct ptlrpc_request_buffer_desc, + rqbd_list); + cfs_list_del (&rqbd->rqbd_list); /* assume we will post successfully */ svc->srv_nrqbd_receiving++; - list_add (&rqbd->rqbd_list, &svc->srv_active_rqbds); + cfs_list_add (&rqbd->rqbd_list, &svc->srv_active_rqbds); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); rc = ptlrpc_register_rqbd(rqbd); if (rc != 0) @@ -414,16 +425,16 @@ ptlrpc_server_post_idle_rqbds (struct ptlrpc_service *svc) posted = 1; } - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); svc->srv_nrqbd_receiving--; - list_del(&rqbd->rqbd_list); - list_add_tail(&rqbd->rqbd_list, &svc->srv_idle_rqbds); + cfs_list_del(&rqbd->rqbd_list); + cfs_list_add_tail(&rqbd->rqbd_list, &svc->srv_idle_rqbds); /* Don't complain if no request buffers are posted right now; LNET * won't drop requests because we set the portal lazy! */ - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); return (-1); } @@ -480,7 +491,7 @@ ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size, int max_reply_size, /* First initialise enough for early teardown */ service->srv_name = name; - spin_lock_init(&service->srv_lock); + cfs_spin_lock_init(&service->srv_lock); CFS_INIT_LIST_HEAD(&service->srv_threads); cfs_waitq_init(&service->srv_waitq); @@ -518,9 +529,9 @@ ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size, int max_reply_size, #endif CFS_INIT_LIST_HEAD(&service->srv_free_rs_list); cfs_waitq_init(&service->srv_free_rs_waitq); - atomic_set(&service->srv_n_difficult_replies, 0); + cfs_atomic_set(&service->srv_n_difficult_replies, 0); - spin_lock_init(&service->srv_at_lock); + cfs_spin_lock_init(&service->srv_at_lock); CFS_INIT_LIST_HEAD(&service->srv_req_in_queue); array = &service->srv_at_array; @@ -530,7 +541,7 @@ ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size, int max_reply_size, array->paa_deadline = -1; /* allocate memory for srv_at_array (ptlrpc_at_array) */ - OBD_ALLOC(array->paa_reqs_array, sizeof(struct list_head) * size); + OBD_ALLOC(array->paa_reqs_array, sizeof(cfs_list_t) * size); if (array->paa_reqs_array == NULL) GOTO(failed, NULL); @@ -546,9 +557,9 @@ ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size, int max_reply_size, timeout is less than this, we'll be sending an early reply. */ at_init(&service->srv_at_estimate, 10, 0); - spin_lock (&ptlrpc_all_services_lock); - list_add (&service->srv_list, &ptlrpc_all_services); - spin_unlock (&ptlrpc_all_services_lock); + cfs_spin_lock (&ptlrpc_all_services_lock); + cfs_list_add (&service->srv_list, &ptlrpc_all_services); + cfs_spin_unlock (&ptlrpc_all_services_lock); /* Now allocate the request buffers */ rc = ptlrpc_grow_req_bufs(service); @@ -582,8 +593,8 @@ failed: */ static void ptlrpc_server_free_request(struct ptlrpc_request *req) { - LASSERT(atomic_read(&req->rq_refcount) == 0); - LASSERT(list_empty(&req->rq_timed_list)); + LASSERT(cfs_atomic_read(&req->rq_refcount) == 0); + LASSERT(cfs_list_empty(&req->rq_timed_list)); /* DEBUG_REQ() assumes the reply state of a request with a valid * ref will not be destroyed until that reference is dropped. */ @@ -600,84 +611,134 @@ static void ptlrpc_server_free_request(struct ptlrpc_request *req) } /** + * increment the number of active requests consuming service threads. + */ +void ptlrpc_server_active_request_inc(struct ptlrpc_request *req) +{ + struct ptlrpc_request_buffer_desc *rqbd = req->rq_rqbd; + struct ptlrpc_service *svc = rqbd->rqbd_service; + + cfs_spin_lock(&svc->srv_lock); + svc->srv_n_active_reqs++; + cfs_spin_unlock(&svc->srv_lock); +} + +/** + * decrement the number of active requests consuming service threads. + */ +void ptlrpc_server_active_request_dec(struct ptlrpc_request *req) +{ + struct ptlrpc_request_buffer_desc *rqbd = req->rq_rqbd; + struct ptlrpc_service *svc = rqbd->rqbd_service; + + cfs_spin_lock(&svc->srv_lock); + svc->srv_n_active_reqs--; + cfs_spin_unlock(&svc->srv_lock); +} + +/** * drop a reference count of the request. if it reaches 0, we either * put it into history list, or free it immediately. */ -static void ptlrpc_server_drop_request(struct ptlrpc_request *req) +void ptlrpc_server_drop_request(struct ptlrpc_request *req) { struct ptlrpc_request_buffer_desc *rqbd = req->rq_rqbd; struct ptlrpc_service *svc = rqbd->rqbd_service; int refcount; - struct list_head *tmp; - struct list_head *nxt; + cfs_list_t *tmp; + cfs_list_t *nxt; - if (!atomic_dec_and_test(&req->rq_refcount)) + if (!cfs_atomic_dec_and_test(&req->rq_refcount)) return; - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_at_lock); + if (req->rq_at_linked) { + struct ptlrpc_at_array *array = &svc->srv_at_array; + __u32 index = req->rq_at_index; + + LASSERT(!cfs_list_empty(&req->rq_timed_list)); + cfs_list_del_init(&req->rq_timed_list); + cfs_spin_lock(&req->rq_lock); + req->rq_at_linked = 0; + cfs_spin_unlock(&req->rq_lock); + array->paa_reqs_count[index]--; + array->paa_count--; + } else + LASSERT(cfs_list_empty(&req->rq_timed_list)); + cfs_spin_unlock(&svc->srv_at_lock); + + /* finalize request */ + if (req->rq_export) { + class_export_put(req->rq_export); + req->rq_export = NULL; + } + + cfs_spin_lock(&svc->srv_lock); svc->srv_n_active_reqs--; - list_add(&req->rq_list, &rqbd->rqbd_reqs); + cfs_list_add(&req->rq_list, &rqbd->rqbd_reqs); refcount = --(rqbd->rqbd_refcount); if (refcount == 0) { /* request buffer is now idle: add to history */ - list_del(&rqbd->rqbd_list); - list_add_tail(&rqbd->rqbd_list, &svc->srv_history_rqbds); + cfs_list_del(&rqbd->rqbd_list); + cfs_list_add_tail(&rqbd->rqbd_list, &svc->srv_history_rqbds); svc->srv_n_history_rqbds++; /* cull some history? * I expect only about 1 or 2 rqbds need to be recycled here */ while (svc->srv_n_history_rqbds > svc->srv_max_history_rqbds) { - rqbd = list_entry(svc->srv_history_rqbds.next, - struct ptlrpc_request_buffer_desc, - rqbd_list); + rqbd = cfs_list_entry(svc->srv_history_rqbds.next, + struct ptlrpc_request_buffer_desc, + rqbd_list); - list_del(&rqbd->rqbd_list); + cfs_list_del(&rqbd->rqbd_list); svc->srv_n_history_rqbds--; /* remove rqbd's reqs from svc's req history while * I've got the service lock */ - list_for_each(tmp, &rqbd->rqbd_reqs) { - req = list_entry(tmp, struct ptlrpc_request, - rq_list); + cfs_list_for_each(tmp, &rqbd->rqbd_reqs) { + req = cfs_list_entry(tmp, struct ptlrpc_request, + rq_list); /* Track the highest culled req seq */ if (req->rq_history_seq > svc->srv_request_max_cull_seq) svc->srv_request_max_cull_seq = req->rq_history_seq; - list_del(&req->rq_history_list); + cfs_list_del(&req->rq_history_list); } - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); - list_for_each_safe(tmp, nxt, &rqbd->rqbd_reqs) { - req = list_entry(rqbd->rqbd_reqs.next, - struct ptlrpc_request, - rq_list); - list_del(&req->rq_list); + cfs_list_for_each_safe(tmp, nxt, &rqbd->rqbd_reqs) { + req = cfs_list_entry(rqbd->rqbd_reqs.next, + struct ptlrpc_request, + rq_list); + cfs_list_del(&req->rq_list); ptlrpc_server_free_request(req); } - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); /* * now all reqs including the embedded req has been * disposed, schedule request buffer for re-use. */ - LASSERT(atomic_read(&rqbd->rqbd_req.rq_refcount) == 0); - list_add_tail(&rqbd->rqbd_list, &svc->srv_idle_rqbds); + LASSERT(cfs_atomic_read(&rqbd->rqbd_req.rq_refcount) == + 0); + cfs_list_add_tail(&rqbd->rqbd_list, + &svc->srv_idle_rqbds); } - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); } else if (req->rq_reply_state && req->rq_reply_state->rs_prealloc) { /* If we are low on memory, we are not interested in history */ - list_del(&req->rq_list); - list_del_init(&req->rq_history_list); - spin_unlock(&svc->srv_lock); + cfs_list_del(&req->rq_list); + cfs_list_del_init(&req->rq_history_list); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_server_free_request(req); } else { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); } } @@ -687,29 +748,6 @@ static void ptlrpc_server_drop_request(struct ptlrpc_request *req) */ static void ptlrpc_server_finish_request(struct ptlrpc_request *req) { - struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service; - - if (req->rq_export) { - class_export_put(req->rq_export); - req->rq_export = NULL; - } - - if (req->rq_phase != RQ_PHASE_NEW) /* incorrect message magic */ - DEBUG_REQ(D_INFO, req, "free req"); - - spin_lock(&svc->srv_at_lock); - req->rq_sent_final = 1; - list_del_init(&req->rq_timed_list); - if (req->rq_at_linked) { - struct ptlrpc_at_array *array = &svc->srv_at_array; - __u32 index = req->rq_at_index; - - req->rq_at_linked = 0; - array->paa_reqs_count[index]--; - array->paa_count--; - } - spin_unlock(&svc->srv_at_lock); - ptlrpc_server_drop_request(req); } @@ -744,21 +782,21 @@ static void ptlrpc_update_export_timer(struct obd_export *exp, long extra_delay) /* exports may get disconnected from the chain even though the export has references, so we must keep the spin lock while manipulating the lists */ - spin_lock(&exp->exp_obd->obd_dev_lock); + cfs_spin_lock(&exp->exp_obd->obd_dev_lock); - if (list_empty(&exp->exp_obd_chain_timed)) { + if (cfs_list_empty(&exp->exp_obd_chain_timed)) { /* this one is not timed */ - spin_unlock(&exp->exp_obd->obd_dev_lock); + cfs_spin_unlock(&exp->exp_obd->obd_dev_lock); RETURN_EXIT; } - list_move_tail(&exp->exp_obd_chain_timed, - &exp->exp_obd->obd_exports_timed); + cfs_list_move_tail(&exp->exp_obd_chain_timed, + &exp->exp_obd->obd_exports_timed); - oldest_exp = list_entry(exp->exp_obd->obd_exports_timed.next, - struct obd_export, exp_obd_chain_timed); + oldest_exp = cfs_list_entry(exp->exp_obd->obd_exports_timed.next, + struct obd_export, exp_obd_chain_timed); oldest_time = oldest_exp->exp_last_request_time; - spin_unlock(&exp->exp_obd->obd_dev_lock); + cfs_spin_unlock(&exp->exp_obd->obd_dev_lock); if (exp->exp_obd->obd_recovering) { /* be nice to everyone during recovery */ @@ -778,8 +816,8 @@ static void ptlrpc_update_export_timer(struct obd_export *exp, long extra_delay) exp->exp_obd->obd_eviction_timer = cfs_time_current_sec() + 3 * PING_INTERVAL; CDEBUG(D_HA, "%s: Think about evicting %s from "CFS_TIME_T"\n", - exp->exp_obd->obd_name, obd_export_nid2str(exp), - oldest_time); + exp->exp_obd->obd_name, + obd_export_nid2str(oldest_exp), oldest_time); } } else { if (cfs_time_current_sec() > @@ -824,10 +862,10 @@ static void ptlrpc_at_set_timer(struct ptlrpc_service *svc) struct ptlrpc_at_array *array = &svc->srv_at_array; __s32 next; - spin_lock(&svc->srv_at_lock); + cfs_spin_lock(&svc->srv_at_lock); if (array->paa_count == 0) { cfs_timer_disarm(&svc->srv_at_timer); - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); return; } @@ -838,7 +876,7 @@ static void ptlrpc_at_set_timer(struct ptlrpc_service *svc) ptlrpc_at_timer((unsigned long)svc); else cfs_timer_arm(&svc->srv_at_timer, cfs_time_shift(next)); - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); CDEBUG(D_INFO, "armed %s at %+ds\n", svc->srv_name, next); } @@ -860,34 +898,32 @@ static int ptlrpc_at_add_timed(struct ptlrpc_request *req) if ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT) == 0) return(-ENOSYS); - spin_lock(&svc->srv_at_lock); + cfs_spin_lock(&svc->srv_at_lock); + LASSERT(cfs_list_empty(&req->rq_timed_list)); - if (unlikely(req->rq_sent_final)) { - spin_unlock(&svc->srv_at_lock); - return 0; - } - - LASSERT(list_empty(&req->rq_timed_list)); - - index = req->rq_deadline % array->paa_size; + index = (unsigned long)req->rq_deadline % array->paa_size; if (array->paa_reqs_count[index] > 0) { /* latest rpcs will have the latest deadlines in the list, * so search backward. */ - list_for_each_entry_reverse(rq, &array->paa_reqs_array[index], - rq_timed_list) { + cfs_list_for_each_entry_reverse(rq, + &array->paa_reqs_array[index], + rq_timed_list) { if (req->rq_deadline >= rq->rq_deadline) { - list_add(&req->rq_timed_list, - &rq->rq_timed_list); + cfs_list_add(&req->rq_timed_list, + &rq->rq_timed_list); break; } } } - + /* Add the request at the head of the list */ - if (list_empty(&req->rq_timed_list)) - list_add(&req->rq_timed_list, &array->paa_reqs_array[index]); + if (cfs_list_empty(&req->rq_timed_list)) + cfs_list_add(&req->rq_timed_list, + &array->paa_reqs_array[index]); + cfs_spin_lock(&req->rq_lock); req->rq_at_linked = 1; + cfs_spin_unlock(&req->rq_lock); req->rq_at_index = index; array->paa_reqs_count[index]++; array->paa_count++; @@ -895,7 +931,7 @@ static int ptlrpc_at_add_timed(struct ptlrpc_request *req) array->paa_deadline = req->rq_deadline; found = 1; } - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); if (found) ptlrpc_at_set_timer(svc); @@ -903,8 +939,7 @@ static int ptlrpc_at_add_timed(struct ptlrpc_request *req) return 0; } -static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req, - int extra_time) +static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req) { struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service; struct ptlrpc_request *reqcopy; @@ -920,7 +955,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req, "%ssending early reply (deadline %+lds, margin %+lds) for " "%d+%d", AT_OFF ? "AT off - not " : "", olddl, olddl - at_get(&svc->srv_at_estimate), - at_get(&svc->srv_at_estimate), extra_time); + at_get(&svc->srv_at_estimate), at_extra); if (AT_OFF) RETURN(0); @@ -940,31 +975,37 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req, RETURN(-ENOSYS); } - if (req->rq_export && req->rq_export->exp_in_recovery) { - /* don't increase server estimates during recovery, and give - clients the full recovery time. */ - newdl = cfs_time_current_sec() + - req->rq_export->exp_obd->obd_recovery_timeout; + if (req->rq_export && + lustre_msg_get_flags(req->rq_reqmsg) & + (MSG_REPLAY | MSG_REQ_REPLAY_DONE | MSG_LOCK_REPLAY_DONE)) { + /* During recovery, we don't want to send too many early + * replies, but on the other hand we want to make sure the + * client has enough time to resend if the rpc is lost. So + * during the recovery period send at least 4 early replies, + * spacing them every at_extra if we can. at_estimate should + * always equal this fixed value during recovery. */ + at_measured(&svc->srv_at_estimate, min(at_extra, + req->rq_export->exp_obd->obd_recovery_timeout / 4)); } else { - if (extra_time) { - /* Fake our processing time into the future to ask the - clients for some extra amount of time */ - extra_time += cfs_time_current_sec() - - req->rq_arrival_time.tv_sec; - at_add(&svc->srv_at_estimate, extra_time); + /* Fake our processing time into the future to ask the clients + * for some extra amount of time */ + at_measured(&svc->srv_at_estimate, at_extra + + cfs_time_current_sec() - + req->rq_arrival_time.tv_sec); + + /* Check to see if we've actually increased the deadline - + * we may be past adaptive_max */ + if (req->rq_deadline >= req->rq_arrival_time.tv_sec + + at_get(&svc->srv_at_estimate)) { + DEBUG_REQ(D_WARNING, req, "Couldn't add any time " + "(%ld/%ld), not sending early reply\n", + olddl, req->rq_arrival_time.tv_sec + + at_get(&svc->srv_at_estimate) - + cfs_time_current_sec()); + RETURN(-ETIMEDOUT); } - newdl = req->rq_arrival_time.tv_sec + - at_get(&svc->srv_at_estimate); - } - if (req->rq_deadline >= newdl) { - /* We're not adding any time, no need to send an early reply - (e.g. maybe at adaptive_max) */ - DEBUG_REQ(D_WARNING, req, "Couldn't add any time (" - CFS_DURATION_T"/"CFS_DURATION_T"), " - "not sending early reply\n", olddl, - cfs_time_sub(newdl, cfs_time_current_sec())); - RETURN(-ETIMEDOUT); } + newdl = cfs_time_current_sec() + at_get(&svc->srv_at_estimate); OBD_ALLOC(reqcopy, sizeof *reqcopy); if (reqcopy == NULL) @@ -986,10 +1027,12 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req, reqcopy->rq_reqmsg = reqmsg; memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen); - if (req->rq_sent_final) { + LASSERT(cfs_atomic_read(&req->rq_refcount)); + /** if it is last refcount then early reply isn't needed */ + if (cfs_atomic_read(&req->rq_refcount) == 1) { DEBUG_REQ(D_ADAPTTO, reqcopy, "Normal reply already sent out, " "abort sending early reply\n"); - GOTO(out, rc = 0); + GOTO(out, rc = -EINVAL); } /* Connection ref */ @@ -1037,7 +1080,7 @@ out: static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) { struct ptlrpc_request *rq, *n; - struct list_head work_list; + cfs_list_t work_list; struct ptlrpc_at_array *array = &svc->srv_at_array; __u32 index, count; time_t deadline; @@ -1046,16 +1089,16 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) int first, counter = 0; ENTRY; - spin_lock(&svc->srv_at_lock); + cfs_spin_lock(&svc->srv_at_lock); if (svc->srv_at_check == 0) { - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); RETURN(0); } delay = cfs_time_sub(cfs_time_current(), svc->srv_at_checktime); svc->srv_at_check = 0; if (array->paa_count == 0) { - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); RETURN(0); } @@ -1063,7 +1106,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) first = array->paa_deadline - now; if (first > at_early_margin) { /* We've still got plenty of time. Reset the timer. */ - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); ptlrpc_at_set_timer(svc); RETURN(0); } @@ -1072,18 +1115,28 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) server will take. Send early replies to everyone expiring soon. */ CFS_INIT_LIST_HEAD(&work_list); deadline = -1; - index = array->paa_deadline % array->paa_size; + index = (unsigned long)array->paa_deadline % array->paa_size; count = array->paa_count; while (count > 0) { count -= array->paa_reqs_count[index]; - list_for_each_entry_safe(rq, n, &array->paa_reqs_array[index], - rq_timed_list) { + cfs_list_for_each_entry_safe(rq, n, + &array->paa_reqs_array[index], + rq_timed_list) { if (rq->rq_deadline <= now + at_early_margin) { - list_move(&rq->rq_timed_list, &work_list); + cfs_list_del_init(&rq->rq_timed_list); + /** + * ptlrpc_server_drop_request() may drop + * refcount to 0 already. Let's check this and + * don't add entry to work_list + */ + if (likely(cfs_atomic_inc_not_zero(&rq->rq_refcount))) + cfs_list_add(&rq->rq_timed_list, &work_list); counter++; array->paa_reqs_count[index]--; array->paa_count--; + cfs_spin_lock(&rq->rq_lock); rq->rq_at_linked = 0; + cfs_spin_unlock(&rq->rq_lock); continue; } @@ -1098,7 +1151,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) index = 0; } array->paa_deadline = deadline; - spin_unlock(&svc->srv_at_lock); + cfs_spin_unlock(&svc->srv_at_lock); /* we have a new earliest deadline, restart the timer */ ptlrpc_at_set_timer(svc); @@ -1116,25 +1169,18 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service *svc) at_get(&svc->srv_at_estimate), delay); } - /* ptlrpc_server_finish_request may delete an entry out of - * the work list */ - spin_lock(&svc->srv_at_lock); - while (!list_empty(&work_list)) { - rq = list_entry(work_list.next, struct ptlrpc_request, - rq_timed_list); - list_del_init(&rq->rq_timed_list); - /* if the entry is still in the worklist, it hasn't been - deleted, and is safe to take a ref to keep the req around */ - atomic_inc(&rq->rq_refcount); - spin_unlock(&svc->srv_at_lock); + /* we took additional refcount so entries can't be deleted from list, no + * locking is needed */ + while (!cfs_list_empty(&work_list)) { + rq = cfs_list_entry(work_list.next, struct ptlrpc_request, + rq_timed_list); + cfs_list_del_init(&rq->rq_timed_list); - if (ptlrpc_at_send_early_reply(rq, at_extra) == 0) + if (ptlrpc_at_send_early_reply(rq) == 0) ptlrpc_at_add_timed(rq); ptlrpc_server_drop_request(rq); - spin_lock(&svc->srv_at_lock); } - spin_unlock(&svc->srv_at_lock); RETURN(0); } @@ -1155,9 +1201,10 @@ static int ptlrpc_hpreq_init(struct ptlrpc_service *svc, RETURN(rc); } if (req->rq_export && req->rq_ops) { - spin_lock(&req->rq_export->exp_lock); - list_add(&req->rq_exp_list, &req->rq_export->exp_queued_rpc); - spin_unlock(&req->rq_export->exp_lock); + cfs_spin_lock(&req->rq_export->exp_lock); + cfs_list_add(&req->rq_exp_list, + &req->rq_export->exp_queued_rpc); + cfs_spin_unlock(&req->rq_export->exp_lock); } RETURN(0); @@ -1168,9 +1215,9 @@ static void ptlrpc_hpreq_fini(struct ptlrpc_request *req) { ENTRY; if (req->rq_export && req->rq_ops) { - spin_lock(&req->rq_export->exp_lock); - list_del_init(&req->rq_exp_list); - spin_unlock(&req->rq_export->exp_lock); + cfs_spin_lock(&req->rq_export->exp_lock); + cfs_list_del_init(&req->rq_exp_list); + cfs_spin_unlock(&req->rq_export->exp_lock); } EXIT; } @@ -1190,17 +1237,17 @@ static void ptlrpc_hpreq_reorder_nolock(struct ptlrpc_service *svc, { ENTRY; LASSERT(svc != NULL); - spin_lock(&req->rq_lock); + cfs_spin_lock(&req->rq_lock); if (req->rq_hp == 0) { int opc = lustre_msg_get_opc(req->rq_reqmsg); /* Add to the high priority queue. */ - list_move_tail(&req->rq_list, &svc->srv_request_hpq); + cfs_list_move_tail(&req->rq_list, &svc->srv_request_hpq); req->rq_hp = 1; if (opc != OBD_PING) DEBUG_REQ(D_NET, req, "high priority req"); } - spin_unlock(&req->rq_lock); + cfs_spin_unlock(&req->rq_lock); EXIT; } @@ -1209,16 +1256,16 @@ void ptlrpc_hpreq_reorder(struct ptlrpc_request *req) struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service; ENTRY; - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); /* It may happen that the request is already taken for the processing * but still in the export list, do not re-add it into the HP list. */ if (req->rq_phase == RQ_PHASE_NEW) ptlrpc_hpreq_reorder_nolock(svc, req); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); EXIT; } -/** Check if the request if a high priority one. */ +/** Check if the request is a high priority one. */ static int ptlrpc_server_hpreq_check(struct ptlrpc_request *req) { int opc, rc = 0; @@ -1246,17 +1293,18 @@ static int ptlrpc_server_request_add(struct ptlrpc_service *svc, if (rc < 0) RETURN(rc); - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); /* Before inserting the request into the queue, check if it is not * inserted yet, or even already handled -- it may happen due to * a racing ldlm_server_blocking_ast(). */ - if (req->rq_phase == RQ_PHASE_NEW && list_empty(&req->rq_list)) { + if (req->rq_phase == RQ_PHASE_NEW && cfs_list_empty(&req->rq_list)) { if (rc) ptlrpc_hpreq_reorder_nolock(svc, req); else - list_add_tail(&req->rq_list, &svc->srv_request_queue); + cfs_list_add_tail(&req->rq_list, + &svc->srv_request_queue); } - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); RETURN(0); } @@ -1269,25 +1317,24 @@ static int ptlrpc_server_request_add(struct ptlrpc_service *svc, static int ptlrpc_server_allow_normal(struct ptlrpc_service *svc, int force) { return force || !svc->srv_hpreq_handler || svc->srv_n_hpreq > 0 || - svc->srv_n_active_reqs < svc->srv_threads_running - 2; + svc->srv_threads_running < svc->srv_threads_started - 2; } static struct ptlrpc_request * -ptlrpc_server_request_get(struct ptlrpc_service *svc, int force) +ptlrpc_server_request_get(struct ptlrpc_service *svc) { struct ptlrpc_request *req = NULL; ENTRY; - if (ptlrpc_server_allow_normal(svc, force) && - !list_empty(&svc->srv_request_queue) && - (list_empty(&svc->srv_request_hpq) || + if (!cfs_list_empty(&svc->srv_request_queue) && + (cfs_list_empty(&svc->srv_request_hpq) || svc->srv_hpreq_count >= svc->srv_hpreq_ratio)) { - req = list_entry(svc->srv_request_queue.next, - struct ptlrpc_request, rq_list); + req = cfs_list_entry(svc->srv_request_queue.next, + struct ptlrpc_request, rq_list); svc->srv_hpreq_count = 0; - } else if (!list_empty(&svc->srv_request_hpq)) { - req = list_entry(svc->srv_request_hpq.next, - struct ptlrpc_request, rq_list); + } else if (!cfs_list_empty(&svc->srv_request_hpq)) { + req = cfs_list_entry(svc->srv_request_hpq.next, + struct ptlrpc_request, rq_list); svc->srv_hpreq_count++; } RETURN(req); @@ -1296,8 +1343,8 @@ ptlrpc_server_request_get(struct ptlrpc_service *svc, int force) static int ptlrpc_server_request_pending(struct ptlrpc_service *svc, int force) { return ((ptlrpc_server_allow_normal(svc, force) && - !list_empty(&svc->srv_request_queue)) || - !list_empty(&svc->srv_request_hpq)); + !cfs_list_empty(&svc->srv_request_queue)) || + !cfs_list_empty(&svc->srv_request_hpq)); } /* Handle freshly incoming reqs, add to timed early reply list, @@ -1312,18 +1359,18 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc) LASSERT(svc); - spin_lock(&svc->srv_lock); - if (list_empty(&svc->srv_req_in_queue)) { - spin_unlock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); + if (cfs_list_empty(&svc->srv_req_in_queue)) { + cfs_spin_unlock(&svc->srv_lock); RETURN(0); } - req = list_entry(svc->srv_req_in_queue.next, - struct ptlrpc_request, rq_list); - list_del_init (&req->rq_list); + req = cfs_list_entry(svc->srv_req_in_queue.next, + struct ptlrpc_request, rq_list); + cfs_list_del_init (&req->rq_list); /* Consider this still a "queued" request as far as stats are concerned */ - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); /* go through security check/transform */ rc = sptlrpc_svc_unwrap_request(req); @@ -1339,15 +1386,18 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc) LBUG(); } - /* Clear request swab mask; this is a new request */ - req->rq_req_swab_mask = 0; - - rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen); - if (rc != 0) { - CERROR("error unpacking request: ptl %d from %s x"LPU64"\n", - svc->srv_req_portal, libcfs_id2str(req->rq_peer), - req->rq_xid); - goto err_req; + /* + * for null-flavored rpc, msg has been unpacked by sptlrpc, although + * redo it wouldn't be harmful. + */ + if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL) { + rc = ptlrpc_unpack_req_msg(req, req->rq_reqlen); + if (rc != 0) { + CERROR("error unpacking request: ptl %d from %s " + "x"LPU64"\n", svc->srv_req_portal, + libcfs_id2str(req->rq_peer), req->rq_xid); + goto err_req; + } } rc = lustre_unpack_req_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF); @@ -1358,6 +1408,13 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc) goto err_req; } + if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DROP_REQ_OPC) && + lustre_msg_get_opc(req->rq_reqmsg) == obd_fail_val) { + CERROR("drop incoming rpc opc %u, x"LPU64"\n", + obd_fail_val, req->rq_xid); + goto err_req; + } + rc = -EINVAL; if (lustre_msg_get_type(req->rq_reqmsg) != PTL_RPC_MSG_REQUEST) { CERROR("wrong packet type received (type=%u) from %s\n", @@ -1425,10 +1482,10 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc) RETURN(1); err_req: - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); svc->srv_n_queued_reqs--; svc->srv_n_active_reqs++; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_server_finish_request(req); RETURN(1); @@ -1449,25 +1506,17 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, LASSERT(svc); - spin_lock(&svc->srv_lock); - if (unlikely(!ptlrpc_server_request_pending(svc, 0) || - ( + cfs_spin_lock(&svc->srv_lock); #ifndef __KERNEL__ - /* !@%$# liblustre only has 1 thread */ - atomic_read(&svc->srv_n_difficult_replies) != 0 && -#endif - svc->srv_n_active_reqs >= (svc->srv_threads_running - 1)))) { - /* Don't handle regular requests in the last thread, in order * re - * to handle difficult replies (which might block other threads) - * as well as handle any incoming reqs, early replies, etc. - * That means we always need at least 2 service threads. */ - spin_unlock(&svc->srv_lock); + /* !@%$# liblustre only has 1 thread */ + if (cfs_atomic_read(&svc->srv_n_difficult_replies) != 0) { + cfs_spin_unlock(&svc->srv_lock); RETURN(0); - } - - request = ptlrpc_server_request_get(svc, 0); + } +#endif + request = ptlrpc_server_request_get(svc); if (request == NULL) { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); RETURN(0); } @@ -1479,19 +1528,18 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, if (unlikely(fail_opc)) { if (request->rq_export && request->rq_ops) { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); OBD_FAIL_TIMEOUT(fail_opc, 4); - spin_lock(&svc->srv_lock); - request = ptlrpc_server_request_get(svc, 0); + cfs_spin_lock(&svc->srv_lock); + request = ptlrpc_server_request_get(svc); if (request == NULL) { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); RETURN(0); } - LASSERT(ptlrpc_server_request_pending(svc, 0)); } } - list_del_init(&request->rq_list); + cfs_list_del_init(&request->rq_list); svc->srv_n_queued_reqs--; svc->srv_n_active_reqs++; if (request->rq_hp) @@ -1500,14 +1548,14 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, /* The phase is changed under the lock here because we need to know * the request is under processing (see ptlrpc_hpreq_reorder()). */ ptlrpc_rqphase_move(request, RQ_PHASE_INTERPRET); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_hpreq_fini(request); if(OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DUMP_LOG)) libcfs_debug_dumplog(); - do_gettimeofday(&work_start); + cfs_gettimeofday(&work_start); timediff = cfs_timeval_sub(&work_start, &request->rq_arrival_time,NULL); if (likely(svc->srv_stats != NULL)) { lprocfs_counter_add(svc->srv_stats, PTLRPC_REQWAIT_CNTR, @@ -1561,27 +1609,18 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, (request->rq_export ? (char *)request->rq_export->exp_client_uuid.uuid : "0"), (request->rq_export ? - atomic_read(&request->rq_export->exp_refcount) : -99), + cfs_atomic_read(&request->rq_export->exp_refcount) : -99), lustre_msg_get_status(request->rq_reqmsg), request->rq_xid, libcfs_id2str(request->rq_peer), lustre_msg_get_opc(request->rq_reqmsg)); - OBD_FAIL_TIMEOUT_MS(OBD_FAIL_PTLRPC_PAUSE_REQ, obd_fail_val); + if (lustre_msg_get_opc(request->rq_reqmsg) != OBD_PING) + OBD_FAIL_TIMEOUT_MS(OBD_FAIL_PTLRPC_PAUSE_REQ, obd_fail_val); rc = svc->srv_handler(request); ptlrpc_rqphase_move(request, RQ_PHASE_COMPLETE); - CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:nid:opc " - "%s:%s+%d:%d:x"LPU64":%s:%d\n", cfs_curproc_comm(), - (request->rq_export ? - (char *)request->rq_export->exp_client_uuid.uuid : "0"), - (request->rq_export ? - atomic_read(&request->rq_export->exp_refcount) : -99), - lustre_msg_get_status(request->rq_reqmsg), request->rq_xid, - libcfs_id2str(request->rq_peer), - lustre_msg_get_opc(request->rq_reqmsg)); - put_rpc_export: if (export != NULL) class_export_rpc_put(export); @@ -1599,17 +1638,28 @@ put_conn: request->rq_deadline)); } - do_gettimeofday(&work_end); + cfs_gettimeofday(&work_end); timediff = cfs_timeval_sub(&work_end, &work_start, NULL); - CDEBUG(D_RPCTRACE, "request x"LPU64" opc %u from %s processed in " + CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:nid:opc " + "%s:%s+%d:%d:x"LPU64":%s:%d Request procesed in " "%ldus (%ldus total) trans "LPU64" rc %d/%d\n", - request->rq_xid, lustre_msg_get_opc(request->rq_reqmsg), - libcfs_id2str(request->rq_peer), timediff, - cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL), - request->rq_repmsg ? lustre_msg_get_transno(request->rq_repmsg) : - request->rq_transno, request->rq_status, - request->rq_repmsg ? lustre_msg_get_status(request->rq_repmsg): - -999); + cfs_curproc_comm(), + (request->rq_export ? + (char *)request->rq_export->exp_client_uuid.uuid : "0"), + (request->rq_export ? + cfs_atomic_read(&request->rq_export->exp_refcount) : -99), + lustre_msg_get_status(request->rq_reqmsg), + request->rq_xid, + libcfs_id2str(request->rq_peer), + lustre_msg_get_opc(request->rq_reqmsg), + timediff, + cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL), + (request->rq_repmsg ? + lustre_msg_get_transno(request->rq_repmsg) : + request->rq_transno), + request->rq_status, + (request->rq_repmsg ? + lustre_msg_get_status(request->rq_repmsg) : -999)); if (likely(svc->srv_stats != NULL && request->rq_reqmsg != NULL)) { __u32 op = lustre_msg_get_opc(request->rq_reqmsg); int opc = opcode_offset(op); @@ -1630,10 +1680,10 @@ put_conn: } out_req: - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); if (request->rq_hp) svc->srv_n_hpreq--; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_server_finish_request(request); RETURN(1); @@ -1657,22 +1707,42 @@ ptlrpc_handle_rs (struct ptlrpc_reply_state *rs) LASSERT (rs->rs_difficult); LASSERT (rs->rs_scheduled); - LASSERT (list_empty(&rs->rs_list)); + LASSERT (cfs_list_empty(&rs->rs_list)); - spin_lock (&exp->exp_lock); + cfs_spin_lock (&exp->exp_lock); /* Noop if removed already */ - list_del_init (&rs->rs_exp_list); - spin_unlock (&exp->exp_lock); - - /* Avoid exp_uncommitted_replies_lock contention if we 100% sure that - * rs has been removed from the list already */ - if (!list_empty_careful(&rs->rs_obd_list)) { - spin_lock(&exp->exp_uncommitted_replies_lock); - list_del_init(&rs->rs_obd_list); - spin_unlock(&exp->exp_uncommitted_replies_lock); + cfs_list_del_init (&rs->rs_exp_list); + cfs_spin_unlock (&exp->exp_lock); + + /* The disk commit callback holds exp_uncommitted_replies_lock while it + * iterates over newly committed replies, removing them from + * exp_uncommitted_replies. It then drops this lock and schedules the + * replies it found for handling here. + * + * We can avoid contention for exp_uncommitted_replies_lock between the + * HRT threads and further commit callbacks by checking rs_committed + * which is set in the commit callback while it holds both + * rs_lock and exp_uncommitted_reples. + * + * If we see rs_committed clear, the commit callback _may_ not have + * handled this reply yet and we race with it to grab + * exp_uncommitted_replies_lock before removing the reply from + * exp_uncommitted_replies. Note that if we lose the race and the + * reply has already been removed, list_del_init() is a noop. + * + * If we see rs_committed set, we know the commit callback is handling, + * or has handled this reply since store reordering might allow us to + * see rs_committed set out of sequence. But since this is done + * holding rs_lock, we can be sure it has all completed once we hold + * rs_lock, which we do right next. + */ + if (!rs->rs_committed) { + cfs_spin_lock(&exp->exp_uncommitted_replies_lock); + cfs_list_del_init(&rs->rs_obd_list); + cfs_spin_unlock(&exp->exp_uncommitted_replies_lock); } - spin_lock(&rs->rs_lock); + cfs_spin_lock(&rs->rs_lock); been_handled = rs->rs_handled; rs->rs_handled = 1; @@ -1686,13 +1756,12 @@ ptlrpc_handle_rs (struct ptlrpc_reply_state *rs) CWARN("All locks stolen from rs %p x"LPD64".t"LPD64 " o%d NID %s\n", rs, - rs->rs_xid, rs->rs_transno, - lustre_msg_get_opc(rs->rs_msg), + rs->rs_xid, rs->rs_transno, rs->rs_opc, libcfs_nid2str(exp->exp_connection->c_peer.nid)); } if ((!been_handled && rs->rs_on_net) || nlocks > 0) { - spin_unlock(&rs->rs_lock); + cfs_spin_unlock(&rs->rs_lock); if (!been_handled && rs->rs_on_net) { LNetMDUnlink(rs->rs_md_h); @@ -1704,27 +1773,27 @@ ptlrpc_handle_rs (struct ptlrpc_reply_state *rs) ldlm_lock_decref(&rs->rs_locks[nlocks], rs->rs_modes[nlocks]); - spin_lock(&rs->rs_lock); + cfs_spin_lock(&rs->rs_lock); } rs->rs_scheduled = 0; if (!rs->rs_on_net) { /* Off the net */ - spin_unlock(&rs->rs_lock); + cfs_spin_unlock(&rs->rs_lock); class_export_put (exp); rs->rs_export = NULL; ptlrpc_rs_decref (rs); - atomic_dec (&svc->srv_outstanding_replies); - if (atomic_dec_and_test(&svc->srv_n_difficult_replies) && + cfs_atomic_dec (&svc->srv_outstanding_replies); + if (cfs_atomic_dec_and_test(&svc->srv_n_difficult_replies) && svc->srv_is_stopping) cfs_waitq_broadcast(&svc->srv_waitq); RETURN(1); } /* still on the net; callback will schedule */ - spin_unlock(&rs->rs_lock); + cfs_spin_unlock(&rs->rs_lock); RETURN(1); } @@ -1735,7 +1804,7 @@ ptlrpc_handle_rs (struct ptlrpc_reply_state *rs) * and process it. * * \param svc a ptlrpc service - * \retval 0 no replies processes + * \retval 0 no replies processed * \retval 1 one reply processed */ static int @@ -1744,14 +1813,14 @@ ptlrpc_server_handle_reply(struct ptlrpc_service *svc) struct ptlrpc_reply_state *rs = NULL; ENTRY; - spin_lock(&svc->srv_lock); - if (!list_empty(&svc->srv_reply_queue)) { - rs = list_entry(svc->srv_reply_queue.prev, - struct ptlrpc_reply_state, - rs_list); - list_del_init(&rs->rs_list); + cfs_spin_lock(&svc->srv_lock); + if (!cfs_list_empty(&svc->srv_reply_queue)) { + rs = cfs_list_entry(svc->srv_reply_queue.prev, + struct ptlrpc_reply_state, + rs_list); + cfs_list_del_init(&rs->rs_list); } - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); if (rs != NULL) ptlrpc_handle_rs(rs); RETURN(rs != NULL); @@ -1763,14 +1832,14 @@ liblustre_check_services (void *arg) { int did_something = 0; int rc; - struct list_head *tmp, *nxt; + cfs_list_t *tmp, *nxt; ENTRY; /* I'm relying on being single threaded, not to have to lock * ptlrpc_all_services etc */ - list_for_each_safe (tmp, nxt, &ptlrpc_all_services) { + cfs_list_for_each_safe (tmp, nxt, &ptlrpc_all_services) { struct ptlrpc_service *svc = - list_entry (tmp, struct ptlrpc_service, srv_list); + cfs_list_entry (tmp, struct ptlrpc_service, srv_list); if (svc->srv_threads_running != 0) /* I've recursed */ continue; @@ -1800,18 +1869,6 @@ liblustre_check_services (void *arg) #else /* __KERNEL__ */ -/* Don't use daemonize, it removes fs struct from new thread (bug 418) */ -void ptlrpc_daemonize(char *name) -{ - struct fs_struct *fs = current->fs; - - atomic_inc(&fs->count); - cfs_daemonize(name); - exit_fs(cfs_current()); - current->fs = fs; - ll_set_fs_pwd(current->fs, init_task.fs->pwdmnt, init_task.fs->pwd); -} - static void ptlrpc_check_rqbd_pool(struct ptlrpc_service *svc) { @@ -1843,6 +1900,85 @@ ptlrpc_retry_rqbds(void *arg) return (-ETIMEDOUT); } +/** + * Status bits to pass todo info from + * ptlrpc_main_check_event to ptlrpc_main. + */ +#define PTLRPC_MAIN_STOPPING 0x01 +#define PTLRPC_MAIN_IN_REQ 0x02 +#define PTLRPC_MAIN_ACTIVE_REQ 0x04 +#define PTLRPC_MAIN_CHECK_TIMED 0x08 +#define PTLRPC_MAIN_REPOST 0x10 + +/** + * A container to share per-thread status variables between + * ptlrpc_main_check_event and ptlrpc_main functions. + */ +struct ptlrpc_main_check_s { + /** todo info for the ptrlrpc_main */ + int todo; + /** is this thread counted as running or not? */ + int running; +}; + +/** + * Check whether current service thread has work to do. + */ +static int ptlrpc_main_check_event(struct ptlrpc_thread *t, + struct ptlrpc_main_check_s *status) +{ + struct ptlrpc_service *svc = t->t_svc; + ENTRY; + + status->todo = 0; + + /* check the stop flags w/o any locking to make all + * concurrently running threads stop faster. */ + if (unlikely((t->t_flags & SVC_STOPPING) || + svc->srv_is_stopping)) { + status->todo |= PTLRPC_MAIN_STOPPING; + goto out; + } + + cfs_spin_lock(&svc->srv_lock); + /* count this thread as not running before possible sleep in + * the outer wait event if it is not done yet. */ + if (status->running) { + LASSERT(svc->srv_threads_running > 0); + svc->srv_threads_running--; + status->running = 0; + } + /* Process all incoming reqs before handling any */ + if (!cfs_list_empty(&svc->srv_req_in_queue)) { + status->todo |= PTLRPC_MAIN_IN_REQ; + } + /* Don't handle regular requests in the last thread, in order + * to handle any incoming reqs, early replies, etc. */ + if (ptlrpc_server_request_pending(svc, 0) && + (svc->srv_threads_running < (svc->srv_threads_started - 1))) { + status->todo |= PTLRPC_MAIN_ACTIVE_REQ; + } + if (svc->srv_at_check) { + status->todo |= PTLRPC_MAIN_CHECK_TIMED; + } + if ((!cfs_list_empty(&svc->srv_idle_rqbds) && + svc->srv_rqbd_timeout == 0)) { + status->todo |= PTLRPC_MAIN_REPOST; + } + /* count this thread as active if it goes out the outer + * wait event */ + if (status->todo) { + svc->srv_threads_running++; + status->running = 1; + } + cfs_spin_unlock(&svc->srv_lock); + out: + RETURN(status->todo); +} + +/** + * Main prlrpc service thread routine. + */ static int ptlrpc_main(void *arg) { struct ptlrpc_svc_data *data = (struct ptlrpc_svc_data *)arg; @@ -1850,14 +1986,16 @@ static int ptlrpc_main(void *arg) struct ptlrpc_thread *thread = data->thread; struct obd_device *dev = data->dev; struct ptlrpc_reply_state *rs; + struct ptlrpc_main_check_s st; #ifdef WITH_GROUP_INFO - struct group_info *ginfo = NULL; + cfs_group_info_t *ginfo = NULL; #endif struct lu_env env; int counter = 0, rc = 0; ENTRY; - ptlrpc_daemonize(data->name); + thread->t_pid = cfs_curproc_pid(); + cfs_daemonize_ctxt(data->name); #if defined(HAVE_NODE_TO_CPUMASK) && defined(CONFIG_NUMA) /* we need to do this before any per-thread allocation is done so that @@ -1865,26 +2003,28 @@ static int ptlrpc_main(void *arg) if (svc->srv_cpu_affinity) { int cpu, num_cpu; - for (cpu = 0, num_cpu = 0; cpu < num_possible_cpus(); cpu++) { - if (!cpu_online(cpu)) + for (cpu = 0, num_cpu = 0; cpu < cfs_num_possible_cpus(); + cpu++) { + if (!cfs_cpu_online(cpu)) continue; - if (num_cpu == thread->t_id % num_online_cpus()) + if (num_cpu == thread->t_id % cfs_num_online_cpus()) break; num_cpu++; } - set_cpus_allowed(cfs_current(), node_to_cpumask(cpu_to_node(cpu))); + cfs_set_cpus_allowed(cfs_current(), + node_to_cpumask(cpu_to_node(cpu))); } #endif #ifdef WITH_GROUP_INFO - ginfo = groups_alloc(0); + ginfo = cfs_groups_alloc(0); if (!ginfo) { rc = -ENOMEM; goto out; } - set_current_groups(ginfo); - put_group_info(ginfo); + cfs_set_current_groups(ginfo); + cfs_put_group_info(ginfo); #endif if (svc->srv_init != NULL) { @@ -1909,20 +2049,25 @@ static int ptlrpc_main(void *arg) goto out_srv_fini; } - /* Record that the thread is running */ - thread->t_flags = SVC_RUNNING; + cfs_spin_lock(&svc->srv_lock); + /* SVC_STOPPING may already be set here if someone else is trying + * to stop the service while this new thread has been dynamically + * forked. We still set SVC_RUNNING to let our creator know that + * we are now running, however we will exit as soon as possible */ + thread->t_flags |= SVC_RUNNING; + cfs_spin_unlock(&svc->srv_lock); + /* * wake up our creator. Note: @data is invalid after this point, * because it's allocated on ptlrpc_start_thread() stack. */ cfs_waitq_signal(&thread->t_ctl_waitq); - thread->t_watchdog = lc_watchdog_add(GET_TIMEOUT(svc), NULL, NULL); + thread->t_watchdog = lc_watchdog_add(CFS_GET_TIMEOUT(svc), NULL, NULL); - spin_lock(&svc->srv_lock); - svc->srv_threads_running++; - list_add(&rs->rs_list, &svc->srv_free_rs_list); - spin_unlock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); + cfs_list_add(&rs->rs_list, &svc->srv_free_rs_list); + cfs_spin_unlock(&svc->srv_lock); cfs_waitq_signal(&svc->srv_free_rs_waitq); CDEBUG(D_NET, "service thread %d (#%d) started\n", thread->t_id, @@ -1930,61 +2075,51 @@ static int ptlrpc_main(void *arg) /* XXX maintain a list of all managed devices: insert here */ - while ((thread->t_flags & SVC_STOPPING) == 0) { + st.running = 0; + st.todo = 0; + + while (!(st.todo & PTLRPC_MAIN_STOPPING)) { /* Don't exit while there are replies to be handled */ struct l_wait_info lwi = LWI_TIMEOUT(svc->srv_rqbd_timeout, ptlrpc_retry_rqbds, svc); lc_watchdog_disable(thread->t_watchdog); - cond_resched(); + cfs_cond_resched(); l_wait_event_exclusive (svc->srv_waitq, - ((thread->t_flags & SVC_STOPPING) != 0) || - (!list_empty(&svc->srv_idle_rqbds) && - svc->srv_rqbd_timeout == 0) || - !list_empty(&svc->srv_req_in_queue) || - (ptlrpc_server_request_pending(svc, 0) && - (svc->srv_n_active_reqs < - (svc->srv_threads_running - 1))) || - svc->srv_at_check, - &lwi); - - lc_watchdog_touch(thread->t_watchdog, GET_TIMEOUT(svc)); + ptlrpc_main_check_event(thread, &st), + &lwi); + + lc_watchdog_touch(thread->t_watchdog, CFS_GET_TIMEOUT(svc)); ptlrpc_check_rqbd_pool(svc); - if ((svc->srv_threads_started < svc->srv_threads_max) && - (svc->srv_n_active_reqs >= (svc->srv_threads_started - 1))){ + if (svc->srv_threads_started < svc->srv_threads_max && + svc->srv_n_active_reqs >= (svc->srv_threads_started - 1)) /* Ignore return code - we tried... */ ptlrpc_start_thread(dev, svc); - } - if (!list_empty(&svc->srv_req_in_queue)) { - /* Process all incoming reqs before handling any */ + if (st.todo & PTLRPC_MAIN_IN_REQ) { ptlrpc_server_handle_req_in(svc); /* but limit ourselves in case of flood */ if (counter++ < 1000) continue; counter = 0; } - - if (svc->srv_at_check) + if (st.todo & PTLRPC_MAIN_CHECK_TIMED) { ptlrpc_at_check_timed(svc); - - /* don't handle requests in the last thread */ - if (ptlrpc_server_request_pending(svc, 0) && - (svc->srv_n_active_reqs < (svc->srv_threads_running - 1))) { + } + if (st.todo & PTLRPC_MAIN_ACTIVE_REQ) { lu_context_enter(&env.le_ctx); ptlrpc_server_handle_request(svc, thread); lu_context_exit(&env.le_ctx); } - - if (!list_empty(&svc->srv_idle_rqbds) && + if ((st.todo & PTLRPC_MAIN_REPOST) && ptlrpc_server_post_idle_rqbds(svc) < 0) { - /* I just failed to repost request buffers. Wait - * for a timeout (unless something else happens) - * before I try again */ + /* I just failed to repost request buffers. + * Wait for a timeout (unless something else + * happens) before I try again */ svc->srv_rqbd_timeout = cfs_time_seconds(1)/10; CDEBUG(D_RPCTRACE,"Posted buffers: %d\n", svc->srv_nrqbd_receiving); @@ -2003,15 +2138,16 @@ out_srv_fini: lu_context_fini(&env.le_ctx); out: - CDEBUG(D_NET, "service thread %d exiting: rc %d\n", thread->t_id, rc); + CDEBUG(D_RPCTRACE, "service thread [ %p : %u ] %d exiting: rc %d\n", + thread, thread->t_pid, thread->t_id, rc); - spin_lock(&svc->srv_lock); - svc->srv_threads_running--; /* must know immediately */ + cfs_spin_lock(&svc->srv_lock); + if (st.running) + svc->srv_threads_running--; thread->t_id = rc; thread->t_flags = SVC_STOPPED; - cfs_waitq_signal(&thread->t_ctl_waitq); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); return rc; } @@ -2023,15 +2159,15 @@ struct ptlrpc_hr_args { }; static int hrt_dont_sleep(struct ptlrpc_hr_thread *t, - struct list_head *replies) + cfs_list_t *replies) { int result; - spin_lock(&t->hrt_lock); - list_splice_init(&t->hrt_queue, replies); - result = test_bit(HRT_STOPPING, &t->hrt_flags) || - !list_empty(replies); - spin_unlock(&t->hrt_lock); + cfs_spin_lock(&t->hrt_lock); + cfs_list_splice_init(&t->hrt_queue, replies); + result = cfs_test_bit(HRT_STOPPING, &t->hrt_flags) || + !cfs_list_empty(replies); + cfs_spin_unlock(&t->hrt_lock); return result; } @@ -2046,30 +2182,30 @@ static int ptlrpc_hr_main(void *arg) snprintf(threadname, sizeof(threadname), "ptlrpc_hr_%d", hr_args->thread_index); - ptlrpc_daemonize(threadname); -#if defined(HAVE_NODE_TO_CPUMASK) - set_cpus_allowed(cfs_current(), - node_to_cpumask(cpu_to_node(hr_args->cpu_index))); + cfs_daemonize_ctxt(threadname); +#if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK) + cfs_set_cpus_allowed(cfs_current(), + node_to_cpumask(cpu_to_node(hr_args->cpu_index))); #endif - set_bit(HRT_RUNNING, &t->hrt_flags); + cfs_set_bit(HRT_RUNNING, &t->hrt_flags); cfs_waitq_signal(&t->hrt_wait); - while (!test_bit(HRT_STOPPING, &t->hrt_flags)) { + while (!cfs_test_bit(HRT_STOPPING, &t->hrt_flags)) { - cfs_wait_event(t->hrt_wait, hrt_dont_sleep(t, &replies)); - while (!list_empty(&replies)) { + l_cfs_wait_event(t->hrt_wait, hrt_dont_sleep(t, &replies)); + while (!cfs_list_empty(&replies)) { struct ptlrpc_reply_state *rs; - rs = list_entry(replies.prev, - struct ptlrpc_reply_state, - rs_list); - list_del_init(&rs->rs_list); + rs = cfs_list_entry(replies.prev, + struct ptlrpc_reply_state, + rs_list); + cfs_list_del_init(&rs->rs_list); ptlrpc_handle_rs(rs); } } - clear_bit(HRT_RUNNING, &t->hrt_flags); - complete(&t->hrt_completion); + cfs_clear_bit(HRT_RUNNING, &t->hrt_flags); + cfs_complete(&t->hrt_completion); return 0; } @@ -2088,10 +2224,10 @@ static int ptlrpc_start_hr_thread(struct ptlrpc_hr_service *hr, int n, int cpu) rc = cfs_kernel_thread(ptlrpc_hr_main, (void*)&args, CLONE_VM|CLONE_FILES); if (rc < 0) { - complete(&t->hrt_completion); + cfs_complete(&t->hrt_completion); GOTO(out, rc); } - cfs_wait_event(t->hrt_wait, test_bit(HRT_RUNNING, &t->hrt_flags)); + l_cfs_wait_event(t->hrt_wait, cfs_test_bit(HRT_RUNNING, &t->hrt_flags)); RETURN(0); out: return rc; @@ -2101,9 +2237,9 @@ static void ptlrpc_stop_hr_thread(struct ptlrpc_hr_thread *t) { ENTRY; - set_bit(HRT_STOPPING, &t->hrt_flags); + cfs_set_bit(HRT_STOPPING, &t->hrt_flags); cfs_waitq_signal(&t->hrt_wait); - wait_for_completion(&t->hrt_completion); + cfs_wait_for_completion(&t->hrt_completion); EXIT; } @@ -2129,10 +2265,10 @@ static int ptlrpc_start_hr_threads(struct ptlrpc_hr_service *hr) LASSERT(hr->hr_n_threads > 0); for (n = 0, cpu = 0; n < hr->hr_n_threads; n++) { -#if defined(HAVE_NODE_TO_CPUMASK) - while(!cpu_online(cpu)) { +#if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK) + while(!cfs_cpu_online(cpu)) { cpu++; - if (cpu >= num_possible_cpus()) + if (cpu >= cfs_num_possible_cpus()) cpu = 0; } #endif @@ -2160,18 +2296,21 @@ static void ptlrpc_stop_thread(struct ptlrpc_service *svc, struct l_wait_info lwi = { 0 }; ENTRY; - CDEBUG(D_RPCTRACE, "Stopping thread %p\n", thread); - spin_lock(&svc->srv_lock); - thread->t_flags = SVC_STOPPING; - spin_unlock(&svc->srv_lock); + CDEBUG(D_RPCTRACE, "Stopping thread [ %p : %u ]\n", + thread, thread->t_pid); + + cfs_spin_lock(&svc->srv_lock); + /* let the thread know that we would like it to stop asap */ + thread->t_flags |= SVC_STOPPING; + cfs_spin_unlock(&svc->srv_lock); cfs_waitq_broadcast(&svc->srv_waitq); - l_wait_event(thread->t_ctl_waitq, (thread->t_flags & SVC_STOPPED), - &lwi); + l_wait_event(thread->t_ctl_waitq, + (thread->t_flags & SVC_STOPPED), &lwi); - spin_lock(&svc->srv_lock); - list_del(&thread->t_link); - spin_unlock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); + cfs_list_del(&thread->t_link); + cfs_spin_unlock(&svc->srv_lock); OBD_FREE_PTR(thread); EXIT; @@ -2182,17 +2321,17 @@ void ptlrpc_stop_all_threads(struct ptlrpc_service *svc) struct ptlrpc_thread *thread; ENTRY; - spin_lock(&svc->srv_lock); - while (!list_empty(&svc->srv_threads)) { - thread = list_entry(svc->srv_threads.next, - struct ptlrpc_thread, t_link); + cfs_spin_lock(&svc->srv_lock); + while (!cfs_list_empty(&svc->srv_threads)) { + thread = cfs_list_entry(svc->srv_threads.next, + struct ptlrpc_thread, t_link); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); ptlrpc_stop_thread(svc, thread); - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); } - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); EXIT; } @@ -2213,6 +2352,7 @@ int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc) CERROR("cannot start %s thread #%d: rc %d\n", svc->srv_thread_name, i, rc); ptlrpc_stop_all_threads(svc); + break; } } RETURN(rc); @@ -2230,6 +2370,10 @@ int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc) CDEBUG(D_RPCTRACE, "%s started %d min %d max %d running %d\n", svc->srv_name, svc->srv_threads_started, svc->srv_threads_min, svc->srv_threads_max, svc->srv_threads_running); + + if (unlikely(svc->srv_is_stopping)) + RETURN(-ESRCH); + if (unlikely(svc->srv_threads_started >= svc->srv_threads_max) || (OBD_FAIL_CHECK(OBD_FAIL_TGT_TOOMANY_THREADS) && svc->srv_threads_started == svc->srv_threads_min - 1)) @@ -2240,15 +2384,15 @@ int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc) RETURN(-ENOMEM); cfs_waitq_init(&thread->t_ctl_waitq); - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); if (svc->srv_threads_started >= svc->srv_threads_max) { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); OBD_FREE_PTR(thread); RETURN(-EMFILE); } - list_add(&thread->t_link, &svc->srv_threads); + cfs_list_add(&thread->t_link, &svc->srv_threads); id = svc->srv_threads_started++; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); thread->t_svc = svc; thread->t_id = id; @@ -2260,17 +2404,17 @@ int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc) CDEBUG(D_RPCTRACE, "starting thread '%s'\n", name); - /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we - * just drop the VM and FILES in ptlrpc_daemonize() right away. + /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we + * just drop the VM and FILES in cfs_daemonize_ctxt() right away. */ rc = cfs_kernel_thread(ptlrpc_main, &d, CLONE_VM | CLONE_FILES); if (rc < 0) { CERROR("cannot start thread '%s': rc %d\n", name, rc); - spin_lock(&svc->srv_lock); - list_del(&thread->t_link); + cfs_spin_lock(&svc->srv_lock); + cfs_list_del(&thread->t_link); --svc->srv_threads_started; - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); OBD_FREE(thread, sizeof(*thread)); RETURN(rc); @@ -2286,9 +2430,10 @@ int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc) int ptlrpc_hr_init(void) { int i; - int n_cpus = num_online_cpus(); + int n_cpus = cfs_num_online_cpus(); struct ptlrpc_hr_service *hr; int size; + int rc; ENTRY; LASSERT(ptlrpc_hr == NULL); @@ -2300,16 +2445,21 @@ int ptlrpc_hr_init(void) for (i = 0; i < n_cpus; i++) { struct ptlrpc_hr_thread *t = &hr->hr_threads[i]; - spin_lock_init(&t->hrt_lock); + cfs_spin_lock_init(&t->hrt_lock); cfs_waitq_init(&t->hrt_wait); CFS_INIT_LIST_HEAD(&t->hrt_queue); - init_completion(&t->hrt_completion); + cfs_init_completion(&t->hrt_completion); } hr->hr_n_threads = n_cpus; hr->hr_size = size; ptlrpc_hr = hr; - RETURN(ptlrpc_start_hr_threads(hr)); + rc = ptlrpc_start_hr_threads(hr); + if (rc) { + OBD_FREE(hr, hr->hr_size); + ptlrpc_hr = NULL; + } + RETURN(rc); } void ptlrpc_hr_fini(void) @@ -2332,8 +2482,8 @@ static void ptlrpc_wait_replies(struct ptlrpc_service *svc) int rc; struct l_wait_info lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL); - rc = l_wait_event(svc->srv_waitq, - atomic_read(&svc->srv_n_difficult_replies) == 0, + rc = l_wait_event(svc->srv_waitq, cfs_atomic_read(&svc-> \ + srv_n_difficult_replies) == 0, &lwi); if (rc == 0) break; @@ -2345,7 +2495,7 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) { int rc; struct l_wait_info lwi; - struct list_head *tmp; + cfs_list_t *tmp; struct ptlrpc_reply_state *rs, *t; struct ptlrpc_at_array *array = &service->srv_at_array; ENTRY; @@ -2354,11 +2504,11 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) cfs_timer_disarm(&service->srv_at_timer); ptlrpc_stop_all_threads(service); - LASSERT(list_empty(&service->srv_threads)); + LASSERT(cfs_list_empty(&service->srv_threads)); - spin_lock (&ptlrpc_all_services_lock); - list_del_init (&service->srv_list); - spin_unlock (&ptlrpc_all_services_lock); + cfs_spin_lock (&ptlrpc_all_services_lock); + cfs_list_del_init (&service->srv_list); + cfs_spin_unlock (&ptlrpc_all_services_lock); ptlrpc_lprocfs_unregister_service(service); @@ -2373,10 +2523,10 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) /* Unlink all the request buffers. This forces a 'final' event with * its 'unlink' flag set for each posted rqbd */ - list_for_each(tmp, &service->srv_active_rqbds) { + cfs_list_for_each(tmp, &service->srv_active_rqbds) { struct ptlrpc_request_buffer_desc *rqbd = - list_entry(tmp, struct ptlrpc_request_buffer_desc, - rqbd_list); + cfs_list_entry(tmp, struct ptlrpc_request_buffer_desc, + rqbd_list); rc = LNetMDUnlink(rqbd->rqbd_md_h); LASSERT (rc == 0 || rc == -ENOENT); @@ -2385,9 +2535,9 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) /* Wait for the network to release any buffers it's currently * filling */ for (;;) { - spin_lock(&service->srv_lock); + cfs_spin_lock(&service->srv_lock); rc = service->srv_nrqbd_receiving; - spin_unlock(&service->srv_lock); + cfs_spin_unlock(&service->srv_lock); if (rc == 0) break; @@ -2405,27 +2555,27 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) } /* schedule all outstanding replies to terminate them */ - spin_lock(&service->srv_lock); - while (!list_empty(&service->srv_active_replies)) { + cfs_spin_lock(&service->srv_lock); + while (!cfs_list_empty(&service->srv_active_replies)) { struct ptlrpc_reply_state *rs = - list_entry(service->srv_active_replies.next, - struct ptlrpc_reply_state, rs_list); - spin_lock(&rs->rs_lock); + cfs_list_entry(service->srv_active_replies.next, + struct ptlrpc_reply_state, rs_list); + cfs_spin_lock(&rs->rs_lock); ptlrpc_schedule_difficult_reply(rs); - spin_unlock(&rs->rs_lock); + cfs_spin_unlock(&rs->rs_lock); } - spin_unlock(&service->srv_lock); + cfs_spin_unlock(&service->srv_lock); /* purge the request queue. NB No new replies (rqbds all unlinked) * and no service threads, so I'm the only thread noodling the * request queue now */ - while (!list_empty(&service->srv_req_in_queue)) { + while (!cfs_list_empty(&service->srv_req_in_queue)) { struct ptlrpc_request *req = - list_entry(service->srv_req_in_queue.next, - struct ptlrpc_request, - rq_list); + cfs_list_entry(service->srv_req_in_queue.next, + struct ptlrpc_request, + rq_list); - list_del(&req->rq_list); + cfs_list_del(&req->rq_list); service->srv_n_queued_reqs--; service->srv_n_active_reqs++; ptlrpc_server_finish_request(req); @@ -2433,8 +2583,8 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) while (ptlrpc_server_request_pending(service, 1)) { struct ptlrpc_request *req; - req = ptlrpc_server_request_get(service, 1); - list_del(&req->rq_list); + req = ptlrpc_server_request_get(service); + cfs_list_del(&req->rq_list); service->srv_n_queued_reqs--; service->srv_n_active_reqs++; ptlrpc_hpreq_fini(req); @@ -2443,23 +2593,24 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) LASSERT(service->srv_n_queued_reqs == 0); LASSERT(service->srv_n_active_reqs == 0); LASSERT(service->srv_n_history_rqbds == 0); - LASSERT(list_empty(&service->srv_active_rqbds)); + LASSERT(cfs_list_empty(&service->srv_active_rqbds)); /* Now free all the request buffers since nothing references them * any more... */ - while (!list_empty(&service->srv_idle_rqbds)) { + while (!cfs_list_empty(&service->srv_idle_rqbds)) { struct ptlrpc_request_buffer_desc *rqbd = - list_entry(service->srv_idle_rqbds.next, - struct ptlrpc_request_buffer_desc, - rqbd_list); + cfs_list_entry(service->srv_idle_rqbds.next, + struct ptlrpc_request_buffer_desc, + rqbd_list); ptlrpc_free_rqbd(rqbd); } ptlrpc_wait_replies(service); - list_for_each_entry_safe(rs, t, &service->srv_free_rs_list, rs_list) { - list_del(&rs->rs_list); + cfs_list_for_each_entry_safe(rs, t, &service->srv_free_rs_list, + rs_list) { + cfs_list_del(&rs->rs_list); OBD_FREE(rs, service->srv_max_reply_size); } @@ -2468,7 +2619,7 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service) if (array->paa_reqs_array != NULL) { OBD_FREE(array->paa_reqs_array, - sizeof(struct list_head) * array->paa_size); + sizeof(cfs_list_t) * array->paa_size); array->paa_reqs_array = NULL; } @@ -2496,23 +2647,23 @@ int ptlrpc_service_health_check(struct ptlrpc_service *svc) if (svc == NULL) return 0; - do_gettimeofday(&right_now); + cfs_gettimeofday(&right_now); - spin_lock(&svc->srv_lock); + cfs_spin_lock(&svc->srv_lock); if (!ptlrpc_server_request_pending(svc, 1)) { - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); return 0; } /* How long has the next entry been waiting? */ - if (list_empty(&svc->srv_request_queue)) - request = list_entry(svc->srv_request_hpq.next, - struct ptlrpc_request, rq_list); + if (cfs_list_empty(&svc->srv_request_queue)) + request = cfs_list_entry(svc->srv_request_hpq.next, + struct ptlrpc_request, rq_list); else - request = list_entry(svc->srv_request_queue.next, - struct ptlrpc_request, rq_list); + request = cfs_list_entry(svc->srv_request_queue.next, + struct ptlrpc_request, rq_list); timediff = cfs_timeval_sub(&right_now, &request->rq_arrival_time, NULL); - spin_unlock(&svc->srv_lock); + cfs_spin_unlock(&svc->srv_lock); if ((timediff / ONE_MILLION) > (AT_OFF ? obd_timeout * 3/2 : at_max)) {