]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/ocfs2/file.c
pipe: change the ->pin() operation to ->confirm()
[mirror_ubuntu-bionic-kernel.git] / fs / ocfs2 / file.c
index 36176018b4b44a1eb93d3ce6c83a78e9965ae1a9..4979b667571734c151a88b2a03f01db5e2b8c761 100644 (file)
@@ -31,7 +31,7 @@
 #include <linux/pagemap.h>
 #include <linux/uio.h>
 #include <linux/sched.h>
-#include <linux/pipe_fs_i.h>
+#include <linux/splice.h>
 #include <linux/mount.h>
 #include <linux/writeback.h>
 
@@ -207,16 +207,16 @@ out:
        return ret;
 }
 
-int ocfs2_set_inode_size(handle_t *handle,
-                        struct inode *inode,
-                        struct buffer_head *fe_bh,
-                        u64 new_i_size)
+static int ocfs2_set_inode_size(handle_t *handle,
+                               struct inode *inode,
+                               struct buffer_head *fe_bh,
+                               u64 new_i_size)
 {
        int status;
 
        mlog_entry_void();
        i_size_write(inode, new_i_size);
-       inode->i_blocks = ocfs2_align_bytes_to_sectors(new_i_size);
+       inode->i_blocks = ocfs2_inode_sector_count(inode);
        inode->i_ctime = inode->i_mtime = CURRENT_TIME;
 
        status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
@@ -326,6 +326,7 @@ static int ocfs2_truncate_file(struct inode *inode,
                   (unsigned long long)OCFS2_I(inode)->ip_blkno,
                   (unsigned long long)new_i_size);
 
+       unmap_mapping_range(inode->i_mapping, new_i_size + PAGE_SIZE - 1, 0, 1);
        truncate_inode_pages(inode->i_mapping, new_i_size);
 
        fe = (struct ocfs2_dinode *) di_bh->b_data;
@@ -713,7 +714,8 @@ restarted_transaction:
        }
 
        mlog(0, "fe: i_clusters = %u, i_size=%llu\n",
-            fe->i_clusters, (unsigned long long)fe->i_size);
+            le32_to_cpu(fe->i_clusters),
+            (unsigned long long)le64_to_cpu(fe->i_size));
        mlog(0, "inode: ip_clusters=%u, i_size=%lld\n",
             OCFS2_I(inode)->ip_clusters, i_size_read(inode));
 
