- * Prepare request (fetched from pool \a poolif not NULL) on import \a imp
- * for operation \a opcode. Request would contain \a count buffers.
- * Sizes of buffers are described in array \a lengths and buffers themselves
- * are provided by a pointer \a bufs.
- * Returns prepared request structure pointer or NULL on error.
- */
-struct ptlrpc_request *
-ptlrpc_prep_req_pool(struct obd_import *imp,
- __u32 version, int opcode,
- int count, __u32 *lengths, char **bufs,
- struct ptlrpc_request_pool *pool)
-{
- struct ptlrpc_request *request;
- int rc;
-
- request = __ptlrpc_request_alloc(imp, pool);
- if (!request)
- return NULL;
-
- rc = __ptlrpc_request_bufs_pack(request, version, opcode, count,
- lengths, bufs, NULL);
- if (rc) {
- ptlrpc_request_free(request);
- request = NULL;
- }
- return request;
-}
-
-/**
- * Same as ptlrpc_prep_req_pool, but without pool
- */
-struct ptlrpc_request *
-ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode, int count,
- __u32 *lengths, char **bufs)
-{
- return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, bufs,
- NULL);
-}
-
-/**
- * Allocate "fake" request that would not be sent anywhere in the end.
- * Only used as a hack because we have no other way of performing
- * async actions in lustre between layers.
- * Used on MDS to request object preallocations from more than one OST at a
- * time.
- */
-struct ptlrpc_request *ptlrpc_prep_fakereq(struct obd_import *imp,
- unsigned int timeout,
- ptlrpc_interpterer_t interpreter)
-{
- struct ptlrpc_request *request = NULL;
- ENTRY;
-
- OBD_ALLOC(request, sizeof(*request));
- if (!request) {
- CERROR("request allocation out of memory\n");
- RETURN(NULL);
- }
-
- request->rq_send_state = LUSTRE_IMP_FULL;
- request->rq_type = PTL_RPC_MSG_REQUEST;
- request->rq_import = class_import_get(imp);
- request->rq_export = NULL;
- request->rq_import_generation = imp->imp_generation;
-
- request->rq_timeout = timeout;
- request->rq_sent = cfs_time_current_sec();
- request->rq_deadline = request->rq_sent + timeout;
- request->rq_reply_deadline = request->rq_deadline;
- request->rq_interpret_reply = interpreter;
- request->rq_phase = RQ_PHASE_RPC;
- request->rq_next_phase = RQ_PHASE_INTERPRET;
- /* don't want reply */
- request->rq_receiving_reply = 0;
- request->rq_must_unlink = 0;
- request->rq_no_delay = request->rq_no_resend = 1;
- request->rq_fake = 1;
-
- cfs_spin_lock_init(&request->rq_lock);
- CFS_INIT_LIST_HEAD(&request->rq_list);
- CFS_INIT_LIST_HEAD(&request->rq_replay_list);
- CFS_INIT_LIST_HEAD(&request->rq_set_chain);
- CFS_INIT_LIST_HEAD(&request->rq_history_list);
- CFS_INIT_LIST_HEAD(&request->rq_exp_list);
- cfs_waitq_init(&request->rq_reply_waitq);
- cfs_waitq_init(&request->rq_set_waitq);
-
- request->rq_xid = ptlrpc_next_xid();
- cfs_atomic_set(&request->rq_refcount, 1);
-
- RETURN(request);
-}
-
-/**
- * Indicate that processing of "fake" request is finished.
- */
-void ptlrpc_fakereq_finished(struct ptlrpc_request *req)
-{
- struct ptlrpc_request_set *set = req->rq_set;
- int wakeup = 0;
-
- /* hold ref on the request to prevent others (ptlrpcd) to free it */
- ptlrpc_request_addref(req);
- cfs_list_del_init(&req->rq_list);
-
- /* if we kill request before timeout - need adjust counter */
- if (req->rq_phase == RQ_PHASE_RPC && set != NULL &&
- cfs_atomic_dec_and_test(&set->set_remaining))
- wakeup = 1;
-
- ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
-
- /* Only need to call wakeup once when to be empty. */
- if (wakeup)
- cfs_waitq_signal(&set->set_waitq);
- ptlrpc_req_finished(req);
-}
-
-/**
- * Allocate and initialize new request set structure.