Whamcloud - gitweb
- fixes to the MDS: it now answers requests from the request test
[fs/lustre-release.git] / lustre / mds / handler.c
index 2380d69..fe58fbc 100644 (file)
@@ -1,14 +1,20 @@
 /*
 /*
- *  linux/fs/ext2_obd/ext2_obd.c
+ *  linux/mds/handler.c
+ *  
+ *  Lustre Metadata Server (mds) request handler
+ * 
+ *  Copyright (C) 2001  Cluster File Systems, Inc.
  *
  *
- * Copyright (C) 2001  Cluster File Systems, Inc.
+ *  This code is issued under the GNU General Public License.
+ *  See the file COPYING in this distribution
  *
  *
- * This code is issued under the GNU General Public License.
- * See the file COPYING in this distribution
- *
- * by Peter Braam <braam@clusterfs.com>
+ *  by Peter Braam <braam@clusterfs.com>
+ * 
+ *  This server is single threaded at present (but can easily be multi threaded). 
+ * 
  */
 
  */
 
+
 #define EXPORT_SYMTAB
 
 #include <linux/version.h>
 #define EXPORT_SYMTAB
 
 #include <linux/version.h>
 #include <linux/lustre_mds.h>
 #include <linux/obd_class.h>
 
 #include <linux/lustre_mds.h>
 #include <linux/obd_class.h>
 
