From 45e24d91da89c4fccd2fb4c33d9171cd58e20f59 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Sun, 4 May 2014 16:05:58 -0500 Subject: [PATCH] LU-5002 flock: accept EDEADLK in sanityn test_74 In flocks_test.c t4() acquiring the second flock may legitimately fail and return -EDEADLK. Handle this and ensure that errors encountered by the child process are returned by the parent. Signed-off-by: John L. Hammond Change-Id: I55172add1412377b1c7125efa4177702d8bf1834 Reviewed-on: http://review.whamcloud.com/10208 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: wangdi Reviewed-by: Andriy Skulysh Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- lustre/tests/flocks_test.c | 61 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/lustre/tests/flocks_test.c b/lustre/tests/flocks_test.c index a4a00a8..c208648 100644 --- a/lustre/tests/flocks_test.c +++ b/lustre/tests/flocks_test.c @@ -371,7 +371,8 @@ int t4(int argc, char *argv[]) }; int fd, fd2; - int pid; + pid_t child_pid; + int child_status; int rc = EXIT_SUCCESS; if (argc != 4) { @@ -389,18 +390,19 @@ int t4(int argc, char *argv[]) goto out; } - pid = fork(); - if (pid == -1) { + child_pid = fork(); + if (child_pid < 0) { perror("fork"); rc = EXIT_FAILURE; goto out; } - if (pid == 0) { + if (child_pid == 0) { printf("%d: get lock1\n", getpid()); fflush(stdout); if (t_fcntl(fd, F_SETLKW, &lock) < 0) { - perror("first flock failed"); + fprintf(stderr, "%d: cannot get lock1: %s\n", + getpid(), strerror(errno)); rc = EXIT_FAILURE; goto out_child; } @@ -409,8 +411,14 @@ int t4(int argc, char *argv[]) printf("%d: get lock2\n", getpid()); fflush(stdout); if (t_fcntl(fd2, F_SETLKW, &lock) < 0) { - perror("first flock failed"); - rc = EXIT_FAILURE; + fprintf(stderr, "%d: cannot get lock2: %s\n", + getpid(), strerror(errno)); + + if (errno == EDEADLK) + rc = EXIT_SUCCESS; + else + rc = EXIT_FAILURE; + goto out_child; } printf("%d: done\n", getpid()); @@ -421,7 +429,8 @@ out_child: printf("%d: get lock2\n", getpid()); fflush(stdout); if (t_fcntl(fd2, F_SETLKW, &lock) < 0) { - perror("first flock failed"); + fprintf(stderr, "%d: cannot get lock2: %s\n", + getpid(), strerror(errno)); rc = EXIT_FAILURE; goto out; } @@ -430,13 +439,43 @@ out_child: printf("%d: get lock1\n", getpid()); fflush(stdout); if (t_fcntl(fd, F_SETLKW, &lock) < 0) { - perror("first flock failed"); - rc = EXIT_FAILURE; - goto out; + fprintf(stderr, "%d: cannot get lock1: %s\n", + getpid(), strerror(errno)); + + if (errno != EDEADLK) { + rc = EXIT_FAILURE; + goto out; + } } printf("%d: done\n", getpid()); } + sleep(1); + + if (close(fd) < 0) { + fprintf(stderr, "%d: error closing file1: %s\n", + getpid(), strerror(errno)); + rc = EXIT_FAILURE; + } + + if (close(fd2) < 0) { + fprintf(stderr, "%d: error closing file2: %s\n", + getpid(), strerror(errno)); + rc = EXIT_FAILURE; + } + + if (waitpid(child_pid, &child_status, 0) < 0) { + fprintf(stderr, "%d: cannot get termination status of %d: %s\n", + getpid(), child_pid, strerror(errno)); + rc = EXIT_FAILURE; + } else if (!WIFEXITED(child_status)) { + fprintf(stderr, "%d: child %d terminated with status %d\n", + getpid(), child_pid, child_status); + rc = EXIT_FAILURE; + } else { + rc = WEXITSTATUS(child_status); + } + out: printf("%d: exit rc=%d\n", getpid(), rc); return rc; -- 1.8.3.1