mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
xfstests: randholes: encapsulate realtime setup code
Encapsulate the code that sets up the use of files on the realtime volume. Using realtime implies direct I/O; move the code that makes that so into the argument parsing code. Signed-off-by: Alex Elder <aelder@sgi.com> Acked-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
+30
-25
@@ -43,7 +43,6 @@ int preserve;
|
|||||||
int test;
|
int test;
|
||||||
__uint64_t fileoffset;
|
__uint64_t fileoffset;
|
||||||
|
|
||||||
struct fsxattr rtattr;
|
|
||||||
|
|
||||||
#define READ_XFER 10 /* block to read at a time when checking */
|
#define READ_XFER 10 /* block to read at a time when checking */
|
||||||
|
|
||||||
@@ -119,13 +118,11 @@ void
|
|||||||
writeblks(char *fname, int fd, size_t alignment)
|
writeblks(char *fname, int fd, size_t alignment)
|
||||||
{
|
{
|
||||||
__uint64_t offset;
|
__uint64_t offset;
|
||||||
char *buffer;
|
char *buffer = NULL;
|
||||||
int block;
|
int block;
|
||||||
struct flock64 fl;
|
struct flock64 fl;
|
||||||
|
|
||||||
if (test)
|
if (!test) {
|
||||||
buffer = NULL;
|
|
||||||
else {
|
|
||||||
if (posix_memalign((void **) &buffer, alignment, blocksize)) {
|
if (posix_memalign((void **) &buffer, alignment, blocksize)) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -307,6 +304,30 @@ get_alignment(char *filename, int fd)
|
|||||||
return (size_t) dioattr.d_mem;
|
return (size_t) dioattr.d_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
realtime_setup(char *filename, int fd)
|
||||||
|
{
|
||||||
|
struct fsxattr rtattr;
|
||||||
|
|
||||||
|
(void) memset(&rtattr, 0, sizeof rtattr);
|
||||||
|
if (xfscntl(filename, fd, FSGETXATTR, &rtattr) < 0) {
|
||||||
|
perror("FSGETXATTR)");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ((rtattr.fsx_xflags & XFS_XFLAG_REALTIME) == 0 ||
|
||||||
|
(extsize && rtattr.fsx_extsize != extsize * blocksize)) {
|
||||||
|
rtattr.fsx_xflags |= XFS_XFLAG_REALTIME;
|
||||||
|
if (extsize)
|
||||||
|
rtattr.fsx_extsize = extsize * blocksize;
|
||||||
|
if (xfscntl(filename, fd, FSSETXATTR, &rtattr) < 0) {
|
||||||
|
perror("FSSETXATTR)");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -333,7 +354,7 @@ main(int argc, char *argv[])
|
|||||||
case 'v': verbose++; break;
|
case 'v': verbose++; break;
|
||||||
case 'w': wsync++; break;
|
case 'w': wsync++; break;
|
||||||
case 'd': direct++; break;
|
case 'd': direct++; break;
|
||||||
case 'r': rt++; break;
|
case 'r': rt++; direct++; break;
|
||||||
case 'a': alloconly++; break;
|
case 'a': alloconly++; break;
|
||||||
case 'p': preserve++; break;
|
case 'p': preserve++; break;
|
||||||
case 't': test++; preserve++; break;
|
case 't': test++; preserve++; break;
|
||||||
@@ -371,7 +392,7 @@ main(int argc, char *argv[])
|
|||||||
blocksize, (unsigned long long)filesize, seed,
|
blocksize, (unsigned long long)filesize, seed,
|
||||||
count, (unsigned long long)fileoffset, extsize);
|
count, (unsigned long long)fileoffset, extsize);
|
||||||
printf("randholes: verbose=%d, wsync=%d, direct=%d, rt=%d, alloconly=%d, preserve=%d, test=%d\n",
|
printf("randholes: verbose=%d, wsync=%d, direct=%d, rt=%d, alloconly=%d, preserve=%d, test=%d\n",
|
||||||
verbose, wsync, direct, rt, alloconly, preserve, test);
|
verbose, wsync, direct ? 1 : 0, rt, alloconly, preserve, test);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the file, write rand block in random places, read them all
|
* Open the file, write rand block in random places, read them all
|
||||||
@@ -382,8 +403,6 @@ main(int argc, char *argv[])
|
|||||||
perror("malloc");
|
perror("malloc");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (rt)
|
|
||||||
direct++;
|
|
||||||
|
|
||||||
oflags=test?(O_RDONLY):(O_RDWR | O_CREAT);
|
oflags=test?(O_RDONLY):(O_RDWR | O_CREAT);
|
||||||
oflags |= (preserve ? 0 : O_TRUNC) |
|
oflags |= (preserve ? 0 : O_TRUNC) |
|
||||||
@@ -395,22 +414,8 @@ main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rt) {
|
if (rt && realtime_setup(filename, fd))
|
||||||
if (xfscntl(filename, fd, FSGETXATTR, &rtattr) < 0) {
|
return 1;
|
||||||
perror("xfsnctl(FSGETXATTR)");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ((rtattr.fsx_xflags & XFS_XFLAG_REALTIME) == 0 ||
|
|
||||||
(extsize && rtattr.fsx_extsize != extsize * blocksize)) {
|
|
||||||
rtattr.fsx_xflags |= XFS_XFLAG_REALTIME;
|
|
||||||
if (extsize)
|
|
||||||
rtattr.fsx_extsize = extsize * blocksize;
|
|
||||||
if (xfscntl(filename, fd, FSSETXATTR, &rtattr) < 0) {
|
|
||||||
perror("xfscntl(FSSETXATTR)");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
alignment = get_alignment(filename, fd);
|
alignment = get_alignment(filename, fd);
|
||||||
if (! alignment)
|
if (! alignment)
|
||||||
|
|||||||
Reference in New Issue
Block a user