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