1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
22 #define DEBUG_SUBSYSTEM S_COBD
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>
36 static int cobd_attach(struct obd_device *obd,
37 obd_count len, void *buf)
39 struct lprocfs_static_vars lvars;
41 lprocfs_init_vars(cobd, &lvars);
42 return lprocfs_obd_attach(obd, lvars.obd_vars);
45 static int cobd_detach(struct obd_device *obd)
47 return lprocfs_obd_detach(obd);
50 static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
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 };
59 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
60 lustre_cfg_buf(lcfg, 1) == NULL) {
61 CERROR("%s: setup requires master device name\n",
66 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 ||
67 lustre_cfg_buf(lcfg, 2) == NULL) {
68 CERROR("%s: setup requires cache device name\n",
72 sema_init(&cobd->sem, 1);
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)
78 memcpy(cobd->master_name, lustre_cfg_string(lcfg, 1),
79 LUSTRE_CFG_BUFLEN(lcfg, 1));
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));
86 memcpy(cobd->cache_name, lustre_cfg_string(lcfg, 2),
87 LUSTRE_CFG_BUFLEN(lcfg, 2));
89 /* getting master obd */
90 master_obd = class_name2obd(cobd->master_name);
92 CERROR("can't find master obd by name %s\n",
94 GOTO(put_names, rc = -EINVAL);
97 /* connecting master */
98 memset(&conn, 0, sizeof(conn));
99 rc = class_connect(&conn, master_obd, &obd->obd_uuid);
103 cobd->master_exp = class_conn2export(&conn);
105 /* getting cache obd */
106 cache_obd = class_name2obd(cobd->cache_name);
108 class_disconnect(cobd->master_exp, 0);
109 CERROR("can't find cache obd by name %s\n",
114 /* connecting cache */
115 memset(&conn, 0, sizeof(conn));
116 rc = class_connect(&conn, cache_obd, &obd->obd_uuid);
118 class_disconnect(cobd->master_exp, 0);
121 cobd->cache_exp = class_conn2export(&conn);
123 /* default set cache on */
128 if (cobd->master_name) {
129 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
130 cobd->master_name = NULL;
132 if (cobd->cache_name) {
133 OBD_FREE(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
134 cobd->cache_name = NULL;
141 static int cobd_cleanup(struct obd_device *obd, int flags)
143 struct cache_obd *cobd = &obd->u.cobd;
147 if (!list_empty(&obd->obd_exports))
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);
157 rc = class_disconnect(cobd->master_exp, flags);
159 CERROR("error disconnecting master, err %d\n",
162 rc = class_disconnect(cobd->cache_exp, flags);
164 CERROR("error disconnecting master, err %d\n",
171 static inline struct obd_export *
172 cobd_get_exp(struct obd_device *obd)
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;
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;
188 client_obd_connect(struct obd_device *obd,
189 struct obd_export *exp,
190 struct lustre_handle *conn,
191 struct obd_connect_data *data,
194 struct obd_device *cli_obd;
201 cli_obd = class_exp2obd(exp);
205 rc = obd_connect(conn, cli_obd, &obd->obd_uuid, data, flags);
207 CERROR("error connecting err %d\n", rc);
213 client_obd_disconnect(struct obd_device *obd,
214 struct obd_export *exp,
217 struct obd_device *cli_obd;
221 cli_obd = class_exp2obd(exp);
222 cli_obd->obd_no_recov = obd->obd_no_recov;
224 rc = obd_disconnect(exp, flags);
226 CERROR("error disconnecting from %s, err %d\n",
227 cli_obd->obd_name, rc);
228 class_export_put(exp);
234 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
235 struct obd_uuid *cluuid, struct obd_connect_data *data,
238 struct lustre_handle cache_conn = { 0 };
239 struct cache_obd *cobd = &obd->u.cobd;
240 struct obd_export *exp, *cobd_exp;
244 rc = class_connect(conn, obd, cluuid);
247 exp = class_conn2export(conn);
249 cobd_exp = cobd_get_exp(obd);
251 /* connecting cache */
252 rc = client_obd_connect(obd, cobd_exp, &cache_conn,
255 GOTO(err_discon, rc);
257 cobd->cache_real_exp = class_conn2export(&cache_conn);
262 class_disconnect(exp, 0);
264 class_export_put(exp);
269 cobd_disconnect(struct obd_export *exp, unsigned long flags)
271 struct obd_device *obd;
272 struct obd_export *cobd_exp;
276 LASSERT(exp != NULL);
277 obd = class_exp2obd(exp);
279 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
280 exp->exp_handle.h_cookie);
283 cobd_exp = cobd_get_exp(obd);
285 rc = client_obd_disconnect(obd, cobd_exp, flags);
287 class_disconnect(exp, flags);
292 static int cobd_get_info(struct obd_export *exp, __u32 keylen,
293 void *key, __u32 *vallen, void *val)
295 struct obd_device *obd = class_exp2obd(exp);
296 struct obd_export *cobd_exp;
299 CERROR("invalid client cookie "LPX64"\n",
300 exp->exp_handle.h_cookie);
303 cobd_exp = cobd_get_exp(obd);
305 /* intercept cache utilisation info? */
306 return obd_get_info(cobd_exp, keylen, key, vallen, val);
309 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
310 void *key, obd_count vallen, void *val)
312 struct obd_device *obd = class_exp2obd(exp);
313 struct obd_export *cobd_exp;
316 CERROR("invalid client cookie "LPX64"\n",
317 exp->exp_handle.h_cookie);
320 cobd_exp = cobd_get_exp(obd);
322 /* intercept cache utilisation info? */
323 return obd_set_info(cobd_exp, keylen, key, vallen, val);
326 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
327 unsigned long max_age)
329 struct obd_export *cobd_exp;
331 cobd_exp = cobd_get_exp(obd);
333 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
336 static int cobd_packmd(struct obd_export *exp,
337 struct lov_mds_md **disk_tgt,
338 struct lov_stripe_md *mem_src)
340 struct obd_device *obd = class_exp2obd(exp);
341 struct obd_export *cobd_exp;
344 CERROR("invalid client cookie "LPX64"\n",
345 exp->exp_handle.h_cookie);
348 cobd_exp = cobd_get_exp(obd);
349 return obd_packmd(cobd_exp, disk_tgt, mem_src);
352 static int cobd_unpackmd(struct obd_export *exp,
353 struct lov_stripe_md **mem_tgt,
354 struct lov_mds_md *disk_src,
357 struct obd_device *obd = class_exp2obd(exp);
358 struct obd_export *cobd_exp;
361 CERROR("invalid client cookie "LPX64"\n",
362 exp->exp_handle.h_cookie);
365 cobd_exp = cobd_get_exp(obd);
366 return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
369 static int cobd_create(struct obd_export *exp, struct obdo *obdo,
370 void *acl, int acl_size,
371 struct lov_stripe_md **ea,
372 struct obd_trans_info *oti)
374 struct obd_device *obd = class_exp2obd(exp);
375 struct obd_export *cobd_exp;
378 CERROR("invalid client cookie "LPX64"\n",
379 exp->exp_handle.h_cookie);
382 cobd_exp = cobd_get_exp(obd);
383 return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
386 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
387 struct lov_stripe_md *ea,
388 struct obd_trans_info *oti)
390 struct obd_device *obd = class_exp2obd(exp);
391 struct obd_export *cobd_exp;
394 CERROR("invalid client cookie "LPX64"\n",
395 exp->exp_handle.h_cookie);
398 cobd_exp = cobd_get_exp(obd);
399 return obd_destroy(cobd_exp, obdo, ea, oti);
402 static int cobd_precleanup(struct obd_device *obd, int flags)
404 /* FIXME-WANGDI: do we need some cleanup here? */
408 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
409 struct lov_stripe_md *ea)
411 struct obd_device *obd = class_exp2obd(exp);
412 struct obd_export *cobd_exp;
415 CERROR("invalid client cookie "LPX64"\n",
416 exp->exp_handle.h_cookie);
419 cobd_exp = cobd_get_exp(obd);
420 return obd_getattr(cobd_exp, oa, ea);
423 static int cobd_getattr_async(struct obd_export *exp,
424 struct obdo *obdo, struct lov_stripe_md *ea,
425 struct ptlrpc_request_set *set)
427 struct obd_device *obd = class_exp2obd(exp);
428 struct obd_export *cobd_exp;
431 CERROR("invalid client cookie "LPX64"\n",
432 exp->exp_handle.h_cookie);
435 cobd_exp = cobd_get_exp(obd);
436 return obd_getattr_async(cobd_exp, obdo, ea, set);
439 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
440 struct lov_stripe_md *ea,
441 struct obd_trans_info *oti)
443 struct obd_device *obd = class_exp2obd(exp);
444 struct obd_export *cobd_exp;
447 CERROR("invalid client cookie "LPX64"\n",
448 exp->exp_handle.h_cookie);
451 cobd_exp = cobd_get_exp(obd);
452 return obd_setattr(cobd_exp, obdo, ea, oti);
455 static int cobd_md_getstatus(struct obd_export *exp,
456 struct lustre_id *rootid)
458 struct obd_device *obd = class_exp2obd(exp);
459 struct obd_export *cobd_exp;
462 CERROR("invalid client cookie "LPX64"\n",
463 exp->exp_handle.h_cookie);
466 cobd_exp = cobd_get_exp(obd);
467 return md_getstatus(cobd_exp, rootid);
470 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
471 struct lov_stripe_md *ea, obd_count oa_bufs,
472 struct brw_page *pg, struct obd_trans_info *oti)
474 struct obd_device *obd = class_exp2obd(exp);
475 struct obd_export *cobd_exp;
478 CERROR("invalid client cookie "LPX64"\n",
479 exp->exp_handle.h_cookie);
482 cobd_exp = cobd_get_exp(obd);
483 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
486 static int cobd_brw_async(int cmd, struct obd_export *exp,
487 struct obdo *oa, struct lov_stripe_md *ea,
488 obd_count oa_bufs, struct brw_page *pg,
489 struct ptlrpc_request_set *set,
490 struct obd_trans_info *oti)
492 struct obd_device *obd = class_exp2obd(exp);
493 struct obd_export *cobd_exp;
496 CERROR("invalid client cookie "LPX64"\n",
497 exp->exp_handle.h_cookie);
500 cobd_exp = cobd_get_exp(obd);
501 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
505 static int cobd_prep_async_page(struct obd_export *exp,
506 struct lov_stripe_md *lsm,
507 struct lov_oinfo *loi,
508 struct page *page, obd_off offset,
509 struct obd_async_page_ops *ops,
510 void *data, void **res)
512 struct obd_device *obd = class_exp2obd(exp);
513 struct obd_export *cobd_exp;
516 CERROR("invalid client cookie "LPX64"\n",
517 exp->exp_handle.h_cookie);
520 cobd_exp = cobd_get_exp(obd);
521 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
525 static int cobd_queue_async_io(struct obd_export *exp,
526 struct lov_stripe_md *lsm,
527 struct lov_oinfo *loi, void *cookie,
528 int cmd, obd_off off, int count,
529 obd_flags brw_flags, obd_flags async_flags)
531 struct obd_device *obd = class_exp2obd(exp);
532 struct obd_export *cobd_exp;
535 CERROR("invalid client cookie "LPX64"\n",
536 exp->exp_handle.h_cookie);
539 cobd_exp = cobd_get_exp(obd);
540 return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
541 brw_flags, async_flags);
544 static int cobd_set_async_flags(struct obd_export *exp,
545 struct lov_stripe_md *lsm,
546 struct lov_oinfo *loi, void *cookie,
547 obd_flags async_flags)
549 struct obd_device *obd = class_exp2obd(exp);
550 struct obd_export *cobd_exp;
553 CERROR("invalid client cookie "LPX64"\n",
554 exp->exp_handle.h_cookie);
557 cobd_exp = cobd_get_exp(obd);
558 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
561 static int cobd_queue_group_io(struct obd_export *exp,
562 struct lov_stripe_md *lsm,
563 struct lov_oinfo *loi,
564 struct obd_io_group *oig,
565 void *cookie, int cmd, obd_off off,
566 int count, obd_flags brw_flags,
567 obd_flags async_flags)
569 struct obd_device *obd = class_exp2obd(exp);
570 struct obd_export *cobd_exp;
573 CERROR("invalid client cookie "LPX64"\n",
574 exp->exp_handle.h_cookie);
577 cobd_exp = cobd_get_exp(obd);
578 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
579 cmd, off, count, brw_flags, async_flags);
582 static int cobd_trigger_group_io(struct obd_export *exp,
583 struct lov_stripe_md *lsm,
584 struct lov_oinfo *loi,
585 struct obd_io_group *oig)
587 struct obd_device *obd = class_exp2obd(exp);
588 struct obd_export *cobd_exp;
591 CERROR("invalid client cookie "LPX64"\n",
592 exp->exp_handle.h_cookie);
595 cobd_exp = cobd_get_exp(obd);
596 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
599 static int cobd_teardown_async_page(struct obd_export *exp,
600 struct lov_stripe_md *lsm,
601 struct lov_oinfo *loi, void *cookie)
603 struct obd_device *obd = class_exp2obd(exp);
604 struct obd_export *cobd_exp;
607 CERROR("invalid client cookie "LPX64"\n",
608 exp->exp_handle.h_cookie);
611 cobd_exp = cobd_get_exp(obd);
612 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
615 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
616 struct lov_stripe_md *ea, obd_size start,
617 obd_size end, struct obd_trans_info *oti)
619 struct obd_device *obd = class_exp2obd(exp);
620 struct obd_export *cobd_exp;
623 CERROR("invalid client cookie "LPX64"\n",
624 exp->exp_handle.h_cookie);
627 cobd_exp = cobd_get_exp(obd);
628 return obd_punch(cobd_exp, oa, ea, start, end, oti);
631 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
632 struct lov_stripe_md *ea, obd_size start,
635 struct obd_device *obd = class_exp2obd(exp);
636 struct obd_export *cobd_exp;
639 CERROR("invalid client cookie "LPX64"\n",
640 exp->exp_handle.h_cookie);
643 cobd_exp = cobd_get_exp(obd);
644 return obd_sync(cobd_exp, oa, ea, start, end);
647 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
648 __u32 type, ldlm_policy_data_t *policy,
649 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
650 void *gl_cb, void *data, __u32 lvb_len,
651 void *lvb_swabber, struct lustre_handle *lockh)
653 struct obd_device *obd = class_exp2obd(exp);
654 struct obd_export *cobd_exp;
657 CERROR("invalid client cookie "LPX64"\n",
658 exp->exp_handle.h_cookie);
661 cobd_exp = cobd_get_exp(obd);
662 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
663 bl_cb, cp_cb, gl_cb, data, lvb_len,
667 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
668 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
669 int *flags, void *data, struct lustre_handle *lockh)
671 struct obd_device *obd = class_exp2obd(exp);
672 struct obd_export *cobd_exp;
675 CERROR("invalid client cookie "LPX64"\n",
676 exp->exp_handle.h_cookie);
679 cobd_exp = cobd_get_exp(obd);
680 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
683 static int cobd_change_cbdata(struct obd_export *exp,
684 struct lov_stripe_md *lsm,
685 ldlm_iterator_t it, void *data)
687 struct obd_device *obd = class_exp2obd(exp);
688 struct obd_export *cobd_exp;
691 CERROR("invalid client cookie "LPX64"\n",
692 exp->exp_handle.h_cookie);
695 cobd_exp = cobd_get_exp(obd);
696 return obd_change_cbdata(cobd_exp, lsm, it, data);
699 static int cobd_cancel(struct obd_export *exp,
700 struct lov_stripe_md *ea, __u32 mode,
701 struct lustre_handle *lockh)
703 struct obd_device *obd = class_exp2obd(exp);
704 struct obd_export *cobd_exp;
707 CERROR("invalid client cookie "LPX64"\n",
708 exp->exp_handle.h_cookie);
711 cobd_exp = cobd_get_exp(obd);
712 return obd_cancel(cobd_exp, ea, mode, lockh);
715 static int cobd_cancel_unused(struct obd_export *exp,
716 struct lov_stripe_md *ea,
717 int flags, void *opaque)
719 struct obd_device *obd = class_exp2obd(exp);
720 struct obd_export *cobd_exp;
723 CERROR("invalid client cookie "LPX64"\n",
724 exp->exp_handle.h_cookie);
727 cobd_exp = cobd_get_exp(obd);
728 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
731 static int cobd_preprw(int cmd, struct obd_export *exp,
732 struct obdo *oa, int objcount,
733 struct obd_ioobj *obj, int niocount,
734 struct niobuf_remote *nb,
735 struct niobuf_local *res,
736 struct obd_trans_info *oti)
738 struct obd_device *obd = class_exp2obd(exp);
739 struct obd_export *cobd_exp;
742 CERROR("invalid client cookie "LPX64"\n",
743 exp->exp_handle.h_cookie);
746 cobd_exp = cobd_get_exp(obd);
747 return obd_preprw(cmd, cobd_exp, oa, objcount, obj,
748 niocount, nb, res, oti);
751 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
752 int objcount, struct obd_ioobj *obj,
753 int niocount, struct niobuf_local *local,
754 struct obd_trans_info *oti, int rc)
756 struct obd_device *obd = class_exp2obd(exp);
757 struct obd_export *cobd_exp;
760 CERROR("invalid client cookie "LPX64"\n",
761 exp->exp_handle.h_cookie);
764 cobd_exp = cobd_get_exp(obd);
765 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj,
766 niocount, local, oti, rc);
769 static int cobd_flush(struct obd_device *obd)
774 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
775 int len, void *karg, void *uarg)
777 struct obd_device *obd = class_exp2obd(exp);
778 struct cache_obd *cobd = &obd->u.cobd;
779 struct obd_export *cobd_exp;
786 case OBD_IOC_COBD_CON:
787 if (!cobd->cache_on) {
788 struct lustre_handle conn = {0};
790 rc = client_obd_disconnect(obd, cobd->master_real_exp, 0);
792 CWARN("can't disconnect master export, err %d\n",
796 rc = client_obd_connect(obd, cobd->cache_exp, &conn,
797 NULL, OBD_OPT_REAL_CLIENT);
801 cobd->cache_real_exp = class_conn2export(&conn);
805 case OBD_IOC_COBD_COFF:
806 if (cobd->cache_on) {
807 struct lustre_handle conn = {0,};
808 struct obd_device *master = NULL;
809 struct obd_device *cache = NULL;
810 int easize, cooksize;
812 cache = class_exp2obd(cobd->cache_exp);
813 easize = cache->u.cli.cl_max_mds_easize;
814 cooksize = cache->u.cli.cl_max_mds_cookiesize;
816 rc = client_obd_disconnect(obd, cobd->cache_real_exp, 0);
818 CWARN("can't disconnect cache export, err %d\n",
821 rc = client_obd_connect(obd, cobd->master_exp, &conn,
822 NULL, OBD_OPT_REAL_CLIENT);
825 cobd->master_real_exp = class_conn2export(&conn);
827 master = class_exp2obd(cobd->master_exp);
828 master->u.cli.cl_max_mds_easize = easize;
829 master->u.cli.cl_max_mds_cookiesize = cooksize;
833 case OBD_IOC_COBD_CFLUSH:
834 if (cobd->cache_on) {
839 CERROR("%s: cache is turned off\n", obd->obd_name);
843 cobd_exp = cobd_get_exp(obd);
844 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
853 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
854 struct obd_device *disk_obd, int count,
855 struct llog_catid *logid)
857 struct obd_export *cobd_exp;
858 struct obd_device *cobd_obd;
860 cobd_exp = cobd_get_exp(obd);
861 cobd_obd = class_exp2obd(cobd_exp);
863 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
864 disk_obd, count, logid);
867 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
870 struct obd_export *cobd_exp;
871 struct obd_device *cobd_obd;
873 cobd_exp = cobd_get_exp(obd);
874 cobd_obd = class_exp2obd(cobd_exp);
876 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
879 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
880 int active, void *data)
882 struct obd_export *cobd_exp;
884 cobd_exp = cobd_get_exp(obd);
886 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
889 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
890 int type, struct obd_client_handle *handle, int flag)
892 struct obd_device *obd = class_exp2obd(exp);
893 struct obd_export *cobd_exp;
896 CERROR("invalid client cookie "LPX64"\n",
897 exp->exp_handle.h_cookie);
900 cobd_exp = cobd_get_exp(obd);
902 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
905 static int cobd_unpin(struct obd_export *exp,
906 struct obd_client_handle *handle, int flag)
908 struct obd_device *obd = class_exp2obd(exp);
909 struct obd_export *cobd_exp;
912 CERROR("invalid client cookie "LPX64"\n",
913 exp->exp_handle.h_cookie);
916 cobd_exp = cobd_get_exp(obd);
918 return obd_unpin(cobd_exp, handle, flag);
921 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
923 struct obd_export *cobd_exp;
925 cobd_exp = cobd_get_exp(exp->exp_obd);
926 return obd_init_ea_size(cobd_exp, easize, cookiesize);
929 static int cobd_import_event(struct obd_device *obd,
930 struct obd_import *imp,
931 enum obd_import_event event)
933 struct obd_export *cobd_exp;
935 cobd_exp = cobd_get_exp(obd);
937 obd_import_event(class_exp2obd(cobd_exp), imp, event);
942 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
943 __u64 valid, const char *ea_name, int ea_namelen,
944 unsigned int ea_size, struct ptlrpc_request **request)
946 struct obd_device *obd = class_exp2obd(exp);
947 struct obd_export *cobd_exp;
950 CERROR("invalid client cookie "LPX64"\n",
951 exp->exp_handle.h_cookie);
954 cobd_exp = cobd_get_exp(obd);
955 return md_getattr(cobd_exp, id, valid, ea_name, ea_namelen, ea_size,
959 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
960 struct ptlrpc_request *req, unsigned int offset,
961 struct obd_export *osc_exp, struct lustre_md *md)
963 struct obd_device *obd = class_exp2obd(mdc_exp);
964 struct obd_export *cobd_exp;
967 CERROR("invalid client cookie "LPX64"\n",
968 mdc_exp->exp_handle.h_cookie);
971 cobd_exp = cobd_get_exp(obd);
972 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
975 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
976 ldlm_iterator_t it, void *data)
978 struct obd_device *obd = class_exp2obd(exp);
979 struct obd_export *cobd_exp;
982 CERROR("invalid client cookie "LPX64"\n",
983 exp->exp_handle.h_cookie);
986 cobd_exp = cobd_get_exp(obd);
987 return md_change_cbdata(cobd_exp, id, it, data);
990 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
991 char *filename, int namelen, __u64 valid,
992 unsigned int ea_size, struct ptlrpc_request **request)
994 struct obd_device *obd = class_exp2obd(exp);
995 struct obd_export *cobd_exp;
998 CERROR("invalid client cookie "LPX64"\n",
999 exp->exp_handle.h_cookie);
1002 cobd_exp = cobd_get_exp(obd);
1003 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
1007 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1008 const void *data, int datalen, int mode,
1009 __u32 uid, __u32 gid, __u64 rdev,
1010 struct ptlrpc_request **request)
1012 struct obd_device *obd = class_exp2obd(exp);
1013 struct obd_export *cobd_exp;
1016 CERROR("invalid client cookie "LPX64"\n",
1017 exp->exp_handle.h_cookie);
1020 cobd_exp = cobd_get_exp(obd);
1021 return md_create(cobd_exp, op_data, data, datalen, mode,
1022 uid, gid, rdev, request);
1025 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1026 struct ptlrpc_request **request)
1028 struct obd_device *obd = class_exp2obd(exp);
1029 struct obd_export *cobd_exp;
1032 CERROR("invalid client cookie "LPX64"\n",
1033 exp->exp_handle.h_cookie);
1036 cobd_exp = cobd_get_exp(obd);
1037 return md_unlink(cobd_exp, data, request);
1040 static int cobd_md_valid_attrs(struct obd_export *exp,
1041 struct lustre_id *id)
1043 struct obd_device *obd = class_exp2obd(exp);
1044 struct obd_export *cobd_exp;
1047 CERROR("invalid client cookie "LPX64"\n",
1048 exp->exp_handle.h_cookie);
1051 cobd_exp = cobd_get_exp(obd);
1052 return md_valid_attrs(cobd_exp, id);
1055 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
1056 const char *old, int oldlen, const char *new,
1057 int newlen, struct ptlrpc_request **request)
1059 struct obd_device *obd = class_exp2obd(exp);
1060 struct obd_export *cobd_exp;
1063 CERROR("invalid client cookie "LPX64"\n",
1064 exp->exp_handle.h_cookie);
1067 cobd_exp = cobd_get_exp(obd);
1068 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1071 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1072 struct ptlrpc_request **request)
1074 struct obd_device *obd = class_exp2obd(exp);
1075 struct obd_export *cobd_exp;
1078 CERROR("invalid client cookie "LPX64"\n",
1079 exp->exp_handle.h_cookie);
1082 cobd_exp = cobd_get_exp(obd);
1083 return md_link(cobd_exp, data, request);
1086 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1087 struct iattr *iattr, void *ea, int ealen, void *ea2,
1088 int ea2len, struct ptlrpc_request **request)
1090 struct obd_device *obd = class_exp2obd(exp);
1091 struct obd_export *cobd_exp;
1094 CERROR("invalid client cookie "LPX64"\n",
1095 exp->exp_handle.h_cookie);
1098 cobd_exp = cobd_get_exp(obd);
1099 return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1102 static int cobd_md_readpage(struct obd_export *exp,
1103 struct lustre_id *mdc_id,
1104 __u64 offset, struct page *page,
1105 struct ptlrpc_request **request)
1107 struct obd_device *obd = class_exp2obd(exp);
1108 struct obd_export *cobd_exp;
1111 CERROR("invalid client cookie "LPX64"\n",
1112 exp->exp_handle.h_cookie);
1115 cobd_exp = cobd_get_exp(obd);
1116 return md_readpage(cobd_exp, mdc_id, offset, page, request);
1119 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1120 struct obd_client_handle *och,
1121 struct ptlrpc_request **request)
1123 struct obd_device *obd = class_exp2obd(exp);
1124 struct obd_export *cobd_exp;
1127 CERROR("invalid client cookie "LPX64"\n",
1128 exp->exp_handle.h_cookie);
1131 cobd_exp = cobd_get_exp(obd);
1132 return md_close(cobd_exp, obdo, och, request);
1135 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1137 struct obd_device *obd = class_exp2obd(exp);
1138 struct obd_export *cobd_exp;
1141 CERROR("invalid client cookie "LPX64"\n",
1142 exp->exp_handle.h_cookie);
1145 cobd_exp = cobd_get_exp(obd);
1146 return md_done_writing(cobd_exp, obdo);
1149 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1150 struct ptlrpc_request **request)
1152 struct obd_device *obd = class_exp2obd(exp);
1153 struct obd_export *cobd_exp;
1156 CERROR("invalid client cookie "LPX64"\n",
1157 exp->exp_handle.h_cookie);
1160 cobd_exp = cobd_get_exp(obd);
1162 return md_sync(cobd_exp, id, request);
1165 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1166 struct obd_client_handle *och,
1167 struct ptlrpc_request *open_req)
1169 struct obd_device *obd = class_exp2obd(exp);
1170 struct obd_export *cobd_exp;
1173 CERROR("invalid client cookie "LPX64"\n",
1174 exp->exp_handle.h_cookie);
1177 cobd_exp = cobd_get_exp(obd);
1179 return md_set_open_replay_data(cobd_exp, och, open_req);
1182 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1183 struct obd_client_handle *och)
1185 struct obd_device *obd = class_exp2obd(exp);
1186 struct obd_export *cobd_exp;
1189 CERROR("invalid client cookie "LPX64"\n",
1190 exp->exp_handle.h_cookie);
1193 cobd_exp = cobd_get_exp(obd);
1195 return md_clear_open_replay_data(cobd_exp, och);
1198 static int cobd_md_store_inode_generation(struct obd_export *exp,
1199 struct ptlrpc_request *req,
1200 int reqoff, int repoff)
1202 struct obd_device *obd = class_exp2obd(exp);
1203 struct obd_export *cobd_exp;
1206 CERROR("invalid client cookie "LPX64"\n",
1207 exp->exp_handle.h_cookie);
1210 cobd_exp = cobd_get_exp(obd);
1212 return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1215 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1217 struct obd_device *obd = class_exp2obd(exp);
1218 struct obd_export *cobd_exp;
1221 CERROR("invalid client cookie "LPX64"\n",
1222 exp->exp_handle.h_cookie);
1225 cobd_exp = cobd_get_exp(obd);
1227 return md_set_lock_data(cobd_exp, l, data);
1230 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1231 struct lookup_intent *it, int lock_mode,
1232 struct mdc_op_data *data, struct lustre_handle *lockh,
1233 void *lmm, int lmmsize,
1234 ldlm_completion_callback cb_completion,
1235 ldlm_blocking_callback cb_blocking, void *cb_data)
1237 struct obd_device *obd = class_exp2obd(exp);
1238 struct obd_export *cobd_exp;
1241 CERROR("invalid client cookie "LPX64"\n",
1242 exp->exp_handle.h_cookie);
1245 cobd_exp = cobd_get_exp(obd);
1246 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1247 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1251 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1252 const char *name, int len, void *lmm, int lmmsize,
1253 struct lustre_id *cid, struct lookup_intent *it,
1254 int lookup_flags, struct ptlrpc_request **reqp,
1255 ldlm_blocking_callback cb_blocking)
1257 struct obd_device *obd = class_exp2obd(exp);
1258 struct obd_export *cobd_exp;
1261 CERROR("invalid client cookie "LPX64"\n",
1262 exp->exp_handle.h_cookie);
1265 cobd_exp = cobd_get_exp(obd);
1266 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1267 cid, it, lookup_flags, reqp, cb_blocking);
1270 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1271 struct lustre_id *id)
1273 struct obd_device *obd = class_exp2obd(exp);
1274 struct obd_export *cobd_exp;
1277 CERROR("invalid client cookie "LPX64"\n",
1278 exp->exp_handle.h_cookie);
1281 cobd_exp = cobd_get_exp(obd);
1282 return md_get_real_obd(cobd_exp, id);
1285 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1286 struct lustre_id *id, char *name,
1287 int namelen, struct lustre_id *id2,
1288 ldlm_iterator_t it, void *data)
1290 struct obd_device *obd = class_exp2obd(exp);
1291 struct obd_export *cobd_exp;
1294 CERROR("invalid client cookie "LPX64"\n",
1295 exp->exp_handle.h_cookie);
1298 cobd_exp = cobd_get_exp(obd);
1299 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1302 static struct obd_ops cobd_obd_ops = {
1303 .o_owner = THIS_MODULE,
1304 .o_attach = cobd_attach,
1305 .o_detach = cobd_detach,
1306 .o_setup = cobd_setup,
1307 .o_cleanup = cobd_cleanup,
1308 .o_connect = cobd_connect,
1309 .o_disconnect = cobd_disconnect,
1310 .o_set_info = cobd_set_info,
1311 .o_get_info = cobd_get_info,
1312 .o_statfs = cobd_statfs,
1314 .o_packmd = cobd_packmd,
1315 .o_unpackmd = cobd_unpackmd,
1316 .o_create = cobd_create,
1317 .o_destroy = cobd_destroy,
1318 .o_precleanup = cobd_precleanup,
1319 .o_getattr = cobd_getattr,
1320 .o_getattr_async = cobd_getattr_async,
1321 .o_setattr = cobd_setattr,
1324 .o_brw_async = cobd_brw_async,
1325 .o_prep_async_page = cobd_prep_async_page,
1326 .o_queue_async_io = cobd_queue_async_io,
1327 .o_set_async_flags = cobd_set_async_flags,
1328 .o_queue_group_io = cobd_queue_group_io,
1329 .o_trigger_group_io = cobd_trigger_group_io,
1330 .o_teardown_async_page = cobd_teardown_async_page,
1331 .o_preprw = cobd_preprw,
1332 .o_punch = cobd_punch,
1333 .o_sync = cobd_sync,
1334 .o_enqueue = cobd_enqueue,
1335 .o_match = cobd_match,
1336 .o_change_cbdata = cobd_change_cbdata,
1337 .o_cancel = cobd_cancel,
1338 .o_cancel_unused = cobd_cancel_unused,
1339 .o_iocontrol = cobd_iocontrol,
1340 .o_commitrw = cobd_commitrw,
1341 .o_llog_init = cobd_llog_init,
1342 .o_llog_finish = cobd_llog_finish,
1343 .o_notify = cobd_notify,
1345 .o_unpin = cobd_unpin,
1346 .o_import_event = cobd_import_event,
1347 .o_init_ea_size = cobd_init_ea_size,
1350 struct md_ops cobd_md_ops = {
1351 .m_getstatus = cobd_md_getstatus,
1352 .m_getattr = cobd_md_getattr,
1353 .m_req2lustre_md = cobd_md_req2lustre_md,
1354 .m_change_cbdata = cobd_md_change_cbdata,
1355 .m_getattr_lock = cobd_md_getattr_lock,
1356 .m_create = cobd_md_create,
1357 .m_unlink = cobd_md_unlink,
1358 .m_valid_attrs = cobd_md_valid_attrs,
1359 .m_rename = cobd_md_rename,
1360 .m_link = cobd_md_link,
1361 .m_setattr = cobd_md_setattr,
1362 .m_readpage = cobd_md_readpage,
1363 .m_close = cobd_md_close,
1364 .m_done_writing = cobd_md_done_writing,
1365 .m_sync = cobd_md_sync,
1366 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1367 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1368 .m_store_inode_generation = cobd_md_store_inode_generation,
1369 .m_set_lock_data = cobd_md_set_lock_data,
1370 .m_enqueue = cobd_md_enqueue,
1371 .m_get_real_obd = cobd_md_get_real_obd,
1372 .m_intent_lock = cobd_md_intent_lock,
1373 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1376 static int __init cobd_init(void)
1378 struct lprocfs_static_vars lvars;
1381 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1383 lprocfs_init_vars(cobd, &lvars);
1384 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1385 lvars.module_vars, OBD_CACHE_DEVICENAME));
1388 static void /*__exit*/ cobd_exit(void)
1390 class_unregister_type(OBD_CACHE_DEVICENAME);
1393 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1394 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1395 MODULE_LICENSE("GPL");
1397 module_init(cobd_init);
1398 module_exit(cobd_exit);