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;
75 static int mds_queue_wait(struct ptlrpc_request *req, struct lustre_peer *peer)
79 /* XXX fix the race here (wait_for_event?)*/
82 printk("--->> %s %d\n", __FUNCTION__, __LINE__);
83 rc = mds_queue_req(req);
85 /* Remote delivery via portals. */
86 req->rq_req_portal = MDS_REQUEST_PORTAL;
87 req->rq_reply_portal = MDS_REPLY_PORTAL;
88 rc = ptl_send_rpc(req, peer);
91 printk(__FUNCTION__ ": error %d, opcode %d\n", rc,
96 init_waitqueue_head(&req->rq_wait_for_rep);
97 printk("-- sleeping\n");
98 interruptible_sleep_on(&req->rq_wait_for_rep);
101 rc = mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
104 printk(__FUNCTION__ ": mds_unpack_rep failed: %d\n", rc);
108 if ( req->rq_rephdr->status == 0 )
109 printk("-->mdc_queue_wait: buf %p len %d status %d\n",
110 req->rq_repbuf, req->rq_replen,
111 req->rq_rephdr->status);
117 void mds_free_req(struct ptlrpc_request *request)
122 int mdc_getattr(struct lustre_peer *peer, ino_t ino, int type, int valid,
123 struct mds_rep **rep, struct ptlrep_hdr **hdr)
125 struct ptlrpc_request *request;
128 request = mds_prep_req(MDS_GETATTR, 0, NULL, 0, NULL);
130 printk("llight request: cannot pack\n");
134 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
136 request->rq_req.mds->valid = valid;
138 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
140 rc = mds_queue_wait(request, peer);
142 printk("llight request: error in handling %d\n", rc);
146 printk("mds_getattr: mode: %o\n", request->rq_rep.mds->mode);
149 *rep = request->rq_rep.mds;
152 *hdr = request->rq_rephdr;
156 mds_free_req(request);
160 int mdc_readpage(struct lustre_peer *peer, ino_t ino, int type, __u64 offset,
161 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
163 struct ptlrpc_request *request;
164 struct niobuf niobuf;
167 niobuf.addr = (__u64) (long) addr;
169 printk("mdc_readpage: inode: %ld\n", ino);
171 request = mds_prep_req(MDS_READPAGE, 0, NULL,
172 sizeof(struct niobuf), (char *)&niobuf);
174 printk("mdc request: cannot pack\n");
178 request->rq_req.mds->fid1.id = ino;
179 request->rq_req.mds->fid1.f_type = type;
180 request->rq_req.mds->size = offset;
181 request->rq_req.mds->tgtlen = sizeof(niobuf);
183 request->rq_bulk_portal = MDS_BULK_PORTAL;
185 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
187 rc = mds_queue_wait(request, peer);
189 printk("mdc request: error in handling %d\n", rc);
193 printk("mdc_readpage: mode: %o\n", request->rq_rep.mds->mode);
196 *rep = request->rq_rep.mds;
199 *hdr = request->rq_rephdr;
203 mds_free_req(request);
207 int mdc_reint(struct lustre_peer *peer, struct ptlrpc_request *request)
211 rc = mds_queue_wait(request, peer);
213 printk("mdc request: error in handling %d\n", rc);
220 static int request_ioctl(struct inode *inode, struct file *file,
221 unsigned int cmd, unsigned long arg)
224 struct lustre_peer peer, *peer_ptr = NULL;
228 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
233 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
234 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
235 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
236 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
237 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
242 err = kportal_uuid_to_peer("mds", &peer);
247 case IOC_REQUEST_GETATTR: {
248 struct ptlrep_hdr *hdr = NULL;
249 printk("-- getting attr for ino 2\n");
250 err = mdc_getattr(peer_ptr, 2, S_IFDIR, ~0, NULL, &hdr);
253 printk("-- done err %d\n", err);
257 case IOC_REQUEST_READPAGE: {
258 struct ptlrep_hdr *hdr = NULL;
260 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
265 printk("-- readpage 0 for ino 2\n");
266 err = mdc_readpage(peer_ptr, 2, S_IFDIR, 0, buf, NULL, &hdr);
267 printk("-- done err %d\n", err);
269 printk("-- status: %d\n", hdr->status);
278 case IOC_REQUEST_SETATTR: {
280 struct ptlrep_hdr *hdr;
284 iattr.ia_mode = 040777;
286 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
288 err = mdc_setattr(peer_ptr, &inode, &iattr, NULL, &hdr);
289 printk("-- done err %d\n", err);
291 printk("-- status: %d\n", hdr->status);
299 case IOC_REQUEST_CREATE: {
301 struct ptlrep_hdr *hdr;
305 iattr.ia_mode = 040777;
307 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
309 err = mdc_create(peer_ptr, &inode, "foofile",
310 strlen("foofile"), 0100707, 47114711,
311 11, 47, 0, NULL, &hdr);
312 printk("-- done err %d\n", err);
314 printk("-- status: %d\n", hdr->status);
331 static struct file_operations requestdev_fops = {
332 ioctl: request_ioctl,
336 static struct miscdevice request_dev = {
343 static int __init ptlrpc_request_init(void)
345 misc_register(&request_dev);
350 static void __exit ptlrpc_request_exit(void)
352 misc_deregister(&request_dev);
355 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
356 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
357 MODULE_LICENSE("GPL");
359 EXPORT_SYMBOL(mdc_create);
360 EXPORT_SYMBOL(mdc_getattr);
361 EXPORT_SYMBOL(mdc_readpage);
362 EXPORT_SYMBOL(mdc_setattr);
364 module_init(ptlrpc_request_init);
365 module_exit(ptlrpc_request_exit);