add mknod support

Add new option '-k' to support file creation test with mknod,
which is widely used in lustre.

Signed-off-by: Gu Zheng <gzheng@ddn.com>
master
Gu Zheng 2018-10-08 20:30:47 +08:00
parent 351f6e9107
commit a6f8388f9f
3 changed files with 41 additions and 5 deletions

View File

@ -107,6 +107,7 @@ ior_aiori_t posix_aiori = {
.name = "POSIX", .name = "POSIX",
.name_legacy = NULL, .name_legacy = NULL,
.create = POSIX_Create, .create = POSIX_Create,
.mknod = POSIX_Mknod,
.open = POSIX_Open, .open = POSIX_Open,
.xfer = POSIX_Xfer, .xfer = POSIX_Xfer,
.close = POSIX_Close, .close = POSIX_Close,
@ -427,6 +428,24 @@ void *POSIX_Create(char *testFileName, IOR_param_t * param)
return ((void *)fd); return ((void *)fd);
} }
/*
* Creat a file through mknod interface.
*/
void *POSIX_Mknod(char *testFileName)
{
int *fd;
fd = (int *)malloc(sizeof(int));
if (fd == NULL)
ERR("Unable to malloc file descriptor");
*fd = mknod(testFileName, S_IFREG | S_IRUSR, 0);
if (*fd < 0)
ERR("mknod failed");
return ((void *)fd);
}
/* /*
* Open a file through the POSIX interface. * Open a file through the POSIX interface.
*/ */

View File

