file.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2000-2002
  3. * Portions Copyright (c) Christoph Hellwig, 2001-2002
  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
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  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
  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
  18. */
  19. #include <linux/fs.h>
  20. #include "jfs_incore.h"
  21. #include "jfs_dmap.h"
  22. #include "jfs_txnmgr.h"
  23. #include "jfs_xattr.h"
  24. #include "jfs_acl.h"
  25. #include "jfs_debug.h"
  26. extern int jfs_commit_inode(struct inode *, int);
  27. extern void jfs_truncate(struct inode *);
  28. int jfs_fsync(struct file *file, struct dentry *dentry, int datasync)
  29. {
  30. struct inode *inode = dentry->d_inode;
  31. int rc = 0;
  32. if (!(inode->i_state & I_DIRTY) ||
  33. (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
  34. /* Make sure committed changes hit the disk */
  35. jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
  36. return rc;
  37. }
  38. rc |= jfs_commit_inode(inode, 1);
  39. return rc ? -EIO : 0;
  40. }
  41. static int jfs_open(struct inode *inode, struct file *file)
  42. {
  43. int rc;
  44. if ((rc = generic_file_open(inode, file)))
  45. return rc;
  46. /*
  47. * We attempt to allow only one "active" file open per aggregate
  48. * group. Otherwise, appending to files in parallel can cause
  49. * fragmentation within the files.
  50. *
  51. * If the file is empty, it was probably just created and going
  52. * to be written to. If it has a size, we'll hold off until the
  53. * file is actually grown.
  54. */
  55. if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
  56. (inode->i_size == 0)) {
  57. struct jfs_inode_info *ji = JFS_IP(inode);
  58. spin_lock_irq(&ji->ag_lock);
  59. if (ji->active_ag == -1) {
  60. ji->active_ag = ji->agno;
  61. atomic_inc(
  62. &JFS_SBI(inode->i_sb)->bmap->db_active[ji->agno]);
  63. }
  64. spin_unlock_irq(&ji->ag_lock);
  65. }
  66. return 0;
  67. }
  68. static int jfs_release(struct inode *inode, struct file *file)
  69. {
  70. struct jfs_inode_info *ji = JFS_IP(inode);
  71. spin_lock_irq(&ji->ag_lock);
  72. if (ji->active_ag != -1) {
  73. struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
  74. atomic_dec(&bmap->db_active[ji->active_ag]);
  75. ji->active_ag = -1;
  76. }
  77. spin_unlock_irq(&ji->ag_lock);
  78. return 0;
  79. }
  80. struct inode_operations jfs_file_inode_operations = {
  81. .truncate = jfs_truncate,
  82. .setxattr = jfs_setxattr,
  83. .getxattr = jfs_getxattr,
  84. .listxattr = jfs_listxattr,
  85. .removexattr = jfs_removexattr,
  86. #ifdef CONFIG_JFS_POSIX_ACL
  87. .setattr = jfs_setattr,
  88. .permission = jfs_permission,
  89. #endif
  90. };
  91. struct file_operations jfs_file_operations = {
  92. .open = jfs_open,
  93. .llseek = generic_file_llseek,
  94. .write = generic_file_write,
  95. .read = generic_file_read,
  96. .aio_read = generic_file_aio_read,
  97. .aio_write = generic_file_aio_write,
  98. .mmap = generic_file_mmap,
  99. .readv = generic_file_readv,
  100. .writev = generic_file_writev,
  101. .sendfile = generic_file_sendfile,
  102. .fsync = jfs_fsync,
  103. .release = jfs_release,
  104. };