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 <libcfs/libcfs.h>
48 #include <obd_class.h>
49 #include <lustre_dlm.h>
50 #include <lustre_net.h>
51 #include <lustre_sec.h>
52 #include "ldlm_internal.h"
54 /* @priority: If non-zero, move the selected connection to the list head.
55 * @create: If zero, only search in existing connections.
57 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
58 int priority, int create)
60 struct ptlrpc_connection *ptlrpc_conn;
61 struct obd_import_conn *imp_conn = NULL, *item;
65 if (!create && !priority) {
66 CDEBUG(D_HA, "Nothing to do\n");
70 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
72 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
77 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
79 GOTO(out_put, rc = -ENOMEM);
83 spin_lock(&imp->imp_lock);
84 list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
85 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
87 list_del(&item->oic_item);
88 list_add(&item->oic_item,
90 item->oic_last_attempt = 0;
92 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
93 imp, imp->imp_obd->obd_name, uuid->uuid,
94 (priority ? ", moved to head" : ""));
95 spin_unlock(&imp->imp_lock);
96 GOTO(out_free, rc = 0);
99 /* No existing import connection found for \a uuid. */
101 imp_conn->oic_conn = ptlrpc_conn;
102 imp_conn->oic_uuid = *uuid;
103 imp_conn->oic_last_attempt = 0;
105 list_add(&imp_conn->oic_item, &imp->imp_conn_list);
107 list_add_tail(&imp_conn->oic_item,
108 &imp->imp_conn_list);
109 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
110 imp, imp->imp_obd->obd_name, uuid->uuid,
111 (priority ? "head" : "tail"));
113 spin_unlock(&imp->imp_lock);
114 GOTO(out_free, rc = -ENOENT);
117 spin_unlock(&imp->imp_lock);
121 OBD_FREE(imp_conn, sizeof(*imp_conn));
123 ptlrpc_connection_put(ptlrpc_conn);
127 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
129 return import_set_conn(imp, uuid, 1, 0);
132 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
135 return import_set_conn(imp, uuid, priority, 1);
137 EXPORT_SYMBOL(client_import_add_conn);
139 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
141 struct obd_import_conn *imp_conn;
142 struct obd_export *dlmexp;
146 spin_lock(&imp->imp_lock);
147 if (list_empty(&imp->imp_conn_list)) {
148 LASSERT(!imp->imp_connection);
152 list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
153 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
155 LASSERT(imp_conn->oic_conn);
157 if (imp_conn == imp->imp_conn_current) {
158 LASSERT(imp_conn->oic_conn == imp->imp_connection);
160 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
161 imp->imp_state != LUSTRE_IMP_DISCON) {
162 CERROR("can't remove current connection\n");
163 GOTO(out, rc = -EBUSY);
166 ptlrpc_connection_put(imp->imp_connection);
167 imp->imp_connection = NULL;
169 dlmexp = class_conn2export(&imp->imp_dlm_handle);
170 if (dlmexp && dlmexp->exp_connection) {
171 LASSERT(dlmexp->exp_connection ==
173 ptlrpc_connection_put(dlmexp->exp_connection);
174 dlmexp->exp_connection = NULL;
178 list_del(&imp_conn->oic_item);
179 ptlrpc_connection_put(imp_conn->oic_conn);
180 OBD_FREE(imp_conn, sizeof(*imp_conn));
181 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
182 imp, imp->imp_obd->obd_name, uuid->uuid);
187 spin_unlock(&imp->imp_lock);
189 CERROR("connection %s not found\n", uuid->uuid);
192 EXPORT_SYMBOL(client_import_del_conn);
195 * Find conn UUID by peer NID. \a peer is a server NID. This function is used
196 * to find a conn uuid of \a imp which can reach \a peer.
198 int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer,
199 struct obd_uuid *uuid)
201 struct obd_import_conn *conn;
205 spin_lock(&imp->imp_lock);
206 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
207 /* Check if conn UUID does have this peer NID. */
208 if (class_check_uuid(&conn->oic_uuid, peer)) {
209 *uuid = conn->oic_uuid;
214 spin_unlock(&imp->imp_lock);
217 EXPORT_SYMBOL(client_import_find_conn);
219 void client_destroy_import(struct obd_import *imp)
221 /* Drop security policy instance after all RPCs have finished/aborted
222 * to let all busy contexts be released. */
223 class_import_get(imp);
224 class_destroy_import(imp);
225 sptlrpc_import_sec_put(imp);
226 class_import_put(imp);
228 EXPORT_SYMBOL(client_destroy_import);
231 * Check whether or not the OSC is on MDT.
234 * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID
236 * setup 0:{fsname}-OSTxxxx-osc 1:lustre-OST0000_UUID 2:NID
239 static int osc_on_mdt(char *obdname)
243 ptr = strrchr(obdname, '-');
247 if (strncmp(ptr + 1, "MDT", 3) == 0)
253 /* Configure an RPC client OBD device.
258 * 3 - inactive-on-startup
260 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
262 struct client_obd *cli = &obddev->u.cli;
263 struct obd_import *imp;
264 struct obd_uuid server_uuid;
265 int rq_portal, rp_portal, connect_op;
266 char *name = obddev->obd_type->typ_name;
267 ldlm_ns_type_t ns_type = LDLM_NS_TYPE_UNKNOWN;
271 /* In a more perfect world, we would hang a ptlrpc_client off of
272 * obd_type and just use the values from there. */
273 if (!strcmp(name, LUSTRE_OSC_NAME)) {
274 rq_portal = OST_REQUEST_PORTAL;
275 rp_portal = OSC_REPLY_PORTAL;
276 connect_op = OST_CONNECT;
277 cli->cl_sp_me = LUSTRE_SP_CLI;
278 cli->cl_sp_to = LUSTRE_SP_OST;
279 ns_type = LDLM_NS_TYPE_OSC;
280 } else if (!strcmp(name, LUSTRE_MDC_NAME) ||
281 !strcmp(name, LUSTRE_LWP_NAME)) {
282 rq_portal = MDS_REQUEST_PORTAL;
283 rp_portal = MDC_REPLY_PORTAL;
284 connect_op = MDS_CONNECT;
285 cli->cl_sp_me = LUSTRE_SP_CLI;
286 cli->cl_sp_to = LUSTRE_SP_MDT;
287 ns_type = LDLM_NS_TYPE_MDC;
288 } else if (!strcmp(name, LUSTRE_OSP_NAME)) {
289 if (strstr(lustre_cfg_buf(lcfg, 1), "OST") == NULL) {
290 /* OSP_on_MDT for other MDTs */
291 connect_op = MDS_CONNECT;
292 cli->cl_sp_to = LUSTRE_SP_MDT;
293 ns_type = LDLM_NS_TYPE_MDC;
294 rq_portal = OUT_PORTAL;
296 /* OSP on MDT for OST */
297 connect_op = OST_CONNECT;
298 cli->cl_sp_to = LUSTRE_SP_OST;
299 ns_type = LDLM_NS_TYPE_OSC;
300 rq_portal = OST_REQUEST_PORTAL;
302 rp_portal = OSC_REPLY_PORTAL;
303 cli->cl_sp_me = LUSTRE_SP_CLI;
304 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
305 rq_portal = MGS_REQUEST_PORTAL;
306 rp_portal = MGC_REPLY_PORTAL;
307 connect_op = MGS_CONNECT;
308 cli->cl_sp_me = LUSTRE_SP_MGC;
309 cli->cl_sp_to = LUSTRE_SP_MGS;
310 cli->cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_INVALID;
311 ns_type = LDLM_NS_TYPE_MGC;
313 CERROR("unknown client OBD type \"%s\", can't setup\n",
318 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
319 CERROR("requires a TARGET UUID\n");
323 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
324 CERROR("client UUID must be less than 38 characters\n");
328 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
329 CERROR("setup requires a SERVER UUID\n");
333 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
334 CERROR("target UUID must be less than 38 characters\n");
338 init_rwsem(&cli->cl_sem);
339 mutex_init(&cli->cl_mgc_mutex);
340 cli->cl_conn_count = 0;
341 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
342 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
343 sizeof(server_uuid)));
345 cli->cl_dirty_pages = 0;
346 cli->cl_avail_grant = 0;
347 /* FIXME: Should limit this for the sum of all cl_dirty_max_pages. */
348 /* cl_dirty_max_pages may be changed at connect time in
349 * ptlrpc_connect_interpret(). */
350 client_adjust_max_dirty(cli);
351 INIT_LIST_HEAD(&cli->cl_cache_waiters);
352 INIT_LIST_HEAD(&cli->cl_loi_ready_list);
353 INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
354 INIT_LIST_HEAD(&cli->cl_loi_write_list);
355 INIT_LIST_HEAD(&cli->cl_loi_read_list);
356 spin_lock_init(&cli->cl_loi_list_lock);
357 atomic_set(&cli->cl_pending_w_pages, 0);
358 atomic_set(&cli->cl_pending_r_pages, 0);
359 cli->cl_r_in_flight = 0;
360 cli->cl_w_in_flight = 0;
362 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
363 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
364 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
365 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
366 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
367 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
370 INIT_LIST_HEAD(&cli->cl_lru_osc);
371 atomic_set(&cli->cl_lru_shrinkers, 0);
372 atomic_long_set(&cli->cl_lru_busy, 0);
373 atomic_long_set(&cli->cl_lru_in_list, 0);
374 INIT_LIST_HEAD(&cli->cl_lru_list);
375 spin_lock_init(&cli->cl_lru_list_lock);
376 atomic_long_set(&cli->cl_unstable_count, 0);
378 init_waitqueue_head(&cli->cl_destroy_waitq);
379 atomic_set(&cli->cl_destroy_in_flight, 0);
380 #ifdef ENABLE_CHECKSUM
381 /* Turn on checksumming by default. */
382 cli->cl_checksum = 1;
384 * The supported checksum types will be worked out at connect time
385 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
388 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
390 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
392 /* This value may be reduced at connect time in
393 * ptlrpc_connect_interpret() . We initialize it to only
394 * 1MB until we know what the performance looks like.
395 * In the future this should likely be increased. LU-1431 */
396 cli->cl_max_pages_per_rpc = min_t(int, PTLRPC_MAX_BRW_PAGES,
397 LNET_MTU >> PAGE_CACHE_SHIFT);
399 /* set cl_chunkbits default value to PAGE_CACHE_SHIFT,
400 * it will be updated at OSC connection time. */
401 cli->cl_chunkbits = PAGE_CACHE_SHIFT;
403 if (!strcmp(name, LUSTRE_MDC_NAME)) {
404 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT;
405 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 128 /* MB */) {
406 cli->cl_max_rpcs_in_flight = 2;
407 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 256 /* MB */) {
408 cli->cl_max_rpcs_in_flight = 3;
409 } else if (totalram_pages >> (20 - PAGE_CACHE_SHIFT) <= 512 /* MB */) {
410 cli->cl_max_rpcs_in_flight = 4;
412 if (osc_on_mdt(obddev->obd_name))
413 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_MAX;
415 cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT;
419 CERROR("ldlm_get_ref failed: %d\n", rc);
423 ptlrpc_init_client(rq_portal, rp_portal, name,
424 &obddev->obd_ldlm_client);
426 imp = class_new_import(obddev);
428 GOTO(err_ldlm, rc = -ENOENT);
429 imp->imp_client = &obddev->obd_ldlm_client;
430 imp->imp_connect_op = connect_op;
431 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
432 LUSTRE_CFG_BUFLEN(lcfg, 1));
433 class_import_put(imp);
435 rc = client_import_add_conn(imp, &server_uuid, 1);
437 CERROR("can't add initial connection\n");
438 GOTO(err_import, rc);
441 cli->cl_import = imp;
442 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
443 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
444 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
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);
467 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
472 class_destroy_import(imp);
479 EXPORT_SYMBOL(client_obd_setup);
481 int client_obd_cleanup(struct obd_device *obddev)
485 ldlm_namespace_free_post(obddev->obd_namespace);
486 obddev->obd_namespace = NULL;
488 obd_cleanup_client_import(obddev);
489 LASSERT(obddev->u.cli.cl_import == NULL);
494 EXPORT_SYMBOL(client_obd_cleanup);
496 /* ->o_connect() method for client side (OSC and MDC and MGC) */
497 int client_connect_import(const struct lu_env *env,
498 struct obd_export **exp,
499 struct obd_device *obd, struct obd_uuid *cluuid,
500 struct obd_connect_data *data, void *localdata)
502 struct client_obd *cli = &obd->u.cli;
503 struct obd_import *imp = cli->cl_import;
504 struct obd_connect_data *ocd;
505 struct lustre_handle conn = { 0 };
510 down_write(&cli->cl_sem);
511 if (cli->cl_conn_count > 0)
512 GOTO(out_sem, rc = -EALREADY);
514 rc = class_connect(&conn, obd, cluuid);
518 cli->cl_conn_count++;
519 *exp = class_conn2export(&conn);
521 LASSERT(obd->obd_namespace);
523 imp->imp_dlm_handle = conn;
524 rc = ptlrpc_init_import(imp);
528 ocd = &imp->imp_connect_data;
531 imp->imp_connect_flags_orig = data->ocd_connect_flags;
534 rc = ptlrpc_connect_import(imp);
536 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
539 LASSERT(*exp != NULL && (*exp)->exp_connection);
542 LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
543 ocd->ocd_connect_flags, "old "LPX64", new "LPX64"\n",
544 data->ocd_connect_flags, ocd->ocd_connect_flags);
545 data->ocd_connect_flags = ocd->ocd_connect_flags;
548 ptlrpc_pinger_add_import(imp);
554 cli->cl_conn_count--;
555 class_disconnect(*exp);
559 up_write(&cli->cl_sem);
563 EXPORT_SYMBOL(client_connect_import);
565 int client_disconnect_export(struct obd_export *exp)
567 struct obd_device *obd = class_exp2obd(exp);
568 struct client_obd *cli;
569 struct obd_import *imp;
574 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
575 exp, exp ? exp->exp_handle.h_cookie : -1);
580 imp = cli->cl_import;
582 down_write(&cli->cl_sem);
583 CDEBUG(D_INFO, "disconnect %s - %zu\n", obd->obd_name,
586 if (cli->cl_conn_count == 0) {
587 CERROR("disconnecting disconnected device (%s)\n",
589 GOTO(out_disconnect, rc = -EINVAL);
592 cli->cl_conn_count--;
593 if (cli->cl_conn_count != 0)
594 GOTO(out_disconnect, rc = 0);
596 /* Mark import deactivated now, so we don't try to reconnect if any
597 * of the cleanup RPCs fails (e.g. LDLM cancel, etc). We don't
598 * fully deactivate the import, or that would drop all requests. */
599 spin_lock(&imp->imp_lock);
600 imp->imp_deactive = 1;
601 spin_unlock(&imp->imp_lock);
603 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
604 * delete it regardless. (It's safe to delete an import that was
606 (void)ptlrpc_pinger_del_import(imp);
608 if (obd->obd_namespace != NULL) {
609 /* obd_force == local only */
610 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
611 obd->obd_force ? LCF_LOCAL : 0, NULL);
612 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force);
615 /* There's no need to hold sem while disconnecting an import,
616 * and it may actually cause deadlock in GSS. */
617 up_write(&cli->cl_sem);
618 rc = ptlrpc_disconnect_import(imp, 0);
619 down_write(&cli->cl_sem);
621 ptlrpc_invalidate_import(imp);
626 /* Use server style - class_disconnect should be always called for
628 err = class_disconnect(exp);
632 up_write(&cli->cl_sem);
636 EXPORT_SYMBOL(client_disconnect_export);
638 #ifdef HAVE_SERVER_SUPPORT
639 int server_disconnect_export(struct obd_export *exp)
644 /* Disconnect early so that clients can't keep using export. */
645 rc = class_disconnect(exp);
646 /* Close import to avoid sending any requests. */
647 if (exp->exp_imp_reverse)
648 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
650 if (exp->exp_obd->obd_namespace != NULL)
651 ldlm_cancel_locks_for_export(exp);
653 /* complete all outstanding replies */
654 spin_lock(&exp->exp_lock);
655 while (!list_empty(&exp->exp_outstanding_replies)) {
656 struct ptlrpc_reply_state *rs =
657 list_entry(exp->exp_outstanding_replies.next,
658 struct ptlrpc_reply_state, rs_exp_list);
659 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
661 spin_lock(&svcpt->scp_rep_lock);
663 list_del_init(&rs->rs_exp_list);
664 spin_lock(&rs->rs_lock);
665 ptlrpc_schedule_difficult_reply(rs);
666 spin_unlock(&rs->rs_lock);
668 spin_unlock(&svcpt->scp_rep_lock);
670 spin_unlock(&exp->exp_lock);
674 EXPORT_SYMBOL(server_disconnect_export);
676 /* --------------------------------------------------------------------------
677 * from old lib/target.c
678 * -------------------------------------------------------------------------- */
680 static int target_handle_reconnect(struct lustre_handle *conn,
681 struct obd_export *exp,
682 struct obd_uuid *cluuid)
686 if (exp->exp_connection && exp->exp_imp_reverse) {
687 struct lustre_handle *hdl;
688 struct obd_device *target;
690 hdl = &exp->exp_imp_reverse->imp_remote_handle;
691 target = exp->exp_obd;
693 /* Might be a re-connect after a partition. */
694 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
695 if (target->obd_recovering) {
696 int timeout = cfs_duration_sec(cfs_time_sub(
698 &target->obd_recovery_timer),
699 cfs_time_current()));
701 LCONSOLE_WARN("%s: Client %s (at %s) reconnect"
702 "ing, waiting for %d clients in recov"
703 "ery for %d:%.02d\n", target->obd_name,
704 obd_uuid2str(&exp->exp_client_uuid),
705 obd_export_nid2str(exp),
706 target->obd_max_recoverable_clients,
707 timeout / 60, timeout % 60);
709 LCONSOLE_WARN("%s: Client %s (at %s) "
710 "reconnecting\n", target->obd_name,
711 obd_uuid2str(&exp->exp_client_uuid),
712 obd_export_nid2str(exp));
715 conn->cookie = exp->exp_handle.h_cookie;
716 /* target_handle_connect() treats EALREADY and
717 * -EALREADY differently. EALREADY means we are
718 * doing a valid reconnect from the same client. */
721 LCONSOLE_WARN("%s: already connected client %s (at %s) "
722 "with handle "LPX64". Rejecting client "
723 "with the same UUID trying to reconnect "
724 "with handle "LPX64"\n", target->obd_name,
725 obd_uuid2str(&exp->exp_client_uuid),
726 obd_export_nid2str(exp),
727 hdl->cookie, conn->cookie);
728 memset(conn, 0, sizeof *conn);
729 /* target_handle_connect() treats EALREADY and
730 * -EALREADY differently. -EALREADY is an error
731 * (same UUID, different handle). */
736 conn->cookie = exp->exp_handle.h_cookie;
737 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
738 cluuid->uuid, exp, conn->cookie);
742 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
745 struct obd_export *exp = cb_data;
747 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
748 obd->obd_name, exp->exp_client_uuid.uuid);
750 spin_lock(&exp->exp_lock);
751 exp->exp_need_sync = 0;
752 spin_unlock(&exp->exp_lock);
753 class_export_cb_put(exp);
755 EXPORT_SYMBOL(target_client_add_cb);
758 check_and_start_recovery_timer(struct obd_device *obd,
759 struct ptlrpc_request *req, int new_client);
761 int target_handle_connect(struct ptlrpc_request *req)
763 struct obd_device *target = NULL, *targref = NULL;
764 struct obd_export *export = NULL;
765 struct obd_import *revimp;
766 struct obd_import *tmp_imp = NULL;
767 struct lustre_handle conn;
768 struct lustre_handle *tmp;
769 struct obd_uuid tgtuuid;
770 struct obd_uuid cluuid;
771 struct obd_uuid remote_uuid;
776 bool mds_conn = false, lw_client = false;
777 struct obd_connect_data *data, *tmpdata;
779 lnet_nid_t *client_nid = NULL;
782 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
784 str = req_capsule_client_get(&req->rq_pill, &RMF_TGTUUID);
786 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
787 GOTO(out, rc = -EINVAL);
790 obd_str2uuid(&tgtuuid, str);
791 target = class_uuid2obd(&tgtuuid);
793 target = class_name2obd(str);
796 deuuidify(str, NULL, &target_start, &target_len);
797 LCONSOLE_ERROR_MSG(0x137, "%s: not available for connect "
798 "from %s (no target). If you are running "
799 "an HA pair check that the target is "
800 "mounted on the other server.\n", str,
801 libcfs_nid2str(req->rq_peer.nid));
802 GOTO(out, rc = -ENODEV);
805 spin_lock(&target->obd_dev_lock);
806 if (target->obd_stopping || !target->obd_set_up) {
807 spin_unlock(&target->obd_dev_lock);
809 deuuidify(str, NULL, &target_start, &target_len);
810 LCONSOLE_INFO("%.*s: Not available for connect from %s (%s)\n",
811 target_len, target_start,
812 libcfs_nid2str(req->rq_peer.nid),
813 (target->obd_stopping ?
814 "stopping" : "not set up"));
815 GOTO(out, rc = -ENODEV);
818 if (target->obd_no_conn) {
819 spin_unlock(&target->obd_dev_lock);
821 CDEBUG(D_INFO, "%s: Temporarily refusing client connection "
822 "from %s\n", target->obd_name,
823 libcfs_nid2str(req->rq_peer.nid));
824 GOTO(out, rc = -EAGAIN);
827 /* Make sure the target isn't cleaned up while we're here. Yes,
828 * there's still a race between the above check and our incref here.
829 * Really, class_uuid2obd should take the ref. */
830 targref = class_incref(target, __FUNCTION__, current);
832 target->obd_conn_inprogress++;
833 spin_unlock(&target->obd_dev_lock);
835 str = req_capsule_client_get(&req->rq_pill, &RMF_CLUUID);
837 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
838 GOTO(out, rc = -EINVAL);
841 obd_str2uuid(&cluuid, str);
843 /* XXX Extract a nettype and format accordingly. */
844 switch (sizeof(lnet_nid_t)) {
845 /* NB the casts only avoid compiler warnings. */
847 snprintf(remote_uuid.uuid, sizeof remote_uuid,
848 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
851 snprintf(remote_uuid.uuid, sizeof remote_uuid,
852 "NET_%x_UUID", (__u32)req->rq_peer.nid);
858 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
860 GOTO(out, rc = -EPROTO);
864 size = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
866 data = req_capsule_client_get(&req->rq_pill, &RMF_CONNECT_DATA);
868 GOTO(out, rc = -EPROTO);
870 rc = req_capsule_server_pack(&req->rq_pill);
874 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
875 if (data->ocd_version < LUSTRE_VERSION_CODE -
876 LUSTRE_VERSION_ALLOWED_OFFSET ||
877 data->ocd_version > LUSTRE_VERSION_CODE +
878 LUSTRE_VERSION_ALLOWED_OFFSET) {
879 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
880 "libclient connection attempt",
881 data->ocd_version < LUSTRE_VERSION_CODE ?
883 OBD_OCD_VERSION_MAJOR(data->ocd_version),
884 OBD_OCD_VERSION_MINOR(data->ocd_version),
885 OBD_OCD_VERSION_PATCH(data->ocd_version),
886 OBD_OCD_VERSION_FIX(data->ocd_version));
887 data = req_capsule_server_sized_get(&req->rq_pill,
889 offsetof(typeof(*data), ocd_version) +
890 sizeof(data->ocd_version));
892 data->ocd_connect_flags = OBD_CONNECT_VERSION;
893 data->ocd_version = LUSTRE_VERSION_CODE;
895 GOTO(out, rc = -EPROTO);
899 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) {
900 mds_conn = (data->ocd_connect_flags & OBD_CONNECT_MDS) != 0;
901 lw_client = (data->ocd_connect_flags &
902 OBD_CONNECT_LIGHTWEIGHT) != 0;
904 /* OBD_CONNECT_MNE_SWAB is defined as OBD_CONNECT_MDS_MDS
905 * for Imperative Recovery connection from MGC to MGS. */
907 (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
908 !(data->ocd_connect_flags & OBD_CONNECT_IMP_RECOV) &&
909 (data->ocd_connect_flags & OBD_CONNECT_VERSION)) {
910 __u32 major = OBD_OCD_VERSION_MAJOR(data->ocd_version);
911 __u32 minor = OBD_OCD_VERSION_MINOR(data->ocd_version);
912 __u32 patch = OBD_OCD_VERSION_PATCH(data->ocd_version);
914 /* We do not support the MDT-MDT interoperations with
915 * different version MDT because of protocol changes. */
916 if (unlikely(major != LUSTRE_MAJOR ||
917 minor != LUSTRE_MINOR ||
918 abs(patch - LUSTRE_PATCH) > 3)) {
919 LCONSOLE_WARN("%s (%u.%u.%u.%u) refused the "
920 "connection from different version MDT "
921 "(%d.%d.%d.%d) %s %s\n",
922 target->obd_name, LUSTRE_MAJOR,
923 LUSTRE_MINOR, LUSTRE_PATCH, LUSTRE_FIX,
925 OBD_OCD_VERSION_FIX(data->ocd_version),
926 libcfs_nid2str(req->rq_peer.nid), str);
928 GOTO(out, rc = -EPROTO);
933 /* lctl gets a backstage, all-access pass. */
934 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
935 goto dont_check_exports;
937 export = cfs_hash_lookup(target->obd_uuid_hash, &cluuid);
941 /* We've found an export in the hash. */
943 spin_lock(&export->exp_lock);
945 if (export->exp_connecting) { /* bug 9635, et. al. */
946 spin_unlock(&export->exp_lock);
947 LCONSOLE_WARN("%s: Export %p already connecting from %s\n",
948 export->exp_obd->obd_name, export,
949 libcfs_nid2str(req->rq_peer.nid));
950 class_export_put(export);
953 } else if ((mds_conn || lw_client) && export->exp_connection != NULL) {
954 spin_unlock(&export->exp_lock);
955 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
956 /* MDS or LWP reconnected after failover. */
957 LCONSOLE_WARN("%s: Received %s connection from "
958 "%s, removing former export from %s\n",
959 target->obd_name, mds_conn ? "MDS" : "LWP",
960 libcfs_nid2str(req->rq_peer.nid),
961 libcfs_nid2str(export->exp_connection->c_peer.nid));
963 /* New MDS connection from the same NID. */
964 LCONSOLE_WARN("%s: Received new %s connection from "
965 "%s, removing former export from same NID\n",
966 target->obd_name, mds_conn ? "MDS" : "LWP",
967 libcfs_nid2str(req->rq_peer.nid));
968 class_fail_export(export);
969 class_export_put(export);
972 } else if (export->exp_connection != NULL &&
973 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
974 (lustre_msg_get_op_flags(req->rq_reqmsg) &
975 MSG_CONNECT_INITIAL)) {
976 spin_unlock(&export->exp_lock);
977 /* In MDS failover we have static UUID but NID can change. */
978 LCONSOLE_WARN("%s: Client %s seen on new nid %s when "
979 "existing nid %s is already connected\n",
980 target->obd_name, cluuid.uuid,
981 libcfs_nid2str(req->rq_peer.nid),
983 export->exp_connection->c_peer.nid));
985 class_export_put(export);
988 export->exp_connecting = 1;
989 spin_unlock(&export->exp_lock);
990 LASSERT(export->exp_obd == target);
992 rc = target_handle_reconnect(&conn, export, &cluuid);
995 /* If we found an export, we already unlocked. */
998 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
999 } else if (req->rq_export == NULL &&
1000 atomic_read(&export->exp_rpc_count) > 0) {
1001 LCONSOLE_WARN("%s: Client %s (at %s) refused connection, "
1002 "still busy with %d references\n",
1003 target->obd_name, cluuid.uuid,
1004 libcfs_nid2str(req->rq_peer.nid),
1005 atomic_read(&export->exp_refcount));
1006 GOTO(out, rc = -EBUSY);
1007 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
1008 if (!strstr(cluuid.uuid, "mdt"))
1009 LCONSOLE_WARN("%s: Rejecting reconnect from the "
1010 "known client %s (at %s) because it "
1011 "is indicating it is a new client",
1012 target->obd_name, cluuid.uuid,
1013 libcfs_nid2str(req->rq_peer.nid));
1014 GOTO(out, rc = -EALREADY);
1016 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
1023 CDEBUG(D_HA, "%s: connection from %s@%s %st"LPU64" exp %p cur %ld last %ld\n",
1024 target->obd_name, cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1025 target->obd_recovering ? "recovering/" : "", data->ocd_transno,
1026 export, (long)cfs_time_current_sec(),
1027 export ? (long)export->exp_last_request_time : 0);
1029 /* If this is the first time a client connects, reset the recovery
1030 * timer. Discard lightweight connections which might be local. */
1031 if (!lw_client && rc == 0 && target->obd_recovering)
1032 check_and_start_recovery_timer(target, req, export == NULL);
1034 /* We want to handle EALREADY but *not* -EALREADY from
1035 * target_handle_reconnect(), return reconnection state in a flag. */
1036 if (rc == EALREADY) {
1037 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
1043 /* Tell the client if we support replayable requests. */
1044 if (target->obd_replayable)
1045 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
1046 client_nid = &req->rq_peer.nid;
1048 if (export == NULL) {
1049 /* allow lightweight connections during recovery */
1050 if (target->obd_recovering && !lw_client) {
1052 int c; /* connected */
1053 int i; /* in progress */
1055 int s; /* stale/evicted */
1057 c = atomic_read(&target->obd_connected_clients);
1058 i = atomic_read(&target->obd_lock_replay_clients);
1059 k = target->obd_max_recoverable_clients;
1060 s = target->obd_stale_clients;
1061 t = cfs_timer_deadline(&target->obd_recovery_timer);
1062 t = cfs_time_sub(t, cfs_time_current());
1063 t = cfs_duration_sec(t);
1064 LCONSOLE_WARN("%s: Denying connection for new client "
1065 "%s (at %s), waiting for all %d known "
1066 "clients (%d recovered, %d in progress, "
1067 "and %d evicted) to recover in %d:%.02d\n",
1068 target->obd_name, cluuid.uuid,
1069 libcfs_nid2str(req->rq_peer.nid), k,
1070 c - i, i, s, (int)t / 60,
1075 rc = obd_connect(req->rq_svc_thread->t_env,
1076 &export, target, &cluuid, data,
1078 if (mds_conn && OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
1079 lustre_msg_add_op_flags(req->rq_repmsg,
1080 MSG_CONNECT_RECOVERING);
1082 conn.cookie = export->exp_handle.h_cookie;
1085 rc = obd_reconnect(req->rq_svc_thread->t_env,
1086 export, target, &cluuid, data, client_nid);
1091 LASSERT(target->u.obt.obt_magic == OBT_MAGIC);
1092 data->ocd_instance = target->u.obt.obt_instance;
1094 /* Return only the parts of obd_connect_data that we understand, so the
1095 * client knows that we don't understand the rest. */
1097 tmpsize = req_capsule_get_size(&req->rq_pill, &RMF_CONNECT_DATA,
1099 tmpdata = req_capsule_server_get(&req->rq_pill,
1101 /* Don't use struct assignment here, because the client reply
1102 * buffer may be smaller/larger than the local struct
1103 * obd_connect_data. */
1104 memcpy(tmpdata, data, min(tmpsize, size));
1107 /* If all else goes well, this is our RPC return code. */
1110 lustre_msg_set_handle(req->rq_repmsg, &conn);
1112 /* If the client and the server are the same node, we will already
1113 * have an export that really points to the client's DLM export,
1114 * because we have a shared handles table.
1116 * XXX this will go away when shaver stops sending the "connect" handle
1117 * in the real "remote handle" field of the request --phik 24 Apr 2003
1119 ptlrpc_request_change_export(req, export);
1121 spin_lock(&export->exp_lock);
1122 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
1123 spin_unlock(&export->exp_lock);
1124 CDEBUG(D_RPCTRACE, "%s: %s already connected at greater "
1125 "or equal conn_cnt: %d >= %d\n",
1126 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
1127 export->exp_conn_cnt,
1128 lustre_msg_get_conn_cnt(req->rq_reqmsg));
1130 GOTO(out, rc = -EALREADY);
1132 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1133 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1135 /* Don't evict liblustre clients for not pinging. */
1136 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1137 export->exp_libclient = 1;
1138 spin_unlock(&export->exp_lock);
1140 spin_lock(&target->obd_dev_lock);
1141 list_del_init(&export->exp_obd_chain_timed);
1142 spin_unlock(&target->obd_dev_lock);
1144 spin_unlock(&export->exp_lock);
1147 if (export->exp_connection != NULL) {
1148 /* Check to see if connection came from another NID. */
1149 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1150 !hlist_unhashed(&export->exp_nid_hash))
1151 cfs_hash_del(export->exp_obd->obd_nid_hash,
1152 &export->exp_connection->c_peer.nid,
1153 &export->exp_nid_hash);
1155 ptlrpc_connection_put(export->exp_connection);
1158 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1161 if (hlist_unhashed(&export->exp_nid_hash)) {
1162 cfs_hash_add(export->exp_obd->obd_nid_hash,
1163 &export->exp_connection->c_peer.nid,
1164 &export->exp_nid_hash);
1167 if (target->obd_recovering && !export->exp_in_recovery && !lw_client) {
1169 __u64 transno = data->ocd_transno;
1171 spin_lock(&export->exp_lock);
1172 /* possible race with class_disconnect_stale_exports,
1173 * export may be already in the eviction process */
1174 if (export->exp_failed) {
1175 spin_unlock(&export->exp_lock);
1176 GOTO(out, rc = -ENODEV);
1178 export->exp_in_recovery = 1;
1179 export->exp_req_replay_needed = 1;
1180 export->exp_lock_replay_needed = 1;
1181 spin_unlock(&export->exp_lock);
1183 has_transno = !!(lustre_msg_get_op_flags(req->rq_reqmsg) &
1184 MSG_CONNECT_TRANSNO);
1185 if (has_transno && transno == 0)
1186 CWARN("Connect with zero transno!\n");
1188 if (has_transno && transno > 0 &&
1189 transno < target->obd_next_recovery_transno &&
1190 transno > target->obd_last_committed) {
1191 /* Another way is to use cmpxchg() to be lock-free. */
1192 spin_lock(&target->obd_recovery_task_lock);
1193 if (transno < target->obd_next_recovery_transno)
1194 target->obd_next_recovery_transno = transno;
1195 spin_unlock(&target->obd_recovery_task_lock);
1198 atomic_inc(&target->obd_req_replay_clients);
1199 atomic_inc(&target->obd_lock_replay_clients);
1200 if (atomic_inc_return(&target->obd_connected_clients) ==
1201 target->obd_max_recoverable_clients)
1202 wake_up(&target->obd_next_transno_waitq);
1205 /* Tell the client we're in recovery, when client is involved in it. */
1206 if (target->obd_recovering && !lw_client)
1207 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
1209 tmp = req_capsule_client_get(&req->rq_pill, &RMF_CONN);
1212 /* Return -ENOTCONN in case of errors to let client reconnect. */
1213 revimp = class_new_import(target);
1214 if (revimp == NULL) {
1215 CERROR("fail to alloc new reverse import.\n");
1216 GOTO(out, rc = -ENOTCONN);
1219 spin_lock(&export->exp_lock);
1220 if (export->exp_imp_reverse != NULL)
1221 /* destroyed import can be still referenced in ctxt */
1222 tmp_imp = export->exp_imp_reverse;
1223 export->exp_imp_reverse = revimp;
1224 spin_unlock(&export->exp_lock);
1226 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1227 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1228 revimp->imp_remote_handle = conn;
1229 revimp->imp_dlm_fake = 1;
1230 revimp->imp_state = LUSTRE_IMP_FULL;
1232 /* Unknown versions will be caught in
1233 * ptlrpc_handle_server_req_in->lustre_unpack_msg(). */
1234 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1236 if ((data->ocd_connect_flags & OBD_CONNECT_AT) &&
1237 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1238 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1240 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1242 if ((data->ocd_connect_flags & OBD_CONNECT_FULL20) &&
1243 (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1))
1244 revimp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
1246 revimp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18;
1248 rc = sptlrpc_import_sec_adapt(revimp, req->rq_svc_ctx, &req->rq_flvr);
1250 CERROR("Failed to get sec for reverse import: %d\n", rc);
1251 spin_lock(&export->exp_lock);
1252 export->exp_imp_reverse = NULL;
1253 spin_unlock(&export->exp_lock);
1254 class_destroy_import(revimp);
1257 class_import_put(revimp);
1260 if (tmp_imp != NULL)
1261 client_destroy_import(tmp_imp);
1263 spin_lock(&export->exp_lock);
1264 export->exp_connecting = 0;
1265 spin_unlock(&export->exp_lock);
1267 class_export_put(export);
1270 spin_lock(&target->obd_dev_lock);
1271 target->obd_conn_inprogress--;
1272 spin_unlock(&target->obd_dev_lock);
1274 class_decref(targref, __func__, current);
1277 req->rq_status = rc;
1280 EXPORT_SYMBOL(target_handle_connect);
1282 int target_handle_disconnect(struct ptlrpc_request *req)
1287 rc = req_capsule_server_pack(&req->rq_pill);
1291 /* Keep the rq_export around so we can send the reply. */
1292 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1296 EXPORT_SYMBOL(target_handle_disconnect);
1298 void target_destroy_export(struct obd_export *exp)
1300 struct obd_import *imp = NULL;
1301 /* exports created from last_rcvd data, and "fake"
1302 exports created by lctl don't have an import */
1303 spin_lock(&exp->exp_lock);
1304 if (exp->exp_imp_reverse != NULL) {
1305 imp = exp->exp_imp_reverse;
1306 exp->exp_imp_reverse = NULL;
1308 spin_unlock(&exp->exp_lock);
1310 client_destroy_import(imp);
1312 LASSERT_ATOMIC_ZERO(&exp->exp_locks_count);
1313 LASSERT_ATOMIC_ZERO(&exp->exp_rpc_count);
1314 LASSERT_ATOMIC_ZERO(&exp->exp_cb_count);
1315 LASSERT_ATOMIC_ZERO(&exp->exp_replay_count);
1317 EXPORT_SYMBOL(target_destroy_export);
1320 * Recovery functions
1322 static void target_request_copy_get(struct ptlrpc_request *req)
1324 class_export_rpc_inc(req->rq_export);
1325 LASSERT(list_empty(&req->rq_list));
1326 INIT_LIST_HEAD(&req->rq_replay_list);
1328 /* Increase refcount to keep request in queue. */
1329 atomic_inc(&req->rq_refcount);
1330 /* Let export know it has replays to be handled. */
1331 atomic_inc(&req->rq_export->exp_replay_count);
1334 static void target_request_copy_put(struct ptlrpc_request *req)
1336 LASSERT(list_empty(&req->rq_replay_list));
1337 LASSERT_ATOMIC_POS(&req->rq_export->exp_replay_count);
1339 atomic_dec(&req->rq_export->exp_replay_count);
1340 class_export_rpc_dec(req->rq_export);
1341 ptlrpc_server_drop_request(req);
1344 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1346 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1347 struct obd_export *exp = req->rq_export;
1348 struct ptlrpc_request *reqiter;
1353 spin_lock(&exp->exp_lock);
1354 list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1356 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1363 /* We expect it with RESENT and REPLAY flags. */
1364 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1365 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1366 CERROR("invalid flags %x of resent replay\n",
1367 lustre_msg_get_flags(req->rq_reqmsg));
1369 list_add_tail(&req->rq_replay_list,
1370 &exp->exp_req_replay_queue);
1373 spin_unlock(&exp->exp_lock);
1377 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1379 LASSERT(!list_empty(&req->rq_replay_list));
1380 LASSERT(req->rq_export);
1382 spin_lock(&req->rq_export->exp_lock);
1383 list_del_init(&req->rq_replay_list);
1384 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 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 (!list_empty(&obd->obd_req_replay_queue) ||
1407 !list_empty(&obd->obd_lock_replay_queue) ||
1408 !list_empty(&obd->obd_final_req_queue)) {
1409 CERROR("%s: Recovery queues ( %s%s%s) are not empty\n",
1411 list_empty(&obd->obd_req_replay_queue) ? "" : "req ",
1412 list_empty(&obd->obd_lock_replay_queue) ? \
1414 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 struct list_head abort_list;
1438 INIT_LIST_HEAD(&abort_list);
1439 spin_lock(&obd->obd_recovery_task_lock);
1440 list_splice_init(&obd->obd_req_replay_queue, &abort_list);
1441 spin_unlock(&obd->obd_recovery_task_lock);
1442 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 struct list_head abort_list;
1459 INIT_LIST_HEAD(&abort_list);
1460 spin_lock(&obd->obd_recovery_task_lock);
1461 list_splice_init(&obd->obd_lock_replay_queue, &abort_list);
1462 spin_unlock(&obd->obd_recovery_task_lock);
1463 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 struct list_head clean_list;
1489 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 list_splice_init(&obd->obd_req_replay_queue, &clean_list);
1502 spin_unlock(&obd->obd_recovery_task_lock);
1504 list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1505 LASSERT(req->rq_reply_state == NULL);
1506 target_exp_dequeue_req_replay(req);
1507 target_request_copy_put(req);
1510 spin_lock(&obd->obd_recovery_task_lock);
1511 list_splice_init(&obd->obd_lock_replay_queue, &clean_list);
1512 list_splice_init(&obd->obd_final_req_queue, &clean_list);
1513 spin_unlock(&obd->obd_recovery_task_lock);
1515 list_for_each_entry_safe(req, n, &clean_list, rq_list) {
1516 LASSERT(req->rq_reply_state == NULL);
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)) {
1596 if (to > obd->obd_recovery_time_hard)
1597 to = obd->obd_recovery_time_hard;
1598 if (obd->obd_recovery_timeout < to) {
1599 obd->obd_recovery_timeout = to;
1600 end = obd->obd_recovery_start + to;
1601 cfs_timer_arm(&obd->obd_recovery_timer,
1602 cfs_time_shift(end - now));
1604 spin_unlock(&obd->obd_dev_lock);
1606 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1607 obd->obd_name, (unsigned)cfs_time_sub(end, now));
1610 /* Reset the timer with each new client connection */
1612 * This timer is actually reconnect_timer, which is for making sure
1613 * the total recovery window is at least as big as my reconnect
1614 * attempt timing. So the initial recovery time_out will be set to
1615 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1616 * from client is bigger than this, then the recovery time_out will
1617 * be extended to make sure the client could be reconnected, in the
1618 * process, the timeout from the new client should be ignored.
1622 check_and_start_recovery_timer(struct obd_device *obd,
1623 struct ptlrpc_request *req,
1626 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1627 struct obd_device_target *obt = &obd->u.obt;
1629 if (!new_client && service_time)
1630 /* Teach server about old server's estimates, as first guess
1631 * at how long new requests will take. */
1632 at_measured(&req->rq_rqbd->rqbd_svcpt->scp_at_estimate,
1635 target_start_recovery_timer(obd);
1637 /* Convert the service time to RPC timeout,
1638 * and reuse service_time to limit stack usage. */
1639 service_time = at_est2timeout(service_time);
1641 /* We expect other clients to timeout within service_time, then try
1642 * to reconnect, then try the failover server. The max delay between
1643 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL. */
1644 service_time += 2 * INITIAL_CONNECT_TIMEOUT;
1646 LASSERT(obt->obt_magic == OBT_MAGIC);
1647 service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
1648 if (service_time > obd->obd_recovery_timeout && !new_client)
1649 extend_recovery_timer(obd, service_time, false);
1652 /** Health checking routines */
1653 static inline int exp_connect_healthy(struct obd_export *exp)
1655 return (exp->exp_in_recovery);
1658 /** if export done req_replay or has replay in queue */
1659 static inline int exp_req_replay_healthy(struct obd_export *exp)
1661 return (!exp->exp_req_replay_needed ||
1662 atomic_read(&exp->exp_replay_count) > 0);
1664 /** if export done lock_replay or has replay in queue */
1665 static inline int exp_lock_replay_healthy(struct obd_export *exp)
1667 return (!exp->exp_lock_replay_needed ||
1668 atomic_read(&exp->exp_replay_count) > 0);
1671 static inline int exp_vbr_healthy(struct obd_export *exp)
1673 return (!exp->exp_vbr_failed);
1676 static inline int exp_finished(struct obd_export *exp)
1678 return (exp->exp_in_recovery && !exp->exp_lock_replay_needed);
1681 /** Checking routines for recovery */
1682 static int check_for_clients(struct obd_device *obd)
1684 unsigned int clnts = atomic_read(&obd->obd_connected_clients);
1686 if (obd->obd_abort_recovery || obd->obd_recovery_expired)
1688 LASSERT(clnts <= obd->obd_max_recoverable_clients);
1689 return (clnts + obd->obd_stale_clients ==
1690 obd->obd_max_recoverable_clients);
1693 static int check_for_next_transno(struct obd_device *obd)
1695 struct ptlrpc_request *req = NULL;
1696 int wake_up = 0, connected, completed, queue_len;
1697 __u64 next_transno, req_transno;
1700 spin_lock(&obd->obd_recovery_task_lock);
1701 if (!list_empty(&obd->obd_req_replay_queue)) {
1702 req = list_entry(obd->obd_req_replay_queue.next,
1703 struct ptlrpc_request, rq_list);
1704 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1709 connected = atomic_read(&obd->obd_connected_clients);
1710 completed = connected - atomic_read(&obd->obd_req_replay_clients);
1711 queue_len = obd->obd_requests_queued_for_recovery;
1712 next_transno = obd->obd_next_recovery_transno;
1714 CDEBUG(D_HA, "max: %d, connected: %d, completed: %d, queue_len: %d, "
1715 "req_transno: "LPU64", next_transno: "LPU64"\n",
1716 obd->obd_max_recoverable_clients, connected, completed,
1717 queue_len, req_transno, next_transno);
1719 if (obd->obd_abort_recovery) {
1720 CDEBUG(D_HA, "waking for aborted recovery\n");
1722 } else if (obd->obd_recovery_expired) {
1723 CDEBUG(D_HA, "waking for expired recovery\n");
1725 } else if (req_transno == next_transno) {
1726 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1728 } else if (queue_len > 0 &&
1729 queue_len == atomic_read(&obd->obd_req_replay_clients)) {
1731 /** handle gaps occured due to lost reply or VBR */
1732 LASSERTF(req_transno >= next_transno,
1733 "req_transno: "LPU64", next_transno: "LPU64"\n",
1734 req_transno, next_transno);
1735 if (req_transno > obd->obd_last_committed &&
1736 !obd->obd_version_recov)
1739 "%s: waking for gap in transno, VBR is %s (skip: "
1740 LPD64", ql: %d, comp: %d, conn: %d, next: "LPD64
1741 ", last_committed: "LPD64")\n",
1742 obd->obd_name, obd->obd_version_recov ? "ON" : "OFF",
1743 next_transno, queue_len, completed, connected,
1744 req_transno, obd->obd_last_committed);
1745 obd->obd_next_recovery_transno = req_transno;
1747 } else if (atomic_read(&obd->obd_req_replay_clients) == 0) {
1748 CDEBUG(D_HA, "waking for completed recovery\n");
1750 } else if (OBD_FAIL_CHECK(OBD_FAIL_MDS_RECOVERY_ACCEPTS_GAPS)) {
1751 CDEBUG(D_HA, "accepting transno gaps is explicitly allowed"
1752 " by fail_lock, waking up ("LPD64")\n", next_transno);
1753 obd->obd_next_recovery_transno = req_transno;
1756 spin_unlock(&obd->obd_recovery_task_lock);
1760 static int check_for_next_lock(struct obd_device *obd)
1764 spin_lock(&obd->obd_recovery_task_lock);
1765 if (!list_empty(&obd->obd_lock_replay_queue)) {
1766 CDEBUG(D_HA, "waking for next lock\n");
1768 } else if (atomic_read(&obd->obd_lock_replay_clients) == 0) {
1769 CDEBUG(D_HA, "waking for completed lock replay\n");
1771 } else if (obd->obd_abort_recovery) {
1772 CDEBUG(D_HA, "waking for aborted recovery\n");
1774 } else if (obd->obd_recovery_expired) {
1775 CDEBUG(D_HA, "waking for expired recovery\n");
1778 spin_unlock(&obd->obd_recovery_task_lock);
1784 * wait for recovery events,
1785 * check its status with help of check_routine
1786 * evict dead clients via health_check
1788 static int target_recovery_overseer(struct obd_device *obd,
1789 int (*check_routine)(struct obd_device *),
1790 int (*health_check)(struct obd_export *))
1793 if ((obd->obd_recovery_start != 0) && (cfs_time_current_sec() >=
1794 (obd->obd_recovery_start + obd->obd_recovery_time_hard))) {
1795 CWARN("recovery is aborted by hard timeout\n");
1796 obd->obd_abort_recovery = 1;
1799 while (wait_event_timeout(obd->obd_next_transno_waitq,
1801 msecs_to_jiffies(60 * MSEC_PER_SEC)) == 0)
1802 /* wait indefinitely for event, but don't trigger watchdog */;
1804 if (obd->obd_abort_recovery) {
1805 CWARN("recovery is aborted, evict exports in recovery\n");
1806 /** evict exports which didn't finish recovery yet */
1807 class_disconnect_stale_exports(obd, exp_finished);
1809 } else if (obd->obd_recovery_expired) {
1810 obd->obd_recovery_expired = 0;
1811 /** If some clients died being recovered, evict them */
1812 LCONSOLE_WARN("%s: recovery is timed out, "
1813 "evict stale exports\n", obd->obd_name);
1814 /** evict cexports with no replay in queue, they are stalled */
1815 class_disconnect_stale_exports(obd, health_check);
1816 /** continue with VBR */
1817 spin_lock(&obd->obd_dev_lock);
1818 obd->obd_version_recov = 1;
1819 spin_unlock(&obd->obd_dev_lock);
1821 * reset timer, recovery will proceed with versions now,
1822 * timeout is set just to handle reconnection delays
1824 extend_recovery_timer(obd, RECONNECT_DELAY_MAX, true);
1825 /** Wait for recovery events again, after evicting bad clients */
1831 static struct ptlrpc_request *target_next_replay_req(struct obd_device *obd)
1833 struct ptlrpc_request *req = NULL;
1836 CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1837 obd->obd_next_recovery_transno);
1839 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLAY_DELAY2, cfs_fail_val);
1840 /** It is needed to extend recovery window above recovery_time_soft.
1841 * Extending is possible only in the end of recovery window
1842 * (see more details in handle_recovery_req).
1844 CFS_FAIL_TIMEOUT_MS(OBD_FAIL_TGT_REPLAY_DELAY, 300);
1846 if (target_recovery_overseer(obd, check_for_next_transno,
1847 exp_req_replay_healthy)) {
1848 abort_req_replay_queue(obd);
1849 abort_lock_replay_queue(obd);
1852 spin_lock(&obd->obd_recovery_task_lock);
1853 if (!list_empty(&obd->obd_req_replay_queue)) {
1854 req = list_entry(obd->obd_req_replay_queue.next,
1855 struct ptlrpc_request, rq_list);
1856 list_del_init(&req->rq_list);
1857 obd->obd_requests_queued_for_recovery--;
1858 spin_unlock(&obd->obd_recovery_task_lock);
1860 spin_unlock(&obd->obd_recovery_task_lock);
1861 LASSERT(list_empty(&obd->obd_req_replay_queue));
1862 LASSERT(atomic_read(&obd->obd_req_replay_clients) == 0);
1863 /** evict exports failed VBR */
1864 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1869 static struct ptlrpc_request *target_next_replay_lock(struct obd_device *obd)
1871 struct ptlrpc_request *req = NULL;
1873 CDEBUG(D_HA, "Waiting for lock\n");
1874 if (target_recovery_overseer(obd, check_for_next_lock,
1875 exp_lock_replay_healthy))
1876 abort_lock_replay_queue(obd);
1878 spin_lock(&obd->obd_recovery_task_lock);
1879 if (!list_empty(&obd->obd_lock_replay_queue)) {
1880 req = list_entry(obd->obd_lock_replay_queue.next,
1881 struct ptlrpc_request, rq_list);
1882 list_del_init(&req->rq_list);
1883 spin_unlock(&obd->obd_recovery_task_lock);
1885 spin_unlock(&obd->obd_recovery_task_lock);
1886 LASSERT(list_empty(&obd->obd_lock_replay_queue));
1887 LASSERT(atomic_read(&obd->obd_lock_replay_clients) == 0);
1888 /** evict exports failed VBR */
1889 class_disconnect_stale_exports(obd, exp_vbr_healthy);
1894 static struct ptlrpc_request *target_next_final_ping(struct obd_device *obd)
1896 struct ptlrpc_request *req = NULL;
1898 spin_lock(&obd->obd_recovery_task_lock);
1899 if (!list_empty(&obd->obd_final_req_queue)) {
1900 req = list_entry(obd->obd_final_req_queue.next,
1901 struct ptlrpc_request, rq_list);
1902 list_del_init(&req->rq_list);
1903 spin_unlock(&obd->obd_recovery_task_lock);
1904 if (req->rq_export->exp_in_recovery) {
1905 spin_lock(&req->rq_export->exp_lock);
1906 req->rq_export->exp_in_recovery = 0;
1907 spin_unlock(&req->rq_export->exp_lock);
1910 spin_unlock(&obd->obd_recovery_task_lock);
1915 static void handle_recovery_req(struct ptlrpc_thread *thread,
1916 struct ptlrpc_request *req,
1917 svc_handler_t handler)
1922 * export can be evicted during recovery, no need to handle replays for
1923 * it after that, discard such request silently
1925 if (req->rq_export->exp_disconnected)
1928 req->rq_session.lc_thread = thread;
1929 req->rq_svc_thread = thread;
1930 req->rq_svc_thread->t_env->le_ses = &req->rq_session;
1932 /* thread context */
1933 lu_context_enter(&thread->t_env->le_ctx);
1935 lu_context_exit(&thread->t_env->le_ctx);
1937 /* don't reset timer for final stage */
1938 if (!exp_finished(req->rq_export)) {
1939 int to = obd_timeout;
1942 * Add request timeout to the recovery time so next request from
1943 * this client may come in recovery time
1946 struct ptlrpc_service_part *svcpt;
1948 svcpt = req->rq_rqbd->rqbd_svcpt;
1949 /* If the server sent early reply for this request,
1950 * the client will recalculate the timeout according to
1951 * current server estimate service time, so we will
1952 * use the maxium timeout here for waiting the client
1953 * sending the next req */
1954 to = max((int)at_est2timeout(
1955 at_get(&svcpt->scp_at_estimate)),
1956 (int)lustre_msg_get_timeout(req->rq_reqmsg));
1957 /* Add 2 net_latency, one for balance rq_deadline
1958 * (see ptl_send_rpc), one for resend the req to server,
1959 * Note: client will pack net_latency in replay req
1960 * (see ptlrpc_replay_req) */
1961 to += 2 * lustre_msg_get_service_time(req->rq_reqmsg);
1963 extend_recovery_timer(class_exp2obd(req->rq_export), to, true);
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;
1976 struct ptlrpc_thread *thread = NULL;
1980 unshare_fs_struct();
1981 OBD_ALLOC_PTR(thread);
1987 OBD_FREE_PTR(thread);
1991 rc = lu_context_init(&env->le_ctx, LCT_MD_THREAD | LCT_DT_THREAD);
1993 OBD_FREE_PTR(thread);
1998 thread->t_env = env;
1999 thread->t_id = -1; /* force filter_iobuf_get/put to use local buffers */
2000 env->le_ctx.lc_thread = thread;
2001 tgt_io_thread_init(thread); /* init thread_big_cache for IO requests */
2002 thread->t_watchdog = NULL;
2004 CDEBUG(D_HA, "%s: started recovery thread pid %d\n", obd->obd_name,
2006 trd->trd_processing_task = current_pid();
2008 spin_lock(&obd->obd_dev_lock);
2009 obd->obd_recovering = 1;
2010 spin_unlock(&obd->obd_dev_lock);
2011 complete(&trd->trd_starting);
2013 /* first of all, we have to know the first transno to replay */
2014 if (target_recovery_overseer(obd, check_for_clients,
2015 exp_connect_healthy)) {
2016 abort_req_replay_queue(obd);
2017 abort_lock_replay_queue(obd);
2020 /* next stage: replay requests */
2022 CDEBUG(D_INFO, "1: request replay stage - %d clients from t"LPU64"\n",
2023 atomic_read(&obd->obd_req_replay_clients),
2024 obd->obd_next_recovery_transno);
2025 while ((req = target_next_replay_req(obd))) {
2026 LASSERT(trd->trd_processing_task == current_pid());
2027 DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s",
2028 lustre_msg_get_transno(req->rq_reqmsg),
2029 libcfs_nid2str(req->rq_peer.nid));
2030 handle_recovery_req(thread, req,
2031 trd->trd_recovery_handler);
2033 * bz18031: increase next_recovery_transno before
2034 * target_request_copy_put() will drop exp_rpc reference
2036 spin_lock(&obd->obd_recovery_task_lock);
2037 obd->obd_next_recovery_transno++;
2038 spin_unlock(&obd->obd_recovery_task_lock);
2039 target_exp_dequeue_req_replay(req);
2040 target_request_copy_put(req);
2041 obd->obd_replayed_requests++;
2045 * The second stage: replay locks
2047 CDEBUG(D_INFO, "2: lock replay stage - %d clients\n",
2048 atomic_read(&obd->obd_lock_replay_clients));
2049 while ((req = target_next_replay_lock(obd))) {
2050 LASSERT(trd->trd_processing_task == current_pid());
2051 DEBUG_REQ(D_HA, req, "processing lock from %s: ",
2052 libcfs_nid2str(req->rq_peer.nid));
2053 handle_recovery_req(thread, req,
2054 trd->trd_recovery_handler);
2055 target_request_copy_put(req);
2056 obd->obd_replayed_locks++;
2060 * The third stage: reply on final pings, at this moment all clients
2061 * must have request in final queue
2063 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLAY_RECONNECT, cfs_fail_val);
2064 CDEBUG(D_INFO, "3: final stage - process recovery completion pings\n");
2065 /** Update server last boot epoch */
2066 tgt_boot_epoch_update(lut);
2067 /* We drop recoverying flag to forward all new requests
2068 * to regular mds_handle() since now */
2069 spin_lock(&obd->obd_dev_lock);
2070 obd->obd_recovering = obd->obd_abort_recovery = 0;
2071 spin_unlock(&obd->obd_dev_lock);
2072 spin_lock(&obd->obd_recovery_task_lock);
2073 target_cancel_recovery_timer(obd);
2074 spin_unlock(&obd->obd_recovery_task_lock);
2075 while ((req = target_next_final_ping(obd))) {
2076 LASSERT(trd->trd_processing_task == current_pid());
2077 DEBUG_REQ(D_HA, req, "processing final ping from %s: ",
2078 libcfs_nid2str(req->rq_peer.nid));
2079 handle_recovery_req(thread, req,
2080 trd->trd_recovery_handler);
2081 /* Because the waiting client can not send ping to server,
2082 * so we need refresh the last_request_time, to avoid the
2083 * export is being evicted */
2084 ptlrpc_update_export_timer(req->rq_export, 0);
2085 target_request_copy_put(req);
2088 delta = jiffies_to_msecs(jiffies - delta) / MSEC_PER_SEC;
2089 CDEBUG(D_INFO,"4: recovery completed in %lus - %d/%d reqs/locks\n",
2090 delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
2091 if (delta > OBD_RECOVERY_TIME_SOFT) {
2092 CWARN("too long recovery - read logs\n");
2093 libcfs_debug_dumplog();
2096 target_finish_recovery(obd);
2098 lu_context_fini(&env->le_ctx);
2099 trd->trd_processing_task = 0;
2100 complete(&trd->trd_finishing);
2102 tgt_io_thread_done(thread);
2103 OBD_FREE_PTR(thread);
2108 static int target_start_recovery_thread(struct lu_target *lut,
2109 svc_handler_t handler)
2111 struct obd_device *obd = lut->lut_obd;
2113 struct target_recovery_data *trd = &obd->obd_recovery_data;
2115 memset(trd, 0, sizeof(*trd));
2116 init_completion(&trd->trd_starting);
2117 init_completion(&trd->trd_finishing);
2118 trd->trd_recovery_handler = handler;
2120 if (!IS_ERR(kthread_run(target_recovery_thread,
2121 lut, "tgt_recov"))) {
2122 wait_for_completion(&trd->trd_starting);
2123 LASSERT(obd->obd_recovering != 0);
2131 void target_stop_recovery_thread(struct obd_device *obd)
2133 if (obd->obd_recovery_data.trd_processing_task > 0) {
2134 struct target_recovery_data *trd = &obd->obd_recovery_data;
2135 /** recovery can be done but postrecovery is not yet */
2136 spin_lock(&obd->obd_dev_lock);
2137 if (obd->obd_recovering) {
2138 CERROR("%s: Aborting recovery\n", obd->obd_name);
2139 obd->obd_abort_recovery = 1;
2140 wake_up(&obd->obd_next_transno_waitq);
2142 spin_unlock(&obd->obd_dev_lock);
2143 wait_for_completion(&trd->trd_finishing);
2146 EXPORT_SYMBOL(target_stop_recovery_thread);
2148 void target_recovery_fini(struct obd_device *obd)
2150 class_disconnect_exports(obd);
2151 target_stop_recovery_thread(obd);
2152 target_cleanup_recovery(obd);
2154 EXPORT_SYMBOL(target_recovery_fini);
2156 static void target_recovery_expired(unsigned long castmeharder)
2158 struct obd_device *obd = (struct obd_device *)castmeharder;
2159 CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery"
2160 " after %lds (%d clients connected)\n",
2161 obd->obd_name, atomic_read(&obd->obd_lock_replay_clients),
2162 cfs_time_current_sec()- obd->obd_recovery_start,
2163 atomic_read(&obd->obd_connected_clients));
2165 obd->obd_recovery_expired = 1;
2166 wake_up(&obd->obd_next_transno_waitq);
2169 void target_recovery_init(struct lu_target *lut, svc_handler_t handler)
2171 struct obd_device *obd = lut->lut_obd;
2172 if (obd->obd_max_recoverable_clients == 0) {
2173 /** Update server last boot epoch */
2174 tgt_boot_epoch_update(lut);
2178 CDEBUG(D_HA, "RECOVERY: service %s, %d recoverable clients, "
2179 "last_transno "LPU64"\n", obd->obd_name,
2180 obd->obd_max_recoverable_clients, obd->obd_last_committed);
2181 LASSERT(obd->obd_stopping == 0);
2182 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
2183 obd->obd_recovery_start = 0;
2184 obd->obd_recovery_end = 0;
2186 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
2187 target_start_recovery_thread(lut, handler);
2189 EXPORT_SYMBOL(target_recovery_init);
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 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 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)
2230 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
2231 struct ptlrpc_request *reqiter;
2235 if (obd->obd_recovery_data.trd_processing_task == current_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 wake_up(&obd->obd_next_transno_waitq);
2248 spin_lock(&obd->obd_recovery_task_lock);
2249 if (obd->obd_recovering) {
2250 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 wake_up(&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 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 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(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 list_for_each_entry(reqiter, &obd->obd_req_replay_queue, rq_list) {
2331 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
2332 list_add_tail(&req->rq_list, &reqiter->rq_list);
2337 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
2339 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
2340 "has been claimed by another client");
2341 spin_unlock(&obd->obd_recovery_task_lock);
2342 target_exp_dequeue_req_replay(req);
2343 target_request_copy_put(req);
2349 list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
2351 obd->obd_requests_queued_for_recovery++;
2352 spin_unlock(&obd->obd_recovery_task_lock);
2353 wake_up(&obd->obd_next_transno_waitq);
2356 EXPORT_SYMBOL(target_queue_recovery_request);
2358 int target_handle_ping(struct ptlrpc_request *req)
2360 obd_ping(req->rq_svc_thread->t_env, req->rq_export);
2361 return req_capsule_server_pack(&req->rq_pill);
2363 EXPORT_SYMBOL(target_handle_ping);
2365 void target_committed_to_req(struct ptlrpc_request *req)
2367 struct obd_export *exp = req->rq_export;
2369 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL)
2370 lustre_msg_set_last_committed(req->rq_repmsg,
2371 exp->exp_last_committed);
2373 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2374 "%d)", exp->exp_obd->obd_no_transno,
2375 req->rq_repmsg == NULL);
2377 CDEBUG(D_INFO, "last_committed "LPU64", transno "LPU64", xid "LPU64"\n",
2378 exp->exp_last_committed, req->rq_transno, req->rq_xid);
2380 EXPORT_SYMBOL(target_committed_to_req);
2382 #endif /* HAVE_SERVER_SUPPORT */
2385 * Packs current SLV and Limit into \a req.
2387 int target_pack_pool_reply(struct ptlrpc_request *req)
2389 struct obd_device *obd;
2392 /* Check that we still have all structures alive as this may
2393 * be some late RPC at shutdown time. */
2394 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
2395 !exp_connect_lru_resize(req->rq_export))) {
2396 lustre_msg_set_slv(req->rq_repmsg, 0);
2397 lustre_msg_set_limit(req->rq_repmsg, 0);
2401 /* OBD is alive here as export is alive, which we checked above. */
2402 obd = req->rq_export->exp_obd;
2404 read_lock(&obd->obd_pool_lock);
2405 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
2406 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
2407 read_unlock(&obd->obd_pool_lock);
2411 EXPORT_SYMBOL(target_pack_pool_reply);
2413 static int target_send_reply_msg(struct ptlrpc_request *req,
2414 int rc, int fail_id)
2416 if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) {
2417 DEBUG_REQ(D_ERROR, req, "dropping reply");
2422 DEBUG_REQ(D_NET, req, "processing error (%d)", rc);
2423 req->rq_status = rc;
2424 return (ptlrpc_send_error(req, 1));
2426 DEBUG_REQ(D_NET, req, "sending reply");
2429 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
2432 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
2434 struct ptlrpc_service_part *svcpt;
2436 struct ptlrpc_reply_state *rs;
2437 struct obd_export *exp;
2440 if (req->rq_no_reply) {
2445 svcpt = req->rq_rqbd->rqbd_svcpt;
2446 rs = req->rq_reply_state;
2447 if (rs == NULL || !rs->rs_difficult) {
2449 target_send_reply_msg (req, rc, fail_id);
2454 /* must be an export if locks saved */
2455 LASSERT(req->rq_export != NULL);
2456 /* req/reply consistent */
2457 LASSERT(rs->rs_svcpt == svcpt);
2460 LASSERT(!rs->rs_scheduled);
2461 LASSERT(!rs->rs_scheduled_ever);
2462 LASSERT(!rs->rs_handled);
2463 LASSERT(!rs->rs_on_net);
2464 LASSERT(rs->rs_export == NULL);
2465 LASSERT(list_empty(&rs->rs_obd_list));
2466 LASSERT(list_empty(&rs->rs_exp_list));
2468 exp = class_export_get(req->rq_export);
2470 /* disable reply scheduling while I'm setting up */
2471 rs->rs_scheduled = 1;
2473 rs->rs_xid = req->rq_xid;
2474 rs->rs_transno = req->rq_transno;
2475 rs->rs_export = exp;
2476 rs->rs_opc = lustre_msg_get_opc(req->rq_reqmsg);
2478 spin_lock(&exp->exp_uncommitted_replies_lock);
2479 CDEBUG(D_NET, "rs transno = "LPU64", last committed = "LPU64"\n",
2480 rs->rs_transno, exp->exp_last_committed);
2481 if (rs->rs_transno > exp->exp_last_committed) {
2482 /* not committed already */
2483 list_add_tail(&rs->rs_obd_list,
2484 &exp->exp_uncommitted_replies);
2486 spin_unlock(&exp->exp_uncommitted_replies_lock);
2488 spin_lock(&exp->exp_lock);
2489 list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies);
2490 spin_unlock(&exp->exp_lock);
2492 netrc = target_send_reply_msg(req, rc, fail_id);
2494 spin_lock(&svcpt->scp_rep_lock);
2496 atomic_inc(&svcpt->scp_nreps_difficult);
2499 /* error sending: reply is off the net. Also we need +1
2500 * reply ref until ptlrpc_handle_rs() is done
2501 * with the reply state (if the send was successful, there
2502 * would have been +1 ref for the net, which
2503 * reply_out_callback leaves alone) */
2505 ptlrpc_rs_addref(rs);
2508 spin_lock(&rs->rs_lock);
2509 if (rs->rs_transno <= exp->exp_last_committed ||
2510 (!rs->rs_on_net && !rs->rs_no_ack) ||
2511 list_empty(&rs->rs_exp_list) || /* completed already */
2512 list_empty(&rs->rs_obd_list)) {
2513 CDEBUG(D_HA, "Schedule reply immediately\n");
2514 ptlrpc_dispatch_difficult_reply(rs);
2516 list_add(&rs->rs_list, &svcpt->scp_rep_active);
2517 rs->rs_scheduled = 0; /* allow notifier to schedule */
2519 spin_unlock(&rs->rs_lock);
2520 spin_unlock(&svcpt->scp_rep_lock);
2523 EXPORT_SYMBOL(target_send_reply);
2525 ldlm_mode_t lck_compat_array[] = {
2526 [LCK_EX] = LCK_COMPAT_EX,
2527 [LCK_PW] = LCK_COMPAT_PW,
2528 [LCK_PR] = LCK_COMPAT_PR,
2529 [LCK_CW] = LCK_COMPAT_CW,
2530 [LCK_CR] = LCK_COMPAT_CR,
2531 [LCK_NL] = LCK_COMPAT_NL,
2532 [LCK_GROUP] = LCK_COMPAT_GROUP,
2533 [LCK_COS] = LCK_COMPAT_COS,
2537 * Rather arbitrary mapping from LDLM error codes to errno values. This should
2538 * not escape to the user level.
2540 int ldlm_error2errno(ldlm_error_t error)
2546 case ELDLM_LOCK_MATCHED:
2549 case ELDLM_LOCK_CHANGED:
2552 case ELDLM_LOCK_ABORTED:
2555 case ELDLM_LOCK_REPLACED:
2558 case ELDLM_NO_LOCK_DATA:
2561 case ELDLM_NAMESPACE_EXISTS:
2564 case ELDLM_BAD_NAMESPACE:
2568 if (((int)error) < 0) /* cast to signed type */
2569 result = error; /* as ldlm_error_t can be unsigned */
2571 CERROR("Invalid DLM result code: %d\n", error);
2577 EXPORT_SYMBOL(ldlm_error2errno);
2580 * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
2582 ldlm_error_t ldlm_errno2error(int err_no)
2591 error = ELDLM_LOCK_CHANGED;
2594 error = ELDLM_LOCK_ABORTED;
2597 error = ELDLM_LOCK_REPLACED;
2600 error = ELDLM_NO_LOCK_DATA;
2603 error = ELDLM_NAMESPACE_EXISTS;
2606 error = ELDLM_BAD_NAMESPACE;
2613 EXPORT_SYMBOL(ldlm_errno2error);
2615 #if LUSTRE_TRACKS_LOCK_EXP_REFS
2616 void ldlm_dump_export_locks(struct obd_export *exp)
2618 spin_lock(&exp->exp_locks_list_guard);
2619 if (!list_empty(&exp->exp_locks_list)) {
2620 struct ldlm_lock *lock;
2622 CERROR("dumping locks for export %p,"
2623 "ignore if the unmount doesn't hang\n", exp);
2624 list_for_each_entry(lock, &exp->exp_locks_list,
2626 LDLM_ERROR(lock, "lock:");
2628 spin_unlock(&exp->exp_locks_list_guard);
2632 #ifdef HAVE_SERVER_SUPPORT
2633 static int target_bulk_timeout(void *data)
2636 /* We don't fail the connection here, because having the export
2637 * killed makes the (vital) call to commitrw very sad.
2642 static inline char *bulk2type(struct ptlrpc_bulk_desc *desc)
2644 return desc->bd_type == BULK_GET_SINK ? "GET" : "PUT";
2647 int target_bulk_io(struct obd_export *exp, struct ptlrpc_bulk_desc *desc,
2648 struct l_wait_info *lwi)
2650 struct ptlrpc_request *req = desc->bd_req;
2651 time_t start = cfs_time_current_sec();
2657 /* If there is eviction in progress, wait for it to finish. */
2658 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
2659 *lwi = LWI_INTR(NULL, NULL);
2660 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
2661 !atomic_read(&exp->exp_obd->
2662 obd_evict_inprogress),
2666 /* Check if client was evicted or reconnected already. */
2667 if (exp->exp_failed ||
2668 exp->exp_conn_cnt > lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
2671 if (desc->bd_type == BULK_PUT_SINK)
2672 rc = sptlrpc_svc_wrap_bulk(req, desc);
2674 rc = ptlrpc_start_bulk_transfer(desc);
2678 DEBUG_REQ(D_ERROR, req, "bulk %s failed: rc %d",
2679 bulk2type(desc), rc);
2683 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
2684 ptlrpc_abort_bulk(desc);
2688 /* limit actual bulk transfer to bulk_timeout seconds */
2689 deadline = start + bulk_timeout;
2690 if (deadline > req->rq_deadline)
2691 deadline = req->rq_deadline;
2694 long timeoutl = deadline - cfs_time_current_sec();
2695 cfs_duration_t timeout = timeoutl <= 0 ?
2696 CFS_TICK : cfs_time_seconds(timeoutl);
2699 *lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
2700 target_bulk_timeout, desc);
2701 rc = l_wait_event(desc->bd_waitq,
2702 !ptlrpc_server_bulk_active(desc) ||
2705 lustre_msg_get_conn_cnt(req->rq_reqmsg),
2707 LASSERT(rc == 0 || rc == -ETIMEDOUT);
2708 /* Wait again if we changed rq_deadline. */
2709 rq_deadline = ACCESS_ONCE(req->rq_deadline);
2710 deadline = start + bulk_timeout;
2711 if (deadline > rq_deadline)
2712 deadline = rq_deadline;
2713 } while ((rc == -ETIMEDOUT) &&
2714 (deadline > cfs_time_current_sec()));
2716 if (rc == -ETIMEDOUT) {
2717 DEBUG_REQ(D_ERROR, req, "timeout on bulk %s after %ld%+lds",
2718 bulk2type(desc), deadline - start,
2719 cfs_time_current_sec() - deadline);
2720 ptlrpc_abort_bulk(desc);
2721 } else if (exp->exp_failed) {
2722 DEBUG_REQ(D_ERROR, req, "Eviction on bulk %s",
2725 ptlrpc_abort_bulk(desc);
2726 } else if (exp->exp_conn_cnt >
2727 lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
2728 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk %s",
2730 /* We don't reply anyway. */
2732 ptlrpc_abort_bulk(desc);
2733 } else if (desc->bd_failure ||
2734 desc->bd_nob_transferred != desc->bd_nob) {
2735 DEBUG_REQ(D_ERROR, req, "%s bulk %s %d(%d)",
2736 desc->bd_failure ? "network error on" : "truncated",
2737 bulk2type(desc), desc->bd_nob_transferred,
2739 /* XXX Should this be a different errno? */
2741 } else if (desc->bd_type == BULK_GET_SINK) {
2742 rc = sptlrpc_svc_unwrap_bulk(req, desc);
2747 EXPORT_SYMBOL(target_bulk_io);
2749 #endif /* HAVE_SERVER_SUPPORT */