xfs_quotaops.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_dmapi.h"
  20. #include "xfs_sb.h"
  21. #include "xfs_inum.h"
  22. #include "xfs_log.h"
  23. #include "xfs_ag.h"
  24. #include "xfs_mount.h"
  25. #include "xfs_quota.h"
  26. #include "xfs_log.h"
  27. #include "xfs_trans.h"
  28. #include "xfs_bmap_btree.h"
  29. #include "xfs_inode.h"
  30. #include "quota/xfs_qm.h"
  31. #include <linux/quota.h>
  32. STATIC int
  33. xfs_quota_type(int type)
  34. {
  35. switch (type) {
  36. case USRQUOTA:
  37. return XFS_DQ_USER;
  38. case GRPQUOTA:
  39. return XFS_DQ_GROUP;
  40. default:
  41. return XFS_DQ_PROJ;
  42. }
  43. }
  44. STATIC int
  45. xfs_fs_get_xstate(
  46. struct super_block *sb,
  47. struct fs_quota_stat *fqs)
  48. {
  49. struct xfs_mount *mp = XFS_M(sb);
  50. if (!XFS_IS_QUOTA_RUNNING(mp))
  51. return -ENOSYS;
  52. return -xfs_qm_scall_getqstat(mp, fqs);
  53. }
  54. STATIC int
  55. xfs_fs_set_xstate(
  56. struct super_block *sb,
  57. unsigned int uflags,
  58. int op)
  59. {
  60. struct xfs_mount *mp = XFS_M(sb);
  61. unsigned int flags = 0;
  62. if (sb->s_flags & MS_RDONLY)
  63. return -EROFS;
  64. if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
  65. return -ENOSYS;
  66. if (uflags & XFS_QUOTA_UDQ_ACCT)
  67. flags |= XFS_UQUOTA_ACCT;
  68. if (uflags & XFS_QUOTA_PDQ_ACCT)
  69. flags |= XFS_PQUOTA_ACCT;
  70. if (uflags & XFS_QUOTA_GDQ_ACCT)
  71. flags |= XFS_GQUOTA_ACCT;
  72. if (uflags & XFS_QUOTA_UDQ_ENFD)
  73. flags |= XFS_UQUOTA_ENFD;
  74. if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
  75. flags |= XFS_OQUOTA_ENFD;
  76. switch (op) {
  77. case Q_XQUOTAON:
  78. return -xfs_qm_scall_quotaon(mp, flags);
  79. case Q_XQUOTAOFF:
  80. if (!XFS_IS_QUOTA_ON(mp))
  81. return -EINVAL;
  82. return -xfs_qm_scall_quotaoff(mp, flags);
  83. case Q_XQUOTARM:
  84. if (XFS_IS_QUOTA_ON(mp))
  85. return -EINVAL;
  86. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  87. }
  88. return -EINVAL;
  89. }
  90. STATIC int
  91. xfs_fs_get_dqblk(
  92. struct super_block *sb,
  93. int type,
  94. qid_t id,
  95. struct fs_disk_quota *fdq)
  96. {
  97. struct xfs_mount *mp = XFS_M(sb);
  98. if (!XFS_IS_QUOTA_RUNNING(mp))
  99. return -ENOSYS;
  100. if (!XFS_IS_QUOTA_ON(mp))
  101. return -ESRCH;
  102. return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
  103. }
  104. STATIC int
  105. xfs_fs_set_dqblk(
  106. struct super_block *sb,
  107. int type,
  108. qid_t id,
  109. struct fs_disk_quota *fdq)
  110. {
  111. struct xfs_mount *mp = XFS_M(sb);
  112. if (sb->s_flags & MS_RDONLY)
  113. return -EROFS;
  114. if (!XFS_IS_QUOTA_RUNNING(mp))
  115. return -ENOSYS;
  116. if (!XFS_IS_QUOTA_ON(mp))
  117. return -ESRCH;
  118. return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
  119. }
  120. const struct quotactl_ops xfs_quotactl_operations = {
  121. .get_xstate = xfs_fs_get_xstate,
  122. .set_xstate = xfs_fs_set_xstate,
  123. .get_dqblk = xfs_fs_get_dqblk,
  124. .set_dqblk = xfs_fs_set_dqblk,
  125. };