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 struct lov_stripe_md **ea,
319 struct obd_trans_info *oti)
321 struct obd_device *obd = class_exp2obd(exp);
322 struct obd_export *cobd_exp;
325 CERROR("invalid client cookie "LPX64"\n",
326 exp->exp_handle.h_cookie);
329 cobd_exp = cobd_get_exp(obd);
330 return obd_create(cobd_exp, obdo, ea, oti);
333 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
334 struct lov_stripe_md *ea,
335 struct obd_trans_info *oti)
337 struct obd_device *obd = class_exp2obd(exp);
338 struct obd_export *cobd_exp;
341 CERROR("invalid client cookie "LPX64"\n",
342 exp->exp_handle.h_cookie);
345 cobd_exp = cobd_get_exp(obd);
346 return obd_destroy(cobd_exp, obdo, ea, oti);
349 static int cobd_precleanup(struct obd_device *obd, int flags)
351 /* FIXME-WANGDI: do we need some cleanup here? */
355 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
356 struct lov_stripe_md *ea)
358 struct obd_device *obd = class_exp2obd(exp);
359 struct obd_export *cobd_exp;
362 CERROR("invalid client cookie "LPX64"\n",
363 exp->exp_handle.h_cookie);
366 cobd_exp = cobd_get_exp(obd);
367 return obd_getattr(cobd_exp, oa, ea);
370 static int cobd_getattr_async(struct obd_export *exp,
371 struct obdo *obdo, struct lov_stripe_md *ea,
372 struct ptlrpc_request_set *set)
374 struct obd_device *obd = class_exp2obd(exp);
375 struct obd_export *cobd_exp;
378 CERROR("invalid client cookie "LPX64"\n",
379 exp->exp_handle.h_cookie);
382 cobd_exp = cobd_get_exp(obd);
383 return obd_getattr_async(cobd_exp, obdo, ea, set);
386 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
387 struct lov_stripe_md *ea,
388 struct obd_trans_info *oti)
390 struct obd_device *obd = class_exp2obd(exp);
391 struct obd_export *cobd_exp;
394 CERROR("invalid client cookie "LPX64"\n",
395 exp->exp_handle.h_cookie);
398 cobd_exp = cobd_get_exp(obd);
399 return obd_setattr(cobd_exp, obdo, ea, oti);
402 static int cobd_md_getstatus(struct obd_export *exp,
403 struct lustre_id *rootid)
405 struct obd_device *obd = class_exp2obd(exp);
406 struct obd_export *cobd_exp;
409 CERROR("invalid client cookie "LPX64"\n",
410 exp->exp_handle.h_cookie);
413 cobd_exp = cobd_get_exp(obd);
414 return md_getstatus(cobd_exp, rootid);
417 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
418 struct lov_stripe_md *ea, obd_count oa_bufs,
419 struct brw_page *pg, struct obd_trans_info *oti)
421 struct obd_device *obd = class_exp2obd(exp);
422 struct obd_export *cobd_exp;
425 CERROR("invalid client cookie "LPX64"\n",
426 exp->exp_handle.h_cookie);
429 cobd_exp = cobd_get_exp(obd);
430 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
433 static int cobd_brw_async(int cmd, struct obd_export *exp,
434 struct obdo *oa, struct lov_stripe_md *ea,
435 obd_count oa_bufs, struct brw_page *pg,
436 struct ptlrpc_request_set *set,
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_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
452 static int cobd_prep_async_page(struct obd_export *exp,
453 struct lov_stripe_md *lsm,
454 struct lov_oinfo *loi,
455 struct page *page, obd_off offset,
456 struct obd_async_page_ops *ops,
457 void *data, void **res)
459 struct obd_device *obd = class_exp2obd(exp);
460 struct obd_export *cobd_exp;
463 CERROR("invalid client cookie "LPX64"\n",
464 exp->exp_handle.h_cookie);
467 cobd_exp = cobd_get_exp(obd);
468 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
472 static int cobd_queue_async_io(struct obd_export *exp,
473 struct lov_stripe_md *lsm,
474 struct lov_oinfo *loi, void *cookie,
475 int cmd, obd_off off, int count,
476 obd_flags brw_flags, obd_flags async_flags)
478 struct obd_device *obd = class_exp2obd(exp);
479 struct obd_export *cobd_exp;
482 CERROR("invalid client cookie "LPX64"\n",
483 exp->exp_handle.h_cookie);
486 cobd_exp = cobd_get_exp(obd);
487 return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
488 brw_flags, async_flags);
491 static int cobd_set_async_flags(struct obd_export *exp,
492 struct lov_stripe_md *lsm,
493 struct lov_oinfo *loi, void *cookie,
494 obd_flags async_flags)
496 struct obd_device *obd = class_exp2obd(exp);
497 struct obd_export *cobd_exp;
500 CERROR("invalid client cookie "LPX64"\n",
501 exp->exp_handle.h_cookie);
504 cobd_exp = cobd_get_exp(obd);
505 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
508 static int cobd_queue_group_io(struct obd_export *exp,
509 struct lov_stripe_md *lsm,
510 struct lov_oinfo *loi,
511 struct obd_io_group *oig,
512 void *cookie, int cmd, obd_off off,
513 int count, obd_flags brw_flags,
514 obd_flags async_flags)
516 struct obd_device *obd = class_exp2obd(exp);
517 struct obd_export *cobd_exp;
520 CERROR("invalid client cookie "LPX64"\n",
521 exp->exp_handle.h_cookie);
524 cobd_exp = cobd_get_exp(obd);
525 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
526 cmd, off, count, brw_flags, async_flags);
529 static int cobd_trigger_group_io(struct obd_export *exp,
530 struct lov_stripe_md *lsm,
531 struct lov_oinfo *loi,
532 struct obd_io_group *oig)
534 struct obd_device *obd = class_exp2obd(exp);
535 struct obd_export *cobd_exp;
538 CERROR("invalid client cookie "LPX64"\n",
539 exp->exp_handle.h_cookie);
542 cobd_exp = cobd_get_exp(obd);
543 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
546 static int cobd_teardown_async_page(struct obd_export *exp,
547 struct lov_stripe_md *lsm,
548 struct lov_oinfo *loi, void *cookie)
550 struct obd_device *obd = class_exp2obd(exp);
551 struct obd_export *cobd_exp;
554 CERROR("invalid client cookie "LPX64"\n",
555 exp->exp_handle.h_cookie);
558 cobd_exp = cobd_get_exp(obd);
559 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
562 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
563 struct lov_stripe_md *ea, obd_size start,
564 obd_size end, struct obd_trans_info *oti)
566 struct obd_device *obd = class_exp2obd(exp);
567 struct obd_export *cobd_exp;
570 CERROR("invalid client cookie "LPX64"\n",
571 exp->exp_handle.h_cookie);
574 cobd_exp = cobd_get_exp(obd);
575 return obd_punch(cobd_exp, oa, ea, start, end, oti);
578 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
579 struct lov_stripe_md *ea, obd_size start,
582 struct obd_device *obd = class_exp2obd(exp);
583 struct obd_export *cobd_exp;
586 CERROR("invalid client cookie "LPX64"\n",
587 exp->exp_handle.h_cookie);
590 cobd_exp = cobd_get_exp(obd);
591 return obd_sync(cobd_exp, oa, ea, start, end);
594 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
595 __u32 type, ldlm_policy_data_t *policy,
596 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
597 void *gl_cb, void *data, __u32 lvb_len,
598 void *lvb_swabber, struct lustre_handle *lockh)
600 struct obd_device *obd = class_exp2obd(exp);
601 struct obd_export *cobd_exp;
604 CERROR("invalid client cookie "LPX64"\n",
605 exp->exp_handle.h_cookie);
608 cobd_exp = cobd_get_exp(obd);
609 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
610 bl_cb, cp_cb, gl_cb, data, lvb_len,
614 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
615 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
616 int *flags, void *data, struct lustre_handle *lockh)
618 struct obd_device *obd = class_exp2obd(exp);
619 struct obd_export *cobd_exp;
622 CERROR("invalid client cookie "LPX64"\n",
623 exp->exp_handle.h_cookie);
626 cobd_exp = cobd_get_exp(obd);
627 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
630 static int cobd_change_cbdata(struct obd_export *exp,
631 struct lov_stripe_md *lsm,
632 ldlm_iterator_t it, void *data)
634 struct obd_device *obd = class_exp2obd(exp);
635 struct obd_export *cobd_exp;
638 CERROR("invalid client cookie "LPX64"\n",
639 exp->exp_handle.h_cookie);
642 cobd_exp = cobd_get_exp(obd);
643 return obd_change_cbdata(cobd_exp, lsm, it, data);
646 static int cobd_cancel(struct obd_export *exp,
647 struct lov_stripe_md *ea, __u32 mode,
648 struct lustre_handle *lockh)
650 struct obd_device *obd = class_exp2obd(exp);
651 struct obd_export *cobd_exp;
654 CERROR("invalid client cookie "LPX64"\n",
655 exp->exp_handle.h_cookie);
658 cobd_exp = cobd_get_exp(obd);
659 return obd_cancel(cobd_exp, ea, mode, lockh);
662 static int cobd_cancel_unused(struct obd_export *exp,
663 struct lov_stripe_md *ea, int flags,
666 struct obd_device *obd = class_exp2obd(exp);
667 struct obd_export *cobd_exp;
670 CERROR("invalid client cookie "LPX64"\n",
671 exp->exp_handle.h_cookie);
674 cobd_exp = cobd_get_exp(obd);
675 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
678 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
679 int objcount, struct obd_ioobj *obj,
680 int niocount, struct niobuf_remote *nb,
681 struct niobuf_local *res, struct obd_trans_info *oti)
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_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
696 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
697 int objcount, struct obd_ioobj *obj,
698 int niocount, struct niobuf_local *local,
699 struct obd_trans_info *oti, int rc)
701 struct obd_device *obd = class_exp2obd(exp);
702 struct obd_export *cobd_exp;
705 CERROR("invalid client cookie "LPX64"\n",
706 exp->exp_handle.h_cookie);
709 cobd_exp = cobd_get_exp(obd);
710 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
714 static int cobd_flush(struct obd_device *obd)
719 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
720 int len, void *karg, void *uarg)
722 struct obd_device *obd = class_exp2obd(exp);
723 struct cache_obd *cobd = &obd->u.cobd;
724 struct obd_export *cobd_exp;
731 case OBD_IOC_COBD_CON:
732 if (!cobd->cache_on) {
733 struct lustre_handle conn = {0};
735 rc = client_obd_disconnect(obd, cobd->master_exp, 0);
736 rc = client_obd_connect(obd, cobd->cache_name, &conn,
740 cobd->cache_exp = class_conn2export(&conn);
744 case OBD_IOC_COBD_COFF:
745 if (cobd->cache_on) {
746 struct lustre_handle conn = {0,};
747 struct obd_device *master = NULL;
748 struct obd_device *cache = NULL;
749 int easize, cooksize;
751 cache = class_exp2obd(cobd->cache_exp);
752 easize = cache->u.cli.cl_max_mds_easize;
753 cooksize = cache->u.cli.cl_max_mds_cookiesize;
755 rc = client_obd_disconnect(obd, cobd->cache_exp, 0);
756 rc = client_obd_connect(obd, cobd->master_name, &conn,
760 cobd->master_exp = class_conn2export(&conn);
762 master = class_exp2obd(cobd->master_exp);
763 master->u.cli.cl_max_mds_easize = easize;
764 master->u.cli.cl_max_mds_cookiesize = cooksize;
768 case OBD_IOC_COBD_CFLUSH:
769 if (cobd->cache_on) {
773 CERROR("%s: cache is turned off\n", obd->obd_name);
777 cobd_exp = cobd_get_exp(obd);
778 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
787 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
788 struct obd_device *disk_obd, int count,
789 struct llog_catid *logid)
791 struct obd_export *cobd_exp;
792 struct obd_device *cobd_obd;
794 cobd_exp = cobd_get_exp(obd);
795 cobd_obd = class_exp2obd(cobd_exp);
797 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
798 disk_obd, count, logid);
801 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
804 struct obd_export *cobd_exp;
805 struct obd_device *cobd_obd;
807 cobd_exp = cobd_get_exp(obd);
808 cobd_obd = class_exp2obd(cobd_exp);
810 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
813 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
814 int active, void *data)
816 struct obd_export *cobd_exp;
818 cobd_exp = cobd_get_exp(obd);
820 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
823 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
824 int type, struct obd_client_handle *handle, int flag)
826 struct obd_device *obd = class_exp2obd(exp);
827 struct obd_export *cobd_exp;
830 CERROR("invalid client cookie "LPX64"\n",
831 exp->exp_handle.h_cookie);
834 cobd_exp = cobd_get_exp(obd);
836 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
839 static int cobd_unpin(struct obd_export *exp,
840 struct obd_client_handle *handle, int flag)
842 struct obd_device *obd = class_exp2obd(exp);
843 struct obd_export *cobd_exp;
846 CERROR("invalid client cookie "LPX64"\n",
847 exp->exp_handle.h_cookie);
850 cobd_exp = cobd_get_exp(obd);
852 return obd_unpin(cobd_exp, handle, flag);
855 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
857 struct obd_export *cobd_exp;
859 cobd_exp = cobd_get_exp(exp->exp_obd);
860 return obd_init_ea_size(cobd_exp, easize, cookiesize);
863 static int cobd_import_event(struct obd_device *obd,
864 struct obd_import *imp,
865 enum obd_import_event event)
867 struct obd_export *cobd_exp;
869 cobd_exp = cobd_get_exp(obd);
871 obd_import_event(class_exp2obd(cobd_exp), imp, event);
876 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
877 __u64 valid, const char *ea_name, int ea_namelen,
878 unsigned int ea_size, struct ptlrpc_request **request)
880 struct obd_device *obd = class_exp2obd(exp);
881 struct obd_export *cobd_exp;
884 CERROR("invalid client cookie "LPX64"\n",
885 exp->exp_handle.h_cookie);
888 cobd_exp = cobd_get_exp(obd);
889 return md_getattr(cobd_exp, id, valid, NULL, 0, ea_size, request);
892 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
893 struct ptlrpc_request *req, unsigned int offset,
894 struct obd_export *osc_exp, struct lustre_md *md)
896 struct obd_device *obd = class_exp2obd(mdc_exp);
897 struct obd_export *cobd_exp;
900 CERROR("invalid client cookie "LPX64"\n",
901 mdc_exp->exp_handle.h_cookie);
904 cobd_exp = cobd_get_exp(obd);
905 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
908 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
909 ldlm_iterator_t it, void *data)
911 struct obd_device *obd = class_exp2obd(exp);
912 struct obd_export *cobd_exp;
915 CERROR("invalid client cookie "LPX64"\n",
916 exp->exp_handle.h_cookie);
919 cobd_exp = cobd_get_exp(obd);
920 return md_change_cbdata(cobd_exp, id, it, data);
923 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
924 char *filename, int namelen, __u64 valid,
925 unsigned int ea_size, struct ptlrpc_request **request)
927 struct obd_device *obd = class_exp2obd(exp);
928 struct obd_export *cobd_exp;
931 CERROR("invalid client cookie "LPX64"\n",
932 exp->exp_handle.h_cookie);
935 cobd_exp = cobd_get_exp(obd);
936 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
940 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
941 const void *data, int datalen, int mode,
942 __u32 uid, __u32 gid, __u64 rdev,
943 struct ptlrpc_request **request)
945 struct obd_device *obd = class_exp2obd(exp);
946 struct obd_export *cobd_exp;
949 CERROR("invalid client cookie "LPX64"\n",
950 exp->exp_handle.h_cookie);
953 cobd_exp = cobd_get_exp(obd);
954 return md_create(cobd_exp, op_data, data, datalen, mode,
955 uid, gid, rdev, request);
958 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
959 struct ptlrpc_request **request)
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_unlink(cobd_exp, data, request);
973 static int cobd_md_valid_attrs(struct obd_export *exp,
974 struct lustre_id *id)
976 struct obd_device *obd = class_exp2obd(exp);
977 struct obd_export *cobd_exp;
980 CERROR("invalid client cookie "LPX64"\n",
981 exp->exp_handle.h_cookie);
984 cobd_exp = cobd_get_exp(obd);
985 return md_valid_attrs(cobd_exp, id);
988 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
989 const char *old, int oldlen, const char *new,
990 int newlen, struct ptlrpc_request **request)
992 struct obd_device *obd = class_exp2obd(exp);
993 struct obd_export *cobd_exp;
996 CERROR("invalid client cookie "LPX64"\n",
997 exp->exp_handle.h_cookie);
1000 cobd_exp = cobd_get_exp(obd);
1001 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1004 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1005 struct ptlrpc_request **request)
1007 struct obd_device *obd = class_exp2obd(exp);
1008 struct obd_export *cobd_exp;
1011 CERROR("invalid client cookie "LPX64"\n",
1012 exp->exp_handle.h_cookie);
1015 cobd_exp = cobd_get_exp(obd);
1016 return md_link(cobd_exp, data, request);
1019 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1020 struct iattr *iattr, void *ea, int ealen, void *ea2,
1021 int ea2len, struct ptlrpc_request **request)
1023 struct obd_device *obd = class_exp2obd(exp);
1024 struct obd_export *cobd_exp;
1027 CERROR("invalid client cookie "LPX64"\n",
1028 exp->exp_handle.h_cookie);
1031 cobd_exp = cobd_get_exp(obd);
1032 return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1035 static int cobd_md_readpage(struct obd_export *exp,
1036 struct lustre_id *mdc_id,
1037 __u64 offset, struct page *page,
1038 struct ptlrpc_request **request)
1040 struct obd_device *obd = class_exp2obd(exp);
1041 struct obd_export *cobd_exp;
1044 CERROR("invalid client cookie "LPX64"\n",
1045 exp->exp_handle.h_cookie);
1048 cobd_exp = cobd_get_exp(obd);
1049 return md_readpage(cobd_exp, mdc_id, offset, page, request);
1052 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1053 struct obd_client_handle *och,
1054 struct ptlrpc_request **request)
1056 struct obd_device *obd = class_exp2obd(exp);
1057 struct obd_export *cobd_exp;
1060 CERROR("invalid client cookie "LPX64"\n",
1061 exp->exp_handle.h_cookie);
1064 cobd_exp = cobd_get_exp(obd);
1065 return md_close(cobd_exp, obdo, och, request);
1068 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1070 struct obd_device *obd = class_exp2obd(exp);
1071 struct obd_export *cobd_exp;
1074 CERROR("invalid client cookie "LPX64"\n",
1075 exp->exp_handle.h_cookie);
1078 cobd_exp = cobd_get_exp(obd);
1079 return md_done_writing(cobd_exp, obdo);
1082 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1083 struct ptlrpc_request **request)
1085 struct obd_device *obd = class_exp2obd(exp);
1086 struct obd_export *cobd_exp;
1089 CERROR("invalid client cookie "LPX64"\n",
1090 exp->exp_handle.h_cookie);
1093 cobd_exp = cobd_get_exp(obd);
1095 return md_sync(cobd_exp, id, request);
1098 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1099 struct obd_client_handle *och,
1100 struct ptlrpc_request *open_req)
1102 struct obd_device *obd = class_exp2obd(exp);
1103 struct obd_export *cobd_exp;
1106 CERROR("invalid client cookie "LPX64"\n",
1107 exp->exp_handle.h_cookie);
1110 cobd_exp = cobd_get_exp(obd);
1112 return md_set_open_replay_data(cobd_exp, och, open_req);
1115 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1116 struct obd_client_handle *och)
1118 struct obd_device *obd = class_exp2obd(exp);
1119 struct obd_export *cobd_exp;
1122 CERROR("invalid client cookie "LPX64"\n",
1123 exp->exp_handle.h_cookie);
1126 cobd_exp = cobd_get_exp(obd);
1128 return md_clear_open_replay_data(cobd_exp, och);
1131 static int cobd_md_store_inode_generation(struct obd_export *exp,
1132 struct ptlrpc_request *req,
1133 int reqoff, int repoff)
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_store_inode_generation(cobd_exp, req, reqoff, repoff);
1148 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1150 struct obd_device *obd = class_exp2obd(exp);
1151 struct obd_export *cobd_exp;
1154 CERROR("invalid client cookie "LPX64"\n",
1155 exp->exp_handle.h_cookie);
1158 cobd_exp = cobd_get_exp(obd);
1160 return md_set_lock_data(cobd_exp, l, data);
1163 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1164 struct lookup_intent *it, int lock_mode,
1165 struct mdc_op_data *data, struct lustre_handle *lockh,
1166 void *lmm, int lmmsize,
1167 ldlm_completion_callback cb_completion,
1168 ldlm_blocking_callback cb_blocking, void *cb_data)
1170 struct obd_device *obd = class_exp2obd(exp);
1171 struct obd_export *cobd_exp;
1174 CERROR("invalid client cookie "LPX64"\n",
1175 exp->exp_handle.h_cookie);
1178 cobd_exp = cobd_get_exp(obd);
1179 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1180 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1184 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1185 const char *name, int len, void *lmm, int lmmsize,
1186 struct lustre_id *cid, struct lookup_intent *it,
1187 int lookup_flags, struct ptlrpc_request **reqp,
1188 ldlm_blocking_callback cb_blocking)
1190 struct obd_device *obd = class_exp2obd(exp);
1191 struct obd_export *cobd_exp;
1194 CERROR("invalid client cookie "LPX64"\n",
1195 exp->exp_handle.h_cookie);
1198 cobd_exp = cobd_get_exp(obd);
1199 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1200 cid, it, lookup_flags, reqp, cb_blocking);
1203 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1204 struct lustre_id *id)
1206 struct obd_device *obd = class_exp2obd(exp);
1207 struct obd_export *cobd_exp;
1210 CERROR("invalid client cookie "LPX64"\n",
1211 exp->exp_handle.h_cookie);
1214 cobd_exp = cobd_get_exp(obd);
1215 return md_get_real_obd(cobd_exp, id);
1218 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1219 struct lustre_id *id, char *name,
1220 int namelen, struct lustre_id *id2,
1221 ldlm_iterator_t it, void *data)
1223 struct obd_device *obd = class_exp2obd(exp);
1224 struct obd_export *cobd_exp;
1227 CERROR("invalid client cookie "LPX64"\n",
1228 exp->exp_handle.h_cookie);
1231 cobd_exp = cobd_get_exp(obd);
1232 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1235 static struct obd_ops cobd_obd_ops = {
1236 .o_owner = THIS_MODULE,
1237 .o_attach = cobd_attach,
1238 .o_detach = cobd_detach,
1239 .o_setup = cobd_setup,
1240 .o_cleanup = cobd_cleanup,
1241 .o_connect = cobd_connect,
1242 .o_disconnect = cobd_disconnect,
1243 .o_set_info = cobd_set_info,
1244 .o_get_info = cobd_get_info,
1245 .o_statfs = cobd_statfs,
1247 .o_packmd = cobd_packmd,
1248 .o_unpackmd = cobd_unpackmd,
1249 .o_create = cobd_create,
1250 .o_destroy = cobd_destroy,
1251 .o_precleanup = cobd_precleanup,
1252 .o_getattr = cobd_getattr,
1253 .o_getattr_async = cobd_getattr_async,
1254 .o_setattr = cobd_setattr,
1257 .o_brw_async = cobd_brw_async,
1258 .o_prep_async_page = cobd_prep_async_page,
1259 .o_queue_async_io = cobd_queue_async_io,
1260 .o_set_async_flags = cobd_set_async_flags,
1261 .o_queue_group_io = cobd_queue_group_io,
1262 .o_trigger_group_io = cobd_trigger_group_io,
1263 .o_teardown_async_page = cobd_teardown_async_page,
1264 .o_preprw = cobd_preprw,
1265 .o_punch = cobd_punch,
1266 .o_sync = cobd_sync,
1267 .o_enqueue = cobd_enqueue,
1268 .o_match = cobd_match,
1269 .o_change_cbdata = cobd_change_cbdata,
1270 .o_cancel = cobd_cancel,
1271 .o_cancel_unused = cobd_cancel_unused,
1272 .o_iocontrol = cobd_iocontrol,
1273 .o_commitrw = cobd_commitrw,
1274 .o_llog_init = cobd_llog_init,
1275 .o_llog_finish = cobd_llog_finish,
1276 .o_notify = cobd_notify,
1278 .o_unpin = cobd_unpin,
1279 .o_import_event = cobd_import_event,
1280 .o_init_ea_size = cobd_init_ea_size,
1283 struct md_ops cobd_md_ops = {
1284 .m_getstatus = cobd_md_getstatus,
1285 .m_getattr = cobd_md_getattr,
1286 .m_req2lustre_md = cobd_md_req2lustre_md,
1287 .m_change_cbdata = cobd_md_change_cbdata,
1288 .m_getattr_lock = cobd_md_getattr_lock,
1289 .m_create = cobd_md_create,
1290 .m_unlink = cobd_md_unlink,
1291 .m_valid_attrs = cobd_md_valid_attrs,
1292 .m_rename = cobd_md_rename,
1293 .m_link = cobd_md_link,
1294 .m_setattr = cobd_md_setattr,
1295 .m_readpage = cobd_md_readpage,
1296 .m_close = cobd_md_close,
1297 .m_done_writing = cobd_md_done_writing,
1298 .m_sync = cobd_md_sync,
1299 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1300 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1301 .m_store_inode_generation = cobd_md_store_inode_generation,
1302 .m_set_lock_data = cobd_md_set_lock_data,
1303 .m_enqueue = cobd_md_enqueue,
1304 .m_get_real_obd = cobd_md_get_real_obd,
1305 .m_intent_lock = cobd_md_intent_lock,
1306 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1309 static int __init cobd_init(void)
1311 struct lprocfs_static_vars lvars;
1314 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1316 lprocfs_init_vars(cobd, &lvars);
1317 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1318 lvars.module_vars, OBD_CACHE_DEVICENAME));
1321 static void /*__exit*/ cobd_exit(void)
1323 class_unregister_type(OBD_CACHE_DEVICENAME);
1326 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1327 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1328 MODULE_LICENSE("GPL");
1330 module_init(cobd_init);
1331 module_exit(cobd_exit);