*
* Copyright (c) 2002, 2003 Cluster File Systems, Inc.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * This file is part of the Lustre file system, http://www.lustre.org
+ * Lustre is a trademark of Cluster File Systems, Inc.
*
- * Lustre is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * You may have signed or agreed to another license before downloading
+ * this software. If so, you are bound by the terms and conditions
+ * of that agreement, and the following does not apply to you. See the
+ * LICENSE file included with this distribution for more information.
*
- * Lustre is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * If you did not agree to a different license, then this copy of Lustre
+ * is open source software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
*
- * You should have received a copy of the GNU General Public License
- * along with Lustre; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * In either case, Lustre is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * license text for more details.
*
*/
#define DEBUG_SUBSYSTEM S_RPC
-#ifdef __KERNEL__
-#include <linux/module.h>
+#ifndef __KERNEL__
+# include <liblustre.h>
#else
-#include <liblustre.h>
+# ifdef __mips64__
+# include <linux/kernel.h>
+# endif
#endif
-#include <linux/obd_class.h>
-#include <linux/lustre_net.h>
+#include <obd_class.h>
+#include <lustre_net.h>
+#include "ptlrpc_internal.h"
-struct ptlrpc_ni ptlrpc_interfaces[NAL_MAX_NR];
-int ptlrpc_ninterfaces;
+lnet_handle_eq_t ptlrpc_eq_h;
-/*
- * Free the packet when it has gone out
+/*
+ * Client's outgoing request callback
*/
-static int request_out_callback(ptl_event_t *ev)
+void request_out_callback(lnet_event_t *ev)
{
- struct ptlrpc_request *req = ev->mem_desc.user_ptr;
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_request *req = cbid->cbid_arg;
ENTRY;
- /* requests always contiguous */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) == 0);
+ LASSERT (ev->type == LNET_EVENT_SEND ||
+ ev->type == LNET_EVENT_UNLINK);
+ LASSERT (ev->unlinked);
+
+ DEBUG_REQ((ev->status == 0) ? D_NET : D_ERROR, req,
+ "type %d, status %d", ev->type, ev->status);
+
+ if (ev->type == LNET_EVENT_UNLINK || ev->status != 0) {
+
+ /* Failed send: make it seem like the reply timed out, just
+ * like failing sends in client.c does currently... */
- if (ev->type != PTL_EVENT_SENT) {
- // XXX make sure we understand all events, including ACK's
- CERROR("Unknown event %d\n", ev->type);
- LBUG();
+ spin_lock(&req->rq_lock);
+ req->rq_net_err = 1;
+ spin_unlock(&req->rq_lock);
+
+ ptlrpc_wake_client_req(req);
}
- /* this balances the atomic_inc in ptl_send_rpc() */
+ /* these balance the references in ptl_send_rpc() */
+ atomic_dec(&req->rq_import->imp_inflight);
ptlrpc_req_finished(req);
- RETURN(1);
+
+ EXIT;
}
/*
- * Free the packet when it has gone out
+ * Client's incoming reply callback
*/
-static int reply_out_callback(ptl_event_t *ev)
+void reply_in_callback(lnet_event_t *ev)
{
- struct ptlrpc_request *req = ev->mem_desc.user_ptr;
- unsigned long flags;
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_request *req = cbid->cbid_arg;
ENTRY;
- /* replies always contiguous */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) == 0);
-
- if (ev->type == PTL_EVENT_SENT) {
- /* NB don't even know if this is the current reply! In fact
- * we can't touch any state in the request, since the
- * service handler zeros it on each incoming request. */
- OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
- } else if (ev->type == PTL_EVENT_ACK) {
- LASSERT(req->rq_want_ack);
- spin_lock_irqsave(&req->rq_lock, flags);
- req->rq_want_ack = 0;
- wake_up(&req->rq_wait_for_rep);
- spin_unlock_irqrestore(&req->rq_lock, flags);
- } else {
- // XXX make sure we understand all events
- CERROR("Unknown event %d\n", ev->type);
- LBUG();
+ LASSERT (ev->type == LNET_EVENT_PUT ||
+ ev->type == LNET_EVENT_UNLINK);
+ LASSERT (ev->unlinked);
+ LASSERT (ev->md.start == req->rq_repmsg);
+ LASSERT (ev->offset == 0);
+ LASSERT (ev->mlength <= req->rq_replen);
+
+ DEBUG_REQ((ev->status == 0) ? D_NET : D_ERROR, req,
+ "type %d, status %d", ev->type, ev->status);
+
+ spin_lock(&req->rq_lock);
+
+ LASSERT (req->rq_receiving_reply);
+ req->rq_receiving_reply = 0;
+
+ if (ev->type == LNET_EVENT_PUT && ev->status == 0) {
+ req->rq_replied = 1;
+ req->rq_nob_received = ev->mlength;
}
- RETURN(1);
+ /* NB don't unlock till after wakeup; req can disappear under us
+ * since we don't have our own ref */
+ ptlrpc_wake_client_req(req);
+
+ spin_unlock(&req->rq_lock);
+ EXIT;
}
-/*
- * Wake up the thread waiting for the reply once it comes in.
+/*
+ * Client's bulk has been written/read
*/
-int reply_in_callback(ptl_event_t *ev)
+void client_bulk_callback (lnet_event_t *ev)
{
- struct ptlrpc_request *req = ev->mem_desc.user_ptr;
- unsigned long flags;
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
ENTRY;
- /* replies always contiguous */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) == 0);
+ LASSERT ((desc->bd_type == BULK_PUT_SINK &&
+ ev->type == LNET_EVENT_PUT) ||
+ (desc->bd_type == BULK_GET_SOURCE &&
+ ev->type == LNET_EVENT_GET) ||
+ ev->type == LNET_EVENT_UNLINK);
+ LASSERT (ev->unlinked);
- if (req->rq_xid == 0x5a5a5a5a5a5a5a5a) {
- CERROR("Reply received for freed request! Probably a missing "
- "ptlrpc_abort()\n");
- LBUG();
+ CDEBUG((ev->status == 0) ? D_NET : D_ERROR,
+ "event type %d, status %d, desc %p\n",
+ ev->type, ev->status, desc);
+
+ spin_lock(&desc->bd_lock);
+
+ LASSERT(desc->bd_network_rw);
+ desc->bd_network_rw = 0;
+
+ if (ev->type != LNET_EVENT_UNLINK && ev->status == 0) {
+ desc->bd_success = 1;
+ desc->bd_nob_transferred = ev->mlength;
}
- if (req->rq_xid != ev->match_bits) {
- CERROR("Reply packet for wrong request\n");
- LBUG();
+ /* NB don't unlock till after wakeup; desc can disappear under us
+ * otherwise */
+ ptlrpc_wake_client_req(desc->bd_req);
+
+ spin_unlock(&desc->bd_lock);
+ EXIT;
+}
+
+/*
+ * Server's incoming request callback
+ */
+void request_in_callback(lnet_event_t *ev)
+{
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_request_buffer_desc *rqbd = cbid->cbid_arg;
+ struct ptlrpc_service *service = rqbd->rqbd_service;
+ struct ptlrpc_request *req;
+ ENTRY;
+
+ LASSERT (ev->type == LNET_EVENT_PUT ||
+ ev->type == LNET_EVENT_UNLINK);
+ LASSERT ((char *)ev->md.start >= rqbd->rqbd_buffer);
+ LASSERT ((char *)ev->md.start + ev->offset + ev->mlength <=
+ rqbd->rqbd_buffer + service->srv_buf_size);
+
+ CDEBUG((ev->status == 0) ? D_NET : D_ERROR,
+ "event type %d, status %d, service %s\n",
+ ev->type, ev->status, service->srv_name);
+
+ if (ev->unlinked) {
+ /* If this is the last request message to fit in the
+ * request buffer we can use the request object embedded in
+ * rqbd. Note that if we failed to allocate a request,
+ * we'd have to re-post the rqbd, which we can't do in this
+ * context. */
+ req = &rqbd->rqbd_req;
+ memset(req, 0, sizeof (*req));
+ } else {
+ LASSERT (ev->type == LNET_EVENT_PUT);
+ if (ev->status != 0) {
+ /* We moaned above already... */
+ return;
+ }
+ OBD_ALLOC_GFP(req, sizeof(*req), CFS_ALLOC_ATOMIC_TRY);
+ if (req == NULL) {
+ CERROR("Can't allocate incoming request descriptor: "
+ "Dropping %s RPC from %s\n",
+ service->srv_name,
+ libcfs_id2str(ev->initiator));
+ return;
+ }
}
- if (ev->type == PTL_EVENT_PUT) {
- /* Bug 1190: should handle non-zero offset as a protocol
- * error */
- LASSERT (ev->offset == 0);
+ /* NB we ABSOLUTELY RELY on req being zeroed, so pointers are NULL,
+ * flags are reset and scalars are zero. We only set the message
+ * size to non-zero if this was a successful receive. */
+ req->rq_xid = ev->match_bits;
+ req->rq_reqmsg = ev->md.start + ev->offset;
+ if (ev->type == LNET_EVENT_PUT && ev->status == 0)
+ req->rq_reqlen = ev->mlength;
+ do_gettimeofday(&req->rq_arrival_time);
+ req->rq_peer = ev->initiator;
+ req->rq_self = ev->target.nid;
+ req->rq_rqbd = rqbd;
+ req->rq_phase = RQ_PHASE_NEW;
+#ifdef CRAY_XT3
+ req->rq_uid = ev->uid;
+#endif
- spin_lock_irqsave (&req->rq_lock, flags);
- LASSERT (req->rq_receiving_reply);
- req->rq_receiving_reply = 0;
- req->rq_replied = 1;
- if (req->rq_set != NULL)
- wake_up(&req->rq_set->set_waitq);
- else
- wake_up(&req->rq_wait_for_rep);
- spin_unlock_irqrestore (&req->rq_lock, flags);
+ spin_lock(&service->srv_lock);
+
+ req->rq_history_seq = service->srv_request_seq++;
+ list_add_tail(&req->rq_history_list, &service->srv_request_history);
+
+ if (ev->unlinked) {
+ service->srv_nrqbd_receiving--;
+ CDEBUG(D_RPCTRACE,"Buffer complete: %d buffers still posted\n",
+ service->srv_nrqbd_receiving);
+
+ /* Normally, don't complain about 0 buffers posted; LNET won't
+ * drop incoming reqs since we set the portal lazy */
+ if (test_req_buffer_pressure &&
+ ev->type != LNET_EVENT_UNLINK &&
+ service->srv_nrqbd_receiving == 0)
+ CWARN("All %s request buffers busy\n",
+ service->srv_name);
+
+ /* req takes over the network's ref on rqbd */
} else {
- // XXX make sure we understand all events, including ACKs
- CERROR("Unknown event %d\n", ev->type);
- LBUG();
+ /* req takes a ref on rqbd */
+ rqbd->rqbd_refcount++;
}
- RETURN(1);
+ list_add_tail(&req->rq_list, &service->srv_request_queue);
+ service->srv_n_queued_reqs++;
+
+ /* NB everything can disappear under us once the request
+ * has been queued and we unlock, so do the wake now... */
+ cfs_waitq_signal(&service->srv_waitq);
+
+ spin_unlock(&service->srv_lock);
+ EXIT;
}
-int request_in_callback(ptl_event_t *ev)
+/*
+ * Server's outgoing reply callback
+ */
+void reply_out_callback(lnet_event_t *ev)
{
- struct ptlrpc_request_buffer_desc *rqbd = ev->mem_desc.user_ptr;
- struct ptlrpc_srv_ni *srv_ni = rqbd->rqbd_srv_ni;
- struct ptlrpc_service *service = srv_ni->sni_service;
-
- /* requests always contiguous */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) == 0);
- /* we only enable puts */
- LASSERT(ev->type == PTL_EVENT_PUT);
- LASSERT(atomic_read(&srv_ni->sni_nrqbds_receiving) > 0);
- LASSERT(atomic_read(&rqbd->rqbd_refcount) > 0);
-
- if (ev->rlength != ev->mlength)
- CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
- ev->mlength, ev->rlength);
-
- if (!PtlHandleEqual (ev->unlinked_me, PTL_HANDLE_NONE)) {
- /* This is the last request to be received into this
- * request buffer. We don't bump the refcount, since the
- * thread servicing this event is effectively taking over
- * portals' reference.
- */
- /* NB ev->unlinked_me.nal_idx is not set properly in a callback */
- LASSERT(ev->unlinked_me.cookie==rqbd->rqbd_me_h.cookie);
-
- /* we're off the air */
- /* we'll probably start dropping packets in portals soon */
- if (atomic_dec_and_test(&srv_ni->sni_nrqbds_receiving))
- CERROR("All request buffers busy\n");
- } else {
- /* +1 ref for service thread */
- atomic_inc(&rqbd->rqbd_refcount);
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_reply_state *rs = cbid->cbid_arg;
+ struct ptlrpc_service *svc = rs->rs_service;
+ ENTRY;
+
+ LASSERT (ev->type == LNET_EVENT_SEND ||
+ ev->type == LNET_EVENT_ACK ||
+ ev->type == LNET_EVENT_UNLINK);
+
+ if (!rs->rs_difficult) {
+ /* 'Easy' replies have no further processing so I drop the
+ * net's ref on 'rs' */
+ LASSERT (ev->unlinked);
+ ptlrpc_rs_decref(rs);
+ atomic_dec (&svc->srv_outstanding_replies);
+ EXIT;
+ return;
}
- wake_up(&service->srv_waitq);
+ LASSERT (rs->rs_on_net);
- return 0;
+ if (ev->unlinked) {
+ /* Last network callback. The net's ref on 'rs' stays put
+ * until ptlrpc_server_handle_reply() is done with it */
+ spin_lock(&svc->srv_lock);
+ rs->rs_on_net = 0;
+ ptlrpc_schedule_difficult_reply (rs);
+ spin_unlock(&svc->srv_lock);
+ }
+
+ EXIT;
}
-static int bulk_put_source_callback(ptl_event_t *ev)
+/*
+ * Server's bulk completion callback
+ */
+void server_bulk_callback (lnet_event_t *ev)
{
- unsigned long flags;
- struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
ENTRY;
- CDEBUG(D_NET, "got %s event %d\n",
- (ev->type == PTL_EVENT_SENT) ? "SENT" :
- (ev->type == PTL_EVENT_ACK) ? "ACK" : "UNEXPECTED", ev->type);
+ LASSERT (ev->type == LNET_EVENT_SEND ||
+ ev->type == LNET_EVENT_UNLINK ||
+ (desc->bd_type == BULK_PUT_SOURCE &&
+ ev->type == LNET_EVENT_ACK) ||
+ (desc->bd_type == BULK_GET_SINK &&
+ ev->type == LNET_EVENT_REPLY));
- LASSERT(ev->type == PTL_EVENT_SENT || ev->type == PTL_EVENT_ACK);
+ CDEBUG((ev->status == 0) ? D_NET : D_ERROR,
+ "event type %d, status %d, desc %p\n",
+ ev->type, ev->status, desc);
- /* 1 fragment for each page always */
- LASSERT(ev->mem_desc.niov == desc->bd_page_count);
-
- spin_lock_irqsave (&desc->bd_lock, flags);
-
- LASSERT(desc->bd_callback_count > 0 &&
- desc->bd_callback_count <= 2);
+ spin_lock(&desc->bd_lock);
- if (--desc->bd_callback_count == 0) {
+ if ((ev->type == LNET_EVENT_ACK ||
+ ev->type == LNET_EVENT_REPLY) &&
+ ev->status == 0) {
+ /* We heard back from the peer, so even if we get this
+ * before the SENT event (oh yes we can), we know we
+ * read/wrote the peer buffer and how much... */
+ desc->bd_success = 1;
+ desc->bd_nob_transferred = ev->mlength;
+ }
+
+ if (ev->unlinked) {
+ /* This is the last callback no matter what... */
desc->bd_network_rw = 0;
- desc->bd_complete = 1;
- wake_up(&desc->bd_waitq);
+ cfs_waitq_signal(&desc->bd_waitq);
}
- spin_unlock_irqrestore (&desc->bd_lock, flags);
- RETURN(0);
+ spin_unlock(&desc->bd_lock);
+ EXIT;
}
-struct ptlrpc_bulk_desc ptlrpc_bad_desc;
-ptl_event_t ptlrpc_bad_event;
-
-static int bulk_put_sink_callback(ptl_event_t *ev)
+static void ptlrpc_master_callback(lnet_event_t *ev)
{
- struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
- unsigned long flags;
- ENTRY;
+ struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
+ void (*callback)(lnet_event_t *ev) = cbid->cbid_fn;
- LASSERT(ev->type == PTL_EVENT_PUT);
-
- /* used iovs */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) ==
- PTL_MD_KIOV);
/* Honestly, it's best to find out early. */
- if (desc->bd_page_count == 0x5a5a5a5a5a ||
- desc->bd_page_count != ev->mem_desc.niov ||
- ev->mem_desc.start != &desc->bd_iov) {
- /* not guaranteed (don't LASSERT) but good for this bug hunt */
- ptlrpc_bad_event = *ev;
- ptlrpc_bad_desc = *desc;
- CERROR ("XXX ev %p type %d portal %d match "LPX64", seq %ld\n",
- ev, ev->type, ev->portal, ev->match_bits, ev->sequence);
- CERROR ("XXX desc %p, export %p import %p gen %d "
- " portal %d\n",
- desc, desc->bd_export,
- desc->bd_import, desc->bd_import_generation,
- desc->bd_portal);
- RETURN (0);
- }
+ LASSERT (cbid->cbid_arg != LP_POISON);
+ LASSERT (callback == request_out_callback ||
+ callback == reply_in_callback ||
+ callback == client_bulk_callback ||
+ callback == request_in_callback ||
+ callback == reply_out_callback ||
+ callback == server_bulk_callback);
- LASSERT(desc->bd_page_count != 0x5a5a5a5a);
- /* 1 fragment for each page always */
- LASSERT(ev->mem_desc.niov == desc->bd_page_count);
- LASSERT(ev->match_bits == desc->bd_req->rq_xid);
-
- /* peer must put with zero offset */
- if (ev->offset != 0) {
- /* Bug 1190: handle this as a protocol failure */
- CERROR ("Bad offset %d\n", ev->offset);
- LBUG ();
- }
+ callback (ev);
+}
- /* No check for total # bytes; this could be a short read */
+int ptlrpc_uuid_to_peer (struct obd_uuid *uuid,
+ lnet_process_id_t *peer, lnet_nid_t *self)
+{
+ int best_dist = 0;
+ int best_order = 0;
+ int count = 0;
+ int rc = -ENOENT;
+ int portals_compatibility;
+ int dist;
+ int order;
+ lnet_nid_t dst_nid;
+ lnet_nid_t src_nid;
+
+ portals_compatibility = LNetCtl(IOC_LIBCFS_PORTALS_COMPATIBILITY, NULL);
+
+ peer->pid = LUSTRE_SRV_LNET_PID;
+
+ /* Choose the matching UUID that's closest */
+ while (lustre_uuid_to_peer(uuid->uuid, &dst_nid, count++) == 0) {
+ dist = LNetDist(dst_nid, &src_nid, &order);
+ if (dist < 0)
+ continue;
+
+ if (dist == 0) { /* local! use loopback LND */
+ peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0);
+ rc = 0;
+ break;
+ }
+
+ LASSERT (order >= 0);
+ if (rc < 0 ||
+ dist < best_dist ||
+ (dist == best_dist && order < best_order)) {
+ best_dist = dist;
+ best_order = order;
+
+ if (portals_compatibility > 1) {
+ /* Strong portals compatibility: Zero the nid's
+ * NET, so if I'm reading new config logs, or
+ * getting configured by (new) lconf I can
+ * still talk to old servers. */
+ dst_nid = LNET_MKNID(0, LNET_NIDADDR(dst_nid));
+ src_nid = LNET_MKNID(0, LNET_NIDADDR(src_nid));
+ }
+ peer->nid = dst_nid;
+ *self = src_nid;
+ rc = 0;
+ }
+ }
- spin_lock_irqsave (&desc->bd_lock, flags);
- desc->bd_network_rw = 0;
- desc->bd_complete = 1;
- if (desc->bd_req->rq_set != NULL)
- wake_up (&desc->bd_req->rq_set->set_waitq);
- else
- wake_up (&desc->bd_req->rq_wait_for_rep);
- spin_unlock_irqrestore (&desc->bd_lock, flags);
+ CDEBUG(D_NET,"%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
+ if (rc != 0)
+ CERROR("No NID found for %s\n", uuid->uuid);
+ return rc;
+}
- RETURN(1);
+void ptlrpc_ni_fini(void)
+{
+ cfs_waitq_t waitq;
+ struct l_wait_info lwi;
+ int rc;
+ int retries;
+
+ /* Wait for the event queue to become idle since there may still be
+ * messages in flight with pending events (i.e. the fire-and-forget
+ * messages == client requests and "non-difficult" server
+ * replies */
+
+ for (retries = 0;; retries++) {
+ rc = LNetEQFree(ptlrpc_eq_h);
+ switch (rc) {
+ default:
+ LBUG();
+
+ case 0:
+ LNetNIFini();
+ return;
+
+ case -EBUSY:
+ if (retries != 0)
+ CWARN("Event queue still busy\n");
+
+ /* Wait for a bit */
+ cfs_waitq_init(&waitq);
+ lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL);
+ l_wait_event(waitq, 0, &lwi);
+ break;
+ }
+ }
+ /* notreached */
}
-static int bulk_get_source_callback(ptl_event_t *ev)
+lnet_pid_t ptl_get_pid(void)
{
- struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
- struct ptlrpc_bulk_page *bulk;
- struct list_head *tmp;
- unsigned long flags;
- ptl_size_t total = 0;
- ENTRY;
+ lnet_pid_t pid;
- LASSERT(ev->type == PTL_EVENT_GET);
+#ifndef __KERNEL__
+ pid = getpid();
+#else
+ pid = LUSTRE_SRV_LNET_PID;
+#endif
+ return pid;
+}
+
+int ptlrpc_ni_init(void)
+{
+ int rc;
+ lnet_pid_t pid;
- /* used iovs */
- LASSERT((ev->mem_desc.options & (PTL_MD_IOV | PTL_MD_KIOV)) ==
- PTL_MD_KIOV);
- /* 1 fragment for each page always */
- LASSERT(ev->mem_desc.niov == desc->bd_page_count);
- LASSERT(ev->match_bits == desc->bd_req->rq_xid);
+ pid = ptl_get_pid();
+ CDEBUG(D_NET, "My pid is: %x\n", pid);
- /* peer must get with zero offset */
- if (ev->offset != 0) {
- /* Bug 1190: handle this as a protocol failure */
- CERROR ("Bad offset %d\n", ev->offset);
- LBUG ();
+ /* We're not passing any limits yet... */
+ rc = LNetNIInit(pid);
+ if (rc < 0) {
+ CDEBUG (D_NET, "Can't init network interface: %d\n", rc);
+ return (-ENOENT);
}
-
- list_for_each (tmp, &desc->bd_page_list) {
- bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
- total += bulk->bp_buflen;
- }
+ /* CAVEAT EMPTOR: how we process portals events is _radically_
+ * different depending on... */
+#ifdef __KERNEL__
+ /* kernel portals calls our master callback when events are added to
+ * the event queue. In fact lustre never pulls events off this queue,
+ * so it's only sized for some debug history. */
+ rc = LNetEQAlloc(1024, ptlrpc_master_callback, &ptlrpc_eq_h);
+#else
+ /* liblustre calls the master callback when it removes events from the
+ * event queue. The event queue has to be big enough not to drop
+ * anything */
+ rc = LNetEQAlloc(10240, LNET_EQ_HANDLER_NONE, &ptlrpc_eq_h);
+#endif
+ if (rc == 0)
+ return 0;
- /* peer must get everything */
- if (ev->mem_desc.length != total) {
- /* Bug 1190: handle this as a protocol failure */
- CERROR ("Bad length/total %d/%d\n", ev->mem_desc.length, total);
- LBUG ();
- }
+ CERROR ("Failed to allocate event queue: %d\n", rc);
+ LNetNIFini();
- spin_lock_irqsave (&desc->bd_lock, flags);
- desc->bd_network_rw = 0;
- desc->bd_complete = 1;
- if (desc->bd_req->rq_set != NULL)
- wake_up (&desc->bd_req->rq_set->set_waitq);
- else
- wake_up (&desc->bd_req->rq_wait_for_rep);
- spin_unlock_irqrestore (&desc->bd_lock, flags);
+ return (-ENOMEM);
+}
- RETURN(1);
+#ifndef __KERNEL__
+CFS_LIST_HEAD(liblustre_wait_callbacks);
+CFS_LIST_HEAD(liblustre_idle_callbacks);
+void *liblustre_services_callback;
+
+void *
+liblustre_register_waitidle_callback (struct list_head *callback_list,
+ const char *name,
+ int (*fn)(void *arg), void *arg)
+{
+ struct liblustre_wait_callback *llwc;
+
+ OBD_ALLOC(llwc, sizeof(*llwc));
+ LASSERT (llwc != NULL);
+
+ llwc->llwc_name = name;
+ llwc->llwc_fn = fn;
+ llwc->llwc_arg = arg;
+ list_add_tail(&llwc->llwc_list, callback_list);
+
+ return (llwc);
}
-static int bulk_get_sink_callback(ptl_event_t *ev)
+void
+liblustre_deregister_waitidle_callback (void *opaque)
{
- struct ptlrpc_bulk_desc *desc = ev->mem_desc.user_ptr;
- unsigned long flags;
- ENTRY;
+ struct liblustre_wait_callback *llwc = opaque;
+
+ list_del(&llwc->llwc_list);
+ OBD_FREE(llwc, sizeof(*llwc));
+}
- CDEBUG(D_NET, "got %s event %d desc %p\n",
- (ev->type == PTL_EVENT_SENT) ? "SENT" :
- (ev->type == PTL_EVENT_REPLY) ? "REPLY" : "UNEXPECTED",
- ev->type, desc);
+void *
+liblustre_register_wait_callback (const char *name,
+ int (*fn)(void *arg), void *arg)
+{
+ return liblustre_register_waitidle_callback(&liblustre_wait_callbacks,
+ name, fn, arg);
+}
- LASSERT(ev->type == PTL_EVENT_SENT || ev->type == PTL_EVENT_REPLY);
+void
+liblustre_deregister_wait_callback (void *opaque)
+{
+ liblustre_deregister_waitidle_callback(opaque);
+}
- /* 1 fragment for each page always */
- LASSERT(ev->mem_desc.niov == desc->bd_page_count);
+void *
+liblustre_register_idle_callback (const char *name,
+ int (*fn)(void *arg), void *arg)
+{
+ return liblustre_register_waitidle_callback(&liblustre_idle_callbacks,
+ name, fn, arg);
+}
- spin_lock_irqsave (&desc->bd_lock, flags);
- LASSERT(desc->bd_callback_count > 0 &&
- desc->bd_callback_count <= 2);
+void
+liblustre_deregister_idle_callback (void *opaque)
+{
+ liblustre_deregister_waitidle_callback(opaque);
+}
- if (--desc->bd_callback_count == 0) {
- desc->bd_network_rw = 0;
- desc->bd_complete = 1;
- wake_up(&desc->bd_waitq);
- }
- spin_unlock_irqrestore (&desc->bd_lock, flags);
+int
+liblustre_check_events (int timeout)
+{
+ lnet_event_t ev;
+ int rc;
+ int i;
+ ENTRY;
- RETURN(0);
+ rc = LNetEQPoll(&ptlrpc_eq_h, 1, timeout * 1000, &ev, &i);
+ if (rc == 0)
+ RETURN(0);
+
+ LASSERT (rc == -EOVERFLOW || rc == 1);
+
+ /* liblustre: no asynch callback so we can't affort to miss any
+ * events... */
+ if (rc == -EOVERFLOW) {
+ CERROR ("Dropped an event!!!\n");
+ abort();
+ }
+
+ ptlrpc_master_callback (&ev);
+ RETURN(1);
}
-int ptlrpc_uuid_to_peer (struct obd_uuid *uuid, struct ptlrpc_peer *peer)
+int liblustre_waiting = 0;
+
+int
+liblustre_wait_event (int timeout)
{
- struct ptlrpc_ni *pni;
- struct lustre_peer lpeer;
- int i;
- int rc = lustre_uuid_to_peer (uuid->uuid, &lpeer);
-
- if (rc != 0)
- RETURN (rc);
-
- for (i = 0; i < ptlrpc_ninterfaces; i++) {
- pni = &ptlrpc_interfaces[i];
-
- if (!memcmp(&lpeer.peer_ni, &pni->pni_ni_h,
- sizeof (lpeer.peer_ni))) {
- peer->peer_nid = lpeer.peer_nid;
- peer->peer_ni = pni;
- return (0);
+ struct list_head *tmp;
+ struct liblustre_wait_callback *llwc;
+ int found_something = 0;
+
+ /* single threaded recursion check... */
+ liblustre_waiting = 1;
+
+ for (;;) {
+ /* Deal with all pending events */
+ while (liblustre_check_events(0))
+ found_something = 1;
+
+ /* Give all registered callbacks a bite at the cherry */
+ list_for_each(tmp, &liblustre_wait_callbacks) {
+ llwc = list_entry(tmp, struct liblustre_wait_callback,
+ llwc_list);
+
+ if (llwc->llwc_fn(llwc->llwc_arg))
+ found_something = 1;
}
+
+ if (found_something || timeout == 0)
+ break;
+
+ /* Nothing so far, but I'm allowed to block... */
+ found_something = liblustre_check_events(timeout);
+ if (!found_something) /* still nothing */
+ break; /* I timed out */
}
- CERROR("Can't find ptlrpc interface for "LPX64" ni handle %08lx."LPX64"\n",
- lpeer.peer_nid, lpeer.peer_ni.nal_idx, lpeer.peer_ni.cookie);
- return (-ENOENT);
-}
+ liblustre_waiting = 0;
-void ptlrpc_ni_fini(struct ptlrpc_ni *pni)
-{
- PtlEQFree(pni->pni_request_out_eq_h);
- PtlEQFree(pni->pni_reply_out_eq_h);
- PtlEQFree(pni->pni_reply_in_eq_h);
- PtlEQFree(pni->pni_bulk_put_source_eq_h);
- PtlEQFree(pni->pni_bulk_put_sink_eq_h);
- PtlEQFree(pni->pni_bulk_get_source_eq_h);
- PtlEQFree(pni->pni_bulk_get_sink_eq_h);
-
- kportal_put_ni (pni->pni_number);
+ return found_something;
}
-int ptlrpc_ni_init(int number, char *name, struct ptlrpc_ni *pni)
+void
+liblustre_wait_idle(void)
{
- int rc;
- ptl_handle_ni_t *nip = kportal_get_ni (number);
+ static int recursed = 0;
+
+ struct list_head *tmp;
+ struct liblustre_wait_callback *llwc;
+ int idle = 0;
- if (nip == NULL) {
- CDEBUG (D_NET, "Network interface %s not loaded\n", name);
- return (-ENOENT);
- }
+ LASSERT(!recursed);
+ recursed = 1;
+
+ do {
+ liblustre_wait_event(0);
+
+ idle = 1;
+
+ list_for_each(tmp, &liblustre_idle_callbacks) {
+ llwc = list_entry(tmp, struct liblustre_wait_callback,
+ llwc_list);
+
+ if (!llwc->llwc_fn(llwc->llwc_arg)) {
+ idle = 0;
+ break;
+ }
+ }
+
+ } while (!idle);
- CDEBUG (D_NET, "init %d %s: nal_idx %ld\n", number, name, nip->nal_idx);
-
- pni->pni_name = name;
- pni->pni_number = number;
- pni->pni_ni_h = *nip;
-
- pni->pni_request_out_eq_h = PTL_HANDLE_NONE;
- pni->pni_reply_out_eq_h = PTL_HANDLE_NONE;
- pni->pni_reply_in_eq_h = PTL_HANDLE_NONE;
- pni->pni_bulk_put_source_eq_h = PTL_HANDLE_NONE;
- pni->pni_bulk_put_sink_eq_h = PTL_HANDLE_NONE;
- pni->pni_bulk_get_source_eq_h = PTL_HANDLE_NONE;
- pni->pni_bulk_get_sink_eq_h = PTL_HANDLE_NONE;
-
- /* NB We never actually PtlEQGet() out of these events queues since
- * we're only interested in the event callback, so we can just let
- * them wrap. Their sizes aren't a big deal, apart from providing
- * a little history for debugging... */
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, request_out_callback,
- &pni->pni_request_out_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, reply_out_callback,
- &pni->pni_reply_out_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, reply_in_callback,
- &pni->pni_reply_in_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, bulk_put_source_callback,
- &pni->pni_bulk_put_source_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, bulk_put_sink_callback,
- &pni->pni_bulk_put_sink_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, bulk_get_source_callback,
- &pni->pni_bulk_get_source_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- rc = PtlEQAlloc(pni->pni_ni_h, 1024, bulk_get_sink_callback,
- &pni->pni_bulk_get_sink_eq_h);
- if (rc != PTL_OK)
- GOTO (fail, rc = -ENOMEM);
-
- return (0);
- fail:
- CERROR ("Failed to initialise network interface %s: %d\n",
- name, rc);
-
- /* OK to do complete teardown since we invalidated the handles above */
- ptlrpc_ni_fini (pni);
- return (rc);
+ recursed = 0;
}
+#endif /* __KERNEL__ */
+
int ptlrpc_init_portals(void)
{
- /* Add new portals network interfaces here.
- * Order is irrelevent! */
- static struct {
- int number;
- char *name;
- } ptl_nis[] = {
- {QSWNAL, "qswnal"},
- {SOCKNAL, "socknal"},
- {GMNAL, "gmnal"},
- {TOENAL, "toenal"},
- {TCPNAL, "tcpnal"},
- {SCIMACNAL, "scimacnal"}};
- int rc;
- int i;
-
- LASSERT(ptlrpc_ninterfaces == 0);
-
- for (i = 0; i < sizeof (ptl_nis) / sizeof (ptl_nis[0]); i++) {
- LASSERT(ptlrpc_ninterfaces < (sizeof(ptlrpc_interfaces) /
- sizeof(ptlrpc_interfaces[0])));
-
- rc = ptlrpc_ni_init(ptl_nis[i].number, ptl_nis[i].name,
- &ptlrpc_interfaces[ptlrpc_ninterfaces]);
- if (rc == 0)
- ptlrpc_ninterfaces++;
- }
+ int rc = ptlrpc_ni_init();
- if (ptlrpc_ninterfaces == 0) {
- CERROR("network initialisation failed: is a NAL module "
- "loaded?\n");
+ if (rc != 0) {
+ CERROR("network initialisation failed\n");
return -EIO;
}
- return 0;
+#ifndef __KERNEL__
+ liblustre_services_callback =
+ liblustre_register_wait_callback("liblustre_check_services",
+ &liblustre_check_services, NULL);
+#endif
+ rc = ptlrpcd_addref();
+ if (rc == 0)
+ return 0;
+
+ CERROR("rpcd initialisation failed\n");
+#ifndef __KERNEL__
+ liblustre_deregister_wait_callback(liblustre_services_callback);
+#endif
+ ptlrpc_ni_fini();
+ return rc;
}
void ptlrpc_exit_portals(void)
{
- while (ptlrpc_ninterfaces > 0)
- ptlrpc_ni_fini (&ptlrpc_interfaces[--ptlrpc_ninterfaces]);
+#ifndef __KERNEL__
+ liblustre_deregister_wait_callback(liblustre_services_callback);
+#endif
+ ptlrpcd_decref();
+ ptlrpc_ni_fini();
}