1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_LDLM
31 # include <libcfs/libcfs.h>
33 # include <liblustre.h>
36 #include <lustre_mds.h>
37 #include <lustre_dlm.h>
38 #include <lustre_net.h>
39 #include <lustre_ver.h>
41 /* @priority: if non-zero, move the selected to the list head
42 * @create: if zero, only search in existed connections
44 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
45 int priority, int create)
47 struct ptlrpc_connection *ptlrpc_conn;
48 struct obd_import_conn *imp_conn = NULL, *item;
52 if (!create && !priority) {
53 CDEBUG(D_HA, "Nothing to do\n");
57 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
59 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
64 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
66 GOTO(out_put, rc = -ENOMEM);
70 spin_lock(&imp->imp_lock);
71 list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
72 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
74 list_del(&item->oic_item);
75 list_add(&item->oic_item, &imp->imp_conn_list);
77 CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n",
78 imp, imp->imp_obd->obd_name, uuid->uuid,
79 (priority ? ", moved to head" : ""));
80 spin_unlock(&imp->imp_lock);
81 GOTO(out_free, rc = 0);
86 imp_conn->oic_conn = ptlrpc_conn;
87 imp_conn->oic_uuid = *uuid;
89 list_add(&imp_conn->oic_item, &imp->imp_conn_list);
91 list_add_tail(&imp_conn->oic_item, &imp->imp_conn_list);
92 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
93 imp, imp->imp_obd->obd_name, uuid->uuid,
94 (priority ? "head" : "tail"));
96 spin_unlock(&imp->imp_lock);
97 GOTO(out_free, rc = -ENOENT);
101 spin_unlock(&imp->imp_lock);
105 OBD_FREE(imp_conn, sizeof(*imp_conn));
107 ptlrpc_put_connection(ptlrpc_conn);
111 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
113 return import_set_conn(imp, uuid, 1, 0);
116 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
119 return import_set_conn(imp, uuid, priority, 1);
122 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
124 struct obd_import_conn *imp_conn;
125 struct obd_import_conn *cur_conn;
126 struct obd_export *dlmexp;
130 spin_lock(&imp->imp_lock);
131 if (list_empty(&imp->imp_conn_list)) {
132 LASSERT(!imp->imp_connection);
136 list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
137 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
139 LASSERT(imp_conn->oic_conn);
141 cur_conn = list_entry(imp->imp_conn_list.next,
142 struct obd_import_conn,
145 /* is current conn? */
146 if (imp_conn == cur_conn) {
147 LASSERT(imp_conn->oic_conn == imp->imp_connection);
149 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
150 imp->imp_state != LUSTRE_IMP_DISCON) {
151 CERROR("can't remove current connection\n");
152 GOTO(out, rc = -EBUSY);
155 ptlrpc_put_connection(imp->imp_connection);
156 imp->imp_connection = NULL;
158 dlmexp = class_conn2export(&imp->imp_dlm_handle);
159 if (dlmexp && dlmexp->exp_connection) {
160 LASSERT(dlmexp->exp_connection ==
162 ptlrpc_put_connection(dlmexp->exp_connection);
163 dlmexp->exp_connection = NULL;
167 list_del(&imp_conn->oic_item);
168 ptlrpc_put_connection(imp_conn->oic_conn);
169 OBD_FREE(imp_conn, sizeof(*imp_conn));
170 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
171 imp, imp->imp_obd->obd_name, uuid->uuid);
176 spin_unlock(&imp->imp_lock);
178 CERROR("connection %s not found\n", uuid->uuid);
182 /* configure an RPC client OBD device
187 * 3 - inactive-on-startup
189 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
191 struct client_obd *cli = &obddev->u.cli;
192 struct obd_import *imp;
193 struct obd_uuid server_uuid;
194 int rq_portal, rp_portal, connect_op;
195 char *name = obddev->obd_type->typ_name;
199 /* In a more perfect world, we would hang a ptlrpc_client off of
200 * obd_type and just use the values from there. */
201 if (!strcmp(name, LUSTRE_OSC_NAME)) {
202 rq_portal = OST_IO_PORTAL;
203 rp_portal = OSC_REPLY_PORTAL;
204 connect_op = OST_CONNECT;
205 } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
206 rq_portal = MDS_REQUEST_PORTAL;
207 rp_portal = MDC_REPLY_PORTAL;
208 connect_op = MDS_CONNECT;
209 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
210 rq_portal = MGS_REQUEST_PORTAL;
211 rp_portal = MGC_REPLY_PORTAL;
212 connect_op = MGS_CONNECT;
214 CERROR("unknown client OBD type \"%s\", can't setup\n",
219 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
220 CERROR("requires a TARGET UUID\n");
224 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
225 CERROR("client UUID must be less than 38 characters\n");
229 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
230 CERROR("setup requires a SERVER UUID\n");
234 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
235 CERROR("target UUID must be less than 38 characters\n");
239 sema_init(&cli->cl_sem, 1);
240 sema_init(&cli->cl_mgc_sem, 1);
241 cli->cl_conn_count = 0;
242 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
243 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
244 sizeof(server_uuid)));
247 cli->cl_avail_grant = 0;
248 /* FIXME: should limit this for the sum of all cl_dirty_max */
249 cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
250 if (cli->cl_dirty_max >> PAGE_SHIFT > num_physpages / 8)
251 cli->cl_dirty_max = num_physpages << (PAGE_SHIFT - 3);
252 CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters);
253 CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list);
254 CFS_INIT_LIST_HEAD(&cli->cl_loi_write_list);
255 CFS_INIT_LIST_HEAD(&cli->cl_loi_read_list);
256 client_obd_list_lock_init(&cli->cl_loi_list_lock);
257 cli->cl_r_in_flight = 0;
258 cli->cl_w_in_flight = 0;
260 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
261 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
262 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
263 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
264 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
265 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
266 cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES;
267 if (num_physpages >> (20 - PAGE_SHIFT) <= 128 /* MB */) {
268 cli->cl_max_rpcs_in_flight = 2;
269 } else if (num_physpages >> (20 - PAGE_SHIFT) <= 256 /* MB */) {
270 cli->cl_max_rpcs_in_flight = 3;
271 } else if (num_physpages >> (20 - PAGE_SHIFT) <= 512 /* MB */) {
272 cli->cl_max_rpcs_in_flight = 4;
274 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
279 CERROR("ldlm_get_ref failed: %d\n", rc);
283 ptlrpc_init_client(rq_portal, rp_portal, name,
284 &obddev->obd_ldlm_client);
286 imp = class_new_import(obddev);
288 GOTO(err_ldlm, rc = -ENOENT);
289 imp->imp_client = &obddev->obd_ldlm_client;
290 imp->imp_connect_op = connect_op;
291 imp->imp_initial_recov = 1;
292 imp->imp_initial_recov_bk = 0;
293 CFS_INIT_LIST_HEAD(&imp->imp_pinger_chain);
294 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
295 LUSTRE_CFG_BUFLEN(lcfg, 1));
296 class_import_put(imp);
298 rc = client_import_add_conn(imp, &server_uuid, 1);
300 CERROR("can't add initial connection\n");
301 GOTO(err_import, rc);
304 cli->cl_import = imp;
305 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
306 cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
307 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
308 cli->cl_sandev = to_kdev_t(0);
310 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
311 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
312 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
313 name, obddev->obd_name,
314 cli->cl_target_uuid.uuid);
315 imp->imp_invalid = 1;
319 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
324 class_destroy_import(imp);
332 int client_obd_cleanup(struct obd_device *obddev)
335 ldlm_put_ref(obddev->obd_force);
340 /* ->o_connect() method for client side (OSC and MDC and MGC) */
341 int client_connect_import(const struct lu_context *ctx,
342 struct lustre_handle *dlm_handle,
343 struct obd_device *obd, struct obd_uuid *cluuid,
344 struct obd_connect_data *data)
346 struct client_obd *cli = &obd->u.cli;
347 struct obd_import *imp = cli->cl_import;
348 struct obd_export *exp;
349 struct obd_connect_data *ocd;
353 mutex_down(&cli->cl_sem);
354 rc = class_connect(dlm_handle, obd, cluuid);
358 cli->cl_conn_count++;
359 if (cli->cl_conn_count > 1)
361 exp = class_conn2export(dlm_handle);
363 if (obd->obd_namespace != NULL)
364 CERROR("already have namespace!\n");
365 obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
366 LDLM_NAMESPACE_CLIENT);
367 if (obd->obd_namespace == NULL)
368 GOTO(out_disco, rc = -ENOMEM);
370 imp->imp_dlm_handle = *dlm_handle;
371 rc = ptlrpc_init_import(imp);
375 ocd = &imp->imp_connect_data;
378 imp->imp_connect_flags_orig = data->ocd_connect_flags;
381 rc = ptlrpc_connect_import(imp, NULL);
383 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
386 LASSERT(exp->exp_connection);
389 LASSERT((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
390 ocd->ocd_connect_flags);
391 data->ocd_connect_flags = ocd->ocd_connect_flags;
394 ptlrpc_pinger_add_import(imp);
400 ldlm_namespace_free(obd->obd_namespace, 0);
401 obd->obd_namespace = NULL;
403 cli->cl_conn_count--;
404 class_disconnect(exp);
406 class_export_put(exp);
409 mutex_up(&cli->cl_sem);
413 int client_disconnect_export(struct obd_export *exp)
415 struct obd_device *obd = class_exp2obd(exp);
416 struct client_obd *cli;
417 struct obd_import *imp;
422 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
423 exp, exp ? exp->exp_handle.h_cookie : -1);
428 imp = cli->cl_import;
430 mutex_down(&cli->cl_sem);
431 if (!cli->cl_conn_count) {
432 CERROR("disconnecting disconnected device (%s)\n",
434 GOTO(out_sem, rc = -EINVAL);
437 cli->cl_conn_count--;
438 if (cli->cl_conn_count)
439 GOTO(out_no_disconnect, rc = 0);
441 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
442 * delete it regardless. (It's safe to delete an import that was
444 (void)ptlrpc_pinger_del_import(imp);
446 if (obd->obd_namespace != NULL) {
447 /* obd_no_recov == local only */
448 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
449 obd->obd_no_recov, NULL);
450 ldlm_namespace_free(obd->obd_namespace, obd->obd_no_recov);
451 obd->obd_namespace = NULL;
454 /* Yeah, obd_no_recov also (mainly) means "forced shutdown". */
455 if (!obd->obd_no_recov)
456 rc = ptlrpc_disconnect_import(imp);
458 ptlrpc_invalidate_import(imp);
459 imp->imp_deactive = 1;
460 ptlrpc_free_rq_pool(imp->imp_rq_pool);
461 class_destroy_import(imp);
462 cli->cl_import = NULL;
466 err = class_disconnect(exp);
470 mutex_up(&cli->cl_sem);
474 /* --------------------------------------------------------------------------
475 * from old lib/target.c
476 * -------------------------------------------------------------------------- */
478 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
479 struct obd_uuid *cluuid)
482 if (exp->exp_connection && exp->exp_imp_reverse) {
483 struct lustre_handle *hdl;
484 hdl = &exp->exp_imp_reverse->imp_remote_handle;
485 /* Might be a re-connect after a partition. */
486 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
487 CWARN("%s: %s reconnecting\n", exp->exp_obd->obd_name,
489 conn->cookie = exp->exp_handle.h_cookie;
490 /* target_handle_connect() treats EALREADY and
491 * -EALREADY differently. EALREADY means we are
492 * doing a valid reconnect from the same client. */
495 CERROR("%s reconnecting from %s, "
496 "handle mismatch (ours "LPX64", theirs "
497 LPX64")\n", cluuid->uuid,
498 exp->exp_connection->c_remote_uuid.uuid,
499 hdl->cookie, conn->cookie);
500 memset(conn, 0, sizeof *conn);
501 /* target_handle_connect() treats EALREADY and
502 * -EALREADY differently. -EALREADY is an error
503 * (same UUID, different handle). */
508 conn->cookie = exp->exp_handle.h_cookie;
509 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
510 cluuid->uuid, exp, conn->cookie);
514 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler)
516 struct obd_device *target;
517 struct obd_export *export = NULL;
518 struct obd_import *revimp;
519 struct lustre_handle conn;
520 struct obd_uuid tgtuuid;
521 struct obd_uuid cluuid;
522 struct obd_uuid remote_uuid;
525 int rc = 0, abort_recovery;
527 struct obd_connect_data *data;
528 int size = sizeof(*data);
531 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
533 LASSERT_REQSWAB (req, 0);
534 str = lustre_msg_string(req->rq_reqmsg, 0, sizeof(tgtuuid) - 1);
536 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
537 GOTO(out, rc = -EINVAL);
540 obd_str2uuid (&tgtuuid, str);
541 target = class_uuid2obd(&tgtuuid);
543 /* old (pre 1.6) lustre_process_log tries to connect to mdsname
544 (eg. mdsA) instead of uuid. */
546 snprintf((char *)tgtuuid.uuid, sizeof(tgtuuid), "%s_UUID", str);
547 target = class_uuid2obd(&tgtuuid);
550 target = class_name2obd(str);
553 if (!target || target->obd_stopping || !target->obd_set_up) {
554 DEBUG_REQ(D_ERROR, req, "UUID '%s' is not available "
555 " for connect (%s)", str,
556 !target ? "no target" :
557 (target->obd_stopping ? "stopping" : "not set up"));
558 GOTO(out, rc = -ENODEV);
561 LASSERT_REQSWAB (req, 1);
562 str = lustre_msg_string(req->rq_reqmsg, 1, sizeof(cluuid) - 1);
564 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
565 GOTO(out, rc = -EINVAL);
568 obd_str2uuid (&cluuid, str);
570 /* XXX extract a nettype and format accordingly */
571 switch (sizeof(lnet_nid_t)) {
572 /* NB the casts only avoid compiler warnings */
574 snprintf(remote_uuid.uuid, sizeof remote_uuid,
575 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
578 snprintf(remote_uuid.uuid, sizeof remote_uuid,
579 "NET_%x_UUID", (__u32)req->rq_peer.nid);
585 spin_lock_bh(&target->obd_processing_task_lock);
586 abort_recovery = target->obd_abort_recovery;
587 spin_unlock_bh(&target->obd_processing_task_lock);
589 target_abort_recovery(target);
591 tmp = lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn);
593 GOTO(out, rc = -EPROTO);
595 memcpy(&conn, tmp, sizeof conn);
597 data = lustre_swab_reqbuf(req, 3, sizeof(*data), lustre_swab_connect);
598 rc = lustre_pack_reply(req, 1, &size, NULL);
602 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
604 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
605 "libclient connection attempt\n");
606 GOTO(out, rc = -EPROTO);
607 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
608 LUSTRE_VERSION_ALLOWED_OFFSET) {
609 DEBUG_REQ(D_WARNING, req, "Refusing old (%d.%d.%d.%d) "
610 "libclient connection attempt\n",
611 OBD_OCD_VERSION_MAJOR(data->ocd_version),
612 OBD_OCD_VERSION_MINOR(data->ocd_version),
613 OBD_OCD_VERSION_PATCH(data->ocd_version),
614 OBD_OCD_VERSION_FIX(data->ocd_version));
615 data = lustre_msg_buf(req->rq_repmsg, 0,
616 offsetof(typeof(*data),
618 sizeof(data->ocd_version));
620 data->ocd_connect_flags = OBD_CONNECT_VERSION;
621 data->ocd_version = LUSTRE_VERSION_CODE;
623 GOTO(out, rc = -EPROTO);
627 /* lctl gets a backstage, all-access pass. */
628 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
629 goto dont_check_exports;
631 spin_lock(&target->obd_dev_lock);
632 list_for_each(p, &target->obd_exports) {
633 export = list_entry(p, struct obd_export, exp_obd_chain);
634 if (obd_uuid_equals(&cluuid, &export->exp_client_uuid)) {
635 if (export->exp_connecting) { /* bug 9635, et. al. */
636 CWARN("%s: exp %p already connecting\n",
637 export->exp_obd->obd_name, export);
642 export->exp_connecting = 1;
643 spin_unlock(&target->obd_dev_lock);
644 LASSERT(export->exp_obd == target);
646 rc = target_handle_reconnect(&conn, export, &cluuid);
651 /* If we found an export, we already unlocked. */
653 spin_unlock(&target->obd_dev_lock);
654 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
655 } else if (req->rq_reqmsg->conn_cnt == 1) {
656 CERROR("%s: NID %s (%s) reconnected with 1 conn_cnt; "
657 "cookies not random?\n", target->obd_name,
658 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
659 GOTO(out, rc = -EALREADY);
661 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
664 /* We want to handle EALREADY but *not* -EALREADY from
665 * target_handle_reconnect(), return reconnection state in a flag */
666 if (rc == EALREADY) {
667 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
673 /* Tell the client if we're in recovery. */
674 /* If this is the first client, start the recovery timer */
675 if (target->obd_recovering) {
676 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
677 target_start_recovery_timer(target, handler);
680 /* Tell the client if we support replayable requests */
681 if (target->obd_replayable)
682 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
684 if (export == NULL) {
685 if (target->obd_recovering) {
686 CERROR("%s: denying connection for new client %s (%s): "
687 "%d clients in recovery for %lds\n",
689 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid,
690 target->obd_recoverable_clients,
691 cfs_duration_sec(cfs_time_sub(cfs_timer_deadline(&target->obd_recovery_timer),
692 cfs_time_current())));
696 rc = obd_connect(req->rq_svc_thread->t_ctx,
697 &conn, target, &cluuid, data);
700 rc = obd_reconnect(export, target, &cluuid, data);
706 /* Return only the parts of obd_connect_data that we understand, so the
707 * client knows that we don't understand the rest. */
709 memcpy(lustre_msg_buf(req->rq_repmsg, 0, sizeof(*data)), data,
712 /* If all else goes well, this is our RPC return code. */
715 req->rq_repmsg->handle = conn;
717 /* ownership of this export ref transfers to the request AFTER we
718 * drop any previous reference the request had, but we don't want
719 * that to go to zero before we get our new export reference. */
720 export = class_conn2export(&conn);
721 LASSERT(export != NULL);
723 /* If the client and the server are the same node, we will already
724 * have an export that really points to the client's DLM export,
725 * because we have a shared handles table.
727 * XXX this will go away when shaver stops sending the "connect" handle
728 * in the real "remote handle" field of the request --phik 24 Apr 2003
730 if (req->rq_export != NULL)
731 class_export_put(req->rq_export);
733 req->rq_export = export;
735 spin_lock_irqsave(&export->exp_lock, flags);
736 if (export->exp_conn_cnt >= req->rq_reqmsg->conn_cnt) {
737 CERROR("%s: %s already connected at higher conn_cnt: %d > %d\n",
738 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
739 export->exp_conn_cnt, req->rq_reqmsg->conn_cnt);
740 spin_unlock_irqrestore(&export->exp_lock, flags);
741 GOTO(out, rc = -EALREADY);
743 export->exp_conn_cnt = req->rq_reqmsg->conn_cnt;
744 spin_unlock_irqrestore(&export->exp_lock, flags);
746 /* request from liblustre? Don't evict it for not pinging. */
747 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
748 export->exp_libclient = 1;
749 spin_lock(&target->obd_dev_lock);
750 list_del_init(&export->exp_obd_chain_timed);
751 spin_unlock(&target->obd_dev_lock);
754 if (export->exp_connection != NULL)
755 ptlrpc_put_connection(export->exp_connection);
756 export->exp_connection = ptlrpc_get_connection(req->rq_peer,
760 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT)
763 if (target->obd_recovering)
764 target->obd_connected_clients++;
766 memcpy(&conn, lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn),
769 if (export->exp_imp_reverse != NULL)
770 class_destroy_import(export->exp_imp_reverse);
771 revimp = export->exp_imp_reverse = class_new_import(target);
772 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
773 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
774 revimp->imp_remote_handle = conn;
775 revimp->imp_dlm_fake = 1;
776 revimp->imp_state = LUSTRE_IMP_FULL;
777 class_import_put(revimp);
780 export->exp_connecting = 0;
786 int target_handle_disconnect(struct ptlrpc_request *req)
791 rc = lustre_pack_reply(req, 0, NULL, NULL);
795 /* keep the rq_export around so we can send the reply */
796 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
800 void target_destroy_export(struct obd_export *exp)
802 /* exports created from last_rcvd data, and "fake"
803 exports created by lctl don't have an import */
804 if (exp->exp_imp_reverse != NULL)
805 class_destroy_import(exp->exp_imp_reverse);
807 /* We cancel locks at disconnect time, but this will catch any locks
808 * granted in a race with recovery-induced disconnect. */
809 if (exp->exp_obd->obd_namespace != NULL)
810 ldlm_cancel_locks_for_export(exp);
818 static void target_release_saved_req(struct ptlrpc_request *req)
820 if (req->rq_reply_state != NULL) {
821 ptlrpc_rs_decref(req->rq_reply_state);
822 /* req->rq_reply_state = NULL; */
825 class_export_put(req->rq_export);
826 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
827 OBD_FREE(req, sizeof *req);
830 static void target_finish_recovery(struct obd_device *obd)
832 struct list_head *tmp, *n;
834 CWARN("%s: sending delayed replies to recovered clients\n",
837 ldlm_reprocess_all_ns(obd->obd_namespace);
839 /* when recovery finished, cleanup orphans on mds and ost */
840 if (OBT(obd) && OBP(obd, postrecov)) {
841 int rc = OBP(obd, postrecov)(obd);
842 CWARN("%s: recovery %s: rc %d\n", obd->obd_name,
843 rc < 0 ? "failed" : "complete", rc);
846 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
847 struct ptlrpc_request *req;
848 req = list_entry(tmp, struct ptlrpc_request, rq_list);
849 list_del(&req->rq_list);
850 DEBUG_REQ(D_WARNING, req, "delayed:");
852 target_release_saved_req(req);
854 obd->obd_recovery_end = CURRENT_SECONDS;
857 static void abort_recovery_queue(struct obd_device *obd)
859 struct ptlrpc_request *req;
860 struct list_head *tmp, *n;
863 list_for_each_safe(tmp, n, &obd->obd_recovery_queue) {
864 req = list_entry(tmp, struct ptlrpc_request, rq_list);
865 list_del(&req->rq_list);
866 DEBUG_REQ(D_ERROR, req, "aborted:");
867 req->rq_status = -ENOTCONN;
868 req->rq_type = PTL_RPC_MSG_ERR;
869 rc = lustre_pack_reply(req, 0, NULL, NULL);
873 DEBUG_REQ(D_ERROR, req,
874 "packing failed for abort-reply; skipping");
876 target_release_saved_req(req);
880 /* Called from a cleanup function if the device is being cleaned up
881 forcefully. The exports should all have been disconnected already,
882 the only thing left to do is
883 - clear the recovery flags
885 - free queued requests and replies, but don't send replies
886 Because the obd_stopping flag is set, no new requests should be received.
889 void target_cleanup_recovery(struct obd_device *obd)
891 struct list_head *tmp, *n;
892 struct ptlrpc_request *req;
895 LASSERT(obd->obd_stopping);
897 spin_lock_bh(&obd->obd_processing_task_lock);
898 if (!obd->obd_recovering) {
899 spin_unlock_bh(&obd->obd_processing_task_lock);
903 obd->obd_recovering = obd->obd_abort_recovery = 0;
904 target_cancel_recovery_timer(obd);
905 spin_unlock_bh(&obd->obd_processing_task_lock);
907 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
908 req = list_entry(tmp, struct ptlrpc_request, rq_list);
909 list_del(&req->rq_list);
910 target_release_saved_req(req);
913 list_for_each_safe(tmp, n, &obd->obd_recovery_queue) {
914 req = list_entry(tmp, struct ptlrpc_request, rq_list);
915 list_del(&req->rq_list);
916 target_release_saved_req(req);
921 void target_abort_recovery(void *data)
923 struct obd_device *obd = data;
926 spin_lock_bh(&obd->obd_processing_task_lock);
927 if (!obd->obd_recovering) {
928 spin_unlock_bh(&obd->obd_processing_task_lock);
932 obd->obd_recovering = obd->obd_abort_recovery = 0;
933 obd->obd_recoverable_clients = 0;
934 target_cancel_recovery_timer(obd);
935 spin_unlock_bh(&obd->obd_processing_task_lock);
937 CERROR("%s: recovery period over; disconnecting unfinished clients.\n",
939 class_disconnect_stale_exports(obd);
940 abort_recovery_queue(obd);
942 target_finish_recovery(obd);
944 ptlrpc_run_recovery_over_upcall(obd);
948 static void target_recovery_expired(unsigned long castmeharder)
950 struct obd_device *obd = (struct obd_device *)castmeharder;
951 CERROR("%s: recovery timed out, aborting\n", obd->obd_name);
952 spin_lock_bh(&obd->obd_processing_task_lock);
953 if (obd->obd_recovering)
954 obd->obd_abort_recovery = 1;
955 cfs_waitq_signal(&obd->obd_next_transno_waitq);
956 spin_unlock_bh(&obd->obd_processing_task_lock);
960 /* obd_processing_task_lock should be held */
961 void target_cancel_recovery_timer(struct obd_device *obd)
963 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
964 cfs_timer_disarm(&obd->obd_recovery_timer);
967 static void reset_recovery_timer(struct obd_device *obd)
969 spin_lock_bh(&obd->obd_processing_task_lock);
970 if (!obd->obd_recovering) {
971 spin_unlock_bh(&obd->obd_processing_task_lock);
974 cfs_timer_arm(&obd->obd_recovery_timer,
975 cfs_time_shift(OBD_RECOVERY_TIMEOUT));
976 spin_unlock_bh(&obd->obd_processing_task_lock);
977 CDEBUG(D_HA, "%s: timer will expire in %u seconds\n", obd->obd_name,
978 OBD_RECOVERY_TIMEOUT);
979 /* Only used for lprocfs_status */
980 obd->obd_recovery_end = CURRENT_SECONDS + OBD_RECOVERY_TIMEOUT;
984 /* Only start it the first time called */
985 void target_start_recovery_timer(struct obd_device *obd, svc_handler_t handler)
987 spin_lock_bh(&obd->obd_processing_task_lock);
988 if (obd->obd_recovery_handler) {
989 spin_unlock_bh(&obd->obd_processing_task_lock);
992 CWARN("%s: starting recovery timer (%us)\n", obd->obd_name,
993 OBD_RECOVERY_TIMEOUT);
994 obd->obd_recovery_handler = handler;
995 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
996 spin_unlock_bh(&obd->obd_processing_task_lock);
998 reset_recovery_timer(obd);
1001 static int check_for_next_transno(struct obd_device *obd)
1003 struct ptlrpc_request *req;
1004 int wake_up = 0, connected, completed, queue_len, max;
1005 __u64 next_transno, req_transno;
1007 spin_lock_bh(&obd->obd_processing_task_lock);
1008 req = list_entry(obd->obd_recovery_queue.next,
1009 struct ptlrpc_request, rq_list);
1010 max = obd->obd_max_recoverable_clients;
1011 req_transno = req->rq_reqmsg->transno;
1012 connected = obd->obd_connected_clients;
1013 completed = max - obd->obd_recoverable_clients;
1014 queue_len = obd->obd_requests_queued_for_recovery;
1015 next_transno = obd->obd_next_recovery_transno;
1017 CDEBUG(D_HA,"max: %d, connected: %d, completed: %d, queue_len: %d, "
1018 "req_transno: "LPU64", next_transno: "LPU64"\n",
1019 max, connected, completed, queue_len, req_transno, next_transno);
1020 if (obd->obd_abort_recovery) {
1021 CDEBUG(D_HA, "waking for aborted recovery\n");
1023 } else if (!obd->obd_recovering) {
1024 CDEBUG(D_HA, "waking for completed recovery (?)\n");
1026 } else if (req_transno == next_transno) {
1027 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1029 } else if (queue_len + completed == max) {
1031 "waking for skipped transno (skip: "LPD64
1032 ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
1033 next_transno, queue_len, completed, max, req_transno);
1034 obd->obd_next_recovery_transno = req_transno;
1037 spin_unlock_bh(&obd->obd_processing_task_lock);
1038 LASSERT(req->rq_reqmsg->transno >= next_transno);
1042 static void process_recovery_queue(struct obd_device *obd)
1044 struct ptlrpc_request *req;
1045 int abort_recovery = 0;
1046 struct l_wait_info lwi = { 0 };
1050 spin_lock_bh(&obd->obd_processing_task_lock);
1051 LASSERT(obd->obd_processing_task == cfs_curproc_pid());
1052 req = list_entry(obd->obd_recovery_queue.next,
1053 struct ptlrpc_request, rq_list);
1055 if (req->rq_reqmsg->transno != obd->obd_next_recovery_transno) {
1056 spin_unlock_bh(&obd->obd_processing_task_lock);
1057 CDEBUG(D_HA, "Waiting for transno "LPD64" (1st is "
1059 obd->obd_next_recovery_transno,
1060 req->rq_reqmsg->transno);
1061 l_wait_event(obd->obd_next_transno_waitq,
1062 check_for_next_transno(obd), &lwi);
1063 spin_lock_bh(&obd->obd_processing_task_lock);
1064 abort_recovery = obd->obd_abort_recovery;
1065 spin_unlock_bh(&obd->obd_processing_task_lock);
1066 if (abort_recovery) {
1067 target_abort_recovery(obd);
1072 list_del_init(&req->rq_list);
1073 obd->obd_requests_queued_for_recovery--;
1074 spin_unlock_bh(&obd->obd_processing_task_lock);
1076 DEBUG_REQ(D_HA, req, "processing: ");
1077 (void)obd->obd_recovery_handler(req);
1078 obd->obd_replayed_requests++;
1079 reset_recovery_timer(obd);
1080 /* bug 1580: decide how to properly sync() in recovery */
1081 //mds_fsync_super(obd->u.obt.obt_sb);
1082 class_export_put(req->rq_export);
1083 if (req->rq_reply_state != NULL) {
1084 ptlrpc_rs_decref(req->rq_reply_state);
1085 /* req->rq_reply_state = NULL; */
1087 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
1088 OBD_FREE(req, sizeof *req);
1089 spin_lock_bh(&obd->obd_processing_task_lock);
1090 obd->obd_next_recovery_transno++;
1091 if (list_empty(&obd->obd_recovery_queue)) {
1092 obd->obd_processing_task = 0;
1093 spin_unlock_bh(&obd->obd_processing_task_lock);
1096 spin_unlock_bh(&obd->obd_processing_task_lock);
1101 int target_queue_recovery_request(struct ptlrpc_request *req,
1102 struct obd_device *obd)
1104 struct list_head *tmp;
1106 __u64 transno = req->rq_reqmsg->transno;
1107 struct ptlrpc_request *saved_req;
1108 struct lustre_msg *reqmsg;
1110 /* CAVEAT EMPTOR: The incoming request message has been swabbed
1111 * (i.e. buflens etc are in my own byte order), but type-dependent
1112 * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
1115 CFS_INIT_LIST_HEAD(&req->rq_list);
1116 DEBUG_REQ(D_HA, req, "not queueing");
1120 /* XXX If I were a real man, these LBUGs would be sane cleanups. */
1121 /* XXX just like the request-dup code in queue_final_reply */
1122 OBD_ALLOC(saved_req, sizeof *saved_req);
1125 OBD_ALLOC(reqmsg, req->rq_reqlen);
1129 spin_lock_bh(&obd->obd_processing_task_lock);
1131 /* If we're processing the queue, we want don't want to queue this
1134 * Also, if this request has a transno less than the one we're waiting
1135 * for, we should process it now. It could (and currently always will)
1136 * be an open request for a descriptor that was opened some time ago.
1138 * Also, a resent, replayed request that has already been
1139 * handled will pass through here and be processed immediately.
1141 if (obd->obd_processing_task == cfs_curproc_pid() ||
1142 transno < obd->obd_next_recovery_transno) {
1143 /* Processing the queue right now, don't re-add. */
1144 LASSERT(list_empty(&req->rq_list));
1145 spin_unlock_bh(&obd->obd_processing_task_lock);
1146 OBD_FREE(reqmsg, req->rq_reqlen);
1147 OBD_FREE(saved_req, sizeof *saved_req);
1151 /* A resent, replayed request that is still on the queue; just drop it.
1152 The queued request will handle this. */
1153 if ((lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT|MSG_REPLAY)) ==
1154 (MSG_RESENT | MSG_REPLAY)) {
1155 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
1156 spin_unlock_bh(&obd->obd_processing_task_lock);
1157 OBD_FREE(reqmsg, req->rq_reqlen);
1158 OBD_FREE(saved_req, sizeof *saved_req);
1162 memcpy(saved_req, req, sizeof *req);
1163 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1165 req->rq_reqmsg = reqmsg;
1166 class_export_get(req->rq_export);
1167 CFS_INIT_LIST_HEAD(&req->rq_list);
1170 list_for_each(tmp, &obd->obd_recovery_queue) {
1171 struct ptlrpc_request *reqiter =
1172 list_entry(tmp, struct ptlrpc_request, rq_list);
1174 if (reqiter->rq_reqmsg->transno > transno) {
1175 list_add_tail(&req->rq_list, &reqiter->rq_list);
1182 list_add_tail(&req->rq_list, &obd->obd_recovery_queue);
1185 obd->obd_requests_queued_for_recovery++;
1187 if (obd->obd_processing_task != 0) {
1188 /* Someone else is processing this queue, we'll leave it to
1191 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1192 spin_unlock_bh(&obd->obd_processing_task_lock);
1196 /* Nobody is processing, and we know there's (at least) one to process
1197 * now, so we'll do the honours.
1199 obd->obd_processing_task = cfs_curproc_pid();
1200 spin_unlock_bh(&obd->obd_processing_task_lock);
1202 process_recovery_queue(obd);
1206 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1208 return req->rq_export->exp_obd;
1211 int target_queue_final_reply(struct ptlrpc_request *req, int rc)
1213 struct obd_device *obd = target_req2obd(req);
1214 struct ptlrpc_request *saved_req;
1215 struct lustre_msg *reqmsg;
1216 int recovery_done = 0;
1218 LASSERT ((rc == 0) == (req->rq_reply_state != NULL));
1221 /* Just like ptlrpc_error, but without the sending. */
1222 rc = lustre_pack_reply(req, 0, NULL, NULL);
1223 LASSERT(rc == 0); /* XXX handle this */
1224 req->rq_type = PTL_RPC_MSG_ERR;
1227 LASSERT (!req->rq_reply_state->rs_difficult);
1228 LASSERT(list_empty(&req->rq_list));
1229 /* XXX a bit like the request-dup code in queue_recovery_request */
1230 OBD_ALLOC(saved_req, sizeof *saved_req);
1233 OBD_ALLOC(reqmsg, req->rq_reqlen);
1237 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1239 /* Don't race cleanup */
1240 spin_lock_bh(&obd->obd_processing_task_lock);
1241 if (obd->obd_stopping) {
1242 spin_unlock_bh(&obd->obd_processing_task_lock);
1243 OBD_FREE(reqmsg, req->rq_reqlen);
1244 OBD_FREE(saved_req, sizeof *req);
1245 req->rq_status = -ENOTCONN;
1246 /* rv is ignored anyhow */
1249 ptlrpc_rs_addref(req->rq_reply_state); /* +1 ref for saved reply */
1251 req->rq_reqmsg = reqmsg;
1252 class_export_get(req->rq_export);
1253 list_add(&req->rq_list, &obd->obd_delayed_reply_queue);
1255 /* only count the first "replay over" request from each
1257 if (req->rq_export->exp_replay_needed) {
1258 --obd->obd_recoverable_clients;
1259 req->rq_export->exp_replay_needed = 0;
1261 recovery_done = (obd->obd_recoverable_clients == 0);
1262 spin_unlock_bh(&obd->obd_processing_task_lock);
1264 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
1265 if (recovery_done) {
1266 spin_lock_bh(&obd->obd_processing_task_lock);
1267 obd->obd_recovering = obd->obd_abort_recovery = 0;
1268 target_cancel_recovery_timer(obd);
1269 spin_unlock_bh(&obd->obd_processing_task_lock);
1271 target_finish_recovery(obd);
1272 ptlrpc_run_recovery_over_upcall(obd);
1274 CWARN("%s: %d recoverable clients remain\n",
1275 obd->obd_name, obd->obd_recoverable_clients);
1276 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1283 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1285 if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1286 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1287 DEBUG_REQ(D_ERROR, req, "dropping reply");
1292 DEBUG_REQ(D_ERROR, req, "processing error (%d)", rc);
1293 req->rq_status = rc;
1294 return (ptlrpc_error(req));
1296 DEBUG_REQ(D_NET, req, "sending reply");
1299 return (ptlrpc_send_reply(req, 1));
1303 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1306 unsigned long flags;
1307 struct ptlrpc_reply_state *rs;
1308 struct obd_device *obd;
1309 struct obd_export *exp;
1310 struct ptlrpc_service *svc;
1312 svc = req->rq_rqbd->rqbd_service;
1313 rs = req->rq_reply_state;
1314 if (rs == NULL || !rs->rs_difficult) {
1316 target_send_reply_msg (req, rc, fail_id);
1320 /* must be an export if locks saved */
1321 LASSERT (req->rq_export != NULL);
1322 /* req/reply consistent */
1323 LASSERT (rs->rs_service == svc);
1326 LASSERT (!rs->rs_scheduled);
1327 LASSERT (!rs->rs_scheduled_ever);
1328 LASSERT (!rs->rs_handled);
1329 LASSERT (!rs->rs_on_net);
1330 LASSERT (rs->rs_export == NULL);
1331 LASSERT (list_empty(&rs->rs_obd_list));
1332 LASSERT (list_empty(&rs->rs_exp_list));
1334 exp = class_export_get (req->rq_export);
1337 /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1338 rs->rs_scheduled = 1;
1340 rs->rs_xid = req->rq_xid;
1341 rs->rs_transno = req->rq_transno;
1342 rs->rs_export = exp;
1344 spin_lock_irqsave (&obd->obd_uncommitted_replies_lock, flags);
1346 if (rs->rs_transno > obd->obd_last_committed) {
1347 /* not committed already */
1348 list_add_tail (&rs->rs_obd_list,
1349 &obd->obd_uncommitted_replies);
1352 spin_unlock (&obd->obd_uncommitted_replies_lock);
1353 spin_lock (&exp->exp_lock);
1355 list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1357 spin_unlock_irqrestore (&exp->exp_lock, flags);
1359 netrc = target_send_reply_msg (req, rc, fail_id);
1361 spin_lock_irqsave (&svc->srv_lock, flags);
1363 svc->srv_n_difficult_replies++;
1366 /* error sending: reply is off the net. Also we need +1
1367 * reply ref until ptlrpc_server_handle_reply() is done
1368 * with the reply state (if the send was successful, there
1369 * would have been +1 ref for the net, which
1370 * reply_out_callback leaves alone) */
1372 ptlrpc_rs_addref(rs);
1373 atomic_inc (&svc->srv_outstanding_replies);
1376 if (!rs->rs_on_net || /* some notifier */
1377 list_empty(&rs->rs_exp_list) || /* completed already */
1378 list_empty(&rs->rs_obd_list)) {
1379 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
1380 cfs_waitq_signal (&svc->srv_waitq);
1382 list_add (&rs->rs_list, &svc->srv_active_replies);
1383 rs->rs_scheduled = 0; /* allow notifier to schedule */
1386 spin_unlock_irqrestore (&svc->srv_lock, flags);
1389 int target_handle_ping(struct ptlrpc_request *req)
1391 return lustre_pack_reply(req, 0, NULL, NULL);
1394 void target_committed_to_req(struct ptlrpc_request *req)
1396 struct obd_device *obd = req->rq_export->exp_obd;
1398 if (!obd->obd_no_transno && req->rq_repmsg != NULL)
1399 req->rq_repmsg->last_committed = obd->obd_last_committed;
1401 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update");
1403 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPU64"\n",
1404 obd->obd_last_committed, req->rq_xid);
1407 EXPORT_SYMBOL(target_committed_to_req);
1409 #ifdef HAVE_QUOTA_SUPPORT
1410 int target_handle_qc_callback(struct ptlrpc_request *req)
1412 struct obd_quotactl *oqctl;
1413 struct client_obd *cli = &req->rq_export->exp_obd->u.cli;
1415 oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl),
1416 lustre_swab_obd_quotactl);
1418 cli->cl_qchk_stat = oqctl->qc_stat;
1423 int target_handle_dqacq_callback(struct ptlrpc_request *req)
1426 struct obd_device *obd = req->rq_export->exp_obd;
1427 struct obd_device *master_obd;
1428 struct lustre_quota_ctxt *qctxt;
1429 struct qunit_data *qdata, *rep;
1430 int rc = 0, repsize = sizeof(struct qunit_data);
1433 rc = lustre_pack_reply(req, 1, &repsize, NULL);
1435 CERROR("packing reply failed!: rc = %d\n", rc);
1438 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
1441 qdata = lustre_swab_reqbuf(req, 0, sizeof(*qdata), lustre_swab_qdata);
1442 if (qdata == NULL) {
1443 CERROR("unpacking request buffer failed!");
1447 /* we use the observer */
1448 LASSERT(obd->obd_observer && obd->obd_observer->obd_observer);
1449 master_obd = obd->obd_observer->obd_observer;
1450 qctxt = &master_obd->u.obt.obt_qctxt;
1452 LASSERT(qctxt->lqc_handler);
1453 rc = qctxt->lqc_handler(master_obd, qdata, req->rq_reqmsg->opc);
1454 if (rc && rc != -EDQUOT)
1455 CDEBUG_EX(rc == -EBUSY ? D_QUOTA : D_ERROR,
1456 "dqacq failed! (rc:%d)\n", rc);
1458 /* the qd_count might be changed in lqc_handler */
1459 memcpy(rep, qdata, sizeof(*rep));
1460 req->rq_status = rc;
1461 rc = ptlrpc_reply(req);
1466 #endif /* !__KERNEL__ */
1468 #endif /* HAVE_QUOTA_SUPPORT */
1470 ldlm_mode_t lck_compat_array[] = {
1471 [LCK_EX] LCK_COMPAT_EX,
1472 [LCK_PW] LCK_COMPAT_PW,
1473 [LCK_PR] LCK_COMPAT_PR,
1474 [LCK_CW] LCK_COMPAT_CW,
1475 [LCK_CR] LCK_COMPAT_CR,
1476 [LCK_NL] LCK_COMPAT_NL,
1477 [LCK_GROUP] LCK_COMPAT_GROUP