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