]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ocfs2/file.c
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[linux-2.6-omap-h63xx.git] / fs / ocfs2 / file.c
index 004c2abbc7323280c0ad1df75f34f17a88352110..4ffa715be09cff4f8243418016c0e0a08e2da40c 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/splice.h>
 #include <linux/mount.h>
 #include <linux/writeback.h>
+#include <linux/falloc.h>
 
 #define MLOG_MASK_PREFIX ML_INODE
 #include <cluster/masklog.h>
@@ -186,6 +187,7 @@ int ocfs2_update_inode_atime(struct inode *inode,
        int ret;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        handle_t *handle;
+       struct ocfs2_dinode *di = (struct ocfs2_dinode *) bh->b_data;
 
        mlog_entry_void();
 
@@ -196,11 +198,27 @@ int ocfs2_update_inode_atime(struct inode *inode,
                goto out;
        }
 
+       ret = ocfs2_journal_access(handle, inode, bh,
+                                  OCFS2_JOURNAL_ACCESS_WRITE);
+       if (ret) {
+               mlog_errno(ret);
+               goto out_commit;
+       }
+
+       /*
+        * Don't use ocfs2_mark_inode_dirty() here as we don't always
+        * have i_mutex to guard against concurrent changes to other
+        * inode fields.
+        */
        inode->i_atime = CURRENT_TIME;
-       ret = ocfs2_mark_inode_dirty(handle, inode, bh);
+       di->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
+       di->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
+
+       ret = ocfs2_journal_dirty(handle, bh);
        if (ret < 0)
                mlog_errno(ret);
 
+out_commit:
        ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
 out:
        mlog_exit(ret);
@@ -1010,6 +1028,11 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
        }
 
        if (size_change && attr->ia_size != i_size_read(inode)) {
+               if (attr->ia_size > sb->s_maxbytes) {
+                       status = -EFBIG;
+                       goto bail_unlock;
+               }
+
                if (i_size_read(inode) > attr->ia_size)
                        status = ocfs2_truncate_file(inode, bh, attr->ia_size);
                else
@@ -1504,29 +1527,18 @@ out:
 /*
  * Parts of this function taken from xfs_change_file_space()
  */
-int ocfs2_change_file_space(struct file *file, unsigned int cmd,
-                           struct ocfs2_space_resv *sr)
+static int __ocfs2_change_file_space(struct file *file, struct inode *inode,
+                                    loff_t f_pos, unsigned int cmd,
+                                    struct ocfs2_space_resv *sr,
+                                    int change_size)
 {
        int ret;
        s64 llen;
-       struct inode *inode = file->f_path.dentry->d_inode;
+       loff_t size;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        struct buffer_head *di_bh = NULL;
        handle_t *handle;
-       unsigned long long max_off = ocfs2_max_file_offset(inode->i_sb->s_blocksize_bits);
-
-       if ((cmd == OCFS2_IOC_RESVSP || cmd == OCFS2_IOC_RESVSP64) &&
-           !ocfs2_writes_unwritten_extents(osb))
-               return -ENOTTY;
-       else if ((cmd == OCFS2_IOC_UNRESVSP || cmd == OCFS2_IOC_UNRESVSP64) &&
-                !ocfs2_sparse_alloc(osb))
-               return -ENOTTY;
-
-       if (!S_ISREG(inode->i_mode))
-               return -EINVAL;
-
-       if (!(file->f_mode & FMODE_WRITE))
-               return -EBADF;
+       unsigned long long max_off = inode->i_sb->s_maxbytes;
 
        if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
                return -EROFS;
@@ -1557,7 +1569,7 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd,
        case 0: /*SEEK_SET*/
                break;
        case 1: /*SEEK_CUR*/
-               sr->l_start += file->f_pos;
+               sr->l_start += f_pos;
                break;
        case 2: /*SEEK_END*/
                sr->l_start += i_size_read(inode);
@@ -1577,6 +1589,7 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd,
                ret = -EINVAL;
                goto out_meta_unlock;
        }
+       size = sr->l_start + sr->l_len;
 
        if (cmd == OCFS2_IOC_RESVSP || cmd == OCFS2_IOC_RESVSP64) {
                if (sr->l_len <= 0) {
@@ -1585,7 +1598,7 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd,
                }
        }
 
-       if (should_remove_suid(file->f_path.dentry)) {
+       if (file && should_remove_suid(file->f_path.dentry)) {
                ret = __ocfs2_write_remove_suid(inode, di_bh);
                if (ret) {
                        mlog_errno(ret);
@@ -1628,6 +1641,9 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd,
                goto out_meta_unlock;
        }
 
+       if (change_size && i_size_read(inode) < size)
+               i_size_write(inode, size);
+
        inode->i_ctime = inode->i_mtime = CURRENT_TIME;
        ret = ocfs2_mark_inode_dirty(handle, inode, di_bh);
        if (ret < 0)
@@ -1646,6 +1662,52 @@ out:
        return ret;
 }
 
+int ocfs2_change_file_space(struct file *file, unsigned int cmd,
+                           struct ocfs2_space_resv *sr)
+{
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);;
+
+       if ((cmd == OCFS2_IOC_RESVSP || cmd == OCFS2_IOC_RESVSP64) &&
+           !ocfs2_writes_unwritten_extents(osb))
+               return -ENOTTY;
+       else if ((cmd == OCFS2_IOC_UNRESVSP || cmd == OCFS2_IOC_UNRESVSP64) &&
+                !ocfs2_sparse_alloc(osb))
+               return -ENOTTY;
+
+       if (!S_ISREG(inode->i_mode))
+               return -EINVAL;
+
+       if (!(file->f_mode & FMODE_WRITE))
+               return -EBADF;
+
+       return __ocfs2_change_file_space(file, inode, file->f_pos, cmd, sr, 0);
+}
+
+static long ocfs2_fallocate(struct inode *inode, int mode, loff_t offset,
+                           loff_t len)
+{
+       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+       struct ocfs2_space_resv sr;
+       int change_size = 1;
+
+       if (!ocfs2_writes_unwritten_extents(osb))
+               return -EOPNOTSUPP;
+
+       if (S_ISDIR(inode->i_mode))
+               return -ENODEV;
+
+       if (mode & FALLOC_FL_KEEP_SIZE)
+               change_size = 0;
+
+       sr.l_whence = 0;
+       sr.l_start = (s64)offset;
+       sr.l_len = (s64)len;
+
+       return __ocfs2_change_file_space(NULL, inode, offset,
+                                        OCFS2_IOC_RESVSP64, &sr, change_size);
+}
+
 static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
                                         loff_t *ppos,
                                         size_t count,
@@ -1902,7 +1964,7 @@ static ssize_t ocfs2_file_buffered_write(struct file *file, loff_t *ppos,
                }
 
                dst = kmap_atomic(page, KM_USER0);
-               memcpy(dst + (pos & (PAGE_CACHE_SIZE - 1)), buf, bytes);
+               memcpy(dst + (pos & (loff_t)(PAGE_CACHE_SIZE - 1)), buf, bytes);
                kunmap_atomic(dst, KM_USER0);
                flush_dcache_page(page);
                ocfs2_put_write_source(user_page);
@@ -2113,7 +2175,7 @@ static int ocfs2_splice_write_actor(struct pipe_inode_info *pipe,
        src = buf->ops->map(pipe, buf, 1);
        dst = kmap_atomic(page, KM_USER1);
        memcpy(dst + offset, src + buf->offset, count);
-       kunmap_atomic(page, KM_USER1);
+       kunmap_atomic(dst, KM_USER1);
        buf->ops->unmap(pipe, buf, src);
 
        copied = ocfs2_write_end(file, file->f_mapping, sd->pos, count, count,
@@ -2312,6 +2374,7 @@ const struct inode_operations ocfs2_file_iops = {
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
        .permission     = ocfs2_permission,
+       .fallocate      = ocfs2_fallocate,
 };
 
 const struct inode_operations ocfs2_special_file_iops = {