2 * Copyright (C) International Business Machines Corp., 2000-2002
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
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
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/quotaops.h>
23 #include "jfs_incore.h"
24 #include "jfs_inode.h"
26 #include "jfs_txnmgr.h"
27 #include "jfs_xattr.h"
29 #include "jfs_debug.h"
31 int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
33 struct inode *inode = file->f_mapping->host;
36 rc = filemap_write_and_wait_range(inode->i_mapping, start, end);
40 mutex_lock(&inode->i_mutex);
41 if (!(inode->i_state & I_DIRTY) ||
42 (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
43 /* Make sure committed changes hit the disk */
44 jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
45 mutex_unlock(&inode->i_mutex);
49 rc |= jfs_commit_inode(inode, 1);
50 mutex_unlock(&inode->i_mutex);
55 static int jfs_open(struct inode *inode, struct file *file)
59 if ((rc = dquot_file_open(inode, file)))
63 * We attempt to allow only one "active" file open per aggregate
64 * group. Otherwise, appending to files in parallel can cause
65 * fragmentation within the files.
67 * If the file is empty, it was probably just created and going
68 * to be written to. If it has a size, we'll hold off until the
69 * file is actually grown.
71 if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
72 (inode->i_size == 0)) {
73 struct jfs_inode_info *ji = JFS_IP(inode);
74 spin_lock_irq(&ji->ag_lock);
75 if (ji->active_ag == -1) {
76 struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
77 ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
78 atomic_inc( &jfs_sb->bmap->db_active[ji->active_ag]);
80 spin_unlock_irq(&ji->ag_lock);
85 static int jfs_release(struct inode *inode, struct file *file)
87 struct jfs_inode_info *ji = JFS_IP(inode);
89 spin_lock_irq(&ji->ag_lock);
90 if (ji->active_ag != -1) {
91 struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
92 atomic_dec(&bmap->db_active[ji->active_ag]);
95 spin_unlock_irq(&ji->ag_lock);
100 int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
102 struct inode *inode = dentry->d_inode;
105 rc = inode_change_ok(inode, iattr);
109 if (is_quota_modification(inode, iattr))
110 dquot_initialize(inode);
111 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
112 (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
113 rc = dquot_transfer(inode, iattr);
118 if ((iattr->ia_valid & ATTR_SIZE) &&
119 iattr->ia_size != i_size_read(inode)) {
120 inode_dio_wait(inode);
122 rc = inode_newsize_ok(inode, iattr->ia_size);
126 truncate_setsize(inode, iattr->ia_size);
130 setattr_copy(inode, iattr);
131 mark_inode_dirty(inode);
133 if (iattr->ia_valid & ATTR_MODE)
134 rc = jfs_acl_chmod(inode);
138 const struct inode_operations jfs_file_inode_operations = {
139 .setxattr = jfs_setxattr,
140 .getxattr = jfs_getxattr,
141 .listxattr = jfs_listxattr,
142 .removexattr = jfs_removexattr,
143 .setattr = jfs_setattr,
144 #ifdef CONFIG_JFS_POSIX_ACL
145 .get_acl = jfs_get_acl,
149 const struct file_operations jfs_file_operations = {
151 .llseek = generic_file_llseek,
152 .write = do_sync_write,
153 .read = do_sync_read,
154 .aio_read = generic_file_aio_read,
155 .aio_write = generic_file_aio_write,
156 .mmap = generic_file_mmap,
157 .splice_read = generic_file_splice_read,
158 .splice_write = generic_file_splice_write,
160 .release = jfs_release,
161 .unlocked_ioctl = jfs_ioctl,
163 .compat_ioctl = jfs_compat_ioctl,