Whamcloud - gitweb
- swab capa data in mdc_replay_open(), the sequence can be:
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001-2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_MDC
26
27 #ifdef __KERNEL__
28 # include <linux/module.h>
29 # include <linux/pagemap.h>
30 # include <linux/miscdevice.h>
31 # include <linux/init.h>
32 #else
33 # include <liblustre.h>
34 #endif
35
36 #include <linux/obd_class.h>
37 #include <linux/lustre_mds.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/lustre_sec.h>
40 #include <linux/lprocfs_status.h>
41 #include <linux/lustre_acl.h>
42 #include <linux/lustre_lite.h>
43 #include <linux/lustre_gs.h>
44 #include "mdc_internal.h"
45
46 #define REQUEST_MINOR 244
47
48 static int mdc_cleanup(struct obd_device *obd, int flags);
49
50 extern int mds_queue_req(struct ptlrpc_request *);
51 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
52 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
53 static int send_getstatus(struct obd_import *imp, struct lustre_id *rootid,
54                           int level, int msg_flags)
55 {
56         struct ptlrpc_request *req;
57         struct mds_body *body;
58         int rc, size[2] = {0, sizeof(*body)};
59         ENTRY;
60
61         //size[0] = lustre_secdesc_size();
62
63         req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS,
64                               2, size, NULL);
65         if (!req)
66                 GOTO(out, rc = -ENOMEM);
67
68         //lustre_pack_secdesc(req, size[0]);
69
70         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
71         req->rq_send_state = level;
72         req->rq_replen = lustre_msg_size(1, &size[1]);
73
74         req->rq_reqmsg->flags |= msg_flags;
75         rc = ptlrpc_queue_wait(req);
76
77         if (!rc) {
78                 body = lustre_swab_repbuf (req, 0, sizeof (*body),
79                                            lustre_swab_mds_body);
80                 if (body == NULL) {
81                         CERROR ("Can't extract mds_body\n");
82                         GOTO (out, rc = -EPROTO);
83                 }
84
85                 memcpy(rootid, &body->id1, sizeof(*rootid));
86
87                 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
88                        ", last_xid="LPU64"\n", rootid->li_stc.u.e3s.l3s_ino,
89                        req->rq_repmsg->last_committed, req->rq_repmsg->last_xid);
90         }
91
92         EXIT;
93  out:
94         ptlrpc_req_finished(req);
95         return rc;
96 }
97
98 /* This should be mdc_get_info("rootid") */
99 int mdc_getstatus(struct obd_export *exp, struct lustre_id *rootid)
100 {
101         return send_getstatus(class_exp2cliimp(exp), rootid,
102                               LUSTRE_IMP_FULL, 0);
103 }
104
105 int
106 mdc_interpret_getattr(struct ptlrpc_request *req, void *unused, int rc)
107 {
108         struct mds_body *body = NULL;
109         struct obd_capa *ocapa;
110         struct lustre_capa *capa = NULL;
111         unsigned long expiry;
112         ENTRY;
113
114         if (rc == 0)
115                 rc = req->rq_status;
116
117         if (rc) {
118                 DEBUG_REQ(rc == -ENOENT ? D_INFO : D_ERROR , req,
119                           "async getattr failed: rc = %d", rc);
120                 RETURN(rc);
121         }
122
123         body = lustre_swab_repbuf(req, 0, sizeof (*body), lustre_swab_mds_body);
124         if (body == NULL) {
125                 CERROR ("Can't unpack mds_body\n");
126                 RETURN(-EPROTO);
127         }
128
129         if (!(body->valid & OBD_MD_CAPA)) {
130                 CDEBUG(D_INFO, "MDS has disabled capability\n");
131                 RETURN(0);
132         }
133
134         capa = lustre_swab_repbuf(req, 1, sizeof(*capa),
135                                   lustre_swab_lustre_capa);
136         if (capa == NULL && rc != 0) {
137                 CERROR ("Can't unpack lustre_capa\n");
138                 RETURN(-EPROTO);
139         }
140
141         ocapa = capa_renew(capa, CLIENT_CAPA);
142         if (!ocapa)
143                 RETURN(-ENOENT);
144
145         spin_lock(&capa_lock);
146         expiry = expiry_to_jiffies(capa->lc_expiry - capa_pre_expiry(capa));
147         CDEBUG(D_INFO, "expiry %lu vs timer %lu, base %p\n",
148                expiry, ll_capa_timer.expires, ll_capa_timer.base);
149         if (time_before(expiry, ll_capa_timer.expires) ||
150             !timer_pending(&ll_capa_timer)) {
151                 mod_timer(&ll_capa_timer, expiry);
152                 CDEBUG(D_INFO, "ll_capa_timer new expiry: %lu\n", expiry);
153         }
154         spin_unlock(&capa_lock);
155
156         RETURN(rc);
157 }
158
159 int mdc_getattr_async(struct obd_export *exp, struct ptlrpc_request *req)
160 {
161         int repsize[2] = {sizeof(struct mds_body), sizeof(struct lustre_capa)};
162         ENTRY;
163
164         req->rq_replen = lustre_msg_size(2, repsize);
165         req->rq_interpret_reply = mdc_interpret_getattr;
166         ptlrpcd_add_req(req);
167
168         RETURN (0);
169 }
170
171 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
172                        struct ptlrpc_request *req)
173 {
174         struct mds_body *body, *reqbody;
175         void            *eadata;
176         int              rc;
177         int              repsize[2] = {sizeof(*body)};
178         int              bufcount = 1;
179         ENTRY;
180
181         /* request message already built */
182
183         if (ea_size != 0) {
184                 repsize[bufcount++] = ea_size;
185                 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
186                        ea_size);
187         }
188
189         reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
190         LASSERT(!(reqbody->valid & OBD_MD_FLACL));
191
192         if (reqbody->valid & OBD_MD_FLKEY) {
193                 repsize[bufcount++] = 5;
194                 repsize[bufcount++] = sizeof(struct lustre_key);
195         } else if (reqbody->valid & OBD_MD_CAPA) {
196                 LASSERT(ea_size == 0);
197                 repsize[bufcount++] = sizeof(struct lustre_capa);
198         }
199
200         req->rq_replen = lustre_msg_size(bufcount, repsize);
201
202         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
203         rc = ptlrpc_queue_wait(req);
204         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
205         if (rc != 0)
206                 RETURN (rc);
207
208         body = lustre_swab_repbuf (req, 0, sizeof (*body),
209                                    lustre_swab_mds_body);
210         if (body == NULL) {
211                 CERROR ("Can't unpack mds_body\n");
212                 RETURN (-EPROTO);
213         }
214
215         CDEBUG(D_NET, "mode: %o\n", body->mode);
216
217         LASSERT_REPSWAB (req, 1);
218
219         /* Skip the check if getxattr/listxattr are called with no buffers */
220         if ((reqbody->eadatasize != 0) &&
221             !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
222                 /* reply indicates presence of eadata; check it's there... */
223                 eadata = lustre_msg_buf (req->rq_repmsg, 1,
224                                          body->eadatasize);
225                 if (eadata == NULL) {
226                         CERROR ("Missing/short eadata\n");
227                         RETURN (-EPROTO);
228                 }
229         }
230
231         RETURN (0);
232 }
233
234 static int mdc_cancel_unused(struct obd_export *exp,
235                              struct lov_stripe_md *lsm, 
236                              int flags, void *opaque)
237 {
238         struct obd_device *obd = class_exp2obd(exp);
239
240         ENTRY;
241         RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
242                                       NULL, flags, opaque));
243 }
244
245 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
246                 __u64 valid, const char *xattr_name,
247                 const void *xattr_data, unsigned int xattr_datalen,
248                 unsigned int ea_size, struct obd_capa *ocapa,
249                 struct ptlrpc_request **request)
250 {
251         struct ptlrpc_request *req;
252         struct mds_body *body;
253         int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
254         int size[4] = {0, sizeof(*body)};
255         int bufcount = 2;
256         int rc;
257         ENTRY;
258
259         size[0] = lustre_secdesc_size();
260
261         if (valid & OBD_MD_FLXATTR) {
262                 size[bufcount++] = xattr_namelen;
263
264                 if (xattr_datalen > 0) {
265                         LASSERT(xattr_data);
266                         size[bufcount++] = xattr_datalen;
267                 }
268         } else if (valid & OBD_MD_CAPA) {
269                 LASSERT(valid  == OBD_MD_CAPA);
270                 LASSERT(ocapa);
271                 size[bufcount++] = sizeof(*ocapa);
272         } else {
273                 LASSERT(!xattr_data && !xattr_datalen);
274         }
275
276         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
277                               MDS_GETATTR, bufcount, size, NULL);
278         if (!req)
279                 GOTO(out, rc = -ENOMEM);
280
281         lustre_pack_secdesc(req, size[0]);
282
283         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
284         memcpy(&body->id1, id, sizeof(*id));
285         body->valid = valid;
286         body->eadatasize = ea_size;
287
288         if (valid & OBD_MD_FLXATTR) {
289                 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
290                        xattr_name, xattr_namelen);
291                 if (xattr_datalen)
292                         memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
293                                xattr_data, xattr_datalen);
294         }
295
296         if (valid & OBD_MD_CAPA) {
297                 /* renew capability */
298                 memcpy(&body->handle, &ocapa->c_handle, sizeof(body->handle));
299                 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, sizeof(ocapa->c_capa)),
300                        &ocapa->c_capa, sizeof(ocapa->c_capa));
301
302                 rc = mdc_getattr_async(exp, req);
303                 req = NULL;     /* ptlrpcd will finish request */
304         } else {
305                 rc = mdc_getattr_common(exp, ea_size, req);
306                 if (rc != 0) {
307                         ptlrpc_req_finished (req);
308                         req = NULL;
309                 }
310         }
311  out:
312         *request = req;
313         RETURN (rc);
314 }
315
316 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
317                      struct ptlrpc_request **request)
318
319 {
320         struct ptlrpc_request *req;
321         struct mds_body *body;
322         int size[2] = {0, sizeof(*body)};
323         int rc;
324         ENTRY;
325
326         size[0] = lustre_secdesc_size();
327         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
328                               MDS_ACCESS_CHECK, 2, size, NULL);
329         if (!req)
330                 GOTO(out, rc = -ENOMEM);
331
332         lustre_pack_secdesc(req, size[0]);
333         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
334         memcpy(&body->id1, id, sizeof(*id));
335
336         size[0] = sizeof(*body);
337         size[1] = sizeof(struct mds_remote_perm);
338         req->rq_replen = lustre_msg_size(2, size);
339
340         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
341         rc = ptlrpc_queue_wait(req);
342         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
343         if (rc != 0) {
344                 ptlrpc_req_finished (req);
345                 req = NULL;
346         } else {
347                 body = lustre_swab_repbuf (req, 0, sizeof (*body),
348                                            lustre_swab_mds_body);
349                 if (body == NULL) {
350                         CERROR ("Can't unpack mds_body\n");
351                         RETURN (-EPROTO);
352                 }
353         }
354
355  out:
356         *request = req;
357         RETURN (rc);
358 }
359
360 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
361                      char *filename, int namelen, __u64 valid,
362                      unsigned int ea_size, struct ptlrpc_request **request)
363 {
364         struct ptlrpc_request *req;
365         struct mds_body *body;
366         int rc, size[3] = {0, sizeof(*body), namelen};
367         ENTRY;
368
369         size[0] = lustre_secdesc_size();
370
371         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
372                               MDS_GETATTR_LOCK, 3, size, NULL);
373         if (!req)
374                 GOTO(out, rc = -ENOMEM);
375
376         lustre_pack_secdesc(req, size[0]);
377
378         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
379         memcpy(&body->id1, id, sizeof(*id));
380         body->valid = valid;
381         body->eadatasize = ea_size;
382
383         if (filename != NULL) {
384                 LASSERT (strnlen (filename, namelen) == namelen - 1);
385                 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
386                        filename, namelen);
387         } else {
388                 LASSERT(namelen == 1);
389         }
390
391         rc = mdc_getattr_common(exp, ea_size, req);
392         if (rc != 0) {
393                 ptlrpc_req_finished (req);
394                 req = NULL;
395         }
396  out:
397         *request = req;
398         RETURN(rc);
399 }
400
401 /* This should be called with both the request and the reply still packed. */
402 int mdc_store_inode_generation(struct obd_export *exp,
403                                struct ptlrpc_request *req,
404                                int reqoff, int repoff)
405 {
406         struct mds_rec_create *rec =
407                 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
408         struct mds_body *body =
409                 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
410
411         LASSERT (rec != NULL);
412         LASSERT (body != NULL);
413
414         memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
415         DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
416                   OLID4(&rec->cr_replayid));
417         return 0;
418 }
419
420 static
421 int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req, 
422                    unsigned int offset, struct lustre_md *md)
423 {
424         struct posix_acl *acl;
425         struct mds_remote_perm *perm;
426         int    size, rc;
427         void  *buf;
428         ENTRY;
429  
430         if (!(md->body->valid & OBD_MD_FLACL))
431                 RETURN(0);
432
433         if (md->body->valid & OBD_MD_FLRMTACL) {
434                 offset++; /* first 'size' is not used */
435
436                 buf = lustre_swab_repbuf(req, offset, sizeof(*perm),
437                                          lustre_swab_remote_perm);
438                 if (buf == NULL) {
439                         CERROR("Can't unpack remote perm\n");
440                         RETURN(-EFAULT);
441                 }
442
443                 OBD_ALLOC(perm, sizeof(*perm));
444                 if (!perm)
445                         RETURN(-ENOMEM);
446                 memcpy(perm, buf, sizeof(*perm));
447                 md->remote_perm = perm;
448         } else {
449                 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
450                                    req->rq_repmsg, offset, 4));
451                 buf = lustre_msg_buf(req->rq_repmsg, offset + 1, size);
452
453                 acl = posix_acl_from_xattr(buf, size);
454                 if (IS_ERR(acl)) {
455                         rc = PTR_ERR(acl);
456                         CERROR("convert xattr to acl failed: %d\n", rc);
457                         RETURN(rc);
458                 } else if (acl) {
459                         rc = posix_acl_valid(acl);
460                         if (rc) {
461                                 CERROR("acl valid error: %d\n", rc);
462                                 posix_acl_release(acl);
463                                 RETURN(rc);
464                         }
465                 }
466
467                 md->posix_acl = acl;
468         }
469
470         RETURN(0);
471 }
472
473 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req, 
474                             unsigned int *offset, struct lustre_md *md)
475
476         int key_off = 0, rc = 0, size = 0;
477         void *buf;
478         
479         key_off = *offset;
480         if (md->body->valid & OBD_MD_FLKEY) {
481                 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg, 
482                                    key_off++, 4));
483                 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
484                 
485                 CDEBUG(D_INFO, "buf %p key_off %d size %d \n", 
486                        buf, key_off, size);
487                 md->key = (struct lustre_key *)buf; 
488                 *offset = key_off; 
489         } else {
490                 *offset += 2;
491         } 
492         RETURN(rc);
493 }
494
495 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req, 
496                       unsigned int offset, struct obd_export *exp_lov, 
497                       struct lustre_md *md)
498 {
499         struct lov_mds_md *lmm;
500         int rc = 0, reply_off;
501         ENTRY;
502
503         LASSERT(md != NULL);
504         memset(md, 0, sizeof(*md));
505
506         md->body = lustre_msg_buf(req->rq_repmsg, offset,
507                                   sizeof(*md->body));
508         if (!md->body)
509                 RETURN(-ENOMEM);
510
511         LASSERT_REPSWABBED(req, offset);
512
513         if (!(md->body->valid & OBD_MD_FLEASIZE) &&
514             !(md->body->valid & OBD_MD_FLDIREA))
515                 RETURN(0);
516
517         if (S_ISREG(md->body->mode)) {
518                 if (md->body->eadatasize == 0) {
519                         CERROR("invalid EA size (0) is detected\n");
520                         RETURN(-EPROTO);
521                 }
522
523                 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
524                                      md->body->eadatasize);
525                 if (!lmm)
526                         RETURN(-EINVAL);
527
528                 LASSERT(exp_lov != NULL);
529                 
530                 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
531                                   md->body->eadatasize);
532                 if (rc > 0) {
533                         LASSERT(rc >= sizeof(*md->lsm));
534                         rc = 0;
535                 }
536         } else if (S_ISDIR(md->body->mode)) {
537                 /* dir can be non-splitted */
538                 if (md->body->eadatasize == 0)
539                         RETURN(0);
540
541                 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
542                                      md->body->eadatasize);
543                 if (!lmm)
544                         RETURN(-EINVAL);
545
546                 if (md->body->valid & OBD_MD_MEA) {
547                         LASSERT(exp_lmv != NULL);
548                 
549                         rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
550                                           lmm, md->body->eadatasize);
551                         if (rc > 0) {
552                                 LASSERT(rc >= sizeof(*md->mea));
553                                 rc = 0;
554                         }
555                 }
556         } else {
557                 LASSERT(S_ISCHR(md->body->mode) ||
558                         S_ISBLK(md->body->mode) ||
559                         S_ISFIFO(md->body->mode)||
560                         S_ISLNK(md->body->mode) ||
561                         S_ISSOCK(md->body->mode));
562         }
563
564         /* if anything wrong when unpacking md, we don't check acl
565          * stuff, for simplicity
566          */
567         if (rc)
568                 RETURN(rc);
569
570         reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
571                                 (offset + 2) : (offset + 1);
572         rc = mdc_unpack_acl(exp_lmv, req, reply_off, md);
573         if (rc) {
574                 CERROR("upack acl error %d \n", rc);
575                 RETURN(rc);
576         }
577         reply_off += 2;
578         
579         rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
580         if (rc)
581                 RETURN(rc);
582
583         RETURN(rc);
584 }
585
586 static void mdc_commit_open(struct ptlrpc_request *req)
587 {
588         struct mdc_open_data *mod = req->rq_cb_data;
589         if (mod == NULL)
590                 return;
591
592         if (mod->mod_close_req != NULL)
593                 mod->mod_close_req->rq_cb_data = NULL;
594
595         if (mod->mod_och != NULL)
596                 mod->mod_och->och_mod = NULL;
597
598         OBD_FREE(mod, sizeof(*mod));
599         req->rq_cb_data = NULL;
600         LASSERT(atomic_read(&req->rq_refcount) > 1);
601         ptlrpc_req_finished(req);
602 }
603
604 static void mdc_replay_open(struct ptlrpc_request *req)
605 {
606         struct mdc_open_data *mod = req->rq_cb_data;
607         struct obd_client_handle *och;
608         struct ptlrpc_request *close_req;
609         struct lustre_handle old;
610         struct mds_body *body;
611         ENTRY;
612
613         body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
614         LASSERT (body != NULL);
615
616
617         if (body->valid & OBD_MD_CAPA) {
618                 DEBUG_REQ(D_HA, req, "swap capa data from open");
619                 lustre_swab_repbuf(req, 7, sizeof(struct lustre_capa),
620                                    lustre_swab_lustre_capa);
621         }
622         if (mod == NULL) {
623                 DEBUG_REQ(D_ERROR, req,
624                           "can't properly replay without open data");
625                 EXIT;
626                 return;
627         }
628
629         och = mod->mod_och;
630         if (och != NULL) {
631                 struct lustre_handle *file_fh;
632                 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
633                 file_fh = &och->och_fh;
634                 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
635                        file_fh->cookie, body->handle.cookie);
636                 memcpy(&old, file_fh, sizeof(old));
637                 memcpy(file_fh, &body->handle, sizeof(*file_fh));
638         }
639
640         close_req = mod->mod_close_req;
641         if (close_req != NULL) {
642                 struct mds_body *close_body;
643                 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
644                 close_body = lustre_msg_buf(close_req->rq_reqmsg,
645                                             MDS_REQ_REC_OFF,
646                                             sizeof(*close_body));
647                 if (och != NULL)
648                         LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
649                 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
650                 memcpy(&close_body->handle, &body->handle,
651                        sizeof(close_body->handle));
652         }
653
654         EXIT;
655 }
656
657 int mdc_set_open_replay_data(struct obd_export *exp,
658                              struct obd_client_handle *och,
659                              struct ptlrpc_request *open_req)
660 {
661         struct mdc_open_data *mod;
662         struct mds_rec_create *rec;
663         struct mds_body *body;
664
665         rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
666                              sizeof(*rec));
667         body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
668
669         LASSERT(rec != NULL);
670         /* outgoing messages always in my byte order */
671         LASSERT(body != NULL);
672         /* incoming message in my byte order (it's been swabbed) */
673         LASSERT_REPSWABBED(open_req, 1);
674
675         OBD_ALLOC(mod, sizeof(*mod));
676         if (mod == NULL) {
677                 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
678                 return 0;
679         }
680
681         och->och_mod = mod;
682         mod->mod_och = och;
683         mod->mod_open_req = ptlrpc_request_addref(open_req);
684
685         if (memcmp(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid)))
686                 CDEBUG(D_ERROR, DLID4" != "DLID4"\n", OLID4(&rec->cr_replayid),
687                        OLID4(&body->id1));
688         LASSERT(id_ino(&rec->cr_replayid) != 0);
689         memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
690         memcpy(&rec->cr_ioepoch, &body->io_epoch, sizeof rec->cr_ioepoch);
691         open_req->rq_replay_cb = mdc_replay_open;
692         open_req->rq_commit_cb = mdc_commit_open;
693         open_req->rq_cb_data = mod;
694         DEBUG_REQ(D_HA, open_req, "set up replay data");
695         return 0;
696 }
697
698 int mdc_clear_open_replay_data(struct obd_export *exp,
699                                struct obd_client_handle *och)
700 {
701         struct mdc_open_data *mod = och->och_mod;
702
703         /* Don't free the structure now (it happens in mdc_commit_open, after
704          * we're sure we won't need to fix up the close request in the future),
705          * but make sure that replay doesn't poke at the och, which is about to
706          * be freed. */
707         LASSERT(mod != LP_POISON);
708         if (mod != NULL)
709                 mod->mod_och = NULL;
710         och->och_mod = NULL;
711         return 0;
712 }
713
714 static void mdc_commit_close(struct ptlrpc_request *req)
715 {
716         struct mdc_open_data *mod = req->rq_cb_data;
717         struct obd_import *imp = req->rq_import;
718         struct ptlrpc_request *open_req;
719
720         DEBUG_REQ(D_HA, req, "close req committed");
721         if (mod == NULL)
722                 return;
723
724         mod->mod_close_req = NULL;
725         req->rq_cb_data = NULL;
726         req->rq_commit_cb = NULL;
727
728         open_req = mod->mod_open_req;
729         LASSERT(open_req != NULL);
730         LASSERT(open_req != LP_POISON);
731         LASSERT(open_req->rq_type != LI_POISON);
732
733         DEBUG_REQ(D_HA, open_req, "open req balanced");
734         if (open_req->rq_transno == 0) {
735                 DEBUG_REQ(D_ERROR, open_req, "BUG 3892  open");
736                 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
737                 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
738         }
739         LASSERT(open_req->rq_import == imp);
740
741         /* We no longer want to preserve this for transno-unconditional
742          * replay. */
743         spin_lock(&open_req->rq_lock);
744         open_req->rq_replay = 0;
745         spin_unlock(&open_req->rq_lock);
746 }
747
748 int mdc_close(struct obd_export *exp, struct mdc_op_data *op_data,
749               struct obd_client_handle *och, struct ptlrpc_request **request)
750 {
751         struct obd_device *obd = class_exp2obd(exp);
752         struct obd_import *imp = class_exp2cliimp(exp);
753         int reqsize[3] = {0, sizeof(struct mds_body),
754                           obd->u.cli.cl_max_mds_cookiesize};
755         int rc, repsize[3] = {sizeof(struct mds_body),
756                               obd->u.cli.cl_max_mds_easize,
757                               obd->u.cli.cl_max_mds_cookiesize};
758         struct ptlrpc_request *req;
759         struct mdc_open_data *mod;
760         ENTRY;
761
762         if (imp->imp_connection == NULL) {
763                 CERROR("request on not connected import %s\n",
764                         imp->imp_obd->obd_name);
765                 RETURN(-EIO);
766         }
767
768         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
769                               MDS_CLOSE, 3, reqsize, NULL);
770         if (req == NULL)
771                 GOTO(out, rc = -ENOMEM);
772         //req->rq_request_portal = MDS_CLOSE_PORTAL;
773
774         /* ensure that this close's handle is fixed up during replay. */
775         LASSERT(och != NULL);
776         mod = och->och_mod;
777         if (likely(mod != NULL)) {
778                 mod->mod_close_req = req;
779                 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
780                 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
781         } else {
782                 CDEBUG(D_HA, "couldn't find open req; "
783                        "expecting close error\n");
784         }
785
786         mdc_close_pack(req, 1, op_data, och);
787
788         req->rq_replen = lustre_msg_size(3, repsize);
789         req->rq_commit_cb = mdc_commit_close;
790         LASSERT(req->rq_cb_data == NULL);
791         req->rq_cb_data = mod;
792
793         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
794         rc = ptlrpc_queue_wait(req);
795         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
796
797         if (req->rq_repmsg == NULL) {
798                 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
799                        req->rq_status);
800                 if (rc == 0)
801                         rc = req->rq_status ? req->rq_status : -EIO;
802         } else if (rc == 0) {
803                 rc = req->rq_repmsg->status;
804                 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
805                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
806                                   "err = %d", rc);
807                         if (rc > 0)
808                                 rc = -rc;
809                 } else {
810                         if (mod == NULL)
811                                 CERROR("Unexpected: can't find mdc_open_data, but "
812                                        "close succeeded. Please tell CFS.\n");
813                         if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
814                                                 lustre_swab_mds_body))
815                         {
816                                 CERROR("Error unpacking mds_body\n");
817                                 rc = -EPROTO;
818                         }
819                 }
820         }
821
822         EXIT;
823  out:
824         *request = req;
825         return rc;
826 }
827
828 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
829 {
830         struct ptlrpc_request *req;
831         struct mds_body *body;
832         int rc, size[2] = {0, sizeof(*body)};
833         ENTRY;
834
835         size[0] = lustre_secdesc_size();
836
837         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
838                               MDS_DONE_WRITING, 2, size, NULL);
839         if (req == NULL)
840                 RETURN(-ENOMEM);
841
842         lustre_pack_secdesc(req, size[0]);
843
844         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, 
845                               sizeof(*body));
846         
847         mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode, 
848                     obdo->o_mds, obdo->o_fid);
849         
850         body->size = obdo->o_size;
851         body->blocks = obdo->o_blocks;
852         body->flags = obdo->o_flags;
853         body->valid = obdo->o_valid;
854
855         req->rq_replen = lustre_msg_size(1, &size[1]);
856
857         rc = ptlrpc_queue_wait(req);
858         ptlrpc_req_finished(req);
859         RETURN(rc);
860 }
861
862 int mdc_readpage(struct obd_export *exp,
863                  struct lustre_id *id,
864                  __u64 offset, struct page *page,
865                  struct ptlrpc_request **request)
866 {
867         struct obd_import *imp = class_exp2cliimp(exp);
868         struct ptlrpc_request *req = NULL;
869         struct ptlrpc_bulk_desc *desc = NULL;
870         struct mds_body *body;
871         int rc, size[2] = {0, sizeof(*body)};
872         ENTRY;
873
874         CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
875
876         size[0] = lustre_secdesc_size();
877
878         req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
879                               2, size, NULL);
880         if (req == NULL)
881                 GOTO(out, rc = -ENOMEM);
882         /* XXX FIXME bug 249 */
883         req->rq_request_portal = MDS_READPAGE_PORTAL;
884
885         lustre_pack_secdesc(req, size[0]);
886
887         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
888         if (desc == NULL)
889                 GOTO(out, rc = -ENOMEM);
890         /* NB req now owns desc and will free it when it gets freed */
891
892         ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
893         mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
894
895         req->rq_replen = lustre_msg_size(1, &size[1]);
896         rc = ptlrpc_queue_wait(req);
897
898         if (rc == 0) {
899                 body = lustre_swab_repbuf(req, 0, sizeof (*body),
900                                           lustre_swab_mds_body);
901                 if (body == NULL) {
902                         CERROR("Can't unpack mds_body\n");
903                         GOTO(out, rc = -EPROTO);
904                 }
905
906                 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
907                         CERROR ("Unexpected # bytes transferred: %d"
908                                 " (%ld expected)\n",
909                                 req->rq_bulk->bd_nob_transferred,
910                                 PAGE_CACHE_SIZE);
911                         GOTO (out, rc = -EPROTO);
912                 }
913         }
914
915         EXIT;
916  out:
917         *request = req;
918         return rc;
919 }
920
921 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
922                          void *karg, void *uarg)
923 {
924         struct obd_device *obd = exp->exp_obd;
925         struct obd_ioctl_data *data = karg;
926         struct obd_import *imp = obd->u.cli.cl_import;
927         struct llog_ctxt *ctxt;
928         int rc;
929         ENTRY;
930
931 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
932         MOD_INC_USE_COUNT;
933 #else
934         if (!try_module_get(THIS_MODULE)) {
935                 CERROR("Can't get module. Is it alive?");
936                 return -EINVAL;
937         }
938 #endif
939         switch (cmd) {
940         case OBD_IOC_CLIENT_RECOVER:
941                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
942                 if (rc < 0)
943                         GOTO(out, rc);
944                 GOTO(out, rc = 0);
945         case IOC_OSC_SET_ACTIVE:
946                 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
947                 GOTO(out, rc);
948         case IOC_OSC_CTL_RECOVERY:
949                 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
950                 GOTO(out, rc);
951         case OBD_IOC_PARSE: {
952                 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
953                                         LLOG_CONFIG_REPL_CTXT);
954                 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
955                 GOTO(out, rc);
956         }
957 #ifdef __KERNEL__
958         case OBD_IOC_LLOG_INFO:
959         case OBD_IOC_LLOG_PRINT: {
960                 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
961                 rc = llog_ioctl(ctxt, cmd, data);
962
963                 GOTO(out, rc);
964         }
965 #endif
966         default:
967                 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
968                 GOTO(out, rc = -ENOTTY);
969         }
970 out:
971 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
972         MOD_DEC_USE_COUNT;
973 #else
974         module_put(THIS_MODULE);
975 #endif
976
977         return rc;
978 }
979
980 int mdc_set_info(struct obd_export *exp, obd_count keylen,
981                  void *key, obd_count vallen, void *val)
982 {
983         int rc = -EINVAL;
984
985         if (keylen == strlen("initial_recov") &&
986             memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
987                 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
988                 if (vallen != sizeof(int))
989                         RETURN(-EINVAL);
990                 imp->imp_initial_recov = *(int *)val;
991                 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
992                        exp->exp_obd->obd_name,
993                        imp->imp_initial_recov);
994                 RETURN(0);
995         } else if ((keylen >= strlen("crypto_type")) && 
996                     strcmp(key, "crypto_type") == 0) {
997                 struct ptlrpc_request *req;
998                 char *bufs[2] = {key, val};
999                 int rc, size[2] = {keylen, vallen};
1000
1001                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1002                                       OST_SET_INFO, 2, size, bufs);
1003                 if (req == NULL)
1004                         RETURN(-ENOMEM);
1005
1006                 req->rq_replen = lustre_msg_size(0, NULL);
1007                 rc = ptlrpc_queue_wait(req);
1008                 ptlrpc_req_finished(req);
1009                 RETURN(rc);
1010         } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1011                 struct obd_import *imp = class_exp2cliimp(exp);
1012                 imp->imp_server_timeout = 1;
1013                 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1014                 RETURN(0);
1015         } else if (keylen == strlen("sec") &&
1016                    memcmp(key, "sec", keylen) == 0) {
1017                 struct client_obd *cli = &exp->exp_obd->u.cli;
1018
1019                 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
1020                 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
1021                         CERROR("unrecognized security type %s\n", (char*) val);
1022                         RETURN(-EINVAL);
1023                 }
1024
1025                 RETURN(0);
1026         } else if (keylen == strlen("sec_flags") &&
1027                    memcmp(key, "sec_flags", keylen) == 0) {
1028                 struct client_obd *cli = &exp->exp_obd->u.cli;
1029
1030                 cli->cl_sec_flags = *((unsigned long *) val);
1031                 RETURN(0);
1032         } else if (keylen == strlen("flush_cred") &&
1033                    memcmp(key, "flush_cred", keylen) == 0) {
1034                 struct client_obd *cli = &exp->exp_obd->u.cli;
1035
1036                 if (cli->cl_import)
1037                         ptlrpcs_import_flush_current_creds(cli->cl_import);
1038                 RETURN(0);
1039         } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
1040                 struct client_obd *cl = &exp->exp_obd->u.cli;
1041                 if (vallen != sizeof(int))
1042                         RETURN(-EINVAL);
1043                 cl->cl_async = *(int *)val;
1044                 CDEBUG(D_HA, "%s: set async = %d\n",
1045                        exp->exp_obd->obd_name, cl->cl_async);
1046                 RETURN(0);
1047         } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
1048                 struct ptlrpc_request *req;
1049                 char *bufs[2] = {key, val};
1050                 int rc, size[2] = {keylen, vallen};
1051
1052                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1053                                       OST_SET_INFO, 2, size, bufs);
1054                 if (req == NULL)
1055                         RETURN(-ENOMEM);
1056
1057                 req->rq_replen = lustre_msg_size(0, NULL);
1058                 rc = ptlrpc_queue_wait(req);
1059                 ptlrpc_req_finished(req);
1060                 RETURN(rc);
1061         } else if (keylen == 5 && strcmp(key, "audit") == 0) {
1062                 struct ptlrpc_request *req;
1063                 char *bufs[2] = {key, val};
1064                 int rc, size[2] = {keylen, vallen};
1065
1066                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1067                                       OST_SET_INFO, 2, size, bufs);
1068                 if (req == NULL)
1069                         RETURN(-ENOMEM);
1070
1071                 req->rq_replen = lustre_msg_size(0, NULL);
1072                 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
1073                                    lustre_swab_audit_attr);
1074                 rc = ptlrpc_queue_wait(req);
1075                 ptlrpc_req_finished(req);
1076
1077                 RETURN(rc);
1078         } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
1079                 struct ptlrpc_request *req;
1080                 struct lustre_id *ids = (struct lustre_id *)val;
1081                 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
1082                 int rc, size[3] = {keylen, sizeof(struct lustre_id), 
1083                                    sizeof(struct lustre_id)};
1084
1085                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1086                                       OST_SET_INFO, 3, size, bufs);
1087                 if (req == NULL)
1088                         RETURN(-ENOMEM);
1089
1090                 req->rq_replen = lustre_msg_size(0, NULL);
1091                 rc = ptlrpc_queue_wait(req);
1092                 ptlrpc_req_finished(req);
1093                 RETURN(rc);
1094         }
1095         RETURN(rc);
1096 }
1097
1098 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1099                       unsigned long max_age)
1100 {
1101         struct obd_statfs *msfs;
1102         struct ptlrpc_request *req;
1103         int rc, size = sizeof(*msfs);
1104         ENTRY;
1105
1106         /* We could possibly pass max_age in the request (as an absolute
1107          * timestamp or a "seconds.usec ago") so the target can avoid doing
1108          * extra calls into the filesystem if that isn't necessary (e.g.
1109          * during mount that would help a bit).  Having relative timestamps
1110          * is not so great if request processing is slow, while absolute
1111          * timestamps are not ideal because they need time synchronization. */
1112         req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1113                               MDS_STATFS, 0, NULL, NULL);
1114         if (!req)
1115                 RETURN(-ENOMEM);
1116
1117         req->rq_replen = lustre_msg_size(1, &size);
1118
1119         mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1120         rc = ptlrpc_queue_wait(req);
1121         mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1122
1123         if (rc) {
1124                 /* this can be LMV fake import, whcih is not connected. */
1125                 if (!req->rq_import->imp_connection)
1126                         memset(osfs, 0, sizeof(*osfs));
1127                 GOTO(out, rc);
1128         }
1129
1130         msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1131                                   lustre_swab_obd_statfs);
1132         if (msfs == NULL) {
1133                 CERROR("Can't unpack obd_statfs\n");
1134                 GOTO(out, rc = -EPROTO);
1135         }
1136
1137         memcpy(osfs, msfs, sizeof (*msfs));
1138         EXIT;
1139 out:
1140         ptlrpc_req_finished(req);
1141         return rc;
1142 }
1143
1144 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1145                    struct obd_client_handle *handle, int flag)
1146 {
1147         struct ptlrpc_request *req;
1148         struct mds_body *body;
1149         int rc, size[2] = {0, sizeof(*body)};
1150         ENTRY;
1151
1152         //size[0] = lustre_secdesc_size();
1153
1154         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1155                               MDS_PIN, 2, size, NULL);
1156         if (req == NULL)
1157                 RETURN(-ENOMEM);
1158
1159         //lustre_pack_secdesc(req, size[0]);
1160
1161         body = lustre_msg_buf(req->rq_reqmsg, 
1162                               MDS_REQ_REC_OFF, sizeof(*body));
1163
1164         /* FIXME-UMKA: here should be also mdsnum and fid. */
1165         mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1166         body->flags = flag;
1167
1168         req->rq_replen = lustre_msg_size(1, &size[1]);
1169
1170         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1171         rc = ptlrpc_queue_wait(req);
1172         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1173         if (rc) {
1174                 CERROR("pin failed: %d\n", rc);
1175                 ptlrpc_req_finished(req);
1176                 RETURN(rc);
1177         }
1178
1179         body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1180         if (body == NULL) {
1181                 ptlrpc_req_finished(req);
1182                 RETURN(rc);
1183         }
1184
1185         memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1186         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1187
1188         OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1189         if (handle->och_mod == NULL) {
1190                 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1191                 RETURN(-ENOMEM);
1192         }
1193         handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1194
1195         RETURN(rc);
1196 }
1197
1198 static int mdc_unpin(struct obd_export *exp,
1199                      struct obd_client_handle *handle, int flag)
1200 {
1201         struct ptlrpc_request *req;
1202         struct mds_body *body;
1203         int rc, size[2] = {0, sizeof(*body)};
1204         ENTRY;
1205
1206         if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1207                 RETURN(0);
1208
1209         //size[0] = lustre_secdesc_size();
1210
1211         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1212                               MDS_CLOSE, 2, size, NULL);
1213         if (req == NULL)
1214                 RETURN(-ENOMEM);
1215
1216         //lustre_pack_secdesc(req, size[0]);
1217
1218         body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1219         memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1220         body->flags = flag;
1221
1222         req->rq_replen = lustre_msg_size(0, NULL);
1223         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1224         rc = ptlrpc_queue_wait(req);
1225         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1226
1227         if (rc != 0)
1228                 CERROR("unpin failed: %d\n", rc);
1229
1230         ptlrpc_req_finished(req);
1231         ptlrpc_req_finished(handle->och_mod->mod_open_req);
1232         OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1233         RETURN(rc);
1234 }
1235
1236 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1237              struct ptlrpc_request **request)
1238 {
1239         struct ptlrpc_request *req;
1240         struct mds_body *body;
1241         int size[2] = {0, sizeof(*body)};
1242         int rc;
1243         ENTRY;
1244
1245         //size[0] = lustre_secdesc_size();
1246
1247         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1248                               MDS_SYNC, 2, size, NULL);
1249         if (!req)
1250                 RETURN(rc = -ENOMEM);
1251
1252         //lustre_pack_secdesc(req, size[0]);
1253
1254         if (id) {
1255                 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1256                                       sizeof (*body));
1257                 memcpy(&body->id1, id, sizeof(*id));
1258         }
1259
1260         req->rq_replen = lustre_msg_size(1, &size[1]);
1261
1262         rc = ptlrpc_queue_wait(req);
1263         if (rc || request == NULL)
1264                 ptlrpc_req_finished(req);
1265         else
1266                 *request = req;
1267
1268         RETURN(rc);
1269 }
1270
1271 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1272                             enum obd_import_event event)
1273 {
1274         int rc = 0;
1275
1276         LASSERT(imp->imp_obd == obd);
1277
1278         switch (event) {
1279         case IMP_EVENT_DISCON: {
1280                 break;
1281         }
1282         case IMP_EVENT_INACTIVE: {
1283                 if (obd->obd_observer)
1284                         rc = obd_notify(obd->obd_observer, obd, 0, 0);
1285                 break;
1286         }
1287         case IMP_EVENT_INVALIDATE: {
1288                 struct ldlm_namespace *ns = obd->obd_namespace;
1289
1290                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1291
1292                 break;
1293         }
1294         case IMP_EVENT_ACTIVE: {
1295                 if (obd->obd_observer)
1296                         rc = obd_notify(obd->obd_observer, obd, 1, 0);
1297                 break;
1298         }
1299         default:
1300                 CERROR("Unknown import event %d\n", event);
1301                 LBUG();
1302         }
1303         RETURN(rc);
1304 }
1305
1306 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1307 {
1308         struct lprocfs_static_vars lvars;
1309
1310         lprocfs_init_vars(mdc, &lvars);
1311         return lprocfs_obd_attach(dev, lvars.obd_vars);
1312 }
1313
1314 static int mdc_detach(struct obd_device *dev)
1315 {
1316         return lprocfs_obd_detach(dev);
1317 }
1318
1319 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1320 {
1321         struct client_obd *cli = &obd->u.cli;
1322         int rc;
1323         ENTRY;
1324
1325         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1326         if (!cli->cl_rpc_lock)
1327                 RETURN(-ENOMEM);
1328         mdc_init_rpc_lock(cli->cl_rpc_lock);
1329
1330         ptlrpcd_addref();
1331
1332         OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1333         if (!cli->cl_setattr_lock)
1334                 GOTO(err_rpc_lock, rc = -ENOMEM);
1335         mdc_init_rpc_lock(cli->cl_setattr_lock);
1336
1337         OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1338         if (!cli->cl_close_lock)
1339                 GOTO(err_setattr_lock, rc = -ENOMEM);
1340         mdc_init_rpc_lock(cli->cl_close_lock);
1341
1342         rc = client_obd_setup(obd, len, buf);
1343         if (rc)
1344                 GOTO(err_close_lock, rc);
1345
1346         rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1347         if (rc) {
1348                 mdc_cleanup(obd, 0);
1349                 CERROR("failed to setup llogging subsystems\n");
1350         }
1351
1352         RETURN(rc);
1353
1354 err_close_lock:
1355         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1356 err_setattr_lock:
1357         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1358 err_rpc_lock:
1359         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1360         ptlrpcd_decref();
1361         RETURN(rc);
1362 }
1363
1364 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1365 {
1366         struct obd_device *obd = exp->exp_obd;
1367         struct client_obd *cli = &obd->u.cli;
1368         ENTRY;
1369
1370         if (cli->cl_max_mds_easize < easize)
1371                 cli->cl_max_mds_easize = easize;
1372         if (cli->cl_max_mds_cookiesize < cookiesize)
1373                 cli->cl_max_mds_cookiesize = cookiesize;
1374         RETURN(0);
1375 }
1376
1377 static int mdc_precleanup(struct obd_device *obd, int flags)
1378 {
1379         int rc = 0;
1380         
1381         rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1382         if (rc != 0)
1383                 CERROR("failed to cleanup llogging subsystems\n");
1384
1385         RETURN(rc);
1386 }
1387
1388 static int mdc_cleanup(struct obd_device *obd, int flags)
1389 {
1390         struct client_obd *cli = &obd->u.cli;
1391
1392         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1393         OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1394         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1395
1396         ptlrpcd_decref();
1397
1398         return client_obd_cleanup(obd, flags);
1399 }
1400
1401
1402 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
1403                          struct obd_device *tgt, int count,
1404                          struct llog_catid *logid)
1405 {
1406         struct llog_ctxt *ctxt;
1407         int rc;
1408         ENTRY;
1409
1410         rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1411                             &llog_client_ops);
1412         if (rc == 0) {
1413                 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1414                 ctxt->loc_imp = obd->u.cli.cl_import;
1415         }
1416
1417         RETURN(rc);
1418 }
1419
1420 static int mdc_llog_finish(struct obd_device *obd,
1421                            struct obd_llogs *llogs, int count)
1422 {
1423         int rc;
1424         ENTRY;
1425
1426         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1427         RETURN(rc);
1428 }
1429
1430 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1431                                            struct lustre_id *id)
1432 {
1433        ENTRY;
1434        RETURN(exp->exp_obd);
1435 }
1436
1437 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1438                         void *key, __u32 *valsize, void *val)
1439 {
1440         struct ptlrpc_request *req;
1441         char *bufs[1] = {key};
1442         int rc = 0;
1443         ENTRY;
1444         
1445         if (!valsize || !val)
1446                 RETURN(-EFAULT);
1447
1448         if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1449                 struct obd_import *imp;
1450                 struct obd_connect_data *data;
1451
1452                 imp = class_exp2cliimp(exp);
1453                 if (!imp) {
1454                         LBUG();
1455                         RETURN(-EINVAL);
1456                 }
1457
1458                 if (imp->imp_state != LUSTRE_IMP_FULL) {
1459                         CERROR("import state not full\n");
1460                         RETURN(-EINVAL);
1461                 }
1462
1463                 data = &imp->imp_connect_data;
1464                 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1465                         *((int *)val) = 1;
1466                         RETURN(0);
1467                 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1468                         *((int *)val) = 0;
1469                         RETURN(0);
1470                 }
1471                 CERROR("no remote flag set?\n");
1472                 RETURN(-EINVAL);
1473         }
1474
1475         if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1476             (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1477             (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1478             (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1479             (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1480             (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1481                 RETURN(-EPROTO);
1482                 
1483         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1484                               OST_GET_INFO, 1, (int *)&keylen, bufs);
1485         if (req == NULL)
1486                 RETURN(-ENOMEM);
1487
1488         req->rq_replen = lustre_msg_size(1, (int *)valsize);
1489         rc = ptlrpc_queue_wait(req);
1490         if (rc)
1491                 GOTO(out_req, rc);
1492
1493         if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1494             (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1495                 struct lustre_id *reply;
1496                 
1497                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1498                                            lustre_swab_lustre_id);
1499                 if (reply == NULL) {
1500                         CERROR("Can't unpack %s\n", (char *)key);
1501                         GOTO(out_req, rc = -EPROTO);
1502                 }
1503
1504                 *(struct lustre_id *)val = *reply;
1505         } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1506                 struct lov_desc *reply;
1507                 
1508                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1509                                            lustre_swab_lov_desc);
1510                 if (reply == NULL) {
1511                         CERROR("Can't unpack %s\n", (char *)key);
1512                         GOTO(out_req, rc = -EPROTO);
1513                 }
1514
1515                 *(struct lov_desc *)val = *reply;
1516                 RETURN(0);
1517         } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1518                 struct fid_extent *reply;
1519                 
1520                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1521                                            lustre_swab_fid_extent);
1522                 if (reply == NULL) {
1523                         CERROR("Can't unpack %s\n", (char *)key);
1524                         GOTO(out_req, rc = -EPROTO);
1525                 }
1526
1527                 *(struct fid_extent *)val = *reply;
1528                 RETURN(0);
1529         } else {
1530                 __u32 *reply;
1531                 
1532                 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1533                                            lustre_swab_generic_32s);
1534                 if (reply == NULL) {
1535                         CERROR("Can't unpack %s\n", (char *)key);
1536                         GOTO(out_req, rc = -EPROTO);
1537                 }
1538                 *((__u32 *)val) = *reply;
1539         }
1540 out_req:
1541         ptlrpc_req_finished(req);
1542         RETURN(rc);
1543 }
1544
1545 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1546                    void *acl, int acl_size, struct lov_stripe_md **ea,
1547                    struct obd_trans_info *oti)
1548 {
1549         struct ptlrpc_request *request;
1550         struct ost_body *body;
1551         char *acl_buf;
1552         int rc, size[2] = { sizeof(*body), acl_size };
1553         ENTRY;
1554
1555         LASSERT(oa);
1556
1557         request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1558                                   OST_CREATE, 2, size, NULL);
1559         if (!request)
1560                 GOTO(out_req, rc = -ENOMEM);
1561
1562         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1563         memcpy(&body->oa, oa, sizeof(body->oa));
1564
1565         if (acl_size) {
1566                 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1567                 memcpy(acl_buf, acl, acl_size);
1568         }
1569
1570         request->rq_replen = lustre_msg_size(1, size);
1571         rc = ptlrpc_queue_wait(request);
1572         if (rc)
1573                 GOTO(out_req, rc);
1574
1575         body = lustre_swab_repbuf(request, 0, sizeof(*body),
1576                                   lustre_swab_ost_body);
1577         if (body == NULL) {
1578                 CERROR ("can't unpack ost_body\n");
1579                 GOTO (out_req, rc = -EPROTO);
1580         }
1581
1582         memcpy(oa, &body->oa, sizeof(*oa));
1583
1584         /* store ino/generation for recovery */
1585         body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1586         body->oa.o_id = oa->o_id;
1587         body->oa.o_generation = oa->o_generation;
1588         body->oa.o_fid = oa->o_fid;
1589         body->oa.o_mds = oa->o_mds;
1590
1591         CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1592         EXIT;
1593 out_req:
1594         ptlrpc_req_finished(request);
1595         return rc;
1596 }
1597
1598 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1599             struct lov_stripe_md *ea, obd_count oa_bufs,
1600             struct brw_page *pgarr, struct obd_trans_info *oti)
1601 {
1602         struct ptlrpc_bulk_desc *desc;
1603         struct niobuf_remote *niobuf;
1604         struct ptlrpc_request *req;
1605         struct obd_ioobj *ioobj;
1606         struct ost_body *body;
1607         int err, opc, i;
1608         int size[3];
1609
1610         opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1611         
1612         size[0] = sizeof(*body);
1613         size[1] = sizeof(*ioobj);
1614         size[2] = oa_bufs * sizeof(*niobuf);
1615
1616         req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1617                               3, size, NULL);
1618         LASSERT(req != NULL);
1619
1620         if (opc == OST_WRITE)
1621                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1622                                             OST_BULK_PORTAL);
1623         else
1624                 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1625                                             OST_BULK_PORTAL);
1626         LASSERT(desc != NULL);
1627
1628         body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1629         ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1630         niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1631
1632         memcpy(&body->oa, oa, sizeof(*oa));
1633         obdo_to_ioobj(oa, ioobj);
1634         ioobj->ioo_bufcnt = oa_bufs;
1635
1636         for (i = 0; i < oa_bufs; i++, niobuf++) {
1637                 struct brw_page *pg = &pgarr[i];
1638
1639                 LASSERT(pg->count > 0);
1640                 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1641
1642                 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1643                                       pg->count);
1644
1645                 niobuf->offset = pg->disk_offset;
1646                 niobuf->len = pg->count;
1647                 niobuf->flags = pg->flag;
1648         }
1649
1650         /* size[0] still sizeof (*body) */
1651         if (opc == OST_WRITE) {
1652                 /* 1 RC per niobuf */
1653                 size[1] = sizeof(__u32) * oa_bufs;
1654                 req->rq_replen = lustre_msg_size(2, size);
1655         } else {
1656                 /* 1 RC for the whole I/O */
1657                 req->rq_replen = lustre_msg_size(1, size);
1658         }
1659         err = ptlrpc_queue_wait(req);
1660         LASSERT(err == 0);
1661
1662         ptlrpc_req_finished(req);
1663         return 0;
1664 }
1665
1666 static int mdc_valid_attrs(struct obd_export *exp,
1667                            struct lustre_id *id)
1668 {
1669         struct ldlm_res_id res_id = { .name = {0} };
1670         struct obd_device *obd = exp->exp_obd;
1671         struct lustre_handle lockh;
1672         ldlm_policy_data_t policy;
1673         int flags;
1674         ENTRY;
1675
1676         res_id.name[0] = id_fid(id);
1677         res_id.name[1] = id_group(id);
1678         policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1679
1680         CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1681                res_id.name[0]);
1682
1683         /* FIXME use LDLM_FL_TEST_LOCK instead */
1684         flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1685         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1686                             LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1687                 ldlm_lock_decref(&lockh, LCK_PR);
1688                 RETURN(1);
1689         }
1690
1691         if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1692                             LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1693                 ldlm_lock_decref(&lockh, LCK_PW);
1694                 RETURN(1);
1695         }
1696         RETURN(0);
1697 }
1698
1699 static int mdc_change_cbdata_name(struct obd_export *exp,
1700                                   struct lustre_id *pid,
1701                                   char *name, int len,
1702                                   struct lustre_id *cid,
1703                                   ldlm_iterator_t it, void *data)
1704 {
1705         int rc;
1706         rc = mdc_change_cbdata(exp, cid, it, data);
1707         RETURN(rc);
1708 }
1709
1710 struct obd_ops mdc_obd_ops = {
1711         .o_owner         = THIS_MODULE,
1712         .o_attach        = mdc_attach,
1713         .o_detach        = mdc_detach,
1714         .o_setup         = mdc_setup,
1715         .o_precleanup    = mdc_precleanup,
1716         .o_cleanup       = mdc_cleanup,
1717         .o_add_conn      = client_import_add_conn,
1718         .o_del_conn      = client_import_del_conn,
1719         .o_connect       = client_connect_import,
1720         .o_disconnect    = client_disconnect_export,
1721         .o_iocontrol     = mdc_iocontrol,
1722         .o_packmd        = mdc_packmd,
1723         .o_unpackmd      = mdc_unpackmd,
1724         .o_statfs        = mdc_statfs,
1725         .o_pin           = mdc_pin,
1726         .o_unpin         = mdc_unpin,
1727         .o_import_event  = mdc_import_event,
1728         .o_llog_init     = mdc_llog_init,
1729         .o_llog_finish   = mdc_llog_finish,
1730         .o_create        = mdc_obj_create,
1731         .o_set_info      = mdc_set_info,
1732         .o_get_info      = mdc_get_info,
1733         .o_brw           = mdc_brw,
1734         .o_cancel_unused = mdc_cancel_unused,
1735         .o_init_ea_size  = mdc_init_ea_size,
1736 };
1737
1738 struct md_ops mdc_md_ops = {
1739         .m_getstatus     = mdc_getstatus,
1740         .m_getattr       = mdc_getattr,
1741         .m_close         = mdc_close,
1742         .m_create        = mdc_create,
1743         .m_done_writing  = mdc_done_writing,
1744         .m_enqueue       = mdc_enqueue,
1745         .m_getattr_lock  = mdc_getattr_lock,
1746         .m_intent_lock   = mdc_intent_lock,
1747         .m_link          = mdc_link,
1748         .m_rename        = mdc_rename,
1749         .m_setattr       = mdc_setattr,
1750         .m_sync          = mdc_sync,
1751         .m_readpage      = mdc_readpage,
1752         .m_unlink        = mdc_unlink,
1753         .m_valid_attrs   = mdc_valid_attrs,
1754         .m_req2lustre_md = mdc_req2lustre_md,
1755         .m_set_open_replay_data   = mdc_set_open_replay_data,
1756         .m_clear_open_replay_data = mdc_clear_open_replay_data,
1757         .m_store_inode_generation = mdc_store_inode_generation,
1758         .m_set_lock_data = mdc_set_lock_data,
1759         .m_get_real_obd  = mdc_get_real_obd,
1760         .m_change_cbdata_name = mdc_change_cbdata_name,
1761         .m_change_cbdata = mdc_change_cbdata,
1762         .m_access_check  = mdc_access_check,
1763 };
1764
1765 int __init mdc_init(void)
1766 {
1767         struct lprocfs_static_vars lvars;
1768         
1769         lprocfs_init_vars(mdc, &lvars);
1770         return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1771                                    lvars.module_vars, OBD_MDC_DEVICENAME);
1772 }
1773
1774 #ifdef __KERNEL__
1775 static void /*__exit*/ mdc_exit(void)
1776 {
1777         class_unregister_type(OBD_MDC_DEVICENAME);
1778 }
1779
1780 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1781 MODULE_DESCRIPTION("Lustre Metadata Client");
1782 MODULE_LICENSE("GPL");
1783
1784 EXPORT_SYMBOL(mdc_req2lustre_md);
1785 EXPORT_SYMBOL(mdc_change_cbdata);
1786 EXPORT_SYMBOL(mdc_getstatus);
1787 EXPORT_SYMBOL(mdc_getattr);
1788 EXPORT_SYMBOL(mdc_getattr_lock);
1789 EXPORT_SYMBOL(mdc_create);
1790 EXPORT_SYMBOL(mdc_unlink);
1791 EXPORT_SYMBOL(mdc_rename);
1792 EXPORT_SYMBOL(mdc_link);
1793 EXPORT_SYMBOL(mdc_readpage);
1794 EXPORT_SYMBOL(mdc_setattr);
1795 EXPORT_SYMBOL(mdc_close);
1796 EXPORT_SYMBOL(mdc_done_writing);
1797 EXPORT_SYMBOL(mdc_sync);
1798 EXPORT_SYMBOL(mdc_set_open_replay_data);
1799 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1800 EXPORT_SYMBOL(mdc_store_inode_generation);
1801
1802 module_init(mdc_init);
1803 module_exit(mdc_exit);
1804 #endif