[PATCH] generic/478: fix potential test blocking

Xiong Zhou
2018-03-23T02:49:44Z

Reduce semtimedop timeout to 5s, 15s is too long if something
get tangled up. Add retry counting to getlk routine, infinite
loop is dangerous. If something goes wrong unexpextedly, test
is blocked wasting time.

Signed-off-by: Xiong Zhou <xzhou@redhat.com>
---

We are hitting this when testing on cifs samba 2.0.

src/t_ofd_locks.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/t_ofd_locks.c b/src/t_ofd_locks.c
index d578cd7..454b2ce 100644
--- a/src/t_ofd_locks.c
+++ b/src/t_ofd_locks.c
@@ -317,14 +317,14 @@ int main(int argc, char **argv)
sop.sem_num = 0;
sop.sem_op = 1;
sop.sem_flg = 0;
- ts.tv_sec = 15;
+ ts.tv_sec = 5;
ts.tv_nsec = 0;
if (semtimedop(semid, &sop, 1, &ts) == -1)
err_exit("inc sem0 2", errno);
sop.sem_num = 1;
sop.sem_op = 1;
sop.sem_flg = 0;
- ts.tv_sec = 15;
+ ts.tv_sec = 5;
ts.tv_nsec = 0;
if (semtimedop(semid, &sop, 1, &ts) == -1)
err_exit("inc sem1 2", errno);
@@ -376,7 +376,7 @@ int main(int argc, char **argv)
sop.sem_num = 1;
sop.sem_op = 0;
sop.sem_flg = 0;
- ts.tv_sec = 15;
+ ts.tv_sec = 5;
ts.tv_nsec = 0;
if (semtimedop(semid, &sop, 1, &ts) == -1)
err_exit("wait sem1 0", errno);
@@ -391,13 +391,16 @@ int main(int argc, char **argv)
/* getlck */
if (lock_cmd == 0) {
/* wait sem created and initialized */
+ retry = 5;
do {
semid = semget(semkey, 2, 0);
if (semid != -1)
break;
- if (errno == ENOENT)
+ if (errno == ENOENT && retry) {
+ sleep(1);
+ retry--;
continue;
- else
+ } else
err_exit("getlk_semget", errno);
} while (1);
do {
@@ -410,7 +413,7 @@ int main(int argc, char **argv)
sop.sem_num = 0;
sop.sem_op = 0;
sop.sem_flg = 0;
- ts.tv_sec = 15;
+ ts.tv_sec = 5;
ts.tv_nsec = 0;
if (semtimedop(semid, &sop, 1, &ts) == -1)
err_exit("wait sem0 0", errno);
--
1.8.3.1