Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1868f4aa DK |
2 | * Copyright (C) International Business Machines Corp., 2000-2002 |
3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 | |
1da177e4 LT |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
63f83c9f | 7 | * the Free Software Foundation; either version 2 of the License, or |
1da177e4 | 8 | * (at your option) any later version. |
63f83c9f | 9 | * |
1da177e4 LT |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
13 | * the GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
63f83c9f | 16 | * along with this program; if not, write to the Free Software |
1da177e4 LT |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | |
19 | ||
1025774c | 20 | #include <linux/mm.h> |
1da177e4 | 21 | #include <linux/fs.h> |
2cc6a5a0 | 22 | #include <linux/posix_acl.h> |
759bfee6 | 23 | #include <linux/quotaops.h> |
1da177e4 | 24 | #include "jfs_incore.h" |
1868f4aa | 25 | #include "jfs_inode.h" |
1da177e4 LT |
26 | #include "jfs_dmap.h" |
27 | #include "jfs_txnmgr.h" | |
28 | #include "jfs_xattr.h" | |
29 | #include "jfs_acl.h" | |
30 | #include "jfs_debug.h" | |
31 | ||
02c24a82 | 32 | int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) |
1da177e4 | 33 | { |
7ea80859 | 34 | struct inode *inode = file->f_mapping->host; |
1da177e4 LT |
35 | int rc = 0; |
36 | ||
02c24a82 JB |
37 | rc = filemap_write_and_wait_range(inode->i_mapping, start, end); |
38 | if (rc) | |
39 | return rc; | |
40 | ||
41 | mutex_lock(&inode->i_mutex); | |
0ae45f63 | 42 | if (!(inode->i_state & I_DIRTY_ALL) || |
1da177e4 LT |
43 | (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) { |
44 | /* Make sure committed changes hit the disk */ | |
45 | jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1); | |
02c24a82 | 46 | mutex_unlock(&inode->i_mutex); |
1da177e4 LT |
47 | return rc; |
48 | } | |
49 | ||
50 | rc |= jfs_commit_inode(inode, 1); | |
02c24a82 | 51 | mutex_unlock(&inode->i_mutex); |
1da177e4 LT |
52 | |
53 | return rc ? -EIO : 0; | |
54 | } | |
55 | ||
56 | static int jfs_open(struct inode *inode, struct file *file) | |
57 | { | |
58 | int rc; | |
59 | ||
907f4554 | 60 | if ((rc = dquot_file_open(inode, file))) |
1da177e4 LT |
61 | return rc; |
62 | ||
63 | /* | |
64 | * We attempt to allow only one "active" file open per aggregate | |
65 | * group. Otherwise, appending to files in parallel can cause | |
66 | * fragmentation within the files. | |
67 | * | |
68 | * If the file is empty, it was probably just created and going | |
69 | * to be written to. If it has a size, we'll hold off until the | |
70 | * file is actually grown. | |
71 | */ | |
72 | if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE && | |
73 | (inode->i_size == 0)) { | |
74 | struct jfs_inode_info *ji = JFS_IP(inode); | |
75 | spin_lock_irq(&ji->ag_lock); | |
76 | if (ji->active_ag == -1) { | |
d31b53e3 DK |
77 | struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb); |
78 | ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb); | |
55a8d02b | 79 | atomic_inc(&jfs_sb->bmap->db_active[ji->active_ag]); |
1da177e4 LT |
80 | } |
81 | spin_unlock_irq(&ji->ag_lock); | |
82 | } | |
83 | ||
84 | return 0; | |
85 | } | |
86 | static int jfs_release(struct inode *inode, struct file *file) | |
87 | { | |
88 | struct jfs_inode_info *ji = JFS_IP(inode); | |
89 | ||
90 | spin_lock_irq(&ji->ag_lock); | |
91 | if (ji->active_ag != -1) { | |
92 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; | |
93 | atomic_dec(&bmap->db_active[ji->active_ag]); | |
94 | ji->active_ag = -1; | |
95 | } | |
96 | spin_unlock_irq(&ji->ag_lock); | |
97 | ||
98 | return 0; | |
99 | } | |
100 | ||
759bfee6 CH |
101 | int jfs_setattr(struct dentry *dentry, struct iattr *iattr) |
102 | { | |
2b0143b5 | 103 | struct inode *inode = d_inode(dentry); |
759bfee6 CH |
104 | int rc; |
105 | ||
106 | rc = inode_change_ok(inode, iattr); | |
107 | if (rc) | |
108 | return rc; | |
109 | ||
12755627 | 110 | if (is_quota_modification(inode, iattr)) |
871a2931 | 111 | dquot_initialize(inode); |
c18cdc1a EB |
112 | if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) || |
113 | (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) { | |
b43fa828 CH |
114 | rc = dquot_transfer(inode, iattr); |
115 | if (rc) | |
116 | return rc; | |
759bfee6 CH |
117 | } |
118 | ||
1025774c CH |
119 | if ((iattr->ia_valid & ATTR_SIZE) && |
120 | iattr->ia_size != i_size_read(inode)) { | |
562c72aa CH |
121 | inode_dio_wait(inode); |
122 | ||
86dd07d6 | 123 | rc = inode_newsize_ok(inode, iattr->ia_size); |
1025774c CH |
124 | if (rc) |
125 | return rc; | |
86dd07d6 MS |
126 | |
127 | truncate_setsize(inode, iattr->ia_size); | |
128 | jfs_truncate(inode); | |
1025774c | 129 | } |
759bfee6 | 130 | |
1025774c CH |
131 | setattr_copy(inode, iattr); |
132 | mark_inode_dirty(inode); | |
759bfee6 | 133 | |
1025774c | 134 | if (iattr->ia_valid & ATTR_MODE) |
2cc6a5a0 | 135 | rc = posix_acl_chmod(inode, inode->i_mode); |
759bfee6 CH |
136 | return rc; |
137 | } | |
138 | ||
92e1d5be | 139 | const struct inode_operations jfs_file_inode_operations = { |
1da177e4 LT |
140 | .setxattr = jfs_setxattr, |
141 | .getxattr = jfs_getxattr, | |
142 | .listxattr = jfs_listxattr, | |
143 | .removexattr = jfs_removexattr, | |
1da177e4 | 144 | .setattr = jfs_setattr, |
759bfee6 | 145 | #ifdef CONFIG_JFS_POSIX_ACL |
4e34e719 | 146 | .get_acl = jfs_get_acl, |
2cc6a5a0 | 147 | .set_acl = jfs_set_acl, |
1da177e4 LT |
148 | #endif |
149 | }; | |
150 | ||
4b6f5d20 | 151 | const struct file_operations jfs_file_operations = { |
1da177e4 LT |
152 | .open = jfs_open, |
153 | .llseek = generic_file_llseek, | |
aad4f8bb | 154 | .read_iter = generic_file_read_iter, |
8174202b | 155 | .write_iter = generic_file_write_iter, |
1da177e4 | 156 | .mmap = generic_file_mmap, |
89f68225 | 157 | .splice_read = generic_file_splice_read, |
8d020765 | 158 | .splice_write = iter_file_splice_write, |
1da177e4 LT |
159 | .fsync = jfs_fsync, |
160 | .release = jfs_release, | |
baab81fa | 161 | .unlocked_ioctl = jfs_ioctl, |
ef1fc2f0 AK |
162 | #ifdef CONFIG_COMPAT |
163 | .compat_ioctl = jfs_compat_ioctl, | |
164 | #endif | |
1da177e4 | 165 | }; |