-
-
Save keyurdg/54e0613e27dbe7946035 to your computer and use it in GitHub Desktop.
Test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <sys/types.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
#define BLOCK_SIZE 524288 | |
#define FILES_LIMIT 2 | |
int main(int argc, char **argv) { | |
char *data; | |
u_int64_t rc, f_i, w_i, rand_n; | |
int64_t fds[FILES_LIMIT]; | |
char filename[2048]; | |
rc = 0; | |
if (posix_memalign((void **) &data, 512, BLOCK_SIZE)) { | |
rc = 2; | |
goto err; | |
} | |
memset(data, 'b', BLOCK_SIZE); | |
for (f_i=0; f_i < FILES_LIMIT; f_i++) { | |
sprintf(filename, "/var/lib/mysql/xfs/plain_pwrite_%lld.werr", f_i); | |
fds[f_i] = open(filename, O_CREAT | O_RDWR | (argc > 1 ? O_DIRECT : 0)); | |
if (fds[f_i] < 0) { | |
rc = 1; | |
goto err; | |
} | |
} | |
for (w_i=0; w_i<8192; w_i++) { | |
int64_t fd, s, off; | |
// rand_n = i % FILES_LIMIT; | |
rand_n = rand() % FILES_LIMIT; | |
fd = fds[rand_n]; | |
printf("file rand = %llu fd = %lld\n", rand_n, fd); | |
off = lseek(fd, 0, SEEK_END); | |
s = pwrite(fd, data, BLOCK_SIZE, off); | |
printf("wrote %lld bytes, file offset %lld\n", s, off); | |
if (s < 0) { | |
rc = 3; | |
goto err; | |
} | |
s = fsync(fd); | |
printf("fsync success %lld\n", s); | |
if (s < 0) { | |
rc = 4; | |
goto err; | |
} | |
} | |
err: | |
free(data); | |
for (; f_i; f_i--) { | |
close(fds[f_i]); | |
} | |
return rc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment