[Ocfs2-test-devel] [PATCH 22/59] xattr-tests: validate return value
Junxiao Bi
junxiao.bi at oracle.com
Sun Sep 13 19:44:08 PDT 2015
From: Jeff Liu <jeff.liu at oracle.com>
- Add more validates upon return value of ftruncate and pwrite since
they might failed in some situations for multiple nodes testing.
- Much more code clean up, compile fix.
Signed-off-by: Jie Liu <jeff.liu at oracle.com>
Signed-off-by: Junxiao Bi <junxiao.bi at oracle.com>
---
programs/xattr_tests/xattr-multi-test.c | 12 +--
programs/xattr_tests/xattr-test-utils.c | 87 +++++++++++++---------
programs/xattr_tests/xattr-test.c | 122 +++++++++++++++++++------------
programs/xattr_tests/xattr-test.h | 1 +
4 files changed, 134 insertions(+), 88 deletions(-)
diff --git a/programs/xattr_tests/xattr-multi-test.c b/programs/xattr_tests/xattr-multi-test.c
index ad6249d..1db9ee0 100755
--- a/programs/xattr_tests/xattr-multi-test.c
+++ b/programs/xattr_tests/xattr-multi-test.c
@@ -355,21 +355,21 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
fd = open(filename, FILE_FLAGS_CREATE, FILE_MODE);
judge_sys_return(fd, "open");
printf("Test %d: Creating commonfile %s on %s(rank 0),"
- "to perform %d EAs.\n",
+ "to perform %lu EAs.\n",
testno, filename, hostname, xattr_nums);
break;
case SYMLINK:
ret = symlink("/no/such/file", filename);
judge_sys_return(ret, "symlink");
printf("Test %d: Creating symlink %s on %s(rank 0),"
- "to perform %d EAs.\n",
+ "to perform %lu EAs.\n",
testno, filename, hostname, xattr_nums);
break;
case DIRECTORY:
ret = mkdir(filename, FILE_MODE);
judge_sys_return(ret, "mkdir");
printf("Test %d: Creating directory %s on %s(rank 0),"
- "to perform %d EAs.\n",
+ "to perform %lu EAs.\n",
testno, filename, hostname, xattr_nums);
break;
default:
@@ -413,13 +413,13 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
if (only_do_add_test == 1) {
if (rank == 0) {
printf("Test %d: Performancing Xattr operations on %s,"
- "all ranks take race to add %d EAs.\n",
+ "all ranks take race to add %lu EAs.\n",
testno, filename, xattr_nums);
}
for (j = 0; j < xattr_nums; j++) {
memset(xattr_name, 0, xattr_name_sz + 1);
memset(xattr_value, 0, xattr_value_sz);
- snprintf(xattr_name, xattr_name_sz, "%s.%s-rank%d-%d",
+ snprintf(xattr_name, xattr_name_sz, "%s.%s-rank%d-%lu",
xattr_namespace_prefix, hostname, rank, j);
if (do_random_test == 1)
xattr_value_generator(j, XATTR_VALUE_LEAST_SZ,
@@ -444,7 +444,7 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
/*Do regular concurrent operations(update/add/remove) testing*/
if (rank == 0) {
printf("Test %d: Performancing Xattrs on %s,all ranks take "
- "race to do update/remove/add/read %d EAs.\n",
+ "race to do update/remove/add/read %lu EAs.\n",
testno, filename, xattr_nums);
fflush(stdout);
diff --git a/programs/xattr_tests/xattr-test-utils.c b/programs/xattr_tests/xattr-test-utils.c
index 503849a..5a16ad6 100644
--- a/programs/xattr_tests/xattr-test-utils.c
+++ b/programs/xattr_tests/xattr-test-utils.c
@@ -107,7 +107,7 @@ void xattr_name_generator(unsigned long xattr_no,
}
xattr_name[xattr_name_rsz - 6] = 0;
- snprintf(postfix, 7, "%06d", xattr_no);
+ snprintf(postfix, 7, "%lu", xattr_no);
strcat(xattr_name, postfix);
strcpy(xattr_name_list_set[xattr_no], xattr_name);
}
@@ -201,9 +201,10 @@ int read_ea(enum FILE_TYPE ft, int fd)
xattr_value_sz);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at fgetxattr(errno:%d, %s) "
- "on %s,xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ fprintf(stderr,
+ "Failed at fgetxattr(errno:%d, %s) "
+ "on %s, xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
@@ -211,9 +212,11 @@ int read_ea(enum FILE_TYPE ft, int fd)
ret = lgetxattr(filename, xattr_name, xattr_value_get,
xattr_value_sz);
if (ret < 0) {
- fprintf(stderr, "Failed at lgetxattr(errno:%d, %s) "
- "on %s,xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ ret = errno;
+ fprintf(stderr,
+ "Failed at lgetxattr(errno:%d, %s) "
+ "on %s,xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
@@ -221,13 +224,17 @@ int read_ea(enum FILE_TYPE ft, int fd)
ret = getxattr(filename, xattr_name, xattr_value_get,
xattr_value_sz);
if (ret < 0) {
- fprintf(stderr, "Failed at getxattr(errno:%d, %s) "
- "on %s,xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ ret = errno;
+ fprintf(stderr,
+ "Failed at getxattr(errno:%d, %s) "
+ "on %s,xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
default:
+ fprintf(stderr, "%s: Invalid file format\n", filename);
+ ret = -1;
break;
}
@@ -245,11 +252,12 @@ int add_or_update_ea(enum FILE_TYPE ft, int fd, int ea_flags,
xattr_value_sz, ea_flags);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at fsetxattr(%s,errno:%d,%s) "
- "on %s:xattr_name=%s,xattr_value_sz=%d,"
- "xattr_value=%s\n", prt_str, ret, strerror(ret),
- filename, xattr_name, strlen(xattr_value) + 1,
- xattr_value);
+ fprintf(stderr,
+ "Failed at fsetxattr(%s,errno:%d,%s) "
+ "on %s:xattr_name=%s,xattr_value_sz=%zu,"
+ "xattr_value=%s\n",
+ prt_str, ret, strerror(ret), filename,
+ xattr_name, strlen(xattr_value) + 1, xattr_value);
ret = -1;
}
break;
@@ -258,11 +266,12 @@ int add_or_update_ea(enum FILE_TYPE ft, int fd, int ea_flags,
xattr_value_sz, ea_flags);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at lsetxattr(%s,errno:%d,%s) "
- "on %s:xattr_name=%s,xattr_value_sz=%d,"
- "xattr_value=%s\n", prt_str, ret, strerror(ret),
- filename, xattr_name, strlen(xattr_value) + 1,
- xattr_value);
+ fprintf(stderr,
+ "Failed at lsetxattr(%s,errno:%d,%s) "
+ "on %s:xattr_name=%s,xattr_value_sz=%zu,"
+ "xattr_value=%s\n",
+ prt_str, ret, strerror(ret), filename,
+ xattr_name, strlen(xattr_value) + 1, xattr_value);
ret = -1;
}
break;
@@ -271,15 +280,18 @@ int add_or_update_ea(enum FILE_TYPE ft, int fd, int ea_flags,
xattr_value_sz, ea_flags);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at setxattr(%s,errno:%d,%s) "
- "on %s:xattr_name=%s,xattr_value_sz=%d,"
- "xattr_value=%s\n", prt_str, ret, strerror(ret),
- filename, xattr_name, strlen(xattr_value) + 1,
- xattr_value);
+ fprintf(stderr,
+ "Failed at setxattr(%s,errno:%d,%s) "
+ "on %s:xattr_name=%s,xattr_value_sz=%zu,"
+ "xattr_value=%s\n",
+ prt_str, ret, strerror(errno), filename,
+ xattr_name, strlen(xattr_value) + 1, xattr_value);
ret = -1;
}
break;
default:
+ fprintf(stderr, "%s: Invalid file format\n", filename);
+ ret = -1;
break;
}
@@ -295,9 +307,10 @@ int remove_ea(enum FILE_TYPE ft, int fd)
ret = fremovexattr(fd, xattr_name);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at fremovexattr(errno:%d,%s) "
- "on %s:xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ fprintf(stderr,
+ "Failed at fremovexattr(errno:%d,%s) "
+ "on %s:xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
@@ -305,9 +318,10 @@ int remove_ea(enum FILE_TYPE ft, int fd)
ret = lremovexattr(filename, xattr_name);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at lremovexattr(errno:%d,%d) "
- "on %s:xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ fprintf(stderr,
+ "Failed at lremovexattr(errno:%d,%s) "
+ "on %s:xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
@@ -315,13 +329,16 @@ int remove_ea(enum FILE_TYPE ft, int fd)
ret = removexattr(filename, xattr_name);
if (ret < 0) {
ret = errno;
- fprintf(stderr, "Failed at removexattr(errno:%d,%s) "
- "on %s:xattr_name=%s\n", ret, strerror(ret),
- filename, xattr_name);
+ fprintf(stderr,
+ "Failed at removexattr(errno:%d,%s) "
+ "on %s:xattr_name=%s\n",
+ ret, strerror(ret), filename, xattr_name);
ret = -1;
}
break;
default:
+ fprintf(stderr, "%s: Invalid file format\n", filename);
+ ret = -1;
break;
}
@@ -348,7 +365,7 @@ void xattr_value_constructor(int xattr_entry_no)
strlen(value_postfix_magic) -
strlen(xattr_name) - 5);
- snprintf(value_sz, 6, "%05d", strlen(value_prefix_magic) +
+ snprintf(value_sz, 6, "%zu", strlen(value_prefix_magic) +
strlen(xattr_name) + strlen(xattr_value) + 5 +
strlen(value_postfix_magic));
diff --git a/programs/xattr_tests/xattr-test.c b/programs/xattr_tests/xattr-test.c
index 3b5af28..dff8298 100755
--- a/programs/xattr_tests/xattr-test.c
+++ b/programs/xattr_tests/xattr-test.c
@@ -293,8 +293,9 @@ static void judge_sys_return(int ret, const char *sys_func)
perror(sys_func);
teardown();
exit(1);
- } else
- return;
+ }
+
+ return;
}
static void sigchld_handler()
@@ -310,8 +311,8 @@ static void sigchld_handler()
static void kill_all_children()
{
+ int process_nums = 0;
int i;
- int process_nums;
if (do_multi_process_test == 1)
process_nums = child_nums;
@@ -341,8 +342,8 @@ static void sigterm_handler()
static void atexit_hook(void)
{
+ int process_nums = 0;
int i;
- int process_nums;
if (do_multi_process_test == 1)
process_nums = child_nums;
@@ -355,23 +356,24 @@ static void atexit_hook(void)
free(child_pid_list);
}
-static int one_round_run(enum FILE_TYPE ft, int round_no)
+static void one_round_run(enum FILE_TYPE ft, int round_no)
{
- int fd, ret, status;
- DIR *dp;
- pid_t pid, ppid;
- unsigned long j;
- int i, k;
+ int fd = -1, status, i, k, ret;
char *write_buf = NULL;
+ unsigned long j;
+ pid_t pid;
testno = 1;
- /* Launch multiple file test by forking multiple processes,each process
- manipulates a file*/
+ /*
+ * Launch multiple file test by forking multiple processes, each
+ * process manipulates a file.
+ */
if (do_multiple_file_test == 1) {
- printf("Test %d: Doing Xattr multiple file test.\n", testno);
+ fprintf(stdout, "Test %d: Performing Xattr multiple file test.\n", testno);
fflush(stdout);
fflush(stderr);
+
signal(SIGCHLD, sigchld_handler);
for (i = 0; i < file_nums; i++) {
pid = fork();
@@ -381,6 +383,7 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
teardown();
exit(1);
}
+
/*child try to create/modify file,add/update xattr*/
if (pid == 0) {
memset(filename, 0, MAX_FILENAME_SZ + 1);
@@ -452,7 +455,8 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
}
/*append file content*/
if (ft == NORMAL) {
- ftruncate(fd, 0);
+ ret = ftruncate(fd, 0);
+ judge_sys_return(ret, "ftruncate");
fsync(fd);
write_buf = realloc(write_buf,
CLUSTER_SIZE);
@@ -507,15 +511,18 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
break;
}
- /* Launch multiple processes to do concurrent operations
- against one file*/
+ /*
+ * Launch multiple processes to do concurrent operations
+ * against one file.
+ */
if (do_multi_process_test == 1) {
-
- /*Father process add a series of xattr entries first*/
- printf("Test %d: Doing Xattr operations on %s with %d "
- "processes.\n", testno, filename, child_nums + 1);
+ /* Father process add a series of xattr entries first */
+ fprintf(stdout,
+ "Test %d: Performing Xattr operations on %s with %d processes.\n",
+ testno, filename, child_nums + 1);
fflush(stdout);
fflush(stderr);
+
for (j = 0; j < xattr_nums; j++) {
memset(xattr_name, 0, xattr_name_sz + 1);
memset(xattr_value, 0, xattr_value_sz);
@@ -538,11 +545,12 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
signal(SIGCHLD, sigchld_handler);
- /*Propagate a fixed number of children to perform update*/
+ /* Propagate a fixed number of children to perform update */
for (i = 0; i < child_nums; i++) {
pid = fork();
if (pid < 0) {
fprintf(stderr, "Fork process error!\n");
+ fflush(stderr);
teardown();
exit(1);
}
@@ -550,10 +558,8 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
if (pid == 0) {
for (k = 0; k < XATTR_CHILD_UPDATE_TIMES; k++) {
for (j = 0; j < xattr_nums; j++) {
- strcpy(xattr_name,
- xattr_name_list_set[j]);
- memset(xattr_value, 0,
- xattr_value_sz);
+ strcpy(xattr_name, xattr_name_list_set[j]);
+ memset(xattr_value, 0, xattr_value_sz);
xattr_value_constructor(j);
ret = add_or_update_ea(ft, fd,
XATTR_REPLACE,
@@ -562,22 +568,26 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
teardown();
exit(1);
}
+
write_buf = realloc(write_buf,
CLUSTER_SIZE);
- ftruncate(fd, 0);
- memset(write_buf, 'a'+j%26,
- CLUSTER_SIZE);
- pwrite(fd, write_buf,
- CLUSTER_SIZE, 0);
+ ret = ftruncate(fd, 0);
+ judge_sys_return(ret, "ftruncate");
+
+ memset(write_buf, 'a'+j%26, CLUSTER_SIZE);
+ ret = pwrite(fd, write_buf, CLUSTER_SIZE, 0);
+ judge_sys_return(ret, "write");
}
}
free(write_buf);
exit(0);
}
+
if (pid > 0)
child_pid_list[i] = pid;
}
- /*Father*/
+
+ /* Father */
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigterm_handler);
atexit(atexit_hook);
@@ -610,10 +620,11 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
testno++;
return;
}
- /* Do normal update/add test*/
- printf("Test %d: Doing normal %d EAs adding and updating on file %s.\n",
- testno, xattr_nums, filename);
+ /* Perform normal update/add test */
+ fprintf(stdout,
+ "Test %d: Doing normal %lu EAs adding and updating on file %s.\n",
+ testno, xattr_nums, filename);
fflush(stdout);
for (j = 0; j < xattr_nums; j++) {
@@ -629,22 +640,27 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
xattr_name_sz);
memset(xattr_value, 'w', xattr_value_sz - 1);
xattr_value[xattr_value_sz - 1] = '\0';
- /*add EA entry*/
+
+ /* Add EA entry */
ret = add_or_update_ea(ft, fd, XATTR_CREATE, "add");
if (ret < 0) {
teardown();
exit(1);
}
+
ret = read_ea(ft, fd);
if (ret < 0) {
teardown();
exit(1);
}
+
if (strcmp(xattr_value, xattr_value_get) != 0) {
fprintf(stderr, "Inconsistent Xattr Value Readed!\n");
+ fflush(stderr);
teardown();
exit(1);
}
+
/*update EA entry here */
memset(xattr_value, 0, xattr_value_sz);
memset(xattr_value_get, 0, xattr_value_sz);
@@ -655,13 +671,16 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
teardown();
exit(1);
}
+
ret = read_ea(ft, fd);
if (ret < 0) {
teardown();
exit(1);
}
+
if (strcmp(xattr_value, xattr_value_get) != 0) {
fprintf(stderr, "Inconsistent Xattr Value Readed!\n");
+ fflush(stderr);
teardown();
exit(1);
}
@@ -671,12 +690,16 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
/*Here we do random_size update and check*/
if (!do_random_test)
goto list_test;
- printf("Test %d: Doing randomsize updating for %d EAs on file %s.\n",
+
+ fprintf(stdout,
+ "Test %d: Doing randomsize updating for %lu EAs on file %s.\n",
testno, xattr_nums, filename);
+ fflush(stdout);
unsigned long update_iter;
for (update_iter = 0; update_iter < XATTR_RANDOMSIZE_UPDATE_TIMES;
update_iter++)
+
for (j = 0; j < xattr_nums; j++) {
memset(xattr_value, 0, xattr_value_sz);
memset(xattr_value_get, 0, xattr_value_sz);
@@ -684,14 +707,14 @@ static int one_round_run(enum FILE_TYPE ft, int round_no)
strcpy(xattr_name, xattr_name_list_set[j]);
xattr_value_generator(j, XATTR_VALUE_LEAST_SZ, xattr_value_sz);
if (j % 2 == 0) {
- /*Random size update*/
+ /* Random size update */
ret = add_or_update_ea(ft, fd, XATTR_REPLACE, "update");
if (ret < 0) {
teardown();
exit(1);
}
} else {
- /*Remove then add*/
+ /* Remove then add */
ret = remove_ea(ft, fd);
if (ret < 0) {
teardown();
@@ -730,8 +753,9 @@ list_test:
for (j = 0; j < xattr_nums; j++)
memset(xattr_name_list_get[j], 0, xattr_name_sz + 1);
- printf("Test %d: Listing all replaced EAs on file %s.\n", testno,
- filename);
+ fprintf(stdout, "Test %d: Listing all replaced EAs on file %s.\n",
+ testno, filename);
+
switch (ft) {
case NORMAL:
ret = flistxattr(fd, (void *)list, list_sz);
@@ -754,18 +778,20 @@ list_test:
for (j = 0; j < xattr_nums; j++) {
if (!is_namelist_member(xattr_nums, xattr_name_list_get[j],
xattr_name_list_set)) {
- fprintf(stderr, "Xattr list name(%s) "
- "did not match the orginal one\n",
+ fprintf(stderr,
+ "Xattr list name(%s) did not match the orginal one\n",
xattr_name_list_get[j]);
+ fflush(stdout);
teardown();
exit(1);
}
}
testno++;
+
bail:
if (keep_ea == 0) {
- printf("Test %d: Removing all EAs on file %s.\n", testno,
- filename);
+ fprintf(stdout, "Test %d: Removing all EAs on file %s.\n",
+ testno, filename);
for (j = 0; j < xattr_nums; j++) {
memset(xattr_name, 0, xattr_name_sz + 1);
strcpy(xattr_name, xattr_name_list_set[j]);
@@ -778,8 +804,9 @@ bail:
}
testno++;
- printf("Test %d: Verifying if all EAs removed from file %s.\n",
- testno, filename);
+ fprintf(stdout, "Test %d: Verifying if all EAs removed from file %s.\n",
+ testno, filename);
+
char *veri_list;
unsigned long veri_list_sz;
veri_list_sz = (xattr_name_sz + 1) * xattr_nums;
@@ -813,9 +840,10 @@ bail:
free((void *)veri_list);
testno++;
}
+
/*Unlink the file*/
#ifdef DO_UNLINK
- printf("Test %d: Removing file %s...\n", testno, filename);
+ fprintf(stdout, "Test %d: Removing file %s...\n", testno, filename);
switch (ft) {
case NORMAL:
ret = unlink(filename);
diff --git a/programs/xattr_tests/xattr-test.h b/programs/xattr_tests/xattr-test.h
index 91c96d1..cb8c2cc 100644
--- a/programs/xattr_tests/xattr-test.h
+++ b/programs/xattr_tests/xattr-test.h
@@ -29,6 +29,7 @@
#include <dirent.h>
#include <sys/wait.h>
#include <signal.h>
+#include <time.h>
#define HOSTNAME_MAX_SZ 100
#define PATH_SZ 100
--
1.7.9.5
More information about the Ocfs2-test-devel
mailing list