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 2008 Sun Microsystems, Inc. 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_invalid = 1;
345 spin_unlock(&imp->imp_lock);
349 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
354 class_destroy_import(imp);
362 int client_obd_cleanup(struct obd_device *obddev)
369 /* ->o_connect() method for client side (OSC and MDC and MGC) */
370 int client_connect_import(struct lustre_handle *dlm_handle,
371 struct obd_device *obd, struct obd_uuid *cluuid,
372 struct obd_connect_data *data, void *localdata)
374 struct client_obd *cli = &obd->u.cli;
375 struct obd_import *imp = cli->cl_import;
376 struct obd_export **exp = localdata;
377 struct obd_connect_data *ocd;
378 struct ldlm_namespace *to_be_freed = NULL;
382 down_write(&cli->cl_sem);
383 if (cli->cl_conn_count > 0)
384 GOTO(out_sem, rc = -EALREADY);
386 rc = class_connect(dlm_handle, obd, cluuid);
390 cli->cl_conn_count++;
391 *exp = class_conn2export(dlm_handle);
393 if (obd->obd_namespace != NULL)
394 CERROR("already have namespace!\n");
395 obd->obd_namespace = ldlm_namespace_new(obd, obd->obd_name,
396 LDLM_NAMESPACE_CLIENT,
397 LDLM_NAMESPACE_GREEDY);
398 if (obd->obd_namespace == NULL)
399 GOTO(out_disco, rc = -ENOMEM);
401 imp->imp_dlm_handle = *dlm_handle;
402 rc = ptlrpc_init_import(imp);
406 ocd = &imp->imp_connect_data;
409 imp->imp_connect_flags_orig = data->ocd_connect_flags;
412 rc = ptlrpc_connect_import(imp, NULL);
414 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
417 LASSERT((*exp)->exp_connection);
420 LASSERT((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
421 ocd->ocd_connect_flags);
422 data->ocd_connect_flags = ocd->ocd_connect_flags;
425 ptlrpc_pinger_add_import(imp);
430 ldlm_namespace_free_prior(obd->obd_namespace, imp, 0);
431 to_be_freed = obd->obd_namespace;
432 obd->obd_namespace = NULL;
434 cli->cl_conn_count--;
435 class_disconnect(*exp);
439 up_write(&cli->cl_sem);
441 ldlm_namespace_free_post(to_be_freed);
445 int client_disconnect_export(struct obd_export *exp)
447 struct obd_device *obd = class_exp2obd(exp);
448 struct client_obd *cli;
449 struct obd_import *imp;
450 struct ldlm_namespace *to_be_freed = NULL;
455 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
456 exp, exp ? exp->exp_handle.h_cookie : -1);
461 imp = cli->cl_import;
463 down_write(&cli->cl_sem);
464 if (!cli->cl_conn_count) {
465 CERROR("disconnecting disconnected device (%s)\n",
467 GOTO(out_disconnect, rc = -EINVAL);
470 cli->cl_conn_count--;
471 if (cli->cl_conn_count)
472 GOTO(out_disconnect, rc = 0);
474 /* Mark import deactivated now, so we don't try to reconnect if any
475 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
476 * fully deactivate the import, or that would drop all requests. */
477 spin_lock(&imp->imp_lock);
478 imp->imp_deactive = 1;
479 spin_unlock(&imp->imp_lock);
481 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
482 * delete it regardless. (It's safe to delete an import that was
484 (void)ptlrpc_pinger_del_import(imp);
486 if (obd->obd_namespace != NULL) {
487 /* obd_force == local only */
488 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
489 obd->obd_force ? LDLM_FL_LOCAL_ONLY:0,
491 ldlm_namespace_free_prior(obd->obd_namespace, imp,
493 to_be_freed = obd->obd_namespace;
496 rc = ptlrpc_disconnect_import(imp, 0);
498 ptlrpc_invalidate_import(imp);
499 /* set obd_namespace to NULL only after invalidate, because we can have
500 * some connect requests in flight, and his need store a connect flags
501 * in obd_namespace. bug 14260 */
502 obd->obd_namespace = NULL;
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);
520 up_write(&cli->cl_sem);
522 ldlm_namespace_free_post(to_be_freed);
526 /* --------------------------------------------------------------------------
527 * from old lib/target.c
528 * -------------------------------------------------------------------------- */
530 static int target_handle_reconnect(struct lustre_handle *conn,
531 struct obd_export *exp,
532 struct obd_uuid *cluuid)
535 if (exp->exp_connection && exp->exp_imp_reverse) {
536 struct lustre_handle *hdl;
537 hdl = &exp->exp_imp_reverse->imp_remote_handle;
538 /* Might be a re-connect after a partition. */
539 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
540 CWARN("%s: %s reconnecting\n", exp->exp_obd->obd_name,
542 conn->cookie = exp->exp_handle.h_cookie;
543 /* target_handle_connect() treats EALREADY and
544 * -EALREADY differently. EALREADY means we are
545 * doing a valid reconnect from the same client. */
548 CERROR("%s reconnecting from %s, "
549 "handle mismatch (ours "LPX64", theirs "
550 LPX64")\n", cluuid->uuid,
551 exp->exp_connection->c_remote_uuid.uuid,
552 hdl->cookie, conn->cookie);
553 memset(conn, 0, sizeof *conn);
554 /* target_handle_connect() treats EALREADY and
555 * -EALREADY differently. -EALREADY is an error
556 * (same UUID, different handle). */
561 conn->cookie = exp->exp_handle.h_cookie;
562 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
563 cluuid->uuid, exp, conn->cookie);
567 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
570 struct obd_export *exp = cb_data;
572 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
573 obd->obd_name, exp->exp_client_uuid.uuid);
575 spin_lock(&exp->exp_lock);
576 exp->exp_need_sync = 0;
577 spin_unlock(&exp->exp_lock);
579 EXPORT_SYMBOL(target_client_add_cb);
582 target_start_and_reset_recovery_timer(struct obd_device *obd,
583 svc_handler_t handler,
584 struct ptlrpc_request *req,
586 void target_stop_recovery(void *, int);
587 static void reset_recovery_timer(struct obd_device *obd, int duration,
589 int target_recovery_check_and_stop(struct obd_device *obd)
591 int abort_recovery = 0;
593 spin_lock_bh(&obd->obd_processing_task_lock);
594 abort_recovery = obd->obd_abort_recovery;
595 obd->obd_abort_recovery = 0;
596 spin_unlock_bh(&obd->obd_processing_task_lock);
599 /** check is fs version-capable */
600 if (target_fs_version_capable(obd)) {
601 class_handle_stale_exports(obd);
603 CWARN("Versions are not supported by ldiskfs, VBR is OFF\n");
604 class_disconnect_stale_exports(obd, exp_flags_from_obd(obd));
606 /* VBR: no clients are remained to replay, stop recovery */
607 spin_lock_bh(&obd->obd_processing_task_lock);
608 if (obd->obd_recovering && obd->obd_recoverable_clients == 0) {
609 spin_unlock_bh(&obd->obd_processing_task_lock);
610 target_stop_recovery(obd, 0);
613 /* always check versions now */
614 obd->obd_version_recov = 1;
615 spin_unlock_bh(&obd->obd_processing_task_lock);
616 /* reset timer, recovery will proceed with versions now */
617 reset_recovery_timer(obd, OBD_RECOVERY_FACTOR * obd_timeout, 1);
620 EXPORT_SYMBOL(target_recovery_check_and_stop);
622 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler)
624 struct obd_device *target, *targref = NULL;
625 struct obd_export *export = NULL;
626 struct obd_import *revimp;
627 struct lustre_handle conn;
628 struct obd_uuid tgtuuid;
629 struct obd_uuid cluuid;
630 struct obd_uuid remote_uuid;
633 struct obd_connect_data *data;
634 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*data) };
635 lnet_nid_t *client_nid = NULL;
639 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
641 lustre_set_req_swabbed(req, REQ_REC_OFF);
642 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, sizeof(tgtuuid)-1);
644 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
645 GOTO(out, rc = -EINVAL);
648 obd_str2uuid (&tgtuuid, str);
649 target = class_uuid2obd(&tgtuuid);
651 /* old (pre 1.6) lustre_process_log tries to connect to mdsname
652 (eg. mdsA) instead of uuid. */
654 snprintf((char *)tgtuuid.uuid, sizeof(tgtuuid), "%s_UUID", str);
655 target = class_uuid2obd(&tgtuuid);
658 target = class_name2obd(str);
661 if (!target || target->obd_stopping || !target->obd_set_up) {
662 LCONSOLE_ERROR_MSG(0x137, "UUID '%s' is not available "
663 " for connect (%s)\n", str,
664 !target ? "no target" :
665 (target->obd_stopping ? "stopping" :
667 GOTO(out, rc = -ENODEV);
670 if (target->obd_no_conn) {
671 LCONSOLE_WARN("%s: temporarily refusing client connection "
672 "from %s\n", target->obd_name,
673 libcfs_nid2str(req->rq_peer.nid));
674 GOTO(out, rc = -EAGAIN);
677 /* Make sure the target isn't cleaned up while we're here. Yes,
678 there's still a race between the above check and our incref here.
679 Really, class_uuid2obd should take the ref. */
680 targref = class_incref(target);
682 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
683 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1,
686 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
687 GOTO(out, rc = -EINVAL);
690 obd_str2uuid (&cluuid, str);
692 /* XXX extract a nettype and format accordingly */
693 switch (sizeof(lnet_nid_t)) {
694 /* NB the casts only avoid compiler warnings */
696 snprintf(remote_uuid.uuid, sizeof remote_uuid,
697 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
700 snprintf(remote_uuid.uuid, sizeof remote_uuid,
701 "NET_%x_UUID", (__u32)req->rq_peer.nid);
707 target_recovery_check_and_stop(target);
709 tmp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn);
711 GOTO(out, rc = -EPROTO);
713 memcpy(&conn, tmp, sizeof conn);
715 data = lustre_swab_reqbuf(req, REQ_REC_OFF + 3, sizeof(*data),
716 lustre_swab_connect);
717 rc = lustre_pack_reply(req, 2, size, NULL);
721 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
723 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
724 "libclient connection attempt");
725 GOTO(out, rc = -EPROTO);
726 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
727 LUSTRE_VERSION_ALLOWED_OFFSET ||
728 data->ocd_version > LUSTRE_VERSION_CODE +
729 LUSTRE_VERSION_ALLOWED_OFFSET) {
730 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
731 "libclient connection attempt",
732 data->ocd_version < LUSTRE_VERSION_CODE ?
734 OBD_OCD_VERSION_MAJOR(data->ocd_version),
735 OBD_OCD_VERSION_MINOR(data->ocd_version),
736 OBD_OCD_VERSION_PATCH(data->ocd_version),
737 OBD_OCD_VERSION_FIX(data->ocd_version));
738 data = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
739 offsetof(typeof(*data),
741 sizeof(data->ocd_version));
743 data->ocd_connect_flags = OBD_CONNECT_VERSION;
744 data->ocd_version = LUSTRE_VERSION_CODE;
746 GOTO(out, rc = -EPROTO);
750 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL) &&
751 (data->ocd_connect_flags & OBD_CONNECT_MDS))
754 /* lctl gets a backstage, all-access pass. */
755 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
756 goto dont_check_exports;
758 export = lustre_hash_lookup(target->obd_uuid_hash, &cluuid);
762 /* we've found an export in the hash */
763 if (export->exp_connecting) {
764 /* bug 9635, et. al. */
765 CWARN("%s: exp %p already connecting\n",
766 export->exp_obd->obd_name, export);
767 class_export_put(export);
770 } else if (mds_conn && export->exp_connection) {
771 if (req->rq_peer.nid != export->exp_connection->c_peer.nid)
772 /* mds reconnected after failover */
773 CWARN("%s: received MDS connection from NID %s,"
774 " removing former export from NID %s\n",
775 target->obd_name, libcfs_nid2str(req->rq_peer.nid),
776 libcfs_nid2str(export->exp_connection->c_peer.nid));
778 /* new mds connection from the same nid */
779 CWARN("%s: received new MDS connection from NID %s,"
780 " removing former export from same NID\n",
781 target->obd_name, libcfs_nid2str(req->rq_peer.nid));
782 class_fail_export(export);
783 class_export_put(export);
786 } else if (export->exp_connection &&
787 req->rq_peer.nid != export->exp_connection->c_peer.nid) {
788 CWARN("%s: cookie %s seen on new NID %s when "
789 "existing NID %s is already connected\n",
790 target->obd_name, cluuid.uuid,
791 libcfs_nid2str(req->rq_peer.nid),
792 libcfs_nid2str(export->exp_connection->c_peer.nid));
794 class_export_put(export);
796 } else if (export->exp_failed) { /* bug 11327 */
797 CDEBUG(D_HA, "%s: exp %p evict in progress - new cookie needed "
798 "for connect\n", export->exp_obd->obd_name, export);
799 class_export_put(export);
802 } else if (export->exp_delayed &&
803 !(data && data->ocd_connect_flags & OBD_CONNECT_VBR)) {
804 class_fail_export(export);
805 class_export_put(export);
807 GOTO(out, rc = -ENODEV);
809 spin_lock(&export->exp_lock);
810 export->exp_connecting = 1;
811 spin_unlock(&export->exp_lock);
812 class_export_put(export);
813 LASSERT(export->exp_obd == target);
815 rc = target_handle_reconnect(&conn, export, &cluuid);
818 /* If we found an export, we already unlocked. */
821 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
822 } else if (req->rq_export == NULL &&
823 atomic_read(&export->exp_rpc_count) > 0) {
824 CWARN("%s: refuse connection from %s/%s to 0x%p; still busy "
825 "with %d references\n", target->obd_name, cluuid.uuid,
826 libcfs_nid2str(req->rq_peer.nid),
827 export, atomic_read(&export->exp_refcount));
828 GOTO(out, rc = -EBUSY);
829 } else if (req->rq_export != NULL &&
830 atomic_read(&export->exp_rpc_count) > 1) {
831 /* the current connect rpc has increased exp_rpc_count */
832 CWARN("%s: refuse reconnection from %s@%s to 0x%p; still busy "
833 "with %d active RPCs\n", target->obd_name, cluuid.uuid,
834 libcfs_nid2str(req->rq_peer.nid),
835 export, atomic_read(&export->exp_rpc_count) - 1);
836 spin_lock(&export->exp_lock);
837 if (req->rq_export->exp_conn_cnt <
838 lustre_msg_get_conn_cnt(req->rq_reqmsg))
839 /* try to abort active requests */
840 req->rq_export->exp_abort_active_req = 1;
841 spin_unlock(&export->exp_lock);
842 GOTO(out, rc = -EBUSY);
843 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
844 CERROR("%s: NID %s (%s) reconnected with 1 conn_cnt; "
845 "cookies not random?\n", target->obd_name,
846 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
847 GOTO(out, rc = -EALREADY);
848 } else if (export->exp_delayed && target->obd_recovering) {
849 /* VBR: don't allow delayed connection during recovery */
850 CWARN("%s: NID %s (%s) export was already marked as delayed "
851 "and will wait for end of recovery\n", target->obd_name,
852 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
853 GOTO(out, rc = -EBUSY);
855 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
861 /* Tell the client if we're in recovery. */
862 if (target->obd_recovering) {
863 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
864 /* If this is the first time a client connects,
865 reset the recovery timer */
867 target_start_and_reset_recovery_timer(target, handler,
871 /* We want to handle EALREADY but *not* -EALREADY from
872 * target_handle_reconnect(), return reconnection state in a flag */
873 if (rc == EALREADY) {
874 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
880 /* Tell the client if we support replayable requests */
881 if (target->obd_replayable)
882 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
883 client_nid = &req->rq_peer.nid;
885 /* VBR: for delayed connections we start recovery */
886 if (export && export->exp_delayed && !export->exp_in_recovery) {
887 LASSERT(!target->obd_recovering);
888 LASSERT(data && data->ocd_connect_flags & OBD_CONNECT_VBR);
889 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_DELAYED |
890 MSG_CONNECT_RECOVERING);
891 spin_lock_bh(&target->obd_processing_task_lock);
892 target->obd_version_recov = 1;
893 spin_unlock_bh(&target->obd_processing_task_lock);
894 target_start_and_reset_recovery_timer(target, handler, req, 1);
897 if (export == NULL) {
898 if (target->obd_recovering) {
899 CERROR("%s: denying connection for new client %s (%s): "
900 "%d clients in recovery for %lds\n",
902 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid,
903 target->obd_recoverable_clients,
904 cfs_duration_sec(cfs_time_sub(cfs_timer_deadline(&target->obd_recovery_timer),
905 cfs_time_current())));
909 rc = obd_connect(&conn, target, &cluuid, data,
913 rc = obd_reconnect(export, target, &cluuid, data, client_nid);
919 /* Return only the parts of obd_connect_data that we understand, so the
920 * client knows that we don't understand the rest. */
922 memcpy(lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
924 data, sizeof(*data));
926 /* If all else goes well, this is our RPC return code. */
929 lustre_msg_set_handle(req->rq_repmsg, &conn);
931 /* ownership of this export ref transfers to the request AFTER we
932 * drop any previous reference the request had, but we don't want
933 * that to go to zero before we get our new export reference. */
934 export = class_conn2export(&conn);
936 DEBUG_REQ(D_ERROR, req, "Missing export!");
937 GOTO(out, rc = -ENODEV);
940 /* If the client and the server are the same node, we will already
941 * have an export that really points to the client's DLM export,
942 * because we have a shared handles table.
944 * XXX this will go away when shaver stops sending the "connect" handle
945 * in the real "remote handle" field of the request --phik 24 Apr 2003
947 if (req->rq_export != NULL)
948 class_export_put(req->rq_export);
950 req->rq_export = export;
952 spin_lock(&export->exp_lock);
953 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
954 CERROR("%s: %s already connected at higher conn_cnt: %d > %d\n",
955 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
956 export->exp_conn_cnt,
957 lustre_msg_get_conn_cnt(req->rq_reqmsg));
959 spin_unlock(&export->exp_lock);
960 GOTO(out, rc = -EALREADY);
962 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
963 export->exp_abort_active_req = 0;
965 /* request from liblustre? Don't evict it for not pinging. */
966 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
967 export->exp_libclient = 1;
968 spin_unlock(&export->exp_lock);
970 spin_lock(&target->obd_dev_lock);
971 list_del_init(&export->exp_obd_chain_timed);
972 spin_unlock(&target->obd_dev_lock);
974 spin_unlock(&export->exp_lock);
977 if (export->exp_connection != NULL)
978 ptlrpc_connection_put(export->exp_connection);
979 export->exp_connection = ptlrpc_connection_get(req->rq_peer,
983 if (hlist_unhashed(&export->exp_nid_hash)) {
984 lustre_hash_add_unique(export->exp_obd->obd_nid_hash,
985 &export->exp_connection->c_peer.nid,
986 &export->exp_nid_hash);
989 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT) {
990 revimp = class_import_get(export->exp_imp_reverse);
991 GOTO(set_flags, rc = 0);
994 if (target->obd_recovering && !export->exp_in_recovery) {
995 spin_lock(&export->exp_lock);
996 export->exp_in_recovery = 1;
997 spin_unlock(&export->exp_lock);
998 target->obd_connected_clients++;
1001 lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn),
1004 if (export->exp_imp_reverse != NULL)
1005 class_destroy_import(export->exp_imp_reverse);
1006 revimp = export->exp_imp_reverse = class_new_import(target);
1007 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
1008 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
1009 revimp->imp_remote_handle = conn;
1010 revimp->imp_dlm_fake = 1;
1011 revimp->imp_state = LUSTRE_IMP_FULL;
1014 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V1 &&
1015 lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) {
1016 revimp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
1017 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_NEXT_VER);
1019 /* unknown versions will be caught in
1020 * ptlrpc_handle_server_req_in->lustre_unpack_msg() */
1021 revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
1024 if (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1) {
1025 if (export->exp_connect_flags & OBD_CONNECT_AT)
1026 revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1028 revimp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1031 class_import_put(revimp);
1034 spin_lock(&export->exp_lock);
1035 export->exp_connecting = 0;
1036 spin_unlock(&export->exp_lock);
1039 class_decref(targref);
1041 req->rq_status = rc;
1045 int target_handle_disconnect(struct ptlrpc_request *req)
1050 rc = lustre_pack_reply(req, 1, NULL, NULL);
1054 /* keep the rq_export around so we can send the reply */
1055 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
1059 void target_destroy_export(struct obd_export *exp)
1061 /* exports created from last_rcvd data, and "fake"
1062 exports created by lctl don't have an import */
1063 if (exp->exp_imp_reverse != NULL)
1064 class_destroy_import(exp->exp_imp_reverse);
1066 /* We cancel locks at disconnect time, but this will catch any locks
1067 * granted in a race with recovery-induced disconnect. */
1068 if (exp->exp_obd->obd_namespace != NULL)
1069 ldlm_cancel_locks_for_export(exp);
1073 * Recovery functions
1076 static int target_exp_enqueue_req_replay(struct ptlrpc_request *req)
1078 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1079 struct obd_export *exp = req->rq_export;
1080 struct ptlrpc_request *reqiter;
1085 spin_lock(&exp->exp_lock);
1086 list_for_each_entry(reqiter, &exp->exp_req_replay_queue,
1088 if (lustre_msg_get_transno(reqiter->rq_reqmsg) == transno) {
1095 /* we expect it with RESENT and REPLAY flags */
1096 if ((lustre_msg_get_flags(req->rq_reqmsg) &
1097 (MSG_RESENT | MSG_REPLAY)) != (MSG_RESENT | MSG_REPLAY))
1098 CERROR("invalid flags %x of resent replay\n",
1099 lustre_msg_get_flags(req->rq_reqmsg));
1101 list_add_tail(&req->rq_replay_list, &exp->exp_req_replay_queue);
1104 spin_unlock(&exp->exp_lock);
1108 static void target_exp_dequeue_req_replay(struct ptlrpc_request *req)
1110 LASSERT(!list_empty(&req->rq_replay_list));
1111 LASSERT(req->rq_export);
1113 spin_lock(&req->rq_export->exp_lock);
1114 list_del_init(&req->rq_replay_list);
1115 spin_unlock(&req->rq_export->exp_lock);
1118 static void target_release_saved_req(struct ptlrpc_request *req)
1120 ptlrpc_req_drop_rs(req);
1121 class_export_put(req->rq_export);
1122 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
1123 OBD_FREE(req, sizeof *req);
1126 static void target_send_delayed_replies(struct obd_device *obd)
1128 int max_clients = obd->obd_max_recoverable_clients;
1129 struct ptlrpc_request *req, *tmp;
1130 time_t elapsed_time = max_t(time_t, 1, cfs_time_current_sec() -
1131 obd->obd_recovery_start);
1133 LCONSOLE_INFO("%s: Recovery period over after %d:%.02d, of %d clients "
1134 "%d recovered and %d %s evicted.\n", obd->obd_name,
1135 (int)elapsed_time/60, (int)elapsed_time%60, max_clients,
1136 max_clients - obd->obd_recoverable_clients,
1137 obd->obd_stale_clients,
1138 obd->obd_stale_clients == 1 ? "was" : "were");
1140 LCONSOLE_INFO("%s: sending delayed replies to recovered clients\n",
1143 list_for_each_entry_safe(req, tmp, &obd->obd_delayed_reply_queue,
1145 list_del_init(&req->rq_list);
1146 DEBUG_REQ(D_HA, req, "delayed:");
1148 target_release_saved_req(req);
1150 obd->obd_recovery_end = cfs_time_current_sec();
1153 static void target_finish_recovery(struct obd_device *obd)
1155 OBD_RACE(OBD_FAIL_TGT_REPLAY_DELAY);
1157 ldlm_reprocess_all_ns(obd->obd_namespace);
1158 spin_lock_bh(&obd->obd_processing_task_lock);
1159 if (list_empty(&obd->obd_recovery_queue)) {
1160 obd->obd_recovery_thread = NULL;
1161 obd->obd_processing_task = 0;
1163 spin_unlock_bh(&obd->obd_processing_task_lock);
1164 CERROR("%s: Recovery queue isn't empty\n", obd->obd_name);
1167 spin_unlock_bh(&obd->obd_processing_task_lock);
1169 /* when recovery finished, cleanup orphans on mds and ost */
1170 if (OBT(obd) && OBP(obd, postrecov)) {
1171 int rc = OBP(obd, postrecov)(obd);
1173 LCONSOLE_WARN("%s: Post recovery failed, rc %d\n",
1176 target_send_delayed_replies(obd);
1179 static void abort_recovery_queue(struct obd_device *obd)
1181 struct ptlrpc_request *req, *n;
1182 struct list_head abort_list;
1185 CFS_INIT_LIST_HEAD(&abort_list);
1186 spin_lock_bh(&obd->obd_processing_task_lock);
1187 list_splice_init(&obd->obd_recovery_queue, &abort_list);
1188 spin_unlock_bh(&obd->obd_processing_task_lock);
1189 /* process abort list unlocked */
1190 list_for_each_entry_safe(req, n, &abort_list, rq_list) {
1191 target_exp_dequeue_req_replay(req);
1192 list_del_init(&req->rq_list);
1193 DEBUG_REQ(D_ERROR, req, "aborted:");
1194 req->rq_status = -ENOTCONN;
1195 req->rq_type = PTL_RPC_MSG_ERR;
1196 rc = lustre_pack_reply(req, 1, NULL, NULL);
1200 DEBUG_REQ(D_ERROR, req,
1201 "packing failed for abort-reply; skipping");
1202 target_release_saved_req(req);
1206 /* Called from a cleanup function if the device is being cleaned up
1207 forcefully. The exports should all have been disconnected already,
1208 the only thing left to do is
1209 - clear the recovery flags
1211 - free queued requests and replies, but don't send replies
1212 Because the obd_stopping flag is set, no new requests should be received.
1215 void target_cleanup_recovery(struct obd_device *obd)
1217 struct list_head *tmp, *n;
1218 struct ptlrpc_request *req;
1219 struct list_head clean_list;
1222 LASSERT(obd->obd_stopping);
1224 spin_lock_bh(&obd->obd_processing_task_lock);
1225 if (!obd->obd_recovering) {
1226 spin_unlock_bh(&obd->obd_processing_task_lock);
1230 obd->obd_recovering = obd->obd_abort_recovery = 0;
1231 target_cancel_recovery_timer(obd);
1232 spin_unlock_bh(&obd->obd_processing_task_lock);
1234 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
1235 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1236 list_del(&req->rq_list);
1237 target_release_saved_req(req);
1240 CFS_INIT_LIST_HEAD(&clean_list);
1241 spin_lock_bh(&obd->obd_processing_task_lock);
1242 list_splice_init(&obd->obd_recovery_queue, &clean_list);
1243 spin_unlock_bh(&obd->obd_processing_task_lock);
1244 list_for_each_safe(tmp, n, &clean_list) {
1245 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1246 target_exp_dequeue_req_replay(req);
1247 list_del_init(&req->rq_list);
1248 target_release_saved_req(req);
1253 void target_stop_recovery(void *data, int abort)
1255 struct obd_device *obd = data;
1256 enum obd_option flags;
1259 spin_lock_bh(&obd->obd_processing_task_lock);
1260 if (!obd->obd_recovering) {
1261 spin_unlock_bh(&obd->obd_processing_task_lock);
1265 flags = exp_flags_from_obd(obd) | OBD_OPT_ABORT_RECOV;
1266 obd->obd_recovering = 0;
1267 obd->obd_abort_recovery = 0;
1268 obd->obd_processing_task = 0;
1270 LASSERT(obd->obd_recoverable_clients == 0);
1272 target_cancel_recovery_timer(obd);
1273 spin_unlock_bh(&obd->obd_processing_task_lock);
1276 LCONSOLE_WARN("%s: recovery is aborted by administrative "
1277 "request; %d clients are not recovered "
1278 "(%d clients did)\n", obd->obd_name,
1279 obd->obd_recoverable_clients,
1280 obd->obd_connected_clients);
1281 class_disconnect_stale_exports(obd, flags);
1283 abort_recovery_queue(obd);
1284 target_finish_recovery(obd);
1285 CDEBUG(D_HA, "%s: recovery complete\n", obd_uuid2str(&obd->obd_uuid));
1289 void target_abort_recovery(void *data)
1291 target_stop_recovery(data, 1);
1294 static void reset_recovery_timer(struct obd_device *, int, int);
1295 static void target_recovery_expired(unsigned long castmeharder)
1297 struct obd_device *obd = (struct obd_device *)castmeharder;
1298 CDEBUG(D_HA, "%s: recovery period over; %d clients never reconnected "
1299 "after %lds (%d clients did)\n", obd->obd_name,
1300 obd->obd_recoverable_clients,
1301 cfs_time_current_sec() - obd->obd_recovery_start,
1302 obd->obd_connected_clients);
1304 spin_lock_bh(&obd->obd_processing_task_lock);
1305 obd->obd_abort_recovery = 1;
1306 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1307 spin_unlock_bh(&obd->obd_processing_task_lock);
1310 /* obd_processing_task_lock should be held */
1311 void target_cancel_recovery_timer(struct obd_device *obd)
1313 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1314 cfs_timer_disarm(&obd->obd_recovery_timer);
1317 /* extend = 1 means require at least "duration" seconds left in the timer,
1318 extend = 0 means set the total duration (start_recovery_timer) */
1319 static void reset_recovery_timer(struct obd_device *obd, int duration,
1322 cfs_time_t now = cfs_time_current_sec();
1323 cfs_duration_t left;
1325 spin_lock_bh(&obd->obd_processing_task_lock);
1326 if (!obd->obd_recovering) {
1327 spin_unlock_bh(&obd->obd_processing_task_lock);
1331 left = cfs_time_sub(obd->obd_recovery_end, now);
1333 if (extend && (duration > left))
1334 obd->obd_recovery_timeout += duration - left;
1335 else if (!extend && (duration > obd->obd_recovery_timeout))
1336 /* Track the client's largest expected replay time */
1337 obd->obd_recovery_timeout = duration;
1340 * If total recovery time already exceed the
1341 * obd_recovery_max_time, then CRAY XT3 will
1342 * abort the recovery
1344 if(obd->obd_recovery_timeout > obd->obd_recovery_max_time)
1345 obd->obd_recovery_timeout = obd->obd_recovery_max_time;
1347 obd->obd_recovery_end = obd->obd_recovery_start +
1348 obd->obd_recovery_timeout;
1349 if (cfs_time_before(now, obd->obd_recovery_end)) {
1350 left = cfs_time_sub(obd->obd_recovery_end, now);
1351 cfs_timer_arm(&obd->obd_recovery_timer, cfs_time_shift(left));
1353 spin_unlock_bh(&obd->obd_processing_task_lock);
1354 CDEBUG(D_HA, "%s: recovery timer will expire in %u seconds\n",
1355 obd->obd_name, (unsigned)left);
1358 static void check_and_start_recovery_timer(struct obd_device *obd,
1359 svc_handler_t handler)
1361 spin_lock_bh(&obd->obd_processing_task_lock);
1362 if (obd->obd_recovery_handler) {
1363 spin_unlock_bh(&obd->obd_processing_task_lock);
1366 CDEBUG(D_HA, "%s: starting recovery timer\n", obd->obd_name);
1367 obd->obd_recovery_start = cfs_time_current_sec();
1369 obd->obd_recovery_timeout = OBD_RECOVERY_FACTOR * obd_timeout;
1370 obd->obd_recovery_handler = handler;
1371 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
1372 spin_unlock_bh(&obd->obd_processing_task_lock);
1374 reset_recovery_timer(obd, obd->obd_recovery_timeout, 0);
1377 /* Reset the timer with each new client connection */
1379 * This timer is actually reconnect_timer, which is for making sure
1380 * the total recovery window is at least as big as my reconnect
1381 * attempt timing. So the initial recovery time_out will be set to
1382 * OBD_RECOVERY_FACTOR * obd_timeout. If the timeout coming
1383 * from client is bigger than this, then the recovery time_out will
1384 * be extend to make sure the client could be reconnected, in the
1385 * process, the timeout from the new client should be ignored.
1389 target_start_and_reset_recovery_timer(struct obd_device *obd,
1390 svc_handler_t handler,
1391 struct ptlrpc_request *req,
1394 int service_time = lustre_msg_get_service_time(req->rq_reqmsg);
1396 if (!new_client && service_time)
1397 /* Teach server about old server's estimates, as first guess
1398 at how long new requests will take. */
1399 at_add(&req->rq_rqbd->rqbd_service->srv_at_estimate,
1402 check_and_start_recovery_timer(obd, handler);
1404 /* convert the service time to rpc timeout,
1405 * reuse service_time to limit stack usage */
1406 service_time = at_est2timeout(service_time);
1408 /* We expect other clients to timeout within service_time, then try
1409 * to reconnect, then try the failover server. The max delay between
1410 * connect attempts is SWITCH_MAX + SWITCH_INC + INITIAL */
1411 service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
1412 INITIAL_CONNECT_TIMEOUT);
1413 if (service_time > obd->obd_recovery_timeout && !new_client)
1414 reset_recovery_timer(obd, service_time, 0);
1417 static int check_for_next_transno(struct obd_device *obd)
1419 struct ptlrpc_request *req;
1420 int wake_up = 0, connected, completed, queue_len, max;
1421 __u64 next_transno, req_transno;
1423 spin_lock_bh(&obd->obd_processing_task_lock);
1424 req = list_entry(obd->obd_recovery_queue.next,
1425 struct ptlrpc_request, rq_list);
1426 max = obd->obd_max_recoverable_clients;
1427 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1428 connected = obd->obd_connected_clients;
1429 completed = max - obd->obd_recoverable_clients -
1430 obd->obd_delayed_clients;
1431 queue_len = obd->obd_requests_queued_for_recovery;
1432 next_transno = obd->obd_next_recovery_transno;
1434 CDEBUG(D_HA,"max: %d, connected: %d, delayed %d, completed: %d, "
1435 "queue_len: %d, req_transno: "LPU64", next_transno: "LPU64"\n",
1436 max, connected, obd->obd_delayed_clients, completed, queue_len,
1437 req_transno, next_transno);
1438 if (obd->obd_abort_recovery) {
1439 CDEBUG(D_HA, "waking for aborted recovery\n");
1441 } else if (!obd->obd_recovering) {
1442 CDEBUG(D_HA, "waking for completed recovery (?)\n");
1444 } else if (req_transno == next_transno) {
1445 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1447 } else if (queue_len == obd->obd_recoverable_clients) {
1449 "waking for skipped transno (skip: "LPD64
1450 ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
1451 next_transno, queue_len, completed, max, req_transno);
1452 obd->obd_next_recovery_transno = req_transno;
1455 spin_unlock_bh(&obd->obd_processing_task_lock);
1456 LASSERT(lustre_msg_get_transno(req->rq_reqmsg) >= next_transno);
1460 static void process_recovery_queue(struct obd_device *obd)
1462 struct ptlrpc_request *req;
1463 struct l_wait_info lwi = { 0 };
1467 spin_lock_bh(&obd->obd_processing_task_lock);
1468 LASSERT(obd->obd_processing_task == cfs_curproc_pid());
1469 req = list_entry(obd->obd_recovery_queue.next,
1470 struct ptlrpc_request, rq_list);
1472 if (lustre_msg_get_transno(req->rq_reqmsg) !=
1473 obd->obd_next_recovery_transno) {
1474 spin_unlock_bh(&obd->obd_processing_task_lock);
1475 CDEBUG(D_HA, "Waiting for transno "LPD64" (1st is "
1476 LPD64", x"LPU64")\n",
1477 obd->obd_next_recovery_transno,
1478 lustre_msg_get_transno(req->rq_reqmsg),
1480 l_wait_event(obd->obd_next_transno_waitq,
1481 check_for_next_transno(obd), &lwi);
1482 if (target_recovery_check_and_stop(obd))
1486 list_del_init(&req->rq_list);
1487 LASSERT(obd->obd_recovery_thread);
1488 /* replace request initial thread with current one, bug #18221 */
1489 req->rq_svc_thread = obd->obd_recovery_thread;
1490 obd->obd_requests_queued_for_recovery--;
1491 spin_unlock_bh(&obd->obd_processing_task_lock);
1493 DEBUG_REQ(D_HA, req, "processing: ");
1494 (void)obd->obd_recovery_handler(req);
1495 obd->obd_replayed_requests++;
1496 /* Extend the recovery timer enough to complete the next
1498 reset_recovery_timer(obd, AT_OFF ? obd_timeout :
1499 at_get(&req->rq_rqbd->rqbd_service->srv_at_estimate), 1);
1500 /* bug 1580: decide how to properly sync() in recovery */
1501 //mds_fsync_super(obd->u.obt.obt_sb);
1502 spin_lock_bh(&obd->obd_processing_task_lock);
1503 obd->obd_next_recovery_transno++;
1504 spin_unlock_bh(&obd->obd_processing_task_lock);
1505 target_exp_dequeue_req_replay(req);
1506 class_export_put(req->rq_export);
1507 ptlrpc_req_drop_rs(req);
1508 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
1509 OBD_FREE(req, sizeof *req);
1510 OBD_RACE(OBD_FAIL_TGT_REPLAY_DELAY);
1511 spin_lock_bh(&obd->obd_processing_task_lock);
1512 if (list_empty(&obd->obd_recovery_queue)) {
1513 obd->obd_processing_task = 0;
1514 obd->obd_recovery_thread = NULL;
1515 spin_unlock_bh(&obd->obd_processing_task_lock);
1518 spin_unlock_bh(&obd->obd_processing_task_lock);
1523 int target_queue_recovery_request(struct ptlrpc_request *req,
1524 struct obd_device *obd)
1526 struct list_head *tmp;
1528 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1529 struct ptlrpc_request *saved_req;
1530 struct lustre_msg *reqmsg;
1533 /* CAVEAT EMPTOR: The incoming request message has been swabbed
1534 * (i.e. buflens etc are in my own byte order), but type-dependent
1535 * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
1538 CFS_INIT_LIST_HEAD(&req->rq_list);
1539 DEBUG_REQ(D_HA, req, "not queueing");
1543 /* XXX If I were a real man, these LBUGs would be sane cleanups. */
1544 /* XXX just like the request-dup code in queue_final_reply */
1545 OBD_ALLOC(saved_req, sizeof *saved_req);
1548 OBD_ALLOC(reqmsg, req->rq_reqlen);
1552 spin_lock_bh(&obd->obd_processing_task_lock);
1554 /* If we're processing the queue, we want don't want to queue this
1557 * Also, if this request has a transno less than the one we're waiting
1558 * for, we should process it now. It could (and currently always will)
1559 * be an open request for a descriptor that was opened some time ago.
1561 * Also, a resent, replayed request that has already been
1562 * handled will pass through here and be processed immediately.
1564 if (obd->obd_processing_task == cfs_curproc_pid() ||
1565 transno < obd->obd_next_recovery_transno) {
1566 /* Processing the queue right now, don't re-add. */
1567 LASSERT(list_empty(&req->rq_list));
1568 spin_unlock_bh(&obd->obd_processing_task_lock);
1569 GOTO(err_free, rc = 1);
1572 if (unlikely(OBD_FAIL_CHECK(OBD_FAIL_TGT_REPLAY_DROP))) {
1573 spin_unlock_bh(&obd->obd_processing_task_lock);
1574 GOTO(err_free, rc = 0);
1577 memcpy(saved_req, req, sizeof *req);
1578 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1580 req->rq_reqmsg = reqmsg;
1581 class_export_get(req->rq_export);
1582 CFS_INIT_LIST_HEAD(&req->rq_list);
1583 CFS_INIT_LIST_HEAD(&req->rq_replay_list);
1585 if (target_exp_enqueue_req_replay(req)) {
1586 spin_unlock_bh(&obd->obd_processing_task_lock);
1587 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
1588 GOTO(err_exp, rc = 0);
1592 list_for_each(tmp, &obd->obd_recovery_queue) {
1593 struct ptlrpc_request *reqiter =
1594 list_entry(tmp, struct ptlrpc_request, rq_list);
1596 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
1597 list_add_tail(&req->rq_list, &reqiter->rq_list);
1602 if (unlikely(lustre_msg_get_transno(reqiter->rq_reqmsg) ==
1604 spin_unlock_bh(&obd->obd_processing_task_lock);
1605 DEBUG_REQ(D_ERROR, req, "dropping replay: transno "
1606 "has been claimed by another client");
1607 target_exp_dequeue_req_replay(req);
1608 GOTO(err_exp, rc = 0);
1613 list_add_tail(&req->rq_list, &obd->obd_recovery_queue);
1616 obd->obd_requests_queued_for_recovery++;
1618 if (obd->obd_processing_task != 0) {
1619 /* Someone else is processing this queue, we'll leave it to
1622 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1623 spin_unlock_bh(&obd->obd_processing_task_lock);
1627 /* Nobody is processing, and we know there's (at least) one to process
1628 * now, so we'll do the honours.
1630 obd->obd_processing_task = cfs_curproc_pid();
1631 /* save thread that handle recovery queue */
1632 obd->obd_recovery_thread = req->rq_svc_thread;
1633 spin_unlock_bh(&obd->obd_processing_task_lock);
1635 process_recovery_queue(obd);
1639 class_export_put(req->rq_export);
1641 OBD_FREE(reqmsg, req->rq_reqlen);
1642 OBD_FREE(saved_req, sizeof(*saved_req));
1646 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1648 return req->rq_export->exp_obd;
1651 int target_queue_last_replay_reply(struct ptlrpc_request *req, int rc)
1653 struct obd_device *obd = target_req2obd(req);
1654 struct ptlrpc_request *saved_req;
1655 struct lustre_msg *reqmsg;
1656 struct obd_export *exp = req->rq_export;
1657 int recovery_done = 0, delayed_done = 0;
1659 LASSERT ((rc == 0) == req->rq_packed_final);
1661 if (!req->rq_packed_final) {
1662 /* Just like ptlrpc_error, but without the sending. */
1663 rc = lustre_pack_reply(req, 1, NULL, NULL);
1666 req->rq_type = PTL_RPC_MSG_ERR;
1669 LASSERT(!req->rq_reply_state->rs_difficult);
1670 LASSERT(list_empty(&req->rq_list));
1671 /* XXX a bit like the request-dup code in queue_recovery_request */
1672 OBD_ALLOC(saved_req, sizeof *saved_req);
1675 OBD_ALLOC(reqmsg, req->rq_reqlen);
1677 OBD_FREE(saved_req, sizeof *req);
1681 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1683 /* Don't race cleanup */
1684 spin_lock_bh(&obd->obd_processing_task_lock);
1685 if (obd->obd_stopping) {
1686 spin_unlock_bh(&obd->obd_processing_task_lock);
1690 if (!exp->exp_vbr_failed) {
1691 ptlrpc_rs_addref(req->rq_reply_state); /* +1 ref for saved reply */
1693 req->rq_reqmsg = reqmsg;
1694 CFS_INIT_LIST_HEAD(&req->rq_list);
1695 CFS_INIT_LIST_HEAD(&req->rq_replay_list);
1696 class_export_get(exp);
1697 list_add(&req->rq_list, &obd->obd_delayed_reply_queue);
1700 /* only count the first "replay over" request from each
1702 if (exp->exp_replay_needed) {
1703 spin_lock(&exp->exp_lock);
1704 exp->exp_replay_needed = 0;
1705 spin_unlock(&exp->exp_lock);
1707 if (!exp->exp_delayed) {
1708 --obd->obd_recoverable_clients;
1710 spin_lock(&exp->exp_lock);
1711 exp->exp_delayed = 0;
1712 spin_unlock(&exp->exp_lock);
1714 if (obd->obd_delayed_clients == 0) {
1715 spin_unlock_bh(&obd->obd_processing_task_lock);
1718 --obd->obd_delayed_clients;
1721 recovery_done = (obd->obd_recoverable_clients == 0);
1722 spin_unlock_bh(&obd->obd_processing_task_lock);
1725 /* start pinging export */
1726 spin_lock(&obd->obd_dev_lock);
1727 list_add_tail(&exp->exp_obd_chain_timed,
1728 &obd->obd_exports_timed);
1729 list_move_tail(&exp->exp_obd_chain, &obd->obd_exports);
1730 spin_unlock(&obd->obd_dev_lock);
1731 target_send_delayed_replies(obd);
1734 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
1735 if (recovery_done) {
1736 spin_lock_bh(&obd->obd_processing_task_lock);
1737 obd->obd_recovering = 0;
1738 obd->obd_version_recov = 0;
1739 obd->obd_abort_recovery = 0;
1740 target_cancel_recovery_timer(obd);
1741 spin_unlock_bh(&obd->obd_processing_task_lock);
1744 target_finish_recovery(obd);
1745 CDEBUG(D_HA, "%s: recovery complete\n",
1746 obd_uuid2str(&obd->obd_uuid));
1748 CWARN("%s: %d recoverable clients remain\n",
1749 obd->obd_name, obd->obd_recoverable_clients);
1750 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1753 /* VBR: disconnect export with failed recovery */
1754 if (exp->exp_vbr_failed) {
1755 CWARN("%s: disconnect export %s\n", obd->obd_name,
1756 exp->exp_client_uuid.uuid);
1757 class_fail_export(exp);
1758 OBD_FREE(reqmsg, req->rq_reqlen);
1759 OBD_FREE(saved_req, sizeof *req);
1761 ptlrpc_send_reply(req, 0);
1767 OBD_FREE(reqmsg, req->rq_reqlen);
1768 OBD_FREE(saved_req, sizeof *req);
1769 req->rq_status = -ENOTCONN;
1770 /* rv is ignored anyhow */
1774 int target_handle_reply(struct ptlrpc_request *req, int rc, int fail)
1776 struct obd_device *obd = NULL;
1779 obd = target_req2obd(req);
1781 /* handle replay reply for version recovery */
1782 if (obd && obd->obd_version_recov &&
1783 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)) {
1784 LASSERT(req->rq_repmsg);
1785 lustre_msg_add_flags(req->rq_repmsg, MSG_VERSION_REPLAY);
1788 /* handle last replay */
1789 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1791 lustre_msg_get_flags(req->rq_reqmsg) & MSG_DELAY_REPLAY) {
1792 DEBUG_REQ(D_HA, req,
1793 "delayed LAST_REPLAY, queuing reply");
1794 rc = target_queue_last_replay_reply(req, rc);
1795 LASSERT(req->rq_export->exp_delayed == 0);
1799 if (obd && obd->obd_recovering) { /* normal recovery */
1800 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1801 rc = target_queue_last_replay_reply(req, rc);
1805 /* Lost a race with recovery; let the error path DTRT. */
1806 rc = req->rq_status = -ENOTCONN;
1808 target_send_reply(req, rc, fail);
1812 static inline struct ldlm_pool *ldlm_exp2pl(struct obd_export *exp)
1814 LASSERT(exp != NULL);
1815 return &exp->exp_obd->obd_namespace->ns_pool;
1818 int target_pack_pool_reply(struct ptlrpc_request *req)
1820 struct obd_device *obd;
1824 * Check that we still have all structures alive as this may
1825 * be some late rpc in shutdown time.
1827 if (unlikely(!req->rq_export || !req->rq_export->exp_obd ||
1828 !exp_connect_lru_resize(req->rq_export))) {
1829 lustre_msg_set_slv(req->rq_repmsg, 0);
1830 lustre_msg_set_limit(req->rq_repmsg, 0);
1835 * OBD is alive here as export is alive, which we checked above.
1837 obd = req->rq_export->exp_obd;
1839 read_lock(&obd->obd_pool_lock);
1840 lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv);
1841 lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit);
1842 read_unlock(&obd->obd_pool_lock);
1848 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1850 if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1851 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1852 DEBUG_REQ(D_ERROR, req, "dropping reply");
1857 DEBUG_REQ(D_ERROR, req, "processing error (%d)", rc);
1858 req->rq_status = rc;
1859 return (ptlrpc_send_error(req, 1));
1861 DEBUG_REQ(D_NET, req, "sending reply");
1864 return (ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT));
1868 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1871 struct ptlrpc_reply_state *rs;
1872 struct obd_device *obd;
1873 struct obd_export *exp;
1874 struct ptlrpc_service *svc;
1876 svc = req->rq_rqbd->rqbd_service;
1877 rs = req->rq_reply_state;
1878 if (rs == NULL || !rs->rs_difficult) {
1880 target_send_reply_msg (req, rc, fail_id);
1884 /* must be an export if locks saved */
1885 LASSERT (req->rq_export != NULL);
1886 /* req/reply consistent */
1887 LASSERT (rs->rs_service == svc);
1890 LASSERT (!rs->rs_scheduled);
1891 LASSERT (!rs->rs_scheduled_ever);
1892 LASSERT (!rs->rs_handled);
1893 LASSERT (!rs->rs_on_net);
1894 LASSERT (rs->rs_export == NULL);
1895 LASSERT (list_empty(&rs->rs_obd_list));
1896 LASSERT (list_empty(&rs->rs_exp_list));
1898 exp = class_export_get(req->rq_export);
1901 /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1902 rs->rs_scheduled = 1;
1904 rs->rs_xid = req->rq_xid;
1905 rs->rs_transno = req->rq_transno;
1906 rs->rs_export = exp;
1908 spin_lock(&exp->exp_uncommitted_replies_lock);
1910 /* VBR: use exp_last_committed */
1911 if (rs->rs_transno > exp->exp_last_committed) {
1912 /* not committed already */
1913 list_add_tail (&rs->rs_obd_list,
1914 &exp->exp_uncommitted_replies);
1917 spin_unlock (&exp->exp_uncommitted_replies_lock);
1918 spin_lock (&exp->exp_lock);
1920 list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1922 spin_unlock(&exp->exp_lock);
1924 netrc = target_send_reply_msg (req, rc, fail_id);
1926 spin_lock(&svc->srv_lock);
1928 svc->srv_n_difficult_replies++;
1931 /* error sending: reply is off the net. Also we need +1
1932 * reply ref until ptlrpc_server_handle_reply() is done
1933 * with the reply state (if the send was successful, there
1934 * would have been +1 ref for the net, which
1935 * reply_out_callback leaves alone) */
1937 ptlrpc_rs_addref(rs);
1938 atomic_inc (&svc->srv_outstanding_replies);
1941 if (!rs->rs_on_net || /* some notifier */
1942 list_empty(&rs->rs_exp_list) || /* completed already */
1943 list_empty(&rs->rs_obd_list)) {
1944 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
1945 cfs_waitq_signal (&svc->srv_waitq);
1947 list_add (&rs->rs_list, &svc->srv_active_replies);
1948 rs->rs_scheduled = 0; /* allow notifier to schedule */
1951 spin_unlock(&svc->srv_lock);
1954 int target_handle_ping(struct ptlrpc_request *req)
1956 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY &&
1957 req->rq_export->exp_in_recovery) {
1958 spin_lock(&req->rq_export->exp_lock);
1959 req->rq_export->exp_in_recovery = 0;
1960 spin_unlock(&req->rq_export->exp_lock);
1962 obd_ping(req->rq_export);
1963 return lustre_pack_reply(req, 1, NULL, NULL);
1966 void target_committed_to_req(struct ptlrpc_request *req)
1968 struct obd_export *exp = req->rq_export;
1969 if (!exp->exp_obd->obd_no_transno && req->rq_repmsg != NULL) {
1970 lustre_msg_set_last_committed(req->rq_repmsg,
1971 exp->exp_last_committed);
1973 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update (%d/"
1974 "%d)", exp->exp_obd->obd_no_transno,
1975 req->rq_repmsg == NULL);
1977 CDEBUG(D_INFO, "last_committed x"LPU64", this req x"LPU64"\n",
1978 exp->exp_obd->obd_last_committed, req->rq_xid);
1981 EXPORT_SYMBOL(target_committed_to_req);
1983 int target_handle_qc_callback(struct ptlrpc_request *req)
1985 struct obd_quotactl *oqctl;
1986 struct client_obd *cli = &req->rq_export->exp_obd->u.cli;
1988 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1989 lustre_swab_obd_quotactl);
1990 if (oqctl == NULL) {
1991 CERROR("Can't unpack obd_quatactl\n");
1995 cli->cl_qchk_stat = oqctl->qc_stat;
2000 #ifdef HAVE_QUOTA_SUPPORT
2001 int target_handle_dqacq_callback(struct ptlrpc_request *req)
2004 struct obd_device *obd = req->rq_export->exp_obd;
2005 struct obd_device *master_obd;
2006 struct lustre_quota_ctxt *qctxt;
2007 struct qunit_data *qdata = NULL;
2009 int repsize[2] = { sizeof(struct ptlrpc_body), 0 };
2012 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_DROP_QUOTA_REQ))
2015 repsize[1] = quota_get_qunit_data_size(req->rq_export->
2018 rc = lustre_pack_reply(req, 2, repsize, NULL);
2022 LASSERT(req->rq_export);
2024 /* there are three forms of qunit(historic causes), so we need to
2025 * adjust qunits from slaves to the same form here */
2026 OBD_ALLOC(qdata, sizeof(struct qunit_data));
2029 rc = quota_get_qdata(req, qdata, QUOTA_REQUEST, QUOTA_EXPORT);
2031 CDEBUG(D_ERROR, "Can't unpack qunit_data(rc: %d)\n", rc);
2035 /* we use the observer */
2036 if (!obd->obd_observer || !obd->obd_observer->obd_observer) {
2037 CERROR("Can't find the observer, it is recovering\n");
2038 req->rq_status = -EAGAIN;
2039 GOTO(send_reply, rc = -EAGAIN);
2042 master_obd = obd->obd_observer->obd_observer;
2043 qctxt = &master_obd->u.obt.obt_qctxt;
2045 if (!qctxt->lqc_setup) {
2046 /* quota_type has not been processed yet, return EAGAIN
2047 * until we know whether or not quotas are supposed to
2049 CDEBUG(D_QUOTA, "quota_type not processed yet, return "
2051 req->rq_status = -EAGAIN;
2052 rc = ptlrpc_reply(req);
2056 LASSERT(qctxt->lqc_handler);
2057 rc = qctxt->lqc_handler(master_obd, qdata,
2058 lustre_msg_get_opc(req->rq_reqmsg));
2059 if (rc && rc != -EDQUOT)
2060 CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR,
2061 "dqacq failed! (rc:%d)\n", rc);
2062 req->rq_status = rc;
2064 /* there are three forms of qunit(historic causes), so we need to
2065 * adjust the same form to different forms slaves needed */
2066 rc = quota_copy_qdata(req, qdata, QUOTA_REPLY, QUOTA_EXPORT);
2068 CDEBUG(D_ERROR, "Can't pack qunit_data(rc: %d)\n", rc);
2072 /* Block the quota req. b=14840 */
2073 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_BLOCK_QUOTA_REQ, obd_timeout);
2075 rc = ptlrpc_reply(req);
2077 OBD_FREE(qdata, sizeof(struct qunit_data));
2081 #endif /* !__KERNEL__ */
2083 #endif /* HAVE_QUOTA_SUPPORT */
2085 ldlm_mode_t lck_compat_array[] = {
2086 [LCK_EX] LCK_COMPAT_EX,
2087 [LCK_PW] LCK_COMPAT_PW,
2088 [LCK_PR] LCK_COMPAT_PR,
2089 [LCK_CW] LCK_COMPAT_CW,
2090 [LCK_CR] LCK_COMPAT_CR,
2091 [LCK_NL] LCK_COMPAT_NL,
2092 [LCK_GROUP] LCK_COMPAT_GROUP