]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/ceph/file.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mv-sheeva.git] / fs / ceph / file.c
index bbf1ccf2d56ef4647df9346f22d260e1855023b0..4add3d5da2c1ba3ee650c0d0945ce4c4ca2f68a5 100644 (file)
@@ -1,6 +1,7 @@
 #include "ceph_debug.h"
 
 #include <linux/sched.h>
+#include <linux/slab.h>
 #include <linux/file.h>
 #include <linux/namei.h>
 #include <linux/writeback.h>
@@ -262,6 +263,9 @@ int ceph_release(struct inode *inode, struct file *file)
        kfree(cf->dir_info);
        dput(cf->dentry);
        kmem_cache_free(ceph_file_cachep, cf);
+
+       /* wake up anyone waiting for caps on this inode */
+       wake_up(&ci->i_cap_wq);
        return 0;
 }
 
@@ -431,7 +435,8 @@ static void zero_page_vector_range(int off, int len, struct page **pages)
  */
 static int striped_read(struct inode *inode,
                        u64 off, u64 len,
-                       struct page **pages, int num_pages)
+                       struct page **pages, int num_pages,
+                       int *checkeof)
 {
        struct ceph_client *client = ceph_inode_to_client(inode);
        struct ceph_inode_info *ci = ceph_inode(inode);
@@ -497,15 +502,7 @@ more:
                }
 
                /* check i_size */
-               ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE);
-               if (ret < 0)
-                       goto out;
-
-               /* hit EOF? */
-               if (pos >= inode->i_size)
-                       goto out;
-
-               goto more;
+               *checkeof = 1;
        }
 
 out:
@@ -522,7 +519,7 @@ out:
  * If the read spans object boundary, just do multiple reads.
  */
 static ssize_t ceph_sync_read(struct file *file, char __user *data,
-                             unsigned len, loff_t *poff)
+                             unsigned len, loff_t *poff, int *checkeof)
 {
        struct inode *inode = file->f_dentry->d_inode;
        struct page **pages;
@@ -552,7 +549,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
        if (ret < 0)
                goto done;
 
-       ret = striped_read(inode, off, len, pages, num_pages);
+       ret = striped_read(inode, off, len, pages, num_pages, checkeof);
 
        if (ret >= 0 && (file->f_flags & O_DIRECT) == 0)
                ret = copy_page_vector_to_user(pages, data, off, ret);
@@ -746,11 +743,14 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
        size_t len = iov->iov_len;
        struct inode *inode = filp->f_dentry->d_inode;
        struct ceph_inode_info *ci = ceph_inode(inode);
+       void *base = iov->iov_base;
        ssize_t ret;
        int got = 0;
+       int checkeof = 0, read = 0;
 
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
+again:
        __ceph_do_pending_vmtruncate(inode);
        ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, CEPH_CAP_FILE_CACHE,
                            &got, -1);
@@ -764,7 +764,7 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
            (iocb->ki_filp->f_flags & O_DIRECT) ||
            (inode->i_sb->s_flags & MS_SYNCHRONOUS))
                /* hmm, this isn't really async... */
-               ret = ceph_sync_read(filp, iov->iov_base, len, ppos);
+               ret = ceph_sync_read(filp, base, len, ppos, &checkeof);
        else
                ret = generic_file_aio_read(iocb, iov, nr_segs, pos);
 
@@ -772,6 +772,23 @@ out:
        dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n",
             inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);
        ceph_put_cap_refs(ci, got);
+
+       if (checkeof && ret >= 0) {
+               int statret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE);
+
+               /* hit EOF or hole? */
+               if (statret == 0 && *ppos < inode->i_size) {
+                       dout("aio_read sync_read hit hole, reading more\n");
+                       read += ret;
+                       base += ret;
+                       len -= ret;
+                       checkeof = 0;
+                       goto again;
+               }
+       }
+       if (ret >= 0)
+               ret += read;
+
        return ret;
 }
 
@@ -794,7 +811,7 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov,
        struct ceph_osd_client *osdc = &ceph_client(inode->i_sb)->osdc;
        loff_t endoff = pos + iov->iov_len;
        int got = 0;
-       int ret;
+       int ret, err;
 
        if (ceph_snap(inode) != CEPH_NOSNAP)
                return -EROFS;
@@ -825,9 +842,12 @@ retry_snap:
 
                if ((ret >= 0 || ret == -EIOCBQUEUED) &&
                    ((file->f_flags & O_SYNC) || IS_SYNC(file->f_mapping->host)
-                    || ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_NEARFULL)))
-                       ret = vfs_fsync_range(file, file->f_path.dentry,
+                    || ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_NEARFULL))) {
+                       err = vfs_fsync_range(file, file->f_path.dentry,
                                              pos, pos + ret - 1, 1);
+                       if (err < 0)
+                               ret = err;
+               }
        }
        if (ret >= 0) {
                spin_lock(&inode->i_lock);