#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);
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_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_req_put_ctx(request);
+ 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 -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");
- *status = -EIO;
+ 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,
* including buflens, status etc is in the sender's byte order. */
-#if SWAB_PARANOIA
/* Clear reply swab mask; this is a new reply in sender's byte order */
req->rq_rep_swab_mask = 0;
-#endif
+
rc = sptlrpc_cli_unwrap_reply(req);
if (rc) {
DEBUG_REQ(D_ERROR, req, "unwrap reply failed (%d):", rc);
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)",
rc = ptlrpc_check_status(req);
imp->imp_connect_error = rc;
- /* Either we've been evicted, or the server has failed for
- * some reason. Try to reconnect, and if that fails, punt to the
- * upcall. */
- if ((rc == -ENOTCONN) || (rc == -ENODEV)) {
- if (req->rq_send_state != LUSTRE_IMP_FULL ||
- imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
- RETURN(-ENOTCONN);
+ if (rc) {
+ /* Either we've been evicted, or the server has failed for
+ * some reason. Try to reconnect, and if that fails, punt to
+ * the upcall. */
+ if (ll_rpc_recoverable_error(rc)) {
+ if (req->rq_send_state != LUSTRE_IMP_FULL ||
+ imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
+ RETURN(rc);
+ }
+ ptlrpc_request_handle_notconn(req);
+ RETURN(rc);
+ }
+ } else {
+ /* Let's look if server send slv. Do it only for RPC with
+ * rc == 0. */
+ if (imp->imp_obd->obd_namespace) {
+ /* Disconnect rpc is sent when namespace is already
+ * destroyed. Let's check this and will not try update
+ * pool. */
+ ldlm_cli_update_pool(req);
}
-
- ptlrpc_request_handle_notconn(req);
-
- RETURN(rc);
}
/* Store transno in reqmsg for replay. */
ENTRY;
LASSERT(req->rq_phase == RQ_PHASE_NEW);
+ if (req->rq_sent && (req->rq_sent > cfs_time_current_sec()))
+ RETURN (0);
+
req->rq_phase = RQ_PHASE_RPC;
imp = req->rq_import;
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);
}
ptlrpc_send_new_req(req)) {
force_timer_recalc = 1;
}
+ /* delayed send - skip */
+ if (req->rq_phase == RQ_PHASE_NEW && req->rq_sent)
+ continue;
if (!(req->rq_phase == RQ_PHASE_RPC ||
req->rq_phase == RQ_PHASE_BULK ||
}
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;
/* request in-flight? */
if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting) ||
- (req->rq_phase == RQ_PHASE_BULK)))
+ (req->rq_phase == RQ_PHASE_BULK) ||
+ (req->rq_phase == RQ_PHASE_NEW)))
continue;
if (req->rq_timedout) /* already timed out */
continue;
- deadline = req->rq_sent + req->rq_timeout;
+ if (req->rq_phase == RQ_PHASE_NEW)
+ deadline = req->rq_sent;
+ else
+ deadline = req->rq_sent + req->rq_timeout;
+
if (deadline <= now) /* actually expired already */
timeout = 1; /* ASAP */
else if (timeout == 0 || timeout > deadline - now)
/* wait until all complete, interrupted, or an in-flight
* req times out */
- CDEBUG(D_HA, "set %p going to sleep for %d seconds\n",
+ CDEBUG(D_RPCTRACE, "set %p going to sleep for %d seconds\n",
set, timeout);
lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout ? timeout : 1),
ptlrpc_expired_set,
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) {
if (!locked)
spin_lock(&request->rq_import->imp_lock);
+ list_del_init(&request->rq_mod_list);
list_del_init(&request->rq_replay_list);
if (!locked)
spin_unlock(&request->rq_import->imp_lock);
if (request->rq_reqbuf != NULL || request->rq_clrbuf != NULL)
sptlrpc_cli_free_reqbuf(request);
- sptlrpc_req_put_ctx(request);
+ sptlrpc_req_put_ctx(request, !locked);
if (request->rq_pool)
__ptlrpc_free_req_to_pool(request);
if (imp->imp_peer_committed_transno == imp->imp_last_transno_checked &&
imp->imp_generation == imp->imp_last_generation_checked) {
- CDEBUG(D_HA, "%s: skip recheck for last_committed "LPU64"\n",
+ CDEBUG(D_RPCTRACE, "%s: skip recheck: last_committed "LPU64"\n",
imp->imp_obd->obd_name, imp->imp_peer_committed_transno);
return;
}
-
- CDEBUG(D_HA, "%s: committing for last_committed "LPU64" gen %d\n",
+
+ CDEBUG(D_RPCTRACE, "%s: committing for last_committed "LPU64" gen %d\n",
imp->imp_obd->obd_name, imp->imp_peer_committed_transno,
imp->imp_generation);
imp->imp_last_transno_checked = imp->imp_peer_committed_transno;
last_req = req;
if (req->rq_import_generation < imp->imp_generation) {
- DEBUG_REQ(D_HA, req, "freeing request with old gen");
+ DEBUG_REQ(D_RPCTRACE, req, "free request with old gen");
GOTO(free_req, 0);
}
if (req->rq_replay) {
- DEBUG_REQ(D_HA, req, "keeping (FL_REPLAY)");
+ DEBUG_REQ(D_RPCTRACE, req, "keeping (FL_REPLAY)");
continue;
}
/* not yet committed */
if (req->rq_transno > imp->imp_peer_committed_transno) {
- DEBUG_REQ(D_HA, req, "stopping search");
+ DEBUG_REQ(D_RPCTRACE, req, "stopping search");
break;
}
- DEBUG_REQ(D_HA, req, "committing (last_committed "LPU64")",
+ DEBUG_REQ(D_RPCTRACE, req, "commit (last_committed "LPU64")",
imp->imp_peer_committed_transno);
free_req:
spin_lock(&req->rq_lock);
}
if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR &&
- lustre_msg_get_status(req->rq_repmsg) == -ENOTCONN)
+ (lustre_msg_get_status(req->rq_repmsg) == -ENOTCONN ||
+ lustre_msg_get_status(req->rq_repmsg) == -ENODEV))
GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg));
/* The transno had better not change over replay. */
struct ptlrpc_request *req =
list_entry(tmp, struct ptlrpc_request, rq_list);
- DEBUG_REQ(D_HA, req, "inflight");
+ DEBUG_REQ(D_RPCTRACE, req, "inflight");
spin_lock (&req->rq_lock);
if (req->rq_import_generation < imp->imp_generation) {
struct ptlrpc_request *req =
list_entry(tmp, struct ptlrpc_request, rq_list);
- DEBUG_REQ(D_HA, req, "aborting waiting req");
+ DEBUG_REQ(D_RPCTRACE, req, "aborting waiting req");
spin_lock (&req->rq_lock);
if (req->rq_import_generation < imp->imp_generation) {