Print this page
7178 tmpfs incorrectly calculates amount of free space


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011, Joyent, Inc. All rights reserved.

  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/param.h>
  28 #include <sys/sysmacros.h>
  29 #include <sys/kmem.h>
  30 #include <sys/time.h>
  31 #include <sys/pathname.h>
  32 #include <sys/vfs.h>
  33 #include <sys/vfs_opreg.h>
  34 #include <sys/vnode.h>
  35 #include <sys/stat.h>
  36 #include <sys/uio.h>
  37 #include <sys/stat.h>
  38 #include <sys/errno.h>
  39 #include <sys/cmn_err.h>
  40 #include <sys/cred.h>
  41 #include <sys/statvfs.h>
  42 #include <sys/mount.h>
  43 #include <sys/debug.h>


 572         if (zp == NULL)
 573                 eff_zid = GLOBAL_ZONEUNIQID;
 574         else
 575                 eff_zid = zp->zone_id;
 576 
 577         sbp->f_bsize = PAGESIZE;
 578         sbp->f_frsize = PAGESIZE;
 579 
 580         /*
 581          * Find the amount of available physical and memory swap
 582          */
 583         mutex_enter(&anoninfo_lock);
 584         ASSERT(k_anoninfo.ani_max >= k_anoninfo.ani_phys_resv);
 585         blocks = (ulong_t)CURRENT_TOTAL_AVAILABLE_SWAP;
 586         mutex_exit(&anoninfo_lock);
 587 
 588         /*
 589          * If tm_anonmax for this mount is less than the available swap space
 590          * (minus the amount tmpfs can't use), use that instead
 591          */
 592         if (blocks > tmpfs_minfree)
 593                 sbp->f_bfree = MIN(blocks - tmpfs_minfree,
 594                     tm->tm_anonmax - tm->tm_anonmem);
 595         else
 596                 sbp->f_bfree = 0;
 597 
 598         sbp->f_bavail = sbp->f_bfree;
 599 
 600         /*
 601          * Total number of blocks is what's available plus what's been used
 602          */
 603         sbp->f_blocks = (fsblkcnt64_t)(sbp->f_bfree + tm->tm_anonmem);
 604 
 605         if (eff_zid != GLOBAL_ZONEUNIQID &&
 606             zp->zone_max_swap_ctl != UINT64_MAX) {
 607                 /*
 608                  * If the fs is used by a non-global zone with a swap cap,
 609                  * then report the capped size.
 610                  */
 611                 rctl_qty_t cap, used;
 612                 pgcnt_t pgcap, pgused;




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
  24  * Copyright 2016 RackTop Systems.
  25  */
  26 
  27 #include <sys/types.h>
  28 #include <sys/param.h>
  29 #include <sys/sysmacros.h>
  30 #include <sys/kmem.h>
  31 #include <sys/time.h>
  32 #include <sys/pathname.h>
  33 #include <sys/vfs.h>
  34 #include <sys/vfs_opreg.h>
  35 #include <sys/vnode.h>
  36 #include <sys/stat.h>
  37 #include <sys/uio.h>
  38 #include <sys/stat.h>
  39 #include <sys/errno.h>
  40 #include <sys/cmn_err.h>
  41 #include <sys/cred.h>
  42 #include <sys/statvfs.h>
  43 #include <sys/mount.h>
  44 #include <sys/debug.h>


 573         if (zp == NULL)
 574                 eff_zid = GLOBAL_ZONEUNIQID;
 575         else
 576                 eff_zid = zp->zone_id;
 577 
 578         sbp->f_bsize = PAGESIZE;
 579         sbp->f_frsize = PAGESIZE;
 580 
 581         /*
 582          * Find the amount of available physical and memory swap
 583          */
 584         mutex_enter(&anoninfo_lock);
 585         ASSERT(k_anoninfo.ani_max >= k_anoninfo.ani_phys_resv);
 586         blocks = (ulong_t)CURRENT_TOTAL_AVAILABLE_SWAP;
 587         mutex_exit(&anoninfo_lock);
 588 
 589         /*
 590          * If tm_anonmax for this mount is less than the available swap space
 591          * (minus the amount tmpfs can't use), use that instead
 592          */
 593         if (blocks > tmpfs_minfree && tm->tm_anonmax > tm->tm_anonmem)
 594                 sbp->f_bfree = MIN(blocks - tmpfs_minfree,
 595                     tm->tm_anonmax - tm->tm_anonmem);
 596         else
 597                 sbp->f_bfree = 0;
 598 
 599         sbp->f_bavail = sbp->f_bfree;
 600 
 601         /*
 602          * Total number of blocks is what's available plus what's been used
 603          */
 604         sbp->f_blocks = (fsblkcnt64_t)(sbp->f_bfree + tm->tm_anonmem);
 605 
 606         if (eff_zid != GLOBAL_ZONEUNIQID &&
 607             zp->zone_max_swap_ctl != UINT64_MAX) {
 608                 /*
 609                  * If the fs is used by a non-global zone with a swap cap,
 610                  * then report the capped size.
 611                  */
 612                 rctl_qty_t cap, used;
 613                 pgcnt_t pgcap, pgused;