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
21 #include <linux/quotaops.h>
22 #include "jfs_incore.h"
23 #include "jfs_inode.h"
25 #include "jfs_txnmgr.h"
26 #include "jfs_xattr.h"
28 #include "jfs_debug.h"
30 int jfs_fsync(struct file
*file
, struct dentry
*dentry
, int datasync
)
32 struct inode
*inode
= dentry
->d_inode
;
35 if (!(inode
->i_state
& I_DIRTY
) ||
36 (datasync
&& !(inode
->i_state
& I_DIRTY_DATASYNC
))) {
37 /* Make sure committed changes hit the disk */
38 jfs_flush_journal(JFS_SBI(inode
->i_sb
)->log
, 1);
42 rc
|= jfs_commit_inode(inode
, 1);
47 static int jfs_open(struct inode
*inode
, struct file
*file
)
51 if ((rc
= generic_file_open(inode
, file
)))
55 * We attempt to allow only one "active" file open per aggregate
56 * group. Otherwise, appending to files in parallel can cause
57 * fragmentation within the files.
59 * If the file is empty, it was probably just created and going
60 * to be written to. If it has a size, we'll hold off until the
61 * file is actually grown.
63 if (S_ISREG(inode
->i_mode
) && file
->f_mode
& FMODE_WRITE
&&
64 (inode
->i_size
== 0)) {
65 struct jfs_inode_info
*ji
= JFS_IP(inode
);
66 spin_lock_irq(&ji
->ag_lock
);
67 if (ji
->active_ag
== -1) {
68 ji
->active_ag
= ji
->agno
;
70 &JFS_SBI(inode
->i_sb
)->bmap
->db_active
[ji
->agno
]);
72 spin_unlock_irq(&ji
->ag_lock
);
77 static int jfs_release(struct inode
*inode
, struct file
*file
)
79 struct jfs_inode_info
*ji
= JFS_IP(inode
);
81 spin_lock_irq(&ji
->ag_lock
);
82 if (ji
->active_ag
!= -1) {
83 struct bmap
*bmap
= JFS_SBI(inode
->i_sb
)->bmap
;
84 atomic_dec(&bmap
->db_active
[ji
->active_ag
]);
87 spin_unlock_irq(&ji
->ag_lock
);
92 int jfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
94 struct inode
*inode
= dentry
->d_inode
;
97 rc
= inode_change_ok(inode
, iattr
);
101 if ((iattr
->ia_valid
& ATTR_UID
&& iattr
->ia_uid
!= inode
->i_uid
) ||
102 (iattr
->ia_valid
& ATTR_GID
&& iattr
->ia_gid
!= inode
->i_gid
)) {
103 if (vfs_dq_transfer(inode
, iattr
))
107 rc
= inode_setattr(inode
, iattr
);
109 if (!rc
&& (iattr
->ia_valid
& ATTR_MODE
))
110 rc
= jfs_acl_chmod(inode
);
115 const struct inode_operations jfs_file_inode_operations
= {
116 .truncate
= jfs_truncate
,
117 .setxattr
= jfs_setxattr
,
118 .getxattr
= jfs_getxattr
,
119 .listxattr
= jfs_listxattr
,
120 .removexattr
= jfs_removexattr
,
121 .setattr
= jfs_setattr
,
122 #ifdef CONFIG_JFS_POSIX_ACL
123 .check_acl
= jfs_check_acl
,
127 const struct file_operations jfs_file_operations
= {
129 .llseek
= generic_file_llseek
,
130 .write
= do_sync_write
,
131 .read
= do_sync_read
,
132 .aio_read
= generic_file_aio_read
,
133 .aio_write
= generic_file_aio_write
,
134 .mmap
= generic_file_mmap
,
135 .splice_read
= generic_file_splice_read
,
136 .splice_write
= generic_file_splice_write
,
138 .release
= jfs_release
,
139 .unlocked_ioctl
= jfs_ioctl
,
141 .compat_ioctl
= jfs_compat_ioctl
,