Skip to content

Commit

Permalink
--file-extra-flags now accepts a list of flags rather than a single v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
akopytov committed Feb 3, 2018
1 parent ddaa13c commit d000761
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 52 deletions.
118 changes: 71 additions & 47 deletions src/tests/fileio/sb_fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ typedef enum
} file_io_mode_t;

typedef enum {
SB_FILE_FLAG_NORMAL,
SB_FILE_FLAG_SYNC,
SB_FILE_FLAG_DSYNC,
SB_FILE_FLAG_DIRECTIO
SB_FILE_FLAG_SYNC = 1,
SB_FILE_FLAG_DSYNC = 2,
SB_FILE_FLAG_DIRECTIO = 4
} file_flags_t;

#ifdef HAVE_LIBAIO
Expand Down Expand Up @@ -221,8 +220,8 @@ static sb_arg_t fileio_args[] = {
"number of asynchronous operatons to queue per thread", "128", INT),
#endif
SB_OPT("file-extra-flags",
"additional flags to use on opening files {sync,dsync,direct}",
"", STRING),
"list of additional flags to use to open files {sync,dsync,direct}",
"", LIST),
SB_OPT("file-fsync-freq", "do fsync() after this number of requests "
"(0 - don't use fsync())", "100", INT),
SB_OPT("file-fsync-all", "do fsync() after each write operation", "off",
Expand Down Expand Up @@ -798,12 +797,21 @@ int file_execute_event(sb_event_t *sb_req, int thread_id)

}

static void print_file_extra_flags(void)
{
log_text(LOG_NOTICE, "Extra file open flags: %s%s%s%s",
file_extra_flags == 0 ? "(none)" : "",
file_extra_flags & SB_FILE_FLAG_SYNC ? "sync " : "",
file_extra_flags & SB_FILE_FLAG_DSYNC ? "dsync ": "",
file_extra_flags & SB_FILE_FLAG_DIRECTIO ? "directio" : ""
);
}

