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>
40 /* @priority: if non-zero, move the selected to the list head
41 * @create: if zero, only search in existed connections
43 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
44 int priority, int create)
46 struct ptlrpc_connection *ptlrpc_conn;
47 struct obd_import_conn *imp_conn = NULL, *item;
51 if (!create && !priority) {
52 CDEBUG(D_HA, "Nothing to do\n");
56 ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
58 CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid);
63 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
65 GOTO(out_put, rc = -ENOMEM);
69 spin_lock(&imp->imp_lock);
70 list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
71 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
73 list_del(&item->oic_item);
74 list_add(&item->oic_item, &imp->imp_conn_list);
75 item->oic_last_attempt = 0;
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;
88 item->oic_last_attempt = 0;
90 list_add(&imp_conn->oic_item, &imp->imp_conn_list);
92 list_add_tail(&imp_conn->oic_item, &imp->imp_conn_list);
93 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
94 imp, imp->imp_obd->obd_name, uuid->uuid,
95 (priority ? "head" : "tail"));
97 spin_unlock(&imp->imp_lock);
98 GOTO(out_free, rc = -ENOENT);
102 spin_unlock(&imp->imp_lock);
106 OBD_FREE(imp_conn, sizeof(*imp_conn));
108 ptlrpc_put_connection(ptlrpc_conn);
112 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
114 return import_set_conn(imp, uuid, 1, 0);
117 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
120 return import_set_conn(imp, uuid, priority, 1);
123 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
125 struct obd_import_conn *imp_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 /* is current conn? */
142 if (imp_conn == imp->imp_conn_current) {
143 LASSERT(imp_conn->oic_conn == imp->imp_connection);
145 if (imp->imp_state != LUSTRE_IMP_CLOSED &&
146 imp->imp_state != LUSTRE_IMP_DISCON) {
147 CERROR("can't remove current connection\n");
148 GOTO(out, rc = -EBUSY);
151 ptlrpc_put_connection(imp->imp_connection);
152 imp->imp_connection = NULL;
154 dlmexp = class_conn2export(&imp->imp_dlm_handle);
155 if (dlmexp && dlmexp->exp_connection) {
156 LASSERT(dlmexp->exp_connection ==
158 ptlrpc_put_connection(dlmexp->exp_connection);
159 dlmexp->exp_connection = NULL;
163 list_del(&imp_conn->oic_item);
164 ptlrpc_put_connection(imp_conn->oic_conn);
165 OBD_FREE(imp_conn, sizeof(*imp_conn));
166 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
167 imp, imp->imp_obd->obd_name, uuid->uuid);
172 spin_unlock(&imp->imp_lock);
174 CERROR("connection %s not found\n", uuid->uuid);
178 /* configure an RPC client OBD device
183 * 3 - inactive-on-startup
185 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
187 struct lustre_cfg* lcfg = buf;
188 struct client_obd *cli = &obddev->u.cli;
189 struct obd_import *imp;
190 struct obd_uuid server_uuid;
191 int rq_portal, rp_portal, connect_op;
192 char *name = obddev->obd_type->typ_name;
196 /* In a more perfect world, we would hang a ptlrpc_client off of
197 * obd_type and just use the values from there. */
198 if (!strcmp(name, LUSTRE_OSC_NAME)) {
200 /* Can be removed in Lustre 1.8, for compatibility only */
201 rq_portal = OST_IO_PORTAL;
203 rq_portal = OST_REQUEST_PORTAL;
205 rp_portal = OSC_REPLY_PORTAL;
206 connect_op = OST_CONNECT;
207 } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
208 rq_portal = MDS_REQUEST_PORTAL;
209 rp_portal = MDC_REPLY_PORTAL;
210 connect_op = MDS_CONNECT;
211 } else if (!strcmp(name, LUSTRE_MGC_NAME)) {
212 rq_portal = MGS_REQUEST_PORTAL;
213 rp_portal = MGC_REPLY_PORTAL;
214 connect_op = MGS_CONNECT;
216 CERROR("unknown client OBD type \"%s\", can't setup\n",
221 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
222 CERROR("requires a TARGET UUID\n");
226 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
227 CERROR("client UUID must be less than 38 characters\n");
231 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
232 CERROR("setup requires a SERVER UUID\n");
236 if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
237 CERROR("target UUID must be less than 38 characters\n");
241 sema_init(&cli->cl_sem, 1);
242 sema_init(&cli->cl_mgc_sem, 1);
243 cli->cl_conn_count = 0;
244 memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
245 min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
246 sizeof(server_uuid)));
249 cli->cl_avail_grant = 0;
250 /* FIXME: should limit this for the sum of all cl_dirty_max */
251 cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
252 if (cli->cl_dirty_max >> CFS_PAGE_SHIFT > num_physpages / 8)
253 cli->cl_dirty_max = num_physpages << (CFS_PAGE_SHIFT - 3);
254 CFS_INIT_LIST_HEAD(&cli->cl_cache_waiters);
255 CFS_INIT_LIST_HEAD(&cli->cl_loi_ready_list);
256 CFS_INIT_LIST_HEAD(&cli->cl_loi_write_list);
257 CFS_INIT_LIST_HEAD(&cli->cl_loi_read_list);
258 client_obd_list_lock_init(&cli->cl_loi_list_lock);
259 cli->cl_r_in_flight = 0;
260 cli->cl_w_in_flight = 0;
261 spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
262 spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
263 spin_lock_init(&cli->cl_read_page_hist.oh_lock);
264 spin_lock_init(&cli->cl_write_page_hist.oh_lock);
265 spin_lock_init(&cli->cl_read_offset_hist.oh_lock);
266 spin_lock_init(&cli->cl_write_offset_hist.oh_lock);
268 /* This value may be changed at connect time in
269 ptlrpc_connect_interpret. */
270 cli->cl_max_pages_per_rpc = min((int)PTLRPC_MAX_BRW_PAGES,
271 (int)(1024 * 1024 >> CFS_PAGE_SHIFT));
273 if (!strcmp(name, LUSTRE_MDC_NAME)) {
274 cli->cl_max_rpcs_in_flight = MDC_MAX_RIF_DEFAULT;
275 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 128 /* MB */) {
276 cli->cl_max_rpcs_in_flight = 2;
277 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 256 /* MB */) {
278 cli->cl_max_rpcs_in_flight = 3;
279 } else if (num_physpages >> (20 - CFS_PAGE_SHIFT) <= 512 /* MB */) {
280 cli->cl_max_rpcs_in_flight = 4;
282 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
286 CERROR("ldlm_get_ref failed: %d\n", rc);
290 ptlrpc_init_client(rq_portal, rp_portal, name,
291 &obddev->obd_ldlm_client);
293 imp = class_new_import(obddev);
295 GOTO(err_ldlm, rc = -ENOENT);
296 imp->imp_client = &obddev->obd_ldlm_client;
297 imp->imp_connect_op = connect_op;
298 imp->imp_initial_recov = 1;
299 imp->imp_initial_recov_bk = 0;
300 CFS_INIT_LIST_HEAD(&imp->imp_pinger_chain);
301 memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
302 LUSTRE_CFG_BUFLEN(lcfg, 1));
303 class_import_put(imp);
305 rc = client_import_add_conn(imp, &server_uuid, 1);
307 CERROR("can't add initial connection\n");
308 GOTO(err_import, rc);
311 cli->cl_import = imp;
312 /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */
313 cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
314 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
316 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
317 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
318 CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
319 name, obddev->obd_name,
320 cli->cl_target_uuid.uuid);
321 imp->imp_invalid = 1;
325 cli->cl_qchk_stat = CL_NOT_QUOTACHECKED;
330 class_destroy_import(imp);
338 int client_obd_cleanup(struct obd_device *obddev)
341 ldlm_put_ref(obddev->obd_force);
346 /* ->o_connect() method for client side (OSC and MDC and MGC) */
347 int client_connect_import(struct lustre_handle *dlm_handle,
348 struct obd_device *obd, struct obd_uuid *cluuid,
349 struct obd_connect_data *data)
351 struct client_obd *cli = &obd->u.cli;
352 struct obd_import *imp = cli->cl_import;
353 struct obd_export *exp;
354 struct obd_connect_data *ocd;
358 mutex_down(&cli->cl_sem);
359 rc = class_connect(dlm_handle, obd, cluuid);
363 cli->cl_conn_count++;
364 if (cli->cl_conn_count > 1)
366 exp = class_conn2export(dlm_handle);
368 if (obd->obd_namespace != NULL)
369 CERROR("already have namespace!\n");
370 obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
371 LDLM_NAMESPACE_CLIENT);
372 if (obd->obd_namespace == NULL)
373 GOTO(out_disco, rc = -ENOMEM);
375 imp->imp_dlm_handle = *dlm_handle;
376 rc = ptlrpc_init_import(imp);
380 ocd = &imp->imp_connect_data;
383 imp->imp_connect_flags_orig = data->ocd_connect_flags;
386 rc = ptlrpc_connect_import(imp, NULL);
388 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
391 LASSERT(exp->exp_connection);
394 LASSERT((ocd->ocd_connect_flags & data->ocd_connect_flags) ==
395 ocd->ocd_connect_flags);
396 data->ocd_connect_flags = ocd->ocd_connect_flags;
399 ptlrpc_pinger_add_import(imp);
404 ldlm_namespace_free(obd->obd_namespace, 0);
405 obd->obd_namespace = NULL;
407 cli->cl_conn_count--;
408 class_disconnect(exp);
410 class_export_put(exp);
413 mutex_up(&cli->cl_sem);
417 int client_disconnect_export(struct obd_export *exp)
419 struct obd_device *obd = class_exp2obd(exp);
420 struct client_obd *cli;
421 struct obd_import *imp;
426 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
427 exp, exp ? exp->exp_handle.h_cookie : -1);
432 imp = cli->cl_import;
434 mutex_down(&cli->cl_sem);
435 if (!cli->cl_conn_count) {
436 CERROR("disconnecting disconnected device (%s)\n",
438 GOTO(out_sem, rc = -EINVAL);
441 cli->cl_conn_count--;
442 if (cli->cl_conn_count)
443 GOTO(out_no_disconnect, rc = 0);
445 /* Mark import deactivated now, so we don't try to reconnect if any
446 * of the cleanup RPCs fails (e.g. ldlm cancel, etc). We don't
447 * fully deactivate the import, or that would drop all requests. */
448 imp->imp_deactive = 1;
450 /* Some non-replayable imports (MDS's OSCs) are pinged, so just
451 * delete it regardless. (It's safe to delete an import that was
453 (void)ptlrpc_pinger_del_import(imp);
455 if (obd->obd_namespace != NULL) {
456 /* obd_no_recov == local only */
457 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
458 obd->obd_no_recov ? LDLM_FL_LOCAL_ONLY:0,
460 ldlm_namespace_free(obd->obd_namespace, obd->obd_no_recov);
461 obd->obd_namespace = NULL;
464 /* Yeah, obd_no_recov also (mainly) means "forced shutdown". */
465 if (!obd->obd_no_recov)
466 rc = ptlrpc_disconnect_import(imp, 0);
468 ptlrpc_invalidate_import(imp);
469 ptlrpc_free_rq_pool(imp->imp_rq_pool);
470 class_destroy_import(imp);
471 cli->cl_import = NULL;
475 err = class_disconnect(exp);
479 mutex_up(&cli->cl_sem);
483 /* --------------------------------------------------------------------------
484 * from old lib/target.c
485 * -------------------------------------------------------------------------- */
487 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
488 struct obd_uuid *cluuid)
491 if (exp->exp_connection && exp->exp_imp_reverse) {
492 struct lustre_handle *hdl;
493 hdl = &exp->exp_imp_reverse->imp_remote_handle;
494 /* Might be a re-connect after a partition. */
495 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
496 CWARN("%s: %s reconnecting\n", exp->exp_obd->obd_name,
498 conn->cookie = exp->exp_handle.h_cookie;
499 /* target_handle_connect() treats EALREADY and
500 * -EALREADY differently. EALREADY means we are
501 * doing a valid reconnect from the same client. */
504 CERROR("%s reconnecting from %s, "
505 "handle mismatch (ours "LPX64", theirs "
506 LPX64")\n", cluuid->uuid,
507 exp->exp_connection->c_remote_uuid.uuid,
508 hdl->cookie, conn->cookie);
509 memset(conn, 0, sizeof *conn);
510 /* target_handle_connect() treats EALREADY and
511 * -EALREADY differently. -EALREADY is an error
512 * (same UUID, different handle). */
517 conn->cookie = exp->exp_handle.h_cookie;
518 CDEBUG(D_HA, "connect export for UUID '%s' at %p, cookie "LPX64"\n",
519 cluuid->uuid, exp, conn->cookie);
523 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
526 struct obd_export *exp = cb_data;
528 CDEBUG(D_HA, "%s: committing for initial connect of %s\n",
529 obd->obd_name, exp->exp_client_uuid.uuid);
530 exp->exp_need_sync = 0;
532 EXPORT_SYMBOL(target_client_add_cb);
534 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler)
536 struct obd_device *target, *targref = NULL;
537 struct obd_export *export = NULL;
538 struct obd_import *revimp;
539 struct lustre_handle conn;
540 struct obd_uuid tgtuuid;
541 struct obd_uuid cluuid;
542 struct obd_uuid remote_uuid;
544 int rc = 0, abort_recovery;
545 struct obd_connect_data *data;
546 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*data) };
549 OBD_RACE(OBD_FAIL_TGT_CONN_RACE);
551 LASSERT_REQSWAB(req, REQ_REC_OFF);
552 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, sizeof(tgtuuid)-1);
554 DEBUG_REQ(D_ERROR, req, "bad target UUID for connect");
555 GOTO(out, rc = -EINVAL);
558 obd_str2uuid (&tgtuuid, str);
559 target = class_uuid2obd(&tgtuuid);
561 /* old (pre 1.6) lustre_process_log tries to connect to mdsname
562 (eg. mdsA) instead of uuid. */
564 snprintf((char *)tgtuuid.uuid, sizeof(tgtuuid), "%s_UUID", str);
565 target = class_uuid2obd(&tgtuuid);
568 target = class_name2obd(str);
571 if (!target || target->obd_stopping || !target->obd_set_up) {
572 DEBUG_REQ(D_ERROR, req, "UUID '%s' is not available "
573 " for connect (%s)", str,
574 !target ? "no target" :
575 (target->obd_stopping ? "stopping" : "not set up"));
576 GOTO(out, rc = -ENODEV);
579 /* Make sure the target isn't cleaned up while we're here. Yes,
580 there's still a race between the above check and our incref here.
581 Really, class_uuid2obd should take the ref. */
582 targref = class_incref(target);
584 LASSERT_REQSWAB(req, REQ_REC_OFF + 1);
585 str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1,
588 DEBUG_REQ(D_ERROR, req, "bad client UUID for connect");
589 GOTO(out, rc = -EINVAL);
592 obd_str2uuid (&cluuid, str);
594 /* XXX extract a nettype and format accordingly */
595 switch (sizeof(lnet_nid_t)) {
596 /* NB the casts only avoid compiler warnings */
598 snprintf(remote_uuid.uuid, sizeof remote_uuid,
599 "NET_"LPX64"_UUID", (__u64)req->rq_peer.nid);
602 snprintf(remote_uuid.uuid, sizeof remote_uuid,
603 "NET_%x_UUID", (__u32)req->rq_peer.nid);
609 spin_lock_bh(&target->obd_processing_task_lock);
610 abort_recovery = target->obd_abort_recovery;
611 spin_unlock_bh(&target->obd_processing_task_lock);
613 target_abort_recovery(target);
615 tmp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn);
617 GOTO(out, rc = -EPROTO);
619 memcpy(&conn, tmp, sizeof conn);
621 data = lustre_swab_reqbuf(req, REQ_REC_OFF + 3, sizeof(*data),
622 lustre_swab_connect);
623 rc = lustre_pack_reply(req, 2, size, NULL);
627 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
629 DEBUG_REQ(D_WARNING, req, "Refusing old (unversioned) "
630 "libclient connection attempt\n");
631 GOTO(out, rc = -EPROTO);
632 } else if (data->ocd_version < LUSTRE_VERSION_CODE -
633 LUSTRE_VERSION_ALLOWED_OFFSET ||
634 data->ocd_version > LUSTRE_VERSION_CODE +
635 LUSTRE_VERSION_ALLOWED_OFFSET) {
636 DEBUG_REQ(D_WARNING, req, "Refusing %s (%d.%d.%d.%d) "
637 "libclient connection attempt\n",
638 data->ocd_version < LUSTRE_VERSION_CODE ?
640 OBD_OCD_VERSION_MAJOR(data->ocd_version),
641 OBD_OCD_VERSION_MINOR(data->ocd_version),
642 OBD_OCD_VERSION_PATCH(data->ocd_version),
643 OBD_OCD_VERSION_FIX(data->ocd_version));
644 data = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
645 offsetof(typeof(*data),
647 sizeof(data->ocd_version));
649 data->ocd_connect_flags = OBD_CONNECT_VERSION;
650 data->ocd_version = LUSTRE_VERSION_CODE;
652 GOTO(out, rc = -EPROTO);
656 /* lctl gets a backstage, all-access pass. */
657 if (obd_uuid_equals(&cluuid, &target->obd_uuid))
658 goto dont_check_exports;
660 spin_lock(&target->obd_dev_lock);
661 export = lustre_hash_get_object_by_key(target->obd_uuid_hash_body, &cluuid);
663 if (export != NULL && export->exp_connecting) { /* bug 9635, et. al. */
664 CWARN("%s: exp %p already connecting\n",
665 export->exp_obd->obd_name, export);
666 class_export_put(export);
669 } else if (export != NULL) {
670 /* make darn sure this is coming from the same peer
671 * if the UUIDs matched */
672 if ((export->exp_connection != NULL) &&
673 (strcmp(libcfs_nid2str(req->rq_peer.nid),
674 libcfs_nid2str(export->exp_connection->c_peer.nid)))) {
675 CWARN("%s: cookie %s seen on new NID %s when "
676 "existing NID %s is already connected\n",
677 target->obd_name, cluuid.uuid,
678 libcfs_nid2str(req->rq_peer.nid),
679 libcfs_nid2str(export->exp_connection->c_peer.nid));
680 class_export_put(export);
684 export->exp_connecting = 1;
685 class_export_put(export);
686 spin_unlock(&target->obd_dev_lock);
687 LASSERT(export->exp_obd == target);
688 rc = target_handle_reconnect(&conn, export, &cluuid);
692 /* If we found an export, we already unlocked. */
694 spin_unlock(&target->obd_dev_lock);
695 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout);
696 } else if (req->rq_export == NULL &&
697 atomic_read(&export->exp_rpc_count) > 0) {
698 CWARN("%s: refuse connection from %s/%s to 0x%p/%d\n",
699 target->obd_name, cluuid.uuid,
700 libcfs_nid2str(req->rq_peer.nid),
701 export, atomic_read(&export->exp_refcount));
702 GOTO(out, rc = -EBUSY);
703 } else if (req->rq_export != NULL &&
704 atomic_read(&export->exp_rpc_count) > 1) {
705 CWARN("%s: refuse reconnection from %s@%s to 0x%p/%d\n",
706 target->obd_name, cluuid.uuid,
707 libcfs_nid2str(req->rq_peer.nid),
708 export, atomic_read(&export->exp_rpc_count));
709 GOTO(out, rc = -EBUSY);
710 } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) {
711 CERROR("%s: NID %s (%s) reconnected with 1 conn_cnt; "
712 "cookies not random?\n", target->obd_name,
713 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid);
714 GOTO(out, rc = -EALREADY);
716 OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_RECONNECT, 2 * obd_timeout);
719 /* We want to handle EALREADY but *not* -EALREADY from
720 * target_handle_reconnect(), return reconnection state in a flag */
721 if (rc == EALREADY) {
722 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
728 /* Tell the client if we're in recovery. */
729 /* If this is the first client, start the recovery timer */
730 if (target->obd_recovering) {
731 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
732 target_start_recovery_timer(target, handler);
735 /* Tell the client if we support replayable requests */
736 if (target->obd_replayable)
737 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
739 if (export == NULL) {
740 if (target->obd_recovering) {
741 CERROR("%s: denying connection for new client %s (%s): "
742 "%d clients in recovery for %lds\n",
744 libcfs_nid2str(req->rq_peer.nid), cluuid.uuid,
745 target->obd_recoverable_clients,
746 cfs_duration_sec(cfs_time_sub(cfs_timer_deadline(&target->obd_recovery_timer),
747 cfs_time_current())));
751 rc = obd_connect(&conn, target, &cluuid, data);
754 rc = obd_reconnect(export, target, &cluuid, data);
760 /* Return only the parts of obd_connect_data that we understand, so the
761 * client knows that we don't understand the rest. */
763 memcpy(lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
765 data, sizeof(*data));
767 /* If all else goes well, this is our RPC return code. */
770 lustre_msg_set_handle(req->rq_repmsg, &conn);
772 /* ownership of this export ref transfers to the request AFTER we
773 * drop any previous reference the request had, but we don't want
774 * that to go to zero before we get our new export reference. */
775 export = class_conn2export(&conn);
777 DEBUG_REQ(D_ERROR, req, "Missing export!\n");
778 GOTO(out, rc = -ENODEV);
781 /* If the client and the server are the same node, we will already
782 * have an export that really points to the client's DLM export,
783 * because we have a shared handles table.
785 * XXX this will go away when shaver stops sending the "connect" handle
786 * in the real "remote handle" field of the request --phik 24 Apr 2003
788 if (req->rq_export != NULL)
789 class_export_put(req->rq_export);
791 req->rq_export = export;
793 spin_lock(&export->exp_lock);
794 if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) {
795 CERROR("%s: %s already connected at higher conn_cnt: %d > %d\n",
796 cluuid.uuid, libcfs_nid2str(req->rq_peer.nid),
797 export->exp_conn_cnt,
798 lustre_msg_get_conn_cnt(req->rq_reqmsg));
800 spin_unlock(&export->exp_lock);
801 GOTO(out, rc = -EALREADY);
803 export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
804 spin_unlock(&export->exp_lock);
806 /* request from liblustre? Don't evict it for not pinging. */
807 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT) {
808 export->exp_libclient = 1;
809 spin_lock(&target->obd_dev_lock);
810 list_del_init(&export->exp_obd_chain_timed);
811 spin_unlock(&target->obd_dev_lock);
814 if (export->exp_connection != NULL)
815 ptlrpc_put_connection(export->exp_connection);
816 export->exp_connection = ptlrpc_get_connection(req->rq_peer,
820 spin_lock(&target->obd_dev_lock);
821 lustre_hash_additem(export->exp_obd->obd_nid_hash_body,
822 &export->exp_connection->c_peer.nid,
823 &export->exp_nid_hash);
824 spin_unlock(&target->obd_dev_lock);
826 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT)
829 if (target->obd_recovering)
830 target->obd_connected_clients++;
833 lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn),
836 if (export->exp_imp_reverse != NULL)
837 class_destroy_import(export->exp_imp_reverse);
838 revimp = export->exp_imp_reverse = class_new_import(target);
839 revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
840 revimp->imp_client = &export->exp_obd->obd_ldlm_client;
841 revimp->imp_remote_handle = conn;
842 revimp->imp_dlm_fake = 1;
843 revimp->imp_state = LUSTRE_IMP_FULL;
845 if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) {
846 revimp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
847 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_NEXT_VER);
850 class_import_put(revimp);
853 export->exp_connecting = 0;
855 class_decref(targref);
861 int target_handle_disconnect(struct ptlrpc_request *req)
866 rc = lustre_pack_reply(req, 1, NULL, NULL);
870 /* keep the rq_export around so we can send the reply */
871 req->rq_status = obd_disconnect(class_export_get(req->rq_export));
875 void target_destroy_export(struct obd_export *exp)
877 /* exports created from last_rcvd data, and "fake"
878 exports created by lctl don't have an import */
879 if (exp->exp_imp_reverse != NULL)
880 class_destroy_import(exp->exp_imp_reverse);
882 /* We cancel locks at disconnect time, but this will catch any locks
883 * granted in a race with recovery-induced disconnect. */
884 if (exp->exp_obd->obd_namespace != NULL)
885 ldlm_cancel_locks_for_export(exp);
893 static void target_release_saved_req(struct ptlrpc_request *req)
895 if (req->rq_reply_state != NULL) {
896 ptlrpc_rs_decref(req->rq_reply_state);
897 /* req->rq_reply_state = NULL; */
900 class_export_put(req->rq_export);
901 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
902 OBD_FREE(req, sizeof *req);
905 static void target_finish_recovery(struct obd_device *obd)
907 struct list_head *tmp, *n;
909 LCONSOLE_INFO("%s: sending delayed replies to recovered clients\n",
912 ldlm_reprocess_all_ns(obd->obd_namespace);
914 /* when recovery finished, cleanup orphans on mds and ost */
915 if (OBT(obd) && OBP(obd, postrecov)) {
916 int rc = OBP(obd, postrecov)(obd);
917 LCONSOLE_WARN("%s: recovery %s: rc %d\n", obd->obd_name,
918 rc < 0 ? "failed" : "complete", rc);
921 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
922 struct ptlrpc_request *req;
923 req = list_entry(tmp, struct ptlrpc_request, rq_list);
924 list_del(&req->rq_list);
925 DEBUG_REQ(D_HA, req, "delayed:");
927 target_release_saved_req(req);
929 obd->obd_recovery_end = CURRENT_SECONDS;
932 static void abort_recovery_queue(struct obd_device *obd)
934 struct ptlrpc_request *req;
935 struct list_head *tmp, *n;
938 list_for_each_safe(tmp, n, &obd->obd_recovery_queue) {
939 req = list_entry(tmp, struct ptlrpc_request, rq_list);
940 list_del(&req->rq_list);
941 DEBUG_REQ(D_ERROR, req, "aborted:");
942 req->rq_status = -ENOTCONN;
943 req->rq_type = PTL_RPC_MSG_ERR;
944 rc = lustre_pack_reply(req, 1, NULL, NULL);
948 DEBUG_REQ(D_ERROR, req,
949 "packing failed for abort-reply; skipping");
951 target_release_saved_req(req);
955 /* Called from a cleanup function if the device is being cleaned up
956 forcefully. The exports should all have been disconnected already,
957 the only thing left to do is
958 - clear the recovery flags
960 - free queued requests and replies, but don't send replies
961 Because the obd_stopping flag is set, no new requests should be received.
964 void target_cleanup_recovery(struct obd_device *obd)
966 struct list_head *tmp, *n;
967 struct ptlrpc_request *req;
970 LASSERT(obd->obd_stopping);
972 spin_lock_bh(&obd->obd_processing_task_lock);
973 if (!obd->obd_recovering) {
974 spin_unlock_bh(&obd->obd_processing_task_lock);
978 obd->obd_recovering = obd->obd_abort_recovery = 0;
979 target_cancel_recovery_timer(obd);
980 spin_unlock_bh(&obd->obd_processing_task_lock);
982 list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
983 req = list_entry(tmp, struct ptlrpc_request, rq_list);
984 list_del(&req->rq_list);
985 target_release_saved_req(req);
988 list_for_each_safe(tmp, n, &obd->obd_recovery_queue) {
989 req = list_entry(tmp, struct ptlrpc_request, rq_list);
990 list_del(&req->rq_list);
991 target_release_saved_req(req);
996 void target_abort_recovery(void *data)
998 struct obd_device *obd = data;
1001 spin_lock_bh(&obd->obd_processing_task_lock);
1002 if (!obd->obd_recovering) {
1003 spin_unlock_bh(&obd->obd_processing_task_lock);
1007 obd->obd_recovering = obd->obd_abort_recovery = 0;
1008 obd->obd_recoverable_clients = 0;
1009 target_cancel_recovery_timer(obd);
1010 spin_unlock_bh(&obd->obd_processing_task_lock);
1012 LCONSOLE_WARN("%s: recovery period over; disconnecting unfinished "
1013 "clients.\n", obd->obd_name);
1014 class_disconnect_stale_exports(obd);
1015 abort_recovery_queue(obd);
1017 target_finish_recovery(obd);
1018 CDEBUG(D_HA, "%s: recovery complete\n", obd_uuid2str(&obd->obd_uuid));
1022 static void target_recovery_expired(unsigned long castmeharder)
1024 struct obd_device *obd = (struct obd_device *)castmeharder;
1025 CERROR("%s: recovery timed out, aborting\n", obd->obd_name);
1026 spin_lock_bh(&obd->obd_processing_task_lock);
1027 if (obd->obd_recovering)
1028 obd->obd_abort_recovery = 1;
1029 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1030 spin_unlock_bh(&obd->obd_processing_task_lock);
1034 /* obd_processing_task_lock should be held */
1035 void target_cancel_recovery_timer(struct obd_device *obd)
1037 CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1038 cfs_timer_disarm(&obd->obd_recovery_timer);
1041 static void reset_recovery_timer(struct obd_device *obd)
1043 spin_lock_bh(&obd->obd_processing_task_lock);
1044 if (!obd->obd_recovering) {
1045 spin_unlock_bh(&obd->obd_processing_task_lock);
1048 cfs_timer_arm(&obd->obd_recovery_timer,
1049 cfs_time_shift(OBD_RECOVERY_TIMEOUT));
1050 spin_unlock_bh(&obd->obd_processing_task_lock);
1051 CDEBUG(D_HA, "%s: timer will expire in %u seconds\n", obd->obd_name,
1052 OBD_RECOVERY_TIMEOUT);
1053 /* Only used for lprocfs_status */
1054 obd->obd_recovery_end = CURRENT_SECONDS + OBD_RECOVERY_TIMEOUT;
1058 /* Only start it the first time called */
1059 void target_start_recovery_timer(struct obd_device *obd, svc_handler_t handler)
1061 spin_lock_bh(&obd->obd_processing_task_lock);
1062 if (obd->obd_recovery_handler) {
1063 spin_unlock_bh(&obd->obd_processing_task_lock);
1066 CWARN("%s: starting recovery timer (%us)\n", obd->obd_name,
1067 OBD_RECOVERY_TIMEOUT);
1068 obd->obd_recovery_handler = handler;
1069 cfs_timer_init(&obd->obd_recovery_timer, target_recovery_expired, obd);
1070 spin_unlock_bh(&obd->obd_processing_task_lock);
1072 reset_recovery_timer(obd);
1075 static int check_for_next_transno(struct obd_device *obd)
1077 struct ptlrpc_request *req;
1078 int wake_up = 0, connected, completed, queue_len, max;
1079 __u64 next_transno, req_transno;
1081 spin_lock_bh(&obd->obd_processing_task_lock);
1082 req = list_entry(obd->obd_recovery_queue.next,
1083 struct ptlrpc_request, rq_list);
1084 max = obd->obd_max_recoverable_clients;
1085 req_transno = lustre_msg_get_transno(req->rq_reqmsg);
1086 connected = obd->obd_connected_clients;
1087 completed = max - obd->obd_recoverable_clients;
1088 queue_len = obd->obd_requests_queued_for_recovery;
1089 next_transno = obd->obd_next_recovery_transno;
1091 CDEBUG(D_HA,"max: %d, connected: %d, completed: %d, queue_len: %d, "
1092 "req_transno: "LPU64", next_transno: "LPU64"\n",
1093 max, connected, completed, queue_len, req_transno, next_transno);
1094 if (obd->obd_abort_recovery) {
1095 CDEBUG(D_HA, "waking for aborted recovery\n");
1097 } else if (!obd->obd_recovering) {
1098 CDEBUG(D_HA, "waking for completed recovery (?)\n");
1100 } else if (req_transno == next_transno) {
1101 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1103 } else if (queue_len + completed == max) {
1105 "waking for skipped transno (skip: "LPD64
1106 ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
1107 next_transno, queue_len, completed, max, req_transno);
1108 obd->obd_next_recovery_transno = req_transno;
1111 spin_unlock_bh(&obd->obd_processing_task_lock);
1112 LASSERT(lustre_msg_get_transno(req->rq_reqmsg) >= next_transno);
1116 static void process_recovery_queue(struct obd_device *obd)
1118 struct ptlrpc_request *req;
1119 int abort_recovery = 0;
1120 struct l_wait_info lwi = { 0 };
1124 spin_lock_bh(&obd->obd_processing_task_lock);
1125 LASSERT(obd->obd_processing_task == cfs_curproc_pid());
1126 req = list_entry(obd->obd_recovery_queue.next,
1127 struct ptlrpc_request, rq_list);
1129 if (lustre_msg_get_transno(req->rq_reqmsg) !=
1130 obd->obd_next_recovery_transno) {
1131 spin_unlock_bh(&obd->obd_processing_task_lock);
1132 CDEBUG(D_HA, "Waiting for transno "LPD64" (1st is "
1134 obd->obd_next_recovery_transno,
1135 lustre_msg_get_transno(req->rq_reqmsg));
1136 l_wait_event(obd->obd_next_transno_waitq,
1137 check_for_next_transno(obd), &lwi);
1138 spin_lock_bh(&obd->obd_processing_task_lock);
1139 abort_recovery = obd->obd_abort_recovery;
1140 spin_unlock_bh(&obd->obd_processing_task_lock);
1141 if (abort_recovery) {
1142 target_abort_recovery(obd);
1147 list_del_init(&req->rq_list);
1148 obd->obd_requests_queued_for_recovery--;
1149 spin_unlock_bh(&obd->obd_processing_task_lock);
1151 DEBUG_REQ(D_HA, req, "processing: ");
1152 (void)obd->obd_recovery_handler(req);
1153 obd->obd_replayed_requests++;
1154 reset_recovery_timer(obd);
1155 /* bug 1580: decide how to properly sync() in recovery */
1156 //mds_fsync_super(obd->u.obt.obt_sb);
1157 class_export_put(req->rq_export);
1158 if (req->rq_reply_state != NULL) {
1159 ptlrpc_rs_decref(req->rq_reply_state);
1160 /* req->rq_reply_state = NULL; */
1162 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
1163 OBD_FREE(req, sizeof *req);
1164 spin_lock_bh(&obd->obd_processing_task_lock);
1165 obd->obd_next_recovery_transno++;
1166 if (list_empty(&obd->obd_recovery_queue)) {
1167 obd->obd_processing_task = 0;
1168 spin_unlock_bh(&obd->obd_processing_task_lock);
1171 spin_unlock_bh(&obd->obd_processing_task_lock);
1176 int target_queue_recovery_request(struct ptlrpc_request *req,
1177 struct obd_device *obd)
1179 struct list_head *tmp;
1181 __u64 transno = lustre_msg_get_transno(req->rq_reqmsg);
1182 struct ptlrpc_request *saved_req;
1183 struct lustre_msg *reqmsg;
1185 /* CAVEAT EMPTOR: The incoming request message has been swabbed
1186 * (i.e. buflens etc are in my own byte order), but type-dependent
1187 * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
1190 CFS_INIT_LIST_HEAD(&req->rq_list);
1191 DEBUG_REQ(D_HA, req, "not queueing");
1195 /* XXX If I were a real man, these LBUGs would be sane cleanups. */
1196 /* XXX just like the request-dup code in queue_final_reply */
1197 OBD_ALLOC(saved_req, sizeof *saved_req);
1200 OBD_ALLOC(reqmsg, req->rq_reqlen);
1204 spin_lock_bh(&obd->obd_processing_task_lock);
1206 /* If we're processing the queue, we want don't want to queue this
1209 * Also, if this request has a transno less than the one we're waiting
1210 * for, we should process it now. It could (and currently always will)
1211 * be an open request for a descriptor that was opened some time ago.
1213 * Also, a resent, replayed request that has already been
1214 * handled will pass through here and be processed immediately.
1216 if (obd->obd_processing_task == cfs_curproc_pid() ||
1217 transno < obd->obd_next_recovery_transno) {
1218 /* Processing the queue right now, don't re-add. */
1219 LASSERT(list_empty(&req->rq_list));
1220 spin_unlock_bh(&obd->obd_processing_task_lock);
1221 OBD_FREE(reqmsg, req->rq_reqlen);
1222 OBD_FREE(saved_req, sizeof *saved_req);
1226 /* A resent, replayed request that is still on the queue; just drop it.
1227 The queued request will handle this. */
1228 if ((lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT|MSG_REPLAY)) ==
1229 (MSG_RESENT | MSG_REPLAY)) {
1230 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
1231 spin_unlock_bh(&obd->obd_processing_task_lock);
1232 OBD_FREE(reqmsg, req->rq_reqlen);
1233 OBD_FREE(saved_req, sizeof *saved_req);
1237 memcpy(saved_req, req, sizeof *req);
1238 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1240 req->rq_reqmsg = reqmsg;
1241 class_export_get(req->rq_export);
1242 CFS_INIT_LIST_HEAD(&req->rq_list);
1245 list_for_each(tmp, &obd->obd_recovery_queue) {
1246 struct ptlrpc_request *reqiter =
1247 list_entry(tmp, struct ptlrpc_request, rq_list);
1249 if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) {
1250 list_add_tail(&req->rq_list, &reqiter->rq_list);
1257 list_add_tail(&req->rq_list, &obd->obd_recovery_queue);
1260 obd->obd_requests_queued_for_recovery++;
1262 if (obd->obd_processing_task != 0) {
1263 /* Someone else is processing this queue, we'll leave it to
1266 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1267 spin_unlock_bh(&obd->obd_processing_task_lock);
1271 /* Nobody is processing, and we know there's (at least) one to process
1272 * now, so we'll do the honours.
1274 obd->obd_processing_task = cfs_curproc_pid();
1275 spin_unlock_bh(&obd->obd_processing_task_lock);
1277 process_recovery_queue(obd);
1281 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1283 return req->rq_export->exp_obd;
1286 int target_queue_final_reply(struct ptlrpc_request *req, int rc)
1288 struct obd_device *obd = target_req2obd(req);
1289 struct ptlrpc_request *saved_req;
1290 struct lustre_msg *reqmsg;
1291 int recovery_done = 0;
1293 LASSERT ((rc == 0) == (req->rq_reply_state != NULL));
1296 /* Just like ptlrpc_error, but without the sending. */
1297 rc = lustre_pack_reply(req, 1, NULL, NULL);
1298 LASSERT(rc == 0); /* XXX handle this */
1299 req->rq_type = PTL_RPC_MSG_ERR;
1302 LASSERT (!req->rq_reply_state->rs_difficult);
1303 LASSERT(list_empty(&req->rq_list));
1304 /* XXX a bit like the request-dup code in queue_recovery_request */
1305 OBD_ALLOC(saved_req, sizeof *saved_req);
1308 OBD_ALLOC(reqmsg, req->rq_reqlen);
1312 memcpy(reqmsg, req->rq_reqmsg, req->rq_reqlen);
1314 /* Don't race cleanup */
1315 spin_lock_bh(&obd->obd_processing_task_lock);
1316 if (obd->obd_stopping) {
1317 spin_unlock_bh(&obd->obd_processing_task_lock);
1318 OBD_FREE(reqmsg, req->rq_reqlen);
1319 OBD_FREE(saved_req, sizeof *req);
1320 req->rq_status = -ENOTCONN;
1321 /* rv is ignored anyhow */
1324 ptlrpc_rs_addref(req->rq_reply_state); /* +1 ref for saved reply */
1326 req->rq_reqmsg = reqmsg;
1327 class_export_get(req->rq_export);
1328 list_add(&req->rq_list, &obd->obd_delayed_reply_queue);
1330 /* only count the first "replay over" request from each
1332 if (req->rq_export->exp_replay_needed) {
1333 --obd->obd_recoverable_clients;
1334 req->rq_export->exp_replay_needed = 0;
1336 recovery_done = (obd->obd_recoverable_clients == 0);
1337 spin_unlock_bh(&obd->obd_processing_task_lock);
1339 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
1340 if (recovery_done) {
1341 spin_lock_bh(&obd->obd_processing_task_lock);
1342 obd->obd_recovering = obd->obd_abort_recovery = 0;
1343 target_cancel_recovery_timer(obd);
1344 spin_unlock_bh(&obd->obd_processing_task_lock);
1346 target_finish_recovery(obd);
1347 CDEBUG(D_HA, "%s: recovery complete\n",
1348 obd_uuid2str(&obd->obd_uuid));
1350 CWARN("%s: %d recoverable clients remain\n",
1351 obd->obd_name, obd->obd_recoverable_clients);
1352 cfs_waitq_signal(&obd->obd_next_transno_waitq);
1359 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1361 if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1362 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1363 DEBUG_REQ(D_ERROR, req, "dropping reply");
1368 DEBUG_REQ(D_ERROR, req, "processing error (%d)", rc);
1369 req->rq_status = rc;
1370 return (ptlrpc_error(req));
1372 DEBUG_REQ(D_NET, req, "sending reply");
1375 return (ptlrpc_send_reply(req, 1));
1379 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1382 struct ptlrpc_reply_state *rs;
1383 struct obd_device *obd;
1384 struct obd_export *exp;
1385 struct ptlrpc_service *svc;
1387 svc = req->rq_rqbd->rqbd_service;
1388 rs = req->rq_reply_state;
1389 if (rs == NULL || !rs->rs_difficult) {
1391 target_send_reply_msg (req, rc, fail_id);
1395 /* must be an export if locks saved */
1396 LASSERT (req->rq_export != NULL);
1397 /* req/reply consistent */
1398 LASSERT (rs->rs_service == svc);
1401 LASSERT (!rs->rs_scheduled);
1402 LASSERT (!rs->rs_scheduled_ever);
1403 LASSERT (!rs->rs_handled);
1404 LASSERT (!rs->rs_on_net);
1405 LASSERT (rs->rs_export == NULL);
1406 LASSERT (list_empty(&rs->rs_obd_list));
1407 LASSERT (list_empty(&rs->rs_exp_list));
1409 exp = class_export_get (req->rq_export);
1412 /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1413 rs->rs_scheduled = 1;
1415 rs->rs_xid = req->rq_xid;
1416 rs->rs_transno = req->rq_transno;
1417 rs->rs_export = exp;
1419 spin_lock(&obd->obd_uncommitted_replies_lock);
1421 if (rs->rs_transno > obd->obd_last_committed) {
1422 /* not committed already */
1423 list_add_tail (&rs->rs_obd_list,
1424 &obd->obd_uncommitted_replies);
1427 spin_unlock (&obd->obd_uncommitted_replies_lock);
1428 spin_lock (&exp->exp_lock);
1430 list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1432 spin_unlock(&exp->exp_lock);
1434 netrc = target_send_reply_msg (req, rc, fail_id);
1436 spin_lock(&svc->srv_lock);
1438 svc->srv_n_difficult_replies++;
1441 /* error sending: reply is off the net. Also we need +1
1442 * reply ref until ptlrpc_server_handle_reply() is done
1443 * with the reply state (if the send was successful, there
1444 * would have been +1 ref for the net, which
1445 * reply_out_callback leaves alone) */
1447 ptlrpc_rs_addref(rs);
1448 atomic_inc (&svc->srv_outstanding_replies);
1451 if (!rs->rs_on_net || /* some notifier */
1452 list_empty(&rs->rs_exp_list) || /* completed already */
1453 list_empty(&rs->rs_obd_list)) {
1454 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
1455 cfs_waitq_signal (&svc->srv_waitq);
1457 list_add (&rs->rs_list, &svc->srv_active_replies);
1458 rs->rs_scheduled = 0; /* allow notifier to schedule */
1461 spin_unlock(&svc->srv_lock);
1464 int target_handle_ping(struct ptlrpc_request *req)
1466 obd_ping(req->rq_export);
1467 return lustre_pack_reply(req, 1, NULL, NULL);
1470 void target_committed_to_req(struct ptlrpc_request *req)
1472 struct obd_device *obd = req->rq_export->exp_obd;
1474 if (!obd->obd_no_transno && req->rq_repmsg != NULL)
1475 lustre_msg_set_last_committed(req->rq_repmsg,
1476 obd->obd_last_committed);
1478 DEBUG_REQ(D_IOCTL, req, "not sending last_committed update");
1480 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPU64"\n",
1481 obd->obd_last_committed, req->rq_xid);
1484 EXPORT_SYMBOL(target_committed_to_req);
1486 #ifdef HAVE_QUOTA_SUPPORT
1487 int target_handle_qc_callback(struct ptlrpc_request *req)
1489 struct obd_quotactl *oqctl;
1490 struct client_obd *cli = &req->rq_export->exp_obd->u.cli;
1492 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1493 lustre_swab_obd_quotactl);
1494 if (oqctl == NULL) {
1495 CERROR("Can't unpack obd_quotactl\n");
1499 cli->cl_qchk_stat = oqctl->qc_stat;
1504 int target_handle_dqacq_callback(struct ptlrpc_request *req)
1507 struct obd_device *obd = req->rq_export->exp_obd;
1508 struct obd_device *master_obd;
1509 struct lustre_quota_ctxt *qctxt;
1510 struct qunit_data *qdata;
1512 struct qunit_data_old *qdata_old;
1514 int repsize[2] = { sizeof(struct ptlrpc_body),
1515 sizeof(struct qunit_data) };
1518 rc = lustre_pack_reply(req, 2, repsize, NULL);
1520 CERROR("packing reply failed!: rc = %d\n", rc);
1523 LASSERT(req->rq_export);
1525 /* fixed for bug10707 */
1526 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_QUOTA64) &&
1527 !OBD_FAIL_CHECK(OBD_FAIL_QUOTA_QD_COUNT_32BIT)) {
1528 CDEBUG(D_QUOTA, "qd_count is 64bit!\n");
1529 rep = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1530 sizeof(struct qunit_data));
1532 qdata = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*qdata),
1535 CDEBUG(D_QUOTA, "qd_count is 32bit!\n");
1536 rep = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1537 sizeof(struct qunit_data_old));
1539 qdata_old = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*qdata_old),
1540 lustre_swab_qdata_old);
1541 qdata = lustre_quota_old_to_new(qdata_old);
1544 if (qdata == NULL) {
1545 CERROR("Can't unpack qunit_data\n");
1549 /* we use the observer */
1550 LASSERT(obd->obd_observer && obd->obd_observer->obd_observer);
1551 master_obd = obd->obd_observer->obd_observer;
1552 qctxt = &master_obd->u.obt.obt_qctxt;
1554 LASSERT(qctxt->lqc_handler);
1555 rc = qctxt->lqc_handler(master_obd, qdata,
1556 lustre_msg_get_opc(req->rq_reqmsg));
1557 if (rc && rc != -EDQUOT)
1558 CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR,
1559 "dqacq failed! (rc:%d)\n", rc);
1561 /* the qd_count might be changed in lqc_handler */
1562 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_QUOTA64) &&
1563 !OBD_FAIL_CHECK(OBD_FAIL_QUOTA_QD_COUNT_32BIT)) {
1564 memcpy(rep,qdata,sizeof(*qdata));
1566 qdata_old = lustre_quota_new_to_old(qdata);
1567 memcpy(rep,qdata_old,sizeof(*qdata_old));
1569 req->rq_status = rc;
1570 rc = ptlrpc_reply(req);
1575 #endif /* !__KERNEL__ */
1577 #endif /* HAVE_QUOTA_SUPPORT */
1579 ldlm_mode_t lck_compat_array[] = {
1580 [LCK_EX] LCK_COMPAT_EX,
1581 [LCK_PW] LCK_COMPAT_PW,
1582 [LCK_PR] LCK_COMPAT_PR,
1583 [LCK_CW] LCK_COMPAT_CW,
1584 [LCK_CR] LCK_COMPAT_CR,
1585 [LCK_NL] LCK_COMPAT_NL,
1586 [LCK_GROUP] LCK_COMPAT_GROUP