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 memset(request, 0, sizeof(*request));
54 request->rq_xid = mdc_xid++;
56 rc = mds_pack_req(name, namelen, tgt, tgtlen,
57 &request->rq_reqhdr, &(request->rq_req.mds),
58 &request->rq_reqlen, &request->rq_reqbuf);
60 printk("llight request: cannot pack request %d\n", rc);
63 printk("--> mds_prep_req: len %d, req %p, tgtlen %d\n",
64 request->rq_reqlen, request->rq_req.mds,
65 request->rq_req.mds->tgtlen);
66 request->rq_reqhdr->opc = opcode;
72 static int mds_queue_wait(struct ptlrpc_request *req, struct lustre_peer *peer)
76 /* XXX fix the race here (wait_for_event?)*/
79 printk("--->> %s %d\n", __FUNCTION__, __LINE__);
80 rc = mds_queue_req(req);
82 /* Remote delivery via portals. */
83 req->rq_req_portal = MDS_REQUEST_PORTAL;
84 req->rq_reply_portal = MDS_REPLY_PORTAL;
85 rc = ptl_send_rpc(req, peer);
88 printk(__FUNCTION__ ": error %d, opcode %d\n", rc,
93 init_waitqueue_head(&req->rq_wait_for_rep);
94 printk("-- sleeping\n");
95 interruptible_sleep_on(&req->rq_wait_for_rep);
98 rc = mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
101 printk(__FUNCTION__ ": mds_unpack_rep failed: %d\n", rc);
105 if ( req->rq_rephdr->status == 0 )
106 printk("-->mdc_queue_wait: buf %p len %d status %d\n",
107 req->rq_repbuf, req->rq_replen,
108 req->rq_rephdr->status);
114 void mdc_free_req(struct ptlrpc_request *request)
119 int mdc_getattr(struct lustre_peer *peer, ino_t ino, int type, int valid,
120 struct mds_rep **rep, struct ptlrep_hdr **hdr)
122 struct ptlrpc_request *request;
125 request = mds_prep_req(MDS_GETATTR, 0, NULL, 0, NULL);
127 printk("llight request: cannot pack\n");
131 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
133 request->rq_req.mds->valid = valid;
135 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
137 rc = mds_queue_wait(request, peer);
139 printk("llight request: error in handling %d\n", rc);
143 printk("mds_getattr: mode: %o\n", request->rq_rep.mds->mode);
146 *rep = request->rq_rep.mds;
149 *hdr = request->rq_rephdr;
153 mdc_free_req(request);
157 int mdc_readpage(struct lustre_peer *peer, ino_t ino, int type, __u64 offset,
158 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
160 struct ptlrpc_request *request;
161 struct niobuf niobuf;
164 niobuf.addr = (__u64) (long) addr;
166 printk("mdc_readpage: inode: %ld\n", ino);
168 request = mds_prep_req(MDS_READPAGE, 0, NULL,
169 sizeof(struct niobuf), (char *)&niobuf);
171 printk("mdc request: cannot pack\n");
175 request->rq_req.mds->fid1.id = ino;
176 request->rq_req.mds->fid1.f_type = type;
177 request->rq_req.mds->size = offset;
178 request->rq_req.mds->tgtlen = sizeof(niobuf);
180 request->rq_bulk_portal = MDS_BULK_PORTAL;
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 mdc_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,
307 "foofile", strlen("foofile"),
308 NULL, 0, 0100707, 47114711,
309 11, 47, 0, NULL, &hdr);
310 printk("-- done err %d\n", err);
312 printk("-- status: %d\n", hdr->status);
329 static struct file_operations requestdev_fops = {
330 ioctl: request_ioctl,
334 static struct miscdevice request_dev = {
341 static int __init ptlrpc_request_init(void)
343 misc_register(&request_dev);
348 static void __exit ptlrpc_request_exit(void)
350 misc_deregister(&request_dev);
353 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
354 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
355 MODULE_LICENSE("GPL");
357 EXPORT_SYMBOL(mdc_create);
358 EXPORT_SYMBOL(mdc_unlink);
359 EXPORT_SYMBOL(mdc_rename);
360 EXPORT_SYMBOL(mdc_link);
361 EXPORT_SYMBOL(mdc_getattr);
362 EXPORT_SYMBOL(mdc_readpage);
363 EXPORT_SYMBOL(mdc_setattr);
365 module_init(ptlrpc_request_init);
366 module_exit(ptlrpc_request_exit);