#include <lustre_lib.h>
#include <lustre_ha.h>
#include <lustre_import.h>
+#include <lustre_req_layout.h>
#include "ptlrpc_internal.h"
return desc;
}
-struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp (struct ptlrpc_request *req,
- int npages, int type, int portal)
+struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
+ int npages, int type, int portal)
{
struct obd_export *exp = req->rq_export;
struct ptlrpc_bulk_desc *desc;
spin_unlock(&pool->prp_lock);
}
-struct ptlrpc_request *
-ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version, int opcode,
- int count, int *lengths, char **bufs,
- struct ptlrpc_request_pool *pool,
- struct ptlrpc_cli_ctx *ctx)
+static int __ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
+ __u32 version, int opcode,
+ int count, int *lengths, char **bufs,
+ struct ptlrpc_cli_ctx *ctx)
{
- struct ptlrpc_request *request = NULL;
- int rc;
+ struct obd_import *imp = request->rq_import;
+ int rc;
ENTRY;
- /* The obd disconnected */
- if (imp == NULL)
- return NULL;
-
- LASSERT(imp != LP_POISON);
- LASSERT((unsigned long)imp->imp_client > 0x1000);
- LASSERT(imp->imp_client != LP_POISON);
-
- if (pool)
- request = ptlrpc_prep_req_from_pool(pool);
-
- if (!request)
- OBD_ALLOC(request, sizeof(*request));
-
- if (!request) {
- CERROR("request allocation out of memory\n");
- RETURN(NULL);
- }
-
- request->rq_import = class_import_get(imp);
-
if (unlikely(ctx))
request->rq_cli_ctx = sptlrpc_cli_ctx_get(ctx);
else {
sptlrpc_req_set_flavor(request, opcode);
- rc = lustre_pack_request(request, imp->imp_msg_magic, count, lengths,
- bufs);
+ rc = lustre_pack_request(request, imp->imp_msg_magic, count,
+ lengths, bufs);
if (rc) {
LASSERT(!request->rq_pool);
GOTO(out_ctx, rc);
CFS_INIT_LIST_HEAD(&request->rq_mod_list);
CFS_INIT_LIST_HEAD(&request->rq_ctx_chain);
CFS_INIT_LIST_HEAD(&request->rq_set_chain);
+ CFS_INIT_LIST_HEAD(&request->rq_history_list);
cfs_waitq_init(&request->rq_reply_waitq);
request->rq_xid = ptlrpc_next_xid();
atomic_set(&request->rq_refcount, 1);
lustre_msg_set_opc(request->rq_reqmsg, opcode);
lustre_msg_set_flags(request->rq_reqmsg, 0);
- RETURN(request);
+ RETURN(0);
out_ctx:
sptlrpc_cli_ctx_put(request->rq_cli_ctx, 1);
out_free:
class_import_put(imp);
+ return rc;
+}
+
+int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
+ __u32 version, int opcode, char **bufs,
+ struct ptlrpc_cli_ctx *ctx)
+{
+ int count;
+
+ count = req_capsule_filled_sizes(&request->rq_pill, RCL_CLIENT);
+ return __ptlrpc_request_bufs_pack(request, version, opcode, count,
+ request->rq_pill.rc_area[RCL_CLIENT],
+ bufs, ctx);
+}
+EXPORT_SYMBOL(ptlrpc_request_bufs_pack);
+
+int ptlrpc_request_pack(struct ptlrpc_request *request,
+ __u32 version, int opcode)
+{
+ return ptlrpc_request_bufs_pack(request, version, opcode, NULL, NULL);
+}
+
+static inline
+struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp,
+ struct ptlrpc_request_pool *pool)
+{
+ struct ptlrpc_request *request = NULL;
+
+ if (pool)
+ request = ptlrpc_prep_req_from_pool(pool);
+
+ if (!request)
+ OBD_ALLOC_PTR(request);
+
+ if (request) {
+ LASSERT((unsigned long)imp > 0x1000);
+ LASSERT(imp != LP_POISON);
+ LASSERT((unsigned long)imp->imp_client > 0x1000);
+ LASSERT(imp->imp_client != LP_POISON);
+
+ request->rq_import = class_import_get(imp);
+ } else {
+ CERROR("request allocation out of memory\n");
+ }
+
+ return request;
+}
+
+static struct ptlrpc_request *
+ptlrpc_request_alloc_internal(struct obd_import *imp,
+ struct ptlrpc_request_pool * pool,
+ const struct req_format *format)
+{
+ struct ptlrpc_request *request;
+
+ request = __ptlrpc_request_alloc(imp, pool);
+ if (request == NULL)
+ return NULL;
+
+ req_capsule_init(&request->rq_pill, request, RCL_CLIENT);
+ req_capsule_set(&request->rq_pill, format);
+ return request;
+}
+
+struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
+ const struct req_format *format)
+{
+ return ptlrpc_request_alloc_internal(imp, NULL, format);
+}
+
+struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
+ struct ptlrpc_request_pool * pool,
+ const struct req_format *format)
+{
+ return ptlrpc_request_alloc_internal(imp, pool, format);
+}
+
+void ptlrpc_request_free(struct ptlrpc_request *request)
+{
if (request->rq_pool)
__ptlrpc_free_req_to_pool(request);
else
- OBD_FREE(request, sizeof(*request));
- return NULL;
+ OBD_FREE_PTR(request);
+}
+
+struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
+ const struct req_format *format,
+ __u32 version, int opcode)
+{
+ struct ptlrpc_request *req = ptlrpc_request_alloc(imp, format);
+ int rc;
+
+ if (req) {
+ rc = ptlrpc_request_pack(req, version, opcode);
+ if (rc) {
+ ptlrpc_request_free(req);
+ req = NULL;
+ }
+ }
+ return req;
+}
+
+struct ptlrpc_request *
+ptlrpc_prep_req_pool(struct obd_import *imp,
+ __u32 version, int opcode,
+ int count, int *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;
}
struct ptlrpc_request *
int *lengths, char **bufs)
{
return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, bufs,
- NULL, NULL);
+ NULL);
}
struct ptlrpc_request_set *ptlrpc_prep_set(void)
set->set_remaining = 0;
spin_lock_init(&set->set_new_req_lock);
CFS_INIT_LIST_HEAD(&set->set_new_requests);
-
+ CFS_INIT_LIST_HEAD(&set->set_cblist);
+
RETURN(set);
}
EXIT;
}
+int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
+ set_interpreter_func fn, void *data)
+{
+ struct ptlrpc_set_cbdata *cbdata;
+
+ OBD_ALLOC_PTR(cbdata);
+ if (cbdata == NULL)
+ RETURN(-ENOMEM);
+
+ cbdata->psc_interpret = fn;
+ cbdata->psc_data = data;
+ list_add_tail(&cbdata->psc_item, &set->set_cblist);
+
+ RETURN(0);
+}
+
void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
struct ptlrpc_request *req)
{
DEBUG_REQ(D_ERROR, req, "IMP_CLOSED ");
*status = -EIO;
} else if (req->rq_send_state == LUSTRE_IMP_CONNECTING &&
- imp->imp_state == LUSTRE_IMP_CONNECTING) {
+ imp->imp_state == LUSTRE_IMP_CONNECTING) {
/* allow CONNECT even if import is invalid */ ;
- } else if (imp->imp_invalid) {
+ if (atomic_read(&imp->imp_inval_count) != 0) {
+ DEBUG_REQ(D_ERROR, req, "invalidate in flight");
+ *status = -EIO;
+ }
+
+ } else if ((imp->imp_invalid && (!imp->imp_recon_bk)) ||
+ imp->imp_obd->obd_no_recov) {
/* If the import has been invalidated (such as by an OST
- * failure) the request must fail with -ESHUTDOWN. This
- * indicates the requests should be discarded; an -EIO
+ * failure), and if the import(MGC) tried all of its connection
+ * list (Bug 13464), the request must fail with -ESHUTDOWN.
+ * This indicates the requests should be discarded; an -EIO
* may result in a resend of the request. */
if (!imp->imp_deactive)
- DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
+ DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
*status = -ESHUTDOWN; /* bz 12940 */
} else if (req->rq_import_generation != imp->imp_generation) {
DEBUG_REQ(D_ERROR, req, "req wrong generation:");
*status = -EIO;
} else if (req->rq_send_state != imp->imp_state) {
- if (imp->imp_obd->obd_no_recov || imp->imp_dlm_fake ||
- req->rq_no_delay)
+ /* invalidate in progress - any requests should be drop */
+ if (atomic_read(&imp->imp_inval_count) != 0) {
+ DEBUG_REQ(D_ERROR, req, "invalidate in flight");
+ *status = -EIO;
+ } else if (imp->imp_dlm_fake || req->rq_no_delay) {
*status = -EWOULDBLOCK;
- else
+ } else {
delay = 1;
+ }
}
RETURN(delay);
static int after_reply(struct ptlrpc_request *req)
{
struct obd_import *imp = req->rq_import;
+ struct obd_device *obd = req->rq_import->imp_obd;
int rc;
+ struct timeval work_start;
+ long timediff;
ENTRY;
LASSERT(!req->rq_receiving_reply);
+ LASSERT(obd);
LASSERT(req->rq_nob_received <= req->rq_repbuf_len);
/* NB Until this point, the whole of the incoming message,
RETURN(-EPROTO);
}
+ do_gettimeofday(&work_start);
+ timediff = cfs_timeval_sub(&work_start, &req->rq_arrival_time, NULL);
+ if (obd->obd_svc_stats != NULL)
+ lprocfs_counter_add(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR,
+ timediff);
+
if (lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_REPLY &&
lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_ERR) {
DEBUG_REQ(D_ERROR, req, "invalid packet received (type=%u)",
ENTRY;
LASSERT(req->rq_phase == RQ_PHASE_NEW);
- if (req->rq_sent && (req->rq_sent > CURRENT_SECONDS))
+ if (req->rq_sent && (req->rq_sent > cfs_time_current_sec()))
RETURN (0);
req->rq_phase = RQ_PHASE_RPC;
RETURN(1);
} else {
/* here begins timeout counting */
- req->rq_sent = CURRENT_SECONDS;
+ req->rq_sent = cfs_time_current_sec();
req->rq_wait_ctx = 1;
RETURN(0);
}
}
if (!req->rq_wait_ctx) {
/* begins timeout counting */
- req->rq_sent = CURRENT_SECONDS;
+ req->rq_sent = cfs_time_current_sec();
req->rq_wait_ctx = 1;
}
continue;
if (req->rq_bulk != NULL)
ptlrpc_unregister_bulk (req);
- req->rq_phase = RQ_PHASE_COMPLETE;
-
if (req->rq_interpret_reply != NULL) {
int (*interpreter)(struct ptlrpc_request *,void *,int) =
req->rq_interpret_reply;
req->rq_status = interpreter(req, &req->rq_async_args,
req->rq_status);
}
+ req->rq_phase = RQ_PHASE_COMPLETE;
CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:nid:"
"opc %s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(),
libcfs_nid2str(imp->imp_connection->c_peer.nid),
lustre_msg_get_opc(req->rq_reqmsg));
- set->set_remaining--;
-
atomic_dec(&imp->imp_inflight);
+ set->set_remaining--;
cfs_waitq_signal(&imp->imp_recovery_waitq);
}
int rc = 0;
ENTRY;
- DEBUG_REQ(D_ERROR|D_NETERROR, req, "%s (sent at %lu, %lus ago)",
+ DEBUG_REQ(D_ERROR|D_NETERROR, req, "%s (sent at %lu, "CFS_DURATION_T"s ago)",
req->rq_net_err ? "network error" : "timeout",
- (long)req->rq_sent, CURRENT_SECONDS - req->rq_sent);
+ (long)req->rq_sent, cfs_time_current_sec() - req->rq_sent);
if (imp != NULL && obd_debug_peer_on_timeout)
LNetCtl(IOC_LIBCFS_DEBUG_PEER, &imp->imp_connection->c_peer);
{
struct ptlrpc_request_set *set = data;
struct list_head *tmp;
- time_t now = CURRENT_SECONDS;
+ time_t now = cfs_time_current_sec();
ENTRY;
LASSERT(set != NULL);
int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
{
struct list_head *tmp;
- time_t now = CURRENT_SECONDS;
+ time_t now = cfs_time_current_sec();
time_t deadline;
int timeout = 0;
struct ptlrpc_request *req;
int (*interpreter)(struct ptlrpc_request_set *set,void *,int) =
set->set_interpret;
rc = interpreter (set, set->set_arg, rc);
+ } else {
+ struct ptlrpc_set_cbdata *cbdata, *n;
+ int err;
+
+ list_for_each_entry_safe(cbdata, n,
+ &set->set_cblist, psc_item) {
+ list_del_init(&cbdata->psc_item);
+ err = cbdata->psc_interpret(set, cbdata->psc_data, rc);
+ if (err && !rc)
+ rc = err;
+ OBD_FREE_PTR(cbdata);
+ }
}
RETURN(rc);
LASSERTF(list_empty(&request->rq_set_chain), "req %p\n", request);
LASSERT(request->rq_cli_ctx);
+ req_capsule_fini(&request->rq_pill);
+
/* We must take it off the imp_replay_list first. Otherwise, we'll set
* request->rq_reqmsg to NULL while osc_close is dereferencing it. */
if (request->rq_import != NULL) {