Whamcloud - gitweb
Fix one build error, one build warning, and one extremely scary
[fs/lustre-release.git] / lustre / llite / dir.c
index 97468c3..6f2e813 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
  *
  * Copyright (C) 1992, 1993, 1994, 1995
  * Remy Card (card@masi.ibp.fr)
 #include <linux/locks.h>
 #include <asm/uaccess.h>
 
-#define DEBUG_SUBSYSTEM S_LLIGHT
+#define DEBUG_SUBSYSTEM S_LLITE
 
 #include <linux/obd_support.h>
 #include <linux/obd_class.h>
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
 #include <linux/lustre_mds.h>
-#include <linux/lustre_light.h>
+#include <linux/lustre_lite.h>
+#include <linux/lustre_dlm.h>
 
 typedef struct ext2_dir_entry_2 ext2_dirent;
 
@@ -60,18 +62,24 @@ static int ll_dir_readpage(struct file *file, struct page *page)
         char *buf;
         __u64 offset;
         int rc = 0;
-        struct ptlrpc_request *request;
+        struct ptlrpc_request *request = NULL;
+        struct lustre_handle lockh; 
+        struct lookup_intent it = {IT_READDIR }; 
 
         ENTRY;
 
-        if ( ((inode->i_size + PAGE_CACHE_SIZE -1)>>PAGE_SHIFT)
-             <= page->index) {
+        if ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_SHIFT <= page->index){
                 memset(kmap(page), 0, PAGE_CACHE_SIZE);
                 kunmap(page);
                 EXIT;
                 goto readpage_out;
         }
 
+        rc = ll_lock(inode, NULL, &it, &lockh);
+        if (rc != ELDLM_OK)
+                CERROR("lock enqueue: err: %d\n", rc);
+        ldlm_lock_dump((void *)(unsigned long)lockh.addr);
+
         if (Page_Uptodate(page)) {
                 CERROR("Explain this please?\n");
                 EXIT;
@@ -80,8 +88,8 @@ static int ll_dir_readpage(struct file *file, struct page *page)
 
         offset = page->index << PAGE_SHIFT; 
         buf = kmap(page);
-        rc = mdc_readpage(&sbi->ll_mds_client, inode->i_ino, S_IFDIR, offset, 
-                          buf, &request);
+        rc = mdc_readpage(&sbi->ll_mdc_conn, inode->i_ino,
+                          S_IFDIR, offset, buf, &request);
         kunmap(page); 
         ptlrpc_free_req(request);
         EXIT;
@@ -91,6 +99,9 @@ static int ll_dir_readpage(struct file *file, struct page *page)
                 SetPageUptodate(page);
 
         UnlockPage(page);
+        rc = ll_unlock(LCK_PR, &lockh);
+        if (rc != ELDLM_OK)
+                CERROR("ll_unlock: err: %d\n", rc);
         return rc;
 } /* ll_dir_readpage */
 
@@ -119,8 +130,7 @@ int waitfor_one_page(struct page *page)
  */
 static inline unsigned ext2_chunk_size(struct inode *inode)
 {
-        //return inode->i_sb->s_blocksize;
-        return PAGE_SIZE;
+        return inode->i_sb->s_blocksize;
 }
 
 static inline void ext2_put_page(struct page *page)
@@ -139,10 +149,12 @@ extern void set_page_clean(struct page *page);
 static int ext2_commit_chunk(struct page *page, unsigned from, unsigned to)
 {
         struct inode *dir = page->mapping->host;
+        loff_t new_size = (page->index << PAGE_CACHE_SHIFT) + to;
         int err = 0;
 
         dir->i_version = ++event;
-        dir->i_size = (page->index << PAGE_CACHE_SHIFT) + to; 
+        if (new_size > dir->i_size)
+                dir->i_size = new_size;
         SetPageUptodate(page);
         set_page_clean(page);
 
@@ -335,7 +347,7 @@ static inline void ext2_set_de_type(ext2_dirent *de, struct inode *inode)
 }
 
 int
-new_ll_readdir (struct file * filp, void * dirent, filldir_t filldir)
+ll_readdir (struct file * filp, void * dirent, filldir_t filldir)
 {
         loff_t pos = filp->f_pos;
         struct inode *inode = filp->f_dentry->d_inode;
@@ -348,7 +360,7 @@ new_ll_readdir (struct file * filp, void * dirent, filldir_t filldir)
         int need_revalidate = (filp->f_version != inode->i_version);
 
         if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
-                goto done;
+                GOTO(done, 0);
 
         types = ext2_filetype_table;
 
@@ -380,7 +392,7 @@ new_ll_readdir (struct file * filp, void * dirent, filldir_t filldir)
                                                 le32_to_cpu(de->inode), d_type);
                                 if (over) {
                                         ext2_put_page(page);
-                                        goto done;
+                                        GOTO(done,0);
                                 }
                         }
                 ext2_put_page(page);
@@ -698,5 +710,5 @@ not_empty:
 
 struct file_operations ll_dir_operations = {
         read: generic_read_dir,
-        readdir: new_ll_readdir
+        readdir: ll_readdir
 };