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 ptlrpc_request *);
38 struct ptlrpc_request *mds_prep_req(int opcode, int namelen, char *name, int tgtlen, char *tgt)
40 struct ptlrpc_request *request;
44 request = (struct ptlrpc_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.mds),
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.mds,
59 request->rq_req.mds->tgtlen);
60 request->rq_reqhdr->opc = opcode;
69 static int mds_queue_wait(struct ptlrpc_request *req, struct lustre_peer *peer)
73 /* XXX fix the race here (wait_for_event?)*/
74 /* hand the packet over to the server */
75 rc = ptl_send_rpc(req, peer);
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 ptlrpc_request *request)
103 int mdc_getattr(struct lustre_peer *peer, ino_t ino, int type, int valid,
104 struct mds_rep **rep, struct ptlrep_hdr **hdr)
106 struct ptlrpc_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.mds->fid1, ino, 0, type);
117 request->rq_req.mds->valid = valid;
119 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
121 rc = mds_queue_wait(request, peer);
123 printk("llight request: error in handling %d\n", rc);
127 printk("mds_getattr: mode: %o\n", request->rq_rep.mds->mode);
130 *rep = request->rq_rep.mds;
133 *hdr = request->rq_rephdr;
137 mds_free_req(request);
141 int mdc_readpage(struct lustre_peer *peer, ino_t ino, int type, __u64 offset,
142 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
144 struct ptlrpc_request *request;
145 struct niobuf niobuf;
148 niobuf.addr = (__u64) (long) addr;
150 printk("mdc_readpage: inode: %ld\n", ino);
152 request = mds_prep_req(MDS_READPAGE, 0, NULL,
153 sizeof(struct niobuf), (char *)&niobuf);
155 printk("mdc request: cannot pack\n");
159 request->rq_req.mds->fid1.id = ino;
160 request->rq_req.mds->fid1.f_type = type;
161 request->rq_req.mds->size = offset;
162 request->rq_req.mds->tgtlen = sizeof(niobuf);
164 rc = mds_queue_wait(request, peer);
166 printk("mdc request: error in handling %d\n", rc);
170 printk("mdc_readpage: mode: %o\n", request->rq_rep.mds->mode);
173 *rep = request->rq_rep.mds;
176 *hdr = request->rq_rephdr;
180 mds_free_req(request);
184 int mdc_reint(struct lustre_peer *peer, struct ptlrpc_request *request)
188 rc = mds_queue_wait(request, peer);
190 printk("mdc request: error in handling %d\n", rc);
197 static int request_ioctl(struct inode *inode, struct file *file,
198 unsigned int cmd, unsigned long arg)
201 struct lustre_peer peer;
205 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
210 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
211 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
212 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
213 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
214 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
219 //rc = ptl_peer("mds", peer);
222 case IOC_REQUEST_GETATTR: {
223 struct ptlrep_hdr *hdr = NULL;
224 printk("-- getting attr for ino 2\n");
225 err = mdc_getattr(&peer, 2, S_IFDIR, ~0, NULL, &hdr);
228 printk("-- done err %d\n", err);
232 case IOC_REQUEST_READPAGE: {
233 struct ptlrep_hdr *hdr = NULL;
235 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
240 printk("-- readpage 0 for ino 2\n");
241 err = mdc_readpage(&peer, 2, S_IFDIR, 0, buf, NULL, &hdr);
242 printk("-- done err %d\n", err);
244 printk("-- status: %d\n", hdr->status);
253 case IOC_REQUEST_SETATTR: {
255 struct ptlrep_hdr *hdr;
259 iattr.ia_mode = 040777;
261 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
263 err = mdc_setattr(&peer, &inode, &iattr, NULL, &hdr);
264 printk("-- done err %d\n", err);
266 printk("-- status: %d\n", hdr->status);
273 case IOC_REQUEST_CREATE: {
275 struct ptlrep_hdr *hdr;
279 iattr.ia_mode = 040777;
281 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
283 err = mdc_create(&peer, &inode, "foofile", strlen("foofile"),
285 11, 47, 0, NULL, &hdr);
286 printk("-- done err %d\n", err);
288 printk("-- status: %d\n", hdr->status);
305 static struct file_operations requestdev_fops = {
306 ioctl: request_ioctl,
310 static struct miscdevice request_dev = {
317 static int __init ptlrpc_request_init(void)
319 misc_register(&request_dev);
324 static void __exit ptlrpc_request_exit(void)
326 misc_deregister(&request_dev);
329 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
330 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
331 MODULE_LICENSE("GPL");
333 EXPORT_SYMBOL(mdc_create);
334 EXPORT_SYMBOL(mdc_getattr);
335 EXPORT_SYMBOL(mdc_readpage);
336 EXPORT_SYMBOL(mdc_setattr);
338 module_init(ptlrpc_request_init);
339 module_exit(ptlrpc_request_exit);