1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2002
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
9 #include <linux/posix_acl.h>
10 #include <linux/quotaops.h>
11 #include "jfs_incore.h"
12 #include "jfs_inode.h"
14 #include "jfs_txnmgr.h"
15 #include "jfs_xattr.h"
17 #include "jfs_debug.h"
19 int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
21 struct inode *inode = file->f_mapping->host;
24 rc = file_write_and_wait_range(file, start, end);
29 if (!(inode->i_state & I_DIRTY_ALL) ||
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);
37 rc |= jfs_commit_inode(inode, 1);
43 static int jfs_open(struct inode *inode, struct file *file)
47 if ((rc = dquot_file_open(inode, file)))
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.
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.
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) {
64 struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
65 ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
66 atomic_inc(&jfs_sb->bmap->db_active[ji->active_ag]);
68 spin_unlock_irq(&ji->ag_lock);
73 static int jfs_release(struct inode *inode, struct file *file)
75 struct jfs_inode_info *ji = JFS_IP(inode);
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]);
83 spin_unlock_irq(&ji->ag_lock);
88 int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
90 struct inode *inode = d_inode(dentry);
93 rc = setattr_prepare(dentry, iattr);
97 if (is_quota_modification(inode, iattr)) {
98 rc = dquot_initialize(inode);
102 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
103 (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
104 rc = dquot_transfer(inode, iattr);
109 if ((iattr->ia_valid & ATTR_SIZE) &&
110 iattr->ia_size != i_size_read(inode)) {
111 inode_dio_wait(inode);
113 rc = inode_newsize_ok(inode, iattr->ia_size);
117 truncate_setsize(inode, iattr->ia_size);
121 setattr_copy(inode, iattr);
122 mark_inode_dirty(inode);
124 if (iattr->ia_valid & ATTR_MODE)
125 rc = posix_acl_chmod(inode, inode->i_mode);
129 const struct inode_operations jfs_file_inode_operations = {
130 .listxattr = jfs_listxattr,
131 .setattr = jfs_setattr,
132 #ifdef CONFIG_JFS_POSIX_ACL
133 .get_acl = jfs_get_acl,
134 .set_acl = jfs_set_acl,
138 const struct file_operations jfs_file_operations = {
140 .llseek = generic_file_llseek,
141 .read_iter = generic_file_read_iter,
142 .write_iter = generic_file_write_iter,
143 .mmap = generic_file_mmap,
144 .splice_read = generic_file_splice_read,
145 .splice_write = iter_file_splice_write,
147 .release = jfs_release,
148 .unlocked_ioctl = jfs_ioctl,
150 .compat_ioctl = jfs_compat_ioctl,