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>
35 #include <linux/obd_lov.h>
37 static int cobd_attach(struct obd_device *obd,
38 obd_count len, void *buf)
40 struct lprocfs_static_vars lvars;
44 lprocfs_init_vars(cobd, &lvars);
45 rc = lprocfs_obd_attach(obd, lvars.obd_vars);
50 static int cobd_detach(struct obd_device *obd)
53 RETURN(lprocfs_obd_detach(obd));
56 static int cobd_setup(struct obd_device *obd, obd_count len, void *buf)
58 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
59 int inst_len = 0, mname_len = 0, cname_len = 0;
60 struct obd_device *master_obd, *cache_obd;
61 struct cache_obd *cobd = &obd->u.cobd;
62 struct lustre_handle conn = { 0 };
66 sema_init(&cobd->sem, 1);
68 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
69 lustre_cfg_buf(lcfg, 1) == NULL) {
70 CERROR("%s: setup requires master device name\n",
75 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 ||
76 lustre_cfg_buf(lcfg, 2) == NULL) {
77 CERROR("%s: setup requires cache device name\n",
81 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 3);
84 LASSERT(lustre_cfg_buf(lcfg, 3) != NULL);
85 mname_len = LUSTRE_CFG_BUFLEN(lcfg, 1) + inst_len;
86 cname_len = LUSTRE_CFG_BUFLEN(lcfg, 2) + inst_len;
88 mname_len = LUSTRE_CFG_BUFLEN(lcfg, 1);
89 cname_len = LUSTRE_CFG_BUFLEN(lcfg, 2);
92 /* get the cache obd name and master name */
93 OBD_ALLOC(cobd->master_name, mname_len);
94 if (!cobd->master_name)
97 sprintf(cobd->master_name, "%s-%s", lustre_cfg_string(lcfg, 1),
98 lustre_cfg_string(lcfg, 3));
100 sprintf(cobd->master_name, "%s", lustre_cfg_string(lcfg, 1));
102 OBD_ALLOC(cobd->cache_name, cname_len);
103 if (!cobd->cache_name) {
104 OBD_FREE(cobd->master_name, mname_len);
108 sprintf(cobd->cache_name, "%s-%s", lustre_cfg_string(lcfg, 2),
109 lustre_cfg_string(lcfg, 3));
111 sprintf(cobd->cache_name, "%s", lustre_cfg_string(lcfg, 2));
113 CDEBUG(D_INFO, "master name %s cache name %s\n", cobd->master_name,
116 /* getting master obd */
117 master_obd = class_name2obd(cobd->master_name);
119 CERROR("can't find master obd by name %s\n",
121 GOTO(put_names, rc = -EINVAL);
124 /* connecting master */
125 memset(&conn, 0, sizeof(conn));
126 rc = class_connect(&conn, master_obd, &obd->obd_uuid);
130 cobd->master_exp = class_conn2export(&conn);
132 /* getting cache obd */
133 cache_obd = class_name2obd(cobd->cache_name);
135 class_disconnect(cobd->master_exp, 0);
136 CERROR("can't find cache obd by name %s\n",
138 GOTO(put_names, rc = -EINVAL);
141 /* connecting cache */
142 memset(&conn, 0, sizeof(conn));
143 rc = class_connect(&conn, cache_obd, &obd->obd_uuid);
145 class_disconnect(cobd->master_exp, 0);
148 cobd->cache_exp = class_conn2export(&conn);
150 /* default set cache on, but nothins is realy connected yet, will be
151 * done in cobd_connect() time. */
154 /* nothing is connected, make exports reflect this state to not confuse
155 * cobd_switch() later. */
156 cobd->cache_real_exp = NULL;
157 cobd->master_real_exp = NULL;
162 if (cobd->master_name) {
163 OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1));
164 cobd->master_name = NULL;
166 if (cobd->cache_name) {
167 OBD_FREE(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2));
168 cobd->cache_name = NULL;
174 static int cobd_cleanup(struct obd_device *obd, int flags)
176 struct cache_obd *cobd = &obd->u.cobd;
180 if (!list_empty(&obd->obd_exports))
183 if (cobd->cache_name)
184 OBD_FREE(cobd->cache_name,
185 strlen(cobd->cache_name) + 1);
186 if (cobd->master_name)
187 OBD_FREE(cobd->master_name,
188 strlen(cobd->master_name) + 1);
190 rc = class_disconnect(cobd->master_exp, flags);
192 CERROR("error disconnecting master, err %d\n",
195 rc = class_disconnect(cobd->cache_exp, flags);
197 CERROR("error disconnecting master, err %d\n",
204 static inline struct obd_export *
205 cobd_get_exp(struct obd_device *obd)
207 struct cache_obd *cobd = &obd->u.cobd;
210 if (cobd->cache_on) {
211 CDEBUG(D_TRACE, "get cache exp %p \n", cobd->cache_exp);
212 if (cobd->cache_real_exp)
213 RETURN(cobd->cache_real_exp);
214 RETURN(cobd->cache_exp);
217 CDEBUG(D_TRACE, "get master exp %p \n", cobd->master_exp);
218 if (cobd->master_real_exp)
219 RETURN(cobd->master_real_exp);
220 RETURN(cobd->master_exp);
223 static int cobd_init_dt_desc(struct obd_device *obd)
225 struct cache_obd *cobd = &obd->u.cobd;
226 struct obd_export *cobd_exp;
231 valsize = sizeof(cobd->dt_desc);
232 memset(&cobd->dt_desc, 0, sizeof(cobd->dt_desc));
234 cobd_exp = cobd_get_exp(obd);
235 rc = obd_get_info(cobd_exp, strlen("lovdesc") + 1,
236 "lovdesc", &valsize, &cobd->dt_desc);
240 static int cobd_init_ea_size(struct obd_device *obd)
242 int rc = 0, tgt_count, easize, cookiesize;
243 struct cache_obd *cobd = &obd->u.cobd;
244 struct obd_export *cobd_exp;
247 tgt_count = cobd->dt_desc.ld_tgt_count;
249 /* no EA setup is needed as there is single OST with no LOV */
253 cobd_exp = cobd_get_exp(obd);
254 easize = lov_mds_md_size(tgt_count);
255 cookiesize = tgt_count * sizeof(struct llog_cookie);
256 rc = obd_init_ea_size(cobd_exp, easize, cookiesize);
261 cobd_connect_client(struct obd_device *obd,
262 struct obd_export *exp,
263 struct lustre_handle *conn,
264 struct obd_connect_data *data,
267 struct obd_device *cli_obd;
274 cli_obd = class_exp2obd(exp);
278 rc = obd_connect(conn, cli_obd, &obd->obd_uuid,
281 CERROR("error connecting err %d\n", rc);
287 cobd_disconnect_client(struct obd_device *obd,
288 struct obd_export *exp,
291 struct obd_device *cli_obd;
295 cli_obd = class_exp2obd(exp);
296 cli_obd->obd_no_recov = obd->obd_no_recov;
298 rc = obd_disconnect(exp, flags);
300 CERROR("error disconnecting from %s, err %d\n",
301 cli_obd->obd_name, rc);
302 class_export_put(exp);
307 #define COBD_CONNECT (1 << 0)
308 #define COBD_DISCON (1 << 1)
309 #define COBD_BOTH (1 << 2)
311 /* magic function for switching cobd between two exports cache and master in
312 * strong correspondence with passed @cache_on. It also may perform partial
313 * actions like only turn off old export or only turn on new one.
315 * bias == COBD_CONNECT only connect new export (used in cobd_connect())
316 * bias == COBD_DISCON only disconnect old export (used in cobd_disconnect())
317 * bias == COBD_BOTH do both (disconnect old and connect new) (used in
320 static int cobd_switch(struct obd_device *obd,
321 int cache_on, int bias)
323 struct cache_obd *cobd = &obd->u.cobd;
324 struct obd_device *cli_obd = NULL;
325 struct lustre_handle conn = {0,};
326 struct obd_export *discon_exp;
327 struct obd_export *conn_exp;
332 discon_exp = cobd->master_real_exp;
333 conn_exp = cobd->cache_exp;
335 discon_exp = cobd->cache_real_exp;
336 conn_exp = cobd->master_exp;
339 /* disconnect old export */
340 if (bias == COBD_BOTH || bias == COBD_DISCON) {
342 rc = cobd_disconnect_client(obd, discon_exp, 0);
344 CWARN("can't disconnect export %p, err %d\n",
350 cobd->master_real_exp = NULL;
352 cobd->cache_real_exp = NULL;
355 /* connect new export */
356 if (bias == COBD_BOTH || bias == COBD_CONNECT) {
357 rc = cobd_connect_client(obd, conn_exp, &conn,
358 NULL, OBD_OPT_REAL_CLIENT);
360 CERROR("can't connect export %p, err %d\n",
366 cobd->cache_real_exp = class_conn2export(&conn);
367 cli_obd = class_exp2obd(cobd->cache_exp);
369 cobd->master_real_exp = class_conn2export(&conn);
370 cli_obd = class_exp2obd(cobd->master_exp);
374 cobd->cache_on = cache_on;
376 if (bias == COBD_BOTH || bias == COBD_CONNECT) {
377 /* re-init EA size for new selected export. This should be done after
378 * assigining new state to @cobd->cache_on to not call not connened
379 * already old export. */
380 if (obd_md_type(cli_obd)) {
381 rc = cobd_init_dt_desc(obd);
383 rc = cobd_init_ea_size(obd);
385 CERROR("can't initialize EA size, "
389 /* ignore cases when we di dnot manage to init
390 * lovdesc. This is because some devices may not know
391 * "lovdesc" info command. */
401 cobd_connect(struct lustre_handle *conn, struct obd_device *obd,
402 struct obd_uuid *cluuid, struct obd_connect_data *data,
405 struct cache_obd *cobd = &obd->u.cobd;
406 struct obd_export *exp;
410 rc = class_connect(conn, obd, cluuid);
414 exp = class_conn2export(conn);
415 rc = cobd_switch(obd, cobd->cache_on,
418 class_disconnect(exp, 0);
420 class_export_put(exp);
425 cobd_disconnect(struct obd_export *exp, unsigned long flags)
427 struct cache_obd *cobd;
428 struct obd_device *obd;
432 LASSERT(exp != NULL);
433 obd = class_exp2obd(exp);
435 CDEBUG(D_IOCTL, "invalid client cookie "
436 LPX64"\n", exp->exp_handle.h_cookie);
440 /* here would be nice also to check that disconnect goes to the same
441 * export as connect did. But as now we are accepting the notion that
442 * cache should be switched after client umount this is not needed.
445 rc = cobd_switch(obd, cobd->cache_on, COBD_DISCON);
446 class_disconnect(exp, flags);
451 static int cobd_get_info(struct obd_export *exp, __u32 keylen,
452 void *key, __u32 *vallen, void *val)
454 struct obd_device *obd = class_exp2obd(exp);
455 struct obd_export *cobd_exp;
460 CERROR("invalid client cookie "LPX64"\n",
461 exp->exp_handle.h_cookie);
464 cobd_exp = cobd_get_exp(obd);
466 /* intercept cache utilisation info? */
467 rc = obd_get_info(cobd_exp, keylen, key, vallen, val);
471 static int cobd_set_info(struct obd_export *exp, obd_count keylen,
472 void *key, obd_count vallen, void *val)
474 struct obd_device *obd = class_exp2obd(exp);
475 struct obd_export *cobd_exp;
480 CERROR("invalid client cookie "LPX64"\n",
481 exp->exp_handle.h_cookie);
484 cobd_exp = cobd_get_exp(obd);
488 /* intercept cache utilisation info? */
489 rc = obd_set_info(cobd_exp, keylen, key, vallen, val);
493 static int cobd_statfs(struct obd_device *obd,
494 struct obd_statfs *osfs,
495 unsigned long max_age)
497 struct obd_export *cobd_exp;
501 cobd_exp = cobd_get_exp(obd);
502 rc = obd_statfs(class_exp2obd(cobd_exp), osfs, max_age);
506 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp,
507 int len, void *karg, void *uarg)
509 struct obd_device *obd = class_exp2obd(exp);
510 struct cache_obd *cobd = &obd->u.cobd;
511 struct obd_export *cobd_exp;
517 /* here would be nice also to make sure somehow that there are no
518 * out-standing requests which go to wrong MDS after cache switch (close
519 * RPCs). But how to check that from COBD? I do not know. --umka */
521 case OBD_IOC_COBD_CON:
523 rc = cobd_switch(obd, 1, COBD_BOTH);
525 case OBD_IOC_COBD_COFF:
527 rc = cobd_switch(obd, 0, COBD_BOTH);
530 cobd_exp = cobd_get_exp(obd);
531 rc = obd_iocontrol(cmd, cobd_exp, len, karg, uarg);
538 static int cobd_dt_packmd(struct obd_export *exp,
539 struct lov_mds_md **disk_tgt,
540 struct lov_stripe_md *mem_src)
542 struct obd_device *obd = class_exp2obd(exp);
543 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 rc = obd_packmd(cobd_exp, disk_tgt, mem_src);
557 static int cobd_dt_unpackmd(struct obd_export *exp,
558 struct lov_stripe_md **mem_tgt,
559 struct lov_mds_md *disk_src,
562 struct obd_device *obd = class_exp2obd(exp);
563 struct obd_export *cobd_exp;
568 CERROR("invalid client cookie "LPX64"\n",
569 exp->exp_handle.h_cookie);
572 cobd_exp = cobd_get_exp(obd);
573 rc = obd_unpackmd(cobd_exp, mem_tgt, disk_src, disk_len);
577 static int cobd_dt_create(struct obd_export *exp,
579 void *acl, int acl_size,
580 struct lov_stripe_md **ea,
581 struct obd_trans_info *oti)
583 struct obd_device *obd = class_exp2obd(exp);
584 struct obd_export *cobd_exp;
589 CERROR("invalid client cookie "LPX64"\n",
590 exp->exp_handle.h_cookie);
593 cobd_exp = cobd_get_exp(obd);
594 rc = obd_create(cobd_exp, obdo, acl, acl_size, ea, oti);
598 static int cobd_dt_destroy(struct obd_export *exp,
600 struct lov_stripe_md *ea,
601 struct obd_trans_info *oti)
603 struct obd_device *obd = class_exp2obd(exp);
604 struct obd_export *cobd_exp;
609 CERROR("invalid client cookie "LPX64"\n",
610 exp->exp_handle.h_cookie);
613 cobd_exp = cobd_get_exp(obd);
614 rc = obd_destroy(cobd_exp, obdo, ea, oti);
618 static int cobd_dt_precleanup(struct obd_device *obd, int flags)
620 /* FIXME: do we need some cleanup here? */
625 static int cobd_dt_getattr(struct obd_export *exp, struct obdo *oa,
626 struct lov_stripe_md *ea)
628 struct obd_device *obd = class_exp2obd(exp);
629 struct obd_export *cobd_exp;
634 CERROR("invalid client cookie "LPX64"\n",
635 exp->exp_handle.h_cookie);
638 cobd_exp = cobd_get_exp(obd);
639 rc = obd_getattr(cobd_exp, oa, ea);
643 static int cobd_dt_getattr_async(struct obd_export *exp,
644 struct obdo *obdo, struct lov_stripe_md *ea,
645 struct ptlrpc_request_set *set)
647 struct obd_device *obd = class_exp2obd(exp);
648 struct obd_export *cobd_exp;
653 CERROR("invalid client cookie "LPX64"\n",
654 exp->exp_handle.h_cookie);
657 cobd_exp = cobd_get_exp(obd);
658 rc = obd_getattr_async(cobd_exp, obdo, ea, set);
662 static int cobd_dt_setattr(struct obd_export *exp, struct obdo *obdo,
663 struct lov_stripe_md *ea,
664 struct obd_trans_info *oti)
666 struct obd_device *obd = class_exp2obd(exp);
667 struct obd_export *cobd_exp;
672 CERROR("invalid client cookie "LPX64"\n",
673 exp->exp_handle.h_cookie);
676 cobd_exp = cobd_get_exp(obd);
677 rc = obd_setattr(cobd_exp, obdo, ea, oti);
681 static int cobd_dt_brw(int cmd, struct obd_export *exp, struct obdo *oa,
682 struct lov_stripe_md *ea, obd_count oa_bufs,
683 struct brw_page *pg, struct obd_trans_info *oti)
685 struct obd_device *obd = class_exp2obd(exp);
686 struct obd_export *cobd_exp;
691 CERROR("invalid client cookie "LPX64"\n",
692 exp->exp_handle.h_cookie);
695 cobd_exp = cobd_get_exp(obd);
696 rc = obd_brw(cmd, cobd_exp, oa, ea, oa_bufs, pg, oti);
700 static int cobd_dt_brw_async(int cmd, struct obd_export *exp,
701 struct obdo *oa, struct lov_stripe_md *ea,
702 obd_count oa_bufs, struct brw_page *pg,
703 struct ptlrpc_request_set *set,
704 struct obd_trans_info *oti)
706 struct obd_device *obd = class_exp2obd(exp);
707 struct obd_export *cobd_exp;
712 CERROR("invalid client cookie "LPX64"\n",
713 exp->exp_handle.h_cookie);
716 cobd_exp = cobd_get_exp(obd);
717 rc = obd_brw_async(cmd, cobd_exp, oa, ea, oa_bufs,
722 static int cobd_dt_prep_async_page(struct obd_export *exp,
723 struct lov_stripe_md *lsm,
724 struct lov_oinfo *loi,
725 struct page *page, obd_off offset,
726 struct obd_async_page_ops *ops,
727 void *data, void **res)
729 struct obd_device *obd = class_exp2obd(exp);
730 struct obd_export *cobd_exp;
735 CERROR("invalid client cookie "LPX64"\n",
736 exp->exp_handle.h_cookie);
739 cobd_exp = cobd_get_exp(obd);
740 rc = obd_prep_async_page(cobd_exp, lsm, loi, page,
741 offset, ops, data, res);
745 static int cobd_dt_queue_async_io(struct obd_export *exp,
746 struct lov_stripe_md *lsm,
747 struct lov_oinfo *loi, void *cookie,
748 int cmd, obd_off off, int count,
749 obd_flags brw_flags, obd_flags async_flags)
751 struct obd_device *obd = class_exp2obd(exp);
752 struct obd_export *cobd_exp;
757 CERROR("invalid client cookie "LPX64"\n",
758 exp->exp_handle.h_cookie);
761 cobd_exp = cobd_get_exp(obd);
762 rc = obd_queue_async_io(cobd_exp, lsm, loi, cookie, cmd, off,
763 count, brw_flags, async_flags);
767 static int cobd_dt_set_async_flags(struct obd_export *exp,
768 struct lov_stripe_md *lsm,
769 struct lov_oinfo *loi, void *cookie,
770 obd_flags async_flags)
772 struct obd_device *obd = class_exp2obd(exp);
773 struct obd_export *cobd_exp;
778 CERROR("invalid client cookie "LPX64"\n",
779 exp->exp_handle.h_cookie);
782 cobd_exp = cobd_get_exp(obd);
783 rc = obd_set_async_flags(cobd_exp, lsm, loi, cookie,
788 static int cobd_dt_queue_group_io(struct obd_export *exp,
789 struct lov_stripe_md *lsm,
790 struct lov_oinfo *loi,
791 struct obd_io_group *oig,
792 void *cookie, int cmd, obd_off off,
793 int count, obd_flags brw_flags,
794 obd_flags async_flags)
796 struct obd_device *obd = class_exp2obd(exp);
797 struct obd_export *cobd_exp;
802 CERROR("invalid client cookie "LPX64"\n",
803 exp->exp_handle.h_cookie);
806 cobd_exp = cobd_get_exp(obd);
807 rc = obd_queue_group_io(cobd_exp, lsm, loi, oig, cookie,
808 cmd, off, count, brw_flags,
813 static int cobd_dt_trigger_group_io(struct obd_export *exp,
814 struct lov_stripe_md *lsm,
815 struct lov_oinfo *loi,
816 struct obd_io_group *oig)
818 struct obd_device *obd = class_exp2obd(exp);
819 struct obd_export *cobd_exp;
824 CERROR("invalid client cookie "LPX64"\n",
825 exp->exp_handle.h_cookie);
828 cobd_exp = cobd_get_exp(obd);
829 rc = obd_trigger_group_io(cobd_exp, lsm, loi, oig);
833 static int cobd_dt_teardown_async_page(struct obd_export *exp,
834 struct lov_stripe_md *lsm,
835 struct lov_oinfo *loi,
838 struct obd_device *obd = class_exp2obd(exp);
839 struct obd_export *cobd_exp;
844 CERROR("invalid client cookie "LPX64"\n",
845 exp->exp_handle.h_cookie);
848 cobd_exp = cobd_get_exp(obd);
849 rc = obd_teardown_async_page(cobd_exp, lsm, loi, cookie);
853 static int cobd_dt_punch(struct obd_export *exp, struct obdo *oa,
854 struct lov_stripe_md *ea, obd_size start,
855 obd_size end, struct obd_trans_info *oti)
857 struct obd_device *obd = class_exp2obd(exp);
858 struct obd_export *cobd_exp;
863 CERROR("invalid client cookie "LPX64"\n",
864 exp->exp_handle.h_cookie);
867 cobd_exp = cobd_get_exp(obd);
868 rc = obd_punch(cobd_exp, oa, ea, start, end, oti);
872 static int cobd_dt_sync(struct obd_export *exp, struct obdo *oa,
873 struct lov_stripe_md *ea, obd_size start,
876 struct obd_device *obd = class_exp2obd(exp);
877 struct obd_export *cobd_exp;
882 CERROR("invalid client cookie "LPX64"\n",
883 exp->exp_handle.h_cookie);
886 cobd_exp = cobd_get_exp(obd);
887 rc = obd_sync(cobd_exp, oa, ea, start, end);
891 static int cobd_dt_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
892 __u32 type, ldlm_policy_data_t *policy,
893 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
894 void *gl_cb, void *data, __u32 lvb_len,
895 void *lvb_swabber, struct lustre_handle *lockh)
897 struct obd_device *obd = class_exp2obd(exp);
898 struct obd_export *cobd_exp;
903 CERROR("invalid client cookie "LPX64"\n",
904 exp->exp_handle.h_cookie);
907 cobd_exp = cobd_get_exp(obd);
908 rc = obd_enqueue(cobd_exp, ea, type, policy, mode, flags,
909 bl_cb, cp_cb, gl_cb, data, lvb_len,
914 static int cobd_dt_match(struct obd_export *exp, struct lov_stripe_md *ea,
915 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
916 int *flags, void *data, struct lustre_handle *lockh)
918 struct obd_device *obd = class_exp2obd(exp);
919 struct obd_export *cobd_exp;
924 CERROR("invalid client cookie "LPX64"\n",
925 exp->exp_handle.h_cookie);
928 cobd_exp = cobd_get_exp(obd);
929 rc = obd_match(cobd_exp, ea, type, policy, mode, flags,
933 static int cobd_dt_change_cbdata(struct obd_export *exp,
934 struct lov_stripe_md *lsm,
935 ldlm_iterator_t it, void *data)
937 struct obd_device *obd = class_exp2obd(exp);
938 struct obd_export *cobd_exp;
943 CERROR("invalid client cookie "LPX64"\n",
944 exp->exp_handle.h_cookie);
947 cobd_exp = cobd_get_exp(obd);
948 rc = obd_change_cbdata(cobd_exp, lsm, it, data);
952 static int cobd_dt_cancel(struct obd_export *exp,
953 struct lov_stripe_md *ea, __u32 mode,
954 struct lustre_handle *lockh)
956 struct obd_device *obd = class_exp2obd(exp);
957 struct obd_export *cobd_exp;
962 CERROR("invalid client cookie "LPX64"\n",
963 exp->exp_handle.h_cookie);
966 cobd_exp = cobd_get_exp(obd);
967 rc = obd_cancel(cobd_exp, ea, mode, lockh);
971 static int cobd_dt_cancel_unused(struct obd_export *exp,
972 struct lov_stripe_md *ea,
973 int flags, void *opaque)
975 struct obd_device *obd = class_exp2obd(exp);
976 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 rc = obd_cancel_unused(cobd_exp, ea, flags, opaque);
990 static int cobd_dt_preprw(int cmd, struct obd_export *exp,
991 struct obdo *oa, int objcount,
992 struct obd_ioobj *obj, int niocount,
993 struct niobuf_remote *nb,
994 struct niobuf_local *res,
995 struct obd_trans_info *oti)
997 struct obd_device *obd = class_exp2obd(exp);
998 struct obd_export *cobd_exp;
1003 CERROR("invalid client cookie "LPX64"\n",
1004 exp->exp_handle.h_cookie);
1007 cobd_exp = cobd_get_exp(obd);
1008 rc = obd_preprw(cmd, cobd_exp, oa, objcount, obj,
1009 niocount, nb, res, oti);
1013 static int cobd_dt_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1014 int objcount, struct obd_ioobj *obj,
1015 int niocount, struct niobuf_local *local,
1016 struct obd_trans_info *oti, int rc)
1018 struct obd_device *obd = class_exp2obd(exp);
1019 struct obd_export *cobd_exp;
1024 CERROR("invalid client cookie "LPX64"\n",
1025 exp->exp_handle.h_cookie);
1028 cobd_exp = cobd_get_exp(obd);
1029 err = obd_commitrw(cmd, cobd_exp, oa, objcount, obj,
1030 niocount, local, oti, rc);
1034 static int cobd_dt_adjust_kms(struct obd_export *exp,
1035 struct lov_stripe_md *lsm,
1036 obd_off size, int shrink)
1038 struct obd_device *obd = class_exp2obd(exp);
1039 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 rc = obd_adjust_kms(cobd_exp, lsm, size, shrink);
1054 static int cobd_dt_llog_init(struct obd_device *obd,
1055 struct obd_llogs *llogs,
1056 struct obd_device *disk_obd,
1057 int count, struct llog_catid *logid)
1059 struct obd_export *cobd_exp;
1060 struct obd_device *cobd_obd;
1064 cobd_exp = cobd_get_exp(obd);
1065 cobd_obd = class_exp2obd(cobd_exp);
1067 rc = obd_llog_init(cobd_obd, &cobd_obd->obd_llogs,
1068 disk_obd, count, logid);
1072 static int cobd_dt_llog_finish(struct obd_device *obd,
1073 struct obd_llogs *llogs,
1076 struct obd_export *cobd_exp;
1077 struct obd_device *cobd_obd;
1081 cobd_exp = cobd_get_exp(obd);
1082 cobd_obd = class_exp2obd(cobd_exp);
1084 rc = obd_llog_finish(cobd_obd, &cobd_obd->obd_llogs, count);
1088 static int cobd_dt_notify(struct obd_device *obd, struct obd_device *watched,
1089 int active, void *data)
1091 struct obd_export *cobd_exp;
1095 cobd_exp = cobd_get_exp(obd);
1096 rc = obd_notify(class_exp2obd(cobd_exp), watched, active, data);
1100 static int cobd_dt_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1101 int type, struct obd_client_handle *handle,
1104 struct obd_device *obd = class_exp2obd(exp);
1105 struct obd_export *cobd_exp;
1110 CERROR("invalid client cookie "LPX64"\n",
1111 exp->exp_handle.h_cookie);
1114 cobd_exp = cobd_get_exp(obd);
1115 rc = obd_pin(cobd_exp, ino, gen, type, handle, flag);
1119 static int cobd_dt_unpin(struct obd_export *exp,
1120 struct obd_client_handle *handle,
1123 struct obd_device *obd = class_exp2obd(exp);
1124 struct obd_export *cobd_exp;
1129 CERROR("invalid client cookie "LPX64"\n",
1130 exp->exp_handle.h_cookie);
1133 cobd_exp = cobd_get_exp(obd);
1134 rc = obd_unpin(cobd_exp, handle, flag);
1138 static int cobd_dt_init_ea_size(struct obd_export *exp, int easize,
1141 struct obd_export *cobd_exp;
1145 cobd_exp = cobd_get_exp(exp->exp_obd);
1146 rc = obd_init_ea_size(cobd_exp, easize, cookiesize);
1150 static int cobd_dt_import_event(struct obd_device *obd,
1151 struct obd_import *imp,
1152 enum obd_import_event event)
1154 struct obd_export *cobd_exp;
1157 cobd_exp = cobd_get_exp(obd);
1158 obd_import_event(class_exp2obd(cobd_exp), imp, event);
1162 static int cobd_md_getstatus(struct obd_export *exp,
1163 struct lustre_id *rootid)
1165 struct obd_device *obd = class_exp2obd(exp);
1166 struct obd_export *cobd_exp;
1171 CERROR("invalid client cookie "LPX64"\n",
1172 exp->exp_handle.h_cookie);
1175 cobd_exp = cobd_get_exp(obd);
1176 rc = md_getstatus(cobd_exp, rootid);
1180 static int cobd_md_getattr(struct obd_export *exp, struct lustre_id *id,
1181 __u64 valid, const char *xattr_name,
1182 const void *xattr_data, unsigned int xattr_datalen,
1183 unsigned int ea_size,
1184 struct ptlrpc_request **request)
1186 struct obd_device *obd = class_exp2obd(exp);
1187 struct obd_export *cobd_exp;
1192 CERROR("invalid client cookie "LPX64"\n",
1193 exp->exp_handle.h_cookie);
1196 cobd_exp = cobd_get_exp(obd);
1197 rc = md_getattr(cobd_exp, id, valid, xattr_name,
1198 xattr_data, xattr_datalen, ea_size, request);
1202 static int cobd_md_req2lustre_md(struct obd_export *mdc_exp,
1203 struct ptlrpc_request *req,
1204 unsigned int offset,
1205 struct obd_export *osc_exp,
1206 struct lustre_md *md)
1208 struct obd_device *obd = class_exp2obd(mdc_exp);
1209 struct obd_export *cobd_exp;
1214 CERROR("invalid client cookie "LPX64"\n",
1215 mdc_exp->exp_handle.h_cookie);
1218 cobd_exp = cobd_get_exp(obd);
1219 rc = md_req2lustre_md(cobd_exp, req, offset, osc_exp, md);
1223 static int cobd_md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1224 ldlm_iterator_t it, void *data)
1226 struct obd_device *obd = class_exp2obd(exp);
1227 struct obd_export *cobd_exp;
1232 CERROR("invalid client cookie "LPX64"\n",
1233 exp->exp_handle.h_cookie);
1236 cobd_exp = cobd_get_exp(obd);
1237 rc = md_change_cbdata(cobd_exp, id, it, data);
1241 static int cobd_md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1242 char *filename, int namelen, __u64 valid,
1243 unsigned int ea_size, struct ptlrpc_request **request)
1245 struct obd_device *obd = class_exp2obd(exp);
1246 struct obd_export *cobd_exp;
1251 CERROR("invalid client cookie "LPX64"\n",
1252 exp->exp_handle.h_cookie);
1255 cobd_exp = cobd_get_exp(obd);
1256 rc = md_getattr_lock(cobd_exp, id, filename, namelen,
1257 valid, ea_size, request);
1261 static int cobd_md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1262 const void *data, int datalen, int mode,
1263 __u32 uid, __u32 gid, __u64 rdev,
1264 struct ptlrpc_request **request)
1266 struct obd_device *obd = class_exp2obd(exp);
1267 struct obd_export *cobd_exp;
1272 CERROR("invalid client cookie "LPX64"\n",
1273 exp->exp_handle.h_cookie);
1276 cobd_exp = cobd_get_exp(obd);
1277 rc = md_create(cobd_exp, op_data, data, datalen, mode,
1278 uid, gid, rdev, request);
1282 static int cobd_md_unlink(struct obd_export *exp,
1283 struct mdc_op_data *data,
1284 struct ptlrpc_request **request)
1286 struct obd_device *obd = class_exp2obd(exp);
1287 struct obd_export *cobd_exp;
1292 CERROR("invalid client cookie "LPX64"\n",
1293 exp->exp_handle.h_cookie);
1296 cobd_exp = cobd_get_exp(obd);
1297 rc = md_unlink(cobd_exp, data, request);
1301 static int cobd_md_valid_attrs(struct obd_export *exp,
1302 struct lustre_id *id)
1304 struct obd_device *obd = class_exp2obd(exp);
1305 struct obd_export *cobd_exp;
1310 CERROR("invalid client cookie "LPX64"\n",
1311 exp->exp_handle.h_cookie);
1314 cobd_exp = cobd_get_exp(obd);
1315 rc = md_valid_attrs(cobd_exp, id);
1319 static int cobd_md_rename(struct obd_export *exp, struct mdc_op_data *data,
1320 const char *old, int oldlen, const char *new,
1321 int newlen, struct ptlrpc_request **request)
1323 struct obd_device *obd = class_exp2obd(exp);
1324 struct obd_export *cobd_exp;
1329 CERROR("invalid client cookie "LPX64"\n",
1330 exp->exp_handle.h_cookie);
1333 cobd_exp = cobd_get_exp(obd);
1334 rc = md_rename(cobd_exp, data, old, oldlen, new, newlen, request);
1338 static int cobd_md_link(struct obd_export *exp, struct mdc_op_data *data,
1339 struct ptlrpc_request **request)
1341 struct obd_device *obd = class_exp2obd(exp);
1342 struct obd_export *cobd_exp;
1347 CERROR("invalid client cookie "LPX64"\n",
1348 exp->exp_handle.h_cookie);
1351 cobd_exp = cobd_get_exp(obd);
1352 rc = md_link(cobd_exp, data, request);
1356 static int cobd_md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1357 struct iattr *iattr, void *ea, int ealen, void *ea2,
1358 int ea2len, void *ea3, int ea3len,
1359 struct ptlrpc_request **request)
1361 struct obd_device *obd = class_exp2obd(exp);
1362 struct obd_export *cobd_exp;
1367 CERROR("invalid client cookie "LPX64"\n",
1368 exp->exp_handle.h_cookie);
1371 cobd_exp = cobd_get_exp(obd);
1372 rc = md_setattr(cobd_exp, data, iattr, ea,
1373 ealen, ea2, ea2len, ea3, ea3len, request);
1377 static int cobd_md_readpage(struct obd_export *exp,
1378 struct lustre_id *mdc_id,
1379 __u64 offset, struct page *page,
1380 struct ptlrpc_request **request)
1382 struct obd_device *obd = class_exp2obd(exp);
1383 struct obd_export *cobd_exp;
1388 CERROR("invalid client cookie "LPX64"\n",
1389 exp->exp_handle.h_cookie);
1392 cobd_exp = cobd_get_exp(obd);
1393 rc = md_readpage(cobd_exp, mdc_id, offset, page, request);
1397 static int cobd_md_close(struct obd_export *exp, struct obdo *obdo,
1398 struct obd_client_handle *och,
1399 struct ptlrpc_request **request)
1401 struct obd_device *obd = class_exp2obd(exp);
1402 struct obd_export *cobd_exp;
1407 CERROR("invalid client cookie "LPX64"\n",
1408 exp->exp_handle.h_cookie);
1411 cobd_exp = cobd_get_exp(obd);
1412 rc = md_close(cobd_exp, obdo, och, request);
1416 static int cobd_md_done_writing(struct obd_export *exp,
1419 struct obd_device *obd = class_exp2obd(exp);
1420 struct obd_export *cobd_exp;
1425 CERROR("invalid client cookie "LPX64"\n",
1426 exp->exp_handle.h_cookie);
1429 cobd_exp = cobd_get_exp(obd);
1430 rc = md_done_writing(cobd_exp, obdo);
1434 static int cobd_md_sync(struct obd_export *exp, struct lustre_id *id,
1435 struct ptlrpc_request **request)
1437 struct obd_device *obd = class_exp2obd(exp);
1438 struct obd_export *cobd_exp;
1443 CERROR("invalid client cookie "LPX64"\n",
1444 exp->exp_handle.h_cookie);
1447 cobd_exp = cobd_get_exp(obd);
1448 rc = md_sync(cobd_exp, id, request);
1452 static int cobd_md_set_open_replay_data(struct obd_export *exp,
1453 struct obd_client_handle *och,
1454 struct ptlrpc_request *open_req)
1456 struct obd_device *obd = class_exp2obd(exp);
1457 struct obd_export *cobd_exp;
1462 CERROR("invalid client cookie "LPX64"\n",
1463 exp->exp_handle.h_cookie);
1466 cobd_exp = cobd_get_exp(obd);
1467 rc = md_set_open_replay_data(cobd_exp, och, open_req);
1471 static int cobd_md_clear_open_replay_data(struct obd_export *exp,
1472 struct obd_client_handle *och)
1474 struct obd_device *obd = class_exp2obd(exp);
1475 struct obd_export *cobd_exp;
1480 CERROR("invalid client cookie "LPX64"\n",
1481 exp->exp_handle.h_cookie);
1484 cobd_exp = cobd_get_exp(obd);
1485 rc = md_clear_open_replay_data(cobd_exp, och);
1489 static int cobd_md_store_inode_generation(struct obd_export *exp,
1490 struct ptlrpc_request *req,
1491 int reqoff, int repoff)
1493 struct obd_device *obd = class_exp2obd(exp);
1494 struct obd_export *cobd_exp;
1499 CERROR("invalid client cookie "LPX64"\n",
1500 exp->exp_handle.h_cookie);
1503 cobd_exp = cobd_get_exp(obd);
1504 rc = md_store_inode_generation(cobd_exp, req, reqoff, repoff);
1508 static int cobd_md_set_lock_data(struct obd_export *exp,
1509 __u64 *l, void *data)
1511 struct obd_device *obd = class_exp2obd(exp);
1512 struct obd_export *cobd_exp;
1517 CERROR("invalid client cookie "LPX64"\n",
1518 exp->exp_handle.h_cookie);
1521 cobd_exp = cobd_get_exp(obd);
1522 rc = md_set_lock_data(cobd_exp, l, data);
1526 static int cobd_md_enqueue(struct obd_export *exp, int lock_type,
1527 struct lookup_intent *it, int lock_mode,
1528 struct mdc_op_data *data, struct lustre_handle *lockh,
1529 void *lmm, int lmmsize,
1530 ldlm_completion_callback cb_completion,
1531 ldlm_blocking_callback cb_blocking, void *cb_data)
1533 struct obd_device *obd = class_exp2obd(exp);
1534 struct obd_export *cobd_exp;
1539 CERROR("invalid client cookie "LPX64"\n",
1540 exp->exp_handle.h_cookie);
1543 cobd_exp = cobd_get_exp(obd);
1544 rc = md_enqueue(cobd_exp, lock_type, it, lock_mode, data,
1545 lockh, lmm, lmmsize, cb_completion, cb_blocking,
1550 static int cobd_md_intent_lock(struct obd_export *exp, struct lustre_id *pid,
1551 const char *name, int len, void *lmm, int lmmsize,
1552 struct lustre_id *cid, struct lookup_intent *it,
1553 int lookup_flags, struct ptlrpc_request **reqp,
1554 ldlm_blocking_callback cb_blocking)
1556 struct obd_device *obd = class_exp2obd(exp);
1557 struct obd_export *cobd_exp;
1562 CERROR("invalid client cookie "LPX64"\n",
1563 exp->exp_handle.h_cookie);
1566 lookup_flags |= LOOKUP_COBD;
1567 cobd_exp = cobd_get_exp(obd);
1569 rc = md_intent_lock(cobd_exp, pid, name, len, lmm, lmmsize,
1570 cid, it, lookup_flags, reqp, cb_blocking);
1574 static struct obd_device *cobd_md_get_real_obd(struct obd_export *exp,
1575 struct lustre_id *id)
1577 struct obd_device *obd = class_exp2obd(exp);
1578 struct obd_export *cobd_exp;
1582 CERROR("invalid client cookie "LPX64"\n",
1583 exp->exp_handle.h_cookie);
1586 cobd_exp = cobd_get_exp(obd);
1587 RETURN(md_get_real_obd(cobd_exp, id));
1590 static int cobd_md_change_cbdata_name(struct obd_export *exp,
1591 struct lustre_id *id, char *name,
1592 int namelen, struct lustre_id *id2,
1593 ldlm_iterator_t it, void *data)
1595 struct obd_device *obd = class_exp2obd(exp);
1596 struct obd_export *cobd_exp;
1600 CERROR("invalid client cookie "LPX64"\n",
1601 exp->exp_handle.h_cookie);
1604 cobd_exp = cobd_get_exp(obd);
1605 rc = md_change_cbdata_name(cobd_exp, id, name, namelen,
1610 static struct obd_ops cobd_obd_ops = {
1611 .o_owner = THIS_MODULE,
1612 .o_attach = cobd_attach,
1613 .o_detach = cobd_detach,
1614 .o_setup = cobd_setup,
1615 .o_cleanup = cobd_cleanup,
1616 .o_connect = cobd_connect,
1617 .o_disconnect = cobd_disconnect,
1618 .o_set_info = cobd_set_info,
1619 .o_get_info = cobd_get_info,
1620 .o_statfs = cobd_statfs,
1621 .o_iocontrol = cobd_iocontrol,
1623 .o_packmd = cobd_dt_packmd,
1624 .o_unpackmd = cobd_dt_unpackmd,
1625 .o_create = cobd_dt_create,
1626 .o_destroy = cobd_dt_destroy,
1627 .o_precleanup = cobd_dt_precleanup,
1628 .o_getattr = cobd_dt_getattr,
1629 .o_getattr_async = cobd_dt_getattr_async,
1630 .o_setattr = cobd_dt_setattr,
1631 .o_brw = cobd_dt_brw,
1632 .o_brw_async = cobd_dt_brw_async,
1633 .o_prep_async_page = cobd_dt_prep_async_page,
1634 .o_queue_async_io = cobd_dt_queue_async_io,
1635 .o_set_async_flags = cobd_dt_set_async_flags,
1636 .o_queue_group_io = cobd_dt_queue_group_io,
1637 .o_trigger_group_io = cobd_dt_trigger_group_io,
1638 .o_teardown_async_page = cobd_dt_teardown_async_page,
1639 .o_preprw = cobd_dt_preprw,
1640 .o_punch = cobd_dt_punch,
1641 .o_sync = cobd_dt_sync,
1642 .o_enqueue = cobd_dt_enqueue,
1643 .o_match = cobd_dt_match,
1644 .o_change_cbdata = cobd_dt_change_cbdata,
1645 .o_cancel = cobd_dt_cancel,
1646 .o_cancel_unused = cobd_dt_cancel_unused,
1647 .o_commitrw = cobd_dt_commitrw,
1648 .o_llog_init = cobd_dt_llog_init,
1649 .o_llog_finish = cobd_dt_llog_finish,
1650 .o_notify = cobd_dt_notify,
1651 .o_pin = cobd_dt_pin,
1652 .o_unpin = cobd_dt_unpin,
1653 .o_import_event = cobd_dt_import_event,
1654 .o_init_ea_size = cobd_dt_init_ea_size,
1655 .o_adjust_kms = cobd_dt_adjust_kms,
1658 struct md_ops cobd_md_ops = {
1659 .m_getstatus = cobd_md_getstatus,
1660 .m_getattr = cobd_md_getattr,
1661 .m_req2lustre_md = cobd_md_req2lustre_md,
1662 .m_change_cbdata = cobd_md_change_cbdata,
1663 .m_getattr_lock = cobd_md_getattr_lock,
1664 .m_create = cobd_md_create,
1665 .m_unlink = cobd_md_unlink,
1666 .m_valid_attrs = cobd_md_valid_attrs,
1667 .m_rename = cobd_md_rename,
1668 .m_link = cobd_md_link,
1669 .m_setattr = cobd_md_setattr,
1670 .m_readpage = cobd_md_readpage,
1671 .m_close = cobd_md_close,
1672 .m_done_writing = cobd_md_done_writing,
1673 .m_sync = cobd_md_sync,
1674 .m_set_open_replay_data = cobd_md_set_open_replay_data,
1675 .m_clear_open_replay_data = cobd_md_clear_open_replay_data,
1676 .m_store_inode_generation = cobd_md_store_inode_generation,
1677 .m_set_lock_data = cobd_md_set_lock_data,
1678 .m_enqueue = cobd_md_enqueue,
1679 .m_get_real_obd = cobd_md_get_real_obd,
1680 .m_intent_lock = cobd_md_intent_lock,
1681 .m_change_cbdata_name = cobd_md_change_cbdata_name,
1684 static int __init cobd_init(void)
1686 struct lprocfs_static_vars lvars;
1689 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
1691 lprocfs_init_vars(cobd, &lvars);
1692 RETURN(class_register_type(&cobd_obd_ops, &cobd_md_ops,
1693 lvars.module_vars, OBD_CACHE_DEVICENAME));
1696 static void /*__exit*/ cobd_exit(void)
1698 class_unregister_type(OBD_CACHE_DEVICENAME);
1701 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1702 MODULE_DESCRIPTION("Lustre Caching OBD driver");
1703 MODULE_LICENSE("GPL");
1705 module_init(cobd_init);
1706 module_exit(cobd_exit);