1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_LDLM
43 # include <libcfs/libcfs.h>
45 # include <liblustre.h>
48 #include <lustre_mds.h>
49 #include <lustre_dlm.h>
50 #include <lustre_net.h>
51 #include "ldlm_internal.h"
53 /* @priority: if non-zero, move the selected to the list head
54 * @create: if zero, only search in existed connections
56 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
57 int priority, int create)
59 struct ptlrpc_connection *ptlrpc_conn;
60 struct obd_import_conn *imp_conn = NULL, *item;
64 if (!create && !priority) {
65 CDEBUG(D_HA, "Nothing to do\n");
69 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
71 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
76 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
78 GOTO(out_put, rc = -ENOMEM);
82 spin_lock(&imp->imp_lock);
83 list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
84 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
86 list_del(&item->oic_item);
87 list_add(&item->oic_item, &imp->imp_conn_list);
88 item->oic_last_attempt = 0;
90 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
91 imp, imp->imp_obd->obd_name, uuid->uuid,
92 (priority ? ", moved to head" : ""));
93 spin_unlock(&imp->imp_lock);
94 GOTO(out_free, rc = 0);
99 imp_conn->oic_conn = ptlrpc_conn;
100 imp_conn->oic_uuid = *uuid;
101 imp_conn->oic_last_attempt = 0;
103 list_add(&imp_conn->oic_item, &imp->imp_conn_list);
105 list_add_tail(&imp_conn->oic_item, &imp->imp_conn_list);
106 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
107 imp, imp->imp_obd->obd_name, uuid->uuid,
108 (priority ? "head" : "tail"));
110 spin_unlock(&imp->imp_lock);
111 GOTO(out_free, rc = -ENOENT);
115 spin_unlock(&imp->imp_lock);
119 OBD_FREE(imp_conn, sizeof(*imp_conn));
121 ptlrpc_connection_put(ptlrpc_conn);
125 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
127 return import_set_conn(imp, uuid, 1, 0);
130 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
133 return import_set_conn(imp, uuid, priority, 1);
136 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
138 struct obd_import_conn *imp_conn;
139 struct obd_export *dlmexp;
143 spin_lock(&imp->imp_lock);
144 if (list_empty(&imp->imp_conn_list)) {
145 LASSERT(!imp->imp_connection);
149 list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
150 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
152 LASSERT(imp_conn->oic_conn);
154 /* is current conn? */
155 if (imp_conn == imp->imp_conn_current) {
156 LASSERT(imp_conn->oic_conn == imp->imp_connection);
158 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
159 imp->imp_state != LUSTRE_IMP_DISCON) {
160 CERROR("can't remove current connection\n");
161 GOTO(out, rc = -EBUSY);
164 ptlrpc_connection_put(imp->imp_connection);
165 imp->imp_connection = NULL;
167 dlmexp = class_conn2export(&imp->imp_dlm_handle);
168 if (dlmexp && dlmexp->exp_connection) {
169 LASSERT(dlmexp->exp_connection ==
171 ptlrpc_connection_put(dlmexp->exp_connection);
172 dlmexp->exp_connection = NULL;
176 list_del(&imp_conn->oic_item);
177 ptlrpc_connection_put(imp_conn->oic_conn);
178 OBD_FREE(imp_conn, sizeof(*imp_conn));
179 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
180 imp, imp->imp_obd->obd_name, uuid->uuid);
185 spin_unlock(&imp->imp_lock);
187 CERROR("connection %s not found\n", uuid->uuid);
191 /* configure an RPC client OBD device
196 * 3 - inactive-on-startup
198 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
200 struct lustre_cfg* lcfg = buf;
201 struct client_obd *cli = &obddev->u.cli;
202 struct obd_import *imp;
203 struct obd_uuid server_uuid;
204 int rq_portal, rp_portal, connect_op;
205 char *name = obddev->obd_type->typ_name;
209 /* In a more perfect world, we would hang a ptlrpc_client off of
210 * obd_type and just use the values from there. */
211 if (!strcmp(name, LUSTRE_OSC_NAME)) {
212 rq_portal = OST_REQUEST_PORTAL;
213 rp_portal = OSC_REPLY_PORTAL;
214 connect_op = OST_CONNECT;
215 } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
216 rq_portal = MDS_REQUEST_PORTAL;
217 rp_portal = MDC_REPLY_PORTAL;
218 connect_op = MDS_CONNECT;
219 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
220 rq_portal = MGS_REQUEST_PORTAL;
221 rp_portal = MGC_REPLY_PORTAL;
222 connect_op = MGS_CONNECT;
224 CERROR("unknown client OBD type \"%s\", can't setup\n",
229 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
230 CERROR("requires a TARGET UUID\n");
234 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
235 CERROR("client UUID must be less than 38 characters\n");
239 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
240 CERROR("setup requires a SERVER UUID\n");
244 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
245 CERROR("target UUID must be less than 38 characters\n");
249 init_rwsem(&cli->cl_sem);
250 sema_init(&cli->cl_mgc_sem, 1);
251 cli->cl_conn_count = 0;
252 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
253 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
254 sizeof(server_uuid)));
257 cli->cl_avail_grant = 0;
258 /* FIXME: should limit this for the sum of all cl_dirty_max */
259 cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
260 if (cli->cl_dirty_max >> CFS_PAGE_SHIFT > num_physpages / 8)
261 cli->cl_dirty_max = num_physpages << (CFS_PAGE_SHIFT - 3);
262 CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters);
263 CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list);
264 CFS_INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list);
265 CFS_INIT_LIST_HEAD(&cli->cl_loi_write_list);
266 CFS_INIT_LIST_HEAD(&cli->cl_loi_read_list);
267 client_obd_list_lock_init(&cli->cl_loi_list_lock);
268 cli->cl_r_in_flight = 0;
269 cli->cl_w_in_flight = 0;
270 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
271 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
272 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
273 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
274 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
275 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
276 cfs_waitq_init(&cli->cl_destroy_waitq);
277 atomic_set(&cli->cl_destroy_in_flight, 0);
278 #ifdef ENABLE_CHECKSUM
279 /* Turn on checksumming by default. */
280 cli->cl_checksum = 1;
282 * The supported checksum types will be worked out at connect time
283 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
286 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
288 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
290 /* This value may be changed at connect time in
291 ptlrpc_connect_interpret. */
292 cli->cl_max_pages_per_rpc = min((int)PTLRPC_MAX_BRW_PAGES,
293 (int)(1024 * 1024 >> CFS_PAGE_SHIFT));
295 if (!strcmp(name, LUSTRE_MDC_NAME)) {
296 cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT;
297 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 128 /* MB */) {
298 cli->cl_max_rpcs_in_flight = 2;
299 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 256 /* MB */) {
300 cli->cl_max_rpcs_in_flight = 3;
301 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 512 /* MB */) {
302 cli->cl_max_rpcs_in_flight = 4;
304 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
308 CERROR("ldlm_get_ref failed: %d\n", rc);
312 ptlrpc_init_client(rq_portal, rp_portal, name,
313 &obddev->obd_ldlm_client);
315 imp = class_new_import(obddev);
317 GOTO(err_ldlm, rc = -ENOENT);
318 imp->imp_client = &obddev->obd_ldlm_client;
319 imp->imp_connect_op = connect_op;
320 imp->imp_initial_recov = 1;
321 imp->imp_initial_recov_bk = 0;
322 CFS_INIT_LIST_HEAD(&imp->imp_pinger_chain);
323 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
324 LUSTRE_CFG_BUFLEN(lcfg, 1));
325 class_import_put(imp);
327 rc = client_import_add_conn(imp, &server_uuid, 1);
329 CERROR("can't add initial connection\n");
330 GOTO(err_import, rc);
333 cli->cl_import = imp;
334 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
335 cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3);
336 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
338 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
339 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
340 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
341 name, obddev->obd_name,
342 cli->cl_target_uuid.uuid);
343 spin_lock(&imp->imp_lock);
344 imp->imp_deactive = 1;
345 spin_unlock(&imp->imp_lock);
349 obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name,
350 LDLM_NAMESPACE_CLIENT,
351 LDLM_NAMESPACE_GREEDY);
352 if (obddev->obd_namespace == NULL) {
353 CERROR("Unable to create client namespace - %s\n",
355 GOTO(err_import, rc = -ENOMEM);
358 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
363 class_destroy_import(imp);
371 int client_obd_cleanup(struct obd_device *obddev)
375 ldlm_namespace_free_post(obddev->obd_namespace);
376 obddev->obd_namespace = NULL;
382 /* ->o_connect() method for client side (OSC and MDC and MGC) */
383 int client_connect_import(struct lustre_handle *dlm_handle,
384 struct obd_device *obd, struct obd_uuid *cluuid,
385 struct obd_connect_data *data, void *localdata)
387 struct client_obd *cli = &obd->u.cli;
388 struct obd_import *imp = cli->cl_import;
389 struct obd_export **exp = localdata;
390 struct obd_connect_data *ocd;
394 down_write(&cli->cl_sem);
395 CDEBUG(D_INFO, "connect %s - %d\n", obd->obd_name,
398 if (cli->cl_conn_count > 0)
399 GOTO(out_sem, rc = -EALREADY);
401 rc = class_connect(dlm_handle, obd, cluuid);
405 cli->cl_conn_count++;
406 *exp = class_conn2export(dlm_handle);
408 LASSERT(obd->obd_namespace);
410 imp->imp_dlm_handle = *dlm_handle;
411 rc = ptlrpc_init_import(imp);
415 ocd = &imp->imp_connect_data;
418 imp->imp_connect_flags_orig = data->ocd_connect_flags;
421 rc = ptlrpc_connect_import(imp, NULL);
423 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
426 LASSERT((*exp)->exp_connection);
429 LASSERT((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
430 ocd->ocd_connect_flags);
431 data->ocd_connect_flags = ocd->ocd_connect_flags;
434 ptlrpc_pinger_add_import(imp);
439 cli->cl_conn_count--;
440 class_disconnect(*exp);
444 up_write(&cli->cl_sem);
448 int client_disconnect_export(struct obd_export *exp)
450 struct obd_device *obd = class_exp2obd(exp);
451 struct client_obd *cli;
452 struct obd_import *imp;
457 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
458 exp, exp ? exp->exp_handle.h_cookie : -1);
463 imp = cli->cl_import;
465 down_write(&cli->cl_sem);
466 CDEBUG(D_INFO, "disconnect %s - %d\n", obd->obd_name,
469 if (!cli->cl_conn_count) {
470 CERROR("disconnecting disconnected device (%s)\n",
472 GOTO(out_disconnect, rc = -EINVAL);
475 cli->cl_conn_count--;
476 if (cli->cl_conn_count)
477 GOTO(out_disconnect, rc = 0);
479 /* Mark import deactivated now, so we don't try to reconnect if any
480 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
481 * fully deactivate the import, or that would drop all requests. */
482 spin_lock(&imp->imp_lock);
483 imp->imp_deactive = 1;
484 spin_unlock(&imp->imp_lock);
486 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
487 * delete it regardless. (It's safe to delete an import that was
489 (void)ptlrpc_pinger_del_import(imp);
491 if (obd->obd_namespace != NULL) {
492 /* obd_force == local only */
493 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
494 obd->obd_force ? LDLM_FL_LOCAL_ONLY:0,
496 ldlm_namespace_free_prior(obd->obd_namespace, imp,
500 rc = ptlrpc_disconnect_import(imp, 0);
502 ptlrpc_invalidate_import(imp);
504 if (imp->imp_rq_pool) {
505 ptlrpc_free_rq_pool(imp->imp_rq_pool);
506 imp->imp_rq_pool = NULL;
508 class_destroy_import(imp);
509 cli->cl_import = NULL;
514 /* use server style - class_disconnect should be always called for
516 err = class_disconnect(exp);
519 up_write(&cli->cl_sem);
524 int server_disconnect_export(struct obd_export *exp)
529 /* Disconnect early so that clients can't keep using export */
530 rc = class_disconnect(exp);
532 /* close import for avoid sending any requests */
533 if (exp->exp_imp_reverse)
534 ptlrpc_cleanup_imp(exp->exp_imp_reverse);
536 if (exp->exp_obd->obd_namespace != NULL)
537 ldlm_cancel_locks_for_export(exp);
539 /* complete all outstanding replies */
540 spin_lock(&exp->exp_lock);
541 while (!list_empty(&exp->exp_outstanding_replies)) {
542 struct ptlrpc_reply_state *rs =
543 list_entry(exp->exp_outstanding_replies.next,
544 struct ptlrpc_reply_state, rs_exp_list);
545 struct ptlrpc_service *svc = rs->rs_service;
547 spin_lock(&svc->srv_lock);
548 list_del_init(&rs->rs_exp_list);
549 ptlrpc_schedule_difficult_reply(rs);
550 spin_unlock(&svc->srv_lock);
552 spin_unlock(&exp->exp_lock);
557 /* --------------------------------------------------------------------------
558 * from old lib/target.c
559 * -------------------------------------------------------------------------- */
561 static int target_handle_reconnect(struct lustre_handle *conn,
562 struct obd_export *exp,
563 struct obd_uuid *cluuid)
566 if (exp->exp_connection && exp->exp_imp_reverse) {
567 struct lustre_handle *hdl;
568 hdl = &exp->exp_imp_reverse->imp_remote_handle;
569 /* Might be a re-connect after a partition. */
570 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
571 CWARN("%s: %s reconnecting\n", exp->exp_obd->obd_name,
573 conn->cookie = exp->exp_handle.h_cookie;
574 /* target_handle_connect() treats EALREADY and
575 * -EALREADY differently. EALREADY means we are
576 * doing a valid reconnect from the same client. */
579 CERROR("%s reconnecting from %s, "
580 "handle mismatch (ours "LPX64", theirs "
581 LPX64")\n", cluuid->uuid,
582 exp->exp_connection->c_remote_uuid.uuid,
583 hdl->cookie, conn->cookie);
584 memset(conn, 0, sizeof *conn);
585 /* target_handle_connect() treats EALREADY and
586 * -EALREADY differently. -EALREADY is an error
587 * (same UUID, different handle). */
592 conn->cookie = exp->exp_handle.h_cookie;
593 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
594 cluuid->uuid, exp, conn->cookie);
598 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
601 struct obd_export *exp = cb_data;
603 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
604 obd->obd_name, exp->exp_client_uuid.uuid);
606 spin_lock(&exp->exp_lock);
607 exp->exp_need_sync = 0;
608 spin_unlock(&exp->exp_lock);
610 EXPORT_SYMBOL(target_client_add_cb);
613 target_start_and_reset_recovery_timer(struct obd_device *obd,
614 svc_handler_t handler,
615 struct ptlrpc_request *req,
617 void target_stop_recovery(void *, int);
618 static void reset_recovery_timer(struct obd_device *obd, int duration,
620 int target_recovery_check_and_stop(struct obd_device *obd)
622 int abort_recovery = 0;
624 if (obd->obd_stopping || !obd->obd_recovering)
627 spin_lock_bh(&obd->obd_processing_task_lock);
628 abort_recovery = obd->obd_abort_recovery;
629 obd->obd_abort_recovery = 0;
630 spin_unlock_bh(&obd->obd_processing_task_lock);
633 /** check if fs version-capable */
634 if (target_fs_version_capable(obd)) {
635 class_handle_stale_exports(obd);
637 CWARN("Versions are not supported by ldiskfs, VBR is OFF\n");
638 class_disconnect_stale_exports(obd, exp_flags_from_obd(obd));
640 /* VBR: no clients are remained to replay, stop recovery */
641 spin_lock_bh(&obd->obd_processing_task_lock);
642 if (obd->obd_recovering && obd->obd_recoverable_clients == 0) {
643 spin_unlock_bh(&obd->obd_processing_task_lock);
644 target_stop_recovery(obd, 0);
647 /* always check versions now */
648 obd->obd_version_recov = 1;
649 cfs_waitq_signal(&obd->obd_next_transno_waitq);
650 spin_unlock_bh(&obd->obd_processing_task_lock);
651 /* reset timer, recovery will proceed with versions now */
652 reset_recovery_timer(obd, OBD_RECOVERY_TIME_SOFT, 1);
655 EXPORT_SYMBOL(target_recovery_check_and_stop);
657 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler)
659 struct obd_device *target, *targref = NULL;
660 struct obd_export *export = NULL;
661 struct obd_import *revimp;
662 struct lustre_handle conn;
663 struct obd_uuid tgtuuid;
664 struct obd_uuid cluuid;
665 struct obd_uuid remote_uuid;
668 struct obd_connect_data *data;
669 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*data) };
670 lnet_nid_t *client_nid = NULL;
674 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
676 lustre_set_req_swabbed(req, REQ_REC_OFF);
677 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, sizeof(tgtuuid)-1);
679 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
680 GOTO(out, rc = -EINVAL);
683 obd_str2uuid (&tgtuuid, str);
684 target = class_uuid2obd(&tgtuuid);
686 /* old (pre 1.6) lustre_process_log tries to connect to mdsname
687 (eg. mdsA) instead of uuid. */
689 snprintf((char *)tgtuuid.uuid, sizeof(tgtuuid), "%s_UUID", str);
690 target = class_uuid2obd(&tgtuuid);
693 target = class_name2obd(str);
696 if (!target || target->obd_stopping || !target->obd_set_up) {
697 LCONSOLE_ERROR_MSG(0x137, "UUID '%s' is not available "
698 " for connect (%s)\n", str,
699 !target ? "no target" :
700 (target->obd_stopping ? "stopping" :
702 GOTO(out, rc = -ENODEV);
705 if (target->obd_no_conn) {
706 LCONSOLE_WARN("%s: temporarily refusing client connection "
707 "from %s\n", target->obd_name,
708 libcfs_nid2str(req->rq_peer.nid));
709 GOTO(out, rc = -EAGAIN);
712 /* Make sure the target isn't cleaned up while we're here. Yes,
713 there's still a race between the above check and our incref here.
714 Really, class_uuid2obd should take the ref. */
715 targref = class_incref(target);
717 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
718 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1,
721 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
722 GOTO(out, rc = -EINVAL);
725 obd_str2uuid (&cluuid, str);
727 /* XXX extract a nettype and format accordingly */
728 switch (sizeof(lnet_nid_t)) {
729 /* NB the casts only avoid compiler warnings */
731 snprintf(remote_uuid.uuid, sizeof remote_uuid,
732 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
735 snprintf(remote_uuid.uuid, sizeof remote_uuid,
736 "NET_%x_UUID", (__u32)req->rq_peer.nid);
742 target_recovery_check_and_stop(target);
744 tmp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn);
746 GOTO(out, rc = -EPROTO);
748 memcpy(&conn, tmp, sizeof conn);
750 data = lustre_swab_reqbuf(req, REQ_REC_OFF + 3, sizeof(*data),
751 lustre_swab_connect);
752 rc = lustre_pack_reply(req, 2, size, NULL);
756 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
758 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
759 "libclient connection attempt");
760 GOTO(out, rc = -EPROTO);
761 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
762 LUSTRE_VERSION_ALLOWED_OFFSET ||
763 data->ocd_version > LUSTRE_VERSION_CODE +
764 LUSTRE_VERSION_ALLOWED_OFFSET) {
765 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
766 "libclient connection attempt",
767 data->ocd_version < LUSTRE_VERSION_CODE ?
769 OBD_OCD_VERSION_MAJOR(data->ocd_version),
770 OBD_OCD_VERSION_MINOR(data->ocd_version),
771 OBD_OCD_VERSION_PATCH(data->ocd_version),
772 OBD_OCD_VERSION_FIX(data->ocd_version));
773 data = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
774 offsetof(typeof(*data),
776 sizeof(data->ocd_version));
778 data->ocd_connect_flags = OBD_CONNECT_VERSION;
779 data->ocd_version = LUSTRE_VERSION_CODE;
781 GOTO(out, rc = -EPROTO);
785 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) &&
786 (data->ocd_connect_flags & OBD_CONNECT_MDS))
789 /* lctl gets a backstage, all-access pass. */
790 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
791 goto dont_check_exports;
793 export = lustre_hash_lookup(target->obd_uuid_hash, &cluuid);
797 /* we've found an export in the hash */
798 if (export->exp_connecting) {
799 /* bug 9635, et. al. */
800 CWARN("%s: exp %p already connecting\n",
801 export->exp_obd->obd_name, export);
802 class_export_put(export);
805 } else if (mds_conn && export->exp_connection) {
806 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
807 /* mds reconnected after failover */
808 CWARN("%s: received MDS connection from NID %s,"
809 " removing former export from NID %s\n",
810 target->obd_name, libcfs_nid2str(req->rq_peer.nid),
811 libcfs_nid2str(export->exp_connection->c_peer.nid));
813 /* new mds connection from the same nid */
814 CWARN("%s: received new MDS connection from NID %s,"
815 " removing former export from same NID\n",
816 target->obd_name, libcfs_nid2str(req->rq_peer.nid));
817 class_fail_export(export);
818 class_export_put(export);
821 } else if (export->exp_connection &&
822 req->rq_peer.nid != export->exp_connection->c_peer.nid &&
823 (lustre_msg_get_op_flags(req->rq_reqmsg) &
824 MSG_CONNECT_INITIAL)) {
825 CWARN("%s: cookie %s seen on new NID %s when "
826 "existing NID %s is already connected\n",
827 target->obd_name, cluuid.uuid,
828 libcfs_nid2str(req->rq_peer.nid),
829 libcfs_nid2str(export->exp_connection->c_peer.nid));
831 class_export_put(export);
833 } else if (export->exp_failed) { /* bug 11327 */
834 CDEBUG(D_HA, "%s: exp %p evict in progress - new cookie needed "
835 "for connect\n", export->exp_obd->obd_name, export);
836 class_export_put(export);
839 } else if (export->exp_delayed &&
840 !(data && data->ocd_connect_flags & OBD_CONNECT_VBR)) {
841 class_fail_export(export);
842 class_export_put(export);
844 GOTO(out, rc = -ENODEV);
846 spin_lock(&export->exp_lock);
847 export->exp_connecting = 1;
848 spin_unlock(&export->exp_lock);
849 class_export_put(export);
850 LASSERT(export->exp_obd == target);
852 rc = target_handle_reconnect(&conn, export, &cluuid);
855 /* If we found an export, we already unlocked. */
858 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
859 } else if (req->rq_export == NULL &&
860 atomic_read(&export->exp_rpc_count) > 0) {
861 CWARN("%s: refuse connection from %s/%s to 0x%p; still busy "
862 "with %d references\n", target->obd_name, cluuid.uuid,
863 libcfs_nid2str(req->rq_peer.nid),
864 export, atomic_read(&export->exp_refcount));
865 GOTO(out, rc = -EBUSY);
866 } else if (req->rq_export != NULL &&
867 atomic_read(&export->exp_rpc_count) > 1) {
868 /* the current connect rpc has increased exp_rpc_count */
869 CWARN("%s: refuse reconnection from %s@%s to 0x%p; still busy "
870 "with %d active RPCs\n", target->obd_name, cluuid.uuid,
871 libcfs_nid2str(req->rq_peer.nid),
872 export, atomic_read(&export->exp_rpc_count) - 1);
873 spin_lock(&export->exp_lock);
874 if (req->rq_export->exp_conn_cnt <
875 lustre_msg_get_conn_cnt(req->rq_reqmsg))
876 /* try to abort active requests */
877 req->rq_export->exp_abort_active_req = 1;
878 spin_unlock(&export->exp_lock);
879 GOTO(out, rc = -EBUSY);
880 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
881 CERROR("%s: NID %s (%s) reconnected with 1 conn_cnt; "
882 "cookies not random?\n", target->obd_name,
883 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
884 GOTO(out, rc = -EALREADY);
885 } else if (export->exp_delayed && target->obd_recovering) {
886 /* VBR: don't allow delayed connection during recovery */
887 CWARN("%s: NID %s (%s) export was already marked as delayed "
888 "and will wait for end of recovery\n", target->obd_name,
889 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
890 GOTO(out, rc = -EBUSY);
892 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
898 /* Tell the client if we're in recovery. */
899 if (target->obd_recovering) {
900 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
901 /* If this is the first time a client connects,
902 reset the recovery timer */
904 target_start_and_reset_recovery_timer(target, handler,
908 /* We want to handle EALREADY but *not* -EALREADY from
909 * target_handle_reconnect(), return reconnection state in a flag */
910 if (rc == EALREADY) {
911 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
917 /* Tell the client if we support replayable requests */
918 if (target->obd_replayable)
919 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
920 client_nid = &req->rq_peer.nid;
922 /* VBR: for delayed connections we start recovery */
923 if (export && export->exp_delayed && !export->exp_in_recovery) {
924 LASSERT(!target->obd_recovering);
925 LASSERT(data && data->ocd_connect_flags & OBD_CONNECT_VBR);
926 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_DELAYED |
927 MSG_CONNECT_RECOVERING);
928 spin_lock_bh(&target->obd_processing_task_lock);
929 target->obd_version_recov = 1;
930 spin_unlock_bh(&target->obd_processing_task_lock);
931 target_start_and_reset_recovery_timer(target, handler, req, 1);
934 if (export == NULL) {
935 if (target->obd_recovering) {
936 CERROR("%s: denying connection for new client %s (%s): "
937 "%d clients in recovery for %lds\n",
939 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid,
940 target->obd_recoverable_clients,
941 cfs_duration_sec(cfs_time_sub(cfs_timer_deadline(&target->obd_recovery_timer),
942 cfs_time_current())));
946 rc = obd_connect(&conn, target, &cluuid, data,
950 rc = obd_reconnect(export, target, &cluuid, data, client_nid);
956 /* Return only the parts of obd_connect_data that we understand, so the
957 * client knows that we don't understand the rest. */
959 memcpy(lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
961 data, sizeof(*data));
963 /* If all else goes well, this is our RPC return code. */
966 lustre_msg_set_handle(req->rq_repmsg, &conn);
968 /* ownership of this export ref transfers to the request AFTER we
969 * drop any previous reference the request had, but we don't want
970 * that to go to zero before we get our new export reference. */
971 export = class_conn2export(&conn);
973 DEBUG_REQ(D_ERROR, req, "Missing export!");
974 GOTO(out, rc = -ENODEV);
977 /* If the client and the server are the same node, we will already
978 * have an export that really points to the client's DLM export,
979 * because we have a shared handles table.
981 * XXX this will go away when shaver stops sending the "connect" handle
982 * in the real "remote handle" field of the request --phik 24 Apr 2003
984 if (req->rq_export != NULL)
985 class_export_put(req->rq_export);
987 req->rq_export = export;
989 spin_lock(&export->exp_lock);
990 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
991 CERROR("%s: %s already connected at higher conn_cnt: %d > %d\n",
992 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
993 export->exp_conn_cnt,
994 lustre_msg_get_conn_cnt(req->rq_reqmsg));
996 spin_unlock(&export->exp_lock);
997 GOTO(out, rc = -EALREADY);
999 LASSERT(lustre_msg_get_conn_cnt(req->rq_reqmsg) > 0);
1000 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
1001 export->exp_abort_active_req = 0;
1003 /* request from liblustre? Don't evict it for not pinging. */
1004 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
1005 export->exp_libclient = 1;
1006 spin_unlock(&export->exp_lock);
1008 spin_lock(&target->obd_dev_lock);
1009 list_del_init(&export->exp_obd_chain_timed);
1010 spin_unlock(&target->obd_dev_lock);
1012 spin_unlock(&export->exp_lock);
1015 if (export->exp_connection != NULL) {
1016 /* Check to see if connection came from another NID */
1017 if ((export->exp_connection->c_peer.nid != req->rq_peer.nid) &&
1018 !hlist_unhashed(&export->exp_nid_hash))
1019 lustre_hash_del(export->exp_obd->obd_nid_hash,
1020 &export->exp_connection->c_peer.nid,
1021 &export->exp_nid_hash);
1023 ptlrpc_connection_put(export->exp_connection);
1026 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
1030 if (hlist_unhashed(&export->exp_nid_hash)) {
1031 lustre_hash_add(export->exp_obd->obd_nid_hash,
1032 &export->exp_connection->c_peer.nid,
1033 &export->exp_nid_hash);
1036 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT) {
1037 revimp = class_import_get(export->exp_imp_reverse);
1038 ptlrpc_connection_put(revimp->imp_connection);
1039 revimp->imp_connection = NULL;
1040 GOTO(set_flags, rc = 0);
1043 if (target->obd_recovering && !export->exp_in_recovery) {
1044 spin_lock(&export->exp_lock);
1045 export->exp_in_recovery = 1;
1046 spin_unlock(&export->exp_lock);
1047 target->obd_connected_clients++;
1050 lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn),
1053 if (export->exp_imp_reverse != NULL)
1054 class_destroy_import(export->exp_imp_reverse);
1055 revimp = export->exp_imp_reverse = class_new_import(target);
1056 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1057 revimp->imp_remote_handle = conn;
1058 revimp->imp_dlm_fake = 1;
1059 revimp->imp_state = LUSTRE_IMP_FULL;
1062 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1063 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V1 &&
1064 lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) {
1065 revimp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
1066 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_NEXT_VER);
1068 /* unknown versions will be caught in
1069 * ptlrpc_handle_server_req_in->lustre_unpack_msg() */
1070 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1073 if (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1) {
1074 if (export->exp_connect_flags & OBD_CONNECT_AT)
1075 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1077 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1080 class_import_put(revimp);
1083 spin_lock(&export->exp_lock);
1084 export->exp_connecting = 0;
1085 spin_unlock(&export->exp_lock);
1088 class_decref(targref);
1090 req->rq_status = rc;
1094 int target_handle_disconnect(struct ptlrpc_request *req)
1099 rc = lustre_pack_reply(req, 1, NULL, NULL);
1103 /* keep the rq_export around so we can send the reply */
1104 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1108 void target_destroy_export(struct obd_export *exp)
1110 /* exports created from last_rcvd data, and "fake"
1111 exports created by lctl don't have an import */
1112 if (exp->exp_imp_reverse != NULL)
1113 class_destroy_import(exp->exp_imp_reverse);
1115 /* We cancel locks at disconnect time, but this will catch any locks
1116 * granted in a race with recovery-induced disconnect. */
1117 if (exp->exp_obd->obd_namespace != NULL)
1118 ldlm_cancel_locks_for_export(exp);
1122 * Recovery functions
1125 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1127 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1128 struct obd_export *exp = req->rq_export;
1129 struct ptlrpc_request *reqiter;
1134 spin_lock(&exp->exp_lock);
1135 list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1137 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1144 /* we expect it with RESENT and REPLAY flags */
1145 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1146 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1147 CERROR("invalid flags %x of resent replay\n",
1148 lustre_msg_get_flags(req->rq_reqmsg));
1150 list_add_tail(&req->rq_replay_list, &exp->exp_req_replay_queue);
1153 spin_unlock(&exp->exp_lock);
1157 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1159 LASSERT(!list_empty(&req->rq_replay_list));
1160 LASSERT(req->rq_export);
1162 spin_lock(&req->rq_export->exp_lock);
1163 list_del_init(&req->rq_replay_list);
1164 spin_unlock(&req->rq_export->exp_lock);
1167 static void target_request_copy_get(struct ptlrpc_request *req)
1169 /* mark that request is in recovery queue, so request handler will not
1170 * drop rpc count in export, bug 19870*/
1171 LASSERT(!req->rq_copy_queued);
1172 spin_lock(&req->rq_lock);
1173 req->rq_copy_queued = 1;
1174 spin_unlock(&req->rq_lock);
1175 /* increase refcount to keep request in queue */
1176 atomic_inc(&req->rq_refcount);
1177 /* release service thread while request is queued
1178 * we are moving the request from active processing
1179 * to waiting on the replay queue */
1180 ptlrpc_server_active_request_dec(req);
1183 static void target_request_copy_put(struct ptlrpc_request *req)
1185 LASSERTF(list_empty(&req->rq_replay_list), "next: %p, prev: %p\n",
1186 req->rq_replay_list.next, req->rq_replay_list.prev);
1187 /* class_export_rpc_get was done before handling request,
1188 * drop it early to allow new requests, see bug 19870.
1190 LASSERT(req->rq_copy_queued);
1191 class_export_rpc_put(req->rq_export);
1192 /* ptlrpc_server_drop_request() assumes the request is active */
1193 ptlrpc_server_active_request_inc(req);
1194 ptlrpc_server_drop_request(req);
1197 static void target_send_delayed_replies(struct obd_device *obd)
1199 int max_clients = obd->obd_max_recoverable_clients;
1200 struct ptlrpc_request *req, *tmp;
1201 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1202 obd->obd_recovery_start);
1204 LCONSOLE_INFO("%s: Recovery period over after %d:%.02d, of %d clients "
1205 "%d recovered and %d %s evicted.\n", obd->obd_name,
1206 (int)elapsed_time/60, (int)elapsed_time%60, max_clients,
1207 obd->obd_connected_clients,
1208 obd->obd_stale_clients,
1209 obd->obd_stale_clients == 1 ? "was" : "were");
1211 LCONSOLE_INFO("%s: sending delayed replies to recovered clients\n",
1214 list_for_each_entry_safe(req, tmp, &obd->obd_delayed_reply_queue,
1216 list_del_init(&req->rq_list);
1217 DEBUG_REQ(D_HA, req, "delayed:");
1219 target_request_copy_put(req);
1221 obd->obd_recovery_end = cfs_time_current_sec();
1224 static void target_finish_recovery(struct obd_device *obd)
1226 OBD_RACE(OBD_FAIL_TGT_REPLAY_DELAY);
1228 ldlm_reprocess_all_ns(obd->obd_namespace);
1229 spin_lock_bh(&obd->obd_processing_task_lock);
1230 if (list_empty(&obd->obd_recovery_queue)) {
1231 obd->obd_recovery_thread = NULL;
1232 obd->obd_processing_task = 0;
1234 spin_unlock_bh(&obd->obd_processing_task_lock);
1235 CERROR("%s: Recovery queue isn't empty\n", obd->obd_name);
1238 spin_unlock_bh(&obd->obd_processing_task_lock);
1240 /* when recovery finished, cleanup orphans on mds and ost */
1241 if (OBT(obd) && OBP(obd, postrecov)) {
1242 int rc = OBP(obd, postrecov)(obd);
1244 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1247 target_send_delayed_replies(obd);
1250 static void abort_recovery_queue(struct obd_device *obd)
1252 struct ptlrpc_request *req, *n;
1253 struct list_head abort_list;
1256 CFS_INIT_LIST_HEAD(&abort_list);
1257 spin_lock_bh(&obd->obd_processing_task_lock);
1258 list_splice_init(&obd->obd_recovery_queue, &abort_list);
1259 spin_unlock_bh(&obd->obd_processing_task_lock);
1260 /* process abort list unlocked */
1261 list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1262 target_exp_dequeue_req_replay(req);
1263 list_del_init(&req->rq_list);
1264 DEBUG_REQ(D_ERROR, req, "%s: aborted:", obd->obd_name);
1265 req->rq_status = -ENOTCONN;
1266 req->rq_type = PTL_RPC_MSG_ERR;
1267 rc = lustre_pack_reply(req, 1, NULL, NULL);
1271 DEBUG_REQ(D_ERROR, req,
1272 "packing failed for abort-reply; skipping");
1273 target_request_copy_put(req);
1277 /* Called from a cleanup function if the device is being cleaned up
1278 forcefully. The exports should all have been disconnected already,
1279 the only thing left to do is
1280 - clear the recovery flags
1282 - free queued requests and replies, but don't send replies
1283 Because the obd_stopping flag is set, no new requests should be received.
1286 void target_cleanup_recovery(struct obd_device *obd)
1288 struct list_head *tmp, *n;
1289 struct ptlrpc_request *req;
1290 struct list_head clean_list;
1293 LASSERT(obd->obd_stopping);
1295 spin_lock_bh(&obd->obd_processing_task_lock);
1296 if (!obd->obd_recovering) {
1297 spin_unlock_bh(&obd->obd_processing_task_lock);
1301 obd->obd_recovering = obd->obd_abort_recovery = 0;
1302 target_cancel_recovery_timer(obd);
1303 spin_unlock_bh(&obd->obd_processing_task_lock);
1305 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
1306 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1307 list_del(&req->rq_list);
1308 target_request_copy_put(req);
1311 CFS_INIT_LIST_HEAD(&clean_list);
1312 spin_lock_bh(&obd->obd_processing_task_lock);
1313 list_splice_init(&obd->obd_recovery_queue, &clean_list);
1314 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1315 spin_unlock_bh(&obd->obd_processing_task_lock);
1316 list_for_each_safe(tmp, n, &clean_list) {
1317 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1318 target_exp_dequeue_req_replay(req);
1319 list_del_init(&req->rq_list);
1320 target_request_copy_put(req);
1325 void target_stop_recovery(void *data, int abort)
1327 struct obd_device *obd = data;
1328 enum obd_option flags;
1331 spin_lock_bh(&obd->obd_processing_task_lock);
1332 if (!obd->obd_recovering) {
1333 spin_unlock_bh(&obd->obd_processing_task_lock);
1337 flags = exp_flags_from_obd(obd) | OBD_OPT_ABORT_RECOV;
1338 obd->obd_recovering = 0;
1339 obd->obd_abort_recovery = 0;
1340 obd->obd_processing_task = 0;
1342 LASSERT(obd->obd_recoverable_clients == 0);
1344 target_cancel_recovery_timer(obd);
1345 spin_unlock_bh(&obd->obd_processing_task_lock);
1348 LCONSOLE_WARN("%s: recovery is aborted by administrative "
1349 "request; %d clients are not recovered "
1350 "(%d clients did)\n", obd->obd_name,
1351 obd->obd_recoverable_clients,
1352 obd->obd_connected_clients);
1353 class_disconnect_stale_exports(obd, flags);
1355 abort_recovery_queue(obd);
1356 target_finish_recovery(obd);
1357 CDEBUG(D_HA, "%s: recovery complete\n", obd_uuid2str(&obd->obd_uuid));
1361 void target_abort_recovery(void *data)
1363 target_stop_recovery(data, 1);
1366 static void reset_recovery_timer(struct obd_device *, int, int);
1367 static void target_recovery_expired(unsigned long castmeharder)
1369 struct obd_device *obd = (struct obd_device *)castmeharder;
1370 CDEBUG(D_HA, "%s: recovery period over; %d clients never reconnected "
1371 "after %lds (%d clients did)\n", obd->obd_name,
1372 obd->obd_recoverable_clients,
1373 cfs_time_current_sec() - obd->obd_recovery_start,
1374 obd->obd_connected_clients);
1376 spin_lock_bh(&obd->obd_processing_task_lock);
1377 obd->obd_abort_recovery = 1;
1378 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1379 spin_unlock_bh(&obd->obd_processing_task_lock);
1382 * The recovery timer expired and target_check_and_stop_recovery()
1383 * must be called. We cannot call it directly because we are in
1384 * interrupt context, so we need to wake up another thread to call it.
1385 * This may happen if there are obd->obd_next_transno_waitq waiters,
1386 * or if we happen to handle a connect request. However, we cannot
1387 * count on either of those things so we wake up the ping evictor
1388 * and leverage it's context to complete recovery.
1390 * Note: HEAD has a separate recovery thread and handle this.
1392 spin_lock(&obd->obd_dev_lock);
1393 ping_evictor_wake(obd->obd_self_export);
1394 spin_unlock(&obd->obd_dev_lock);
1397 /* obd_processing_task_lock should be held */
1398 void target_cancel_recovery_timer(struct obd_device *obd)
1400 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1401 cfs_timer_disarm(&obd->obd_recovery_timer);
1404 /* extend = 1 means require at least "duration" seconds left in the timer,
1405 extend = 0 means set the total duration (start_recovery_timer) */
1406 static void reset_recovery_timer(struct obd_device *obd, int duration,
1409 cfs_time_t now = cfs_time_current_sec();
1410 cfs_duration_t left;
1412 spin_lock_bh(&obd->obd_processing_task_lock);
1413 if (!obd->obd_recovering) {
1414 spin_unlock_bh(&obd->obd_processing_task_lock);
1418 left = cfs_time_sub(obd->obd_recovery_end, now);
1420 if (extend && (duration > left))
1421 obd->obd_recovery_timeout += duration - left;
1422 else if (!extend && (duration > obd->obd_recovery_timeout))
1423 /* Track the client's largest expected replay time */
1424 obd->obd_recovery_timeout = duration;
1426 /* Hard limit of obd_recovery_time_hard which should not happen */
1427 if(obd->obd_recovery_timeout > obd->obd_recovery_time_hard)
1428 obd->obd_recovery_timeout = obd->obd_recovery_time_hard;
1430 obd->obd_recovery_end = obd->obd_recovery_start +
1431 obd->obd_recovery_timeout;
1432 if (cfs_time_before(now, obd->obd_recovery_end)) {
1433 left = cfs_time_sub(obd->obd_recovery_end, now);
1434 cfs_timer_arm(&obd->obd_recovery_timer, cfs_time_shift(left));
1436 spin_unlock_bh(&obd->obd_processing_task_lock);
1437 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1438 obd->obd_name, (unsigned)left);
1441 static void check_and_start_recovery_timer(struct obd_device *obd,
1442 svc_handler_t handler)
1444 spin_lock_bh(&obd->obd_processing_task_lock);
1445 if (obd->obd_recovery_handler) {
1446 spin_unlock_bh(&obd->obd_processing_task_lock);
1449 CDEBUG(D_HA, "%s: starting recovery timer\n", obd->obd_name);
1450 obd->obd_recovery_start = cfs_time_current_sec();
1451 obd->obd_recovery_handler = handler;
1452 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
1453 spin_unlock_bh(&obd->obd_processing_task_lock);
1455 reset_recovery_timer(obd, obd->obd_recovery_timeout, 0);
1458 /* Reset the timer with each new client connection */
1460 * This timer is actually reconnect_timer, which is for making sure
1461 * the total recovery window is at least as big as my reconnect
1462 * attempt timing. So the initial recovery time_out will be set to
1463 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1464 * from client is bigger than this, then the recovery time_out will
1465 * be extend to make sure the client could be reconnected, in the
1466 * process, the timeout from the new client should be ignored.
1470 target_start_and_reset_recovery_timer(struct obd_device *obd,
1471 svc_handler_t handler,
1472 struct ptlrpc_request *req,
1475 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1477 if (!new_client && service_time)
1478 /* Teach server about old server's estimates, as first guess
1479 at how long new requests will take. */
1480 at_measured(&req->rq_rqbd->rqbd_service->srv_at_estimate,
1483 check_and_start_recovery_timer(obd, handler);
1485 /* convert the service time to rpc timeout,
1486 * reuse service_time to limit stack usage */
1487 service_time = at_est2timeout(service_time);
1489 /* We expect other clients to timeout within service_time, then try
1490 * to reconnect, then try the failover server. The max delay between
1491 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL */
1492 service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
1493 INITIAL_CONNECT_TIMEOUT);
1494 if (service_time > obd->obd_recovery_timeout && !new_client)
1495 reset_recovery_timer(obd, service_time, 0);
1498 static int check_for_next_transno(struct obd_device *obd)
1500 struct ptlrpc_request *req;
1501 int wake_up = 0, connected, completed, queue_len, max;
1502 __u64 next_transno, req_transno;
1504 if (obd->obd_stopping) {
1505 CDEBUG(D_HA, "waking for stopping device\n");
1509 spin_lock_bh(&obd->obd_processing_task_lock);
1510 if (obd->obd_abort_recovery) {
1511 CDEBUG(D_HA, "waking for aborted recovery\n");
1512 spin_unlock_bh(&obd->obd_processing_task_lock);
1514 } else if (!obd->obd_recovering) {
1515 CDEBUG(D_HA, "waking for completed recovery (?)\n");
1516 spin_unlock_bh(&obd->obd_processing_task_lock);
1520 LASSERT(!list_empty(&obd->obd_recovery_queue));
1521 req = list_entry(obd->obd_recovery_queue.next,
1522 struct ptlrpc_request, rq_list);
1523 max = obd->obd_max_recoverable_clients;
1524 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1525 connected = obd->obd_connected_clients;
1526 completed = max - obd->obd_recoverable_clients -
1527 obd->obd_delayed_clients;
1528 queue_len = obd->obd_requests_queued_for_recovery;
1529 next_transno = obd->obd_next_recovery_transno;
1531 CDEBUG(D_HA,"max: %d, connected: %d, delayed %d, completed: %d, "
1532 "queue_len: %d, req_transno: "LPU64", next_transno: "LPU64"\n",
1533 max, connected, obd->obd_delayed_clients, completed, queue_len,
1534 req_transno, next_transno);
1535 if (req_transno == next_transno) {
1536 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1538 } else if (queue_len == obd->obd_recoverable_clients) {
1540 "%s: waking for skipped transno (skip: "LPD64
1541 ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
1542 obd->obd_name, next_transno, queue_len, completed, max,
1544 obd->obd_next_recovery_transno = req_transno;
1547 spin_unlock_bh(&obd->obd_processing_task_lock);
1548 LASSERT(lustre_msg_get_transno(req->rq_reqmsg) >= next_transno);
1552 static void process_recovery_queue(struct obd_device *obd)
1554 struct ptlrpc_request *req;
1555 struct l_wait_info lwi = { 0 };
1559 spin_lock_bh(&obd->obd_processing_task_lock);
1561 if (!obd->obd_recovering) {
1562 spin_unlock_bh(&obd->obd_processing_task_lock);
1567 LASSERTF(obd->obd_processing_task == cfs_curproc_pid(),
1568 "%s: invalid pid in obd_processing_task (%d != %d)\n",
1569 obd->obd_name, obd->obd_processing_task,
1571 req = list_entry(obd->obd_recovery_queue.next,
1572 struct ptlrpc_request, rq_list);
1574 if (lustre_msg_get_transno(req->rq_reqmsg) !=
1575 obd->obd_next_recovery_transno) {
1576 spin_unlock_bh(&obd->obd_processing_task_lock);
1577 CDEBUG(D_HA, "%s: waiting for transno "LPD64" (1st is "
1578 LPD64", x"LPU64")\n", obd->obd_name,
1579 obd->obd_next_recovery_transno,
1580 lustre_msg_get_transno(req->rq_reqmsg),
1582 l_wait_event(obd->obd_next_transno_waitq,
1583 check_for_next_transno(obd), &lwi);
1584 if (target_recovery_check_and_stop(obd)) {
1590 list_del_init(&req->rq_list);
1591 LASSERT(obd->obd_recovery_thread);
1592 /* replace request initial thread with current one, bug #18221 */
1593 req->rq_svc_thread = obd->obd_recovery_thread;
1594 obd->obd_requests_queued_for_recovery--;
1595 spin_unlock_bh(&obd->obd_processing_task_lock);
1597 DEBUG_REQ(D_HA, req, "processing: ");
1598 (void)obd->obd_recovery_handler(req);
1599 obd->obd_replayed_requests++;
1600 /* Extend the recovery timer enough to complete the next
1602 reset_recovery_timer(obd, AT_OFF ? obd_timeout :
1603 at_get(&req->rq_rqbd->rqbd_service->srv_at_estimate), 1);
1604 /* bug 1580: decide how to properly sync() in recovery */
1605 //mds_fsync_super(obd->u.obt.obt_sb);
1606 spin_lock_bh(&obd->obd_processing_task_lock);
1607 obd->obd_next_recovery_transno++;
1608 spin_unlock_bh(&obd->obd_processing_task_lock);
1609 target_exp_dequeue_req_replay(req);
1610 target_request_copy_put(req);
1611 OBD_RACE(OBD_FAIL_TGT_REPLAY_DELAY);
1612 spin_lock_bh(&obd->obd_processing_task_lock);
1613 if (list_empty(&obd->obd_recovery_queue)) {
1614 obd->obd_processing_task = 0;
1615 obd->obd_recovery_thread = NULL;
1616 spin_unlock_bh(&obd->obd_processing_task_lock);
1619 spin_unlock_bh(&obd->obd_processing_task_lock);
1624 int target_queue_recovery_request(struct ptlrpc_request *req,
1625 struct obd_device *obd)
1627 struct list_head *tmp;
1629 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1631 /* CAVEAT EMPTOR: The incoming request message has been swabbed
1632 * (i.e. buflens etc are in my own byte order), but type-dependent
1633 * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
1636 CFS_INIT_LIST_HEAD(&req->rq_list);
1637 DEBUG_REQ(D_HA, req, "not queueing");
1641 spin_lock_bh(&obd->obd_processing_task_lock);
1643 if (!obd->obd_recovering) {
1644 spin_unlock_bh(&obd->obd_processing_task_lock);
1648 /* If we're processing the queue, we want don't want to queue this
1651 * Also, if this request has a transno less than the one we're waiting
1652 * for, we should process it now. It could (and currently always will)
1653 * be an open request for a descriptor that was opened some time ago.
1655 * Also, a resent, replayed request that has already been
1656 * handled will pass through here and be processed immediately.
1658 if (obd->obd_processing_task == cfs_curproc_pid() ||
1659 transno < obd->obd_next_recovery_transno) {
1660 /* Processing the queue right now, don't re-add. */
1661 LASSERT(list_empty(&req->rq_list));
1662 spin_unlock_bh(&obd->obd_processing_task_lock);
1666 if (unlikely(OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))) {
1667 spin_unlock_bh(&obd->obd_processing_task_lock);
1671 if (target_exp_enqueue_req_replay(req)) {
1672 spin_unlock_bh(&obd->obd_processing_task_lock);
1673 DEBUG_REQ(D_ERROR, req, "%s: dropping resent queued req",
1679 list_for_each(tmp, &obd->obd_recovery_queue) {
1680 struct ptlrpc_request *reqiter =
1681 list_entry(tmp, struct ptlrpc_request, rq_list);
1683 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
1684 list_add_tail(&req->rq_list, &reqiter->rq_list);
1689 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
1691 spin_unlock_bh(&obd->obd_processing_task_lock);
1692 DEBUG_REQ(D_ERROR, req, "%s: dropping replay: transno "
1693 "has been claimed by another client",
1695 target_exp_dequeue_req_replay(req);
1701 list_add_tail(&req->rq_list, &obd->obd_recovery_queue);
1704 target_request_copy_get(req);
1705 obd->obd_requests_queued_for_recovery++;
1707 if (obd->obd_processing_task != 0) {
1708 /* Someone else is processing this queue, we'll leave it to
1711 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1712 spin_unlock_bh(&obd->obd_processing_task_lock);
1716 /* Nobody is processing, and we know there's (at least) one to process
1717 * now, so we'll do the honours.
1719 obd->obd_processing_task = cfs_curproc_pid();
1720 /* save thread that handle recovery queue */
1721 obd->obd_recovery_thread = req->rq_svc_thread;
1722 spin_unlock_bh(&obd->obd_processing_task_lock);
1724 process_recovery_queue(obd);
1728 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1730 return req->rq_export->exp_obd;
1733 int target_queue_last_replay_reply(struct ptlrpc_request *req, int rc)
1735 struct obd_device *obd = target_req2obd(req);
1736 struct obd_export *exp = req->rq_export;
1737 int recovery_done = 0, delayed_done = 0;
1739 LASSERT ((rc == 0) == req->rq_packed_final);
1741 if (!req->rq_packed_final) {
1742 /* Just like ptlrpc_error, but without the sending. */
1743 rc = lustre_pack_reply(req, 1, NULL, NULL);
1746 req->rq_type = PTL_RPC_MSG_ERR;
1749 LASSERT(!req->rq_reply_state->rs_difficult);
1750 LASSERT(list_empty(&req->rq_list));
1752 /* Don't race cleanup */
1753 spin_lock_bh(&obd->obd_processing_task_lock);
1754 if (obd->obd_stopping) {
1755 spin_unlock_bh(&obd->obd_processing_task_lock);
1759 if (!exp->exp_vbr_failed) {
1760 target_request_copy_get(req);
1761 list_add(&req->rq_list, &obd->obd_delayed_reply_queue);
1764 /* only count the first "replay over" request from each
1766 if (exp->exp_replay_needed) {
1767 spin_lock(&exp->exp_lock);
1768 exp->exp_replay_needed = 0;
1769 spin_unlock(&exp->exp_lock);
1771 if (!exp->exp_delayed) {
1772 --obd->obd_recoverable_clients;
1774 spin_lock(&exp->exp_lock);
1775 exp->exp_delayed = 0;
1776 spin_unlock(&exp->exp_lock);
1778 if (obd->obd_delayed_clients == 0) {
1779 spin_unlock_bh(&obd->obd_processing_task_lock);
1782 --obd->obd_delayed_clients;
1785 recovery_done = (obd->obd_recoverable_clients == 0);
1786 spin_unlock_bh(&obd->obd_processing_task_lock);
1789 /* start pinging export */
1790 spin_lock(&obd->obd_dev_lock);
1791 list_add_tail(&exp->exp_obd_chain_timed,
1792 &obd->obd_exports_timed);
1793 list_move_tail(&exp->exp_obd_chain, &obd->obd_exports);
1794 spin_unlock(&obd->obd_dev_lock);
1795 target_send_delayed_replies(obd);
1798 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
1799 if (recovery_done) {
1800 spin_lock_bh(&obd->obd_processing_task_lock);
1801 obd->obd_recovering = 0;
1802 obd->obd_version_recov = 0;
1803 obd->obd_abort_recovery = 0;
1804 target_cancel_recovery_timer(obd);
1805 spin_unlock_bh(&obd->obd_processing_task_lock);
1808 target_finish_recovery(obd);
1809 CDEBUG(D_HA, "%s: recovery complete\n",
1810 obd_uuid2str(&obd->obd_uuid));
1812 CWARN("%s: %d recoverable clients remain\n",
1813 obd->obd_name, obd->obd_recoverable_clients);
1814 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1817 /* VBR: disconnect export with failed recovery */
1818 if (exp->exp_vbr_failed) {
1819 CWARN("%s: disconnect export %s\n", obd->obd_name,
1820 exp->exp_client_uuid.uuid);
1821 class_fail_export(exp);
1823 ptlrpc_send_reply(req, 0);
1829 req->rq_status = -ENOTCONN;
1830 /* rv is ignored anyhow */
1834 int target_handle_reply(struct ptlrpc_request *req, int rc, int fail)
1836 struct obd_device *obd = NULL;
1839 obd = target_req2obd(req);
1841 /* handle replay reply for version recovery */
1842 if (obd && obd->obd_version_recov &&
1843 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)) {
1844 LASSERT(req->rq_repmsg);
1845 lustre_msg_add_flags(req->rq_repmsg, MSG_VERSION_REPLAY);
1848 /* handle last replay */
1849 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1851 lustre_msg_get_flags(req->rq_reqmsg) & MSG_DELAY_REPLAY) {
1852 DEBUG_REQ(D_HA, req,
1853 "delayed LAST_REPLAY, queuing reply");
1854 rc = target_queue_last_replay_reply(req, rc);
1855 LASSERT(req->rq_export->exp_delayed == 0);
1859 if (obd && obd->obd_recovering) { /* normal recovery */
1860 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1861 rc = target_queue_last_replay_reply(req, rc);
1865 /* Lost a race with recovery; let the error path DTRT. */
1866 rc = req->rq_status = -ENOTCONN;
1868 target_send_reply(req, rc, fail);
1872 static inline struct ldlm_pool *ldlm_exp2pl(struct obd_export *exp)
1874 LASSERT(exp != NULL);
1875 return &exp->exp_obd->obd_namespace->ns_pool;
1878 int target_pack_pool_reply(struct ptlrpc_request *req)
1880 struct obd_device *obd;
1884 * Check that we still have all structures alive as this may
1885 * be some late rpc in shutdown time.
1887 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
1888 !exp_connect_lru_resize(req->rq_export))) {
1889 lustre_msg_set_slv(req->rq_repmsg, 0);
1890 lustre_msg_set_limit(req->rq_repmsg, 0);
1895 * OBD is alive here as export is alive, which we checked above.
1897 obd = req->rq_export->exp_obd;
1899 read_lock(&obd->obd_pool_lock);
1900 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
1901 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
1902 read_unlock(&obd->obd_pool_lock);
1908 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1910 if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1911 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1912 DEBUG_REQ(D_ERROR, req, "dropping reply");
1917 DEBUG_REQ(D_ERROR, req, "processing error (%d)", rc);
1918 req->rq_status = rc;
1919 return (ptlrpc_send_error(req, 1));
1921 DEBUG_REQ(D_NET, req, "sending reply");
1924 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
1928 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1931 struct ptlrpc_reply_state *rs;
1932 struct obd_device *obd;
1933 struct obd_export *exp;
1934 struct ptlrpc_service *svc;
1936 svc = req->rq_rqbd->rqbd_service;
1937 rs = req->rq_reply_state;
1938 if (rs == NULL || !rs->rs_difficult) {
1940 target_send_reply_msg (req, rc, fail_id);
1944 /* must be an export if locks saved */
1945 LASSERT (req->rq_export != NULL);
1946 /* req/reply consistent */
1947 LASSERT (rs->rs_service == svc);
1950 LASSERT (!rs->rs_scheduled);
1951 LASSERT (!rs->rs_scheduled_ever);
1952 LASSERT (!rs->rs_handled);
1953 LASSERT (!rs->rs_on_net);
1954 LASSERT (rs->rs_export == NULL);
1955 LASSERT (list_empty(&rs->rs_obd_list));
1956 LASSERT (list_empty(&rs->rs_exp_list));
1958 exp = class_export_get(req->rq_export);
1961 /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1962 rs->rs_scheduled = 1;
1964 rs->rs_xid = req->rq_xid;
1965 rs->rs_transno = req->rq_transno;
1966 rs->rs_export = exp;
1968 spin_lock(&exp->exp_uncommitted_replies_lock);
1970 /* VBR: use exp_last_committed */
1971 if (rs->rs_transno > exp->exp_last_committed) {
1972 /* not committed already */
1973 list_add_tail (&rs->rs_obd_list,
1974 &exp->exp_uncommitted_replies);
1977 spin_unlock (&exp->exp_uncommitted_replies_lock);
1978 spin_lock (&exp->exp_lock);
1980 list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1982 spin_unlock(&exp->exp_lock);
1984 netrc = target_send_reply_msg (req, rc, fail_id);
1986 spin_lock(&svc->srv_lock);
1988 svc->srv_n_difficult_replies++;
1991 /* error sending: reply is off the net. Also we need +1
1992 * reply ref until ptlrpc_server_handle_reply() is done
1993 * with the reply state (if the send was successful, there
1994 * would have been +1 ref for the net, which
1995 * reply_out_callback leaves alone) */
1997 ptlrpc_rs_addref(rs);
1998 atomic_inc (&svc->srv_outstanding_replies);
2001 if (!rs->rs_on_net || /* some notifier */
2002 list_empty(&rs->rs_exp_list) || /* completed already */
2003 list_empty(&rs->rs_obd_list)) {
2004 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
2005 cfs_waitq_signal (&svc->srv_waitq);
2007 list_add (&rs->rs_list, &svc->srv_active_replies);
2008 rs->rs_scheduled = 0; /* allow notifier to schedule */
2011 spin_unlock(&svc->srv_lock);
2014 int target_handle_ping(struct ptlrpc_request *req)
2016 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY &&
2017 req->rq_export->exp_in_recovery) {
2018 spin_lock(&req->rq_export->exp_lock);
2019 req->rq_export->exp_in_recovery = 0;
2020 spin_unlock(&req->rq_export->exp_lock);
2022 obd_ping(req->rq_export);
2023 return lustre_pack_reply(req, 1, NULL, NULL);
2026 void target_committed_to_req(struct ptlrpc_request *req)
2028 struct obd_export *exp = req->rq_export;
2029 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL) {
2030 lustre_msg_set_last_committed(req->rq_repmsg,
2031 exp->exp_last_committed);
2033 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
2034 "%d)", exp->exp_obd->obd_no_transno,
2035 req->rq_repmsg == NULL);
2037 CDEBUG(D_INFO, "last_committed x"LPU64", this req x"LPU64"\n",
2038 exp->exp_obd->obd_last_committed, req->rq_xid);
2041 EXPORT_SYMBOL(target_committed_to_req);
2043 int target_handle_qc_callback(struct ptlrpc_request *req)
2045 struct obd_quotactl *oqctl;
2046 struct client_obd *cli = &req->rq_export->exp_obd->u.cli;
2048 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
2049 lustre_swab_obd_quotactl);
2050 if (oqctl == NULL) {
2051 CERROR("Can't unpack obd_quatactl\n");
2055 cli->cl_qchk_stat = oqctl->qc_stat;
2060 #ifdef HAVE_QUOTA_SUPPORT
2061 int target_handle_dqacq_callback(struct ptlrpc_request *req)
2064 struct obd_device *obd = req->rq_export->exp_obd;
2065 struct obd_device *master_obd = NULL, *lov_obd = NULL;
2066 struct lustre_quota_ctxt *qctxt;
2067 struct qunit_data *qdata = NULL;
2069 int repsize[2] = { sizeof(struct ptlrpc_body), 0 };
2072 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_DROP_QUOTA_REQ))
2075 repsize[1] = quota_get_qunit_data_size(req->rq_export->
2078 rc = lustre_pack_reply(req, 2, repsize, NULL);
2082 LASSERT(req->rq_export);
2084 /* there are three forms of qunit(historic causes), so we need to
2085 * adjust qunits from slaves to the same form here */
2086 OBD_ALLOC(qdata, sizeof(struct qunit_data));
2089 rc = quota_get_qdata(req, qdata, QUOTA_REQUEST, QUOTA_EXPORT);
2091 CDEBUG(D_ERROR, "Can't unpack qunit_data(rc: %d)\n", rc);
2095 /* we use the observer */
2096 if (obd_pin_observer(obd, &lov_obd) ||
2097 obd_pin_observer(lov_obd, &master_obd)) {
2098 CERROR("Can't find the observer, it is recovering\n");
2099 req->rq_status = -EAGAIN;
2100 GOTO(send_reply, rc = -EAGAIN);
2103 qctxt = &master_obd->u.obt.obt_qctxt;
2105 if (!qctxt->lqc_setup) {
2106 /* quota_type has not been processed yet, return EAGAIN
2107 * until we know whether or not quotas are supposed to
2109 CDEBUG(D_QUOTA, "quota_type not processed yet, return "
2111 req->rq_status = -EAGAIN;
2112 rc = ptlrpc_reply(req);
2116 LASSERT(qctxt->lqc_handler);
2117 rc = qctxt->lqc_handler(master_obd, qdata,
2118 lustre_msg_get_opc(req->rq_reqmsg));
2119 if (rc && rc != -EDQUOT)
2120 CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR,
2121 "dqacq failed! (rc:%d)\n", rc);
2122 req->rq_status = rc;
2124 /* there are three forms of qunit(historic causes), so we need to
2125 * adjust the same form to different forms slaves needed */
2126 rc = quota_copy_qdata(req, qdata, QUOTA_REPLY, QUOTA_EXPORT);
2128 CDEBUG(D_ERROR, "Can't pack qunit_data(rc: %d)\n", rc);
2132 /* Block the quota req. b=14840 */
2133 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_BLOCK_QUOTA_REQ, obd_timeout);
2135 rc = ptlrpc_reply(req);
2138 obd_unpin_observer(lov_obd);
2140 obd_unpin_observer(obd);
2141 OBD_FREE(qdata, sizeof(struct qunit_data));
2145 #endif /* !__KERNEL__ */
2147 #endif /* HAVE_QUOTA_SUPPORT */
2149 ldlm_mode_t lck_compat_array[] = {
2150 [LCK_EX] LCK_COMPAT_EX,
2151 [LCK_PW] LCK_COMPAT_PW,
2152 [LCK_PR] LCK_COMPAT_PR,
2153 [LCK_CW] LCK_COMPAT_CW,
2154 [LCK_CR] LCK_COMPAT_CR,
2155 [LCK_NL] LCK_COMPAT_NL,
2156 [LCK_GROUP] LCK_COMPAT_GROUP