Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / llite / rw26.c
index 4852d43..7cbc293 100644 (file)
@@ -20,7 +20,8 @@
  *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-#ifdef HAVE_KERNEL_CONFIG_H
+
+#ifndef AUTOCONF_INCLUDED
 #include <linux/config.h>
 #endif
 #include <linux/kernel.h>
 #include <linux/writeback.h>
 #include <linux/stat.h>
 #include <asm/uaccess.h>
-#include <asm/segment.h>
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/smp_lock.h>
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
+//#include <lustre_mdc.h>
 #include <lustre_lite.h>
 #include "llite_internal.h"
 #include <linux/lustre_compat25.h>
@@ -71,13 +72,10 @@ static int ll_invalidatepage(struct page *page, unsigned long offset)
 #else
 static void ll_invalidatepage(struct page *page, unsigned long offset)
 {
-        if (offset)
-                return;
-        if (PagePrivate(page))
+        if (offset == 0 && PagePrivate(page))
                 ll_removepage(page);
 }
 #endif
-
 static int ll_releasepage(struct page *page, gfp_t gfp_mask)
 {
         if (PagePrivate(page))
@@ -85,6 +83,19 @@ static int ll_releasepage(struct page *page, gfp_t gfp_mask)
         return 1;
 }
 
+static int ll_set_page_dirty(struct page *page)
+{
+        struct ll_async_page *llap;
+        ENTRY;
+        
+        llap = llap_from_page(page, LLAP_ORIGIN_UNKNOWN);
+        if (IS_ERR(llap))
+                RETURN(PTR_ERR(llap));
+        
+        llap_write_pending(page->mapping->host, llap);
+        RETURN(__set_page_dirty_nobuffers(page));
+}
+
 #define MAX_DIRECTIO_SIZE 2*1024*1024*1024UL
 
 static inline int ll_get_user_pages(int rw, unsigned long user_addr,
@@ -99,10 +110,10 @@ static inline int ll_get_user_pages(int rw, unsigned long user_addr,
                 return -EFBIG;
         }
 
-        page_count = ((user_addr + size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT)-
-                      (user_addr >> CFS_PAGE_SHIFT);
+        page_count = (user_addr + size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
+        page_count -= user_addr >> CFS_PAGE_SHIFT;
 
-        OBD_ALLOC_GFP(*pages, page_count * sizeof(**pages), GFP_KERNEL);
+        OBD_ALLOC_WAIT(*pages, page_count * sizeof(**pages));
         if (*pages) {
                 down_read(&current->mm->mmap_sem);
                 result = get_user_pages(current, current->mm, user_addr,
@@ -133,12 +144,12 @@ static void ll_free_user_pages(struct page **pages, int npages, int do_dirty)
 
 static ssize_t ll_direct_IO_26_seg(int rw, struct inode *inode,
                                    struct address_space *mapping,
-                                   struct lov_stripe_md *lsm,
+                                   struct obd_info *oinfo,
+                                   struct ptlrpc_request_set *set,
                                    size_t size, loff_t file_offset,
                                    struct page **pages, int page_count)
 {
         struct brw_page *pga;
-        struct obdo oa;
         int i, rc = 0;
         size_t length;
         ENTRY;
@@ -146,7 +157,7 @@ static ssize_t ll_direct_IO_26_seg(int rw, struct inode *inode,
         OBD_ALLOC(pga, sizeof(*pga) * page_count);
         if (!pga) {
                 CDEBUG(D_VFSTRACE, "sizeof(*pga) = %u page_count = %u\n",
-                      (int)sizeof(*pga), page_count);
+                       (int)sizeof(*pga), page_count);
                 RETURN(-ENOMEM);
         }
 
@@ -155,25 +166,19 @@ static ssize_t ll_direct_IO_26_seg(int rw, struct inode *inode,
                 pga[i].pg = pages[i];
                 pga[i].off = file_offset;
                 /* To the end of the page, or the length, whatever is less */
-                pga[i].count = min_t(int, CFS_PAGE_SIZE -(file_offset & ~CFS_PAGE_MASK),
+                pga[i].count = min_t(int, CFS_PAGE_SIZE - 
+                                          (file_offset & ~CFS_PAGE_MASK),
                                      length);
                 pga[i].flag = 0;
                 if (rw == READ)
                         POISON_PAGE(pages[i], 0x0d);
         }
 
-        ll_inode_fill_obdo(inode, rw, &oa);
-
-        rc = obd_brw_rqset(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
-                           ll_i2obdexp(inode), &oa, lsm, page_count, pga, NULL);
-        if (rc == 0) {
+        rc = obd_brw_async(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
+                                ll_i2dtexp(inode), oinfo, page_count,
+                                pga, NULL, set);
+        if (rc == 0)
                 rc = size;
-                if (rw == WRITE) {
-                        lov_stripe_lock(lsm);
-                        obd_adjust_kms(ll_i2obdexp(inode), lsm, file_offset, 0);
-                        lov_stripe_unlock(lsm);
-                }
-        }
 
         OBD_FREE(pga, sizeof(*pga) * page_count);
         RETURN(rc);
@@ -193,29 +198,36 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
         struct inode *inode = file->f_mapping->host;
         ssize_t count = iov_length(iov, nr_segs), tot_bytes = 0;
         struct ll_inode_info *lli = ll_i2info(inode);
-        unsigned long seg;
+        struct lov_stripe_md *lsm = lli->lli_smd;
+        struct ptlrpc_request_set *set;
+        struct obd_info oinfo;
+        struct obdo oa;
+        unsigned long seg = 0;
         size_t size = MAX_DIO_SIZE;
+        int opc;
         ENTRY;
 
         if (!lli->lli_smd || !lli->lli_smd->lsm_object_id)
                 RETURN(-EBADF);
 
-        /* FIXME: io smaller than CFS_PAGE_SIZE is broken on ia64 ??? */
-        if ((file_offset & (~CFS_PAGE_MASK)) || (count & ~CFS_PAGE_MASK))
+        /* FIXME: io smaller than PAGE_SIZE is broken on ia64 ??? */
+        if ((file_offset & ~CFS_PAGE_MASK) || (count & ~CFS_PAGE_MASK))
                 RETURN(-EINVAL);
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), size="LPSZ" (max "LPSZ
-               "), offset=%lld=%llx, pages "LPSZ" (max "LPSZ")\n",
+        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), size="LPSZ" (max %lu), "
+               "offset=%lld=%llx, pages "LPSZ" (max %lu)\n",
                inode->i_ino, inode->i_generation, inode, count, MAX_DIO_SIZE,
                file_offset, file_offset, count >> CFS_PAGE_SHIFT,
                MAX_DIO_SIZE >> CFS_PAGE_SHIFT);
 
-        if (rw == WRITE)
-                lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
-                                    LPROC_LL_DIRECT_WRITE, count);
-        else
-                lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
-                                    LPROC_LL_DIRECT_READ, count);
+        if (rw == WRITE) {
+                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_DIRECT_WRITE, count);
+                opc = CAPA_OPC_OSS_WRITE;
+                llap_write_pending(inode, NULL);
+        } else {
+                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_DIRECT_READ, count);
+                opc = CAPA_OPC_OSS_RW;
+        }
 
         /* Check that all user buffers are aligned as well */
         for (seg = 0; seg < nr_segs; seg++) {
@@ -224,10 +236,31 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
                         RETURN(-EINVAL);
         }
 
+        set = ptlrpc_prep_set();
+        if (set == NULL)
+                RETURN(-ENOMEM);
+
+        ll_inode_fill_obdo(inode, rw, &oa);
+        oinfo.oi_oa = &oa;
+        oinfo.oi_md = lsm;
+        oinfo.oi_capa = ll_osscapa_get(inode, opc);
+
+        /* need locking between buffered and direct access. and race with 
+         *size changing by concurrent truncates and writes. */
+        if (rw == READ)
+                LOCK_INODE_MUTEX(inode);
+
         for (seg = 0; seg < nr_segs; seg++) {
                 size_t iov_left = iov[seg].iov_len;
                 unsigned long user_addr = (unsigned long)iov[seg].iov_base;
 
+                if (rw == READ) {
+                        if (file_offset >= inode->i_size)
+                                break;
+                        if (file_offset + iov_left > inode->i_size)
+                                iov_left = inode->i_size - file_offset;
+                }
+
                 while (iov_left > 0) {
                         struct page **pages;
                         int page_count;
@@ -240,7 +273,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
                         if (page_count > 0) {
                                 result = ll_direct_IO_26_seg(rw, inode,
                                                              file->f_mapping,
-                                                             lli->lli_smd,
+                                                             &oinfo, set,
                                                              min(size,iov_left),
                                                              file_offset, pages,
                                                              page_count);
@@ -264,9 +297,10 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
                                                (int)size);
                                         continue;
                                 }
-                                if (tot_bytes > 0)
-                                        RETURN(tot_bytes);
-                                RETURN(page_count < 0 ? page_count : result);
+
+                                if (tot_bytes <= 0)
+                                        tot_bytes = page_count < 0 ? page_count : result;
+                                GOTO(out, tot_bytes);
                         }
 
                         tot_bytes += result;
@@ -275,6 +309,25 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
                         user_addr += result;
                 }
         }
+out:
+        if (rw == READ)
+                UNLOCK_INODE_MUTEX(inode);
+
+        if (tot_bytes > 0) {
+                int rc;
+                
+                rc = ptlrpc_set_wait(set);
+                if (rc) {
+                        tot_bytes = rc;
+                } else if (rw == WRITE) {
+                        lov_stripe_lock(lsm);
+                        obd_adjust_kms(ll_i2dtexp(inode), lsm, file_offset, 0);
+                        lov_stripe_unlock(lsm);
+                }
+        }
+
+        capa_put(oinfo.oi_capa);
+        ptlrpc_set_destroy(set);
         RETURN(tot_bytes);
 }
 
@@ -284,7 +337,7 @@ struct address_space_operations ll_aops = {
         .direct_IO      = ll_direct_IO_26,
         .writepage      = ll_writepage_26,
         .writepages     = generic_writepages,
-        .set_page_dirty = __set_page_dirty_nobuffers,
+        .set_page_dirty = ll_set_page_dirty,
         .sync_page      = NULL,
         .prepare_write  = ll_prepare_write,
         .commit_write   = ll_commit_write,