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