+// for testing
+static struct mds_obd *MDS;
+
+// for testing
+static int mds_queue_req(struct mds_request *req)
+{
+       
+       if (!MDS) { 
+               EXIT;
+               return -1;
+       }
+
+       list_add(&req->rq_list, &MDS->mds_reqs); 
+       init_waitqueue_head(&req->rq_wait_for_mds_rep);
+       req->rq_obd = MDS;
+       wake_up(&MDS->mds_waitq);
+       printk("-- sleeping\n");
+       interruptible_sleep_on(&req->rq_wait_for_mds_rep);
+       printk("-- done\n");
+       return 0;
+}
 
 static struct dentry *mds_fid2dentry(struct mds_obd *mds, struct lustre_fid *fid)
 {
 
 static struct dentry *mds_fid2dentry(struct mds_obd *mds, struct lustre_fid *fid)
 {
@@ -52,7 +79,7 @@ int mds_getattr(struct mds_request *req)
 {
        struct dentry *de = mds_fid2dentry(req->rq_obd, &req->rq_req->fid1);
        struct inode *inode;
 {
        struct dentry *de = mds_fid2dentry(req->rq_obd, &req->rq_req->fid1);
        struct inode *inode;
-       struct mds_rep *rep = req->rq_rep;
+       struct mds_rep *rep;
        int rc;
        
        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep, 
        int rc;
        
        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep, 
@@ -65,6 +92,7 @@ int mds_getattr(struct mds_request *req)
        }
 
        req->rq_rephdr->seqno = req->rq_reqhdr->seqno;
        }
 
        req->rq_rephdr->seqno = req->rq_reqhdr->seqno;
+       rep = req->rq_rep;
 
        if (!de) { 
                EXIT;
 
        if (!de) { 
                EXIT;
@@ -81,6 +109,7 @@ int mds_getattr(struct mds_request *req)
        rep->size = inode->i_size;
        rep->mode = inode->i_mode;
 
        rep->size = inode->i_size;
        rep->mode = inode->i_mode;
 
+       dput(de); 
        return 0;
 }
 
        return 0;
 }
 
@@ -126,9 +155,9 @@ int mds_handle(struct mds_request *req)
 
        hdr = (struct mds_req_hdr *)req->rq_reqbuf;
 
 
        hdr = (struct mds_req_hdr *)req->rq_reqbuf;
 
-       if (NTOH_u32(hdr->type) != MDS_TYPE_REQ) {
+       if (NTOH__u32(hdr->type) != MDS_TYPE_REQ) {
                printk("lustre_mds: wrong packet type sent %d\n",
                printk("lustre_mds: wrong packet type sent %d\n",
-                      NTOH_u32(hdr->type));
+                      NTOH__u32(hdr->type));
                rc = -EINVAL;
                goto out;
        }
                rc = -EINVAL;
                goto out;
        }
@@ -227,13 +256,16 @@ int mds_main(void *arg)
        mds->mds_thread = current;
        wake_up(&mds->mds_done_waitq); 
 
        mds->mds_thread = current;
        wake_up(&mds->mds_done_waitq); 
 
-       printk(KERN_INFO "lustre_mds starting.  Commit interval %ld seconds\n",
+       printk(KERN_INFO "lustre_mds starting.  Commit interval %d seconds\n",
                        mds->mds_interval / HZ);
 
        /* XXX maintain a list of all managed devices: insert here */
 
        /* And now, wait forever for commit wakeup events. */
        while (1) {
                        mds->mds_interval / HZ);
 
        /* XXX maintain a list of all managed devices: insert here */
 
        /* And now, wait forever for commit wakeup events. */
        while (1) {
+               struct mds_request *request;
+               int rc; 
+
                if (mds->mds_flags & MDS_UNMOUNT)
                        break;
 
                if (mds->mds_flags & MDS_UNMOUNT)
                        break;
 
@@ -246,6 +278,11 @@ int mds_main(void *arg)
 
                if (list_empty(&mds->mds_reqs)) { 
                        CDEBUG(D_INODE, "woke because of timer\n"); 
 
                if (list_empty(&mds->mds_reqs)) { 
                        CDEBUG(D_INODE, "woke because of timer\n"); 
+               } else { 
+                       request = list_entry(mds->mds_reqs.next, 
+                                            struct mds_request, rq_list);
+                       list_del(&request->rq_list);
+                       rc = mds_handle(request); 
                }
        }
 
                }
        }
 
@@ -314,6 +351,7 @@ static int mds_setup(struct obd_device *obddev, obd_count len,
        mds->mds_ctxt.pwdmnt = mnt;
        mds->mds_ctxt.pwd = mnt->mnt_root;
        mds->mds_ctxt.fs = KERNEL_DS;
        mds->mds_ctxt.pwdmnt = mnt;
        mds->mds_ctxt.pwd = mnt->mnt_root;
        mds->mds_ctxt.fs = KERNEL_DS;
+       MDS = mds;
 
        spin_lock_init(&obddev->u.mds.fo_lock);
 
 
        spin_lock_init(&obddev->u.mds.fo_lock);
 
@@ -342,6 +380,7 @@ static int mds_cleanup(struct obd_device * obddev)
                 return -EBUSY;
         }
 
                 return -EBUSY;
         }
 
+       MDS = NULL;
        mds_stop_srv_thread(mds);
         sb = mds->mds_sb;
         if (!mds->mds_sb){
        mds_stop_srv_thread(mds);
         sb = mds->mds_sb;
         if (!mds->mds_sb){
@@ -374,8 +413,8 @@ static struct obd_ops mds_obd_ops = {
 
 static int __init mds_init(void)
 {
 
 static int __init mds_init(void)
 {
-        printk(KERN_INFO "Lustre MDS v0.01, braam@clusterfs.com\n");
         obd_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
         obd_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
+       return 0;
 }
 
 static void __exit mds_exit(void)
 }
 
 static void __exit mds_exit(void)
@@ -384,8 +423,12 @@ static void __exit mds_exit(void)
 }
 
 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
 }
 
 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
-MODULE_DESCRIPTION("Lustre Metadata server module");
+MODULE_DESCRIPTION("Lustre Metadata Server (MDS) v0.01");
 MODULE_LICENSE("GPL");
 
 MODULE_LICENSE("GPL");
 
+
+// for testing (maybe this stays)
+EXPORT_SYMBOL(mds_queue_req);
+
 module_init(mds_init);
 module_exit(mds_exit);
 module_init(mds_init);
 module_exit(mds_exit);