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) 2010, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * This file deals with various client/target related logic including recovery.
40 * TODO: This code more logically belongs in the ptlrpc module than in ldlm and
44 #define DEBUG_SUBSYSTEM S_LDLM
47 # include <libcfs/libcfs.h>
49 # include <liblustre.h>
52 #include <obd_class.h>
53 #include <lustre_dlm.h>
54 #include <lustre_net.h>
55 #include <lustre_sec.h>
56 #include "ldlm_internal.h"
58 /* @priority: If non-zero, move the selected connection to the list head.
59 * @create: If zero, only search in existing connections.
61 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
62 int priority, int create)
64 struct ptlrpc_connection *ptlrpc_conn;
65 struct obd_import_conn *imp_conn = NULL, *item;
69 if (!create && !priority) {
70 CDEBUG(D_HA, "Nothing to do\n");
74 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
76 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
81 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
83 GOTO(out_put, rc = -ENOMEM);
87 spin_lock(&imp->imp_lock);
88 cfs_list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
89 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
91 cfs_list_del(&item->oic_item);
92 cfs_list_add(&item->oic_item,
94 item->oic_last_attempt = 0;
96 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
97 imp, imp->imp_obd->obd_name, uuid->uuid,
98 (priority ? ", moved to head" : ""));
99 spin_unlock(&imp->imp_lock);
100 GOTO(out_free, rc = 0);
103 /* No existing import connection found for \a uuid. */
105 imp_conn->oic_conn = ptlrpc_conn;
106 imp_conn->oic_uuid = *uuid;
107 imp_conn->oic_last_attempt = 0;
109 cfs_list_add(&imp_conn->oic_item, &imp->imp_conn_list);
111 cfs_list_add_tail(&imp_conn->oic_item,
112 &imp->imp_conn_list);
113 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
114 imp, imp->imp_obd->obd_name, uuid->uuid,
115 (priority ? "head" : "tail"));
117 spin_unlock(&imp->imp_lock);
118 GOTO(out_free, rc = -ENOENT);
121 spin_unlock(&imp->imp_lock);
125 OBD_FREE(imp_conn, sizeof(*imp_conn));
127 ptlrpc_connection_put(ptlrpc_conn);
131 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
133 return import_set_conn(imp, uuid, 1, 0);
136 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
139 return import_set_conn(imp, uuid, priority, 1);
141 EXPORT_SYMBOL(client_import_add_conn);
143 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
145 struct obd_import_conn *imp_conn;
146 struct obd_export *dlmexp;
150 spin_lock(&imp->imp_lock);
151 if (cfs_list_empty(&imp->imp_conn_list)) {
152 LASSERT(!imp->imp_connection);
156 cfs_list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
157 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
159 LASSERT(imp_conn->oic_conn);
161 if (imp_conn == imp->imp_conn_current) {
162 LASSERT(imp_conn->oic_conn == imp->imp_connection);
164 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
165 imp->imp_state != LUSTRE_IMP_DISCON) {
166 CERROR("can't remove current connection\n");
167 GOTO(out, rc = -EBUSY);
170 ptlrpc_connection_put(imp->imp_connection);
171 imp->imp_connection = NULL;
173 dlmexp = class_conn2export(&imp->imp_dlm_handle);
174 if (dlmexp && dlmexp->exp_connection) {
175 LASSERT(dlmexp->exp_connection ==
177 ptlrpc_connection_put(dlmexp->exp_connection);
178 dlmexp->exp_connection = NULL;
182 cfs_list_del(&imp_conn->oic_item);
183 ptlrpc_connection_put(imp_conn->oic_conn);
184 OBD_FREE(imp_conn, sizeof(*imp_conn));
185 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
186 imp, imp->imp_obd->obd_name, uuid->uuid);
191 spin_unlock(&imp->imp_lock);
193 CERROR("connection %s not found\n", uuid->uuid);
196 EXPORT_SYMBOL(client_import_del_conn);
199 * Find conn UUID by peer NID. \a peer is a server NID. This function is used
200 * to find a conn uuid of \a imp which can reach \a peer.
202 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
203 struct obd_uuid *uuid)
205 struct obd_import_conn *conn;
209 spin_lock(&imp->imp_lock);
210 cfs_list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
211 /* Check if conn UUID does have this peer NID. */
212 if (class_check_uuid(&conn->oic_uuid, peer)) {
213 *uuid = conn->oic_uuid;
218 spin_unlock(&imp->imp_lock);
221 EXPORT_SYMBOL(client_import_find_conn);
223 void client_destroy_import(struct obd_import *imp)
225 /* Drop security policy instance after all RPCs have finished/aborted
226 * to let all busy contexts be released. */
227 class_import_get(imp);
228 class_destroy_import(imp);
229 sptlrpc_import_sec_put(imp);
230 class_import_put(imp);
232 EXPORT_SYMBOL(client_destroy_import);
235 * Check whether or not the OSC is on MDT.
238 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
240 * setup 0:{fsname}-OSTxxxx-osc 1:lustre-OST0000_UUID 2:NID
243 static int osc_on_mdt(char *obdname)
247 ptr = strrchr(obdname, '-');
251 if (strncmp(ptr + 1, "MDT", 3) == 0)
257 /* Configure an RPC client OBD device.
262 * 3 - inactive-on-startup
264 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
266 struct client_obd *cli = &obddev->u.cli;
267 struct obd_import *imp;
268 struct obd_uuid server_uuid;
269 int rq_portal, rp_portal, connect_op;
270 char *name = obddev->obd_type->typ_name;
271 ldlm_ns_type_t ns_type = LDLM_NS_TYPE_UNKNOWN;
273 char *cli_name = lustre_cfg_buf(lcfg, 0);
276 /* In a more perfect world, we would hang a ptlrpc_client off of
277 * obd_type and just use the values from there. */
278 if (!strcmp(name, LUSTRE_OSC_NAME) ||
279 (!(strcmp(name, LUSTRE_OSP_NAME)) &&
280 (is_osp_on_mdt(cli_name) &&
281 strstr(lustre_cfg_buf(lcfg, 1), "OST") != NULL))) {
282 /* OSC or OSP_on_MDT for OSTs */
283 rq_portal = OST_REQUEST_PORTAL;
284 rp_portal = OSC_REPLY_PORTAL;
285 connect_op = OST_CONNECT;
286 cli->cl_sp_me = LUSTRE_SP_CLI;
287 cli->cl_sp_to = LUSTRE_SP_OST;
288 ns_type = LDLM_NS_TYPE_OSC;
289 } else if (!strcmp(name, LUSTRE_MDC_NAME) ||
290 !strcmp(name, LUSTRE_LWP_NAME) ||
291 (!strcmp(name, LUSTRE_OSP_NAME) &&
292 (is_osp_on_mdt(cli_name) &&
293 strstr(lustre_cfg_buf(lcfg, 1), "OST") == NULL))) {
294 /* MDC or OSP_on_MDT for other MDTs */
295 rq_portal = MDS_REQUEST_PORTAL;
296 rp_portal = MDC_REPLY_PORTAL;
297 connect_op = MDS_CONNECT;
298 cli->cl_sp_me = LUSTRE_SP_CLI;
299 cli->cl_sp_to = LUSTRE_SP_MDT;
300 ns_type = LDLM_NS_TYPE_MDC;
301 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
302 rq_portal = MGS_REQUEST_PORTAL;
303 rp_portal = MGC_REPLY_PORTAL;
304 connect_op = MGS_CONNECT;
305 cli->cl_sp_me = LUSTRE_SP_MGC;
306 cli->cl_sp_to = LUSTRE_SP_MGS;
307 cli->cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_INVALID;
308 ns_type = LDLM_NS_TYPE_MGC;
310 CERROR("unknown client OBD type \"%s\", can't setup\n",
315 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
316 CERROR("requires a TARGET UUID\n");
320 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
321 CERROR("client UUID must be less than 38 characters\n");
325 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
326 CERROR("setup requires a SERVER UUID\n");
330 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
331 CERROR("target UUID must be less than 38 characters\n");
335 init_rwsem(&cli->cl_sem);
336 sema_init(&cli->cl_mgc_sem, 1);
337 cli->cl_conn_count = 0;
338 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
339 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
340 sizeof(server_uuid)));
342 cli->cl_dirty_pages = 0;
343 cli->cl_avail_grant = 0;
344 /* FIXME: Should limit this for the sum of all cl_dirty_max_pages. */
345 /* cl_dirty_max_pages may be changed at connect time in
346 * ptlrpc_connect_interpret(). */
347 client_adjust_max_dirty(cli);
348 CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters);
349 CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list);
350 CFS_INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
351 CFS_INIT_LIST_HEAD(&cli->cl_loi_write_list);
352 CFS_INIT_LIST_HEAD(&cli->cl_loi_read_list);
353 client_obd_list_lock_init(&cli->cl_loi_list_lock);
354 cfs_atomic_set(&cli->cl_pending_w_pages, 0);
355 cfs_atomic_set(&cli->cl_pending_r_pages, 0);
356 cli->cl_r_in_flight = 0;
357 cli->cl_w_in_flight = 0;
359 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
360 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
361 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
362 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
363 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
364 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
367 CFS_INIT_LIST_HEAD(&cli->cl_lru_osc);
368 cfs_atomic_set(&cli->cl_lru_shrinkers, 0);
369 cfs_atomic_set(&cli->cl_lru_busy, 0);
370 cfs_atomic_set(&cli->cl_lru_in_list, 0);
371 CFS_INIT_LIST_HEAD(&cli->cl_lru_list);
372 client_obd_list_lock_init(&cli->cl_lru_list_lock);
374 init_waitqueue_head(&cli->cl_destroy_waitq);
375 cfs_atomic_set(&cli->cl_destroy_in_flight, 0);
376 #ifdef ENABLE_CHECKSUM
377 /* Turn on checksumming by default. */
378 cli->cl_checksum = 1;
380 * The supported checksum types will be worked out at connect time
381 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
384 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
386 cfs_atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
388 /* This value may be reduced at connect time in
389 * ptlrpc_connect_interpret() . We initialize it to only
390 * 1MB until we know what the performance looks like.
391 * In the future this should likely be increased. LU-1431 */
392 cli->cl_max_pages_per_rpc = min_t(int, PTLRPC_MAX_BRW_PAGES,
393 LNET_MTU >> PAGE_CACHE_SHIFT);
395 /* set cl_chunkbits default value to PAGE_CACHE_SHIFT,
396 * it will be updated at OSC connection time. */
397 cli->cl_chunkbits = PAGE_CACHE_SHIFT;
399 if (!strcmp(name, LUSTRE_MDC_NAME)) {
400 cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT;
401 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 128 /* MB */) {
402 cli->cl_max_rpcs_in_flight = 2;
403 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 256 /* MB */) {
404 cli->cl_max_rpcs_in_flight = 3;
405 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 512 /* MB */) {
406 cli->cl_max_rpcs_in_flight = 4;
408 if (osc_on_mdt(obddev->obd_name))
409 cli->cl_max_rpcs_in_flight = MDS_OSC_MAX_RIF_DEFAULT;
411 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
415 CERROR("ldlm_get_ref failed: %d\n", rc);
419 ptlrpc_init_client(rq_portal, rp_portal, name,
420 &obddev->obd_ldlm_client);
422 imp = class_new_import(obddev);
424 GOTO(err_ldlm, rc = -ENOENT);
425 imp->imp_client = &obddev->obd_ldlm_client;
426 imp->imp_connect_op = connect_op;
427 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
428 LUSTRE_CFG_BUFLEN(lcfg, 1));
429 class_import_put(imp);
431 rc = client_import_add_conn(imp, &server_uuid, 1);
433 CERROR("can't add initial connection\n");
434 GOTO(err_import, rc);
437 cli->cl_import = imp;
438 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
439 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
440 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
442 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
443 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
444 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
445 name, obddev->obd_name,
446 cli->cl_target_uuid.uuid);
447 spin_lock(&imp->imp_lock);
448 imp->imp_deactive = 1;
449 spin_unlock(&imp->imp_lock);
453 obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
454 LDLM_NAMESPACE_CLIENT,
455 LDLM_NAMESPACE_GREEDY,
457 if (obddev->obd_namespace == NULL) {
458 CERROR("Unable to create client namespace - %s\n",
460 GOTO(err_import, rc = -ENOMEM);
463 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
468 class_destroy_import(imp);
475 EXPORT_SYMBOL(client_obd_setup);
477 int client_obd_cleanup(struct obd_device *obddev)
481 ldlm_namespace_free_post(obddev->obd_namespace);
482 obddev->obd_namespace = NULL;
484 LASSERT(obddev->u.cli.cl_import == NULL);
489 EXPORT_SYMBOL(client_obd_cleanup);
491 /* ->o_connect() method for client side (OSC and MDC and MGC) */
492 int client_connect_import(const struct lu_env *env,
493 struct obd_export **exp,
494 struct obd_device *obd, struct obd_uuid *cluuid,
495 struct obd_connect_data *data, void *localdata)
497 struct client_obd *cli = &obd->u.cli;
498 struct obd_import *imp = cli->cl_import;
499 struct obd_connect_data *ocd;
500 struct lustre_handle conn = { 0 };
505 down_write(&cli->cl_sem);
506 if (cli->cl_conn_count > 0 )
507 GOTO(out_sem, rc = -EALREADY);
509 rc = class_connect(&conn, obd, cluuid);
513 cli->cl_conn_count++;
514 *exp = class_conn2export(&conn);
516 LASSERT(obd->obd_namespace);
518 imp->imp_dlm_handle = conn;
519 rc = ptlrpc_init_import(imp);
523 ocd = &imp->imp_connect_data;
526 imp->imp_connect_flags_orig = data->ocd_connect_flags;
529 rc = ptlrpc_connect_import(imp);
531 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
534 LASSERT((*exp)->exp_connection);
537 LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
538 ocd->ocd_connect_flags, "old "LPX64", new "LPX64"\n",
539 data->ocd_connect_flags, ocd->ocd_connect_flags);
540 data->ocd_connect_flags = ocd->ocd_connect_flags;
543 ptlrpc_pinger_add_import(imp);
549 cli->cl_conn_count--;
550 class_disconnect(*exp);
554 up_write(&cli->cl_sem);
558 EXPORT_SYMBOL(client_connect_import);
560 int client_disconnect_export(struct obd_export *exp)
562 struct obd_device *obd = class_exp2obd(exp);
563 struct client_obd *cli;
564 struct obd_import *imp;
569 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
570 exp, exp ? exp->exp_handle.h_cookie : -1);
575 imp = cli->cl_import;
577 down_write(&cli->cl_sem);
578 CDEBUG(D_INFO, "disconnect %s - %d\n", obd->obd_name,
581 if (!cli->cl_conn_count) {
582 CERROR("disconnecting disconnected device (%s)\n",
584 GOTO(out_disconnect, rc = -EINVAL);
587 cli->cl_conn_count--;
588 if (cli->cl_conn_count)
589 GOTO(out_disconnect, rc = 0);
591 /* Mark import deactivated now, so we don't try to reconnect if any
592 * of the cleanup RPCs fails (e.g. LDLM cancel, etc). We don't
593 * fully deactivate the import, or that would drop all requests. */
594 spin_lock(&imp->imp_lock);
595 imp->imp_deactive = 1;
596 spin_unlock(&imp->imp_lock);
598 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
599 * delete it regardless. (It's safe to delete an import that was
601 (void)ptlrpc_pinger_del_import(imp);
603 if (obd->obd_namespace != NULL) {
604 /* obd_force == local only */
605 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
606 obd->obd_force ? LCF_LOCAL : 0, NULL);
607 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force);
610 /* There's no need to hold sem while disconnecting an import,
611 * and it may actually cause deadlock in GSS. */
612 up_write(&cli->cl_sem);
613 rc = ptlrpc_disconnect_import(imp, 0);
614 down_write(&cli->cl_sem);
616 ptlrpc_invalidate_import(imp);
621 /* Use server style - class_disconnect should be always called for
623 err = class_disconnect(exp);
627 up_write(&cli->cl_sem);
631 EXPORT_SYMBOL(client_disconnect_export);
633 #ifdef HAVE_SERVER_SUPPORT
634 int server_disconnect_export(struct obd_export *exp)
639 /* Disconnect early so that clients can't keep using export. */
640 rc = class_disconnect(exp);
641 /* Close import to avoid sending any requests. */
642 if (exp->exp_imp_reverse)
643 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
645 if (exp->exp_obd->obd_namespace != NULL)
646 ldlm_cancel_locks_for_export(exp);
648 /* complete all outstanding replies */
649 spin_lock(&exp->exp_lock);
650 while (!cfs_list_empty(&exp->exp_outstanding_replies)) {
651 struct ptlrpc_reply_state *rs =
652 cfs_list_entry(exp->exp_outstanding_replies.next,
653 struct ptlrpc_reply_state, rs_exp_list);
654 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
656 spin_lock(&svcpt->scp_rep_lock);
658 cfs_list_del_init(&rs->rs_exp_list);
659 spin_lock(&rs->rs_lock);
660 ptlrpc_schedule_difficult_reply(rs);
661 spin_unlock(&rs->rs_lock);
663 spin_unlock(&svcpt->scp_rep_lock);
665 spin_unlock(&exp->exp_lock);
669 EXPORT_SYMBOL(server_disconnect_export);
671 /* --------------------------------------------------------------------------
672 * from old lib/target.c
673 * -------------------------------------------------------------------------- */
675 static int target_handle_reconnect(struct lustre_handle *conn,
676 struct obd_export *exp,
677 struct obd_uuid *cluuid)
681 if (exp->exp_connection && exp->exp_imp_reverse) {
682 struct lustre_handle *hdl;
683 struct obd_device *target;
685 hdl = &exp->exp_imp_reverse->imp_remote_handle;
686 target = exp->exp_obd;
688 /* Might be a re-connect after a partition. */
689 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
690 if (target->obd_recovering) {
691 int timeout = cfs_duration_sec(cfs_time_sub(
693 &target->obd_recovery_timer),
694 cfs_time_current()));
696 LCONSOLE_WARN("%s: Client %s (at %s) reconnect"
697 "ing, waiting for %d clients in recov"
698 "ery for %d:%.02d\n", target->obd_name,
699 obd_uuid2str(&exp->exp_client_uuid),
700 obd_export_nid2str(exp),
701 target->obd_max_recoverable_clients,
702 timeout / 60, timeout % 60);
704 LCONSOLE_WARN("%s: Client %s (at %s) "
705 "reconnecting\n", target->obd_name,
706 obd_uuid2str(&exp->exp_client_uuid),
707 obd_export_nid2str(exp));
710 conn->cookie = exp->exp_handle.h_cookie;
711 /* target_handle_connect() treats EALREADY and
712 * -EALREADY differently. EALREADY means we are
713 * doing a valid reconnect from the same client. */
716 LCONSOLE_WARN("%s: already connected client %s (at %s) "
717 "with handle "LPX64". Rejecting client "
718 "with the same UUID trying to reconnect "
719 "with handle "LPX64"\n", target->obd_name,
720 obd_uuid2str(&exp->exp_client_uuid),
721 obd_export_nid2str(exp),
722 hdl->cookie, conn->cookie);
723 memset(conn, 0, sizeof *conn);
724 /* target_handle_connect() treats EALREADY and
725 * -EALREADY differently. -EALREADY is an error
726 * (same UUID, different handle). */
731 conn->cookie = exp->exp_handle.h_cookie;
732 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
733 cluuid->uuid, exp, conn->cookie);
737 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
740 struct obd_export *exp = cb_data;
742 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
743 obd->obd_name, exp->exp_client_uuid.uuid);
745 spin_lock(&exp->exp_lock);
746 exp->exp_need_sync = 0;
747 spin_unlock(&exp->exp_lock);
748 class_export_cb_put(exp);
750 EXPORT_SYMBOL(target_client_add_cb);
754 check_and_start_recovery_timer(struct obd_device *obd,
755 struct ptlrpc_request *req, int new_client);
758 check_and_start_recovery_timer(struct obd_device *obd,
759 struct ptlrpc_request *req, int new_client)
764 int target_handle_connect(struct ptlrpc_request *req)
766 struct obd_device *target = NULL, *targref = NULL;
767 struct obd_export *export = NULL;
768 struct obd_import *revimp;
769 struct obd_import *tmp_imp = NULL;
770 struct lustre_handle conn;
771 struct lustre_handle *tmp;
772 struct obd_uuid tgtuuid;
773 struct obd_uuid cluuid;
774 struct obd_uuid remote_uuid;
779 bool mds_conn = false, lw_client = false;
780 struct obd_connect_data *data, *tmpdata;
782 lnet_nid_t *client_nid = NULL;
785 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
787 str = req_capsule_client_get(&req->rq_pill, &RMF_TGTUUID);
789 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
790 GOTO(out, rc = -EINVAL);
793 obd_str2uuid(&tgtuuid, str);
794 target = class_uuid2obd(&tgtuuid);
796 target = class_name2obd(str);
799 deuuidify(str, NULL, &target_start, &target_len);
800 LCONSOLE_ERROR_MSG(0x137, "%s: not available for connect "
801 "from %s (no target). If you are running "
802 "an HA pair check that the target is "
803 "mounted on the other server.\n", str,
804 libcfs_nid2str(req->rq_peer.nid));
805 GOTO(out, rc = -ENODEV);
808 spin_lock(&target->obd_dev_lock);
809 if (target->obd_stopping || !target->obd_set_up) {
810 spin_unlock(&target->obd_dev_lock);
812 deuuidify(str, NULL, &target_start, &target_len);
813 LCONSOLE_INFO("%.*s: Not available for connect from %s (%s)\n",
814 target_len, target_start,
815 libcfs_nid2str(req->rq_peer.nid),
816 (target->obd_stopping ?
817 "stopping" : "not set up"));
818 GOTO(out, rc = -ENODEV);
821 if (target->obd_no_conn) {
822 spin_unlock(&target->obd_dev_lock);
824 CDEBUG(D_INFO, "%s: Temporarily refusing client connection "
825 "from %s\n", target->obd_name,
826 libcfs_nid2str(req->rq_peer.nid));
827 GOTO(out, rc = -EAGAIN);
830 /* Make sure the target isn't cleaned up while we're here. Yes,
831 * there's still a race between the above check and our incref here.
832 * Really, class_uuid2obd should take the ref. */
833 targref = class_incref(target, __FUNCTION__, current);
835 target->obd_conn_inprogress++;
836 spin_unlock(&target->obd_dev_lock);
838 str = req_capsule_client_get(&req->rq_pill, &RMF_CLUUID);
840 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
841 GOTO(out, rc = -EINVAL);
844 obd_str2uuid(&cluuid, str);
846 /* XXX Extract a nettype and format accordingly. */
847 switch (sizeof(lnet_nid_t)) {
848 /* NB the casts only avoid compiler warnings. */
850 snprintf(remote_uuid.uuid, sizeof remote_uuid,
851 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
854 snprintf(remote_uuid.uuid, sizeof remote_uuid,
855 "NET_%x_UUID", (__u32)req->rq_peer.nid);
861 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
863 GOTO(out, rc = -EPROTO);
867 size = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
869 data = req_capsule_client_get(&req->rq_pill, &RMF_CONNECT_DATA);
871 GOTO(out, rc = -EPROTO);
873 rc = req_capsule_server_pack(&req->rq_pill);
877 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
878 if (data->ocd_version < LUSTRE_VERSION_CODE -
879 LUSTRE_VERSION_ALLOWED_OFFSET ||
880 data->ocd_version > LUSTRE_VERSION_CODE +
881 LUSTRE_VERSION_ALLOWED_OFFSET) {
882 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
883 "libclient connection attempt",
884 data->ocd_version < LUSTRE_VERSION_CODE ?
886 OBD_OCD_VERSION_MAJOR(data->ocd_version),
887 OBD_OCD_VERSION_MINOR(data->ocd_version),
888 OBD_OCD_VERSION_PATCH(data->ocd_version),
889 OBD_OCD_VERSION_FIX(data->ocd_version));
890 data = req_capsule_server_sized_get(&req->rq_pill,
892 offsetof(typeof(*data), ocd_version) +
893 sizeof(data->ocd_version));
895 data->ocd_connect_flags = OBD_CONNECT_VERSION;
896 data->ocd_version = LUSTRE_VERSION_CODE;
898 GOTO(out, rc = -EPROTO);
902 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) &&
903 (data->ocd_connect_flags & OBD_CONNECT_MDS))
906 if ((data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) != 0)
909 /* lctl gets a backstage, all-access pass. */
910 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
911 goto dont_check_exports;
913 export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
917 /* We've found an export in the hash. */
919 spin_lock(&export->exp_lock);
921 if (export->exp_connecting) { /* bug 9635, et. al. */
922 spin_unlock(&export->exp_lock);
923 LCONSOLE_WARN("%s: Export %p already connecting from %s\n",
924 export->exp_obd->obd_name, export,
925 libcfs_nid2str(req->rq_peer.nid));
926 class_export_put(export);
929 } else if (mds_conn && export->exp_connection) {
930 spin_unlock(&export->exp_lock);
931 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
932 /* MDS reconnected after failover. */
933 LCONSOLE_WARN("%s: Received MDS connection from "
934 "%s, removing former export from %s\n",
935 target->obd_name, libcfs_nid2str(req->rq_peer.nid),
936 libcfs_nid2str(export->exp_connection->c_peer.nid));
938 /* New MDS connection from the same NID. */
939 LCONSOLE_WARN("%s: Received new MDS connection from "
940 "%s, removing former export from same NID\n",
941 target->obd_name, libcfs_nid2str(req->rq_peer.nid));
942 class_fail_export(export);
943 class_export_put(export);
946 } else if (export->exp_connection != NULL &&
947 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
948 (lustre_msg_get_op_flags(req->rq_reqmsg) &
949 MSG_CONNECT_INITIAL)) {
950 spin_unlock(&export->exp_lock);
951 /* In MDS failover we have static UUID but NID can change. */
952 LCONSOLE_WARN("%s: Client %s seen on new nid %s when "
953 "existing nid %s is already connected\n",
954 target->obd_name, cluuid.uuid,
955 libcfs_nid2str(req->rq_peer.nid),
957 export->exp_connection->c_peer.nid));
959 class_export_put(export);
962 export->exp_connecting = 1;
963 spin_unlock(&export->exp_lock);
964 LASSERT(export->exp_obd == target);
966 rc = target_handle_reconnect(&conn, export, &cluuid);
969 /* If we found an export, we already unlocked. */
972 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
973 } else if (req->rq_export == NULL &&
974 cfs_atomic_read(&export->exp_rpc_count) > 0) {
975 LCONSOLE_WARN("%s: Client %s (at %s) refused connection, "
976 "still busy with %d references\n",
977 target->obd_name, cluuid.uuid,
978 libcfs_nid2str(req->rq_peer.nid),
979 cfs_atomic_read(&export->exp_refcount));
980 GOTO(out, rc = -EBUSY);
981 } else if (req->rq_export != NULL &&
982 (cfs_atomic_read(&export->exp_rpc_count) > 1)) {
983 /* The current connect RPC has increased exp_rpc_count. */
984 LCONSOLE_WARN("%s: Client %s (at %s) refused reconnection, "
985 "still busy with %d active RPCs\n",
986 target->obd_name, cluuid.uuid,
987 libcfs_nid2str(req->rq_peer.nid),
988 cfs_atomic_read(&export->exp_rpc_count) - 1);
989 spin_lock(&export->exp_lock);
990 if (req->rq_export->exp_conn_cnt <
991 lustre_msg_get_conn_cnt(req->rq_reqmsg))
992 /* try to abort active requests */
993 req->rq_export->exp_abort_active_req = 1;
994 spin_unlock(&export->exp_lock);
995 GOTO(out, rc = -EBUSY);
996 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
997 if (!strstr(cluuid.uuid, "mdt"))
998 LCONSOLE_WARN("%s: Rejecting reconnect from the "
999 "known client %s (at %s) because it "
1000 "is indicating it is a new client",
1001 target->obd_name, cluuid.uuid,
1002 libcfs_nid2str(req->rq_peer.nid));
1003 GOTO(out, rc = -EALREADY);
1005 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
1012 CDEBUG(D_HA, "%s: connection from %s@%s %st"LPU64" exp %p cur %ld last %ld\n",
1013 target->obd_name, cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1014 target->obd_recovering ? "recovering/" : "", data->ocd_transno,
1015 export, (long)cfs_time_current_sec(),
1016 export ? (long)export->exp_last_request_time : 0);
1018 /* If this is the first time a client connects, reset the recovery
1019 * timer. Discard lightweight connections which might be local. */
1020 if (!lw_client && rc == 0 && target->obd_recovering)
1021 check_and_start_recovery_timer(target, req, export == NULL);
1023 /* We want to handle EALREADY but *not* -EALREADY from
1024 * target_handle_reconnect(), return reconnection state in a flag. */
1025 if (rc == EALREADY) {
1026 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
1032 /* Tell the client if we support replayable requests. */
1033 if (target->obd_replayable)
1034 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
1035 client_nid = &req->rq_peer.nid;
1037 if (export == NULL) {
1038 /* allow lightweight connections during recovery */
1039 if (target->obd_recovering && !lw_client) {
1041 int c; /* connected */
1042 int i; /* in progress */
1044 int s; /* stale/evicted */
1046 c = cfs_atomic_read(&target->obd_connected_clients);
1047 i = cfs_atomic_read(&target->obd_lock_replay_clients);
1048 k = target->obd_max_recoverable_clients;
1049 s = target->obd_stale_clients;
1050 t = cfs_timer_deadline(&target->obd_recovery_timer);
1051 t = cfs_time_sub(t, cfs_time_current());
1052 t = cfs_duration_sec(t);
1053 LCONSOLE_WARN("%s: Denying connection for new client "
1054 "%s (at %s), waiting for all %d known "
1055 "clients (%d recovered, %d in progress, "
1056 "and %d evicted) to recover in %d:%.02d\n",
1057 target->obd_name, cluuid.uuid,
1058 libcfs_nid2str(req->rq_peer.nid), k,
1059 c - i, i, s, (int)t / 60,
1064 rc = obd_connect(req->rq_svc_thread->t_env,
1065 &export, target, &cluuid, data,
1067 if (mds_conn && OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
1068 lustre_msg_add_op_flags(req->rq_repmsg,
1069 MSG_CONNECT_RECOVERING);
1071 conn.cookie = export->exp_handle.h_cookie;
1074 rc = obd_reconnect(req->rq_svc_thread->t_env,
1075 export, target, &cluuid, data, client_nid);
1080 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
1081 /* 2.2.0 clients always swab nidtbl entries due to a bug, so server
1082 * will do the swabbing for if the client is using the same endianness.
1084 * This fixup is version-limited, because we don't want to carry the
1085 * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we need
1086 * interop with unpatched 2.2 clients. For newer clients, servers
1087 * will never do MNE swabbing, let the client handle that. LU-1644 */
1088 export->exp_need_mne_swab = !ptlrpc_req_need_swab(req) &&
1089 !(data->ocd_connect_flags & OBD_CONNECT_MNE_SWAB);
1091 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and exp_need_mne_swab"
1094 LASSERT(target->u.obt.obt_magic == OBT_MAGIC);
1095 data->ocd_instance = target->u.obt.obt_instance;
1097 /* Return only the parts of obd_connect_data that we understand, so the
1098 * client knows that we don't understand the rest. */
1100 tmpsize = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
1102 tmpdata = req_capsule_server_get(&req->rq_pill,
1104 /* Don't use struct assignment here, because the client reply
1105 * buffer may be smaller/larger than the local struct
1106 * obd_connect_data. */
1107 memcpy(tmpdata, data, min(tmpsize, size));
1110 /* If all else goes well, this is our RPC return code. */
1113 lustre_msg_set_handle(req->rq_repmsg, &conn);
1115 /* If the client and the server are the same node, we will already
1116 * have an export that really points to the client's DLM export,
1117 * because we have a shared handles table.
1119 * XXX this will go away when shaver stops sending the "connect" handle
1120 * in the real "remote handle" field of the request --phik 24 Apr 2003
1122 ptlrpc_request_change_export(req, export);
1124 spin_lock(&export->exp_lock);
1125 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
1126 spin_unlock(&export->exp_lock);
1127 CDEBUG(D_RPCTRACE, "%s: %s already connected at greater "
1128 "or equal conn_cnt: %d >= %d\n",
1129 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1130 export->exp_conn_cnt,
1131 lustre_msg_get_conn_cnt(req->rq_reqmsg));
1133 GOTO(out, rc = -EALREADY);
1135 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1136 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1137 export->exp_abort_active_req = 0;
1139 /* Don't evict liblustre clients for not pinging. */
1140 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1141 export->exp_libclient = 1;
1142 spin_unlock(&export->exp_lock);
1144 spin_lock(&target->obd_dev_lock);
1145 cfs_list_del_init(&export->exp_obd_chain_timed);
1146 spin_unlock(&target->obd_dev_lock);
1148 spin_unlock(&export->exp_lock);
1151 if (export->exp_connection != NULL) {
1152 /* Check to see if connection came from another NID. */
1153 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1154 !cfs_hlist_unhashed(&export->exp_nid_hash))
1155 cfs_hash_del(export->exp_obd->obd_nid_hash,
1156 &export->exp_connection->c_peer.nid,
1157 &export->exp_nid_hash);
1159 ptlrpc_connection_put(export->exp_connection);
1162 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1165 if (cfs_hlist_unhashed(&export->exp_nid_hash)) {
1166 cfs_hash_add(export->exp_obd->obd_nid_hash,
1167 &export->exp_connection->c_peer.nid,
1168 &export->exp_nid_hash);
1171 if (target->obd_recovering && !export->exp_in_recovery && !lw_client) {
1173 __u64 transno = data->ocd_transno;
1175 spin_lock(&export->exp_lock);
1176 /* possible race with class_disconnect_stale_exports,
1177 * export may be already in the eviction process */
1178 if (export->exp_failed) {
1179 spin_unlock(&export->exp_lock);
1180 GOTO(out, rc = -ENODEV);
1182 export->exp_in_recovery = 1;
1183 export->exp_req_replay_needed = 1;
1184 export->exp_lock_replay_needed = 1;
1185 spin_unlock(&export->exp_lock);
1187 has_transno = !!(lustre_msg_get_op_flags(req->rq_reqmsg) &
1188 MSG_CONNECT_TRANSNO);
1189 if (has_transno && transno == 0)
1190 CWARN("Connect with zero transno!\n");
1192 if (has_transno && transno > 0 &&
1193 transno < target->obd_next_recovery_transno &&
1194 transno > target->obd_last_committed) {
1195 /* Another way is to use cmpxchg() to be lock-free. */
1196 spin_lock(&target->obd_recovery_task_lock);
1197 if (transno < target->obd_next_recovery_transno)
1198 target->obd_next_recovery_transno = transno;
1199 spin_unlock(&target->obd_recovery_task_lock);
1202 cfs_atomic_inc(&target->obd_req_replay_clients);
1203 cfs_atomic_inc(&target->obd_lock_replay_clients);
1204 if (cfs_atomic_inc_return(&target->obd_connected_clients) ==
1205 target->obd_max_recoverable_clients)
1206 wake_up(&target->obd_next_transno_waitq);
1209 /* Tell the client we're in recovery, when client is involved in it. */
1210 if (target->obd_recovering && !lw_client)
1211 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
1213 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
1216 /* Return -ENOTCONN in case of errors to let client reconnect. */
1217 revimp = class_new_import(target);
1218 if (revimp == NULL) {
1219 CERROR("fail to alloc new reverse import.\n");
1220 GOTO(out, rc = -ENOTCONN);
1223 spin_lock(&export->exp_lock);
1224 if (export->exp_imp_reverse != NULL)
1225 /* destroyed import can be still referenced in ctxt */
1226 tmp_imp = export->exp_imp_reverse;
1227 export->exp_imp_reverse = revimp;
1228 spin_unlock(&export->exp_lock);
1230 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1231 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1232 revimp->imp_remote_handle = conn;
1233 revimp->imp_dlm_fake = 1;
1234 revimp->imp_state = LUSTRE_IMP_FULL;
1236 /* Unknown versions will be caught in
1237 * ptlrpc_handle_server_req_in->lustre_unpack_msg(). */
1238 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1240 if ((data->ocd_connect_flags & OBD_CONNECT_AT) &&
1241 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1242 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1244 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1246 if ((data->ocd_connect_flags & OBD_CONNECT_FULL20) &&
1247 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1248 revimp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
1250 revimp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18;
1252 rc = sptlrpc_import_sec_adapt(revimp, req->rq_svc_ctx, &req->rq_flvr);
1254 CERROR("Failed to get sec for reverse import: %d\n", rc);
1255 spin_lock(&export->exp_lock);
1256 export->exp_imp_reverse = NULL;
1257 spin_unlock(&export->exp_lock);
1258 class_destroy_import(revimp);
1261 class_import_put(revimp);
1264 if (tmp_imp != NULL)
1265 client_destroy_import(tmp_imp);
1267 spin_lock(&export->exp_lock);
1268 export->exp_connecting = 0;
1269 spin_unlock(&export->exp_lock);
1271 class_export_put(export);
1274 spin_lock(&target->obd_dev_lock);
1275 target->obd_conn_inprogress--;
1276 spin_unlock(&target->obd_dev_lock);
1278 class_decref(targref, __func__, current);
1281 req->rq_status = rc;
1284 EXPORT_SYMBOL(target_handle_connect);
1286 int target_handle_disconnect(struct ptlrpc_request *req)
1291 rc = req_capsule_server_pack(&req->rq_pill);
1295 /* Keep the rq_export around so we can send the reply. */
1296 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1300 EXPORT_SYMBOL(target_handle_disconnect);
1302 void target_destroy_export(struct obd_export *exp)
1304 struct obd_import *imp = NULL;
1305 /* exports created from last_rcvd data, and "fake"
1306 exports created by lctl don't have an import */
1307 spin_lock(&exp->exp_lock);
1308 if (exp->exp_imp_reverse != NULL) {
1309 imp = exp->exp_imp_reverse;
1310 exp->exp_imp_reverse = NULL;
1312 spin_unlock(&exp->exp_lock);
1314 client_destroy_import(imp);
1316 LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
1317 LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
1318 LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
1319 LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
1321 EXPORT_SYMBOL(target_destroy_export);
1324 * Recovery functions
1326 static void target_request_copy_get(struct ptlrpc_request *req)
1328 class_export_rpc_inc(req->rq_export);
1329 LASSERT(cfs_list_empty(&req->rq_list));
1330 CFS_INIT_LIST_HEAD(&req->rq_replay_list);
1332 /* Increase refcount to keep request in queue. */
1333 cfs_atomic_inc(&req->rq_refcount);
1334 /* Let export know it has replays to be handled. */
1335 cfs_atomic_inc(&req->rq_export->exp_replay_count);
1338 static void target_request_copy_put(struct ptlrpc_request *req)
1340 LASSERT(cfs_list_empty(&req->rq_replay_list));
1341 LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
1343 cfs_atomic_dec(&req->rq_export->exp_replay_count);
1344 class_export_rpc_dec(req->rq_export);
1345 ptlrpc_server_drop_request(req);
1348 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1350 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1351 struct obd_export *exp = req->rq_export;
1352 struct ptlrpc_request *reqiter;
1357 spin_lock(&exp->exp_lock);
1358 cfs_list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1360 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1367 /* We expect it with RESENT and REPLAY flags. */
1368 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1369 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1370 CERROR("invalid flags %x of resent replay\n",
1371 lustre_msg_get_flags(req->rq_reqmsg));
1373 cfs_list_add_tail(&req->rq_replay_list,
1374 &exp->exp_req_replay_queue);
1377 spin_unlock(&exp->exp_lock);
1381 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1383 LASSERT(!cfs_list_empty(&req->rq_replay_list));
1384 LASSERT(req->rq_export);
1386 spin_lock(&req->rq_export->exp_lock);
1387 cfs_list_del_init(&req->rq_replay_list);
1388 spin_unlock(&req->rq_export->exp_lock);
1392 static void target_finish_recovery(struct obd_device *obd)
1396 /* Only log a recovery message when recovery has occurred. */
1397 if (obd->obd_recovery_start) {
1398 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1399 obd->obd_recovery_start);
1400 LCONSOLE_INFO("%s: Recovery over after %d:%.02d, of %d clients "
1401 "%d recovered and %d %s evicted.\n", obd->obd_name,
1402 (int)elapsed_time / 60, (int)elapsed_time % 60,
1403 obd->obd_max_recoverable_clients,
1404 cfs_atomic_read(&obd->obd_connected_clients),
1405 obd->obd_stale_clients,
1406 obd->obd_stale_clients == 1 ? "was" : "were");
1409 ldlm_reprocess_all_ns(obd->obd_namespace);
1410 spin_lock(&obd->obd_recovery_task_lock);
1411 if (!cfs_list_empty(&obd->obd_req_replay_queue) ||
1412 !cfs_list_empty(&obd->obd_lock_replay_queue) ||
1413 !cfs_list_empty(&obd->obd_final_req_queue)) {
1414 CERROR("%s: Recovery queues ( %s%s%s) are not empty\n",
1416 cfs_list_empty(&obd->obd_req_replay_queue) ? "" : "req ",
1417 cfs_list_empty(&obd->obd_lock_replay_queue) ? \
1419 cfs_list_empty(&obd->obd_final_req_queue) ? \
1421 spin_unlock(&obd->obd_recovery_task_lock);
1424 spin_unlock(&obd->obd_recovery_task_lock);
1426 obd->obd_recovery_end = cfs_time_current_sec();
1428 /* When recovery finished, cleanup orphans on MDS and OST. */
1429 if (OBT(obd) && OBP(obd, postrecov)) {
1430 int rc = OBP(obd, postrecov)(obd);
1432 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1438 static void abort_req_replay_queue(struct obd_device *obd)
1440 struct ptlrpc_request *req, *n;
1441 cfs_list_t abort_list;
1443 CFS_INIT_LIST_HEAD(&abort_list);
1444 spin_lock(&obd->obd_recovery_task_lock);
1445 cfs_list_splice_init(&obd->obd_req_replay_queue, &abort_list);
1446 spin_unlock(&obd->obd_recovery_task_lock);
1447 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1448 DEBUG_REQ(D_WARNING, req, "aborted:");
1449 req->rq_status = -ENOTCONN;
1450 if (ptlrpc_error(req)) {
1451 DEBUG_REQ(D_ERROR, req,
1452 "failed abort_req_reply; skipping");
1454 target_exp_dequeue_req_replay(req);
1455 target_request_copy_put(req);
1459 static void abort_lock_replay_queue(struct obd_device *obd)
1461 struct ptlrpc_request *req, *n;
1462 cfs_list_t abort_list;
1464 CFS_INIT_LIST_HEAD(&abort_list);
1465 spin_lock(&obd->obd_recovery_task_lock);
1466 cfs_list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
1467 spin_unlock(&obd->obd_recovery_task_lock);
1468 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list){
1469 DEBUG_REQ(D_ERROR, req, "aborted:");
1470 req->rq_status = -ENOTCONN;
1471 if (ptlrpc_error(req)) {
1472 DEBUG_REQ(D_ERROR, req,
1473 "failed abort_lock_reply; skipping");
1475 target_request_copy_put(req);
1479 /* Called from a cleanup function if the device is being cleaned up
1480 forcefully. The exports should all have been disconnected already,
1481 the only thing left to do is
1482 - clear the recovery flags
1484 - free queued requests and replies, but don't send replies
1485 Because the obd_stopping flag is set, no new requests should be received.
1488 void target_cleanup_recovery(struct obd_device *obd)
1490 struct ptlrpc_request *req, *n;
1491 cfs_list_t clean_list;
1494 CFS_INIT_LIST_HEAD(&clean_list);
1495 spin_lock(&obd->obd_dev_lock);
1496 if (!obd->obd_recovering) {
1497 spin_unlock(&obd->obd_dev_lock);
1501 obd->obd_recovering = obd->obd_abort_recovery = 0;
1502 spin_unlock(&obd->obd_dev_lock);
1504 spin_lock(&obd->obd_recovery_task_lock);
1505 target_cancel_recovery_timer(obd);
1506 cfs_list_splice_init(&obd->obd_req_replay_queue, &clean_list);
1507 spin_unlock(&obd->obd_recovery_task_lock);
1509 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1510 LASSERT(req->rq_reply_state == 0);
1511 target_exp_dequeue_req_replay(req);
1512 target_request_copy_put(req);
1515 spin_lock(&obd->obd_recovery_task_lock);
1516 cfs_list_splice_init(&obd->obd_lock_replay_queue, &clean_list);
1517 cfs_list_splice_init(&obd->obd_final_req_queue, &clean_list);
1518 spin_unlock(&obd->obd_recovery_task_lock);
1520 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list){
1521 LASSERT(req->rq_reply_state == 0);
1522 target_request_copy_put(req);
1527 EXPORT_SYMBOL(target_cleanup_recovery);
1529 /* obd_recovery_task_lock should be held */
1530 void target_cancel_recovery_timer(struct obd_device *obd)
1532 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1533 cfs_timer_disarm(&obd->obd_recovery_timer);
1535 EXPORT_SYMBOL(target_cancel_recovery_timer);
1537 static void target_start_recovery_timer(struct obd_device *obd)
1539 if (obd->obd_recovery_start != 0)
1542 spin_lock(&obd->obd_dev_lock);
1543 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1544 spin_unlock(&obd->obd_dev_lock);
1548 LASSERT(obd->obd_recovery_timeout != 0);
1550 if (obd->obd_recovery_start != 0) {
1551 spin_unlock(&obd->obd_dev_lock);
1555 cfs_timer_arm(&obd->obd_recovery_timer,
1556 cfs_time_shift(obd->obd_recovery_timeout));
1557 obd->obd_recovery_start = cfs_time_current_sec();
1558 spin_unlock(&obd->obd_dev_lock);
1560 LCONSOLE_WARN("%s: Will be in recovery for at least %d:%.02d, "
1561 "or until %d client%s reconnect%s\n",
1563 obd->obd_recovery_timeout / 60,
1564 obd->obd_recovery_timeout % 60,
1565 obd->obd_max_recoverable_clients,
1566 (obd->obd_max_recoverable_clients == 1) ? "" : "s",
1567 (obd->obd_max_recoverable_clients == 1) ? "s": "");
1571 * extend recovery window.
1573 * if @extend is true, extend recovery window to have @drt remaining at least;
1574 * otherwise, make sure the recovery timeout value is not less than @drt.
1576 static void extend_recovery_timer(struct obd_device *obd, int drt, bool extend)
1580 cfs_duration_t left;
1583 spin_lock(&obd->obd_dev_lock);
1584 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1585 spin_unlock(&obd->obd_dev_lock);
1588 LASSERT(obd->obd_recovery_start != 0);
1590 now = cfs_time_current_sec();
1591 to = obd->obd_recovery_timeout;
1592 end = obd->obd_recovery_start + to;
1593 left = cfs_time_sub(end, now);
1595 if (extend && (drt > left)) {
1597 } else if (!extend && (drt > to)) {
1599 /* reduce drt by already passed time */
1600 drt -= obd->obd_recovery_timeout - left;
1603 if (to > obd->obd_recovery_time_hard)
1604 to = obd->obd_recovery_time_hard;
1605 if (obd->obd_recovery_timeout < to ||
1606 obd->obd_recovery_timeout == obd->obd_recovery_time_hard) {
1607 obd->obd_recovery_timeout = to;
1608 cfs_timer_arm(&obd->obd_recovery_timer,
1609 cfs_time_shift(drt));
1611 spin_unlock(&obd->obd_dev_lock);
1613 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1614 obd->obd_name, (unsigned)drt);
1617 /* Reset the timer with each new client connection */
1619 * This timer is actually reconnect_timer, which is for making sure
1620 * the total recovery window is at least as big as my reconnect
1621 * attempt timing. So the initial recovery time_out will be set to
1622 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1623 * from client is bigger than this, then the recovery time_out will
1624 * be extended to make sure the client could be reconnected, in the
1625 * process, the timeout from the new client should be ignored.
1629 check_and_start_recovery_timer(struct obd_device *obd,
1630 struct ptlrpc_request *req,
1633 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1634 struct obd_device_target *obt = &obd->u.obt;
1636 if (!new_client && service_time)
1637 /* Teach server about old server's estimates, as first guess
1638 * at how long new requests will take. */
1639 at_measured(&req->rq_rqbd->rqbd_svcpt->scp_at_estimate,
1642 target_start_recovery_timer(obd);
1644 /* Convert the service time to RPC timeout,
1645 * and reuse service_time to limit stack usage. */
1646 service_time = at_est2timeout(service_time);
1648 /* We expect other clients to timeout within service_time, then try
1649 * to reconnect, then try the failover server. The max delay between
1650 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL. */
1651 service_time += 2 * INITIAL_CONNECT_TIMEOUT;
1653 LASSERT(obt->obt_magic == OBT_MAGIC);
1654 service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
1655 if (service_time > obd->obd_recovery_timeout && !new_client)
1656 extend_recovery_timer(obd, service_time, false);
1659 /** Health checking routines */
1660 static inline int exp_connect_healthy(struct obd_export *exp)
1662 return (exp->exp_in_recovery);
1665 /** if export done req_replay or has replay in queue */
1666 static inline int exp_req_replay_healthy(struct obd_export *exp)
1668 return (!exp->exp_req_replay_needed ||
1669 cfs_atomic_read(&exp->exp_replay_count) > 0);
1671 /** if export done lock_replay or has replay in queue */
1672 static inline int exp_lock_replay_healthy(struct obd_export *exp)
1674 return (!exp->exp_lock_replay_needed ||
1675 cfs_atomic_read(&exp->exp_replay_count) > 0);
1678 static inline int exp_vbr_healthy(struct obd_export *exp)
1680 return (!exp->exp_vbr_failed);
1683 static inline int exp_finished(struct obd_export *exp)
1685 return (exp->exp_in_recovery && !exp->exp_lock_replay_needed);
1688 /** Checking routines for recovery */
1689 static int check_for_clients(struct obd_device *obd)
1691 unsigned int clnts = cfs_atomic_read(&obd->obd_connected_clients);
1693 if (obd->obd_abort_recovery || obd->obd_recovery_expired)
1695 LASSERT(clnts <= obd->obd_max_recoverable_clients);
1696 return (clnts + obd->obd_stale_clients ==
1697 obd->obd_max_recoverable_clients);
1700 static int check_for_next_transno(struct obd_device *obd)
1702 struct ptlrpc_request *req = NULL;
1703 int wake_up = 0, connected, completed, queue_len;
1704 __u64 next_transno, req_transno;
1707 spin_lock(&obd->obd_recovery_task_lock);
1708 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1709 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1710 struct ptlrpc_request, rq_list);
1711 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1716 connected = cfs_atomic_read(&obd->obd_connected_clients);
1717 completed = connected - cfs_atomic_read(&obd->obd_req_replay_clients);
1718 queue_len = obd->obd_requests_queued_for_recovery;
1719 next_transno = obd->obd_next_recovery_transno;
1721 CDEBUG(D_HA, "max: %d, connected: %d, completed: %d, queue_len: %d, "
1722 "req_transno: "LPU64", next_transno: "LPU64"\n",
1723 obd->obd_max_recoverable_clients, connected, completed,
1724 queue_len, req_transno, next_transno);
1726 if (obd->obd_abort_recovery) {
1727 CDEBUG(D_HA, "waking for aborted recovery\n");
1729 } else if (obd->obd_recovery_expired) {
1730 CDEBUG(D_HA, "waking for expired recovery\n");
1732 } else if (req_transno == next_transno) {
1733 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1735 } else if (queue_len > 0 &&
1736 queue_len == cfs_atomic_read(&obd->obd_req_replay_clients)) {
1738 /** handle gaps occured due to lost reply or VBR */
1739 LASSERTF(req_transno >= next_transno,
1740 "req_transno: "LPU64", next_transno: "LPU64"\n",
1741 req_transno, next_transno);
1742 if (req_transno > obd->obd_last_committed &&
1743 !obd->obd_version_recov)
1746 "%s: waking for gap in transno, VBR is %s (skip: "
1747 LPD64", ql: %d, comp: %d, conn: %d, next: "LPD64
1748 ", last_committed: "LPD64")\n",
1749 obd->obd_name, obd->obd_version_recov ? "ON" : "OFF",
1750 next_transno, queue_len, completed, connected,
1751 req_transno, obd->obd_last_committed);
1752 obd->obd_next_recovery_transno = req_transno;
1754 } else if (cfs_atomic_read(&obd->obd_req_replay_clients) == 0) {
1755 CDEBUG(D_HA, "waking for completed recovery\n");
1757 } else if (OBD_FAIL_CHECK(OBD_FAIL_MDS_RECOVERY_ACCEPTS_GAPS)) {
1758 CDEBUG(D_HA, "accepting transno gaps is explicitly allowed"
1759 " by fail_lock, waking up ("LPD64")\n", next_transno);
1760 obd->obd_next_recovery_transno = req_transno;
1763 spin_unlock(&obd->obd_recovery_task_lock);
1767 static int check_for_next_lock(struct obd_device *obd)
1771 spin_lock(&obd->obd_recovery_task_lock);
1772 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1773 CDEBUG(D_HA, "waking for next lock\n");
1775 } else if (cfs_atomic_read(&obd->obd_lock_replay_clients) == 0) {
1776 CDEBUG(D_HA, "waking for completed lock replay\n");
1778 } else if (obd->obd_abort_recovery) {
1779 CDEBUG(D_HA, "waking for aborted recovery\n");
1781 } else if (obd->obd_recovery_expired) {
1782 CDEBUG(D_HA, "waking for expired recovery\n");
1785 spin_unlock(&obd->obd_recovery_task_lock);
1791 * wait for recovery events,
1792 * check its status with help of check_routine
1793 * evict dead clients via health_check
1795 static int target_recovery_overseer(struct obd_device *obd,
1796 int (*check_routine)(struct obd_device *),
1797 int (*health_check)(struct obd_export *))
1800 wait_event(obd->obd_next_transno_waitq, check_routine(obd));
1801 if (obd->obd_abort_recovery) {
1802 CWARN("recovery is aborted, evict exports in recovery\n");
1803 /** evict exports which didn't finish recovery yet */
1804 class_disconnect_stale_exports(obd, exp_finished);
1806 } else if (obd->obd_recovery_expired) {
1807 obd->obd_recovery_expired = 0;
1808 /** If some clients died being recovered, evict them */
1809 LCONSOLE_WARN("%s: recovery is timed out, "
1810 "evict stale exports\n", obd->obd_name);
1811 /** evict cexports with no replay in queue, they are stalled */
1812 class_disconnect_stale_exports(obd, health_check);
1813 /** continue with VBR */
1814 spin_lock(&obd->obd_dev_lock);
1815 obd->obd_version_recov = 1;
1816 spin_unlock(&obd->obd_dev_lock);
1818 * reset timer, recovery will proceed with versions now,
1819 * timeout is set just to handle reconnection delays
1821 extend_recovery_timer(obd, RECONNECT_DELAY_MAX, true);
1822 /** Wait for recovery events again, after evicting bad clients */
1828 static struct ptlrpc_request *target_next_replay_req(struct obd_device *obd)
1830 struct ptlrpc_request *req = NULL;
1833 CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1834 obd->obd_next_recovery_transno);
1836 if (target_recovery_overseer(obd, check_for_next_transno,
1837 exp_req_replay_healthy)) {
1838 abort_req_replay_queue(obd);
1839 abort_lock_replay_queue(obd);
1842 spin_lock(&obd->obd_recovery_task_lock);
1843 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1844 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1845 struct ptlrpc_request, rq_list);
1846 cfs_list_del_init(&req->rq_list);
1847 obd->obd_requests_queued_for_recovery--;
1848 spin_unlock(&obd->obd_recovery_task_lock);
1850 spin_unlock(&obd->obd_recovery_task_lock);
1851 LASSERT(cfs_list_empty(&obd->obd_req_replay_queue));
1852 LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
1853 /** evict exports failed VBR */
1854 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1859 static struct ptlrpc_request *target_next_replay_lock(struct obd_device *obd)
1861 struct ptlrpc_request *req = NULL;
1863 CDEBUG(D_HA, "Waiting for lock\n");
1864 if (target_recovery_overseer(obd, check_for_next_lock,
1865 exp_lock_replay_healthy))
1866 abort_lock_replay_queue(obd);
1868 spin_lock(&obd->obd_recovery_task_lock);
1869 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1870 req = cfs_list_entry(obd->obd_lock_replay_queue.next,
1871 struct ptlrpc_request, rq_list);
1872 cfs_list_del_init(&req->rq_list);
1873 spin_unlock(&obd->obd_recovery_task_lock);
1875 spin_unlock(&obd->obd_recovery_task_lock);
1876 LASSERT(cfs_list_empty(&obd->obd_lock_replay_queue));
1877 LASSERT(cfs_atomic_read(&obd->obd_lock_replay_clients) == 0);
1878 /** evict exports failed VBR */
1879 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1884 static struct ptlrpc_request *target_next_final_ping(struct obd_device *obd)
1886 struct ptlrpc_request *req = NULL;
1888 spin_lock(&obd->obd_recovery_task_lock);
1889 if (!cfs_list_empty(&obd->obd_final_req_queue)) {
1890 req = cfs_list_entry(obd->obd_final_req_queue.next,
1891 struct ptlrpc_request, rq_list);
1892 cfs_list_del_init(&req->rq_list);
1893 spin_unlock(&obd->obd_recovery_task_lock);
1894 if (req->rq_export->exp_in_recovery) {
1895 spin_lock(&req->rq_export->exp_lock);
1896 req->rq_export->exp_in_recovery = 0;
1897 spin_unlock(&req->rq_export->exp_lock);
1900 spin_unlock(&obd->obd_recovery_task_lock);
1905 static int handle_recovery_req(struct ptlrpc_thread *thread,
1906 struct ptlrpc_request *req,
1907 svc_handler_t handler)
1913 * export can be evicted during recovery, no need to handle replays for
1914 * it after that, discard such request silently
1916 if (req->rq_export->exp_disconnected)
1917 GOTO(reqcopy_put, rc = 0);
1919 rc = lu_context_init(&req->rq_recov_session, LCT_SERVER_SESSION);
1921 CERROR("Failure to initialize session: %d\n", rc);
1922 GOTO(reqcopy_put, rc);
1925 req->rq_recov_session.lc_thread = thread;
1926 lu_context_enter(&req->rq_recov_session);
1927 req->rq_svc_thread = thread;
1928 req->rq_svc_thread->t_env->le_ses = &req->rq_recov_session;
1930 /* thread context */
1931 lu_context_enter(&thread->t_env->le_ctx);
1933 lu_context_exit(&thread->t_env->le_ctx);
1935 lu_context_exit(&req->rq_recov_session);
1936 lu_context_fini(&req->rq_recov_session);
1937 /* don't reset timer for final stage */
1938 if (!exp_finished(req->rq_export)) {
1939 int to = obd_timeout;
1942 * Add request timeout to the recovery time so next request from
1943 * this client may come in recovery time
1946 struct ptlrpc_service_part *svcpt;
1948 svcpt = req->rq_rqbd->rqbd_svcpt;
1949 /* If the server sent early reply for this request,
1950 * the client will recalculate the timeout according to
1951 * current server estimate service time, so we will
1952 * use the maxium timeout here for waiting the client
1953 * sending the next req */
1954 to = max((int)at_est2timeout(
1955 at_get(&svcpt->scp_at_estimate)),
1956 (int)lustre_msg_get_timeout(req->rq_reqmsg));
1957 /* Add 2 net_latency, one for balance rq_deadline
1958 * (see ptl_send_rpc), one for resend the req to server,
1959 * Note: client will pack net_latency in replay req
1960 * (see ptlrpc_replay_req) */
1961 to += 2 * lustre_msg_get_service_time(req->rq_reqmsg);
1963 extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
1969 static int target_recovery_thread(void *arg)
1971 struct lu_target *lut = arg;
1972 struct obd_device *obd = lut->lut_obd;
1973 struct ptlrpc_request *req;
1974 struct target_recovery_data *trd = &obd->obd_recovery_data;
1975 unsigned long delta;
1977 struct ptlrpc_thread *thread = NULL;
1981 unshare_fs_struct();
1982 OBD_ALLOC_PTR(thread);
1988 OBD_FREE_PTR(thread);
1992 rc = lu_context_init(&env->le_ctx, LCT_MD_THREAD | LCT_DT_THREAD);
1994 OBD_FREE_PTR(thread);
1999 thread->t_env = env;
2000 thread->t_id = -1; /* force filter_iobuf_get/put to use local buffers */
2001 env->le_ctx.lc_thread = thread;
2002 thread->t_data = NULL;
2003 thread->t_watchdog = NULL;
2005 CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
2007 trd->trd_processing_task = current_pid();
2009 spin_lock(&obd->obd_dev_lock);
2010 obd->obd_recovering = 1;
2011 spin_unlock(&obd->obd_dev_lock);
2012 complete(&trd->trd_starting);
2014 /* first of all, we have to know the first transno to replay */
2015 if (target_recovery_overseer(obd, check_for_clients,
2016 exp_connect_healthy)) {
2017 abort_req_replay_queue(obd);
2018 abort_lock_replay_queue(obd);
2021 /* next stage: replay requests */
2023 CDEBUG(D_INFO, "1: request replay stage - %d clients from t"LPU64"\n",
2024 cfs_atomic_read(&obd->obd_req_replay_clients),
2025 obd->obd_next_recovery_transno);
2026 while ((req = target_next_replay_req(obd))) {
2027 LASSERT(trd->trd_processing_task == current_pid());
2028 DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s",
2029 lustre_msg_get_transno(req->rq_reqmsg),
2030 libcfs_nid2str(req->rq_peer.nid));
2031 handle_recovery_req(thread, req,
2032 trd->trd_recovery_handler);
2034 * bz18031: increase next_recovery_transno before
2035 * target_request_copy_put() will drop exp_rpc reference
2037 spin_lock(&obd->obd_recovery_task_lock);
2038 obd->obd_next_recovery_transno++;
2039 spin_unlock(&obd->obd_recovery_task_lock);
2040 target_exp_dequeue_req_replay(req);
2041 target_request_copy_put(req);
2042 obd->obd_replayed_requests++;
2046 * The second stage: replay locks
2048 CDEBUG(D_INFO, "2: lock replay stage - %d clients\n",
2049 cfs_atomic_read(&obd->obd_lock_replay_clients));
2050 while ((req = target_next_replay_lock(obd))) {
2051 LASSERT(trd->trd_processing_task == current_pid());
2052 DEBUG_REQ(D_HA, req, "processing lock from %s: ",
2053 libcfs_nid2str(req->rq_peer.nid));
2054 handle_recovery_req(thread, req,
2055 trd->trd_recovery_handler);
2056 target_request_copy_put(req);
2057 obd->obd_replayed_locks++;
2061 * The third stage: reply on final pings, at this moment all clients
2062 * must have request in final queue
2064 CDEBUG(D_INFO, "3: final stage - process recovery completion pings\n");
2065 /** Update server last boot epoch */
2066 tgt_boot_epoch_update(lut);
2067 /* We drop recoverying flag to forward all new requests
2068 * to regular mds_handle() since now */
2069 spin_lock(&obd->obd_dev_lock);
2070 obd->obd_recovering = obd->obd_abort_recovery = 0;
2071 spin_unlock(&obd->obd_dev_lock);
2072 spin_lock(&obd->obd_recovery_task_lock);
2073 target_cancel_recovery_timer(obd);
2074 spin_unlock(&obd->obd_recovery_task_lock);
2075 while ((req = target_next_final_ping(obd))) {
2076 LASSERT(trd->trd_processing_task == current_pid());
2077 DEBUG_REQ(D_HA, req, "processing final ping from %s: ",
2078 libcfs_nid2str(req->rq_peer.nid));
2079 handle_recovery_req(thread, req,
2080 trd->trd_recovery_handler);
2081 target_request_copy_put(req);
2084 delta = (jiffies - delta) / HZ;
2085 CDEBUG(D_INFO,"4: recovery completed in %lus - %d/%d reqs/locks\n",
2086 delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
2087 if (delta > OBD_RECOVERY_TIME_SOFT) {
2088 CWARN("too long recovery - read logs\n");
2089 libcfs_debug_dumplog();
2092 target_finish_recovery(obd);
2094 lu_context_fini(&env->le_ctx);
2095 trd->trd_processing_task = 0;
2096 complete(&trd->trd_finishing);
2098 OBD_FREE_PTR(thread);
2103 static int target_start_recovery_thread(struct lu_target *lut,
2104 svc_handler_t handler)
2106 struct obd_device *obd = lut->lut_obd;
2108 struct target_recovery_data *trd = &obd->obd_recovery_data;
2110 memset(trd, 0, sizeof(*trd));
2111 init_completion(&trd->trd_starting);
2112 init_completion(&trd->trd_finishing);
2113 trd->trd_recovery_handler = handler;
2115 if (!IS_ERR(kthread_run(target_recovery_thread,
2116 lut, "tgt_recov"))) {
2117 wait_for_completion(&trd->trd_starting);
2118 LASSERT(obd->obd_recovering != 0);
2126 void target_stop_recovery_thread(struct obd_device *obd)
2128 if (obd->obd_recovery_data.trd_processing_task > 0) {
2129 struct target_recovery_data *trd = &obd->obd_recovery_data;
2130 /** recovery can be done but postrecovery is not yet */
2131 spin_lock(&obd->obd_dev_lock);
2132 if (obd->obd_recovering) {
2133 CERROR("%s: Aborting recovery\n", obd->obd_name);
2134 obd->obd_abort_recovery = 1;
2135 wake_up(&obd->obd_next_transno_waitq);
2137 spin_unlock(&obd->obd_dev_lock);
2138 wait_for_completion(&trd->trd_finishing);
2141 EXPORT_SYMBOL(target_stop_recovery_thread);
2143 void target_recovery_fini(struct obd_device *obd)
2145 class_disconnect_exports(obd);
2146 target_stop_recovery_thread(obd);
2147 target_cleanup_recovery(obd);
2149 EXPORT_SYMBOL(target_recovery_fini);
2151 static void target_recovery_expired(unsigned long castmeharder)
2153 struct obd_device *obd = (struct obd_device *)castmeharder;
2154 CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery"
2155 " after %lds (%d clients connected)\n",
2156 obd->obd_name, cfs_atomic_read(&obd->obd_lock_replay_clients),
2157 cfs_time_current_sec()- obd->obd_recovery_start,
2158 cfs_atomic_read(&obd->obd_connected_clients));
2160 obd->obd_recovery_expired = 1;
2161 wake_up(&obd->obd_next_transno_waitq);
2164 void target_recovery_init(struct lu_target *lut, svc_handler_t handler)
2166 struct obd_device *obd = lut->lut_obd;
2167 if (obd->obd_max_recoverable_clients == 0) {
2168 /** Update server last boot epoch */
2169 tgt_boot_epoch_update(lut);
2173 CDEBUG(D_HA, "RECOVERY: service %s, %d recoverable clients, "
2174 "last_transno "LPU64"\n", obd->obd_name,
2175 obd->obd_max_recoverable_clients, obd->obd_last_committed);
2176 LASSERT(obd->obd_stopping == 0);
2177 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
2178 obd->obd_recovery_start = 0;
2179 obd->obd_recovery_end = 0;
2181 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
2182 target_start_recovery_thread(lut, handler);
2184 EXPORT_SYMBOL(target_recovery_init);
2186 #endif /* __KERNEL__ */
2188 static int target_process_req_flags(struct obd_device *obd,
2189 struct ptlrpc_request *req)
2191 struct obd_export *exp = req->rq_export;
2192 LASSERT(exp != NULL);
2193 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2194 /* client declares he's ready to replay locks */
2195 spin_lock(&exp->exp_lock);
2196 if (exp->exp_req_replay_needed) {
2197 exp->exp_req_replay_needed = 0;
2198 spin_unlock(&exp->exp_lock);
2200 LASSERT_ATOMIC_POS(&obd->obd_req_replay_clients);
2201 cfs_atomic_dec(&obd->obd_req_replay_clients);
2203 spin_unlock(&exp->exp_lock);
2206 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2207 /* client declares he's ready to complete recovery
2208 * so, we put the request on th final queue */
2209 spin_lock(&exp->exp_lock);
2210 if (exp->exp_lock_replay_needed) {
2211 exp->exp_lock_replay_needed = 0;
2212 spin_unlock(&exp->exp_lock);
2214 LASSERT_ATOMIC_POS(&obd->obd_lock_replay_clients);
2215 cfs_atomic_dec(&obd->obd_lock_replay_clients);
2217 spin_unlock(&exp->exp_lock);
2223 int target_queue_recovery_request(struct ptlrpc_request *req,
2224 struct obd_device *obd)
2228 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
2231 if (obd->obd_recovery_data.trd_processing_task == current_pid()) {
2232 /* Processing the queue right now, don't re-add. */
2236 target_process_req_flags(obd, req);
2238 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2239 /* client declares he's ready to complete recovery
2240 * so, we put the request on th final queue */
2241 target_request_copy_get(req);
2242 DEBUG_REQ(D_HA, req, "queue final req");
2243 wake_up(&obd->obd_next_transno_waitq);
2244 spin_lock(&obd->obd_recovery_task_lock);
2245 if (obd->obd_recovering) {
2246 cfs_list_add_tail(&req->rq_list,
2247 &obd->obd_final_req_queue);
2249 spin_unlock(&obd->obd_recovery_task_lock);
2250 target_request_copy_put(req);
2251 RETURN(obd->obd_stopping ? -ENOTCONN : 1);
2253 spin_unlock(&obd->obd_recovery_task_lock);
2256 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2257 /* client declares he's ready to replay locks */
2258 target_request_copy_get(req);
2259 DEBUG_REQ(D_HA, req, "queue lock replay req");
2260 wake_up(&obd->obd_next_transno_waitq);
2261 spin_lock(&obd->obd_recovery_task_lock);
2262 LASSERT(obd->obd_recovering);
2263 /* usually due to recovery abort */
2264 if (!req->rq_export->exp_in_recovery) {
2265 spin_unlock(&obd->obd_recovery_task_lock);
2266 target_request_copy_put(req);
2269 LASSERT(req->rq_export->exp_lock_replay_needed);
2270 cfs_list_add_tail(&req->rq_list, &obd->obd_lock_replay_queue);
2271 spin_unlock(&obd->obd_recovery_task_lock);
2275 /* CAVEAT EMPTOR: The incoming request message has been swabbed
2276 * (i.e. buflens etc are in my own byte order), but type-dependent
2277 * buffers (eg mdt_body, ost_body etc) have NOT been swabbed. */
2280 CFS_INIT_LIST_HEAD(&req->rq_list);
2281 DEBUG_REQ(D_HA, req, "not queueing");
2285 /* If we're processing the queue, we want don't want to queue this
2288 * Also, if this request has a transno less than the one we're waiting
2289 * for, we should process it now. It could (and currently always will)
2290 * be an open request for a descriptor that was opened some time ago.
2292 * Also, a resent, replayed request that has already been
2293 * handled will pass through here and be processed immediately.
2295 CDEBUG(D_HA, "Next recovery transno: "LPU64
2296 ", current: "LPU64", replaying\n",
2297 obd->obd_next_recovery_transno, transno);
2298 spin_lock(&obd->obd_recovery_task_lock);
2299 if (transno < obd->obd_next_recovery_transno) {
2300 /* Processing the queue right now, don't re-add. */
2301 LASSERT(cfs_list_empty(&req->rq_list));
2302 spin_unlock(&obd->obd_recovery_task_lock);
2305 spin_unlock(&obd->obd_recovery_task_lock);
2307 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))
2310 target_request_copy_get(req);
2311 if (!req->rq_export->exp_in_recovery) {
2312 target_request_copy_put(req);
2315 LASSERT(req->rq_export->exp_req_replay_needed);
2317 if (target_exp_enqueue_req_replay(req)) {
2318 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
2319 target_request_copy_put(req);
2324 spin_lock(&obd->obd_recovery_task_lock);
2325 LASSERT(obd->obd_recovering);
2326 cfs_list_for_each(tmp, &obd->obd_req_replay_queue) {
2327 struct ptlrpc_request *reqiter =
2328 cfs_list_entry(tmp, struct ptlrpc_request, rq_list);
2330 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
2331 cfs_list_add_tail(&req->rq_list, &reqiter->rq_list);
2336 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
2338 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
2339 "has been claimed by another client");
2340 spin_unlock(&obd->obd_recovery_task_lock);
2341 target_exp_dequeue_req_replay(req);
2342 target_request_copy_put(req);
2348 cfs_list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
2350 obd->obd_requests_queued_for_recovery++;
2351 spin_unlock(&obd->obd_recovery_task_lock);
2352 wake_up(&obd->obd_next_transno_waitq);
2355 EXPORT_SYMBOL(target_queue_recovery_request);
2357 int target_handle_ping(struct ptlrpc_request *req)
2359 obd_ping(req->rq_svc_thread->t_env, req->rq_export);
2360 return req_capsule_server_pack(&req->rq_pill);
2362 EXPORT_SYMBOL(target_handle_ping);
2364 void target_committed_to_req(struct ptlrpc_request *req)
2366 struct obd_export *exp = req->rq_export;
2368 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL)
2369 lustre_msg_set_last_committed(req->rq_repmsg,
2370 exp->exp_last_committed);
2372 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2373 "%d)", exp->exp_obd->obd_no_transno,
2374 req->rq_repmsg == NULL);
2376 CDEBUG(D_INFO, "last_committed "LPU64", transno "LPU64", xid "LPU64"\n",
2377 exp->exp_last_committed, req->rq_transno, req->rq_xid);
2379 EXPORT_SYMBOL(target_committed_to_req);
2381 #endif /* HAVE_SERVER_SUPPORT */
2384 * Packs current SLV and Limit into \a req.
2386 int target_pack_pool_reply(struct ptlrpc_request *req)
2388 struct obd_device *obd;
2391 /* Check that we still have all structures alive as this may
2392 * be some late RPC at shutdown time. */
2393 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
2394 !exp_connect_lru_resize(req->rq_export))) {
2395 lustre_msg_set_slv(req->rq_repmsg, 0);
2396 lustre_msg_set_limit(req->rq_repmsg, 0);
2400 /* OBD is alive here as export is alive, which we checked above. */
2401 obd = req->rq_export->exp_obd;
2403 read_lock(&obd->obd_pool_lock);
2404 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
2405 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
2406 read_unlock(&obd->obd_pool_lock);
2410 EXPORT_SYMBOL(target_pack_pool_reply);
2412 int target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id)
2414 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
2415 DEBUG_REQ(D_ERROR, req, "dropping reply");
2420 DEBUG_REQ(D_NET, req, "processing error (%d)", rc);
2421 req->rq_status = rc;
2422 return (ptlrpc_send_error(req, 1));
2424 DEBUG_REQ(D_NET, req, "sending reply");
2427 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
2430 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
2432 struct ptlrpc_service_part *svcpt;
2434 struct ptlrpc_reply_state *rs;
2435 struct obd_export *exp;
2438 if (req->rq_no_reply) {
2443 svcpt = req->rq_rqbd->rqbd_svcpt;
2444 rs = req->rq_reply_state;
2445 if (rs == NULL || !rs->rs_difficult) {
2447 target_send_reply_msg (req, rc, fail_id);
2452 /* must be an export if locks saved */
2453 LASSERT (req->rq_export != NULL);
2454 /* req/reply consistent */
2455 LASSERT(rs->rs_svcpt == svcpt);
2458 LASSERT (!rs->rs_scheduled);
2459 LASSERT (!rs->rs_scheduled_ever);
2460 LASSERT (!rs->rs_handled);
2461 LASSERT (!rs->rs_on_net);
2462 LASSERT (rs->rs_export == NULL);
2463 LASSERT (cfs_list_empty(&rs->rs_obd_list));
2464 LASSERT (cfs_list_empty(&rs->rs_exp_list));
2466 exp = class_export_get (req->rq_export);
2468 /* disable reply scheduling while I'm setting up */
2469 rs->rs_scheduled = 1;
2471 rs->rs_xid = req->rq_xid;
2472 rs->rs_transno = req->rq_transno;
2473 rs->rs_export = exp;
2474 rs->rs_opc = lustre_msg_get_opc(req->rq_reqmsg);
2476 spin_lock(&exp->exp_uncommitted_replies_lock);
2477 CDEBUG(D_NET, "rs transno = "LPU64", last committed = "LPU64"\n",
2478 rs->rs_transno, exp->exp_last_committed);
2479 if (rs->rs_transno > exp->exp_last_committed) {
2480 /* not committed already */
2481 cfs_list_add_tail(&rs->rs_obd_list,
2482 &exp->exp_uncommitted_replies);
2484 spin_unlock(&exp->exp_uncommitted_replies_lock);
2486 spin_lock(&exp->exp_lock);
2487 cfs_list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies);
2488 spin_unlock(&exp->exp_lock);
2490 netrc = target_send_reply_msg(req, rc, fail_id);
2492 spin_lock(&svcpt->scp_rep_lock);
2494 cfs_atomic_inc(&svcpt->scp_nreps_difficult);
2497 /* error sending: reply is off the net. Also we need +1
2498 * reply ref until ptlrpc_handle_rs() is done
2499 * with the reply state (if the send was successful, there
2500 * would have been +1 ref for the net, which
2501 * reply_out_callback leaves alone) */
2503 ptlrpc_rs_addref(rs);
2506 spin_lock(&rs->rs_lock);
2507 if (rs->rs_transno <= exp->exp_last_committed ||
2508 (!rs->rs_on_net && !rs->rs_no_ack) ||
2509 cfs_list_empty(&rs->rs_exp_list) || /* completed already */
2510 cfs_list_empty(&rs->rs_obd_list)) {
2511 CDEBUG(D_HA, "Schedule reply immediately\n");
2512 ptlrpc_dispatch_difficult_reply(rs);
2514 cfs_list_add(&rs->rs_list, &svcpt->scp_rep_active);
2515 rs->rs_scheduled = 0; /* allow notifier to schedule */
2517 spin_unlock(&rs->rs_lock);
2518 spin_unlock(&svcpt->scp_rep_lock);
2521 EXPORT_SYMBOL(target_send_reply);
2523 ldlm_mode_t lck_compat_array[] = {
2524 [LCK_EX] LCK_COMPAT_EX,
2525 [LCK_PW] LCK_COMPAT_PW,
2526 [LCK_PR] LCK_COMPAT_PR,
2527 [LCK_CW] LCK_COMPAT_CW,
2528 [LCK_CR] LCK_COMPAT_CR,
2529 [LCK_NL] LCK_COMPAT_NL,
2530 [LCK_GROUP] LCK_COMPAT_GROUP,
2531 [LCK_COS] LCK_COMPAT_COS,
2535 * Rather arbitrary mapping from LDLM error codes to errno values. This should
2536 * not escape to the user level.
2538 int ldlm_error2errno(ldlm_error_t error)
2546 case ELDLM_LOCK_CHANGED:
2549 case ELDLM_LOCK_ABORTED:
2552 case ELDLM_LOCK_REPLACED:
2555 case ELDLM_NO_LOCK_DATA:
2558 case ELDLM_NAMESPACE_EXISTS:
2561 case ELDLM_BAD_NAMESPACE:
2565 if (((int)error) < 0) /* cast to signed type */
2566 result = error; /* as ldlm_error_t can be unsigned */
2568 CERROR("Invalid DLM result code: %d\n", error);
2574 EXPORT_SYMBOL(ldlm_error2errno);
2577 * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
2579 ldlm_error_t ldlm_errno2error(int err_no)
2588 error = ELDLM_LOCK_CHANGED;
2591 error = ELDLM_LOCK_ABORTED;
2594 error = ELDLM_LOCK_REPLACED;
2597 error = ELDLM_NO_LOCK_DATA;
2600 error = ELDLM_NAMESPACE_EXISTS;
2603 error = ELDLM_BAD_NAMESPACE;
2610 EXPORT_SYMBOL(ldlm_errno2error);
2612 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2613 void ldlm_dump_export_locks(struct obd_export *exp)
2615 spin_lock(&exp->exp_locks_list_guard);
2616 if (!cfs_list_empty(&exp->exp_locks_list)) {
2617 struct ldlm_lock *lock;
2619 CERROR("dumping locks for export %p,"
2620 "ignore if the unmount doesn't hang\n", exp);
2621 cfs_list_for_each_entry(lock, &exp->exp_locks_list,
2623 LDLM_ERROR(lock, "lock:");
2625 spin_unlock(&exp->exp_locks_list_guard);
2629 #ifdef HAVE_SERVER_SUPPORT
2630 static int target_bulk_timeout(void *data)
2633 /* We don't fail the connection here, because having the export
2634 * killed makes the (vital) call to commitrw very sad.
2639 static inline char *bulk2type(struct ptlrpc_bulk_desc *desc)
2641 return desc->bd_type == BULK_GET_SINK ? "GET" : "PUT";
2644 int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc,
2645 struct l_wait_info *lwi)
2647 struct ptlrpc_request *req = desc->bd_req;
2651 /* If there is eviction in progress, wait for it to finish. */
2652 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
2653 *lwi = LWI_INTR(NULL, NULL);
2654 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
2655 !cfs_atomic_read(&exp->exp_obd->
2656 obd_evict_inprogress),
2660 /* Check if client was evicted or tried to reconnect already. */
2661 if (exp->exp_failed || exp->exp_abort_active_req) {
2664 if (desc->bd_type == BULK_PUT_SINK)
2665 rc = sptlrpc_svc_wrap_bulk(req, desc);
2667 rc = ptlrpc_start_bulk_transfer(desc);
2670 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
2671 ptlrpc_abort_bulk(desc);
2672 } else if (rc == 0) {
2673 time_t start = cfs_time_current_sec();
2675 long timeoutl = req->rq_deadline - cfs_time_current_sec();
2676 cfs_duration_t timeout = timeoutl <= 0 ?
2677 CFS_TICK : cfs_time_seconds(timeoutl);
2678 *lwi = LWI_TIMEOUT_INTERVAL(timeout,
2679 cfs_time_seconds(1),
2680 target_bulk_timeout,
2682 rc = l_wait_event(desc->bd_waitq,
2683 !ptlrpc_server_bulk_active(desc) ||
2685 exp->exp_abort_active_req,
2687 LASSERT(rc == 0 || rc == -ETIMEDOUT);
2688 /* Wait again if we changed deadline. */
2689 } while ((rc == -ETIMEDOUT) &&
2690 (req->rq_deadline > cfs_time_current_sec()));
2692 if (rc == -ETIMEDOUT) {
2693 DEBUG_REQ(D_ERROR, req,
2694 "timeout on bulk %s after %ld%+lds",
2696 req->rq_deadline - start,
2697 cfs_time_current_sec() -
2699 ptlrpc_abort_bulk(desc);
2700 } else if (exp->exp_failed) {
2701 DEBUG_REQ(D_ERROR, req, "Eviction on bulk %s",
2704 ptlrpc_abort_bulk(desc);
2705 } else if (exp->exp_abort_active_req) {
2706 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk %s",
2708 /* We don't reply anyway. */
2710 ptlrpc_abort_bulk(desc);
2711 } else if (desc->bd_failure ||
2712 desc->bd_nob_transferred != desc->bd_nob) {
2713 DEBUG_REQ(D_ERROR, req, "%s bulk %s %d(%d)",
2715 "network error on" : "truncated",
2717 desc->bd_nob_transferred,
2719 /* XXX Should this be a different errno? */
2721 } else if (desc->bd_type == BULK_GET_SINK) {
2722 rc = sptlrpc_svc_unwrap_bulk(req, desc);
2725 DEBUG_REQ(D_ERROR, req, "bulk %s failed: rc %d",
2726 bulk2type(desc), rc);
2731 EXPORT_SYMBOL(target_bulk_io);
2733 #endif /* HAVE_SERVER_SUPPORT */