xfs_quotaops.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_sb.h"
  21. #include "xfs_log.h"
  22. #include "xfs_ag.h"
  23. #include "xfs_mount.h"
  24. #include "xfs_quota.h"
  25. #include "xfs_trans.h"
  26. #include "xfs_bmap_btree.h"
  27. #include "xfs_inode.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_set_xstate(
  54. struct super_block *sb,
  55. unsigned int uflags,
  56. int op)
  57. {
  58. struct xfs_mount *mp = XFS_M(sb);
  59. unsigned int flags = 0;
  60. if (sb->s_flags & MS_RDONLY)
  61. return -EROFS;
  62. if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
  63. return -ENOSYS;
  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. switch (op) {
  77. case Q_XQUOTAON:
  78. return -xfs_qm_scall_quotaon(mp, flags);
  79. case Q_XQUOTAOFF:
  80. if (!XFS_IS_QUOTA_ON(mp))
  81. return -EINVAL;
  82. return -xfs_qm_scall_quotaoff(mp, flags);
  83. case Q_XQUOTARM:
  84. if (XFS_IS_QUOTA_ON(mp))
  85. return -EINVAL;
  86. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  87. }
  88. return -EINVAL;
  89. }
  90. STATIC int
  91. xfs_fs_get_dqblk(
  92. struct super_block *sb,
  93. struct kqid qid,
  94. struct fs_disk_quota *fdq)
  95. {
  96. struct xfs_mount *mp = XFS_M(sb);
  97. if (!XFS_IS_QUOTA_RUNNING(mp))
  98. return -ENOSYS;
  99. if (!XFS_IS_QUOTA_ON(mp))
  100. return -ESRCH;
  101. return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
  102. xfs_quota_type(qid.type), fdq);
  103. }
  104. STATIC int
  105. xfs_fs_set_dqblk(
  106. struct super_block *sb,
  107. struct kqid qid,
  108. struct fs_disk_quota *fdq)
  109. {
  110. struct xfs_mount *mp = XFS_M(sb);
  111. if (sb->s_flags & MS_RDONLY)
  112. return -EROFS;
  113. if (!XFS_IS_QUOTA_RUNNING(mp))
  114. return -ENOSYS;
  115. if (!XFS_IS_QUOTA_ON(mp))
  116. return -ESRCH;
  117. return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
  118. xfs_quota_type(qid.type), fdq);
  119. }
  120. const struct quotactl_ops xfs_quotactl_operations = {
  121. .get_xstate = xfs_fs_get_xstate,
  122. .set_xstate = xfs_fs_set_xstate,
  123. .get_dqblk = xfs_fs_get_dqblk,
  124. .set_dqblk = xfs_fs_set_dqblk,
  125. };