Whamcloud - gitweb
- landed b_hd_mdref (mostly WB cache fixes)
[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 #include <linux/lustre_sec.h>
39 #include <linux/lustre_gs.h>
40
41 /* @priority: if non-zero, move the selected to the list head
42  * @nocreate: if non-zero, only search in existed connections
43  */
44 static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
45                            int priority, int nocreate)
46 {
47         struct ptlrpc_connection *ptlrpc_conn;
48         struct obd_import_conn *imp_conn = NULL, *item;
49         int rc = 0;
50         ENTRY;
51
52         LASSERT(!(nocreate && !priority));
53
54         ptlrpc_conn = ptlrpc_uuid_to_connection(uuid);
55         if (!ptlrpc_conn) {
56                 CERROR("can't find connection %s\n", uuid->uuid);
57                 RETURN (-EINVAL);
58         }
59
60         if (!nocreate) {
61                 OBD_ALLOC(imp_conn, sizeof(*imp_conn));
62                 if (!imp_conn) {
63                         CERROR("fail to alloc memory\n");
64                         GOTO(out_put, rc = -ENOMEM);
65                 }
66         }
67
68         spin_lock(&imp->imp_lock);
69         list_for_each_entry(item, &imp->imp_conn_list, oic_item) {
70                 if (obd_uuid_equals(uuid, &item->oic_uuid)) {
71                         if (priority) {
72                                 list_del(&item->oic_item);
73                                 list_add(&item->oic_item, &imp->imp_conn_list);
74                                 item->oic_last_attempt = 0;
75                         }
76                         CDEBUG(D_HA, "imp %p@%s: find existed conn %s%s\n",
77                                imp, imp->imp_obd->obd_name, uuid->uuid,
78                                (priority ? ", move to head." : ""));
79                         spin_unlock(&imp->imp_lock);
80                         GOTO(out_free, rc = 0);
81                 }
82         }
83         /* not found */
84         if (!nocreate) {
85                 imp_conn->oic_conn = ptlrpc_conn;
86                 imp_conn->oic_uuid = *uuid;
87                 imp_conn->oic_last_attempt = 0;
88                 if (priority)
89                         list_add(&imp_conn->oic_item, &imp->imp_conn_list);
90                 else
91                         list_add_tail(&imp_conn->oic_item, &imp->imp_conn_list);
92                 CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n",
93                        imp, imp->imp_obd->obd_name, uuid->uuid,
94                        (priority ? "head" : "tail"));
95         } else
96                 rc = -ENOENT;
97
98         spin_unlock(&imp->imp_lock);
99         RETURN(0);
100 out_free:
101         if (imp_conn)
102                 OBD_FREE(imp_conn, sizeof(*imp_conn));
103 out_put:
104         ptlrpc_put_connection(ptlrpc_conn);
105         RETURN(rc);
106 }
107
108 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid)
109 {
110         return import_set_conn(imp, uuid, 1, 1);
111 }
112
113 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
114                            int priority)
115 {
116         return import_set_conn(imp, uuid, priority, 0);
117 }
118
119 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
120 {
121         struct obd_import_conn *imp_conn;
122         struct obd_export *dlmexp;
123         int rc = -ENOENT;
124         ENTRY;
125
126         spin_lock(&imp->imp_lock);
127         if (list_empty(&imp->imp_conn_list)) {
128                 LASSERT(!imp->imp_conn_current);
129                 LASSERT(!imp->imp_connection);
130                 GOTO(out, rc);
131         }
132
133         list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) {
134                 if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid))
135                         continue;
136                 LASSERT(imp_conn->oic_conn);
137
138                 /* is current conn? */
139                 if (imp_conn == imp->imp_conn_current) {
140                         LASSERT(imp_conn->oic_conn == imp->imp_connection);
141
142                         if (imp->imp_state != LUSTRE_IMP_CLOSED &&
143                             imp->imp_state != LUSTRE_IMP_DISCON) {
144                                 CERROR("can't remove current connection\n");
145                                 GOTO(out, rc = -EBUSY);
146                         }
147
148                         ptlrpc_put_connection(imp->imp_connection);
149                         imp->imp_connection = NULL;
150
151                         dlmexp = class_conn2export(&imp->imp_dlm_handle);
152                         if (dlmexp && dlmexp->exp_connection) {
153                                 LASSERT(dlmexp->exp_connection ==
154                                         imp_conn->oic_conn);
155                                 ptlrpc_put_connection(dlmexp->exp_connection);
156                                 dlmexp->exp_connection = NULL;
157                         }
158                 }
159
160                 list_del(&imp_conn->oic_item);
161                 ptlrpc_put_connection(imp_conn->oic_conn);
162                 OBD_FREE(imp_conn, sizeof(*imp_conn));
163                 CDEBUG(D_HA, "imp %p@%s: remove connection %s\n",
164                        imp, imp->imp_obd->obd_name, uuid->uuid);
165                 rc = 0;
166                 break;
167         }
168 out:
169         spin_unlock(&imp->imp_lock);
170         if (rc == -ENOENT)
171                 CERROR("connection %s not found\n", uuid->uuid);
172         RETURN(rc);
173 }
174
175 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
176 {
177         struct lustre_cfg* lcfg = buf;
178         struct client_obd *cli = &obddev->u.cli;
179         struct obd_import *imp;
180         struct obd_uuid server_uuid;
181         int rq_portal, rp_portal, connect_op;
182         char *name = obddev->obd_type->typ_name;
183         char *mgmt_name = NULL;
184         int rc;
185         ENTRY;
186
187         /* In a more perfect world, we would hang a ptlrpc_client off of
188          * obd_type and just use the values from there. */
189         if (!strcmp(name, OBD_OSC_DEVICENAME)) {
190                 rq_portal = OST_REQUEST_PORTAL;
191                 rp_portal = OSC_REPLY_PORTAL;
192                 connect_op = OST_CONNECT;
193         } else if (!strcmp(name, OBD_MDC_DEVICENAME)) {
194                 rq_portal = MDS_REQUEST_PORTAL;
195                 rp_portal = MDC_REPLY_PORTAL;
196                 connect_op = MDS_CONNECT;
197         } else if (!strcmp(name, OBD_MGMTCLI_DEVICENAME)) {
198                 rq_portal = MGMT_REQUEST_PORTAL;
199                 rp_portal = MGMT_REPLY_PORTAL;
200                 connect_op = MGMT_CONNECT;
201         } else if (!strcmp(name, LUSTRE_GKC_NAME)) {
202                 rq_portal = GKS_REQUEST_PORTAL;
203                 rp_portal = GKC_REPLY_PORTAL;
204                 connect_op = GKS_CONNECT;
205
206         } else {
207                 CERROR("unknown client OBD type \"%s\", can't setup\n",
208                        name);
209                 RETURN(-EINVAL);
210         }
211
212
213         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
214                 CERROR("requires a TARGET UUID\n");
215                 RETURN(-EINVAL);
216         }
217
218         if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
219                 CERROR("client UUID must be less than 38 characters\n");
220                 RETURN(-EINVAL);
221         }
222
223         if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
224                 CERROR("setup requires a SERVER UUID\n");
225                 RETURN(-EINVAL);
226         }
227
228         if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
229                 CERROR("target UUID must be less than 38 characters\n");
230                 RETURN(-EINVAL);
231         }
232
233         sema_init(&cli->cl_sem, 1);
234         cli->cl_conn_count = 0;
235         memcpy(server_uuid.uuid,  lustre_cfg_buf(lcfg, 2),
236                min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2), 
237                sizeof(server_uuid)));
238
239         cli->cl_dirty = 0;
240         cli->cl_avail_grant = 0;
241         /* FIXME: should limit this for the sum of all cl_dirty_max */
242         cli->cl_dirty_max = OSC_MAX_DIRTY_DEFAULT * 1024 * 1024;
243         if (cli->cl_dirty_max >> PAGE_SHIFT > num_physpages / 8)
244                 cli->cl_dirty_max = num_physpages << (PAGE_SHIFT - 3);
245         INIT_LIST_HEAD(&cli->cl_cache_waiters);
246         INIT_LIST_HEAD(&cli->cl_loi_ready_list);
247         INIT_LIST_HEAD(&cli->cl_loi_write_list);
248         INIT_LIST_HEAD(&cli->cl_loi_read_list);
249         spin_lock_init(&cli->cl_loi_list_lock);
250         cli->cl_r_in_flight = 0;
251         cli->cl_w_in_flight = 0;
252         spin_lock_init(&cli->cl_read_rpc_hist.oh_lock);
253         spin_lock_init(&cli->cl_write_rpc_hist.oh_lock);
254         spin_lock_init(&cli->cl_read_page_hist.oh_lock);
255         spin_lock_init(&cli->cl_write_page_hist.oh_lock);
256
257         if (num_physpages >> (20 - PAGE_SHIFT) <= 128) { /* <= 128 MB */
258                 cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES / 4;
259                 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT / 4;
260 #if 0
261         } else if (num_physpages >> (20 - PAGE_SHIFT) <= 512) { /* <= 512 MB */
262                 cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES / 2;
263                 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT / 2;
264 #endif
265         } else {
266                 cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES;
267                 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
268         }
269
270         rc = ldlm_get_ref();
271         if (rc) {
272                 CERROR("ldlm_get_ref failed: %d\n", rc);
273                 GOTO(err, rc);
274         }
275
276         ptlrpc_init_client(rq_portal, rp_portal, name,
277                            &obddev->obd_ldlm_client);
278
279         imp = class_new_import();
280         if (imp == NULL) 
281                 GOTO(err_ldlm, rc = -ENOENT);
282         imp->imp_client = &obddev->obd_ldlm_client;
283         imp->imp_obd = obddev;
284         imp->imp_connect_op = connect_op;
285         imp->imp_generation = 0;
286         imp->imp_initial_recov = 1;
287         INIT_LIST_HEAD(&imp->imp_pinger_chain);
288         memcpy(imp->imp_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
289                LUSTRE_CFG_BUFLEN(lcfg, 1));
290         class_import_put(imp);
291
292         rc = client_import_add_conn(imp, &server_uuid, 1);
293         if (rc) {
294                 CERROR("can't add initial connection\n");
295                 GOTO(err_import, rc);
296         }
297
298         cli->cl_import = imp;
299         cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
300         cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
301         cli->cl_sandev = to_kdev_t(0);
302
303         if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
304                 if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) {
305                         CDEBUG(D_HA, "marking %s %s->%s as inactive\n",
306                                name, obddev->obd_name,
307                                imp->imp_target_uuid.uuid);
308                         imp->imp_invalid = 1;
309
310                         if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0)
311                                 mgmt_name = lustre_cfg_string(lcfg, 4);
312                 } else {
313                         mgmt_name = lustre_cfg_string(lcfg, 3);
314                 }
315         }
316 #if 0
317         if (mgmt_name != NULL) {
318                 /* Register with management client if we need to. */
319                 CDEBUG(D_HA, "%s registering with %s for events about %s\n",
320                        obddev->obd_name, mgmt_name, server_uuid.uuid);
321
322                 mgmt_obd = class_name2obd(mgmt_name);
323                 if (!mgmt_obd) {
324                         CERROR("can't find mgmtcli %s to register\n",
325                                mgmt_name);
326                         GOTO(err_import, rc = -ENOSYS);
327                 }
328
329                 register_f = (mgmtcli_register_for_events_t)symbol_get("mgmtcli_register_for_events");
330                 if (!register_f) {
331                         CERROR("can't i_m_g mgmtcli_register_for_events\n");
332                         GOTO(err_import, rc = -ENOSYS);
333                 }
334
335                 rc = register_f(mgmt_obd, obddev, &imp->imp_target_uuid);
336                 symbol_put("mgmtcli_register_for_events");
337
338                 if (!rc)
339                         cli->cl_mgmtcli_obd = mgmt_obd;
340         }
341 #endif
342         RETURN(rc);
343
344 err_import:
345         class_destroy_import(imp);
346 err_ldlm:
347         ldlm_put_ref(0);
348 err:
349         RETURN(rc);
350
351 }
352
353 int client_obd_cleanup(struct obd_device *obddev, int flags)
354 {
355         struct client_obd *cli = &obddev->u.cli;
356         ENTRY;
357
358         if (!cli->cl_import)
359                 RETURN(-EINVAL);
360         if (cli->cl_mgmtcli_obd) {
361                 mgmtcli_deregister_for_events_t dereg_f;
362
363                 dereg_f = (mgmtcli_deregister_for_events_t)symbol_get("mgmtcli_deregister_for_events");
364                 dereg_f(cli->cl_mgmtcli_obd, obddev);
365                 symbol_put("mgmtcli_deregister_for_events");
366         }
367
368         /* Here we try to drop the security structure after destroy import,
369          * to avoid issue of "sleep in spinlock".
370          */
371         class_import_get(cli->cl_import);
372         class_destroy_import(cli->cl_import);
373         ptlrpcs_import_drop_sec(cli->cl_import);
374         class_import_put(cli->cl_import);
375         cli->cl_import = NULL;
376
377         ldlm_put_ref(flags & OBD_OPT_FORCE);
378
379         RETURN(0);
380 }
381
382 int client_connect_import(struct lustre_handle *dlm_handle,
383                           struct obd_device *obd,
384                           struct obd_uuid *cluuid,
385                           struct obd_connect_data *conn_data,
386                           unsigned long connect_flags)
387 {
388         struct client_obd *cli = &obd->u.cli;
389         struct obd_import *imp = cli->cl_import;
390         struct obd_export *exp;
391         int rc;
392         ENTRY;
393
394         down(&cli->cl_sem);
395         rc = class_connect(dlm_handle, obd, cluuid);
396         if (rc)
397                 GOTO(out_sem, rc);
398
399         cli->cl_conn_count++;
400         if (cli->cl_conn_count > 1)
401                 GOTO(out_sem, rc);
402         exp = class_conn2export(dlm_handle);
403
404         if (obd->obd_namespace != NULL)
405                 CERROR("already have namespace!\n");
406         obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
407                                                 LDLM_NAMESPACE_CLIENT);
408         if (obd->obd_namespace == NULL)
409                 GOTO(out_disco, rc = -ENOMEM);
410
411         rc = ptlrpcs_import_get_sec(imp);
412         if (rc != 0)
413                 GOTO(out_ldlm, rc);
414
415         imp->imp_dlm_handle = *dlm_handle;
416         rc = ptlrpc_init_import(imp);
417         if (rc != 0) 
418                 GOTO(out_ldlm, rc);
419
420         imp->imp_connect_flags = connect_flags;
421         if (conn_data)
422                 memcpy(&imp->imp_connect_data, conn_data, sizeof(*conn_data));
423
424         rc = ptlrpc_connect_import(imp, NULL);
425         if (rc != 0) {
426                 LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
427                 GOTO(out_ldlm, rc);
428         }
429         LASSERT(exp->exp_connection);
430         ptlrpc_pinger_add_import(imp);
431         EXIT;
432
433         if (rc) {
434 out_ldlm:
435                 ldlm_namespace_free(obd->obd_namespace, 0);
436                 obd->obd_namespace = NULL;
437 out_disco:
438                 cli->cl_conn_count--;
439                 class_disconnect(exp, 0);
440         } else {
441                 class_export_put(exp);
442         }
443 out_sem:
444         up(&cli->cl_sem);
445         return rc;
446 }
447
448 int client_disconnect_export(struct obd_export *exp, unsigned long flags)
449 {
450         struct obd_device *obd = class_exp2obd(exp);
451         struct client_obd *cli = &obd->u.cli;
452         struct obd_import *imp = cli->cl_import;
453         int rc = 0, err;
454         ENTRY;
455
456         if (!obd) {
457                 CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
458                        exp, exp ? exp->exp_handle.h_cookie : -1);
459                 RETURN(-EINVAL);
460         }
461
462         down(&cli->cl_sem);
463         if (!cli->cl_conn_count) {
464                 CERROR("disconnecting disconnected device (%s)\n",
465                        obd->obd_name);
466                 GOTO(out_sem, rc = -EINVAL);
467         }
468
469         cli->cl_conn_count--;
470         if (cli->cl_conn_count)
471                 GOTO(out_no_disconnect, rc = 0);
472
473         /* Some non-replayable imports (MDS's OSCs) are pinged, so just
474          * delete it regardless.  (It's safe to delete an import that was
475          * never added.) */
476         (void)ptlrpc_pinger_del_import(imp);
477
478         if (obd->obd_namespace != NULL) {
479                 /* obd_no_recov == local only */
480                 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
481                                        obd->obd_no_recov, NULL);
482                 ldlm_namespace_free(obd->obd_namespace, obd->obd_no_recov);
483                 obd->obd_namespace = NULL;
484         }
485
486         /* 
487          * Yeah, obd_no_recov also (mainly) means "forced shutdown".
488          */
489         if (obd->obd_no_recov)
490                 ptlrpc_invalidate_import(imp, 0);
491         else
492                 rc = ptlrpc_disconnect_import(imp);
493
494         EXIT;
495  out_no_disconnect:
496         err = class_disconnect(exp, 0);
497         if (!rc && err)
498                 rc = err;
499  out_sem:
500         up(&cli->cl_sem);
501         RETURN(rc);
502 }
503
504 /* --------------------------------------------------------------------------
505  * from old lib/target.c
506  * -------------------------------------------------------------------------- */
507
508 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
509                             struct obd_uuid *cluuid, int initial_conn)
510 {
511         if (exp->exp_connection && !initial_conn) {
512                 struct lustre_handle *hdl;
513                 hdl = &exp->exp_imp_reverse->imp_remote_handle;
514                 /* Might be a re-connect after a partition. */
515                 if (!memcmp(&conn->cookie, &hdl->cookie, sizeof conn->cookie)) {
516                         CERROR("%s reconnecting\n", cluuid->uuid);
517                         conn->cookie = exp->exp_handle.h_cookie;
518                         RETURN(EALREADY);
519                 } else {
520                         CERROR("%s reconnecting from %s, "
521                                "handle mismatch (ours "LPX64", theirs "
522                                LPX64")\n", cluuid->uuid,
523                                exp->exp_connection->c_remote_uuid.uuid,
524                                hdl->cookie, conn->cookie);
525                         memset(conn, 0, sizeof *conn);
526                         RETURN(-EALREADY);
527                 }
528         }
529
530         conn->cookie = exp->exp_handle.h_cookie;
531         CDEBUG(D_INFO, "existing export for UUID '%s' at %p\n",
532                cluuid->uuid, exp);
533         CDEBUG(D_IOCTL,"connect: cookie "LPX64"\n", conn->cookie);
534         RETURN(0);
535 }
536
537 static inline int ptlrpc_peer_is_local(struct ptlrpc_peer *peer)
538 {
539         ptl_process_id_t myid;
540
541         PtlGetId(peer->peer_ni->pni_ni_h, &myid);
542         return (memcmp(&peer->peer_id, &myid, sizeof(myid)) == 0);
543 }
544
545 /* To check whether the p_flavor is in deny list or not
546  * rc:
547  *      0           not found, pass
548  *      EPERM       found, refuse
549  */
550
551 static int check_deny_list(struct list_head *head, __u32 flavor)
552 {
553         deny_sec_t *p_deny_sec = NULL;
554         deny_sec_t *n_deny_sec = NULL;
555
556         list_for_each_entry_safe(p_deny_sec, n_deny_sec, head, list) {
557                 if (p_deny_sec->flavor == flavor)
558                         return -EPERM;
559         }
560         return 0;
561 }
562
563 int target_check_deny_sec(struct obd_device *target, struct ptlrpc_request *req)
564 {
565         __u32 flavor;
566         int rc = 0;
567
568         flavor = req->rq_req_secflvr;
569
570         if (!strcmp(target->obd_type->typ_name, OBD_MDS_DEVICENAME)) {
571                 spin_lock(&target->u.mds.mds_denylist_lock);
572                 rc = check_deny_list(&target->u.mds.mds_denylist, flavor);
573                 spin_unlock(&target->u.mds.mds_denylist_lock);
574         } else if (!strcmp(target->obd_type->typ_name, OBD_FILTER_DEVICENAME)) {
575                 spin_lock(&target->u.filter.fo_denylist_lock);
576                 rc = check_deny_list(&target->u.filter.fo_denylist, flavor);
577                 spin_unlock(&target->u.filter.fo_denylist_lock);
578         }
579
580         return rc;
581 }
582
583 int target_handle_connect(struct ptlrpc_request *req)
584 {
585         unsigned long connect_flags = 0, *cfp;
586         struct obd_device *target;
587         struct obd_export *export = NULL;
588         struct obd_import *revimp;
589         struct lustre_handle conn;
590         struct obd_uuid tgtuuid;
591         struct obd_uuid cluuid;
592         struct obd_uuid remote_uuid;
593         struct list_head *p;
594         struct obd_connect_data *conn_data;
595         int conn_data_size = sizeof(*conn_data);
596         char *str, *tmp;
597         int rc = 0;
598         unsigned long flags;
599         int initial_conn = 0;
600         char peer_str[PTL_NALFMT_SIZE];
601         const int offset = 1;
602         ENTRY;
603
604         OBD_RACE(OBD_FAIL_TGT_CONN_RACE); 
605
606         LASSERT_REQSWAB (req, offset + 0);
607         str = lustre_msg_string(req->rq_reqmsg, offset + 0,
608                                 sizeof(tgtuuid) - 1);
609         if (str == NULL) {
610                 CERROR("bad target UUID for connect\n");
611                 GOTO(out, rc = -EINVAL);
612         }
613
614         obd_str2uuid (&tgtuuid, str);
615         target = class_uuid2obd(&tgtuuid);
616         if (!target)
617                 target = class_name2obd(str);
618         
619         if (!target || target->obd_stopping || !target->obd_set_up) {
620                 CERROR("UUID '%s' is not available for connect from %s\n",
621                        str, req->rq_peerstr);
622                 GOTO(out, rc = -ENODEV);
623         }
624
625         /* check the secure deny list of mds/ost */
626         rc = target_check_deny_sec(target, req);
627         if (rc != 0)
628                 GOTO(out, rc);
629
630         LASSERT_REQSWAB (req, offset + 1);
631         str = lustre_msg_string(req->rq_reqmsg, offset + 1, sizeof(cluuid) - 1);
632         if (str == NULL) {
633                 CERROR("bad client UUID for connect\n");
634                 GOTO(out, rc = -EINVAL);
635         }
636
637         obd_str2uuid (&cluuid, str);
638
639         /* XXX extract a nettype and format accordingly */
640         switch (sizeof(ptl_nid_t)) {
641                 /* NB the casts only avoid compiler warnings */
642         case 8:
643                 snprintf((char *)remote_uuid.uuid, sizeof(remote_uuid),
644                          "NET_"LPX64"_UUID", (__u64)req->rq_peer.peer_id.nid);
645                 break;
646         case 4:
647                 snprintf((char *)remote_uuid.uuid, sizeof(remote_uuid),
648                          "NET_%x_UUID", (__u32)req->rq_peer.peer_id.nid);
649                 break;
650         default:
651                 LBUG();
652         }
653
654         tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, sizeof(conn));
655         if (tmp == NULL)
656                 GOTO(out, rc = -EPROTO);
657
658         memcpy(&conn, tmp, sizeof conn);
659
660         cfp = lustre_msg_buf(req->rq_reqmsg, offset + 3, sizeof(unsigned long));
661         LASSERT(cfp != NULL);
662         connect_flags = *cfp;
663
664         conn_data = lustre_swab_reqbuf(req, offset + 4, sizeof(*conn_data),
665                                        lustre_swab_connect);
666         if (!conn_data)
667                 GOTO(out, rc = -EPROTO);
668
669         rc = lustre_pack_reply(req, 1, &conn_data_size, NULL);
670         if (rc)
671                 GOTO(out, rc);
672         
673         if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_INITIAL)
674                 initial_conn = 1;
675         
676         /* lctl gets a backstage, all-access pass. */
677         if (obd_uuid_equals(&cluuid, &target->obd_uuid))
678                 goto dont_check_exports;
679
680         spin_lock(&target->obd_dev_lock);
681         list_for_each(p, &target->obd_exports) {
682                 export = list_entry(p, struct obd_export, exp_obd_chain);
683                 if (obd_uuid_equals(&cluuid, &export->exp_client_uuid)) {
684                         spin_unlock(&target->obd_dev_lock);
685                         LASSERT(export->exp_obd == target);
686
687                         rc = target_handle_reconnect(&conn, export, &cluuid,
688                                                      initial_conn);
689                         break;
690                 }
691                 export = NULL;
692         }
693         /* If we found an export, we already unlocked. */
694         if (!export) {
695                 spin_unlock(&target->obd_dev_lock);
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                       ptlrpc_peernid2str(&req->rq_peer, peer_str),
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                       ptlrpc_peernid2str(&req->rq_peer, peer_str),
708                       export, atomic_read(&export->exp_rpc_count));
709                 GOTO(out, rc = -EBUSY);
710         } else if (req->rq_reqmsg->conn_cnt == 1 && !initial_conn) {
711                 CERROR("%s reconnected with 1 conn_cnt; cookies not random?\n",
712                        cluuid.uuid);
713                 GOTO(out, rc = -EALREADY);
714         }
715
716         /* Tell the client if we're in recovery. */
717         /* If this is the first client, start the recovery timer */
718         CWARN("%s: connection from %s@%s/%lu %st"LPU64"\n", target->obd_name,
719               cluuid.uuid, ptlrpc_peernid2str(&req->rq_peer, peer_str), *cfp,
720               target->obd_recovering ? "recovering/" : "", conn_data->transno);
721
722         if (target->obd_recovering) {
723                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
724                 target_start_recovery_timer(target);
725         }
726
727 #if 0
728         /* Tell the client if we support replayable requests */
729         if (target->obd_replayable)
730                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
731 #endif
732
733         if (export == NULL) {
734                 if (target->obd_recovering) {
735                         CERROR("%s denying connection for new client %s@%s: "
736                                "%d clients in recovery for %lds\n", target->obd_name, 
737                                cluuid.uuid,
738                                ptlrpc_peernid2str(&req->rq_peer, peer_str),
739                                target->obd_recoverable_clients,
740                                (target->obd_recovery_timer.expires-jiffies)/HZ);
741                         rc = -EBUSY;
742                 } else {
743  dont_check_exports:
744                         rc = obd_connect(&conn, target, &cluuid, conn_data,
745                                          connect_flags);
746                 }
747         }
748
749         /* Return only the parts of obd_connect_data that we understand, so the
750          * client knows that we don't understand the rest. */
751         conn_data->ocd_connect_flags &= OBD_CONNECT_SUPPORTED;
752         memcpy(lustre_msg_buf(req->rq_repmsg, 0, sizeof(*conn_data)), conn_data,
753                sizeof(*conn_data));
754
755         /* Tell the client if we support replayable requests */
756         if (target->obd_replayable)
757                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_REPLAYABLE);
758
759         /* If all else goes well, this is our RPC return code. */
760         req->rq_status = 0;
761
762         if (rc && rc != EALREADY)
763                 GOTO(out, rc);
764
765         req->rq_repmsg->handle = conn;
766
767         /* If the client and the server are the same node, we will already
768          * have an export that really points to the client's DLM export,
769          * because we have a shared handles table.
770          *
771          * XXX this will go away when shaver stops sending the "connect" handle
772          * in the real "remote handle" field of the request --phik 24 Apr 2003
773          */
774         if (req->rq_export != NULL)
775                 class_export_put(req->rq_export);
776
777         /* ownership of this export ref transfers to the request */
778         export = req->rq_export = class_conn2export(&conn);
779         LASSERT(export != NULL);
780
781         spin_lock_irqsave(&export->exp_lock, flags);
782         if (initial_conn) {
783                 req->rq_repmsg->conn_cnt = export->exp_conn_cnt + 1;
784         } else if (export->exp_conn_cnt >= req->rq_reqmsg->conn_cnt) {
785                 CERROR("%s@%s: already connected at a higher conn_cnt: %d > %d\n",
786                        cluuid.uuid, ptlrpc_peernid2str(&req->rq_peer, peer_str),
787                        export->exp_conn_cnt, 
788                        req->rq_reqmsg->conn_cnt);
789                 spin_unlock_irqrestore(&export->exp_lock, flags);
790                 GOTO(out, rc = -EALREADY);
791         } 
792         export->exp_conn_cnt = req->rq_reqmsg->conn_cnt;
793         spin_unlock_irqrestore(&export->exp_lock, flags);
794
795         /* request from liblustre? */
796         if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_LIBCLIENT)
797                 export->exp_libclient = 1;
798
799         if (!(lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_ASYNC) &&
800             ptlrpc_peer_is_local(&req->rq_peer)) {
801                 CWARN("%s: exp %p set sync\n", target->obd_name, export);
802                 export->exp_sync = 1;
803         } else {
804                 CDEBUG(D_HA, "%s: exp %p set async\n",target->obd_name,export);
805                 export->exp_sync = 0;
806         }
807
808         if (export->exp_connection != NULL)
809                 ptlrpc_put_connection(export->exp_connection);
810         export->exp_connection = ptlrpc_get_connection(&req->rq_peer,
811                                                        &remote_uuid);
812
813         if (rc == EALREADY) {
814                 /* We indicate the reconnection in a flag, not an error code. */
815                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT);
816                 GOTO(out, rc = 0);
817         }
818
819         spin_lock_bh(&target->obd_processing_task_lock);
820         if (target->obd_recovering && export->exp_connected == 0) {
821                 __u64 t = conn_data->transno;
822                 export->exp_connected = 1;
823                 if ((lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_TRANSNO)
824                                 && t < target->obd_next_recovery_transno)
825                         target->obd_next_recovery_transno = t;
826                 target->obd_connected_clients++;
827                 if (target->obd_connected_clients == target->obd_max_recoverable_clients)
828                         wake_up(&target->obd_next_transno_waitq);
829         }
830         spin_unlock_bh(&target->obd_processing_task_lock);
831
832         memcpy(&conn, lustre_msg_buf(req->rq_reqmsg, offset + 2, sizeof(conn)),
833                sizeof(conn));
834
835         if (export->exp_imp_reverse != NULL) {
836                 /* same logic as client_obd_cleanup */
837                 class_import_get(export->exp_imp_reverse);
838                 class_destroy_import(export->exp_imp_reverse);
839                 ptlrpcs_import_drop_sec(export->exp_imp_reverse);
840                 class_import_put(export->exp_imp_reverse);
841         }
842
843         /* for the rest part, we return -ENOTCONN in case of errors
844          * in order to let client initialize connection again.
845          */
846         revimp = export->exp_imp_reverse = class_new_import();
847         if (!revimp) {
848                 CERROR("fail to alloc new reverse import.\n");
849                 GOTO(out, rc = -ENOTCONN);
850         }
851
852         revimp->imp_connection = ptlrpc_connection_addref(export->exp_connection);
853         revimp->imp_client = &export->exp_obd->obd_ldlm_client;
854         revimp->imp_remote_handle = conn;
855         revimp->imp_obd = target;
856         revimp->imp_dlm_fake = 1;
857         revimp->imp_state = LUSTRE_IMP_FULL;
858
859         rc = ptlrpcs_import_get_sec(revimp);
860         if (rc) {
861                 CERROR("reverse import can not get sec: %d\n", rc);
862                 class_destroy_import(revimp);
863                 export->exp_imp_reverse = NULL;
864                 GOTO(out, rc = -ENOTCONN);
865         }
866
867         class_import_put(revimp);
868
869         rc = obd_connect_post(export, initial_conn, connect_flags);
870 out:
871         if (rc)
872                 req->rq_status = rc;
873         RETURN(rc);
874 }
875
876 int target_handle_disconnect(struct ptlrpc_request *req)
877 {
878         struct obd_export *exp;
879         int rc;
880         ENTRY;
881
882         rc = lustre_pack_reply(req, 0, NULL, NULL);
883         if (rc)
884                 RETURN(rc);
885
886         /* keep the rq_export around so we can send the reply */
887         exp = class_export_get(req->rq_export);
888         req->rq_status = obd_disconnect(exp, 0);
889         RETURN(0);
890 }
891
892 void target_destroy_export(struct obd_export *exp)
893 {
894         /* exports created from last_rcvd data, and "fake"
895            exports created by lctl don't have an import */
896         if (exp->exp_imp_reverse != NULL) {
897                 ptlrpcs_import_drop_sec(exp->exp_imp_reverse);
898                 class_destroy_import(exp->exp_imp_reverse);
899         }
900
901         /* We cancel locks at disconnect time, but this will catch any locks
902          * granted in a race with recovery-induced disconnect. */
903         if (exp->exp_obd->obd_namespace != NULL)
904                 ldlm_cancel_locks_for_export(exp);
905 }
906
907 /*
908  * Recovery functions
909  */
910
911 struct ptlrpc_request *
912 ptlrpc_clone_req( struct ptlrpc_request *orig_req) 
913 {
914         struct ptlrpc_request *copy_req;
915         struct lustre_msg *copy_reqmsg;
916
917         OBD_ALLOC(copy_req, sizeof *copy_req);
918         if (!copy_req)
919                 return NULL;
920         OBD_ALLOC(copy_reqmsg, orig_req->rq_reqlen);
921         if (!copy_reqmsg){
922                 OBD_FREE(copy_req, sizeof *copy_req);
923                 return NULL;
924         }
925
926         memcpy(copy_req, orig_req, sizeof *copy_req);
927         memcpy(copy_reqmsg, orig_req->rq_reqmsg, orig_req->rq_reqlen);
928         /* the copied req takes over the reply state and security data */
929         orig_req->rq_reply_state = NULL;
930         orig_req->rq_svcsec_data = NULL;
931
932         copy_req->rq_reqmsg = copy_reqmsg;
933         class_export_get(copy_req->rq_export);
934         INIT_LIST_HEAD(&copy_req->rq_list);
935
936         return copy_req;
937 }
938
939 void ptlrpc_free_clone( struct ptlrpc_request *req) 
940 {
941         if (req->rq_svcsec)
942                 svcsec_cleanup_req(req);
943
944         class_export_put(req->rq_export);
945         list_del(&req->rq_list);
946         OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
947         OBD_FREE(req, sizeof *req);
948 }
949
950 static void target_release_saved_req(struct ptlrpc_request *req)
951 {
952         if (req->rq_svcsec)
953                 svcsec_cleanup_req(req);
954
955         class_export_put(req->rq_export);
956         OBD_FREE(req->rq_reqmsg, req->rq_reqlen);
957         OBD_FREE(req, sizeof *req);
958 }
959
960 static void target_finish_recovery(struct obd_device *obd)
961 {
962         int rc;
963
964         ldlm_reprocess_all_ns(obd->obd_namespace);
965
966         /* when recovery finished, cleanup orphans on mds and ost */
967         if (OBT(obd) && OBP(obd, postrecov)) {
968                 rc = OBP(obd, postrecov)(obd);
969                 if (rc >= 0)
970                         CWARN("%s: all clients recovered, %d MDS "
971                               "orphans deleted\n", obd->obd_name, rc);
972                 else
973                         CERROR("postrecov failed %d\n", rc);
974         }
975
976         obd->obd_recovery_end = LTIME_S(CURRENT_TIME);
977         return;
978 }
979
980 static void abort_req_replay_queue(struct obd_device *obd)
981 {
982         struct ptlrpc_request *req;
983         struct list_head *tmp, *n;
984         int rc;
985
986         list_for_each_safe(tmp, n, &obd->obd_req_replay_queue) {
987                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
988                 list_del(&req->rq_list);
989                 DEBUG_REQ(D_ERROR, req, "aborted:");
990                 req->rq_status = -ENOTCONN;
991                 req->rq_type = PTL_RPC_MSG_ERR;
992                 rc = lustre_pack_reply(req, 0, NULL, NULL);
993                 if (rc == 0) {
994                         ptlrpc_reply(req);
995                 } else {
996                         DEBUG_REQ(D_ERROR, req,
997                                   "packing failed for abort-reply; skipping");
998                 }
999                 target_release_saved_req(req);
1000         }
1001 }
1002
1003 static void abort_lock_replay_queue(struct obd_device *obd)
1004 {
1005         struct ptlrpc_request *req;
1006         struct list_head *tmp, *n;
1007         int rc;
1008
1009         list_for_each_safe(tmp, n, &obd->obd_lock_replay_queue) {
1010                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1011                 list_del(&req->rq_list);
1012                 DEBUG_REQ(D_ERROR, req, "aborted:");
1013                 req->rq_status = -ENOTCONN;
1014                 req->rq_type = PTL_RPC_MSG_ERR;
1015                 rc = lustre_pack_reply(req, 0, NULL, NULL);
1016                 if (rc == 0) {
1017                         ptlrpc_reply(req);
1018                 } else {
1019                         DEBUG_REQ(D_ERROR, req,
1020                                   "packing failed for abort-reply; skipping");
1021                 }
1022                 target_release_saved_req(req);
1023         }
1024 }
1025
1026 /* Called from a cleanup function if the device is being cleaned up
1027    forcefully.  The exports should all have been disconnected already,
1028    the only thing left to do is
1029      - clear the recovery flags
1030      - cancel the timer
1031      - free queued requests and replies, but don't send replies
1032    Because the obd_stopping flag is set, no new requests should be received.
1033
1034 */
1035 void target_cleanup_recovery(struct obd_device *obd)
1036 {
1037         struct list_head *tmp, *n;
1038         struct ptlrpc_request *req;
1039
1040         spin_lock_bh(&obd->obd_processing_task_lock);
1041         if (!obd->obd_recovering) {
1042                 spin_unlock_bh(&obd->obd_processing_task_lock);
1043                 EXIT;
1044                 return;
1045         }
1046         obd->obd_recovering = obd->obd_abort_recovery = 0;
1047         target_cancel_recovery_timer(obd);
1048         spin_unlock_bh(&obd->obd_processing_task_lock);
1049
1050         list_for_each_safe(tmp, n, &obd->obd_req_replay_queue) {
1051                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1052                 list_del(&req->rq_list);
1053                 LASSERT (req->rq_reply_state == 0);
1054                 target_release_saved_req(req);
1055         }
1056         list_for_each_safe(tmp, n, &obd->obd_lock_replay_queue) {
1057                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1058                 list_del(&req->rq_list);
1059                 LASSERT (req->rq_reply_state == 0);
1060                 target_release_saved_req(req);
1061         }
1062         list_for_each_safe(tmp, n, &obd->obd_final_req_queue) {
1063                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
1064                 list_del(&req->rq_list);
1065                 LASSERT (req->rq_reply_state == 0);
1066                 target_release_saved_req(req);
1067         }
1068 }
1069
1070 #if 0
1071 static void target_abort_recovery(void *data)
1072 {
1073         struct obd_device *obd = data;
1074
1075         LASSERT(!obd->obd_recovering);
1076
1077         class_disconnect_stale_exports(obd, 0);
1078
1079         CERROR("%s: recovery period over; disconnecting unfinished clients.\n",
1080                obd->obd_name);
1081
1082         abort_recovery_queue(obd);
1083         target_finish_recovery(obd);
1084         ptlrpc_run_recovery_over_upcall(obd);
1085 }
1086 #endif
1087
1088 static void target_recovery_expired(unsigned long castmeharder)
1089 {
1090         struct obd_device *obd = (struct obd_device *)castmeharder;
1091         spin_lock_bh(&obd->obd_processing_task_lock);
1092         if (obd->obd_recovering)
1093                 obd->obd_abort_recovery = 1;
1094
1095         wake_up(&obd->obd_next_transno_waitq);
1096         spin_unlock_bh(&obd->obd_processing_task_lock);
1097 }
1098
1099
1100 /* obd_processing_task_lock should be held */
1101 void target_cancel_recovery_timer(struct obd_device *obd)
1102 {
1103         CDEBUG(D_HA, "%s: cancel recovery timer\n", obd->obd_name);
1104         del_timer(&obd->obd_recovery_timer);
1105 }
1106
1107 #ifdef __KERNEL__
1108 static void reset_recovery_timer(struct obd_device *obd)
1109 {
1110         spin_lock_bh(&obd->obd_processing_task_lock);
1111         if (!obd->obd_recovering) {
1112                 spin_unlock_bh(&obd->obd_processing_task_lock);
1113                 return;
1114         }                
1115         CDEBUG(D_HA, "timer will expire in %u seconds\n",
1116                OBD_RECOVERY_TIMEOUT / HZ);
1117         mod_timer(&obd->obd_recovery_timer, jiffies + OBD_RECOVERY_TIMEOUT);
1118         spin_unlock_bh(&obd->obd_processing_task_lock);
1119 }
1120 #endif
1121
1122 /* Only start it the first time called */
1123 void target_start_recovery_timer(struct obd_device *obd)
1124 {
1125         spin_lock_bh(&obd->obd_processing_task_lock);
1126         if (!obd->obd_recovering || timer_pending(&obd->obd_recovery_timer)) {
1127                 spin_unlock_bh(&obd->obd_processing_task_lock);
1128                 return;
1129         }
1130         CWARN("%s: starting recovery timer (%us)\n", obd->obd_name,
1131                OBD_RECOVERY_TIMEOUT / HZ);
1132         obd->obd_recovery_timer.function = target_recovery_expired;
1133         obd->obd_recovery_timer.data = (unsigned long)obd;
1134         mod_timer(&obd->obd_recovery_timer, jiffies + OBD_RECOVERY_TIMEOUT);
1135         spin_unlock_bh(&obd->obd_processing_task_lock);
1136 }
1137
1138 #ifdef __KERNEL__
1139 static int check_for_next_transno(struct obd_device *obd)
1140 {
1141         struct ptlrpc_request *req = NULL;
1142         int wake_up = 0, connected, completed, queue_len, max;
1143         __u64 next_transno, req_transno;
1144
1145         spin_lock_bh(&obd->obd_processing_task_lock);
1146         if (!list_empty(&obd->obd_req_replay_queue)) {
1147                 req = list_entry(obd->obd_req_replay_queue.next,
1148                                  struct ptlrpc_request, rq_list);
1149                 req_transno = req->rq_reqmsg->transno;
1150         } else {
1151                 req_transno = 0;
1152         }
1153
1154         max = obd->obd_max_recoverable_clients;
1155         connected = obd->obd_connected_clients;
1156         completed = max - obd->obd_recoverable_clients;
1157         queue_len = obd->obd_requests_queued_for_recovery;
1158         next_transno = obd->obd_next_recovery_transno;
1159
1160         CDEBUG(D_HA,"max: %d, connected: %d, completed: %d, queue_len: %d, "
1161                "req_transno: "LPU64", next_transno: "LPU64"\n",
1162                max, connected, completed, queue_len, req_transno, next_transno);
1163         if (obd->obd_abort_recovery) {
1164                 CDEBUG(D_HA, "waking for aborted recovery\n");
1165                 wake_up = 1;
1166         } else if (atomic_read(&obd->obd_req_replay_clients) == 0) {
1167                 CDEBUG(D_HA, "waking for completed recovery\n");
1168                 wake_up = 1;
1169         } else if (req_transno == next_transno) {
1170                 CDEBUG(D_HA, "waking for next ("LPD64")\n", next_transno);
1171                 wake_up = 1;
1172         } else if (queue_len + completed == max) {
1173                 LASSERT(req->rq_reqmsg->transno >= next_transno);
1174                 CDEBUG(req_transno > obd->obd_last_committed ? D_ERROR : D_HA,
1175                        "waking for skipped transno (skip: "LPD64
1176                        ", ql: %d, comp: %d, conn: %d, next: "LPD64")\n",
1177                        next_transno, queue_len, completed, max, req_transno);
1178                 obd->obd_next_recovery_transno = req_transno;
1179                 wake_up = 1;
1180         } else if (queue_len == atomic_read(&obd->obd_req_replay_clients)) {
1181                 /* some clients haven't connected in time, but we can try
1182                  * to replay requests that demand on already committed ones
1183                  * also, we can replay first non-committed transation */
1184                 LASSERT(req_transno != 0);
1185                 if (req_transno == obd->obd_last_committed + 1) {
1186                         obd->obd_next_recovery_transno = req_transno;
1187                 } else if (req_transno > obd->obd_last_committed) {
1188                         /* can't continue recovery: have no needed transno */
1189                         obd->obd_abort_recovery = 1;
1190                         CDEBUG(D_ERROR, "abort due to missed clients. max: %d, "
1191                                "connected: %d, completed: %d, queue_len: %d, "
1192                                "req_transno: "LPU64", next_transno: "LPU64"\n",
1193                                max, connected, completed, queue_len,
1194                                req_transno, next_transno);
1195                 }
1196                 wake_up = 1;
1197         }
1198         spin_unlock_bh(&obd->obd_processing_task_lock);
1199         
1200         return wake_up;
1201 }
1202
1203 static struct ptlrpc_request *
1204 target_next_replay_req(struct obd_device *obd)
1205 {
1206         struct l_wait_info lwi = { 0 };
1207         struct ptlrpc_request *req;
1208
1209         CDEBUG(D_HA, "Waiting for transno "LPD64"\n",
1210                obd->obd_next_recovery_transno);
1211         l_wait_event(obd->obd_next_transno_waitq,
1212                      check_for_next_transno(obd), &lwi);
1213         
1214         spin_lock_bh(&obd->obd_processing_task_lock);
1215         if (obd->obd_abort_recovery) {
1216                 req = NULL;
1217         } else if (!list_empty(&obd->obd_req_replay_queue)) {
1218                 req = list_entry(obd->obd_req_replay_queue.next,
1219                                  struct ptlrpc_request, rq_list);
1220                 list_del_init(&req->rq_list);
1221                 obd->obd_requests_queued_for_recovery--;
1222         } else {
1223                 req = NULL;
1224         }
1225         spin_unlock_bh(&obd->obd_processing_task_lock);
1226         return req;
1227 }
1228
1229 static int check_for_next_lock(struct obd_device *obd)
1230 {
1231         struct ptlrpc_request *req = NULL;
1232         int wake_up = 0;
1233
1234         spin_lock_bh(&obd->obd_processing_task_lock);
1235         if (!list_empty(&obd->obd_lock_replay_queue)) {
1236                 req = list_entry(obd->obd_lock_replay_queue.next,
1237                                  struct ptlrpc_request, rq_list);
1238                 CDEBUG(D_HA, "waking for next lock\n");
1239                 wake_up = 1;
1240         } else if (atomic_read(&obd->obd_lock_replay_clients) == 0) {
1241                 CDEBUG(D_HA, "waking for completed lock replay\n");
1242                 wake_up = 1;
1243         } else if (obd->obd_abort_recovery) {
1244                 CDEBUG(D_HA, "waking for aborted recovery\n");
1245                 wake_up = 1;
1246         }
1247         spin_unlock_bh(&obd->obd_processing_task_lock);
1248         
1249         return wake_up;
1250 }
1251
1252 static struct ptlrpc_request *
1253 target_next_replay_lock(struct obd_device *obd)
1254 {
1255         struct l_wait_info lwi = { 0 };
1256         struct ptlrpc_request *req;
1257
1258         CDEBUG(D_HA, "Waiting for lock\n");
1259         l_wait_event(obd->obd_next_transno_waitq,
1260                      check_for_next_lock(obd), &lwi);
1261         
1262         spin_lock_bh(&obd->obd_processing_task_lock);
1263         if (obd->obd_abort_recovery) {
1264                 req = NULL;
1265         } else if (!list_empty(&obd->obd_lock_replay_queue)) {
1266                 req = list_entry(obd->obd_lock_replay_queue.next,
1267                                  struct ptlrpc_request, rq_list);
1268                 list_del_init(&req->rq_list);
1269         } else {
1270                 req = NULL;
1271         }
1272         spin_unlock_bh(&obd->obd_processing_task_lock);
1273         return req;
1274 }
1275
1276 static struct ptlrpc_request *
1277 target_next_final_ping(struct obd_device *obd)
1278 {
1279         struct ptlrpc_request *req;
1280
1281         spin_lock_bh(&obd->obd_processing_task_lock);
1282         if (!list_empty(&obd->obd_final_req_queue)) {
1283                 req = list_entry(obd->obd_final_req_queue.next,
1284                                  struct ptlrpc_request, rq_list);
1285                 list_del_init(&req->rq_list);
1286         } else {
1287                 req = NULL;
1288         }
1289         spin_unlock_bh(&obd->obd_processing_task_lock);
1290         return req;
1291 }
1292
1293 static int req_replay_done(struct obd_export *exp)
1294 {
1295         if (exp->exp_req_replay_needed)
1296                 return 0;
1297         return 1;
1298 }
1299
1300 static int lock_replay_done(struct obd_export *exp)
1301 {
1302         if (exp->exp_lock_replay_needed)
1303                 return 0;
1304         return 1;
1305 }
1306
1307 static int connect_done(struct obd_export *exp)
1308 {
1309         if (exp->exp_connected)
1310                 return 1;
1311         return 0;
1312 }
1313
1314 static int check_for_clients(struct obd_device *obd)
1315 {
1316         if (obd->obd_abort_recovery)
1317                 return 1;
1318         LASSERT(obd->obd_connected_clients <= obd->obd_max_recoverable_clients);
1319         if (obd->obd_connected_clients == obd->obd_max_recoverable_clients)
1320                 return 1;
1321         return 0;
1322 }
1323
1324 static int target_recovery_thread(void *arg)
1325 {
1326         struct obd_device *obd = arg;
1327         struct ptlrpc_request *req;
1328         struct target_recovery_data *trd = &obd->obd_recovery_data;
1329         char peer_str[PTL_NALFMT_SIZE];
1330         struct l_wait_info lwi = { 0 };
1331         unsigned long delta;
1332         unsigned long flags;
1333         ENTRY;
1334
1335         kportal_daemonize("tgt-recov");
1336
1337         SIGNAL_MASK_LOCK(current, flags);
1338         sigfillset(&current->blocked);
1339         RECALC_SIGPENDING;
1340         SIGNAL_MASK_UNLOCK(current, flags);
1341
1342         CERROR("%s: started recovery thread pid %d\n", obd->obd_name, 
1343                current->pid);
1344         trd->trd_processing_task = current->pid;
1345
1346         obd->obd_recovering = 1;
1347         complete(&trd->trd_starting);
1348
1349         /* first of all, we have to know the first transno to replay */
1350         obd->obd_abort_recovery = 0;
1351         l_wait_event(obd->obd_next_transno_waitq,
1352                      check_for_clients(obd), &lwi);
1353         
1354         spin_lock_bh(&obd->obd_processing_task_lock);
1355         target_cancel_recovery_timer(obd);
1356         spin_unlock_bh(&obd->obd_processing_task_lock);
1357
1358         /* If some clients haven't connected in time, evict them */
1359         if (obd->obd_abort_recovery) {
1360                 int stale;
1361                 CDEBUG(D_ERROR, "few clients haven't connect in time (%d/%d),"
1362                        "evict them ...\n", obd->obd_connected_clients,
1363                        obd->obd_max_recoverable_clients);
1364                 obd->obd_abort_recovery = 0;
1365                 stale = class_disconnect_stale_exports(obd, connect_done, 0);
1366                 atomic_sub(stale, &obd->obd_req_replay_clients);
1367                 atomic_sub(stale, &obd->obd_lock_replay_clients);
1368         }
1369
1370         /* next stage: replay requests */
1371         delta = jiffies;
1372         CDEBUG(D_ERROR, "1: request replay stage - %d clients from t"LPU64"\n",
1373               atomic_read(&obd->obd_req_replay_clients),
1374               obd->obd_next_recovery_transno);
1375         while ((req = target_next_replay_req(obd))) {
1376                 LASSERT(trd->trd_processing_task == current->pid);
1377                 DEBUG_REQ(D_HA, req, "processing t"LPD64" from %s: ", 
1378                           req->rq_reqmsg->transno, 
1379                           ptlrpc_peernid2str(&req->rq_peer, peer_str));
1380                 (void)trd->trd_recovery_handler(req);
1381                 obd->obd_replayed_requests++;
1382                 reset_recovery_timer(obd);
1383                 /* bug 1580: decide how to properly sync() in recovery*/
1384                 //mds_fsync_super(mds->mds_sb);
1385                 ptlrpc_free_clone(req);
1386                 spin_lock_bh(&obd->obd_processing_task_lock);
1387                 obd->obd_next_recovery_transno++;
1388                 spin_unlock_bh(&obd->obd_processing_task_lock);
1389         }
1390
1391         spin_lock_bh(&obd->obd_processing_task_lock);
1392         target_cancel_recovery_timer(obd);
1393         spin_unlock_bh(&obd->obd_processing_task_lock);
1394
1395         /* If some clients haven't replayed requests in time, evict them */
1396         if (obd->obd_abort_recovery) {
1397                 int stale;
1398                 CDEBUG(D_ERROR, "req replay timed out, aborting ...\n");
1399                 obd->obd_abort_recovery = 0;
1400                 stale = class_disconnect_stale_exports(obd, req_replay_done, 0);
1401                 atomic_sub(stale, &obd->obd_lock_replay_clients);
1402                 abort_req_replay_queue(obd);
1403                 /* XXX for debuggin tests 11 and 17 */
1404                 LBUG();
1405         }
1406
1407         /* The second stage: replay locks */
1408         CDEBUG(D_ERROR, "2: lock replay stage - %d clients\n",
1409               atomic_read(&obd->obd_lock_replay_clients));
1410         while ((req = target_next_replay_lock(obd))) {
1411                 LASSERT(trd->trd_processing_task == current->pid);
1412                 DEBUG_REQ(D_HA, req, "processing lock from %s: ", 
1413                           ptlrpc_peernid2str(&req->rq_peer, peer_str));
1414                 (void)trd->trd_recovery_handler(req);
1415                 reset_recovery_timer(obd);
1416                 ptlrpc_free_clone(req);
1417                 obd->obd_replayed_locks++;
1418         }
1419         
1420         spin_lock_bh(&obd->obd_processing_task_lock);
1421         target_cancel_recovery_timer(obd);
1422         spin_unlock_bh(&obd->obd_processing_task_lock);
1423
1424         /* If some clients haven't replayed requests in time, evict them */
1425         if (obd->obd_abort_recovery) {
1426                 int stale;
1427                 CERROR("lock replay timed out, aborting ...\n");
1428                 obd->obd_abort_recovery = 0;
1429                 stale = class_disconnect_stale_exports(obd, lock_replay_done, 0);
1430                 abort_lock_replay_queue(obd);
1431         }
1432
1433         /* We drop recoverying flag to forward all new requests
1434          * to regular mds_handle() since now */
1435         spin_lock_bh(&obd->obd_processing_task_lock);
1436         obd->obd_recovering = 0;
1437         spin_unlock_bh(&obd->obd_processing_task_lock);
1438
1439         /* The third stage: reply on final pings */
1440         CDEBUG(D_ERROR, "3: final stage - process recovery completion pings\n");
1441         while ((req = target_next_final_ping(obd))) {
1442                 LASSERT(trd->trd_processing_task == current->pid);
1443                 DEBUG_REQ(D_HA, req, "processing final ping from %s: ", 
1444                           ptlrpc_peernid2str(&req->rq_peer, peer_str));
1445                 (void)trd->trd_recovery_handler(req);
1446                 ptlrpc_free_clone(req);
1447         }
1448        
1449         delta = (jiffies - delta) / HZ;
1450         CDEBUG(D_ERROR,"4: recovery completed in %lus - %d/%d reqs/locks\n",
1451               delta, obd->obd_replayed_requests, obd->obd_replayed_locks);
1452         if (delta > obd_timeout * 2) {
1453                 CWARN("too long recovery - read logs\n");
1454                 portals_debug_dumplog();
1455         }
1456         target_finish_recovery(obd);
1457
1458         trd->trd_processing_task = 0;
1459         complete(&trd->trd_finishing);
1460         return 0;
1461 }
1462
1463 int target_start_recovery_thread(struct obd_device *obd, svc_handler_t handler)
1464 {
1465         int rc = 0;
1466         struct target_recovery_data *trd = &obd->obd_recovery_data;
1467
1468         memset(trd, 0, sizeof(*trd));
1469         init_completion(&trd->trd_starting);
1470         init_completion(&trd->trd_finishing);
1471         trd->trd_recovery_handler = handler;
1472
1473         if (kernel_thread(target_recovery_thread, obd, 0) > 0) {
1474                 wait_for_completion(&trd->trd_starting);
1475                 LASSERT(obd->obd_recovering != 0);
1476         } else
1477                 rc = -ECHILD;
1478
1479         return rc;
1480 }
1481
1482 void target_stop_recovery_thread(struct obd_device *obd)
1483 {
1484         spin_lock_bh(&obd->obd_processing_task_lock);
1485         if (obd->obd_recovery_data.trd_processing_task > 0) {
1486                 struct target_recovery_data *trd = &obd->obd_recovery_data;
1487                 CERROR("%s: aborting recovery\n", obd->obd_name);
1488                 obd->obd_abort_recovery = 1;
1489                 wake_up(&obd->obd_next_transno_waitq);
1490                 spin_unlock_bh(&obd->obd_processing_task_lock);
1491                 wait_for_completion(&trd->trd_finishing);
1492         } else {
1493                 spin_unlock_bh(&obd->obd_processing_task_lock);
1494         }
1495 }
1496 #endif
1497
1498 int target_process_req_flags(struct obd_device *obd, struct ptlrpc_request *req)
1499 {
1500         struct obd_export *exp = req->rq_export;
1501         LASSERT(exp != NULL);
1502         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
1503                 /* client declares he's ready to replay locks */
1504                 spin_lock_bh(&obd->obd_processing_task_lock);
1505                 if (exp->exp_req_replay_needed) {
1506                         LASSERT(atomic_read(&obd->obd_req_replay_clients) > 0);
1507                         exp->exp_req_replay_needed = 0;
1508                         atomic_dec(&obd->obd_req_replay_clients);
1509                         obd->obd_recoverable_clients--;
1510                         if (atomic_read(&obd->obd_req_replay_clients) == 0)
1511                                 CDEBUG(D_HA, "all clients have replayed reqs\n");
1512                         wake_up(&obd->obd_next_transno_waitq);
1513                 }
1514                 spin_unlock_bh(&obd->obd_processing_task_lock);
1515         }
1516         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
1517                 /* client declares he's ready to complete recovery 
1518                  * so, we put the request on th final queue */
1519                 spin_lock_bh(&obd->obd_processing_task_lock);
1520                 if (exp->exp_lock_replay_needed) {
1521                         LASSERT(atomic_read(&obd->obd_lock_replay_clients) > 0);
1522                         exp->exp_lock_replay_needed = 0;
1523                         atomic_dec(&obd->obd_lock_replay_clients);
1524                         if (atomic_read(&obd->obd_lock_replay_clients) == 0)
1525                                 CDEBUG(D_HA, "all clients have replayed locks\n");
1526                         wake_up(&obd->obd_next_transno_waitq);
1527                 }
1528                 spin_unlock_bh(&obd->obd_processing_task_lock);
1529         }
1530
1531         return 0;
1532 }
1533
1534 int target_queue_recovery_request(struct ptlrpc_request *req,
1535                                   struct obd_device *obd)
1536 {
1537         struct list_head *tmp;
1538         int inserted = 0;
1539         __u64 transno = req->rq_reqmsg->transno;
1540
1541         if (obd->obd_recovery_data.trd_processing_task == current->pid) {
1542                 /* Processing the queue right now, don't re-add. */
1543                 return 1;
1544         }
1545
1546         target_process_req_flags(obd, req);
1547
1548         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LOCK_REPLAY_DONE) {
1549                 /* client declares he's ready to complete recovery 
1550                  * so, we put the request on th final queue */
1551                 req = ptlrpc_clone_req(req);
1552                 if (req == NULL)
1553                         return -ENOMEM;
1554                 DEBUG_REQ(D_HA, req, "queue final req");
1555                 spin_lock_bh(&obd->obd_processing_task_lock);
1556                 list_add_tail(&req->rq_list, &obd->obd_final_req_queue);
1557                 spin_unlock_bh(&obd->obd_processing_task_lock);
1558                 return 0;
1559         }
1560         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REQ_REPLAY_DONE) {
1561                 /* client declares he's ready to replay locks */
1562                 req = ptlrpc_clone_req(req);
1563                 if (req == NULL)
1564                         return -ENOMEM;
1565                 DEBUG_REQ(D_HA, req, "queue lock replay req");
1566                 spin_lock_bh(&obd->obd_processing_task_lock);
1567                 list_add_tail(&req->rq_list, &obd->obd_lock_replay_queue);
1568                 spin_unlock_bh(&obd->obd_processing_task_lock);
1569                 wake_up(&obd->obd_next_transno_waitq);
1570                 return 0;
1571         }
1572
1573
1574         /* CAVEAT EMPTOR: The incoming request message has been swabbed
1575          * (i.e. buflens etc are in my own byte order), but type-dependent
1576          * buffers (eg mds_body, ost_body etc) have NOT been swabbed. */
1577
1578         if (!transno) {
1579                 INIT_LIST_HEAD(&req->rq_list);
1580                 DEBUG_REQ(D_HA, req, "not queueing");
1581                 return 1;
1582         }
1583
1584
1585         /* If we're processing the queue, we want don't want to queue this
1586          * message.
1587          *
1588          * Also, if this request has a transno less than the one we're waiting
1589          * for, we should process it now.  It could (and currently always will)
1590          * be an open request for a descriptor that was opened some time ago.
1591          *
1592          * Also, a resent, replayed request that has already been
1593          * handled will pass through here and be processed immediately.
1594          */
1595         spin_lock_bh(&obd->obd_processing_task_lock);
1596         if (transno < obd->obd_next_recovery_transno && check_for_clients(obd)) {
1597                 /* Processing the queue right now, don't re-add. */
1598                 LASSERT(list_empty(&req->rq_list));
1599                 spin_unlock_bh(&obd->obd_processing_task_lock);
1600                 return 1;
1601         }
1602         spin_unlock_bh(&obd->obd_processing_task_lock);
1603
1604         /* A resent, replayed request that is still on the queue; just drop it.
1605            The queued request will handle this. */
1606         if ((lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY))
1607             == (MSG_RESENT | MSG_REPLAY)) {
1608                 DEBUG_REQ(D_ERROR, req, "dropping resent queued req");
1609                 return 0;
1610         }
1611
1612         req = ptlrpc_clone_req(req);
1613         if (req == NULL)
1614                 return -ENOMEM;
1615
1616         spin_lock_bh(&obd->obd_processing_task_lock);
1617
1618         /* XXX O(n^2) */
1619         list_for_each(tmp, &obd->obd_req_replay_queue) {
1620                 struct ptlrpc_request *reqiter =
1621                         list_entry(tmp, struct ptlrpc_request, rq_list);
1622
1623                 if (reqiter->rq_reqmsg->transno > transno) {
1624                         list_add_tail(&req->rq_list, &reqiter->rq_list);
1625                         inserted = 1;
1626                         break;
1627                 }
1628         }
1629
1630         if (!inserted)
1631                 list_add_tail(&req->rq_list, &obd->obd_req_replay_queue);
1632
1633         obd->obd_requests_queued_for_recovery++;
1634         wake_up(&obd->obd_next_transno_waitq);
1635         spin_unlock_bh(&obd->obd_processing_task_lock);
1636         return 0;
1637 }
1638
1639 struct obd_device * target_req2obd(struct ptlrpc_request *req)
1640 {
1641         return req->rq_export->exp_obd;
1642 }
1643
1644 int
1645 target_send_reply_msg (struct ptlrpc_request *req, int rc, int fail_id)
1646 {
1647         if (OBD_FAIL_CHECK(fail_id | OBD_FAIL_ONCE)) {
1648                 obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED;
1649                 DEBUG_REQ(D_ERROR, req, "dropping reply");
1650                 /* NB this does _not_ send with ACK disabled, to simulate
1651                  * sending OK, but timing out for the ACK */
1652                 if (req->rq_reply_state != NULL) {
1653                         if (!req->rq_reply_state->rs_difficult) {
1654                                 lustre_free_reply_state (req->rq_reply_state);
1655                                 req->rq_reply_state = NULL;
1656                         } else {
1657                                 struct ptlrpc_service *svc =
1658                                         req->rq_rqbd->rqbd_srv_ni->sni_service;
1659                                 atomic_inc(&svc->srv_outstanding_replies);
1660                         }
1661                 }
1662                 return (-ECOMM);
1663         }
1664
1665         if (rc) {
1666                 req->rq_status = rc;
1667                 return (ptlrpc_error(req));
1668         } else {
1669                 DEBUG_REQ(D_NET, req, "sending reply");
1670         }
1671         
1672         return (ptlrpc_send_reply(req, 1));
1673 }
1674
1675 void 
1676 target_send_reply(struct ptlrpc_request *req, int rc, int fail_id)
1677 {
1678         int                        netrc;
1679         unsigned long              flags;
1680         struct ptlrpc_reply_state *rs;
1681         struct obd_device         *obd;
1682         struct obd_export         *exp;
1683         struct ptlrpc_srv_ni      *sni;
1684         struct ptlrpc_service     *svc;
1685
1686         sni = req->rq_rqbd->rqbd_srv_ni;
1687         svc = sni->sni_service;
1688         
1689         rs = req->rq_reply_state;
1690         if (rs == NULL || !rs->rs_difficult) {
1691                 /* The easy case; no notifiers and reply_out_callback()
1692                  * cleans up (i.e. we can't look inside rs after a
1693                  * successful send) */
1694                 netrc = target_send_reply_msg (req, rc, fail_id);
1695
1696                 LASSERT (netrc == 0 || req->rq_reply_state == NULL);
1697                 return;
1698         }
1699
1700         /* must be an export if locks saved */
1701         LASSERT (req->rq_export != NULL);
1702         /* req/reply consistent */
1703         LASSERT (rs->rs_srv_ni == sni);
1704
1705         /* "fresh" reply */
1706         LASSERT (!rs->rs_scheduled);
1707         LASSERT (!rs->rs_scheduled_ever);
1708         LASSERT (!rs->rs_handled);
1709         LASSERT (!rs->rs_on_net);
1710         LASSERT (rs->rs_export == NULL);
1711         LASSERT (list_empty(&rs->rs_obd_list));
1712         LASSERT (list_empty(&rs->rs_exp_list));
1713
1714         exp = class_export_get (req->rq_export);
1715         obd = exp->exp_obd;
1716
1717         /* disable reply scheduling onto srv_reply_queue while I'm setting up */
1718         rs->rs_scheduled = 1;
1719         rs->rs_on_net    = 1;
1720         rs->rs_xid       = req->rq_xid;
1721         rs->rs_transno   = req->rq_transno;
1722         rs->rs_export    = exp;
1723         
1724         spin_lock_irqsave (&obd->obd_uncommitted_replies_lock, flags);
1725
1726         if (rs->rs_transno > obd->obd_last_committed) {
1727                 /* not committed already */ 
1728                 list_add_tail (&rs->rs_obd_list, 
1729                                &obd->obd_uncommitted_replies);
1730         }
1731
1732         spin_unlock (&obd->obd_uncommitted_replies_lock);
1733         spin_lock (&exp->exp_lock);
1734
1735         list_add_tail (&rs->rs_exp_list, &exp->exp_outstanding_replies);
1736
1737         spin_unlock_irqrestore (&exp->exp_lock, flags);
1738
1739         netrc = target_send_reply_msg (req, rc, fail_id);
1740
1741         spin_lock_irqsave (&svc->srv_lock, flags);
1742
1743         svc->srv_n_difficult_replies++;
1744
1745         if (netrc != 0) /* error sending: reply is off the net */
1746                 rs->rs_on_net = 0;
1747
1748         if (!rs->rs_on_net ||                   /* some notifier */
1749             list_empty(&rs->rs_exp_list) ||     /* completed already */
1750             list_empty(&rs->rs_obd_list)) {
1751                 list_add_tail (&rs->rs_list, &svc->srv_reply_queue);
1752                 wake_up (&svc->srv_waitq);
1753         } else {
1754                 list_add (&rs->rs_list, &sni->sni_active_replies);
1755                 rs->rs_scheduled = 0;           /* allow notifier to schedule */
1756         }
1757
1758         spin_unlock_irqrestore (&svc->srv_lock, flags);
1759 }
1760
1761 int target_handle_ping(struct ptlrpc_request *req)
1762 {
1763         return lustre_pack_reply(req, 0, NULL, NULL);
1764 }