file.c 3.3 KB

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