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 /* FIXME: this belongs in some sort of service struct */
39 static int mdc_xid = 0;
41 struct ptlrpc_request *mds_prep_req(int opcode, int namelen, char *name, int tgtlen, char *tgt)
43 struct ptlrpc_request *request;
47 request = (struct ptlrpc_request *)kmalloc(sizeof(*request), GFP_KERNEL);
49 printk("mds_prep_req: request allocation out of memory\n");
53 request->rq_xid = mdc_xid++;
55 rc = mds_pack_req(name, namelen, tgt, tgtlen,
56 &request->rq_reqhdr, &(request->rq_req.mds),
57 &request->rq_reqlen, &request->rq_reqbuf);
59 printk("llight request: cannot pack request %d\n", rc);
62 printk("--> mds_prep_req: len %d, req %p, tgtlen %d\n",
63 request->rq_reqlen, request->rq_req.mds,
64 request->rq_req.mds->tgtlen);
65 request->rq_reqhdr->opc = opcode;
74 static int mds_queue_wait(struct ptlrpc_request *req, struct lustre_peer *peer)
78 /* XXX fix the race here (wait_for_event?)*/
81 rc = mds_queue_req(req);
83 /* Remote delivery via portals. */
84 req->rq_req_portal = MDS_REQUEST_PORTAL;
85 req->rq_reply_portal = MDS_REPLY_PORTAL;
86 rc = ptl_send_rpc(req, peer);
89 printk(__FUNCTION__ ": error %d, opcode %d\n", rc,
94 init_waitqueue_head(&req->rq_wait_for_rep);
95 printk("-- sleeping\n");
96 interruptible_sleep_on(&req->rq_wait_for_rep);
99 rc = mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
102 printk(__FUNCTION__ ": mds_unpack_rep failed: %d\n", rc);
106 if ( req->rq_rephdr->status == 0 )
107 printk("-->mdc_queue_wait: buf %p len %d status %d\n",
108 req->rq_repbuf, req->rq_replen,
109 req->rq_rephdr->status);
115 void mds_free_req(struct ptlrpc_request *request)
120 int mdc_getattr(struct lustre_peer *peer, ino_t ino, int type, int valid,
121 struct mds_rep **rep, struct ptlrep_hdr **hdr)
123 struct ptlrpc_request *request;
126 request = mds_prep_req(MDS_GETATTR, 0, NULL, 0, NULL);
128 printk("llight request: cannot pack\n");
132 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
134 request->rq_req.mds->valid = valid;
136 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
138 rc = mds_queue_wait(request, peer);
140 printk("llight request: error in handling %d\n", rc);
144 printk("mds_getattr: mode: %o\n", request->rq_rep.mds->mode);
147 *rep = request->rq_rep.mds;
150 *hdr = request->rq_rephdr;
154 mds_free_req(request);
158 int mdc_readpage(struct lustre_peer *peer, ino_t ino, int type, __u64 offset,
159 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
161 struct ptlrpc_request *request;
162 struct niobuf niobuf;
165 niobuf.addr = (__u64) (long) addr;
167 printk("mdc_readpage: inode: %ld\n", ino);
169 request = mds_prep_req(MDS_READPAGE, 0, NULL,
170 sizeof(struct niobuf), (char *)&niobuf);
172 printk("mdc request: cannot pack\n");
176 request->rq_req.mds->fid1.id = ino;
177 request->rq_req.mds->fid1.f_type = type;
178 request->rq_req.mds->size = offset;
179 request->rq_req.mds->tgtlen = sizeof(niobuf);
182 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
184 rc = mds_queue_wait(request, peer);
186 printk("mdc request: error in handling %d\n", rc);
190 printk("mdc_readpage: mode: %o\n", request->rq_rep.mds->mode);
193 *rep = request->rq_rep.mds;
196 *hdr = request->rq_rephdr;
200 mds_free_req(request);
204 int mdc_reint(struct lustre_peer *peer, struct ptlrpc_request *request)
208 rc = mds_queue_wait(request, peer);
210 printk("mdc request: error in handling %d\n", rc);
217 static int request_ioctl(struct inode *inode, struct file *file,
218 unsigned int cmd, unsigned long arg)
221 struct lustre_peer peer, *peer_ptr = NULL;
225 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
230 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
231 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
232 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
233 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
234 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
239 err = kportal_uuid_to_peer("mds", &peer);
244 case IOC_REQUEST_GETATTR: {
245 struct ptlrep_hdr *hdr = NULL;
246 printk("-- getting attr for ino 2\n");
247 err = mdc_getattr(peer_ptr, 2, S_IFDIR, ~0, NULL, &hdr);
250 printk("-- done err %d\n", err);
254 case IOC_REQUEST_READPAGE: {
255 struct ptlrep_hdr *hdr = NULL;
257 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
262 printk("-- readpage 0 for ino 2\n");
263 err = mdc_readpage(peer_ptr, 2, S_IFDIR, 0, buf, NULL, &hdr);
264 printk("-- done err %d\n", err);
266 printk("-- status: %d\n", hdr->status);
275 case IOC_REQUEST_SETATTR: {
277 struct ptlrep_hdr *hdr;
281 iattr.ia_mode = 040777;
283 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
285 err = mdc_setattr(peer_ptr, &inode, &iattr, NULL, &hdr);
286 printk("-- done err %d\n", err);
288 printk("-- status: %d\n", hdr->status);
296 case IOC_REQUEST_CREATE: {
298 struct ptlrep_hdr *hdr;
302 iattr.ia_mode = 040777;
304 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
306 err = mdc_create(peer_ptr, &inode, "foofile",
307 strlen("foofile"), 0100707, 47114711,
308 11, 47, 0, NULL, &hdr);
309 printk("-- done err %d\n", err);
311 printk("-- status: %d\n", hdr->status);
328 static struct file_operations requestdev_fops = {
329 ioctl: request_ioctl,
333 static struct miscdevice request_dev = {
340 static int __init ptlrpc_request_init(void)
342 misc_register(&request_dev);
347 static void __exit ptlrpc_request_exit(void)
349 misc_deregister(&request_dev);
352 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
353 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
354 MODULE_LICENSE("GPL");
356 EXPORT_SYMBOL(mdc_create);
357 EXPORT_SYMBOL(mdc_getattr);
358 EXPORT_SYMBOL(mdc_readpage);
359 EXPORT_SYMBOL(mdc_setattr);
361 module_init(ptlrpc_request_init);
362 module_exit(ptlrpc_request_exit);