]>
Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 | 2 | /* |
1868f4aa DK |
3 | * Copyright (C) International Business Machines Corp., 2000-2002 |
4 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 | |
1da177e4 LT |
5 | */ |
6 | ||
1025774c | 7 | #include <linux/mm.h> |
1da177e4 | 8 | #include <linux/fs.h> |
2cc6a5a0 | 9 | #include <linux/posix_acl.h> |
759bfee6 | 10 | #include <linux/quotaops.h> |
1da177e4 | 11 | #include "jfs_incore.h" |
1868f4aa | 12 | #include "jfs_inode.h" |
1da177e4 LT |
13 | #include "jfs_dmap.h" |
14 | #include "jfs_txnmgr.h" | |
15 | #include "jfs_xattr.h" | |
16 | #include "jfs_acl.h" | |
17 | #include "jfs_debug.h" | |
18 | ||
02c24a82 | 19 | int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) |
1da177e4 | 20 | { |
7ea80859 | 21 | struct inode *inode = file->f_mapping->host; |
1da177e4 LT |
22 | int rc = 0; |
23 | ||
3b49c9a1 | 24 | rc = file_write_and_wait_range(file, start, end); |
02c24a82 JB |
25 | if (rc) |
26 | return rc; | |
27 | ||
5955102c | 28 | inode_lock(inode); |
0ae45f63 | 29 | if (!(inode->i_state & I_DIRTY_ALL) || |
1da177e4 LT |
30 | (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) { |
31 | /* Make sure committed changes hit the disk */ | |
32 | jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1); | |
5955102c | 33 | inode_unlock(inode); |
1da177e4 LT |
34 | return rc; |
35 | } | |
36 | ||
37 | rc |= jfs_commit_inode(inode, 1); | |
5955102c | 38 | inode_unlock(inode); |
1da177e4 LT |
39 | |
40 | return rc ? -EIO : 0; | |
41 | } | |
42 | ||
43 | static int jfs_open(struct inode *inode, struct file *file) | |
44 | { | |
45 | int rc; | |
46 | ||
907f4554 | 47 | if ((rc = dquot_file_open(inode, file))) |
1da177e4 LT |
48 | return rc; |
49 | ||
50 | /* | |
51 | * We attempt to allow only one "active" file open per aggregate | |
52 | * group. Otherwise, appending to files in parallel can cause | |
53 | * fragmentation within the files. | |
54 | * | |
55 | * If the file is empty, it was probably just created and going | |
56 | * to be written to. If it has a size, we'll hold off until the | |
57 | * file is actually grown. | |
58 | */ | |
59 | if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE && | |
60 | (inode->i_size == 0)) { | |
61 | struct jfs_inode_info *ji = JFS_IP(inode); | |
62 | spin_lock_irq(&ji->ag_lock); | |
63 | if (ji->active_ag == -1) { | |
d31b53e3 DK |
64 | struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb); |
65 | ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb); | |
55a8d02b | 66 | atomic_inc(&jfs_sb->bmap->db_active[ji->active_ag]); |
1da177e4 LT |
67 | } |
68 | spin_unlock_irq(&ji->ag_lock); | |
69 | } | |
70 | ||
71 | return 0; | |
72 | } | |
73 | static int jfs_release(struct inode *inode, struct file *file) | |
74 | { | |
75 | struct jfs_inode_info *ji = JFS_IP(inode); | |
76 | ||
77 | spin_lock_irq(&ji->ag_lock); | |
78 | if (ji->active_ag != -1) { | |
79 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; | |
80 | atomic_dec(&bmap->db_active[ji->active_ag]); | |
81 | ji->active_ag = -1; | |
82 | } | |
83 | spin_unlock_irq(&ji->ag_lock); | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
c1632a0f | 88 | int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, |
549c7297 | 89 | struct iattr *iattr) |
759bfee6 | 90 | { |
2b0143b5 | 91 | struct inode *inode = d_inode(dentry); |
759bfee6 CH |
92 | int rc; |
93 | ||
c1632a0f | 94 | rc = setattr_prepare(&nop_mnt_idmap, dentry, iattr); |
759bfee6 CH |
95 | if (rc) |
96 | return rc; | |
97 | ||
f861646a | 98 | if (is_quota_modification(&nop_mnt_idmap, inode, iattr)) { |
acc84b05 DK |
99 | rc = dquot_initialize(inode); |
100 | if (rc) | |
101 | return rc; | |
102 | } | |
c18cdc1a EB |
103 | if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) || |
104 | (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) { | |
f861646a | 105 | rc = dquot_transfer(&nop_mnt_idmap, inode, iattr); |
b43fa828 CH |
106 | if (rc) |
107 | return rc; | |
759bfee6 CH |
108 | } |
109 | ||
1025774c CH |
110 | if ((iattr->ia_valid & ATTR_SIZE) && |
111 | iattr->ia_size != i_size_read(inode)) { | |
562c72aa CH |
112 | inode_dio_wait(inode); |
113 | ||
86dd07d6 | 114 | rc = inode_newsize_ok(inode, iattr->ia_size); |
1025774c CH |
115 | if (rc) |
116 | return rc; | |
86dd07d6 MS |
117 | |
118 | truncate_setsize(inode, iattr->ia_size); | |
119 | jfs_truncate(inode); | |
1025774c | 120 | } |
759bfee6 | 121 | |
c1632a0f | 122 | setattr_copy(&nop_mnt_idmap, inode, iattr); |
1025774c | 123 | mark_inode_dirty(inode); |
759bfee6 | 124 | |
1025774c | 125 | if (iattr->ia_valid & ATTR_MODE) |
13e83a49 | 126 | rc = posix_acl_chmod(&nop_mnt_idmap, dentry, inode->i_mode); |
759bfee6 CH |
127 | return rc; |
128 | } | |
129 | ||
92e1d5be | 130 | const struct inode_operations jfs_file_inode_operations = { |
1da177e4 | 131 | .listxattr = jfs_listxattr, |
1da177e4 | 132 | .setattr = jfs_setattr, |
2ca58e30 MS |
133 | .fileattr_get = jfs_fileattr_get, |
134 | .fileattr_set = jfs_fileattr_set, | |
759bfee6 | 135 | #ifdef CONFIG_JFS_POSIX_ACL |
cac2f8b8 | 136 | .get_inode_acl = jfs_get_acl, |
2cc6a5a0 | 137 | .set_acl = jfs_set_acl, |
1da177e4 LT |
138 | #endif |
139 | }; | |
140 | ||
4b6f5d20 | 141 | const struct file_operations jfs_file_operations = { |
1da177e4 LT |
142 | .open = jfs_open, |
143 | .llseek = generic_file_llseek, | |
aad4f8bb | 144 | .read_iter = generic_file_read_iter, |
8174202b | 145 | .write_iter = generic_file_write_iter, |
1da177e4 | 146 | .mmap = generic_file_mmap, |
2cb1e089 | 147 | .splice_read = filemap_splice_read, |
8d020765 | 148 | .splice_write = iter_file_splice_write, |
1da177e4 LT |
149 | .fsync = jfs_fsync, |
150 | .release = jfs_release, | |
baab81fa | 151 | .unlocked_ioctl = jfs_ioctl, |
2ca58e30 | 152 | .compat_ioctl = compat_ptr_ioctl, |
1da177e4 | 153 | }; |