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 master 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 master */
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);
122 /*default set cache on*/
127 if (cobd->master_name) {
128 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
129 cobd->master_name = NULL;
131 if (cobd->cache_name) {
132 OBD_FREE(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
133 cobd->cache_name = NULL;
140 static int cobd_cleanup(struct obd_device *obd, int flags)
142 struct cache_obd *cobd = &obd->u.cobd;
146 if (!list_empty(&obd->obd_exports))
149 if (cobd->cache_name)
150 OBD_FREE(cobd->cache_name,
151 strlen(cobd->cache_name) + 1);
152 if (cobd->master_name)
153 OBD_FREE(cobd->master_name,
154 strlen(cobd->master_name) + 1);
156 rc = class_disconnect(cobd->master_exp, flags);
158 CERROR("error disconnecting master, err %d\n",
161 rc = class_disconnect(cobd->cache_exp, flags);
163 CERROR("error disconnecting master, err %d\n",
170 static inline struct obd_export *
171 cobd_get_exp(struct obd_device *obd)
173 struct cache_obd *cobd = &obd->u.cobd;
174 if (cobd->cache_on) {
175 CDEBUG(D_TRACE, "get cache exp %p \n", cobd->cache_exp);
176 if (cobd->cache_real_exp)
177 return cobd->cache_real_exp;
178 return cobd->cache_exp;
180 CDEBUG(D_TRACE, "get master exp %p \n", cobd->master_exp);
181 if (cobd->master_real_exp)
182 return cobd->master_real_exp;
183 return cobd->master_exp;
186 static int client_obd_connect(struct obd_device *obd, struct obd_export *exp,
187 struct lustre_handle *conn,
188 struct obd_connect_data *data,
191 struct obd_device *cli_obd;
198 cli_obd = class_exp2obd(exp);
202 rc = obd_connect(conn, cli_obd, &obd->obd_uuid, data, flags);
204 CERROR("error connecting err %d\n", rc);
209 static int client_obd_disconnect(struct obd_device *obd,
210 struct obd_export *exp,
213 struct obd_device *cli_obd;
217 cli_obd = class_exp2obd(exp);
218 cli_obd->obd_no_recov = obd->obd_no_recov;
220 rc = obd_disconnect(exp, flags);
222 CERROR("error disconnecting from %s, err %d\n",
223 cli_obd->obd_name, rc);
224 class_export_put(exp);
230 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
231 struct obd_uuid *cluuid, struct obd_connect_data *data,
234 struct lustre_handle cache_conn = { 0 };
235 struct cache_obd *cobd = &obd->u.cobd;
236 struct obd_export *exp, *cobd_exp;
240 rc = class_connect(conn, obd, cluuid);
243 exp = class_conn2export(conn);
245 cobd_exp = cobd_get_exp(obd);
247 /* connecting cache */
248 rc = client_obd_connect(obd, cobd_exp, &cache_conn,
251 GOTO(err_discon, rc);
253 cobd->cache_real_exp = class_conn2export(&cache_conn);
258 class_disconnect(exp, 0);
260 class_export_put(exp);
265 cobd_disconnect(struct obd_export *exp, unsigned long flags)
267 struct obd_device *obd;
268 struct obd_export *cobd_exp;
272 LASSERT(exp != NULL);
273 obd = class_exp2obd(exp);
275 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
276 exp->exp_handle.h_cookie);
279 cobd_exp = cobd_get_exp(obd);
281 rc = client_obd_disconnect(obd, cobd_exp, flags);
283 class_disconnect(exp, flags);
288 static int cobd_get_info(struct obd_export *exp, __u32 keylen,
289 void *key, __u32 *vallen, void *val)
291 struct obd_device *obd = class_exp2obd(exp);
292 struct obd_export *cobd_exp;
295 CERROR("invalid client cookie "LPX64"\n",
296 exp->exp_handle.h_cookie);
299 cobd_exp = cobd_get_exp(obd);
301 /* intercept cache utilisation info? */
302 return obd_get_info(cobd_exp, keylen, key, vallen, val);
305 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
306 void *key, obd_count vallen, void *val)
308 struct obd_device *obd = class_exp2obd(exp);
309 struct obd_export *cobd_exp;
312 CERROR("invalid client cookie "LPX64"\n",
313 exp->exp_handle.h_cookie);
316 cobd_exp = cobd_get_exp(obd);
318 /* intercept cache utilisation info? */
319 return obd_set_info(cobd_exp, keylen, key, vallen, val);
322 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
323 unsigned long max_age)
325 struct obd_export *cobd_exp;
327 cobd_exp = cobd_get_exp(obd);
329 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
332 static int cobd_packmd(struct obd_export *exp,
333 struct lov_mds_md **disk_tgt,
334 struct lov_stripe_md *mem_src)
336 struct obd_device *obd = class_exp2obd(exp);
337 struct obd_export *cobd_exp;
340 CERROR("invalid client cookie "LPX64"\n",
341 exp->exp_handle.h_cookie);
344 cobd_exp = cobd_get_exp(obd);
345 return obd_packmd(cobd_exp, disk_tgt, mem_src);
348 static int cobd_unpackmd(struct obd_export *exp,
349 struct lov_stripe_md **mem_tgt,
350 struct lov_mds_md *disk_src,
353 struct obd_device *obd = class_exp2obd(exp);
354 struct obd_export *cobd_exp;
357 CERROR("invalid client cookie "LPX64"\n",
358 exp->exp_handle.h_cookie);
361 cobd_exp = cobd_get_exp(obd);
362 return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
365 static int cobd_create(struct obd_export *exp, struct obdo *obdo,
366 void *acl, int acl_size,
367 struct lov_stripe_md **ea,
368 struct obd_trans_info *oti)
370 struct obd_device *obd = class_exp2obd(exp);
371 struct obd_export *cobd_exp;
374 CERROR("invalid client cookie "LPX64"\n",
375 exp->exp_handle.h_cookie);
378 cobd_exp = cobd_get_exp(obd);
379 return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
382 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
383 struct lov_stripe_md *ea,
384 struct obd_trans_info *oti)
386 struct obd_device *obd = class_exp2obd(exp);
387 struct obd_export *cobd_exp;
390 CERROR("invalid client cookie "LPX64"\n",
391 exp->exp_handle.h_cookie);
394 cobd_exp = cobd_get_exp(obd);
395 return obd_destroy(cobd_exp, obdo, ea, oti);
398 static int cobd_precleanup(struct obd_device *obd, int flags)
400 /* FIXME-WANGDI: do we need some cleanup here? */
404 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
405 struct lov_stripe_md *ea)
407 struct obd_device *obd = class_exp2obd(exp);
408 struct obd_export *cobd_exp;
411 CERROR("invalid client cookie "LPX64"\n",
412 exp->exp_handle.h_cookie);
415 cobd_exp = cobd_get_exp(obd);
416 return obd_getattr(cobd_exp, oa, ea);
419 static int cobd_getattr_async(struct obd_export *exp,
420 struct obdo *obdo, struct lov_stripe_md *ea,
421 struct ptlrpc_request_set *set)
423 struct obd_device *obd = class_exp2obd(exp);
424 struct obd_export *cobd_exp;
427 CERROR("invalid client cookie "LPX64"\n",
428 exp->exp_handle.h_cookie);
431 cobd_exp = cobd_get_exp(obd);
432 return obd_getattr_async(cobd_exp, obdo, ea, set);
435 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
436 struct lov_stripe_md *ea,
437 struct obd_trans_info *oti)
439 struct obd_device *obd = class_exp2obd(exp);
440 struct obd_export *cobd_exp;
443 CERROR("invalid client cookie "LPX64"\n",
444 exp->exp_handle.h_cookie);
447 cobd_exp = cobd_get_exp(obd);
448 return obd_setattr(cobd_exp, obdo, ea, oti);
451 static int cobd_md_getstatus(struct obd_export *exp,
452 struct lustre_id *rootid)
454 struct obd_device *obd = class_exp2obd(exp);
455 struct obd_export *cobd_exp;
458 CERROR("invalid client cookie "LPX64"\n",
459 exp->exp_handle.h_cookie);
462 cobd_exp = cobd_get_exp(obd);
463 return md_getstatus(cobd_exp, rootid);
466 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
467 struct lov_stripe_md *ea, obd_count oa_bufs,
468 struct brw_page *pg, struct obd_trans_info *oti)
470 struct obd_device *obd = class_exp2obd(exp);
471 struct obd_export *cobd_exp;
474 CERROR("invalid client cookie "LPX64"\n",
475 exp->exp_handle.h_cookie);
478 cobd_exp = cobd_get_exp(obd);
479 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
482 static int cobd_brw_async(int cmd, struct obd_export *exp,
483 struct obdo *oa, struct lov_stripe_md *ea,
484 obd_count oa_bufs, struct brw_page *pg,
485 struct ptlrpc_request_set *set,
486 struct obd_trans_info *oti)
488 struct obd_device *obd = class_exp2obd(exp);
489 struct obd_export *cobd_exp;
492 CERROR("invalid client cookie "LPX64"\n",
493 exp->exp_handle.h_cookie);
496 cobd_exp = cobd_get_exp(obd);
497 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
501 static int cobd_prep_async_page(struct obd_export *exp,
502 struct lov_stripe_md *lsm,
503 struct lov_oinfo *loi,
504 struct page *page, obd_off offset,
505 struct obd_async_page_ops *ops,
506 void *data, void **res)
508 struct obd_device *obd = class_exp2obd(exp);
509 struct obd_export *cobd_exp;
512 CERROR("invalid client cookie "LPX64"\n",
513 exp->exp_handle.h_cookie);
516 cobd_exp = cobd_get_exp(obd);
517 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
521 static int cobd_queue_async_io(struct obd_export *exp,
522 struct lov_stripe_md *lsm,
523 struct lov_oinfo *loi, void *cookie,
524 int cmd, obd_off off, int count,
525 obd_flags brw_flags, obd_flags async_flags)
527 struct obd_device *obd = class_exp2obd(exp);
528 struct obd_export *cobd_exp;
531 CERROR("invalid client cookie "LPX64"\n",
532 exp->exp_handle.h_cookie);
535 cobd_exp = cobd_get_exp(obd);
536 return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
537 brw_flags, async_flags);
540 static int cobd_set_async_flags(struct obd_export *exp,
541 struct lov_stripe_md *lsm,
542 struct lov_oinfo *loi, void *cookie,
543 obd_flags async_flags)
545 struct obd_device *obd = class_exp2obd(exp);
546 struct obd_export *cobd_exp;
549 CERROR("invalid client cookie "LPX64"\n",
550 exp->exp_handle.h_cookie);
553 cobd_exp = cobd_get_exp(obd);
554 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
557 static int cobd_queue_group_io(struct obd_export *exp,
558 struct lov_stripe_md *lsm,
559 struct lov_oinfo *loi,
560 struct obd_io_group *oig,
561 void *cookie, int cmd, obd_off off,
562 int count, obd_flags brw_flags,
563 obd_flags async_flags)
565 struct obd_device *obd = class_exp2obd(exp);
566 struct obd_export *cobd_exp;
569 CERROR("invalid client cookie "LPX64"\n",
570 exp->exp_handle.h_cookie);
573 cobd_exp = cobd_get_exp(obd);
574 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
575 cmd, off, count, brw_flags, async_flags);
578 static int cobd_trigger_group_io(struct obd_export *exp,
579 struct lov_stripe_md *lsm,
580 struct lov_oinfo *loi,
581 struct obd_io_group *oig)
583 struct obd_device *obd = class_exp2obd(exp);
584 struct obd_export *cobd_exp;
587 CERROR("invalid client cookie "LPX64"\n",
588 exp->exp_handle.h_cookie);
591 cobd_exp = cobd_get_exp(obd);
592 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
595 static int cobd_teardown_async_page(struct obd_export *exp,
596 struct lov_stripe_md *lsm,
597 struct lov_oinfo *loi, void *cookie)
599 struct obd_device *obd = class_exp2obd(exp);
600 struct obd_export *cobd_exp;
603 CERROR("invalid client cookie "LPX64"\n",
604 exp->exp_handle.h_cookie);
607 cobd_exp = cobd_get_exp(obd);
608 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
611 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
612 struct lov_stripe_md *ea, obd_size start,
613 obd_size end, struct obd_trans_info *oti)
615 struct obd_device *obd = class_exp2obd(exp);
616 struct obd_export *cobd_exp;
619 CERROR("invalid client cookie "LPX64"\n",
620 exp->exp_handle.h_cookie);
623 cobd_exp = cobd_get_exp(obd);
624 return obd_punch(cobd_exp, oa, ea, start, end, oti);
627 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
628 struct lov_stripe_md *ea, obd_size start,
631 struct obd_device *obd = class_exp2obd(exp);
632 struct obd_export *cobd_exp;
635 CERROR("invalid client cookie "LPX64"\n",
636 exp->exp_handle.h_cookie);
639 cobd_exp = cobd_get_exp(obd);
640 return obd_sync(cobd_exp, oa, ea, start, end);
643 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
644 __u32 type, ldlm_policy_data_t *policy,
645 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
646 void *gl_cb, void *data, __u32 lvb_len,
647 void *lvb_swabber, struct lustre_handle *lockh)
649 struct obd_device *obd = class_exp2obd(exp);
650 struct obd_export *cobd_exp;
653 CERROR("invalid client cookie "LPX64"\n",
654 exp->exp_handle.h_cookie);
657 cobd_exp = cobd_get_exp(obd);
658 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
659 bl_cb, cp_cb, gl_cb, data, lvb_len,
663 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
664 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
665 int *flags, void *data, struct lustre_handle *lockh)
667 struct obd_device *obd = class_exp2obd(exp);
668 struct obd_export *cobd_exp;
671 CERROR("invalid client cookie "LPX64"\n",
672 exp->exp_handle.h_cookie);
675 cobd_exp = cobd_get_exp(obd);
676 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
679 static int cobd_change_cbdata(struct obd_export *exp,
680 struct lov_stripe_md *lsm,
681 ldlm_iterator_t it, void *data)
683 struct obd_device *obd = class_exp2obd(exp);
684 struct obd_export *cobd_exp;
687 CERROR("invalid client cookie "LPX64"\n",
688 exp->exp_handle.h_cookie);
691 cobd_exp = cobd_get_exp(obd);
692 return obd_change_cbdata(cobd_exp, lsm, it, data);
695 static int cobd_cancel(struct obd_export *exp,
696 struct lov_stripe_md *ea, __u32 mode,
697 struct lustre_handle *lockh)
699 struct obd_device *obd = class_exp2obd(exp);
700 struct obd_export *cobd_exp;
703 CERROR("invalid client cookie "LPX64"\n",
704 exp->exp_handle.h_cookie);
707 cobd_exp = cobd_get_exp(obd);
708 return obd_cancel(cobd_exp, ea, mode, lockh);
711 static int cobd_cancel_unused(struct obd_export *exp,
712 struct lov_stripe_md *ea, int flags,
715 struct obd_device *obd = class_exp2obd(exp);
716 struct obd_export *cobd_exp;
719 CERROR("invalid client cookie "LPX64"\n",
720 exp->exp_handle.h_cookie);
723 cobd_exp = cobd_get_exp(obd);
724 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
727 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
728 int objcount, struct obd_ioobj *obj,
729 int niocount, struct niobuf_remote *nb,
730 struct niobuf_local *res, struct obd_trans_info *oti)
732 struct obd_device *obd = class_exp2obd(exp);
733 struct obd_export *cobd_exp;
736 CERROR("invalid client cookie "LPX64"\n",
737 exp->exp_handle.h_cookie);
740 cobd_exp = cobd_get_exp(obd);
741 return obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
745 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
746 int objcount, struct obd_ioobj *obj,
747 int niocount, struct niobuf_local *local,
748 struct obd_trans_info *oti, int rc)
750 struct obd_device *obd = class_exp2obd(exp);
751 struct obd_export *cobd_exp;
754 CERROR("invalid client cookie "LPX64"\n",
755 exp->exp_handle.h_cookie);
758 cobd_exp = cobd_get_exp(obd);
759 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
763 static int cobd_flush(struct obd_device *obd)
768 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
769 int len, void *karg, void *uarg)
771 struct obd_device *obd = class_exp2obd(exp);
772 struct cache_obd *cobd = &obd->u.cobd;
773 struct obd_export *cobd_exp;
780 case OBD_IOC_COBD_CON:
781 if (!cobd->cache_on) {
782 struct lustre_handle conn = {0};
784 rc = client_obd_disconnect(obd, cobd->master_real_exp, 0);
785 rc = client_obd_connect(obd, cobd->cache_exp, &conn,
786 NULL, OBD_OPT_REAL_CLIENT);
789 cobd->cache_real_exp = class_conn2export(&conn);
793 case OBD_IOC_COBD_COFF:
794 if (cobd->cache_on) {
795 struct lustre_handle conn = {0,};
796 struct obd_device *master = NULL;
797 struct obd_device *cache = NULL;
798 int easize, cooksize;
800 cache = class_exp2obd(cobd->cache_exp);
801 easize = cache->u.cli.cl_max_mds_easize;
802 cooksize = cache->u.cli.cl_max_mds_cookiesize;
804 rc = client_obd_disconnect(obd, cobd->cache_real_exp, 0);
805 rc = client_obd_connect(obd, cobd->master_exp, &conn,
806 NULL, OBD_OPT_REAL_CLIENT);
809 cobd->master_real_exp = class_conn2export(&conn);
811 master = class_exp2obd(cobd->master_exp);
812 master->u.cli.cl_max_mds_easize = easize;
813 master->u.cli.cl_max_mds_cookiesize = cooksize;
817 case OBD_IOC_COBD_CFLUSH:
818 if (cobd->cache_on) {
822 CERROR("%s: cache is turned off\n", obd->obd_name);
826 cobd_exp = cobd_get_exp(obd);
827 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
836 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
837 struct obd_device *disk_obd, int count,
838 struct llog_catid *logid)
840 struct obd_export *cobd_exp;
841 struct obd_device *cobd_obd;
843 cobd_exp = cobd_get_exp(obd);
844 cobd_obd = class_exp2obd(cobd_exp);
846 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
847 disk_obd, count, logid);
850 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
853 struct obd_export *cobd_exp;
854 struct obd_device *cobd_obd;
856 cobd_exp = cobd_get_exp(obd);
857 cobd_obd = class_exp2obd(cobd_exp);
859 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
862 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
863 int active, void *data)
865 struct obd_export *cobd_exp;
867 cobd_exp = cobd_get_exp(obd);
869 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
872 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
873 int type, struct obd_client_handle *handle, int flag)
875 struct obd_device *obd = class_exp2obd(exp);
876 struct obd_export *cobd_exp;
879 CERROR("invalid client cookie "LPX64"\n",
880 exp->exp_handle.h_cookie);
883 cobd_exp = cobd_get_exp(obd);
885 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
888 static int cobd_unpin(struct obd_export *exp,
889 struct obd_client_handle *handle, int flag)
891 struct obd_device *obd = class_exp2obd(exp);
892 struct obd_export *cobd_exp;
895 CERROR("invalid client cookie "LPX64"\n",
896 exp->exp_handle.h_cookie);
899 cobd_exp = cobd_get_exp(obd);
901 return obd_unpin(cobd_exp, handle, flag);
904 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
906 struct obd_export *cobd_exp;
908 cobd_exp = cobd_get_exp(exp->exp_obd);
909 return obd_init_ea_size(cobd_exp, easize, cookiesize);
912 static int cobd_import_event(struct obd_device *obd,
913 struct obd_import *imp,
914 enum obd_import_event event)
916 struct obd_export *cobd_exp;
918 cobd_exp = cobd_get_exp(obd);
920 obd_import_event(class_exp2obd(cobd_exp), imp, event);
925 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
926 __u64 valid, const char *ea_name, int ea_namelen,
927 unsigned int ea_size, struct ptlrpc_request **request)
929 struct obd_device *obd = class_exp2obd(exp);
930 struct obd_export *cobd_exp;
933 CERROR("invalid client cookie "LPX64"\n",
934 exp->exp_handle.h_cookie);
937 cobd_exp = cobd_get_exp(obd);
938 return md_getattr(cobd_exp, id, valid, ea_name, ea_namelen, ea_size,
942 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
943 struct ptlrpc_request *req, unsigned int offset,
944 struct obd_export *osc_exp, struct lustre_md *md)
946 struct obd_device *obd = class_exp2obd(mdc_exp);
947 struct obd_export *cobd_exp;
950 CERROR("invalid client cookie "LPX64"\n",
951 mdc_exp->exp_handle.h_cookie);
954 cobd_exp = cobd_get_exp(obd);
955 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
958 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
959 ldlm_iterator_t it, void *data)
961 struct obd_device *obd = class_exp2obd(exp);
962 struct obd_export *cobd_exp;
965 CERROR("invalid client cookie "LPX64"\n",
966 exp->exp_handle.h_cookie);
969 cobd_exp = cobd_get_exp(obd);
970 return md_change_cbdata(cobd_exp, id, it, data);
973 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
974 char *filename, int namelen, __u64 valid,
975 unsigned int ea_size, struct ptlrpc_request **request)
977 struct obd_device *obd = class_exp2obd(exp);
978 struct obd_export *cobd_exp;
981 CERROR("invalid client cookie "LPX64"\n",
982 exp->exp_handle.h_cookie);
985 cobd_exp = cobd_get_exp(obd);
986 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
990 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
991 const void *data, int datalen, int mode,
992 __u32 uid, __u32 gid, __u64 rdev,
993 struct ptlrpc_request **request)
995 struct obd_device *obd = class_exp2obd(exp);
996 struct obd_export *cobd_exp;
999 CERROR("invalid client cookie "LPX64"\n",
1000 exp->exp_handle.h_cookie);
1003 cobd_exp = cobd_get_exp(obd);
1004 return md_create(cobd_exp, op_data, data, datalen, mode,
1005 uid, gid, rdev, request);
1008 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1009 struct ptlrpc_request **request)
1011 struct obd_device *obd = class_exp2obd(exp);
1012 struct obd_export *cobd_exp;
1015 CERROR("invalid client cookie "LPX64"\n",
1016 exp->exp_handle.h_cookie);
1019 cobd_exp = cobd_get_exp(obd);
1020 return md_unlink(cobd_exp, data, request);
1023 static int cobd_md_valid_attrs(struct obd_export *exp,
1024 struct lustre_id *id)
1026 struct obd_device *obd = class_exp2obd(exp);
1027 struct obd_export *cobd_exp;
1030 CERROR("invalid client cookie "LPX64"\n",
1031 exp->exp_handle.h_cookie);
1034 cobd_exp = cobd_get_exp(obd);
1035 return md_valid_attrs(cobd_exp, id);
1038 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
1039 const char *old, int oldlen, const char *new,
1040 int newlen, struct ptlrpc_request **request)
1042 struct obd_device *obd = class_exp2obd(exp);
1043 struct obd_export *cobd_exp;
1046 CERROR("invalid client cookie "LPX64"\n",
1047 exp->exp_handle.h_cookie);
1050 cobd_exp = cobd_get_exp(obd);
1051 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1054 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1055 struct ptlrpc_request **request)
1057 struct obd_device *obd = class_exp2obd(exp);
1058 struct obd_export *cobd_exp;
1061 CERROR("invalid client cookie "LPX64"\n",
1062 exp->exp_handle.h_cookie);
1065 cobd_exp = cobd_get_exp(obd);
1066 return md_link(cobd_exp, data, request);
1069 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1070 struct iattr *iattr, void *ea, int ealen, void *ea2,
1071 int ea2len, struct ptlrpc_request **request)
1073 struct obd_device *obd = class_exp2obd(exp);
1074 struct obd_export *cobd_exp;
1077 CERROR("invalid client cookie "LPX64"\n",
1078 exp->exp_handle.h_cookie);
1081 cobd_exp = cobd_get_exp(obd);
1082 return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1085 static int cobd_md_readpage(struct obd_export *exp,
1086 struct lustre_id *mdc_id,
1087 __u64 offset, struct page *page,
1088 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_readpage(cobd_exp, mdc_id, offset, page, request);
1102 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1103 struct obd_client_handle *och,
1104 struct ptlrpc_request **request)
1106 struct obd_device *obd = class_exp2obd(exp);
1107 struct obd_export *cobd_exp;
1110 CERROR("invalid client cookie "LPX64"\n",
1111 exp->exp_handle.h_cookie);
1114 cobd_exp = cobd_get_exp(obd);
1115 return md_close(cobd_exp, obdo, och, request);
1118 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1120 struct obd_device *obd = class_exp2obd(exp);
1121 struct obd_export *cobd_exp;
1124 CERROR("invalid client cookie "LPX64"\n",
1125 exp->exp_handle.h_cookie);
1128 cobd_exp = cobd_get_exp(obd);
1129 return md_done_writing(cobd_exp, obdo);
1132 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1133 struct ptlrpc_request **request)
1135 struct obd_device *obd = class_exp2obd(exp);
1136 struct obd_export *cobd_exp;
1139 CERROR("invalid client cookie "LPX64"\n",
1140 exp->exp_handle.h_cookie);
1143 cobd_exp = cobd_get_exp(obd);
1145 return md_sync(cobd_exp, id, request);
1148 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1149 struct obd_client_handle *och,
1150 struct ptlrpc_request *open_req)
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_set_open_replay_data(cobd_exp, och, open_req);
1165 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1166 struct obd_client_handle *och)
1168 struct obd_device *obd = class_exp2obd(exp);
1169 struct obd_export *cobd_exp;
1172 CERROR("invalid client cookie "LPX64"\n",
1173 exp->exp_handle.h_cookie);
1176 cobd_exp = cobd_get_exp(obd);
1178 return md_clear_open_replay_data(cobd_exp, och);
1181 static int cobd_md_store_inode_generation(struct obd_export *exp,
1182 struct ptlrpc_request *req,
1183 int reqoff, int repoff)
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_store_inode_generation(cobd_exp, req, reqoff, repoff);
1198 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1200 struct obd_device *obd = class_exp2obd(exp);
1201 struct obd_export *cobd_exp;
1204 CERROR("invalid client cookie "LPX64"\n",
1205 exp->exp_handle.h_cookie);
1208 cobd_exp = cobd_get_exp(obd);
1210 return md_set_lock_data(cobd_exp, l, data);
1213 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1214 struct lookup_intent *it, int lock_mode,
1215 struct mdc_op_data *data, struct lustre_handle *lockh,
1216 void *lmm, int lmmsize,
1217 ldlm_completion_callback cb_completion,
1218 ldlm_blocking_callback cb_blocking, void *cb_data)
1220 struct obd_device *obd = class_exp2obd(exp);
1221 struct obd_export *cobd_exp;
1224 CERROR("invalid client cookie "LPX64"\n",
1225 exp->exp_handle.h_cookie);
1228 cobd_exp = cobd_get_exp(obd);
1229 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1230 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1234 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1235 const char *name, int len, void *lmm, int lmmsize,
1236 struct lustre_id *cid, struct lookup_intent *it,
1237 int lookup_flags, struct ptlrpc_request **reqp,
1238 ldlm_blocking_callback cb_blocking)
1240 struct obd_device *obd = class_exp2obd(exp);
1241 struct obd_export *cobd_exp;
1244 CERROR("invalid client cookie "LPX64"\n",
1245 exp->exp_handle.h_cookie);
1248 cobd_exp = cobd_get_exp(obd);
1249 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1250 cid, it, lookup_flags, reqp, cb_blocking);
1253 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1254 struct lustre_id *id)
1256 struct obd_device *obd = class_exp2obd(exp);
1257 struct obd_export *cobd_exp;
1260 CERROR("invalid client cookie "LPX64"\n",
1261 exp->exp_handle.h_cookie);
1264 cobd_exp = cobd_get_exp(obd);
1265 return md_get_real_obd(cobd_exp, id);
1268 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1269 struct lustre_id *id, char *name,
1270 int namelen, struct lustre_id *id2,
1271 ldlm_iterator_t it, void *data)
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_change_cbdata_name(cobd_exp, id, name, namelen,
1285 static struct obd_ops cobd_obd_ops = {
1286 .o_owner = THIS_MODULE,
1287 .o_attach = cobd_attach,
1288 .o_detach = cobd_detach,
1289 .o_setup = cobd_setup,
1290 .o_cleanup = cobd_cleanup,
1291 .o_connect = cobd_connect,
1292 .o_disconnect = cobd_disconnect,
1293 .o_set_info = cobd_set_info,
1294 .o_get_info = cobd_get_info,
1295 .o_statfs = cobd_statfs,
1297 .o_packmd = cobd_packmd,
1298 .o_unpackmd = cobd_unpackmd,
1299 .o_create = cobd_create,
1300 .o_destroy = cobd_destroy,
1301 .o_precleanup = cobd_precleanup,
1302 .o_getattr = cobd_getattr,
1303 .o_getattr_async = cobd_getattr_async,
1304 .o_setattr = cobd_setattr,
1307 .o_brw_async = cobd_brw_async,
1308 .o_prep_async_page = cobd_prep_async_page,
1309 .o_queue_async_io = cobd_queue_async_io,
1310 .o_set_async_flags = cobd_set_async_flags,
1311 .o_queue_group_io = cobd_queue_group_io,
1312 .o_trigger_group_io = cobd_trigger_group_io,
1313 .o_teardown_async_page = cobd_teardown_async_page,
1314 .o_preprw = cobd_preprw,
1315 .o_punch = cobd_punch,
1316 .o_sync = cobd_sync,
1317 .o_enqueue = cobd_enqueue,
1318 .o_match = cobd_match,
1319 .o_change_cbdata = cobd_change_cbdata,
1320 .o_cancel = cobd_cancel,
1321 .o_cancel_unused = cobd_cancel_unused,
1322 .o_iocontrol = cobd_iocontrol,
1323 .o_commitrw = cobd_commitrw,
1324 .o_llog_init = cobd_llog_init,
1325 .o_llog_finish = cobd_llog_finish,
1326 .o_notify = cobd_notify,
1328 .o_unpin = cobd_unpin,
1329 .o_import_event = cobd_import_event,
1330 .o_init_ea_size = cobd_init_ea_size,
1333 struct md_ops cobd_md_ops = {
1334 .m_getstatus = cobd_md_getstatus,
1335 .m_getattr = cobd_md_getattr,
1336 .m_req2lustre_md = cobd_md_req2lustre_md,
1337 .m_change_cbdata = cobd_md_change_cbdata,
1338 .m_getattr_lock = cobd_md_getattr_lock,
1339 .m_create = cobd_md_create,
1340 .m_unlink = cobd_md_unlink,
1341 .m_valid_attrs = cobd_md_valid_attrs,
1342 .m_rename = cobd_md_rename,
1343 .m_link = cobd_md_link,
1344 .m_setattr = cobd_md_setattr,
1345 .m_readpage = cobd_md_readpage,
1346 .m_close = cobd_md_close,
1347 .m_done_writing = cobd_md_done_writing,
1348 .m_sync = cobd_md_sync,
1349 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1350 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1351 .m_store_inode_generation = cobd_md_store_inode_generation,
1352 .m_set_lock_data = cobd_md_set_lock_data,
1353 .m_enqueue = cobd_md_enqueue,
1354 .m_get_real_obd = cobd_md_get_real_obd,
1355 .m_intent_lock = cobd_md_intent_lock,
1356 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1359 static int __init cobd_init(void)
1361 struct lprocfs_static_vars lvars;
1364 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1366 lprocfs_init_vars(cobd, &lvars);
1367 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1368 lvars.module_vars, OBD_CACHE_DEVICENAME));
1371 static void /*__exit*/ cobd_exit(void)
1373 class_unregister_type(OBD_CACHE_DEVICENAME);
1376 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1377 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1378 MODULE_LICENSE("GPL");
1380 module_init(cobd_init);
1381 module_exit(cobd_exit);