file.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/mm.h>
  20. #include <linux/fs.h>
  21. #include <linux/quotaops.h>
  22. #include "jfs_incore.h"
  23. #include "jfs_inode.h"
  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. int jfs_fsync(struct file *file, int datasync)
  30. {
  31. struct inode *inode = file->f_mapping->host;
  32. int rc = 0;
  33. if (!(inode->i_state & I_DIRTY) ||
  34. (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
  35. /* Make sure committed changes hit the disk */
  36. jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
  37. return rc;
  38. }
  39. rc |= jfs_commit_inode(inode, 1);
  40. return rc ? -EIO : 0;
  41. }
  42. static int jfs_open(struct inode *inode, struct file *file)
  43. {
  44. int rc;
  45. if ((rc = dquot_file_open(inode, file)))
  46. return rc;
  47. /*
  48. * We attempt to allow only one "active" file open per aggregate
  49. * group. Otherwise, appending to files in parallel can cause
  50. * fragmentation within the files.
  51. *
  52. * If the file is empty, it was probably just created and going
  53. * to be written to. If it has a size, we'll hold off until the
  54. * file is actually grown.
  55. */
  56. if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
  57. (inode->i_size == 0)) {
  58. struct jfs_inode_info *ji = JFS_IP(inode);
  59. spin_lock_irq(&ji->ag_lock);
  60. if (ji->active_ag == -1) {
  61. struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
  62. ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
  63. atomic_inc( &jfs_sb->bmap->db_active[ji->active_ag]);
  64. }
  65. spin_unlock_irq(&ji->ag_lock);
  66. }
  67. return 0;
  68. }
  69. static int jfs_release(struct inode *inode, struct file *file)
  70. {
  71. struct jfs_inode_info *ji = JFS_IP(inode);
  72. spin_lock_irq(&ji->ag_lock);
  73. if (ji->active_ag != -1) {
  74. struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
  75. atomic_dec(&bmap->db_active[ji->active_ag]);
  76. ji->active_ag = -1;
  77. }
  78. spin_unlock_irq(&ji->ag_lock);
  79. return 0;
  80. }
  81. int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
  82. {
  83. struct inode *inode = dentry->d_inode;
  84. int rc;
  85. rc = inode_change_ok(inode, iattr);
  86. if (rc)
  87. return rc;
  88. if (is_quota_modification(inode, iattr))
  89. dquot_initialize(inode);
  90. if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
  91. (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
  92. rc = dquot_transfer(inode, iattr);
  93. if (rc)
  94. return rc;
  95. }
  96. if ((iattr->ia_valid & ATTR_SIZE) &&
  97. iattr->ia_size != i_size_read(inode)) {
  98. rc = vmtruncate(inode, iattr->ia_size);
  99. if (rc)
  100. return rc;
  101. }
  102. setattr_copy(inode, iattr);
  103. mark_inode_dirty(inode);
  104. if (iattr->ia_valid & ATTR_MODE)
  105. rc = jfs_acl_chmod(inode);
  106. return rc;
  107. }
  108. const struct inode_operations jfs_file_inode_operations = {
  109. .truncate = jfs_truncate,
  110. .setxattr = jfs_setxattr,
  111. .getxattr = jfs_getxattr,
  112. .listxattr = jfs_listxattr,
  113. .removexattr = jfs_removexattr,
  114. .setattr = jfs_setattr,
  115. #ifdef CONFIG_JFS_POSIX_ACL
  116. .check_acl = jfs_check_acl,
  117. #endif
  118. };
  119. const struct file_operations jfs_file_operations = {
  120. .open = jfs_open,
  121. .llseek = generic_file_llseek,
  122. .write = do_sync_write,
  123. .read = do_sync_read,
  124. .aio_read = generic_file_aio_read,
  125. .aio_write = generic_file_aio_write,
  126. .mmap = generic_file_mmap,
  127. .splice_read = generic_file_splice_read,
  128. .splice_write = generic_file_splice_write,
  129. .fsync = jfs_fsync,
  130. .release = jfs_release,
  131. .unlocked_ioctl = jfs_ioctl,
  132. #ifdef CONFIG_COMPAT
  133. .compat_ioctl = jfs_compat_ioctl,
  134. #endif
  135. };