void file_print_mode(void)
{
char sizestr[16];
log_text(LOG_NOTICE, "Extra file open flags: %x", file_extra_flags);

print_file_extra_flags();
log_text(LOG_NOTICE, "%d files, %sB each", num_files,
sb_print_value_size(sizestr, sizeof(sizestr), file_size));
log_text(LOG_NOTICE, "%sB total file size",
Expand Down Expand Up @@ -974,52 +982,63 @@ const char *get_test_mode_str(file_test_mode_t mode)

static int convert_extra_flags(file_flags_t extra_flags, int *open_flags)
{
switch (extra_flags) {
case SB_FILE_FLAG_NORMAL:
if (extra_flags == 0)
{
#ifdef _WIN32
*open_flags = FILE_ATTRIBUTE_NORMAL;
#endif
break;
case SB_FILE_FLAG_SYNC:
}
else
{
*open_flags = 0;

if (extra_flags & SB_FILE_FLAG_SYNC)
{
#ifdef _WIN32
*open_flags = FILE_FLAG_WRITE_THROUGH;
*open_flags |= FILE_FLAG_WRITE_THROUGH;
#else
*open_flags = O_SYNC;
*open_flags |= O_SYNC;
#endif
break;
case SB_FILE_FLAG_DSYNC:
}

if (extra_flags & SB_FILE_FLAG_DSYNC)
{
#ifdef O_DSYNC
*open_flags = O_DSYNC;
*open_flags |= O_DSYNC;
#else
log_text(LOG_FATAL,
"--file-extra-flags=dsync is not supported on this platform.");
return 1;
log_text(LOG_FATAL,
"--file-extra-flags=dsync is not supported on this platform.");
return 1;
#endif
break;
case SB_FILE_FLAG_DIRECTIO:
}

if (extra_flags & SB_FILE_FLAG_DIRECTIO)
{
#ifdef HAVE_DIRECTIO
/* Will call directio(3) later */
/* Will call directio(3) later */
#elif defined(O_DIRECT)
*open_flags = O_DIRECT;
*open_flags |= O_DIRECT;
#elif defined _WIN32
*open_flags = FILE_FLAG_NO_BUFFERING;
*open_flags |= FILE_FLAG_NO_BUFFERING;
#else
log_text(LOG_FATAL,
"--file-extra-flags=direct is not supported on this platform.");
return 1;
log_text(LOG_FATAL,
"--file-extra-flags=direct is not supported on this platform.");
return 1;
#endif
break;
default:
log_text(LOG_FATAL, "Unknown extra flags value: %d", (int) extra_flags);
return 1;
}

if (extra_flags > SB_FILE_FLAG_DIRECTIO)
{
log_text(LOG_FATAL, "Unknown extra flags value: %d", (int) extra_flags);
return 1;
}
}

return 0;
}

/* Create files of necessary size for test */


int create_files(void)
{
unsigned int i;
Expand All @@ -1035,7 +1054,7 @@ int create_files(void)
(long)(file_size / 1024),
(long)((file_size * num_files) / (1024 * 1024)));
log_text(LOG_NOTICE, "Creating files for the test...");
log_text(LOG_NOTICE, "Extra file open flags: %x", file_extra_flags);
print_file_extra_flags();

if (convert_extra_flags(file_extra_flags, &flags))
return 1;
Expand Down Expand Up @@ -1873,20 +1892,25 @@ int parse_arguments(void)
file_request_size = file_block_size;

mode = sb_get_value_string("file-extra-flags");
if (mode == NULL || !strlen(mode))
file_extra_flags = SB_FILE_FLAG_NORMAL;
else if (!strcmp(mode, "sync"))
file_extra_flags = SB_FILE_FLAG_SYNC;
else if (!strcmp(mode, "dsync"))
file_extra_flags = SB_FILE_FLAG_DSYNC;
else if (!strcmp(mode, "direct"))
file_extra_flags = SB_FILE_FLAG_DIRECTIO;
else

sb_list_item_t *pos;
SB_LIST_FOR_EACH(pos, sb_get_value_list("file-extra-flags"))
{
log_text(LOG_FATAL, "Invalid value for file-extra-flags: %s", mode);
return 1;
const char *val = SB_LIST_ENTRY(pos, value_t, listitem)->data;

if (!strcmp(val, "sync"))
file_extra_flags |= SB_FILE_FLAG_SYNC;
else if (!strcmp(val, "dsync"))
file_extra_flags |= SB_FILE_FLAG_DSYNC;
else if (!strcmp(val, "direct"))
file_extra_flags |= SB_FILE_FLAG_DIRECTIO;
else
{
log_text(LOG_FATAL, "Invalid value for file-extra-flags: %s", mode);
return 1;
}
}

file_fsync_freq = sb_get_value_int("file-fsync-freq");
if (file_fsync_freq < 0)
{
Expand Down Expand Up @@ -2028,7 +2052,7 @@ static FILE_DESCRIPTOR sb_open(const char *name)
#endif

#ifdef HAVE_DIRECTIO
if (VALID_FILE(file) && file_extra_flags == SB_FILE_FLAG_DIRECTIO &&
if (VALID_FILE(file) && file_extra_flags & SB_FILE_FLAG_DIRECTIO &&
directio(file, DIRECTIO_ON))
{
log_errno(LOG_FATAL, "directio() failed");
Expand Down
56 changes: 51 additions & 5 deletions tests/t/test_fileio.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fileio benchmark tests

4 files, 8192Kb each, 32Mb total
Creating files for the test...
Extra file open flags: 0
Extra file open flags: (none)
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Expand Down Expand Up @@ -42,7 +42,7 @@ fileio benchmark tests
Initializing random number generator from current time


Extra file open flags: 0
Extra file open flags: (none)
4 files, 8MiB each
32MiB total file size
Block size 16KiB
Expand Down Expand Up @@ -89,7 +89,7 @@ fileio benchmark tests
Initializing random number generator from current time


Extra file open flags: 0
Extra file open flags: (none)
4 files, 8MiB each
32MiB total file size
Block size 16KiB
Expand Down Expand Up @@ -137,7 +137,7 @@ fileio benchmark tests
Initializing random number generator from current time


Extra file open flags: 0
Extra file open flags: (none)
4 files, 8MiB each
32MiB total file size
Block size 16KiB
Expand Down Expand Up @@ -183,7 +183,7 @@ fileio benchmark tests
Initializing random number generator from current time


Extra file open flags: 0
Extra file open flags: (none)
4 files, 8MiB each
32MiB total file size
Block size 16KiB
Expand Down Expand Up @@ -269,3 +269,49 @@ GH-198: Tolerate misaligned test_files.
$ sysbench $args --file-test-mode=rndrd run
$ sysbench $args cleanup
$ unset args

########################################################################
Extra file flags. Not testing 'direct' as that is not supported on all
tested platforms
########################################################################
$ args="$fileio_args --file-total-size=16K --file-num=1"
$ sysbench $args --file-extra-flags= prepare
sysbench * (glob)

1 files, 16Kb each, 0Mb total
Creating files for the test...
Extra file open flags: (none)
Creating file test_file.0
16384 bytes written in 0.00 seconds (* MiB/sec). (glob)

$ sysbench $args --file-extra-flags=sync prepare
sysbench * (glob)

1 files, 16Kb each, 0Mb total
Creating files for the test...
Extra file open flags: sync
Reusing existing file test_file.0
No bytes written.

$ sysbench $args --file-extra-flags=dsync prepare
sysbench * (glob)

1 files, 16Kb each, 0Mb total
Creating files for the test...
Extra file open flags: dsync
Reusing existing file test_file.0
No bytes written.

$ sysbench $args --file-extra-flags=dsync,sync prepare
sysbench * (glob)

1 files, 16Kb each, 0Mb total
Creating files for the test...
Extra file open flags: sync dsync
Reusing existing file test_file.0
No bytes written.

$ sysbench $args --file-extra-flags= cleanup
sysbench * (glob)

Removing test files...

0 comments on commit d000761

Please sign in to comment.