xfs_quotaops.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 int
  61. xfs_fs_set_xstate(
  62. struct super_block *sb,
  63. unsigned int uflags,
  64. int op)
  65. {
  66. struct xfs_mount *mp = XFS_M(sb);
  67. unsigned int flags = 0;
  68. if (sb->s_flags & MS_RDONLY)
  69. return -EROFS;
  70. if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
  71. return -ENOSYS;
  72. if (uflags & FS_QUOTA_UDQ_ACCT)
  73. flags |= XFS_UQUOTA_ACCT;
  74. if (uflags & FS_QUOTA_PDQ_ACCT)
  75. flags |= XFS_PQUOTA_ACCT;
  76. if (uflags & FS_QUOTA_GDQ_ACCT)
  77. flags |= XFS_GQUOTA_ACCT;
  78. if (uflags & FS_QUOTA_UDQ_ENFD)
  79. flags |= XFS_UQUOTA_ENFD;
  80. if (uflags & FS_QUOTA_GDQ_ENFD)
  81. flags |= XFS_GQUOTA_ENFD;
  82. if (uflags & FS_QUOTA_PDQ_ENFD)
  83. flags |= XFS_PQUOTA_ENFD;
  84. switch (op) {
  85. case Q_XQUOTAON:
  86. return xfs_qm_scall_quotaon(mp, flags);
  87. case Q_XQUOTAOFF:
  88. if (!XFS_IS_QUOTA_ON(mp))
  89. return -EINVAL;
  90. return xfs_qm_scall_quotaoff(mp, flags);
  91. }
  92. return -EINVAL;
  93. }
  94. STATIC int
  95. xfs_fs_rm_xquota(
  96. struct super_block *sb,
  97. unsigned int uflags)
  98. {
  99. struct xfs_mount *mp = XFS_M(sb);
  100. unsigned int flags = 0;
  101. if (sb->s_flags & MS_RDONLY)
  102. return -EROFS;
  103. if (XFS_IS_QUOTA_ON(mp))
  104. return -EINVAL;
  105. if (uflags & FS_USER_QUOTA)
  106. flags |= XFS_DQ_USER;
  107. if (uflags & FS_GROUP_QUOTA)
  108. flags |= XFS_DQ_GROUP;
  109. if (uflags & FS_PROJ_QUOTA)
  110. flags |= XFS_DQ_PROJ;
  111. return xfs_qm_scall_trunc_qfiles(mp, flags);
  112. }
  113. STATIC int
  114. xfs_fs_get_dqblk(
  115. struct super_block *sb,
  116. struct kqid qid,
  117. struct fs_disk_quota *fdq)
  118. {
  119. struct xfs_mount *mp = XFS_M(sb);
  120. if (!XFS_IS_QUOTA_RUNNING(mp))
  121. return -ENOSYS;
  122. if (!XFS_IS_QUOTA_ON(mp))
  123. return -ESRCH;
  124. return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
  125. xfs_quota_type(qid.type), fdq);
  126. }
  127. STATIC int
  128. xfs_fs_set_dqblk(
  129. struct super_block *sb,
  130. struct kqid qid,
  131. struct fs_disk_quota *fdq)
  132. {
  133. struct xfs_mount *mp = XFS_M(sb);
  134. if (sb->s_flags & MS_RDONLY)
  135. return -EROFS;
  136. if (!XFS_IS_QUOTA_RUNNING(mp))
  137. return -ENOSYS;
  138. if (!XFS_IS_QUOTA_ON(mp))
  139. return -ESRCH;
  140. return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
  141. xfs_quota_type(qid.type), fdq);
  142. }
  143. const struct quotactl_ops xfs_quotactl_operations = {
  144. .get_xstatev = xfs_fs_get_xstatev,
  145. .get_xstate = xfs_fs_get_xstate,
  146. .set_xstate = xfs_fs_set_xstate,
  147. .rm_xquota = xfs_fs_rm_xquota,
  148. .get_dqblk = xfs_fs_get_dqblk,
  149. .set_dqblk = xfs_fs_set_dqblk,
  150. };