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> |
| 21 | #include "jfs_incore.h" |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 22 | #include "jfs_inode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "jfs_dmap.h" |
| 24 | #include "jfs_txnmgr.h" |
| 25 | #include "jfs_xattr.h" |
| 26 | #include "jfs_acl.h" |
| 27 | #include "jfs_debug.h" |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | int jfs_fsync(struct file *file, struct dentry *dentry, int datasync) |
| 30 | { |
| 31 | struct inode *inode = dentry->d_inode; |
| 32 | int rc = 0; |
| 33 | |
| 34 | if (!(inode->i_state & I_DIRTY) || |
| 35 | (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) { |
| 36 | /* Make sure committed changes hit the disk */ |
| 37 | jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1); |
| 38 | return rc; |
| 39 | } |
| 40 | |
| 41 | rc |= jfs_commit_inode(inode, 1); |
| 42 | |
| 43 | return rc ? -EIO : 0; |
| 44 | } |
| 45 | |
| 46 | static int jfs_open(struct inode *inode, struct file *file) |
| 47 | { |
| 48 | int rc; |
| 49 | |
| 50 | if ((rc = generic_file_open(inode, file))) |
| 51 | return rc; |
| 52 | |
| 53 | /* |
| 54 | * We attempt to allow only one "active" file open per aggregate |
| 55 | * group. Otherwise, appending to files in parallel can cause |
| 56 | * fragmentation within the files. |
| 57 | * |
| 58 | * If the file is empty, it was probably just created and going |
| 59 | * to be written to. If it has a size, we'll hold off until the |
| 60 | * file is actually grown. |
| 61 | */ |
| 62 | if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE && |
| 63 | (inode->i_size == 0)) { |
| 64 | struct jfs_inode_info *ji = JFS_IP(inode); |
| 65 | spin_lock_irq(&ji->ag_lock); |
| 66 | if (ji->active_ag == -1) { |
| 67 | ji->active_ag = ji->agno; |
| 68 | atomic_inc( |
| 69 | &JFS_SBI(inode->i_sb)->bmap->db_active[ji->agno]); |
| 70 | } |
| 71 | spin_unlock_irq(&ji->ag_lock); |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | static int jfs_release(struct inode *inode, struct file *file) |
| 77 | { |
| 78 | struct jfs_inode_info *ji = JFS_IP(inode); |
| 79 | |
| 80 | spin_lock_irq(&ji->ag_lock); |
| 81 | if (ji->active_ag != -1) { |
| 82 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; |
| 83 | atomic_dec(&bmap->db_active[ji->active_ag]); |
| 84 | ji->active_ag = -1; |
| 85 | } |
| 86 | spin_unlock_irq(&ji->ag_lock); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | struct inode_operations jfs_file_inode_operations = { |
| 92 | .truncate = jfs_truncate, |
| 93 | .setxattr = jfs_setxattr, |
| 94 | .getxattr = jfs_getxattr, |
| 95 | .listxattr = jfs_listxattr, |
| 96 | .removexattr = jfs_removexattr, |
| 97 | #ifdef CONFIG_JFS_POSIX_ACL |
| 98 | .setattr = jfs_setattr, |
| 99 | .permission = jfs_permission, |
| 100 | #endif |
| 101 | }; |
| 102 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 103 | const struct file_operations jfs_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .open = jfs_open, |
| 105 | .llseek = generic_file_llseek, |
Badari Pulavarty | 543ade1 | 2006-09-30 23:28:48 -0700 | [diff] [blame] | 106 | .write = do_sync_write, |
| 107 | .read = do_sync_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | .aio_read = generic_file_aio_read, |
| 109 | .aio_write = generic_file_aio_write, |
| 110 | .mmap = generic_file_mmap, |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame^] | 111 | .sendfile = generic_file_sendfile, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | .fsync = jfs_fsync, |
| 113 | .release = jfs_release, |
Herbert Poetzl | fa3241d | 2006-02-09 09:09:16 -0600 | [diff] [blame] | 114 | .ioctl = jfs_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |