xfs_quotaops.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_format.h"
  20. #include "xfs_log_format.h"
  21. #include "xfs_trans_resv.h"
  22. #include "xfs_sb.h"
  23. #include "xfs_ag.h"
  24. #include "xfs_mount.h"
  25. #include "xfs_inode.h"
  26. #include "xfs_quota.h"
  27. #include "xfs_trans.h"
  28. #include "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_get_xstatev(
  54. struct super_block *sb,
  55. struct fs_quota_statv *fqs)
  56. {
  57. struct xfs_mount *mp = XFS_M(sb);
  58. if (!XFS_IS_QUOTA_RUNNING(mp))
  59. return -ENOSYS;
  60. return -xfs_qm_scall_getqstatv(mp, fqs);
  61. }
  62. STATIC int
  63. xfs_fs_set_xstate(
  64. struct super_block *sb,
  65. unsigned int uflags,
  66. int op)
  67. {
  68. struct xfs_mount *mp = XFS_M(sb);
  69. unsigned int flags = 0;
  70. if (sb->s_flags & MS_RDONLY)
  71. return -EROFS;
  72. if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
  73. return -ENOSYS;
  74. if (uflags & FS_QUOTA_UDQ_ACCT)
  75. flags |= XFS_UQUOTA_ACCT;
  76. if (uflags & FS_QUOTA_PDQ_ACCT)
  77. flags |= XFS_PQUOTA_ACCT;
  78. if (uflags & FS_QUOTA_GDQ_ACCT)
  79. flags |= XFS_GQUOTA_ACCT;
  80. if (uflags & FS_QUOTA_UDQ_ENFD)
  81. flags |= XFS_UQUOTA_ENFD;
  82. if (uflags & FS_QUOTA_GDQ_ENFD)
  83. flags |= XFS_GQUOTA_ENFD;
  84. if (uflags & FS_QUOTA_PDQ_ENFD)
  85. flags |= XFS_PQUOTA_ENFD;
  86. switch (op) {
  87. case Q_XQUOTAON:
  88. return -xfs_qm_scall_quotaon(mp, flags);
  89. case Q_XQUOTAOFF:
  90. if (!XFS_IS_QUOTA_ON(mp))
  91. return -EINVAL;
  92. return -xfs_qm_scall_quotaoff(mp, flags);
  93. case Q_XQUOTARM:
  94. if (XFS_IS_QUOTA_ON(mp))
  95. return -EINVAL;
  96. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  97. }
  98. return -EINVAL;
  99. }
  100. STATIC int
  101. xfs_fs_get_dqblk(
  102. struct super_block *sb,
  103. struct kqid qid,
  104. struct fs_disk_quota *fdq)
  105. {
  106. struct xfs_mount *mp = XFS_M(sb);
  107. if (!XFS_IS_QUOTA_RUNNING(mp))
  108. return -ENOSYS;
  109. if (!XFS_IS_QUOTA_ON(mp))
  110. return -ESRCH;
  111. return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
  112. xfs_quota_type(qid.type), fdq);
  113. }
  114. STATIC int
  115. xfs_fs_set_dqblk(
  116. struct super_block *sb,
  117. struct kqid qid,
  118. struct fs_disk_quota *fdq)
  119. {
  120. struct xfs_mount *mp = XFS_M(sb);
  121. if (sb->s_flags & MS_RDONLY)
  122. return -EROFS;
  123. if (!XFS_IS_QUOTA_RUNNING(mp))
  124. return -ENOSYS;
  125. if (!XFS_IS_QUOTA_ON(mp))
  126. return -ESRCH;
  127. return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
  128. xfs_quota_type(qid.type), fdq);
  129. }
  130. const struct quotactl_ops xfs_quotactl_operations = {
  131. .get_xstatev = xfs_fs_get_xstatev,
  132. .get_xstate = xfs_fs_get_xstate,
  133. .set_xstate = xfs_fs_set_xstate,
  134. .get_dqblk = xfs_fs_get_dqblk,
  135. .set_dqblk = xfs_fs_set_dqblk,
  136. };