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-xfsx @ Mon Jul 31 20:08:34 PDT 2023 Lines: 52 52 100.0 %
Date: 2023-07-31 20:08:34 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        3355 : xfs_fill_statvfs_from_dquot(
      22             :         struct kstatfs          *statp,
      23             :         struct xfs_inode        *ip,
      24             :         struct xfs_dquot        *dqp)
      25             : {
      26        3355 :         struct xfs_dquot_res    *blkres = &dqp->q_blk;
      27        3355 :         uint64_t                limit;
      28             : 
      29        3355 :         if (XFS_IS_REALTIME_MOUNT(ip->i_mount) &&
      30        1528 :             (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME)))
      31         111 :                 blkres = &dqp->q_rtb;
      32             : 
      33        3355 :         limit = blkres->softlimit ?
      34        3355 :                 blkres->softlimit :
      35             :                 blkres->hardlimit;
      36        3355 :         if (limit && statp->f_blocks > limit) {
      37        2559 :                 statp->f_blocks = limit;
      38        2559 :                 statp->f_bfree = statp->f_bavail =
      39        2559 :                         (statp->f_blocks > blkres->reserved) ?
      40        2559 :                          (statp->f_blocks - blkres->reserved) : 0;
      41             :         }
      42             : 
      43        3355 :         limit = dqp->q_ino.softlimit ?
      44        3355 :                 dqp->q_ino.softlimit :
      45             :                 dqp->q_ino.hardlimit;
      46        3355 :         if (limit && statp->f_files > limit) {
      47        1256 :                 statp->f_files = limit;
      48        1256 :                 statp->f_ffree =
      49        1256 :                         (statp->f_files > dqp->q_ino.reserved) ?
      50        1256 :                          (statp->f_files - dqp->q_ino.reserved) : 0;
      51             :         }
      52        3355 : }
      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        3355 : xfs_qm_statvfs(
      64             :         struct xfs_inode        *ip,
      65             :         struct kstatfs          *statp)
      66             : {
      67        3355 :         struct xfs_mount        *mp = ip->i_mount;
      68        3355 :         struct xfs_dquot        *dqp;
      69             : 
      70        3355 :         if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
      71        3355 :                 xfs_fill_statvfs_from_dquot(statp, ip, dqp);
      72        3355 :                 xfs_qm_dqput(dqp);
      73             :         }
      74        3355 : }
      75             : 
      76             : int
      77       57646 : xfs_qm_newmount(
      78             :         xfs_mount_t     *mp,
      79             :         uint            *needquotamount,
      80             :         uint            *quotaflags)
      81             : {
      82       57646 :         uint            quotaondisk;
      83       57646 :         uint            uquotaondisk = 0, gquotaondisk = 0, pquotaondisk = 0;
      84             : 
      85       57646 :         quotaondisk = xfs_has_quota(mp) &&
      86       44072 :                                 (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT);
      87             : 
      88       57646 :         if (quotaondisk) {
      89       43956 :                 uquotaondisk = mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT;
      90       43956 :                 pquotaondisk = mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT;
      91       43956 :                 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       57646 :         if (((uquotaondisk && !XFS_IS_UQUOTA_ON(mp)) ||
     102       57536 :             (!uquotaondisk &&  XFS_IS_UQUOTA_ON(mp)) ||
     103       44065 :              (gquotaondisk && !XFS_IS_GQUOTA_ON(mp)) ||
     104       44021 :             (!gquotaondisk &&  XFS_IS_GQUOTA_ON(mp)) ||
     105       43736 :              (pquotaondisk && !XFS_IS_PQUOTA_ON(mp)) ||
     106       15225 :             (!pquotaondisk &&  XFS_IS_PQUOTA_ON(mp)))  &&
     107       14156 :             xfs_dev_is_read_only(mp, "changing quota state")) {
     108          80 :                 xfs_warn(mp, "please mount with%s%s%s%s.",
     109             :                         (!quotaondisk ? "out quota" : ""),
     110             :                         (uquotaondisk ? " usrquota" : ""),
     111             :                         (gquotaondisk ? " grpquota" : ""),
     112             :                         (pquotaondisk ? " prjquota" : ""));
     113          20 :                 return -EPERM;
     114             :         }
     115             : 
     116       57626 :         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       57626 :                 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       43352 :                         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       14274 :                         *needquotamount = true;
     138       14274 :                         *quotaflags = mp->m_qflags;
     139       14274 :                         mp->m_qflags = 0;
     140             :                 }
     141             :         }
     142             : 
     143             :         return 0;
     144             : }

Generated by: LCOV version 1.14