Whamcloud - gitweb
Fix small typos in ost/osc
[fs/lustre-release.git] / lustre / llite / request.c
1 /*
2  * Copryright (C) 2001 Cluster File Systems, Inc.
3  *
4  */
5
6 #define EXPORT_SYMTAB
7
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.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>
17
18 #include <asm/system.h>
19 #include <asm/uaccess.h>
20
21 #include <linux/fs.h>
22 #include <linux/stat.h>
23 #include <asm/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <asm/segment.h>
26 #include <linux/miscdevice.h>
27
28 #include <linux/obd_support.h>
29 #include <linux/lustre_lib.h>
30 #include <linux/lustre_idl.h>
31 #include <linux/lustre_mds.h>
32
33 #define REQUEST_MINOR 244
34 extern int mds_queue_req(struct mds_request *);
35
36 static int mds_send_req(struct mds_request *req)
37 {
38         int rc;
39         init_waitqueue_head(&req->rq_wait_for_rep);
40         /* XXX replace the following with networking code */ 
41         rc = mds_queue_req(req); 
42         if (rc) { 
43                 EXIT;
44                 return rc;
45         }
46
47         printk("-- sleeping\n");
48         interruptible_sleep_on(&req->rq_wait_for_rep);
49         printk("-- done\n");
50         return 0;
51 }
52
53 int llight_getattr(ino_t ino, struct  mds_rep  *rep)
54 {
55         struct mds_request *request;
56         int rc; 
57
58         request = (struct mds_request *)kmalloc(sizeof(*request), 
59                                                 GFP_KERNEL); 
60         if (!request) { 
61                 printk("llight request: out of memory\n");
62                 return -ENOMEM;
63         }
64
65         rc = mds_pack_req(NULL, 0, NULL, 0, 
66                           &request->rq_reqhdr, &request->rq_req, 
67                           &request->rq_reqlen, &request->rq_reqbuf);
68         if (rc) { 
69                 printk("llight request: cannot pack request %d\n", rc); 
70                 return rc;
71         }
72         request->rq_req->fid1.id = ino;
73
74         request->rq_reqhdr->opc = MDS_GETATTR;
75         
76         rc = mds_send_req(request);
77         if (rc) { 
78                 printk("llight request: error in handling %d\n", rc); 
79                 return rc;
80         }
81
82         printk("mode: %o\n", request->rq_rep->mode); 
83         if (rep) { 
84                 memcpy(rep, request->rq_repbuf, sizeof(*rep));
85         }
86         kfree(request->rq_repbuf);
87         kfree(request);
88         return 0;
89 }
90
91
92 static int request_ioctl(struct inode *inode, struct file *file, 
93                        unsigned int cmd, unsigned long arg)
94 {
95         int err;
96
97         ENTRY;
98
99         if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
100                 EXIT;
101                 return -EINVAL;
102         }
103
104         if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE || 
105              _IOC_NR(cmd) < IOC_REQUEST_MIN_NR  || 
106              _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
107                 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
108                                 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
109                 EXIT;
110                 return -EINVAL;
111         }
112
113         
114         switch (cmd) {
115         case IOC_REQUEST_GETATTR: { 
116                 printk("-- getting attr for ino 2\n"); 
117                 err = llight_getattr(2, NULL);
118                 printk("-- done err %d\n", err);
119                 break;
120         }
121         default:                
122                 err = -EINVAL;
123                 EXIT;
124                 break;
125         }
126         EXIT;
127         return err;
128 }
129
130
131 static struct file_operations requestdev_fops = {
132         ioctl: request_ioctl,
133 };
134
135
136 static struct miscdevice request_dev = {
137         REQUEST_MINOR,
138         "request",
139         &requestdev_fops
140 };
141
142
143 int init_request_module(void)
144 {
145         misc_register( &request_dev );
146         return 0 ;
147 }
148
149 #ifdef MODULE
150 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
151 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
152
153 #include <linux/module.h>
154
155 int init_module(void)
156 {
157         return init_request_module();
158 }
159
160 void cleanup_module(void)
161 {
162         misc_deregister(&request_dev);
163         return;
164 }
165
166 #endif