xfs_quotaops.c 3.1 KB

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