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