Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 2 | * Copyright (C) International Business Machines Corp., 2000-2002 |
| 3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 7 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * (at your option) any later version. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <linux/fs.h> |
Christoph Hellwig | 759bfee | 2010-03-03 09:05:02 -0500 | [diff] [blame] | 21 | #include <linux/quotaops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "jfs_incore.h" |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 23 | #include "jfs_inode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "jfs_dmap.h" |
| 25 | #include "jfs_txnmgr.h" |
| 26 | #include "jfs_xattr.h" |
| 27 | #include "jfs_acl.h" |
| 28 | #include "jfs_debug.h" |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | int jfs_fsync(struct file *file, struct dentry *dentry, int datasync) |
| 31 | { |
| 32 | struct inode *inode = dentry->d_inode; |
| 33 | int rc = 0; |
| 34 | |
| 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); |
| 39 | return rc; |
| 40 | } |
| 41 | |
| 42 | rc |= jfs_commit_inode(inode, 1); |
| 43 | |
| 44 | return rc ? -EIO : 0; |
| 45 | } |
| 46 | |
| 47 | static int jfs_open(struct inode *inode, struct file *file) |
| 48 | { |
| 49 | int rc; |
| 50 | |
| 51 | if ((rc = generic_file_open(inode, file))) |
| 52 | return rc; |
| 53 | |
| 54 | /* |
| 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. |
| 58 | * |
| 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. |
| 62 | */ |
| 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; |
| 69 | atomic_inc( |
| 70 | &JFS_SBI(inode->i_sb)->bmap->db_active[ji->agno]); |
| 71 | } |
| 72 | spin_unlock_irq(&ji->ag_lock); |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | static int jfs_release(struct inode *inode, struct file *file) |
| 78 | { |
| 79 | struct jfs_inode_info *ji = JFS_IP(inode); |
| 80 | |
| 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]); |
| 85 | ji->active_ag = -1; |
| 86 | } |
| 87 | spin_unlock_irq(&ji->ag_lock); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Christoph Hellwig | 759bfee | 2010-03-03 09:05:02 -0500 | [diff] [blame] | 92 | int jfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 93 | { |
| 94 | struct inode *inode = dentry->d_inode; |
| 95 | int rc; |
| 96 | |
| 97 | rc = inode_change_ok(inode, iattr); |
| 98 | if (rc) |
| 99 | return rc; |
| 100 | |
| 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)) { |
Christoph Hellwig | b43fa82 | 2010-03-03 09:05:03 -0500 | [diff] [blame^] | 103 | rc = dquot_transfer(inode, iattr); |
| 104 | if (rc) |
| 105 | return rc; |
Christoph Hellwig | 759bfee | 2010-03-03 09:05:02 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | rc = inode_setattr(inode, iattr); |
| 109 | |
| 110 | if (!rc && (iattr->ia_valid & ATTR_MODE)) |
| 111 | rc = jfs_acl_chmod(inode); |
| 112 | |
| 113 | return rc; |
| 114 | } |
| 115 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 116 | const struct inode_operations jfs_file_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .truncate = jfs_truncate, |
| 118 | .setxattr = jfs_setxattr, |
| 119 | .getxattr = jfs_getxattr, |
| 120 | .listxattr = jfs_listxattr, |
| 121 | .removexattr = jfs_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .setattr = jfs_setattr, |
Christoph Hellwig | 759bfee | 2010-03-03 09:05:02 -0500 | [diff] [blame] | 123 | #ifdef CONFIG_JFS_POSIX_ACL |
Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 124 | .check_acl = jfs_check_acl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #endif |
| 126 | }; |
| 127 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 128 | const struct file_operations jfs_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | .open = jfs_open, |
| 130 | .llseek = generic_file_llseek, |
Badari Pulavarty | 543ade1 | 2006-09-30 23:28:48 -0700 | [diff] [blame] | 131 | .write = do_sync_write, |
| 132 | .read = do_sync_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .aio_read = generic_file_aio_read, |
| 134 | .aio_write = generic_file_aio_write, |
| 135 | .mmap = generic_file_mmap, |
Daniel Drake | 89f6822 | 2006-10-30 11:47:02 -0600 | [diff] [blame] | 136 | .splice_read = generic_file_splice_read, |
| 137 | .splice_write = generic_file_splice_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | .fsync = jfs_fsync, |
| 139 | .release = jfs_release, |
Andi Kleen | baab81f | 2008-01-27 16:58:51 -0600 | [diff] [blame] | 140 | .unlocked_ioctl = jfs_ioctl, |
Andi Kleen | ef1fc2f | 2008-01-27 17:02:02 -0600 | [diff] [blame] | 141 | #ifdef CONFIG_COMPAT |
| 142 | .compat_ioctl = jfs_compat_ioctl, |
| 143 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |