xfs_quotaops.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. }
  94. return -EINVAL;
  95. }
  96. STATIC int
  97. xfs_fs_rm_xquota(
  98. struct super_block *sb,
  99. unsigned int uflags)
  100. {
  101. struct xfs_mount *mp = XFS_M(sb);
  102. unsigned int flags = 0;
  103. if (sb->s_flags & MS_RDONLY)
  104. return -EROFS;
  105. if (XFS_IS_QUOTA_ON(mp))
  106. return -EINVAL;
  107. if (uflags & FS_USER_QUOTA)
  108. flags |= XFS_DQ_USER;
  109. if (uflags & FS_GROUP_QUOTA)
  110. flags |= XFS_DQ_GROUP;
  111. if (uflags & FS_USER_QUOTA)
  112. flags |= XFS_DQ_PROJ;
  113. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  114. }
  115. STATIC int
  116. xfs_fs_get_dqblk(
  117. struct super_block *sb,
  118. struct kqid qid,
  119. struct fs_disk_quota *fdq)
  120. {
  121. struct xfs_mount *mp = XFS_M(sb);
  122. if (!XFS_IS_QUOTA_RUNNING(mp))
  123. return -ENOSYS;
  124. if (!XFS_IS_QUOTA_ON(mp))
  125. return -ESRCH;
  126. return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
  127. xfs_quota_type(qid.type), fdq);
  128. }
  129. STATIC int
  130. xfs_fs_set_dqblk(
  131. struct super_block *sb,
  132. struct kqid qid,
  133. struct fs_disk_quota *fdq)
  134. {
  135. struct xfs_mount *mp = XFS_M(sb);
  136. if (sb->s_flags & MS_RDONLY)
  137. return -EROFS;
  138. if (!XFS_IS_QUOTA_RUNNING(mp))
  139. return -ENOSYS;
  140. if (!XFS_IS_QUOTA_ON(mp))
  141. return -ESRCH;
  142. return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
  143. xfs_quota_type(qid.type), fdq);
  144. }
  145. const struct quotactl_ops xfs_quotactl_operations = {
  146. .get_xstatev = xfs_fs_get_xstatev,
  147. .get_xstate = xfs_fs_get_xstate,
  148. .set_xstate = xfs_fs_set_xstate,
  149. .rm_xquota = xfs_fs_rm_xquota,
  150. .get_dqblk = xfs_fs_get_dqblk,
  151. .set_dqblk = xfs_fs_set_dqblk,
  152. };