aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/file.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2006-12-05 12:01:28 -0500
committerDavid Howells <dhowells@warthog.cambridge.redhat.com>2006-12-05 12:01:28 -0500
commit9db73724453a9350e1c22dbe732d427e2939a5c9 (patch)
tree15e3ead6413ae97398a54292acc199bee0864d42 /fs/ocfs2/file.c
parent4c1ac1b49122b805adfa4efc620592f68dccf5db (diff)
parente62438630ca37539c8cc1553710bbfaa3cf960a7 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts: drivers/ata/libata-scsi.c include/linux/libata.h Futher merge of Linus's head and compilation fixups. Signed-Off-By: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r--fs/ocfs2/file.c343
1 files changed, 239 insertions, 104 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 1be74c4e7814..8786b3c490aa 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -31,6 +31,8 @@
31#include <linux/pagemap.h> 31#include <linux/pagemap.h>
32#include <linux/uio.h> 32#include <linux/uio.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/pipe_fs_i.h>
35#include <linux/mount.h>
34 36
35#define MLOG_MASK_PREFIX ML_INODE 37#define MLOG_MASK_PREFIX ML_INODE
36#include <cluster/masklog.h> 38#include <cluster/masklog.h>
@@ -134,7 +136,58 @@ bail:
134 return (err < 0) ? -EIO : 0; 136 return (err < 0) ? -EIO : 0;
135} 137}
136 138
137int ocfs2_set_inode_size(struct ocfs2_journal_handle *handle, 139int ocfs2_should_update_atime(struct inode *inode,
140 struct vfsmount *vfsmnt)
141{
142 struct timespec now;
143 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
144
145 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
146 return 0;
147
148 if ((inode->i_flags & S_NOATIME) ||
149 ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode)))
150 return 0;
151
152 if ((vfsmnt->mnt_flags & MNT_NOATIME) ||
153 ((vfsmnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
154 return 0;
155
156 now = CURRENT_TIME;
157 if ((now.tv_sec - inode->i_atime.tv_sec <= osb->s_atime_quantum))
158 return 0;
159 else
160 return 1;
161}
162
163int ocfs2_update_inode_atime(struct inode *inode,
164 struct buffer_head *bh)
165{
166 int ret;
167 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
168 handle_t *handle;
169
170 mlog_entry_void();
171
172 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
173 if (handle == NULL) {
174 ret = -ENOMEM;
175 mlog_errno(ret);
176 goto out;
177 }
178
179 inode->i_atime = CURRENT_TIME;
180 ret = ocfs2_mark_inode_dirty(handle, inode, bh);
181 if (ret < 0)
182 mlog_errno(ret);
183
184 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
185out:
186 mlog_exit(ret);
187 return ret;
188}
189
190int ocfs2_set_inode_size(handle_t *handle,
138 struct inode *inode, 191 struct inode *inode,
139 struct buffer_head *fe_bh, 192 struct buffer_head *fe_bh,
140 u64 new_i_size) 193 u64 new_i_size)
@@ -163,10 +216,9 @@ static int ocfs2_simple_size_update(struct inode *inode,
163{ 216{
164 int ret; 217 int ret;
165 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 218 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
166 struct ocfs2_journal_handle *handle = NULL; 219 handle_t *handle = NULL;
167 220
168 handle = ocfs2_start_trans(osb, NULL, 221 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
169 OCFS2_INODE_UPDATE_CREDITS);
170 if (handle == NULL) { 222 if (handle == NULL) {
171 ret = -ENOMEM; 223 ret = -ENOMEM;
172 mlog_errno(ret); 224 mlog_errno(ret);
@@ -178,7 +230,7 @@ static int ocfs2_simple_size_update(struct inode *inode,
178 if (ret < 0) 230 if (ret < 0)
179 mlog_errno(ret); 231 mlog_errno(ret);
180 232
181 ocfs2_commit_trans(handle); 233 ocfs2_commit_trans(osb, handle);
182out: 234out:
183 return ret; 235 return ret;
184} 236}
@@ -189,14 +241,14 @@ static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
189 u64 new_i_size) 241 u64 new_i_size)
190{ 242{
191 int status; 243 int status;
192 struct ocfs2_journal_handle *handle; 244 handle_t *handle;
193 245
194 mlog_entry_void(); 246 mlog_entry_void();
195 247
196 /* TODO: This needs to actually orphan the inode in this 248 /* TODO: This needs to actually orphan the inode in this
197 * transaction. */ 249 * transaction. */
198 250
199 handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS); 251 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
200 if (IS_ERR(handle)) { 252 if (IS_ERR(handle)) {
201 status = PTR_ERR(handle); 253 status = PTR_ERR(handle);
202 mlog_errno(status); 254 mlog_errno(status);
@@ -207,7 +259,7 @@ static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
207 if (status < 0) 259 if (status < 0)
208 mlog_errno(status); 260 mlog_errno(status);
209 261
210 ocfs2_commit_trans(handle); 262 ocfs2_commit_trans(osb, handle);
211out: 263out:
212 mlog_exit(status); 264 mlog_exit(status);
213 return status; 265 return status;
@@ -328,7 +380,7 @@ int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
328 struct inode *inode, 380 struct inode *inode,
329 u32 clusters_to_add, 381 u32 clusters_to_add,
330 struct buffer_head *fe_bh, 382 struct buffer_head *fe_bh,
331 struct ocfs2_journal_handle *handle, 383 handle_t *handle,
332 struct ocfs2_alloc_context *data_ac, 384 struct ocfs2_alloc_context *data_ac,
333 struct ocfs2_alloc_context *meta_ac, 385 struct ocfs2_alloc_context *meta_ac,
334 enum ocfs2_alloc_restarted *reason_ret) 386 enum ocfs2_alloc_restarted *reason_ret)
@@ -433,7 +485,7 @@ static int ocfs2_extend_allocation(struct inode *inode,
433 u32 prev_clusters; 485 u32 prev_clusters;
434 struct buffer_head *bh = NULL; 486 struct buffer_head *bh = NULL;
435 struct ocfs2_dinode *fe = NULL; 487 struct ocfs2_dinode *fe = NULL;
436 struct ocfs2_journal_handle *handle = NULL; 488 handle_t *handle = NULL;
437 struct ocfs2_alloc_context *data_ac = NULL; 489 struct ocfs2_alloc_context *data_ac = NULL;
438 struct ocfs2_alloc_context *meta_ac = NULL; 490 struct ocfs2_alloc_context *meta_ac = NULL;
439 enum ocfs2_alloc_restarted why; 491 enum ocfs2_alloc_restarted why;
@@ -463,13 +515,6 @@ restart_all:
463 (unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode), 515 (unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode),
464 fe->i_clusters, clusters_to_add); 516 fe->i_clusters, clusters_to_add);
465 517
466 handle = ocfs2_alloc_handle(osb);
467 if (handle == NULL) {
468 status = -ENOMEM;
469 mlog_errno(status);
470 goto leave;
471 }
472
473 num_free_extents = ocfs2_num_free_extents(osb, 518 num_free_extents = ocfs2_num_free_extents(osb,
474 inode, 519 inode,
475 fe); 520 fe);
@@ -480,10 +525,7 @@ restart_all:
480 } 525 }
481 526
482 if (!num_free_extents) { 527 if (!num_free_extents) {
483 status = ocfs2_reserve_new_metadata(osb, 528 status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
484 handle,
485 fe,
486 &meta_ac);
487 if (status < 0) { 529 if (status < 0) {
488 if (status != -ENOSPC) 530 if (status != -ENOSPC)
489 mlog_errno(status); 531 mlog_errno(status);
@@ -491,10 +533,7 @@ restart_all:
491 } 533 }
492 } 534 }
493 535
494 status = ocfs2_reserve_clusters(osb, 536 status = ocfs2_reserve_clusters(osb, clusters_to_add, &data_ac);
495 handle,
496 clusters_to_add,
497 &data_ac);
498 if (status < 0) { 537 if (status < 0) {
499 if (status != -ENOSPC) 538 if (status != -ENOSPC)
500 mlog_errno(status); 539 mlog_errno(status);
@@ -509,7 +548,7 @@ restart_all:
509 drop_alloc_sem = 1; 548 drop_alloc_sem = 1;
510 549
511 credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add); 550 credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add);
512 handle = ocfs2_start_trans(osb, handle, credits); 551 handle = ocfs2_start_trans(osb, credits);
513 if (IS_ERR(handle)) { 552 if (IS_ERR(handle)) {
514 status = PTR_ERR(handle); 553 status = PTR_ERR(handle);
515 handle = NULL; 554 handle = NULL;
@@ -589,7 +628,7 @@ leave:
589 drop_alloc_sem = 0; 628 drop_alloc_sem = 0;
590 } 629 }
591 if (handle) { 630 if (handle) {
592 ocfs2_commit_trans(handle); 631 ocfs2_commit_trans(osb, handle);
593 handle = NULL; 632 handle = NULL;
594 } 633 }
595 if (data_ac) { 634 if (data_ac) {
@@ -624,7 +663,7 @@ static int ocfs2_write_zero_page(struct inode *inode,
624 struct page *page; 663 struct page *page;
625 unsigned long index; 664 unsigned long index;
626 unsigned int offset; 665 unsigned int offset;
627 struct ocfs2_journal_handle *handle = NULL; 666 handle_t *handle = NULL;
628 int ret; 667 int ret;
629 668
630 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */ 669 offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */
@@ -668,7 +707,7 @@ static int ocfs2_write_zero_page(struct inode *inode,
668 ret = 0; 707 ret = 0;
669 708
670 if (handle) 709 if (handle)
671 ocfs2_commit_trans(handle); 710 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
672out_unlock: 711out_unlock:
673 unlock_page(page); 712 unlock_page(page);
674 page_cache_release(page); 713 page_cache_release(page);
@@ -789,7 +828,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
789 struct super_block *sb = inode->i_sb; 828 struct super_block *sb = inode->i_sb;
790 struct ocfs2_super *osb = OCFS2_SB(sb); 829 struct ocfs2_super *osb = OCFS2_SB(sb);
791 struct buffer_head *bh = NULL; 830 struct buffer_head *bh = NULL;
792 struct ocfs2_journal_handle *handle = NULL; 831 handle_t *handle = NULL;
793 832
794 mlog_entry("(0x%p, '%.*s')\n", dentry, 833 mlog_entry("(0x%p, '%.*s')\n", dentry,
795 dentry->d_name.len, dentry->d_name.name); 834 dentry->d_name.len, dentry->d_name.name);
@@ -825,7 +864,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
825 } 864 }
826 } 865 }
827 866
828 status = ocfs2_meta_lock(inode, NULL, &bh, 1); 867 status = ocfs2_meta_lock(inode, &bh, 1);
829 if (status < 0) { 868 if (status < 0) {
830 if (status != -ENOENT) 869 if (status != -ENOENT)
831 mlog_errno(status); 870 mlog_errno(status);
@@ -845,7 +884,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
845 } 884 }
846 } 885 }
847 886
848 handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS); 887 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
849 if (IS_ERR(handle)) { 888 if (IS_ERR(handle)) {
850 status = PTR_ERR(handle); 889 status = PTR_ERR(handle);
851 mlog_errno(status); 890 mlog_errno(status);
@@ -863,7 +902,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
863 mlog_errno(status); 902 mlog_errno(status);
864 903
865bail_commit: 904bail_commit:
866 ocfs2_commit_trans(handle); 905 ocfs2_commit_trans(osb, handle);
867bail_unlock: 906bail_unlock:
868 ocfs2_meta_unlock(inode, 1); 907 ocfs2_meta_unlock(inode, 1);
869bail_unlock_rw: 908bail_unlock_rw:
@@ -906,19 +945,41 @@ bail:
906 return err; 945 return err;
907} 946}
908 947
948int ocfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
949{
950 int ret;
951
952 mlog_entry_void();
953
954 ret = ocfs2_meta_lock(inode, NULL, 0);
955 if (ret) {
956 mlog_errno(ret);
957 goto out;
958 }
959
960 ret = generic_permission(inode, mask, NULL);
961 if (ret)
962 mlog_errno(ret);
963
964 ocfs2_meta_unlock(inode, 0);
965out:
966 mlog_exit(ret);
967 return ret;
968}
969
909static int ocfs2_write_remove_suid(struct inode *inode) 970static int ocfs2_write_remove_suid(struct inode *inode)
910{ 971{
911 int ret; 972 int ret;
912 struct buffer_head *bh = NULL; 973 struct buffer_head *bh = NULL;
913 struct ocfs2_inode_info *oi = OCFS2_I(inode); 974 struct ocfs2_inode_info *oi = OCFS2_I(inode);
914 struct ocfs2_journal_handle *handle; 975 handle_t *handle;
915 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 976 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
916 struct ocfs2_dinode *di; 977 struct ocfs2_dinode *di;
917 978
918 mlog_entry("(Inode %llu, mode 0%o)\n", 979 mlog_entry("(Inode %llu, mode 0%o)\n",
919 (unsigned long long)oi->ip_blkno, inode->i_mode); 980 (unsigned long long)oi->ip_blkno, inode->i_mode);
920 981
921 handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS); 982 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
922 if (handle == NULL) { 983 if (handle == NULL) {
923 ret = -ENOMEM; 984 ret = -ENOMEM;
924 mlog_errno(ret); 985 mlog_errno(ret);
@@ -951,75 +1012,29 @@ static int ocfs2_write_remove_suid(struct inode *inode)
951out_bh: 1012out_bh:
952 brelse(bh); 1013 brelse(bh);
953out_trans: 1014out_trans:
954 ocfs2_commit_trans(handle); 1015 ocfs2_commit_trans(osb, handle);
955out: 1016out:
956 mlog_exit(ret); 1017 mlog_exit(ret);
957 return ret; 1018 return ret;
958} 1019}
959 1020
960static inline int ocfs2_write_should_remove_suid(struct inode *inode) 1021static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
961{ 1022 loff_t *ppos,
962 mode_t mode = inode->i_mode; 1023 size_t count,
963 1024 int appending)
964 if (!capable(CAP_FSETID)) {
965 if (unlikely(mode & S_ISUID))
966 return 1;
967
968 if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
969 return 1;
970 }
971 return 0;
972}
973
974static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
975 const struct iovec *iov,
976 unsigned long nr_segs,
977 loff_t pos)
978{ 1025{
979 int ret, rw_level = -1, meta_level = -1, have_alloc_sem = 0; 1026 int ret = 0, meta_level = appending;
1027 struct inode *inode = dentry->d_inode;
980 u32 clusters; 1028 u32 clusters;
981 struct file *filp = iocb->ki_filp;
982 struct inode *inode = filp->f_dentry->d_inode;
983 loff_t newsize, saved_pos; 1029 loff_t newsize, saved_pos;
984 1030
985 mlog_entry("(0x%p, %u, '%.*s')\n", filp,
986 (unsigned int)nr_segs,
987 filp->f_dentry->d_name.len,
988 filp->f_dentry->d_name.name);
989
990 /* happy write of zero bytes */
991 if (iocb->ki_left == 0)
992 return 0;
993
994 if (!inode) {
995 mlog(0, "bad inode\n");
996 return -EIO;
997 }
998
999 mutex_lock(&inode->i_mutex);
1000 /* to match setattr's i_mutex -> i_alloc_sem -> rw_lock ordering */
1001 if (filp->f_flags & O_DIRECT) {
1002 have_alloc_sem = 1;
1003 down_read(&inode->i_alloc_sem);
1004 }
1005
1006 /* concurrent O_DIRECT writes are allowed */
1007 rw_level = (filp->f_flags & O_DIRECT) ? 0 : 1;
1008 ret = ocfs2_rw_lock(inode, rw_level);
1009 if (ret < 0) {
1010 rw_level = -1;
1011 mlog_errno(ret);
1012 goto out;
1013 }
1014
1015 /* 1031 /*
1016 * We sample i_size under a read level meta lock to see if our write 1032 * We sample i_size under a read level meta lock to see if our write
1017 * is extending the file, if it is we back off and get a write level 1033 * is extending the file, if it is we back off and get a write level
1018 * meta lock. 1034 * meta lock.
1019 */ 1035 */
1020 meta_level = (filp->f_flags & O_APPEND) ? 1 : 0;
1021 for(;;) { 1036 for(;;) {
1022 ret = ocfs2_meta_lock(inode, NULL, NULL, meta_level); 1037 ret = ocfs2_meta_lock(inode, NULL, meta_level);
1023 if (ret < 0) { 1038 if (ret < 0) {
1024 meta_level = -1; 1039 meta_level = -1;
1025 mlog_errno(ret); 1040 mlog_errno(ret);
@@ -1035,7 +1050,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1035 * inode. There's also the dinode i_size state which 1050 * inode. There's also the dinode i_size state which
1036 * can be lost via setattr during extending writes (we 1051 * can be lost via setattr during extending writes (we
1037 * set inode->i_size at the end of a write. */ 1052 * set inode->i_size at the end of a write. */
1038 if (ocfs2_write_should_remove_suid(inode)) { 1053 if (should_remove_suid(dentry)) {
1039 if (meta_level == 0) { 1054 if (meta_level == 0) {
1040 ocfs2_meta_unlock(inode, meta_level); 1055 ocfs2_meta_unlock(inode, meta_level);
1041 meta_level = 1; 1056 meta_level = 1;
@@ -1045,19 +1060,19 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1045 ret = ocfs2_write_remove_suid(inode); 1060 ret = ocfs2_write_remove_suid(inode);
1046 if (ret < 0) { 1061 if (ret < 0) {
1047 mlog_errno(ret); 1062 mlog_errno(ret);
1048 goto out; 1063 goto out_unlock;
1049 } 1064 }
1050 } 1065 }
1051 1066
1052 /* work on a copy of ppos until we're sure that we won't have 1067 /* work on a copy of ppos until we're sure that we won't have
1053 * to recalculate it due to relocking. */ 1068 * to recalculate it due to relocking. */
1054 if (filp->f_flags & O_APPEND) { 1069 if (appending) {
1055 saved_pos = i_size_read(inode); 1070 saved_pos = i_size_read(inode);
1056 mlog(0, "O_APPEND: inode->i_size=%llu\n", saved_pos); 1071 mlog(0, "O_APPEND: inode->i_size=%llu\n", saved_pos);
1057 } else { 1072 } else {
1058 saved_pos = iocb->ki_pos; 1073 saved_pos = *ppos;
1059 } 1074 }
1060 newsize = iocb->ki_left + saved_pos; 1075 newsize = count + saved_pos;
1061 1076
1062 mlog(0, "pos=%lld newsize=%lld cursize=%lld\n", 1077 mlog(0, "pos=%lld newsize=%lld cursize=%lld\n",
1063 (long long) saved_pos, (long long) newsize, 1078 (long long) saved_pos, (long long) newsize,
@@ -1090,19 +1105,66 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1090 if (!clusters) 1105 if (!clusters)
1091 break; 1106 break;
1092 1107
1093 ret = ocfs2_extend_file(inode, NULL, newsize, iocb->ki_left); 1108 ret = ocfs2_extend_file(inode, NULL, newsize, count);
1094 if (ret < 0) { 1109 if (ret < 0) {
1095 if (ret != -ENOSPC) 1110 if (ret != -ENOSPC)
1096 mlog_errno(ret); 1111 mlog_errno(ret);
1097 goto out; 1112 goto out_unlock;
1098 } 1113 }
1099 break; 1114 break;
1100 } 1115 }
1101 1116
1102 /* ok, we're done with i_size and alloc work */ 1117 if (appending)
1103 iocb->ki_pos = saved_pos; 1118 *ppos = saved_pos;
1119
1120out_unlock:
1104 ocfs2_meta_unlock(inode, meta_level); 1121 ocfs2_meta_unlock(inode, meta_level);
1105 meta_level = -1; 1122
1123out:
1124 return ret;
1125}
1126
1127static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1128 const struct iovec *iov,
1129 unsigned long nr_segs,
1130 loff_t pos)
1131{
1132 int ret, rw_level, have_alloc_sem = 0;
1133 struct file *filp = iocb->ki_filp;
1134 struct inode *inode = filp->f_dentry->d_inode;
1135 int appending = filp->f_flags & O_APPEND ? 1 : 0;
1136
1137 mlog_entry("(0x%p, %u, '%.*s')\n", filp,
1138 (unsigned int)nr_segs,
1139 filp->f_dentry->d_name.len,
1140 filp->f_dentry->d_name.name);
1141
1142 /* happy write of zero bytes */
1143 if (iocb->ki_left == 0)
1144 return 0;
1145
1146 mutex_lock(&inode->i_mutex);
1147 /* to match setattr's i_mutex -> i_alloc_sem -> rw_lock ordering */
1148 if (filp->f_flags & O_DIRECT) {
1149 have_alloc_sem = 1;
1150 down_read(&inode->i_alloc_sem);
1151 }
1152
1153 /* concurrent O_DIRECT writes are allowed */
1154 rw_level = (filp->f_flags & O_DIRECT) ? 0 : 1;
1155 ret = ocfs2_rw_lock(inode, rw_level);
1156 if (ret < 0) {
1157 rw_level = -1;
1158 mlog_errno(ret);
1159 goto out;
1160 }
1161
1162 ret = ocfs2_prepare_inode_for_write(filp->f_dentry, &iocb->ki_pos,
1163 iocb->ki_left, appending);
1164 if (ret < 0) {
1165 mlog_errno(ret);
1166 goto out;
1167 }
1106 1168
1107 /* communicate with ocfs2_dio_end_io */ 1169 /* communicate with ocfs2_dio_end_io */
1108 ocfs2_iocb_set_rw_locked(iocb); 1170 ocfs2_iocb_set_rw_locked(iocb);
@@ -1128,8 +1190,6 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1128 } 1190 }
1129 1191
1130out: 1192out:
1131 if (meta_level != -1)
1132 ocfs2_meta_unlock(inode, meta_level);
1133 if (have_alloc_sem) 1193 if (have_alloc_sem)
1134 up_read(&inode->i_alloc_sem); 1194 up_read(&inode->i_alloc_sem);
1135 if (rw_level != -1) 1195 if (rw_level != -1)
@@ -1140,12 +1200,83 @@ out:
1140 return ret; 1200 return ret;
1141} 1201}
1142 1202
1203static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
1204 struct file *out,
1205 loff_t *ppos,
1206 size_t len,
1207 unsigned int flags)
1208{
1209 int ret;
1210 struct inode *inode = out->f_dentry->d_inode;
1211
1212 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe,
1213 (unsigned int)len,
1214 out->f_dentry->d_name.len,
1215 out->f_dentry->d_name.name);
1216
1217 inode_double_lock(inode, pipe->inode);
1218
1219 ret = ocfs2_rw_lock(inode, 1);
1220 if (ret < 0) {
1221 mlog_errno(ret);
1222 goto out;
1223 }
1224
1225 ret = ocfs2_prepare_inode_for_write(out->f_dentry, ppos, len, 0);
1226 if (ret < 0) {
1227 mlog_errno(ret);
1228 goto out_unlock;
1229 }
1230
1231 /* ok, we're done with i_size and alloc work */
1232 ret = generic_file_splice_write_nolock(pipe, out, ppos, len, flags);
1233
1234out_unlock:
1235 ocfs2_rw_unlock(inode, 1);
1236out:
1237 inode_double_unlock(inode, pipe->inode);
1238
1239 mlog_exit(ret);
1240 return ret;
1241}
1242
1243static ssize_t ocfs2_file_splice_read(struct file *in,
1244 loff_t *ppos,
1245 struct pipe_inode_info *pipe,
1246 size_t len,
1247 unsigned int flags)
1248{
1249 int ret = 0;
1250 struct inode *inode = in->f_dentry->d_inode;
1251
1252 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", in, pipe,
1253 (unsigned int)len,
1254 in->f_dentry->d_name.len,
1255 in->f_dentry->d_name.name);
1256
1257 /*
1258 * See the comment in ocfs2_file_aio_read()
1259 */
1260 ret = ocfs2_meta_lock(inode, NULL, 0);
1261 if (ret < 0) {
1262 mlog_errno(ret);
1263 goto bail;
1264 }
1265 ocfs2_meta_unlock(inode, 0);
1266
1267 ret = generic_file_splice_read(in, ppos, pipe, len, flags);
1268
1269bail:
1270 mlog_exit(ret);
1271 return ret;
1272}
1273
1143static ssize_t ocfs2_file_aio_read(struct kiocb *iocb, 1274static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1144 const struct iovec *iov, 1275 const struct iovec *iov,
1145 unsigned long nr_segs, 1276 unsigned long nr_segs,
1146 loff_t pos) 1277 loff_t pos)
1147{ 1278{
1148 int ret = 0, rw_level = -1, have_alloc_sem = 0; 1279 int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
1149 struct file *filp = iocb->ki_filp; 1280 struct file *filp = iocb->ki_filp;
1150 struct inode *inode = filp->f_dentry->d_inode; 1281 struct inode *inode = filp->f_dentry->d_inode;
1151 1282
@@ -1187,12 +1318,12 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1187 * like i_size. This allows the checks down below 1318 * like i_size. This allows the checks down below
1188 * generic_file_aio_read() a chance of actually working. 1319 * generic_file_aio_read() a chance of actually working.
1189 */ 1320 */
1190 ret = ocfs2_meta_lock(inode, NULL, NULL, 0); 1321 ret = ocfs2_meta_lock_atime(inode, filp->f_vfsmnt, &lock_level);
1191 if (ret < 0) { 1322 if (ret < 0) {
1192 mlog_errno(ret); 1323 mlog_errno(ret);
1193 goto bail; 1324 goto bail;
1194 } 1325 }
1195 ocfs2_meta_unlock(inode, 0); 1326 ocfs2_meta_unlock(inode, lock_level);
1196 1327
1197 ret = generic_file_aio_read(iocb, iov, nr_segs, iocb->ki_pos); 1328 ret = generic_file_aio_read(iocb, iov, nr_segs, iocb->ki_pos);
1198 if (ret == -EINVAL) 1329 if (ret == -EINVAL)
@@ -1220,11 +1351,13 @@ bail:
1220struct inode_operations ocfs2_file_iops = { 1351struct inode_operations ocfs2_file_iops = {
1221 .setattr = ocfs2_setattr, 1352 .setattr = ocfs2_setattr,
1222 .getattr = ocfs2_getattr, 1353 .getattr = ocfs2_getattr,
1354 .permission = ocfs2_permission,
1223}; 1355};
1224 1356
1225struct inode_operations ocfs2_special_file_iops = { 1357struct inode_operations ocfs2_special_file_iops = {
1226 .setattr = ocfs2_setattr, 1358 .setattr = ocfs2_setattr,
1227 .getattr = ocfs2_getattr, 1359 .getattr = ocfs2_getattr,
1360 .permission = ocfs2_permission,
1228}; 1361};
1229 1362
1230const struct file_operations ocfs2_fops = { 1363const struct file_operations ocfs2_fops = {
@@ -1238,6 +1371,8 @@ const struct file_operations ocfs2_fops = {
1238 .aio_read = ocfs2_file_aio_read, 1371 .aio_read = ocfs2_file_aio_read,
1239 .aio_write = ocfs2_file_aio_write, 1372 .aio_write = ocfs2_file_aio_write,
1240 .ioctl = ocfs2_ioctl, 1373 .ioctl = ocfs2_ioctl,
1374 .splice_read = ocfs2_file_splice_read,
1375 .splice_write = ocfs2_file_splice_write,
1241}; 1376};
1242 1377
1243const struct file_operations ocfs2_dops = { 1378const struct file_operations ocfs2_dops = {