aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r--fs/ocfs2/file.c88
1 files changed, 51 insertions, 37 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index de059f490586..a5fbd9cea968 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -107,6 +107,9 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)
107 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file, 107 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
108 file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name); 108 file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
109 109
110 if (file->f_mode & FMODE_WRITE)
111 dquot_initialize(inode);
112
110 spin_lock(&oi->ip_lock); 113 spin_lock(&oi->ip_lock);
111 114
112 /* Check that the inode hasn't been wiped from disk by another 115 /* Check that the inode hasn't been wiped from disk by another
@@ -629,11 +632,10 @@ restart_all:
629 } 632 }
630 633
631restarted_transaction: 634restarted_transaction:
632 if (vfs_dq_alloc_space_nodirty(inode, ocfs2_clusters_to_bytes(osb->sb, 635 status = dquot_alloc_space_nodirty(inode,
633 clusters_to_add))) { 636 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
634 status = -EDQUOT; 637 if (status)
635 goto leave; 638 goto leave;
636 }
637 did_quota = 1; 639 did_quota = 1;
638 640
639 /* reserve a write to the file entry early on - that we if we 641 /* reserve a write to the file entry early on - that we if we
@@ -674,7 +676,7 @@ restarted_transaction:
674 clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters); 676 clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters);
675 spin_unlock(&OCFS2_I(inode)->ip_lock); 677 spin_unlock(&OCFS2_I(inode)->ip_lock);
676 /* Release unused quota reservation */ 678 /* Release unused quota reservation */
677 vfs_dq_free_space(inode, 679 dquot_free_space(inode,
678 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add)); 680 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
679 did_quota = 0; 681 did_quota = 0;
680 682
@@ -682,6 +684,7 @@ restarted_transaction:
682 if (why == RESTART_META) { 684 if (why == RESTART_META) {
683 mlog(0, "restarting function.\n"); 685 mlog(0, "restarting function.\n");
684 restart_func = 1; 686 restart_func = 1;
687 status = 0;
685 } else { 688 } else {
686 BUG_ON(why != RESTART_TRANS); 689 BUG_ON(why != RESTART_TRANS);
687 690
@@ -710,7 +713,7 @@ restarted_transaction:
710 713
711leave: 714leave:
712 if (status < 0 && did_quota) 715 if (status < 0 && did_quota)
713 vfs_dq_free_space(inode, 716 dquot_free_space(inode,
714 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add)); 717 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
715 if (handle) { 718 if (handle) {
716 ocfs2_commit_trans(osb, handle); 719 ocfs2_commit_trans(osb, handle);
@@ -749,7 +752,7 @@ static int ocfs2_write_zero_page(struct inode *inode,
749 int ret; 752 int ret;
750 753
751 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */ 754 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */
752 /* ugh. in prepare/commit_write, if from==to==start of block, we 755 /* ugh. in prepare/commit_write, if from==to==start of block, we
753 ** skip the prepare. make sure we never send an offset for the start 756 ** skip the prepare. make sure we never send an offset for the start
754 ** of a block 757 ** of a block
755 */ 758 */
@@ -978,6 +981,8 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
978 981
979 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE; 982 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
980 if (size_change) { 983 if (size_change) {
984 dquot_initialize(inode);
985
981 status = ocfs2_rw_lock(inode, 1); 986 status = ocfs2_rw_lock(inode, 1);
982 if (status < 0) { 987 if (status < 0) {
983 mlog_errno(status); 988 mlog_errno(status);
@@ -993,10 +998,9 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
993 } 998 }
994 999
995 if (size_change && attr->ia_size != i_size_read(inode)) { 1000 if (size_change && attr->ia_size != i_size_read(inode)) {
996 if (attr->ia_size > sb->s_maxbytes) { 1001 status = inode_newsize_ok(inode, attr->ia_size);
997 status = -EFBIG; 1002 if (status)
998 goto bail_unlock; 1003 goto bail_unlock;
999 }
1000 1004
1001 if (i_size_read(inode) > attr->ia_size) { 1005 if (i_size_read(inode) > attr->ia_size) {
1002 if (ocfs2_should_order_data(inode)) { 1006 if (ocfs2_should_order_data(inode)) {
@@ -1021,7 +1025,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1021 /* 1025 /*
1022 * Gather pointers to quota structures so that allocation / 1026 * Gather pointers to quota structures so that allocation /
1023 * freeing of quota structures happens here and not inside 1027 * freeing of quota structures happens here and not inside
1024 * vfs_dq_transfer() where we have problems with lock ordering 1028 * dquot_transfer() where we have problems with lock ordering
1025 */ 1029 */
1026 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid 1030 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid
1027 && OCFS2_HAS_RO_COMPAT_FEATURE(sb, 1031 && OCFS2_HAS_RO_COMPAT_FEATURE(sb,
@@ -1054,7 +1058,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1054 mlog_errno(status); 1058 mlog_errno(status);
1055 goto bail_unlock; 1059 goto bail_unlock;
1056 } 1060 }
1057 status = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; 1061 status = dquot_transfer(inode, attr);
1058 if (status < 0) 1062 if (status < 0)
1059 goto bail_commit; 1063 goto bail_commit;
1060 } else { 1064 } else {
@@ -1772,13 +1776,14 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
1772 loff_t *ppos, 1776 loff_t *ppos,
1773 size_t count, 1777 size_t count,
1774 int appending, 1778 int appending,
1775 int *direct_io) 1779 int *direct_io,
1780 int *has_refcount)
1776{ 1781{
1777 int ret = 0, meta_level = 0; 1782 int ret = 0, meta_level = 0;
1778 struct inode *inode = dentry->d_inode; 1783 struct inode *inode = dentry->d_inode;
1779 loff_t saved_pos, end; 1784 loff_t saved_pos, end;
1780 1785
1781 /* 1786 /*
1782 * We start with a read level meta lock and only jump to an ex 1787 * We start with a read level meta lock and only jump to an ex
1783 * if we need to make modifications here. 1788 * if we need to make modifications here.
1784 */ 1789 */
@@ -1833,6 +1838,10 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
1833 saved_pos, 1838 saved_pos,
1834 count, 1839 count,
1835 &meta_level); 1840 &meta_level);
1841 if (has_refcount)
1842 *has_refcount = 1;
1843 if (direct_io)
1844 *direct_io = 0;
1836 } 1845 }
1837 1846
1838 if (ret < 0) { 1847 if (ret < 0) {
@@ -1899,7 +1908,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1899 loff_t pos) 1908 loff_t pos)
1900{ 1909{
1901 int ret, direct_io, appending, rw_level, have_alloc_sem = 0; 1910 int ret, direct_io, appending, rw_level, have_alloc_sem = 0;
1902 int can_do_direct; 1911 int can_do_direct, has_refcount = 0;
1903 ssize_t written = 0; 1912 ssize_t written = 0;
1904 size_t ocount; /* original count */ 1913 size_t ocount; /* original count */
1905 size_t count; /* after file limit checks */ 1914 size_t count; /* after file limit checks */
@@ -1942,7 +1951,7 @@ relock:
1942 can_do_direct = direct_io; 1951 can_do_direct = direct_io;
1943 ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos, 1952 ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos,
1944 iocb->ki_left, appending, 1953 iocb->ki_left, appending,
1945 &can_do_direct); 1954 &can_do_direct, &has_refcount);
1946 if (ret < 0) { 1955 if (ret < 0) {
1947 mlog_errno(ret); 1956 mlog_errno(ret);
1948 goto out; 1957 goto out;
@@ -1973,18 +1982,18 @@ relock:
1973 /* communicate with ocfs2_dio_end_io */ 1982 /* communicate with ocfs2_dio_end_io */
1974 ocfs2_iocb_set_rw_locked(iocb, rw_level); 1983 ocfs2_iocb_set_rw_locked(iocb, rw_level);
1975 1984
1976 if (direct_io) { 1985 ret = generic_segment_checks(iov, &nr_segs, &ocount,
1977 ret = generic_segment_checks(iov, &nr_segs, &ocount, 1986 VERIFY_READ);
1978 VERIFY_READ); 1987 if (ret)
1979 if (ret) 1988 goto out_dio;
1980 goto out_dio;
1981 1989
1982 count = ocount; 1990 count = ocount;
1983 ret = generic_write_checks(file, ppos, &count, 1991 ret = generic_write_checks(file, ppos, &count,
1984 S_ISBLK(inode->i_mode)); 1992 S_ISBLK(inode->i_mode));
1985 if (ret) 1993 if (ret)
1986 goto out_dio; 1994 goto out_dio;
1987 1995
1996 if (direct_io) {
1988 written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos, 1997 written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos,
1989 ppos, count, ocount); 1998 ppos, count, ocount);
1990 if (written < 0) { 1999 if (written < 0) {
@@ -1999,21 +2008,26 @@ relock:
1999 goto out_dio; 2008 goto out_dio;
2000 } 2009 }
2001 } else { 2010 } else {
2002 written = __generic_file_aio_write(iocb, iov, nr_segs, ppos); 2011 current->backing_dev_info = file->f_mapping->backing_dev_info;
2012 written = generic_file_buffered_write(iocb, iov, nr_segs, *ppos,
2013 ppos, count, 0);
2014 current->backing_dev_info = NULL;
2003 } 2015 }
2004 2016
2005out_dio: 2017out_dio:
2006 /* buffered aio wouldn't have proper lock coverage today */ 2018 /* buffered aio wouldn't have proper lock coverage today */
2007 BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); 2019 BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT));
2008 2020
2009 if ((file->f_flags & O_SYNC && !direct_io) || IS_SYNC(inode)) { 2021 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||
2022 ((file->f_flags & O_DIRECT) && has_refcount)) {
2010 ret = filemap_fdatawrite_range(file->f_mapping, pos, 2023 ret = filemap_fdatawrite_range(file->f_mapping, pos,
2011 pos + count - 1); 2024 pos + count - 1);
2012 if (ret < 0) 2025 if (ret < 0)
2013 written = ret; 2026 written = ret;
2014 2027
2015 if (!ret && (old_size != i_size_read(inode) || 2028 if (!ret && ((old_size != i_size_read(inode)) ||
2016 old_clusters != OCFS2_I(inode)->ip_clusters)) { 2029 (old_clusters != OCFS2_I(inode)->ip_clusters) ||
2030 has_refcount)) {
2017 ret = jbd2_journal_force_commit(osb->journal->j_journal); 2031 ret = jbd2_journal_force_commit(osb->journal->j_journal);
2018 if (ret < 0) 2032 if (ret < 0)
2019 written = ret; 2033 written = ret;
@@ -2024,7 +2038,7 @@ out_dio:
2024 pos + count - 1); 2038 pos + count - 1);
2025 } 2039 }
2026 2040
2027 /* 2041 /*
2028 * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io 2042 * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
2029 * function pointer which is called when o_direct io completes so that 2043 * function pointer which is called when o_direct io completes so that
2030 * it can unlock our rw lock. (it's the clustered equivalent of 2044 * it can unlock our rw lock. (it's the clustered equivalent of
@@ -2034,7 +2048,7 @@ out_dio:
2034 * async dio is going to do it in the future or an end_io after an 2048 * async dio is going to do it in the future or an end_io after an
2035 * error has already done it. 2049 * error has already done it.
2036 */ 2050 */
2037 if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { 2051 if ((ret == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
2038 rw_level = -1; 2052 rw_level = -1;
2039 have_alloc_sem = 0; 2053 have_alloc_sem = 0;
2040 } 2054 }
@@ -2062,7 +2076,7 @@ static int ocfs2_splice_to_file(struct pipe_inode_info *pipe,
2062 int ret; 2076 int ret;
2063 2077
2064 ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, 2078 ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos,
2065 sd->total_len, 0, NULL); 2079 sd->total_len, 0, NULL, NULL);
2066 if (ret < 0) { 2080 if (ret < 0) {
2067 mlog_errno(ret); 2081 mlog_errno(ret);
2068 return ret; 2082 return ret;
@@ -2189,7 +2203,7 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2189 goto bail; 2203 goto bail;
2190 } 2204 }
2191 2205
2192 /* 2206 /*
2193 * buffered reads protect themselves in ->readpage(). O_DIRECT reads 2207 * buffered reads protect themselves in ->readpage(). O_DIRECT reads
2194 * need locks to protect pending reads from racing with truncate. 2208 * need locks to protect pending reads from racing with truncate.
2195 */ 2209 */
@@ -2211,10 +2225,10 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2211 * We're fine letting folks race truncates and extending 2225 * We're fine letting folks race truncates and extending
2212 * writes with read across the cluster, just like they can 2226 * writes with read across the cluster, just like they can
2213 * locally. Hence no rw_lock during read. 2227 * locally. Hence no rw_lock during read.
2214 * 2228 *
2215 * Take and drop the meta data lock to update inode fields 2229 * Take and drop the meta data lock to update inode fields
2216 * like i_size. This allows the checks down below 2230 * like i_size. This allows the checks down below
2217 * generic_file_aio_read() a chance of actually working. 2231 * generic_file_aio_read() a chance of actually working.
2218 */ 2232 */
2219 ret = ocfs2_inode_lock_atime(inode, filp->f_vfsmnt, &lock_level); 2233 ret = ocfs2_inode_lock_atime(inode, filp->f_vfsmnt, &lock_level);
2220 if (ret < 0) { 2234 if (ret < 0) {
@@ -2239,7 +2253,7 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2239bail: 2253bail:
2240 if (have_alloc_sem) 2254 if (have_alloc_sem)
2241 up_read(&inode->i_alloc_sem); 2255 up_read(&inode->i_alloc_sem);
2242 if (rw_level != -1) 2256 if (rw_level != -1)
2243 ocfs2_rw_unlock(inode, rw_level); 2257 ocfs2_rw_unlock(inode, rw_level);
2244 mlog_exit(ret); 2258 mlog_exit(ret);
2245 2259