X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fptlrpc%2Fevents.c;h=69716b3049bd0129dfd8bd93c2ec003c9fd783b7;hp=777ef75d94c4aac5965cf4c0b05398eeae69ca18;hb=0a59f0c68978fc2dcab11ec5a4b41cead47bc71c;hpb=859678cc6b075f7c81903e44b99bdbd18c635cbb diff --git a/lustre/ptlrpc/events.c b/lustre/ptlrpc/events.c index 777ef75..69716b3 100644 --- a/lustre/ptlrpc/events.c +++ b/lustre/ptlrpc/events.c @@ -1,26 +1,37 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (c) 2002, 2003 Cluster File Systems, Inc. + * GPL HEADER START * - * This file is part of the Lustre file system, http://www.lustre.org - * Lustre is a trademark of Cluster File Systems, Inc. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * 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. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. * - * 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. + * This program 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 version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * 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. + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. */ #define DEBUG_SUBSYSTEM S_RPC @@ -28,17 +39,20 @@ #ifndef __KERNEL__ # include #else +# include # ifdef __mips64__ # include # endif #endif + #include #include +#include #include "ptlrpc_internal.h" lnet_handle_eq_t ptlrpc_eq_h; -/* +/* * Client's outgoing request callback */ void request_out_callback(lnet_event_t *ev) @@ -51,23 +65,23 @@ void request_out_callback(lnet_event_t *ev) 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); + DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status); + + sptlrpc_request_out_callback(req); + req->rq_real_sent = cfs_time_current_sec(); 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... */ - spin_lock(&req->rq_lock); + cfs_spin_lock(&req->rq_lock); req->rq_net_err = 1; - spin_unlock(&req->rq_lock); + cfs_spin_unlock(&req->rq_lock); - ptlrpc_wake_client_req(req); + ptlrpc_client_wake_req(req); } - /* these balance the references in ptl_send_rpc() */ - atomic_dec(&req->rq_import->imp_inflight); ptlrpc_req_finished(req); EXIT; @@ -82,35 +96,84 @@ void reply_in_callback(lnet_event_t *ev) struct ptlrpc_request *req = cbid->cbid_arg; ENTRY; - 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); + DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status); + + LASSERT (ev->type == LNET_EVENT_PUT || ev->type == LNET_EVENT_UNLINK); + LASSERT (ev->md.start == req->rq_repbuf); + LASSERT (ev->offset + ev->mlength <= req->rq_repbuf_len); + /* We've set LNET_MD_MANAGE_REMOTE for all outgoing requests + for adaptive timeouts' early reply. */ + LASSERT((ev->md.options & LNET_MD_MANAGE_REMOTE) != 0); - spin_lock(&req->rq_lock); + cfs_spin_lock(&req->rq_lock); - LASSERT (req->rq_receiving_reply); req->rq_receiving_reply = 0; + req->rq_early = 0; + if (ev->unlinked) + req->rq_must_unlink = 0; + + if (ev->status) + goto out_wake; - if (ev->type == LNET_EVENT_PUT && ev->status == 0) { + if (ev->type == LNET_EVENT_UNLINK) { + LASSERT(ev->unlinked); + DEBUG_REQ(D_RPCTRACE, req, "unlink"); + goto out_wake; + } + + if (ev->mlength < ev->rlength ) { + CDEBUG(D_RPCTRACE, "truncate req %p rpc %d - %d+%d\n", req, + req->rq_replen, ev->rlength, ev->offset); + req->rq_reply_truncate = 1; + req->rq_replied = 1; + req->rq_status = -EOVERFLOW; + req->rq_nob_received = ev->rlength + ev->offset; + goto out_wake; + } + + if ((ev->offset == 0) && + ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) { + /* Early reply */ + DEBUG_REQ(D_ADAPTTO, req, + "Early reply received: mlen=%u offset=%d replen=%d " + "replied=%d unlinked=%d", ev->mlength, ev->offset, + req->rq_replen, req->rq_replied, ev->unlinked); + + req->rq_early_count++; /* number received, client side */ + + if (req->rq_replied) /* already got the real reply */ + goto out_wake; + + req->rq_early = 1; + req->rq_reply_off = ev->offset; + req->rq_nob_received = ev->mlength; + /* And we're still receiving */ + req->rq_receiving_reply = 1; + } else { + /* Real reply */ + req->rq_rep_swab_mask = 0; req->rq_replied = 1; + req->rq_reply_off = ev->offset; req->rq_nob_received = ev->mlength; + /* LNetMDUnlink can't be called under the LNET_LOCK, + so we must unlink in ptlrpc_unregister_reply */ + DEBUG_REQ(D_INFO, req, + "reply in flags=%x mlen=%u offset=%d replen=%d", + lustre_msg_get_flags(req->rq_reqmsg), + ev->mlength, ev->offset, req->rq_replen); } + req->rq_import->imp_last_reply_time = cfs_time_current_sec(); + +out_wake: /* 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); + ptlrpc_client_wake_req(req); + cfs_spin_unlock(&req->rq_lock); EXIT; } -/* +/* * Client's bulk has been written/read */ void client_bulk_callback (lnet_event_t *ev) @@ -119,7 +182,7 @@ void client_bulk_callback (lnet_event_t *ev) struct ptlrpc_bulk_desc *desc = cbid->cbid_arg; ENTRY; - LASSERT ((desc->bd_type == BULK_PUT_SINK && + LASSERT ((desc->bd_type == BULK_PUT_SINK && ev->type == LNET_EVENT_PUT) || (desc->bd_type == BULK_GET_SOURCE && ev->type == LNET_EVENT_GET) || @@ -127,10 +190,10 @@ void client_bulk_callback (lnet_event_t *ev) LASSERT (ev->unlinked); CDEBUG((ev->status == 0) ? D_NET : D_ERROR, - "event type %d, status %d, desc %p\n", + "event type %d, status %d, desc %p\n", ev->type, ev->status, desc); - spin_lock(&desc->bd_lock); + cfs_spin_lock(&desc->bd_lock); LASSERT(desc->bd_network_rw); desc->bd_network_rw = 0; @@ -138,17 +201,22 @@ void client_bulk_callback (lnet_event_t *ev) if (ev->type != LNET_EVENT_UNLINK && ev->status == 0) { desc->bd_success = 1; desc->bd_nob_transferred = ev->mlength; + desc->bd_sender = ev->sender; } + /* release the encrypted pages for write */ + if (desc->bd_req->rq_bulk_write) + sptlrpc_enc_pool_put_pages(desc); + /* NB don't unlock till after wakeup; desc can disappear under us * otherwise */ - ptlrpc_wake_client_req(desc->bd_req); + ptlrpc_client_wake_req(desc->bd_req); - spin_unlock(&desc->bd_lock); + cfs_spin_unlock(&desc->bd_lock); EXIT; } -/* +/* * Server's incoming request callback */ void request_in_callback(lnet_event_t *ev) @@ -166,7 +234,7 @@ void request_in_callback(lnet_event_t *ev) rqbd->rqbd_buffer + service->srv_buf_size); CDEBUG((ev->status == 0) ? D_NET : D_ERROR, - "event type %d, status %d, service %s\n", + "event type %d, status %d, service %s\n", ev->type, ev->status, service->srv_name); if (ev->unlinked) { @@ -187,7 +255,7 @@ void request_in_callback(lnet_event_t *ev) if (req == NULL) { CERROR("Can't allocate incoming request descriptor: " "Dropping %s RPC from %s\n", - service->srv_name, + service->srv_name, libcfs_id2str(ev->initiator)); return; } @@ -197,10 +265,10 @@ void request_in_callback(lnet_event_t *ev) * 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; + req->rq_reqbuf = 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_reqdata_len = ev->mlength; + cfs_gettimeofday(&req->rq_arrival_time); req->rq_peer = ev->initiator; req->rq_self = ev->target.nid; req->rq_rqbd = rqbd; @@ -208,15 +276,23 @@ void request_in_callback(lnet_event_t *ev) #ifdef CRAY_XT3 req->rq_uid = ev->uid; #endif + cfs_spin_lock_init(&req->rq_lock); + CFS_INIT_LIST_HEAD(&req->rq_timed_list); + cfs_atomic_set(&req->rq_refcount, 1); + if (ev->type == LNET_EVENT_PUT) + CDEBUG(D_RPCTRACE, "incoming req@%p x"LPU64" msgsize %u\n", + req, req->rq_xid, ev->mlength); - spin_lock(&service->srv_lock); + CDEBUG(D_RPCTRACE, "peer: %s\n", libcfs_id2str(req->rq_peer)); + + cfs_spin_lock(&service->srv_lock); req->rq_history_seq = service->srv_request_seq++; - list_add_tail(&req->rq_history_list, &service->srv_request_history); + cfs_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", + CDEBUG(D_INFO, "Buffer complete: %d buffers still posted\n", service->srv_nrqbd_receiving); /* Normally, don't complain about 0 buffers posted; LNET won't @@ -233,14 +309,14 @@ void request_in_callback(lnet_event_t *ev) rqbd->rqbd_refcount++; } - list_add_tail(&req->rq_list, &service->srv_request_queue); + cfs_list_add_tail(&req->rq_list, &service->srv_req_in_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); + cfs_spin_unlock(&service->srv_lock); EXIT; } @@ -263,7 +339,7 @@ void reply_out_callback(lnet_event_t *ev) * net's ref on 'rs' */ LASSERT (ev->unlinked); ptlrpc_rs_decref(rs); - atomic_dec (&svc->srv_outstanding_replies); + cfs_atomic_dec (&svc->srv_outstanding_replies); EXIT; return; } @@ -271,12 +347,16 @@ void reply_out_callback(lnet_event_t *ev) LASSERT (rs->rs_on_net); 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); + /* Last network callback. The net's ref on 'rs' stays put + * until ptlrpc_handle_rs() is done with it */ + cfs_spin_lock(&svc->srv_lock); + cfs_spin_lock(&rs->rs_lock); rs->rs_on_net = 0; - ptlrpc_schedule_difficult_reply (rs); - spin_unlock(&svc->srv_lock); + if (!rs->rs_no_ack || + rs->rs_transno <= rs->rs_export->exp_obd->obd_last_committed) + ptlrpc_schedule_difficult_reply (rs); + cfs_spin_unlock(&rs->rs_lock); + cfs_spin_unlock(&svc->srv_lock); } EXIT; @@ -299,11 +379,11 @@ void server_bulk_callback (lnet_event_t *ev) ev->type == LNET_EVENT_REPLY)); CDEBUG((ev->status == 0) ? D_NET : D_ERROR, - "event type %d, status %d, desc %p\n", + "event type %d, status %d, desc %p\n", ev->type, ev->status, desc); - spin_lock(&desc->bd_lock); - + cfs_spin_lock(&desc->bd_lock); + if ((ev->type == LNET_EVENT_ACK || ev->type == LNET_EVENT_REPLY) && ev->status == 0) { @@ -312,6 +392,7 @@ void server_bulk_callback (lnet_event_t *ev) * read/wrote the peer buffer and how much... */ desc->bd_success = 1; desc->bd_nob_transferred = ev->mlength; + desc->bd_sender = ev->sender; } if (ev->unlinked) { @@ -320,7 +401,7 @@ void server_bulk_callback (lnet_event_t *ev) cfs_waitq_signal(&desc->bd_waitq); } - spin_unlock(&desc->bd_lock); + cfs_spin_unlock(&desc->bd_lock); EXIT; } @@ -337,20 +418,20 @@ static void ptlrpc_master_callback(lnet_event_t *ev) callback == request_in_callback || callback == reply_out_callback || callback == server_bulk_callback); - + callback (ev); } -int ptlrpc_uuid_to_peer (struct obd_uuid *uuid, +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; + __u32 best_order = 0; int count = 0; int rc = -ENOENT; int portals_compatibility; int dist; - int order; + __u32 order; lnet_nid_t dst_nid; lnet_nid_t src_nid; @@ -369,8 +450,7 @@ int ptlrpc_uuid_to_peer (struct obd_uuid *uuid, rc = 0; break; } - - LASSERT (order >= 0); + if (rc < 0 || dist < best_dist || (dist == best_dist && order < best_order)) { @@ -392,8 +472,6 @@ int ptlrpc_uuid_to_peer (struct obd_uuid *uuid, } 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; } @@ -403,7 +481,7 @@ void ptlrpc_ni_fini(void) 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 @@ -418,11 +496,11 @@ void ptlrpc_ni_fini(void) 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); @@ -444,7 +522,7 @@ lnet_pid_t ptl_get_pid(void) #endif return pid; } - + int ptlrpc_ni_init(void) { int rc; @@ -488,20 +566,20 @@ CFS_LIST_HEAD(liblustre_idle_callbacks); void *liblustre_services_callback; void * -liblustre_register_waitidle_callback (struct list_head *callback_list, +liblustre_register_waitidle_callback (cfs_list_t *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); - + cfs_list_add_tail(&llwc->llwc_list, callback_list); + return (llwc); } @@ -509,8 +587,8 @@ void liblustre_deregister_waitidle_callback (void *opaque) { struct liblustre_wait_callback *llwc = opaque; - - list_del(&llwc->llwc_list); + + cfs_list_del(&llwc->llwc_list); OBD_FREE(llwc, sizeof(*llwc)); } @@ -553,16 +631,16 @@ liblustre_check_events (int timeout) 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 + + /* liblustre: no asynch callback so we can't afford to miss any * events... */ if (rc == -EOVERFLOW) { CERROR ("Dropped an event!!!\n"); abort(); } - + ptlrpc_master_callback (&ev); RETURN(1); } @@ -572,7 +650,7 @@ int liblustre_waiting = 0; int liblustre_wait_event (int timeout) { - struct list_head *tmp; + cfs_list_t *tmp; struct liblustre_wait_callback *llwc; int found_something = 0; @@ -585,10 +663,11 @@ liblustre_wait_event (int timeout) 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); - + cfs_list_for_each(tmp, &liblustre_wait_callbacks) { + llwc = cfs_list_entry(tmp, + struct liblustre_wait_callback, + llwc_list); + if (llwc->llwc_fn(llwc->llwc_arg)) found_something = 1; } @@ -611,29 +690,30 @@ void liblustre_wait_idle(void) { static int recursed = 0; - - struct list_head *tmp; + + cfs_list_t *tmp; struct liblustre_wait_callback *llwc; int idle = 0; 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); - + cfs_list_for_each(tmp, &liblustre_idle_callbacks) { + llwc = cfs_list_entry(tmp, + struct liblustre_wait_callback, + llwc_list); + if (!llwc->llwc_fn(llwc->llwc_arg)) { idle = 0; break; } } - + } while (!idle); recursed = 0; @@ -650,14 +730,16 @@ int ptlrpc_init_portals(void) return -EIO; } #ifndef __KERNEL__ - liblustre_services_callback = + liblustre_services_callback = liblustre_register_wait_callback("liblustre_check_services", - &liblustre_check_services, NULL); + &liblustre_check_services, + NULL); + cfs_init_completion_module(liblustre_wait_event); #endif rc = ptlrpcd_addref(); if (rc == 0) return 0; - + CERROR("rpcd initialisation failed\n"); #ifndef __KERNEL__ liblustre_deregister_wait_callback(liblustre_services_callback);