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,
327 struct obd_statfs *osfs,
328 unsigned long max_age)
330 struct obd_export *cobd_exp;
332 cobd_exp = cobd_get_exp(obd);
333 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
336 static int cobd_dt_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_dt_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_dt_create(struct obd_export *exp,
371 void *acl, int acl_size,
372 struct lov_stripe_md **ea,
373 struct obd_trans_info *oti)
375 struct obd_device *obd = class_exp2obd(exp);
376 struct obd_export *cobd_exp;
379 CERROR("invalid client cookie "LPX64"\n",
380 exp->exp_handle.h_cookie);
383 cobd_exp = cobd_get_exp(obd);
384 return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
387 static int cobd_dt_destroy(struct obd_export *exp,
389 struct lov_stripe_md *ea,
390 struct obd_trans_info *oti)
392 struct obd_device *obd = class_exp2obd(exp);
393 struct obd_export *cobd_exp;
396 CERROR("invalid client cookie "LPX64"\n",
397 exp->exp_handle.h_cookie);
400 cobd_exp = cobd_get_exp(obd);
401 return obd_destroy(cobd_exp, obdo, ea, oti);
404 static int cobd_dt_precleanup(struct obd_device *obd, int flags)
406 /* FIXME-WANGDI: do we need some cleanup here? */
410 static int cobd_dt_getattr(struct obd_export *exp, struct obdo *oa,
411 struct lov_stripe_md *ea)
413 struct obd_device *obd = class_exp2obd(exp);
414 struct obd_export *cobd_exp;
417 CERROR("invalid client cookie "LPX64"\n",
418 exp->exp_handle.h_cookie);
421 cobd_exp = cobd_get_exp(obd);
422 return obd_getattr(cobd_exp, oa, ea);
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)
429 struct obd_device *obd = class_exp2obd(exp);
430 struct obd_export *cobd_exp;
433 CERROR("invalid client cookie "LPX64"\n",
434 exp->exp_handle.h_cookie);
437 cobd_exp = cobd_get_exp(obd);
438 return obd_getattr_async(cobd_exp, obdo, ea, set);
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)
445 struct obd_device *obd = class_exp2obd(exp);
446 struct obd_export *cobd_exp;
449 CERROR("invalid client cookie "LPX64"\n",
450 exp->exp_handle.h_cookie);
453 cobd_exp = cobd_get_exp(obd);
454 return obd_setattr(cobd_exp, obdo, ea, oti);
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)
461 struct obd_device *obd = class_exp2obd(exp);
462 struct obd_export *cobd_exp;
465 CERROR("invalid client cookie "LPX64"\n",
466 exp->exp_handle.h_cookie);
469 cobd_exp = cobd_get_exp(obd);
470 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
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)
479 struct obd_device *obd = class_exp2obd(exp);
480 struct obd_export *cobd_exp;
483 CERROR("invalid client cookie "LPX64"\n",
484 exp->exp_handle.h_cookie);
487 cobd_exp = cobd_get_exp(obd);
488 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
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)
499 struct obd_device *obd = class_exp2obd(exp);
500 struct obd_export *cobd_exp;
503 CERROR("invalid client cookie "LPX64"\n",
504 exp->exp_handle.h_cookie);
507 cobd_exp = cobd_get_exp(obd);
508 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
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)
518 struct obd_device *obd = class_exp2obd(exp);
519 struct obd_export *cobd_exp;
522 CERROR("invalid client cookie "LPX64"\n",
523 exp->exp_handle.h_cookie);
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);
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)
536 struct obd_device *obd = class_exp2obd(exp);
537 struct obd_export *cobd_exp;
540 CERROR("invalid client cookie "LPX64"\n",
541 exp->exp_handle.h_cookie);
544 cobd_exp = cobd_get_exp(obd);
545 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
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)
556 struct obd_device *obd = class_exp2obd(exp);
557 struct obd_export *cobd_exp;
560 CERROR("invalid client cookie "LPX64"\n",
561 exp->exp_handle.h_cookie);
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);
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)
574 struct obd_device *obd = class_exp2obd(exp);
575 struct obd_export *cobd_exp;
578 CERROR("invalid client cookie "LPX64"\n",
579 exp->exp_handle.h_cookie);
582 cobd_exp = cobd_get_exp(obd);
583 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
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)
590 struct obd_device *obd = class_exp2obd(exp);
591 struct obd_export *cobd_exp;
594 CERROR("invalid client cookie "LPX64"\n",
595 exp->exp_handle.h_cookie);
598 cobd_exp = cobd_get_exp(obd);
599 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
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)
606 struct obd_device *obd = class_exp2obd(exp);
607 struct obd_export *cobd_exp;
610 CERROR("invalid client cookie "LPX64"\n",
611 exp->exp_handle.h_cookie);
614 cobd_exp = cobd_get_exp(obd);
615 return obd_punch(cobd_exp, oa, ea, start, end, oti);
618 static int cobd_dt_sync(struct obd_export *exp, struct obdo *oa,
619 struct lov_stripe_md *ea, obd_size start,
622 struct obd_device *obd = class_exp2obd(exp);
623 struct obd_export *cobd_exp;
626 CERROR("invalid client cookie "LPX64"\n",
627 exp->exp_handle.h_cookie);
630 cobd_exp = cobd_get_exp(obd);
631 return obd_sync(cobd_exp, oa, ea, start, end);
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)
640 struct obd_device *obd = class_exp2obd(exp);
641 struct obd_export *cobd_exp;
644 CERROR("invalid client cookie "LPX64"\n",
645 exp->exp_handle.h_cookie);
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,
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)
658 struct obd_device *obd = class_exp2obd(exp);
659 struct obd_export *cobd_exp;
662 CERROR("invalid client cookie "LPX64"\n",
663 exp->exp_handle.h_cookie);
666 cobd_exp = cobd_get_exp(obd);
667 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
670 static int cobd_dt_change_cbdata(struct obd_export *exp,
671 struct lov_stripe_md *lsm,
672 ldlm_iterator_t it, void *data)
674 struct obd_device *obd = class_exp2obd(exp);
675 struct obd_export *cobd_exp;
678 CERROR("invalid client cookie "LPX64"\n",
679 exp->exp_handle.h_cookie);
682 cobd_exp = cobd_get_exp(obd);
683 return obd_change_cbdata(cobd_exp, lsm, it, data);
686 static int cobd_dt_cancel(struct obd_export *exp,
687 struct lov_stripe_md *ea, __u32 mode,
688 struct lustre_handle *lockh)
690 struct obd_device *obd = class_exp2obd(exp);
691 struct obd_export *cobd_exp;
694 CERROR("invalid client cookie "LPX64"\n",
695 exp->exp_handle.h_cookie);
698 cobd_exp = cobd_get_exp(obd);
699 return obd_cancel(cobd_exp, ea, mode, lockh);
702 static int cobd_dt_cancel_unused(struct obd_export *exp,
703 struct lov_stripe_md *ea,
704 int flags, void *opaque)
706 struct obd_device *obd = class_exp2obd(exp);
707 struct obd_export *cobd_exp;
710 CERROR("invalid client cookie "LPX64"\n",
711 exp->exp_handle.h_cookie);
714 cobd_exp = cobd_get_exp(obd);
715 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
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)
725 struct obd_device *obd = class_exp2obd(exp);
726 struct obd_export *cobd_exp;
729 CERROR("invalid client cookie "LPX64"\n",
730 exp->exp_handle.h_cookie);
733 cobd_exp = cobd_get_exp(obd);
734 return obd_preprw(cmd, cobd_exp, oa, objcount, obj,
735 niocount, nb, res, oti);
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)
743 struct obd_device *obd = class_exp2obd(exp);
744 struct obd_export *cobd_exp;
747 CERROR("invalid client cookie "LPX64"\n",
748 exp->exp_handle.h_cookie);
751 cobd_exp = cobd_get_exp(obd);
752 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj,
753 niocount, local, oti, rc);
756 static int cobd_flush(struct obd_device *obd)
761 static int cobd_dt_iocontrol(unsigned int cmd, struct obd_export *exp,
762 int len, void *karg, void *uarg)
764 struct obd_device *obd = class_exp2obd(exp);
765 struct cache_obd *cobd = &obd->u.cobd;
766 struct obd_export *cobd_exp;
773 case OBD_IOC_COBD_CON:
774 if (!cobd->cache_on) {
775 struct lustre_handle conn = {0};
777 rc = client_obd_disconnect(obd, cobd->master_real_exp, 0);
779 CWARN("can't disconnect master export, err %d\n",
783 rc = client_obd_connect(obd, cobd->cache_exp, &conn,
784 NULL, OBD_OPT_REAL_CLIENT);
788 cobd->cache_real_exp = class_conn2export(&conn);
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;
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;
803 rc = client_obd_disconnect(obd, cobd->cache_real_exp, 0);
805 CWARN("can't disconnect cache export, err %d\n",
808 rc = client_obd_connect(obd, cobd->master_exp, &conn,
809 NULL, OBD_OPT_REAL_CLIENT);
812 cobd->master_real_exp = class_conn2export(&conn);
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;
820 case OBD_IOC_COBD_CFLUSH:
821 if (cobd->cache_on) {
826 CERROR("%s: cache is turned off\n", obd->obd_name);
830 cobd_exp = cobd_get_exp(obd);
831 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
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)
845 struct obd_export *cobd_exp;
846 struct obd_device *cobd_obd;
848 cobd_exp = cobd_get_exp(obd);
849 cobd_obd = class_exp2obd(cobd_exp);
851 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
852 disk_obd, count, logid);
855 static int cobd_dt_llog_finish(struct obd_device *obd,
856 struct obd_llogs *llogs,
859 struct obd_export *cobd_exp;
860 struct obd_device *cobd_obd;
862 cobd_exp = cobd_get_exp(obd);
863 cobd_obd = class_exp2obd(cobd_exp);
865 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
868 static int cobd_dt_notify(struct obd_device *obd, struct obd_device *watched,
869 int active, void *data)
871 struct obd_export *cobd_exp;
873 cobd_exp = cobd_get_exp(obd);
875 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
878 static int cobd_dt_pin(struct obd_export *exp, obd_id ino, __u32 gen,
879 int type, struct obd_client_handle *handle,
882 struct obd_device *obd = class_exp2obd(exp);
883 struct obd_export *cobd_exp;
886 CERROR("invalid client cookie "LPX64"\n",
887 exp->exp_handle.h_cookie);
890 cobd_exp = cobd_get_exp(obd);
892 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
895 static int cobd_dt_unpin(struct obd_export *exp,
896 struct obd_client_handle *handle,
899 struct obd_device *obd = class_exp2obd(exp);
900 struct obd_export *cobd_exp;
903 CERROR("invalid client cookie "LPX64"\n",
904 exp->exp_handle.h_cookie);
907 cobd_exp = cobd_get_exp(obd);
909 return obd_unpin(cobd_exp, handle, flag);
912 static int cobd_dt_init_ea_size(struct obd_export *exp, int easize,
915 struct obd_export *cobd_exp;
917 cobd_exp = cobd_get_exp(exp->exp_obd);
918 return obd_init_ea_size(cobd_exp, easize, cookiesize);
921 static int cobd_dt_import_event(struct obd_device *obd,
922 struct obd_import *imp,
923 enum obd_import_event event)
925 struct obd_export *cobd_exp;
927 cobd_exp = cobd_get_exp(obd);
928 obd_import_event(class_exp2obd(cobd_exp), imp, event);
932 static int cobd_md_getstatus(struct obd_export *exp,
933 struct lustre_id *rootid)
935 struct obd_device *obd = class_exp2obd(exp);
936 struct obd_export *cobd_exp;
939 CERROR("invalid client cookie "LPX64"\n",
940 exp->exp_handle.h_cookie);
943 cobd_exp = cobd_get_exp(obd);
944 return md_getstatus(cobd_exp, rootid);
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)
951 struct obd_device *obd = class_exp2obd(exp);
952 struct obd_export *cobd_exp;
955 CERROR("invalid client cookie "LPX64"\n",
956 exp->exp_handle.h_cookie);
959 cobd_exp = cobd_get_exp(obd);
960 return md_getattr(cobd_exp, id, valid, ea_name, ea_namelen,
964 static int cobd_md_req2lustre_md(struct obd_export *mdc_exp,
965 struct ptlrpc_request *req,
967 struct obd_export *osc_exp,
968 struct lustre_md *md)
970 struct obd_device *obd = class_exp2obd(mdc_exp);
971 struct obd_export *cobd_exp;
974 CERROR("invalid client cookie "LPX64"\n",
975 mdc_exp->exp_handle.h_cookie);
978 cobd_exp = cobd_get_exp(obd);
979 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
982 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
983 ldlm_iterator_t it, void *data)
985 struct obd_device *obd = class_exp2obd(exp);
986 struct obd_export *cobd_exp;
989 CERROR("invalid client cookie "LPX64"\n",
990 exp->exp_handle.h_cookie);
993 cobd_exp = cobd_get_exp(obd);
994 return md_change_cbdata(cobd_exp, id, it, data);
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)
1001 struct obd_device *obd = class_exp2obd(exp);
1002 struct obd_export *cobd_exp;
1005 CERROR("invalid client cookie "LPX64"\n",
1006 exp->exp_handle.h_cookie);
1009 cobd_exp = cobd_get_exp(obd);
1010 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
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)
1019 struct obd_device *obd = class_exp2obd(exp);
1020 struct obd_export *cobd_exp;
1023 CERROR("invalid client cookie "LPX64"\n",
1024 exp->exp_handle.h_cookie);
1027 cobd_exp = cobd_get_exp(obd);
1028 return md_create(cobd_exp, op_data, data, datalen, mode,
1029 uid, gid, rdev, request);
1032 static int cobd_md_unlink(struct obd_export *exp,
1033 struct mdc_op_data *data,
1034 struct ptlrpc_request **request)
1036 struct obd_device *obd = class_exp2obd(exp);
1037 struct obd_export *cobd_exp;
1040 CERROR("invalid client cookie "LPX64"\n",
1041 exp->exp_handle.h_cookie);
1044 cobd_exp = cobd_get_exp(obd);
1045 return md_unlink(cobd_exp, data, request);
1048 static int cobd_md_valid_attrs(struct obd_export *exp,
1049 struct lustre_id *id)
1051 struct obd_device *obd = class_exp2obd(exp);
1052 struct obd_export *cobd_exp;
1055 CERROR("invalid client cookie "LPX64"\n",
1056 exp->exp_handle.h_cookie);
1059 cobd_exp = cobd_get_exp(obd);
1060 return md_valid_attrs(cobd_exp, id);
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)
1067 struct obd_device *obd = class_exp2obd(exp);
1068 struct obd_export *cobd_exp;
1071 CERROR("invalid client cookie "LPX64"\n",
1072 exp->exp_handle.h_cookie);
1075 cobd_exp = cobd_get_exp(obd);
1076 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1079 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1080 struct ptlrpc_request **request)
1082 struct obd_device *obd = class_exp2obd(exp);
1083 struct obd_export *cobd_exp;
1086 CERROR("invalid client cookie "LPX64"\n",
1087 exp->exp_handle.h_cookie);
1090 cobd_exp = cobd_get_exp(obd);
1091 return md_link(cobd_exp, data, request);
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)
1098 struct obd_device *obd = class_exp2obd(exp);
1099 struct obd_export *cobd_exp;
1102 CERROR("invalid client cookie "LPX64"\n",
1103 exp->exp_handle.h_cookie);
1106 cobd_exp = cobd_get_exp(obd);
1107 return md_setattr(cobd_exp, data, iattr, ea,
1108 ealen, ea2, ea2len, request);
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)
1116 struct obd_device *obd = class_exp2obd(exp);
1117 struct obd_export *cobd_exp;
1120 CERROR("invalid client cookie "LPX64"\n",
1121 exp->exp_handle.h_cookie);
1124 cobd_exp = cobd_get_exp(obd);
1125 return md_readpage(cobd_exp, mdc_id, offset, page, request);
1128 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1129 struct obd_client_handle *och,
1130 struct ptlrpc_request **request)
1132 struct obd_device *obd = class_exp2obd(exp);
1133 struct obd_export *cobd_exp;
1136 CERROR("invalid client cookie "LPX64"\n",
1137 exp->exp_handle.h_cookie);
1140 cobd_exp = cobd_get_exp(obd);
1141 return md_close(cobd_exp, obdo, och, request);
1144 static int cobd_md_done_writing(struct obd_export *exp,
1147 struct obd_device *obd = class_exp2obd(exp);
1148 struct obd_export *cobd_exp;
1151 CERROR("invalid client cookie "LPX64"\n",
1152 exp->exp_handle.h_cookie);
1155 cobd_exp = cobd_get_exp(obd);
1156 return md_done_writing(cobd_exp, obdo);
1159 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1160 struct ptlrpc_request **request)
1162 struct obd_device *obd = class_exp2obd(exp);
1163 struct obd_export *cobd_exp;
1166 CERROR("invalid client cookie "LPX64"\n",
1167 exp->exp_handle.h_cookie);
1170 cobd_exp = cobd_get_exp(obd);
1172 return md_sync(cobd_exp, id, request);
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)
1179 struct obd_device *obd = class_exp2obd(exp);
1180 struct obd_export *cobd_exp;
1183 CERROR("invalid client cookie "LPX64"\n",
1184 exp->exp_handle.h_cookie);
1187 cobd_exp = cobd_get_exp(obd);
1189 return md_set_open_replay_data(cobd_exp, och, open_req);
1192 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1193 struct obd_client_handle *och)
1195 struct obd_device *obd = class_exp2obd(exp);
1196 struct obd_export *cobd_exp;
1199 CERROR("invalid client cookie "LPX64"\n",
1200 exp->exp_handle.h_cookie);
1203 cobd_exp = cobd_get_exp(obd);
1205 return md_clear_open_replay_data(cobd_exp, och);
1208 static int cobd_md_store_inode_generation(struct obd_export *exp,
1209 struct ptlrpc_request *req,
1210 int reqoff, int repoff)
1212 struct obd_device *obd = class_exp2obd(exp);
1213 struct obd_export *cobd_exp;
1216 CERROR("invalid client cookie "LPX64"\n",
1217 exp->exp_handle.h_cookie);
1220 cobd_exp = cobd_get_exp(obd);
1222 return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1225 static int cobd_md_set_lock_data(struct obd_export *exp,
1226 __u64 *l, void *data)
1228 struct obd_device *obd = class_exp2obd(exp);
1229 struct obd_export *cobd_exp;
1232 CERROR("invalid client cookie "LPX64"\n",
1233 exp->exp_handle.h_cookie);
1236 cobd_exp = cobd_get_exp(obd);
1238 return md_set_lock_data(cobd_exp, l, data);
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)
1248 struct obd_device *obd = class_exp2obd(exp);
1249 struct obd_export *cobd_exp;
1252 CERROR("invalid client cookie "LPX64"\n",
1253 exp->exp_handle.h_cookie);
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,
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)
1268 struct obd_device *obd = class_exp2obd(exp);
1269 struct obd_export *cobd_exp;
1272 CERROR("invalid client cookie "LPX64"\n",
1273 exp->exp_handle.h_cookie);
1276 lookup_flags |= LOOKUP_COBD;
1277 cobd_exp = cobd_get_exp(obd);
1279 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1280 cid, it, lookup_flags, reqp, cb_blocking);
1283 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1284 struct lustre_id *id)
1286 struct obd_device *obd = class_exp2obd(exp);
1287 struct obd_export *cobd_exp;
1290 CERROR("invalid client cookie "LPX64"\n",
1291 exp->exp_handle.h_cookie);
1294 cobd_exp = cobd_get_exp(obd);
1295 return md_get_real_obd(cobd_exp, id);
1298 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1299 struct lustre_id *id, char *name,
1300 int namelen, struct lustre_id *id2,
1301 ldlm_iterator_t it, void *data)
1303 struct obd_device *obd = class_exp2obd(exp);
1304 struct obd_export *cobd_exp;
1307 CERROR("invalid client cookie "LPX64"\n",
1308 exp->exp_handle.h_cookie);
1311 cobd_exp = cobd_get_exp(obd);
1312 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1315 static struct obd_ops cobd_obd_ops = {
1316 .o_owner = THIS_MODULE,
1317 .o_attach = cobd_attach,
1318 .o_detach = cobd_detach,
1319 .o_setup = cobd_setup,
1320 .o_cleanup = cobd_cleanup,
1321 .o_connect = cobd_connect,
1322 .o_disconnect = cobd_disconnect,
1323 .o_set_info = cobd_set_info,
1324 .o_get_info = cobd_get_info,
1325 .o_statfs = cobd_statfs,
1327 .o_packmd = cobd_dt_packmd,
1328 .o_unpackmd = cobd_dt_unpackmd,
1329 .o_create = cobd_dt_create,
1330 .o_destroy = cobd_dt_destroy,
1331 .o_precleanup = cobd_dt_precleanup,
1332 .o_getattr = cobd_dt_getattr,
1333 .o_getattr_async = cobd_dt_getattr_async,
1334 .o_setattr = cobd_dt_setattr,
1335 .o_brw = cobd_dt_brw,
1336 .o_brw_async = cobd_dt_brw_async,
1337 .o_prep_async_page = cobd_dt_prep_async_page,
1338 .o_queue_async_io = cobd_dt_queue_async_io,
1339 .o_set_async_flags = cobd_dt_set_async_flags,
1340 .o_queue_group_io = cobd_dt_queue_group_io,
1341 .o_trigger_group_io = cobd_dt_trigger_group_io,
1342 .o_teardown_async_page = cobd_dt_teardown_async_page,
1343 .o_preprw = cobd_dt_preprw,
1344 .o_punch = cobd_dt_punch,
1345 .o_sync = cobd_dt_sync,
1346 .o_enqueue = cobd_dt_enqueue,
1347 .o_match = cobd_dt_match,
1348 .o_change_cbdata = cobd_dt_change_cbdata,
1349 .o_cancel = cobd_dt_cancel,
1350 .o_cancel_unused = cobd_dt_cancel_unused,
1351 .o_iocontrol = cobd_dt_iocontrol,
1352 .o_commitrw = cobd_dt_commitrw,
1353 .o_llog_init = cobd_dt_llog_init,
1354 .o_llog_finish = cobd_dt_llog_finish,
1355 .o_notify = cobd_dt_notify,
1356 .o_pin = cobd_dt_pin,
1357 .o_unpin = cobd_dt_unpin,
1358 .o_import_event = cobd_dt_import_event,
1359 .o_init_ea_size = cobd_dt_init_ea_size,
1362 struct md_ops cobd_md_ops = {
1363 .m_getstatus = cobd_md_getstatus,
1364 .m_getattr = cobd_md_getattr,
1365 .m_req2lustre_md = cobd_md_req2lustre_md,
1366 .m_change_cbdata = cobd_md_change_cbdata,
1367 .m_getattr_lock = cobd_md_getattr_lock,
1368 .m_create = cobd_md_create,
1369 .m_unlink = cobd_md_unlink,
1370 .m_valid_attrs = cobd_md_valid_attrs,
1371 .m_rename = cobd_md_rename,
1372 .m_link = cobd_md_link,
1373 .m_setattr = cobd_md_setattr,
1374 .m_readpage = cobd_md_readpage,
1375 .m_close = cobd_md_close,
1376 .m_done_writing = cobd_md_done_writing,
1377 .m_sync = cobd_md_sync,
1378 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1379 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1380 .m_store_inode_generation = cobd_md_store_inode_generation,
1381 .m_set_lock_data = cobd_md_set_lock_data,
1382 .m_enqueue = cobd_md_enqueue,
1383 .m_get_real_obd = cobd_md_get_real_obd,
1384 .m_intent_lock = cobd_md_intent_lock,
1385 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1388 static int __init cobd_init(void)
1390 struct lprocfs_static_vars lvars;
1393 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1395 lprocfs_init_vars(cobd, &lvars);
1396 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1397 lvars.module_vars, OBD_CACHE_DEVICENAME));
1400 static void /*__exit*/ cobd_exit(void)
1402 class_unregister_type(OBD_CACHE_DEVICENAME);
1405 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1406 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1407 MODULE_LICENSE("GPL");
1409 module_init(cobd_init);
1410 module_exit(cobd_exit);