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)));
343 cli->cl_avail_grant = 0;
344 /* FIXME: Should limit this for the sum of all cl_dirty_max. */
345 cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
346 if (cli->cl_dirty_max >> CFS_PAGE_SHIFT > cfs_num_physpages / 8)
347 cli->cl_dirty_max = cfs_num_physpages << (CFS_PAGE_SHIFT - 3);
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 cfs_waitq_init(&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 >> CFS_PAGE_SHIFT);
395 if (!strcmp(name, LUSTRE_MDC_NAME)) {
396 cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT;
397 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 128 /* MB */) {
398 cli->cl_max_rpcs_in_flight = 2;
399 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 256 /* MB */) {
400 cli->cl_max_rpcs_in_flight = 3;
401 } else if (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT) <= 512 /* MB */) {
402 cli->cl_max_rpcs_in_flight = 4;
404 if (osc_on_mdt(obddev->obd_name))
405 cli->cl_max_rpcs_in_flight = MDS_OSC_MAX_RIF_DEFAULT;
407 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
411 CERROR("ldlm_get_ref failed: %d\n", rc);
415 ptlrpc_init_client(rq_portal, rp_portal, name,
416 &obddev->obd_ldlm_client);
418 imp = class_new_import(obddev);
420 GOTO(err_ldlm, rc = -ENOENT);
421 imp->imp_client = &obddev->obd_ldlm_client;
422 imp->imp_connect_op = connect_op;
423 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
424 LUSTRE_CFG_BUFLEN(lcfg, 1));
425 class_import_put(imp);
427 rc = client_import_add_conn(imp, &server_uuid, 1);
429 CERROR("can't add initial connection\n");
430 GOTO(err_import, rc);
433 cli->cl_import = imp;
434 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
435 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
436 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
438 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
439 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
440 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
441 name, obddev->obd_name,
442 cli->cl_target_uuid.uuid);
443 spin_lock(&imp->imp_lock);
444 imp->imp_deactive = 1;
445 spin_unlock(&imp->imp_lock);
449 obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
450 LDLM_NAMESPACE_CLIENT,
451 LDLM_NAMESPACE_GREEDY,
453 if (obddev->obd_namespace == NULL) {
454 CERROR("Unable to create client namespace - %s\n",
456 GOTO(err_import, rc = -ENOMEM);
459 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
464 class_destroy_import(imp);
471 EXPORT_SYMBOL(client_obd_setup);
473 int client_obd_cleanup(struct obd_device *obddev)
477 ldlm_namespace_free_post(obddev->obd_namespace);
478 obddev->obd_namespace = NULL;
480 LASSERT(obddev->u.cli.cl_import == NULL);
485 EXPORT_SYMBOL(client_obd_cleanup);
487 /* ->o_connect() method for client side (OSC and MDC and MGC) */
488 int client_connect_import(const struct lu_env *env,
489 struct obd_export **exp,
490 struct obd_device *obd, struct obd_uuid *cluuid,
491 struct obd_connect_data *data, void *localdata)
493 struct client_obd *cli = &obd->u.cli;
494 struct obd_import *imp = cli->cl_import;
495 struct obd_connect_data *ocd;
496 struct lustre_handle conn = { 0 };
501 down_write(&cli->cl_sem);
502 if (cli->cl_conn_count > 0 )
503 GOTO(out_sem, rc = -EALREADY);
505 rc = class_connect(&conn, obd, cluuid);
509 cli->cl_conn_count++;
510 *exp = class_conn2export(&conn);
512 LASSERT(obd->obd_namespace);
514 imp->imp_dlm_handle = conn;
515 rc = ptlrpc_init_import(imp);
519 ocd = &imp->imp_connect_data;
522 imp->imp_connect_flags_orig = data->ocd_connect_flags;
525 rc = ptlrpc_connect_import(imp);
527 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
530 LASSERT((*exp)->exp_connection);
533 LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
534 ocd->ocd_connect_flags, "old "LPX64", new "LPX64"\n",
535 data->ocd_connect_flags, ocd->ocd_connect_flags);
536 data->ocd_connect_flags = ocd->ocd_connect_flags;
539 ptlrpc_pinger_add_import(imp);
545 cli->cl_conn_count--;
546 class_disconnect(*exp);
550 up_write(&cli->cl_sem);
554 EXPORT_SYMBOL(client_connect_import);
556 int client_disconnect_export(struct obd_export *exp)
558 struct obd_device *obd = class_exp2obd(exp);
559 struct client_obd *cli;
560 struct obd_import *imp;
565 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
566 exp, exp ? exp->exp_handle.h_cookie : -1);
571 imp = cli->cl_import;
573 down_write(&cli->cl_sem);
574 CDEBUG(D_INFO, "disconnect %s - %d\n", obd->obd_name,
577 if (!cli->cl_conn_count) {
578 CERROR("disconnecting disconnected device (%s)\n",
580 GOTO(out_disconnect, rc = -EINVAL);
583 cli->cl_conn_count--;
584 if (cli->cl_conn_count)
585 GOTO(out_disconnect, rc = 0);
587 /* Mark import deactivated now, so we don't try to reconnect if any
588 * of the cleanup RPCs fails (e.g. LDLM cancel, etc). We don't
589 * fully deactivate the import, or that would drop all requests. */
590 spin_lock(&imp->imp_lock);
591 imp->imp_deactive = 1;
592 spin_unlock(&imp->imp_lock);
594 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
595 * delete it regardless. (It's safe to delete an import that was
597 (void)ptlrpc_pinger_del_import(imp);
599 if (obd->obd_namespace != NULL) {
600 /* obd_force == local only */
601 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
602 obd->obd_force ? LCF_LOCAL : 0, NULL);
603 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force);
606 /* There's no need to hold sem while disconnecting an import,
607 * and it may actually cause deadlock in GSS. */
608 up_write(&cli->cl_sem);
609 rc = ptlrpc_disconnect_import(imp, 0);
610 down_write(&cli->cl_sem);
612 ptlrpc_invalidate_import(imp);
617 /* Use server style - class_disconnect should be always called for
619 err = class_disconnect(exp);
623 up_write(&cli->cl_sem);
627 EXPORT_SYMBOL(client_disconnect_export);
629 #ifdef HAVE_SERVER_SUPPORT
630 int server_disconnect_export(struct obd_export *exp)
635 /* Disconnect early so that clients can't keep using export. */
636 rc = class_disconnect(exp);
637 /* Close import to avoid sending any requests. */
638 if (exp->exp_imp_reverse)
639 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
641 if (exp->exp_obd->obd_namespace != NULL)
642 ldlm_cancel_locks_for_export(exp);
644 /* complete all outstanding replies */
645 spin_lock(&exp->exp_lock);
646 while (!cfs_list_empty(&exp->exp_outstanding_replies)) {
647 struct ptlrpc_reply_state *rs =
648 cfs_list_entry(exp->exp_outstanding_replies.next,
649 struct ptlrpc_reply_state, rs_exp_list);
650 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
652 spin_lock(&svcpt->scp_rep_lock);
654 cfs_list_del_init(&rs->rs_exp_list);
655 spin_lock(&rs->rs_lock);
656 ptlrpc_schedule_difficult_reply(rs);
657 spin_unlock(&rs->rs_lock);
659 spin_unlock(&svcpt->scp_rep_lock);
661 spin_unlock(&exp->exp_lock);
665 EXPORT_SYMBOL(server_disconnect_export);
667 /* --------------------------------------------------------------------------
668 * from old lib/target.c
669 * -------------------------------------------------------------------------- */
671 static int target_handle_reconnect(struct lustre_handle *conn,
672 struct obd_export *exp,
673 struct obd_uuid *cluuid)
677 if (exp->exp_connection && exp->exp_imp_reverse) {
678 struct lustre_handle *hdl;
679 struct obd_device *target;
681 hdl = &exp->exp_imp_reverse->imp_remote_handle;
682 target = exp->exp_obd;
684 /* Might be a re-connect after a partition. */
685 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
686 if (target->obd_recovering) {
687 int timeout = cfs_duration_sec(cfs_time_sub(
689 &target->obd_recovery_timer),
690 cfs_time_current()));
692 LCONSOLE_WARN("%s: Client %s (at %s) reconnect"
693 "ing, waiting for %d clients in recov"
694 "ery for %d:%.02d\n", target->obd_name,
695 obd_uuid2str(&exp->exp_client_uuid),
696 obd_export_nid2str(exp),
697 target->obd_max_recoverable_clients,
698 timeout / 60, timeout % 60);
700 LCONSOLE_WARN("%s: Client %s (at %s) "
701 "reconnecting\n", target->obd_name,
702 obd_uuid2str(&exp->exp_client_uuid),
703 obd_export_nid2str(exp));
706 conn->cookie = exp->exp_handle.h_cookie;
707 /* target_handle_connect() treats EALREADY and
708 * -EALREADY differently. EALREADY means we are
709 * doing a valid reconnect from the same client. */
712 LCONSOLE_WARN("%s: already connected client %s (at %s) "
713 "with handle "LPX64". Rejecting client "
714 "with the same UUID trying to reconnect "
715 "with handle "LPX64"\n", target->obd_name,
716 obd_uuid2str(&exp->exp_client_uuid),
717 obd_export_nid2str(exp),
718 hdl->cookie, conn->cookie);
719 memset(conn, 0, sizeof *conn);
720 /* target_handle_connect() treats EALREADY and
721 * -EALREADY differently. -EALREADY is an error
722 * (same UUID, different handle). */
727 conn->cookie = exp->exp_handle.h_cookie;
728 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
729 cluuid->uuid, exp, conn->cookie);
733 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
736 struct obd_export *exp = cb_data;
738 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
739 obd->obd_name, exp->exp_client_uuid.uuid);
741 spin_lock(&exp->exp_lock);
742 exp->exp_need_sync = 0;
743 spin_unlock(&exp->exp_lock);
744 class_export_cb_put(exp);
746 EXPORT_SYMBOL(target_client_add_cb);
750 check_and_start_recovery_timer(struct obd_device *obd,
751 struct ptlrpc_request *req, int new_client);
754 check_and_start_recovery_timer(struct obd_device *obd,
755 struct ptlrpc_request *req, int new_client)
760 int target_handle_connect(struct ptlrpc_request *req)
762 struct obd_device *target = NULL, *targref = NULL;
763 struct obd_export *export = NULL;
764 struct obd_import *revimp;
765 struct obd_import *tmp_imp = NULL;
766 struct lustre_handle conn;
767 struct lustre_handle *tmp;
768 struct obd_uuid tgtuuid;
769 struct obd_uuid cluuid;
770 struct obd_uuid remote_uuid;
775 bool mds_conn = false, lw_client = false;
776 struct obd_connect_data *data, *tmpdata;
778 lnet_nid_t *client_nid = NULL;
781 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
783 str = req_capsule_client_get(&req->rq_pill, &RMF_TGTUUID);
785 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
786 GOTO(out, rc = -EINVAL);
789 obd_str2uuid(&tgtuuid, str);
790 target = class_uuid2obd(&tgtuuid);
792 target = class_name2obd(str);
795 deuuidify(str, NULL, &target_start, &target_len);
796 LCONSOLE_ERROR_MSG(0x137, "%s: not available for connect "
797 "from %s (no target)\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__, cfs_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_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
873 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
874 "libclient connection attempt");
875 GOTO(out, rc = -EPROTO);
876 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
877 LUSTRE_VERSION_ALLOWED_OFFSET ||
878 data->ocd_version > LUSTRE_VERSION_CODE +
879 LUSTRE_VERSION_ALLOWED_OFFSET) {
880 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
881 "libclient connection attempt",
882 data->ocd_version < LUSTRE_VERSION_CODE ?
884 OBD_OCD_VERSION_MAJOR(data->ocd_version),
885 OBD_OCD_VERSION_MINOR(data->ocd_version),
886 OBD_OCD_VERSION_PATCH(data->ocd_version),
887 OBD_OCD_VERSION_FIX(data->ocd_version));
888 data = req_capsule_server_sized_get(&req->rq_pill,
890 offsetof(typeof(*data), ocd_version) +
891 sizeof(data->ocd_version));
893 data->ocd_connect_flags = OBD_CONNECT_VERSION;
894 data->ocd_version = LUSTRE_VERSION_CODE;
896 GOTO(out, rc = -EPROTO);
900 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) &&
901 (data->ocd_connect_flags & OBD_CONNECT_MDS))
904 if ((data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) != 0)
907 /* lctl gets a backstage, all-access pass. */
908 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
909 goto dont_check_exports;
911 export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
915 /* We've found an export in the hash. */
917 spin_lock(&export->exp_lock);
919 if (export->exp_connecting) { /* bug 9635, et. al. */
920 spin_unlock(&export->exp_lock);
921 LCONSOLE_WARN("%s: Export %p already connecting from %s\n",
922 export->exp_obd->obd_name, export,
923 libcfs_nid2str(req->rq_peer.nid));
924 class_export_put(export);
927 } else if (mds_conn && export->exp_connection) {
928 spin_unlock(&export->exp_lock);
929 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
930 /* MDS reconnected after failover. */
931 LCONSOLE_WARN("%s: Received MDS connection from "
932 "%s, removing former export from %s\n",
933 target->obd_name, libcfs_nid2str(req->rq_peer.nid),
934 libcfs_nid2str(export->exp_connection->c_peer.nid));
936 /* New MDS connection from the same NID. */
937 LCONSOLE_WARN("%s: Received new MDS connection from "
938 "%s, removing former export from same NID\n",
939 target->obd_name, libcfs_nid2str(req->rq_peer.nid));
940 class_fail_export(export);
941 class_export_put(export);
944 } else if (export->exp_connection != NULL &&
945 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
946 (lustre_msg_get_op_flags(req->rq_reqmsg) &
947 MSG_CONNECT_INITIAL)) {
948 spin_unlock(&export->exp_lock);
949 /* In MDS failover we have static UUID but NID can change. */
950 LCONSOLE_WARN("%s: Client %s seen on new nid %s when "
951 "existing nid %s is already connected\n",
952 target->obd_name, cluuid.uuid,
953 libcfs_nid2str(req->rq_peer.nid),
955 export->exp_connection->c_peer.nid));
957 class_export_put(export);
960 export->exp_connecting = 1;
961 spin_unlock(&export->exp_lock);
962 LASSERT(export->exp_obd == target);
964 rc = target_handle_reconnect(&conn, export, &cluuid);
967 /* If we found an export, we already unlocked. */
970 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
971 } else if (req->rq_export == NULL &&
972 cfs_atomic_read(&export->exp_rpc_count) > 0) {
973 LCONSOLE_WARN("%s: Client %s (at %s) refused connection, "
974 "still busy with %d references\n",
975 target->obd_name, cluuid.uuid,
976 libcfs_nid2str(req->rq_peer.nid),
977 cfs_atomic_read(&export->exp_refcount));
978 GOTO(out, rc = -EBUSY);
979 } else if (req->rq_export != NULL &&
980 (cfs_atomic_read(&export->exp_rpc_count) > 1)) {
981 /* The current connect RPC has increased exp_rpc_count. */
982 LCONSOLE_WARN("%s: Client %s (at %s) refused reconnection, "
983 "still busy with %d active RPCs\n",
984 target->obd_name, cluuid.uuid,
985 libcfs_nid2str(req->rq_peer.nid),
986 cfs_atomic_read(&export->exp_rpc_count) - 1);
987 spin_lock(&export->exp_lock);
988 if (req->rq_export->exp_conn_cnt <
989 lustre_msg_get_conn_cnt(req->rq_reqmsg))
990 /* try to abort active requests */
991 req->rq_export->exp_abort_active_req = 1;
992 spin_unlock(&export->exp_lock);
993 GOTO(out, rc = -EBUSY);
994 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
995 if (!strstr(cluuid.uuid, "mdt"))
996 LCONSOLE_WARN("%s: Rejecting reconnect from the "
997 "known client %s (at %s) because it "
998 "is indicating it is a new client",
999 target->obd_name, cluuid.uuid,
1000 libcfs_nid2str(req->rq_peer.nid));
1001 GOTO(out, rc = -EALREADY);
1003 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
1010 CDEBUG(D_HA, "%s: connection from %s@%s %st"LPU64" exp %p cur %ld last %ld\n",
1011 target->obd_name, cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1012 target->obd_recovering ? "recovering/" : "", data->ocd_transno,
1013 export, (long)cfs_time_current_sec(),
1014 export ? (long)export->exp_last_request_time : 0);
1016 /* If this is the first time a client connects, reset the recovery
1017 * timer. Discard lightweight connections which might be local. */
1018 if (!lw_client && rc == 0 && target->obd_recovering)
1019 check_and_start_recovery_timer(target, req, export == NULL);
1021 /* We want to handle EALREADY but *not* -EALREADY from
1022 * target_handle_reconnect(), return reconnection state in a flag. */
1023 if (rc == EALREADY) {
1024 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
1030 /* Tell the client if we support replayable requests. */
1031 if (target->obd_replayable)
1032 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
1033 client_nid = &req->rq_peer.nid;
1035 if (export == NULL) {
1036 /* allow lightweight connections during recovery */
1037 if (target->obd_recovering && !lw_client) {
1039 int c; /* connected */
1040 int i; /* in progress */
1042 int s; /* stale/evicted */
1044 c = cfs_atomic_read(&target->obd_connected_clients);
1045 i = cfs_atomic_read(&target->obd_lock_replay_clients);
1046 k = target->obd_max_recoverable_clients;
1047 s = target->obd_stale_clients;
1048 t = cfs_timer_deadline(&target->obd_recovery_timer);
1049 t = cfs_time_sub(t, cfs_time_current());
1050 t = cfs_duration_sec(t);
1051 LCONSOLE_WARN("%s: Denying connection for new client "
1052 "%s (at %s), waiting for all %d known "
1053 "clients (%d recovered, %d in progress, "
1054 "and %d evicted) to recover in %d:%.02d\n",
1055 target->obd_name, cluuid.uuid,
1056 libcfs_nid2str(req->rq_peer.nid), k,
1057 c - i, i, s, (int)t / 60,
1062 rc = obd_connect(req->rq_svc_thread->t_env,
1063 &export, target, &cluuid, data,
1066 conn.cookie = export->exp_handle.h_cookie;
1069 rc = obd_reconnect(req->rq_svc_thread->t_env,
1070 export, target, &cluuid, data, client_nid);
1075 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
1076 /* 2.2.0 clients always swab nidtbl entries due to a bug, so server
1077 * will do the swabbing for if the client is using the same endianness.
1079 * This fixup is version-limited, because we don't want to carry the
1080 * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we need
1081 * interop with unpatched 2.2 clients. For newer clients, servers
1082 * will never do MNE swabbing, let the client handle that. LU-1644 */
1083 export->exp_need_mne_swab = !ptlrpc_req_need_swab(req) &&
1084 !(data->ocd_connect_flags & OBD_CONNECT_MNE_SWAB);
1086 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and exp_need_mne_swab"
1089 LASSERT(target->u.obt.obt_magic == OBT_MAGIC);
1090 data->ocd_instance = target->u.obt.obt_instance;
1092 /* Return only the parts of obd_connect_data that we understand, so the
1093 * client knows that we don't understand the rest. */
1095 tmpsize = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
1097 tmpdata = req_capsule_server_get(&req->rq_pill,
1099 /* Don't use struct assignment here, because the client reply
1100 * buffer may be smaller/larger than the local struct
1101 * obd_connect_data. */
1102 memcpy(tmpdata, data, min(tmpsize, size));
1105 /* If all else goes well, this is our RPC return code. */
1108 lustre_msg_set_handle(req->rq_repmsg, &conn);
1110 /* If the client and the server are the same node, we will already
1111 * have an export that really points to the client's DLM export,
1112 * because we have a shared handles table.
1114 * XXX this will go away when shaver stops sending the "connect" handle
1115 * in the real "remote handle" field of the request --phik 24 Apr 2003
1117 ptlrpc_request_change_export(req, export);
1119 spin_lock(&export->exp_lock);
1120 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
1121 spin_unlock(&export->exp_lock);
1122 CDEBUG(D_RPCTRACE, "%s: %s already connected at greater "
1123 "or equal conn_cnt: %d >= %d\n",
1124 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1125 export->exp_conn_cnt,
1126 lustre_msg_get_conn_cnt(req->rq_reqmsg));
1128 GOTO(out, rc = -EALREADY);
1130 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1131 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1132 export->exp_abort_active_req = 0;
1134 /* Don't evict liblustre clients for not pinging. */
1135 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1136 export->exp_libclient = 1;
1137 spin_unlock(&export->exp_lock);
1139 spin_lock(&target->obd_dev_lock);
1140 cfs_list_del_init(&export->exp_obd_chain_timed);
1141 spin_unlock(&target->obd_dev_lock);
1143 spin_unlock(&export->exp_lock);
1146 if (export->exp_connection != NULL) {
1147 /* Check to see if connection came from another NID. */
1148 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1149 !cfs_hlist_unhashed(&export->exp_nid_hash))
1150 cfs_hash_del(export->exp_obd->obd_nid_hash,
1151 &export->exp_connection->c_peer.nid,
1152 &export->exp_nid_hash);
1154 ptlrpc_connection_put(export->exp_connection);
1157 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1160 if (cfs_hlist_unhashed(&export->exp_nid_hash)) {
1161 cfs_hash_add(export->exp_obd->obd_nid_hash,
1162 &export->exp_connection->c_peer.nid,
1163 &export->exp_nid_hash);
1166 if (target->obd_recovering && !export->exp_in_recovery && !lw_client) {
1168 __u64 transno = data->ocd_transno;
1170 spin_lock(&export->exp_lock);
1171 /* possible race with class_disconnect_stale_exports,
1172 * export may be already in the eviction process */
1173 if (export->exp_failed) {
1174 spin_unlock(&export->exp_lock);
1175 GOTO(out, rc = -ENODEV);
1177 export->exp_in_recovery = 1;
1178 export->exp_req_replay_needed = 1;
1179 export->exp_lock_replay_needed = 1;
1180 spin_unlock(&export->exp_lock);
1182 has_transno = !!(lustre_msg_get_op_flags(req->rq_reqmsg) &
1183 MSG_CONNECT_TRANSNO);
1184 if (has_transno && transno == 0)
1185 CWARN("Connect with zero transno!\n");
1187 if (has_transno && transno > 0 &&
1188 transno < target->obd_next_recovery_transno &&
1189 transno > target->obd_last_committed) {
1190 /* Another way is to use cmpxchg() to be lock-free. */
1191 spin_lock(&target->obd_recovery_task_lock);
1192 if (transno < target->obd_next_recovery_transno)
1193 target->obd_next_recovery_transno = transno;
1194 spin_unlock(&target->obd_recovery_task_lock);
1197 cfs_atomic_inc(&target->obd_req_replay_clients);
1198 cfs_atomic_inc(&target->obd_lock_replay_clients);
1199 if (cfs_atomic_inc_return(&target->obd_connected_clients) ==
1200 target->obd_max_recoverable_clients)
1201 cfs_waitq_signal(&target->obd_next_transno_waitq);
1204 /* Tell the client we're in recovery, when client is involved in it. */
1205 if (target->obd_recovering && !lw_client)
1206 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
1208 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
1211 /* Return -ENOTCONN in case of errors to let client reconnect. */
1212 revimp = class_new_import(target);
1213 if (revimp == NULL) {
1214 CERROR("fail to alloc new reverse import.\n");
1215 GOTO(out, rc = -ENOTCONN);
1218 spin_lock(&export->exp_lock);
1219 if (export->exp_imp_reverse != NULL)
1220 /* destroyed import can be still referenced in ctxt */
1221 tmp_imp = export->exp_imp_reverse;
1222 export->exp_imp_reverse = revimp;
1223 spin_unlock(&export->exp_lock);
1225 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1226 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1227 revimp->imp_remote_handle = conn;
1228 revimp->imp_dlm_fake = 1;
1229 revimp->imp_state = LUSTRE_IMP_FULL;
1231 /* Unknown versions will be caught in
1232 * ptlrpc_handle_server_req_in->lustre_unpack_msg(). */
1233 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1235 if ((data->ocd_connect_flags & OBD_CONNECT_AT) &&
1236 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1237 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1239 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1241 if ((data->ocd_connect_flags & OBD_CONNECT_FULL20) &&
1242 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1243 revimp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
1245 revimp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18;
1247 rc = sptlrpc_import_sec_adapt(revimp, req->rq_svc_ctx, &req->rq_flvr);
1249 CERROR("Failed to get sec for reverse import: %d\n", rc);
1250 spin_lock(&export->exp_lock);
1251 export->exp_imp_reverse = NULL;
1252 spin_unlock(&export->exp_lock);
1253 class_destroy_import(revimp);
1256 class_import_put(revimp);
1259 if (tmp_imp != NULL)
1260 client_destroy_import(tmp_imp);
1262 spin_lock(&export->exp_lock);
1263 export->exp_connecting = 0;
1264 spin_unlock(&export->exp_lock);
1266 class_export_put(export);
1269 spin_lock(&target->obd_dev_lock);
1270 target->obd_conn_inprogress--;
1271 spin_unlock(&target->obd_dev_lock);
1273 class_decref(targref, __func__, cfs_current());
1276 req->rq_status = rc;
1279 EXPORT_SYMBOL(target_handle_connect);
1281 int target_handle_disconnect(struct ptlrpc_request *req)
1286 rc = req_capsule_server_pack(&req->rq_pill);
1290 /* Keep the rq_export around so we can send the reply. */
1291 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1295 EXPORT_SYMBOL(target_handle_disconnect);
1297 void target_destroy_export(struct obd_export *exp)
1299 struct obd_import *imp = NULL;
1300 /* exports created from last_rcvd data, and "fake"
1301 exports created by lctl don't have an import */
1302 spin_lock(&exp->exp_lock);
1303 if (exp->exp_imp_reverse != NULL) {
1304 imp = exp->exp_imp_reverse;
1305 exp->exp_imp_reverse = NULL;
1307 spin_unlock(&exp->exp_lock);
1309 client_destroy_import(imp);
1311 LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
1312 LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
1313 LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
1314 LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
1316 EXPORT_SYMBOL(target_destroy_export);
1319 * Recovery functions
1321 static void target_request_copy_get(struct ptlrpc_request *req)
1323 class_export_rpc_inc(req->rq_export);
1324 LASSERT(cfs_list_empty(&req->rq_list));
1325 CFS_INIT_LIST_HEAD(&req->rq_replay_list);
1327 /* Increase refcount to keep request in queue. */
1328 cfs_atomic_inc(&req->rq_refcount);
1329 /* Let export know it has replays to be handled. */
1330 cfs_atomic_inc(&req->rq_export->exp_replay_count);
1333 static void target_request_copy_put(struct ptlrpc_request *req)
1335 LASSERT(cfs_list_empty(&req->rq_replay_list));
1336 LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
1338 cfs_atomic_dec(&req->rq_export->exp_replay_count);
1339 class_export_rpc_dec(req->rq_export);
1340 ptlrpc_server_drop_request(req);
1343 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1345 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1346 struct obd_export *exp = req->rq_export;
1347 struct ptlrpc_request *reqiter;
1352 spin_lock(&exp->exp_lock);
1353 cfs_list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1355 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1362 /* We expect it with RESENT and REPLAY flags. */
1363 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1364 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1365 CERROR("invalid flags %x of resent replay\n",
1366 lustre_msg_get_flags(req->rq_reqmsg));
1368 cfs_list_add_tail(&req->rq_replay_list,
1369 &exp->exp_req_replay_queue);
1372 spin_unlock(&exp->exp_lock);
1376 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1378 LASSERT(!cfs_list_empty(&req->rq_replay_list));
1379 LASSERT(req->rq_export);
1381 spin_lock(&req->rq_export->exp_lock);
1382 cfs_list_del_init(&req->rq_replay_list);
1383 spin_unlock(&req->rq_export->exp_lock);
1387 static void target_finish_recovery(struct obd_device *obd)
1391 /* Only log a recovery message when recovery has occurred. */
1392 if (obd->obd_recovery_start) {
1393 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1394 obd->obd_recovery_start);
1395 LCONSOLE_INFO("%s: Recovery over after %d:%.02d, of %d clients "
1396 "%d recovered and %d %s evicted.\n", obd->obd_name,
1397 (int)elapsed_time / 60, (int)elapsed_time % 60,
1398 obd->obd_max_recoverable_clients,
1399 cfs_atomic_read(&obd->obd_connected_clients),
1400 obd->obd_stale_clients,
1401 obd->obd_stale_clients == 1 ? "was" : "were");
1404 ldlm_reprocess_all_ns(obd->obd_namespace);
1405 spin_lock(&obd->obd_recovery_task_lock);
1406 if (!cfs_list_empty(&obd->obd_req_replay_queue) ||
1407 !cfs_list_empty(&obd->obd_lock_replay_queue) ||
1408 !cfs_list_empty(&obd->obd_final_req_queue)) {
1409 CERROR("%s: Recovery queues ( %s%s%s) are not empty\n",
1411 cfs_list_empty(&obd->obd_req_replay_queue) ? "" : "req ",
1412 cfs_list_empty(&obd->obd_lock_replay_queue) ? \
1414 cfs_list_empty(&obd->obd_final_req_queue) ? \
1416 spin_unlock(&obd->obd_recovery_task_lock);
1419 spin_unlock(&obd->obd_recovery_task_lock);
1421 obd->obd_recovery_end = cfs_time_current_sec();
1423 /* When recovery finished, cleanup orphans on MDS and OST. */
1424 if (OBT(obd) && OBP(obd, postrecov)) {
1425 int rc = OBP(obd, postrecov)(obd);
1427 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1433 static void abort_req_replay_queue(struct obd_device *obd)
1435 struct ptlrpc_request *req, *n;
1436 cfs_list_t abort_list;
1438 CFS_INIT_LIST_HEAD(&abort_list);
1439 spin_lock(&obd->obd_recovery_task_lock);
1440 cfs_list_splice_init(&obd->obd_req_replay_queue, &abort_list);
1441 spin_unlock(&obd->obd_recovery_task_lock);
1442 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1443 DEBUG_REQ(D_WARNING, req, "aborted:");
1444 req->rq_status = -ENOTCONN;
1445 if (ptlrpc_error(req)) {
1446 DEBUG_REQ(D_ERROR, req,
1447 "failed abort_req_reply; skipping");
1449 target_exp_dequeue_req_replay(req);
1450 target_request_copy_put(req);
1454 static void abort_lock_replay_queue(struct obd_device *obd)
1456 struct ptlrpc_request *req, *n;
1457 cfs_list_t abort_list;
1459 CFS_INIT_LIST_HEAD(&abort_list);
1460 spin_lock(&obd->obd_recovery_task_lock);
1461 cfs_list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
1462 spin_unlock(&obd->obd_recovery_task_lock);
1463 cfs_list_for_each_entry_safe(req, n, &abort_list, rq_list){
1464 DEBUG_REQ(D_ERROR, req, "aborted:");
1465 req->rq_status = -ENOTCONN;
1466 if (ptlrpc_error(req)) {
1467 DEBUG_REQ(D_ERROR, req,
1468 "failed abort_lock_reply; skipping");
1470 target_request_copy_put(req);
1474 /* Called from a cleanup function if the device is being cleaned up
1475 forcefully. The exports should all have been disconnected already,
1476 the only thing left to do is
1477 - clear the recovery flags
1479 - free queued requests and replies, but don't send replies
1480 Because the obd_stopping flag is set, no new requests should be received.
1483 void target_cleanup_recovery(struct obd_device *obd)
1485 struct ptlrpc_request *req, *n;
1486 cfs_list_t clean_list;
1489 CFS_INIT_LIST_HEAD(&clean_list);
1490 spin_lock(&obd->obd_dev_lock);
1491 if (!obd->obd_recovering) {
1492 spin_unlock(&obd->obd_dev_lock);
1496 obd->obd_recovering = obd->obd_abort_recovery = 0;
1497 spin_unlock(&obd->obd_dev_lock);
1499 spin_lock(&obd->obd_recovery_task_lock);
1500 target_cancel_recovery_timer(obd);
1501 cfs_list_splice_init(&obd->obd_req_replay_queue, &clean_list);
1502 spin_unlock(&obd->obd_recovery_task_lock);
1504 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1505 LASSERT(req->rq_reply_state == 0);
1506 target_exp_dequeue_req_replay(req);
1507 target_request_copy_put(req);
1510 spin_lock(&obd->obd_recovery_task_lock);
1511 cfs_list_splice_init(&obd->obd_lock_replay_queue, &clean_list);
1512 cfs_list_splice_init(&obd->obd_final_req_queue, &clean_list);
1513 spin_unlock(&obd->obd_recovery_task_lock);
1515 cfs_list_for_each_entry_safe(req, n, &clean_list, rq_list){
1516 LASSERT(req->rq_reply_state == 0);
1517 target_request_copy_put(req);
1522 EXPORT_SYMBOL(target_cleanup_recovery);
1524 /* obd_recovery_task_lock should be held */
1525 void target_cancel_recovery_timer(struct obd_device *obd)
1527 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1528 cfs_timer_disarm(&obd->obd_recovery_timer);
1530 EXPORT_SYMBOL(target_cancel_recovery_timer);
1532 static void target_start_recovery_timer(struct obd_device *obd)
1534 if (obd->obd_recovery_start != 0)
1537 spin_lock(&obd->obd_dev_lock);
1538 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1539 spin_unlock(&obd->obd_dev_lock);
1543 LASSERT(obd->obd_recovery_timeout != 0);
1545 if (obd->obd_recovery_start != 0) {
1546 spin_unlock(&obd->obd_dev_lock);
1550 cfs_timer_arm(&obd->obd_recovery_timer,
1551 cfs_time_shift(obd->obd_recovery_timeout));
1552 obd->obd_recovery_start = cfs_time_current_sec();
1553 spin_unlock(&obd->obd_dev_lock);
1555 LCONSOLE_WARN("%s: Will be in recovery for at least %d:%.02d, "
1556 "or until %d client%s reconnect%s\n",
1558 obd->obd_recovery_timeout / 60,
1559 obd->obd_recovery_timeout % 60,
1560 obd->obd_max_recoverable_clients,
1561 (obd->obd_max_recoverable_clients == 1) ? "" : "s",
1562 (obd->obd_max_recoverable_clients == 1) ? "s": "");
1566 * extend recovery window.
1568 * if @extend is true, extend recovery window to have @drt remaining at least;
1569 * otherwise, make sure the recovery timeout value is not less than @drt.
1571 static void extend_recovery_timer(struct obd_device *obd, int drt, bool extend)
1575 cfs_duration_t left;
1578 spin_lock(&obd->obd_dev_lock);
1579 if (!obd->obd_recovering || obd->obd_abort_recovery) {
1580 spin_unlock(&obd->obd_dev_lock);
1583 LASSERT(obd->obd_recovery_start != 0);
1585 now = cfs_time_current_sec();
1586 to = obd->obd_recovery_timeout;
1587 end = obd->obd_recovery_start + to;
1588 left = cfs_time_sub(end, now);
1590 if (extend && (drt > left)) {
1592 } else if (!extend && (drt > to)) {
1594 /* reduce drt by already passed time */
1595 drt -= obd->obd_recovery_timeout - left;
1598 if (to > obd->obd_recovery_time_hard)
1599 to = obd->obd_recovery_time_hard;
1600 if (obd->obd_recovery_timeout < to ||
1601 obd->obd_recovery_timeout == obd->obd_recovery_time_hard) {
1602 obd->obd_recovery_timeout = to;
1603 cfs_timer_arm(&obd->obd_recovery_timer,
1604 cfs_time_shift(drt));
1606 spin_unlock(&obd->obd_dev_lock);
1608 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1609 obd->obd_name, (unsigned)drt);
1612 /* Reset the timer with each new client connection */
1614 * This timer is actually reconnect_timer, which is for making sure
1615 * the total recovery window is at least as big as my reconnect
1616 * attempt timing. So the initial recovery time_out will be set to
1617 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1618 * from client is bigger than this, then the recovery time_out will
1619 * be extended to make sure the client could be reconnected, in the
1620 * process, the timeout from the new client should be ignored.
1624 check_and_start_recovery_timer(struct obd_device *obd,
1625 struct ptlrpc_request *req,
1628 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1629 struct obd_device_target *obt = &obd->u.obt;
1630 struct lustre_sb_info *lsi;
1632 if (!new_client && service_time)
1633 /* Teach server about old server's estimates, as first guess
1634 * at how long new requests will take. */
1635 at_measured(&req->rq_rqbd->rqbd_svcpt->scp_at_estimate,
1638 target_start_recovery_timer(obd);
1640 /* Convert the service time to RPC timeout,
1641 * and reuse service_time to limit stack usage. */
1642 service_time = at_est2timeout(service_time);
1644 /* We expect other clients to timeout within service_time, then try
1645 * to reconnect, then try the failover server. The max delay between
1646 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL. */
1647 service_time += 2 * INITIAL_CONNECT_TIMEOUT;
1649 LASSERT(obt->obt_magic == OBT_MAGIC);
1650 lsi = s2lsi(obt->obt_sb);
1651 if (!(lsi->lsi_flags | LDD_F_IR_CAPABLE))
1652 service_time += 2 * (CONNECTION_SWITCH_MAX +
1653 CONNECTION_SWITCH_INC);
1654 if (service_time > obd->obd_recovery_timeout && !new_client)
1655 extend_recovery_timer(obd, service_time, false);
1658 /** Health checking routines */
1659 static inline int exp_connect_healthy(struct obd_export *exp)
1661 return (exp->exp_in_recovery);
1664 /** if export done req_replay or has replay in queue */
1665 static inline int exp_req_replay_healthy(struct obd_export *exp)
1667 return (!exp->exp_req_replay_needed ||
1668 cfs_atomic_read(&exp->exp_replay_count) > 0);
1670 /** if export done lock_replay or has replay in queue */
1671 static inline int exp_lock_replay_healthy(struct obd_export *exp)
1673 return (!exp->exp_lock_replay_needed ||
1674 cfs_atomic_read(&exp->exp_replay_count) > 0);
1677 static inline int exp_vbr_healthy(struct obd_export *exp)
1679 return (!exp->exp_vbr_failed);
1682 static inline int exp_finished(struct obd_export *exp)
1684 return (exp->exp_in_recovery && !exp->exp_lock_replay_needed);
1687 /** Checking routines for recovery */
1688 static int check_for_clients(struct obd_device *obd)
1690 unsigned int clnts = cfs_atomic_read(&obd->obd_connected_clients);
1692 if (obd->obd_abort_recovery || obd->obd_recovery_expired)
1694 LASSERT(clnts <= obd->obd_max_recoverable_clients);
1695 return (clnts + obd->obd_stale_clients ==
1696 obd->obd_max_recoverable_clients);
1699 static int check_for_next_transno(struct obd_device *obd)
1701 struct ptlrpc_request *req = NULL;
1702 int wake_up = 0, connected, completed, queue_len;
1703 __u64 next_transno, req_transno;
1706 spin_lock(&obd->obd_recovery_task_lock);
1707 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1708 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1709 struct ptlrpc_request, rq_list);
1710 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1715 connected = cfs_atomic_read(&obd->obd_connected_clients);
1716 completed = connected - cfs_atomic_read(&obd->obd_req_replay_clients);
1717 queue_len = obd->obd_requests_queued_for_recovery;
1718 next_transno = obd->obd_next_recovery_transno;
1720 CDEBUG(D_HA, "max: %d, connected: %d, completed: %d, queue_len: %d, "
1721 "req_transno: "LPU64", next_transno: "LPU64"\n",
1722 obd->obd_max_recoverable_clients, connected, completed,
1723 queue_len, req_transno, next_transno);
1725 if (obd->obd_abort_recovery) {
1726 CDEBUG(D_HA, "waking for aborted recovery\n");
1728 } else if (obd->obd_recovery_expired) {
1729 CDEBUG(D_HA, "waking for expired recovery\n");
1731 } else if (req_transno == next_transno) {
1732 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1734 } else if (queue_len > 0 &&
1735 queue_len == cfs_atomic_read(&obd->obd_req_replay_clients)) {
1737 /** handle gaps occured due to lost reply or VBR */
1738 LASSERTF(req_transno >= next_transno,
1739 "req_transno: "LPU64", next_transno: "LPU64"\n",
1740 req_transno, next_transno);
1741 if (req_transno > obd->obd_last_committed &&
1742 !obd->obd_version_recov)
1745 "%s: waking for gap in transno, VBR is %s (skip: "
1746 LPD64", ql: %d, comp: %d, conn: %d, next: "LPD64
1747 ", last_committed: "LPD64")\n",
1748 obd->obd_name, obd->obd_version_recov ? "ON" : "OFF",
1749 next_transno, queue_len, completed, connected,
1750 req_transno, obd->obd_last_committed);
1751 obd->obd_next_recovery_transno = req_transno;
1753 } else if (cfs_atomic_read(&obd->obd_req_replay_clients) == 0) {
1754 CDEBUG(D_HA, "waking for completed recovery\n");
1756 } else if (OBD_FAIL_CHECK(OBD_FAIL_MDS_RECOVERY_ACCEPTS_GAPS)) {
1757 CDEBUG(D_HA, "accepting transno gaps is explicitly allowed"
1758 " by fail_lock, waking up ("LPD64")\n", next_transno);
1759 obd->obd_next_recovery_transno = req_transno;
1762 spin_unlock(&obd->obd_recovery_task_lock);
1766 static int check_for_next_lock(struct obd_device *obd)
1770 spin_lock(&obd->obd_recovery_task_lock);
1771 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1772 CDEBUG(D_HA, "waking for next lock\n");
1774 } else if (cfs_atomic_read(&obd->obd_lock_replay_clients) == 0) {
1775 CDEBUG(D_HA, "waking for completed lock replay\n");
1777 } else if (obd->obd_abort_recovery) {
1778 CDEBUG(D_HA, "waking for aborted recovery\n");
1780 } else if (obd->obd_recovery_expired) {
1781 CDEBUG(D_HA, "waking for expired recovery\n");
1784 spin_unlock(&obd->obd_recovery_task_lock);
1790 * wait for recovery events,
1791 * check its status with help of check_routine
1792 * evict dead clients via health_check
1794 static int target_recovery_overseer(struct obd_device *obd,
1795 int (*check_routine)(struct obd_device *),
1796 int (*health_check)(struct obd_export *))
1799 cfs_wait_event(obd->obd_next_transno_waitq, check_routine(obd));
1800 if (obd->obd_abort_recovery) {
1801 CWARN("recovery is aborted, evict exports in recovery\n");
1802 /** evict exports which didn't finish recovery yet */
1803 class_disconnect_stale_exports(obd, exp_finished);
1805 } else if (obd->obd_recovery_expired) {
1806 obd->obd_recovery_expired = 0;
1807 /** If some clients died being recovered, evict them */
1808 LCONSOLE_WARN("%s: recovery is timed out, "
1809 "evict stale exports\n", obd->obd_name);
1810 /** evict cexports with no replay in queue, they are stalled */
1811 class_disconnect_stale_exports(obd, health_check);
1812 /** continue with VBR */
1813 spin_lock(&obd->obd_dev_lock);
1814 obd->obd_version_recov = 1;
1815 spin_unlock(&obd->obd_dev_lock);
1817 * reset timer, recovery will proceed with versions now,
1818 * timeout is set just to handle reconnection delays
1820 extend_recovery_timer(obd, RECONNECT_DELAY_MAX, true);
1821 /** Wait for recovery events again, after evicting bad clients */
1827 static struct ptlrpc_request *target_next_replay_req(struct obd_device *obd)
1829 struct ptlrpc_request *req = NULL;
1832 CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1833 obd->obd_next_recovery_transno);
1835 if (target_recovery_overseer(obd, check_for_next_transno,
1836 exp_req_replay_healthy)) {
1837 abort_req_replay_queue(obd);
1838 abort_lock_replay_queue(obd);
1841 spin_lock(&obd->obd_recovery_task_lock);
1842 if (!cfs_list_empty(&obd->obd_req_replay_queue)) {
1843 req = cfs_list_entry(obd->obd_req_replay_queue.next,
1844 struct ptlrpc_request, rq_list);
1845 cfs_list_del_init(&req->rq_list);
1846 obd->obd_requests_queued_for_recovery--;
1847 spin_unlock(&obd->obd_recovery_task_lock);
1849 spin_unlock(&obd->obd_recovery_task_lock);
1850 LASSERT(cfs_list_empty(&obd->obd_req_replay_queue));
1851 LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
1852 /** evict exports failed VBR */
1853 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1858 static struct ptlrpc_request *target_next_replay_lock(struct obd_device *obd)
1860 struct ptlrpc_request *req = NULL;
1862 CDEBUG(D_HA, "Waiting for lock\n");
1863 if (target_recovery_overseer(obd, check_for_next_lock,
1864 exp_lock_replay_healthy))
1865 abort_lock_replay_queue(obd);
1867 spin_lock(&obd->obd_recovery_task_lock);
1868 if (!cfs_list_empty(&obd->obd_lock_replay_queue)) {
1869 req = cfs_list_entry(obd->obd_lock_replay_queue.next,
1870 struct ptlrpc_request, rq_list);
1871 cfs_list_del_init(&req->rq_list);
1872 spin_unlock(&obd->obd_recovery_task_lock);
1874 spin_unlock(&obd->obd_recovery_task_lock);
1875 LASSERT(cfs_list_empty(&obd->obd_lock_replay_queue));
1876 LASSERT(cfs_atomic_read(&obd->obd_lock_replay_clients) == 0);
1877 /** evict exports failed VBR */
1878 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1883 static struct ptlrpc_request *target_next_final_ping(struct obd_device *obd)
1885 struct ptlrpc_request *req = NULL;
1887 spin_lock(&obd->obd_recovery_task_lock);
1888 if (!cfs_list_empty(&obd->obd_final_req_queue)) {
1889 req = cfs_list_entry(obd->obd_final_req_queue.next,
1890 struct ptlrpc_request, rq_list);
1891 cfs_list_del_init(&req->rq_list);
1892 spin_unlock(&obd->obd_recovery_task_lock);
1893 if (req->rq_export->exp_in_recovery) {
1894 spin_lock(&req->rq_export->exp_lock);
1895 req->rq_export->exp_in_recovery = 0;
1896 spin_unlock(&req->rq_export->exp_lock);
1899 spin_unlock(&obd->obd_recovery_task_lock);
1904 static int handle_recovery_req(struct ptlrpc_thread *thread,
1905 struct ptlrpc_request *req,
1906 svc_handler_t handler)
1912 * export can be evicted during recovery, no need to handle replays for
1913 * it after that, discard such request silently
1915 if (req->rq_export->exp_disconnected)
1916 GOTO(reqcopy_put, rc = 0);
1918 rc = lu_context_init(&req->rq_recov_session, LCT_SESSION);
1920 CERROR("Failure to initialize session: %d\n", rc);
1921 GOTO(reqcopy_put, rc);
1924 req->rq_recov_session.lc_thread = thread;
1925 lu_context_enter(&req->rq_recov_session);
1926 req->rq_svc_thread = thread;
1927 req->rq_svc_thread->t_env->le_ses = &req->rq_recov_session;
1929 /* thread context */
1930 lu_context_enter(&thread->t_env->le_ctx);
1932 lu_context_exit(&thread->t_env->le_ctx);
1934 lu_context_exit(&req->rq_recov_session);
1935 lu_context_fini(&req->rq_recov_session);
1936 /* don't reset timer for final stage */
1937 if (!exp_finished(req->rq_export)) {
1938 int to = obd_timeout;
1941 * Add request timeout to the recovery time so next request from
1942 * this client may come in recovery time
1945 struct ptlrpc_service_part *svcpt;
1947 svcpt = req->rq_rqbd->rqbd_svcpt;
1948 /* If the server sent early reply for this request,
1949 * the client will recalculate the timeout according to
1950 * current server estimate service time, so we will
1951 * use the maxium timeout here for waiting the client
1952 * sending the next req */
1953 to = max((int)at_est2timeout(
1954 at_get(&svcpt->scp_at_estimate)),
1955 (int)lustre_msg_get_timeout(req->rq_reqmsg));
1956 /* Add 2 net_latency, one for balance rq_deadline
1957 * (see ptl_send_rpc), one for resend the req to server,
1958 * Note: client will pack net_latency in replay req
1959 * (see ptlrpc_replay_req) */
1960 to += 2 * lustre_msg_get_service_time(req->rq_reqmsg);
1962 extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
1968 static int target_recovery_thread(void *arg)
1970 struct lu_target *lut = arg;
1971 struct obd_device *obd = lut->lut_obd;
1972 struct ptlrpc_request *req;
1973 struct target_recovery_data *trd = &obd->obd_recovery_data;
1974 unsigned long delta;
1975 unsigned long flags;
1977 struct ptlrpc_thread *thread = NULL;
1981 cfs_daemonize_ctxt("tgt_recov");
1983 SIGNAL_MASK_LOCK(current, flags);
1984 sigfillset(¤t->blocked);
1986 SIGNAL_MASK_UNLOCK(current, flags);
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 thread->t_data = NULL;
2009 thread->t_watchdog = NULL;
2011 CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
2013 trd->trd_processing_task = cfs_curproc_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 cfs_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 == cfs_curproc_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 cfs_atomic_read(&obd->obd_lock_replay_clients));
2056 while ((req = target_next_replay_lock(obd))) {
2057 LASSERT(trd->trd_processing_task == cfs_curproc_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 CDEBUG(D_INFO, "3: final stage - process recovery completion pings\n");
2071 /** Update server last boot epoch */
2072 tgt_boot_epoch_update(lut);
2073 /* We drop recoverying flag to forward all new requests
2074 * to regular mds_handle() since now */
2075 spin_lock(&obd->obd_dev_lock);
2076 obd->obd_recovering = obd->obd_abort_recovery = 0;
2077 spin_unlock(&obd->obd_dev_lock);
2078 spin_lock(&obd->obd_recovery_task_lock);
2079 target_cancel_recovery_timer(obd);
2080 spin_unlock(&obd->obd_recovery_task_lock);
2081 while ((req = target_next_final_ping(obd))) {
2082 LASSERT(trd->trd_processing_task == cfs_curproc_pid());
2083 DEBUG_REQ(D_HA, req, "processing final ping from %s: ",
2084 libcfs_nid2str(req->rq_peer.nid));
2085 handle_recovery_req(thread, req,
2086 trd->trd_recovery_handler);
2087 target_request_copy_put(req);
2090 delta = (jiffies - delta) / CFS_HZ;
2091 CDEBUG(D_INFO,"4: recovery completed in %lus - %d/%d reqs/locks\n",
2092 delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
2093 if (delta > OBD_RECOVERY_TIME_SOFT) {
2094 CWARN("too long recovery - read logs\n");
2095 libcfs_debug_dumplog();
2098 target_finish_recovery(obd);
2100 lu_context_fini(&env->le_ctx);
2101 trd->trd_processing_task = 0;
2102 complete(&trd->trd_finishing);
2104 OBD_FREE_PTR(thread);
2109 static int target_start_recovery_thread(struct lu_target *lut,
2110 svc_handler_t handler)
2112 struct obd_device *obd = lut->lut_obd;
2114 struct target_recovery_data *trd = &obd->obd_recovery_data;
2116 memset(trd, 0, sizeof(*trd));
2117 init_completion(&trd->trd_starting);
2118 init_completion(&trd->trd_finishing);
2119 trd->trd_recovery_handler = handler;
2121 if (cfs_create_thread(target_recovery_thread, lut, 0) > 0) {
2122 wait_for_completion(&trd->trd_starting);
2123 LASSERT(obd->obd_recovering != 0);
2130 void target_stop_recovery_thread(struct obd_device *obd)
2132 if (obd->obd_recovery_data.trd_processing_task > 0) {
2133 struct target_recovery_data *trd = &obd->obd_recovery_data;
2134 /** recovery can be done but postrecovery is not yet */
2135 spin_lock(&obd->obd_dev_lock);
2136 if (obd->obd_recovering) {
2137 CERROR("%s: Aborting recovery\n", obd->obd_name);
2138 obd->obd_abort_recovery = 1;
2139 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2141 spin_unlock(&obd->obd_dev_lock);
2142 wait_for_completion(&trd->trd_finishing);
2145 EXPORT_SYMBOL(target_stop_recovery_thread);
2147 void target_recovery_fini(struct obd_device *obd)
2149 class_disconnect_exports(obd);
2150 target_stop_recovery_thread(obd);
2151 target_cleanup_recovery(obd);
2153 EXPORT_SYMBOL(target_recovery_fini);
2155 static void target_recovery_expired(unsigned long castmeharder)
2157 struct obd_device *obd = (struct obd_device *)castmeharder;
2158 CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery"
2159 " after %lds (%d clients connected)\n",
2160 obd->obd_name, cfs_atomic_read(&obd->obd_lock_replay_clients),
2161 cfs_time_current_sec()- obd->obd_recovery_start,
2162 cfs_atomic_read(&obd->obd_connected_clients));
2164 obd->obd_recovery_expired = 1;
2165 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2168 void target_recovery_init(struct lu_target *lut, svc_handler_t handler)
2170 struct obd_device *obd = lut->lut_obd;
2171 if (obd->obd_max_recoverable_clients == 0) {
2172 /** Update server last boot epoch */
2173 tgt_boot_epoch_update(lut);
2177 CDEBUG(D_HA, "RECOVERY: service %s, %d recoverable clients, "
2178 "last_transno "LPU64"\n", obd->obd_name,
2179 obd->obd_max_recoverable_clients, obd->obd_last_committed);
2180 LASSERT(obd->obd_stopping == 0);
2181 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
2182 obd->obd_recovery_start = 0;
2183 obd->obd_recovery_end = 0;
2185 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
2186 target_start_recovery_thread(lut, handler);
2188 EXPORT_SYMBOL(target_recovery_init);
2190 #endif /* __KERNEL__ */
2192 static int target_process_req_flags(struct obd_device *obd,
2193 struct ptlrpc_request *req)
2195 struct obd_export *exp = req->rq_export;
2196 LASSERT(exp != NULL);
2197 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2198 /* client declares he's ready to replay locks */
2199 spin_lock(&exp->exp_lock);
2200 if (exp->exp_req_replay_needed) {
2201 exp->exp_req_replay_needed = 0;
2202 spin_unlock(&exp->exp_lock);
2204 LASSERT_ATOMIC_POS(&obd->obd_req_replay_clients);
2205 cfs_atomic_dec(&obd->obd_req_replay_clients);
2207 spin_unlock(&exp->exp_lock);
2210 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2211 /* client declares he's ready to complete recovery
2212 * so, we put the request on th final queue */
2213 spin_lock(&exp->exp_lock);
2214 if (exp->exp_lock_replay_needed) {
2215 exp->exp_lock_replay_needed = 0;
2216 spin_unlock(&exp->exp_lock);
2218 LASSERT_ATOMIC_POS(&obd->obd_lock_replay_clients);
2219 cfs_atomic_dec(&obd->obd_lock_replay_clients);
2221 spin_unlock(&exp->exp_lock);
2227 int target_queue_recovery_request(struct ptlrpc_request *req,
2228 struct obd_device *obd)
2232 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
2235 if (obd->obd_recovery_data.trd_processing_task == cfs_curproc_pid()) {
2236 /* Processing the queue right now, don't re-add. */
2240 target_process_req_flags(obd, req);
2242 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
2243 /* client declares he's ready to complete recovery
2244 * so, we put the request on th final queue */
2245 target_request_copy_get(req);
2246 DEBUG_REQ(D_HA, req, "queue final req");
2247 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2248 spin_lock(&obd->obd_recovery_task_lock);
2249 if (obd->obd_recovering) {
2250 cfs_list_add_tail(&req->rq_list,
2251 &obd->obd_final_req_queue);
2253 spin_unlock(&obd->obd_recovery_task_lock);
2254 target_request_copy_put(req);
2255 RETURN(obd->obd_stopping ? -ENOTCONN : 1);
2257 spin_unlock(&obd->obd_recovery_task_lock);
2260 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
2261 /* client declares he's ready to replay locks */
2262 target_request_copy_get(req);
2263 DEBUG_REQ(D_HA, req, "queue lock replay req");
2264 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2265 spin_lock(&obd->obd_recovery_task_lock);
2266 LASSERT(obd->obd_recovering);
2267 /* usually due to recovery abort */
2268 if (!req->rq_export->exp_in_recovery) {
2269 spin_unlock(&obd->obd_recovery_task_lock);
2270 target_request_copy_put(req);
2273 LASSERT(req->rq_export->exp_lock_replay_needed);
2274 cfs_list_add_tail(&req->rq_list, &obd->obd_lock_replay_queue);
2275 spin_unlock(&obd->obd_recovery_task_lock);
2279 /* CAVEAT EMPTOR: The incoming request message has been swabbed
2280 * (i.e. buflens etc are in my own byte order), but type-dependent
2281 * buffers (eg mdt_body, ost_body etc) have NOT been swabbed. */
2284 CFS_INIT_LIST_HEAD(&req->rq_list);
2285 DEBUG_REQ(D_HA, req, "not queueing");
2289 /* If we're processing the queue, we want don't want to queue this
2292 * Also, if this request has a transno less than the one we're waiting
2293 * for, we should process it now. It could (and currently always will)
2294 * be an open request for a descriptor that was opened some time ago.
2296 * Also, a resent, replayed request that has already been
2297 * handled will pass through here and be processed immediately.
2299 CDEBUG(D_HA, "Next recovery transno: "LPU64
2300 ", current: "LPU64", replaying\n",
2301 obd->obd_next_recovery_transno, transno);
2302 spin_lock(&obd->obd_recovery_task_lock);
2303 if (transno < obd->obd_next_recovery_transno) {
2304 /* Processing the queue right now, don't re-add. */
2305 LASSERT(cfs_list_empty(&req->rq_list));
2306 spin_unlock(&obd->obd_recovery_task_lock);
2309 spin_unlock(&obd->obd_recovery_task_lock);
2311 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))
2314 target_request_copy_get(req);
2315 if (!req->rq_export->exp_in_recovery) {
2316 target_request_copy_put(req);
2319 LASSERT(req->rq_export->exp_req_replay_needed);
2321 if (target_exp_enqueue_req_replay(req)) {
2322 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
2323 target_request_copy_put(req);
2328 spin_lock(&obd->obd_recovery_task_lock);
2329 LASSERT(obd->obd_recovering);
2330 cfs_list_for_each(tmp, &obd->obd_req_replay_queue) {
2331 struct ptlrpc_request *reqiter =
2332 cfs_list_entry(tmp, struct ptlrpc_request, rq_list);
2334 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
2335 cfs_list_add_tail(&req->rq_list, &reqiter->rq_list);
2340 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
2342 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
2343 "has been claimed by another client");
2344 spin_unlock(&obd->obd_recovery_task_lock);
2345 target_exp_dequeue_req_replay(req);
2346 target_request_copy_put(req);
2352 cfs_list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
2354 obd->obd_requests_queued_for_recovery++;
2355 spin_unlock(&obd->obd_recovery_task_lock);
2356 cfs_waitq_signal(&obd->obd_next_transno_waitq);
2359 EXPORT_SYMBOL(target_queue_recovery_request);
2361 int target_handle_ping(struct ptlrpc_request *req)
2363 obd_ping(req->rq_svc_thread->t_env, req->rq_export);
2364 return req_capsule_server_pack(&req->rq_pill);
2366 EXPORT_SYMBOL(target_handle_ping);
2368 void target_committed_to_req(struct ptlrpc_request *req)
2370 struct obd_export *exp = req->rq_export;
2372 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL)
2373 lustre_msg_set_last_committed(req->rq_repmsg,
2374 exp->exp_last_committed);
2376 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2377 "%d)", exp->exp_obd->obd_no_transno,
2378 req->rq_repmsg == NULL);
2380 CDEBUG(D_INFO, "last_committed "LPU64", transno "LPU64", xid "LPU64"\n",
2381 exp->exp_last_committed, req->rq_transno, req->rq_xid);
2383 EXPORT_SYMBOL(target_committed_to_req);
2385 #endif /* HAVE_SERVER_SUPPORT */
2388 * Packs current SLV and Limit into \a req.
2390 int target_pack_pool_reply(struct ptlrpc_request *req)
2392 struct obd_device *obd;
2395 /* Check that we still have all structures alive as this may
2396 * be some late RPC at shutdown time. */
2397 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
2398 !exp_connect_lru_resize(req->rq_export))) {
2399 lustre_msg_set_slv(req->rq_repmsg, 0);
2400 lustre_msg_set_limit(req->rq_repmsg, 0);
2404 /* OBD is alive here as export is alive, which we checked above. */
2405 obd = req->rq_export->exp_obd;
2407 read_lock(&obd->obd_pool_lock);
2408 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
2409 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
2410 read_unlock(&obd->obd_pool_lock);
2414 EXPORT_SYMBOL(target_pack_pool_reply);
2416 int target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id)
2418 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
2419 DEBUG_REQ(D_ERROR, req, "dropping reply");
2424 DEBUG_REQ(D_NET, req, "processing error (%d)", rc);
2425 req->rq_status = rc;
2426 return (ptlrpc_send_error(req, 1));
2428 DEBUG_REQ(D_NET, req, "sending reply");
2431 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
2434 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
2436 struct ptlrpc_service_part *svcpt;
2438 struct ptlrpc_reply_state *rs;
2439 struct obd_export *exp;
2442 if (req->rq_no_reply) {
2447 svcpt = req->rq_rqbd->rqbd_svcpt;
2448 rs = req->rq_reply_state;
2449 if (rs == NULL || !rs->rs_difficult) {
2451 target_send_reply_msg (req, rc, fail_id);
2456 /* must be an export if locks saved */
2457 LASSERT (req->rq_export != NULL);
2458 /* req/reply consistent */
2459 LASSERT(rs->rs_svcpt == svcpt);
2462 LASSERT (!rs->rs_scheduled);
2463 LASSERT (!rs->rs_scheduled_ever);
2464 LASSERT (!rs->rs_handled);
2465 LASSERT (!rs->rs_on_net);
2466 LASSERT (rs->rs_export == NULL);
2467 LASSERT (cfs_list_empty(&rs->rs_obd_list));
2468 LASSERT (cfs_list_empty(&rs->rs_exp_list));
2470 exp = class_export_get (req->rq_export);
2472 /* disable reply scheduling while I'm setting up */
2473 rs->rs_scheduled = 1;
2475 rs->rs_xid = req->rq_xid;
2476 rs->rs_transno = req->rq_transno;
2477 rs->rs_export = exp;
2478 rs->rs_opc = lustre_msg_get_opc(req->rq_reqmsg);
2480 spin_lock(&exp->exp_uncommitted_replies_lock);
2481 CDEBUG(D_NET, "rs transno = "LPU64", last committed = "LPU64"\n",
2482 rs->rs_transno, exp->exp_last_committed);
2483 if (rs->rs_transno > exp->exp_last_committed) {
2484 /* not committed already */
2485 cfs_list_add_tail(&rs->rs_obd_list,
2486 &exp->exp_uncommitted_replies);
2488 spin_unlock(&exp->exp_uncommitted_replies_lock);
2490 spin_lock(&exp->exp_lock);
2491 cfs_list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies);
2492 spin_unlock(&exp->exp_lock);
2494 netrc = target_send_reply_msg(req, rc, fail_id);
2496 spin_lock(&svcpt->scp_rep_lock);
2498 cfs_atomic_inc(&svcpt->scp_nreps_difficult);
2501 /* error sending: reply is off the net. Also we need +1
2502 * reply ref until ptlrpc_handle_rs() is done
2503 * with the reply state (if the send was successful, there
2504 * would have been +1 ref for the net, which
2505 * reply_out_callback leaves alone) */
2507 ptlrpc_rs_addref(rs);
2510 spin_lock(&rs->rs_lock);
2511 if (rs->rs_transno <= exp->exp_last_committed ||
2512 (!rs->rs_on_net && !rs->rs_no_ack) ||
2513 cfs_list_empty(&rs->rs_exp_list) || /* completed already */
2514 cfs_list_empty(&rs->rs_obd_list)) {
2515 CDEBUG(D_HA, "Schedule reply immediately\n");
2516 ptlrpc_dispatch_difficult_reply(rs);
2518 cfs_list_add(&rs->rs_list, &svcpt->scp_rep_active);
2519 rs->rs_scheduled = 0; /* allow notifier to schedule */
2521 spin_unlock(&rs->rs_lock);
2522 spin_unlock(&svcpt->scp_rep_lock);
2525 EXPORT_SYMBOL(target_send_reply);
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)
2550 case ELDLM_LOCK_CHANGED:
2553 case ELDLM_LOCK_ABORTED:
2556 case ELDLM_LOCK_REPLACED:
2559 case ELDLM_NO_LOCK_DATA:
2562 case ELDLM_NAMESPACE_EXISTS:
2565 case ELDLM_BAD_NAMESPACE:
2569 if (((int)error) < 0) /* cast to signed type */
2570 result = error; /* as ldlm_error_t can be unsigned */
2572 CERROR("Invalid DLM result code: %d\n", error);
2578 EXPORT_SYMBOL(ldlm_error2errno);
2581 * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
2583 ldlm_error_t ldlm_errno2error(int err_no)
2592 error = ELDLM_LOCK_CHANGED;
2595 error = ELDLM_LOCK_ABORTED;
2598 error = ELDLM_LOCK_REPLACED;
2601 error = ELDLM_NO_LOCK_DATA;
2604 error = ELDLM_NAMESPACE_EXISTS;
2607 error = ELDLM_BAD_NAMESPACE;
2614 EXPORT_SYMBOL(ldlm_errno2error);
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 (!cfs_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 cfs_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 char *bulk2type(struct ptlrpc_bulk_desc *desc)
2645 return desc->bd_type == BULK_GET_SINK ? "GET" : "PUT";
2648 int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc,
2649 struct l_wait_info *lwi)
2651 struct ptlrpc_request *req = desc->bd_req;
2655 /* If there is eviction in progress, wait for it to finish. */
2656 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
2657 *lwi = LWI_INTR(NULL, NULL);
2658 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
2659 !cfs_atomic_read(&exp->exp_obd->
2660 obd_evict_inprogress),
2664 /* Check if client was evicted or tried to reconnect already. */
2665 if (exp->exp_failed || exp->exp_abort_active_req) {
2668 if (desc->bd_type == BULK_PUT_SINK)
2669 rc = sptlrpc_svc_wrap_bulk(req, desc);
2671 rc = ptlrpc_start_bulk_transfer(desc);
2674 if (rc == 0 && OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
2675 ptlrpc_abort_bulk(desc);
2676 } else if (rc == 0) {
2677 time_t start = cfs_time_current_sec();
2679 long timeoutl = req->rq_deadline - cfs_time_current_sec();
2680 cfs_duration_t timeout = timeoutl <= 0 ?
2681 CFS_TICK : cfs_time_seconds(timeoutl);
2682 *lwi = LWI_TIMEOUT_INTERVAL(timeout,
2683 cfs_time_seconds(1),
2684 target_bulk_timeout,
2686 rc = l_wait_event(desc->bd_waitq,
2687 !ptlrpc_server_bulk_active(desc) ||
2689 exp->exp_abort_active_req,
2691 LASSERT(rc == 0 || rc == -ETIMEDOUT);
2692 /* Wait again if we changed deadline. */
2693 } while ((rc == -ETIMEDOUT) &&
2694 (req->rq_deadline > cfs_time_current_sec()));
2696 if (rc == -ETIMEDOUT) {
2697 DEBUG_REQ(D_ERROR, req,
2698 "timeout on bulk %s after %ld%+lds",
2700 req->rq_deadline - start,
2701 cfs_time_current_sec() -
2703 ptlrpc_abort_bulk(desc);
2704 } else if (exp->exp_failed) {
2705 DEBUG_REQ(D_ERROR, req, "Eviction on bulk %s",
2708 ptlrpc_abort_bulk(desc);
2709 } else if (exp->exp_abort_active_req) {
2710 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk %s",
2712 /* We don't reply anyway. */
2714 ptlrpc_abort_bulk(desc);
2715 } else if (desc->bd_failure ||
2716 desc->bd_nob_transferred != desc->bd_nob) {
2717 DEBUG_REQ(D_ERROR, req, "%s bulk %s %d(%d)",
2719 "network error on" : "truncated",
2721 desc->bd_nob_transferred,
2723 /* XXX Should this be a different errno? */
2725 } else if (desc->bd_type == BULK_GET_SINK) {
2726 rc = sptlrpc_svc_unwrap_bulk(req, desc);
2729 DEBUG_REQ(D_ERROR, req, "bulk %s failed: rc %d",
2730 bulk2type(desc), rc);
2735 EXPORT_SYMBOL(target_bulk_io);
2737 #endif /* HAVE_SERVER_SUPPORT */