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>
20 #include <linux/module.h>
23 #include <linux/stat.h>
24 #include <asm/uaccess.h>
25 #include <linux/vmalloc.h>
26 #include <asm/segment.h>
27 #include <linux/miscdevice.h>
29 #include <linux/obd_support.h>
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_mds.h>
34 #define REQUEST_MINOR 244
36 extern int mds_queue_req(struct mds_request *);
38 struct mds_request *mds_prep_req(int size, int opcode, int namelen, char *name, int tgtlen, char *tgt)
40 struct mds_request *request;
44 request = (struct mds_request *)kmalloc(sizeof(*request), GFP_KERNEL);
46 printk("mds_prep_req: request allocation out of memory\n");
50 rc = mds_pack_req(name, namelen, tgt, tgtlen,
51 &request->rq_reqhdr, &request->rq_req,
52 &request->rq_reqlen, &request->rq_reqbuf);
54 printk("llight request: cannot pack request %d\n", rc);
57 request->rq_reqhdr->opc = opcode;
66 static int mds_queue_wait(struct mds_request *req)
70 /* XXX fix the race here (wait_for_event?)*/
71 /* hand the packet over to the server */
72 rc = mds_queue_req(req);
74 printk("mdc_queue_wait: error %d, opcode %d\n", rc,
79 init_waitqueue_head(&req->rq_wait_for_rep);
80 printk("-- sleeping\n");
81 interruptible_sleep_on(&req->rq_wait_for_rep);
84 mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
86 printk("-->mdc_queue_wait: buf %p len %d status %d\n",
87 req->rq_repbuf, req->rq_replen, req->rq_rephdr->status);
90 return req->rq_rephdr->status;
93 void mds_free_req(struct mds_request *request)
98 int mdc_getattr(ino_t ino, int type, int valid,
99 struct mds_rep **rep, struct mds_rep_hdr **hdr)
101 struct mds_request *request;
104 request = mds_prep_req(sizeof(*request), MDS_GETATTR,
107 printk("llight request: cannot pack\n");
111 request->rq_req->fid1.id = ino;
112 request->rq_req->fid1.f_type = type;
113 request->rq_req->valid = valid;
115 rc = mds_queue_wait(request);
117 printk("llight request: error in handling %d\n", rc);
121 printk("mds_getattr: mode: %o\n", request->rq_rep->mode);
124 *rep = request->rq_rep;
127 *hdr = request->rq_rephdr;
131 mds_free_req(request);
135 int mdc_readpage(ino_t ino, int type, __u64 offset, char *addr,
136 struct mds_rep **rep, struct mds_rep_hdr **hdr)
138 struct mds_request *request;
139 struct niobuf niobuf;
142 niobuf.addr = (__u64) (long) addr;
144 printk("mdc_readpage: inode: %ld\n", ino);
146 request = mds_prep_req(sizeof(*request), MDS_READPAGE,
148 sizeof(struct niobuf), (char *)&niobuf);
150 printk("mdc request: cannot pack\n");
154 request->rq_req->fid1.id = ino;
155 request->rq_req->fid1.f_type = type;
156 request->rq_req->size = offset;
157 request->rq_req->tgtlen = sizeof(niobuf);
159 rc = mds_queue_wait(request);
161 printk("mdc request: error in handling %d\n", rc);
165 printk("mdc_readpage: mode: %o\n", request->rq_rep->mode);
168 *rep = request->rq_rep;
171 *hdr = request->rq_rephdr;
175 mds_free_req(request);
180 static int request_ioctl(struct inode *inode, struct file *file,
181 unsigned int cmd, unsigned long arg)
187 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
192 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
193 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
194 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
195 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
196 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
203 case IOC_REQUEST_GETATTR: {
204 struct mds_rep_hdr *hdr;
205 printk("-- getting attr for ino 2\n");
206 err = mdc_getattr(2, S_IFDIR, ~0, NULL, &hdr);
208 printk("-- done err %d\n", err);
212 case IOC_REQUEST_READPAGE: {
213 struct mds_rep_hdr *hdr;
215 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
220 printk("-- readpage 0 for ino 2\n");
221 err = mdc_readpage(2, S_IFDIR, 0, buf, NULL, &hdr);
222 printk("-- done err %d\n", err);
224 printk("-- status: %d\n", hdr->status);
241 static struct file_operations requestdev_fops = {
242 ioctl: request_ioctl,
246 static struct miscdevice request_dev = {
253 static int __init mds_request_init(void)
255 misc_register(&request_dev);
260 static void __exit mds_request_exit(void)
262 misc_deregister(&request_dev);
265 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
266 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
267 MODULE_LICENSE("GPL");
269 EXPORT_SYMBOL(mdc_getattr);
270 EXPORT_SYMBOL(mdc_readpage);
272 module_init(mds_request_init);
273 module_exit(mds_request_exit);