Whamcloud - gitweb
b=14471
[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         ptlrpc_request_set_replen(req);
822         req->rq_commit_cb = mdc_commit_delayed;
823         req->rq_replay = 1;
824         LASSERT(req->rq_cb_data == NULL);
825         req->rq_cb_data = mod;
826
827         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
828         rc = ptlrpc_queue_wait(req);
829         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
830
831         if (req->rq_repmsg == NULL) {
832                 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
833                        req->rq_status);
834                 if (rc == 0)
835                         rc = req->rq_status ?: -EIO;
836         } else if (rc == 0 || rc == -EAGAIN) {
837                 struct mdt_body *body;
838
839                 rc = lustre_msg_get_status(req->rq_repmsg);
840                 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
841                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
842                                   "= %d", rc);
843                         if (rc > 0)
844                                 rc = -rc;
845                 } else if (mod == NULL) {
846                         if (req->rq_import->imp_replayable) 
847                                 CERROR("Unexpected: can't find md_open_data," 
848                                        "but close succeeded with replayable imp"
849                                        "Please tell CFS.\n");
850                 }
851
852                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
853                 if (body == NULL)
854                         rc = -EPROTO;
855         }
856
857         EXIT;
858         if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
859                 req->rq_commit_cb(req);
860
861         *request = req;
862         return rc;
863 }
864
865 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
866                      struct md_open_data *mod)
867 {
868         struct obd_device     *obd = class_exp2obd(exp);
869         struct ptlrpc_request *req;
870         int                    rc;
871         ENTRY;
872
873         req = ptlrpc_request_alloc(class_exp2cliimp(exp),
874                                    &RQF_MDS_DONE_WRITING);
875         if (req == NULL)
876                 RETURN(-ENOMEM);
877
878         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
879         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
880         if (rc) {
881                 ptlrpc_request_free(req);
882                 RETURN(rc);
883         }
884
885         /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
886          * recovery will be ready. */
887         mdc_close_pack(req, op_data);
888         ptlrpc_request_set_replen(req);
889         req->rq_replay = 1;
890         req->rq_cb_data = mod;
891         req->rq_commit_cb = mdc_commit_delayed;
892         if (likely(mod != NULL))
893                 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
894         else
895                 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
896
897         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
898         rc = ptlrpc_queue_wait(req);
899         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
900
901         /* Close the open replay sequence if an error occured or no SOM
902          * attribute update is needed. */
903         if (rc != -EAGAIN)
904                 ptlrpc_close_replay_seq(req);
905                 
906         if (rc && rc != -EAGAIN && req->rq_commit_cb)
907                 req->rq_commit_cb(req);
908
909         ptlrpc_req_finished(req);
910         RETURN(rc);
911 }
912
913 #ifdef HAVE_SPLIT_SUPPORT
914 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
915                  const struct page *page, int offset)
916 {
917         struct ptlrpc_request   *req;
918         struct ptlrpc_bulk_desc *desc;
919         int                      rc;
920         ENTRY;
921
922         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
923         if (req == NULL)
924                 RETURN(-ENOMEM);
925
926         /* FIXME: capa doesn't support split yet */
927         mdc_set_capa_size(req, &RMF_CAPA1, NULL);
928
929         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
930         if (rc) {
931                 ptlrpc_request_free(req);
932                 RETURN(rc);
933         }
934
935         req->rq_request_portal = MDS_READPAGE_PORTAL;
936
937         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
938         if (desc == NULL)
939                 GOTO(out, rc = -ENOMEM);
940
941         /* NB req now owns desc and will free it when it gets freed. */
942         ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
943         mdc_readdir_pack(req, 0, offset, fid, NULL);
944
945         ptlrpc_request_set_replen(req);
946         rc = ptlrpc_queue_wait(req);
947         GOTO(out, rc);
948 out:
949         ptlrpc_req_finished(req);
950         return rc;
951 }
952 EXPORT_SYMBOL(mdc_sendpage);
953 #endif
954
955 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
956                  struct obd_capa *oc, __u64 offset, struct page *page,
957                  struct ptlrpc_request **request)
958 {
959         struct ptlrpc_request   *req;
960         struct ptlrpc_bulk_desc *desc;
961         int                      rc;
962         ENTRY;
963
964         *request = NULL;
965         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
966         if (req == NULL)
967                 RETURN(-ENOMEM);
968
969         mdc_set_capa_size(req, &RMF_CAPA1, oc);
970
971         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
972         if (rc) {
973                 ptlrpc_request_free(req);
974                 RETURN(rc);
975         }
976
977         /* XXX FIXME bug 249 */
978         req->rq_request_portal = MDS_READPAGE_PORTAL;
979         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
980         if (desc == NULL) {
981                 ptlrpc_request_free(req);
982                 RETURN(-ENOMEM);
983         }
984
985         /* NB req now owns desc and will free it when it gets freed */
986         ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
987         mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
988
989         ptlrpc_request_set_replen(req);
990         rc = ptlrpc_queue_wait(req);
991         if (rc) {
992                 ptlrpc_req_finished(req);
993                 RETURN(rc);
994         }
995
996         if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
997                 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
998                         req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
999                 ptlrpc_req_finished(req);
1000                 RETURN(-EPROTO);
1001         }
1002
1003         *request = req;
1004         RETURN(0);
1005 }
1006
1007 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1008                          void *karg, void *uarg)
1009 {
1010         struct obd_device *obd = exp->exp_obd;
1011         struct obd_ioctl_data *data = karg;
1012         struct obd_import *imp = obd->u.cli.cl_import;
1013         struct llog_ctxt *ctxt;
1014         int rc;
1015         ENTRY;
1016
1017         if (!try_module_get(THIS_MODULE)) {
1018                 CERROR("Can't get module. Is it alive?");
1019                 return -EINVAL;
1020         }
1021         switch (cmd) {
1022         case OBD_IOC_CLIENT_RECOVER:
1023                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1024                 if (rc < 0)
1025                         GOTO(out, rc);
1026                 GOTO(out, rc = 0);
1027         case IOC_OSC_SET_ACTIVE:
1028                 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1029                 GOTO(out, rc);
1030         case OBD_IOC_PARSE: {
1031                 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1032                 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1033                 GOTO(out, rc);
1034         }
1035 #ifdef __KERNEL__
1036         case OBD_IOC_LLOG_INFO:
1037         case OBD_IOC_LLOG_PRINT: {
1038                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1039                 rc = llog_ioctl(ctxt, cmd, data);
1040
1041                 GOTO(out, rc);
1042         }
1043 #endif
1044         case OBD_IOC_POLL_QUOTACHECK:
1045                 rc = lquota_poll_check(quota_interface, exp,
1046                                        (struct if_quotacheck *)karg);
1047                 GOTO(out, rc);
1048         default:
1049                 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1050                 GOTO(out, rc = -ENOTTY);
1051         }
1052 out:
1053         module_put(THIS_MODULE);
1054
1055         return rc;
1056 }
1057
1058 static int do_set_info_async(struct obd_export *exp,
1059                              obd_count keylen, void *key,
1060                              obd_count vallen, void *val,
1061                              struct ptlrpc_request_set *set)
1062 {
1063         struct obd_import     *imp = class_exp2cliimp(exp);
1064         struct ptlrpc_request *req;
1065         char                  *tmp;
1066         int                    rc;
1067         ENTRY;
1068
1069         if (vallen != sizeof(int))
1070                 RETURN(-EINVAL);
1071
1072         spin_lock(&imp->imp_lock);
1073         if (*((int *)val)) {
1074                 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1075                 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1076         } else {
1077                 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1078                 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1079         }
1080         spin_unlock(&imp->imp_lock);
1081
1082         req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1083         if (req == NULL)
1084                 RETURN(-ENOMEM);
1085
1086         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1087                              RCL_CLIENT, keylen);
1088         req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1089                              RCL_CLIENT, vallen);
1090         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1091         if (rc) {
1092                 ptlrpc_request_free(req);
1093                 RETURN(rc);
1094         }
1095
1096         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1097         memcpy(tmp, key, keylen);
1098         tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1099         memcpy(tmp, val, vallen);
1100
1101         ptlrpc_request_set_replen(req);
1102
1103         if (set) {
1104                 ptlrpc_set_add_req(set, req);
1105                 ptlrpc_check_set(set);
1106         } else {
1107                 rc = ptlrpc_queue_wait(req);
1108                 ptlrpc_req_finished(req);
1109         }
1110
1111         RETURN(rc);
1112 }
1113
1114 int mdc_set_info_async(struct obd_export *exp,
1115                        obd_count keylen, void *key,
1116                        obd_count vallen, void *val,
1117                        struct ptlrpc_request_set *set)
1118 {
1119         struct obd_import *imp = class_exp2cliimp(exp);
1120         int                rc = -EINVAL;
1121         ENTRY;
1122
1123         if (KEY_IS(KEY_INIT_RECOV)) {
1124                 if (vallen != sizeof(int))
1125                         RETURN(-EINVAL);
1126                 spin_lock(&imp->imp_lock);
1127                 imp->imp_initial_recov = *(int *)val;
1128                 spin_unlock(&imp->imp_lock);
1129                 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1130                        exp->exp_obd->obd_name, imp->imp_initial_recov);
1131                 RETURN(0);
1132         }
1133         /* Turn off initial_recov after we try all backup servers once */
1134         if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1135                 if (vallen != sizeof(int))
1136                         RETURN(-EINVAL);
1137                 spin_lock(&imp->imp_lock);
1138                 imp->imp_initial_recov_bk = *(int *)val;
1139                 if (imp->imp_initial_recov_bk)
1140                         imp->imp_initial_recov = 1;
1141                 spin_unlock(&imp->imp_lock);
1142                 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1143                        exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1144                 RETURN(0);
1145         }
1146         if (KEY_IS(KEY_READ_ONLY)) {
1147                 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1148                 RETURN(rc);
1149         }
1150         if (KEY_IS(KEY_FLUSH_CTX)) {
1151                 sptlrpc_import_flush_my_ctx(imp);
1152                 RETURN(0);
1153         }
1154         if (KEY_IS(KEY_MDS_CONN)) {
1155                 struct obd_import *imp = class_exp2cliimp(exp);
1156                 
1157                 /* mds-mds import */
1158                 spin_lock(&imp->imp_lock);
1159                 imp->imp_server_timeout = 1;
1160                 spin_unlock(&imp->imp_lock);
1161                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1162                 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1163                 RETURN(0);
1164         }
1165
1166         RETURN(rc);
1167 }
1168
1169 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1170                  __u32 *vallen, void *val)
1171 {
1172         int rc = -EINVAL;
1173
1174         if (KEY_IS(KEY_MAX_EASIZE)) {
1175                 int mdsize, *max_easize;
1176
1177                 if (*vallen != sizeof(int))
1178                         RETURN(-EINVAL);
1179                 mdsize = *(int*)val;
1180                 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1181                         exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1182                 max_easize = val;
1183                 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1184                 RETURN(0);
1185         }
1186         if (KEY_IS(KEY_CONN_DATA)) {
1187                 struct obd_import *imp = class_exp2cliimp(exp);
1188                 struct obd_connect_data *data = val;
1189
1190                 if (*vallen != sizeof(*data))
1191                         RETURN(-EINVAL);
1192
1193                 *data = imp->imp_connect_data;
1194                 RETURN(0);
1195         }
1196                 
1197         RETURN(rc);
1198 }
1199
1200 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1201                       __u64 max_age)
1202 {
1203         struct ptlrpc_request *req;
1204         struct obd_statfs     *msfs;
1205         int                    rc;
1206         ENTRY;
1207
1208         req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_MDS_STATFS,
1209                                         LUSTRE_MDS_VERSION, MDS_STATFS);
1210         if (req == NULL)
1211                 RETURN(-ENOMEM);
1212
1213         ptlrpc_request_set_replen(req);
1214
1215         rc = ptlrpc_queue_wait(req);
1216         if (rc) {
1217                 /* check connection error first */
1218                 if (obd->u.cli.cl_import->imp_connect_error)
1219                         rc = obd->u.cli.cl_import->imp_connect_error;
1220                 GOTO(out, rc);
1221         }
1222
1223         msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1224         if (msfs == NULL)
1225                 GOTO(out, rc = -EPROTO);
1226
1227         *osfs = *msfs;
1228         EXIT;
1229 out:
1230         ptlrpc_req_finished(req);
1231         return rc;
1232 }
1233
1234 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1235                    struct obd_capa *oc, struct obd_client_handle *handle,
1236                    int flags)
1237 {
1238         struct ptlrpc_request *req;
1239         struct mdt_body       *body;
1240         int                    rc;
1241         ENTRY;
1242
1243         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1244         if (req == NULL)
1245                 RETURN(-ENOMEM);
1246
1247         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1248
1249         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1250         if (rc) {
1251                 ptlrpc_request_free(req);
1252                 RETURN(rc);
1253         }
1254
1255         mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1256
1257         ptlrpc_request_set_replen(req);
1258
1259         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1260         rc = ptlrpc_queue_wait(req);
1261         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1262         if (rc) {
1263                 CERROR("Pin failed: %d\n", rc);
1264                 GOTO(err_out, rc);
1265         }
1266
1267         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1268         if (body == NULL)
1269                 GOTO(err_out, rc = -EPROTO);
1270
1271         handle->och_fh = body->handle;
1272         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1273
1274         OBD_ALLOC_PTR(handle->och_mod);
1275         if (handle->och_mod == NULL) {
1276                 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1277                 GOTO(err_out, rc = -ENOMEM);
1278         }
1279         /* will be dropped by unpin */
1280         CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1281         list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1282
1283         RETURN(0);
1284
1285 err_out:
1286         ptlrpc_req_finished(req);
1287         RETURN(rc);
1288 }
1289
1290 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1291                      int flag)
1292 {
1293         struct ptlrpc_request *req;
1294         struct mdt_body       *body;
1295         int                    rc;
1296         ENTRY;
1297
1298         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1299                                         LUSTRE_MDS_VERSION, MDS_UNPIN);
1300         if (req == NULL)
1301                 RETURN(-ENOMEM);
1302
1303         body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1304         body->handle = handle->och_fh;
1305         body->flags = flag;
1306
1307         ptlrpc_request_set_replen(req);
1308
1309         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1310         rc = ptlrpc_queue_wait(req);
1311         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1312
1313         if (rc != 0)
1314                 CERROR("Unpin failed: %d\n", rc);
1315
1316         ptlrpc_req_finished(req);
1317
1318         LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1319         req = list_entry(handle->och_mod->mod_replay_list.next,
1320                          typeof(*req), rq_mod_list);
1321         list_del_init(&req->rq_mod_list);
1322         ptlrpc_req_finished(req);
1323         LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1324
1325         OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1326         RETURN(rc);
1327 }
1328
1329 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1330              struct obd_capa *oc, struct ptlrpc_request **request)
1331 {
1332         struct ptlrpc_request *req;
1333         int                    rc;
1334         ENTRY;
1335
1336         *request = NULL;
1337         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1338         if (req == NULL)
1339                 RETURN(-ENOMEM);
1340
1341         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1342
1343         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1344         if (rc) {
1345                 ptlrpc_request_free(req);
1346                 RETURN(rc);
1347         }
1348
1349         mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1350
1351         ptlrpc_request_set_replen(req);
1352
1353         rc = ptlrpc_queue_wait(req);
1354         if (rc)
1355                 ptlrpc_req_finished(req);
1356         else
1357                 *request = req;
1358         RETURN(rc);
1359 }
1360
1361 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1362                             enum obd_import_event event)
1363 {
1364         int rc = 0;
1365
1366         LASSERT(imp->imp_obd == obd);
1367
1368         switch (event) {
1369         case IMP_EVENT_DISCON: {
1370 #if 0
1371                 /* XXX Pass event up to OBDs stack. used only for FLD now */
1372                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1373 #endif
1374                 break;
1375         }
1376         case IMP_EVENT_INACTIVE: {
1377                 struct client_obd *cli = &obd->u.cli;
1378                 /* 
1379                  * Flush current sequence to make client obtain new one
1380                  * from server in case of disconnect/reconnect.
1381                  * If range is already empty then no need to flush it.
1382                  */
1383                 if (cli->cl_seq != NULL && 
1384                     !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1385                         seq_client_flush(cli->cl_seq);
1386                 }
1387
1388                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1389                 break;
1390         }
1391         case IMP_EVENT_INVALIDATE: {
1392                 struct ldlm_namespace *ns = obd->obd_namespace;
1393
1394                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1395
1396                 break;
1397         }
1398         case IMP_EVENT_ACTIVE: {
1399                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1400                 break;
1401         }
1402         case IMP_EVENT_OCD:
1403                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1404                 break;
1405
1406         default:
1407                 CERROR("Unknown import event %x\n", event);
1408                 LBUG();
1409         }
1410         RETURN(rc);
1411 }
1412
1413 static int mdc_fid_init(struct obd_export *exp)
1414 {
1415         struct client_obd *cli = &exp->exp_obd->u.cli;
1416         char *prefix;
1417         int rc;
1418         ENTRY;
1419
1420         OBD_ALLOC_PTR(cli->cl_seq);
1421         if (cli->cl_seq == NULL)
1422                 RETURN(-ENOMEM);
1423
1424         OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1425         if (prefix == NULL)
1426                 GOTO(out_free_seq, rc = -ENOMEM);
1427
1428         snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1429                  exp->exp_obd->obd_name);
1430
1431         /* Init client side sequence-manager */
1432         rc = seq_client_init(cli->cl_seq, exp, 
1433                              LUSTRE_SEQ_METADATA,
1434                              prefix, NULL);
1435         OBD_FREE(prefix, MAX_OBD_NAME + 5);
1436         if (rc)
1437                 GOTO(out_free_seq, rc);
1438
1439         RETURN(rc);
1440 out_free_seq:
1441         OBD_FREE_PTR(cli->cl_seq);
1442         cli->cl_seq = NULL;
1443         return rc;
1444 }
1445
1446 static int mdc_fid_fini(struct obd_export *exp)
1447 {
1448         struct client_obd *cli = &exp->exp_obd->u.cli;
1449         ENTRY;
1450
1451         if (cli->cl_seq != NULL) {
1452                 seq_client_fini(cli->cl_seq);
1453                 OBD_FREE_PTR(cli->cl_seq);
1454                 cli->cl_seq = NULL;
1455         }
1456         
1457         RETURN(0);
1458 }
1459
1460 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1461                   struct md_op_data *op_data)
1462 {
1463         struct client_obd *cli = &exp->exp_obd->u.cli;
1464         struct lu_client_seq *seq = cli->cl_seq;
1465         ENTRY;
1466         RETURN(seq_client_alloc_fid(seq, fid));
1467 }
1468
1469 /* XXX This method is used only to clear current fid seq
1470  * once fld/mds insert failed */
1471 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1472 {
1473         struct client_obd *cli = &exp->exp_obd->u.cli;
1474         
1475         seq_client_flush(cli->cl_seq);
1476         return 0;
1477 }
1478
1479 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1480 {
1481         struct client_obd *cli = &obd->u.cli;
1482         struct lprocfs_static_vars lvars = { 0 };
1483         int rc;
1484         ENTRY;
1485
1486         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1487         if (!cli->cl_rpc_lock)
1488                 RETURN(-ENOMEM);
1489         mdc_init_rpc_lock(cli->cl_rpc_lock);
1490
1491         ptlrpcd_addref();
1492
1493         OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1494         if (!cli->cl_setattr_lock)
1495                 GOTO(err_rpc_lock, rc = -ENOMEM);
1496         mdc_init_rpc_lock(cli->cl_setattr_lock);
1497
1498         OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1499         if (!cli->cl_close_lock)
1500                 GOTO(err_setattr_lock, rc = -ENOMEM);
1501         mdc_init_rpc_lock(cli->cl_close_lock);
1502
1503         rc = client_obd_setup(obd, cfg);
1504         if (rc)
1505                 GOTO(err_close_lock, rc);
1506         lprocfs_mdc_init_vars(&lvars);
1507         lprocfs_obd_setup(obd, lvars.obd_vars);
1508         sptlrpc_lprocfs_cliobd_attach(obd);
1509         ptlrpc_lprocfs_register_obd(obd);
1510
1511         rc = obd_llog_init(obd, NULL, obd, 0, NULL, NULL);
1512         if (rc) {
1513                 mdc_cleanup(obd);
1514                 CERROR("failed to setup llogging subsystems\n");
1515         }
1516
1517         RETURN(rc);
1518
1519 err_close_lock:
1520         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1521 err_setattr_lock:
1522         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1523 err_rpc_lock:
1524         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1525         ptlrpcd_decref();
1526         RETURN(rc);
1527 }
1528
1529 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
1530  * us to make MDS RPCs with large enough reply buffers to hold the
1531  * maximum-sized (= maximum striped) EA and cookie without having to
1532  * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1533 int mdc_init_ea_size(struct obd_export *exp, int easize,
1534                      int def_easize, int cookiesize)
1535 {
1536         struct obd_device *obd = exp->exp_obd;
1537         struct client_obd *cli = &obd->u.cli;
1538         ENTRY;
1539
1540         if (cli->cl_max_mds_easize < easize)
1541                 cli->cl_max_mds_easize = easize;
1542
1543         if (cli->cl_default_mds_easize < def_easize)
1544                 cli->cl_default_mds_easize = def_easize;
1545
1546         if (cli->cl_max_mds_cookiesize < cookiesize)
1547                 cli->cl_max_mds_cookiesize = cookiesize;
1548
1549         RETURN(0);
1550 }
1551
1552 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1553 {
1554         int rc = 0;
1555         ENTRY;
1556
1557         switch (stage) {
1558         case OBD_CLEANUP_EARLY:
1559         case OBD_CLEANUP_EXPORTS:
1560                 /* If we set up but never connected, the
1561                    client import will not have been cleaned. */
1562                 if (obd->u.cli.cl_import) {
1563                         struct obd_import *imp;
1564                         imp = obd->u.cli.cl_import;
1565                         CERROR("client import never connected\n");
1566                         ptlrpc_invalidate_import(imp);
1567                         ptlrpc_free_rq_pool(imp->imp_rq_pool);
1568                         class_destroy_import(imp);
1569                         obd->u.cli.cl_import = NULL;
1570                 }
1571                 break;
1572         case OBD_CLEANUP_SELF_EXP:
1573                 rc = obd_llog_finish(obd, 0);
1574                 if (rc != 0)
1575                         CERROR("failed to cleanup llogging subsystems\n");
1576         case OBD_CLEANUP_OBD:
1577                 break;
1578         }
1579         RETURN(rc);
1580 }
1581
1582 static int mdc_cleanup(struct obd_device *obd)
1583 {
1584         struct client_obd *cli = &obd->u.cli;
1585
1586         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1587         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1588         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1589
1590         ptlrpc_lprocfs_unregister_obd(obd);
1591         lprocfs_obd_cleanup(obd);
1592         ptlrpcd_decref();
1593
1594         return client_obd_cleanup(obd);
1595 }
1596
1597
1598 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1599                          struct obd_device *tgt, int count,
1600                          struct llog_catid *logid, struct obd_uuid *uuid)
1601 {
1602         struct llog_ctxt *ctxt;
1603         int rc;
1604         ENTRY;
1605
1606         rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1607                         &llog_client_ops);
1608         if (rc == 0) {
1609                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1610                 ctxt->loc_imp = obd->u.cli.cl_import;
1611         }
1612
1613         rc = llog_setup(obd, llogs, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1614                        &llog_client_ops);
1615         if (rc == 0) {
1616                 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1617                 ctxt->loc_imp = obd->u.cli.cl_import;
1618         }
1619
1620         RETURN(rc);
1621 }
1622
1623 static int mdc_llog_finish(struct obd_device *obd, int count)
1624 {
1625         int rc;
1626         ENTRY;
1627
1628         rc = llog_cleanup(llog_get_context(obd, LLOG_LOVEA_REPL_CTXT));
1629         if (rc) {
1630                 CERROR("can not cleanup LLOG_CONFIG_REPL_CTXT rc %d\n", rc);
1631         }
1632         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
1633         RETURN(rc);
1634 }
1635
1636 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1637 {
1638         struct lustre_cfg *lcfg = buf;
1639         struct lprocfs_static_vars lvars = { 0 };
1640         int rc = 0;
1641
1642         lprocfs_mdc_init_vars(&lvars);
1643
1644         switch (lcfg->lcfg_command) {
1645         case LCFG_SPTLRPC_CONF:
1646                 rc = sptlrpc_cliobd_process_config(obd, lcfg);
1647                 break;
1648         default:
1649                 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1650                                               lcfg, obd);
1651                 break;
1652         }
1653         return(rc);
1654 }
1655
1656
1657 /* get remote permission for current user on fid */
1658 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1659                         struct obd_capa *oc, __u32 suppgid,
1660                         struct ptlrpc_request **request)
1661 {
1662         struct ptlrpc_request  *req;
1663         int                    rc;
1664         ENTRY;
1665
1666         *request = NULL;
1667         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1668         if (req == NULL)
1669                 RETURN(-ENOMEM);
1670
1671         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1672
1673         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1674         if (rc) {
1675                 ptlrpc_request_free(req);
1676                 RETURN(rc);
1677         }
1678
1679         mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1680
1681         ptlrpc_request_set_replen(req);
1682
1683         rc = ptlrpc_queue_wait(req);
1684         if (rc)
1685                 ptlrpc_req_finished(req);
1686         else
1687                 *request = req;
1688         RETURN(rc);
1689 }
1690
1691 static int mdc_interpret_renew_capa(struct ptlrpc_request *req, void *unused,
1692                                     int status)
1693 {
1694         struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1695         renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1696         struct mdt_body *body = NULL;
1697         struct lustre_capa *capa;
1698         ENTRY;
1699
1700         if (status)
1701                 GOTO(out, capa = ERR_PTR(status));
1702
1703         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1704         if (body == NULL)
1705                 GOTO(out, capa = ERR_PTR(-EFAULT));
1706
1707         if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1708                 GOTO(out, capa = ERR_PTR(-ENOENT));
1709
1710         capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1711         if (!capa)
1712                 GOTO(out, capa = ERR_PTR(-EFAULT));
1713         EXIT;
1714 out:
1715         cb(oc, capa);
1716         return 0;
1717 }
1718
1719 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1720                           renew_capa_cb_t cb)
1721 {
1722         struct ptlrpc_request *req;
1723         ENTRY;
1724
1725         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1726                                         LUSTRE_MDS_VERSION, MDS_GETATTR);
1727         if (req == NULL)
1728                 RETURN(-ENOMEM);
1729
1730         /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1731          * capa to renew is oss capa.
1732          */
1733         mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1734         ptlrpc_request_set_replen(req);
1735
1736         req->rq_async_args.pointer_arg[0] = oc;
1737         req->rq_async_args.pointer_arg[1] = cb;
1738         req->rq_interpret_reply = mdc_interpret_renew_capa;
1739         ptlrpcd_add_req(req);
1740         RETURN(0);
1741 }
1742
1743 static int mdc_connect(const struct lu_env *env,
1744                        struct lustre_handle *dlm_handle,
1745                        struct obd_device *obd, struct obd_uuid *cluuid,
1746                        struct obd_connect_data *data)
1747 {
1748         struct obd_import *imp = obd->u.cli.cl_import;
1749
1750         /* mds-mds import features */
1751         if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1752                 spin_lock(&imp->imp_lock);
1753                 imp->imp_server_timeout = 1;
1754                 spin_unlock(&imp->imp_lock);
1755                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1756                 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1757                        obd->obd_name);
1758         }
1759
1760         return client_connect_import(env, dlm_handle, obd, cluuid, data);
1761 }
1762
1763 struct obd_ops mdc_obd_ops = {
1764         .o_owner            = THIS_MODULE,
1765         .o_setup            = mdc_setup,
1766         .o_precleanup       = mdc_precleanup,
1767         .o_cleanup          = mdc_cleanup,
1768         .o_add_conn         = client_import_add_conn,
1769         .o_del_conn         = client_import_del_conn,
1770         .o_connect          = mdc_connect,
1771         .o_disconnect       = client_disconnect_export,
1772         .o_iocontrol        = mdc_iocontrol,
1773         .o_set_info_async   = mdc_set_info_async,
1774         .o_statfs           = mdc_statfs,
1775         .o_pin              = mdc_pin,
1776         .o_unpin            = mdc_unpin,
1777         .o_fid_init         = mdc_fid_init,
1778         .o_fid_fini         = mdc_fid_fini,
1779         .o_fid_alloc        = mdc_fid_alloc,
1780         .o_fid_delete       = mdc_fid_delete,
1781         .o_import_event     = mdc_import_event,
1782         .o_llog_init        = mdc_llog_init,
1783         .o_llog_finish      = mdc_llog_finish,
1784         .o_get_info         = mdc_get_info,
1785         .o_process_config  = mdc_process_config,
1786 };
1787
1788 struct md_ops mdc_md_ops = {
1789         .m_getstatus        = mdc_getstatus,
1790         .m_change_cbdata    = mdc_change_cbdata,
1791         .m_close            = mdc_close,
1792         .m_create           = mdc_create,
1793         .m_done_writing     = mdc_done_writing,
1794         .m_enqueue          = mdc_enqueue,
1795         .m_getattr          = mdc_getattr,
1796         .m_getattr_name     = mdc_getattr_name,
1797         .m_intent_lock      = mdc_intent_lock,
1798         .m_link             = mdc_link,
1799         .m_is_subdir        = mdc_is_subdir,
1800         .m_rename           = mdc_rename,
1801         .m_setattr          = mdc_setattr,
1802         .m_setxattr         = mdc_setxattr,
1803         .m_getxattr         = mdc_getxattr,
1804         .m_sync             = mdc_sync,
1805         .m_readpage         = mdc_readpage,
1806         .m_unlink           = mdc_unlink,
1807         .m_cancel_unused    = mdc_cancel_unused,
1808         .m_init_ea_size     = mdc_init_ea_size,
1809         .m_set_lock_data    = mdc_set_lock_data,
1810         .m_lock_match       = mdc_lock_match,
1811         .m_get_lustre_md    = mdc_get_lustre_md,
1812         .m_free_lustre_md   = mdc_free_lustre_md,
1813         .m_set_open_replay_data = mdc_set_open_replay_data,
1814         .m_clear_open_replay_data = mdc_clear_open_replay_data,
1815         .m_get_remote_perm  = mdc_get_remote_perm,
1816         .m_renew_capa       = mdc_renew_capa
1817 };
1818
1819 extern quota_interface_t mdc_quota_interface;
1820
1821 int __init mdc_init(void)
1822 {
1823         int rc;
1824         struct lprocfs_static_vars lvars = { 0 };
1825         lprocfs_mdc_init_vars(&lvars);
1826         
1827         request_module("lquota");
1828         quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1829         init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1830
1831         rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1832                                  LUSTRE_MDC_NAME, NULL);
1833         if (rc && quota_interface)
1834                 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1835
1836         RETURN(rc);
1837 }
1838
1839 #ifdef __KERNEL__
1840 static void /*__exit*/ mdc_exit(void)
1841 {
1842         if (quota_interface)
1843                 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1844
1845         class_unregister_type(LUSTRE_MDC_NAME);
1846 }
1847
1848 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1849 MODULE_DESCRIPTION("Lustre Metadata Client");
1850 MODULE_LICENSE("GPL");
1851
1852 module_init(mdc_init);
1853 module_exit(mdc_exit);
1854 #endif