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, 2014, 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
46 #include <linux/kthread.h>
47 #include <libcfs/libcfs.h>
49 #include <obd_class.h>
50 #include <lustre_dlm.h>
51 #include <lustre_net.h>
52 #include <lustre_sec.h>
53 #include "ldlm_internal.h"
55 /* @priority: If non-zero, move the selected connection to the list head.
56 * @create: If zero, only search in existing connections.
58 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
59 int priority, int create)
61 struct ptlrpc_connection *ptlrpc_conn;
62 struct obd_import_conn *imp_conn = NULL, *item;
66 if (!create && !priority) {
67 CDEBUG(D_HA, "Nothing to do\n");
71 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
73 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
78 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
80 GOTO(out_put, rc = -ENOMEM);
84 spin_lock(&imp->imp_lock);
85 list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
86 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
88 list_del(&item->oic_item);
89 list_add(&item->oic_item,
91 item->oic_last_attempt = 0;
93 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
94 imp, imp->imp_obd->obd_name, uuid->uuid,
95 (priority ? ", moved to head" : ""));
96 spin_unlock(&imp->imp_lock);
97 GOTO(out_free, rc = 0);
100 /* No existing import connection found for \a uuid. */
102 imp_conn->oic_conn = ptlrpc_conn;
103 imp_conn->oic_uuid = *uuid;
104 imp_conn->oic_last_attempt = 0;
106 list_add(&imp_conn->oic_item, &imp->imp_conn_list);
108 list_add_tail(&imp_conn->oic_item,
109 &imp->imp_conn_list);
110 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
111 imp, imp->imp_obd->obd_name, uuid->uuid,
112 (priority ? "head" : "tail"));
114 spin_unlock(&imp->imp_lock);
115 GOTO(out_free, rc = -ENOENT);
118 spin_unlock(&imp->imp_lock);
122 OBD_FREE(imp_conn, sizeof(*imp_conn));
124 ptlrpc_connection_put(ptlrpc_conn);
128 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
130 return import_set_conn(imp, uuid, 1, 0);
133 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
136 return import_set_conn(imp, uuid, priority, 1);
138 EXPORT_SYMBOL(client_import_add_conn);
140 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
142 struct obd_import_conn *imp_conn;
143 struct obd_export *dlmexp;
147 spin_lock(&imp->imp_lock);
148 if (list_empty(&imp->imp_conn_list)) {
149 LASSERT(!imp->imp_connection);
153 list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
154 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
156 LASSERT(imp_conn->oic_conn);
158 if (imp_conn == imp->imp_conn_current) {
159 LASSERT(imp_conn->oic_conn == imp->imp_connection);
161 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
162 imp->imp_state != LUSTRE_IMP_DISCON) {
163 CERROR("can't remove current connection\n");
164 GOTO(out, rc = -EBUSY);
167 ptlrpc_connection_put(imp->imp_connection);
168 imp->imp_connection = NULL;
170 dlmexp = class_conn2export(&imp->imp_dlm_handle);
171 if (dlmexp && dlmexp->exp_connection) {
172 LASSERT(dlmexp->exp_connection ==
174 ptlrpc_connection_put(dlmexp->exp_connection);
175 dlmexp->exp_connection = NULL;
179 list_del(&imp_conn->oic_item);
180 ptlrpc_connection_put(imp_conn->oic_conn);
181 OBD_FREE(imp_conn, sizeof(*imp_conn));
182 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
183 imp, imp->imp_obd->obd_name, uuid->uuid);
188 spin_unlock(&imp->imp_lock);
190 CERROR("connection %s not found\n", uuid->uuid);
193 EXPORT_SYMBOL(client_import_del_conn);
196 * Find conn UUID by peer NID. \a peer is a server NID. This function is used
197 * to find a conn uuid of \a imp which can reach \a peer.
199 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
200 struct obd_uuid *uuid)
202 struct obd_import_conn *conn;
206 spin_lock(&imp->imp_lock);
207 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
208 /* Check if conn UUID does have this peer NID. */
209 if (class_check_uuid(&conn->oic_uuid, peer)) {
210 *uuid = conn->oic_uuid;
215 spin_unlock(&imp->imp_lock);
218 EXPORT_SYMBOL(client_import_find_conn);
220 void client_destroy_import(struct obd_import *imp)
222 /* Drop security policy instance after all RPCs have finished/aborted
223 * to let all busy contexts be released. */
224 class_import_get(imp);
225 class_destroy_import(imp);
226 sptlrpc_import_sec_put(imp);
227 class_import_put(imp);
229 EXPORT_SYMBOL(client_destroy_import);
232 * Check whether or not the OSC is on MDT.
235 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
237 * setup 0:{fsname}-OSTxxxx-osc 1:lustre-OST0000_UUID 2:NID
240 static int osc_on_mdt(char *obdname)
244 ptr = strrchr(obdname, '-');
248 if (strncmp(ptr + 1, "MDT", 3) == 0)
254 /* Configure an RPC client OBD device.
259 * 3 - inactive-on-startup
261 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
263 struct client_obd *cli = &obddev->u.cli;
264 struct obd_import *imp;
265 struct obd_uuid server_uuid;
266 int rq_portal, rp_portal, connect_op;
267 char *name = obddev->obd_type->typ_name;
268 ldlm_ns_type_t ns_type = LDLM_NS_TYPE_UNKNOWN;
272 /* In a more perfect world, we would hang a ptlrpc_client off of
273 * obd_type and just use the values from there. */
274 if (!strcmp(name, LUSTRE_OSC_NAME)) {
275 rq_portal = OST_REQUEST_PORTAL;
276 rp_portal = OSC_REPLY_PORTAL;
277 connect_op = OST_CONNECT;
278 cli->cl_sp_me = LUSTRE_SP_CLI;
279 cli->cl_sp_to = LUSTRE_SP_OST;
280 ns_type = LDLM_NS_TYPE_OSC;
281 } else if (!strcmp(name, LUSTRE_MDC_NAME) ||
282 !strcmp(name, LUSTRE_LWP_NAME)) {
283 rq_portal = MDS_REQUEST_PORTAL;
284 rp_portal = MDC_REPLY_PORTAL;
285 connect_op = MDS_CONNECT;
286 cli->cl_sp_me = LUSTRE_SP_CLI;
287 cli->cl_sp_to = LUSTRE_SP_MDT;
288 ns_type = LDLM_NS_TYPE_MDC;
289 } else if (!strcmp(name, LUSTRE_OSP_NAME)) {
290 if (strstr(lustre_cfg_buf(lcfg, 1), "OST") == NULL) {
291 /* OSP_on_MDT for other MDTs */
292 connect_op = MDS_CONNECT;
293 cli->cl_sp_to = LUSTRE_SP_MDT;
294 ns_type = LDLM_NS_TYPE_MDC;
295 rq_portal = OUT_PORTAL;
297 /* OSP on MDT for OST */
298 connect_op = OST_CONNECT;
299 cli->cl_sp_to = LUSTRE_SP_OST;
300 ns_type = LDLM_NS_TYPE_OSC;
301 rq_portal = OST_REQUEST_PORTAL;
303 rp_portal = OSC_REPLY_PORTAL;
304 cli->cl_sp_me = LUSTRE_SP_CLI;
305 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
306 rq_portal = MGS_REQUEST_PORTAL;
307 rp_portal = MGC_REPLY_PORTAL;
308 connect_op = MGS_CONNECT;
309 cli->cl_sp_me = LUSTRE_SP_MGC;
310 cli->cl_sp_to = LUSTRE_SP_MGS;
311 cli->cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_INVALID;
312 ns_type = LDLM_NS_TYPE_MGC;
314 CERROR("unknown client OBD type \"%s\", can't setup\n",
319 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
320 CERROR("requires a TARGET UUID\n");
324 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
325 CERROR("client UUID must be less than 38 characters\n");
329 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
330 CERROR("setup requires a SERVER UUID\n");
334 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
335 CERROR("target UUID must be less than 38 characters\n");
339 init_rwsem(&cli->cl_sem);
340 mutex_init(&cli->cl_mgc_mutex);
341 cli->cl_conn_count = 0;
342 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
343 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
344 sizeof(server_uuid)));
346 cli->cl_dirty_pages = 0;
347 cli->cl_avail_grant = 0;
348 /* FIXME: Should limit this for the sum of all cl_dirty_max_pages. */
349 /* cl_dirty_max_pages may be changed at connect time in
350 * ptlrpc_connect_interpret(). */
351 client_adjust_max_dirty(cli);
352 INIT_LIST_HEAD(&cli->cl_cache_waiters);
353 INIT_LIST_HEAD(&cli->cl_loi_ready_list);
354 INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
355 INIT_LIST_HEAD(&cli->cl_loi_write_list);
356 INIT_LIST_HEAD(&cli->cl_loi_read_list);
357 spin_lock_init(&cli->cl_loi_list_lock);
358 atomic_set(&cli->cl_pending_w_pages, 0);
359 atomic_set(&cli->cl_pending_r_pages, 0);
360 cli->cl_r_in_flight = 0;
361 cli->cl_w_in_flight = 0;
363 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
364 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
365 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
366 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
367 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
368 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
371 INIT_LIST_HEAD(&cli->cl_lru_osc);
372 atomic_set(&cli->cl_lru_shrinkers, 0);
373 atomic_long_set(&cli->cl_lru_busy, 0);
374 atomic_long_set(&cli->cl_lru_in_list, 0);
375 INIT_LIST_HEAD(&cli->cl_lru_list);
376 spin_lock_init(&cli->cl_lru_list_lock);
377 atomic_long_set(&cli->cl_unstable_count, 0);
379 init_waitqueue_head(&cli->cl_destroy_waitq);
380 atomic_set(&cli->cl_destroy_in_flight, 0);
381 #ifdef ENABLE_CHECKSUM
382 /* Turn on checksumming by default. */
383 cli->cl_checksum = 1;
385 * The supported checksum types will be worked out at connect time
386 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
389 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
391 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
393 /* This value may be reduced at connect time in
394 * ptlrpc_connect_interpret() . We initialize it to only
395 * 1MB until we know what the performance looks like.
396 * In the future this should likely be increased. LU-1431 */
397 cli->cl_max_pages_per_rpc = min_t(int, PTLRPC_MAX_BRW_PAGES,
398 LNET_MTU >> PAGE_CACHE_SHIFT);
400 /* set cl_chunkbits default value to PAGE_CACHE_SHIFT,
401 * it will be updated at OSC connection time. */
402 cli->cl_chunkbits = PAGE_CACHE_SHIFT;
404 if (!strcmp(name, LUSTRE_MDC_NAME)) {
405 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT;
406 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 128 /* MB */) {
407 cli->cl_max_rpcs_in_flight = 2;
408 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 256 /* MB */) {
409 cli->cl_max_rpcs_in_flight = 3;
410 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 512 /* MB */) {
411 cli->cl_max_rpcs_in_flight = 4;
413 if (osc_on_mdt(obddev->obd_name))
414 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_MAX;
416 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT;
420 CERROR("ldlm_get_ref failed: %d\n", rc);
424 ptlrpc_init_client(rq_portal, rp_portal, name,
425 &obddev->obd_ldlm_client);
427 imp = class_new_import(obddev);
429 GOTO(err_ldlm, rc = -ENOENT);
430 imp->imp_client = &obddev->obd_ldlm_client;
431 imp->imp_connect_op = connect_op;
432 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
433 LUSTRE_CFG_BUFLEN(lcfg, 1));
434 class_import_put(imp);
436 rc = client_import_add_conn(imp, &server_uuid, 1);
438 CERROR("can't add initial connection\n");
439 GOTO(err_import, rc);
442 cli->cl_import = imp;
443 /* cli->cl_max_mds_easize updated by mdc_init_ea_size() */
444 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
446 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
447 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
448 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
449 name, obddev->obd_name,
450 cli->cl_target_uuid.uuid);
451 spin_lock(&imp->imp_lock);
452 imp->imp_deactive = 1;
453 spin_unlock(&imp->imp_lock);
457 obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
458 LDLM_NAMESPACE_CLIENT,
459 LDLM_NAMESPACE_GREEDY,
461 if (obddev->obd_namespace == NULL) {
462 CERROR("Unable to create client namespace - %s\n",
464 GOTO(err_import, rc = -ENOMEM);
470 class_destroy_import(imp);
477 EXPORT_SYMBOL(client_obd_setup);
479 int client_obd_cleanup(struct obd_device *obddev)
483 ldlm_namespace_free_post(obddev->obd_namespace);
484 obddev->obd_namespace = NULL;
486 obd_cleanup_client_import(obddev);
487 LASSERT(obddev->u.cli.cl_import == NULL);
492 EXPORT_SYMBOL(client_obd_cleanup);
494 /* ->o_connect() method for client side (OSC and MDC and MGC) */
495 int client_connect_import(const struct lu_env *env,
496 struct obd_export **exp,
497 struct obd_device *obd, struct obd_uuid *cluuid,
498 struct obd_connect_data *data, void *localdata)
500 struct client_obd *cli = &obd->u.cli;
501 struct obd_import *imp = cli->cl_import;
502 struct obd_connect_data *ocd;
503 struct lustre_handle conn = { 0 };
508 down_write(&cli->cl_sem);
509 if (cli->cl_conn_count > 0)
510 GOTO(out_sem, rc = -EALREADY);
512 rc = class_connect(&conn, obd, cluuid);
516 cli->cl_conn_count++;
517 *exp = class_conn2export(&conn);
519 LASSERT(obd->obd_namespace);
521 imp->imp_dlm_handle = conn;
522 rc = ptlrpc_init_import(imp);
526 ocd = &imp->imp_connect_data;
529 imp->imp_connect_flags_orig = data->ocd_connect_flags;
532 rc = ptlrpc_connect_import(imp);
534 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
537 LASSERT(*exp != NULL && (*exp)->exp_connection);
540 LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
541 ocd->ocd_connect_flags, "old "LPX64", new "LPX64"\n",
542 data->ocd_connect_flags, ocd->ocd_connect_flags);
543 data->ocd_connect_flags = ocd->ocd_connect_flags;
546 ptlrpc_pinger_add_import(imp);
552 cli->cl_conn_count--;
553 class_disconnect(*exp);
557 up_write(&cli->cl_sem);
561 EXPORT_SYMBOL(client_connect_import);
563 int client_disconnect_export(struct obd_export *exp)
565 struct obd_device *obd = class_exp2obd(exp);
566 struct client_obd *cli;
567 struct obd_import *imp;
572 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
573 exp, exp ? exp->exp_handle.h_cookie : -1);
578 imp = cli->cl_import;
580 down_write(&cli->cl_sem);
581 CDEBUG(D_INFO, "disconnect %s - %zu\n", obd->obd_name,
584 if (cli->cl_conn_count == 0) {
585 CERROR("disconnecting disconnected device (%s)\n",
587 GOTO(out_disconnect, rc = -EINVAL);
590 cli->cl_conn_count--;
591 if (cli->cl_conn_count != 0)
592 GOTO(out_disconnect, rc = 0);
594 /* Mark import deactivated now, so we don't try to reconnect if any
595 * of the cleanup RPCs fails (e.g. LDLM cancel, etc). We don't
596 * fully deactivate the import, or that would drop all requests. */
597 spin_lock(&imp->imp_lock);
598 imp->imp_deactive = 1;
599 spin_unlock(&imp->imp_lock);
601 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
602 * delete it regardless. (It's safe to delete an import that was
604 (void)ptlrpc_pinger_del_import(imp);
606 if (obd->obd_namespace != NULL) {
607 /* obd_force == local only */
608 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
609 obd->obd_force ? LCF_LOCAL : 0, NULL);
610 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force);
613 /* There's no need to hold sem while disconnecting an import,
614 * and it may actually cause deadlock in GSS. */
615 up_write(&cli->cl_sem);
616 rc = ptlrpc_disconnect_import(imp, 0);
617 down_write(&cli->cl_sem);
619 ptlrpc_invalidate_import(imp);
624 /* Use server style - class_disconnect should be always called for
626 err = class_disconnect(exp);
630 up_write(&cli->cl_sem);
634 EXPORT_SYMBOL(client_disconnect_export);
636 #ifdef HAVE_SERVER_SUPPORT
637 int server_disconnect_export(struct obd_export *exp)
642 /* Disconnect early so that clients can't keep using export. */
643 rc = class_disconnect(exp);
644 /* Close import to avoid sending any requests. */
645 if (exp->exp_imp_reverse)
646 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
648 if (exp->exp_obd->obd_namespace != NULL)
649 ldlm_cancel_locks_for_export(exp);
651 /* complete all outstanding replies */
652 spin_lock(&exp->exp_lock);
653 while (!list_empty(&exp->exp_outstanding_replies)) {
654 struct ptlrpc_reply_state *rs =
655 list_entry(exp->exp_outstanding_replies.next,
656 struct ptlrpc_reply_state, rs_exp_list);
657 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
659 spin_lock(&svcpt->scp_rep_lock);
661 list_del_init(&rs->rs_exp_list);
662 spin_lock(&rs->rs_lock);
663 ptlrpc_schedule_difficult_reply(rs);
664 spin_unlock(&rs->rs_lock);
666 spin_unlock(&svcpt->scp_rep_lock);
668 spin_unlock(&exp->exp_lock);
672 EXPORT_SYMBOL(server_disconnect_export);
674 /* --------------------------------------------------------------------------
675 * from old lib/target.c
676 * -------------------------------------------------------------------------- */
678 static int target_handle_reconnect(struct lustre_handle *conn,
679 struct obd_export *exp,
680 struct obd_uuid *cluuid)
684 if (exp->exp_connection && exp->exp_imp_reverse) {
685 struct lustre_handle *hdl;
686 struct obd_device *target;
688 hdl = &exp->exp_imp_reverse->imp_remote_handle;
689 target = exp->exp_obd;
691 /* Might be a re-connect after a partition. */
692 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
693 if (target->obd_recovering) {
694 int timeout = cfs_duration_sec(cfs_time_sub(
696 &target->obd_recovery_timer),
697 cfs_time_current()));
699 LCONSOLE_WARN("%s: Client %s (at %s) reconnect"
700 "ing, waiting for %d clients in recov"
701 "ery for %d:%.02d\n", target->obd_name,
702 obd_uuid2str(&exp->exp_client_uuid),
703 obd_export_nid2str(exp),
704 target->obd_max_recoverable_clients,
705 timeout / 60, timeout % 60);
707 LCONSOLE_WARN("%s: Client %s (at %s) "
708 "reconnecting\n", target->obd_name,
709 obd_uuid2str(&exp->exp_client_uuid),
710 obd_export_nid2str(exp));
713 conn->cookie = exp->exp_handle.h_cookie;
714 /* target_handle_connect() treats EALREADY and
715 * -EALREADY differently. EALREADY means we are
716 * doing a valid reconnect from the same client. */
719 LCONSOLE_WARN("%s: already connected client %s (at %s) "
720 "with handle "LPX64". Rejecting client "
721 "with the same UUID trying to reconnect "
722 "with handle "LPX64"\n", target->obd_name,
723 obd_uuid2str(&exp->exp_client_uuid),
724 obd_export_nid2str(exp),
725 hdl->cookie, conn->cookie);
726 memset(conn, 0, sizeof *conn);
727 /* target_handle_connect() treats EALREADY and
728 * -EALREADY differently. -EALREADY is an error
729 * (same UUID, different handle). */
734 conn->cookie = exp->exp_handle.h_cookie;
735 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
736 cluuid->uuid, exp, conn->cookie);
740 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
743 struct obd_export *exp = cb_data;
745 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
746 obd->obd_name, exp->exp_client_uuid.uuid);
748 spin_lock(&exp->exp_lock);
749 exp->exp_need_sync = 0;
750 spin_unlock(&exp->exp_lock);
751 class_export_cb_put(exp);
755 check_and_start_recovery_timer(struct obd_device *obd,
756 struct ptlrpc_request *req, int new_client);
758 int target_handle_connect(struct ptlrpc_request *req)
760 struct obd_device *target = NULL, *targref = NULL;
761 struct obd_export *export = NULL;
762 struct obd_import *revimp;
763 struct obd_import *tmp_imp = NULL;
764 struct lustre_handle conn;
765 struct lustre_handle *tmp;
766 struct obd_uuid tgtuuid;
767 struct obd_uuid cluuid;
768 struct obd_uuid remote_uuid;
773 bool mds_conn = false, lw_client = false;
774 struct obd_connect_data *data, *tmpdata;
776 lnet_nid_t *client_nid = NULL;
779 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
781 str = req_capsule_client_get(&req->rq_pill, &RMF_TGTUUID);
783 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
784 GOTO(out, rc = -EINVAL);
787 obd_str2uuid(&tgtuuid, str);
788 target = class_uuid2obd(&tgtuuid);
790 target = class_name2obd(str);
793 deuuidify(str, NULL, &target_start, &target_len);
794 LCONSOLE_ERROR_MSG(0x137, "%s: not available for connect "
795 "from %s (no target). If you are running "
796 "an HA pair check that the target is "
797 "mounted on the other server.\n", str,
798 libcfs_nid2str(req->rq_peer.nid));
799 GOTO(out, rc = -ENODEV);
802 spin_lock(&target->obd_dev_lock);
803 if (target->obd_stopping || !target->obd_set_up) {
804 spin_unlock(&target->obd_dev_lock);
806 deuuidify(str, NULL, &target_start, &target_len);
807 LCONSOLE_INFO("%.*s: Not available for connect from %s (%s)\n",
808 target_len, target_start,
809 libcfs_nid2str(req->rq_peer.nid),
810 (target->obd_stopping ?
811 "stopping" : "not set up"));
812 GOTO(out, rc = -ENODEV);
815 if (target->obd_no_conn) {
816 spin_unlock(&target->obd_dev_lock);
818 CDEBUG(D_INFO, "%s: Temporarily refusing client connection "
819 "from %s\n", target->obd_name,
820 libcfs_nid2str(req->rq_peer.nid));
821 GOTO(out, rc = -EAGAIN);
824 /* Make sure the target isn't cleaned up while we're here. Yes,
825 * there's still a race between the above check and our incref here.
826 * Really, class_uuid2obd should take the ref. */
827 targref = class_incref(target, __FUNCTION__, current);
829 target->obd_conn_inprogress++;
830 spin_unlock(&target->obd_dev_lock);
832 str = req_capsule_client_get(&req->rq_pill, &RMF_CLUUID);
834 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
835 GOTO(out, rc = -EINVAL);
838 obd_str2uuid(&cluuid, str);
840 /* XXX Extract a nettype and format accordingly. */
841 switch (sizeof(lnet_nid_t)) {
842 /* NB the casts only avoid compiler warnings. */
844 snprintf(remote_uuid.uuid, sizeof remote_uuid,
845 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
848 snprintf(remote_uuid.uuid, sizeof remote_uuid,
849 "NET_%x_UUID", (__u32)req->rq_peer.nid);
855 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
857 GOTO(out, rc = -EPROTO);
861 size = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
863 data = req_capsule_client_get(&req->rq_pill, &RMF_CONNECT_DATA);
865 GOTO(out, rc = -EPROTO);
867 rc = req_capsule_server_pack(&req->rq_pill);
871 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
872 /* Don't allow clients to connect that are using old 1.8 format
873 * protocol conventions (LUSTRE_MSG_MAGIC_v1, !MSGHDR_CKSUM_INCOMPAT18,
874 * ldlm_flock_policy_wire format, MDT_ATTR_xTIME_SET, etc). The
875 * FULL20 flag should be set on all connections since 2.0, but no
876 * longer affects behaviour.
878 * Later this check will be disabled and the flag can be retired
879 * completely once interop with 3.0 is no longer needed.
881 if (!(data->ocd_connect_flags & OBD_CONNECT_FULL20))
882 GOTO(out, rc = -EPROTO);
885 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
886 if (data->ocd_version < LUSTRE_VERSION_CODE -
887 LUSTRE_VERSION_ALLOWED_OFFSET ||
888 data->ocd_version > LUSTRE_VERSION_CODE +
889 LUSTRE_VERSION_ALLOWED_OFFSET) {
890 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
891 "libclient connection attempt",
892 data->ocd_version < LUSTRE_VERSION_CODE ?
894 OBD_OCD_VERSION_MAJOR(data->ocd_version),
895 OBD_OCD_VERSION_MINOR(data->ocd_version),
896 OBD_OCD_VERSION_PATCH(data->ocd_version),
897 OBD_OCD_VERSION_FIX(data->ocd_version));
898 data = req_capsule_server_sized_get(&req->rq_pill,
900 offsetof(typeof(*data), ocd_version) +
901 sizeof(data->ocd_version));
903 data->ocd_connect_flags = OBD_CONNECT_VERSION;
904 data->ocd_version = LUSTRE_VERSION_CODE;
906 GOTO(out, rc = -EPROTO);
910 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) {
911 mds_conn = (data->ocd_connect_flags & OBD_CONNECT_MDS) != 0;
912 lw_client = (data->ocd_connect_flags &
913 OBD_CONNECT_LIGHTWEIGHT) != 0;
915 /* OBD_CONNECT_MNE_SWAB is defined as OBD_CONNECT_MDS_MDS
916 * for Imperative Recovery connection from MGC to MGS.
918 * Via check OBD_CONNECT_FID, we can distinguish whether
919 * the OBD_CONNECT_MDS_MDS/OBD_CONNECT_MNE_SWAB is from
922 (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
923 (data->ocd_connect_flags & OBD_CONNECT_FID) &&
924 (data->ocd_connect_flags & OBD_CONNECT_VERSION)) {
925 __u32 major = OBD_OCD_VERSION_MAJOR(data->ocd_version);
926 __u32 minor = OBD_OCD_VERSION_MINOR(data->ocd_version);
927 __u32 patch = OBD_OCD_VERSION_PATCH(data->ocd_version);
929 /* We do not support the MDT-MDT interoperations with
930 * different version MDT because of protocol changes. */
931 if (unlikely(major != LUSTRE_MAJOR ||
932 minor != LUSTRE_MINOR ||
933 abs(patch - LUSTRE_PATCH) > 3)) {
934 LCONSOLE_WARN("%s (%u.%u.%u.%u) refused the "
935 "connection from different version MDT "
936 "(%d.%d.%d.%d) %s %s\n",
937 target->obd_name, LUSTRE_MAJOR,
938 LUSTRE_MINOR, LUSTRE_PATCH, LUSTRE_FIX,
940 OBD_OCD_VERSION_FIX(data->ocd_version),
941 libcfs_nid2str(req->rq_peer.nid), str);
943 GOTO(out, rc = -EPROTO);
948 /* lctl gets a backstage, all-access pass. */
949 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
950 goto dont_check_exports;
952 export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
956 /* We've found an export in the hash. */
958 spin_lock(&export->exp_lock);
960 if (export->exp_connecting) { /* bug 9635, et. al. */
961 spin_unlock(&export->exp_lock);
962 LCONSOLE_WARN("%s: Export %p already connecting from %s\n",
963 export->exp_obd->obd_name, export,
964 libcfs_nid2str(req->rq_peer.nid));
965 class_export_put(export);
968 } else if ((mds_conn || lw_client) && export->exp_connection != NULL) {
969 spin_unlock(&export->exp_lock);
970 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
971 /* MDS or LWP reconnected after failover. */
972 LCONSOLE_WARN("%s: Received %s connection from "
973 "%s, removing former export from %s\n",
974 target->obd_name, mds_conn ? "MDS" : "LWP",
975 libcfs_nid2str(req->rq_peer.nid),
976 libcfs_nid2str(export->exp_connection->c_peer.nid));
978 /* New MDS connection from the same NID. */
979 LCONSOLE_WARN("%s: Received new %s connection from "
980 "%s, removing former export from same NID\n",
981 target->obd_name, mds_conn ? "MDS" : "LWP",
982 libcfs_nid2str(req->rq_peer.nid));
983 class_fail_export(export);
984 class_export_put(export);
987 } else if (export->exp_connection != NULL &&
988 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
989 (lustre_msg_get_op_flags(req->rq_reqmsg) &
990 MSG_CONNECT_INITIAL)) {
991 spin_unlock(&export->exp_lock);
992 /* In MDS failover we have static UUID but NID can change. */
993 LCONSOLE_WARN("%s: Client %s seen on new nid %s when "
994 "existing nid %s is already connected\n",
995 target->obd_name, cluuid.uuid,
996 libcfs_nid2str(req->rq_peer.nid),
998 export->exp_connection->c_peer.nid));
1000 class_export_put(export);
1003 export->exp_connecting = 1;
1004 spin_unlock(&export->exp_lock);
1005 LASSERT(export->exp_obd == target);
1007 rc = target_handle_reconnect(&conn, export, &cluuid);
1010 /* If we found an export, we already unlocked. */
1013 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
1014 } else if (req->rq_export == NULL &&
1015 atomic_read(&export->exp_rpc_count) > 0) {
1016 LCONSOLE_WARN("%s: Client %s (at %s) refused connection, "
1017 "still busy with %d references\n",
1018 target->obd_name, cluuid.uuid,
1019 libcfs_nid2str(req->rq_peer.nid),
1020 atomic_read(&export->exp_refcount));
1021 GOTO(out, rc = -EBUSY);
1022 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
1023 if (!strstr(cluuid.uuid, "mdt"))
1024 LCONSOLE_WARN("%s: Rejecting reconnect from the "
1025 "known client %s (at %s) because it "
1026 "is indicating it is a new client",
1027 target->obd_name, cluuid.uuid,
1028 libcfs_nid2str(req->rq_peer.nid));
1029 GOTO(out, rc = -EALREADY);
1031 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
1038 CDEBUG(D_HA, "%s: connection from %s@%s %st"LPU64" exp %p cur %ld last %ld\n",
1039 target->obd_name, cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1040 target->obd_recovering ? "recovering/" : "", data->ocd_transno,
1041 export, (long)cfs_time_current_sec(),
1042 export ? (long)export->exp_last_request_time : 0);
1044 /* If this is the first time a client connects, reset the recovery
1045 * timer. Discard lightweight connections which might be local. */
1046 if (!lw_client && rc == 0 && target->obd_recovering)
1047 check_and_start_recovery_timer(target, req, export == NULL);
1049 /* We want to handle EALREADY but *not* -EALREADY from
1050 * target_handle_reconnect(), return reconnection state in a flag. */
1051 if (rc == EALREADY) {
1052 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
1058 /* Tell the client if we support replayable requests. */
1059 if (target->obd_replayable)
1060 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
1061 client_nid = &req->rq_peer.nid;
1063 if (export == NULL) {
1064 /* allow lightweight connections during recovery */
1065 if (target->obd_recovering && !lw_client) {
1067 int c; /* connected */
1068 int i; /* in progress */
1070 int s; /* stale/evicted */
1072 c = atomic_read(&target->obd_connected_clients);
1073 i = atomic_read(&target->obd_lock_replay_clients);
1074 k = target->obd_max_recoverable_clients;
1075 s = target->obd_stale_clients;
1076 t = cfs_timer_deadline(&target->obd_recovery_timer);
1077 t = cfs_time_sub(t, cfs_time_current());
1078 t = cfs_duration_sec(t);
1079 LCONSOLE_WARN("%s: Denying connection for new client %s"
1080 "(at %s), waiting for %d known clients "
1081 "(%d recovered, %d in progress, and %d "
1082 "evicted) to recover in %d:%.02d\n",
1083 target->obd_name, cluuid.uuid,
1084 libcfs_nid2str(req->rq_peer.nid), k,
1085 c - i, i, s, (int)t / 60,
1090 rc = obd_connect(req->rq_svc_thread->t_env,
1091 &export, target, &cluuid, data,
1093 if (mds_conn && OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
1094 lustre_msg_add_op_flags(req->rq_repmsg,
1095 MSG_CONNECT_RECOVERING);
1097 conn.cookie = export->exp_handle.h_cookie;
1100 rc = obd_reconnect(req->rq_svc_thread->t_env,
1101 export, target, &cluuid, data, client_nid);
1106 LASSERT(target->u.obt.obt_magic == OBT_MAGIC);
1107 data->ocd_instance = target->u.obt.obt_instance;
1109 /* Return only the parts of obd_connect_data that we understand, so the
1110 * client knows that we don't understand the rest. */
1112 tmpsize = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
1114 tmpdata = req_capsule_server_get(&req->rq_pill,
1116 /* Don't use struct assignment here, because the client reply
1117 * buffer may be smaller/larger than the local struct
1118 * obd_connect_data. */
1119 memcpy(tmpdata, data, min(tmpsize, size));
1122 /* If all else goes well, this is our RPC return code. */
1125 lustre_msg_set_handle(req->rq_repmsg, &conn);
1127 /* If the client and the server are the same node, we will already
1128 * have an export that really points to the client's DLM export,
1129 * because we have a shared handles table.
1131 * XXX this will go away when shaver stops sending the "connect" handle
1132 * in the real "remote handle" field of the request --phik 24 Apr 2003
1134 ptlrpc_request_change_export(req, export);
1136 spin_lock(&export->exp_lock);
1137 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
1138 spin_unlock(&export->exp_lock);
1139 CDEBUG(D_RPCTRACE, "%s: %s already connected at greater "
1140 "or equal conn_cnt: %d >= %d\n",
1141 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1142 export->exp_conn_cnt,
1143 lustre_msg_get_conn_cnt(req->rq_reqmsg));
1145 GOTO(out, rc = -EALREADY);
1147 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1148 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1150 /* Don't evict liblustre clients for not pinging. */
1151 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1152 export->exp_libclient = 1;
1153 spin_unlock(&export->exp_lock);
1155 spin_lock(&target->obd_dev_lock);
1156 list_del_init(&export->exp_obd_chain_timed);
1157 spin_unlock(&target->obd_dev_lock);
1159 spin_unlock(&export->exp_lock);
1162 if (export->exp_connection != NULL) {
1163 /* Check to see if connection came from another NID. */
1164 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1165 !hlist_unhashed(&export->exp_nid_hash))
1166 cfs_hash_del(export->exp_obd->obd_nid_hash,
1167 &export->exp_connection->c_peer.nid,
1168 &export->exp_nid_hash);
1170 ptlrpc_connection_put(export->exp_connection);
1173 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1176 if (hlist_unhashed(&export->exp_nid_hash)) {
1177 cfs_hash_add(export->exp_obd->obd_nid_hash,
1178 &export->exp_connection->c_peer.nid,
1179 &export->exp_nid_hash);
1182 if (target->obd_recovering && !export->exp_in_recovery && !lw_client) {
1184 __u64 transno = data->ocd_transno;
1186 spin_lock(&export->exp_lock);
1187 /* possible race with class_disconnect_stale_exports,
1188 * export may be already in the eviction process */
1189 if (export->exp_failed) {
1190 spin_unlock(&export->exp_lock);
1191 GOTO(out, rc = -ENODEV);
1193 export->exp_in_recovery = 1;
1194 export->exp_req_replay_needed = 1;
1195 export->exp_lock_replay_needed = 1;
1196 spin_unlock(&export->exp_lock);
1198 has_transno = !!(lustre_msg_get_op_flags(req->rq_reqmsg) &
1199 MSG_CONNECT_TRANSNO);
1200 if (has_transno && transno == 0)
1201 CWARN("Connect with zero transno!\n");
1203 if (has_transno && transno > 0 &&
1204 transno < target->obd_next_recovery_transno &&
1205 transno > target->obd_last_committed) {
1206 /* Another way is to use cmpxchg() to be lock-free. */
1207 spin_lock(&target->obd_recovery_task_lock);
1208 if (transno < target->obd_next_recovery_transno)
1209 target->obd_next_recovery_transno = transno;
1210 spin_unlock(&target->obd_recovery_task_lock);
1213 atomic_inc(&target->obd_req_replay_clients);
1214 atomic_inc(&target->obd_lock_replay_clients);
1215 if (atomic_inc_return(&target->obd_connected_clients) ==
1216 target->obd_max_recoverable_clients)
1217 wake_up(&target->obd_next_transno_waitq);
1220 /* Tell the client we're in recovery, when client is involved in it. */
1221 if (target->obd_recovering && !lw_client)
1222 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
1224 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
1227 /* Return -ENOTCONN in case of errors to let client reconnect. */
1228 revimp = class_new_import(target);
1229 if (revimp == NULL) {
1230 CERROR("fail to alloc new reverse import.\n");
1231 GOTO(out, rc = -ENOTCONN);
1234 spin_lock(&export->exp_lock);
1235 if (export->exp_imp_reverse != NULL)
1236 /* destroyed import can be still referenced in ctxt */
1237 tmp_imp = export->exp_imp_reverse;
1238 export->exp_imp_reverse = revimp;
1239 spin_unlock(&export->exp_lock);
1241 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1242 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1243 revimp->imp_remote_handle = conn;
1244 revimp->imp_dlm_fake = 1;
1245 revimp->imp_state = LUSTRE_IMP_FULL;
1247 /* Unknown versions will be caught in
1248 * ptlrpc_handle_server_req_in->lustre_unpack_msg(). */
1249 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1251 if (data->ocd_connect_flags & OBD_CONNECT_AT)
1252 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1254 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1256 revimp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
1258 rc = sptlrpc_import_sec_adapt(revimp, req->rq_svc_ctx, &req->rq_flvr);
1260 CERROR("Failed to get sec for reverse import: %d\n", rc);
1261 spin_lock(&export->exp_lock);
1262 export->exp_imp_reverse = NULL;
1263 spin_unlock(&export->exp_lock);
1264 class_destroy_import(revimp);
1267 class_import_put(revimp);
1270 if (tmp_imp != NULL)
1271 client_destroy_import(tmp_imp);
1273 spin_lock(&export->exp_lock);
1274 export->exp_connecting = 0;
1275 spin_unlock(&export->exp_lock);
1277 class_export_put(export);
1280 spin_lock(&target->obd_dev_lock);
1281 target->obd_conn_inprogress--;
1282 spin_unlock(&target->obd_dev_lock);
1284 class_decref(targref, __func__, current);
1287 req->rq_status = rc;
1291 int target_handle_disconnect(struct ptlrpc_request *req)
1296 rc = req_capsule_server_pack(&req->rq_pill);
1300 /* Keep the rq_export around so we can send the reply. */
1301 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1306 void target_destroy_export(struct obd_export *exp)
1308 struct obd_import *imp = NULL;
1309 /* exports created from last_rcvd data, and "fake"
1310 exports created by lctl don't have an import */
1311 spin_lock(&exp->exp_lock);
1312 if (exp->exp_imp_reverse != NULL) {
1313 imp = exp->exp_imp_reverse;
1314 exp->exp_imp_reverse = NULL;
1316 spin_unlock(&exp->exp_lock);
1318 client_destroy_import(imp);
1320 LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
1321 LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
1322 LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
1323 LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
1325 EXPORT_SYMBOL(target_destroy_export);
1328 * Recovery functions
1330 static void target_request_copy_get(struct ptlrpc_request *req)
1332 class_export_rpc_inc(req->rq_export);
1333 LASSERT(list_empty(&req->rq_list));
1334 INIT_LIST_HEAD(&req->rq_replay_list);
1336 /* Increase refcount to keep request in queue. */
1337 atomic_inc(&req->rq_refcount);
1338 /* Let export know it has replays to be handled. */
1339 atomic_inc(&req->rq_export->exp_replay_count);
1342 static void target_request_copy_put(struct ptlrpc_request *req)
1344 LASSERT(list_empty(&req->rq_replay_list));
1345 LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
1347 atomic_dec(&req->rq_export->exp_replay_count);
1348 class_export_rpc_dec(req->rq_export);
1349 ptlrpc_server_drop_request(req);
1352 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1354 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1355 struct obd_export *exp = req->rq_export;
1356 struct ptlrpc_request *reqiter;
1361 spin_lock(&exp->exp_lock);
1362 list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1364 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1371 /* We expect it with RESENT and REPLAY flags. */
1372 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1373 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1374 CERROR("invalid flags %x of resent replay\n",
1375 lustre_msg_get_flags(req->rq_reqmsg));
1377 list_add_tail(&req->rq_replay_list,
1378 &exp->exp_req_replay_queue);
1381 spin_unlock(&exp->exp_lock);
1385 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1387 LASSERT(!list_empty(&req->rq_replay_list));
1388 LASSERT(req->rq_export);
1390 spin_lock(&req->rq_export->exp_lock);
1391 list_del_init(&req->rq_replay_list);
1392 spin_unlock(&req->rq_export->exp_lock);
1395 static void target_finish_recovery(struct obd_device *obd)
1399 /* Only log a recovery message when recovery has occurred. */
1400 if (obd->obd_recovery_start) {
1401 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1402 obd->obd_recovery_start);
1403 LCONSOLE_INFO("%s: Recovery over after %d:%.02d, of %d clients "
1404 "%d recovered and %d %s evicted.\n", obd->obd_name,
1405 (int)elapsed_time / 60, (int)elapsed_time % 60,
1406 obd->obd_max_recoverable_clients,
1407 atomic_read(&obd->obd_connected_clients),
1408 obd->obd_stale_clients,
1409 obd->obd_stale_clients == 1 ? "was" : "were");
1412 ldlm_reprocess_all_ns(obd->obd_namespace);
1413 spin_lock(&obd->obd_recovery_task_lock);
1414 if (!list_empty(&obd->obd_req_replay_queue) ||
1415 !list_empty(&obd->obd_lock_replay_queue) ||
1416 !list_empty(&obd->obd_final_req_queue)) {
1417 CERROR("%s: Recovery queues ( %s%s%s) are not empty\n",
1419 list_empty(&obd->obd_req_replay_queue) ? "" : "req ",
1420 list_empty(&obd->obd_lock_replay_queue) ? \
1422 list_empty(&obd->obd_final_req_queue) ? \
1424 spin_unlock(&obd->obd_recovery_task_lock);
1427 spin_unlock(&obd->obd_recovery_task_lock);
1429 obd->obd_recovery_end = cfs_time_current_sec();
1431 /* When recovery finished, cleanup orphans on MDS and OST. */
1432 if (OBT(obd) && OBP(obd, postrecov)) {
1433 int rc = OBP(obd, postrecov)(obd);
1435 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1441 static void abort_req_replay_queue(struct obd_device *obd)
1443 struct ptlrpc_request *req, *n;
1444 struct list_head abort_list;
1446 INIT_LIST_HEAD(&abort_list);
1447 spin_lock(&obd->obd_recovery_task_lock);
1448 list_splice_init(&obd->obd_req_replay_queue, &abort_list);
1449 spin_unlock(&obd->obd_recovery_task_lock);
1450 list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1451 DEBUG_REQ(D_WARNING, req, "aborted:");
1452 req->rq_status = -ENOTCONN;
1453 if (ptlrpc_error(req)) {
1454 DEBUG_REQ(D_ERROR, req,
1455 "failed abort_req_reply; skipping");
1457 target_exp_dequeue_req_replay(req);
1458 target_request_copy_put(req);
1462 static void abort_lock_replay_queue(struct obd_device *obd)
1464 struct ptlrpc_request *req, *n;
1465 struct list_head abort_list;
1467 INIT_LIST_HEAD(&abort_list);
1468 spin_lock(&obd->obd_recovery_task_lock);
1469 list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
1470 spin_unlock(&obd->obd_recovery_task_lock);
1471 list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1472 DEBUG_REQ(D_ERROR, req, "aborted:");
1473 req->rq_status = -ENOTCONN;
1474 if (ptlrpc_error(req)) {
1475 DEBUG_REQ(D_ERROR, req,
1476 "failed abort_lock_reply; skipping");
1478 target_request_copy_put(req);
1482 /* Called from a cleanup function if the device is being cleaned up
1483 forcefully. The exports should all have been disconnected already,
1484 the only thing left to do is
1485 - clear the recovery flags
1487 - free queued requests and replies, but don't send replies
1488 Because the obd_stopping flag is set, no new requests should be received.
1491 void target_cleanup_recovery(struct obd_device *obd)
1493 struct ptlrpc_request *req, *n;
1494 struct list_head clean_list;
1497 INIT_LIST_HEAD(&clean_list);
1498 spin_lock(&obd->obd_dev_lock);
1499 if (!obd->obd_recovering) {
1500 spin_unlock(&obd->obd_dev_lock);
1504 obd->obd_recovering = obd->obd_abort_recovery = 0;
1505 spin_unlock(&obd->obd_dev_lock);
1507 spin_lock(&obd->obd_recovery_task_lock);
1508 target_cancel_recovery_timer(obd);
1509 list_splice_init(&obd->obd_req_replay_queue, &clean_list);
1510 spin_unlock(&obd->obd_recovery_task_lock);
1512 list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1513 LASSERT(req->rq_reply_state == NULL);
1514 target_exp_dequeue_req_replay(req);
1515 target_request_copy_put(req);
1518 spin_lock(&obd->obd_recovery_task_lock);
1519 list_splice_init(&obd->obd_lock_replay_queue, &clean_list);
1520 list_splice_init(&obd->obd_final_req_queue, &clean_list);
1521 spin_unlock(&obd->obd_recovery_task_lock);
1523 list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1524 LASSERT(req->rq_reply_state == NULL);
1525 target_request_copy_put(req);
1530 EXPORT_SYMBOL(target_cleanup_recovery);
1532 /* obd_recovery_task_lock should be held */
1533 void target_cancel_recovery_timer(struct obd_device *obd)
1535 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1536 cfs_timer_disarm(&obd->obd_recovery_timer);
1539 static void target_start_recovery_timer(struct obd_device *obd)
1541 if (obd->obd_recovery_start != 0)
1544 spin_lock(&obd->obd_dev_lock);
1545 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1546 spin_unlock(&obd->obd_dev_lock);
1550 LASSERT(obd->obd_recovery_timeout != 0);
1552 if (obd->obd_recovery_start != 0) {
1553 spin_unlock(&obd->obd_dev_lock);
1557 cfs_timer_arm(&obd->obd_recovery_timer,
1558 cfs_time_shift(obd->obd_recovery_timeout));
1559 obd->obd_recovery_start = cfs_time_current_sec();
1560 spin_unlock(&obd->obd_dev_lock);
1562 LCONSOLE_WARN("%s: Will be in recovery for at least %d:%.02d, "
1563 "or until %d client%s reconnect%s\n",
1565 obd->obd_recovery_timeout / 60,
1566 obd->obd_recovery_timeout % 60,
1567 obd->obd_max_recoverable_clients,
1568 (obd->obd_max_recoverable_clients == 1) ? "" : "s",
1569 (obd->obd_max_recoverable_clients == 1) ? "s": "");
1573 * extend recovery window.
1575 * if @extend is true, extend recovery window to have @drt remaining at least;
1576 * otherwise, make sure the recovery timeout value is not less than @drt.
1578 static void extend_recovery_timer(struct obd_device *obd, int drt, bool extend)
1582 cfs_duration_t left;
1585 spin_lock(&obd->obd_dev_lock);
1586 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1587 spin_unlock(&obd->obd_dev_lock);
1590 LASSERT(obd->obd_recovery_start != 0);
1592 now = cfs_time_current_sec();
1593 to = obd->obd_recovery_timeout;
1594 end = obd->obd_recovery_start + to;
1595 left = cfs_time_sub(end, now);
1597 if (extend && (drt > left)) {
1599 } else if (!extend && (drt > to)) {
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 = to;
1607 end = obd->obd_recovery_start + to;
1608 cfs_timer_arm(&obd->obd_recovery_timer,
1609 cfs_time_shift(end - now));
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)cfs_time_sub(end, now));
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 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 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 = 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 (!list_empty(&obd->obd_req_replay_queue)) {
1709 req = 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 = atomic_read(&obd->obd_connected_clients);
1717 completed = connected - 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 == 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 (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 (!list_empty(&obd->obd_lock_replay_queue)) {
1773 CDEBUG(D_HA, "waking for next lock\n");
1775 } else if (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 if ((obd->obd_recovery_start != 0) && (cfs_time_current_sec() >=
1801 (obd->obd_recovery_start + obd->obd_recovery_time_hard))) {
1802 CWARN("recovery is aborted by hard timeout\n");
1803 obd->obd_abort_recovery = 1;
1806 while (wait_event_timeout(obd->obd_next_transno_waitq,
1808 msecs_to_jiffies(60 * MSEC_PER_SEC)) == 0)
1809 /* wait indefinitely for event, but don't trigger watchdog */;
1811 if (obd->obd_abort_recovery) {
1812 CWARN("recovery is aborted, evict exports in recovery\n");
1813 /** evict exports which didn't finish recovery yet */
1814 class_disconnect_stale_exports(obd, exp_finished);
1816 } else if (obd->obd_recovery_expired) {
1817 obd->obd_recovery_expired = 0;
1818 /** If some clients died being recovered, evict them */
1819 LCONSOLE_WARN("%s: recovery is timed out, "
1820 "evict stale exports\n", obd->obd_name);
1821 /** evict cexports with no replay in queue, they are stalled */
1822 class_disconnect_stale_exports(obd, health_check);
1823 /** continue with VBR */
1824 spin_lock(&obd->obd_dev_lock);
1825 obd->obd_version_recov = 1;
1826 spin_unlock(&obd->obd_dev_lock);
1828 * reset timer, recovery will proceed with versions now,
1829 * timeout is set just to handle reconnection delays
1831 extend_recovery_timer(obd, RECONNECT_DELAY_MAX, true);
1832 /** Wait for recovery events again, after evicting bad clients */
1838 static struct ptlrpc_request *target_next_replay_req(struct obd_device *obd)
1840 struct ptlrpc_request *req = NULL;
1843 CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1844 obd->obd_next_recovery_transno);
1846 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLAY_DELAY2, cfs_fail_val);
1847 /** It is needed to extend recovery window above recovery_time_soft.
1848 * Extending is possible only in the end of recovery window
1849 * (see more details in handle_recovery_req).
1851 CFS_FAIL_TIMEOUT_MS(OBD_FAIL_TGT_REPLAY_DELAY, 300);
1853 if (target_recovery_overseer(obd, check_for_next_transno,
1854 exp_req_replay_healthy)) {
1855 abort_req_replay_queue(obd);
1856 abort_lock_replay_queue(obd);
1859 spin_lock(&obd->obd_recovery_task_lock);
1860 if (!list_empty(&obd->obd_req_replay_queue)) {
1861 req = list_entry(obd->obd_req_replay_queue.next,
1862 struct ptlrpc_request, rq_list);
1863 list_del_init(&req->rq_list);
1864 obd->obd_requests_queued_for_recovery--;
1865 spin_unlock(&obd->obd_recovery_task_lock);
1867 spin_unlock(&obd->obd_recovery_task_lock);
1868 LASSERT(list_empty(&obd->obd_req_replay_queue));
1869 LASSERT(atomic_read(&obd->obd_req_replay_clients) == 0);
1870 /** evict exports failed VBR */
1871 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1876 static struct ptlrpc_request *target_next_replay_lock(struct obd_device *obd)
1878 struct ptlrpc_request *req = NULL;
1880 CDEBUG(D_HA, "Waiting for lock\n");
1881 if (target_recovery_overseer(obd, check_for_next_lock,
1882 exp_lock_replay_healthy))
1883 abort_lock_replay_queue(obd);
1885 spin_lock(&obd->obd_recovery_task_lock);
1886 if (!list_empty(&obd->obd_lock_replay_queue)) {
1887 req = list_entry(obd->obd_lock_replay_queue.next,
1888 struct ptlrpc_request, rq_list);
1889 list_del_init(&req->rq_list);
1890 spin_unlock(&obd->obd_recovery_task_lock);
1892 spin_unlock(&obd->obd_recovery_task_lock);
1893 LASSERT(list_empty(&obd->obd_lock_replay_queue));
1894 LASSERT(atomic_read(&obd->obd_lock_replay_clients) == 0);
1895 /** evict exports failed VBR */
1896 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1901 static struct ptlrpc_request *target_next_final_ping(struct obd_device *obd)
1903 struct ptlrpc_request *req = NULL;
1905 spin_lock(&obd->obd_recovery_task_lock);
1906 if (!list_empty(&obd->obd_final_req_queue)) {
1907 req = list_entry(obd->obd_final_req_queue.next,
1908 struct ptlrpc_request, rq_list);
1909 list_del_init(&req->rq_list);
1910 spin_unlock(&obd->obd_recovery_task_lock);
1911 if (req->rq_export->exp_in_recovery) {
1912 spin_lock(&req->rq_export->exp_lock);
1913 req->rq_export->exp_in_recovery = 0;
1914 spin_unlock(&req->rq_export->exp_lock);
1917 spin_unlock(&obd->obd_recovery_task_lock);
1922 static void handle_recovery_req(struct ptlrpc_thread *thread,
1923 struct ptlrpc_request *req,
1924 svc_handler_t handler)
1929 * export can be evicted during recovery, no need to handle replays for
1930 * it after that, discard such request silently
1932 if (req->rq_export->exp_disconnected)
1935 req->rq_session.lc_thread = thread;
1936 req->rq_svc_thread = thread;
1937 req->rq_svc_thread->t_env->le_ses = &req->rq_session;
1939 /* thread context */
1940 lu_context_enter(&thread->t_env->le_ctx);
1942 lu_context_exit(&thread->t_env->le_ctx);
1944 /* don't reset timer for final stage */
1945 if (!exp_finished(req->rq_export)) {
1946 int to = obd_timeout;
1949 * Add request timeout to the recovery time so next request from
1950 * this client may come in recovery time
1953 struct ptlrpc_service_part *svcpt;
1955 svcpt = req->rq_rqbd->rqbd_svcpt;
1956 /* If the server sent early reply for this request,
1957 * the client will recalculate the timeout according to
1958 * current server estimate service time, so we will
1959 * use the maxium timeout here for waiting the client
1960 * sending the next req */
1961 to = max((int)at_est2timeout(
1962 at_get(&svcpt->scp_at_estimate)),
1963 (int)lustre_msg_get_timeout(req->rq_reqmsg));
1964 /* Add 2 net_latency, one for balance rq_deadline
1965 * (see ptl_send_rpc), one for resend the req to server,
1966 * Note: client will pack net_latency in replay req
1967 * (see ptlrpc_replay_req) */
1968 to += 2 * lustre_msg_get_service_time(req->rq_reqmsg);
1970 extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
1975 static int target_recovery_thread(void *arg)
1977 struct lu_target *lut = arg;
1978 struct obd_device *obd = lut->lut_obd;
1979 struct ptlrpc_request *req;
1980 struct target_recovery_data *trd = &obd->obd_recovery_data;
1981 unsigned long delta;
1983 struct ptlrpc_thread *thread = NULL;
1987 unshare_fs_struct();
1988 OBD_ALLOC_PTR(thread);
1994 OBD_FREE_PTR(thread);
1998 rc = lu_context_init(&env->le_ctx, LCT_MD_THREAD | LCT_DT_THREAD);
2000 OBD_FREE_PTR(thread);
2005 thread->t_env = env;
2006 thread->t_id = -1; /* force filter_iobuf_get/put to use local buffers */
2007 env->le_ctx.lc_thread = thread;
2008 tgt_io_thread_init(thread); /* init thread_big_cache for IO requests */
2009 thread->t_watchdog = NULL;
2011 CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
2013 trd->trd_processing_task = current_pid();
2015 spin_lock(&obd->obd_dev_lock);
2016 obd->obd_recovering = 1;
2017 spin_unlock(&obd->obd_dev_lock);
2018 complete(&trd->trd_starting);
2020 /* first of all, we have to know the first transno to replay */
2021 if (target_recovery_overseer(obd, check_for_clients,
2022 exp_connect_healthy)) {
2023 abort_req_replay_queue(obd);
2024 abort_lock_replay_queue(obd);
2027 /* next stage: replay requests */
2029 CDEBUG(D_INFO, "1: request replay stage - %d clients from t"LPU64"\n",
2030 atomic_read(&obd->obd_req_replay_clients),
2031 obd->obd_next_recovery_transno);
2032 while ((req = target_next_replay_req(obd))) {
2033 LASSERT(trd->trd_processing_task == current_pid());
2034 DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s",
2035 lustre_msg_get_transno(req->rq_reqmsg),
2036 libcfs_nid2str(req->rq_peer.nid));
2037 handle_recovery_req(thread, req,
2038 trd->trd_recovery_handler);
2040 * bz18031: increase next_recovery_transno before
2041 * target_request_copy_put() will drop exp_rpc reference
2043 spin_lock(&obd->obd_recovery_task_lock);
2044 obd->obd_next_recovery_transno++;
2045 spin_unlock(&obd->obd_recovery_task_lock);
2046 target_exp_dequeue_req_replay(req);
2047 target_request_copy_put(req);
2048 obd->obd_replayed_requests++;
2052 * The second stage: replay locks
2054 CDEBUG(D_INFO, "2: lock replay stage - %d clients\n",
2055 atomic_read(&obd->obd_lock_replay_clients));
2056 while ((req = target_next_replay_lock(obd))) {
2057 LASSERT(trd->trd_processing_task == current_pid());
2058 DEBUG_REQ(D_HA, req, "processing lock from %s: ",
2059 libcfs_nid2str(req->rq_peer.nid));
2060 handle_recovery_req(thread, req,
2061 trd->trd_recovery_handler);
2062 target_request_copy_put(req);
2063 obd->obd_replayed_locks++;
2067 * The third stage: reply on final pings, at this moment all clients
2068 * must have request in final queue
2070 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLAY_RECONNECT, cfs_fail_val);
2071 CDEBUG(D_INFO, "3: final stage - process recovery completion pings\n");
2072 /** Update server last boot epoch */
2073 tgt_boot_epoch_update(lut);
2074 /* We drop recoverying flag to forward all new requests
2075 * to regular mds_handle() since now */
2076 spin_lock(&obd->obd_dev_lock);
2077 obd->obd_recovering = obd->obd_abort_recovery = 0;
2078 spin_unlock(&obd->obd_dev_lock);
2079 spin_lock(&obd->obd_recovery_task_lock);
2080 target_cancel_recovery_timer(obd);
2081 spin_unlock(&obd->obd_recovery_task_lock);
2082 while ((req = target_next_final_ping(obd))) {
2083 LASSERT(trd->trd_processing_task == current_pid());
2084 DEBUG_REQ(D_HA, req, "processing final ping from %s: ",
2085 libcfs_nid2str(req->rq_peer.nid));
2086 handle_recovery_req(thread, req,
2087 trd->trd_recovery_handler);
2088 /* Because the waiting client can not send ping to server,
2089 * so we need refresh the last_request_time, to avoid the
2090 * export is being evicted */
2091 ptlrpc_update_export_timer(req->rq_export, 0);
2092 target_request_copy_put(req);
2095 delta = jiffies_to_msecs(jiffies - delta) / MSEC_PER_SEC;
2096 CDEBUG(D_INFO,"4: recovery completed in %lus - %d/%d reqs/locks\n",
2097 delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
2098 if (delta > OBD_RECOVERY_TIME_SOFT) {
2099 CWARN("too long recovery - read logs\n");
2100 libcfs_debug_dumplog();
2103 target_finish_recovery(obd);
2105 lu_context_fini(&env->le_ctx);
2106 trd->trd_processing_task = 0;
2107 complete(&trd->trd_finishing);
2109 tgt_io_thread_done(thread);
2110 OBD_FREE_PTR(thread);
2115 static int target_start_recovery_thread(struct lu_target *lut,
2116 svc_handler_t handler)
2118 struct obd_device *obd = lut->lut_obd;
2120 struct target_recovery_data *trd = &obd->obd_recovery_data;
2122 memset(trd, 0, sizeof(*trd));
2123 init_completion(&trd->trd_starting);
2124 init_completion(&trd->trd_finishing);
2125 trd->trd_recovery_handler = handler;
2127 if (!IS_ERR(kthread_run(target_recovery_thread,
2128 lut, "tgt_recov"))) {
2129 wait_for_completion(&trd->trd_starting);
2130 LASSERT(obd->obd_recovering != 0);
2138 void target_stop_recovery_thread(struct obd_device *obd)
2140 if (obd->obd_recovery_data.trd_processing_task > 0) {
2141 struct target_recovery_data *trd = &obd->obd_recovery_data;
2142 /** recovery can be done but postrecovery is not yet */
2143 spin_lock(&obd->obd_dev_lock);
2144 if (obd->obd_recovering) {
2145 CERROR("%s: Aborting recovery\n", obd->obd_name);
2146 obd->obd_abort_recovery = 1;
2147 wake_up(&obd->obd_next_transno_waitq);
2149 spin_unlock(&obd->obd_dev_lock);
2150 wait_for_completion(&trd->trd_finishing);
2153 EXPORT_SYMBOL(target_stop_recovery_thread);
2155 void target_recovery_fini(struct obd_device *obd)
2157 class_disconnect_exports(obd);
2158 target_stop_recovery_thread(obd);
2159 target_cleanup_recovery(obd);
2161 EXPORT_SYMBOL(target_recovery_fini);
2163 static void target_recovery_expired(unsigned long castmeharder)
2165 struct obd_device *obd = (struct obd_device *)castmeharder;
2166 CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery"
2167 " after %lds (%d clients connected)\n",
2168 obd->obd_name, atomic_read(&obd->obd_lock_replay_clients),
2169 cfs_time_current_sec()- obd->obd_recovery_start,
2170 atomic_read(&obd->obd_connected_clients));
2172 obd->obd_recovery_expired = 1;
2173 wake_up(&obd->obd_next_transno_waitq);
2176 void target_recovery_init(struct lu_target *lut, svc_handler_t handler)
2178 struct obd_device *obd = lut->lut_obd;
2179 if (obd->obd_max_recoverable_clients == 0) {
2180 /** Update server last boot epoch */
2181 tgt_boot_epoch_update(lut);
2185 CDEBUG(D_HA, "RECOVERY: service %s, %d recoverable clients, "
2186 "last_transno "LPU64"\n", obd->obd_name,
2187 obd->obd_max_recoverable_clients, obd->obd_last_committed);
2188 LASSERT(obd->obd_stopping == 0);
2189 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
2190 obd->obd_recovery_start = 0;
2191 obd->obd_recovery_end = 0;
2193 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
2194 target_start_recovery_thread(lut, handler);
2196 EXPORT_SYMBOL(target_recovery_init);
2199 static int target_process_req_flags(struct obd_device *obd,
2200 struct ptlrpc_request *req)
2202 struct obd_export *exp = req->rq_export;
2203 LASSERT(exp != NULL);
2204 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2205 /* client declares he's ready to replay locks */
2206 spin_lock(&exp->exp_lock);
2207 if (exp->exp_req_replay_needed) {
2208 exp->exp_req_replay_needed = 0;
2209 spin_unlock(&exp->exp_lock);
2211 LASSERT_ATOMIC_POS(&obd->obd_req_replay_clients);
2212 atomic_dec(&obd->obd_req_replay_clients);
2214 spin_unlock(&exp->exp_lock);
2217 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2218 /* client declares he's ready to complete recovery
2219 * so, we put the request on th final queue */
2220 spin_lock(&exp->exp_lock);
2221 if (exp->exp_lock_replay_needed) {
2222 exp->exp_lock_replay_needed = 0;
2223 spin_unlock(&exp->exp_lock);
2225 LASSERT_ATOMIC_POS(&obd->obd_lock_replay_clients);
2226 atomic_dec(&obd->obd_lock_replay_clients);
2228 spin_unlock(&exp->exp_lock);
2234 int target_queue_recovery_request(struct ptlrpc_request *req,
2235 struct obd_device *obd)
2237 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
2238 struct ptlrpc_request *reqiter;
2242 if (obd->obd_recovery_data.trd_processing_task == current_pid()) {
2243 /* Processing the queue right now, don't re-add. */
2247 target_process_req_flags(obd, req);
2249 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2250 /* client declares he's ready to complete recovery
2251 * so, we put the request on th final queue */
2252 target_request_copy_get(req);
2253 DEBUG_REQ(D_HA, req, "queue final req");
2254 wake_up(&obd->obd_next_transno_waitq);
2255 spin_lock(&obd->obd_recovery_task_lock);
2256 if (obd->obd_recovering) {
2257 list_add_tail(&req->rq_list,
2258 &obd->obd_final_req_queue);
2260 spin_unlock(&obd->obd_recovery_task_lock);
2261 target_request_copy_put(req);
2262 RETURN(obd->obd_stopping ? -ENOTCONN : 1);
2264 spin_unlock(&obd->obd_recovery_task_lock);
2267 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2268 /* client declares he's ready to replay locks */
2269 target_request_copy_get(req);
2270 DEBUG_REQ(D_HA, req, "queue lock replay req");
2271 wake_up(&obd->obd_next_transno_waitq);
2272 spin_lock(&obd->obd_recovery_task_lock);
2273 LASSERT(obd->obd_recovering);
2274 /* usually due to recovery abort */
2275 if (!req->rq_export->exp_in_recovery) {
2276 spin_unlock(&obd->obd_recovery_task_lock);
2277 target_request_copy_put(req);
2280 LASSERT(req->rq_export->exp_lock_replay_needed);
2281 list_add_tail(&req->rq_list, &obd->obd_lock_replay_queue);
2282 spin_unlock(&obd->obd_recovery_task_lock);
2286 /* CAVEAT EMPTOR: The incoming request message has been swabbed
2287 * (i.e. buflens etc are in my own byte order), but type-dependent
2288 * buffers (eg mdt_body, ost_body etc) have NOT been swabbed. */
2291 INIT_LIST_HEAD(&req->rq_list);
2292 DEBUG_REQ(D_HA, req, "not queueing");
2296 /* If we're processing the queue, we want don't want to queue this
2299 * Also, if this request has a transno less than the one we're waiting
2300 * for, we should process it now. It could (and currently always will)
2301 * be an open request for a descriptor that was opened some time ago.
2303 * Also, a resent, replayed request that has already been
2304 * handled will pass through here and be processed immediately.
2306 CDEBUG(D_HA, "Next recovery transno: "LPU64
2307 ", current: "LPU64", replaying\n",
2308 obd->obd_next_recovery_transno, transno);
2309 spin_lock(&obd->obd_recovery_task_lock);
2310 if (transno < obd->obd_next_recovery_transno) {
2311 /* Processing the queue right now, don't re-add. */
2312 LASSERT(list_empty(&req->rq_list));
2313 spin_unlock(&obd->obd_recovery_task_lock);
2316 spin_unlock(&obd->obd_recovery_task_lock);
2318 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))
2321 target_request_copy_get(req);
2322 if (!req->rq_export->exp_in_recovery) {
2323 target_request_copy_put(req);
2326 LASSERT(req->rq_export->exp_req_replay_needed);
2328 if (target_exp_enqueue_req_replay(req)) {
2329 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
2330 target_request_copy_put(req);
2335 spin_lock(&obd->obd_recovery_task_lock);
2336 LASSERT(obd->obd_recovering);
2337 list_for_each_entry(reqiter, &obd->obd_req_replay_queue, rq_list) {
2338 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
2339 list_add_tail(&req->rq_list, &reqiter->rq_list);
2344 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
2346 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
2347 "has been claimed by another client");
2348 spin_unlock(&obd->obd_recovery_task_lock);
2349 target_exp_dequeue_req_replay(req);
2350 target_request_copy_put(req);
2356 list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
2358 obd->obd_requests_queued_for_recovery++;
2359 spin_unlock(&obd->obd_recovery_task_lock);
2360 wake_up(&obd->obd_next_transno_waitq);
2364 int target_handle_ping(struct ptlrpc_request *req)
2366 obd_ping(req->rq_svc_thread->t_env, req->rq_export);
2367 return req_capsule_server_pack(&req->rq_pill);
2370 void target_committed_to_req(struct ptlrpc_request *req)
2372 struct obd_export *exp = req->rq_export;
2374 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL)
2375 lustre_msg_set_last_committed(req->rq_repmsg,
2376 exp->exp_last_committed);
2378 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2379 "%d)", exp->exp_obd->obd_no_transno,
2380 req->rq_repmsg == NULL);
2382 CDEBUG(D_INFO, "last_committed "LPU64", transno "LPU64", xid "LPU64"\n",
2383 exp->exp_last_committed, req->rq_transno, req->rq_xid);
2386 #endif /* HAVE_SERVER_SUPPORT */
2389 * Packs current SLV and Limit into \a req.
2391 int target_pack_pool_reply(struct ptlrpc_request *req)
2393 struct obd_device *obd;
2396 /* Check that we still have all structures alive as this may
2397 * be some late RPC at shutdown time. */
2398 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
2399 !exp_connect_lru_resize(req->rq_export))) {
2400 lustre_msg_set_slv(req->rq_repmsg, 0);
2401 lustre_msg_set_limit(req->rq_repmsg, 0);
2405 /* OBD is alive here as export is alive, which we checked above. */
2406 obd = req->rq_export->exp_obd;
2408 read_lock(&obd->obd_pool_lock);
2409 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
2410 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
2411 read_unlock(&obd->obd_pool_lock);
2416 static int target_send_reply_msg(struct ptlrpc_request *req,
2417 int rc, int fail_id)
2419 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
2420 DEBUG_REQ(D_ERROR, req, "dropping reply");
2425 DEBUG_REQ(D_NET, req, "processing error (%d)", rc);
2426 req->rq_status = rc;
2427 return (ptlrpc_send_error(req, 1));
2429 DEBUG_REQ(D_NET, req, "sending reply");
2432 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
2435 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
2437 struct ptlrpc_service_part *svcpt;
2439 struct ptlrpc_reply_state *rs;
2440 struct obd_export *exp;
2443 if (req->rq_no_reply) {
2448 svcpt = req->rq_rqbd->rqbd_svcpt;
2449 rs = req->rq_reply_state;
2450 if (rs == NULL || !rs->rs_difficult) {
2452 target_send_reply_msg (req, rc, fail_id);
2457 /* must be an export if locks saved */
2458 LASSERT(req->rq_export != NULL);
2459 /* req/reply consistent */
2460 LASSERT(rs->rs_svcpt == svcpt);
2463 LASSERT(!rs->rs_scheduled);
2464 LASSERT(!rs->rs_scheduled_ever);
2465 LASSERT(!rs->rs_handled);
2466 LASSERT(!rs->rs_on_net);
2467 LASSERT(rs->rs_export == NULL);
2468 LASSERT(list_empty(&rs->rs_obd_list));
2469 LASSERT(list_empty(&rs->rs_exp_list));
2471 exp = class_export_get(req->rq_export);
2473 /* disable reply scheduling while I'm setting up */
2474 rs->rs_scheduled = 1;
2476 rs->rs_xid = req->rq_xid;
2477 rs->rs_transno = req->rq_transno;
2478 rs->rs_export = exp;
2479 rs->rs_opc = lustre_msg_get_opc(req->rq_reqmsg);
2481 spin_lock(&exp->exp_uncommitted_replies_lock);
2482 CDEBUG(D_NET, "rs transno = "LPU64", last committed = "LPU64"\n",
2483 rs->rs_transno, exp->exp_last_committed);
2484 if (rs->rs_transno > exp->exp_last_committed) {
2485 /* not committed already */
2486 list_add_tail(&rs->rs_obd_list,
2487 &exp->exp_uncommitted_replies);
2489 spin_unlock(&exp->exp_uncommitted_replies_lock);
2491 spin_lock(&exp->exp_lock);
2492 list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies);
2493 spin_unlock(&exp->exp_lock);
2495 netrc = target_send_reply_msg(req, rc, fail_id);
2497 spin_lock(&svcpt->scp_rep_lock);
2499 atomic_inc(&svcpt->scp_nreps_difficult);
2502 /* error sending: reply is off the net. Also we need +1
2503 * reply ref until ptlrpc_handle_rs() is done
2504 * with the reply state (if the send was successful, there
2505 * would have been +1 ref for the net, which
2506 * reply_out_callback leaves alone) */
2508 ptlrpc_rs_addref(rs);
2511 spin_lock(&rs->rs_lock);
2512 if (rs->rs_transno <= exp->exp_last_committed ||
2513 (!rs->rs_on_net && !rs->rs_no_ack) ||
2514 list_empty(&rs->rs_exp_list) || /* completed already */
2515 list_empty(&rs->rs_obd_list)) {
2516 CDEBUG(D_HA, "Schedule reply immediately\n");
2517 ptlrpc_dispatch_difficult_reply(rs);
2519 list_add(&rs->rs_list, &svcpt->scp_rep_active);
2520 rs->rs_scheduled = 0; /* allow notifier to schedule */
2522 spin_unlock(&rs->rs_lock);
2523 spin_unlock(&svcpt->scp_rep_lock);
2527 ldlm_mode_t lck_compat_array[] = {
2528 [LCK_EX] = LCK_COMPAT_EX,
2529 [LCK_PW] = LCK_COMPAT_PW,
2530 [LCK_PR] = LCK_COMPAT_PR,
2531 [LCK_CW] = LCK_COMPAT_CW,
2532 [LCK_CR] = LCK_COMPAT_CR,
2533 [LCK_NL] = LCK_COMPAT_NL,
2534 [LCK_GROUP] = LCK_COMPAT_GROUP,
2535 [LCK_COS] = LCK_COMPAT_COS,
2539 * Rather arbitrary mapping from LDLM error codes to errno values. This should
2540 * not escape to the user level.
2542 int ldlm_error2errno(ldlm_error_t error)
2548 case ELDLM_LOCK_MATCHED:
2551 case ELDLM_LOCK_CHANGED:
2554 case ELDLM_LOCK_ABORTED:
2557 case ELDLM_LOCK_REPLACED:
2560 case ELDLM_NO_LOCK_DATA:
2563 case ELDLM_NAMESPACE_EXISTS:
2566 case ELDLM_BAD_NAMESPACE:
2570 if (((int)error) < 0) /* cast to signed type */
2571 result = error; /* as ldlm_error_t can be unsigned */
2573 CERROR("Invalid DLM result code: %d\n", error);
2579 EXPORT_SYMBOL(ldlm_error2errno);
2582 * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
2584 ldlm_error_t ldlm_errno2error(int err_no)
2593 error = ELDLM_LOCK_CHANGED;
2596 error = ELDLM_LOCK_ABORTED;
2599 error = ELDLM_LOCK_REPLACED;
2602 error = ELDLM_NO_LOCK_DATA;
2605 error = ELDLM_NAMESPACE_EXISTS;
2608 error = ELDLM_BAD_NAMESPACE;
2616 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2617 void ldlm_dump_export_locks(struct obd_export *exp)
2619 spin_lock(&exp->exp_locks_list_guard);
2620 if (!list_empty(&exp->exp_locks_list)) {
2621 struct ldlm_lock *lock;
2623 CERROR("dumping locks for export %p,"
2624 "ignore if the unmount doesn't hang\n", exp);
2625 list_for_each_entry(lock, &exp->exp_locks_list,
2627 LDLM_ERROR(lock, "lock:");
2629 spin_unlock(&exp->exp_locks_list_guard);
2633 #ifdef HAVE_SERVER_SUPPORT
2634 static int target_bulk_timeout(void *data)
2637 /* We don't fail the connection here, because having the export
2638 * killed makes the (vital) call to commitrw very sad.
2643 static inline const char *bulk2type(struct ptlrpc_request *req)
2645 if (req->rq_bulk_read)
2647 if (req->rq_bulk_write)
2652 int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc,
2653 struct l_wait_info *lwi)
2655 struct ptlrpc_request *req = desc->bd_req;
2656 time_t start = cfs_time_current_sec();
2662 /* If there is eviction in progress, wait for it to finish. */
2663 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
2664 *lwi = LWI_INTR(NULL, NULL);
2665 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
2666 !atomic_read(&exp->exp_obd->
2667 obd_evict_inprogress),
2671 /* Check if client was evicted or reconnected already. */
2672 if (exp->exp_failed ||
2673 exp->exp_conn_cnt > lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
2676 if (req->rq_bulk_read)
2677 rc = sptlrpc_svc_wrap_bulk(req, desc);
2679 rc = ptlrpc_start_bulk_transfer(desc);
2683 DEBUG_REQ(D_ERROR, req, "bulk %s failed: rc %d",
2684 bulk2type(req), rc);
2688 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
2689 ptlrpc_abort_bulk(desc);
2693 /* limit actual bulk transfer to bulk_timeout seconds */
2694 deadline = start + bulk_timeout;
2695 if (deadline > req->rq_deadline)
2696 deadline = req->rq_deadline;
2699 long timeoutl = deadline - cfs_time_current_sec();
2700 cfs_duration_t timeout = timeoutl <= 0 ?
2701 CFS_TICK : cfs_time_seconds(timeoutl);
2704 *lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
2705 target_bulk_timeout, desc);
2706 rc = l_wait_event(desc->bd_waitq,
2707 !ptlrpc_server_bulk_active(desc) ||
2710 lustre_msg_get_conn_cnt(req->rq_reqmsg),
2712 LASSERT(rc == 0 || rc == -ETIMEDOUT);
2713 /* Wait again if we changed rq_deadline. */
2714 rq_deadline = ACCESS_ONCE(req->rq_deadline);
2715 deadline = start + bulk_timeout;
2716 if (deadline > rq_deadline)
2717 deadline = rq_deadline;
2718 } while ((rc == -ETIMEDOUT) &&
2719 (deadline > cfs_time_current_sec()));
2721 if (rc == -ETIMEDOUT) {
2722 DEBUG_REQ(D_ERROR, req, "timeout on bulk %s after %ld%+lds",
2723 bulk2type(req), deadline - start,
2724 cfs_time_current_sec() - deadline);
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_conn_cnt >
2732 lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
2733 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk %s",
2735 /* We don't reply anyway. */
2737 ptlrpc_abort_bulk(desc);
2738 } else if (desc->bd_failure) {
2739 DEBUG_REQ(D_ERROR, req, "network error on bulk %s",
2741 /* XXX should this be a different errno? */
2744 if (req->rq_bulk_write)
2745 rc = sptlrpc_svc_unwrap_bulk(req, desc);
2746 if (rc == 0 && desc->bd_nob_transferred != desc->bd_nob) {
2747 DEBUG_REQ(D_ERROR, req, "truncated bulk %s %d(%d)",
2748 bulk2type(req), desc->bd_nob_transferred,
2750 /* XXX should this be a different errno? */
2757 EXPORT_SYMBOL(target_bulk_io);
2759 #endif /* HAVE_SERVER_SUPPORT */