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/obd_support.h>
25 #include <linux/lustre_lib.h>
26 #include <linux/lustre_net.h>
27 #include <linux/lustre_idl.h>
28 #include <linux/obd_class.h>
29 #include <linux/obd_cache.h>
31 static int cobd_attach(struct obd_device *dev, obd_count len, void *data)
33 struct lprocfs_static_vars lvars;
35 lprocfs_init_vars(&lvars);
36 return lprocfs_obd_attach(dev, lvars.obd_vars);
39 static int cobd_detach(struct obd_device *dev)
41 return lprocfs_obd_detach(dev);
45 cobd_setup (struct obd_device *dev, obd_count len, void *buf)
47 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
48 struct cache_obd *cobd = &dev->u.cobd;
49 struct obd_device *target;
50 struct obd_device *cache;
51 struct obd_uuid target_uuid;
52 struct obd_uuid cache_uuid;
55 if (data->ioc_inlbuf1 == NULL ||
56 data->ioc_inlbuf2 == NULL)
59 obd_str2uuid(&target_uuid, data->ioc_inlbuf1);
60 target = class_uuid2obd (&target_uuid);
62 obd_str2uuid(&cache_uuid, data->ioc_inlbuf2);
63 cache = class_uuid2obd (&cache_uuid);
68 /* don't bother checking attached/setup;
69 * obd_connect() should, and it can change underneath us */
70 rc = obd_connect (&cobd->cobd_target, target, &target_uuid, NULL, NULL);
74 rc = obd_connect (&cobd->cobd_cache, cache, &cache_uuid, NULL, NULL);
81 obd_disconnect (&cobd->cobd_target);
86 cobd_cleanup (struct obd_device *dev)
88 struct cache_obd *cobd = &dev->u.cobd;
91 if (!list_empty (&dev->obd_exports))
94 rc = obd_disconnect (&cobd->cobd_cache);
96 CERROR ("error %d disconnecting cache\n", rc);
98 rc = obd_disconnect (&cobd->cobd_target);
100 CERROR ("error %d disconnecting target\n", rc);
106 cobd_connect (struct lustre_handle *conn, struct obd_device *obd,
107 struct obd_uuid *cluuid, struct recovd_obd *recovd,
108 ptlrpc_recovery_cb_t recover)
110 int rc = class_connect (conn, obd, cluuid);
112 CERROR ("rc %d\n", rc);
117 cobd_disconnect (struct lustre_handle *conn)
119 int rc = class_disconnect (conn);
121 CERROR ("rc %d\n", rc);
126 cobd_get_info(struct lustre_handle *conn, obd_count keylen,
127 void *key, obd_count *vallen, void **val)
129 struct obd_device *obd = class_conn2obd(conn);
130 struct cache_obd *cobd;
133 CERROR("invalid client "LPX64"\n", conn->addr);
139 /* intercept cache utilisation info? */
141 return (obd_get_info (&cobd->cobd_target,
142 keylen, key, vallen, val));
146 cobd_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
148 struct obd_device *obd = class_conn2obd(conn);
149 struct cache_obd *cobd;
152 CERROR("invalid client "LPX64"\n", conn->addr);
157 return (obd_statfs (&cobd->cobd_target, osfs));
161 cobd_getattr(struct lustre_handle *conn, struct obdo *oa,
162 struct lov_stripe_md *lsm)
164 struct obd_device *obd = class_conn2obd(conn);
165 struct cache_obd *cobd;
168 CERROR("invalid client "LPX64"\n", conn->addr);
173 return (obd_getattr (&cobd->cobd_target, oa, lsm));
177 cobd_open(struct lustre_handle *conn, struct obdo *oa,
178 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
180 struct obd_device *obd = class_conn2obd(conn);
181 struct cache_obd *cobd;
184 CERROR("invalid client "LPX64"\n", conn->addr);
189 return (obd_open (&cobd->cobd_target, oa, lsm, oti));
193 cobd_close(struct lustre_handle *conn, struct obdo *oa,
194 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
196 struct obd_device *obd = class_conn2obd(conn);
197 struct cache_obd *cobd;
200 CERROR("invalid client "LPX64"\n", conn->addr);
205 return (obd_close (&cobd->cobd_target, oa, lsm, oti));
209 cobd_preprw(int cmd, struct lustre_handle *conn,
210 int objcount, struct obd_ioobj *obj,
211 int niocount, struct niobuf_remote *nb,
212 struct niobuf_local *res, void **desc_private,
213 struct obd_trans_info *oti)
215 struct obd_device *obd = class_conn2obd(conn);
216 struct cache_obd *cobd;
219 CERROR("invalid client "LPX64"\n", conn->addr);
223 if ((cmd & OBD_BRW_WRITE) != 0)
227 return (obd_preprw (cmd, &cobd->cobd_target,
230 res, desc_private, oti));
234 cobd_commitrw(int cmd, struct lustre_handle *conn,
235 int objcount, struct obd_ioobj *obj,
236 int niocount, struct niobuf_local *local,
237 void *desc_private, struct obd_trans_info *oti)
239 struct obd_device *obd = class_conn2obd(conn);
240 struct cache_obd *cobd;
243 CERROR("invalid client "LPX64"\n", conn->addr);
247 if ((cmd & OBD_BRW_WRITE) != 0)
251 return (obd_commitrw (cmd, &cobd->cobd_target,
258 cobd_brw(int cmd, struct lustre_handle *conn,
259 struct lov_stripe_md *lsm, obd_count oa_bufs,
260 struct brw_page *pga, struct obd_brw_set *set,
261 struct obd_trans_info *oti)
263 struct obd_device *obd = class_conn2obd(conn);
264 struct cache_obd *cobd;
267 CERROR("invalid client "LPX64"\n", conn->addr);
271 if ((cmd & OBD_BRW_WRITE) != 0)
275 return (obd_brw (cmd, &cobd->cobd_target,
276 lsm, oa_bufs, pga, set, oti));
280 cobd_iocontrol(unsigned int cmd, struct lustre_handle *conn, int len,
281 void *karg, void *uarg)
283 struct obd_device *obd = class_conn2obd(conn);
284 struct cache_obd *cobd;
287 CERROR("invalid client "LPX64"\n", conn->addr);
294 return (obd_iocontrol (cmd, &cobd->cobd_target, len, karg, uarg));
297 static struct obd_ops cobd_ops = {
298 o_owner: THIS_MODULE,
299 o_attach: cobd_attach,
300 o_detach: cobd_detach,
303 o_cleanup: cobd_cleanup,
305 o_connect: cobd_connect,
306 o_disconnect: cobd_disconnect,
308 o_get_info: cobd_get_info,
309 o_statfs: cobd_statfs,
311 o_getattr: cobd_getattr,
314 o_preprw: cobd_preprw,
315 o_commitrw: cobd_commitrw,
317 o_iocontrol: cobd_iocontrol,
320 static int __init cobd_init(void)
322 struct lprocfs_static_vars lvars;
325 printk(KERN_INFO "Lustre Caching OBD driver; info@clusterfs.com\n");
327 lprocfs_init_vars(&lvars);
328 RETURN(class_register_type(&cobd_ops, lvars.module_vars,
329 OBD_CACHE_DEVICENAME));
332 static void __exit cobd_exit(void)
334 class_unregister_type(OBD_CACHE_DEVICENAME);
337 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
338 MODULE_DESCRIPTION("Lustre Caching OBD driver");
339 MODULE_LICENSE("GPL");
341 module_init(cobd_init);
342 module_exit(cobd_exit);