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.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index de059f490586..17947dc8341e 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
@@ -710,7 +712,7 @@ restarted_transaction:
710 712
711leave: 713leave:
712 if (status < 0 && did_quota) 714 if (status < 0 && did_quota)
713 vfs_dq_free_space(inode, 715 dquot_free_space(inode,
714 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add)); 716 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
715 if (handle) { 717 if (handle) {
716 ocfs2_commit_trans(osb, handle); 718 ocfs2_commit_trans(osb, handle);
@@ -749,7 +751,7 @@ static int ocfs2_write_zero_page(struct inode *inode,
749 int ret; 751 int ret;
750 752
751 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */ 753 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */
752 /* ugh. in prepare/commit_write, if from==to==start of block, we 754 /* 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 755 ** skip the prepare. make sure we never send an offset for the start
754 ** of a block 756 ** of a block
755 */ 757 */
@@ -978,6 +980,8 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
978 980
979 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE; 981 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
980 if (size_change) { 982 if (size_change) {
983 dquot_initialize(inode);
984
981 status = ocfs2_rw_lock(inode, 1); 985 status = ocfs2_rw_lock(inode, 1);
982 if (status < 0) { 986 if (status < 0) {
983 mlog_errno(status); 987 mlog_errno(status);
@@ -993,10 +997,9 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
993 } 997 }
994 998
995 if (size_change && attr->ia_size != i_size_read(inode)) { 999 if (size_change && attr->ia_size != i_size_read(inode)) {
996 if (attr->ia_size > sb->s_maxbytes) { 1000 status = inode_newsize_ok(inode, attr->ia_size);
997 status = -EFBIG; 1001 if (status)
998 goto bail_unlock; 1002 goto bail_unlock;
999 }
1000 1003
1001 if (i_size_read(inode) > attr->ia_size) { 1004 if (i_size_read(inode) > attr->ia_size) {
1002 if (ocfs2_should_order_data(inode)) { 1005 if (ocfs2_should_order_data(inode)) {
@@ -1021,7 +1024,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1021 /* 1024 /*
1022 * Gather pointers to quota structures so that allocation / 1025 * Gather pointers to quota structures so that allocation /
1023 * freeing of quota structures happens here and not inside 1026 * freeing of quota structures happens here and not inside
1024 * vfs_dq_transfer() where we have problems with lock ordering 1027 * dquot_transfer() where we have problems with lock ordering
1025 */ 1028 */
1026 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid 1029 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid
1027 && OCFS2_HAS_RO_COMPAT_FEATURE(sb, 1030 && OCFS2_HAS_RO_COMPAT_FEATURE(sb,
@@ -1054,7 +1057,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1054 mlog_errno(status); 1057 mlog_errno(status);
1055 goto bail_unlock; 1058 goto bail_unlock;
1056 } 1059 }
1057 status = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; 1060 status = dquot_transfer(inode, attr);
1058 if (status < 0) 1061 if (status < 0)
1059 goto bail_commit; 1062 goto bail_commit;
1060 } else { 1063 } else {
@@ -1772,13 +1775,14 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
1772 loff_t *ppos, 1775 loff_t *ppos,
1773 size_t count, 1776 size_t count,
1774 int appending, 1777 int appending,
1775 int *direct_io) 1778 int *direct_io,
1779 int *has_refcount)
1776{ 1780{
1777 int ret = 0, meta_level = 0; 1781 int ret = 0, meta_level = 0;
1778 struct inode *inode = dentry->d_inode; 1782 struct inode *inode = dentry->d_inode;
1779 loff_t saved_pos, end; 1783 loff_t saved_pos, end;
1780 1784
1781 /* 1785 /*
1782 * We start with a read level meta lock and only jump to an ex 1786 * We start with a read level meta lock and only jump to an ex
1783 * if we need to make modifications here. 1787 * if we need to make modifications here.
1784 */ 1788 */
@@ -1833,6 +1837,10 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
1833 saved_pos, 1837 saved_pos,
1834 count, 1838 count,
1835 &meta_level); 1839 &meta_level);
1840 if (has_refcount)
1841 *has_refcount = 1;
1842 if (direct_io)
1843 *direct_io = 0;
1836 } 1844 }
1837 1845
1838 if (ret < 0) { 1846 if (ret < 0) {
@@ -1899,7 +1907,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1899 loff_t pos) 1907 loff_t pos)
1900{ 1908{
1901 int ret, direct_io, appending, rw_level, have_alloc_sem = 0; 1909 int ret, direct_io, appending, rw_level, have_alloc_sem = 0;
1902 int can_do_direct; 1910 int can_do_direct, has_refcount = 0;
1903 ssize_t written = 0; 1911 ssize_t written = 0;
1904 size_t ocount; /* original count */ 1912 size_t ocount; /* original count */
1905 size_t count; /* after file limit checks */ 1913 size_t count; /* after file limit checks */
@@ -1942,7 +1950,7 @@ relock:
1942 can_do_direct = direct_io; 1950 can_do_direct = direct_io;
1943 ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos, 1951 ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos,
1944 iocb->ki_left, appending, 1952 iocb->ki_left, appending,
1945 &can_do_direct); 1953 &can_do_direct, &has_refcount);
1946 if (ret < 0) { 1954 if (ret < 0) {
1947 mlog_errno(ret); 1955 mlog_errno(ret);
1948 goto out; 1956 goto out;
@@ -2006,14 +2014,16 @@ out_dio:
2006 /* buffered aio wouldn't have proper lock coverage today */ 2014 /* buffered aio wouldn't have proper lock coverage today */
2007 BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); 2015 BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT));
2008 2016
2009 if ((file->f_flags & O_SYNC && !direct_io) || IS_SYNC(inode)) { 2017 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||
2018 ((file->f_flags & O_DIRECT) && has_refcount)) {
2010 ret = filemap_fdatawrite_range(file->f_mapping, pos, 2019 ret = filemap_fdatawrite_range(file->f_mapping, pos,
2011 pos + count - 1); 2020 pos + count - 1);
2012 if (ret < 0) 2021 if (ret < 0)
2013 written = ret; 2022 written = ret;
2014 2023
2015 if (!ret && (old_size != i_size_read(inode) || 2024 if (!ret && (old_size != i_size_read(inode) ||
2016 old_clusters != OCFS2_I(inode)->ip_clusters)) { 2025 old_clusters != OCFS2_I(inode)->ip_clusters ||
2026 has_refcount)) {
2017 ret = jbd2_journal_force_commit(osb->journal->j_journal); 2027 ret = jbd2_journal_force_commit(osb->journal->j_journal);
2018 if (ret < 0) 2028 if (ret < 0)
2019 written = ret; 2029 written = ret;
@@ -2024,7 +2034,7 @@ out_dio:
2024 pos + count - 1); 2034 pos + count - 1);
2025 } 2035 }
2026 2036
2027 /* 2037 /*
2028 * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io 2038 * 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 2039 * 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 2040 * it can unlock our rw lock. (it's the clustered equivalent of
@@ -2034,7 +2044,7 @@ out_dio:
2034 * async dio is going to do it in the future or an end_io after an 2044 * async dio is going to do it in the future or an end_io after an
2035 * error has already done it. 2045 * error has already done it.
2036 */ 2046 */
2037 if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { 2047 if ((ret == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
2038 rw_level = -1; 2048 rw_level = -1;
2039 have_alloc_sem = 0; 2049 have_alloc_sem = 0;
2040 } 2050 }
@@ -2062,7 +2072,7 @@ static int ocfs2_splice_to_file(struct pipe_inode_info *pipe,
2062 int ret; 2072 int ret;
2063 2073
2064 ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, 2074 ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos,
2065 sd->total_len, 0, NULL); 2075 sd->total_len, 0, NULL, NULL);
2066 if (ret < 0) { 2076 if (ret < 0) {
2067 mlog_errno(ret); 2077 mlog_errno(ret);
2068 return ret; 2078 return ret;
@@ -2189,7 +2199,7 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2189 goto bail; 2199 goto bail;
2190 } 2200 }
2191 2201
2192 /* 2202 /*
2193 * buffered reads protect themselves in ->readpage(). O_DIRECT reads 2203 * buffered reads protect themselves in ->readpage(). O_DIRECT reads
2194 * need locks to protect pending reads from racing with truncate. 2204 * need locks to protect pending reads from racing with truncate.
2195 */ 2205 */
@@ -2211,10 +2221,10 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2211 * We're fine letting folks race truncates and extending 2221 * We're fine letting folks race truncates and extending
2212 * writes with read across the cluster, just like they can 2222 * writes with read across the cluster, just like they can
2213 * locally. Hence no rw_lock during read. 2223 * locally. Hence no rw_lock during read.
2214 * 2224 *
2215 * Take and drop the meta data lock to update inode fields 2225 * Take and drop the meta data lock to update inode fields
2216 * like i_size. This allows the checks down below 2226 * like i_size. This allows the checks down below
2217 * generic_file_aio_read() a chance of actually working. 2227 * generic_file_aio_read() a chance of actually working.
2218 */ 2228 */
2219 ret = ocfs2_inode_lock_atime(inode, filp->f_vfsmnt, &lock_level); 2229 ret = ocfs2_inode_lock_atime(inode, filp->f_vfsmnt, &lock_level);
2220 if (ret < 0) { 2230 if (ret < 0) {
@@ -2239,7 +2249,7 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
2239bail: 2249bail:
2240 if (have_alloc_sem) 2250 if (have_alloc_sem)
2241 up_read(&inode->i_alloc_sem); 2251 up_read(&inode->i_alloc_sem);
2242 if (rw_level != -1) 2252 if (rw_level != -1)
2243 ocfs2_rw_unlock(inode, rw_level); 2253 ocfs2_rw_unlock(inode, rw_level);
2244 mlog_exit(ret); 2254 mlog_exit(ret);
2245 2255