@@ -1127,6 +1129,7 @@ static int ocfs2_check_range_for_holes(struct inode *inode, loff_t pos,
                                       size_t count)
 {
        int ret = 0;
+       unsigned int extent_flags;
        u32 cpos, clusters, extent_len, phys_cpos;
        struct super_block *sb = inode->i_sb;
 
@@ -1134,13 +1137,14 @@ static int ocfs2_check_range_for_holes(struct inode *inode, loff_t pos,
        clusters = ocfs2_clusters_for_bytes(sb, pos + count) - cpos;
 
        while (clusters) {
-               ret = ocfs2_get_clusters(inode, cpos, &phys_cpos, &extent_len);
+               ret = ocfs2_get_clusters(inode, cpos, &phys_cpos, &extent_len,
+                                        &extent_flags);
                if (ret < 0) {
                        mlog_errno(ret);
                        goto out;
                }
 
-               if (phys_cpos == 0) {
+               if (phys_cpos == 0 || (extent_flags & OCFS2_EXT_UNWRITTEN)) {
                        ret = 1;
                        break;
                }
@@ -1415,36 +1419,6 @@ out:
        return total ? total : ret;
 }
 
-static int ocfs2_check_iovec(const struct iovec *iov, size_t *counted,
-                            unsigned long *nr_segs)
-{
-       size_t ocount;          /* original count */
-       unsigned long seg;
-
-       ocount = 0;
-       for (seg = 0; seg < *nr_segs; seg++) {
-               const struct iovec *iv = &iov[seg];
-
-               /*
-                * If any segment has a negative length, or the cumulative
-                * length ever wraps negative then return -EINVAL.
-                */
-               ocount += iv->iov_len;
-               if (unlikely((ssize_t)(ocount|iv->iov_len) < 0))
-                       return -EINVAL;
-               if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
-                       continue;
-               if (seg == 0)
-                       return -EFAULT;
-               *nr_segs = seg;
-               ocount -= iv->iov_len;  /* This segment is no good */
-               break;
-       }
-
-       *counted = ocount;
-       return 0;
-}
-
 static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
                                    const struct iovec *iov,
                                    unsigned long nr_segs,
@@ -1467,7 +1441,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
        if (iocb->ki_left == 0)
                return 0;
 
-       ret = ocfs2_check_iovec(iov, &ocount, &nr_segs);
+       ret = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ);
        if (ret)
                return ret;
 
@@ -1540,7 +1514,7 @@ relock:
        pos = *ppos;
 
        /* communicate with ocfs2_dio_end_io */
-       ocfs2_iocb_set_rw_locked(iocb);
+       ocfs2_iocb_set_rw_locked(iocb, rw_level);
 
        if (direct_io) {
                written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos,
@@ -1609,7 +1583,7 @@ static int ocfs2_splice_write_actor(struct pipe_inode_info *pipe,
        ssize_t copied = 0;
        struct ocfs2_splice_write_priv sp;
 
-       ret = buf->ops->pin(pipe, buf);
+       ret = buf->ops->confirm(pipe, buf);
        if (ret)
                goto out;
 
@@ -1630,7 +1604,7 @@ static int ocfs2_splice_write_actor(struct pipe_inode_info *pipe,
                 * might enter ocfs2_buffered_write_cluster() more
                 * than once, so keep track of our progress here.
                 */
-               copied = ocfs2_buffered_write_cluster(sd->file,
+               copied = ocfs2_buffered_write_cluster(sd->u.file,
                                                      (loff_t)sd->pos + total,
                                                      count,
                                                      ocfs2_map_and_write_splice_data,
@@ -1662,9 +1636,14 @@ static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe,
        int ret, err;
        struct address_space *mapping = out->f_mapping;
        struct inode *inode = mapping->host;
-
-       ret = __splice_from_pipe(pipe, out, ppos, len, flags,
-                                ocfs2_splice_write_actor);
+       struct splice_desc sd = {
+               .total_len = len,
+               .flags = flags,
+               .pos = *ppos,
+               .u.file = out,
+       };
+
+       ret = __splice_from_pipe(pipe, &sd, ocfs2_splice_write_actor);
        if (ret > 0) {
                *ppos += ret;
 
@@ -1786,7 +1765,7 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
                }
                rw_level = 0;
                /* communicate with ocfs2_dio_end_io */
-               ocfs2_iocb_set_rw_locked(iocb);
+               ocfs2_iocb_set_rw_locked(iocb, rw_level);
        }
 
        /*
@@ -1843,7 +1822,6 @@ const struct inode_operations ocfs2_special_file_iops = {
 const struct file_operations ocfs2_fops = {
        .read           = do_sync_read,
        .write          = do_sync_write,
-       .sendfile       = generic_file_sendfile,
        .mmap           = ocfs2_mmap,
        .fsync          = ocfs2_sync_file,
        .release        = ocfs2_file_release,
@@ -1851,6 +1829,9 @@ const struct file_operations ocfs2_fops = {
        .aio_read       = ocfs2_file_aio_read,
        .aio_write      = ocfs2_file_aio_write,
        .ioctl          = ocfs2_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = ocfs2_compat_ioctl,
+#endif
        .splice_read    = ocfs2_file_splice_read,
        .splice_write   = ocfs2_file_splice_write,
 };
@@ -1860,4 +1841,7 @@ const struct file_operations ocfs2_dops = {
        .readdir        = ocfs2_readdir,
        .fsync          = ocfs2_sync_file,
        .ioctl          = ocfs2_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = ocfs2_compat_ioctl,
+#endif
 };