common: _scratch_mkfs_sized() for tmpfs
authorHugh Dickins <hughd@google.com>
Thu, 18 Feb 2016 23:44:11 +0000 (10:44 +1100)
committerDave Chinner <david@fromorbit.com>
Thu, 18 Feb 2016 23:44:11 +0000 (10:44 +1100)
Enable _scratch_mkfs_sized() for use with tmpfs, so that tests which
use this helper can now run.

Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Junho Ryu <jayr@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
common/rc

index 52c4a36ec8d9a594364e747c9c86272548809375..582a32c8cb5828a90f1b3b253f72c8bf676e6b70 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -783,6 +783,12 @@ _scratch_pool_mkfs()
     esac
 }
 
+# Return the amount of free memory available on the system
+_free_memory_bytes()
+{
+    free -b | grep ^Mem | awk '{print $4}'
+}
+
 # Create fs of certain size on scratch device
 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
 _scratch_mkfs_sized()
@@ -813,7 +819,7 @@ _scratch_mkfs_sized()
 
     blocks=`expr $fssize / $blocksize`
 
-    if [ "$HOSTOS" == "Linux" ]; then
+    if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
        devsize=`blockdev --getsize64 $SCRATCH_DEV`
        [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
     fi
@@ -849,6 +855,13 @@ _scratch_mkfs_sized()
        sector_size=`blockdev --getss $SCRATCH_DEV`
        $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
        ;;
+    tmpfs)
+       free_mem=`_free_memory_bytes`
+       if [ "$free_mem" -lt "$fssize" ] ; then
+          _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
+       fi
+       export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
+       ;;
     *)
        _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
        ;;