Whamcloud - gitweb
b58bdcf937c54a0c18988378643782a7c62862fe
[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-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  */
24
25 #ifndef EXPORT_SYMTAB
26 # define EXPORT_SYMTAB
27 #endif
28 #define DEBUG_SUBSYSTEM S_MDC
29
30 #ifdef __KERNEL__
31 # include <linux/module.h>
32 # include <linux/pagemap.h>
33 # include <linux/miscdevice.h>
34 # include <linux/init.h>
35 #else
36 # include <liblustre.h>
37 #endif
38
39 #include <linux/lustre_acl.h>
40 #include <obd_class.h>
41 #include <lustre_dlm.h>
42 #include <lustre_fid.h>
43 #include <md_object.h>
44 #include <lprocfs_status.h>
45 #include <lustre_param.h>
46 #include "mdc_internal.h"
47
48 static quota_interface_t *quota_interface;
49
50 #define REQUEST_MINOR 244
51
52 static quota_interface_t *quota_interface;
53 extern quota_interface_t mdc_quota_interface;
54
55 static int mdc_cleanup(struct obd_device *obd);
56
57 static struct obd_capa *mdc_unpack_capa(struct ptlrpc_request *req,
58                                         const struct req_msg_field *field)
59 {
60         struct lustre_capa *capa;
61         struct obd_capa *oc;
62
63         /* swabbed already in mdc_enqueue */
64         capa = req_capsule_server_get(&req->rq_pill, field);
65         if (capa == NULL)
66                 return ERR_PTR(-EPROTO);
67
68         oc = alloc_capa(CAPA_SITE_CLIENT);
69         if (!oc) {
70                 CDEBUG(D_INFO, "alloc capa failed!\n");
71                 return ERR_PTR(-ENOMEM);
72         }
73         oc->c_capa = *capa;
74
75         return oc;
76 }
77
78 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
79 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
80 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
81                           struct obd_capa **pc, int level, int msg_flags)
82 {
83         struct ptlrpc_request *req;
84         struct mdt_body       *body;
85         int                    rc;
86         ENTRY;
87
88         req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
89                                         LUSTRE_MDS_VERSION, MDS_GETSTATUS);
90         if (req == NULL)
91                 RETURN(-ENOMEM);
92
93         mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
94         lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
95         req->rq_send_state = level;
96
97         ptlrpc_request_set_replen(req);
98
99         rc = ptlrpc_queue_wait(req);
100         if (rc)
101                 GOTO(out, rc);
102
103         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
104         if (body == NULL)
105                 GOTO(out, rc = -EPROTO);
106
107         if (body->valid & OBD_MD_FLMDSCAPA) {
108                 struct obd_capa *oc;
109
110                 oc = mdc_unpack_capa(req, &RMF_CAPA1);
111                 if (IS_ERR(oc))
112                         GOTO(out, rc = PTR_ERR(oc));
113                 *pc = oc;
114         }
115
116         *rootfid = body->fid1;
117         CDEBUG(D_NET,
118                "root fid="DFID", last_committed="LPU64", last_xid="LPU64"\n",
119                PFID(rootfid),
120                lustre_msg_get_last_committed(req->rq_repmsg),
121                lustre_msg_get_last_xid(req->rq_repmsg));
122         EXIT;
123 out:
124         ptlrpc_req_finished(req);
125         return rc;
126 }
127
128 /* This should be mdc_get_info("rootfid") */
129 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
130                   struct obd_capa **pc)
131 {
132         return send_getstatus(class_exp2cliimp(exp), rootfid, pc, 
133                               LUSTRE_IMP_FULL, 0);
134 }
135
136 /*
137  * This function now is known to always saying that it will receive 4 buffers
138  * from server. Even for cases when acl_size and md_size is zero, RPC header
139  * willcontain 4 fields and RPC itself will contain zero size fields. This is
140  * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
141  * and thus zero, it shirinks it, making zero size. The same story about
142  * md_size. And this is course of problem when client waits for smaller number
143  * of fields. This issue will be fixed later when client gets awar of RPC
144  * layouts.  --umka
145  */
146 static int mdc_getattr_common(struct obd_export *exp,
147                               struct ptlrpc_request *req)
148 {
149         struct req_capsule *pill = &req->rq_pill;
150         struct mdt_body    *body;
151         void               *eadata;
152         int                 rc;
153         ENTRY;
154
155         /* Request message already built. */
156         rc = ptlrpc_queue_wait(req);
157         if (rc != 0)
158                 RETURN(rc);
159
160         /* sanity check for the reply */
161         body = req_capsule_server_get(pill, &RMF_MDT_BODY);
162         if (body == NULL)
163                 RETURN(-EPROTO);
164
165         CDEBUG(D_NET, "mode: %o\n", body->mode);
166
167         if (body->eadatasize != 0) {
168                 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
169                                                       body->eadatasize);
170                 if (eadata == NULL)
171                         RETURN(-EPROTO);
172         }
173
174         if (body->valid & OBD_MD_FLMODEASIZE) {
175                 struct client_obd *cli = &exp->exp_obd->u.cli;
176
177                 if (cli->cl_max_mds_easize < body->max_mdsize)
178                         cli->cl_max_mds_easize = body->max_mdsize;
179                 if (cli->cl_max_mds_cookiesize < body->max_cookiesize)
180                         cli->cl_max_mds_cookiesize = body->max_cookiesize;
181         }
182
183         if (body->valid & OBD_MD_FLRMTPERM) {
184                 struct mdt_remote_perm *perm;
185
186                 LASSERT(client_is_remote(exp));
187                 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
188                                                 lustre_swab_mdt_remote_perm);
189                 if (perm == NULL)
190                         RETURN(-EPROTO);
191         }
192
193         if (body->valid & OBD_MD_FLMDSCAPA) {
194                 struct lustre_capa *capa;
195                 capa = req_capsule_server_get(pill, &RMF_CAPA1);
196                 if (capa == NULL)
197                         RETURN(-EPROTO);
198         }
199
200         RETURN(0);
201 }
202
203 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
204                 struct obd_capa *oc, obd_valid valid, int ea_size,
205                 struct ptlrpc_request **request)
206 {
207         struct ptlrpc_request *req;
208         int                    rc;
209         ENTRY;
210
211         *request = NULL;
212         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
213         if (req == NULL)
214                 RETURN(-ENOMEM);
215
216         mdc_set_capa_size(req, &RMF_CAPA1, oc);
217
218         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
219         if (rc) {
220                 ptlrpc_request_free(req);
221                 RETURN(rc);
222         }
223
224         /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
225         mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
226
227         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
228         if (valid & OBD_MD_FLRMTPERM) {
229                 LASSERT(client_is_remote(exp));
230                 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
231                                      sizeof(struct mdt_remote_perm));
232         }
233         ptlrpc_request_set_replen(req);
234
235         rc = mdc_getattr_common(exp, req);
236         if (rc)
237                 ptlrpc_req_finished(req);
238         else
239                 *request = req;
240         RETURN(rc);
241 }
242
243 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
244                      struct obd_capa *oc, const char *filename, int namelen,
245                      obd_valid valid, int ea_size, __u32 suppgid,
246                      struct ptlrpc_request **request)
247 {
248         struct ptlrpc_request *req;
249         int                    rc;
250         ENTRY;
251
252         *request = NULL;
253         req = ptlrpc_request_alloc(class_exp2cliimp(exp),
254                                    &RQF_MDS_GETATTR_NAME);
255         if (req == NULL)
256                 RETURN(-ENOMEM);
257
258         mdc_set_capa_size(req, &RMF_CAPA1, oc);
259         req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
260
261         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
262         if (rc) {
263                 ptlrpc_request_free(req);
264                 RETURN(rc);
265         }
266
267         /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
268         mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
269                       MDS_BFLAG_EXT_FLAGS);
270
271         if (filename) {
272                 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
273                 LASSERT(strnlen(filename, namelen) == namelen - 1);
274                 memcpy(name, filename, namelen);
275         }
276
277         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
278         ptlrpc_request_set_replen(req);
279
280         rc = mdc_getattr_common(exp, req);
281         if (rc)
282                 ptlrpc_req_finished(req);
283         else
284                 *request = req;
285         RETURN(rc);
286 }
287
288 static int mdc_is_subdir(struct obd_export *exp,
289                          const struct lu_fid *pfid,
290                          const struct lu_fid *cfid,
291                          struct ptlrpc_request **request)
292 {
293         struct ptlrpc_request  *req;
294         int                     rc;
295
296         ENTRY;
297
298         *request = NULL;
299         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
300                                         &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
301                                         MDS_IS_SUBDIR);
302         if (req == NULL)
303                 RETURN(-ENOMEM);
304
305         mdc_is_subdir_pack(req, pfid, cfid, 0);
306         ptlrpc_request_set_replen(req);
307
308         rc = ptlrpc_queue_wait(req);
309         if (rc && rc != -EREMOTE)
310                 ptlrpc_req_finished(req);
311         else
312                 *request = req;
313         RETURN(rc);
314 }
315
316 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
317                             const struct lu_fid *fid,
318                             struct obd_capa *oc, int opcode, obd_valid valid,
319                             const char *xattr_name, const char *input,
320                             int input_size, int output_size, int flags,
321                             __u32 suppgid, struct ptlrpc_request **request)
322 {
323         struct ptlrpc_request *req;
324         int   xattr_namelen = 0;
325         char *tmp;
326         int   rc;
327         ENTRY;
328
329         *request = NULL;
330         req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
331         if (req == NULL)
332                 RETURN(-ENOMEM);
333
334         mdc_set_capa_size(req, &RMF_CAPA1, oc);
335         if (xattr_name) {
336                 xattr_namelen = strlen(xattr_name) + 1;
337                 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
338                                      xattr_namelen);
339         }
340         if (input_size) {
341                 LASSERT(input);
342                 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
343                                      input_size);
344         }
345
346         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
347         if (rc) {
348                 ptlrpc_request_free(req);
349                 RETURN(rc);
350         }
351
352         if (opcode == MDS_REINT) {
353                 struct mdt_rec_setxattr *rec;
354
355                 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
356                          sizeof(struct mdt_rec_reint));
357                 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
358                 rec->sx_opcode = REINT_SETXATTR;
359                 /* TODO: 
360                  *  cfs_curproc_fs{u,g}id() should replace 
361                  *  current->fs{u,g}id for portability.
362                  */
363                 rec->sx_fsuid  = current->fsuid;
364                 rec->sx_fsgid  = current->fsgid;
365                 rec->sx_cap    = current->cap_effective;
366                 rec->sx_suppgid1 = suppgid;
367                 rec->sx_suppgid1 = -1;
368                 rec->sx_fid    = *fid;
369                 rec->sx_valid  = valid;
370                 rec->sx_size   = output_size;
371                 rec->sx_flags  = flags;
372
373                 mdc_pack_capa(req, &RMF_CAPA1, oc);
374         } else {
375                 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
376         }
377
378         if (xattr_name) {
379                 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
380                 memcpy(tmp, xattr_name, xattr_namelen);
381         }
382         if (input_size) {
383                 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
384                 memcpy(tmp, input, input_size);
385         }
386
387         if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
388                 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
389                                      RCL_SERVER, output_size);
390         ptlrpc_request_set_replen(req);
391
392         /* make rpc */
393         if (opcode == MDS_REINT)
394                 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
395
396         rc = ptlrpc_queue_wait(req);
397
398         if (opcode == MDS_REINT)
399                 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
400
401         if (rc)
402                 ptlrpc_req_finished(req);
403         else
404                 *request = req;
405         RETURN(rc);
406 }
407
408 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
409                  struct obd_capa *oc, obd_valid valid, const char *xattr_name,
410                  const char *input, int input_size, int output_size,
411                  int flags, __u32 suppgid, struct ptlrpc_request **request)
412 {
413         return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR, 
414                                 fid, oc, MDS_REINT, valid, xattr_name,
415                                 input, input_size, output_size, flags,
416                                 suppgid, request);
417 }
418
419 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
420                  struct obd_capa *oc, obd_valid valid, const char *xattr_name,
421                  const char *input, int input_size, int output_size,
422                  int flags, struct ptlrpc_request **request)
423 {
424         return mdc_xattr_common(exp, &RQF_MDS_GETXATTR, 
425                                 fid, oc, MDS_GETXATTR, valid, xattr_name,
426                                 input, input_size, output_size, flags,
427                                 -1, request);
428 }
429
430 #ifdef CONFIG_FS_POSIX_ACL
431 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
432 {
433         struct req_capsule     *pill = &req->rq_pill;
434         struct mdt_body        *body = md->body;
435         struct posix_acl       *acl;
436         void                   *buf;
437         int                     rc;
438         ENTRY;
439
440         if (!body->aclsize)
441                 RETURN(0);
442
443         buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
444
445         if (!buf)
446                 RETURN(-EPROTO);
447
448         acl = posix_acl_from_xattr(buf, body->aclsize);
449         if (IS_ERR(acl)) {
450                 rc = PTR_ERR(acl);
451                 CERROR("convert xattr to acl: %d\n", rc);
452                 RETURN(rc);
453         }
454
455         rc = posix_acl_valid(acl);
456         if (rc) {
457                 CERROR("validate acl: %d\n", rc);
458                 posix_acl_release(acl);
459                 RETURN(rc);
460         }
461
462         md->posix_acl = acl;
463         RETURN(0);
464 }
465 #else
466 #define mdc_unpack_acl(req, md) 0
467 #endif
468
469 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
470                       struct obd_export *dt_exp, struct obd_export *md_exp,
471                       struct lustre_md *md)
472 {
473         struct req_capsule *pill = &req->rq_pill;
474         int rc;
475         ENTRY;
476
477         LASSERT(md);
478         memset(md, 0, sizeof(*md));
479
480         md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
481         LASSERT(md->body != NULL);
482
483         if (md->body->valid & OBD_MD_FLEASIZE) {
484                 int lmmsize;
485                 struct lov_mds_md *lmm;
486
487                 if (!S_ISREG(md->body->mode)) {
488                         CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
489                                "regular file, but is not\n");
490                         GOTO(out, rc = -EPROTO);
491                 }
492
493                 if (md->body->eadatasize == 0) {
494                         CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
495                                "but eadatasize 0\n");
496                         GOTO(out, rc = -EPROTO);
497                 }
498                 lmmsize = md->body->eadatasize;
499                 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
500                 if (!lmm)
501                         GOTO(out, rc = -EPROTO);
502
503                 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
504                 if (rc < 0)
505                         GOTO(out, rc);
506
507                 if (rc < sizeof(*md->lsm)) {
508                         CDEBUG(D_INFO, "lsm size too small: "
509                                "rc < sizeof (*md->lsm) (%d < %d)\n",
510                                rc, (int)sizeof(*md->lsm));
511                         GOTO(out, rc = -EPROTO);
512                 }
513
514         } else if (md->body->valid & OBD_MD_FLDIREA) {
515                 int lmvsize;
516                 struct lov_mds_md *lmv;
517
518                 if(!S_ISDIR(md->body->mode)) {
519                         CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
520                                "directory, but is not\n");
521                         GOTO(out, rc = -EPROTO);
522                 }
523
524                 if (md->body->eadatasize == 0) {
525                         CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
526                                "but eadatasize 0\n");
527                         RETURN(-EPROTO);
528                 }
529                 if (md->body->valid & OBD_MD_MEA) {
530                         lmvsize = md->body->eadatasize;
531                         lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
532                                                            lmvsize);
533                         if (!lmv)
534                                 GOTO(out, rc = -EPROTO);
535
536                         rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
537                                           lmvsize);
538                         if (rc < 0)
539                                 GOTO(out, rc);
540
541                         if (rc < sizeof(*md->mea)) {
542                                 CDEBUG(D_INFO, "size too small:  "
543                                        "rc < sizeof(*md->mea) (%d < %d)\n",
544                                         rc, sizeof(*md->mea));
545                                 GOTO(out, rc = -EPROTO);
546                         }
547                 }
548         }
549         rc = 0;
550
551         if (md->body->valid & OBD_MD_FLRMTPERM) {
552                 /* remote permission */
553                 LASSERT(client_is_remote(exp));
554                 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
555                                                 lustre_swab_mdt_remote_perm);
556                 if (!md->remote_perm)
557                         GOTO(out, rc = -EPROTO);
558         }
559         else if (md->body->valid & OBD_MD_FLACL) {
560                 /* for ACL, it's possible that FLACL is set but aclsize is zero.
561                  * only when aclsize != 0 there's an actual segment for ACL 
562                  * in reply buffer. 
563                  */
564                 if (md->body->aclsize) {
565                         rc = mdc_unpack_acl(req, md);
566                         if (rc)
567                                 GOTO(out, rc);
568 #ifdef CONFIG_FS_POSIX_ACL
569                 } else {
570                         md->posix_acl = NULL;
571 #endif
572                 }
573         }
574         if (md->body->valid & OBD_MD_FLMDSCAPA) {
575                 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA1);
576
577                 if (IS_ERR(oc))
578                         GOTO(out, rc = PTR_ERR(oc));
579                 md->mds_capa = oc;
580         }
581
582         if (md->body->valid & OBD_MD_FLOSSCAPA) {
583                 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA2);
584
585                 if (IS_ERR(oc))
586                         GOTO(out, rc = PTR_ERR(oc));
587                 md->oss_capa = oc;
588         }
589
590         EXIT;
591 out:
592         if (rc) {
593                 if (md->oss_capa)
594                         free_capa(md->oss_capa);
595                 if (md->mds_capa)
596                         free_capa(md->mds_capa);
597 #ifdef CONFIG_FS_POSIX_ACL
598                 posix_acl_release(md->posix_acl);
599 #endif
600                 if (md->lsm)
601                         obd_free_memmd(dt_exp, &md->lsm);
602         }
603         return rc;
604 }
605
606 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
607 {
608         ENTRY;
609         RETURN(0);
610 }
611
612 static void mdc_replay_open(struct ptlrpc_request *req)
613 {
614         struct md_open_data *mod = req->rq_cb_data;
615         struct ptlrpc_request *cur, *tmp;
616         struct obd_client_handle *och;
617         struct lustre_handle old;
618         struct mdt_body *body;
619         ENTRY;
620
621         if (mod == NULL) {
622                 DEBUG_REQ(D_ERROR, req,
623                           "Can't properly replay without open data.");
624                 EXIT;
625                 return;
626         }
627
628         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
629         LASSERT(body != NULL);
630
631         och = mod->mod_och;
632         if (och != NULL) {
633                 struct lustre_handle *file_fh;
634
635                 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
636
637                 file_fh = &och->och_fh;
638                 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
639                        file_fh->cookie, body->handle.cookie);
640                 old = *file_fh;
641                 *file_fh = body->handle;
642         }
643         list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list, rq_mod_list) {
644                 int opc = lustre_msg_get_opc(cur->rq_reqmsg);
645                 struct mdt_epoch *epoch = NULL;
646
647                 if (opc == MDS_CLOSE || opc == MDS_DONE_WRITING) {
648                         epoch = req_capsule_client_get(&cur->rq_pill,
649                                                &RMF_MDT_EPOCH);
650                         LASSERT(epoch);
651                         DEBUG_REQ(D_HA, cur, "updating %s body with new fh",
652                                   opc == MDS_CLOSE ? "CLOSE" : "DONE_WRITING");
653                 } else if (opc == MDS_REINT) {
654                         struct mdt_rec_setattr *rec;
655                         
656                         /* Check this is REINT_SETATTR. */
657                         rec = req_capsule_client_get(&cur->rq_pill,
658                                                &RMF_REC_REINT);
659                         LASSERT(rec && rec->sa_opcode == REINT_SETATTR);
660
661                         epoch = req_capsule_client_get(&cur->rq_pill,
662                                                &RMF_MDT_EPOCH);
663                         LASSERT(epoch);
664                         DEBUG_REQ(D_HA, cur, "updating REINT_SETATTR body "
665                                   "with new fh");
666                 }
667                 if (epoch) {
668                         if (och != NULL)
669                                 LASSERT(!memcmp(&old, &epoch->handle,
670                                                 sizeof(old)));
671                         epoch->handle = body->handle;
672                 }
673         }
674         EXIT;
675 }
676
677 void mdc_commit_delayed(struct ptlrpc_request *req)
678 {
679         struct md_open_data *mod = req->rq_cb_data;
680         struct ptlrpc_request *cur, *tmp;
681         
682         DEBUG_REQ(D_HA, req, "req committed");
683
684         if (mod == NULL)
685                 return;
686
687         req->rq_cb_data = NULL;
688         req->rq_commit_cb = NULL;
689         list_del_init(&req->rq_mod_list);
690         if (req->rq_sequence) {
691                 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
692                                          rq_mod_list) {
693                         LASSERT(cur != LP_POISON);
694                         LASSERT(cur->rq_type != LI_POISON);
695                         DEBUG_REQ(D_HA, cur, "req balanced");
696                         LASSERT(cur->rq_transno != 0);
697                         LASSERT(cur->rq_import == req->rq_import);
698
699                         /* We no longer want to preserve this for transno-
700                          * unconditional replay. */
701                         spin_lock(&cur->rq_lock);
702                         cur->rq_replay = 0;
703                         spin_unlock(&cur->rq_lock);
704                 }
705         }
706
707         if (list_empty(&mod->mod_replay_list)) {
708                 if (mod->mod_och != NULL)
709                         mod->mod_och->och_mod = NULL;
710
711                 OBD_FREE_PTR(mod);
712         }
713 }
714
715 int mdc_set_open_replay_data(struct obd_export *exp,
716                              struct obd_client_handle *och,
717                              struct ptlrpc_request *open_req)
718 {
719         struct md_open_data   *mod;
720         struct mdt_rec_create *rec;
721         struct mdt_body       *body;
722         struct obd_import     *imp = open_req->rq_import;
723         ENTRY;
724
725         if (!open_req->rq_replay)
726                 RETURN(0);
727
728         rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
729         body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
730         LASSERT(rec != NULL);
731         /* Incoming message in my byte order (it's been swabbed). */
732         /* Outgoing messages always in my byte order. */
733         LASSERT(body != NULL);
734
735         /* Only if the import is replayable, we set replay_open data */
736         if (och && imp->imp_replayable) {
737                 OBD_ALLOC_PTR(mod);
738                 if (mod == NULL) {
739                         DEBUG_REQ(D_ERROR, open_req,
740                                   "Can't allocate md_open_data");
741                         RETURN(0);
742                 }
743                 CFS_INIT_LIST_HEAD(&mod->mod_replay_list);
744
745                 spin_lock(&open_req->rq_lock);
746                 och->och_mod = mod;
747                 mod->mod_och = och;
748                 open_req->rq_cb_data = mod;
749                 list_add_tail(&open_req->rq_mod_list, &mod->mod_replay_list);
750                 open_req->rq_commit_cb = mdc_commit_delayed;
751                 spin_unlock(&open_req->rq_lock);
752         }
753
754         rec->cr_fid2 = body->fid1;
755         rec->cr_ioepoch = body->ioepoch;
756         rec->cr_old_handle.cookie = body->handle.cookie;
757         open_req->rq_replay_cb = mdc_replay_open;
758         if (!fid_is_sane(&body->fid1)) {
759                 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
760                           "insane fid");
761                 LBUG();
762         }
763
764         DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
765         RETURN(0);
766 }
767
768 int mdc_clear_open_replay_data(struct obd_export *exp,
769                                struct obd_client_handle *och)
770 {
771         struct md_open_data *mod = och->och_mod;
772         ENTRY;
773
774         /*
775          * Don't free the structure now (it happens in mdc_commit_delayed(),
776          * after the last request is removed from its replay list),
777          * but make sure that replay doesn't poke at the och, which is about to
778          * be freed.
779          */
780         LASSERT(mod != LP_POISON);
781         if (mod != NULL)
782                 mod->mod_och = NULL;
783
784         och->och_mod = NULL;
785         RETURN(0);
786 }
787
788 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
789               struct md_open_data *mod, struct ptlrpc_request **request)
790 {
791         struct obd_device     *obd = class_exp2obd(exp);
792         struct ptlrpc_request *req;
793         int                    rc;
794         ENTRY;
795
796         *request = NULL;
797         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
798         if (req == NULL)
799                 RETURN(-ENOMEM);
800
801         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
802
803         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
804         if (rc) {
805                 ptlrpc_request_free(req);
806                 RETURN(rc);
807         }
808
809         /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
810          * portal whose threads are not taking any DLM locks and are therefore
811          * always progressing */
812         /* XXX FIXME bug 249 */
813         req->rq_request_portal = MDS_READPAGE_PORTAL;
814
815         /* Ensure that this close's handle is fixed up during replay. */
816         if (likely(mod != NULL))
817                 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
818         else
819                 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
820
821         mdc_close_pack(req, op_data);
822
823         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
824                              obd->u.cli.cl_max_mds_easize);
825         req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
826                              obd->u.cli.cl_max_mds_cookiesize);
827
828         ptlrpc_request_set_replen(req);
829
830         req->rq_commit_cb = mdc_commit_delayed;
831         req->rq_replay = 1;
832         LASSERT(req->rq_cb_data == NULL);
833         req->rq_cb_data = mod;
834
835         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
836         rc = ptlrpc_queue_wait(req);
837         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
838
839         if (req->rq_repmsg == NULL) {
840                 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
841                        req->rq_status);
842                 if (rc == 0)
843                         rc = req->rq_status ?: -EIO;
844         } else if (rc == 0 || rc == -EAGAIN) {
845                 struct mdt_body *body;
846
847                 rc = lustre_msg_get_status(req->rq_repmsg);
848                 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
849                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
850                                   "= %d", rc);
851                         if (rc > 0)
852                                 rc = -rc;
853                 } else if (mod == NULL) {
854                         if (req->rq_import->imp_replayable) 
855                                 CERROR("Unexpected: can't find md_open_data," 
856                                        "but close succeeded with replayable imp"
857                                        "Please tell CFS.\n");
858                 }
859
860                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
861                 if (body == NULL)
862                         rc = -EPROTO;
863         }
864
865         EXIT;
866         if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
867                 req->rq_commit_cb(req);
868
869         *request = req;
870         return rc;
871 }
872
873 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
874                      struct md_open_data *mod)
875 {
876         struct obd_device     *obd = class_exp2obd(exp);
877         struct ptlrpc_request *req;
878         int                    rc;
879         ENTRY;
880
881         req = ptlrpc_request_alloc(class_exp2cliimp(exp),
882                                    &RQF_MDS_DONE_WRITING);
883         if (req == NULL)
884                 RETURN(-ENOMEM);
885
886         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
887         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
888         if (rc) {
889                 ptlrpc_request_free(req);
890                 RETURN(rc);
891         }
892
893         /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
894          * recovery will be ready. */
895         mdc_close_pack(req, op_data);
896         ptlrpc_request_set_replen(req);
897         req->rq_replay = 1;
898         req->rq_cb_data = mod;
899         req->rq_commit_cb = mdc_commit_delayed;
900         if (likely(mod != NULL))
901                 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
902         else
903                 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
904
905         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
906         rc = ptlrpc_queue_wait(req);
907         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
908
909         /* Close the open replay sequence if an error occured or no SOM
910          * attribute update is needed. */
911         if (rc != -EAGAIN)
912                 ptlrpc_close_replay_seq(req);
913                 
914         if (rc && rc != -EAGAIN && req->rq_commit_cb)
915                 req->rq_commit_cb(req);
916
917         ptlrpc_req_finished(req);
918         RETURN(rc);
919 }
920
921 #ifdef HAVE_SPLIT_SUPPORT
922 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
923                  const struct page *page, int offset)
924 {
925         struct ptlrpc_request   *req;
926         struct ptlrpc_bulk_desc *desc;
927         int                      rc;
928         ENTRY;
929
930         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
931         if (req == NULL)
932                 RETURN(-ENOMEM);
933
934         /* FIXME: capa doesn't support split yet */
935         mdc_set_capa_size(req, &RMF_CAPA1, NULL);
936
937         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
938         if (rc) {
939                 ptlrpc_request_free(req);
940                 RETURN(rc);
941         }
942
943         req->rq_request_portal = MDS_READPAGE_PORTAL;
944
945         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
946         if (desc == NULL)
947                 GOTO(out, rc = -ENOMEM);
948
949         /* NB req now owns desc and will free it when it gets freed. */
950         ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
951         mdc_readdir_pack(req, 0, offset, fid, NULL);
952
953         ptlrpc_request_set_replen(req);
954         rc = ptlrpc_queue_wait(req);
955         GOTO(out, rc);
956 out:
957         ptlrpc_req_finished(req);
958         return rc;
959 }
960 EXPORT_SYMBOL(mdc_sendpage);
961 #endif
962
963 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
964                  struct obd_capa *oc, __u64 offset, struct page *page,
965                  struct ptlrpc_request **request)
966 {
967         struct ptlrpc_request   *req;
968         struct ptlrpc_bulk_desc *desc;
969         int                      rc;
970         ENTRY;
971
972         *request = NULL;
973         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
974         if (req == NULL)
975                 RETURN(-ENOMEM);
976
977         mdc_set_capa_size(req, &RMF_CAPA1, oc);
978
979         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
980         if (rc) {
981                 ptlrpc_request_free(req);
982                 RETURN(rc);
983         }
984
985         /* XXX FIXME bug 249 */
986         req->rq_request_portal = MDS_READPAGE_PORTAL;
987         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
988         if (desc == NULL) {
989                 ptlrpc_request_free(req);
990                 RETURN(-ENOMEM);
991         }
992
993         /* NB req now owns desc and will free it when it gets freed */
994         ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
995         mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
996
997         ptlrpc_request_set_replen(req);
998         rc = ptlrpc_queue_wait(req);
999         if (rc) {
1000                 ptlrpc_req_finished(req);
1001                 RETURN(rc);
1002         }
1003
1004         if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
1005                 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1006                         req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
1007                 ptlrpc_req_finished(req);
1008                 RETURN(-EPROTO);
1009         }
1010
1011         *request = req;
1012         RETURN(0);
1013 }
1014
1015 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1016                          void *karg, void *uarg)
1017 {
1018         struct obd_device *obd = exp->exp_obd;
1019         struct obd_ioctl_data *data = karg;
1020         struct obd_import *imp = obd->u.cli.cl_import;
1021         struct llog_ctxt *ctxt;
1022         int rc;
1023         ENTRY;
1024
1025         if (!try_module_get(THIS_MODULE)) {
1026                 CERROR("Can't get module. Is it alive?");
1027                 return -EINVAL;
1028         }
1029         switch (cmd) {
1030         case OBD_IOC_CLIENT_RECOVER:
1031                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1032                 if (rc < 0)
1033                         GOTO(out, rc);
1034                 GOTO(out, rc = 0);
1035         case IOC_OSC_SET_ACTIVE:
1036                 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1037                 GOTO(out, rc);
1038         case OBD_IOC_PARSE: {
1039                 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1040                 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1041                 llog_ctxt_put(ctxt);
1042                 GOTO(out, rc);
1043         }
1044 #ifdef __KERNEL__
1045         case OBD_IOC_LLOG_INFO:
1046         case OBD_IOC_LLOG_PRINT: {
1047                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1048                 rc = llog_ioctl(ctxt, cmd, data);
1049                 llog_ctxt_put(ctxt);
1050                 GOTO(out, rc);
1051         }
1052 #endif
1053         case OBD_IOC_POLL_QUOTACHECK:
1054                 rc = lquota_poll_check(quota_interface, exp,
1055                                        (struct if_quotacheck *)karg);
1056                 GOTO(out, rc);
1057         default:
1058                 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1059                 GOTO(out, rc = -ENOTTY);
1060         }
1061 out:
1062         module_put(THIS_MODULE);
1063
1064         return rc;
1065 }
1066
1067 static int do_set_info_async(struct obd_export *exp,
1068                              obd_count keylen, void *key,
1069                              obd_count vallen, void *val,
1070                              struct ptlrpc_request_set *set)
1071 {
1072         struct obd_import     *imp = class_exp2cliimp(exp);
1073         struct ptlrpc_request *req;
1074         char                  *tmp;
1075         int                    rc;
1076         ENTRY;
1077
1078         if (vallen != sizeof(int))
1079                 RETURN(-EINVAL);
1080
1081         spin_lock(&imp->imp_lock);
1082         if (*((int *)val)) {
1083                 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1084                 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1085         } else {
1086                 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1087                 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1088         }
1089         spin_unlock(&imp->imp_lock);
1090
1091         req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1092         if (req == NULL)
1093                 RETURN(-ENOMEM);
1094
1095         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1096                              RCL_CLIENT, keylen);
1097         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1098                              RCL_CLIENT, vallen);
1099         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1100         if (rc) {
1101                 ptlrpc_request_free(req);
1102                 RETURN(rc);
1103         }
1104
1105         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1106         memcpy(tmp, key, keylen);
1107         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1108         memcpy(tmp, val, vallen);
1109
1110         ptlrpc_request_set_replen(req);
1111
1112         if (set) {
1113                 ptlrpc_set_add_req(set, req);
1114                 ptlrpc_check_set(set);
1115         } else {
1116                 rc = ptlrpc_queue_wait(req);
1117                 ptlrpc_req_finished(req);
1118         }
1119
1120         RETURN(rc);
1121 }
1122
1123 int mdc_set_info_async(struct obd_export *exp,
1124                        obd_count keylen, void *key,
1125                        obd_count vallen, void *val,
1126                        struct ptlrpc_request_set *set)
1127 {
1128         struct obd_import *imp = class_exp2cliimp(exp);
1129         int                rc = -EINVAL;
1130         ENTRY;
1131
1132         if (KEY_IS(KEY_INIT_RECOV)) {
1133                 if (vallen != sizeof(int))
1134                         RETURN(-EINVAL);
1135                 spin_lock(&imp->imp_lock);
1136                 imp->imp_initial_recov = *(int *)val;
1137                 spin_unlock(&imp->imp_lock);
1138                 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1139                        exp->exp_obd->obd_name, imp->imp_initial_recov);
1140                 RETURN(0);
1141         }
1142         /* Turn off initial_recov after we try all backup servers once */
1143         if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1144                 if (vallen != sizeof(int))
1145                         RETURN(-EINVAL);
1146                 spin_lock(&imp->imp_lock);
1147                 imp->imp_initial_recov_bk = *(int *)val;
1148                 if (imp->imp_initial_recov_bk)
1149                         imp->imp_initial_recov = 1;
1150                 spin_unlock(&imp->imp_lock);
1151                 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1152                        exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1153                 RETURN(0);
1154         }
1155         if (KEY_IS(KEY_READ_ONLY)) {
1156                 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1157                 RETURN(rc);
1158         }
1159         if (KEY_IS(KEY_FLUSH_CTX)) {
1160                 sptlrpc_import_flush_my_ctx(imp);
1161                 RETURN(0);
1162         }
1163         if (KEY_IS(KEY_MDS_CONN)) {
1164                 struct obd_import *imp = class_exp2cliimp(exp);
1165                 
1166                 /* mds-mds import */
1167                 spin_lock(&imp->imp_lock);
1168                 imp->imp_server_timeout = 1;
1169                 spin_unlock(&imp->imp_lock);
1170                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1171                 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1172                 RETURN(0);
1173         }
1174
1175         RETURN(rc);
1176 }
1177
1178 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1179                  __u32 *vallen, void *val)
1180 {
1181         int rc = -EINVAL;
1182
1183         if (KEY_IS(KEY_MAX_EASIZE)) {
1184                 int mdsize, *max_easize;
1185
1186                 if (*vallen != sizeof(int))
1187                         RETURN(-EINVAL);
1188                 mdsize = *(int*)val;
1189                 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1190                         exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1191                 max_easize = val;
1192                 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1193                 RETURN(0);
1194         }
1195         if (KEY_IS(KEY_CONN_DATA)) {
1196                 struct obd_import *imp = class_exp2cliimp(exp);
1197                 struct obd_connect_data *data = val;
1198
1199                 if (*vallen != sizeof(*data))
1200                         RETURN(-EINVAL);
1201
1202                 *data = imp->imp_connect_data;
1203                 RETURN(0);
1204         }
1205                 
1206         RETURN(rc);
1207 }
1208
1209 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1210                       __u64 max_age, __u32 flags)
1211 {
1212         struct ptlrpc_request *req;
1213         struct obd_statfs     *msfs;
1214         int                    rc;
1215         ENTRY;
1216
1217         req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_MDS_STATFS,
1218                                         LUSTRE_MDS_VERSION, MDS_STATFS);
1219         if (req == NULL)
1220                 RETURN(-ENOMEM);
1221
1222         ptlrpc_request_set_replen(req);
1223
1224         if (flags & OBD_STATFS_NODELAY) {
1225                 /* procfs requests not want stay in wait for avoid deadlock */
1226                 req->rq_no_resend = 1;
1227                 req->rq_no_delay = 1;
1228         }
1229
1230         rc = ptlrpc_queue_wait(req);
1231         if (rc) {
1232                 /* check connection error first */
1233                 if (obd->u.cli.cl_import->imp_connect_error)
1234                         rc = obd->u.cli.cl_import->imp_connect_error;
1235                 GOTO(out, rc);
1236         }
1237
1238         msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1239         if (msfs == NULL)
1240                 GOTO(out, rc = -EPROTO);
1241
1242         *osfs = *msfs;
1243         EXIT;
1244 out:
1245         ptlrpc_req_finished(req);
1246         return rc;
1247 }
1248
1249 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1250                    struct obd_capa *oc, struct obd_client_handle *handle,
1251                    int flags)
1252 {
1253         struct ptlrpc_request *req;
1254         struct mdt_body       *body;
1255         int                    rc;
1256         ENTRY;
1257
1258         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1259         if (req == NULL)
1260                 RETURN(-ENOMEM);
1261
1262         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1263
1264         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1265         if (rc) {
1266                 ptlrpc_request_free(req);
1267                 RETURN(rc);
1268         }
1269
1270         mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1271
1272         ptlrpc_request_set_replen(req);
1273
1274         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1275         rc = ptlrpc_queue_wait(req);
1276         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1277         if (rc) {
1278                 CERROR("Pin failed: %d\n", rc);
1279                 GOTO(err_out, rc);
1280         }
1281
1282         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1283         if (body == NULL)
1284                 GOTO(err_out, rc = -EPROTO);
1285
1286         handle->och_fh = body->handle;
1287         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1288
1289         OBD_ALLOC_PTR(handle->och_mod);
1290         if (handle->och_mod == NULL) {
1291                 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1292                 GOTO(err_out, rc = -ENOMEM);
1293         }
1294         /* will be dropped by unpin */
1295         CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1296         list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1297
1298         RETURN(0);
1299
1300 err_out:
1301         ptlrpc_req_finished(req);
1302         RETURN(rc);
1303 }
1304
1305 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1306                      int flag)
1307 {
1308         struct ptlrpc_request *req;
1309         struct mdt_body       *body;
1310         int                    rc;
1311         ENTRY;
1312
1313         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1314                                         LUSTRE_MDS_VERSION, MDS_UNPIN);
1315         if (req == NULL)
1316                 RETURN(-ENOMEM);
1317
1318         body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1319         body->handle = handle->och_fh;
1320         body->flags = flag;
1321
1322         ptlrpc_request_set_replen(req);
1323
1324         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1325         rc = ptlrpc_queue_wait(req);
1326         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1327
1328         if (rc != 0)
1329                 CERROR("Unpin failed: %d\n", rc);
1330
1331         ptlrpc_req_finished(req);
1332
1333         LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1334         req = list_entry(handle->och_mod->mod_replay_list.next,
1335                          typeof(*req), rq_mod_list);
1336         list_del_init(&req->rq_mod_list);
1337         ptlrpc_req_finished(req);
1338         LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1339
1340         OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1341         RETURN(rc);
1342 }
1343
1344 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1345              struct obd_capa *oc, struct ptlrpc_request **request)
1346 {
1347         struct ptlrpc_request *req;
1348         int                    rc;
1349         ENTRY;
1350
1351         *request = NULL;
1352         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1353         if (req == NULL)
1354                 RETURN(-ENOMEM);
1355
1356         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1357
1358         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1359         if (rc) {
1360                 ptlrpc_request_free(req);
1361                 RETURN(rc);
1362         }
1363
1364         mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1365
1366         ptlrpc_request_set_replen(req);
1367
1368         rc = ptlrpc_queue_wait(req);
1369         if (rc)
1370                 ptlrpc_req_finished(req);
1371         else
1372                 *request = req;
1373         RETURN(rc);
1374 }
1375
1376 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1377                             enum obd_import_event event)
1378 {
1379         int rc = 0;
1380
1381         LASSERT(imp->imp_obd == obd);
1382
1383         switch (event) {
1384         case IMP_EVENT_DISCON: {
1385 #if 0
1386                 /* XXX Pass event up to OBDs stack. used only for FLD now */
1387                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1388 #endif
1389                 break;
1390         }
1391         case IMP_EVENT_INACTIVE: {
1392                 struct client_obd *cli = &obd->u.cli;
1393                 /* 
1394                  * Flush current sequence to make client obtain new one
1395                  * from server in case of disconnect/reconnect.
1396                  * If range is already empty then no need to flush it.
1397                  */
1398                 if (cli->cl_seq != NULL && 
1399                     !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1400                         seq_client_flush(cli->cl_seq);
1401                 }
1402
1403                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1404                 break;
1405         }
1406         case IMP_EVENT_INVALIDATE: {
1407                 struct ldlm_namespace *ns = obd->obd_namespace;
1408
1409                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1410
1411                 break;
1412         }
1413         case IMP_EVENT_ACTIVE: {
1414                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1415                 break;
1416         }
1417         case IMP_EVENT_OCD:
1418                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1419                 break;
1420
1421         default:
1422                 CERROR("Unknown import event %x\n", event);
1423                 LBUG();
1424         }
1425         RETURN(rc);
1426 }
1427
1428 static int mdc_fid_init(struct obd_export *exp)
1429 {
1430         struct client_obd *cli = &exp->exp_obd->u.cli;
1431         char *prefix;
1432         int rc;
1433         ENTRY;
1434
1435         OBD_ALLOC_PTR(cli->cl_seq);
1436         if (cli->cl_seq == NULL)
1437                 RETURN(-ENOMEM);
1438
1439         OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1440         if (prefix == NULL)
1441                 GOTO(out_free_seq, rc = -ENOMEM);
1442
1443         snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1444                  exp->exp_obd->obd_name);
1445
1446         /* Init client side sequence-manager */
1447         rc = seq_client_init(cli->cl_seq, exp, 
1448                              LUSTRE_SEQ_METADATA,
1449                              prefix, NULL);
1450         OBD_FREE(prefix, MAX_OBD_NAME + 5);
1451         if (rc)
1452                 GOTO(out_free_seq, rc);
1453
1454         RETURN(rc);
1455 out_free_seq:
1456         OBD_FREE_PTR(cli->cl_seq);
1457         cli->cl_seq = NULL;
1458         return rc;
1459 }
1460
1461 static int mdc_fid_fini(struct obd_export *exp)
1462 {
1463         struct client_obd *cli = &exp->exp_obd->u.cli;
1464         ENTRY;
1465
1466         if (cli->cl_seq != NULL) {
1467                 seq_client_fini(cli->cl_seq);
1468                 OBD_FREE_PTR(cli->cl_seq);
1469                 cli->cl_seq = NULL;
1470         }
1471         
1472         RETURN(0);
1473 }
1474
1475 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1476                   struct md_op_data *op_data)
1477 {
1478         struct client_obd *cli = &exp->exp_obd->u.cli;
1479         struct lu_client_seq *seq = cli->cl_seq;
1480         ENTRY;
1481         RETURN(seq_client_alloc_fid(seq, fid));
1482 }
1483
1484 /* XXX This method is used only to clear current fid seq
1485  * once fld/mds insert failed */
1486 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1487 {
1488         struct client_obd *cli = &exp->exp_obd->u.cli;
1489         
1490         seq_client_flush(cli->cl_seq);
1491         return 0;
1492 }
1493
1494 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1495 {
1496         struct client_obd *cli = &obd->u.cli;
1497         struct lprocfs_static_vars lvars = { 0 };
1498         int rc;
1499         ENTRY;
1500
1501         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1502         if (!cli->cl_rpc_lock)
1503                 RETURN(-ENOMEM);
1504         mdc_init_rpc_lock(cli->cl_rpc_lock);
1505
1506         ptlrpcd_addref();
1507
1508         OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1509         if (!cli->cl_setattr_lock)
1510                 GOTO(err_rpc_lock, rc = -ENOMEM);
1511         mdc_init_rpc_lock(cli->cl_setattr_lock);
1512
1513         OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1514         if (!cli->cl_close_lock)
1515                 GOTO(err_setattr_lock, rc = -ENOMEM);
1516         mdc_init_rpc_lock(cli->cl_close_lock);
1517
1518         rc = client_obd_setup(obd, cfg);
1519         if (rc)
1520                 GOTO(err_close_lock, rc);
1521         lprocfs_mdc_init_vars(&lvars);
1522         lprocfs_obd_setup(obd, lvars.obd_vars);
1523         sptlrpc_lprocfs_cliobd_attach(obd);
1524         ptlrpc_lprocfs_register_obd(obd);
1525
1526         rc = obd_llog_init(obd, OBD_LLOG_GROUP, obd, 0, NULL, NULL);
1527         if (rc) {
1528                 mdc_cleanup(obd);
1529                 CERROR("failed to setup llogging subsystems\n");
1530         }
1531
1532         RETURN(rc);
1533
1534 err_close_lock:
1535         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1536 err_setattr_lock:
1537         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1538 err_rpc_lock:
1539         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1540         ptlrpcd_decref();
1541         RETURN(rc);
1542 }
1543
1544 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
1545  * us to make MDS RPCs with large enough reply buffers to hold the
1546  * maximum-sized (= maximum striped) EA and cookie without having to
1547  * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1548 static int mdc_init_ea_size(struct obd_export *exp, int easize,
1549                      int def_easize, int cookiesize)
1550 {
1551         struct obd_device *obd = exp->exp_obd;
1552         struct client_obd *cli = &obd->u.cli;
1553         ENTRY;
1554
1555         if (cli->cl_max_mds_easize < easize)
1556                 cli->cl_max_mds_easize = easize;
1557
1558         if (cli->cl_default_mds_easize < def_easize)
1559                 cli->cl_default_mds_easize = def_easize;
1560
1561         if (cli->cl_max_mds_cookiesize < cookiesize)
1562                 cli->cl_max_mds_cookiesize = cookiesize;
1563
1564         RETURN(0);
1565 }
1566
1567 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1568 {
1569         int rc = 0;
1570         ENTRY;
1571
1572         switch (stage) {
1573         case OBD_CLEANUP_EARLY:
1574         case OBD_CLEANUP_EXPORTS:
1575                 /* If we set up but never connected, the
1576                    client import will not have been cleaned. */
1577                 if (obd->u.cli.cl_import) {
1578                         struct obd_import *imp;
1579                         imp = obd->u.cli.cl_import;
1580                         CERROR("client import never connected\n");
1581                         ptlrpc_invalidate_import(imp);
1582                         ptlrpc_free_rq_pool(imp->imp_rq_pool);
1583                         class_destroy_import(imp);
1584                         obd->u.cli.cl_import = NULL;
1585                 }
1586                 break;
1587         case OBD_CLEANUP_SELF_EXP:
1588                 rc = obd_llog_finish(obd, 0);
1589                 if (rc != 0)
1590                         CERROR("failed to cleanup llogging subsystems\n");
1591         case OBD_CLEANUP_OBD:
1592                 break;
1593         }
1594         RETURN(rc);
1595 }
1596
1597 static int mdc_cleanup(struct obd_device *obd)
1598 {
1599         struct client_obd *cli = &obd->u.cli;
1600
1601         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1602         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1603         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1604
1605         ptlrpc_lprocfs_unregister_obd(obd);
1606         lprocfs_obd_cleanup(obd);
1607         ptlrpcd_decref();
1608
1609         return client_obd_cleanup(obd);
1610 }
1611
1612
1613 static int mdc_llog_init(struct obd_device *obd, int group,
1614                          struct obd_device *tgt, int count,
1615                          struct llog_catid *logid, struct obd_uuid *uuid)
1616 {
1617         struct llog_ctxt *ctxt;
1618         struct obd_llog_group *olg = &obd->obd_olg;
1619         int rc;
1620         ENTRY;
1621
1622         LASSERT(group == OBD_LLOG_GROUP);
1623         LASSERT(olg->olg_group == group);
1624
1625         rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0,
1626                         NULL, &llog_client_ops);
1627         if (rc == 0) {
1628                 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1629                 llog_initiator_connect(ctxt);
1630                 llog_ctxt_put(ctxt);
1631         }
1632
1633         RETURN(rc);
1634 }
1635
1636 static int mdc_llog_finish(struct obd_device *obd, int count)
1637 {
1638         struct llog_ctxt *ctxt;
1639         int rc = 0;
1640         ENTRY;
1641
1642         ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1643         if (ctxt)
1644                 rc = llog_cleanup(ctxt);
1645
1646         RETURN(rc);
1647 }
1648
1649 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1650 {
1651         struct lustre_cfg *lcfg = buf;
1652         struct lprocfs_static_vars lvars = { 0 };
1653         int rc = 0;
1654
1655         lprocfs_mdc_init_vars(&lvars);
1656
1657         switch (lcfg->lcfg_command) {
1658         case LCFG_SPTLRPC_CONF:
1659                 rc = sptlrpc_cliobd_process_config(obd, lcfg);
1660                 break;
1661         default:
1662                 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1663                                               lcfg, obd);
1664                 break;
1665         }
1666         return(rc);
1667 }
1668
1669
1670 /* get remote permission for current user on fid */
1671 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1672                         struct obd_capa *oc, __u32 suppgid,
1673                         struct ptlrpc_request **request)
1674 {
1675         struct ptlrpc_request  *req;
1676         int                    rc;
1677         ENTRY;
1678
1679         LASSERT(client_is_remote(exp));
1680
1681         *request = NULL;
1682         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1683         if (req == NULL)
1684                 RETURN(-ENOMEM);
1685
1686         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1687
1688         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1689         if (rc) {
1690                 ptlrpc_request_free(req);
1691                 RETURN(rc);
1692         }
1693
1694         mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1695
1696         req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
1697                              sizeof(struct mdt_remote_perm));
1698
1699         ptlrpc_request_set_replen(req);
1700
1701         rc = ptlrpc_queue_wait(req);
1702         if (rc)
1703                 ptlrpc_req_finished(req);
1704         else
1705                 *request = req;
1706         RETURN(rc);
1707 }
1708
1709 static int mdc_interpret_renew_capa(struct ptlrpc_request *req, void *unused,
1710                                     int status)
1711 {
1712         struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1713         renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1714         struct mdt_body *body = NULL;
1715         struct lustre_capa *capa;
1716         ENTRY;
1717
1718         if (status)
1719                 GOTO(out, capa = ERR_PTR(status));
1720
1721         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1722         if (body == NULL)
1723                 GOTO(out, capa = ERR_PTR(-EFAULT));
1724
1725         if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1726                 GOTO(out, capa = ERR_PTR(-ENOENT));
1727
1728         capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1729         if (!capa)
1730                 GOTO(out, capa = ERR_PTR(-EFAULT));
1731         EXIT;
1732 out:
1733         cb(oc, capa);
1734         return 0;
1735 }
1736
1737 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1738                           renew_capa_cb_t cb)
1739 {
1740         struct ptlrpc_request *req;
1741         ENTRY;
1742
1743         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1744                                         LUSTRE_MDS_VERSION, MDS_GETATTR);
1745         if (req == NULL)
1746                 RETURN(-ENOMEM);
1747
1748         /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1749          * capa to renew is oss capa.
1750          */
1751         mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1752         ptlrpc_request_set_replen(req);
1753
1754         req->rq_async_args.pointer_arg[0] = oc;
1755         req->rq_async_args.pointer_arg[1] = cb;
1756         req->rq_interpret_reply = mdc_interpret_renew_capa;
1757         ptlrpcd_add_req(req);
1758         RETURN(0);
1759 }
1760
1761 static int mdc_connect(const struct lu_env *env,
1762                        struct lustre_handle *dlm_handle,
1763                        struct obd_device *obd, struct obd_uuid *cluuid,
1764                        struct obd_connect_data *data,
1765                        void *localdata)
1766 {
1767         struct obd_import *imp = obd->u.cli.cl_import;
1768
1769         /* mds-mds import features */
1770         if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1771                 spin_lock(&imp->imp_lock);
1772                 imp->imp_server_timeout = 1;
1773                 spin_unlock(&imp->imp_lock);
1774                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1775                 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1776                        obd->obd_name);
1777         }
1778
1779         return client_connect_import(env, dlm_handle, obd, cluuid, data, NULL);
1780 }
1781
1782 struct obd_ops mdc_obd_ops = {
1783         .o_owner            = THIS_MODULE,
1784         .o_setup            = mdc_setup,
1785         .o_precleanup       = mdc_precleanup,
1786         .o_cleanup          = mdc_cleanup,
1787         .o_add_conn         = client_import_add_conn,
1788         .o_del_conn         = client_import_del_conn,
1789         .o_connect          = mdc_connect,
1790         .o_disconnect       = client_disconnect_export,
1791         .o_iocontrol        = mdc_iocontrol,
1792         .o_set_info_async   = mdc_set_info_async,
1793         .o_statfs           = mdc_statfs,
1794         .o_pin              = mdc_pin,
1795         .o_unpin            = mdc_unpin,
1796         .o_fid_init         = mdc_fid_init,
1797         .o_fid_fini         = mdc_fid_fini,
1798         .o_fid_alloc        = mdc_fid_alloc,
1799         .o_fid_delete       = mdc_fid_delete,
1800         .o_import_event     = mdc_import_event,
1801         .o_llog_init        = mdc_llog_init,
1802         .o_llog_finish      = mdc_llog_finish,
1803         .o_get_info         = mdc_get_info,
1804         .o_process_config  = mdc_process_config,
1805 };
1806
1807 struct md_ops mdc_md_ops = {
1808         .m_getstatus        = mdc_getstatus,
1809         .m_change_cbdata    = mdc_change_cbdata,
1810         .m_close            = mdc_close,
1811         .m_create           = mdc_create,
1812         .m_done_writing     = mdc_done_writing,
1813         .m_enqueue          = mdc_enqueue,
1814         .m_getattr          = mdc_getattr,
1815         .m_getattr_name     = mdc_getattr_name,
1816         .m_intent_lock      = mdc_intent_lock,
1817         .m_link             = mdc_link,
1818         .m_is_subdir        = mdc_is_subdir,
1819         .m_rename           = mdc_rename,
1820         .m_setattr          = mdc_setattr,
1821         .m_setxattr         = mdc_setxattr,
1822         .m_getxattr         = mdc_getxattr,
1823         .m_sync             = mdc_sync,
1824         .m_readpage         = mdc_readpage,
1825         .m_unlink           = mdc_unlink,
1826         .m_cancel_unused    = mdc_cancel_unused,
1827         .m_init_ea_size     = mdc_init_ea_size,
1828         .m_set_lock_data    = mdc_set_lock_data,
1829         .m_lock_match       = mdc_lock_match,
1830         .m_get_lustre_md    = mdc_get_lustre_md,
1831         .m_free_lustre_md   = mdc_free_lustre_md,
1832         .m_set_open_replay_data = mdc_set_open_replay_data,
1833         .m_clear_open_replay_data = mdc_clear_open_replay_data,
1834         .m_get_remote_perm  = mdc_get_remote_perm,
1835         .m_renew_capa       = mdc_renew_capa
1836 };
1837
1838 extern quota_interface_t mdc_quota_interface;
1839
1840 int __init mdc_init(void)
1841 {
1842         int rc;
1843         struct lprocfs_static_vars lvars = { 0 };
1844         lprocfs_mdc_init_vars(&lvars);
1845         
1846         request_module("lquota");
1847         quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1848         init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1849
1850         rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1851                                  LUSTRE_MDC_NAME, NULL);
1852         if (rc && quota_interface)
1853                 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1854
1855         RETURN(rc);
1856 }
1857
1858 #ifdef __KERNEL__
1859 static void /*__exit*/ mdc_exit(void)
1860 {
1861         if (quota_interface)
1862                 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1863
1864         class_unregister_type(LUSTRE_MDC_NAME);
1865 }
1866
1867 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1868 MODULE_DESCRIPTION("Lustre Metadata Client");
1869 MODULE_LICENSE("GPL");
1870
1871 module_init(mdc_init);
1872 module_exit(mdc_exit);
1873 #endif