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