common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / common / populate
index eeac66d70c4a030bd29efcf4e14d8fc119d8e382..867776cdd189bf6184cc058692f1cd5d52e3ff47 100644 (file)
@@ -154,6 +154,16 @@ _scratch_xfs_populate() {
 
        _populate_xfs_qmount_option
        _scratch_mount
+
+       # We cannot directly force the filesystem to create the metadata
+       # structures we want; we can only achieve this indirectly by carefully
+       # crafting files and a directory tree.  Therefore, we must have exact
+       # control over the layout and device selection of all files created.
+       # Clear the rtinherit flag on the root directory so that files are
+       # always created on the data volume regardless of MKFS_OPTIONS.  We can
+       # set the realtime flag when needed.
+       _xfs_force_bdev data $SCRATCH_MNT
+
        blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
        dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
        crc="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep crc= | sed -e 's/^.*crc=//g' -e 's/\([0-9]*\).*$/\1/g')"
@@ -220,7 +230,8 @@ _scratch_xfs_populate() {
        # Char & block
        echo "+ special"
        mknod "${SCRATCH_MNT}/S_IFCHR" c 1 1
-       mknod "${SCRATCH_MNT}/S_IFBLK" c 1 1
+       mknod "${SCRATCH_MNT}/S_IFBLK" b 1 1
+       mknod "${SCRATCH_MNT}/S_IFIFO" p
 
        # special file with an xattr
        setfacl -P -m u:nobody:r ${SCRATCH_MNT}/S_IFCHR
@@ -306,6 +317,7 @@ _scratch_xfs_populate() {
        if [ $is_rmapbt -gt 0 ] && [ $is_rt -gt 0 ]; then
                echo "+ rtrmapbt btree"
                nr="$((blksz * 2 / 32))"
+               $XFS_IO_PROG -R -f -c 'truncate 0' "${SCRATCH_MNT}/RTRMAPBT"
                __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/RTRMAPBT"
        fi
 
@@ -391,7 +403,8 @@ _scratch_ext4_populate() {
        # Char & block
        echo "+ special"
        mknod "${SCRATCH_MNT}/S_IFCHR" c 1 1
-       mknod "${SCRATCH_MNT}/S_IFBLK" c 1 1
+       mknod "${SCRATCH_MNT}/S_IFBLK" b 1 1
+       mknod "${SCRATCH_MNT}/S_IFIFO" p
 
        # special file with an xattr
        setfacl -P -m u:nobody:r ${SCRATCH_MNT}/S_IFCHR
@@ -569,6 +582,7 @@ _scratch_xfs_populate_check() {
        extents_slink="$(__populate_find_inode "${SCRATCH_MNT}/S_IFLNK.FMT_EXTENTS")"
        bdev="$(__populate_find_inode "${SCRATCH_MNT}/S_IFBLK")"
        cdev="$(__populate_find_inode "${SCRATCH_MNT}/S_IFCHR")"
+       fifo="$(__populate_find_inode "${SCRATCH_MNT}/S_IFIFO")"
        local_attr="$(__populate_find_inode "${SCRATCH_MNT}/ATTR.FMT_LOCAL")"
        leaf_attr="$(__populate_find_inode "${SCRATCH_MNT}/ATTR.FMT_LEAF")"
        node_attr="$(__populate_find_inode "${SCRATCH_MNT}/ATTR.FMT_NODE")"
@@ -594,6 +608,7 @@ _scratch_xfs_populate_check() {
        __populate_check_xfs_dformat "${btree_dir}" "btree"
        __populate_check_xfs_dformat "${bdev}" "dev"
        __populate_check_xfs_dformat "${cdev}" "dev"
+       __populate_check_xfs_dformat "${fifo}" "dev"
        __populate_check_xfs_attr "${local_attr}" "local"
        __populate_check_xfs_attr "${leaf_attr}" "leaf"
        __populate_check_xfs_attr "${node_attr}" "node"
@@ -777,7 +792,7 @@ _fill_fs()
                fi
 
                if [ -f $dir/$file_count ]; then
-                       bytes_written=$(stat -c '%s' $dir/$file_count)
+                       bytes_written=$(_get_filesize $dir/$file_count)
                fi
 
                # If there was no room to make the file, then divide it in
@@ -793,13 +808,23 @@ _fill_fs()
 _scratch_populate_cache_tag() {
        local extra_descr=""
        local size="$(blockdev --getsz "${SCRATCH_DEV}")"
+       local logdev_sz="none"
+       local rtdev_sz="none"
+
+       if [ "${USE_EXTERNAL}" = "yes" ] && [ -n "${SCRATCH_LOGDEV}" ]; then
+               logdev_sz="$(blockdev --getsz "${SCRATCH_LOGDEV}")"
+       fi
+
+       if [ "${USE_EXTERNAL}" = "yes" ] && [ -n "${SCRATCH_RTDEV}" ]; then
+               rtdev_sz="$(blockdev --getsz "${SCRATCH_RTDEV}")"
+       fi
 
        case "${FSTYP}" in
        "ext4")
-               extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL}"
+               extra_descr="LOGDEV_SIZE ${logdev_sz}"
                ;;
        "xfs")
-               extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL} RTDEV ${SCRATCH_RTDEV}"
+               extra_descr="LOGDEV_SIZE ${logdev_sz} RTDEV_SIZE ${rtdev_sz}"
                _populate_xfs_qmount_option
                if echo "${MOUNT_OPTIONS}" | grep -q 'usrquota'; then
                        extra_descr="${extra_descr} QUOTAS"
@@ -813,6 +838,17 @@ _scratch_populate_cache_tag() {
 _scratch_populate_restore_cached() {
        local metadump="$1"
 
+       # If we're configured for compressed dumps and there isn't already an
+       # uncompressed dump, see if we can use DUMP_COMPRESSOR to decompress
+       # something.
+       if [ -n "$DUMP_COMPRESSOR" ]; then
+               for compr in "$metadump".*; do
+                       [ -e "$compr" ] && $DUMP_COMPRESSOR -d -f -k "$compr" && break
+               done
+       fi
+
+       test -r "$metadump" || return 1
+
        case "${FSTYP}" in
        "xfs")
                xfs_mdrestore "${metadump}" "${SCRATCH_DEV}" && return 0
@@ -844,8 +880,7 @@ _scratch_populate_cached() {
                rm -rf "${POPULATE_METADUMP}"
 
        # Try to restore from the metadump
-       test -r "${POPULATE_METADUMP}" && \
-               _scratch_populate_restore_cached "${POPULATE_METADUMP}" && \
+       _scratch_populate_restore_cached "${POPULATE_METADUMP}" && \
                return
 
        # Oh well, just create one from scratch
@@ -855,12 +890,19 @@ _scratch_populate_cached() {
        "xfs")
                _scratch_xfs_populate $@
                _scratch_xfs_populate_check
-               _scratch_metadump "${POPULATE_METADUMP}" -a -o
+               _scratch_xfs_metadump "${POPULATE_METADUMP}"
+
+               local logdev=
+               [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+                       logdev=$SCRATCH_LOGDEV
+
+               _xfs_metadump "$POPULATE_METADUMP" "$SCRATCH_DEV" "$logdev" \
+                       compress
                ;;
        "ext2"|"ext3"|"ext4")
                _scratch_ext4_populate $@
                _scratch_ext4_populate_check
-               e2image -Q "${SCRATCH_DEV}" "${POPULATE_METADUMP}"
+               _ext4_metadump "${SCRATCH_DEV}" "${POPULATE_METADUMP}" compress
                ;;
        *)
                _fail "Don't know how to populate a ${FSTYP} filesystem."