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