From: Alex Elder <aelder@sgi.com>
To: xfs@oss.sgi.com
Subject: [PATCH 08/11] xfstests: randholes: encapsulate realtime setup code
Date: Thu, 14 Oct 2010 09:50:43 -0500 [thread overview]
Message-ID: <1287067843.2362.220.camel@doink> (raw)
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>
---
src/randholes.c | 55 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 30 insertions(+), 25 deletions(-)
Index: b/src/randholes.c
===================================================================
--- a/src/randholes.c
+++ b/src/randholes.c
@@ -43,7 +43,6 @@ int preserve;
int test;
__uint64_t fileoffset;
-struct fsxattr rtattr;
#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)
{
__uint64_t offset;
- char *buffer;
+ char *buffer = NULL;
int block;
struct flock64 fl;
- if (test)
- buffer = NULL;
- else {
+ if (!test) {
if (posix_memalign((void **) &buffer, alignment, blocksize)) {
perror("malloc");
exit(1);
@@ -307,6 +304,30 @@ get_alignment(char *filename, int fd)
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
main(int argc, char *argv[])
{
@@ -333,7 +354,7 @@ main(int argc, char *argv[])
case 'v': verbose++; break;
case 'w': wsync++; break;
case 'd': direct++; break;
- case 'r': rt++; break;
+ case 'r': rt++; direct++; break;
case 'a': alloconly++; break;
case 'p': preserve++; break;
case 't': test++; preserve++; break;
@@ -371,7 +392,7 @@ main(int argc, char *argv[])
blocksize, (unsigned long long)filesize, seed,
count, (unsigned long long)fileoffset, extsize);
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
@@ -382,8 +403,6 @@ main(int argc, char *argv[])
perror("malloc");
return 1;
}
- if (rt)
- direct++;
oflags=test?(O_RDONLY):(O_RDWR | O_CREAT);
oflags |= (preserve ? 0 : O_TRUNC) |
@@ -395,22 +414,8 @@ main(int argc, char *argv[])
return 1;
}
- if (rt) {
- if (xfscntl(filename, fd, FSGETXATTR, &rtattr) < 0) {
- 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;
- }
- }
- }
+ if (rt && realtime_setup(filename, fd))
+ return 1;
alignment = get_alignment(filename, fd);
if (! alignment)
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
reply other threads:[~2010-10-14 14:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287067843.2362.220.camel@doink \
--to=aelder@sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox