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 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 printk("--> mds_prep_req: len %d, req %p, tgtlen %d\n",
58 request->rq_reqlen, request->rq_req,
59 request->rq_req->tgtlen);
60 request->rq_reqhdr->opc = opcode;
69 static int mds_queue_wait(struct mds_request *req)
73 /* XXX fix the race here (wait_for_event?)*/
74 /* hand the packet over to the server */
75 rc = mds_queue_req(req);
77 printk("mdc_queue_wait: error %d, opcode %d\n", rc,
82 init_waitqueue_head(&req->rq_wait_for_rep);
83 printk("-- sleeping\n");
84 interruptible_sleep_on(&req->rq_wait_for_rep);
87 mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
89 if ( req->rq_rephdr->status == 0 )
90 printk("-->mdc_queue_wait: buf %p len %d status %d\n",
91 req->rq_repbuf, req->rq_replen,
92 req->rq_rephdr->status);
95 return req->rq_rephdr->status;
98 void mds_free_req(struct mds_request *request)
103 int mdc_getattr(ino_t ino, int type, int valid,
104 struct mds_rep **rep, struct mds_rep_hdr **hdr)
106 struct mds_request *request;
109 request = mds_prep_req(MDS_GETATTR, 0, NULL, 0, NULL);
111 printk("llight request: cannot pack\n");
115 ll_ino2fid(&request->rq_req->fid1, ino, 0, type);
117 request->rq_req->valid = valid;
119 rc = mds_queue_wait(request);
121 printk("llight request: error in handling %d\n", rc);
125 printk("mds_getattr: mode: %o\n", request->rq_rep->mode);
128 *rep = request->rq_rep;
131 *hdr = request->rq_rephdr;
135 mds_free_req(request);
139 int mdc_readpage(ino_t ino, int type, __u64 offset, char *addr,
140 struct mds_rep **rep, struct mds_rep_hdr **hdr)
142 struct mds_request *request;
143 struct niobuf niobuf;
146 niobuf.addr = (__u64) (long) addr;
148 printk("mdc_readpage: inode: %ld\n", ino);
150 request = mds_prep_req(MDS_READPAGE, 0, NULL,
151 sizeof(struct niobuf), (char *)&niobuf);
153 printk("mdc request: cannot pack\n");
157 request->rq_req->fid1.id = ino;
158 request->rq_req->fid1.f_type = type;
159 request->rq_req->size = offset;
160 request->rq_req->tgtlen = sizeof(niobuf);
162 rc = mds_queue_wait(request);
164 printk("mdc request: error in handling %d\n", rc);
168 printk("mdc_readpage: mode: %o\n", request->rq_rep->mode);
171 *rep = request->rq_rep;
174 *hdr = request->rq_rephdr;
178 mds_free_req(request);
182 int mdc_reint(struct mds_request *request)
186 rc = mds_queue_wait(request);
188 printk("mdc request: error in handling %d\n", rc);
195 static int request_ioctl(struct inode *inode, struct file *file,
196 unsigned int cmd, unsigned long arg)
202 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
207 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
208 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
209 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
210 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
211 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
218 case IOC_REQUEST_GETATTR: {
219 struct mds_rep_hdr *hdr = NULL;
220 printk("-- getting attr for ino 2\n");
221 err = mdc_getattr(2, S_IFDIR, ~0, NULL, &hdr);
224 printk("-- done err %d\n", err);
228 case IOC_REQUEST_READPAGE: {
229 struct mds_rep_hdr *hdr = NULL;
231 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
236 printk("-- readpage 0 for ino 2\n");
237 err = mdc_readpage(2, S_IFDIR, 0, buf, NULL, &hdr);
238 printk("-- done err %d\n", err);
240 printk("-- status: %d\n", hdr->status);
249 case IOC_REQUEST_SETATTR: {
251 struct mds_rep_hdr *hdr;
255 iattr.ia_mode = 040777;
257 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
259 err = mdc_setattr(&inode, &iattr, NULL, &hdr);
260 printk("-- done err %d\n", err);
262 printk("-- status: %d\n", hdr->status);
279 static struct file_operations requestdev_fops = {
280 ioctl: request_ioctl,
284 static struct miscdevice request_dev = {
291 static int __init mds_request_init(void)
293 misc_register(&request_dev);
298 static void __exit mds_request_exit(void)
300 misc_deregister(&request_dev);
303 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
304 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
305 MODULE_LICENSE("GPL");
307 EXPORT_SYMBOL(mdc_getattr);
308 EXPORT_SYMBOL(mdc_readpage);
309 EXPORT_SYMBOL(mdc_setattr);
311 module_init(mds_request_init);
312 module_exit(mds_request_exit);