Whamcloud - gitweb
land b_ost_amd onto HEAD.
[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         LASSERT(open_req->rq_transno != 0);
430         LASSERT(open_req->rq_import == imp);
431
432         /* We no longer want to preserve this for transno-unconditional
433          * replay. */
434         spin_lock(&open_req->rq_lock);
435         open_req->rq_replay = 0;
436         spin_unlock(&open_req->rq_lock);
437 }
438
439 static int mdc_close_interpret(struct ptlrpc_request *req, void *data, int rc)
440 {
441         union ptlrpc_async_args *aa = data;
442         struct mdc_rpc_lock *rpc_lock;
443         struct obd_device *obd = aa->pointer_arg[1];
444         unsigned long flags;
445
446         spin_lock_irqsave(&req->rq_lock, flags);
447         rpc_lock = aa->pointer_arg[0];
448         aa->pointer_arg[0] = NULL;
449         spin_unlock_irqrestore (&req->rq_lock, flags);
450
451         if (rpc_lock == NULL) {
452                 CERROR("called with NULL rpc_lock\n");
453         } else {
454                 mdc_put_rpc_lock(rpc_lock, NULL);
455                 LASSERTF(rpc_lock == obd->u.cli.cl_rpc_lock, "%p != %p\n",
456                          rpc_lock, obd->u.cli.cl_rpc_lock);
457         }
458         wake_up(&req->rq_reply_waitq);
459         RETURN(rc);
460 }
461
462 /* We can't use ptlrpc_check_reply, because we don't want to wake up for
463  * anything but a reply or an error. */
464 static int mdc_close_check_reply(struct ptlrpc_request *req)
465 {
466         int rc = 0;
467         unsigned long flags;
468
469         spin_lock_irqsave(&req->rq_lock, flags);
470         if (req->rq_async_args.pointer_arg[0] == NULL)
471                 rc = 1;
472         spin_unlock_irqrestore (&req->rq_lock, flags);
473         return rc;
474 }
475
476 static int go_back_to_sleep(void *unused)
477 {
478         return 0;
479 }
480
481 int mdc_close(struct obd_export *exp, struct obdo *oa,
482               struct obd_client_handle *och, struct ptlrpc_request **request)
483 {
484         struct obd_device *obd = class_exp2obd(exp);
485         int reqsize = sizeof(struct mds_body);
486         int rc, repsize[3] = {sizeof(struct mds_body),
487                               obd->u.cli.cl_max_mds_easize,
488                               obd->u.cli.cl_max_mds_cookiesize};
489         struct ptlrpc_request *req;
490         struct mdc_open_data *mod;
491         struct l_wait_info lwi;
492         ENTRY;
493
494         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &reqsize,
495                               NULL);
496         if (req == NULL)
497                 GOTO(out, rc = -ENOMEM);
498
499         /* Ensure that this close's handle is fixed up during replay. */
500         LASSERT(och != NULL);
501         mod = och->och_mod;
502         if (likely(mod != NULL)) {
503                 mod->mod_close_req = req;
504                 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
505                 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open req %p",
506                           mod->mod_open_req);
507         } else {
508                 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
509         }
510
511         mdc_close_pack(req, 0, oa, oa->o_valid, och);
512
513         req->rq_replen = lustre_msg_size(3, repsize);
514         req->rq_commit_cb = mdc_commit_close;
515         LASSERT(req->rq_cb_data == NULL);
516         req->rq_cb_data = mod;
517
518         /* We hand a ref to the rpcd here, so we need another one of our own. */
519         ptlrpc_request_addref(req);
520
521         mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
522         req->rq_interpret_reply = mdc_close_interpret;
523         req->rq_async_args.pointer_arg[0] = obd->u.cli.cl_rpc_lock;
524         req->rq_async_args.pointer_arg[1] = obd;
525         ptlrpcd_add_req(req);
526         lwi = LWI_TIMEOUT_INTR(MAX(req->rq_timeout * HZ, 1), go_back_to_sleep,
527                                NULL, NULL);
528         rc = l_wait_event(req->rq_reply_waitq, mdc_close_check_reply(req),
529                           &lwi);
530         if (req->rq_repmsg == NULL) {
531                 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
532                        req->rq_status);
533                 if (rc == 0)
534                         rc = req->rq_status ? req->rq_status : -EIO;
535         } else if (rc == 0) {
536                 rc = req->rq_repmsg->status;
537                 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
538                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
539                                   "= %d", rc);
540                         if (rc > 0)
541                                 rc = -rc;
542                 } else if (mod == NULL) {
543                         CERROR("Unexpected: can't find mdc_open_data, but the "
544                                "close succeeded.  Please tell CFS.\n");
545                 }
546                 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
547                                         lustre_swab_mds_body)) {
548                         CERROR("Error unpacking mds_body\n");
549                         rc = -EPROTO;
550                 }
551         }
552         if (req->rq_async_args.pointer_arg[0] != NULL) {
553                 CERROR("returned without dropping rpc_lock: rc %d\n", rc);
554                 mdc_close_interpret(req, &req->rq_async_args, rc);
555                 portals_debug_dumplog();
556         }
557
558         EXIT;
559  out:
560         *request = req;
561         return rc;
562 }
563
564 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
565 {
566         struct ptlrpc_request *req;
567         struct mds_body *body;
568         int rc, size = sizeof(*body);
569         ENTRY;
570
571         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_DONE_WRITING, 1,
572                               &size, NULL);
573         if (req == NULL)
574                 RETURN(-ENOMEM);
575
576         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
577         mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
578         body->size = obdo->o_size;
579         body->blocks = obdo->o_blocks;
580         body->flags = obdo->o_flags;
581         body->valid = obdo->o_valid;
582 //        memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
583
584         req->rq_replen = lustre_msg_size(1, &size);
585
586         rc = ptlrpc_queue_wait(req);
587         ptlrpc_req_finished(req);
588         RETURN(rc);
589 }
590
591 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
592                  __u64 offset, struct page *page,
593                  struct ptlrpc_request **request)
594 {
595         struct obd_import *imp = class_exp2cliimp(exp);
596         struct ptlrpc_request *req = NULL;
597         struct ptlrpc_bulk_desc *desc = NULL;
598         struct mds_body *body;
599         int rc, size = sizeof(*body);
600         ENTRY;
601
602         CDEBUG(D_INODE, "inode: %ld\n", (long)mdc_fid->id);
603
604         req = ptlrpc_prep_req(imp, MDS_READPAGE, 1, &size, NULL);
605         if (req == NULL)
606                 GOTO(out, rc = -ENOMEM);
607         /* XXX FIXME bug 249 */
608         req->rq_request_portal = MDS_READPAGE_PORTAL;
609
610         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
611         if (desc == NULL)
612                 GOTO(out, rc = -ENOMEM);
613         /* NB req now owns desc and will free it when it gets freed */
614
615         ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
616
617         mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE, mdc_fid);
618
619         req->rq_replen = lustre_msg_size(1, &size);
620         rc = ptlrpc_queue_wait(req);
621
622         if (rc == 0) {
623                 body = lustre_swab_repbuf(req, 0, sizeof (*body),
624                                           lustre_swab_mds_body);
625                 if (body == NULL) {
626                         CERROR("Can't unpack mds_body\n");
627                         GOTO(out, rc = -EPROTO);
628                 }
629
630                 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
631                         CERROR ("Unexpected # bytes transferred: %d"
632                                 " (%ld expected)\n",
633                                 req->rq_bulk->bd_nob_transferred,
634                                 PAGE_CACHE_SIZE);
635                         GOTO (out, rc = -EPROTO);
636                 }
637         }
638
639         EXIT;
640  out:
641         *request = req;
642         return rc;
643 }
644
645 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
646                          void *karg, void *uarg)
647 {
648         struct obd_device *obd = exp->exp_obd;
649         struct obd_ioctl_data *data = karg;
650         struct obd_import *imp = obd->u.cli.cl_import;
651         struct llog_ctxt *ctxt;
652         int rc;
653         ENTRY;
654
655 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
656         MOD_INC_USE_COUNT;
657 #else
658         if (!try_module_get(THIS_MODULE)) {
659                 CERROR("Can't get module. Is it alive?");
660                 return -EINVAL;
661         }
662 #endif
663         switch (cmd) {
664         case OBD_IOC_CLIENT_RECOVER:
665                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
666                 if (rc < 0)
667                         GOTO(out, rc);
668                 GOTO(out, rc = 0);
669         case IOC_OSC_SET_ACTIVE:
670                 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
671                 GOTO(out, rc);
672         case OBD_IOC_PARSE: {
673                 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
674                                         LLOG_CONFIG_REPL_CTXT);
675                 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
676                 GOTO(out, rc);
677         }
678 #ifdef __KERNEL__
679         case OBD_IOC_LLOG_INFO:
680         case OBD_IOC_LLOG_PRINT: {
681                 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
682                 rc = llog_ioctl(ctxt, cmd, data);
683
684                 GOTO(out, rc);
685         }
686 #endif
687         default:
688                 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
689                 GOTO(out, rc = -ENOTTY);
690         }
691 out:
692 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
693         MOD_DEC_USE_COUNT;
694 #else
695         module_put(THIS_MODULE);
696 #endif
697
698         return rc;
699 }
700
701 int mdc_set_info(struct obd_export *exp, obd_count keylen,
702                  void *key, obd_count vallen, void *val)
703 {
704         int rc = -EINVAL;
705
706         if (keylen == strlen("initial_recov") &&
707             memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
708                 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
709                 if (vallen != sizeof(int))
710                         RETURN(-EINVAL);
711                 imp->imp_initial_recov = *(int *)val;
712                 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
713                        exp->exp_obd->obd_name,
714                        imp->imp_initial_recov);
715                 RETURN(0);
716         } else if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
717                 struct ptlrpc_request *req;
718                 char *bufs[1] = {key};
719                 int rc;
720                 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SET_INFO, 1,
721                                       &keylen, bufs);
722                 if (req == NULL)
723                         RETURN(-ENOMEM);
724
725                 req->rq_replen = lustre_msg_size(0, NULL);
726                 rc = ptlrpc_queue_wait(req);
727                 ptlrpc_req_finished(req);
728                 RETURN(rc);
729         } else if (keylen >= strlen("mds_num") && strcmp(key, "mds_num") == 0) {
730                 struct ptlrpc_request *req;
731                 int rc, size[2] = {keylen, vallen};
732                 char *bufs[2] = {key, val};
733
734                 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SET_INFO, 2,
735                                       size, bufs);
736                 if (req == NULL)
737                         RETURN(-ENOMEM);
738
739                 req->rq_replen = lustre_msg_size(0, NULL);
740                 rc = ptlrpc_queue_wait(req);
741                 ptlrpc_req_finished(req);
742                 RETURN(rc);
743         } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
744                 struct obd_import *imp = class_exp2cliimp(exp);
745                 imp->imp_server_timeout = 1;
746                 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
747                 RETURN(0);
748         }
749         RETURN(rc);
750 }
751
752 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
753                       unsigned long max_age)
754 {
755         struct ptlrpc_request *req;
756         struct obd_statfs *msfs;
757         int rc, size = sizeof(*msfs);
758         ENTRY;
759
760         /* We could possibly pass max_age in the request (as an absolute
761          * timestamp or a "seconds.usec ago") so the target can avoid doing
762          * extra calls into the filesystem if that isn't necessary (e.g.
763          * during mount that would help a bit).  Having relative timestamps
764          * is not so great if request processing is slow, while absolute
765          * timestamps are not ideal because they need time synchronization. */
766         req = ptlrpc_prep_req(obd->u.cli.cl_import, MDS_STATFS, 0, NULL, NULL);
767         if (!req)
768                 RETURN(-ENOMEM);
769
770         req->rq_replen = lustre_msg_size(1, &size);
771
772         mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
773         rc = ptlrpc_queue_wait(req);
774         mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
775
776         if (rc)
777                 GOTO(out, rc);
778
779         msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),lustre_swab_obd_statfs);
780         if (msfs == NULL) {
781                 CERROR("Can't unpack obd_statfs\n");
782                 GOTO(out, rc = -EPROTO);
783         }
784
785         memcpy(osfs, msfs, sizeof (*msfs));
786         EXIT;
787 out:
788         ptlrpc_req_finished(req);
789
790         return rc;
791 }
792
793 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
794                    struct obd_client_handle *handle, int flag)
795 {
796         struct ptlrpc_request *req;
797         struct mds_body *body;
798         int rc, size = sizeof(*body);
799         ENTRY;
800
801         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_PIN, 1, &size, NULL);
802         if (req == NULL)
803                 RETURN(-ENOMEM);
804
805         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
806         mdc_pack_fid(&body->fid1, ino, gen, type);
807         body->flags = flag;
808
809         req->rq_replen = lustre_msg_size(1, &size);
810
811         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
812         rc = ptlrpc_queue_wait(req);
813         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
814         if (rc) {
815                 CERROR("pin failed: %d\n", rc);
816                 ptlrpc_req_finished(req);
817                 RETURN(rc);
818         }
819
820         body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
821         if (body == NULL) {
822                 ptlrpc_req_finished(req);
823                 RETURN(rc);
824         }
825
826         memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
827         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
828
829         OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
830         if (handle->och_mod == NULL) {
831                 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
832                 RETURN(-ENOMEM);
833         }
834         handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
835
836         RETURN(rc);
837 }
838
839 static int mdc_unpin(struct obd_export *exp,
840                      struct obd_client_handle *handle, int flag)
841 {
842         struct ptlrpc_request *req;
843         struct mds_body *body;
844         int rc, size = sizeof(*body);
845         ENTRY;
846
847         if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
848                 RETURN(0);
849
850         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &size, NULL);
851         if (req == NULL)
852                 RETURN(-ENOMEM);
853
854         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
855         memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
856         body->flags = flag;
857
858         req->rq_replen = lustre_msg_size(0, NULL);
859         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
860         rc = ptlrpc_queue_wait(req);
861         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
862
863         if (rc != 0)
864                 CERROR("unpin failed: %d\n", rc);
865
866         ptlrpc_req_finished(req);
867         ptlrpc_req_finished(handle->och_mod->mod_open_req);
868         OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
869         RETURN(rc);
870 }
871
872 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
873              struct ptlrpc_request **request)
874 {
875         struct ptlrpc_request *req;
876         struct mds_body *body;
877         int size = sizeof(*body);
878         int rc;
879         ENTRY;
880
881         req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_SYNC, 1,&size,NULL);
882         if (!req)
883                 RETURN(rc = -ENOMEM);
884
885         if (fid) {
886                 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
887                 memcpy(&body->fid1, fid, sizeof(*fid));
888                 mdc_pack_req_body(req);
889         }
890
891         req->rq_replen = lustre_msg_size(1, &size);
892
893         rc = ptlrpc_queue_wait(req);
894         if (rc || request == NULL)
895                 ptlrpc_req_finished(req);
896         else
897                 *request = req;
898
899         RETURN(rc);
900 }
901
902 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
903                             enum obd_import_event event)
904 {
905         int rc = 0;
906
907         LASSERT(imp->imp_obd == obd);
908
909         switch (event) {
910         case IMP_EVENT_DISCON: {
911                 break;
912         }
913         case IMP_EVENT_INACTIVE: {
914                 if (obd->obd_observer)
915                         rc = obd_notify(obd->obd_observer, obd, 0);
916                 break;
917         }
918         case IMP_EVENT_INVALIDATE: {
919                 struct ldlm_namespace *ns = obd->obd_namespace;
920
921                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
922
923                 break;
924         }
925         case IMP_EVENT_ACTIVE: {
926                 if (obd->obd_observer)
927                         rc = obd_notify(obd->obd_observer, obd, 1);
928                 break;
929         }
930         default:
931                 CERROR("Unknown import event %d\n", event);
932                 LBUG();
933         }
934         RETURN(rc);
935 }
936
937 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
938 {
939         struct lprocfs_static_vars lvars;
940
941         lprocfs_init_vars(mdc, &lvars);
942         return lprocfs_obd_attach(dev, lvars.obd_vars);
943 }
944
945 static int mdc_detach(struct obd_device *dev)
946 {
947         return lprocfs_obd_detach(dev);
948 }
949
950 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
951 {
952         struct client_obd *cli = &obd->u.cli;
953         int rc;
954         ENTRY;
955
956         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
957         if (!cli->cl_rpc_lock)
958                 RETURN(-ENOMEM);
959         mdc_init_rpc_lock(cli->cl_rpc_lock);
960
961         ptlrpcd_addref();
962
963         OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
964         if (!cli->cl_setattr_lock)
965                 GOTO(err_rpc_lock, rc = -ENOMEM);
966         mdc_init_rpc_lock(cli->cl_setattr_lock);
967
968         rc = client_obd_setup(obd, len, buf);
969         if (rc)
970                 GOTO(err_setattr_lock, rc);
971
972         rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
973         if (rc) {
974                 mdc_cleanup(obd, 0);
975                 CERROR("failed to setup llogging subsystems\n");
976         }
977
978         RETURN(rc);
979
980 err_setattr_lock:
981         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
982 err_rpc_lock:
983         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
984         ptlrpcd_decref();
985         RETURN(rc);
986 }
987
988 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
989 {
990         struct obd_device *obd = exp->exp_obd;
991         struct client_obd *cli = &obd->u.cli;
992         ENTRY;
993
994         if (cli->cl_max_mds_easize < easize)
995                 cli->cl_max_mds_easize = easize;
996         if (cli->cl_max_mds_cookiesize < cookiesize)
997                 cli->cl_max_mds_cookiesize = cookiesize;
998         RETURN(0);
999 }
1000
1001 static int mdc_precleanup(struct obd_device *obd, int flags)
1002 {
1003         int rc = 0;
1004         
1005         rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1006         if (rc != 0)
1007                 CERROR("failed to cleanup llogging subsystems\n");
1008
1009         RETURN(rc);
1010 }
1011
1012 static int mdc_cleanup(struct obd_device *obd, int flags)
1013 {
1014         struct client_obd *cli = &obd->u.cli;
1015
1016         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1017         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1018
1019         ptlrpcd_decref();
1020
1021         return client_obd_cleanup(obd, flags);
1022 }
1023
1024
1025 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
1026                          struct obd_device *tgt, int count,
1027                          struct llog_catid *logid)
1028 {
1029         struct llog_ctxt *ctxt;
1030         int rc;
1031         ENTRY;
1032
1033         rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1034                             &llog_client_ops);
1035         if (rc == 0) {
1036                 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1037                 ctxt->loc_imp = obd->u.cli.cl_import;
1038         }
1039
1040         RETURN(rc);
1041 }
1042
1043 static int mdc_llog_finish(struct obd_device *obd,
1044                            struct obd_llogs *llogs, int count)
1045 {
1046         int rc;
1047         ENTRY;
1048
1049         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1050         RETURN(rc);
1051 }
1052 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1053                                            char *name, int len)
1054 {
1055        ENTRY;
1056        RETURN(exp->exp_obd);
1057 }
1058
1059 static int mdc_get_info(struct obd_export *exp, obd_count keylen,
1060                         void *key, __u32 *vallen, void *val)
1061 {
1062         ENTRY;
1063         if (!vallen || !val)
1064                 RETURN(-EFAULT);
1065
1066         if (keylen >= strlen("mdsize") && strcmp(key, "mdsize") == 0) {
1067                 struct ptlrpc_request *req;
1068                 __u32 *reply;
1069                 char *bufs[1] = {key};
1070                 int rc;
1071                 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_GET_INFO, 1,
1072                                       &keylen, bufs);
1073                 if (req == NULL)
1074                         RETURN(-ENOMEM);
1075
1076                 req->rq_replen = lustre_msg_size(1, vallen);
1077                 rc = ptlrpc_queue_wait(req);
1078                 if (rc)
1079                         GOTO(out, rc);
1080
1081                 /* FIXME: right swap routine here! */
1082                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply), NULL);
1083                 if (reply == NULL) {
1084                         CERROR("Can't unpack mdsize\n");
1085                         GOTO(out, rc = -EPROTO);
1086                 }
1087                 *((__u32 *)val) = *reply;
1088         out:
1089                 ptlrpc_req_finished(req);
1090                 RETURN(rc);
1091         }
1092         RETURN(-EINVAL);
1093 }
1094
1095 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1096                     struct lov_stripe_md **ea, struct obd_trans_info *oti)
1097 {
1098         struct ptlrpc_request *request;
1099         struct ost_body *body;
1100         int rc, size = sizeof(*body);
1101         ENTRY;
1102
1103         LASSERT(oa);
1104
1105         request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_CREATE,
1106                                   1, &size, NULL);
1107         if (!request)
1108                 GOTO(out_req, rc = -ENOMEM);
1109
1110         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1111         memcpy(&body->oa, oa, sizeof(body->oa));
1112
1113         request->rq_replen = lustre_msg_size(1, &size);
1114         rc = ptlrpc_queue_wait(request);
1115         if (rc)
1116                 GOTO(out_req, rc);
1117
1118         body = lustre_swab_repbuf(request, 0, sizeof(*body),
1119                                   lustre_swab_ost_body);
1120         if (body == NULL) {
1121                 CERROR ("can't unpack ost_body\n");
1122                 GOTO (out_req, rc = -EPROTO);
1123         }
1124
1125         memcpy(oa, &body->oa, sizeof(*oa));
1126
1127         /* store ino/generation for recovery */
1128         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1129         body->oa.o_id = oa->o_id;
1130         body->oa.o_generation = oa->o_generation;
1131
1132         CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1133         EXIT;
1134 out_req:
1135         ptlrpc_req_finished(request);
1136         return rc;
1137 }
1138
1139 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1140                 struct lov_stripe_md *ea, obd_count oa_bufs,
1141                 struct brw_page *pgarr, struct obd_trans_info *oti)
1142 {
1143         struct ptlrpc_bulk_desc *desc;
1144         struct niobuf_remote *niobuf;
1145         struct ptlrpc_request *req;
1146         struct obd_ioobj *ioobj;
1147         struct ost_body *body;
1148         int err, opc, i;
1149         int size[3];
1150
1151         opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1152         
1153         size[0] = sizeof(*body);
1154         size[1] = sizeof(*ioobj);
1155         size[2] = oa_bufs * sizeof(*niobuf);
1156
1157         req = ptlrpc_prep_req(class_exp2cliimp(exp), opc, 3, size, NULL);
1158         LASSERT(req != NULL);
1159
1160         if (opc == OST_WRITE)
1161                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1162                                             OST_BULK_PORTAL);
1163         else
1164                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1165                                             OST_BULK_PORTAL);
1166         LASSERT(desc != NULL);
1167
1168         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1169         ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1170         niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1171
1172         memcpy(&body->oa, oa, sizeof(*oa));
1173         obdo_to_ioobj(oa, ioobj);
1174         ioobj->ioo_bufcnt = oa_bufs;
1175
1176         for (i = 0; i < oa_bufs; i++, niobuf++) {
1177                 struct brw_page *pg = &pgarr[i];
1178
1179                 LASSERT(pg->count > 0);
1180                 LASSERT((pg->off & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1181
1182                 ptlrpc_prep_bulk_page(desc, pg->pg, pg->off & ~PAGE_MASK,
1183                                       pg->count);
1184
1185                 niobuf->offset = pg->off;
1186                 niobuf->len = pg->count;
1187                 niobuf->flags = pg->flag;
1188         }
1189
1190         /* size[0] still sizeof (*body) */
1191         if (opc == OST_WRITE) {
1192                 /* 1 RC per niobuf */
1193                 size[1] = sizeof(__u32) * oa_bufs;
1194                 req->rq_replen = lustre_msg_size(2, size);
1195         } else {
1196                 /* 1 RC for the whole I/O */
1197                 req->rq_replen = lustre_msg_size(1, size);
1198         }
1199         err = ptlrpc_queue_wait(req);
1200         LASSERT(err == 0);
1201
1202         ptlrpc_req_finished(req);
1203         return 0;
1204 }
1205
1206 static int mdc_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1207 {
1208         struct ldlm_res_id res_id = { .name = {0} };
1209         struct obd_device *obd = exp->exp_obd;
1210         struct lustre_handle lockh;
1211         ldlm_policy_data_t policy;
1212         int flags;
1213         ENTRY;
1214
1215         res_id.name[0] = fid->id;
1216         res_id.name[1] = fid->generation;
1217         policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1218
1219         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
1220
1221         /* FIXME use LDLM_FL_TEST_LOCK instead */
1222         flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1223         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1224                             LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1225                 ldlm_lock_decref(&lockh, LCK_PR);
1226                 RETURN(1);
1227         }
1228
1229         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1230                             LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1231                 ldlm_lock_decref(&lockh, LCK_PW);
1232                 RETURN(1);
1233         }
1234         RETURN(0);
1235 }
1236 static int mdc_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
1237                                   char *name, int len, struct ll_fid *cfid,
1238                                   ldlm_iterator_t it, void *data)
1239 {
1240         int rc;
1241         rc = mdc_change_cbdata(exp, cfid, it, data);
1242         RETURN(rc);
1243 }
1244
1245 struct obd_ops mdc_obd_ops = {
1246         .o_owner         = THIS_MODULE,
1247         .o_attach        = mdc_attach,
1248         .o_detach        = mdc_detach,
1249         .o_setup         = mdc_setup,
1250         .o_precleanup    = mdc_precleanup,
1251         .o_cleanup       = mdc_cleanup,
1252         .o_connect       = client_connect_import,
1253         .o_disconnect    = client_disconnect_export,
1254         .o_iocontrol     = mdc_iocontrol,
1255         .o_set_info      = mdc_set_info,
1256         .o_statfs        = mdc_statfs,
1257         .o_pin           = mdc_pin,
1258         .o_unpin         = mdc_unpin,
1259         .o_import_event  = mdc_import_event,
1260         .o_llog_init     = mdc_llog_init,
1261         .o_llog_finish   = mdc_llog_finish,
1262         .o_create        = mdc_obj_create,
1263         .o_set_info      = mdc_set_info,
1264         .o_get_info      = mdc_get_info,
1265         .o_brw           = mdc_brw,
1266         .o_init_ea_size  = mdc_init_ea_size,
1267 };
1268
1269 struct md_ops mdc_md_ops = {
1270         .m_getstatus     = mdc_getstatus,
1271         .m_getattr       = mdc_getattr,
1272         .m_change_cbdata = mdc_change_cbdata,
1273         .m_close         = mdc_close,
1274         .m_create        = mdc_create,
1275         .m_done_writing  = mdc_done_writing,
1276         .m_enqueue       = mdc_enqueue,
1277         .m_getattr_name  = mdc_getattr_name,
1278         .m_intent_lock   = mdc_intent_lock,
1279         .m_link          = mdc_link,
1280         .m_rename        = mdc_rename,
1281         .m_setattr       = mdc_setattr,
1282         .m_sync          = mdc_sync,
1283         .m_readpage      = mdc_readpage,
1284         .m_unlink        = mdc_unlink,
1285         .m_valid_attrs   = mdc_valid_attrs,
1286         .m_req2lustre_md = mdc_req2lustre_md,
1287         .m_set_open_replay_data   = mdc_set_open_replay_data,
1288         .m_clear_open_replay_data = mdc_clear_open_replay_data,
1289         .m_store_inode_generation = mdc_store_inode_generation,
1290         .m_set_lock_data = mdc_set_lock_data,
1291         .m_get_real_obd  = mdc_get_real_obd,
1292         .m_change_cbdata_name = mdc_change_cbdata_name,
1293         .m_change_cbdata = mdc_change_cbdata,
1294 };
1295
1296 int __init mdc_init(void)
1297 {
1298         struct lprocfs_static_vars lvars;
1299         lprocfs_init_vars(mdc, &lvars);
1300         return class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1301                                    LUSTRE_MDC_NAME);
1302 }
1303
1304 #ifdef __KERNEL__
1305 static void /*__exit*/ mdc_exit(void)
1306 {
1307         class_unregister_type(LUSTRE_MDC_NAME);
1308 }
1309
1310 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1311 MODULE_DESCRIPTION("Lustre Metadata Client");
1312 MODULE_LICENSE("GPL");
1313
1314 EXPORT_SYMBOL(mdc_req2lustre_md);
1315 EXPORT_SYMBOL(mdc_change_cbdata);
1316 EXPORT_SYMBOL(mdc_getstatus);
1317 EXPORT_SYMBOL(mdc_getattr);
1318 EXPORT_SYMBOL(mdc_getattr_name);
1319 EXPORT_SYMBOL(mdc_create);
1320 EXPORT_SYMBOL(mdc_unlink);
1321 EXPORT_SYMBOL(mdc_rename);
1322 EXPORT_SYMBOL(mdc_link);
1323 EXPORT_SYMBOL(mdc_readpage);
1324 EXPORT_SYMBOL(mdc_setattr);
1325 EXPORT_SYMBOL(mdc_close);
1326 EXPORT_SYMBOL(mdc_done_writing);
1327 EXPORT_SYMBOL(mdc_sync);
1328 EXPORT_SYMBOL(mdc_set_open_replay_data);
1329 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1330 EXPORT_SYMBOL(mdc_store_inode_generation);
1331
1332 module_init(mdc_init);
1333 module_exit(mdc_exit);
1334 #endif