1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
10 #define DEBUG_SUBSYSTEM S_COBD
12 #include <linux/obd_support.h>
13 #include <linux/lustre_lib.h>
14 #include <linux/lustre_net.h>
15 #include <linux/lustre_idl.h>
16 #include <linux/obd_class.h>
17 #include <linux/obd_cache.h>
19 extern struct lprocfs_vars status_var_nm_1[];
20 extern struct lprocfs_vars status_class_var[];
23 cobd_attach (struct obd_device *dev, obd_count len, void *data)
25 return (lprocfs_reg_obd (dev, status_var_nm_1, dev));
29 cobd_detach (struct obd_device *dev)
31 return (lprocfs_dereg_obd (dev));
35 cobd_setup (struct obd_device *dev, obd_count len, void *buf)
37 struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
38 struct cache_obd *cobd = &dev->u.cobd;
39 struct obd_device *target;
40 struct obd_device *cache;
43 if (data->ioc_inlbuf1 == NULL ||
44 data->ioc_inlbuf2 == NULL)
47 target = class_uuid2obd (data->ioc_inlbuf1);
48 cache = class_uuid2obd (data->ioc_inlbuf2);
53 /* don't bother checking attached/setup;
54 * obd_connect() should, and it can change underneath us */
56 rc = obd_connect (&cobd->cobd_target, target, NULL, NULL, NULL);
60 rc = obd_connect (&cobd->cobd_cache, cache, NULL, NULL, NULL);
67 obd_disconnect (&cobd->cobd_target);
72 cobd_cleanup (struct obd_device *dev)
74 struct cache_obd *cobd = &dev->u.cobd;
77 if (!list_empty (&dev->obd_exports))
80 rc = obd_disconnect (&cobd->cobd_cache);
82 CERROR ("error %d disconnecting cache\n", rc);
84 rc = obd_disconnect (&cobd->cobd_target);
86 CERROR ("error %d disconnecting target\n", rc);
92 cobd_connect (struct lustre_handle *conn, struct obd_device *obd,
93 obd_uuid_t cluuid, struct recovd_obd *recovd,
94 ptlrpc_recovery_cb_t recover)
96 int rc = class_connect (conn, obd, cluuid);
98 CERROR ("rc %d\n", rc);
103 cobd_disconnect (struct lustre_handle *conn)
105 int rc = class_disconnect (conn);
107 CERROR ("rc %d\n", rc);
112 cobd_get_info(struct lustre_handle *conn, obd_count keylen,
113 void *key, obd_count *vallen, void **val)
115 struct obd_device *obd = class_conn2obd(conn);
116 struct cache_obd *cobd;
119 CERROR("invalid client "LPX64"\n", conn->addr);
125 /* intercept cache utilisation info? */
127 return (obd_get_info (&cobd->cobd_target,
128 keylen, key, vallen, val));
132 cobd_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
134 struct obd_device *obd = class_conn2obd(conn);
135 struct cache_obd *cobd;
138 CERROR("invalid client "LPX64"\n", conn->addr);
143 return (obd_statfs (&cobd->cobd_target, osfs));
147 cobd_getattr(struct lustre_handle *conn, struct obdo *oa,
148 struct lov_stripe_md *lsm)
150 struct obd_device *obd = class_conn2obd(conn);
151 struct cache_obd *cobd;
154 CERROR("invalid client "LPX64"\n", conn->addr);
159 return (obd_getattr (&cobd->cobd_target, oa, lsm));
163 cobd_open(struct lustre_handle *conn, struct obdo *oa,
164 struct lov_stripe_md *lsm)
166 struct obd_device *obd = class_conn2obd(conn);
167 struct cache_obd *cobd;
170 CERROR("invalid client "LPX64"\n", conn->addr);
175 return (obd_open (&cobd->cobd_target, oa, lsm));
179 cobd_close(struct lustre_handle *conn, struct obdo *oa,
180 struct lov_stripe_md *lsm)
182 struct obd_device *obd = class_conn2obd(conn);
183 struct cache_obd *cobd;
186 CERROR("invalid client "LPX64"\n", conn->addr);
191 return (obd_close (&cobd->cobd_target, oa, lsm));
195 cobd_preprw(int cmd, struct lustre_handle *conn,
196 int objcount, struct obd_ioobj *obj,
197 int niocount, struct niobuf_remote *nb,
198 struct niobuf_local *res, void **desc_private)
200 struct obd_device *obd = class_conn2obd(conn);
201 struct cache_obd *cobd;
204 CERROR("invalid client "LPX64"\n", conn->addr);
208 if ((cmd & OBD_BRW_WRITE) != 0)
212 return (obd_preprw (cmd, &cobd->cobd_target,
219 cobd_commitrw(int cmd, struct lustre_handle *conn,
220 int objcount, struct obd_ioobj *obj,
221 int niocount, struct niobuf_local *local,
224 struct obd_device *obd = class_conn2obd(conn);
225 struct cache_obd *cobd;
228 CERROR("invalid client "LPX64"\n", conn->addr);
232 if ((cmd & OBD_BRW_WRITE) != 0)
236 return (obd_commitrw (cmd, &cobd->cobd_target,
243 cobd_brw(int cmd, struct lustre_handle *conn,
244 struct lov_stripe_md *lsm, obd_count oa_bufs,
245 struct brw_page *pga, struct obd_brw_set *set)
247 struct obd_device *obd = class_conn2obd(conn);
248 struct cache_obd *cobd;
251 CERROR("invalid client "LPX64"\n", conn->addr);
255 if ((cmd & OBD_BRW_WRITE) != 0)
259 return (obd_brw (cmd, &cobd->cobd_target,
260 lsm, oa_bufs, pga, set));
264 cobd_iocontrol(unsigned int cmd, struct lustre_handle *conn, int len,
265 void *karg, void *uarg)
267 struct obd_device *obd = class_conn2obd(conn);
268 struct cache_obd *cobd;
271 CERROR("invalid client "LPX64"\n", conn->addr);
278 return (obd_iocontrol (cmd, &cobd->cobd_target, len, karg, uarg));
281 static struct obd_ops cobd_ops = {
282 o_owner: THIS_MODULE,
283 o_attach: cobd_attach,
284 o_detach: cobd_detach,
287 o_cleanup: cobd_cleanup,
289 o_connect: cobd_connect,
290 o_disconnect: cobd_disconnect,
292 o_get_info: cobd_get_info,
293 o_statfs: cobd_statfs,
295 o_getattr: cobd_getattr,
298 o_preprw: cobd_preprw,
299 o_commitrw: cobd_commitrw,
301 o_iocontrol: cobd_iocontrol,
309 printk (KERN_INFO "Lustre Caching OBD driver\n");
311 rc = class_register_type (&cobd_ops, status_class_var,
312 OBD_CACHE_DEVICENAME);
319 class_unregister_type (OBD_CACHE_DEVICENAME);
322 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
323 MODULE_DESCRIPTION("Lustre Caching OBD driver");
324 MODULE_LICENSE("GPL");
326 module_init(cobd_init);
327 module_exit(cobd_exit);