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;
58 if (lcfg->lcfg_inllen1 == 0 || lcfg->lcfg_inlbuf1 == NULL) {
59 CERROR("%s: setup requires master device name\n",
64 if (lcfg->lcfg_inllen2 == 0 || lcfg->lcfg_inlbuf2 == NULL) {
65 CERROR("%s: setup requires cache device name\n",
70 master = class_name2obd(lcfg->lcfg_inlbuf1);
72 CERROR("%s: unable to find master: %s\n",
73 obd->obd_name, lcfg->lcfg_inlbuf1);
77 sema_init(&cobd->sem, 1);
79 OBD_ALLOC(cobd->master_name, lcfg->lcfg_inllen1);
80 if (!cobd->master_name)
82 memcpy(cobd->master_name, lcfg->lcfg_inlbuf1,
85 OBD_ALLOC(cobd->cache_name, lcfg->lcfg_inllen2);
86 if (!cobd->cache_name)
87 GOTO(put_names, rc = -ENOMEM);
88 memcpy(cobd->cache_name, lcfg->lcfg_inlbuf2,
94 OBD_FREE(cobd->master_name, lcfg->lcfg_inllen1);
95 cobd->master_name = NULL;
100 static int cobd_cleanup(struct obd_device *obd, int flags)
102 struct cache_obd *cobd = &obd->u.cobd;
105 if (!list_empty(&obd->obd_exports))
108 if (cobd->cache_name)
109 OBD_FREE(cobd->cache_name,
110 strlen(cobd->cache_name) + 1);
111 if (cobd->master_name)
112 OBD_FREE(cobd->master_name,
113 strlen(cobd->master_name) + 1);
118 static inline struct obd_export *
119 cobd_get_exp(struct obd_device *obd)
121 struct cache_obd *cobd = &obd->u.cobd;
123 return cobd->cache_exp;
124 return cobd->master_exp;
127 static int client_obd_connect(struct obd_device *obd, char *name,
128 struct lustre_handle *conn,
131 struct obd_device *cli_obd;
139 cli_obd = class_name2obd(name);
140 if (cli_obd == NULL) {
141 CERROR("%s: unable to find a client for obd: %s\n",
142 obd->obd_name, name);
145 rc = obd_connect(conn, cli_obd, &obd->obd_uuid, flags);
147 CERROR("error connecting to %s, err %d\n",
153 static int client_obd_disconnect(struct obd_device *obd,
154 struct obd_export *exp,
157 struct obd_device *cli_obd;
161 cli_obd = class_exp2obd(exp);
162 cli_obd->obd_no_recov = obd->obd_no_recov;
164 rc = obd_disconnect(exp, flags);
166 CERROR("error disconnecting from %s, err %d\n",
167 cli_obd->obd_name, rc);
168 class_export_put(exp);
174 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
175 struct obd_uuid *cluuid, unsigned long flags)
177 struct lustre_handle cache_conn = { 0 };
178 struct cache_obd *cobd = &obd->u.cobd;
179 struct obd_export *exp;
183 /* connecting class */
184 rc = class_connect(conn, obd, cluuid);
187 exp = class_conn2export(conn);
189 /* connecting cache */
190 rc = client_obd_connect(obd, cobd->cache_name,
193 GOTO(err_discon, rc);
194 cobd->cache_exp = class_conn2export(&cache_conn);
200 class_disconnect(exp, 0);
202 class_export_put(exp);
207 cobd_disconnect(struct obd_export *exp, unsigned long flags)
209 struct obd_device *obd;
210 struct cache_obd *cobd;
214 LASSERT(exp != NULL);
215 obd = class_exp2obd(exp);
217 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
218 exp->exp_handle.h_cookie);
224 if (cobd->cache_on) {
225 rc = client_obd_disconnect(obd, cobd->cache_exp,
227 cobd->cache_exp = NULL;
229 rc = client_obd_disconnect(obd, cobd->master_exp,
231 cobd->master_exp = NULL;
234 rc = class_disconnect(exp, flags);
238 static int cobd_get_info(struct obd_export *exp, obd_count keylen,
239 void *key, __u32 *vallen, void *val)
241 struct obd_device *obd = class_exp2obd(exp);
242 struct obd_export *cobd_exp;
245 CERROR("invalid client cookie "LPX64"\n",
246 exp->exp_handle.h_cookie);
249 cobd_exp = cobd_get_exp(obd);
251 /* intercept cache utilisation info? */
252 return obd_get_info(cobd_exp, keylen, key, vallen, val);
255 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
256 void *key, obd_count vallen, void *val)
258 struct obd_device *obd = class_exp2obd(exp);
259 struct obd_export *cobd_exp;
262 CERROR("invalid client cookie "LPX64"\n",
263 exp->exp_handle.h_cookie);
266 cobd_exp = cobd_get_exp(obd);
268 /* intercept cache utilisation info? */
269 return obd_set_info(cobd_exp, keylen, key, vallen, val);
272 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
273 unsigned long max_age)
275 struct obd_export *cobd_exp;
277 cobd_exp = cobd_get_exp(obd);
279 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
282 static int cobd_packmd(struct obd_export *exp,
283 struct lov_mds_md **disk_tgt,
284 struct lov_stripe_md *mem_src)
286 struct obd_device *obd = class_exp2obd(exp);
287 struct obd_export *cobd_exp;
290 CERROR("invalid client cookie "LPX64"\n",
291 exp->exp_handle.h_cookie);
294 cobd_exp = cobd_get_exp(obd);
295 return obd_packmd(cobd_exp, disk_tgt, mem_src);
298 static int cobd_unpackmd(struct obd_export *exp,
299 struct lov_stripe_md **mem_tgt,
300 struct lov_mds_md *disk_src,
303 struct obd_device *obd = class_exp2obd(exp);
304 struct obd_export *cobd_exp;
307 CERROR("invalid client cookie "LPX64"\n",
308 exp->exp_handle.h_cookie);
311 cobd_exp = cobd_get_exp(obd);
312 return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
315 static int cobd_create(struct obd_export *exp, struct obdo *obdo,
316 struct lov_stripe_md **ea,
317 struct obd_trans_info *oti)
319 struct obd_device *obd = class_exp2obd(exp);
320 struct obd_export *cobd_exp;
323 CERROR("invalid client cookie "LPX64"\n",
324 exp->exp_handle.h_cookie);
327 cobd_exp = cobd_get_exp(obd);
328 return obd_create(cobd_exp, obdo, ea, oti);
331 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
332 struct lov_stripe_md *ea,
333 struct obd_trans_info *oti)
335 struct obd_device *obd = class_exp2obd(exp);
336 struct obd_export *cobd_exp;
339 CERROR("invalid client cookie "LPX64"\n",
340 exp->exp_handle.h_cookie);
343 cobd_exp = cobd_get_exp(obd);
344 return obd_destroy(cobd_exp, obdo, ea, oti);
347 static int cobd_precleanup(struct obd_device *obd, int flags)
349 /* FIXME-WANGDI: do we need some cleanup here? */
353 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
354 struct lov_stripe_md *lsm)
356 struct obd_device *obd = class_exp2obd(exp);
357 struct obd_export *cobd_exp;
360 CERROR("invalid client cookie "LPX64"\n",
361 exp->exp_handle.h_cookie);
364 cobd_exp = cobd_get_exp(obd);
365 return obd_getattr(cobd_exp, oa, lsm);
368 static int cobd_getattr_async(struct obd_export *exp,
369 struct obdo *obdo, struct lov_stripe_md *ea,
370 struct ptlrpc_request_set *set)
372 struct obd_device *obd = class_exp2obd(exp);
373 struct obd_export *cobd_exp;
376 CERROR("invalid client cookie "LPX64"\n",
377 exp->exp_handle.h_cookie);
380 cobd_exp = cobd_get_exp(obd);
381 return obd_getattr_async(cobd_exp, obdo, ea, set);
384 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
385 struct lov_stripe_md *ea,
386 struct obd_trans_info *oti)
388 struct obd_device *obd = class_exp2obd(exp);
389 struct obd_export *cobd_exp;
392 CERROR("invalid client cookie "LPX64"\n",
393 exp->exp_handle.h_cookie);
396 cobd_exp = cobd_get_exp(obd);
397 return obd_setattr(cobd_exp, obdo, ea, oti);
400 static int cobd_md_getstatus(struct obd_export *exp,
401 struct lustre_id *rootid)
403 struct obd_device *obd = class_exp2obd(exp);
404 struct obd_export *cobd_exp;
407 CERROR("invalid client cookie "LPX64"\n",
408 exp->exp_handle.h_cookie);
411 cobd_exp = cobd_get_exp(obd);
412 return md_getstatus(cobd_exp, rootid);
415 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
416 struct lov_stripe_md *ea, obd_count oa_bufs,
417 struct brw_page *pg, struct obd_trans_info *oti)
419 struct obd_device *obd = class_exp2obd(exp);
420 struct obd_export *cobd_exp;
423 CERROR("invalid client cookie "LPX64"\n",
424 exp->exp_handle.h_cookie);
427 cobd_exp = cobd_get_exp(obd);
428 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
431 static int cobd_brw_async(int cmd, struct obd_export *exp,
432 struct obdo *oa, struct lov_stripe_md *ea,
433 obd_count oa_bufs, struct brw_page *pg,
434 struct ptlrpc_request_set *set,
435 struct obd_trans_info *oti)
437 struct obd_device *obd = class_exp2obd(exp);
438 struct obd_export *cobd_exp;
441 CERROR("invalid client cookie "LPX64"\n",
442 exp->exp_handle.h_cookie);
445 cobd_exp = cobd_get_exp(obd);
446 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
450 static int cobd_prep_async_page(struct obd_export *exp,
451 struct lov_stripe_md *lsm,
452 struct lov_oinfo *loi,
453 struct page *page, obd_off offset,
454 struct obd_async_page_ops *ops,
455 void *data, void **res)
457 struct obd_device *obd = class_exp2obd(exp);
458 struct obd_export *cobd_exp;
461 CERROR("invalid client cookie "LPX64"\n",
462 exp->exp_handle.h_cookie);
465 cobd_exp = cobd_get_exp(obd);
466 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
470 static int cobd_queue_async_io(struct obd_export *exp,
471 struct lov_stripe_md *lsm,
472 struct lov_oinfo *loi, void *cookie,
473 int cmd, obd_off off, int count,
474 obd_flags brw_flags, obd_flags async_flags)
476 struct obd_device *obd = class_exp2obd(exp);
477 struct obd_export *cobd_exp;
480 CERROR("invalid client cookie "LPX64"\n",
481 exp->exp_handle.h_cookie);
484 cobd_exp = cobd_get_exp(obd);
485 return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
486 brw_flags, async_flags);
489 static int cobd_set_async_flags(struct obd_export *exp,
490 struct lov_stripe_md *lsm,
491 struct lov_oinfo *loi, void *cookie,
492 obd_flags async_flags)
494 struct obd_device *obd = class_exp2obd(exp);
495 struct obd_export *cobd_exp;
498 CERROR("invalid client cookie "LPX64"\n",
499 exp->exp_handle.h_cookie);
502 cobd_exp = cobd_get_exp(obd);
503 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
506 static int cobd_queue_group_io(struct obd_export *exp,
507 struct lov_stripe_md *lsm,
508 struct lov_oinfo *loi,
509 struct obd_io_group *oig,
510 void *cookie, int cmd, obd_off off,
511 int count, obd_flags brw_flags,
512 obd_flags async_flags)
514 struct obd_device *obd = class_exp2obd(exp);
515 struct obd_export *cobd_exp;
518 CERROR("invalid client cookie "LPX64"\n",
519 exp->exp_handle.h_cookie);
522 cobd_exp = cobd_get_exp(obd);
523 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
524 cmd, off, count, brw_flags, async_flags);
527 static int cobd_trigger_group_io(struct obd_export *exp,
528 struct lov_stripe_md *lsm,
529 struct lov_oinfo *loi,
530 struct obd_io_group *oig)
532 struct obd_device *obd = class_exp2obd(exp);
533 struct obd_export *cobd_exp;
536 CERROR("invalid client cookie "LPX64"\n",
537 exp->exp_handle.h_cookie);
540 cobd_exp = cobd_get_exp(obd);
541 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
544 static int cobd_teardown_async_page(struct obd_export *exp,
545 struct lov_stripe_md *lsm,
546 struct lov_oinfo *loi, void *cookie)
548 struct obd_device *obd = class_exp2obd(exp);
549 struct obd_export *cobd_exp;
552 CERROR("invalid client cookie "LPX64"\n",
553 exp->exp_handle.h_cookie);
556 cobd_exp = cobd_get_exp(obd);
557 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
560 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
561 struct lov_stripe_md *ea, obd_size start,
562 obd_size end, struct obd_trans_info *oti)
564 struct obd_device *obd = class_exp2obd(exp);
565 struct obd_export *cobd_exp;
568 CERROR("invalid client cookie "LPX64"\n",
569 exp->exp_handle.h_cookie);
572 cobd_exp = cobd_get_exp(obd);
573 return obd_punch(cobd_exp, oa, ea, start, end, oti);
576 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
577 struct lov_stripe_md *ea, obd_size start,
580 struct obd_device *obd = class_exp2obd(exp);
581 struct obd_export *cobd_exp;
584 CERROR("invalid client cookie "LPX64"\n",
585 exp->exp_handle.h_cookie);
588 cobd_exp = cobd_get_exp(obd);
589 return obd_sync(cobd_exp, oa, ea, start, end);
592 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
593 __u32 type, ldlm_policy_data_t *policy,
594 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
595 void *gl_cb, void *data, __u32 lvb_len,
596 void *lvb_swabber, struct lustre_handle *lockh)
598 struct obd_device *obd = class_exp2obd(exp);
599 struct obd_export *cobd_exp;
602 CERROR("invalid client cookie "LPX64"\n",
603 exp->exp_handle.h_cookie);
606 cobd_exp = cobd_get_exp(obd);
607 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
608 bl_cb, cp_cb, gl_cb, data, lvb_len,
612 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
613 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
614 int *flags, void *data, struct lustre_handle *lockh)
616 struct obd_device *obd = class_exp2obd(exp);
617 struct obd_export *cobd_exp;
620 CERROR("invalid client cookie "LPX64"\n",
621 exp->exp_handle.h_cookie);
624 cobd_exp = cobd_get_exp(obd);
625 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
628 static int cobd_change_cbdata(struct obd_export *exp,
629 struct lov_stripe_md *lsm,
630 ldlm_iterator_t it, void *data)
632 struct obd_device *obd = class_exp2obd(exp);
633 struct obd_export *cobd_exp;
636 CERROR("invalid client cookie "LPX64"\n",
637 exp->exp_handle.h_cookie);
640 cobd_exp = cobd_get_exp(obd);
641 return obd_change_cbdata(cobd_exp, lsm, it, data);
644 static int cobd_cancel(struct obd_export *exp,
645 struct lov_stripe_md *ea, __u32 mode,
646 struct lustre_handle *lockh)
648 struct obd_device *obd = class_exp2obd(exp);
649 struct obd_export *cobd_exp;
652 CERROR("invalid client cookie "LPX64"\n",
653 exp->exp_handle.h_cookie);
656 cobd_exp = cobd_get_exp(obd);
657 return obd_cancel(cobd_exp, ea, mode, lockh);
660 static int cobd_cancel_unused(struct obd_export *exp,
661 struct lov_stripe_md *ea, int flags,
664 struct obd_device *obd = class_exp2obd(exp);
665 struct obd_export *cobd_exp;
668 CERROR("invalid client cookie "LPX64"\n",
669 exp->exp_handle.h_cookie);
672 cobd_exp = cobd_get_exp(obd);
673 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
676 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
677 int objcount, struct obd_ioobj *obj,
678 int niocount, struct niobuf_remote *nb,
679 struct niobuf_local *res, struct obd_trans_info *oti)
681 struct obd_device *obd = class_exp2obd(exp);
682 struct obd_export *cobd_exp;
685 CERROR("invalid client cookie "LPX64"\n",
686 exp->exp_handle.h_cookie);
689 cobd_exp = cobd_get_exp(obd);
690 return obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
694 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
695 int objcount, struct obd_ioobj *obj,
696 int niocount, struct niobuf_local *local,
697 struct obd_trans_info *oti, int rc)
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_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
712 static int cobd_flush(struct obd_device *obd)
717 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
718 int len, void *karg, void *uarg)
720 struct obd_device *obd = class_exp2obd(exp);
721 struct cache_obd *cobd = &obd->u.cobd;
722 struct obd_export *cobd_exp;
729 case OBD_IOC_COBD_CON:
730 if (!cobd->cache_on) {
731 struct lustre_handle conn = {0};
733 rc = client_obd_disconnect(obd, cobd->master_exp, 0);
734 rc = client_obd_connect(obd, cobd->cache_name, &conn, 0);
737 cobd->cache_exp = class_conn2export(&conn);
741 case OBD_IOC_COBD_COFF:
742 if (cobd->cache_on) {
743 struct lustre_handle conn = {0,};
744 struct obd_device *master = NULL;
745 struct obd_device *cache = NULL;
746 int easize, cooksize;
748 cache = class_exp2obd(cobd->cache_exp);
749 easize = cache->u.cli.cl_max_mds_easize;
750 cooksize = cache->u.cli.cl_max_mds_cookiesize;
752 rc = client_obd_disconnect(obd, cobd->cache_exp, 0);
753 rc = client_obd_connect(obd, cobd->master_name, &conn, 0);
756 cobd->master_exp = class_conn2export(&conn);
758 master = class_exp2obd(cobd->master_exp);
759 master->u.cli.cl_max_mds_easize = easize;
760 master->u.cli.cl_max_mds_cookiesize = cooksize;
764 case OBD_IOC_COBD_CFLUSH:
765 if (cobd->cache_on) {
769 CERROR("%s: cache is turned off\n", obd->obd_name);
773 cobd_exp = cobd_get_exp(obd);
774 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
783 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
784 struct obd_device *disk_obd, int count,
785 struct llog_catid *logid)
787 struct obd_export *cobd_exp;
788 struct obd_device *cobd_obd;
790 cobd_exp = cobd_get_exp(obd);
791 cobd_obd = class_exp2obd(cobd_exp);
793 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
794 disk_obd, count, logid);
797 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
800 struct obd_export *cobd_exp;
801 struct obd_device *cobd_obd;
803 cobd_exp = cobd_get_exp(obd);
804 cobd_obd = class_exp2obd(cobd_exp);
806 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
809 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
810 int active, void *data)
812 struct obd_export *cobd_exp;
814 cobd_exp = cobd_get_exp(obd);
816 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
819 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
820 int type, struct obd_client_handle *handle, int flag)
822 struct obd_device *obd = class_exp2obd(exp);
823 struct obd_export *cobd_exp;
826 CERROR("invalid client cookie "LPX64"\n",
827 exp->exp_handle.h_cookie);
830 cobd_exp = cobd_get_exp(obd);
832 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
835 static int cobd_unpin(struct obd_export *exp,
836 struct obd_client_handle *handle, int flag)
838 struct obd_device *obd = class_exp2obd(exp);
839 struct obd_export *cobd_exp;
842 CERROR("invalid client cookie "LPX64"\n",
843 exp->exp_handle.h_cookie);
846 cobd_exp = cobd_get_exp(obd);
848 return obd_unpin(cobd_exp, handle, flag);
851 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
853 struct obd_export *cobd_exp;
855 cobd_exp = cobd_get_exp(exp->exp_obd);
856 return obd_init_ea_size(cobd_exp, easize, cookiesize);
859 static int cobd_import_event(struct obd_device *obd,
860 struct obd_import *imp,
861 enum obd_import_event event)
863 struct obd_export *cobd_exp;
865 cobd_exp = cobd_get_exp(obd);
867 obd_import_event(class_exp2obd(cobd_exp), imp, event);
872 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
873 __u64 valid, unsigned int ea_size,
874 struct ptlrpc_request **request)
876 struct obd_device *obd = class_exp2obd(exp);
877 struct obd_export *cobd_exp;
880 CERROR("invalid client cookie "LPX64"\n",
881 exp->exp_handle.h_cookie);
884 cobd_exp = cobd_get_exp(obd);
885 return md_getattr(cobd_exp, id, valid, ea_size, request);
888 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
889 struct ptlrpc_request *req, unsigned int offset,
890 struct obd_export *osc_exp, struct lustre_md *md)
892 struct obd_device *obd = class_exp2obd(mdc_exp);
893 struct obd_export *cobd_exp;
896 CERROR("invalid client cookie "LPX64"\n",
897 mdc_exp->exp_handle.h_cookie);
900 cobd_exp = cobd_get_exp(obd);
901 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
904 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
905 ldlm_iterator_t it, void *data)
907 struct obd_device *obd = class_exp2obd(exp);
908 struct obd_export *cobd_exp;
911 CERROR("invalid client cookie "LPX64"\n",
912 exp->exp_handle.h_cookie);
915 cobd_exp = cobd_get_exp(obd);
916 return md_change_cbdata(cobd_exp, id, it, data);
919 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
920 char *filename, int namelen, __u64 valid,
921 unsigned int ea_size, struct ptlrpc_request **request)
923 struct obd_device *obd = class_exp2obd(exp);
924 struct obd_export *cobd_exp;
927 CERROR("invalid client cookie "LPX64"\n",
928 exp->exp_handle.h_cookie);
931 cobd_exp = cobd_get_exp(obd);
932 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
936 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
937 const void *data, int datalen, int mode,
938 __u32 uid, __u32 gid, __u64 rdev,
939 struct ptlrpc_request **request)
941 struct obd_device *obd = class_exp2obd(exp);
942 struct obd_export *cobd_exp;
945 CERROR("invalid client cookie "LPX64"\n",
946 exp->exp_handle.h_cookie);
949 cobd_exp = cobd_get_exp(obd);
950 return md_create(cobd_exp, op_data, data, datalen, mode,
951 uid, gid, rdev, request);
954 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
955 struct ptlrpc_request **request)
957 struct obd_device *obd = class_exp2obd(exp);
958 struct obd_export *cobd_exp;
961 CERROR("invalid client cookie "LPX64"\n",
962 exp->exp_handle.h_cookie);
965 cobd_exp = cobd_get_exp(obd);
966 return md_unlink(cobd_exp, data, request);
969 static int cobd_md_valid_attrs(struct obd_export *exp,
970 struct lustre_id *id)
972 struct obd_device *obd = class_exp2obd(exp);
973 struct obd_export *cobd_exp;
976 CERROR("invalid client cookie "LPX64"\n",
977 exp->exp_handle.h_cookie);
980 cobd_exp = cobd_get_exp(obd);
981 return md_valid_attrs(cobd_exp, id);
984 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
985 const char *old, int oldlen, const char *new,
986 int newlen, struct ptlrpc_request **request)
988 struct obd_device *obd = class_exp2obd(exp);
989 struct obd_export *cobd_exp;
992 CERROR("invalid client cookie "LPX64"\n",
993 exp->exp_handle.h_cookie);
996 cobd_exp = cobd_get_exp(obd);
997 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1000 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1001 struct ptlrpc_request **request)
1003 struct obd_device *obd = class_exp2obd(exp);
1004 struct obd_export *cobd_exp;
1007 CERROR("invalid client cookie "LPX64"\n",
1008 exp->exp_handle.h_cookie);
1011 cobd_exp = cobd_get_exp(obd);
1012 return md_link(cobd_exp, data, request);
1015 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1016 struct iattr *iattr, void *ea, int ealen, void *ea2,
1017 int ea2len, 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_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1031 static int cobd_md_readpage(struct obd_export *exp,
1032 struct lustre_id *mdc_id,
1033 __u64 offset, struct page *page,
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_readpage(cobd_exp, mdc_id, offset, page, request);
1048 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1049 struct obd_client_handle *och,
1050 struct ptlrpc_request **request)
1052 struct obd_device *obd = class_exp2obd(exp);
1053 struct obd_export *cobd_exp;
1056 CERROR("invalid client cookie "LPX64"\n",
1057 exp->exp_handle.h_cookie);
1060 cobd_exp = cobd_get_exp(obd);
1061 return md_close(cobd_exp, obdo, och, request);
1064 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1066 struct obd_device *obd = class_exp2obd(exp);
1067 struct obd_export *cobd_exp;
1070 CERROR("invalid client cookie "LPX64"\n",
1071 exp->exp_handle.h_cookie);
1074 cobd_exp = cobd_get_exp(obd);
1075 return md_done_writing(cobd_exp, obdo);
1078 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1079 struct ptlrpc_request **request)
1081 struct obd_device *obd = class_exp2obd(exp);
1082 struct obd_export *cobd_exp;
1085 CERROR("invalid client cookie "LPX64"\n",
1086 exp->exp_handle.h_cookie);
1089 cobd_exp = cobd_get_exp(obd);
1091 return md_sync(cobd_exp, id, request);
1094 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1095 struct obd_client_handle *och,
1096 struct ptlrpc_request *open_req)
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);
1108 return md_set_open_replay_data(cobd_exp, och, open_req);
1111 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1112 struct obd_client_handle *och)
1114 struct obd_device *obd = class_exp2obd(exp);
1115 struct obd_export *cobd_exp;
1118 CERROR("invalid client cookie "LPX64"\n",
1119 exp->exp_handle.h_cookie);
1122 cobd_exp = cobd_get_exp(obd);
1124 return md_clear_open_replay_data(cobd_exp, och);
1127 static int cobd_md_store_inode_generation(struct obd_export *exp,
1128 struct ptlrpc_request *req,
1129 int reqoff, int repoff)
1131 struct obd_device *obd = class_exp2obd(exp);
1132 struct obd_export *cobd_exp;
1135 CERROR("invalid client cookie "LPX64"\n",
1136 exp->exp_handle.h_cookie);
1139 cobd_exp = cobd_get_exp(obd);
1141 return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1144 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1146 struct obd_device *obd = class_exp2obd(exp);
1147 struct obd_export *cobd_exp;
1150 CERROR("invalid client cookie "LPX64"\n",
1151 exp->exp_handle.h_cookie);
1154 cobd_exp = cobd_get_exp(obd);
1156 return md_set_lock_data(cobd_exp, l, data);
1159 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1160 struct lookup_intent *it, int lock_mode,
1161 struct mdc_op_data *data, struct lustre_handle *lockh,
1162 void *lmm, int lmmsize,
1163 ldlm_completion_callback cb_completion,
1164 ldlm_blocking_callback cb_blocking, void *cb_data)
1166 struct obd_device *obd = class_exp2obd(exp);
1167 struct obd_export *cobd_exp;
1170 CERROR("invalid client cookie "LPX64"\n",
1171 exp->exp_handle.h_cookie);
1174 cobd_exp = cobd_get_exp(obd);
1175 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1176 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1180 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1181 const char *name, int len, void *lmm, int lmmsize,
1182 struct lustre_id *cid, struct lookup_intent *it,
1183 int lookup_flags, struct ptlrpc_request **reqp,
1184 ldlm_blocking_callback cb_blocking)
1186 struct obd_device *obd = class_exp2obd(exp);
1187 struct obd_export *cobd_exp;
1190 CERROR("invalid client cookie "LPX64"\n",
1191 exp->exp_handle.h_cookie);
1194 cobd_exp = cobd_get_exp(obd);
1195 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1196 cid, it, lookup_flags, reqp, cb_blocking);
1199 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1200 char *name, int len)
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);
1211 return md_get_real_obd(cobd_exp, name, len);
1214 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1215 struct lustre_id *id, char *name,
1216 int namelen, struct lustre_id *id2,
1217 ldlm_iterator_t it, void *data)
1219 struct obd_device *obd = class_exp2obd(exp);
1220 struct obd_export *cobd_exp;
1223 CERROR("invalid client cookie "LPX64"\n",
1224 exp->exp_handle.h_cookie);
1227 cobd_exp = cobd_get_exp(obd);
1228 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1231 static struct obd_ops cobd_obd_ops = {
1232 .o_owner = THIS_MODULE,
1233 .o_attach = cobd_attach,
1234 .o_detach = cobd_detach,
1235 .o_setup = cobd_setup,
1236 .o_cleanup = cobd_cleanup,
1237 .o_connect = cobd_connect,
1238 .o_disconnect = cobd_disconnect,
1239 .o_set_info = cobd_set_info,
1240 .o_get_info = cobd_get_info,
1241 .o_statfs = cobd_statfs,
1243 .o_packmd = cobd_packmd,
1244 .o_unpackmd = cobd_unpackmd,
1245 .o_create = cobd_create,
1246 .o_destroy = cobd_destroy,
1247 .o_precleanup = cobd_precleanup,
1248 .o_getattr = cobd_getattr,
1249 .o_getattr_async = cobd_getattr_async,
1250 .o_setattr = cobd_setattr,
1253 .o_brw_async = cobd_brw_async,
1254 .o_prep_async_page = cobd_prep_async_page,
1255 .o_queue_async_io = cobd_queue_async_io,
1256 .o_set_async_flags = cobd_set_async_flags,
1257 .o_queue_group_io = cobd_queue_group_io,
1258 .o_trigger_group_io = cobd_trigger_group_io,
1259 .o_teardown_async_page = cobd_teardown_async_page,
1260 .o_preprw = cobd_preprw,
1261 .o_punch = cobd_punch,
1262 .o_sync = cobd_sync,
1263 .o_enqueue = cobd_enqueue,
1264 .o_match = cobd_match,
1265 .o_change_cbdata = cobd_change_cbdata,
1266 .o_cancel = cobd_cancel,
1267 .o_cancel_unused = cobd_cancel_unused,
1268 .o_iocontrol = cobd_iocontrol,
1269 .o_commitrw = cobd_commitrw,
1270 .o_llog_init = cobd_llog_init,
1271 .o_llog_finish = cobd_llog_finish,
1272 .o_notify = cobd_notify,
1274 .o_unpin = cobd_unpin,
1275 .o_import_event = cobd_import_event,
1276 .o_init_ea_size = cobd_init_ea_size,
1279 struct md_ops cobd_md_ops = {
1280 .m_getstatus = cobd_md_getstatus,
1281 .m_getattr = cobd_md_getattr,
1282 .m_req2lustre_md = cobd_md_req2lustre_md,
1283 .m_change_cbdata = cobd_md_change_cbdata,
1284 .m_getattr_lock = cobd_md_getattr_lock,
1285 .m_create = cobd_md_create,
1286 .m_unlink = cobd_md_unlink,
1287 .m_valid_attrs = cobd_md_valid_attrs,
1288 .m_rename = cobd_md_rename,
1289 .m_link = cobd_md_link,
1290 .m_setattr = cobd_md_setattr,
1291 .m_readpage = cobd_md_readpage,
1292 .m_close = cobd_md_close,
1293 .m_done_writing = cobd_md_done_writing,
1294 .m_sync = cobd_md_sync,
1295 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1296 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1297 .m_store_inode_generation = cobd_md_store_inode_generation,
1298 .m_set_lock_data = cobd_md_set_lock_data,
1299 .m_enqueue = cobd_md_enqueue,
1300 .m_get_real_obd = cobd_md_get_real_obd,
1301 .m_intent_lock = cobd_md_intent_lock,
1302 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1305 static int __init cobd_init(void)
1307 struct lprocfs_static_vars lvars;
1310 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1312 lprocfs_init_vars(cobd, &lvars);
1313 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1314 lvars.module_vars, OBD_CACHE_DEVICENAME));
1317 static void /*__exit*/ cobd_exit(void)
1319 class_unregister_type(OBD_CACHE_DEVICENAME);
1322 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1323 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1324 MODULE_LICENSE("GPL");
1326 module_init(cobd_init);
1327 module_exit(cobd_exit);