xfs_quotaops.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_dmapi.h"
  20. #include "xfs_sb.h"
  21. #include "xfs_inum.h"
  22. #include "xfs_ag.h"
  23. #include "xfs_mount.h"
  24. #include "xfs_quota.h"
  25. #include "xfs_log.h"
  26. #include "xfs_trans.h"
  27. #include "xfs_bmap_btree.h"
  28. #include "xfs_inode.h"
  29. #include "quota/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_quota_sync(
  45. struct super_block *sb,
  46. int type)
  47. {
  48. struct xfs_mount *mp = XFS_M(sb);
  49. if (sb->s_flags & MS_RDONLY)
  50. return -EROFS;
  51. if (!XFS_IS_QUOTA_RUNNING(mp))
  52. return -ENOSYS;
  53. return -xfs_sync_data(mp, 0);
  54. }
  55. STATIC int
  56. xfs_fs_get_xstate(
  57. struct super_block *sb,
  58. struct fs_quota_stat *fqs)
  59. {
  60. struct xfs_mount *mp = XFS_M(sb);
  61. if (!XFS_IS_QUOTA_RUNNING(mp))
  62. return -ENOSYS;
  63. return -xfs_qm_scall_getqstat(mp, fqs);
  64. }
  65. STATIC int
  66. xfs_fs_set_xstate(
  67. struct super_block *sb,
  68. unsigned int uflags,
  69. int op)
  70. {
  71. struct xfs_mount *mp = XFS_M(sb);
  72. unsigned int flags = 0;
  73. if (sb->s_flags & MS_RDONLY)
  74. return -EROFS;
  75. if (!XFS_IS_QUOTA_RUNNING(mp))
  76. return -ENOSYS;
  77. if (!capable(CAP_SYS_ADMIN))
  78. return -EPERM;
  79. if (uflags & XFS_QUOTA_UDQ_ACCT)
  80. flags |= XFS_UQUOTA_ACCT;
  81. if (uflags & XFS_QUOTA_PDQ_ACCT)
  82. flags |= XFS_PQUOTA_ACCT;
  83. if (uflags & XFS_QUOTA_GDQ_ACCT)
  84. flags |= XFS_GQUOTA_ACCT;
  85. if (uflags & XFS_QUOTA_UDQ_ENFD)
  86. flags |= XFS_UQUOTA_ENFD;
  87. if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
  88. flags |= XFS_OQUOTA_ENFD;
  89. switch (op) {
  90. case Q_XQUOTAON:
  91. return -xfs_qm_scall_quotaon(mp, flags);
  92. case Q_XQUOTAOFF:
  93. if (!XFS_IS_QUOTA_ON(mp))
  94. return -EINVAL;
  95. return -xfs_qm_scall_quotaoff(mp, flags);
  96. case Q_XQUOTARM:
  97. if (XFS_IS_QUOTA_ON(mp))
  98. return -EINVAL;
  99. return -xfs_qm_scall_trunc_qfiles(mp, flags);
  100. }
  101. return -EINVAL;
  102. }
  103. STATIC int
  104. xfs_fs_get_xquota(
  105. struct super_block *sb,
  106. int type,
  107. qid_t id,
  108. struct fs_disk_quota *fdq)
  109. {
  110. struct xfs_mount *mp = XFS_M(sb);
  111. if (!XFS_IS_QUOTA_RUNNING(mp))
  112. return -ENOSYS;
  113. if (!XFS_IS_QUOTA_ON(mp))
  114. return -ESRCH;
  115. return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
  116. }
  117. STATIC int
  118. xfs_fs_set_xquota(
  119. struct super_block *sb,
  120. int type,
  121. qid_t id,
  122. struct fs_disk_quota *fdq)
  123. {
  124. struct xfs_mount *mp = XFS_M(sb);
  125. if (sb->s_flags & MS_RDONLY)
  126. return -EROFS;
  127. if (!XFS_IS_QUOTA_RUNNING(mp))
  128. return -ENOSYS;
  129. if (!XFS_IS_QUOTA_ON(mp))
  130. return -ESRCH;
  131. if (!capable(CAP_SYS_ADMIN))
  132. return -EPERM;
  133. return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
  134. }
  135. struct quotactl_ops xfs_quotactl_operations = {
  136. .quota_sync = xfs_fs_quota_sync,
  137. .get_xstate = xfs_fs_get_xstate,
  138. .set_xstate = xfs_fs_set_xstate,
  139. .get_xquota = xfs_fs_get_xquota,
  140. .set_xquota = xfs_fs_set_xquota,
  141. };