Whamcloud - gitweb
Fix small typos in ost/osc
[fs/lustre-release.git] / lustre / mdc / mdc_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 #include <linux/module.h>
21
22 #include <linux/fs.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>
28
29 #include <linux/obd_support.h>
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_mds.h>
33
34 #define REQUEST_MINOR 244
35
36 extern int mds_queue_req(struct mds_request *);
37
38 struct mds_request *mds_prep_req(int size, int opcode)
39 {
40         struct mds_request *request;
41         int rc;
42         ENTRY; 
43
44         request = (struct mds_request *)kmalloc(sizeof(*request), GFP_KERNEL); 
45         if (!request) { 
46                 printk("mds_prep_req: request allocation out of memory\n");
47                 return NULL;
48         }
49
50         rc = mds_pack_req(NULL, 0, NULL, 0, 
51                           &request->rq_reqhdr, &request->rq_req, 
52                           &request->rq_reqlen, &request->rq_reqbuf);
53         if (rc) { 
54                 printk("llight request: cannot pack request %d\n", rc); 
55                 return NULL;
56         }
57         request->rq_reqhdr->opc = opcode;
58
59         EXIT;
60         return request;
61 }
62
63
64
65
66 static int mds_queue_wait(struct mds_request *req)
67 {
68         int rc;
69
70         /* XXX fix the race here (wait_for_event?)*/
71         /* hand the packet over to the server */
72         rc = mds_queue_req(req); 
73         if (rc) { 
74                 printk("osc_queue_wait: error %d, opcode %d\n", rc, 
75                        req->rq_reqhdr->opc); 
76                 return -rc;
77         }
78
79         init_waitqueue_head(&req->rq_wait_for_rep);
80         printk("-- sleeping\n");
81         interruptible_sleep_on(&req->rq_wait_for_rep);
82         printk("-- done\n");
83
84         mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr, 
85                        &req->rq_rep); 
86         printk("-->osc_queue_wait: buf %p len %d status %d\n", 
87                req->rq_repbuf, req->rq_replen, req->rq_rephdr->status); 
88
89         EXIT;
90         return req->rq_rephdr->status;
91 }
92
93 void mds_free_req(struct mds_request *request)
94 {
95         kfree(request);
96 }
97
98 int mdc_getattr(ino_t ino, struct  mds_rep  **rep)
99 {
100         struct mds_request *request;
101         int rc; 
102
103         request = mds_prep_req(sizeof(*request), MDS_GETATTR); 
104         if (!request) { 
105                 printk("llight request: cannot pack\n");
106                 return -ENOMEM;
107         }
108
109         request->rq_req->fid1.id = ino;
110
111         rc = mds_queue_wait(request);
112         if (rc) { 
113                 printk("llight request: error in handling %d\n", rc); 
114                 goto out;
115         }
116
117         printk("mds_getattr: mode: %o\n", request->rq_rep->mode); 
118
119         if (rep ) { 
120                 *rep = request->rq_rep;
121         }
122
123  out: 
124         mds_free_req(request);
125         return rc;
126 }
127
128 static int request_ioctl(struct inode *inode, struct file *file, 
129                        unsigned int cmd, unsigned long arg)
130 {
131         int err;
132
133         ENTRY;
134
135         if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
136                 EXIT;
137                 return -EINVAL;
138         }
139
140         if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE || 
141              _IOC_NR(cmd) < IOC_REQUEST_MIN_NR  || 
142              _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
143                 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
144                                 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
145                 EXIT;
146                 return -EINVAL;
147         }
148
149         
150         switch (cmd) {
151         case IOC_REQUEST_GETATTR: { 
152                 printk("-- getting attr for ino 2\n"); 
153                 err = mdc_getattr(2, NULL);
154                 printk("-- done err %d\n", err);
155                 break;
156         }
157         default:                
158                 err = -EINVAL;
159                 EXIT;
160                 break;
161         }
162         EXIT;
163         return err;
164 }
165
166
167 static struct file_operations requestdev_fops = {
168         ioctl: request_ioctl,
169 };
170
171
172 static struct miscdevice request_dev = {
173         REQUEST_MINOR,
174         "request",
175         &requestdev_fops
176 };
177
178
179 static int __init mds_request_init(void)
180 {
181         misc_register(&request_dev);
182         return 0 ;
183 }
184
185
186 static void __exit mds_request_exit(void)
187 {
188         misc_deregister(&request_dev);
189 }
190
191 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
192 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
193 MODULE_LICENSE("GPL");
194
195 EXPORT_SYMBOL(mdc_getattr); 
196
197
198 module_init(mds_request_init);
199 module_exit(mds_request_exit);