Whamcloud - gitweb
4e88c5f7051028a46c25ebb6349d1637a4a14d9f
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001-2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
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_MDC
26
27 #ifdef __KERNEL__
28 # include <linux/module.h>
29 # include <linux/pagemap.h>
30 # include <linux/miscdevice.h>
31 # include <linux/init.h>
32 #else
33 # include <liblustre.h>
34 #endif
35
36 #include <linux/obd_class.h>
37 #include <linux/lustre_mds.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/lprocfs_status.h>
40 #include "mdc_internal.h"
41
42 #define REQUEST_MINOR 244
43
44 static int mdc_cleanup(struct obd_device *obd, int flags);
45
46 extern int mds_queue_req(struct ptlrpc_request *);
47 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
48 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
49 static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid,
50                           int level, int msg_flags)
51 {
52         struct ptlrpc_request *req;
53         struct mds_body *body;
54         int rc, size = sizeof(*body);
55         ENTRY;
56
57         req = ptlrpc_prep_req(imp, MDS_GETSTATUS, 1, &size, NULL);
58         if (!req)
59                 GOTO(out, rc = -ENOMEM);
60
61         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
62         req->rq_send_state = level;
63         req->rq_replen = lustre_msg_size(1, &size);
64
65         mdc_pack_req_body(req);
66         req->rq_reqmsg->flags |= msg_flags;
67         rc = ptlrpc_queue_wait(req);
68
69         if (!rc) {
70                 body = lustre_swab_repbuf (req, 0, sizeof (*body),
71                                            lustre_swab_mds_body);
72                 if (body == NULL) {
73                         CERROR ("Can't extract mds_body\n");
74                         GOTO (out, rc = -EPROTO);
75                 }
76
77                 memcpy(rootfid, &body->fid1, sizeof(*rootfid));
78
79                 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
80                        ", last_xid="LPU64"\n",
81                        rootfid->id, req->rq_repmsg->last_committed,
82                        req->rq_repmsg->last_xid);
83         }
84
85         EXIT;
86  out:
87         ptlrpc_req_finished(req);
88         return rc;
89 }
90
91 /* This should be mdc_get_info("rootfid") */
92 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid)
93 {
94         return send_getstatus(class_exp2cliimp(exp), rootfid, LUSTRE_IMP_FULL,
95                               0);
96 }
97
98 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
99                        struct ptlrpc_request *req)
100 {
101         struct mds_body *body;
102         void            *eadata;
103         int              rc;
104         int              size[2] = {sizeof(*body), 0};
105         int              bufcount = 1;
106         ENTRY;
107
108         /* request message already built */
109
110         if (ea_size != 0) {
111                 size[bufcount++] = ea_size;
112                 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
113                        ea_size);
114         }
115         req->rq_replen = lustre_msg_size(bufcount, size);
116
117         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
118         rc = ptlrpc_queue_wait(req);
119         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
120         if (rc != 0)
121                 RETURN (rc);
122
123         body = lustre_swab_repbuf (req, 0, sizeof (*body),
124                                    lustre_swab_mds_body);
125         if (body == NULL) {
126                 CERROR ("Can't unpack mds_body\n");
127                 RETURN (-EPROTO);
128         }
129
130         CDEBUG(D_NET, "mode: %o\n", body->mode);
131
132         LASSERT_REPSWAB (req, 1);
133         if (body->eadatasize != 0) {
134                 /* reply indicates presence of eadata; check it's there... */
135                 eadata = lustre_msg_buf (req->rq_repmsg, 1, body->eadatasize);
136                 if (eadata == NULL) {
137                         CERROR ("Missing/short eadata\n");
138                         RETURN (-EPROTO);
139                 }
140         }
141
142         RETURN (0);
143 }
144
145 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
146                 unsigned long valid, unsigned int ea_size,
147                 struct ptlrpc_request **request)
148 {
149         struct ptlrpc_request *req;
150         struct mds_body *body;
151         int size = sizeof(*body);
152         int rc;
153         ENTRY;
154
155         /* XXX do we need to make another request here?  We just did a getattr
156          *     to do the lookup in the first place.
157          */
158         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR, 1, &size,
159                               NULL);
160         if (!req)
161                 GOTO(out, rc = -ENOMEM);
162
163         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
164         memcpy(&body->fid1, fid, sizeof(*fid));
165         body->valid = valid;
166         body->eadatasize = ea_size;
167         mdc_pack_req_body(req);
168
169         rc = mdc_getattr_common(exp, ea_size, req);
170         if (rc != 0) {
171                 ptlrpc_req_finished (req);
172                 req = NULL;
173         }
174  out:
175         *request = req;
176         RETURN (rc);
177 }
178
179 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
180                      char *filename, int namelen, unsigned long valid,
181                      unsigned int ea_size, struct ptlrpc_request **request)
182 {
183         struct ptlrpc_request *req;
184         struct mds_body *body;
185         int rc, size[2] = {sizeof(*body), namelen};
186         ENTRY;
187
188         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR_NAME, 2,
189                               size, NULL);
190         if (!req)
191                 GOTO(out, rc = -ENOMEM);
192
193         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
194         memcpy(&body->fid1, fid, sizeof(*fid));
195         body->valid = valid;
196         body->eadatasize = ea_size;
197         mdc_pack_req_body(req);
198
199         if (filename != NULL) {
200                 LASSERT (strnlen (filename, namelen) == namelen - 1);
201                 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, namelen),
202                        filename, namelen);
203         } else {
204                 LASSERT(namelen == 1);
205         }
206
207         rc = mdc_getattr_common(exp, ea_size, req);
208         if (rc != 0) {
209                 ptlrpc_req_finished (req);
210                 req = NULL;
211         }
212  out:
213         *request = req;
214         RETURN(rc);
215 }
216
217 /* This should be called with both the request and the reply still packed. */
218 int mdc_store_inode_generation(struct obd_export *exp,
219                                 struct ptlrpc_request *req, int reqoff,
220                                 int repoff)
221 {
222         struct mds_rec_create *rec =
223                 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
224         struct mds_body *body =
225                 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
226
227         LASSERT (rec != NULL);
228         LASSERT (body != NULL);
229
230         memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
231         DEBUG_REQ(D_HA, req, "storing generation %u for ino "LPU64,
232                   rec->cr_replayfid.generation, rec->cr_replayfid.id);
233         return 0;
234 }
235
236 int mdc_req2lustre_md(struct obd_export *exp_mdc, struct ptlrpc_request *req, 
237                       unsigned int offset, struct obd_export *exp_osc, 
238                       struct lustre_md *md)
239 {
240         int rc = 0;
241         ENTRY;
242
243         LASSERT(md);
244         memset(md, 0, sizeof(*md));
245
246         md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
247         LASSERT (md->body != NULL);
248         LASSERT_REPSWABBED (req, offset);
249
250         if (!(md->body->valid & OBD_MD_FLEASIZE) && 
251             !(md->body->valid & OBD_MD_FLDIREA))
252                 RETURN(0);
253
254         /* ea is presented in reply, parse it */
255         if (S_ISREG(md->body->mode)) {
256                 int lmmsize;
257                 struct lov_mds_md *lmm;
258
259                 if (md->body->eadatasize == 0) {
260                         CERROR ("OBD_MD_FLEASIZE set, but eadatasize 0\n");
261                         RETURN(-EPROTO);
262                 }
263                 lmmsize = md->body->eadatasize;
264                 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1, lmmsize);
265                 LASSERT (lmm != NULL);
266                 LASSERT_REPSWABBED (req, offset + 1);
267
268                 rc = obd_unpackmd(exp_osc, &md->lsm, lmm, lmmsize);
269                 if (rc >= 0) {
270                         LASSERT (rc >= sizeof (*md->lsm));
271                         rc = 0;
272                 }
273         } else if (S_ISDIR(md->body->mode)) {
274                 struct mea *mea;
275                 int mdsize;
276                 LASSERT(exp_mdc != NULL);
277                 /* dir can be non-splitted */
278                 if (md->body->eadatasize == 0)
279                         RETURN(0);
280
281                 mdsize = md->body->eadatasize;
282                 mea = lustre_msg_buf(req->rq_repmsg, offset + 1, mdsize);
283                 LASSERT(mea != NULL);
284
285                 rc = obd_unpackmd(exp_mdc, (void *) &md->mea,
286                                   (void *) mea, mdsize);
287                 if (rc >= 0) {
288                         LASSERT (rc >= sizeof (*md->mea));
289                         rc = 0;
290                 }
291         } else {
292                 LASSERT(0);
293         }
294         RETURN(rc);
295 }
296
297 static void mdc_commit_open(struct ptlrpc_request *req)
298 {
299         struct mdc_open_data *mod = req->rq_cb_data;
300         if (mod == NULL)
301                 return;
302
303         if (mod->mod_close_req != NULL)
304                 mod->mod_close_req->rq_cb_data = NULL;
305
306         if (mod->mod_och != NULL)
307                 mod->mod_och->och_mod = NULL;
308
309         OBD_FREE(mod, sizeof(*mod));
310         req->rq_cb_data = NULL;
311 }
312
313 static void mdc_replay_open(struct ptlrpc_request *req)
314 {
315         struct mdc_open_data *mod = req->rq_cb_data;
316         struct obd_client_handle *och;
317         struct ptlrpc_request *close_req;
318         struct lustre_handle old;
319         struct mds_body *body;
320         ENTRY;
321
322         body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
323         LASSERT (body != NULL);
324
325         if (mod == NULL) {
326                 DEBUG_REQ(D_ERROR, req,
327                           "can't properly replay without open data");
328                 EXIT;
329                 return;
330         }
331
332         och = mod->mod_och;
333         if (och != NULL) {
334                 struct lustre_handle *file_fh;
335                 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
336                 file_fh = &och->och_fh;
337                 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
338                        file_fh->cookie, body->handle.cookie);
339                 memcpy(&old, file_fh, sizeof(old));
340                 memcpy(file_fh, &body->handle, sizeof(*file_fh));
341         }
342
343         close_req = mod->mod_close_req;
344         if (close_req != NULL) {
345                 struct mds_body *close_body;
346                 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
347                 close_body = lustre_msg_buf(close_req->rq_reqmsg, 0,
348                                             sizeof(*close_body));
349                 if (och != NULL)
350                         LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
351                 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
352                 memcpy(&close_body->handle, &body->handle,
353                        sizeof(close_body->handle));
354         }
355
356         EXIT;
357 }
358
359 int  mdc_set_open_replay_data(struct obd_export *exp,
360                               struct obd_client_handle *och,
361                               struct ptlrpc_request *open_req)
362 {
363         struct mdc_open_data *mod;
364         struct mds_rec_create *rec =
365                 lustre_msg_buf(open_req->rq_reqmsg, 2, sizeof(*rec));
366         struct mds_body *body =
367                 lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
368
369         LASSERT(rec != NULL);
370         /* outgoing messages always in my byte order */
371         LASSERT(body != NULL);
372         /* incoming message in my byte order (it's been swabbed) */
373         LASSERT_REPSWABBED(open_req, 1);
374
375         OBD_ALLOC(mod, sizeof(*mod));
376         if (mod == NULL) {
377                 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
378                 return 0;
379         }
380
381         och->och_mod = mod;
382         mod->mod_och = och;
383         mod->mod_open_req = open_req;
384
385         memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
386         open_req->rq_replay_cb = mdc_replay_open;
387         open_req->rq_commit_cb = mdc_commit_open;
388         open_req->rq_cb_data = mod;
389         DEBUG_REQ(D_HA, open_req, "set up replay data");
390         return 0;
391 }
392
393 int mdc_clear_open_replay_data(struct obd_export *exp,
394                                struct obd_client_handle *och)
395 {
396         struct mdc_open_data *mod = och->och_mod;
397
398         /* Don't free the structure now (it happens in mdc_commit_open, after
399          * we're sure we won't need to fix up the close request in the future),
400          * but make sure that replay doesn't poke at the och, which is about to
401          * be freed. */
402         LASSERT(mod != LP_POISON);
403         if (mod != NULL)
404                 mod->mod_och = NULL;
405         och->och_mod = NULL;
406         return 0;
407 }
408
409 static void mdc_commit_close(struct ptlrpc_request *req)
410 {
411         struct mdc_open_data *mod = req->rq_cb_data;
412         struct ptlrpc_request *open_req;
413         struct obd_import *imp = req->rq_import;
414
415         DEBUG_REQ(D_HA, req, "close req committed");
416         if (mod == NULL)
417                 return;
418
419         mod->mod_close_req = NULL;
420         req->rq_cb_data = NULL;
421         req->rq_commit_cb = NULL;
422
423         open_req = mod->mod_open_req;
424         LASSERT(open_req != NULL);
425         LASSERT(open_req != LP_POISON);
426         LASSERT(open_req->rq_type != LI_POISON);
427
428         DEBUG_REQ(D_HA, open_req, "open req balanced");
429         if (open_req->rq_transno == 0) {
430                 DEBUG_REQ(D_ERROR, open_req, "BUG 3892  open");
431                 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
432                 LASSERTF(open_req->rq_transno != 0, "BUG 3892");
433         }
434         LASSERT(open_req->rq_import == imp);
435
436         /* We no longer want to preserve this for transno-unconditional
437          * replay. */
438         spin_lock(&open_req->rq_lock);
439         open_req->rq_replay = 0;
440         spin_unlock(&open_req->rq_lock);
441 }
442
443 static int mdc_close_interpret(struct ptlrpc_request *req, void *data, int rc)
444 {
445         union ptlrpc_async_args *aa = data;
446         struct mdc_rpc_lock *rpc_lock;
447         struct obd_device *obd = aa->pointer_arg[1];
448         unsigned long flags;
449
450         spin_lock_irqsave(&req->rq_lock, flags);
451         rpc_lock = aa->pointer_arg[0];
452         aa->pointer_arg[0] = NULL;
453         spin_unlock_irqrestore (&req->rq_lock, flags);
454
455         if (rpc_lock == NULL) {
456                 CERROR("called with NULL rpc_lock\n");
457         } else {
458                 mdc_put_rpc_lock(rpc_lock, NULL);
459                 LASSERTF(rpc_lock == obd->u.cli.cl_rpc_lock, "%p != %p\n",
460                          rpc_lock, obd->u.cli.cl_rpc_lock);
461         }
462         wake_up(&req->rq_reply_waitq);
463         RETURN(rc);
464 }
465
466 /* We can't use ptlrpc_check_reply, because we don't want to wake up for
467  * anything but a reply or an error. */
468 static int mdc_close_check_reply(struct ptlrpc_request *req)
469 {
470         int rc = 0;
471         unsigned long flags;
472
473         spin_lock_irqsave(&req->rq_lock, flags);
474         if (req->rq_async_args.pointer_arg[0] == NULL)
475                 rc = 1;
476         spin_unlock_irqrestore (&req->rq_lock, flags);
477         return rc;
478 }
479
480 static int go_back_to_sleep(void *unused)
481 {
482         return 0;
483 }
484
485 int mdc_close(struct obd_export *exp, struct obdo *oa,
486               struct obd_client_handle *och, struct ptlrpc_request **request)
487 {
488         struct obd_device *obd = class_exp2obd(exp);
489         int reqsize[2] = {sizeof(struct mds_body),
490                           obd->u.cli.cl_max_mds_cookiesize};
491         int rc, repsize[3] = {sizeof(struct mds_body),
492                               obd->u.cli.cl_max_mds_easize,
493                               obd->u.cli.cl_max_mds_cookiesize};
494         struct ptlrpc_request *req;
495         struct mdc_open_data *mod;
496         struct l_wait_info lwi;
497         ENTRY;
498
499         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 2, reqsize,
500                               NULL);
501         if (req == NULL)
502                 GOTO(out, rc = -ENOMEM);
503
504         /* Ensure that this close's handle is fixed up during replay. */
505         LASSERT(och != NULL);
506         mod = och->och_mod;
507         if (likely(mod != NULL)) {
508                 mod->mod_close_req = req;
509                 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
510                 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open req %p",
511                           mod->mod_open_req);
512         } else {
513                 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
514         }
515
516         mdc_close_pack(req, 0, oa, oa->o_valid, och);
517
518         req->rq_replen = lustre_msg_size(3, repsize);
519         req->rq_commit_cb = mdc_commit_close;
520         LASSERT(req->rq_cb_data == NULL);
521         req->rq_cb_data = mod;
522
523         /* We hand a ref to the rpcd here, so we need another one of our own. */
524         ptlrpc_request_addref(req);
525
526         mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
527         req->rq_interpret_reply = mdc_close_interpret;
528         req->rq_async_args.pointer_arg[0] = obd->u.cli.cl_rpc_lock;
529         req->rq_async_args.pointer_arg[1] = obd;
530         ptlrpcd_add_req(req);
531         lwi = LWI_TIMEOUT_INTR(MAX(req->rq_timeout * HZ, 1), go_back_to_sleep,
532                                NULL, NULL);
533         rc = l_wait_event(req->rq_reply_waitq, mdc_close_check_reply(req),
534                           &lwi);
535         if (req->rq_repmsg == NULL) {
536                 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
537                        req->rq_status);
538                 if (rc == 0)
539                         rc = req->rq_status ? req->rq_status : -EIO;
540         } else if (rc == 0) {
541                 rc = req->rq_repmsg->status;
542                 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
543                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
544                                   "= %d", rc);
545                         if (rc > 0)
546                                 rc = -rc;
547                 } else if (mod == NULL) {
548                         CERROR("Unexpected: can't find mdc_open_data, but the "
549                                "close succeeded.  Please tell CFS.\n");
550                 }
551                 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
552                                         lustre_swab_mds_body)) {
553                         CERROR("Error unpacking mds_body\n");
554                         rc = -EPROTO;
555                 }
556         }
557         if (req->rq_async_args.pointer_arg[0] != NULL) {
558                 CERROR("returned without dropping rpc_lock: rc %d\n", rc);
559                 mdc_close_interpret(req, &req->rq_async_args, rc);
560                 portals_debug_dumplog();
561         }
562
563         EXIT;
564  out:
565         *request = req;
566         return rc;
567 }
568
569 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
570 {
571         struct ptlrpc_request *req;
572         struct mds_body *body;
573         int rc, size = sizeof(*body);
574         ENTRY;
575
576         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_DONE_WRITING, 1,
577                               &size, NULL);
578         if (req == NULL)
579                 RETURN(-ENOMEM);
580
581         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
582         mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
583         body->size = obdo->o_size;
584         body->blocks = obdo->o_blocks;
585         body->flags = obdo->o_flags;
586         body->valid = obdo->o_valid;
587 //        memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
588
589         req->rq_replen = lustre_msg_size(1, &size);
590
591         rc = ptlrpc_queue_wait(req);
592         ptlrpc_req_finished(req);
593         RETURN(rc);
594 }
595
596 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
597                  __u64 offset, struct page *page,
598                  struct ptlrpc_request **request)
599 {
600         struct obd_import *imp = class_exp2cliimp(exp);
601         struct ptlrpc_request *req = NULL;
602         struct ptlrpc_bulk_desc *desc = NULL;
603         struct mds_body *body;
604         int rc, size = sizeof(*body);
605         ENTRY;
606
607         CDEBUG(D_INODE, "inode: %ld\n", (long)mdc_fid->id);
608
609         req = ptlrpc_prep_req(imp, MDS_READPAGE, 1, &size, NULL);
610         if (req == NULL)
611                 GOTO(out, rc = -ENOMEM);
612         /* XXX FIXME bug 249 */
613         req->rq_request_portal = MDS_READPAGE_PORTAL;
614
615         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
616         if (desc == NULL)
617                 GOTO(out, rc = -ENOMEM);
618         /* NB req now owns desc and will free it when it gets freed */
619
620         ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
621
622         mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE, mdc_fid);
623
624         req->rq_replen = lustre_msg_size(1, &size);
625         rc = ptlrpc_queue_wait(req);
626
627         if (rc == 0) {
628                 body = lustre_swab_repbuf(req, 0, sizeof (*body),
629                                           lustre_swab_mds_body);
630                 if (body == NULL) {
631                         CERROR("Can't unpack mds_body\n");
632                         GOTO(out, rc = -EPROTO);
633                 }
634
635                 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
636                         CERROR ("Unexpected # bytes transferred: %d"
637                                 " (%ld expected)\n",
638                                 req->rq_bulk->bd_nob_transferred,
639                                 PAGE_CACHE_SIZE);
640                         GOTO (out, rc = -EPROTO);
641                 }
642         }
643
644         EXIT;
645  out:
646         *request = req;
647         return rc;
648 }
649
650 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
651                          void *karg, void *uarg)
652 {
653         struct obd_device *obd = exp->exp_obd;
654         struct obd_ioctl_data *data = karg;
655         struct obd_import *imp = obd->u.cli.cl_import;
656         struct llog_ctxt *ctxt;
657         int rc;
658         ENTRY;
659
660 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
661         MOD_INC_USE_COUNT;
662 #else
663         if (!try_module_get(THIS_MODULE)) {
664                 CERROR("Can't get module. Is it alive?");
665                 return -EINVAL;
666         }
667 #endif
668         switch (cmd) {
669         case OBD_IOC_CLIENT_RECOVER:
670                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
671                 if (rc < 0)
672                         GOTO(out, rc);
673                 GOTO(out, rc = 0);
674         case IOC_OSC_SET_ACTIVE:
675                 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
676                 GOTO(out, rc);
677         case OBD_IOC_PARSE: {
678                 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
679                                         LLOG_CONFIG_REPL_CTXT);
680                 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
681                 GOTO(out, rc);
682         }
683 #ifdef __KERNEL__
684         case OBD_IOC_LLOG_INFO:
685         case OBD_IOC_LLOG_PRINT: {
686                 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
687                 rc = llog_ioctl(ctxt, cmd, data);
688
689                 GOTO(out, rc);
690         }
691 #endif
692         default:
693                 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
694                 GOTO(out, rc = -ENOTTY);
695         }
696 out:
697 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
698         MOD_DEC_USE_COUNT;
699 #else
700         module_put(THIS_MODULE);
701 #endif
702
703         return rc;
704 }
705
706 int mdc_set_info(struct obd_export *exp, obd_count keylen,
707                  void *key, obd_count vallen, void *val)
708 {
709         int rc = -EINVAL;
710
711         if (keylen == strlen("initial_recov") &&
712             memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
713                 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
714                 if (vallen != sizeof(int))
715                         RETURN(-EINVAL);
716                 imp->imp_initial_recov = *(int *)val;
717                 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
718                        exp->exp_obd->obd_name,
719                        imp->imp_initial_recov);
720                 RETURN(0);
721         } else if (keylen >= strlen("mds_num") && strcmp(key, "mds_num") == 0) {
722                 struct ptlrpc_request *req;
723                 int rc, size[2] = {keylen, vallen};
724                 char *bufs[2] = {key, val};
725
726                 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SET_INFO, 2,
727                                       size, bufs);
728                 if (req == NULL)
729                         RETURN(-ENOMEM);
730
731                 req->rq_replen = lustre_msg_size(0, NULL);
732                 rc = ptlrpc_queue_wait(req);
733                 ptlrpc_req_finished(req);
734                 RETURN(rc);
735         } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
736                 struct obd_import *imp = class_exp2cliimp(exp);
737                 imp->imp_server_timeout = 1;
738                 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
739                 RETURN(0);
740         }
741         RETURN(rc);
742 }
743
744 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
745                       unsigned long max_age)
746 {
747         struct ptlrpc_request *req;
748         struct obd_statfs *msfs;
749         int rc, size = sizeof(*msfs);
750         ENTRY;
751
752         /* We could possibly pass max_age in the request (as an absolute
753          * timestamp or a "seconds.usec ago") so the target can avoid doing
754          * extra calls into the filesystem if that isn't necessary (e.g.
755          * during mount that would help a bit).  Having relative timestamps
756          * is not so great if request processing is slow, while absolute
757          * timestamps are not ideal because they need time synchronization. */
758         req = ptlrpc_prep_req(obd->u.cli.cl_import, MDS_STATFS, 0, NULL, NULL);
759         if (!req)
760                 RETURN(-ENOMEM);
761
762         req->rq_replen = lustre_msg_size(1, &size);
763
764         mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
765         rc = ptlrpc_queue_wait(req);
766         mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
767
768         if (rc)
769                 GOTO(out, rc);
770
771         msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),lustre_swab_obd_statfs);
772         if (msfs == NULL) {
773                 CERROR("Can't unpack obd_statfs\n");
774                 GOTO(out, rc = -EPROTO);
775         }
776
777         memcpy(osfs, msfs, sizeof (*msfs));
778         EXIT;
779 out:
780         ptlrpc_req_finished(req);
781
782         return rc;
783 }
784
785 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
786                    struct obd_client_handle *handle, int flag)
787 {
788         struct ptlrpc_request *req;
789         struct mds_body *body;
790         int rc, size = sizeof(*body);
791         ENTRY;
792
793         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_PIN, 1, &size, NULL);
794         if (req == NULL)
795                 RETURN(-ENOMEM);
796
797         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
798         mdc_pack_fid(&body->fid1, ino, gen, type);
799         body->flags = flag;
800
801         req->rq_replen = lustre_msg_size(1, &size);
802
803         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
804         rc = ptlrpc_queue_wait(req);
805         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
806         if (rc) {
807                 CERROR("pin failed: %d\n", rc);
808                 ptlrpc_req_finished(req);
809                 RETURN(rc);
810         }
811
812         body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
813         if (body == NULL) {
814                 ptlrpc_req_finished(req);
815                 RETURN(rc);
816         }
817
818         memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
819         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
820
821         OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
822         if (handle->och_mod == NULL) {
823                 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
824                 RETURN(-ENOMEM);
825         }
826         handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
827
828         RETURN(rc);
829 }
830
831 static int mdc_unpin(struct obd_export *exp,
832                      struct obd_client_handle *handle, int flag)
833 {
834         struct ptlrpc_request *req;
835         struct mds_body *body;
836         int rc, size = sizeof(*body);
837         ENTRY;
838
839         if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
840                 RETURN(0);
841
842         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &size, NULL);
843         if (req == NULL)
844                 RETURN(-ENOMEM);
845
846         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
847         memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
848         body->flags = flag;
849
850         req->rq_replen = lustre_msg_size(0, NULL);
851         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
852         rc = ptlrpc_queue_wait(req);
853         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
854
855         if (rc != 0)
856                 CERROR("unpin failed: %d\n", rc);
857
858         ptlrpc_req_finished(req);
859         ptlrpc_req_finished(handle->och_mod->mod_open_req);
860         OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
861         RETURN(rc);
862 }
863
864 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
865              struct ptlrpc_request **request)
866 {
867         struct ptlrpc_request *req;
868         struct mds_body *body;
869         int size = sizeof(*body);
870         int rc;
871         ENTRY;
872
873         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_SYNC, 1,&size,NULL);
874         if (!req)
875                 RETURN(rc = -ENOMEM);
876
877         if (fid) {
878                 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
879                 memcpy(&body->fid1, fid, sizeof(*fid));
880                 mdc_pack_req_body(req);
881         }
882
883         req->rq_replen = lustre_msg_size(1, &size);
884
885         rc = ptlrpc_queue_wait(req);
886         if (rc || request == NULL)
887                 ptlrpc_req_finished(req);
888         else
889                 *request = req;
890
891         RETURN(rc);
892 }
893
894 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
895                             enum obd_import_event event)
896 {
897         int rc = 0;
898
899         LASSERT(imp->imp_obd == obd);
900
901         switch (event) {
902         case IMP_EVENT_DISCON: {
903                 break;
904         }
905         case IMP_EVENT_INACTIVE: {
906                 if (obd->obd_observer)
907                         rc = obd_notify(obd->obd_observer, obd, 0);
908                 break;
909         }
910         case IMP_EVENT_INVALIDATE: {
911                 struct ldlm_namespace *ns = obd->obd_namespace;
912
913                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
914
915                 break;
916         }
917         case IMP_EVENT_ACTIVE: {
918                 if (obd->obd_observer)
919                         rc = obd_notify(obd->obd_observer, obd, 1);
920                 break;
921         }
922         default:
923                 CERROR("Unknown import event %d\n", event);
924                 LBUG();
925         }
926         RETURN(rc);
927 }
928
929 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
930 {
931         struct lprocfs_static_vars lvars;
932
933         lprocfs_init_vars(mdc, &lvars);
934         return lprocfs_obd_attach(dev, lvars.obd_vars);
935 }
936
937 static int mdc_detach(struct obd_device *dev)
938 {
939         return lprocfs_obd_detach(dev);
940 }
941
942 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
943 {
944         struct client_obd *cli = &obd->u.cli;
945         int rc;
946         ENTRY;
947
948         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
949         if (!cli->cl_rpc_lock)
950                 RETURN(-ENOMEM);
951         mdc_init_rpc_lock(cli->cl_rpc_lock);
952
953         ptlrpcd_addref();
954
955         OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
956         if (!cli->cl_setattr_lock)
957                 GOTO(err_rpc_lock, rc = -ENOMEM);
958         mdc_init_rpc_lock(cli->cl_setattr_lock);
959
960         rc = client_obd_setup(obd, len, buf);
961         if (rc)
962                 GOTO(err_setattr_lock, rc);
963
964         rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
965         if (rc) {
966                 mdc_cleanup(obd, 0);
967                 CERROR("failed to setup llogging subsystems\n");
968         }
969
970         RETURN(rc);
971
972 err_setattr_lock:
973         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
974 err_rpc_lock:
975         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
976         ptlrpcd_decref();
977         RETURN(rc);
978 }
979
980 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
981 {
982         struct obd_device *obd = exp->exp_obd;
983         struct client_obd *cli = &obd->u.cli;
984         ENTRY;
985
986         if (cli->cl_max_mds_easize < easize)
987                 cli->cl_max_mds_easize = easize;
988         if (cli->cl_max_mds_cookiesize < cookiesize)
989                 cli->cl_max_mds_cookiesize = cookiesize;
990         RETURN(0);
991 }
992
993 static int mdc_precleanup(struct obd_device *obd, int flags)
994 {
995         int rc = 0;
996         
997         rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
998         if (rc != 0)
999                 CERROR("failed to cleanup llogging subsystems\n");
1000
1001         RETURN(rc);
1002 }
1003
1004 static int mdc_cleanup(struct obd_device *obd, int flags)
1005 {
1006         struct client_obd *cli = &obd->u.cli;
1007
1008         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1009         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1010
1011         ptlrpcd_decref();
1012
1013         return client_obd_cleanup(obd, flags);
1014 }
1015
1016
1017 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
1018                          struct obd_device *tgt, int count,
1019                          struct llog_catid *logid)
1020 {
1021         struct llog_ctxt *ctxt;
1022         int rc;
1023         ENTRY;
1024
1025         rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1026                             &llog_client_ops);
1027         if (rc == 0) {
1028                 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1029                 ctxt->loc_imp = obd->u.cli.cl_import;
1030         }
1031
1032         RETURN(rc);
1033 }
1034
1035 static int mdc_llog_finish(struct obd_device *obd,
1036                            struct obd_llogs *llogs, int count)
1037 {
1038         int rc;
1039         ENTRY;
1040
1041         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1042         RETURN(rc);
1043 }
1044 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1045                                            char *name, int len)
1046 {
1047        ENTRY;
1048        RETURN(exp->exp_obd);
1049 }
1050
1051 static int mdc_get_info(struct obd_export *exp, obd_count keylen,
1052                         void *key, __u32 *vallen, void *val)
1053 {
1054         ENTRY;
1055         if (!vallen || !val)
1056                 RETURN(-EFAULT);
1057
1058         if (keylen >= strlen("mdsize") && strcmp(key, "mdsize") == 0) {
1059                 struct ptlrpc_request *req;
1060                 __u32 *reply;
1061                 char *bufs[1] = {key};
1062                 int rc;
1063                 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_GET_INFO, 1,
1064                                       &keylen, bufs);
1065                 if (req == NULL)
1066                         RETURN(-ENOMEM);
1067
1068                 req->rq_replen = lustre_msg_size(1, vallen);
1069                 rc = ptlrpc_queue_wait(req);
1070                 if (rc)
1071                         GOTO(out, rc);
1072
1073                 /* FIXME: right swap routine here! */
1074                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply), NULL);
1075                 if (reply == NULL) {
1076                         CERROR("Can't unpack mdsize\n");
1077                         GOTO(out, rc = -EPROTO);
1078                 }
1079                 *((__u32 *)val) = *reply;
1080         out:
1081                 ptlrpc_req_finished(req);
1082                 RETURN(rc);
1083         }
1084         RETURN(-EINVAL);
1085 }
1086
1087 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1088                     struct lov_stripe_md **ea, struct obd_trans_info *oti)
1089 {
1090         struct ptlrpc_request *request;
1091         struct ost_body *body;
1092         int rc, size = sizeof(*body);
1093         ENTRY;
1094
1095         LASSERT(oa);
1096
1097         request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_CREATE,
1098                                   1, &size, NULL);
1099         if (!request)
1100                 GOTO(out_req, rc = -ENOMEM);
1101
1102         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1103         memcpy(&body->oa, oa, sizeof(body->oa));
1104
1105         request->rq_replen = lustre_msg_size(1, &size);
1106         rc = ptlrpc_queue_wait(request);
1107         if (rc)
1108                 GOTO(out_req, rc);
1109
1110         body = lustre_swab_repbuf(request, 0, sizeof(*body),
1111                                   lustre_swab_ost_body);
1112         if (body == NULL) {
1113                 CERROR ("can't unpack ost_body\n");
1114                 GOTO (out_req, rc = -EPROTO);
1115         }
1116
1117         memcpy(oa, &body->oa, sizeof(*oa));
1118
1119         /* store ino/generation for recovery */
1120         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1121         body->oa.o_id = oa->o_id;
1122         body->oa.o_generation = oa->o_generation;
1123
1124         CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1125         EXIT;
1126 out_req:
1127         ptlrpc_req_finished(request);
1128         return rc;
1129 }
1130
1131 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1132                 struct lov_stripe_md *ea, obd_count oa_bufs,
1133                 struct brw_page *pgarr, struct obd_trans_info *oti)
1134 {
1135         struct ptlrpc_bulk_desc *desc;
1136         struct niobuf_remote *niobuf;
1137         struct ptlrpc_request *req;
1138         struct obd_ioobj *ioobj;
1139         struct ost_body *body;
1140         int err, opc, i;
1141         int size[3];
1142
1143         opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1144         
1145         size[0] = sizeof(*body);
1146         size[1] = sizeof(*ioobj);
1147         size[2] = oa_bufs * sizeof(*niobuf);
1148
1149         req = ptlrpc_prep_req(class_exp2cliimp(exp), opc, 3, size, NULL);
1150         LASSERT(req != NULL);
1151
1152         if (opc == OST_WRITE)
1153                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1154                                             OST_BULK_PORTAL);
1155         else
1156                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1157                                             OST_BULK_PORTAL);
1158         LASSERT(desc != NULL);
1159
1160         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1161         ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1162         niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1163
1164         memcpy(&body->oa, oa, sizeof(*oa));
1165         obdo_to_ioobj(oa, ioobj);
1166         ioobj->ioo_bufcnt = oa_bufs;
1167
1168         for (i = 0; i < oa_bufs; i++, niobuf++) {
1169                 struct brw_page *pg = &pgarr[i];
1170
1171                 LASSERT(pg->count > 0);
1172                 LASSERT((pg->off & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1173
1174                 ptlrpc_prep_bulk_page(desc, pg->pg, pg->off & ~PAGE_MASK,
1175                                       pg->count);
1176
1177                 niobuf->offset = pg->off;
1178                 niobuf->len = pg->count;
1179                 niobuf->flags = pg->flag;
1180         }
1181
1182         /* size[0] still sizeof (*body) */
1183         if (opc == OST_WRITE) {
1184                 /* 1 RC per niobuf */
1185                 size[1] = sizeof(__u32) * oa_bufs;
1186                 req->rq_replen = lustre_msg_size(2, size);
1187         } else {
1188                 /* 1 RC for the whole I/O */
1189                 req->rq_replen = lustre_msg_size(1, size);
1190         }
1191         err = ptlrpc_queue_wait(req);
1192         LASSERT(err == 0);
1193
1194         ptlrpc_req_finished(req);
1195         return 0;
1196 }
1197
1198 static int mdc_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1199 {
1200         struct ldlm_res_id res_id = { .name = {0} };
1201         struct obd_device *obd = exp->exp_obd;
1202         struct lustre_handle lockh;
1203         ldlm_policy_data_t policy;
1204         int flags;
1205         ENTRY;
1206
1207         res_id.name[0] = fid->id;
1208         res_id.name[1] = fid->generation;
1209         policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1210
1211         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
1212
1213         /* FIXME use LDLM_FL_TEST_LOCK instead */
1214         flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1215         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1216                             LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1217                 ldlm_lock_decref(&lockh, LCK_PR);
1218                 RETURN(1);
1219         }
1220
1221         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1222                             LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1223                 ldlm_lock_decref(&lockh, LCK_PW);
1224                 RETURN(1);
1225         }
1226         RETURN(0);
1227 }
1228 static int mdc_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
1229                                   char *name, int len, struct ll_fid *cfid,
1230                                   ldlm_iterator_t it, void *data)
1231 {
1232         int rc;
1233         rc = mdc_change_cbdata(exp, cfid, it, data);
1234         RETURN(rc);
1235 }
1236
1237 struct obd_ops mdc_obd_ops = {
1238         .o_owner         = THIS_MODULE,
1239         .o_attach        = mdc_attach,
1240         .o_detach        = mdc_detach,
1241         .o_setup         = mdc_setup,
1242         .o_precleanup    = mdc_precleanup,
1243         .o_cleanup       = mdc_cleanup,
1244         .o_connect       = client_connect_import,
1245         .o_disconnect    = client_disconnect_export,
1246         .o_iocontrol     = mdc_iocontrol,
1247         .o_set_info      = mdc_set_info,
1248         .o_statfs        = mdc_statfs,
1249         .o_pin           = mdc_pin,
1250         .o_unpin         = mdc_unpin,
1251         .o_import_event  = mdc_import_event,
1252         .o_llog_init     = mdc_llog_init,
1253         .o_llog_finish   = mdc_llog_finish,
1254         .o_create        = mdc_obj_create,
1255         .o_set_info      = mdc_set_info,
1256         .o_get_info      = mdc_get_info,
1257         .o_brw           = mdc_brw,
1258         .o_init_ea_size  = mdc_init_ea_size,
1259 };
1260
1261 struct md_ops mdc_md_ops = {
1262         .m_getstatus     = mdc_getstatus,
1263         .m_getattr       = mdc_getattr,
1264         .m_change_cbdata = mdc_change_cbdata,
1265         .m_close         = mdc_close,
1266         .m_create        = mdc_create,
1267         .m_done_writing  = mdc_done_writing,
1268         .m_enqueue       = mdc_enqueue,
1269         .m_getattr_name  = mdc_getattr_name,
1270         .m_intent_lock   = mdc_intent_lock,
1271         .m_link          = mdc_link,
1272         .m_rename        = mdc_rename,
1273         .m_setattr       = mdc_setattr,
1274         .m_sync          = mdc_sync,
1275         .m_readpage      = mdc_readpage,
1276         .m_unlink        = mdc_unlink,
1277         .m_valid_attrs   = mdc_valid_attrs,
1278         .m_req2lustre_md = mdc_req2lustre_md,
1279         .m_set_open_replay_data   = mdc_set_open_replay_data,
1280         .m_clear_open_replay_data = mdc_clear_open_replay_data,
1281         .m_store_inode_generation = mdc_store_inode_generation,
1282         .m_set_lock_data = mdc_set_lock_data,
1283         .m_get_real_obd  = mdc_get_real_obd,
1284         .m_change_cbdata_name = mdc_change_cbdata_name,
1285         .m_change_cbdata = mdc_change_cbdata,
1286 };
1287
1288 int __init mdc_init(void)
1289 {
1290         struct lprocfs_static_vars lvars;
1291         lprocfs_init_vars(mdc, &lvars);
1292         return class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1293                                    LUSTRE_MDC_NAME);
1294 }
1295
1296 #ifdef __KERNEL__
1297 static void /*__exit*/ mdc_exit(void)
1298 {
1299         class_unregister_type(LUSTRE_MDC_NAME);
1300 }
1301
1302 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1303 MODULE_DESCRIPTION("Lustre Metadata Client");
1304 MODULE_LICENSE("GPL");
1305
1306 EXPORT_SYMBOL(mdc_req2lustre_md);
1307 EXPORT_SYMBOL(mdc_change_cbdata);
1308 EXPORT_SYMBOL(mdc_getstatus);
1309 EXPORT_SYMBOL(mdc_getattr);
1310 EXPORT_SYMBOL(mdc_getattr_name);
1311 EXPORT_SYMBOL(mdc_create);
1312 EXPORT_SYMBOL(mdc_unlink);
1313 EXPORT_SYMBOL(mdc_rename);
1314 EXPORT_SYMBOL(mdc_link);
1315 EXPORT_SYMBOL(mdc_readpage);
1316 EXPORT_SYMBOL(mdc_setattr);
1317 EXPORT_SYMBOL(mdc_close);
1318 EXPORT_SYMBOL(mdc_done_writing);
1319 EXPORT_SYMBOL(mdc_sync);
1320 EXPORT_SYMBOL(mdc_set_open_replay_data);
1321 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1322 EXPORT_SYMBOL(mdc_store_inode_generation);
1323
1324 module_init(mdc_init);
1325 module_exit(mdc_exit);
1326 #endif