xfs_quotaops.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_mount.h"
  23. #include "xfs_inode.h"
  24. #include "xfs_quota.h"
  25. #include "xfs_trans.h"
  26. #include "xfs_qm.h"
  27. #include <linux/quota.h>
  28. STATIC int
  29. xfs_quota_type(int type)
  30. {
  31. switch (type) {
  32. case USRQUOTA:
  33. return XFS_DQ_USER;
  34. case GRPQUOTA:
  35. return XFS_DQ_GROUP;
  36. default:
  37. return XFS_DQ_PROJ;
  38. }
  39. }
  40. STATIC int
  41. xfs_fs_get_xstate(
  42. struct super_block *sb,
  43. struct fs_quota_stat *fqs)
  44. {
  45. struct xfs_mount *mp = XFS_M(sb);
  46. if (!XFS_IS_QUOTA_RUNNING(mp))
  47. return -ENOSYS;
  48. return xfs_qm_scall_getqstat(mp, fqs);
  49. }
  50. STATIC int
  51. xfs_fs_get_xstatev(
  52. struct super_block *sb,
  53. struct fs_quota_statv *fqs)
  54. {
  55. struct xfs_mount *mp = XFS_M(sb);
  56. if (!XFS_IS_QUOTA_RUNNING(mp))
  57. return -ENOSYS;
  58. return xfs_qm_scall_getqstatv(mp, fqs);
  59. }
  60. static unsigned int
  61. xfs_quota_flags(unsigned int uflags)
  62. {
  63. unsigned int flags = 0;
  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_GDQ_ENFD)
  73. flags |= XFS_GQUOTA_ENFD;
  74. if (uflags & FS_QUOTA_PDQ_ENFD)
  75. flags |= XFS_PQUOTA_ENFD;
  76. return flags;
  77. }
  78. STATIC int
  79. xfs_quota_enable(
  80. struct super_block *sb,
  81. unsigned int uflags)
  82. {
  83. struct xfs_mount *mp = XFS_M(sb);
  84. if (sb->s_flags & MS_RDONLY)
  85. return -EROFS;
  86. if (!XFS_IS_QUOTA_RUNNING(mp))
  87. return -ENOSYS;
  88. return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags));
  89. }
  90. STATIC int
  91. xfs_quota_disable(
  92. struct super_block *sb,
  93. unsigned int uflags)
  94. {
  95. struct xfs_mount *mp = XFS_M(sb);
  96. if (sb->s_flags & MS_RDONLY)
  97. return -EROFS;
  98. if (!XFS_IS_QUOTA_RUNNING(mp))
  99. return -ENOSYS;
  100. if (!XFS_IS_QUOTA_ON(mp))
  101. return -EINVAL;
  102. return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags));
  103. }
  104. STATIC int
  105. xfs_fs_rm_xquota(
  106. struct super_block *sb,
  107. unsigned int uflags)
  108. {
  109. struct xfs_mount *mp = XFS_M(sb);
  110. unsigned int flags = 0;
  111. if (sb->s_flags & MS_RDONLY)
  112. return -EROFS;
  113. if (XFS_IS_QUOTA_ON(mp))
  114. return -EINVAL;
  115. if (uflags & FS_USER_QUOTA)
  116. flags |= XFS_DQ_USER;
  117. if (uflags & FS_GROUP_QUOTA)
  118. flags |= XFS_DQ_GROUP;
  119. if (uflags & FS_PROJ_QUOTA)
  120. flags |= XFS_DQ_PROJ;
  121. return xfs_qm_scall_trunc_qfiles(mp, flags);
  122. }
  123. STATIC int
  124. xfs_fs_get_dqblk(
  125. struct super_block *sb,
  126. struct kqid qid,
  127. struct qc_dqblk *qdq)
  128. {
  129. struct xfs_mount *mp = XFS_M(sb);
  130. if (!XFS_IS_QUOTA_RUNNING(mp))
  131. return -ENOSYS;
  132. if (!XFS_IS_QUOTA_ON(mp))
  133. return -ESRCH;
  134. return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
  135. xfs_quota_type(qid.type), qdq);
  136. }
  137. STATIC int
  138. xfs_fs_set_dqblk(
  139. struct super_block *sb,
  140. struct kqid qid,
  141. struct qc_dqblk *qdq)
  142. {
  143. struct xfs_mount *mp = XFS_M(sb);
  144. if (sb->s_flags & MS_RDONLY)
  145. return -EROFS;
  146. if (!XFS_IS_QUOTA_RUNNING(mp))
  147. return -ENOSYS;
  148. if (!XFS_IS_QUOTA_ON(mp))
  149. return -ESRCH;
  150. return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
  151. xfs_quota_type(qid.type), qdq);
  152. }
  153. const struct quotactl_ops xfs_quotactl_operations = {
  154. .get_xstatev = xfs_fs_get_xstatev,
  155. .get_xstate = xfs_fs_get_xstate,
  156. .quota_enable = xfs_quota_enable,
  157. .quota_disable = xfs_quota_disable,
  158. .rm_xquota = xfs_fs_rm_xquota,
  159. .get_dqblk = xfs_fs_get_dqblk,
  160. .set_dqblk = xfs_fs_set_dqblk,
  161. };