xfs_quotaops.c 3.4 KB

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