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,
129 struct obd_connect_data *data,
132 struct obd_device *cli_obd;
140 cli_obd = class_name2obd(name);
141 if (cli_obd == NULL) {
142 CERROR("%s: unable to find a client for obd: %s\n",
143 obd->obd_name, name);
146 rc = obd_connect(conn, cli_obd, &obd->obd_uuid, data, flags);
148 CERROR("error connecting to %s, err %d\n",
154 static int client_obd_disconnect(struct obd_device *obd,
155 struct obd_export *exp,
158 struct obd_device *cli_obd;
162 cli_obd = class_exp2obd(exp);
163 cli_obd->obd_no_recov = obd->obd_no_recov;
165 rc = obd_disconnect(exp, flags);
167 CERROR("error disconnecting from %s, err %d\n",
168 cli_obd->obd_name, rc);
169 class_export_put(exp);
175 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
176 struct obd_uuid *cluuid, struct obd_connect_data *data,
179 struct lustre_handle cache_conn = { 0 };
180 struct cache_obd *cobd = &obd->u.cobd;
181 struct obd_export *exp;
185 /* connecting class */
186 rc = class_connect(conn, obd, cluuid);
189 exp = class_conn2export(conn);
191 /* connecting cache */
192 rc = client_obd_connect(obd, cobd->cache_name,
193 &cache_conn, data, flags);
195 GOTO(err_discon, rc);
196 cobd->cache_exp = class_conn2export(&cache_conn);
202 class_disconnect(exp, 0);
204 class_export_put(exp);
209 cobd_disconnect(struct obd_export *exp, unsigned long flags)
211 struct obd_device *obd;
212 struct cache_obd *cobd;
216 LASSERT(exp != NULL);
217 obd = class_exp2obd(exp);
219 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
220 exp->exp_handle.h_cookie);
226 if (cobd->cache_on) {
227 rc = client_obd_disconnect(obd, cobd->cache_exp,
229 cobd->cache_exp = NULL;
231 rc = client_obd_disconnect(obd, cobd->master_exp,
233 cobd->master_exp = NULL;
236 rc = class_disconnect(exp, flags);
240 static int cobd_get_info(struct obd_export *exp, obd_count keylen,
241 void *key, __u32 *vallen, void *val)
243 struct obd_device *obd = class_exp2obd(exp);
244 struct obd_export *cobd_exp;
247 CERROR("invalid client cookie "LPX64"\n",
248 exp->exp_handle.h_cookie);
251 cobd_exp = cobd_get_exp(obd);
253 /* intercept cache utilisation info? */
254 return obd_get_info(cobd_exp, keylen, key, vallen, val);
257 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
258 void *key, obd_count vallen, void *val)
260 struct obd_device *obd = class_exp2obd(exp);
261 struct obd_export *cobd_exp;
264 CERROR("invalid client cookie "LPX64"\n",
265 exp->exp_handle.h_cookie);
268 cobd_exp = cobd_get_exp(obd);
270 /* intercept cache utilisation info? */
271 return obd_set_info(cobd_exp, keylen, key, vallen, val);
274 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
275 unsigned long max_age)
277 struct obd_export *cobd_exp;
279 cobd_exp = cobd_get_exp(obd);
281 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
284 static int cobd_packmd(struct obd_export *exp,
285 struct lov_mds_md **disk_tgt,
286 struct lov_stripe_md *mem_src)
288 struct obd_device *obd = class_exp2obd(exp);
289 struct obd_export *cobd_exp;
292 CERROR("invalid client cookie "LPX64"\n",
293 exp->exp_handle.h_cookie);
296 cobd_exp = cobd_get_exp(obd);
297 return obd_packmd(cobd_exp, disk_tgt, mem_src);
300 static int cobd_unpackmd(struct obd_export *exp,
301 struct lov_stripe_md **mem_tgt,
302 struct lov_mds_md *disk_src,
305 struct obd_device *obd = class_exp2obd(exp);
306 struct obd_export *cobd_exp;
309 CERROR("invalid client cookie "LPX64"\n",
310 exp->exp_handle.h_cookie);
313 cobd_exp = cobd_get_exp(obd);
314 return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
317 static int cobd_create(struct obd_export *exp, struct obdo *obdo,
318 void *acl, int acl_size,
319 struct lov_stripe_md **ea,
320 struct obd_trans_info *oti)
322 struct obd_device *obd = class_exp2obd(exp);
323 struct obd_export *cobd_exp;
326 CERROR("invalid client cookie "LPX64"\n",
327 exp->exp_handle.h_cookie);
330 cobd_exp = cobd_get_exp(obd);
331 return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
334 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
335 struct lov_stripe_md *ea,
336 struct obd_trans_info *oti)
338 struct obd_device *obd = class_exp2obd(exp);
339 struct obd_export *cobd_exp;
342 CERROR("invalid client cookie "LPX64"\n",
343 exp->exp_handle.h_cookie);
346 cobd_exp = cobd_get_exp(obd);
347 return obd_destroy(cobd_exp, obdo, ea, oti);
350 static int cobd_precleanup(struct obd_device *obd, int flags)
352 /* FIXME-WANGDI: do we need some cleanup here? */
356 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
357 struct lov_stripe_md *ea)
359 struct obd_device *obd = class_exp2obd(exp);
360 struct obd_export *cobd_exp;
363 CERROR("invalid client cookie "LPX64"\n",
364 exp->exp_handle.h_cookie);
367 cobd_exp = cobd_get_exp(obd);
368 return obd_getattr(cobd_exp, oa, ea);
371 static int cobd_getattr_async(struct obd_export *exp,
372 struct obdo *obdo, struct lov_stripe_md *ea,
373 struct ptlrpc_request_set *set)
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_getattr_async(cobd_exp, obdo, ea, set);
387 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
388 struct lov_stripe_md *ea,
389 struct obd_trans_info *oti)
391 struct obd_device *obd = class_exp2obd(exp);
392 struct obd_export *cobd_exp;
395 CERROR("invalid client cookie "LPX64"\n",
396 exp->exp_handle.h_cookie);
399 cobd_exp = cobd_get_exp(obd);
400 return obd_setattr(cobd_exp, obdo, ea, oti);
403 static int cobd_md_getstatus(struct obd_export *exp,
404 struct lustre_id *rootid)
406 struct obd_device *obd = class_exp2obd(exp);
407 struct obd_export *cobd_exp;
410 CERROR("invalid client cookie "LPX64"\n",
411 exp->exp_handle.h_cookie);
414 cobd_exp = cobd_get_exp(obd);
415 return md_getstatus(cobd_exp, rootid);
418 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
419 struct lov_stripe_md *ea, obd_count oa_bufs,
420 struct brw_page *pg, struct obd_trans_info *oti)
422 struct obd_device *obd = class_exp2obd(exp);
423 struct obd_export *cobd_exp;
426 CERROR("invalid client cookie "LPX64"\n",
427 exp->exp_handle.h_cookie);
430 cobd_exp = cobd_get_exp(obd);
431 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
434 static int cobd_brw_async(int cmd, struct obd_export *exp,
435 struct obdo *oa, struct lov_stripe_md *ea,
436 obd_count oa_bufs, struct brw_page *pg,
437 struct ptlrpc_request_set *set,
438 struct obd_trans_info *oti)
440 struct obd_device *obd = class_exp2obd(exp);
441 struct obd_export *cobd_exp;
444 CERROR("invalid client cookie "LPX64"\n",
445 exp->exp_handle.h_cookie);
448 cobd_exp = cobd_get_exp(obd);
449 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
453 static int cobd_prep_async_page(struct obd_export *exp,
454 struct lov_stripe_md *lsm,
455 struct lov_oinfo *loi,
456 struct page *page, obd_off offset,
457 struct obd_async_page_ops *ops,
458 void *data, void **res)
460 struct obd_device *obd = class_exp2obd(exp);
461 struct obd_export *cobd_exp;
464 CERROR("invalid client cookie "LPX64"\n",
465 exp->exp_handle.h_cookie);
468 cobd_exp = cobd_get_exp(obd);
469 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
473 static int cobd_queue_async_io(struct obd_export *exp,
474 struct lov_stripe_md *lsm,
475 struct lov_oinfo *loi, void *cookie,
476 int cmd, obd_off off, int count,
477 obd_flags brw_flags, obd_flags async_flags)
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_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
489 brw_flags, async_flags);
492 static int cobd_set_async_flags(struct obd_export *exp,
493 struct lov_stripe_md *lsm,
494 struct lov_oinfo *loi, void *cookie,
495 obd_flags async_flags)
497 struct obd_device *obd = class_exp2obd(exp);
498 struct obd_export *cobd_exp;
501 CERROR("invalid client cookie "LPX64"\n",
502 exp->exp_handle.h_cookie);
505 cobd_exp = cobd_get_exp(obd);
506 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
509 static int cobd_queue_group_io(struct obd_export *exp,
510 struct lov_stripe_md *lsm,
511 struct lov_oinfo *loi,
512 struct obd_io_group *oig,
513 void *cookie, int cmd, obd_off off,
514 int count, obd_flags brw_flags,
515 obd_flags async_flags)
517 struct obd_device *obd = class_exp2obd(exp);
518 struct obd_export *cobd_exp;
521 CERROR("invalid client cookie "LPX64"\n",
522 exp->exp_handle.h_cookie);
525 cobd_exp = cobd_get_exp(obd);
526 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
527 cmd, off, count, brw_flags, async_flags);
530 static int cobd_trigger_group_io(struct obd_export *exp,
531 struct lov_stripe_md *lsm,
532 struct lov_oinfo *loi,
533 struct obd_io_group *oig)
535 struct obd_device *obd = class_exp2obd(exp);
536 struct obd_export *cobd_exp;
539 CERROR("invalid client cookie "LPX64"\n",
540 exp->exp_handle.h_cookie);
543 cobd_exp = cobd_get_exp(obd);
544 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
547 static int cobd_teardown_async_page(struct obd_export *exp,
548 struct lov_stripe_md *lsm,
549 struct lov_oinfo *loi, void *cookie)
551 struct obd_device *obd = class_exp2obd(exp);
552 struct obd_export *cobd_exp;
555 CERROR("invalid client cookie "LPX64"\n",
556 exp->exp_handle.h_cookie);
559 cobd_exp = cobd_get_exp(obd);
560 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
563 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
564 struct lov_stripe_md *ea, obd_size start,
565 obd_size end, struct obd_trans_info *oti)
567 struct obd_device *obd = class_exp2obd(exp);
568 struct obd_export *cobd_exp;
571 CERROR("invalid client cookie "LPX64"\n",
572 exp->exp_handle.h_cookie);
575 cobd_exp = cobd_get_exp(obd);
576 return obd_punch(cobd_exp, oa, ea, start, end, oti);
579 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
580 struct lov_stripe_md *ea, obd_size start,
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_sync(cobd_exp, oa, ea, start, end);
595 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
596 __u32 type, ldlm_policy_data_t *policy,
597 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
598 void *gl_cb, void *data, __u32 lvb_len,
599 void *lvb_swabber, struct lustre_handle *lockh)
601 struct obd_device *obd = class_exp2obd(exp);
602 struct obd_export *cobd_exp;
605 CERROR("invalid client cookie "LPX64"\n",
606 exp->exp_handle.h_cookie);
609 cobd_exp = cobd_get_exp(obd);
610 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
611 bl_cb, cp_cb, gl_cb, data, lvb_len,
615 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
616 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
617 int *flags, void *data, struct lustre_handle *lockh)
619 struct obd_device *obd = class_exp2obd(exp);
620 struct obd_export *cobd_exp;
623 CERROR("invalid client cookie "LPX64"\n",
624 exp->exp_handle.h_cookie);
627 cobd_exp = cobd_get_exp(obd);
628 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
631 static int cobd_change_cbdata(struct obd_export *exp,
632 struct lov_stripe_md *lsm,
633 ldlm_iterator_t it, void *data)
635 struct obd_device *obd = class_exp2obd(exp);
636 struct obd_export *cobd_exp;
639 CERROR("invalid client cookie "LPX64"\n",
640 exp->exp_handle.h_cookie);
643 cobd_exp = cobd_get_exp(obd);
644 return obd_change_cbdata(cobd_exp, lsm, it, data);
647 static int cobd_cancel(struct obd_export *exp,
648 struct lov_stripe_md *ea, __u32 mode,
649 struct lustre_handle *lockh)
651 struct obd_device *obd = class_exp2obd(exp);
652 struct obd_export *cobd_exp;
655 CERROR("invalid client cookie "LPX64"\n",
656 exp->exp_handle.h_cookie);
659 cobd_exp = cobd_get_exp(obd);
660 return obd_cancel(cobd_exp, ea, mode, lockh);
663 static int cobd_cancel_unused(struct obd_export *exp,
664 struct lov_stripe_md *ea, int flags,
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_cancel_unused(cobd_exp, ea, flags, opaque);
679 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
680 int objcount, struct obd_ioobj *obj,
681 int niocount, struct niobuf_remote *nb,
682 struct niobuf_local *res, struct obd_trans_info *oti)
684 struct obd_device *obd = class_exp2obd(exp);
685 struct obd_export *cobd_exp;
688 CERROR("invalid client cookie "LPX64"\n",
689 exp->exp_handle.h_cookie);
692 cobd_exp = cobd_get_exp(obd);
693 return obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
697 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
698 int objcount, struct obd_ioobj *obj,
699 int niocount, struct niobuf_local *local,
700 struct obd_trans_info *oti, int rc)
702 struct obd_device *obd = class_exp2obd(exp);
703 struct obd_export *cobd_exp;
706 CERROR("invalid client cookie "LPX64"\n",
707 exp->exp_handle.h_cookie);
710 cobd_exp = cobd_get_exp(obd);
711 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
715 static int cobd_flush(struct obd_device *obd)
720 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
721 int len, void *karg, void *uarg)
723 struct obd_device *obd = class_exp2obd(exp);
724 struct cache_obd *cobd = &obd->u.cobd;
725 struct obd_export *cobd_exp;
732 case OBD_IOC_COBD_CON:
733 if (!cobd->cache_on) {
734 struct lustre_handle conn = {0};
736 rc = client_obd_disconnect(obd, cobd->master_exp, 0);
737 rc = client_obd_connect(obd, cobd->cache_name, &conn,
741 cobd->cache_exp = class_conn2export(&conn);
745 case OBD_IOC_COBD_COFF:
746 if (cobd->cache_on) {
747 struct lustre_handle conn = {0,};
748 struct obd_device *master = NULL;
749 struct obd_device *cache = NULL;
750 int easize, cooksize;
752 cache = class_exp2obd(cobd->cache_exp);
753 easize = cache->u.cli.cl_max_mds_easize;
754 cooksize = cache->u.cli.cl_max_mds_cookiesize;
756 rc = client_obd_disconnect(obd, cobd->cache_exp, 0);
757 rc = client_obd_connect(obd, cobd->master_name, &conn,
761 cobd->master_exp = class_conn2export(&conn);
763 master = class_exp2obd(cobd->master_exp);
764 master->u.cli.cl_max_mds_easize = easize;
765 master->u.cli.cl_max_mds_cookiesize = cooksize;
769 case OBD_IOC_COBD_CFLUSH:
770 if (cobd->cache_on) {
774 CERROR("%s: cache is turned off\n", obd->obd_name);
778 cobd_exp = cobd_get_exp(obd);
779 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
788 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
789 struct obd_device *disk_obd, int count,
790 struct llog_catid *logid)
792 struct obd_export *cobd_exp;
793 struct obd_device *cobd_obd;
795 cobd_exp = cobd_get_exp(obd);
796 cobd_obd = class_exp2obd(cobd_exp);
798 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
799 disk_obd, count, logid);
802 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
805 struct obd_export *cobd_exp;
806 struct obd_device *cobd_obd;
808 cobd_exp = cobd_get_exp(obd);
809 cobd_obd = class_exp2obd(cobd_exp);
811 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
814 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
815 int active, void *data)
817 struct obd_export *cobd_exp;
819 cobd_exp = cobd_get_exp(obd);
821 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
824 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
825 int type, struct obd_client_handle *handle, int flag)
827 struct obd_device *obd = class_exp2obd(exp);
828 struct obd_export *cobd_exp;
831 CERROR("invalid client cookie "LPX64"\n",
832 exp->exp_handle.h_cookie);
835 cobd_exp = cobd_get_exp(obd);
837 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
840 static int cobd_unpin(struct obd_export *exp,
841 struct obd_client_handle *handle, int flag)
843 struct obd_device *obd = class_exp2obd(exp);
844 struct obd_export *cobd_exp;
847 CERROR("invalid client cookie "LPX64"\n",
848 exp->exp_handle.h_cookie);
851 cobd_exp = cobd_get_exp(obd);
853 return obd_unpin(cobd_exp, handle, flag);
856 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
858 struct obd_export *cobd_exp;
860 cobd_exp = cobd_get_exp(exp->exp_obd);
861 return obd_init_ea_size(cobd_exp, easize, cookiesize);
864 static int cobd_import_event(struct obd_device *obd,
865 struct obd_import *imp,
866 enum obd_import_event event)
868 struct obd_export *cobd_exp;
870 cobd_exp = cobd_get_exp(obd);
872 obd_import_event(class_exp2obd(cobd_exp), imp, event);
877 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
878 __u64 valid, const char *ea_name, int ea_namelen,
879 unsigned int ea_size, struct ptlrpc_request **request)
881 struct obd_device *obd = class_exp2obd(exp);
882 struct obd_export *cobd_exp;
885 CERROR("invalid client cookie "LPX64"\n",
886 exp->exp_handle.h_cookie);
889 cobd_exp = cobd_get_exp(obd);
890 return md_getattr(cobd_exp, id, valid, NULL, 0, ea_size, request);
893 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
894 struct ptlrpc_request *req, unsigned int offset,
895 struct obd_export *osc_exp, struct lustre_md *md)
897 struct obd_device *obd = class_exp2obd(mdc_exp);
898 struct obd_export *cobd_exp;
901 CERROR("invalid client cookie "LPX64"\n",
902 mdc_exp->exp_handle.h_cookie);
905 cobd_exp = cobd_get_exp(obd);
906 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
909 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
910 ldlm_iterator_t it, void *data)
912 struct obd_device *obd = class_exp2obd(exp);
913 struct obd_export *cobd_exp;
916 CERROR("invalid client cookie "LPX64"\n",
917 exp->exp_handle.h_cookie);
920 cobd_exp = cobd_get_exp(obd);
921 return md_change_cbdata(cobd_exp, id, it, data);
924 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
925 char *filename, int namelen, __u64 valid,
926 unsigned int ea_size, struct ptlrpc_request **request)
928 struct obd_device *obd = class_exp2obd(exp);
929 struct obd_export *cobd_exp;
932 CERROR("invalid client cookie "LPX64"\n",
933 exp->exp_handle.h_cookie);
936 cobd_exp = cobd_get_exp(obd);
937 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
941 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
942 const void *data, int datalen, int mode,
943 __u32 uid, __u32 gid, __u64 rdev,
944 struct ptlrpc_request **request)
946 struct obd_device *obd = class_exp2obd(exp);
947 struct obd_export *cobd_exp;
950 CERROR("invalid client cookie "LPX64"\n",
951 exp->exp_handle.h_cookie);
954 cobd_exp = cobd_get_exp(obd);
955 return md_create(cobd_exp, op_data, data, datalen, mode,
956 uid, gid, rdev, request);
959 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
960 struct ptlrpc_request **request)
962 struct obd_device *obd = class_exp2obd(exp);
963 struct obd_export *cobd_exp;
966 CERROR("invalid client cookie "LPX64"\n",
967 exp->exp_handle.h_cookie);
970 cobd_exp = cobd_get_exp(obd);
971 return md_unlink(cobd_exp, data, request);
974 static int cobd_md_valid_attrs(struct obd_export *exp,
975 struct lustre_id *id)
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_valid_attrs(cobd_exp, id);
989 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
990 const char *old, int oldlen, const char *new,
991 int newlen, struct ptlrpc_request **request)
993 struct obd_device *obd = class_exp2obd(exp);
994 struct obd_export *cobd_exp;
997 CERROR("invalid client cookie "LPX64"\n",
998 exp->exp_handle.h_cookie);
1001 cobd_exp = cobd_get_exp(obd);
1002 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1005 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1006 struct ptlrpc_request **request)
1008 struct obd_device *obd = class_exp2obd(exp);
1009 struct obd_export *cobd_exp;
1012 CERROR("invalid client cookie "LPX64"\n",
1013 exp->exp_handle.h_cookie);
1016 cobd_exp = cobd_get_exp(obd);
1017 return md_link(cobd_exp, data, request);
1020 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1021 struct iattr *iattr, void *ea, int ealen, void *ea2,
1022 int ea2len, struct ptlrpc_request **request)
1024 struct obd_device *obd = class_exp2obd(exp);
1025 struct obd_export *cobd_exp;
1028 CERROR("invalid client cookie "LPX64"\n",
1029 exp->exp_handle.h_cookie);
1032 cobd_exp = cobd_get_exp(obd);
1033 return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1036 static int cobd_md_readpage(struct obd_export *exp,
1037 struct lustre_id *mdc_id,
1038 __u64 offset, struct page *page,
1039 struct ptlrpc_request **request)
1041 struct obd_device *obd = class_exp2obd(exp);
1042 struct obd_export *cobd_exp;
1045 CERROR("invalid client cookie "LPX64"\n",
1046 exp->exp_handle.h_cookie);
1049 cobd_exp = cobd_get_exp(obd);
1050 return md_readpage(cobd_exp, mdc_id, offset, page, request);
1053 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1054 struct obd_client_handle *och,
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_close(cobd_exp, obdo, och, request);
1069 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1071 struct obd_device *obd = class_exp2obd(exp);
1072 struct obd_export *cobd_exp;
1075 CERROR("invalid client cookie "LPX64"\n",
1076 exp->exp_handle.h_cookie);
1079 cobd_exp = cobd_get_exp(obd);
1080 return md_done_writing(cobd_exp, obdo);
1083 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1084 struct ptlrpc_request **request)
1086 struct obd_device *obd = class_exp2obd(exp);
1087 struct obd_export *cobd_exp;
1090 CERROR("invalid client cookie "LPX64"\n",
1091 exp->exp_handle.h_cookie);
1094 cobd_exp = cobd_get_exp(obd);
1096 return md_sync(cobd_exp, id, request);
1099 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1100 struct obd_client_handle *och,
1101 struct ptlrpc_request *open_req)
1103 struct obd_device *obd = class_exp2obd(exp);
1104 struct obd_export *cobd_exp;
1107 CERROR("invalid client cookie "LPX64"\n",
1108 exp->exp_handle.h_cookie);
1111 cobd_exp = cobd_get_exp(obd);
1113 return md_set_open_replay_data(cobd_exp, och, open_req);
1116 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1117 struct obd_client_handle *och)
1119 struct obd_device *obd = class_exp2obd(exp);
1120 struct obd_export *cobd_exp;
1123 CERROR("invalid client cookie "LPX64"\n",
1124 exp->exp_handle.h_cookie);
1127 cobd_exp = cobd_get_exp(obd);
1129 return md_clear_open_replay_data(cobd_exp, och);
1132 static int cobd_md_store_inode_generation(struct obd_export *exp,
1133 struct ptlrpc_request *req,
1134 int reqoff, int repoff)
1136 struct obd_device *obd = class_exp2obd(exp);
1137 struct obd_export *cobd_exp;
1140 CERROR("invalid client cookie "LPX64"\n",
1141 exp->exp_handle.h_cookie);
1144 cobd_exp = cobd_get_exp(obd);
1146 return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1149 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1151 struct obd_device *obd = class_exp2obd(exp);
1152 struct obd_export *cobd_exp;
1155 CERROR("invalid client cookie "LPX64"\n",
1156 exp->exp_handle.h_cookie);
1159 cobd_exp = cobd_get_exp(obd);
1161 return md_set_lock_data(cobd_exp, l, data);
1164 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1165 struct lookup_intent *it, int lock_mode,
1166 struct mdc_op_data *data, struct lustre_handle *lockh,
1167 void *lmm, int lmmsize,
1168 ldlm_completion_callback cb_completion,
1169 ldlm_blocking_callback cb_blocking, void *cb_data)
1171 struct obd_device *obd = class_exp2obd(exp);
1172 struct obd_export *cobd_exp;
1175 CERROR("invalid client cookie "LPX64"\n",
1176 exp->exp_handle.h_cookie);
1179 cobd_exp = cobd_get_exp(obd);
1180 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1181 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1185 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1186 const char *name, int len, void *lmm, int lmmsize,
1187 struct lustre_id *cid, struct lookup_intent *it,
1188 int lookup_flags, struct ptlrpc_request **reqp,
1189 ldlm_blocking_callback cb_blocking)
1191 struct obd_device *obd = class_exp2obd(exp);
1192 struct obd_export *cobd_exp;
1195 CERROR("invalid client cookie "LPX64"\n",
1196 exp->exp_handle.h_cookie);
1199 cobd_exp = cobd_get_exp(obd);
1200 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1201 cid, it, lookup_flags, reqp, cb_blocking);
1204 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1205 struct lustre_id *id)
1207 struct obd_device *obd = class_exp2obd(exp);
1208 struct obd_export *cobd_exp;
1211 CERROR("invalid client cookie "LPX64"\n",
1212 exp->exp_handle.h_cookie);
1215 cobd_exp = cobd_get_exp(obd);
1216 return md_get_real_obd(cobd_exp, id);
1219 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1220 struct lustre_id *id, char *name,
1221 int namelen, struct lustre_id *id2,
1222 ldlm_iterator_t it, void *data)
1224 struct obd_device *obd = class_exp2obd(exp);
1225 struct obd_export *cobd_exp;
1228 CERROR("invalid client cookie "LPX64"\n",
1229 exp->exp_handle.h_cookie);
1232 cobd_exp = cobd_get_exp(obd);
1233 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1236 static struct obd_ops cobd_obd_ops = {
1237 .o_owner = THIS_MODULE,
1238 .o_attach = cobd_attach,
1239 .o_detach = cobd_detach,
1240 .o_setup = cobd_setup,
1241 .o_cleanup = cobd_cleanup,
1242 .o_connect = cobd_connect,
1243 .o_disconnect = cobd_disconnect,
1244 .o_set_info = cobd_set_info,
1245 .o_get_info = cobd_get_info,
1246 .o_statfs = cobd_statfs,
1248 .o_packmd = cobd_packmd,
1249 .o_unpackmd = cobd_unpackmd,
1250 .o_create = cobd_create,
1251 .o_destroy = cobd_destroy,
1252 .o_precleanup = cobd_precleanup,
1253 .o_getattr = cobd_getattr,
1254 .o_getattr_async = cobd_getattr_async,
1255 .o_setattr = cobd_setattr,
1258 .o_brw_async = cobd_brw_async,
1259 .o_prep_async_page = cobd_prep_async_page,
1260 .o_queue_async_io = cobd_queue_async_io,
1261 .o_set_async_flags = cobd_set_async_flags,
1262 .o_queue_group_io = cobd_queue_group_io,
1263 .o_trigger_group_io = cobd_trigger_group_io,
1264 .o_teardown_async_page = cobd_teardown_async_page,
1265 .o_preprw = cobd_preprw,
1266 .o_punch = cobd_punch,
1267 .o_sync = cobd_sync,
1268 .o_enqueue = cobd_enqueue,
1269 .o_match = cobd_match,
1270 .o_change_cbdata = cobd_change_cbdata,
1271 .o_cancel = cobd_cancel,
1272 .o_cancel_unused = cobd_cancel_unused,
1273 .o_iocontrol = cobd_iocontrol,
1274 .o_commitrw = cobd_commitrw,
1275 .o_llog_init = cobd_llog_init,
1276 .o_llog_finish = cobd_llog_finish,
1277 .o_notify = cobd_notify,
1279 .o_unpin = cobd_unpin,
1280 .o_import_event = cobd_import_event,
1281 .o_init_ea_size = cobd_init_ea_size,
1284 struct md_ops cobd_md_ops = {
1285 .m_getstatus = cobd_md_getstatus,
1286 .m_getattr = cobd_md_getattr,
1287 .m_req2lustre_md = cobd_md_req2lustre_md,
1288 .m_change_cbdata = cobd_md_change_cbdata,
1289 .m_getattr_lock = cobd_md_getattr_lock,
1290 .m_create = cobd_md_create,
1291 .m_unlink = cobd_md_unlink,
1292 .m_valid_attrs = cobd_md_valid_attrs,
1293 .m_rename = cobd_md_rename,
1294 .m_link = cobd_md_link,
1295 .m_setattr = cobd_md_setattr,
1296 .m_readpage = cobd_md_readpage,
1297 .m_close = cobd_md_close,
1298 .m_done_writing = cobd_md_done_writing,
1299 .m_sync = cobd_md_sync,
1300 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1301 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1302 .m_store_inode_generation = cobd_md_store_inode_generation,
1303 .m_set_lock_data = cobd_md_set_lock_data,
1304 .m_enqueue = cobd_md_enqueue,
1305 .m_get_real_obd = cobd_md_get_real_obd,
1306 .m_intent_lock = cobd_md_intent_lock,
1307 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1310 static int __init cobd_init(void)
1312 struct lprocfs_static_vars lvars;
1315 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1317 lprocfs_init_vars(cobd, &lvars);
1318 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1319 lvars.module_vars, OBD_CACHE_DEVICENAME));
1322 static void /*__exit*/ cobd_exit(void)
1324 class_unregister_type(OBD_CACHE_DEVICENAME);
1327 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1328 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1329 MODULE_LICENSE("GPL");
1331 module_init(cobd_init);
1332 module_exit(cobd_exit);