xfs_quotaops.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2008, Christoph Hellwig
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_sb.h"
  20. #include "xfs_log.h"
  21. #include "xfs_ag.h"
  22. #include "xfs_mount.h"
  23. #include "xfs_quota.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_bmap_btree.h"
  26. #include "xfs_inode.h"
  27. #include "xfs_qm.h"
  28. #include <linux/quota.h>
  29. STATIC int
  30. xfs_quota_type(int type)
  31. {
  32. switch (type) {
  33. case USRQUOTA:
  34. return XFS_DQ_USER;
  35. case GRPQUOTA:
  36. return XFS_DQ_GROUP;
  37. default:
  38. return XFS_DQ_PROJ;
  39. }
  40. }
  41. STATIC int
  42. xfs_fs_get_xstate(
  43. struct super_block *sb,
  44. struct fs_quota_stat *fqs)
  45. {
  46. struct xfs_mount *mp = XFS_M(sb);
  47. if (!XFS_IS_QUOTA_RUNNING(mp))
  48. return -ENOSYS;
  49. return -xfs_qm_scall_getqstat(mp, fqs);
  50. }
  51. STATIC int
  52. xfs_fs_set_xstate(
  53. struct super_block *sb,
  54. unsigned int uflags,
  55. int op)
  56. {
  57. struct xfs_mount *mp = XFS_M(sb);
  58. unsigned int flags = 0;
  59. if (sb->s_flags & MS_RDONLY)
  60. return -EROFS;
  61. if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
  62. return -ENOSYS;
  63. if (uflags & FS_QUOTA_UDQ_ACCT)
  64. flags |= XFS_UQUOTA_ACCT;
  65. if (uflags & FS_QUOTA_PDQ_ACCT)
  66. flags |= XFS_PQUOTA_ACCT;
  67. if (uflags & FS_QUOTA_GDQ_ACCT)
  68. flags |= XFS_GQUOTA_ACCT;
  69. if (uflags & FS_QUOTA_UDQ_ENFD)
  70. flags |= XFS_UQUOTA_ENFD;
  71. if (uflags & (FS_QUOTA_PDQ_ENFD|FS_QUOTA_GDQ_ENFD))
  72. flags |= XFS_OQUOTA_ENFD;
  73. switch (op) {
  74. case Q_XQUOTAON:
  75. return -xfs_qm_scall_quotaon(mp, flags);
  76. case Q_XQUOTAOFF:
  77. if (!XFS_IS_QUOTA_ON(mp))
  78. return -EINVAL;
  79. return -xfs_qm_scall_quotaoff(mp, flags);
  80. case Q_XQUOTARM:
  81. if (XFS_IS_QUOTA_ON(mp))
  82. return -EINVAL;
  83. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  84. }
  85. return -EINVAL;
  86. }
  87. STATIC int
  88. xfs_fs_get_dqblk(
  89. struct super_block *sb,
  90. int type,
  91. qid_t id,
  92. struct fs_disk_quota *fdq)
  93. {
  94. struct xfs_mount *mp = XFS_M(sb);
  95. if (!XFS_IS_QUOTA_RUNNING(mp))
  96. return -ENOSYS;
  97. if (!XFS_IS_QUOTA_ON(mp))
  98. return -ESRCH;
  99. return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
  100. }
  101. STATIC int
  102. xfs_fs_set_dqblk(
  103. struct super_block *sb,
  104. int type,
  105. qid_t id,
  106. struct fs_disk_quota *fdq)
  107. {
  108. struct xfs_mount *mp = XFS_M(sb);
  109. if (sb->s_flags & MS_RDONLY)
  110. return -EROFS;
  111. if (!XFS_IS_QUOTA_RUNNING(mp))
  112. return -ENOSYS;
  113. if (!XFS_IS_QUOTA_ON(mp))
  114. return -ESRCH;
  115. return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
  116. }
  117. const struct quotactl_ops xfs_quotactl_operations = {
  118. .get_xstate = xfs_fs_get_xstate,
  119. .set_xstate = xfs_fs_set_xstate,
  120. .get_dqblk = xfs_fs_get_dqblk,
  121. .set_dqblk = xfs_fs_set_dqblk,
  122. };