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