1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_COBD
24 #include <linux/version.h>
25 #include <linux/init.h>
26 #include <linux/obd_support.h>
27 #include <linux/lustre_lib.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_idl.h>
30 #include <linux/lustre_log.h>
31 #include <linux/lustre_mds.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_cache.h>
34 #include <linux/obd_lmv.h>
36 static int cobd_attach(struct obd_device *obd,
37 obd_count len, void *buf)
39 struct lprocfs_static_vars lvars;
41 lprocfs_init_vars(cobd, &lvars);
42 return lprocfs_obd_attach(obd, lvars.obd_vars);
45 static int cobd_detach(struct obd_device *obd)
47 return lprocfs_obd_detach(obd);
50 static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
52 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
53 struct cache_obd *cobd = &obd->u.cobd;
54 struct obd_device *master_obd, *cache_obd;
55 struct lustre_handle conn = { 0 };
59 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
60 lustre_cfg_buf(lcfg, 1) == NULL) {
61 CERROR("%s: setup requires master device name\n",
66 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 ||
67 lustre_cfg_buf(lcfg, 2) == NULL) {
68 CERROR("%s: setup requires cache device name\n",
72 sema_init(&cobd->sem, 1);
74 /*get the cache obd name and master name */
75 OBD_ALLOC(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
76 if (!cobd->master_name)
78 memcpy(cobd->master_name, lustre_cfg_string(lcfg, 1),
79 LUSTRE_CFG_BUFLEN(lcfg, 1));
81 OBD_ALLOC(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
82 if (!cobd->cache_name) {
83 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
86 memcpy(cobd->cache_name, lustre_cfg_string(lcfg, 2),
87 LUSTRE_CFG_BUFLEN(lcfg, 2));
89 /* getting master obd */
90 master_obd = class_name2obd(cobd->master_name);
92 CERROR("can't find master obd by name %s\n",
94 GOTO(put_names, rc = -EINVAL);
97 /* connecting master */
98 memset(&conn, 0, sizeof(conn));
99 rc = obd_connect(&conn, master_obd, &obd->obd_uuid, NULL, 0);
103 cobd->master_exp = class_conn2export(&conn);
105 /* getting master obd */
106 cache_obd = class_name2obd(cobd->cache_name);
108 obd_disconnect(cobd->master_exp, 0);
109 CERROR("can't find cache obd by name %s\n",
114 /* connecting master */
115 memset(&conn, 0, sizeof(conn));
116 rc = obd_connect(&conn, cache_obd, &obd->obd_uuid, NULL, 0);
118 obd_disconnect(cobd->master_exp, 0);
121 cobd->cache_exp = class_conn2export(&conn);
125 if (cobd->master_name) {
126 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
127 cobd->master_name = NULL;
129 if (cobd->cache_name) {
130 OBD_FREE(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
131 cobd->cache_name = NULL;
138 static int cobd_cleanup(struct obd_device *obd, int flags)
140 struct cache_obd *cobd = &obd->u.cobd;
143 if (!list_empty(&obd->obd_exports))
146 if (cobd->cache_name)
147 OBD_FREE(cobd->cache_name,
148 strlen(cobd->cache_name) + 1);
149 if (cobd->master_name)
150 OBD_FREE(cobd->master_name,
151 strlen(cobd->master_name) + 1);
156 static inline struct obd_export *
157 cobd_get_exp(struct obd_device *obd)
159 struct cache_obd *cobd = &obd->u.cobd;
161 return cobd->cache_exp;
162 return cobd->master_exp;
165 static int client_obd_connect(struct obd_device *obd, char *name,
166 struct lustre_handle *conn,
167 struct obd_connect_data *data,
170 struct obd_device *cli_obd;
178 cli_obd = class_name2obd(name);
179 if (cli_obd == NULL) {
180 CERROR("%s: unable to find a client for obd: %s\n",
181 obd->obd_name, name);
184 rc = obd_connect(conn, cli_obd, &obd->obd_uuid, data, flags);
186 CERROR("error connecting to %s, err %d\n",
192 static int client_obd_disconnect(struct obd_device *obd,
193 struct obd_export *exp,
196 struct obd_device *cli_obd;
200 cli_obd = class_exp2obd(exp);
201 cli_obd->obd_no_recov = obd->obd_no_recov;
203 rc = obd_disconnect(exp, flags);
205 CERROR("error disconnecting from %s, err %d\n",
206 cli_obd->obd_name, rc);
207 class_export_put(exp);
213 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
214 struct obd_uuid *cluuid, struct obd_connect_data *data,
217 struct obd_export *cobd_exp;
219 cobd_exp = cobd_get_exp(obd);
221 return obd_connect(conn, class_exp2obd(cobd_exp), cluuid,
226 cobd_disconnect(struct obd_export *exp, unsigned long flags)
228 struct obd_device *obd;
229 struct obd_export *cobd_exp;
233 LASSERT(exp != NULL);
234 obd = class_exp2obd(exp);
236 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
237 exp->exp_handle.h_cookie);
240 cobd_exp = cobd_get_exp(obd);
242 rc = obd_disconnect(cobd_exp, flags);
244 class_disconnect(exp, flags);
249 static int cobd_get_info(struct obd_export *exp, __u32 keylen,
250 void *key, __u32 *vallen, void *val)
252 struct obd_device *obd = class_exp2obd(exp);
253 struct obd_export *cobd_exp;
256 CERROR("invalid client cookie "LPX64"\n",
257 exp->exp_handle.h_cookie);
260 cobd_exp = cobd_get_exp(obd);
262 /* intercept cache utilisation info? */
263 return obd_get_info(cobd_exp, keylen, key, vallen, val);
266 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
267 void *key, obd_count vallen, void *val)
269 struct obd_device *obd = class_exp2obd(exp);
270 struct obd_export *cobd_exp;
273 CERROR("invalid client cookie "LPX64"\n",
274 exp->exp_handle.h_cookie);
277 cobd_exp = cobd_get_exp(obd);
279 /* intercept cache utilisation info? */
280 return obd_set_info(cobd_exp, keylen, key, vallen, val);
283 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
284 unsigned long max_age)
286 struct obd_export *cobd_exp;
288 cobd_exp = cobd_get_exp(obd);
290 return obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
293 static int cobd_packmd(struct obd_export *exp,
294 struct lov_mds_md **disk_tgt,
295 struct lov_stripe_md *mem_src)
297 struct obd_device *obd = class_exp2obd(exp);
298 struct obd_export *cobd_exp;
301 CERROR("invalid client cookie "LPX64"\n",
302 exp->exp_handle.h_cookie);
305 cobd_exp = cobd_get_exp(obd);
306 return obd_packmd(cobd_exp, disk_tgt, mem_src);
309 static int cobd_unpackmd(struct obd_export *exp,
310 struct lov_stripe_md **mem_tgt,
311 struct lov_mds_md *disk_src,
314 struct obd_device *obd = class_exp2obd(exp);
315 struct obd_export *cobd_exp;
318 CERROR("invalid client cookie "LPX64"\n",
319 exp->exp_handle.h_cookie);
322 cobd_exp = cobd_get_exp(obd);
323 return obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
326 static int cobd_create(struct obd_export *exp, struct obdo *obdo,
327 void *acl, int acl_size,
328 struct lov_stripe_md **ea,
329 struct obd_trans_info *oti)
331 struct obd_device *obd = class_exp2obd(exp);
332 struct obd_export *cobd_exp;
335 CERROR("invalid client cookie "LPX64"\n",
336 exp->exp_handle.h_cookie);
339 cobd_exp = cobd_get_exp(obd);
340 return obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
343 static int cobd_destroy(struct obd_export *exp, struct obdo *obdo,
344 struct lov_stripe_md *ea,
345 struct obd_trans_info *oti)
347 struct obd_device *obd = class_exp2obd(exp);
348 struct obd_export *cobd_exp;
351 CERROR("invalid client cookie "LPX64"\n",
352 exp->exp_handle.h_cookie);
355 cobd_exp = cobd_get_exp(obd);
356 return obd_destroy(cobd_exp, obdo, ea, oti);
359 static int cobd_precleanup(struct obd_device *obd, int flags)
361 /* FIXME-WANGDI: do we need some cleanup here? */
365 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
366 struct lov_stripe_md *ea)
368 struct obd_device *obd = class_exp2obd(exp);
369 struct obd_export *cobd_exp;
372 CERROR("invalid client cookie "LPX64"\n",
373 exp->exp_handle.h_cookie);
376 cobd_exp = cobd_get_exp(obd);
377 return obd_getattr(cobd_exp, oa, ea);
380 static int cobd_getattr_async(struct obd_export *exp,
381 struct obdo *obdo, struct lov_stripe_md *ea,
382 struct ptlrpc_request_set *set)
384 struct obd_device *obd = class_exp2obd(exp);
385 struct obd_export *cobd_exp;
388 CERROR("invalid client cookie "LPX64"\n",
389 exp->exp_handle.h_cookie);
392 cobd_exp = cobd_get_exp(obd);
393 return obd_getattr_async(cobd_exp, obdo, ea, set);
396 static int cobd_setattr(struct obd_export *exp, struct obdo *obdo,
397 struct lov_stripe_md *ea,
398 struct obd_trans_info *oti)
400 struct obd_device *obd = class_exp2obd(exp);
401 struct obd_export *cobd_exp;
404 CERROR("invalid client cookie "LPX64"\n",
405 exp->exp_handle.h_cookie);
408 cobd_exp = cobd_get_exp(obd);
409 return obd_setattr(cobd_exp, obdo, ea, oti);
412 static int cobd_md_getstatus(struct obd_export *exp,
413 struct lustre_id *rootid)
415 struct obd_device *obd = class_exp2obd(exp);
416 struct obd_export *cobd_exp;
419 CERROR("invalid client cookie "LPX64"\n",
420 exp->exp_handle.h_cookie);
423 cobd_exp = cobd_get_exp(obd);
424 return md_getstatus(cobd_exp, rootid);
427 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
428 struct lov_stripe_md *ea, obd_count oa_bufs,
429 struct brw_page *pg, struct obd_trans_info *oti)
431 struct obd_device *obd = class_exp2obd(exp);
432 struct obd_export *cobd_exp;
435 CERROR("invalid client cookie "LPX64"\n",
436 exp->exp_handle.h_cookie);
439 cobd_exp = cobd_get_exp(obd);
440 return obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
443 static int cobd_brw_async(int cmd, struct obd_export *exp,
444 struct obdo *oa, struct lov_stripe_md *ea,
445 obd_count oa_bufs, struct brw_page *pg,
446 struct ptlrpc_request_set *set,
447 struct obd_trans_info *oti)
449 struct obd_device *obd = class_exp2obd(exp);
450 struct obd_export *cobd_exp;
453 CERROR("invalid client cookie "LPX64"\n",
454 exp->exp_handle.h_cookie);
457 cobd_exp = cobd_get_exp(obd);
458 return obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
462 static int cobd_prep_async_page(struct obd_export *exp,
463 struct lov_stripe_md *lsm,
464 struct lov_oinfo *loi,
465 struct page *page, obd_off offset,
466 struct obd_async_page_ops *ops,
467 void *data, void **res)
469 struct obd_device *obd = class_exp2obd(exp);
470 struct obd_export *cobd_exp;
473 CERROR("invalid client cookie "LPX64"\n",
474 exp->exp_handle.h_cookie);
477 cobd_exp = cobd_get_exp(obd);
478 return obd_prep_async_page(cobd_exp, lsm, loi, page, offset,
482 static int cobd_queue_async_io(struct obd_export *exp,
483 struct lov_stripe_md *lsm,
484 struct lov_oinfo *loi, void *cookie,
485 int cmd, obd_off off, int count,
486 obd_flags brw_flags, obd_flags async_flags)
488 struct obd_device *obd = class_exp2obd(exp);
489 struct obd_export *cobd_exp;
492 CERROR("invalid client cookie "LPX64"\n",
493 exp->exp_handle.h_cookie);
496 cobd_exp = cobd_get_exp(obd);
497 return obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off, count,
498 brw_flags, async_flags);
501 static int cobd_set_async_flags(struct obd_export *exp,
502 struct lov_stripe_md *lsm,
503 struct lov_oinfo *loi, void *cookie,
504 obd_flags async_flags)
506 struct obd_device *obd = class_exp2obd(exp);
507 struct obd_export *cobd_exp;
510 CERROR("invalid client cookie "LPX64"\n",
511 exp->exp_handle.h_cookie);
514 cobd_exp = cobd_get_exp(obd);
515 return obd_set_async_flags(cobd_exp, lsm, loi, cookie, async_flags);
518 static int cobd_queue_group_io(struct obd_export *exp,
519 struct lov_stripe_md *lsm,
520 struct lov_oinfo *loi,
521 struct obd_io_group *oig,
522 void *cookie, int cmd, obd_off off,
523 int count, obd_flags brw_flags,
524 obd_flags async_flags)
526 struct obd_device *obd = class_exp2obd(exp);
527 struct obd_export *cobd_exp;
530 CERROR("invalid client cookie "LPX64"\n",
531 exp->exp_handle.h_cookie);
534 cobd_exp = cobd_get_exp(obd);
535 return obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
536 cmd, off, count, brw_flags, async_flags);
539 static int cobd_trigger_group_io(struct obd_export *exp,
540 struct lov_stripe_md *lsm,
541 struct lov_oinfo *loi,
542 struct obd_io_group *oig)
544 struct obd_device *obd = class_exp2obd(exp);
545 struct obd_export *cobd_exp;
548 CERROR("invalid client cookie "LPX64"\n",
549 exp->exp_handle.h_cookie);
552 cobd_exp = cobd_get_exp(obd);
553 return obd_trigger_group_io(cobd_exp, lsm, loi, oig);
556 static int cobd_teardown_async_page(struct obd_export *exp,
557 struct lov_stripe_md *lsm,
558 struct lov_oinfo *loi, void *cookie)
560 struct obd_device *obd = class_exp2obd(exp);
561 struct obd_export *cobd_exp;
564 CERROR("invalid client cookie "LPX64"\n",
565 exp->exp_handle.h_cookie);
568 cobd_exp = cobd_get_exp(obd);
569 return obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
572 static int cobd_punch(struct obd_export *exp, struct obdo *oa,
573 struct lov_stripe_md *ea, obd_size start,
574 obd_size end, struct obd_trans_info *oti)
576 struct obd_device *obd = class_exp2obd(exp);
577 struct obd_export *cobd_exp;
580 CERROR("invalid client cookie "LPX64"\n",
581 exp->exp_handle.h_cookie);
584 cobd_exp = cobd_get_exp(obd);
585 return obd_punch(cobd_exp, oa, ea, start, end, oti);
588 static int cobd_sync(struct obd_export *exp, struct obdo *oa,
589 struct lov_stripe_md *ea, obd_size start,
592 struct obd_device *obd = class_exp2obd(exp);
593 struct obd_export *cobd_exp;
596 CERROR("invalid client cookie "LPX64"\n",
597 exp->exp_handle.h_cookie);
600 cobd_exp = cobd_get_exp(obd);
601 return obd_sync(cobd_exp, oa, ea, start, end);
604 static int cobd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
605 __u32 type, ldlm_policy_data_t *policy,
606 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
607 void *gl_cb, void *data, __u32 lvb_len,
608 void *lvb_swabber, struct lustre_handle *lockh)
610 struct obd_device *obd = class_exp2obd(exp);
611 struct obd_export *cobd_exp;
614 CERROR("invalid client cookie "LPX64"\n",
615 exp->exp_handle.h_cookie);
618 cobd_exp = cobd_get_exp(obd);
619 return obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
620 bl_cb, cp_cb, gl_cb, data, lvb_len,
624 static int cobd_match(struct obd_export *exp, struct lov_stripe_md *ea,
625 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
626 int *flags, void *data, struct lustre_handle *lockh)
628 struct obd_device *obd = class_exp2obd(exp);
629 struct obd_export *cobd_exp;
632 CERROR("invalid client cookie "LPX64"\n",
633 exp->exp_handle.h_cookie);
636 cobd_exp = cobd_get_exp(obd);
637 return obd_match(cobd_exp, ea, type, policy, mode, flags, data,
640 static int cobd_change_cbdata(struct obd_export *exp,
641 struct lov_stripe_md *lsm,
642 ldlm_iterator_t it, void *data)
644 struct obd_device *obd = class_exp2obd(exp);
645 struct obd_export *cobd_exp;
648 CERROR("invalid client cookie "LPX64"\n",
649 exp->exp_handle.h_cookie);
652 cobd_exp = cobd_get_exp(obd);
653 return obd_change_cbdata(cobd_exp, lsm, it, data);
656 static int cobd_cancel(struct obd_export *exp,
657 struct lov_stripe_md *ea, __u32 mode,
658 struct lustre_handle *lockh)
660 struct obd_device *obd = class_exp2obd(exp);
661 struct obd_export *cobd_exp;
664 CERROR("invalid client cookie "LPX64"\n",
665 exp->exp_handle.h_cookie);
668 cobd_exp = cobd_get_exp(obd);
669 return obd_cancel(cobd_exp, ea, mode, lockh);
672 static int cobd_cancel_unused(struct obd_export *exp,
673 struct lov_stripe_md *ea, int flags,
676 struct obd_device *obd = class_exp2obd(exp);
677 struct obd_export *cobd_exp;
680 CERROR("invalid client cookie "LPX64"\n",
681 exp->exp_handle.h_cookie);
684 cobd_exp = cobd_get_exp(obd);
685 return obd_cancel_unused(cobd_exp, ea, flags, opaque);
688 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
689 int objcount, struct obd_ioobj *obj,
690 int niocount, struct niobuf_remote *nb,
691 struct niobuf_local *res, struct obd_trans_info *oti)
693 struct obd_device *obd = class_exp2obd(exp);
694 struct obd_export *cobd_exp;
697 CERROR("invalid client cookie "LPX64"\n",
698 exp->exp_handle.h_cookie);
701 cobd_exp = cobd_get_exp(obd);
702 return obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb,
706 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
707 int objcount, struct obd_ioobj *obj,
708 int niocount, struct niobuf_local *local,
709 struct obd_trans_info *oti, int rc)
711 struct obd_device *obd = class_exp2obd(exp);
712 struct obd_export *cobd_exp;
715 CERROR("invalid client cookie "LPX64"\n",
716 exp->exp_handle.h_cookie);
719 cobd_exp = cobd_get_exp(obd);
720 return obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount,
724 static int cobd_flush(struct obd_device *obd)
729 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
730 int len, void *karg, void *uarg)
732 struct obd_device *obd = class_exp2obd(exp);
733 struct cache_obd *cobd = &obd->u.cobd;
734 struct obd_export *cobd_exp;
741 case OBD_IOC_COBD_CON:
742 if (!cobd->cache_on) {
743 struct lustre_handle conn = {0};
745 rc = client_obd_disconnect(obd, cobd->master_exp, 0);
746 rc = client_obd_connect(obd, cobd->cache_name, &conn,
750 cobd->cache_exp = class_conn2export(&conn);
754 case OBD_IOC_COBD_COFF:
755 if (cobd->cache_on) {
756 struct lustre_handle conn = {0,};
757 struct obd_device *master = NULL;
758 struct obd_device *cache = NULL;
759 int easize, cooksize;
761 cache = class_exp2obd(cobd->cache_exp);
762 easize = cache->u.cli.cl_max_mds_easize;
763 cooksize = cache->u.cli.cl_max_mds_cookiesize;
765 rc = client_obd_disconnect(obd, cobd->cache_exp, 0);
766 rc = client_obd_connect(obd, cobd->master_name, &conn,
770 cobd->master_exp = class_conn2export(&conn);
772 master = class_exp2obd(cobd->master_exp);
773 master->u.cli.cl_max_mds_easize = easize;
774 master->u.cli.cl_max_mds_cookiesize = cooksize;
778 case OBD_IOC_COBD_CFLUSH:
779 if (cobd->cache_on) {
783 CERROR("%s: cache is turned off\n", obd->obd_name);
787 cobd_exp = cobd_get_exp(obd);
788 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
797 static int cobd_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
798 struct obd_device *disk_obd, int count,
799 struct llog_catid *logid)
801 struct obd_export *cobd_exp;
802 struct obd_device *cobd_obd;
804 cobd_exp = cobd_get_exp(obd);
805 cobd_obd = class_exp2obd(cobd_exp);
807 return obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
808 disk_obd, count, logid);
811 static int cobd_llog_finish(struct obd_device *obd, struct obd_llogs *llogs,
814 struct obd_export *cobd_exp;
815 struct obd_device *cobd_obd;
817 cobd_exp = cobd_get_exp(obd);
818 cobd_obd = class_exp2obd(cobd_exp);
820 return obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
823 static int cobd_notify(struct obd_device *obd, struct obd_device *watched,
824 int active, void *data)
826 struct obd_export *cobd_exp;
828 cobd_exp = cobd_get_exp(obd);
830 return obd_notify(class_exp2obd(cobd_exp), watched, active, data);
833 static int cobd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
834 int type, struct obd_client_handle *handle, int flag)
836 struct obd_device *obd = class_exp2obd(exp);
837 struct obd_export *cobd_exp;
840 CERROR("invalid client cookie "LPX64"\n",
841 exp->exp_handle.h_cookie);
844 cobd_exp = cobd_get_exp(obd);
846 return obd_pin(cobd_exp, ino, gen, type, handle, flag);
849 static int cobd_unpin(struct obd_export *exp,
850 struct obd_client_handle *handle, int flag)
852 struct obd_device *obd = class_exp2obd(exp);
853 struct obd_export *cobd_exp;
856 CERROR("invalid client cookie "LPX64"\n",
857 exp->exp_handle.h_cookie);
860 cobd_exp = cobd_get_exp(obd);
862 return obd_unpin(cobd_exp, handle, flag);
865 static int cobd_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
867 struct obd_export *cobd_exp;
869 cobd_exp = cobd_get_exp(exp->exp_obd);
870 return obd_init_ea_size(cobd_exp, easize, cookiesize);
873 static int cobd_import_event(struct obd_device *obd,
874 struct obd_import *imp,
875 enum obd_import_event event)
877 struct obd_export *cobd_exp;
879 cobd_exp = cobd_get_exp(obd);
881 obd_import_event(class_exp2obd(cobd_exp), imp, event);
886 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
887 __u64 valid, const char *ea_name, int ea_namelen,
888 unsigned int ea_size, struct ptlrpc_request **request)
890 struct obd_device *obd = class_exp2obd(exp);
891 struct obd_export *cobd_exp;
894 CERROR("invalid client cookie "LPX64"\n",
895 exp->exp_handle.h_cookie);
898 cobd_exp = cobd_get_exp(obd);
899 return md_getattr(cobd_exp, id, valid, NULL, 0, ea_size, request);
902 static int cobd_md_req2lustre_md (struct obd_export *mdc_exp,
903 struct ptlrpc_request *req, unsigned int offset,
904 struct obd_export *osc_exp, struct lustre_md *md)
906 struct obd_device *obd = class_exp2obd(mdc_exp);
907 struct obd_export *cobd_exp;
910 CERROR("invalid client cookie "LPX64"\n",
911 mdc_exp->exp_handle.h_cookie);
914 cobd_exp = cobd_get_exp(obd);
915 return md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
918 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
919 ldlm_iterator_t it, void *data)
921 struct obd_device *obd = class_exp2obd(exp);
922 struct obd_export *cobd_exp;
925 CERROR("invalid client cookie "LPX64"\n",
926 exp->exp_handle.h_cookie);
929 cobd_exp = cobd_get_exp(obd);
930 return md_change_cbdata(cobd_exp, id, it, data);
933 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
934 char *filename, int namelen, __u64 valid,
935 unsigned int ea_size, struct ptlrpc_request **request)
937 struct obd_device *obd = class_exp2obd(exp);
938 struct obd_export *cobd_exp;
941 CERROR("invalid client cookie "LPX64"\n",
942 exp->exp_handle.h_cookie);
945 cobd_exp = cobd_get_exp(obd);
946 return md_getattr_lock(cobd_exp, id, filename, namelen, valid,
950 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
951 const void *data, int datalen, int mode,
952 __u32 uid, __u32 gid, __u64 rdev,
953 struct ptlrpc_request **request)
955 struct obd_device *obd = class_exp2obd(exp);
956 struct obd_export *cobd_exp;
959 CERROR("invalid client cookie "LPX64"\n",
960 exp->exp_handle.h_cookie);
963 cobd_exp = cobd_get_exp(obd);
964 return md_create(cobd_exp, op_data, data, datalen, mode,
965 uid, gid, rdev, request);
968 static int cobd_md_unlink(struct obd_export *exp, struct mdc_op_data *data,
969 struct ptlrpc_request **request)
971 struct obd_device *obd = class_exp2obd(exp);
972 struct obd_export *cobd_exp;
975 CERROR("invalid client cookie "LPX64"\n",
976 exp->exp_handle.h_cookie);
979 cobd_exp = cobd_get_exp(obd);
980 return md_unlink(cobd_exp, data, request);
983 static int cobd_md_valid_attrs(struct obd_export *exp,
984 struct lustre_id *id)
986 struct obd_device *obd = class_exp2obd(exp);
987 struct obd_export *cobd_exp;
990 CERROR("invalid client cookie "LPX64"\n",
991 exp->exp_handle.h_cookie);
994 cobd_exp = cobd_get_exp(obd);
995 return md_valid_attrs(cobd_exp, id);
998 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
999 const char *old, int oldlen, const char *new,
1000 int newlen, struct ptlrpc_request **request)
1002 struct obd_device *obd = class_exp2obd(exp);
1003 struct obd_export *cobd_exp;
1006 CERROR("invalid client cookie "LPX64"\n",
1007 exp->exp_handle.h_cookie);
1010 cobd_exp = cobd_get_exp(obd);
1011 return md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1014 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1015 struct ptlrpc_request **request)
1017 struct obd_device *obd = class_exp2obd(exp);
1018 struct obd_export *cobd_exp;
1021 CERROR("invalid client cookie "LPX64"\n",
1022 exp->exp_handle.h_cookie);
1025 cobd_exp = cobd_get_exp(obd);
1026 return md_link(cobd_exp, data, request);
1029 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1030 struct iattr *iattr, void *ea, int ealen, void *ea2,
1031 int ea2len, struct ptlrpc_request **request)
1033 struct obd_device *obd = class_exp2obd(exp);
1034 struct obd_export *cobd_exp;
1037 CERROR("invalid client cookie "LPX64"\n",
1038 exp->exp_handle.h_cookie);
1041 cobd_exp = cobd_get_exp(obd);
1042 return md_setattr(cobd_exp, data, iattr, ea, ealen, ea2, ea2len, request);
1045 static int cobd_md_readpage(struct obd_export *exp,
1046 struct lustre_id *mdc_id,
1047 __u64 offset, struct page *page,
1048 struct ptlrpc_request **request)
1050 struct obd_device *obd = class_exp2obd(exp);
1051 struct obd_export *cobd_exp;
1054 CERROR("invalid client cookie "LPX64"\n",
1055 exp->exp_handle.h_cookie);
1058 cobd_exp = cobd_get_exp(obd);
1059 return md_readpage(cobd_exp, mdc_id, offset, page, request);
1062 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1063 struct obd_client_handle *och,
1064 struct ptlrpc_request **request)
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_close(cobd_exp, obdo, och, request);
1078 static int cobd_md_done_writing(struct obd_export *exp, struct obdo *obdo)
1080 struct obd_device *obd = class_exp2obd(exp);
1081 struct obd_export *cobd_exp;
1084 CERROR("invalid client cookie "LPX64"\n",
1085 exp->exp_handle.h_cookie);
1088 cobd_exp = cobd_get_exp(obd);
1089 return md_done_writing(cobd_exp, obdo);
1092 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1093 struct ptlrpc_request **request)
1095 struct obd_device *obd = class_exp2obd(exp);
1096 struct obd_export *cobd_exp;
1099 CERROR("invalid client cookie "LPX64"\n",
1100 exp->exp_handle.h_cookie);
1103 cobd_exp = cobd_get_exp(obd);
1105 return md_sync(cobd_exp, id, request);
1108 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1109 struct obd_client_handle *och,
1110 struct ptlrpc_request *open_req)
1112 struct obd_device *obd = class_exp2obd(exp);
1113 struct obd_export *cobd_exp;
1116 CERROR("invalid client cookie "LPX64"\n",
1117 exp->exp_handle.h_cookie);
1120 cobd_exp = cobd_get_exp(obd);
1122 return md_set_open_replay_data(cobd_exp, och, open_req);
1125 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1126 struct obd_client_handle *och)
1128 struct obd_device *obd = class_exp2obd(exp);
1129 struct obd_export *cobd_exp;
1132 CERROR("invalid client cookie "LPX64"\n",
1133 exp->exp_handle.h_cookie);
1136 cobd_exp = cobd_get_exp(obd);
1138 return md_clear_open_replay_data(cobd_exp, och);
1141 static int cobd_md_store_inode_generation(struct obd_export *exp,
1142 struct ptlrpc_request *req,
1143 int reqoff, int repoff)
1145 struct obd_device *obd = class_exp2obd(exp);
1146 struct obd_export *cobd_exp;
1149 CERROR("invalid client cookie "LPX64"\n",
1150 exp->exp_handle.h_cookie);
1153 cobd_exp = cobd_get_exp(obd);
1155 return md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1158 static int cobd_md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1160 struct obd_device *obd = class_exp2obd(exp);
1161 struct obd_export *cobd_exp;
1164 CERROR("invalid client cookie "LPX64"\n",
1165 exp->exp_handle.h_cookie);
1168 cobd_exp = cobd_get_exp(obd);
1170 return md_set_lock_data(cobd_exp, l, data);
1173 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1174 struct lookup_intent *it, int lock_mode,
1175 struct mdc_op_data *data, struct lustre_handle *lockh,
1176 void *lmm, int lmmsize,
1177 ldlm_completion_callback cb_completion,
1178 ldlm_blocking_callback cb_blocking, void *cb_data)
1180 struct obd_device *obd = class_exp2obd(exp);
1181 struct obd_export *cobd_exp;
1184 CERROR("invalid client cookie "LPX64"\n",
1185 exp->exp_handle.h_cookie);
1188 cobd_exp = cobd_get_exp(obd);
1189 return md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1190 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1194 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1195 const char *name, int len, void *lmm, int lmmsize,
1196 struct lustre_id *cid, struct lookup_intent *it,
1197 int lookup_flags, struct ptlrpc_request **reqp,
1198 ldlm_blocking_callback cb_blocking)
1200 struct obd_device *obd = class_exp2obd(exp);
1201 struct obd_export *cobd_exp;
1204 CERROR("invalid client cookie "LPX64"\n",
1205 exp->exp_handle.h_cookie);
1208 cobd_exp = cobd_get_exp(obd);
1209 return md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1210 cid, it, lookup_flags, reqp, cb_blocking);
1213 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1214 struct lustre_id *id)
1216 struct obd_device *obd = class_exp2obd(exp);
1217 struct obd_export *cobd_exp;
1220 CERROR("invalid client cookie "LPX64"\n",
1221 exp->exp_handle.h_cookie);
1224 cobd_exp = cobd_get_exp(obd);
1225 return md_get_real_obd(cobd_exp, id);
1228 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1229 struct lustre_id *id, char *name,
1230 int namelen, struct lustre_id *id2,
1231 ldlm_iterator_t it, void *data)
1233 struct obd_device *obd = class_exp2obd(exp);
1234 struct obd_export *cobd_exp;
1237 CERROR("invalid client cookie "LPX64"\n",
1238 exp->exp_handle.h_cookie);
1241 cobd_exp = cobd_get_exp(obd);
1242 return md_change_cbdata_name(cobd_exp, id, name, namelen,
1245 static struct obd_ops cobd_obd_ops = {
1246 .o_owner = THIS_MODULE,
1247 .o_attach = cobd_attach,
1248 .o_detach = cobd_detach,
1249 .o_setup = cobd_setup,
1250 .o_cleanup = cobd_cleanup,
1251 .o_connect = cobd_connect,
1252 .o_disconnect = cobd_disconnect,
1253 .o_set_info = cobd_set_info,
1254 .o_get_info = cobd_get_info,
1255 .o_statfs = cobd_statfs,
1257 .o_packmd = cobd_packmd,
1258 .o_unpackmd = cobd_unpackmd,
1259 .o_create = cobd_create,
1260 .o_destroy = cobd_destroy,
1261 .o_precleanup = cobd_precleanup,
1262 .o_getattr = cobd_getattr,
1263 .o_getattr_async = cobd_getattr_async,
1264 .o_setattr = cobd_setattr,
1267 .o_brw_async = cobd_brw_async,
1268 .o_prep_async_page = cobd_prep_async_page,
1269 .o_queue_async_io = cobd_queue_async_io,
1270 .o_set_async_flags = cobd_set_async_flags,
1271 .o_queue_group_io = cobd_queue_group_io,
1272 .o_trigger_group_io = cobd_trigger_group_io,
1273 .o_teardown_async_page = cobd_teardown_async_page,
1274 .o_preprw = cobd_preprw,
1275 .o_punch = cobd_punch,
1276 .o_sync = cobd_sync,
1277 .o_enqueue = cobd_enqueue,
1278 .o_match = cobd_match,
1279 .o_change_cbdata = cobd_change_cbdata,
1280 .o_cancel = cobd_cancel,
1281 .o_cancel_unused = cobd_cancel_unused,
1282 .o_iocontrol = cobd_iocontrol,
1283 .o_commitrw = cobd_commitrw,
1284 .o_llog_init = cobd_llog_init,
1285 .o_llog_finish = cobd_llog_finish,
1286 .o_notify = cobd_notify,
1288 .o_unpin = cobd_unpin,
1289 .o_import_event = cobd_import_event,
1290 .o_init_ea_size = cobd_init_ea_size,
1293 struct md_ops cobd_md_ops = {
1294 .m_getstatus = cobd_md_getstatus,
1295 .m_getattr = cobd_md_getattr,
1296 .m_req2lustre_md = cobd_md_req2lustre_md,
1297 .m_change_cbdata = cobd_md_change_cbdata,
1298 .m_getattr_lock = cobd_md_getattr_lock,
1299 .m_create = cobd_md_create,
1300 .m_unlink = cobd_md_unlink,
1301 .m_valid_attrs = cobd_md_valid_attrs,
1302 .m_rename = cobd_md_rename,
1303 .m_link = cobd_md_link,
1304 .m_setattr = cobd_md_setattr,
1305 .m_readpage = cobd_md_readpage,
1306 .m_close = cobd_md_close,
1307 .m_done_writing = cobd_md_done_writing,
1308 .m_sync = cobd_md_sync,
1309 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1310 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1311 .m_store_inode_generation = cobd_md_store_inode_generation,
1312 .m_set_lock_data = cobd_md_set_lock_data,
1313 .m_enqueue = cobd_md_enqueue,
1314 .m_get_real_obd = cobd_md_get_real_obd,
1315 .m_intent_lock = cobd_md_intent_lock,
1316 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1319 static int __init cobd_init(void)
1321 struct lprocfs_static_vars lvars;
1324 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1326 lprocfs_init_vars(cobd, &lvars);
1327 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1328 lvars.module_vars, OBD_CACHE_DEVICENAME));
1331 static void /*__exit*/ cobd_exit(void)
1333 class_unregister_type(OBD_CACHE_DEVICENAME);
1336 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1337 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1338 MODULE_LICENSE("GPL");
1340 module_init(cobd_init);
1341 module_exit(cobd_exit);