Whamcloud - gitweb
Small fixes to the request processing.
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
similarity index 62%
rename from lustre/llite/request.c
rename to lustre/mdc/mdc_request.c
index baf102e..37feabd 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <linux/module.h>
 
 #include <linux/fs.h>
 #include <linux/stat.h>
 #include <linux/lustre_mds.h>
 
 #define REQUEST_MINOR 244
+
 extern int mds_queue_req(struct mds_request *);
 
-static int mds_send_req(struct mds_request *req)
+struct mds_request *mds_prep_req(int size, int opcode)
 {
+       struct mds_request *request;
        int rc;
-       init_waitqueue_head(&req->rq_wait_for_rep);
-       /* XXX replace the following with networking code */ 
+       ENTRY; 
+
+       request = (struct mds_request *)kmalloc(sizeof(*request), GFP_KERNEL); 
+       if (!request) { 
+               printk("mds_prep_req: request allocation out of memory\n");
+               return NULL;
+       }
+
+       rc = mds_pack_req(NULL, 0, NULL, 0, 
+                         &request->rq_reqhdr, &request->rq_req, 
+                         &request->rq_reqlen, &request->rq_reqbuf);
+       if (rc) { 
+               printk("llight request: cannot pack request %d\n", rc); 
+               return NULL;
+       }
+       request->rq_reqhdr->opc = opcode;
+
+       EXIT;
+       return request;
+}
+
+
+
+
+static int mds_queue_wait(struct mds_request *req)
+{
+       int rc;
+
+       /* XXX fix the race here (wait_for_event?)*/
+       /* hand the packet over to the server */
        rc = mds_queue_req(req); 
        if (rc) { 
-               EXIT;
-               return rc;
+               printk("osc_queue_wait: error %d, opcode %d\n", rc, 
+                      req->rq_reqhdr->opc); 
+               return -rc;
        }
 
+       init_waitqueue_head(&req->rq_wait_for_rep);
        printk("-- sleeping\n");
        interruptible_sleep_on(&req->rq_wait_for_rep);
        printk("-- done\n");
-       return 0;
+
+       mds_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr, 
+                      &req->rq_rep); 
+       printk("-->osc_queue_wait: buf %p len %d status %d\n", 
+              req->rq_repbuf, req->rq_replen, req->rq_rephdr->status); 
+
+       EXIT;
+       return req->rq_rephdr->status;
 }
 
-int llight_getattr(ino_t ino, struct  mds_rep  *rep)
+void mds_free_req(struct mds_request *request)
+{
+       kfree(request);
+}
+
+int mdc_getattr(ino_t ino, struct  mds_rep  **rep)
 {
        struct mds_request *request;
        int rc; 
 
-       request = (struct mds_request *)kmalloc(sizeof(*request), 
-                                               GFP_KERNEL); 
+       request = mds_prep_req(sizeof(*request), MDS_GETATTR); 
        if (!request) { 
-               printk("llight request: out of memory\n");
+               printk("llight request: cannot pack\n");
                return -ENOMEM;
        }
 
-       rc = mds_pack_req(NULL, 0, NULL, 0, 
-                         &request->rq_reqhdr, &request->rq_req, 
-                         &request->rq_reqlen, &request->rq_reqbuf);
-       if (rc) { 
-               printk("llight request: cannot pack request %d\n", rc); 
-               return rc;
-       }
        request->rq_req->fid1.id = ino;
 
-       request->rq_reqhdr->opc = MDS_GETATTR;
-       
-       rc = mds_send_req(request);
+       rc = mds_queue_wait(request);
        if (rc) { 
                printk("llight request: error in handling %d\n", rc); 
-               return rc;
+               goto out;
        }
 
-       printk("mode: %o\n", request->rq_rep->mode); 
-       if (rep) { 
-               memcpy(rep, request->rq_repbuf, sizeof(*rep));
+       printk("mds_getattr: mode: %o\n", request->rq_rep->mode); 
+
+       if (rep ) { 
+               *rep = request->rq_rep;
        }
-       kfree(request->rq_repbuf);
-       kfree(request);
-       return 0;
-}
 
+ out: 
+       mds_free_req(request);
+       return rc;
+}
 
 static int request_ioctl(struct inode *inode, struct file *file, 
                       unsigned int cmd, unsigned long arg)
@@ -114,7 +150,7 @@ static int request_ioctl(struct inode *inode, struct file *file,
        switch (cmd) {
        case IOC_REQUEST_GETATTR: { 
                printk("-- getting attr for ino 2\n"); 
-               err = llight_getattr(2, NULL);
+               err = mdc_getattr(2, NULL);
                printk("-- done err %d\n", err);
                break;
        }
@@ -140,27 +176,24 @@ static struct miscdevice request_dev = {
 };
 
 
-int init_request_module(void)
+static int __init mds_request_init(void)
 {
-       misc_register( &request_dev );
+       misc_register(&request_dev);
         return 0 ;
 }
 
-#ifdef MODULE
-MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
-MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
-
-#include <linux/module.h>
-
-int init_module(void)
-{
-        return init_request_module();
-}
 
-void cleanup_module(void)
+static void __exit mds_request_exit(void)
 {
        misc_deregister(&request_dev);
-       return;
 }
 
-#endif
+MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
+MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
+MODULE_LICENSE("GPL");
+
+EXPORT_SYMBOL(mdc_getattr); 
+
+
+module_init(mds_request_init);
+module_exit(mds_request_exit);