@ -68,6 +68,7 @@ typedef struct ior_aiori {
char *name; char *name;
char *name_legacy; char *name_legacy;
void *(*create)(char *, IOR_param_t *); void *(*create)(char *, IOR_param_t *);
void *(*mknod)(char *);
void *(*open)(char *, IOR_param_t *); void *(*open)(char *, IOR_param_t *);
IOR_offset_t (*xfer)(int, void *, IOR_size_t *, IOR_offset_t (*xfer)(int, void *, IOR_size_t *,
IOR_offset_t, IOR_param_t *); IOR_offset_t, IOR_param_t *);
@ -125,6 +126,7 @@ int aiori_posix_access (const char *path, int mode, IOR_param_t * param);
int aiori_posix_stat (const char *path, struct stat *buf, IOR_param_t * param); int aiori_posix_stat (const char *path, struct stat *buf, IOR_param_t * param);
void *POSIX_Create(char *testFileName, IOR_param_t * param); void *POSIX_Create(char *testFileName, IOR_param_t * param);
void *POSIX_Mknod(char *testFileName);
void *POSIX_Open(char *testFileName, IOR_param_t * param); void *POSIX_Open(char *testFileName, IOR_param_t * param);
IOR_offset_t POSIX_GetFileSize(IOR_param_t * test, MPI_Comm testComm, char *testFileName); IOR_offset_t POSIX_GetFileSize(IOR_param_t * test, MPI_Comm testComm, char *testFileName);
void POSIX_Delete(char *testFileName, IOR_param_t * param); void POSIX_Delete(char *testFileName, IOR_param_t * param);

View File

@ -145,6 +145,7 @@ static size_t read_bytes;
static int sync_file; static int sync_file;
static int path_count; static int path_count;
static int nstride; /* neighbor stride */ static int nstride; /* neighbor stride */
static int make_node = 0;
static mdtest_results_t * summary_table; static mdtest_results_t * summary_table;
static pid_t pid; static pid_t pid;
@ -337,7 +338,10 @@ static void create_file (const char *path, uint64_t itemNum) {
fflush( out_logfile ); fflush( out_logfile );
} }
aiori_fh = backend->open (curr_item, &param); if (make_node)
aiori_fh = backend->mknod (curr_item);
else
aiori_fh = backend->open (curr_item, &param);
if (NULL == aiori_fh) { if (NULL == aiori_fh) {
FAIL("unable to open file"); FAIL("unable to open file");
} }
@ -354,7 +358,10 @@ static void create_file (const char *path, uint64_t itemNum) {
fflush( out_logfile ); fflush( out_logfile );
} }
aiori_fh = backend->create (curr_item, &param); if (make_node)
aiori_fh = backend->mknod (curr_item);
else
aiori_fh = backend->create (curr_item, &param);
if (NULL == aiori_fh) { if (NULL == aiori_fh) {
FAIL("unable to create file"); FAIL("unable to create file");
} }
@ -382,7 +389,8 @@ static void create_file (const char *path, uint64_t itemNum) {
fflush( out_logfile ); fflush( out_logfile );
} }
backend->close (aiori_fh, &param); if (!make_node)
backend->close (aiori_fh, &param);
} }
/* helper for creating/removing items */ /* helper for creating/removing items */
@ -1328,7 +1336,7 @@ void print_help (void) {
fprintf(out_logfile, fprintf(out_logfile,
"Usage: mdtest [-b branching_factor] [-B] [-c] [-C] [-d testdir] [-D] [-e number_of_bytes_to_read]\n" "Usage: mdtest [-b branching_factor] [-B] [-c] [-C] [-d testdir] [-D] [-e number_of_bytes_to_read]\n"
" [-E] [-f first] [-F] [-h] [-i iterations] [-I items_per_dir] [-l last] [-L]\n" " [-E] [-f first] [-F] [-h] [-i iterations] [-I items_per_dir] [-k] [-l last] [-L]\n"
" [-n number_of_items] [-N stride_length] [-p seconds] [-r]\n" " [-n number_of_items] [-N stride_length] [-p seconds] [-r]\n"
" [-R[seed]] [-s stride] [-S] [-t] [-T] [-u] [-v] [-a API]\n" " [-R[seed]] [-s stride] [-S] [-t] [-T] [-u] [-v] [-a API]\n"
" [-V verbosity_value] [-w number_of_bytes_to_write] [-W seconds] [-y] [-z depth] -Z\n" " [-V verbosity_value] [-w number_of_bytes_to_write] [-W seconds] [-y] [-z depth] -Z\n"
@ -1346,6 +1354,7 @@ void print_help (void) {
"\t-h: prints this help message\n" "\t-h: prints this help message\n"
"\t-i: number of iterations the test will run\n" "\t-i: number of iterations the test will run\n"
"\t-I: number of items per directory in tree\n" "\t-I: number of items per directory in tree\n"
"\t-k: use mknod\n"
"\t-l: last number of tasks on which the test will run\n" "\t-l: last number of tasks on which the test will run\n"
"\t-L: files only at leaf level of tree\n" "\t-L: files only at leaf level of tree\n"
"\t-n: every process will creat/stat/read/remove # directories and files\n" "\t-n: every process will creat/stat/read/remove # directories and files\n"
@ -1610,7 +1619,10 @@ void valid_tests() {
FAIL("items + items_per_dir can only be set without stonewalling"); FAIL("items + items_per_dir can only be set without stonewalling");
} }
} }
/* check for using mknod */
if (write_bytes > 0 && make_node) {
FAIL("-k not compatible with -w");
}
} }
void show_file_system_size(char *file_system) { void show_file_system_size(char *file_system) {
@ -2096,6 +2108,7 @@ void mdtest_init_args(){
sync_file = 0; sync_file = 0;
path_count = 0; path_count = 0;
nstride = 0; nstride = 0;
make_node = 0;
} }
mdtest_results_t * mdtest_run(int argc, char **argv, MPI_Comm world_com, FILE * world_out) { mdtest_results_t * mdtest_run(int argc, char **argv, MPI_Comm world_com, FILE * world_out) {
@ -2144,6 +2157,7 @@ mdtest_results_t * mdtest_run(int argc, char **argv, MPI_Comm world_com, FILE *
{'F', NULL, "perform test on files only (no directories)", OPTION_FLAG, 'd', & files_only}, {'F', NULL, "perform test on files only (no directories)", OPTION_FLAG, 'd', & files_only},
{'i', NULL, "number of iterations the test will run", OPTION_OPTIONAL_ARGUMENT, 'd', & iterations}, {'i', NULL, "number of iterations the test will run", OPTION_OPTIONAL_ARGUMENT, 'd', & iterations},
{'I', NULL, "number of items per directory in tree", OPTION_OPTIONAL_ARGUMENT, 'l', & items_per_dir}, {'I', NULL, "number of items per directory in tree", OPTION_OPTIONAL_ARGUMENT, 'l', & items_per_dir},
{'k', NULL, "use mknod to create file", OPTION_FLAG, 'd', & make_node},
{'l', NULL, "last number of tasks on which the test will run", OPTION_OPTIONAL_ARGUMENT, 'd', & last}, {'l', NULL, "last number of tasks on which the test will run", OPTION_OPTIONAL_ARGUMENT, 'd', & last},
{'L', NULL, "files only at leaf level of tree", OPTION_FLAG, 'd', & leaf_only}, {'L', NULL, "files only at leaf level of tree", OPTION_FLAG, 'd', & leaf_only},
{'n', NULL, "every process will creat/stat/read/remove # directories and files", OPTION_OPTIONAL_ARGUMENT, 'l', & items}, {'n', NULL, "every process will creat/stat/read/remove # directories and files", OPTION_OPTIONAL_ARGUMENT, 'l', & items},
@ -2249,6 +2263,7 @@ mdtest_results_t * mdtest_run(int argc, char **argv, MPI_Comm world_com, FILE *
fprintf( out_logfile, "write_bytes : "LLU"\n", write_bytes ); fprintf( out_logfile, "write_bytes : "LLU"\n", write_bytes );
fprintf( out_logfile, "sync_file : %s\n", ( sync_file ? "True" : "False" )); fprintf( out_logfile, "sync_file : %s\n", ( sync_file ? "True" : "False" ));
fprintf( out_logfile, "depth : %d\n", depth ); fprintf( out_logfile, "depth : %d\n", depth );
fprintf( out_logfile, "make_node : %d\n", make_node );
fflush( out_logfile ); fflush( out_logfile );
} }