2 * Copryright (C) 2001 Cluster File Systems, Inc.
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/errno.h>
15 #include <linux/locks.h>
16 #include <linux/unistd.h>
18 #include <asm/system.h>
19 #include <asm/uaccess.h>
22 #include <linux/stat.h>
23 #include <asm/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <asm/segment.h>
26 #include <linux/miscdevice.h>
28 #include <linux/obd_support.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
33 extern int ost_queue_req(struct obd_device *, struct ost_request *);
35 struct ost_request *osc_prep_req(int size, int opcode)
37 struct ost_request *request;
41 request = (struct ost_request *)kmalloc(sizeof(*request), GFP_KERNEL);
43 printk("osc_prep_req: request allocation out of memory\n");
47 rc = ost_pack_req(NULL, 0, NULL, 0,
48 &request->rq_reqhdr, &request->rq_req,
49 &request->rq_reqlen, &request->rq_reqbuf);
51 printk("llight request: cannot pack request %d\n", rc);
54 request->rq_reqhdr->opc = opcode;
60 extern int osc_queue_wait(struct obd_conn *conn, struct ost_request *req)
62 struct obd_device *client = conn->oc_dev;
63 struct obd_device *target = client->u.osc.osc_tgt;
67 /* set the connection id */
68 req->rq_req->connid = conn->oc_id;
70 CDEBUG(D_INODE, "tgt at %p, conn id %d, opcode %d request at: %p\n",
71 &conn->oc_dev->u.osc.osc_tgt->u.ost,
72 conn->oc_id, req->rq_reqhdr->opc, req);
74 /* XXX fix the race here (wait_for_event?)*/
75 /* hand the packet over to the server */
76 rc = ost_queue_req(target, req);
78 printk("osc_queue_wait: error %d, opcode %d\n", rc,
83 /* wait for the reply */
84 init_waitqueue_head(&req->rq_wait_for_rep);
85 interruptible_sleep_on(&req->rq_wait_for_rep);
87 ost_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
89 printk("-->osc_queue_wait: buf %p len %d status %d\n",
90 req->rq_repbuf, req->rq_replen, req->rq_rephdr->status);
93 return req->rq_rephdr->status;
96 void osc_free_req(struct ost_request *request)
98 if (request->rq_repbuf)
99 kfree(request->rq_repbuf);
104 int osc_connect(struct obd_conn *conn)
106 struct ost_request *request;
110 request = osc_prep_req(sizeof(*request), OST_CONNECT);
112 printk("osc_connect: cannot pack req!\n");
116 rc = osc_queue_wait(conn, request);
122 CDEBUG(D_INODE, "received connid %d\n", request->rq_rep->connid);
124 conn->oc_id = request->rq_rep->connid;
126 osc_free_req(request);
131 int osc_disconnect(struct obd_conn *conn)
133 struct ost_request *request;
137 request = osc_prep_req(sizeof(*request), OST_DISCONNECT);
139 printk("osc_connect: cannot pack req!\n");
143 rc = osc_queue_wait(conn, request);
149 osc_free_req(request);
155 int osc_getattr(struct obd_conn *conn, struct obdo *oa)
157 struct ost_request *request;
160 request = osc_prep_req(sizeof(*request), OST_GETATTR);
162 printk("osc_connect: cannot pack req!\n");
166 memcpy(&request->rq_req->oa, oa, sizeof(*oa));
167 request->rq_req->oa.o_valid = ~0;
169 rc = osc_queue_wait(conn, request);
175 CDEBUG(D_INODE, "mode: %o\n", request->rq_rep->oa.o_mode);
177 memcpy(oa, &request->rq_rep->oa, sizeof(*oa));
181 osc_free_req(request);
185 int osc_create(struct obd_conn *conn, struct obdo *oa)
187 struct ost_request *request;
191 printk(__FUNCTION__ ": oa NULL\n");
193 request = osc_prep_req(sizeof(*request), OST_CREATE);
195 printk("osc_connect: cannot pack req!\n");
199 memcpy(&request->rq_req->oa, oa, sizeof(*oa));
200 request->rq_req->oa.o_valid = ~0;
202 rc = osc_queue_wait(conn, request);
207 memcpy(oa, &request->rq_rep->oa, sizeof(*oa));
210 osc_free_req(request);
215 /* mount the file system (secretly) */
216 static int osc_setup(struct obd_device *obddev, obd_count len,
220 struct obd_ioctl_data* data = buf;
221 struct osc_obd *osc = &obddev->u.osc;
224 if (data->ioc_dev < 0 || data->ioc_dev > MAX_OBD_DEVICES) {
229 osc->osc_tgt = &obd_dev[data->ioc_dev];
230 printk("OSC: tgt %d ost at %p\n", data->ioc_dev, &osc->osc_tgt->u.ost);
231 if ( ! (osc->osc_tgt->obd_flags & OBD_ATTACHED) ||
232 ! (osc->osc_tgt->obd_flags & OBD_SET_UP) ){
233 printk("device not attached or not set up (%d)\n",
245 static int osc_cleanup(struct obd_device * obddev)
249 if ( !(obddev->obd_flags & OBD_SET_UP) ) {
260 struct obd_ops osc_obd_ops = {
262 o_cleanup: osc_cleanup,
263 o_create: osc_create,
264 o_getattr: osc_getattr,
265 o_connect: osc_connect,
266 o_disconnect: osc_disconnect
269 static int __init osc_init(void)
271 obd_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
275 static void __exit osc_exit(void)
277 obd_unregister_type(LUSTRE_OSC_NAME);
280 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
281 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
282 MODULE_LICENSE("GPL");
284 module_init(osc_init);
285 module_exit(osc_exit);