generic: Add first statx test

Add a statx test script that does the following:

 (1) Creates one each of the various types of file object and creates a
     hard link to the regular file.

     Note that the creation of an AF_UNIX socket is done with netcat in a
     bash coprocessing thread.  This might be best done with another
     in-house helper to avoid a dependency on nc.

 (2) Invokes the C test program included in this patch after the creation
     and hands it a list of things to check appropriate to each object.

 (3) Asks the test program to check the creation time of each object
     against that of the preceding object.

 (4) Makes various tests on the timestamps of the hardlinked file.

The patch also creates a C[*] test program to do the actual stat checking.
The test program then does the following:

 (1) Compares the output of statx() to that of fstatat().

 (2) Optionally compares the timestamps to see that they're sensibly
     ordered with respect to each other.

 (3) Optionally compares the timestamps to those of a reference file.

 (4) Optionally compares the timestamps to a specified time.

 (5) Optionally compares selected stats to values specified on the command
     line.

 (6) Optionally compares all the stats to those of a reference file,
     requiring them to be the same (hard link checking).

For example:

	./src/stat_test /dev/null \
	       stx_type=char \
	       stx_rdev_major=3 \
	       stx_rdev_minor=8 \
	       stx_nlink=1 \
	       ref=/dev/zero \
	       ts=B,b

The test program can also be given a --check-statx parameter to give a
quick exit code-based answer on whether statx() exists within the kernel.

[*] Note that it proved much easier to do this in C than trying to do it in
    shell script and trying parsing the output of xfs_io.  Using xfs_io has
    other pitfalls also: it wants to *open* the file, even if the file is
    not an appropriate type for this or does not grant permission to do so.
    I can get around this by opening O_PATH, but then xfs_io fails to
    handle XFS files because it wants to issue ioctls on every fd it opens.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
