Whamcloud - gitweb
- changed name convention in cobd, thus all MD related methods have _md_ prefix like...
[fs/lustre-release.git] / lustre / cobd / cache_obd.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
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 #define DEBUG_SUBSYSTEM S_COBD
23
24 #include <linux/version.h>
25 #include <linux/init.h>
26 #include <linux/obd_support.h>
27 #include <linux/lustre_lib.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_idl.h>
30 #include <linux/lustre_log.h>
31 #include <linux/lustre_mds.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_cache.h>
34 #include <linux/obd_lmv.h>
35
36 static int cobd_attach(struct obd_device *obd,
37                        obd_count len, void *buf)
38 {
39         struct lprocfs_static_vars lvars;
40         
41         lprocfs_init_vars(cobd, &lvars);
42         return lprocfs_obd_attach(obd, lvars.obd_vars);
43 }
44
45 static int cobd_detach(struct obd_device *obd)
46 {
47         return lprocfs_obd_detach(obd);
48 }
49
50 static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
51 {
52         struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
53         struct cache_obd  *cobd = &obd->u.cobd;
54         struct obd_device *master_obd, *cache_obd;
55         struct lustre_handle conn = { 0 };
56         int rc = 0;
57         ENTRY;
58
59         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
60             lustre_cfg_buf(lcfg, 1) == NULL) {
61                 CERROR("%s: setup requires master device name\n", 
62                        obd->obd_name);
63                 RETURN(-EINVAL);
64         }
65
66         if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 ||
67             lustre_cfg_buf(lcfg, 2) == NULL) {
68                 CERROR("%s: setup requires cache device name\n",
69                        obd->obd_name);
70                 RETURN(-EINVAL);
71         }
72         sema_init(&cobd->sem, 1);
73
74         /*get the cache obd name and master name */
75         OBD_ALLOC(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
76         if (!cobd->master_name) 
77                 RETURN(-ENOMEM);
78         memcpy(cobd->master_name, lustre_cfg_string(lcfg, 1), 
79                LUSTRE_CFG_BUFLEN(lcfg, 1));
80         
81         OBD_ALLOC(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
82         if (!cobd->cache_name) {
83                 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
84                 RETURN(-ENOMEM);
85         }
86         memcpy(cobd->cache_name, lustre_cfg_string(lcfg, 2), 
87                LUSTRE_CFG_BUFLEN(lcfg, 2));
88
89         /* getting master obd */
90         master_obd = class_name2obd(cobd->master_name);
91         if (!master_obd) {
92                 CERROR("can't find master obd by name %s\n",
93                        cobd->master_name);
94                 GOTO(put_names, rc = -EINVAL);
95         }
96
97         /* connecting master */
98         memset(&conn, 0, sizeof(conn));
99         rc = class_connect(&conn, master_obd, &obd->obd_uuid);
100         if (rc)
101                GOTO(put_names, rc);
102         
103         cobd->master_exp = class_conn2export(&conn);
104
105         /* getting cache obd */
106         cache_obd = class_name2obd(cobd->cache_name);
107         if (!cache_obd) {
108                 class_disconnect(cobd->master_exp, 0);
109                 CERROR("can't find cache obd by name %s\n",
110                        cobd->cache_name);
111                 GOTO(put_names, rc);
112         }
113
114         /* connecting cache */
115         memset(&conn, 0, sizeof(conn));
116         rc = class_connect(&conn, cache_obd, &obd->obd_uuid);
117         if (rc) {
118                 class_disconnect(cobd->master_exp, 0);
119                 GOTO(put_names, rc);
120         }
121         cobd->cache_exp = class_conn2export(&conn);
122         
123         /* default set cache on */
124         cobd->cache_on = 1;
125         EXIT;
126 put_names:
127         if (rc) {
128                 if (cobd->master_name) {
129                         OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
130                         cobd->master_name = NULL;
131                 } 
132                 if (cobd->cache_name) {
133                         OBD_FREE(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
134                         cobd->cache_name = NULL;
135                 }
136         
137         }
138         RETURN(rc);
139 }
140
141 static int cobd_cleanup(struct obd_device *obd, int flags)
142 {
143         struct cache_obd  *cobd = &obd->u.cobd;
144         int rc = 0;
145         ENTRY;
146
147         if (!list_empty(&obd->obd_exports))
148                 RETURN(-EBUSY);
149
150         if (cobd->cache_name)
151                 OBD_FREE(cobd->cache_name, 
152                          strlen(cobd->cache_name) + 1);
153         if (cobd->master_name)
154                 OBD_FREE(cobd->master_name, 
155                          strlen(cobd->master_name) + 1);
156         
157         rc = class_disconnect(cobd->master_exp, flags);
158         if (rc) {
159                 CERROR("error disconnecting master, err %d\n",
160                        rc);
161         }
162         rc = class_disconnect(cobd->cache_exp, flags);
163         if (rc) {
164                 CERROR("error disconnecting master, err %d\n",
165                        rc);
166         }
167
168         RETURN(0);
169 }
170
171 static inline struct obd_export *
172 cobd_get_exp(struct obd_device *obd)
173 {
174         struct cache_obd *cobd = &obd->u.cobd;
175         if (cobd->cache_on) {
176                 CDEBUG(D_TRACE, "get cache exp %p \n", cobd->cache_exp); 
177                 if (cobd->cache_real_exp)
178                        return cobd->cache_real_exp;
179                 return cobd->cache_exp;
180         }
181         CDEBUG(D_TRACE, "get master exp %p \n", cobd->master_exp);
182         if (cobd->master_real_exp)
183                 return cobd->master_real_exp; 
184         return cobd->master_exp;
185 }
186
187 static int
188 client_obd_connect(struct obd_device *obd,
189                    struct obd_export *exp,
190                    struct lustre_handle *conn,
191                    struct obd_connect_data *data,
192                    unsigned long flags)
193
194         struct obd_device *cli_obd;
195         int rc = 0;
196         ENTRY;
197  
198         LASSERT(obd);
199         LASSERT(conn);
200         
201         cli_obd = class_exp2obd(exp);
202         if (cli_obd == NULL) 
203                 RETURN(-EINVAL);
204
205         rc = obd_connect(conn, cli_obd, &obd->obd_uuid, data, flags);
206         if (rc) 
207                 CERROR("error connecting err %d\n", rc);
208         
209         RETURN(rc);
210 }
211
212 static int
213 client_obd_disconnect(struct obd_device *obd,
214                       struct obd_export *exp,
215                       unsigned long flags)
216 {
217         struct obd_device *cli_obd;
218         int rc = 0;
219         ENTRY;
220
221         cli_obd = class_exp2obd(exp);
222         cli_obd->obd_no_recov = obd->obd_no_recov;
223         
224         rc = obd_disconnect(exp, flags);
225         if (rc) {
226                 CERROR("error disconnecting from %s, err %d\n",
227                        cli_obd->obd_name, rc);
228                 class_export_put(exp);
229         }
230         RETURN(rc);
231 }
232
233 static int
234 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
235              struct obd_uuid *cluuid, struct obd_connect_data *data,
236              unsigned long flags)
237 {
238         struct lustre_handle cache_conn = { 0 };
239         struct cache_obd *cobd = &obd->u.cobd;
240         struct obd_export *exp, *cobd_exp;
241         int rc = 0;
242         ENTRY;
243
244         rc = class_connect(conn, obd, cluuid);
245         if (rc)
246                 RETURN(rc);
247         exp = class_conn2export(conn);
248
249         cobd_exp = cobd_get_exp(obd);
250         
251         /* connecting cache */
252         rc = client_obd_connect(obd, cobd_exp, &cache_conn, 
253                                 data, flags);
254         if (rc)
255                 GOTO(err_discon, rc);
256        
257         cobd->cache_real_exp = class_conn2export(&cache_conn);
258         cobd->cache_on = 1;
259         EXIT;
260 err_discon:
261         if (rc)
262                 class_disconnect(exp, 0);
263         else
264                 class_export_put(exp);
265         RETURN(rc);
266 }
267
268 static int
269 cobd_disconnect(struct obd_export *exp, unsigned long flags)
270 {
271         struct obd_device *obd;
272         struct obd_export *cobd_exp;
273         int rc = 0;
274         ENTRY;
275         
276         LASSERT(exp != NULL);
277         obd = class_exp2obd(exp);
278         if (obd == NULL) {
279                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
280                        exp->exp_handle.h_cookie);
281                 RETURN(-EINVAL);
282         }
283         cobd_exp = cobd_get_exp(obd);
284         
285         rc = client_obd_disconnect(obd, cobd_exp, flags);
286
287         class_disconnect(exp, flags);
288         
289         RETURN(rc);
290 }
291
292 static int cobd_get_info(struct obd_export *exp, __u32 keylen,
293                          void *key, __u32 *vallen, void *val)
294 {
295         struct obd_device *obd = class_exp2obd(exp);
296         struct obd_export *cobd_exp;
297         
298         if (obd == NULL) {
299                 CERROR("invalid client cookie "LPX64"\n", 
300                        exp->exp_handle.h_cookie);
301                 return -EINVAL;
302         }
303         cobd_exp = cobd_get_exp(obd);
304
305         /* intercept cache utilisation info? */
306         return obd_get_info(cobd_exp, keylen, key, vallen, val);
307 }
308
309 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
310                          void *key, obd_count vallen, void *val)
311 {
312         struct obd_device *obd = class_exp2obd(exp);
313         struct obd_export *cobd_exp;
314
315         if (obd == NULL) {
316                 CERROR("invalid client cookie "LPX64"\n", 
317                        exp->exp_handle.h_cookie);
318                 return -EINVAL;
319         }
320         cobd_exp = cobd_get_exp(obd);
321         
322         /* intercept cache utilisation info? */
323         return obd_set_info(cobd_exp, keylen, key, vallen, val);
324 }
325
326 static int cobd_statfs(struct obd_device *obd,
327                        struct obd_statfs *osfs,
328                        unsigned long max_age)
329 {
330         struct obd_export *cobd_exp;
331
332         cobd_exp = cobd_get_exp(obd);
333         return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
334 }
335
336 static int cobd_dt_packmd(struct obd_export *exp,
337                           struct lov_mds_md **disk_tgt,
338                           struct lov_stripe_md *mem_src)
339 {
340         struct obd_device *obd = class_exp2obd(exp);
341         struct obd_export *cobd_exp;
342
343         if (obd == NULL) {
344                 CERROR("invalid client cookie "LPX64"\n", 
345                        exp->exp_handle.h_cookie);
346                 return -EINVAL;
347         }
348         cobd_exp = cobd_get_exp(obd);
349         return obd_packmd(cobd_exp, disk_tgt, mem_src);
350 }
351
352 static int cobd_dt_unpackmd(struct obd_export *exp,
353                             struct lov_stripe_md **mem_tgt,
354                             struct lov_mds_md *disk_src,
355                             int disk_len)
356 {
357         struct obd_device *obd = class_exp2obd(exp);
358         struct obd_export *cobd_exp;
359
360         if (obd == NULL) {
361                 CERROR("invalid client cookie "LPX64"\n", 
362                        exp->exp_handle.h_cookie);
363                 return -EINVAL;
364         }
365         cobd_exp = cobd_get_exp(obd);
366         return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
367 }
368
369 static int cobd_dt_create(struct obd_export *exp,
370                           struct obdo *obdo,
371                           void *acl, int acl_size,
372                           struct lov_stripe_md **ea,
373                           struct obd_trans_info *oti)
374 {
375         struct obd_device *obd = class_exp2obd(exp);
376         struct obd_export *cobd_exp;
377
378         if (obd == NULL) {
379                 CERROR("invalid client cookie "LPX64"\n", 
380                        exp->exp_handle.h_cookie);
381                 return -EINVAL;
382         }
383         cobd_exp = cobd_get_exp(obd);
384         return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
385 }
386
387 static int cobd_dt_destroy(struct obd_export *exp,
388                            struct obdo *obdo,
389                            struct lov_stripe_md *ea,
390                            struct obd_trans_info *oti)
391 {
392         struct obd_device *obd = class_exp2obd(exp);
393         struct obd_export *cobd_exp;
394
395         if (obd == NULL) {
396                 CERROR("invalid client cookie "LPX64"\n", 
397                        exp->exp_handle.h_cookie);
398                 return -EINVAL;
399         }
400         cobd_exp = cobd_get_exp(obd);
401         return obd_destroy(cobd_exp, obdo, ea, oti); 
402 }
403
404 static int cobd_dt_precleanup(struct obd_device *obd, int flags)
405 {
406         /* FIXME-WANGDI: do we need some cleanup here? */
407         return 0;
408 }
409
410 static int cobd_dt_getattr(struct obd_export *exp, struct obdo *oa,
411                            struct lov_stripe_md *ea)
412 {
413         struct obd_device *obd = class_exp2obd(exp);
414         struct obd_export *cobd_exp;
415
416         if (obd == NULL) {
417                 CERROR("invalid client cookie "LPX64"\n", 
418                        exp->exp_handle.h_cookie);
419                 return -EINVAL;
420         }
421         cobd_exp = cobd_get_exp(obd);
422         return obd_getattr(cobd_exp, oa, ea);
423 }
424
425 static int cobd_dt_getattr_async(struct obd_export *exp,
426                                  struct obdo *obdo, struct lov_stripe_md *ea,
427                                  struct ptlrpc_request_set *set)
428 {
429         struct obd_device *obd = class_exp2obd(exp);
430         struct obd_export *cobd_exp;
431
432         if (obd == NULL) {
433                 CERROR("invalid client cookie "LPX64"\n", 
434                        exp->exp_handle.h_cookie);
435                 return -EINVAL;
436         }
437         cobd_exp = cobd_get_exp(obd);
438         return obd_getattr_async(cobd_exp, obdo, ea, set);
439 }
440
441 static int cobd_dt_setattr(struct obd_export *exp, struct obdo *obdo,
442                            struct lov_stripe_md *ea,
443                            struct obd_trans_info *oti)
444 {
445         struct obd_device *obd = class_exp2obd(exp);
446         struct obd_export *cobd_exp;
447
448         if (obd == NULL) {
449                 CERROR("invalid client cookie "LPX64"\n", 
450                        exp->exp_handle.h_cookie);
451                 return -EINVAL;
452         }
453         cobd_exp = cobd_get_exp(obd);
454         return obd_setattr(cobd_exp, obdo, ea, oti);
455 }
456
457 static int cobd_dt_brw(int cmd, struct obd_export *exp, struct obdo *oa,
458                        struct lov_stripe_md *ea, obd_count oa_bufs,
459                        struct brw_page *pg, struct obd_trans_info *oti)
460 {
461         struct obd_device *obd = class_exp2obd(exp);
462         struct obd_export *cobd_exp;
463
464         if (obd == NULL) {
465                 CERROR("invalid client cookie "LPX64"\n", 
466                        exp->exp_handle.h_cookie);
467                 return -EINVAL;
468         }
469         cobd_exp = cobd_get_exp(obd);
470         return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
471 }
472
473 static int cobd_dt_brw_async(int cmd, struct obd_export *exp,
474                              struct obdo *oa, struct lov_stripe_md *ea,
475                              obd_count oa_bufs, struct brw_page *pg,
476                              struct ptlrpc_request_set *set,
477                              struct obd_trans_info *oti)
478 {
479         struct obd_device *obd = class_exp2obd(exp);
480         struct obd_export *cobd_exp;
481
482         if (obd == NULL) {
483                 CERROR("invalid client cookie "LPX64"\n", 
484                        exp->exp_handle.h_cookie);
485                 return -EINVAL;
486         }
487         cobd_exp = cobd_get_exp(obd);
488         return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs, 
489                              pg, set, oti);
490 }
491
492 static int cobd_dt_prep_async_page(struct obd_export *exp, 
493                                    struct lov_stripe_md *lsm,
494                                    struct lov_oinfo *loi, 
495                                    struct page *page, obd_off offset, 
496                                    struct obd_async_page_ops *ops, 
497                                    void *data, void **res)
498 {
499         struct obd_device *obd = class_exp2obd(exp);
500         struct obd_export *cobd_exp;
501
502         if (obd == NULL) {
503                 CERROR("invalid client cookie "LPX64"\n", 
504                        exp->exp_handle.h_cookie);
505                 return -EINVAL;
506         }
507         cobd_exp = cobd_get_exp(obd);
508         return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
509                                    ops, data, res);
510 }
511
512 static int cobd_dt_queue_async_io(struct obd_export *exp,
513                                   struct lov_stripe_md *lsm,
514                                   struct lov_oinfo *loi, void *cookie,
515                                   int cmd, obd_off off, int count,
516                                   obd_flags brw_flags, obd_flags async_flags)
517 {
518         struct obd_device *obd = class_exp2obd(exp);
519         struct obd_export *cobd_exp;
520
521         if (obd == NULL) {
522                 CERROR("invalid client cookie "LPX64"\n", 
523                        exp->exp_handle.h_cookie);
524                 return -EINVAL;
525         }
526         cobd_exp = cobd_get_exp(obd);
527         return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
528                                   brw_flags, async_flags);
529 }
530
531 static int cobd_dt_set_async_flags(struct obd_export *exp,
532                                    struct lov_stripe_md *lsm,
533                                    struct lov_oinfo *loi, void *cookie,
534                                    obd_flags async_flags)
535 {
536         struct obd_device *obd = class_exp2obd(exp);
537         struct obd_export *cobd_exp;
538
539         if (obd == NULL) {
540                 CERROR("invalid client cookie "LPX64"\n", 
541                        exp->exp_handle.h_cookie);
542                 return -EINVAL;
543         }
544         cobd_exp = cobd_get_exp(obd);
545         return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
546 }
547
548 static int cobd_dt_queue_group_io(struct obd_export *exp, 
549                                   struct lov_stripe_md *lsm, 
550                                   struct lov_oinfo *loi, 
551                                   struct obd_io_group *oig, 
552                                   void *cookie, int cmd, obd_off off, 
553                                   int count, obd_flags brw_flags,
554                                   obd_flags async_flags)
555 {
556         struct obd_device *obd = class_exp2obd(exp);
557         struct obd_export *cobd_exp;
558
559         if (obd == NULL) {
560                 CERROR("invalid client cookie "LPX64"\n", 
561                        exp->exp_handle.h_cookie);
562                 return -EINVAL;
563         }
564         cobd_exp = cobd_get_exp(obd);
565         return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
566                                   cmd, off, count, brw_flags, async_flags);
567 }
568
569 static int cobd_dt_trigger_group_io(struct obd_export *exp, 
570                                     struct lov_stripe_md *lsm, 
571                                     struct lov_oinfo *loi,
572                                     struct obd_io_group *oig)
573 {
574         struct obd_device *obd = class_exp2obd(exp);
575         struct obd_export *cobd_exp;
576
577         if (obd == NULL) {
578                 CERROR("invalid client cookie "LPX64"\n", 
579                        exp->exp_handle.h_cookie);
580                 return -EINVAL;
581         }
582         cobd_exp = cobd_get_exp(obd);
583         return obd_trigger_group_io(cobd_exp, lsm, loi, oig); 
584 }
585
586 static int cobd_dt_teardown_async_page(struct obd_export *exp,
587                                        struct lov_stripe_md *lsm,
588                                        struct lov_oinfo *loi, void *cookie)
589 {
590         struct obd_device *obd = class_exp2obd(exp);
591         struct obd_export *cobd_exp;
592
593         if (obd == NULL) {
594                 CERROR("invalid client cookie "LPX64"\n", 
595                        exp->exp_handle.h_cookie);
596                 return -EINVAL;
597         }
598         cobd_exp = cobd_get_exp(obd);
599         return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
600 }
601
602 static int cobd_dt_punch(struct obd_export *exp, struct obdo *oa,
603                          struct lov_stripe_md *ea, obd_size start,
604                          obd_size end, struct obd_trans_info *oti)
605 {
606         struct obd_device *obd = class_exp2obd(exp);
607         struct obd_export *cobd_exp;
608
609         if (obd == NULL) {
610                 CERROR("invalid client cookie "LPX64"\n", 
611                        exp->exp_handle.h_cookie);
612                 return -EINVAL;
613         }
614         cobd_exp = cobd_get_exp(obd);
615         return obd_punch(cobd_exp, oa, ea, start, end, oti);
616 }
617
618 static int cobd_dt_sync(struct obd_export *exp, struct obdo *oa,
619                         struct lov_stripe_md *ea, obd_size start, 
620                         obd_size end)
621 {
622         struct obd_device *obd = class_exp2obd(exp);
623         struct obd_export *cobd_exp;
624
625         if (obd == NULL) {
626                 CERROR("invalid client cookie "LPX64"\n", 
627                        exp->exp_handle.h_cookie);
628                 return -EINVAL;
629         }
630         cobd_exp = cobd_get_exp(obd);
631         return obd_sync(cobd_exp, oa, ea, start, end);
632 }
633
634 static int cobd_dt_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
635                            __u32 type, ldlm_policy_data_t *policy,
636                            __u32 mode, int *flags, void *bl_cb, void *cp_cb,
637                            void *gl_cb, void *data, __u32 lvb_len,
638                            void *lvb_swabber, struct lustre_handle *lockh)
639 {
640         struct obd_device *obd = class_exp2obd(exp);
641         struct obd_export *cobd_exp;
642
643         if (obd == NULL) {
644                 CERROR("invalid client cookie "LPX64"\n", 
645                        exp->exp_handle.h_cookie);
646                 return -EINVAL;
647         }
648         cobd_exp = cobd_get_exp(obd);
649         return obd_enqueue(cobd_exp, ea, type, policy, mode, flags, 
650                            bl_cb, cp_cb, gl_cb, data, lvb_len,
651                            lvb_swabber, lockh);
652 }
653
654 static int cobd_dt_match(struct obd_export *exp, struct lov_stripe_md *ea,
655                          __u32 type, ldlm_policy_data_t *policy, __u32 mode,
656                          int *flags, void *data, struct lustre_handle *lockh)
657 {
658         struct obd_device *obd = class_exp2obd(exp);
659         struct obd_export *cobd_exp;
660
661         if (obd == NULL) {
662                 CERROR("invalid client cookie "LPX64"\n", 
663                        exp->exp_handle.h_cookie);
664                 return -EINVAL;
665         }
666         cobd_exp = cobd_get_exp(obd);
667         return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
668                          lockh); 
669 }
670 static int cobd_dt_change_cbdata(struct obd_export *exp,
671                                  struct lov_stripe_md *lsm, 
672                                  ldlm_iterator_t it, void *data)
673 {
674         struct obd_device *obd = class_exp2obd(exp);
675         struct obd_export *cobd_exp;
676
677         if (obd == NULL) {
678                 CERROR("invalid client cookie "LPX64"\n", 
679                        exp->exp_handle.h_cookie);
680                 return -EINVAL;
681         }
682         cobd_exp = cobd_get_exp(obd);
683         return obd_change_cbdata(cobd_exp, lsm, it, data);
684 }
685
686 static int cobd_dt_cancel(struct obd_export *exp,
687                           struct lov_stripe_md *ea, __u32 mode,
688                           struct lustre_handle *lockh)
689 {
690         struct obd_device *obd = class_exp2obd(exp);
691         struct obd_export *cobd_exp;
692
693         if (obd == NULL) {
694                 CERROR("invalid client cookie "LPX64"\n", 
695                        exp->exp_handle.h_cookie);
696                 return -EINVAL;
697         }
698         cobd_exp = cobd_get_exp(obd);
699         return obd_cancel(cobd_exp, ea, mode, lockh);
700 }
701
702 static int cobd_dt_cancel_unused(struct obd_export *exp,
703                                  struct lov_stripe_md *ea,
704                                  int flags, void *opaque)
705 {
706         struct obd_device *obd = class_exp2obd(exp);
707         struct obd_export *cobd_exp;
708
709         if (obd == NULL) {
710                 CERROR("invalid client cookie "LPX64"\n", 
711                        exp->exp_handle.h_cookie);
712                 return -EINVAL;
713         }
714         cobd_exp = cobd_get_exp(obd);
715         return obd_cancel_unused(cobd_exp, ea, flags, opaque);
716 }
717
718 static int cobd_dt_preprw(int cmd, struct obd_export *exp,
719                           struct obdo *oa, int objcount,
720                           struct obd_ioobj *obj, int niocount,
721                           struct niobuf_remote *nb,
722                           struct niobuf_local *res,
723                           struct obd_trans_info *oti)
724 {
725         struct obd_device *obd = class_exp2obd(exp);
726         struct obd_export *cobd_exp;
727
728         if (obd == NULL) {
729                 CERROR("invalid client cookie "LPX64"\n", 
730                        exp->exp_handle.h_cookie);
731                 return -EINVAL;
732         }
733         cobd_exp = cobd_get_exp(obd);
734         return obd_preprw(cmd, cobd_exp, oa, objcount, obj,
735                           niocount, nb, res, oti);
736 }
737
738 static int cobd_dt_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
739                             int objcount, struct obd_ioobj *obj,
740                             int niocount, struct niobuf_local *local,
741                             struct obd_trans_info *oti, int rc)
742 {
743         struct obd_device *obd = class_exp2obd(exp);
744         struct obd_export *cobd_exp;
745
746         if (obd == NULL) {
747                 CERROR("invalid client cookie "LPX64"\n", 
748                        exp->exp_handle.h_cookie);
749                 return -EINVAL;
750         }
751         cobd_exp = cobd_get_exp(obd);
752         return obd_commitrw(cmd, cobd_exp, oa, objcount, obj,
753                             niocount, local, oti, rc);
754 }
755
756 static int cobd_flush(struct obd_device *obd)
757 {
758         return 0; 
759 }
760
761 static int cobd_dt_iocontrol(unsigned int cmd, struct obd_export *exp,
762                              int len, void *karg, void *uarg)
763 {
764         struct obd_device *obd = class_exp2obd(exp);
765         struct cache_obd  *cobd = &obd->u.cobd;
766         struct obd_export *cobd_exp;
767         int rc = 0;
768         ENTRY;
769
770         down(&cobd->sem);
771         
772         switch (cmd) {
773         case OBD_IOC_COBD_CON:
774                 if (!cobd->cache_on) {
775                         struct lustre_handle conn = {0};
776
777                         rc = client_obd_disconnect(obd, cobd->master_real_exp, 0);
778                         if (rc) {
779                                 CWARN("can't disconnect master export, err %d\n",
780                                       rc);
781                         }
782                         
783                         rc = client_obd_connect(obd, cobd->cache_exp, &conn,
784                                                 NULL, OBD_OPT_REAL_CLIENT);
785                         if (rc)
786                                 GOTO(out, rc);
787
788                         cobd->cache_real_exp = class_conn2export(&conn);
789                         cobd->cache_on = 1;
790                 }
791                 break;
792         case OBD_IOC_COBD_COFF: 
793                 if (cobd->cache_on) {
794                         struct lustre_handle conn = {0,};
795                         struct obd_device *master = NULL;
796                         struct obd_device *cache = NULL;
797                         int easize, cooksize;
798
799                         cache = class_exp2obd(cobd->cache_exp); 
800                         easize = cache->u.cli.cl_max_mds_easize; 
801                         cooksize = cache->u.cli.cl_max_mds_cookiesize;
802
803                         rc = client_obd_disconnect(obd, cobd->cache_real_exp, 0);
804                         if (rc) {
805                                 CWARN("can't disconnect cache export, err %d\n",
806                                       rc);
807                         }
808                         rc = client_obd_connect(obd, cobd->master_exp, &conn,
809                                                 NULL, OBD_OPT_REAL_CLIENT);
810                         if (rc)
811                                 GOTO(out, rc);
812                         cobd->master_real_exp = class_conn2export(&conn);
813
814                         master = class_exp2obd(cobd->master_exp);
815                         master->u.cli.cl_max_mds_easize = easize;
816                         master->u.cli.cl_max_mds_cookiesize = cooksize;
817                         cobd->cache_on = 0;
818                 }
819                 break;
820         case OBD_IOC_COBD_CFLUSH:
821                 if (cobd->cache_on) {
822                         cobd->cache_on = 0;
823                         cobd_flush(obd);
824                         cobd->cache_on = 1;
825                 } else {
826                         CERROR("%s: cache is turned off\n", obd->obd_name);
827                 }
828                 break;
829         default:
830                 cobd_exp = cobd_get_exp(obd);
831                 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
832         }
833
834         EXIT;
835 out:
836         up(&cobd->sem);
837         return rc;
838 }
839
840 static int cobd_dt_llog_init(struct obd_device *obd,
841                              struct obd_llogs *llogs, 
842                              struct obd_device *disk_obd,
843                              int count, struct llog_catid *logid)
844 {
845         struct obd_export *cobd_exp;
846         struct obd_device *cobd_obd;
847
848         cobd_exp = cobd_get_exp(obd);
849         cobd_obd = class_exp2obd(cobd_exp);
850         
851         return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs, 
852                              disk_obd, count, logid);
853 }
854
855 static int cobd_dt_llog_finish(struct obd_device *obd,
856                                struct obd_llogs *llogs, 
857                                int count)
858 {
859         struct obd_export *cobd_exp;
860         struct obd_device *cobd_obd;
861
862         cobd_exp = cobd_get_exp(obd);
863         cobd_obd = class_exp2obd(cobd_exp);
864
865         return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
866 }
867
868 static int cobd_dt_notify(struct obd_device *obd, struct obd_device *watched,
869                           int active, void *data)
870 {
871         struct obd_export *cobd_exp;
872
873         cobd_exp = cobd_get_exp(obd);
874
875         return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
876 }
877
878 static int cobd_dt_pin(struct obd_export *exp, obd_id ino, __u32 gen,
879                        int type, struct obd_client_handle *handle,
880                        int flag)
881 {
882         struct obd_device *obd = class_exp2obd(exp);
883         struct obd_export *cobd_exp;
884
885         if (obd == NULL) {
886                 CERROR("invalid client cookie "LPX64"\n", 
887                        exp->exp_handle.h_cookie);
888                 return -EINVAL;
889         }
890         cobd_exp = cobd_get_exp(obd);
891
892         return obd_pin(cobd_exp, ino, gen, type, handle, flag);
893 }
894
895 static int cobd_dt_unpin(struct obd_export *exp,
896                          struct obd_client_handle *handle,
897                          int flag)
898 {
899         struct obd_device *obd = class_exp2obd(exp);
900         struct obd_export *cobd_exp;
901
902         if (obd == NULL) {
903                 CERROR("invalid client cookie "LPX64"\n", 
904                        exp->exp_handle.h_cookie);
905                 return -EINVAL;
906         }
907         cobd_exp = cobd_get_exp(obd);
908
909         return obd_unpin(cobd_exp, handle, flag);
910 }
911
912 static int cobd_dt_init_ea_size(struct obd_export *exp, int easize,
913                                 int cookiesize)
914 {
915         struct obd_export *cobd_exp;
916
917         cobd_exp = cobd_get_exp(exp->exp_obd);
918         return obd_init_ea_size(cobd_exp, easize, cookiesize);
919 }
920
921 static int cobd_dt_import_event(struct obd_device *obd,
922                                 struct obd_import *imp,
923                                 enum obd_import_event event)
924 {
925         struct obd_export *cobd_exp;
926
927         cobd_exp = cobd_get_exp(obd);
928         obd_import_event(class_exp2obd(cobd_exp), imp, event);
929         return 0; 
930 }
931
932 static int cobd_md_getstatus(struct obd_export *exp,
933                              struct lustre_id *rootid)
934 {
935         struct obd_device *obd = class_exp2obd(exp);
936         struct obd_export *cobd_exp;
937
938         if (obd == NULL) {
939                 CERROR("invalid client cookie "LPX64"\n", 
940                        exp->exp_handle.h_cookie);
941                 return -EINVAL;
942         }
943         cobd_exp = cobd_get_exp(obd);
944         return md_getstatus(cobd_exp, rootid);
945 }
946
947 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
948                            __u64 valid, const char *ea_name, int ea_namelen,
949                            unsigned int ea_size, struct ptlrpc_request **request)
950 {
951         struct obd_device *obd = class_exp2obd(exp);
952         struct obd_export *cobd_exp;
953
954         if (obd == NULL) {
955                 CERROR("invalid client cookie "LPX64"\n", 
956                        exp->exp_handle.h_cookie);
957                 return -EINVAL;
958         }
959         cobd_exp = cobd_get_exp(obd);
960         return md_getattr(cobd_exp, id, valid, ea_name, ea_namelen,
961                           ea_size, request);
962 }
963
964 static int cobd_md_req2lustre_md(struct obd_export *mdc_exp, 
965                                  struct ptlrpc_request *req,
966                                  unsigned int offset,
967                                  struct obd_export *osc_exp,
968                                  struct lustre_md *md)
969 {
970         struct obd_device *obd = class_exp2obd(mdc_exp);
971         struct obd_export *cobd_exp;
972
973         if (obd == NULL) {
974                 CERROR("invalid client cookie "LPX64"\n", 
975                        mdc_exp->exp_handle.h_cookie);
976                 return -EINVAL;
977         }
978         cobd_exp = cobd_get_exp(obd);
979         return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
980 }
981
982 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id, 
983                                  ldlm_iterator_t it, void *data)
984 {
985         struct obd_device *obd = class_exp2obd(exp);
986         struct obd_export *cobd_exp;
987
988         if (obd == NULL) {
989                 CERROR("invalid client cookie "LPX64"\n", 
990                        exp->exp_handle.h_cookie);
991                 return -EINVAL;
992         }
993         cobd_exp = cobd_get_exp(obd);
994         return md_change_cbdata(cobd_exp, id, it, data);
995 }
996
997 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
998                                 char *filename, int namelen, __u64 valid,
999                                 unsigned int ea_size, struct ptlrpc_request **request)
1000 {
1001         struct obd_device *obd = class_exp2obd(exp);
1002         struct obd_export *cobd_exp;
1003
1004         if (obd == NULL) {
1005                 CERROR("invalid client cookie "LPX64"\n", 
1006                        exp->exp_handle.h_cookie);
1007                 return -EINVAL;
1008         }
1009         cobd_exp = cobd_get_exp(obd);
1010         return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
1011                                ea_size, request);
1012 }
1013
1014 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1015                           const void *data, int datalen, int mode, 
1016                           __u32 uid, __u32 gid, __u64 rdev, 
1017                           struct ptlrpc_request **request)
1018 {
1019         struct obd_device *obd = class_exp2obd(exp);
1020         struct obd_export *cobd_exp;
1021
1022         if (obd == NULL) {
1023                 CERROR("invalid client cookie "LPX64"\n", 
1024                        exp->exp_handle.h_cookie);
1025                 return -EINVAL;
1026         }
1027         cobd_exp = cobd_get_exp(obd);
1028         return md_create(cobd_exp, op_data, data, datalen, mode,
1029                          uid, gid, rdev, request);
1030 }
1031
1032 static int cobd_md_unlink(struct obd_export *exp,
1033                           struct mdc_op_data *data,
1034                           struct ptlrpc_request **request)
1035 {
1036         struct obd_device *obd = class_exp2obd(exp);
1037         struct obd_export *cobd_exp;
1038
1039         if (obd == NULL) {
1040                 CERROR("invalid client cookie "LPX64"\n", 
1041                        exp->exp_handle.h_cookie);
1042                 return -EINVAL;
1043         }
1044         cobd_exp = cobd_get_exp(obd);
1045         return md_unlink(cobd_exp, data, request);
1046 }
1047
1048 static int cobd_md_valid_attrs(struct obd_export *exp,
1049                                struct lustre_id *id)
1050 {
1051         struct obd_device *obd = class_exp2obd(exp);
1052         struct obd_export *cobd_exp;
1053
1054         if (obd == NULL) {
1055                 CERROR("invalid client cookie "LPX64"\n", 
1056                        exp->exp_handle.h_cookie);
1057                 return -EINVAL;
1058         }
1059         cobd_exp = cobd_get_exp(obd);
1060         return md_valid_attrs(cobd_exp, id);
1061 }
1062
1063 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
1064                           const char *old, int oldlen, const char *new, 
1065                           int newlen, struct ptlrpc_request **request)
1066 {
1067         struct obd_device *obd = class_exp2obd(exp);
1068         struct obd_export *cobd_exp;
1069
1070         if (obd == NULL) {
1071                 CERROR("invalid client cookie "LPX64"\n", 
1072                        exp->exp_handle.h_cookie);
1073                 return -EINVAL;
1074         }
1075         cobd_exp = cobd_get_exp(obd);
1076         return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1077 }
1078
1079 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1080                         struct ptlrpc_request **request)
1081 {
1082         struct obd_device *obd = class_exp2obd(exp);
1083         struct obd_export *cobd_exp;
1084
1085         if (obd == NULL) {
1086                 CERROR("invalid client cookie "LPX64"\n", 
1087                        exp->exp_handle.h_cookie);
1088                 return -EINVAL;
1089         }
1090         cobd_exp = cobd_get_exp(obd);
1091         return md_link(cobd_exp, data, request);
1092 }
1093
1094 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1095                            struct iattr *iattr, void *ea, int ealen, void *ea2, 
1096                            int ea2len, struct ptlrpc_request **request)
1097 {
1098         struct obd_device *obd = class_exp2obd(exp);
1099         struct obd_export *cobd_exp;
1100
1101         if (obd == NULL) {
1102                 CERROR("invalid client cookie "LPX64"\n", 
1103                        exp->exp_handle.h_cookie);
1104                 return -EINVAL;
1105         }
1106         cobd_exp = cobd_get_exp(obd);
1107         return md_setattr(cobd_exp, data, iattr, ea,
1108                           ealen, ea2, ea2len, request);
1109 }
1110
1111 static int cobd_md_readpage(struct obd_export *exp,
1112                             struct lustre_id *mdc_id,
1113                             __u64 offset, struct page *page, 
1114                             struct ptlrpc_request **request)
1115 {
1116         struct obd_device *obd = class_exp2obd(exp);
1117         struct obd_export *cobd_exp;
1118
1119         if (obd == NULL) {
1120                 CERROR("invalid client cookie "LPX64"\n", 
1121                        exp->exp_handle.h_cookie);
1122                 return -EINVAL;
1123         }
1124         cobd_exp = cobd_get_exp(obd);
1125         return md_readpage(cobd_exp, mdc_id, offset, page, request);
1126 }
1127
1128 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1129                          struct obd_client_handle *och, 
1130                          struct ptlrpc_request **request)
1131 {
1132         struct obd_device *obd = class_exp2obd(exp);
1133         struct obd_export *cobd_exp;
1134
1135         if (obd == NULL) {
1136                 CERROR("invalid client cookie "LPX64"\n", 
1137                        exp->exp_handle.h_cookie);
1138                 return -EINVAL;
1139         }
1140         cobd_exp = cobd_get_exp(obd);
1141         return md_close(cobd_exp, obdo, och, request);
1142 }
1143
1144 static int cobd_md_done_writing(struct obd_export *exp,
1145                                 struct obdo *obdo)
1146 {
1147         struct obd_device *obd = class_exp2obd(exp);
1148         struct obd_export *cobd_exp;
1149
1150         if (obd == NULL) {
1151                 CERROR("invalid client cookie "LPX64"\n", 
1152                        exp->exp_handle.h_cookie);
1153                 return -EINVAL;
1154         }
1155         cobd_exp = cobd_get_exp(obd);
1156         return md_done_writing(cobd_exp, obdo);
1157 }
1158
1159 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1160                         struct ptlrpc_request **request)
1161 {
1162         struct obd_device *obd = class_exp2obd(exp);
1163         struct obd_export *cobd_exp;
1164
1165         if (obd == NULL) {
1166                 CERROR("invalid client cookie "LPX64"\n", 
1167                        exp->exp_handle.h_cookie);
1168                 return -EINVAL;
1169         }
1170         cobd_exp = cobd_get_exp(obd);
1171         
1172         return md_sync(cobd_exp, id, request);
1173 }
1174
1175 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1176                                         struct obd_client_handle *och,
1177                                         struct ptlrpc_request *open_req)
1178 {
1179         struct obd_device *obd = class_exp2obd(exp);
1180         struct obd_export *cobd_exp;
1181
1182         if (obd == NULL) {
1183                 CERROR("invalid client cookie "LPX64"\n", 
1184                        exp->exp_handle.h_cookie);
1185                 return -EINVAL;
1186         }
1187         cobd_exp = cobd_get_exp(obd);
1188         
1189         return md_set_open_replay_data(cobd_exp, och, open_req);
1190 }
1191
1192 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1193                                           struct obd_client_handle *och)
1194 {
1195         struct obd_device *obd = class_exp2obd(exp);
1196         struct obd_export *cobd_exp;
1197
1198         if (obd == NULL) {
1199                 CERROR("invalid client cookie "LPX64"\n", 
1200                        exp->exp_handle.h_cookie);
1201                 return -EINVAL;
1202         }
1203         cobd_exp = cobd_get_exp(obd);
1204  
1205         return md_clear_open_replay_data(cobd_exp, och);
1206 }
1207
1208 static int cobd_md_store_inode_generation(struct obd_export *exp,
1209                                           struct ptlrpc_request *req, 
1210                                           int reqoff, int repoff)
1211 {
1212         struct obd_device *obd = class_exp2obd(exp);
1213         struct obd_export *cobd_exp;
1214
1215         if (obd == NULL) {
1216                 CERROR("invalid client cookie "LPX64"\n", 
1217                        exp->exp_handle.h_cookie);
1218                 return -EINVAL;
1219         }
1220         cobd_exp = cobd_get_exp(obd);
1221
1222         return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1223 }
1224
1225 static int cobd_md_set_lock_data(struct obd_export *exp,
1226                                  __u64 *l, void *data)
1227 {
1228         struct obd_device *obd = class_exp2obd(exp);
1229         struct obd_export *cobd_exp;
1230
1231         if (obd == NULL) {
1232                 CERROR("invalid client cookie "LPX64"\n", 
1233                        exp->exp_handle.h_cookie);
1234                 return -EINVAL;
1235         }
1236         cobd_exp = cobd_get_exp(obd);
1237
1238         return md_set_lock_data(cobd_exp, l, data);
1239 }
1240
1241 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1242                            struct lookup_intent *it, int lock_mode,
1243                            struct mdc_op_data *data, struct lustre_handle *lockh,
1244                            void *lmm, int lmmsize, 
1245                            ldlm_completion_callback cb_completion,
1246                            ldlm_blocking_callback cb_blocking, void *cb_data)
1247 {
1248         struct obd_device *obd = class_exp2obd(exp);
1249         struct obd_export *cobd_exp;
1250
1251         if (obd == NULL) {
1252                 CERROR("invalid client cookie "LPX64"\n", 
1253                        exp->exp_handle.h_cookie);
1254                 return -EINVAL;
1255         }
1256         cobd_exp = cobd_get_exp(obd);
1257         return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1258                           lockh, lmm, lmmsize, cb_completion, cb_blocking,
1259                           cb_data);
1260 }
1261
1262 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid, 
1263                                const char *name, int len, void *lmm, int lmmsize,
1264                                struct lustre_id *cid, struct lookup_intent *it,
1265                                int lookup_flags, struct ptlrpc_request **reqp,
1266                                ldlm_blocking_callback cb_blocking)
1267 {
1268         struct obd_device *obd = class_exp2obd(exp);
1269         struct obd_export *cobd_exp;
1270
1271         if (obd == NULL) {
1272                 CERROR("invalid client cookie "LPX64"\n", 
1273                        exp->exp_handle.h_cookie);
1274                 return -EINVAL;
1275         }
1276         cobd_exp = cobd_get_exp(obd);
1277         return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1278                               cid, it, lookup_flags, reqp, cb_blocking);
1279 }
1280
1281 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1282                                                struct lustre_id *id)
1283 {
1284         struct obd_device *obd = class_exp2obd(exp);
1285         struct obd_export *cobd_exp;
1286
1287         if (obd == NULL) {
1288                 CERROR("invalid client cookie "LPX64"\n", 
1289                        exp->exp_handle.h_cookie);
1290                 return NULL;
1291         }
1292         cobd_exp = cobd_get_exp(obd);
1293         return md_get_real_obd(cobd_exp, id);
1294 }
1295
1296 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1297                                       struct lustre_id *id, char *name,
1298                                       int namelen, struct lustre_id *id2,
1299                                       ldlm_iterator_t it, void *data)
1300 {
1301         struct obd_device *obd = class_exp2obd(exp);
1302         struct obd_export *cobd_exp;
1303
1304         if (obd == NULL) {
1305                 CERROR("invalid client cookie "LPX64"\n", 
1306                        exp->exp_handle.h_cookie);
1307                 return -EINVAL;
1308         }
1309         cobd_exp = cobd_get_exp(obd);
1310         return md_change_cbdata_name(cobd_exp, id, name, namelen,
1311                                      id2, it, data);
1312 }
1313 static struct obd_ops cobd_obd_ops = {
1314         .o_owner                  = THIS_MODULE,
1315         .o_attach                 = cobd_attach,
1316         .o_detach                 = cobd_detach,
1317         .o_setup                  = cobd_setup,
1318         .o_cleanup                = cobd_cleanup,
1319         .o_connect                = cobd_connect,
1320         .o_disconnect             = cobd_disconnect,
1321         .o_set_info               = cobd_set_info,
1322         .o_get_info               = cobd_get_info,
1323         .o_statfs                 = cobd_statfs,
1324
1325         .o_packmd                 = cobd_dt_packmd,
1326         .o_unpackmd               = cobd_dt_unpackmd,
1327         .o_create                 = cobd_dt_create,
1328         .o_destroy                = cobd_dt_destroy,
1329         .o_precleanup             = cobd_dt_precleanup,
1330         .o_getattr                = cobd_dt_getattr,
1331         .o_getattr_async          = cobd_dt_getattr_async,
1332         .o_setattr                = cobd_dt_setattr,
1333         .o_brw                    = cobd_dt_brw,
1334         .o_brw_async              = cobd_dt_brw_async,
1335         .o_prep_async_page        = cobd_dt_prep_async_page,
1336         .o_queue_async_io         = cobd_dt_queue_async_io,
1337         .o_set_async_flags        = cobd_dt_set_async_flags,
1338         .o_queue_group_io         = cobd_dt_queue_group_io,
1339         .o_trigger_group_io       = cobd_dt_trigger_group_io,
1340         .o_teardown_async_page    = cobd_dt_teardown_async_page,
1341         .o_preprw                 = cobd_dt_preprw,
1342         .o_punch                  = cobd_dt_punch,
1343         .o_sync                   = cobd_dt_sync,
1344         .o_enqueue                = cobd_dt_enqueue,
1345         .o_match                  = cobd_dt_match,
1346         .o_change_cbdata          = cobd_dt_change_cbdata,
1347         .o_cancel                 = cobd_dt_cancel,
1348         .o_cancel_unused          = cobd_dt_cancel_unused,
1349         .o_iocontrol              = cobd_dt_iocontrol,
1350         .o_commitrw               = cobd_dt_commitrw,
1351         .o_llog_init              = cobd_dt_llog_init,
1352         .o_llog_finish            = cobd_dt_llog_finish,
1353         .o_notify                 = cobd_dt_notify,
1354         .o_pin                    = cobd_dt_pin,
1355         .o_unpin                  = cobd_dt_unpin,
1356         .o_import_event           = cobd_dt_import_event,
1357         .o_init_ea_size           = cobd_dt_init_ea_size,
1358 };
1359
1360 struct md_ops cobd_md_ops = {
1361         .m_getstatus              = cobd_md_getstatus,
1362         .m_getattr                = cobd_md_getattr,
1363         .m_req2lustre_md          = cobd_md_req2lustre_md,
1364         .m_change_cbdata          = cobd_md_change_cbdata,
1365         .m_getattr_lock           = cobd_md_getattr_lock,
1366         .m_create                 = cobd_md_create,
1367         .m_unlink                 = cobd_md_unlink,
1368         .m_valid_attrs            = cobd_md_valid_attrs,
1369         .m_rename                 = cobd_md_rename,
1370         .m_link                   = cobd_md_link,
1371         .m_setattr                = cobd_md_setattr,
1372         .m_readpage               = cobd_md_readpage,
1373         .m_close                  = cobd_md_close,
1374         .m_done_writing           = cobd_md_done_writing,
1375         .m_sync                   = cobd_md_sync,
1376         .m_set_open_replay_data   = cobd_md_set_open_replay_data,
1377         .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1378         .m_store_inode_generation = cobd_md_store_inode_generation,
1379         .m_set_lock_data          = cobd_md_set_lock_data,
1380         .m_enqueue                = cobd_md_enqueue,
1381         .m_get_real_obd           = cobd_md_get_real_obd,
1382         .m_intent_lock            = cobd_md_intent_lock,
1383         .m_change_cbdata_name     = cobd_md_change_cbdata_name,
1384 };
1385
1386 static int __init cobd_init(void)
1387 {
1388         struct lprocfs_static_vars lvars;
1389         ENTRY;
1390
1391         printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1392
1393         lprocfs_init_vars(cobd, &lvars);
1394         RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1395                                    lvars.module_vars, OBD_CACHE_DEVICENAME));
1396 }
1397
1398 static void /*__exit*/ cobd_exit(void)
1399 {
1400         class_unregister_type(OBD_CACHE_DEVICENAME);
1401 }
1402
1403 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1404 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1405 MODULE_LICENSE("GPL");
1406
1407 module_init(cobd_init);
1408 module_exit(cobd_exit);