xfs_quotaops.c 3.2 KB

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