Whamcloud - gitweb
b=4019
[fs/lustre-release.git] / lustre / ldlm / ldlm_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_LDLM
26
27 #ifdef __KERNEL__
28 # include <linux/module.h>
29 #else
30 # include <liblustre.h>
31 #endif
32 #include <linux/obd.h>
33 #include <linux/obd_ost.h> /* for LUSTRE_OSC_NAME */
34 #include <linux/lustre_mds.h> /* for LUSTRE_MDC_NAME */
35 #include <linux/lustre_mgmt.h>
36 #include <linux/lustre_dlm.h>
37 #include <linux/lustre_net.h>
38
39 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
40 {
41         struct ptlrpc_connection *conn;
42         struct lustre_cfg* lcfg = buf;
43         struct client_obd *cli = &obddev->u.cli;
44         struct obd_import *imp;
45         struct obd_uuid server_uuid;
46         int rq_portal, rp_portal, connect_op;
47         char *name = obddev->obd_type->typ_name;
48         char *mgmt_name = NULL;
49         int rc;
50         struct obd_device *mgmt_obd;
51         mgmtcli_register_for_events_t register_f;
52         ENTRY;
53
54         /* In a more perfect world, we would hang a ptlrpc_client off of
55          * obd_type and just use the values from there. */
56         if (!strcmp(name, LUSTRE_OSC_NAME)) {
57                 rq_portal = OST_REQUEST_PORTAL;
58                 rp_portal = OSC_REPLY_PORTAL;
59                 connect_op = OST_CONNECT;
60         } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
61                 rq_portal = MDS_REQUEST_PORTAL;
62                 rp_portal = MDC_REPLY_PORTAL;
63                 connect_op = MDS_CONNECT;
64         } else if (!strcmp(name, LUSTRE_MGMTCLI_NAME)) {
65                 rq_portal = MGMT_REQUEST_PORTAL;
66                 rp_portal = MGMT_REPLY_PORTAL;
67                 connect_op = MGMT_CONNECT;
68         } else {
69                 CERROR("unknown client OBD type \"%s\", can't setup\n",
70                        name);
71                 RETURN(-EINVAL);
72         }
73
74         if (lcfg->lcfg_inllen1 < 1) {
75                 CERROR("requires a TARGET UUID\n");
76                 RETURN(-EINVAL);
77         }
78
79         if (lcfg->lcfg_inllen1 > 37) {
80                 CERROR("client UUID must be less than 38 characters\n");
81                 RETURN(-EINVAL);
82         }
83
84         if (lcfg->lcfg_inllen2 < 1) {
85                 CERROR("setup requires a SERVER UUID\n");
86                 RETURN(-EINVAL);
87         }
88
89         if (lcfg->lcfg_inllen2 > 37) {
90                 CERROR("target UUID must be less than 38 characters\n");
91                 RETURN(-EINVAL);
92         }
93
94         sema_init(&cli->cl_sem, 1);
95         cli->cl_conn_count = 0;
96         memcpy(server_uuid.uuid, lcfg->lcfg_inlbuf2,
97                min_t(unsigned int, lcfg->lcfg_inllen2, sizeof(server_uuid)));
98
99         cli->cl_dirty = 0;
100         cli->cl_avail_grant = 0;
101         cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
102         INIT_LIST_HEAD(&cli->cl_cache_waiters);
103         INIT_LIST_HEAD(&cli->cl_loi_ready_list);
104         INIT_LIST_HEAD(&cli->cl_loi_write_list);
105         INIT_LIST_HEAD(&cli->cl_loi_read_list);
106         spin_lock_init(&cli->cl_loi_list_lock);
107         cli->cl_brw_in_flight = 0;
108         spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
109         spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
110         spin_lock_init(&cli->cl_read_page_hist.oh_lock);
111         spin_lock_init(&cli->cl_write_page_hist.oh_lock);
112         cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES;
113         cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
114
115         rc = ldlm_get_ref();
116         if (rc) {
117                 CERROR("ldlm_get_ref failed: %d\n", rc);
118                 GOTO(err, rc);
119         }
120
121         conn = ptlrpc_uuid_to_connection(&server_uuid);
122         if (conn == NULL)
123                 GOTO(err_ldlm, rc = -ENOENT);
124
125         ptlrpc_init_client(rq_portal, rp_portal, name,
126                            &obddev->obd_ldlm_client);
127
128         imp = class_new_import();
129         if (imp == NULL) {
130                 ptlrpc_put_connection(conn);
131                 GOTO(err_ldlm, rc = -ENOENT);
132         }
133         imp->imp_connection = conn;
134         imp->imp_client = &obddev->obd_ldlm_client;
135         imp->imp_obd = obddev;
136         imp->imp_connect_op = connect_op;
137         imp->imp_generation = 0;
138         imp->imp_initial_recov = 1;
139         INIT_LIST_HEAD(&imp->imp_pinger_chain);
140         memcpy(imp->imp_target_uuid.uuid, lcfg->lcfg_inlbuf1,
141               lcfg->lcfg_inllen1);
142         class_import_put(imp);
143
144         cli->cl_import = imp;
145         cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
146         cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
147         cli->cl_sandev = to_kdev_t(0);
148
149         if (lcfg->lcfg_inllen3 != 0) {
150                 if (!strcmp(lcfg->lcfg_inlbuf3, "inactive")) {
151                         CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
152                                name, obddev->obd_name,
153                                imp->imp_target_uuid.uuid);
154                         imp->imp_invalid = 1;
155
156                         if (lcfg->lcfg_inllen4 != 0)
157                                 mgmt_name = lcfg->lcfg_inlbuf4;
158                 } else {
159                         mgmt_name = lcfg->lcfg_inlbuf3;
160                 }
161         }
162
163         if (mgmt_name != NULL) {
164                 /* Register with management client if we need to. */
165                 CDEBUG(D_HA, "%s registering with %s for events about %s\n",
166                        obddev->obd_name, mgmt_name, server_uuid.uuid);
167
168                 mgmt_obd = class_name2obd(mgmt_name);
169                 if (!mgmt_obd) {
170                         CERROR("can't find mgmtcli %s to register\n",
171                                mgmt_name);
172                         GOTO(err_import, rc = -ENOSYS);
173                 }
174
175                 register_f = inter_module_get("mgmtcli_register_for_events");
176                 if (!register_f) {
177                         CERROR("can't i_m_g mgmtcli_register_for_events\n");
178                         GOTO(err_import, rc = -ENOSYS);
179                 }
180
181                 rc = register_f(mgmt_obd, obddev, &imp->imp_target_uuid);
182                 inter_module_put("mgmtcli_register_for_events");
183
184                 if (!rc)
185                         cli->cl_mgmtcli_obd = mgmt_obd;
186         }
187
188         RETURN(rc);
189
190 err_import:
191         class_destroy_import(imp);
192 err_ldlm:
193         ldlm_put_ref(0);
194 err:
195         RETURN(rc);
196
197 }
198
199 int client_obd_cleanup(struct obd_device *obddev, int flags)
200 {
201         struct client_obd *cli = &obddev->u.cli;
202
203         if (!cli->cl_import)
204                 RETURN(-EINVAL);
205         if (cli->cl_mgmtcli_obd) {
206                 mgmtcli_deregister_for_events_t dereg_f;
207
208                 dereg_f = inter_module_get("mgmtcli_deregister_for_events");
209                 dereg_f(cli->cl_mgmtcli_obd, obddev);
210                 inter_module_put("mgmtcli_deregister_for_events");
211         }
212         class_destroy_import(cli->cl_import);
213         cli->cl_import = NULL;
214
215         ldlm_put_ref(flags & OBD_OPT_FORCE);
216
217         RETURN(0);
218 }
219
220 int client_connect_import(struct lustre_handle *dlm_handle,
221                           struct obd_device *obd,
222                           struct obd_uuid *cluuid,
223                           unsigned long connect_flags)
224 {
225         struct client_obd *cli = &obd->u.cli;
226         struct obd_import *imp = cli->cl_import;
227         struct obd_export *exp;
228         int rc;
229         ENTRY;
230
231         down(&cli->cl_sem);
232         rc = class_connect(dlm_handle, obd, cluuid);
233         if (rc)
234                 GOTO(out_sem, rc);
235
236         cli->cl_conn_count++;
237         if (cli->cl_conn_count > 1)
238                 GOTO(out_sem, rc);
239         exp = class_conn2export(dlm_handle);
240
241         if (obd->obd_namespace != NULL)
242                 CERROR("already have namespace!\n");
243         obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
244                                                 LDLM_NAMESPACE_CLIENT);
245         if (obd->obd_namespace == NULL)
246                 GOTO(out_disco, rc = -ENOMEM);
247
248         imp->imp_dlm_handle = *dlm_handle;
249         rc = ptlrpc_init_import(imp);
250         if (rc != 0) 
251                 GOTO(out_ldlm, rc);
252
253         exp->exp_connection = ptlrpc_connection_addref(imp->imp_connection);
254         imp->imp_connect_flags = connect_flags;
255         rc = ptlrpc_connect_import(imp, NULL);
256         if (rc != 0) {
257                 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
258                 GOTO(out_ldlm, rc);
259         }
260
261         ptlrpc_pinger_add_import(imp);
262         EXIT;
263
264         if (rc) {
265 out_ldlm:
266                 ldlm_namespace_free(obd->obd_namespace, 0);
267                 obd->obd_namespace = NULL;
268 out_disco:
269                 cli->cl_conn_count--;
270                 class_disconnect(exp, 0);
271         } else {
272                 class_export_put(exp);
273         }
274 out_sem:
275         up(&cli->cl_sem);
276         return rc;
277 }
278
279 int client_disconnect_export(struct obd_export *exp, int failover)
280 {
281         struct obd_device *obd = class_exp2obd(exp);
282         struct client_obd *cli = &obd->u.cli;
283         struct obd_import *imp = cli->cl_import;
284         int rc = 0, err;
285         ENTRY;
286
287         if (!obd) {
288                 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
289                        exp, exp ? exp->exp_handle.h_cookie : -1);
290                 RETURN(-EINVAL);
291         }
292
293         down(&cli->cl_sem);
294         if (!cli->cl_conn_count) {
295                 CERROR("disconnecting disconnected device (%s)\n",
296                        obd->obd_name);
297                 GOTO(out_sem, rc = -EINVAL);
298         }
299
300         cli->cl_conn_count--;
301         if (cli->cl_conn_count)
302                 GOTO(out_no_disconnect, rc = 0);
303
304         /* Some non-replayable imports (MDS's OSCs) are pinged, so just
305          * delete it regardless.  (It's safe to delete an import that was
306          * never added.) */
307         (void)ptlrpc_pinger_del_import(imp);
308
309         if (obd->obd_namespace != NULL) {
310                 /* obd_no_recov == local only */
311                 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
312                                        obd->obd_no_recov, NULL);
313                 ldlm_namespace_free(obd->obd_namespace, obd->obd_no_recov);
314                 obd->obd_namespace = NULL;
315         }
316
317         /* Yeah, obd_no_recov also (mainly) means "forced shutdown". */
318         if (obd->obd_no_recov)
319                 ptlrpc_invalidate_import(imp, 0);
320         else
321                 rc = ptlrpc_disconnect_import(imp);
322
323         EXIT;
324  out_no_disconnect:
325         err = class_disconnect(exp, 0);
326         if (!rc && err)
327                 rc = err;
328  out_sem:
329         up(&cli->cl_sem);
330         RETURN(rc);
331 }
332
333 /* --------------------------------------------------------------------------
334  * from old lib/target.c
335  * -------------------------------------------------------------------------- */
336
337 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
338                             struct obd_uuid *cluuid, int initial_conn)
339 {
340         if (exp->exp_connection && !initial_conn) {
341                 struct lustre_handle *hdl;
342                 hdl = &exp->exp_imp_reverse->imp_remote_handle;
343                 /* Might be a re-connect after a partition. */
344                 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
345                         CERROR("%s reconnecting\n", cluuid->uuid);
346                         conn->cookie = exp->exp_handle.h_cookie;
347                         RETURN(EALREADY);
348                 } else {
349                         CERROR("%s reconnecting from %s, "
350                                "handle mismatch (ours "LPX64", theirs "
351                                LPX64")\n", cluuid->uuid,
352                                exp->exp_connection->c_remote_uuid.uuid,
353                                hdl->cookie, conn->cookie);
354                         memset(conn, 0, sizeof *conn);
355                         RETURN(-EALREADY);
356                 }
357         }
358
359         conn->cookie = exp->exp_handle.h_cookie;
360         CDEBUG(D_INFO, "existing export for UUID '%s' at %p\n",
361                cluuid->uuid, exp);
362         CDEBUG(D_IOCTL,"connect: cookie "LPX64"\n", conn->cookie);
363         RETURN(0);
364 }
365
366 int target_handle_connect(struct ptlrpc_request *req)
367 {
368         unsigned long connect_flags = 0, *cfp;
369         struct obd_device *target;
370         struct obd_export *export = NULL;
371         struct obd_import *revimp;
372         struct lustre_handle conn;
373         struct obd_uuid tgtuuid;
374         struct obd_uuid cluuid;
375         struct obd_uuid remote_uuid;
376         struct list_head *p;
377         char *str, *tmp;
378         int rc = 0;
379         unsigned long flags;
380         int initial_conn = 0;
381         char peer_str[PTL_NALFMT_SIZE];
382         ENTRY;
383
384         OBD_RACE(OBD_FAIL_TGT_CONN_RACE); 
385
386         LASSERT_REQSWAB (req, 0);
387         str = lustre_msg_string(req->rq_reqmsg, 0, sizeof(tgtuuid) - 1);
388         if (str == NULL) {
389                 CERROR("bad target UUID for connect\n");
390                 GOTO(out, rc = -EINVAL);
391         }
392
393         obd_str2uuid (&tgtuuid, str);
394         target = class_uuid2obd(&tgtuuid);
395         if (!target) {
396                 target = class_name2obd(str);
397         }
398         
399         if (!target || target->obd_stopping || !target->obd_set_up) {
400                 CERROR("UUID '%s' is not available for connect\n", str);
401
402                 GOTO(out, rc = -ENODEV);
403         }
404
405         LASSERT_REQSWAB (req, 1);
406         str = lustre_msg_string(req->rq_reqmsg, 1, sizeof(cluuid) - 1);
407         if (str == NULL) {
408                 CERROR("bad client UUID for connect\n");
409                 GOTO(out, rc = -EINVAL);
410         }
411
412         obd_str2uuid (&cluuid, str);
413
414         /* XXX extract a nettype and format accordingly */
415         switch (sizeof(ptl_nid_t)) {
416                 /* NB the casts only avoid compiler warnings */
417         case 8:
418                 snprintf(remote_uuid.uuid, sizeof remote_uuid,
419                          "NET_"LPX64"_UUID", (__u64)req->rq_peer.peer_nid);
420                 break;
421         case 4:
422                 snprintf(remote_uuid.uuid, sizeof remote_uuid,
423                          "NET_%x_UUID", (__u32)req->rq_peer.peer_nid);
424                 break;
425         default:
426                 LBUG();
427         }
428
429         tmp = lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn);
430         if (tmp == NULL)
431                 GOTO(out, rc = -EPROTO);
432
433         memcpy(&conn, tmp, sizeof conn);
434
435         cfp = lustre_msg_buf(req->rq_reqmsg, 3, sizeof(unsigned long));
436         LASSERT(cfp != NULL);
437         connect_flags = *cfp;
438
439         rc = lustre_pack_reply(req, 0, NULL, NULL);
440         if (rc)
441                 GOTO(out, rc);
442         
443         if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL)
444                 initial_conn = 1;
445         
446         /* lctl gets a backstage, all-access pass. */
447         if (obd_uuid_equals(&cluuid, &target->obd_uuid))
448                 goto dont_check_exports;
449
450         spin_lock(&target->obd_dev_lock);
451         list_for_each(p, &target->obd_exports) {
452                 export = list_entry(p, struct obd_export, exp_obd_chain);
453                 if (obd_uuid_equals(&cluuid, &export->exp_client_uuid)) {
454                         spin_unlock(&target->obd_dev_lock);
455                         LASSERT(export->exp_obd == target);
456
457                         rc = target_handle_reconnect(&conn, export, &cluuid,
458                                                      initial_conn);
459                         break;
460                 }
461                 export = NULL;
462         }
463         /* If we found an export, we already unlocked. */
464         if (!export) {
465                 spin_unlock(&target->obd_dev_lock);
466         } else if (req->rq_export == NULL && 
467                    atomic_read(&export->exp_rpc_count) > 0) {
468                 CWARN("%s: refuse connection from %s/%s to 0x%p/%d\n",
469                       target->obd_name, cluuid.uuid,
470                       ptlrpc_peernid2str(&req->rq_peer, peer_str),
471                       export, atomic_read(&export->exp_refcount));
472                 GOTO(out, rc = -EBUSY);
473         } else if (req->rq_export != NULL &&
474                    atomic_read(&export->exp_rpc_count) > 1) {
475                 CWARN("%s: refuse reconnection from %s@%s to 0x%p/%d\n",
476                       target->obd_name, cluuid.uuid,
477                       ptlrpc_peernid2str(&req->rq_peer, peer_str),
478                       export, atomic_read(&export->exp_rpc_count));
479                 GOTO(out, rc = -EBUSY);
480         }
481         else if (req->rq_reqmsg->conn_cnt == 1 && !initial_conn) {
482                 CERROR("%s reconnected with 1 conn_cnt; cookies not random?\n",
483                        cluuid.uuid);
484                 GOTO(out, rc = -EALREADY);
485         }
486
487         /* Tell the client if we're in recovery. */
488         /* If this is the first client, start the recovery timer */
489         CWARN("%s: connection from %s@%s/%lu %s\n", target->obd_name, cluuid.uuid,
490               ptlrpc_peernid2str(&req->rq_peer, peer_str), *cfp,
491               target->obd_recovering ? "(recovering)" : "");
492         if (target->obd_recovering) {
493                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
494                 target_start_recovery_timer(target);
495         }
496 #if 0
497         /* Tell the client if we support replayable requests */
498         if (target->obd_replayable)
499                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
500 #endif
501         if (export == NULL) {
502                 if (target->obd_recovering) {
503                         CERROR("denying connection for new client %s@%s: "
504                                "%d clients in recovery for %lds\n", cluuid.uuid,
505                                ptlrpc_peernid2str(&req->rq_peer, peer_str),
506                                target->obd_recoverable_clients,
507                                (target->obd_recovery_timer.expires-jiffies)/HZ);
508                         rc = -EBUSY;
509                 } else {
510  dont_check_exports:
511                         rc = obd_connect(&conn, target, &cluuid, connect_flags);
512                 }
513         }
514         /* Tell the client if we support replayable requests */
515         if (target->obd_replayable)
516                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
517
518         /* If all else goes well, this is our RPC return code. */
519         req->rq_status = 0;
520
521         if (rc && rc != EALREADY)
522                 GOTO(out, rc);
523
524         req->rq_repmsg->handle = conn;
525
526         /* If the client and the server are the same node, we will already
527          * have an export that really points to the client's DLM export,
528          * because we have a shared handles table.
529          *
530          * XXX this will go away when shaver stops sending the "connect" handle
531          * in the real "remote handle" field of the request --phik 24 Apr 2003
532          */
533         if (req->rq_export != NULL)
534                 class_export_put(req->rq_export);
535
536         /* ownership of this export ref transfers to the request */
537         export = req->rq_export = class_conn2export(&conn);
538         LASSERT(export != NULL);
539
540         spin_lock_irqsave(&export->exp_lock, flags);
541         if (initial_conn) {
542                 req->rq_repmsg->conn_cnt = export->exp_conn_cnt + 1;
543         } else if (export->exp_conn_cnt >= req->rq_reqmsg->conn_cnt) {
544                 CERROR("%s@%s: already connected at a higher conn_cnt: %d > %d\n",
545                        cluuid.uuid, ptlrpc_peernid2str(&req->rq_peer, peer_str),
546                        export->exp_conn_cnt, 
547                        req->rq_reqmsg->conn_cnt);
548                 spin_unlock_irqrestore(&export->exp_lock, flags);
549                 GOTO(out, rc = -EALREADY);
550         } 
551         export->exp_conn_cnt = req->rq_reqmsg->conn_cnt;
552         spin_unlock_irqrestore(&export->exp_lock, flags);
553
554         /* request from liblustre? */
555         if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT)
556                 export->exp_libclient = 1;
557
558         if (export->exp_connection != NULL)
559                 ptlrpc_put_connection(export->exp_connection);
560         export->exp_connection = ptlrpc_get_connection(&req->rq_peer,
561                                                        &remote_uuid);
562
563         if (rc == EALREADY) {
564                 /* We indicate the reconnection in a flag, not an error code. */
565                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
566                 GOTO(out, rc = 0);
567         }
568
569         if (target->obd_recovering) {
570                 target->obd_connected_clients++;
571         }
572
573         memcpy(&conn, lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn),
574                sizeof conn);
575
576         if (export->exp_imp_reverse != NULL)
577                 class_destroy_import(export->exp_imp_reverse);
578         revimp = export->exp_imp_reverse = class_new_import();
579         revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
580         revimp->imp_client = &export->exp_obd->obd_ldlm_client;
581         revimp->imp_remote_handle = conn;
582         revimp->imp_obd = target;
583         revimp->imp_dlm_fake = 1;
584         revimp->imp_state = LUSTRE_IMP_FULL;
585         class_import_put(revimp);
586 out:
587         if (rc)
588                 req->rq_status = rc;
589         RETURN(rc);
590 }
591
592 int target_handle_disconnect(struct ptlrpc_request *req)
593 {
594         struct obd_export *exp;
595         int rc;
596         ENTRY;
597
598         rc = lustre_pack_reply(req, 0, NULL, NULL);
599         if (rc)
600                 RETURN(rc);
601
602         /* keep the rq_export around so we can send the reply */
603         exp = class_export_get(req->rq_export);
604         req->rq_status = obd_disconnect(exp, 0);
605         RETURN(0);
606 }
607
608 void target_destroy_export(struct obd_export *exp)
609 {
610         /* exports created from last_rcvd data, and "fake"
611            exports created by lctl don't have an import */
612         if (exp->exp_imp_reverse != NULL)
613                 class_destroy_import(exp->exp_imp_reverse);
614
615         /* We cancel locks at disconnect time, but this will catch any locks
616          * granted in a race with recovery-induced disconnect. */
617         if (exp->exp_obd->obd_namespace != NULL)
618                 ldlm_cancel_locks_for_export(exp);
619 }
620
621 /*
622  * Recovery functions
623  */
624
625 struct ptlrpc_request *
626 ptlrpc_clone_req( struct ptlrpc_request *orig_req) 
627 {
628         struct ptlrpc_request *copy_req;
629         struct lustre_msg *copy_reqmsg;
630
631         OBD_ALLOC(copy_req, sizeof *copy_req);
632         if (!copy_req)
633                 return NULL;
634         OBD_ALLOC(copy_reqmsg, orig_req->rq_reqlen);
635         if (!copy_reqmsg){
636                 OBD_FREE(copy_req, sizeof *copy_req);
637                 return NULL;
638         }
639
640         memcpy(copy_req, orig_req, sizeof *copy_req);
641         memcpy(copy_reqmsg, orig_req->rq_reqmsg, orig_req->rq_reqlen);
642         /* the copied req takes over the reply state */
643         orig_req->rq_reply_state = NULL;
644
645         copy_req->rq_reqmsg = copy_reqmsg;
646         class_export_get(copy_req->rq_export);
647         INIT_LIST_HEAD(&copy_req->rq_list);
648
649         return copy_req;
650 }
651 void ptlrpc_free_clone( struct ptlrpc_request *req) 
652 {
653         class_export_put(req->rq_export);
654         list_del(&req->rq_list);
655         OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
656         OBD_FREE(req, sizeof *req);
657 }
658
659 static void abort_delayed_replies(struct obd_device *obd)
660 {
661         struct ptlrpc_request *req;
662         struct list_head *tmp, *n;
663         list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
664                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
665                 DEBUG_REQ(D_ERROR, req, "aborted:");
666                 req->rq_status = -ENOTCONN;
667                 req->rq_type = PTL_RPC_MSG_ERR;
668                 ptlrpc_reply(req);
669                 class_export_put(req->rq_export);
670                 list_del(&req->rq_list);
671                 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
672                 OBD_FREE(req, sizeof *req);
673         }
674 }
675
676 static void abort_recovery_queue(struct obd_device *obd)
677 {
678         struct ptlrpc_request *req;
679         struct list_head *tmp, *n;
680         int rc;
681
682         list_for_each_safe(tmp, n, &obd->obd_recovery_queue) {
683                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
684                 DEBUG_REQ(D_ERROR, req, "aborted:");
685                 req->rq_status = -ENOTCONN;
686                 req->rq_type = PTL_RPC_MSG_ERR;
687                 rc = lustre_pack_reply(req, 0, NULL, NULL);
688                 if (rc == 0) {
689                         ptlrpc_reply(req);
690                 } else {
691                         DEBUG_REQ(D_ERROR, req,
692                                   "packing failed for abort-reply; skipping");
693                 }
694                 list_del(&req->rq_list);
695                 class_export_put(req->rq_export);
696                 OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
697                 OBD_FREE(req, sizeof *req);
698         }
699 }
700
701 static void target_abort_recovery(void *data)
702 {
703         struct obd_device *obd = data;
704         int rc;
705
706         CERROR("disconnecting clients and aborting recovery\n");
707         LASSERT(!obd->obd_recovering);
708
709         class_disconnect_exports(obd, 0);
710
711         /* when recovery was aborted, cleanup orphans on mds and ost */
712         if (OBT(obd) && OBP(obd, postrecov)) {
713                 rc = OBP(obd, postrecov)(obd);
714                 if (rc >= 0)
715                         CWARN("Cleanup %d orphans after recovery was aborted\n",
716                               rc);
717                 else
718                         CERROR("postrecov failed %d\n", rc);
719         }
720
721         abort_delayed_replies(obd);
722         abort_recovery_queue(obd);
723         ptlrpc_run_recovery_over_upcall(obd);
724 }
725
726 static void target_recovery_expired(unsigned long castmeharder)
727 {
728         struct obd_device *obd = (struct obd_device *)castmeharder;
729         CERROR("recovery timed out, aborting\n");
730         spin_lock_bh(&obd->obd_processing_task_lock);
731         obd->obd_abort_recovery = 1;
732         wake_up(&obd->obd_next_transno_waitq);
733         spin_unlock_bh(&obd->obd_processing_task_lock);
734 }
735
736
737 /* obd_processing_task_lock should be held */
738 void target_cancel_recovery_timer(struct obd_device *obd)
739 {
740         CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
741         del_timer(&obd->obd_recovery_timer);
742 }
743
744 static void reset_recovery_timer(struct obd_device *obd)
745 {
746         spin_lock_bh(&obd->obd_processing_task_lock);
747         if (!obd->obd_recovering) {
748                 spin_unlock_bh(&obd->obd_processing_task_lock);
749                 return;
750         }                
751         CDEBUG(D_HA, "timer will expire in %u seconds\n",
752                OBD_RECOVERY_TIMEOUT / HZ);
753         mod_timer(&obd->obd_recovery_timer, jiffies + OBD_RECOVERY_TIMEOUT);
754         spin_unlock_bh(&obd->obd_processing_task_lock);
755 }
756
757
758 /* Only start it the first time called */
759 void target_start_recovery_timer(struct obd_device *obd)
760 {
761         spin_lock_bh(&obd->obd_processing_task_lock);
762         if (!obd->obd_recovering || timer_pending(&obd->obd_recovery_timer)) {
763                 spin_unlock_bh(&obd->obd_processing_task_lock);
764                 return;
765         }
766         CWARN("%s: starting recovery timer (%us)\n", obd->obd_name,
767                OBD_RECOVERY_TIMEOUT / HZ);
768         obd->obd_recovery_timer.function = target_recovery_expired;
769         obd->obd_recovery_timer.data = (unsigned long)obd;
770         mod_timer(&obd->obd_recovery_timer, jiffies + OBD_RECOVERY_TIMEOUT);
771         spin_unlock_bh(&obd->obd_processing_task_lock);
772 }
773
774 static void target_finish_recovery(struct obd_device *obd)
775 {
776         struct list_head *tmp, *n;
777         int rc2;
778
779         ldlm_reprocess_all_ns(obd->obd_namespace);
780
781         CWARN("%s: all clients recovered, calling postrecov\n",
782               obd->obd_name);
783         /* when recovery finished, cleanup orphans on mds and ost */
784         if (OBT(obd) && OBP(obd, postrecov)) {
785                 rc2 = OBP(obd, postrecov)(obd);
786                 if (rc2 >= 0)
787                         CWARN("%s: all clients recovered, %d MDS "
788                               "orphans deleted\n", obd->obd_name, rc2);
789                 else
790                         CERROR("postrecov failed %d\n", rc2);
791         }
792
793         CWARN("%s: recovery over, sending delayed replies\n",
794               obd->obd_name);
795         list_for_each_safe(tmp, n, &obd->obd_delayed_reply_queue) {
796                 struct ptlrpc_request *req;
797                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
798                 DEBUG_REQ(D_ERROR, req, "delayed:");
799                 ptlrpc_reply(req);
800                 ptlrpc_free_clone(req);
801         }
802         ptlrpc_run_recovery_over_upcall(obd);
803 }
804
805 static int check_for_next_transno(struct obd_device *obd)
806 {
807         struct ptlrpc_request *req;
808         int wake_up = 0, connected, completed, queue_len, max;
809         __u64 next_transno, req_transno;
810
811         spin_lock_bh(&obd->obd_processing_task_lock);
812         if (!list_empty(&obd->obd_recovery_queue)) {
813                 req = list_entry(obd->obd_recovery_queue.next,
814                                  struct ptlrpc_request, rq_list);
815                 req_transno = req->rq_reqmsg->transno;
816         } else {
817                 req_transno = 0;
818         }
819
820         max = obd->obd_max_recoverable_clients;
821         connected = obd->obd_connected_clients;
822         completed = max - obd->obd_recoverable_clients;
823         queue_len = obd->obd_requests_queued_for_recovery;
824         next_transno = obd->obd_next_recovery_transno;
825
826         CDEBUG(D_HA,"max: %d, connected: %d, completed: %d, queue_len: %d, "
827                "req_transno: "LPU64", next_transno: "LPU64"\n",
828                max, connected, completed, queue_len, req_transno, next_transno);
829         if (obd->obd_abort_recovery) {
830                 CDEBUG(D_HA, "waking for aborted recovery\n");
831                 wake_up = 1;
832         } else if (max == completed) {
833                 CDEBUG(D_HA, "waking for completed recovery\n");
834                 wake_up = 1;
835         } else if (req_transno == next_transno) {
836                 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
837                 wake_up = 1;
838         } else if (queue_len + completed == max) {
839                 LASSERT(req->rq_reqmsg->transno >= next_transno);
840                 CDEBUG(D_ERROR,
841                        "waking for skipped transno (skip: "LPD64
842                        ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
843                        next_transno, queue_len, completed, max, req_transno);
844                 obd->obd_next_recovery_transno = req_transno;
845                 wake_up = 1;
846         }
847         spin_unlock_bh(&obd->obd_processing_task_lock);
848         
849         return wake_up;
850 }
851
852 static struct ptlrpc_request *
853 target_next_replay_req(struct obd_device *obd)
854 {
855         struct l_wait_info lwi = { 0 };
856         struct ptlrpc_request *req;
857
858         CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
859                obd->obd_next_recovery_transno);
860         l_wait_event(obd->obd_next_transno_waitq,
861                      check_for_next_transno(obd), &lwi);
862         
863         spin_lock_bh(&obd->obd_processing_task_lock);
864         if (obd->obd_abort_recovery) {
865                 req = NULL;
866         } else if (!list_empty(&obd->obd_recovery_queue)) {
867                 req = list_entry(obd->obd_recovery_queue.next,
868                                  struct ptlrpc_request, rq_list);
869                 list_del_init(&req->rq_list);
870                 obd->obd_requests_queued_for_recovery--;
871         } else {
872                 req = NULL;
873         }
874         spin_unlock_bh(&obd->obd_processing_task_lock);
875         return req;
876 }
877
878
879 static int target_recovery_thread(void *arg)
880 {
881         struct obd_device *obd = arg;
882         struct ptlrpc_request *req;
883         struct target_recovery_data *trd = &obd->obd_recovery_data;
884         unsigned long flags;
885         ENTRY;
886
887         kportal_daemonize("tgt-recov");
888
889         SIGNAL_MASK_LOCK(current, flags);
890         sigfillset(&current->blocked);
891         RECALC_SIGPENDING;
892         SIGNAL_MASK_UNLOCK(current, flags);
893
894         CERROR("%s: started recovery thread pid %d\n", obd->obd_name, 
895                current->pid);
896         trd->trd_processing_task = current->pid;
897
898         obd->obd_recovering = 1;
899         complete(&trd->trd_starting);
900
901         while (obd->obd_recovering) {
902                 LASSERT(trd->trd_processing_task == current->pid);
903                 req = target_next_replay_req(obd);
904                 if (req != NULL) {
905                         char peer_str[PTL_NALFMT_SIZE];
906                         DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s: ", 
907                                   req->rq_reqmsg->transno, 
908                                   ptlrpc_peernid2str(&req->rq_peer, peer_str));
909                         (void)trd->trd_recovery_handler(req);
910                         obd->obd_replayed_requests++;
911                         reset_recovery_timer(obd);
912                         /* bug 1580: decide how to properly sync() in recovery*/
913                         //mds_fsync_super(mds->mds_sb);
914                         ptlrpc_free_clone(req);
915                         spin_lock_bh(&obd->obd_processing_task_lock);
916                         obd->obd_next_recovery_transno++;
917                         spin_unlock_bh(&obd->obd_processing_task_lock);
918                 } else {
919                         /* recovery is over */
920                         spin_lock_bh(&obd->obd_processing_task_lock);
921                         obd->obd_recovering = 0;
922                         target_cancel_recovery_timer(obd);
923                         if (obd->obd_abort_recovery) {
924                                 obd->obd_abort_recovery = 0;
925                                 spin_unlock_bh(&obd->obd_processing_task_lock);
926                                 target_abort_recovery(obd); 
927                         } else {
928                                 LASSERT(obd->obd_recoverable_clients == 0);
929                                 spin_unlock_bh(&obd->obd_processing_task_lock);
930                                 target_finish_recovery(obd);
931                         }
932                 }
933         }
934
935         trd->trd_processing_task = 0;
936         complete(&trd->trd_finishing);
937         return 0;
938 }
939
940 int target_start_recovery_thread(struct obd_device *obd, svc_handler_t handler)
941 {
942         int rc = 0;
943         struct target_recovery_data *trd = &obd->obd_recovery_data;
944
945         memset(trd, 0, sizeof(*trd));
946         init_completion(&trd->trd_starting);
947         init_completion(&trd->trd_finishing);
948         trd->trd_recovery_handler = handler;
949
950         if (kernel_thread(target_recovery_thread, obd, 0) == 0) 
951                 wait_for_completion(&trd->trd_starting);
952         else
953                 rc = -ECHILD;
954
955         return rc;
956 }
957
958 void target_stop_recovery_thread(struct obd_device *obd)
959 {
960         spin_lock_bh(&obd->obd_processing_task_lock);
961         if (obd->obd_recovery_data.trd_processing_task > 0) {
962                 struct target_recovery_data *trd = &obd->obd_recovery_data;
963                 CERROR("%s: aborting recovery\n", obd->obd_name);
964                 obd->obd_abort_recovery = 1;
965                 wake_up(&obd->obd_next_transno_waitq);
966                 spin_unlock_bh(&obd->obd_processing_task_lock);
967                 wait_for_completion(&trd->trd_finishing);
968         } else {
969                 spin_unlock_bh(&obd->obd_processing_task_lock);
970         }
971 }
972
973 int target_queue_recovery_request(struct ptlrpc_request *req,
974                                   struct obd_device *obd)
975 {
976         struct list_head *tmp;
977         int inserted = 0;
978         __u64 transno = req->rq_reqmsg->transno;
979
980         /* CAVEAT EMPTOR: The incoming request message has been swabbed
981          * (i.e. buflens etc are in my own byte order), but type-dependent
982          * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
983
984         if (!transno) {
985                 INIT_LIST_HEAD(&req->rq_list);
986                 DEBUG_REQ(D_HA, req, "not queueing");
987                 return 1;
988         }
989
990
991         /* If we're processing the queue, we want don't want to queue this
992          * message.
993          *
994          * Also, if this request has a transno less than the one we're waiting
995          * for, we should process it now.  It could (and currently always will)
996          * be an open request for a descriptor that was opened some time ago.
997          *
998          * Also, a resent, replayed request that has already been
999          * handled will pass through here and be processed immediately.
1000          */
1001         spin_lock_bh(&obd->obd_processing_task_lock);
1002         if (obd->obd_recovery_data.trd_processing_task == current->pid ||
1003             transno < obd->obd_next_recovery_transno) {
1004                 /* Processing the queue right now, don't re-add. */
1005                 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1006                 LASSERT(list_empty(&req->rq_list));
1007                 spin_unlock_bh(&obd->obd_processing_task_lock);
1008                 return 1;
1009         }
1010         spin_unlock_bh(&obd->obd_processing_task_lock);
1011
1012         /* A resent, replayed request that is still on the queue; just drop it.
1013            The queued request will handle this. */
1014         if ((lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY))
1015             == (MSG_RESENT | MSG_REPLAY)) {
1016                 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
1017                 return 0;
1018         }
1019
1020         req = ptlrpc_clone_req(req);
1021         if (req == NULL)
1022                 return -ENOMEM;
1023
1024         spin_lock_bh(&obd->obd_processing_task_lock);
1025
1026         /* XXX O(n^2) */
1027         list_for_each(tmp, &obd->obd_recovery_queue) {
1028                 struct ptlrpc_request *reqiter =
1029                         list_entry(tmp, struct ptlrpc_request, rq_list);
1030
1031                 if (reqiter->rq_reqmsg->transno > transno) {
1032                         list_add_tail(&req->rq_list, &reqiter->rq_list);
1033                         inserted = 1;
1034                         break;
1035                 }
1036         }
1037
1038         if (!inserted) {
1039                 list_add_tail(&req->rq_list, &obd->obd_recovery_queue);
1040         }
1041
1042         obd->obd_requests_queued_for_recovery++;
1043         wake_up(&obd->obd_next_transno_waitq);
1044         spin_unlock_bh(&obd->obd_processing_task_lock);
1045
1046         return 0;
1047 }
1048
1049 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1050 {
1051         return req->rq_export->exp_obd;
1052 }
1053
1054 int target_queue_final_reply(struct ptlrpc_request *req, int rc)
1055 {
1056         struct obd_device *obd = target_req2obd(req);
1057
1058         LASSERT ((rc == 0) == (req->rq_reply_state != NULL));
1059
1060         if (rc) {
1061                 /* Just like ptlrpc_error, but without the sending. */
1062                 rc = lustre_pack_reply(req, 0, NULL, NULL);
1063                 LASSERT(rc == 0); /* XXX handle this */
1064                 req->rq_type = PTL_RPC_MSG_ERR;
1065         }
1066
1067         LASSERT (!req->rq_reply_state->rs_difficult);
1068         LASSERT(list_empty(&req->rq_list));
1069         
1070         req = ptlrpc_clone_req(req);
1071
1072         spin_lock_bh(&obd->obd_processing_task_lock);
1073
1074         list_add(&req->rq_list, &obd->obd_delayed_reply_queue);
1075
1076         /* only count the first "replay over" request from each
1077            export */
1078         if (req->rq_export->exp_replay_needed) {
1079                 --obd->obd_recoverable_clients;
1080                 req->rq_export->exp_replay_needed = 0;
1081                 CWARN("%s: %d recoverable clients remain\n",
1082                       obd->obd_name, obd->obd_recoverable_clients);
1083         }
1084         wake_up(&obd->obd_next_transno_waitq);
1085         spin_unlock_bh(&obd->obd_processing_task_lock);
1086         return 1;
1087 }
1088
1089 int
1090 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1091 {
1092         if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1093                 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1094                 DEBUG_REQ(D_ERROR, req, "dropping reply");
1095                 /* NB this does _not_ send with ACK disabled, to simulate
1096                  * sending OK, but timing out for the ACK */
1097                 if (req->rq_reply_state != NULL) {
1098                         if (!req->rq_reply_state->rs_difficult) {
1099                                 lustre_free_reply_state (req->rq_reply_state);
1100                                 req->rq_reply_state = NULL;
1101                         } else {
1102                                 struct ptlrpc_service *svc =
1103                                         req->rq_rqbd->rqbd_srv_ni->sni_service;
1104                                 atomic_inc(&svc->srv_outstanding_replies);
1105                         }
1106                 }
1107                 return (-ECOMM);
1108         }
1109
1110         if (rc) {
1111                 DEBUG_REQ(D_ERROR, req, "processing error (%d)", rc);
1112                 if (req->rq_reply_state == NULL) {
1113                         rc = lustre_pack_reply (req, 0, NULL, NULL);
1114                         if (rc != 0) {
1115                                 CERROR ("can't allocate reply\n");
1116                                 return (rc);
1117                         }
1118                 }
1119                 req->rq_type = PTL_RPC_MSG_ERR;
1120         } else {
1121                 DEBUG_REQ(D_NET, req, "sending reply");
1122         }
1123         
1124         return (ptlrpc_send_reply(req, 1));
1125 }
1126
1127 void 
1128 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1129 {
1130         int                        netrc;
1131         unsigned long              flags;
1132         struct ptlrpc_reply_state *rs;
1133         struct obd_device         *obd;
1134         struct obd_export         *exp;
1135         struct ptlrpc_srv_ni      *sni;
1136         struct ptlrpc_service     *svc;
1137
1138         sni = req->rq_rqbd->rqbd_srv_ni;
1139         svc = sni->sni_service;
1140         
1141         rs = req->rq_reply_state;
1142         if (rs == NULL || !rs->rs_difficult) {
1143                 /* The easy case; no notifiers and reply_out_callback()
1144                  * cleans up (i.e. we can't look inside rs after a
1145                  * successful send) */
1146                 netrc = target_send_reply_msg (req, rc, fail_id);
1147
1148                 LASSERT (netrc == 0 || req->rq_reply_state == NULL);
1149                 return;
1150         }
1151
1152         /* must be an export if locks saved */
1153         LASSERT (req->rq_export != NULL);
1154         /* req/reply consistent */
1155         LASSERT (rs->rs_srv_ni == sni);
1156
1157         /* "fresh" reply */
1158         LASSERT (!rs->rs_scheduled);
1159         LASSERT (!rs->rs_scheduled_ever);
1160         LASSERT (!rs->rs_handled);
1161         LASSERT (!rs->rs_on_net);
1162         LASSERT (rs->rs_export == NULL);
1163         LASSERT (list_empty(&rs->rs_obd_list));
1164         LASSERT (list_empty(&rs->rs_exp_list));
1165
1166         exp = class_export_get (req->rq_export);
1167         obd = exp->exp_obd;
1168
1169         /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1170         rs->rs_scheduled = 1;
1171         rs->rs_on_net    = 1;
1172         rs->rs_xid       = req->rq_xid;
1173         rs->rs_transno   = req->rq_transno;
1174         rs->rs_export    = exp;
1175         
1176         spin_lock_irqsave (&obd->obd_uncommitted_replies_lock, flags);
1177
1178         if (rs->rs_transno > obd->obd_last_committed) {
1179                 /* not committed already */ 
1180                 list_add_tail (&rs->rs_obd_list, 
1181                                &obd->obd_uncommitted_replies);
1182         }
1183
1184         spin_unlock (&obd->obd_uncommitted_replies_lock);
1185         spin_lock (&exp->exp_lock);
1186
1187         list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1188
1189         spin_unlock_irqrestore (&exp->exp_lock, flags);
1190
1191         netrc = target_send_reply_msg (req, rc, fail_id);
1192
1193         spin_lock_irqsave (&svc->srv_lock, flags);
1194
1195         svc->srv_n_difficult_replies++;
1196
1197         if (netrc != 0) /* error sending: reply is off the net */
1198                 rs->rs_on_net = 0;
1199
1200         if (!rs->rs_on_net ||                   /* some notifier */
1201             list_empty(&rs->rs_exp_list) ||     /* completed already */
1202             list_empty(&rs->rs_obd_list)) {
1203                 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
1204                 wake_up (&svc->srv_waitq);
1205         } else {
1206                 list_add (&rs->rs_list, &sni->sni_active_replies);
1207                 rs->rs_scheduled = 0;           /* allow notifier to schedule */
1208         }
1209
1210         spin_unlock_irqrestore (&svc->srv_lock, flags);
1211 }
1212
1213 int target_handle_ping(struct ptlrpc_request *req)
1214 {
1215         return lustre_pack_reply(req, 0, NULL, NULL);
1216 }