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/obd_class.h>
31 #include <linux/obd_cache.h>
33 static int cobd_setup (struct obd_device *obd, obd_count len, void *buf)
35 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
36 struct cache_obd *cobd = &obd->u.cobd;
37 struct obd_device *target;
38 struct obd_device *cache;
39 struct obd_uuid target_uuid;
40 struct obd_uuid cache_uuid;
41 struct lustre_handle target_conn = {0,}, cache_conn = {0,};
42 struct lprocfs_static_vars lvars;
45 if (lcfg->lcfg_inlbuf1 == NULL || lcfg->lcfg_inlbuf2 == NULL)
48 obd_str2uuid(&target_uuid, lcfg->lcfg_inlbuf1);
49 target = class_uuid2obd (&target_uuid);
51 obd_str2uuid(&cache_uuid, lcfg->lcfg_inlbuf2);
52 cache = class_uuid2obd (&cache_uuid);
57 /* don't bother checking attached/setup;
58 * obd_connect() should, and it can change underneath us */
59 rc = obd_connect(&target_conn, target, &target_uuid);
62 cobd->cobd_target_exp = class_conn2export(&target_conn);
64 rc = obd_connect(&cache_conn, cache, &cache_uuid);
66 obd_disconnect(cobd->cobd_target_exp, 0);
69 cobd->cobd_cache_exp = class_conn2export(&cache_conn);
71 lprocfs_init_vars(cobd, &lvars);
72 lprocfs_obd_setup(obd, lvars.obd_vars);
77 static int cobd_cleanup(struct obd_device *obd, int flags)
79 struct cache_obd *cobd = &obd->u.cobd;
82 if (!list_empty(&obd->obd_exports))
85 lprocfs_obd_cleanup(obd);
87 rc = obd_disconnect(cobd->cobd_cache_exp, flags);
89 CERROR("error %d disconnecting cache\n", rc);
91 rc = obd_disconnect(cobd->cobd_target_exp, flags);
93 CERROR("error %d disconnecting target\n", rc);
99 cobd_connect (struct lustre_handle *conn, struct obd_device *obd,
100 struct obd_uuid *cluuid)
102 int rc = class_connect (conn, obd, cluuid);
104 CERROR ("rc %d\n", rc);
108 static int cobd_disconnect(struct obd_export *exp, int flags)
110 int rc = class_disconnect(exp, flags);
112 CERROR ("rc %d\n", rc);
116 static int cobd_get_info(struct obd_export *exp, obd_count keylen,
117 void *key, __u32 *vallen, void *val)
119 struct obd_device *obd = class_exp2obd(exp);
120 struct cache_obd *cobd;
123 CERROR("invalid client cookie "LPX64"\n",
124 exp->exp_handle.h_cookie);
130 /* intercept cache utilisation info? */
132 return obd_get_info(cobd->cobd_target_exp, keylen, key, vallen, val);
135 static int cobd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
136 unsigned long max_age)
138 return obd_statfs(class_exp2obd(obd->u.cobd.cobd_target_exp), osfs,
142 static int cobd_getattr(struct obd_export *exp, struct obdo *oa,
143 struct lov_stripe_md *lsm)
145 struct obd_device *obd = class_exp2obd(exp);
146 struct cache_obd *cobd;
149 CERROR("invalid client cookie "LPX64"\n",
150 exp->exp_handle.h_cookie);
155 return obd_getattr(cobd->cobd_target_exp, oa, lsm);
158 static int cobd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
159 int objcount, struct obd_ioobj *obj,
160 int niocount, struct niobuf_remote *nb,
161 struct niobuf_local *res, struct obd_trans_info *oti)
163 struct obd_export *cobd_exp;
166 if (exp->exp_obd == NULL)
169 if ((cmd & OBD_BRW_WRITE) != 0)
172 cobd_exp = exp->exp_obd->u.cobd.cobd_target_exp;
173 rc = obd_preprw(cmd, cobd_exp, oa, objcount, obj, niocount, nb, res,
179 static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
180 int objcount, struct obd_ioobj *obj,
181 int niocount, struct niobuf_local *local,
182 struct obd_trans_info *oti, int rc)
184 struct obd_export *cobd_exp;
186 if (exp->exp_obd == NULL)
189 if ((cmd & OBD_BRW_WRITE) != 0)
192 cobd_exp = exp->exp_obd->u.cobd.cobd_target_exp;
193 rc = obd_commitrw(cmd, cobd_exp, oa, objcount, obj, niocount, local,
198 static int cobd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
199 struct lov_stripe_md *lsm, obd_count oa_bufs,
200 struct brw_page *pga, struct obd_trans_info *oti)
202 struct obd_device *obd = class_exp2obd(exp);
203 struct cache_obd *cobd;
206 CERROR("invalid client cookie "LPX64"\n",
207 exp->exp_handle.h_cookie);
211 if ((cmd & OBD_BRW_WRITE) != 0)
215 return obd_brw(cmd, cobd->cobd_target_exp, oa, lsm, oa_bufs, pga, oti);
218 static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
219 void *karg, void *uarg)
221 struct obd_device *obd = class_exp2obd(exp);
222 struct cache_obd *cobd;
225 CERROR("invalid client cookie "LPX64"\n",
226 exp->exp_handle.h_cookie);
233 return obd_iocontrol(cmd, cobd->cobd_target_exp, len, karg, uarg);
236 static struct obd_ops cobd_ops = {
237 o_owner: THIS_MODULE,
240 o_cleanup: cobd_cleanup,
242 o_connect: cobd_connect,
243 o_disconnect: cobd_disconnect,
245 o_get_info: cobd_get_info,
246 o_statfs: cobd_statfs,
248 o_getattr: cobd_getattr,
249 o_preprw: cobd_preprw,
250 o_commitrw: cobd_commitrw,
252 o_iocontrol: cobd_iocontrol,
255 static int __init cobd_init(void)
257 struct lprocfs_static_vars lvars;
260 printk(KERN_INFO "Lustre: Caching OBD driver; info@clusterfs.com\n");
262 lprocfs_init_vars(cobd, &lvars);
263 RETURN(class_register_type(&cobd_ops, lvars.module_vars,
264 OBD_CACHE_DEVICENAME));
267 static void /*__exit*/ cobd_exit(void)
269 class_unregister_type(OBD_CACHE_DEVICENAME);
272 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
273 MODULE_DESCRIPTION("Lustre Caching OBD driver");
274 MODULE_LICENSE("GPL");
276 module_init(cobd_init);
277 module_exit(cobd_exit);