David Howells
2017-04-10 14:32:52 +01:00
committed by Eryu Guan
parent 29f8137fcb
commit d1ba8b79a6
8 changed files with 1093 additions and 1 deletions
+1
View File
@@ -93,6 +93,7 @@
/src/seek_copy_test /src/seek_copy_test
/src/seek_sanity_test /src/seek_sanity_test
/src/stale_handle /src/stale_handle
/src/stat_test
/src/t_access_root /src/t_access_root
/src/t_dir_offset /src/t_dir_offset
/src/t_dir_offset2 /src/t_dir_offset2
+6
View File
@@ -3447,6 +3447,12 @@ _require_fs_sysfs()
fi fi
} }
_require_statx()
{
$here/src/stat_test --check-statx ||
_notrun "This test requires the statx system call"
}
# Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
# #
# All arguments are necessary, and in this order: # All arguments are necessary, and in this order:
+1 -1
View File
@@ -22,7 +22,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
renameat2 t_getcwd e4compact test-nextquota punch-alternating \ renameat2 t_getcwd e4compact test-nextquota punch-alternating \
attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \ attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \
dio-invalidate-cache dio-invalidate-cache stat_test
SUBDIRS = SUBDIRS =
+719
View File
File diff suppressed because it is too large Load Diff
+174
View File
@@ -0,0 +1,174 @@
#ifndef STATX_H
#define STATX_H
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/types.h>
#ifndef AT_STATX_SYNC_TYPE
#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
#endif
#ifndef AT_NO_AUTOMOUNT
#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
#endif
#ifndef __NR_statx
# ifdef __i386__
# define __NR_statx 383
# elif defined (__ILP32__)
# define __NR_statx (__X32_SYSCALL_BIT + 332)
# elif defined(__x86_64__)
# define __NR_statx 332
# endif
#endif
#ifndef STATX_TYPE
/*
* Timestamp structure for the timestamps in struct statx.
*
* tv_sec holds the number of seconds before (negative) or after (positive)
* 00:00:00 1st January 1970 UTC.
*
* tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
* negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
*
* Note that if both tv_sec and tv_nsec are non-zero, then the two values must
* either be both positive or both negative.
*
* __reserved is held in case we need a yet finer resolution.
*/
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
/*
* Structures for the extended file attribute retrieval system call
* (statx()).
*
* The caller passes a mask of what they're specifically interested in as a
* parameter to statx(). What statx() actually got will be indicated in
* st_mask upon return.
*
* For each bit in the mask argument:
*
* - if the datum is not supported:
*
* - the bit will be cleared, and
*
* - the datum will be set to an appropriate fabricated value if one is
* available (eg. CIFS can take a default uid and gid), otherwise
*
* - the field will be cleared;
*
* - otherwise, if explicitly requested:
*
* - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
* set or if the datum is considered out of date, and
*
* - the field will be filled in and the bit will be set;
*
* - otherwise, if not requested, but available in approximate form without any
* effort, it will be filled in anyway, and the bit will be set upon return
* (it might not be up to date, however, and no attempt will be made to
* synchronise the internal state first);
*
* - otherwise the field and the bit will be cleared before returning.
*
* Items in STATX_BASIC_STATS may be marked unavailable on return, but they
* will have values installed for compatibility purposes so that stat() and
* co. can be emulated in userspace.
*/
struct statx {
/* 0x00 */
__u32 stx_mask; /* What results were written [uncond] */
__u32 stx_blksize; /* Preferred general I/O size [uncond] */
__u64 stx_attributes; /* Flags conveying information about the file [uncond] */
/* 0x10 */
__u32 stx_nlink; /* Number of hard links */
__u32 stx_uid; /* User ID of owner */
__u32 stx_gid; /* Group ID of owner */
__u16 stx_mode; /* File mode */
__u16 __spare0[1];
/* 0x20 */
__u64 stx_ino; /* Inode number */
__u64 stx_size; /* File size */
__u64 stx_blocks; /* Number of 512-byte blocks allocated */
__u64 __spare1[1];
/* 0x40 */
struct statx_timestamp stx_atime; /* Last access time */
struct statx_timestamp stx_btime; /* File creation time */
struct statx_timestamp stx_ctime; /* Last attribute change time */
struct statx_timestamp stx_mtime; /* Last data modification time */
/* 0x80 */
__u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
__u32 stx_rdev_minor;
__u32 stx_dev_major; /* ID of device containing file [uncond] */
__u32 stx_dev_minor;
/* 0x90 */
__u64 __spare2[14]; /* Spare space for future expansion */
/* 0x100 */
};
/*
* Flags to be stx_mask
*
* Query request/result mask for statx() and struct statx::stx_mask.
*
* These bits should be set in the mask argument of statx() to request
* particular items when calling statx().
*/
#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
#define STATX_UID 0x00000008U /* Want/got stx_uid */
#define STATX_GID 0x00000010U /* Want/got stx_gid */
#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
#define STATX_INO 0x00000100U /* Want/got stx_ino */
#define STATX_SIZE 0x00000200U /* Want/got stx_size */
#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
#define STATX_ALL 0x00000fffU /* All currently supported flags */
/*
* Attributes to be found in stx_attributes
*
* These give information about the features or the state of a file that might
* be of use to ordinary userspace programs such as GUIs or ls rather than
* specialised tools.
*
* Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
* semantically. Where possible, the numerical value is picked to correspond
* also.
*/
#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
static inline
int xfstests_statx(int dfd, const char *filename, unsigned flags,
unsigned int mask, struct statx *buffer)
{
#ifdef __NR_statx
return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif /* STATX_TYPE */
#endif /* STATX_H */
+180
View File
@@ -0,0 +1,180 @@
#! /bin/bash
# FS QA Test 423
#
# Test the statx system call
#
#-----------------------------------------------------------------------
# Copyright (c) 2017 Red Hat, Inc. All Rights Reserved.
# Written by David Howells (dhowells@redhat.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#-----------------------------------------------------------------------
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
cd /
rm -f $tmp.*
rm -rf $TEST_DIR/$seq-*
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
# remove previous $seqres.full before test
rm -f $seqres.full
# real QA test starts here
# Modify as appropriate.
_supported_fs generic
_supported_os Linux
_require_test
_require_test_program "stat_test"
_require_test_program "af_unix"
_require_statx
function check_stat () {
$here/src/stat_test $* || echo stat_test failed
}
function create_af_unix () {
$here/src/af_unix $* || echo af_unix failed
}
###############################################################################
#
# Check statx'ing of various types of object
#
# After each object is created, barring the first, we check that the creation
# time and the change time of the new object as same as or later than the
# corresponding timestamps on the previous object created.
#
###############################################################################
echo "Test statx on a fifo"
mkfifo -m 0600 $TEST_DIR/$seq-fifo
check_stat $TEST_DIR/$seq-fifo \
ts_order \
stx_type=fifo \
stx_mode=0600 \
stx_rdev_major=0 \
stx_rdev_minor=0 \
stx_nlink=1
echo "Test statx on a chardev"
mknod -m 0600 $TEST_DIR/$seq-null c 1 3
check_stat $TEST_DIR/$seq-null \
ts_order \
ref=$TEST_DIR/$seq-fifo \
ts=B,b \
ts=M,m \
stx_type=char \
stx_mode=0600 \
stx_rdev_major=1 \
stx_rdev_minor=3 \
stx_nlink=1
echo "Test statx on a directory"
mkdir $TEST_DIR/$seq-dir
check_stat $TEST_DIR/$seq-dir \
ts_order \
ref=$TEST_DIR/$seq-null \
ts=B,b \
ts=M,m \
stx_type=dir \
stx_mode=0755 \
stx_rdev_major=0 \
stx_rdev_minor=0
echo "Test statx on a blockdev"
mknod -m 0600 $TEST_DIR/$seq-loopy b 7 123
check_stat $TEST_DIR/$seq-loopy \
ts_order \
ref=$TEST_DIR/$seq-dir \
ts=B,b \
ts=M,m \
stx_type=block \
stx_mode=0600 \
stx_rdev_major=7 \
stx_rdev_minor=123 \
stx_nlink=1
echo "Test statx on a file"
dd if=/dev/zero of=$TEST_DIR/$seq-file bs=1024 count=20
check_stat $TEST_DIR/$seq-file \
ts_order \
ref=$TEST_DIR/$seq-loopy \
ts=B,b \
ts=M,m \
stx_type=file \
stx_size=20480 \
stx_rdev_major=0 \
stx_rdev_minor=0 \
stx_nlink=1
echo "Test statx on a symlink"
ln -s $TEST_DIR/$seq-nowhere $TEST_DIR/$seq-symlink
check_stat $TEST_DIR/$seq-symlink \
ts_order \
ref=$TEST_DIR/$seq-file \
ts=B,b \
ts=M,m \
stx_type=sym \
stx_rdev_major=0 \
stx_rdev_minor=0 \
stx_nlink=1
echo "Test statx on an AF_UNIX socket"
create_af_unix $TEST_DIR/$seq-sock
check_stat $TEST_DIR/$seq-sock \
ts_order \
ref=$TEST_DIR/$seq-symlink \
ts=B,b \
ts=M,m \
stx_type=sock \
stx_rdev_major=0 \
stx_rdev_minor=0 \
stx_nlink=1
#
# Test hard link creation. Make sure that the file's ctime is now same as or
# later than the creation time of the socket, but that the file's creation time
# still lies somewhere between those of the directory and the socket.
#
echo "Test a hard link to a file"
ln $TEST_DIR/$seq-file $TEST_DIR/$seq-link
check_stat $TEST_DIR/$seq-link \
ref=$TEST_DIR/$seq-dir \
ts=B,b \
ref=$TEST_DIR/$seq-sock \
ts=b,B \
ts=B,c \
ts=C,c \
ref=$TEST_DIR/$seq-file \
cmp_ref \
stx_nlink=2
# Done. We leave the success determination to the output comparator.
status=0
exit
+11
View File
@@ -0,0 +1,11 @@
QA output created by 423
Test statx on a fifo
Test statx on a chardev
Test statx on a directory
Test statx on a blockdev
Test statx on a file
20+0 records in
20+0 records out
Test statx on a symlink
Test statx on an AF_UNIX socket
Test a hard link to a file
+1
View File
@@ -425,3 +425,4 @@
420 auto quick punch 420 auto quick punch
421 auto quick encrypt dangerous 421 auto quick encrypt dangerous
422 auto quick 422 auto quick
423 auto quick