4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LDLM
40 # include <libcfs/libcfs.h>
42 # include <liblustre.h>
45 #include <lustre_mds.h>
46 #include <lustre_dlm.h>
47 #include <lustre_net.h>
48 #include <lustre_sec.h>
49 #include "ldlm_internal.h"
51 /* @priority: if non-zero, move the selected to the list head
52 * @create: if zero, only search in existed connections
54 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
55 int priority, int create)
57 struct ptlrpc_connection *ptlrpc_conn;
58 struct obd_import_conn *imp_conn = NULL, *item;
62 if (!create && !priority) {
63 CDEBUG(D_HA, "Nothing to do\n");
67 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
69 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
74 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
76 GOTO(out_put, rc = -ENOMEM);
80 cfs_spin_lock(&imp->imp_lock);
81 cfs_list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
82 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
84 cfs_list_del(&item->oic_item);
85 cfs_list_add(&item->oic_item,
87 item->oic_last_attempt = 0;
89 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
90 imp, imp->imp_obd->obd_name, uuid->uuid,
91 (priority ? ", moved to head" : ""));
92 cfs_spin_unlock(&imp->imp_lock);
93 GOTO(out_free, rc = 0);
98 imp_conn->oic_conn = ptlrpc_conn;
99 imp_conn->oic_uuid = *uuid;
100 imp_conn->oic_last_attempt = 0;
102 cfs_list_add(&imp_conn->oic_item, &imp->imp_conn_list);
104 cfs_list_add_tail(&imp_conn->oic_item,
105 &imp->imp_conn_list);
106 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
107 imp, imp->imp_obd->obd_name, uuid->uuid,
108 (priority ? "head" : "tail"));
110 cfs_spin_unlock(&imp->imp_lock);
111 GOTO(out_free, rc = -ENOENT);
114 cfs_spin_unlock(&imp->imp_lock);
118 OBD_FREE(imp_conn, sizeof(*imp_conn));
120 ptlrpc_connection_put(ptlrpc_conn);
124 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
126 return import_set_conn(imp, uuid, 1, 0);
129 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
132 return import_set_conn(imp, uuid, priority, 1);
135 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
137 struct obd_import_conn *imp_conn;
138 struct obd_export *dlmexp;
142 cfs_spin_lock(&imp->imp_lock);
143 if (cfs_list_empty(&imp->imp_conn_list)) {
144 LASSERT(!imp->imp_connection);
148 cfs_list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
149 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
151 LASSERT(imp_conn->oic_conn);
153 /* is current conn? */
154 if (imp_conn == imp->imp_conn_current) {
155 LASSERT(imp_conn->oic_conn == imp->imp_connection);
157 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
158 imp->imp_state != LUSTRE_IMP_DISCON) {
159 CERROR("can't remove current connection\n");
160 GOTO(out, rc = -EBUSY);
163 ptlrpc_connection_put(imp->imp_connection);
164 imp->imp_connection = NULL;
166 dlmexp = class_conn2export(&imp->imp_dlm_handle);
167 if (dlmexp && dlmexp->exp_connection) {
168 LASSERT(dlmexp->exp_connection ==
170 ptlrpc_connection_put(dlmexp->exp_connection);
171 dlmexp->exp_connection = NULL;
175 cfs_list_del(&imp_conn->oic_item);
176 ptlrpc_connection_put(imp_conn->oic_conn);
177 OBD_FREE(imp_conn, sizeof(*imp_conn));
178 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
179 imp, imp->imp_obd->obd_name, uuid->uuid);
184 cfs_spin_unlock(&imp->imp_lock);
186 CERROR("connection %s not found\n", uuid->uuid);
191 * Find conn uuid by peer nid. @peer is a server nid. This function is used
192 * to find a conn uuid of @imp which can reach @peer.
194 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
195 struct obd_uuid *uuid)
197 struct obd_import_conn *conn;
201 cfs_spin_lock(&imp->imp_lock);
202 cfs_list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
203 /* check if conn uuid does have this peer nid */
204 if (class_check_uuid(&conn->oic_uuid, peer)) {
205 *uuid = conn->oic_uuid;
210 cfs_spin_unlock(&imp->imp_lock);
213 EXPORT_SYMBOL(client_import_find_conn);
215 void client_destroy_import(struct obd_import *imp)
217 /* drop security policy instance after all rpc finished/aborted
218 * to let all busy contexts be released. */
219 class_import_get(imp);
220 class_destroy_import(imp);
221 sptlrpc_import_sec_put(imp);
222 class_import_put(imp);
224 EXPORT_SYMBOL(client_destroy_import);
227 * check whether the osc is on MDT or not
230 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
232 * setup 0:{fsname}-OSTxxxx-osc 1:lustre-OST0000_UUID 2:NID
235 static int osc_on_mdt(char *obdname)
239 ptr = strrchr(obdname, '-');
243 if (strncmp(ptr + 1, "MDT", 3) == 0)
249 /* configure an RPC client OBD device
254 * 3 - inactive-on-startup
256 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
258 struct client_obd *cli = &obddev->u.cli;
259 struct obd_import *imp;
260 struct obd_uuid server_uuid;
261 int rq_portal, rp_portal, connect_op;
262 char *name = obddev->obd_type->typ_name;
263 ldlm_ns_type_t ns_type = LDLM_NS_TYPE_UNKNOWN;
267 /* In a more perfect world, we would hang a ptlrpc_client off of
268 * obd_type and just use the values from there. */
269 if (!strcmp(name, LUSTRE_OSC_NAME)) {
270 rq_portal = OST_REQUEST_PORTAL;
271 rp_portal = OSC_REPLY_PORTAL;
272 connect_op = OST_CONNECT;
273 cli->cl_sp_me = LUSTRE_SP_CLI;
274 cli->cl_sp_to = LUSTRE_SP_OST;
275 ns_type = LDLM_NS_TYPE_OSC;
277 } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
278 rq_portal = MDS_REQUEST_PORTAL;
279 rp_portal = MDC_REPLY_PORTAL;
280 connect_op = MDS_CONNECT;
281 cli->cl_sp_me = LUSTRE_SP_CLI;
282 cli->cl_sp_to = LUSTRE_SP_MDT;
283 ns_type = LDLM_NS_TYPE_MDC;
285 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
286 rq_portal = MGS_REQUEST_PORTAL;
287 rp_portal = MGC_REPLY_PORTAL;
288 connect_op = MGS_CONNECT;
289 cli->cl_sp_me = LUSTRE_SP_MGC;
290 cli->cl_sp_to = LUSTRE_SP_MGS;
291 cli->cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_INVALID;
292 ns_type = LDLM_NS_TYPE_MGC;
295 CERROR("unknown client OBD type \"%s\", can't setup\n",
300 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
301 CERROR("requires a TARGET UUID\n");
305 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
306 CERROR("client UUID must be less than 38 characters\n");
310 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
311 CERROR("setup requires a SERVER UUID\n");
315 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
316 CERROR("target UUID must be less than 38 characters\n");
320 cfs_init_rwsem(&cli->cl_sem);
321 cfs_sema_init(&cli->cl_mgc_sem, 1);
322 cli->cl_conn_count = 0;
323 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
324 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
325 sizeof(server_uuid)));
328 cli->cl_avail_grant = 0;
329 /* FIXME: should limit this for the sum of all cl_dirty_max */
330 cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
331 if (cli->cl_dirty_max >> CFS_PAGE_SHIFT > cfs_num_physpages / 8)
332 cli->cl_dirty_max = cfs_num_physpages << (CFS_PAGE_SHIFT - 3);
333 CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters);
334 CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list);
335 CFS_INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
336 CFS_INIT_LIST_HEAD(&cli->cl_loi_write_list);
337 CFS_INIT_LIST_HEAD(&cli->cl_loi_read_list);
338 client_obd_list_lock_init(&cli->cl_loi_list_lock);
339 cfs_atomic_set(&cli->cl_pending_w_pages, 0);
340 cfs_atomic_set(&cli->cl_pending_r_pages, 0);
341 cli->cl_r_in_flight = 0;
342 cli->cl_w_in_flight = 0;
344 cfs_spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
345 cfs_spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
346 cfs_spin_lock_init(&cli->cl_read_page_hist.oh_lock);
347 cfs_spin_lock_init(&cli->cl_write_page_hist.oh_lock);
348 cfs_spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
349 cfs_spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
350 cfs_waitq_init(&cli->cl_destroy_waitq);
351 cfs_atomic_set(&cli->cl_destroy_in_flight, 0);
352 #ifdef ENABLE_CHECKSUM
353 /* Turn on checksumming by default. */
354 cli->cl_checksum = 1;
356 * The supported checksum types will be worked out at connect time
357 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
360 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
362 cfs_atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
364 /* This value may be changed at connect time in
365 ptlrpc_connect_interpret. */
366 cli->cl_max_pages_per_rpc = min((int)PTLRPC_MAX_BRW_PAGES,
367 (int)(1024 * 1024 >> CFS_PAGE_SHIFT));
369 if (!strcmp(name, LUSTRE_MDC_NAME)) {
370 cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT;
371 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 128 /* MB */) {
372 cli->cl_max_rpcs_in_flight = 2;
373 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 256 /* MB */) {
374 cli->cl_max_rpcs_in_flight = 3;
375 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 512 /* MB */) {
376 cli->cl_max_rpcs_in_flight = 4;
378 if (osc_on_mdt(obddev->obd_name))
379 cli->cl_max_rpcs_in_flight = MDS_OSC_MAX_RIF_DEFAULT;
381 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
385 CERROR("ldlm_get_ref failed: %d\n", rc);
389 ptlrpc_init_client(rq_portal, rp_portal, name,
390 &obddev->obd_ldlm_client);
392 imp = class_new_import(obddev);
394 GOTO(err_ldlm, rc = -ENOENT);
395 imp->imp_client = &obddev->obd_ldlm_client;
396 imp->imp_connect_op = connect_op;
397 CFS_INIT_LIST_HEAD(&imp->imp_pinger_chain);
398 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
399 LUSTRE_CFG_BUFLEN(lcfg, 1));
400 class_import_put(imp);
402 rc = client_import_add_conn(imp, &server_uuid, 1);
404 CERROR("can't add initial connection\n");
405 GOTO(err_import, rc);
408 cli->cl_import = imp;
409 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
410 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
411 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
413 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
414 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
415 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
416 name, obddev->obd_name,
417 cli->cl_target_uuid.uuid);
418 cfs_spin_lock(&imp->imp_lock);
419 imp->imp_deactive = 1;
420 cfs_spin_unlock(&imp->imp_lock);
424 obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
425 LDLM_NAMESPACE_CLIENT,
426 LDLM_NAMESPACE_GREEDY,
428 if (obddev->obd_namespace == NULL) {
429 CERROR("Unable to create client namespace - %s\n",
431 GOTO(err_import, rc = -ENOMEM);
434 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
439 class_destroy_import(imp);
447 int client_obd_cleanup(struct obd_device *obddev)
451 ldlm_namespace_free_post(obddev->obd_namespace);
452 obddev->obd_namespace = NULL;
454 LASSERT(obddev->u.cli.cl_import == NULL);
460 /* ->o_connect() method for client side (OSC and MDC and MGC) */
461 int client_connect_import(const struct lu_env *env,
462 struct obd_export **exp,
463 struct obd_device *obd, struct obd_uuid *cluuid,
464 struct obd_connect_data *data, void *localdata)
466 struct client_obd *cli = &obd->u.cli;
467 struct obd_import *imp = cli->cl_import;
468 struct obd_connect_data *ocd;
469 struct lustre_handle conn = { 0 };
474 cfs_down_write(&cli->cl_sem);
475 if (cli->cl_conn_count > 0 )
476 GOTO(out_sem, rc = -EALREADY);
478 rc = class_connect(&conn, obd, cluuid);
482 cli->cl_conn_count++;
483 *exp = class_conn2export(&conn);
485 LASSERT(obd->obd_namespace);
487 imp->imp_dlm_handle = conn;
488 rc = ptlrpc_init_import(imp);
492 ocd = &imp->imp_connect_data;
495 imp->imp_connect_flags_orig = data->ocd_connect_flags;
498 rc = ptlrpc_connect_import(imp);
500 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
503 LASSERT((*exp)->exp_connection);
506 LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
507 ocd->ocd_connect_flags, "old "LPX64", new "LPX64"\n",
508 data->ocd_connect_flags, ocd->ocd_connect_flags);
509 data->ocd_connect_flags = ocd->ocd_connect_flags;
512 ptlrpc_pinger_add_import(imp);
518 cli->cl_conn_count--;
519 class_disconnect(*exp);
523 cfs_up_write(&cli->cl_sem);
528 int client_disconnect_export(struct obd_export *exp)
530 struct obd_device *obd = class_exp2obd(exp);
531 struct client_obd *cli;
532 struct obd_import *imp;
537 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
538 exp, exp ? exp->exp_handle.h_cookie : -1);
543 imp = cli->cl_import;
545 cfs_down_write(&cli->cl_sem);
546 CDEBUG(D_INFO, "disconnect %s - %d\n", obd->obd_name,
549 if (!cli->cl_conn_count) {
550 CERROR("disconnecting disconnected device (%s)\n",
552 GOTO(out_disconnect, rc = -EINVAL);
555 cli->cl_conn_count--;
556 if (cli->cl_conn_count)
557 GOTO(out_disconnect, rc = 0);
559 /* Mark import deactivated now, so we don't try to reconnect if any
560 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
561 * fully deactivate the import, or that would drop all requests. */
562 cfs_spin_lock(&imp->imp_lock);
563 imp->imp_deactive = 1;
564 cfs_spin_unlock(&imp->imp_lock);
566 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
567 * delete it regardless. (It's safe to delete an import that was
569 (void)ptlrpc_pinger_del_import(imp);
571 if (obd->obd_namespace != NULL) {
572 /* obd_force == local only */
573 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
574 obd->obd_force ? LCF_LOCAL : 0, NULL);
575 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force);
579 * there's no need to hold sem during disconnecting an import,
580 * and actually it may cause deadlock in gss.
582 cfs_up_write(&cli->cl_sem);
583 rc = ptlrpc_disconnect_import(imp, 0);
584 cfs_down_write(&cli->cl_sem);
586 ptlrpc_invalidate_import(imp);
591 /* use server style - class_disconnect should be always called for
593 err = class_disconnect(exp);
597 cfs_up_write(&cli->cl_sem);
602 #ifdef HAVE_SERVER_SUPPORT
603 int server_disconnect_export(struct obd_export *exp)
608 /* Disconnect early so that clients can't keep using export */
609 rc = class_disconnect(exp);
610 /* close import for avoid sending any requests */
611 if (exp->exp_imp_reverse)
612 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
614 if (exp->exp_obd->obd_namespace != NULL)
615 ldlm_cancel_locks_for_export(exp);
617 /* complete all outstanding replies */
618 cfs_spin_lock(&exp->exp_lock);
619 while (!cfs_list_empty(&exp->exp_outstanding_replies)) {
620 struct ptlrpc_reply_state *rs =
621 cfs_list_entry(exp->exp_outstanding_replies.next,
622 struct ptlrpc_reply_state, rs_exp_list);
623 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
625 cfs_spin_lock(&svcpt->scp_rep_lock);
627 cfs_list_del_init(&rs->rs_exp_list);
628 cfs_spin_lock(&rs->rs_lock);
629 ptlrpc_schedule_difficult_reply(rs);
630 cfs_spin_unlock(&rs->rs_lock);
632 cfs_spin_unlock(&svcpt->scp_rep_lock);
634 cfs_spin_unlock(&exp->exp_lock);
639 /* --------------------------------------------------------------------------
640 * from old lib/target.c
641 * -------------------------------------------------------------------------- */
643 static int target_handle_reconnect(struct lustre_handle *conn,
644 struct obd_export *exp,
645 struct obd_uuid *cluuid)
649 if (exp->exp_connection && exp->exp_imp_reverse) {
650 struct lustre_handle *hdl;
651 struct obd_device *target;
653 hdl = &exp->exp_imp_reverse->imp_remote_handle;
654 target = exp->exp_obd;
656 /* Might be a re-connect after a partition. */
657 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
658 if (target->obd_recovering) {
659 int timeout = cfs_duration_sec(cfs_time_sub(
661 &target->obd_recovery_timer),
662 cfs_time_current()));
664 LCONSOLE_WARN("%s: Client %s (at %s) reconnect"
665 "ing, waiting for %d clients in recov"
666 "ery for %d:%.02d\n", target->obd_name,
667 obd_uuid2str(&exp->exp_client_uuid),
668 obd_export_nid2str(exp),
669 target->obd_max_recoverable_clients,
670 timeout / 60, timeout % 60);
672 LCONSOLE_WARN("%s: Client %s (at %s) "
673 "reconnecting\n", target->obd_name,
674 obd_uuid2str(&exp->exp_client_uuid),
675 obd_export_nid2str(exp));
678 conn->cookie = exp->exp_handle.h_cookie;
679 /* target_handle_connect() treats EALREADY and
680 * -EALREADY differently. EALREADY means we are
681 * doing a valid reconnect from the same client. */
684 LCONSOLE_WARN("%s: already connected client %s (at %s) "
685 "with handle "LPX64". Rejecting client "
686 "with the same UUID trying to reconnect "
687 "with handle "LPX64"\n", target->obd_name,
688 obd_uuid2str(&exp->exp_client_uuid),
689 obd_export_nid2str(exp),
690 hdl->cookie, conn->cookie);
691 memset(conn, 0, sizeof *conn);
692 /* target_handle_connect() treats EALREADY and
693 * -EALREADY differently. -EALREADY is an error
694 * (same UUID, different handle). */
699 conn->cookie = exp->exp_handle.h_cookie;
700 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
701 cluuid->uuid, exp, conn->cookie);
705 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
708 struct obd_export *exp = cb_data;
710 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
711 obd->obd_name, exp->exp_client_uuid.uuid);
713 cfs_spin_lock(&exp->exp_lock);
714 exp->exp_need_sync = 0;
715 cfs_spin_unlock(&exp->exp_lock);
716 class_export_cb_put(exp);
718 EXPORT_SYMBOL(target_client_add_cb);
722 check_and_start_recovery_timer(struct obd_device *obd,
723 struct ptlrpc_request *req, int new_client);
726 check_and_start_recovery_timer(struct obd_device *obd,
727 struct ptlrpc_request *req, int new_client)
732 int target_handle_connect(struct ptlrpc_request *req)
734 struct obd_device *target, *targref = NULL;
735 struct obd_export *export = NULL;
736 struct obd_import *revimp;
737 struct lustre_handle conn;
738 struct lustre_handle *tmp;
739 struct obd_uuid tgtuuid;
740 struct obd_uuid cluuid;
741 struct obd_uuid remote_uuid;
747 struct obd_connect_data *data, *tmpdata;
749 lnet_nid_t *client_nid = NULL;
752 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
754 str = req_capsule_client_get(&req->rq_pill, &RMF_TGTUUID);
756 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
757 GOTO(out, rc = -EINVAL);
760 obd_str2uuid(&tgtuuid, str);
761 target = class_uuid2obd(&tgtuuid);
763 target = class_name2obd(str);
765 if (!target || target->obd_stopping || !target->obd_set_up) {
766 deuuidify(str, NULL, &target_start, &target_len);
767 LCONSOLE_ERROR_MSG(0x137, "%.*s: Not available for connect "
768 "from %s (%s)\n", target_len, target_start,
769 libcfs_nid2str(req->rq_peer.nid), !target ?
770 "no target" : (target->obd_stopping ?
771 "stopping" : "not set up"));
772 GOTO(out, rc = -ENODEV);
775 if (target->obd_no_conn) {
776 LCONSOLE_WARN("%s: Temporarily refusing client connection "
777 "from %s\n", target->obd_name,
778 libcfs_nid2str(req->rq_peer.nid));
779 GOTO(out, rc = -EAGAIN);
782 /* Make sure the target isn't cleaned up while we're here. Yes,
783 there's still a race between the above check and our incref here.
784 Really, class_uuid2obd should take the ref. */
785 targref = class_incref(target, __FUNCTION__, cfs_current());
788 str = req_capsule_client_get(&req->rq_pill, &RMF_CLUUID);
790 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
791 GOTO(out, rc = -EINVAL);
794 obd_str2uuid(&cluuid, str);
796 /* XXX extract a nettype and format accordingly */
797 switch (sizeof(lnet_nid_t)) {
798 /* NB the casts only avoid compiler warnings */
800 snprintf(remote_uuid.uuid, sizeof remote_uuid,
801 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
804 snprintf(remote_uuid.uuid, sizeof remote_uuid,
805 "NET_%x_UUID", (__u32)req->rq_peer.nid);
811 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
813 GOTO(out, rc = -EPROTO);
817 size = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
819 data = req_capsule_client_get(&req->rq_pill, &RMF_CONNECT_DATA);
821 GOTO(out, rc = -EPROTO);
823 rc = req_capsule_server_pack(&req->rq_pill);
827 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
829 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
830 "libclient connection attempt");
831 GOTO(out, rc = -EPROTO);
832 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
833 LUSTRE_VERSION_ALLOWED_OFFSET ||
834 data->ocd_version > LUSTRE_VERSION_CODE +
835 LUSTRE_VERSION_ALLOWED_OFFSET) {
836 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
837 "libclient connection attempt",
838 data->ocd_version < LUSTRE_VERSION_CODE ?
840 OBD_OCD_VERSION_MAJOR(data->ocd_version),
841 OBD_OCD_VERSION_MINOR(data->ocd_version),
842 OBD_OCD_VERSION_PATCH(data->ocd_version),
843 OBD_OCD_VERSION_FIX(data->ocd_version));
844 data = req_capsule_server_sized_get(&req->rq_pill,
846 offsetof(typeof(*data), ocd_version) +
847 sizeof(data->ocd_version));
849 data->ocd_connect_flags = OBD_CONNECT_VERSION;
850 data->ocd_version = LUSTRE_VERSION_CODE;
852 GOTO(out, rc = -EPROTO);
856 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) &&
857 (data->ocd_connect_flags & OBD_CONNECT_MDS))
860 /* lctl gets a backstage, all-access pass. */
861 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
862 goto dont_check_exports;
864 export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
868 /* we've found an export in the hash */
869 if (export->exp_connecting) { /* bug 9635, et. al. */
870 LCONSOLE_WARN("%s: Export %p already connecting from %s\n",
871 export->exp_obd->obd_name, export,
872 libcfs_nid2str(req->rq_peer.nid));
873 class_export_put(export);
876 } else if (mds_conn && export->exp_connection) {
877 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
878 /* mds reconnected after failover */
879 LCONSOLE_WARN("%s: Received MDS connection from "
880 "%s, removing former export from %s\n",
881 target->obd_name, libcfs_nid2str(req->rq_peer.nid),
882 libcfs_nid2str(export->exp_connection->c_peer.nid));
884 /* new mds connection from the same nid */
885 LCONSOLE_WARN("%s: Received new MDS connection from "
886 "%s, removing former export from same NID\n",
887 target->obd_name, libcfs_nid2str(req->rq_peer.nid));
888 class_fail_export(export);
889 class_export_put(export);
892 } else if (export->exp_connection != NULL &&
893 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
894 (lustre_msg_get_op_flags(req->rq_reqmsg) &
895 MSG_CONNECT_INITIAL)) {
896 /* in mds failover we have static uuid but nid can be
898 LCONSOLE_WARN("%s: Client %s seen on new nid %s when "
899 "existing nid %s is already connected\n",
900 target->obd_name, cluuid.uuid,
901 libcfs_nid2str(req->rq_peer.nid),
903 export->exp_connection->c_peer.nid));
905 class_export_put(export);
908 cfs_spin_lock(&export->exp_lock);
909 export->exp_connecting = 1;
910 cfs_spin_unlock(&export->exp_lock);
911 LASSERT(export->exp_obd == target);
913 rc = target_handle_reconnect(&conn, export, &cluuid);
916 /* If we found an export, we already unlocked. */
919 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
920 } else if (req->rq_export == NULL &&
921 cfs_atomic_read(&export->exp_rpc_count) > 0) {
922 LCONSOLE_WARN("%s: Client %s (at %s) refused connection, "
923 "still busy with %d references\n",
924 target->obd_name, cluuid.uuid,
925 libcfs_nid2str(req->rq_peer.nid),
926 cfs_atomic_read(&export->exp_refcount));
927 GOTO(out, rc = -EBUSY);
928 } else if (req->rq_export != NULL &&
929 (cfs_atomic_read(&export->exp_rpc_count) > 1)) {
930 /* the current connect rpc has increased exp_rpc_count */
931 LCONSOLE_WARN("%s: Client %s (at %s) refused reconnection, "
932 "still busy with %d active RPCs\n",
933 target->obd_name, cluuid.uuid,
934 libcfs_nid2str(req->rq_peer.nid),
935 cfs_atomic_read(&export->exp_rpc_count) - 1);
936 cfs_spin_lock(&export->exp_lock);
937 if (req->rq_export->exp_conn_cnt <
938 lustre_msg_get_conn_cnt(req->rq_reqmsg))
939 /* try to abort active requests */
940 req->rq_export->exp_abort_active_req = 1;
941 cfs_spin_unlock(&export->exp_lock);
942 GOTO(out, rc = -EBUSY);
943 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
944 if (!strstr(cluuid.uuid, "mdt"))
945 LCONSOLE_WARN("%s: Rejecting reconnect from the "
946 "known client %s (at %s) because it "
947 "is indicating it is a new client",
948 target->obd_name, cluuid.uuid,
949 libcfs_nid2str(req->rq_peer.nid));
950 GOTO(out, rc = -EALREADY);
952 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
959 CDEBUG(D_HA, "%s: connection from %s@%s %st"LPU64" exp %p cur %ld last %ld\n",
960 target->obd_name, cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
961 target->obd_recovering ? "recovering/" : "", data->ocd_transno,
962 export, (long)cfs_time_current_sec(),
963 export ? (long)export->exp_last_request_time : 0);
965 /* If this is the first time a client connects, reset the recovery
967 if (rc == 0 && target->obd_recovering)
968 check_and_start_recovery_timer(target, req, export == NULL);
970 /* We want to handle EALREADY but *not* -EALREADY from
971 * target_handle_reconnect(), return reconnection state in a flag */
972 if (rc == EALREADY) {
973 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
979 /* Tell the client if we support replayable requests */
980 if (target->obd_replayable)
981 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
982 client_nid = &req->rq_peer.nid;
984 if (export == NULL) {
985 if (target->obd_recovering) {
988 t = cfs_timer_deadline(&target->obd_recovery_timer);
989 t = cfs_time_sub(t, cfs_time_current());
990 t = cfs_duration_sec(t);
991 LCONSOLE_WARN("%s: Denying connection for new client "
992 "%s (at %s), waiting for %d clients in "
993 "recovery for %d:%.02d\n",
995 libcfs_nid2str(req->rq_peer.nid),
997 cfs_atomic_read(&target-> \
998 obd_lock_replay_clients),
999 (int)t / 60, (int)t % 60);
1003 rc = obd_connect(req->rq_svc_thread->t_env,
1004 &export, target, &cluuid, data,
1007 conn.cookie = export->exp_handle.h_cookie;
1008 /* LU-1092 reconnect put export refcount in the
1009 * end, connect needs take one here too. */
1010 class_export_get(export);
1014 rc = obd_reconnect(req->rq_svc_thread->t_env,
1015 export, target, &cluuid, data, client_nid);
1017 /* prevous done via class_conn2export */
1018 class_export_get(export);
1023 LASSERT(target->u.obt.obt_magic == OBT_MAGIC);
1024 data->ocd_instance = target->u.obt.obt_instance;
1026 /* Return only the parts of obd_connect_data that we understand, so the
1027 * client knows that we don't understand the rest. */
1029 tmpsize = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
1031 tmpdata = req_capsule_server_get(&req->rq_pill,
1033 /* Don't use struct assignment here, because the client reply
1034 * buffer may be smaller/larger than the local struct
1035 * obd_connect_data. */
1036 memcpy(tmpdata, data, min(tmpsize, size));
1039 /* If all else goes well, this is our RPC return code. */
1042 lustre_msg_set_handle(req->rq_repmsg, &conn);
1044 /* If the client and the server are the same node, we will already
1045 * have an export that really points to the client's DLM export,
1046 * because we have a shared handles table.
1048 * XXX this will go away when shaver stops sending the "connect" handle
1049 * in the real "remote handle" field of the request --phik 24 Apr 2003
1051 if (req->rq_export != NULL)
1052 class_export_put(req->rq_export);
1054 req->rq_export = export;
1056 cfs_spin_lock(&export->exp_lock);
1057 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
1058 cfs_spin_unlock(&export->exp_lock);
1059 CDEBUG(D_RPCTRACE, "%s: %s already connected at higher "
1060 "conn_cnt: %d > %d\n",
1061 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1062 export->exp_conn_cnt,
1063 lustre_msg_get_conn_cnt(req->rq_reqmsg));
1065 GOTO(out, rc = -EALREADY);
1067 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1068 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1069 export->exp_abort_active_req = 0;
1071 /* request from liblustre? Don't evict it for not pinging. */
1072 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1073 export->exp_libclient = 1;
1074 cfs_spin_unlock(&export->exp_lock);
1076 cfs_spin_lock(&target->obd_dev_lock);
1077 cfs_list_del_init(&export->exp_obd_chain_timed);
1078 cfs_spin_unlock(&target->obd_dev_lock);
1080 cfs_spin_unlock(&export->exp_lock);
1083 if (export->exp_connection != NULL) {
1084 /* Check to see if connection came from another NID */
1085 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1086 !cfs_hlist_unhashed(&export->exp_nid_hash))
1087 cfs_hash_del(export->exp_obd->obd_nid_hash,
1088 &export->exp_connection->c_peer.nid,
1089 &export->exp_nid_hash);
1091 ptlrpc_connection_put(export->exp_connection);
1094 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1097 if (cfs_hlist_unhashed(&export->exp_nid_hash)) {
1098 cfs_hash_add(export->exp_obd->obd_nid_hash,
1099 &export->exp_connection->c_peer.nid,
1100 &export->exp_nid_hash);
1103 class_disconnect->class_export_recovery_cleanup() race
1105 if (target->obd_recovering && !export->exp_in_recovery) {
1107 __u64 transno = data->ocd_transno;
1109 cfs_spin_lock(&export->exp_lock);
1110 export->exp_in_recovery = 1;
1111 export->exp_req_replay_needed = 1;
1112 export->exp_lock_replay_needed = 1;
1113 cfs_spin_unlock(&export->exp_lock);
1115 has_transno = !!(lustre_msg_get_op_flags(req->rq_reqmsg) &
1116 MSG_CONNECT_TRANSNO);
1117 if (has_transno && transno == 0)
1118 CWARN("Connect with zero transno!\n");
1120 if (has_transno && transno > 0 &&
1121 transno < target->obd_next_recovery_transno &&
1122 transno > target->obd_last_committed) {
1123 /* another way is to use cmpxchg() so it will be
1125 cfs_spin_lock(&target->obd_recovery_task_lock);
1126 if (transno < target->obd_next_recovery_transno)
1127 target->obd_next_recovery_transno = transno;
1128 cfs_spin_unlock(&target->obd_recovery_task_lock);
1131 cfs_atomic_inc(&target->obd_req_replay_clients);
1132 cfs_atomic_inc(&target->obd_lock_replay_clients);
1133 if (cfs_atomic_inc_return(&target->obd_connected_clients) ==
1134 target->obd_max_recoverable_clients)
1135 cfs_waitq_signal(&target->obd_next_transno_waitq);
1138 /* Tell the client we're in recovery, when client is involved in it. */
1139 if (target->obd_recovering)
1140 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
1142 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
1145 if (export->exp_imp_reverse != NULL) {
1146 /* destroyed import can be still referenced in ctxt */
1147 obd_set_info_async(req->rq_svc_thread->t_env, export,
1148 sizeof(KEY_REVIMP_UPD), KEY_REVIMP_UPD,
1151 client_destroy_import(export->exp_imp_reverse);
1154 /* for the rest part, we return -ENOTCONN in case of errors
1155 * in order to let client initialize connection again.
1157 revimp = export->exp_imp_reverse = class_new_import(target);
1159 CERROR("fail to alloc new reverse import.\n");
1160 GOTO(out, rc = -ENOTCONN);
1163 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1164 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1165 revimp->imp_remote_handle = conn;
1166 revimp->imp_dlm_fake = 1;
1167 revimp->imp_state = LUSTRE_IMP_FULL;
1169 /* unknown versions will be caught in
1170 * ptlrpc_handle_server_req_in->lustre_unpack_msg() */
1171 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1173 if ((export->exp_connect_flags & OBD_CONNECT_AT) &&
1174 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1175 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1177 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1179 if ((export->exp_connect_flags & OBD_CONNECT_FULL20) &&
1180 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1181 revimp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
1183 revimp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18;
1185 rc = sptlrpc_import_sec_adapt(revimp, req->rq_svc_ctx, &req->rq_flvr);
1187 CERROR("Failed to get sec for reverse import: %d\n", rc);
1188 export->exp_imp_reverse = NULL;
1189 class_destroy_import(revimp);
1192 class_import_put(revimp);
1195 cfs_spin_lock(&export->exp_lock);
1196 export->exp_connecting = 0;
1197 cfs_spin_unlock(&export->exp_lock);
1199 class_export_put(export);
1202 class_decref(targref, __FUNCTION__, cfs_current());
1204 req->rq_status = rc;
1208 int target_handle_disconnect(struct ptlrpc_request *req)
1213 rc = req_capsule_server_pack(&req->rq_pill);
1217 /* keep the rq_export around so we can send the reply */
1218 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1223 void target_destroy_export(struct obd_export *exp)
1225 /* exports created from last_rcvd data, and "fake"
1226 exports created by lctl don't have an import */
1227 if (exp->exp_imp_reverse != NULL)
1228 client_destroy_import(exp->exp_imp_reverse);
1230 LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
1231 LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
1232 LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
1233 LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
1237 * Recovery functions
1239 static void target_request_copy_get(struct ptlrpc_request *req)
1241 class_export_rpc_get(req->rq_export);
1242 LASSERT(cfs_list_empty(&req->rq_list));
1243 CFS_INIT_LIST_HEAD(&req->rq_replay_list);
1245 /* increase refcount to keep request in queue */
1246 cfs_atomic_inc(&req->rq_refcount);
1247 /** let export know it has replays to be handled */
1248 cfs_atomic_inc(&req->rq_export->exp_replay_count);
1251 static void target_request_copy_put(struct ptlrpc_request *req)
1253 LASSERT(cfs_list_empty(&req->rq_replay_list));
1254 LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
1256 cfs_atomic_dec(&req->rq_export->exp_replay_count);
1257 class_export_rpc_put(req->rq_export);
1258 ptlrpc_server_drop_request(req);
1261 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1263 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1264 struct obd_export *exp = req->rq_export;
1265 struct ptlrpc_request *reqiter;
1270 cfs_spin_lock(&exp->exp_lock);
1271 cfs_list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1273 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1280 /* we expect it with RESENT and REPLAY flags */
1281 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1282 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1283 CERROR("invalid flags %x of resent replay\n",
1284 lustre_msg_get_flags(req->rq_reqmsg));
1286 cfs_list_add_tail(&req->rq_replay_list,
1287 &exp->exp_req_replay_queue);
1290 cfs_spin_unlock(&exp->exp_lock);
1294 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1296 LASSERT(!cfs_list_empty(&req->rq_replay_list));
1297 LASSERT(req->rq_export);
1299 cfs_spin_lock(&req->rq_export->exp_lock);
1300 cfs_list_del_init(&req->rq_replay_list);
1301 cfs_spin_unlock(&req->rq_export->exp_lock);
1305 static void target_finish_recovery(struct obd_device *obd)
1307 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1308 obd->obd_recovery_start);
1311 LCONSOLE_INFO("%s: Recovery over after %d:%.02d, of %d clients "
1312 "%d recovered and %d %s evicted.\n", obd->obd_name,
1313 (int)elapsed_time / 60, (int)elapsed_time % 60,
1314 obd->obd_max_recoverable_clients,
1315 cfs_atomic_read(&obd->obd_connected_clients),
1316 obd->obd_stale_clients,
1317 obd->obd_stale_clients == 1 ? "was" : "were");
1319 ldlm_reprocess_all_ns(obd->obd_namespace);
1320 cfs_spin_lock(&obd->obd_recovery_task_lock);
1321 if (!cfs_list_empty(&obd->obd_req_replay_queue) ||
1322 !cfs_list_empty(&obd->obd_lock_replay_queue) ||
1323 !cfs_list_empty(&obd->obd_final_req_queue)) {
1324 CERROR("%s: Recovery queues ( %s%s%s) are not empty\n",
1326 cfs_list_empty(&obd->obd_req_replay_queue) ? "" : "req ",
1327 cfs_list_empty(&obd->obd_lock_replay_queue) ? \
1329 cfs_list_empty(&obd->obd_final_req_queue) ? \
1331 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1334 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1336 obd->obd_recovery_end = cfs_time_current_sec();
1338 /* when recovery finished, cleanup orphans on mds and ost */
1339 if (OBT(obd) && OBP(obd, postrecov)) {
1340 int rc = OBP(obd, postrecov)(obd);
1342 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1348 static void abort_req_replay_queue(struct obd_device *obd)
1350 struct ptlrpc_request *req, *n;
1351 cfs_list_t abort_list;
1353 CFS_INIT_LIST_HEAD(&abort_list);
1354 cfs_spin_lock(&obd->obd_recovery_task_lock);
1355 cfs_list_splice_init(&obd->obd_req_replay_queue, &abort_list);
1356 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1357 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1358 DEBUG_REQ(D_WARNING, req, "aborted:");
1359 req->rq_status = -ENOTCONN;
1360 if (ptlrpc_error(req)) {
1361 DEBUG_REQ(D_ERROR, req,
1362 "failed abort_req_reply; skipping");
1364 target_exp_dequeue_req_replay(req);
1365 target_request_copy_put(req);
1369 static void abort_lock_replay_queue(struct obd_device *obd)
1371 struct ptlrpc_request *req, *n;
1372 cfs_list_t abort_list;
1374 CFS_INIT_LIST_HEAD(&abort_list);
1375 cfs_spin_lock(&obd->obd_recovery_task_lock);
1376 cfs_list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
1377 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1378 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list){
1379 DEBUG_REQ(D_ERROR, req, "aborted:");
1380 req->rq_status = -ENOTCONN;
1381 if (ptlrpc_error(req)) {
1382 DEBUG_REQ(D_ERROR, req,
1383 "failed abort_lock_reply; skipping");
1385 target_request_copy_put(req);
1389 /* Called from a cleanup function if the device is being cleaned up
1390 forcefully. The exports should all have been disconnected already,
1391 the only thing left to do is
1392 - clear the recovery flags
1394 - free queued requests and replies, but don't send replies
1395 Because the obd_stopping flag is set, no new requests should be received.
1398 void target_cleanup_recovery(struct obd_device *obd)
1400 struct ptlrpc_request *req, *n;
1401 cfs_list_t clean_list;
1404 CFS_INIT_LIST_HEAD(&clean_list);
1405 cfs_spin_lock(&obd->obd_dev_lock);
1406 if (!obd->obd_recovering) {
1407 cfs_spin_unlock(&obd->obd_dev_lock);
1411 obd->obd_recovering = obd->obd_abort_recovery = 0;
1412 cfs_spin_unlock(&obd->obd_dev_lock);
1414 cfs_spin_lock(&obd->obd_recovery_task_lock);
1415 target_cancel_recovery_timer(obd);
1416 cfs_list_splice_init(&obd->obd_req_replay_queue, &clean_list);
1417 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1419 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1420 LASSERT(req->rq_reply_state == 0);
1421 target_exp_dequeue_req_replay(req);
1422 target_request_copy_put(req);
1425 cfs_spin_lock(&obd->obd_recovery_task_lock);
1426 cfs_list_splice_init(&obd->obd_lock_replay_queue, &clean_list);
1427 cfs_list_splice_init(&obd->obd_final_req_queue, &clean_list);
1428 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1430 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list){
1431 LASSERT(req->rq_reply_state == 0);
1432 target_request_copy_put(req);
1438 /* obd_recovery_task_lock should be held */
1439 void target_cancel_recovery_timer(struct obd_device *obd)
1441 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1442 cfs_timer_disarm(&obd->obd_recovery_timer);
1445 static void target_start_recovery_timer(struct obd_device *obd)
1447 if (obd->obd_recovery_start != 0)
1450 cfs_spin_lock(&obd->obd_dev_lock);
1451 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1452 cfs_spin_unlock(&obd->obd_dev_lock);
1456 LASSERT(obd->obd_recovery_timeout != 0);
1458 if (obd->obd_recovery_start != 0) {
1459 cfs_spin_unlock(&obd->obd_dev_lock);
1463 cfs_timer_arm(&obd->obd_recovery_timer,
1464 cfs_time_shift(obd->obd_recovery_timeout));
1465 obd->obd_recovery_start = cfs_time_current_sec();
1466 cfs_spin_unlock(&obd->obd_dev_lock);
1468 LCONSOLE_WARN("%s: Will be in recovery for at least %d:%.02d, "
1469 "or until %d client%s reconnect%s\n",
1471 obd->obd_recovery_timeout / 60,
1472 obd->obd_recovery_timeout % 60,
1473 obd->obd_max_recoverable_clients,
1474 (obd->obd_max_recoverable_clients == 1) ? "" : "s",
1475 (obd->obd_max_recoverable_clients == 1) ? "s": "");
1479 * extend recovery window.
1481 * if @extend is true, extend recovery window to have @drt remaining at least;
1482 * otherwise, make sure the recovery timeout value is not less than @drt.
1484 static void extend_recovery_timer(struct obd_device *obd, int drt, bool extend)
1488 cfs_duration_t left;
1491 cfs_spin_lock(&obd->obd_dev_lock);
1492 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1493 cfs_spin_unlock(&obd->obd_dev_lock);
1496 LASSERT(obd->obd_recovery_start != 0);
1498 now = cfs_time_current_sec();
1499 to = obd->obd_recovery_timeout;
1500 end = obd->obd_recovery_start + to;
1501 left = cfs_time_sub(end, now);
1503 if (extend && (drt > left)) {
1505 } else if (!extend && (drt > to)) {
1507 /* reduce drt by already passed time */
1508 drt -= obd->obd_recovery_timeout - left;
1511 if (to > obd->obd_recovery_time_hard)
1512 to = obd->obd_recovery_time_hard;
1513 if (obd->obd_recovery_timeout < to) {
1514 obd->obd_recovery_timeout = to;
1515 cfs_timer_arm(&obd->obd_recovery_timer,
1516 cfs_time_shift(drt));
1518 cfs_spin_unlock(&obd->obd_dev_lock);
1520 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1521 obd->obd_name, (unsigned)drt);
1524 /* Reset the timer with each new client connection */
1526 * This timer is actually reconnect_timer, which is for making sure
1527 * the total recovery window is at least as big as my reconnect
1528 * attempt timing. So the initial recovery time_out will be set to
1529 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1530 * from client is bigger than this, then the recovery time_out will
1531 * be extended to make sure the client could be reconnected, in the
1532 * process, the timeout from the new client should be ignored.
1536 check_and_start_recovery_timer(struct obd_device *obd,
1537 struct ptlrpc_request *req,
1540 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1541 struct obd_device_target *obt = &obd->u.obt;
1542 struct lustre_sb_info *lsi;
1544 if (!new_client && service_time)
1545 /* Teach server about old server's estimates, as first guess
1546 * at how long new requests will take. */
1547 at_measured(&req->rq_rqbd->rqbd_svcpt->scp_at_estimate,
1550 target_start_recovery_timer(obd);
1552 /* convert the service time to rpc timeout,
1553 * reuse service_time to limit stack usage */
1554 service_time = at_est2timeout(service_time);
1556 /* We expect other clients to timeout within service_time, then try
1557 * to reconnect, then try the failover server. The max delay between
1558 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL */
1559 service_time += 2 * INITIAL_CONNECT_TIMEOUT;
1561 LASSERT(obt->obt_magic == OBT_MAGIC);
1562 lsi = s2lsi(obt->obt_sb);
1563 if (!(lsi->lsi_flags | LSI_IR_CAPABLE))
1564 service_time += 2 * (CONNECTION_SWITCH_MAX +
1565 CONNECTION_SWITCH_INC);
1566 if (service_time > obd->obd_recovery_timeout && !new_client)
1567 extend_recovery_timer(obd, service_time, false);
1570 /** Health checking routines */
1571 static inline int exp_connect_healthy(struct obd_export *exp)
1573 return (exp->exp_in_recovery);
1576 /** if export done req_replay or has replay in queue */
1577 static inline int exp_req_replay_healthy(struct obd_export *exp)
1579 return (!exp->exp_req_replay_needed ||
1580 cfs_atomic_read(&exp->exp_replay_count) > 0);
1582 /** if export done lock_replay or has replay in queue */
1583 static inline int exp_lock_replay_healthy(struct obd_export *exp)
1585 return (!exp->exp_lock_replay_needed ||
1586 cfs_atomic_read(&exp->exp_replay_count) > 0);
1589 static inline int exp_vbr_healthy(struct obd_export *exp)
1591 return (!exp->exp_vbr_failed);
1594 static inline int exp_finished(struct obd_export *exp)
1596 return (exp->exp_in_recovery && !exp->exp_lock_replay_needed);
1599 /** Checking routines for recovery */
1600 static int check_for_clients(struct obd_device *obd)
1602 unsigned int clnts = cfs_atomic_read(&obd->obd_connected_clients);
1604 if (obd->obd_abort_recovery || obd->obd_recovery_expired)
1606 LASSERT(clnts <= obd->obd_max_recoverable_clients);
1607 if (obd->obd_no_conn == 0 &&
1608 clnts + obd->obd_stale_clients == obd->obd_max_recoverable_clients)
1613 static int check_for_next_transno(struct obd_device *obd)
1615 struct ptlrpc_request *req = NULL;
1616 int wake_up = 0, connected, completed, queue_len;
1617 __u64 next_transno, req_transno;
1620 cfs_spin_lock(&obd->obd_recovery_task_lock);
1621 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1622 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1623 struct ptlrpc_request, rq_list);
1624 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1629 connected = cfs_atomic_read(&obd->obd_connected_clients);
1630 completed = connected - cfs_atomic_read(&obd->obd_req_replay_clients);
1631 queue_len = obd->obd_requests_queued_for_recovery;
1632 next_transno = obd->obd_next_recovery_transno;
1634 CDEBUG(D_HA, "max: %d, connected: %d, completed: %d, queue_len: %d, "
1635 "req_transno: "LPU64", next_transno: "LPU64"\n",
1636 obd->obd_max_recoverable_clients, connected, completed,
1637 queue_len, req_transno, next_transno);
1639 if (obd->obd_abort_recovery) {
1640 CDEBUG(D_HA, "waking for aborted recovery\n");
1642 } else if (obd->obd_recovery_expired) {
1643 CDEBUG(D_HA, "waking for expired recovery\n");
1645 } else if (cfs_atomic_read(&obd->obd_req_replay_clients) == 0) {
1646 CDEBUG(D_HA, "waking for completed recovery\n");
1648 } else if (req_transno == next_transno) {
1649 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1651 } else if (queue_len == cfs_atomic_read(&obd->obd_req_replay_clients)) {
1653 /** handle gaps occured due to lost reply or VBR */
1654 LASSERTF(req_transno >= next_transno,
1655 "req_transno: "LPU64", next_transno: "LPU64"\n",
1656 req_transno, next_transno);
1657 if (req_transno > obd->obd_last_committed &&
1658 !obd->obd_version_recov)
1661 "%s: waking for gap in transno, VBR is %s (skip: "
1662 LPD64", ql: %d, comp: %d, conn: %d, next: "LPD64
1663 ", last_committed: "LPD64")\n",
1664 obd->obd_name, obd->obd_version_recov ? "ON" : "OFF",
1665 next_transno, queue_len, completed, connected,
1666 req_transno, obd->obd_last_committed);
1667 obd->obd_next_recovery_transno = req_transno;
1669 } else if (OBD_FAIL_CHECK(OBD_FAIL_MDS_RECOVERY_ACCEPTS_GAPS)) {
1670 CDEBUG(D_HA, "accepting transno gaps is explicitly allowed"
1671 " by fail_lock, waking up ("LPD64")\n", next_transno);
1672 obd->obd_next_recovery_transno = req_transno;
1675 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1679 static int check_for_next_lock(struct obd_device *obd)
1683 cfs_spin_lock(&obd->obd_recovery_task_lock);
1684 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1685 CDEBUG(D_HA, "waking for next lock\n");
1687 } else if (cfs_atomic_read(&obd->obd_lock_replay_clients) == 0) {
1688 CDEBUG(D_HA, "waking for completed lock replay\n");
1690 } else if (obd->obd_abort_recovery) {
1691 CDEBUG(D_HA, "waking for aborted recovery\n");
1693 } else if (obd->obd_recovery_expired) {
1694 CDEBUG(D_HA, "waking for expired recovery\n");
1697 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1703 * wait for recovery events,
1704 * check its status with help of check_routine
1705 * evict dead clients via health_check
1707 static int target_recovery_overseer(struct obd_device *obd,
1708 int (*check_routine)(struct obd_device *),
1709 int (*health_check)(struct obd_export *))
1712 cfs_wait_event(obd->obd_next_transno_waitq, check_routine(obd));
1713 if (obd->obd_abort_recovery) {
1714 CWARN("recovery is aborted, evict exports in recovery\n");
1715 /** evict exports which didn't finish recovery yet */
1716 class_disconnect_stale_exports(obd, exp_finished);
1718 } else if (obd->obd_recovery_expired) {
1719 obd->obd_recovery_expired = 0;
1720 /** If some clients died being recovered, evict them */
1721 LCONSOLE_WARN("%s: recovery is timed out, "
1722 "evict stale exports\n", obd->obd_name);
1723 /** evict cexports with no replay in queue, they are stalled */
1724 class_disconnect_stale_exports(obd, health_check);
1725 /** continue with VBR */
1726 cfs_spin_lock(&obd->obd_dev_lock);
1727 obd->obd_version_recov = 1;
1728 cfs_spin_unlock(&obd->obd_dev_lock);
1730 * reset timer, recovery will proceed with versions now,
1731 * timeout is set just to handle reconnection delays
1733 extend_recovery_timer(obd, RECONNECT_DELAY_MAX, true);
1734 /** Wait for recovery events again, after evicting bad clients */
1740 static struct ptlrpc_request *target_next_replay_req(struct obd_device *obd)
1742 struct ptlrpc_request *req = NULL;
1745 CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1746 obd->obd_next_recovery_transno);
1748 if (target_recovery_overseer(obd, check_for_next_transno,
1749 exp_req_replay_healthy)) {
1750 abort_req_replay_queue(obd);
1751 abort_lock_replay_queue(obd);
1754 cfs_spin_lock(&obd->obd_recovery_task_lock);
1755 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1756 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1757 struct ptlrpc_request, rq_list);
1758 cfs_list_del_init(&req->rq_list);
1759 obd->obd_requests_queued_for_recovery--;
1760 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1762 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1763 LASSERT(cfs_list_empty(&obd->obd_req_replay_queue));
1764 LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
1765 /** evict exports failed VBR */
1766 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1771 static struct ptlrpc_request *target_next_replay_lock(struct obd_device *obd)
1773 struct ptlrpc_request *req = NULL;
1775 CDEBUG(D_HA, "Waiting for lock\n");
1776 if (target_recovery_overseer(obd, check_for_next_lock,
1777 exp_lock_replay_healthy))
1778 abort_lock_replay_queue(obd);
1780 cfs_spin_lock(&obd->obd_recovery_task_lock);
1781 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1782 req = cfs_list_entry(obd->obd_lock_replay_queue.next,
1783 struct ptlrpc_request, rq_list);
1784 cfs_list_del_init(&req->rq_list);
1785 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1787 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1788 LASSERT(cfs_list_empty(&obd->obd_lock_replay_queue));
1789 LASSERT(cfs_atomic_read(&obd->obd_lock_replay_clients) == 0);
1790 /** evict exports failed VBR */
1791 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1796 static struct ptlrpc_request *target_next_final_ping(struct obd_device *obd)
1798 struct ptlrpc_request *req = NULL;
1800 cfs_spin_lock(&obd->obd_recovery_task_lock);
1801 if (!cfs_list_empty(&obd->obd_final_req_queue)) {
1802 req = cfs_list_entry(obd->obd_final_req_queue.next,
1803 struct ptlrpc_request, rq_list);
1804 cfs_list_del_init(&req->rq_list);
1805 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1806 if (req->rq_export->exp_in_recovery) {
1807 cfs_spin_lock(&req->rq_export->exp_lock);
1808 req->rq_export->exp_in_recovery = 0;
1809 cfs_spin_unlock(&req->rq_export->exp_lock);
1812 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1817 static int handle_recovery_req(struct ptlrpc_thread *thread,
1818 struct ptlrpc_request *req,
1819 svc_handler_t handler)
1825 * export can be evicted during recovery, no need to handle replays for
1826 * it after that, discard such request silently
1828 if (req->rq_export->exp_disconnected)
1829 GOTO(reqcopy_put, rc = 0);
1831 rc = lu_context_init(&req->rq_recov_session, LCT_SESSION);
1833 CERROR("Failure to initialize session: %d\n", rc);
1834 GOTO(reqcopy_put, rc);
1837 req->rq_recov_session.lc_thread = thread;
1838 lu_context_enter(&req->rq_recov_session);
1839 req->rq_svc_thread = thread;
1840 req->rq_svc_thread->t_env->le_ses = &req->rq_recov_session;
1842 /* thread context */
1843 lu_context_enter(&thread->t_env->le_ctx);
1845 lu_context_exit(&thread->t_env->le_ctx);
1847 lu_context_exit(&req->rq_recov_session);
1848 lu_context_fini(&req->rq_recov_session);
1849 /* don't reset timer for final stage */
1850 if (!exp_finished(req->rq_export)) {
1851 int to = obd_timeout;
1854 * Add request timeout to the recovery time so next request from
1855 * this client may come in recovery time
1858 struct ptlrpc_service_part *svcpt;
1860 svcpt = req->rq_rqbd->rqbd_svcpt;
1861 /* If the server sent early reply for this request,
1862 * the client will recalculate the timeout according to
1863 * current server estimate service time, so we will
1864 * use the maxium timeout here for waiting the client
1865 * sending the next req */
1866 to = max((int)at_est2timeout(
1867 at_get(&svcpt->scp_at_estimate)),
1868 (int)lustre_msg_get_timeout(req->rq_reqmsg));
1869 /* Add net_latency (see ptlrpc_replay_req) */
1870 to += lustre_msg_get_service_time(req->rq_reqmsg);
1872 extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
1878 static int target_recovery_thread(void *arg)
1880 struct lu_target *lut = arg;
1881 struct obd_device *obd = lut->lut_obd;
1882 struct ptlrpc_request *req;
1883 struct target_recovery_data *trd = &obd->obd_recovery_data;
1884 unsigned long delta;
1885 unsigned long flags;
1887 struct ptlrpc_thread *thread = NULL;
1891 cfs_daemonize_ctxt("tgt_recov");
1893 SIGNAL_MASK_LOCK(current, flags);
1894 sigfillset(¤t->blocked);
1896 SIGNAL_MASK_UNLOCK(current, flags);
1898 OBD_ALLOC_PTR(thread);
1904 OBD_FREE_PTR(thread);
1908 rc = lu_context_init(&env->le_ctx, LCT_MD_THREAD | LCT_DT_THREAD);
1910 OBD_FREE_PTR(thread);
1915 thread->t_env = env;
1916 thread->t_id = -1; /* force filter_iobuf_get/put to use local buffers */
1917 env->le_ctx.lc_thread = thread;
1918 thread->t_data = NULL;
1919 thread->t_watchdog = NULL;
1921 CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
1923 trd->trd_processing_task = cfs_curproc_pid();
1925 cfs_spin_lock(&obd->obd_dev_lock);
1926 obd->obd_recovering = 1;
1927 cfs_spin_unlock(&obd->obd_dev_lock);
1928 cfs_complete(&trd->trd_starting);
1930 /* first of all, we have to know the first transno to replay */
1931 if (target_recovery_overseer(obd, check_for_clients,
1932 exp_connect_healthy)) {
1933 abort_req_replay_queue(obd);
1934 abort_lock_replay_queue(obd);
1937 /* next stage: replay requests */
1939 CDEBUG(D_INFO, "1: request replay stage - %d clients from t"LPU64"\n",
1940 cfs_atomic_read(&obd->obd_req_replay_clients),
1941 obd->obd_next_recovery_transno);
1942 while ((req = target_next_replay_req(obd))) {
1943 LASSERT(trd->trd_processing_task == cfs_curproc_pid());
1944 DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s",
1945 lustre_msg_get_transno(req->rq_reqmsg),
1946 libcfs_nid2str(req->rq_peer.nid));
1947 handle_recovery_req(thread, req,
1948 trd->trd_recovery_handler);
1950 * bz18031: increase next_recovery_transno before
1951 * target_request_copy_put() will drop exp_rpc reference
1953 cfs_spin_lock(&obd->obd_recovery_task_lock);
1954 obd->obd_next_recovery_transno++;
1955 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1956 target_exp_dequeue_req_replay(req);
1957 target_request_copy_put(req);
1958 obd->obd_replayed_requests++;
1962 * The second stage: replay locks
1964 CDEBUG(D_INFO, "2: lock replay stage - %d clients\n",
1965 cfs_atomic_read(&obd->obd_lock_replay_clients));
1966 while ((req = target_next_replay_lock(obd))) {
1967 LASSERT(trd->trd_processing_task == cfs_curproc_pid());
1968 DEBUG_REQ(D_HA, req, "processing lock from %s: ",
1969 libcfs_nid2str(req->rq_peer.nid));
1970 handle_recovery_req(thread, req,
1971 trd->trd_recovery_handler);
1972 target_request_copy_put(req);
1973 obd->obd_replayed_locks++;
1977 * The third stage: reply on final pings, at this moment all clients
1978 * must have request in final queue
1980 CDEBUG(D_INFO, "3: final stage - process recovery completion pings\n");
1981 /** Update server last boot epoch */
1982 lut_boot_epoch_update(lut);
1983 /* We drop recoverying flag to forward all new requests
1984 * to regular mds_handle() since now */
1985 cfs_spin_lock(&obd->obd_dev_lock);
1986 obd->obd_recovering = obd->obd_abort_recovery = 0;
1987 cfs_spin_unlock(&obd->obd_dev_lock);
1988 cfs_spin_lock(&obd->obd_recovery_task_lock);
1989 target_cancel_recovery_timer(obd);
1990 cfs_spin_unlock(&obd->obd_recovery_task_lock);
1991 while ((req = target_next_final_ping(obd))) {
1992 LASSERT(trd->trd_processing_task == cfs_curproc_pid());
1993 DEBUG_REQ(D_HA, req, "processing final ping from %s: ",
1994 libcfs_nid2str(req->rq_peer.nid));
1995 handle_recovery_req(thread, req,
1996 trd->trd_recovery_handler);
1997 target_request_copy_put(req);
2000 delta = (jiffies - delta) / CFS_HZ;
2001 CDEBUG(D_INFO,"4: recovery completed in %lus - %d/%d reqs/locks\n",
2002 delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
2003 if (delta > OBD_RECOVERY_TIME_SOFT) {
2004 CWARN("too long recovery - read logs\n");
2005 libcfs_debug_dumplog();
2008 target_finish_recovery(obd);
2010 lu_context_fini(&env->le_ctx);
2011 trd->trd_processing_task = 0;
2012 cfs_complete(&trd->trd_finishing);
2014 OBD_FREE_PTR(thread);
2019 static int target_start_recovery_thread(struct lu_target *lut,
2020 svc_handler_t handler)
2022 struct obd_device *obd = lut->lut_obd;
2024 struct target_recovery_data *trd = &obd->obd_recovery_data;
2026 memset(trd, 0, sizeof(*trd));
2027 cfs_init_completion(&trd->trd_starting);
2028 cfs_init_completion(&trd->trd_finishing);
2029 trd->trd_recovery_handler = handler;
2031 if (cfs_create_thread(target_recovery_thread, lut, 0) > 0) {
2032 cfs_wait_for_completion(&trd->trd_starting);
2033 LASSERT(obd->obd_recovering != 0);
2040 void target_stop_recovery_thread(struct obd_device *obd)
2042 if (obd->obd_recovery_data.trd_processing_task > 0) {
2043 struct target_recovery_data *trd = &obd->obd_recovery_data;
2044 /** recovery can be done but postrecovery is not yet */
2045 cfs_spin_lock(&obd->obd_dev_lock);
2046 if (obd->obd_recovering) {
2047 CERROR("%s: Aborting recovery\n", obd->obd_name);
2048 obd->obd_abort_recovery = 1;
2049 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2051 cfs_spin_unlock(&obd->obd_dev_lock);
2052 cfs_wait_for_completion(&trd->trd_finishing);
2056 void target_recovery_fini(struct obd_device *obd)
2058 class_disconnect_exports(obd);
2059 target_stop_recovery_thread(obd);
2060 target_cleanup_recovery(obd);
2062 EXPORT_SYMBOL(target_recovery_fini);
2064 static void target_recovery_expired(unsigned long castmeharder)
2066 struct obd_device *obd = (struct obd_device *)castmeharder;
2067 CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery"
2068 " after %lds (%d clients connected)\n",
2069 obd->obd_name, cfs_atomic_read(&obd->obd_lock_replay_clients),
2070 cfs_time_current_sec()- obd->obd_recovery_start,
2071 cfs_atomic_read(&obd->obd_connected_clients));
2073 obd->obd_recovery_expired = 1;
2074 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2077 void target_recovery_init(struct lu_target *lut, svc_handler_t handler)
2079 struct obd_device *obd = lut->lut_obd;
2080 if (obd->obd_max_recoverable_clients == 0) {
2081 /** Update server last boot epoch */
2082 lut_boot_epoch_update(lut);
2086 CWARN("RECOVERY: service %s, %d recoverable clients, "
2087 "last_transno "LPU64"\n", obd->obd_name,
2088 obd->obd_max_recoverable_clients, obd->obd_last_committed);
2089 LASSERT(obd->obd_stopping == 0);
2090 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
2091 obd->obd_recovery_start = 0;
2092 obd->obd_recovery_end = 0;
2094 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
2095 target_start_recovery_thread(lut, handler);
2097 EXPORT_SYMBOL(target_recovery_init);
2099 #endif /* __KERNEL__ */
2101 static int target_process_req_flags(struct obd_device *obd,
2102 struct ptlrpc_request *req)
2104 struct obd_export *exp = req->rq_export;
2105 LASSERT(exp != NULL);
2106 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2107 /* client declares he's ready to replay locks */
2108 cfs_spin_lock(&exp->exp_lock);
2109 if (exp->exp_req_replay_needed) {
2110 exp->exp_req_replay_needed = 0;
2111 cfs_spin_unlock(&exp->exp_lock);
2113 LASSERT_ATOMIC_POS(&obd->obd_req_replay_clients);
2114 cfs_atomic_dec(&obd->obd_req_replay_clients);
2116 cfs_spin_unlock(&exp->exp_lock);
2119 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2120 /* client declares he's ready to complete recovery
2121 * so, we put the request on th final queue */
2122 cfs_spin_lock(&exp->exp_lock);
2123 if (exp->exp_lock_replay_needed) {
2124 exp->exp_lock_replay_needed = 0;
2125 cfs_spin_unlock(&exp->exp_lock);
2127 LASSERT_ATOMIC_POS(&obd->obd_lock_replay_clients);
2128 cfs_atomic_dec(&obd->obd_lock_replay_clients);
2130 cfs_spin_unlock(&exp->exp_lock);
2136 int target_queue_recovery_request(struct ptlrpc_request *req,
2137 struct obd_device *obd)
2141 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
2144 if (obd->obd_recovery_data.trd_processing_task == cfs_curproc_pid()) {
2145 /* Processing the queue right now, don't re-add. */
2149 target_process_req_flags(obd, req);
2151 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2152 /* client declares he's ready to complete recovery
2153 * so, we put the request on th final queue */
2154 target_request_copy_get(req);
2155 DEBUG_REQ(D_HA, req, "queue final req");
2156 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2157 cfs_spin_lock(&obd->obd_recovery_task_lock);
2158 if (obd->obd_recovering) {
2159 cfs_list_add_tail(&req->rq_list,
2160 &obd->obd_final_req_queue);
2162 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2163 target_request_copy_put(req);
2164 RETURN(obd->obd_stopping ? -ENOTCONN : 1);
2166 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2169 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2170 /* client declares he's ready to replay locks */
2171 target_request_copy_get(req);
2172 DEBUG_REQ(D_HA, req, "queue lock replay req");
2173 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2174 cfs_spin_lock(&obd->obd_recovery_task_lock);
2175 LASSERT(obd->obd_recovering);
2176 /* usually due to recovery abort */
2177 if (!req->rq_export->exp_in_recovery) {
2178 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2179 target_request_copy_put(req);
2182 LASSERT(req->rq_export->exp_lock_replay_needed);
2183 cfs_list_add_tail(&req->rq_list, &obd->obd_lock_replay_queue);
2184 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2188 /* CAVEAT EMPTOR: The incoming request message has been swabbed
2189 * (i.e. buflens etc are in my own byte order), but type-dependent
2190 * buffers (eg mdt_body, ost_body etc) have NOT been swabbed. */
2193 CFS_INIT_LIST_HEAD(&req->rq_list);
2194 DEBUG_REQ(D_HA, req, "not queueing");
2198 /* If we're processing the queue, we want don't want to queue this
2201 * Also, if this request has a transno less than the one we're waiting
2202 * for, we should process it now. It could (and currently always will)
2203 * be an open request for a descriptor that was opened some time ago.
2205 * Also, a resent, replayed request that has already been
2206 * handled will pass through here and be processed immediately.
2208 CDEBUG(D_HA, "Next recovery transno: "LPU64
2209 ", current: "LPU64", replaying\n",
2210 obd->obd_next_recovery_transno, transno);
2211 cfs_spin_lock(&obd->obd_recovery_task_lock);
2212 if (transno < obd->obd_next_recovery_transno) {
2213 /* Processing the queue right now, don't re-add. */
2214 LASSERT(cfs_list_empty(&req->rq_list));
2215 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2218 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2220 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))
2223 target_request_copy_get(req);
2224 if (!req->rq_export->exp_in_recovery) {
2225 target_request_copy_put(req);
2228 LASSERT(req->rq_export->exp_req_replay_needed);
2230 if (target_exp_enqueue_req_replay(req)) {
2231 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
2232 target_request_copy_put(req);
2237 cfs_spin_lock(&obd->obd_recovery_task_lock);
2238 LASSERT(obd->obd_recovering);
2239 cfs_list_for_each(tmp, &obd->obd_req_replay_queue) {
2240 struct ptlrpc_request *reqiter =
2241 cfs_list_entry(tmp, struct ptlrpc_request, rq_list);
2243 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
2244 cfs_list_add_tail(&req->rq_list, &reqiter->rq_list);
2249 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
2251 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
2252 "has been claimed by another client");
2253 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2254 target_exp_dequeue_req_replay(req);
2255 target_request_copy_put(req);
2261 cfs_list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
2263 obd->obd_requests_queued_for_recovery++;
2264 cfs_spin_unlock(&obd->obd_recovery_task_lock);
2265 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2269 int target_handle_ping(struct ptlrpc_request *req)
2271 obd_ping(req->rq_svc_thread->t_env, req->rq_export);
2272 return req_capsule_server_pack(&req->rq_pill);
2275 void target_committed_to_req(struct ptlrpc_request *req)
2277 struct obd_export *exp = req->rq_export;
2279 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL)
2280 lustre_msg_set_last_committed(req->rq_repmsg,
2281 exp->exp_last_committed);
2283 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2284 "%d)", exp->exp_obd->obd_no_transno,
2285 req->rq_repmsg == NULL);
2287 CDEBUG(D_INFO, "last_committed "LPU64", transno "LPU64", xid "LPU64"\n",
2288 exp->exp_last_committed, req->rq_transno, req->rq_xid);
2290 EXPORT_SYMBOL(target_committed_to_req);
2292 #endif /* HAVE_SERVER_SUPPORT */
2295 * Packs current SLV and Limit into \a req.
2297 int target_pack_pool_reply(struct ptlrpc_request *req)
2299 struct obd_device *obd;
2303 * Check that we still have all structures alive as this may
2304 * be some late rpc in shutdown time.
2306 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
2307 !exp_connect_lru_resize(req->rq_export))) {
2308 lustre_msg_set_slv(req->rq_repmsg, 0);
2309 lustre_msg_set_limit(req->rq_repmsg, 0);
2314 * OBD is alive here as export is alive, which we checked above.
2316 obd = req->rq_export->exp_obd;
2318 cfs_read_lock(&obd->obd_pool_lock);
2319 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
2320 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
2321 cfs_read_unlock(&obd->obd_pool_lock);
2326 int target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id)
2328 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
2329 DEBUG_REQ(D_ERROR, req, "dropping reply");
2334 DEBUG_REQ(D_NET, req, "processing error (%d)", rc);
2335 req->rq_status = rc;
2336 return (ptlrpc_send_error(req, 1));
2338 DEBUG_REQ(D_NET, req, "sending reply");
2341 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
2344 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
2346 struct ptlrpc_service_part *svcpt;
2348 struct ptlrpc_reply_state *rs;
2349 struct obd_export *exp;
2352 if (req->rq_no_reply) {
2357 svcpt = req->rq_rqbd->rqbd_svcpt;
2358 rs = req->rq_reply_state;
2359 if (rs == NULL || !rs->rs_difficult) {
2361 target_send_reply_msg (req, rc, fail_id);
2366 /* must be an export if locks saved */
2367 LASSERT (req->rq_export != NULL);
2368 /* req/reply consistent */
2369 LASSERT(rs->rs_svcpt == svcpt);
2372 LASSERT (!rs->rs_scheduled);
2373 LASSERT (!rs->rs_scheduled_ever);
2374 LASSERT (!rs->rs_handled);
2375 LASSERT (!rs->rs_on_net);
2376 LASSERT (rs->rs_export == NULL);
2377 LASSERT (cfs_list_empty(&rs->rs_obd_list));
2378 LASSERT (cfs_list_empty(&rs->rs_exp_list));
2380 exp = class_export_get (req->rq_export);
2382 /* disable reply scheduling while I'm setting up */
2383 rs->rs_scheduled = 1;
2385 rs->rs_xid = req->rq_xid;
2386 rs->rs_transno = req->rq_transno;
2387 rs->rs_export = exp;
2388 rs->rs_opc = lustre_msg_get_opc(rs->rs_msg);
2390 cfs_spin_lock(&exp->exp_uncommitted_replies_lock);
2391 CDEBUG(D_NET, "rs transno = "LPU64", last committed = "LPU64"\n",
2392 rs->rs_transno, exp->exp_last_committed);
2393 if (rs->rs_transno > exp->exp_last_committed) {
2394 /* not committed already */
2395 cfs_list_add_tail(&rs->rs_obd_list,
2396 &exp->exp_uncommitted_replies);
2398 cfs_spin_unlock (&exp->exp_uncommitted_replies_lock);
2400 cfs_spin_lock(&exp->exp_lock);
2401 cfs_list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies);
2402 cfs_spin_unlock(&exp->exp_lock);
2404 netrc = target_send_reply_msg (req, rc, fail_id);
2406 cfs_spin_lock(&svcpt->scp_rep_lock);
2408 cfs_atomic_inc(&svcpt->scp_nreps_difficult);
2411 /* error sending: reply is off the net. Also we need +1
2412 * reply ref until ptlrpc_handle_rs() is done
2413 * with the reply state (if the send was successful, there
2414 * would have been +1 ref for the net, which
2415 * reply_out_callback leaves alone) */
2417 ptlrpc_rs_addref(rs);
2420 cfs_spin_lock(&rs->rs_lock);
2421 if (rs->rs_transno <= exp->exp_last_committed ||
2422 (!rs->rs_on_net && !rs->rs_no_ack) ||
2423 cfs_list_empty(&rs->rs_exp_list) || /* completed already */
2424 cfs_list_empty(&rs->rs_obd_list)) {
2425 CDEBUG(D_HA, "Schedule reply immediately\n");
2426 ptlrpc_dispatch_difficult_reply(rs);
2428 cfs_list_add(&rs->rs_list, &svcpt->scp_rep_active);
2429 rs->rs_scheduled = 0; /* allow notifier to schedule */
2431 cfs_spin_unlock(&rs->rs_lock);
2432 cfs_spin_unlock(&svcpt->scp_rep_lock);
2436 int target_handle_qc_callback(struct ptlrpc_request *req)
2438 struct obd_quotactl *oqctl;
2439 struct client_obd *cli = &req->rq_export->exp_obd->u.cli;
2441 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
2442 if (oqctl == NULL) {
2443 CERROR("Can't unpack obd_quotactl\n");
2447 cli->cl_qchk_stat = oqctl->qc_stat;
2452 #ifdef HAVE_QUOTA_SUPPORT
2453 int target_handle_dqacq_callback(struct ptlrpc_request *req)
2456 struct obd_device *obd = req->rq_export->exp_obd;
2457 struct obd_device *master_obd = NULL, *lov_obd = NULL;
2458 struct obd_device_target *obt;
2459 struct lustre_quota_ctxt *qctxt;
2460 struct qunit_data *qdata = NULL;
2464 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DROP_QUOTA_REQ))
2467 rc = req_capsule_server_pack(&req->rq_pill);
2469 CERROR("packing reply failed!: rc = %d\n", rc);
2473 LASSERT(req->rq_export);
2475 qdata = quota_get_qdata(req, QUOTA_REQUEST, QUOTA_EXPORT);
2476 if (IS_ERR(qdata)) {
2477 rc = PTR_ERR(qdata);
2478 CDEBUG(D_ERROR, "Can't unpack qunit_data(rc: %d)\n", rc);
2479 req->rq_status = rc;
2483 /* we use the observer */
2484 if (obd_pin_observer(obd, &lov_obd) ||
2485 obd_pin_observer(lov_obd, &master_obd)) {
2486 CERROR("Can't find the observer, it is recovering\n");
2487 req->rq_status = -EAGAIN;
2491 obt = &master_obd->u.obt;
2492 qctxt = &obt->obt_qctxt;
2494 if (!qctxt->lqc_setup || !qctxt->lqc_valid) {
2495 /* quota_type has not been processed yet, return EAGAIN
2496 * until we know whether or not quotas are supposed to
2498 CDEBUG(D_QUOTA, "quota_type not processed yet, return "
2500 req->rq_status = -EAGAIN;
2504 cfs_down_read(&obt->obt_rwsem);
2505 if (qctxt->lqc_lqs_hash == NULL) {
2506 cfs_up_read(&obt->obt_rwsem);
2507 /* quota_type has not been processed yet, return EAGAIN
2508 * until we know whether or not quotas are supposed to
2510 CDEBUG(D_QUOTA, "quota_ctxt is not ready yet, return "
2512 req->rq_status = -EAGAIN;
2516 LASSERT(qctxt->lqc_handler);
2517 rc = qctxt->lqc_handler(master_obd, qdata,
2518 lustre_msg_get_opc(req->rq_reqmsg));
2519 cfs_up_read(&obt->obt_rwsem);
2520 if (rc && rc != -EDQUOT)
2521 CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR,
2522 "dqacq/dqrel failed! (rc:%d)\n", rc);
2523 req->rq_status = rc;
2525 rc = quota_copy_qdata(req, qdata, QUOTA_REPLY, QUOTA_EXPORT);
2527 CERROR("Can't pack qunit_data(rc: %d)\n", rc);
2531 /* Block the quota req. b=14840 */
2532 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_BLOCK_QUOTA_REQ, obd_timeout);
2537 obd_unpin_observer(lov_obd);
2539 obd_unpin_observer(obd);
2541 rc = ptlrpc_reply(req);
2545 #endif /* !__KERNEL__ */
2547 #endif /* HAVE_QUOTA_SUPPORT */
2549 ldlm_mode_t lck_compat_array[] = {
2550 [LCK_EX] LCK_COMPAT_EX,
2551 [LCK_PW] LCK_COMPAT_PW,
2552 [LCK_PR] LCK_COMPAT_PR,
2553 [LCK_CW] LCK_COMPAT_CW,
2554 [LCK_CR] LCK_COMPAT_CR,
2555 [LCK_NL] LCK_COMPAT_NL,
2556 [LCK_GROUP] LCK_COMPAT_GROUP,
2557 [LCK_COS] LCK_COMPAT_COS,
2561 * Rather arbitrary mapping from LDLM error codes to errno values. This should
2562 * not escape to the user level.
2564 int ldlm_error2errno(ldlm_error_t error)
2572 case ELDLM_LOCK_CHANGED:
2575 case ELDLM_LOCK_ABORTED:
2578 case ELDLM_LOCK_REPLACED:
2581 case ELDLM_NO_LOCK_DATA:
2584 case ELDLM_NAMESPACE_EXISTS:
2587 case ELDLM_BAD_NAMESPACE:
2591 if (((int)error) < 0) /* cast to signed type */
2592 result = error; /* as ldlm_error_t can be unsigned */
2594 CERROR("Invalid DLM result code: %d\n", error);
2600 EXPORT_SYMBOL(ldlm_error2errno);
2603 * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
2605 ldlm_error_t ldlm_errno2error(int err_no)
2614 error = ELDLM_LOCK_CHANGED;
2617 error = ELDLM_LOCK_ABORTED;
2620 error = ELDLM_LOCK_REPLACED;
2623 error = ELDLM_NO_LOCK_DATA;
2626 error = ELDLM_NAMESPACE_EXISTS;
2629 error = ELDLM_BAD_NAMESPACE;
2636 EXPORT_SYMBOL(ldlm_errno2error);
2638 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2639 void ldlm_dump_export_locks(struct obd_export *exp)
2641 cfs_spin_lock(&exp->exp_locks_list_guard);
2642 if (!cfs_list_empty(&exp->exp_locks_list)) {
2643 struct ldlm_lock *lock;
2645 CERROR("dumping locks for export %p,"
2646 "ignore if the unmount doesn't hang\n", exp);
2647 cfs_list_for_each_entry(lock, &exp->exp_locks_list, l_exp_refs_link)
2648 LDLM_ERROR(lock, "lock:");
2650 cfs_spin_unlock(&exp->exp_locks_list_guard);
2654 #ifdef HAVE_SERVER_SUPPORT
2655 static int target_bulk_timeout(void *data)
2658 /* We don't fail the connection here, because having the export
2659 * killed makes the (vital) call to commitrw very sad.
2664 static inline char *bulk2type(struct ptlrpc_bulk_desc *desc)
2666 return desc->bd_type == BULK_GET_SINK ? "GET" : "PUT";
2669 int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc,
2670 struct l_wait_info *lwi)
2672 struct ptlrpc_request *req = desc->bd_req;
2676 /* Check if there is eviction in progress, and if so, wait for
2678 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
2679 *lwi = LWI_INTR(NULL, NULL);
2680 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
2681 !cfs_atomic_read(&exp->exp_obd->
2682 obd_evict_inprogress),
2686 /* Check if client was evicted or tried to reconnect already */
2687 if (exp->exp_failed || exp->exp_abort_active_req) {
2690 if (desc->bd_type == BULK_PUT_SINK)
2691 rc = sptlrpc_svc_wrap_bulk(req, desc);
2693 rc = ptlrpc_start_bulk_transfer(desc);
2696 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
2697 ptlrpc_abort_bulk(desc);
2698 } else if (rc == 0) {
2699 time_t start = cfs_time_current_sec();
2701 long timeoutl = req->rq_deadline - cfs_time_current_sec();
2702 cfs_duration_t timeout = timeoutl <= 0 ?
2703 CFS_TICK : cfs_time_seconds(timeoutl);
2704 *lwi = LWI_TIMEOUT_INTERVAL(timeout,
2705 cfs_time_seconds(1),
2706 target_bulk_timeout,
2708 rc = l_wait_event(desc->bd_waitq,
2709 !ptlrpc_server_bulk_active(desc) ||
2711 exp->exp_abort_active_req,
2713 LASSERT(rc == 0 || rc == -ETIMEDOUT);
2714 /* Wait again if we changed deadline */
2715 } while ((rc == -ETIMEDOUT) &&
2716 (req->rq_deadline > cfs_time_current_sec()));
2718 if (rc == -ETIMEDOUT) {
2719 DEBUG_REQ(D_ERROR, req,
2720 "timeout on bulk %s after %ld%+lds",
2722 req->rq_deadline - start,
2723 cfs_time_current_sec() -
2725 ptlrpc_abort_bulk(desc);
2726 } else if (exp->exp_failed) {
2727 DEBUG_REQ(D_ERROR, req, "Eviction on bulk %s",
2730 ptlrpc_abort_bulk(desc);
2731 } else if (exp->exp_abort_active_req) {
2732 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk %s",
2734 /* we don't reply anyway */
2736 ptlrpc_abort_bulk(desc);
2737 } else if (!desc->bd_success ||
2738 desc->bd_nob_transferred != desc->bd_nob) {
2739 DEBUG_REQ(D_ERROR, req, "%s bulk %s %d(%d)",
2741 "truncated" : "network error on",
2743 desc->bd_nob_transferred,
2745 /* XXX should this be a different errno? */
2747 } else if (desc->bd_type == BULK_GET_SINK) {
2748 rc = sptlrpc_svc_unwrap_bulk(req, desc);
2751 DEBUG_REQ(D_ERROR, req, "bulk %s failed: rc %d",
2752 bulk2type(desc), rc);
2757 EXPORT_SYMBOL(target_bulk_io);
2759 #endif /* HAVE_SERVER_SUPPORT */