LCOV - code coverage report
Current view: top level - fs/xfs - xfs_qm_bhv.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 50 52 96.2 %
Date: 2023-07-31 20:08:27 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : #include "xfs.h"
       7             : #include "xfs_fs.h"
       8             : #include "xfs_shared.h"
       9             : #include "xfs_format.h"
      10             : #include "xfs_log_format.h"
      11             : #include "xfs_trans_resv.h"
      12             : #include "xfs_mount.h"
      13             : #include "xfs_quota.h"
      14             : #include "xfs_mount.h"
      15             : #include "xfs_inode.h"
      16             : #include "xfs_trans.h"
      17             : #include "xfs_qm.h"
      18             : 
      19             : 
      20             : STATIC void
      21         608 : xfs_fill_statvfs_from_dquot(
      22             :         struct kstatfs          *statp,
      23             :         struct xfs_inode        *ip,
      24             :         struct xfs_dquot        *dqp)
      25             : {
      26         608 :         struct xfs_dquot_res    *blkres = &dqp->q_blk;
      27         608 :         uint64_t                limit;
      28             : 
      29         608 :         if (XFS_IS_REALTIME_MOUNT(ip->i_mount) &&
      30           0 :             (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME)))
      31           0 :                 blkres = &dqp->q_rtb;
      32             : 
      33         608 :         limit = blkres->softlimit ?
      34         608 :                 blkres->softlimit :
      35             :                 blkres->hardlimit;
      36         608 :         if (limit && statp->f_blocks > limit) {
      37         474 :                 statp->f_blocks = limit;
      38         474 :                 statp->f_bfree = statp->f_bavail =
      39         474 :                         (statp->f_blocks > blkres->reserved) ?
      40         474 :                          (statp->f_blocks - blkres->reserved) : 0;
      41             :         }
      42             : 
      43         608 :         limit = dqp->q_ino.softlimit ?
      44         608 :                 dqp->q_ino.softlimit :
      45             :                 dqp->q_ino.hardlimit;
      46         608 :         if (limit && statp->f_files > limit) {
      47         228 :                 statp->f_files = limit;
      48         228 :                 statp->f_ffree =
      49         228 :                         (statp->f_files > dqp->q_ino.reserved) ?
      50         228 :                          (statp->f_files - dqp->q_ino.reserved) : 0;
      51             :         }
      52         608 : }
      53             : 
      54             : 
      55             : /*
      56             :  * Directory tree accounting is implemented using project quotas, where
      57             :  * the project identifier is inherited from parent directories.
      58             :  * A statvfs (df, etc.) of a directory that is using project quota should
      59             :  * return a statvfs of the project, not the entire filesystem.
      60             :  * This makes such trees appear as if they are filesystems in themselves.
      61             :  */
      62             : void
      63         608 : xfs_qm_statvfs(
      64             :         struct xfs_inode        *ip,
      65             :         struct kstatfs          *statp)
      66             : {
      67         608 :         struct xfs_mount        *mp = ip->i_mount;
      68         608 :         struct xfs_dquot        *dqp;
      69             : 
      70         608 :         if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
      71         608 :                 xfs_fill_statvfs_from_dquot(statp, ip, dqp);
      72         608 :                 xfs_qm_dqput(dqp);
      73             :         }
      74         608 : }
      75             : 
      76             : int
      77       22322 : xfs_qm_newmount(
      78             :         xfs_mount_t     *mp,
      79             :         uint            *needquotamount,
      80             :         uint            *quotaflags)
      81             : {
      82       22322 :         uint            quotaondisk;
      83       22322 :         uint            uquotaondisk = 0, gquotaondisk = 0, pquotaondisk = 0;
      84             : 
      85       22322 :         quotaondisk = xfs_has_quota(mp) &&
      86       19377 :                                 (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT);
      87             : 
      88       22322 :         if (quotaondisk) {
      89       19355 :                 uquotaondisk = mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT;
      90       19355 :                 pquotaondisk = mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT;
      91       19355 :                 gquotaondisk = mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT;
      92             :         }
      93             : 
      94             :         /*
      95             :          * If the device itself is read-only, we can't allow
      96             :          * the user to change the state of quota on the mount -
      97             :          * this would generate a transaction on the ro device,
      98             :          * which would lead to an I/O error and shutdown
      99             :          */
     100             : 
     101       22322 :         if (((uquotaondisk && !XFS_IS_UQUOTA_ON(mp)) ||
     102       22302 :             (!uquotaondisk &&  XFS_IS_UQUOTA_ON(mp)) ||
     103       19373 :              (gquotaondisk && !XFS_IS_GQUOTA_ON(mp)) ||
     104       19365 :             (!gquotaondisk &&  XFS_IS_GQUOTA_ON(mp)) ||
     105       19311 :              (pquotaondisk && !XFS_IS_PQUOTA_ON(mp)) ||
     106        3249 :             (!pquotaondisk &&  XFS_IS_PQUOTA_ON(mp)))  &&
     107        3057 :             xfs_dev_is_read_only(mp, "changing quota state")) {
     108          12 :                 xfs_warn(mp, "please mount with%s%s%s%s.",
     109             :                         (!quotaondisk ? "out quota" : ""),
     110             :                         (uquotaondisk ? " usrquota" : ""),
     111             :                         (gquotaondisk ? " grpquota" : ""),
     112             :                         (pquotaondisk ? " prjquota" : ""));
     113           4 :                 return -EPERM;
     114             :         }
     115             : 
     116       22318 :         if (XFS_IS_QUOTA_ON(mp) || quotaondisk) {
     117             :                 /*
     118             :                  * Call mount_quotas at this point only if we won't have to do
     119             :                  * a quotacheck.
     120             :                  */
     121       22318 :                 if (quotaondisk && !XFS_QM_NEED_QUOTACHECK(mp)) {
     122             :                         /*
     123             :                          * If an error occurred, qm_mount_quotas code
     124             :                          * has already disabled quotas. So, just finish
     125             :                          * mounting, and get on with the boring life
     126             :                          * without disk quotas.
     127             :                          */
     128       19237 :                         return xfs_qm_mount_quotas(mp);
     129             :                 } else {
     130             :                         /*
     131             :                          * Clear the quota flags, but remember them. This
     132             :                          * is so that the quota code doesn't get invoked
     133             :                          * before we're ready. This can happen when an
     134             :                          * inode goes inactive and wants to free blocks,
     135             :                          * or via xfs_log_mount_finish.
     136             :                          */
     137        3081 :                         *needquotamount = true;
     138        3081 :                         *quotaflags = mp->m_qflags;
     139        3081 :                         mp->m_qflags = 0;
     140             :                 }
     141             :         }
     142             : 
     143             :         return 0;
     144             : }

Generated by: LCOV version 1.14