fsstress: avoid infinite zero byte reading

copyrange_f and splice_f functions use a while loop to read a file,
it's fine if there's only one fsstress process(and its children),
but if some third part testing processes remove the file in the
middle phase of copyrange_f running, copyrange_f maybe always return
0, and the while loop can't be end. As below:

root     47184  xxxxxx S+ ./fsstress -R -d /mnt/scratch -n 10000 -p 20 -v
root     47187  xxxxxx R+ ./fsstress -d /mnt/scratch -n 10000 -p 20 -v
root     47199  xxxxxx R+ ./fsstress -d /mnt/scratch -n 10000 -p 20 -v
root     47314  xxxxxx S+ grep --color=auto fsstress
...
...
copy_file_range(3, [372258], 4, [2658770], 71179, 0) = 0
copy_file_range(3, [372258], 4, [2658770], 71179, 0) = 0
copy_file_range(3, [372258], 4, [2658770], 71179, 0) = 0
copy_file_range(3, [372258], 4, [2658770], 71179, 0) = 0
...
...
lr-x------. 1 root root 64 Jan 28 11:34 /proc/47187/fd/3 -> '/mnt/scratch/p2/f2 (deleted)'

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
This commit is contained in:
Zorro Lang
2019-02-16 15:25:40 +08:00
committed by Eryu Guan
parent e6703b903a
commit 1ee89eea1c
+3 -3
View File
@@ -2363,7 +2363,7 @@ copyrange_f(
int v2;
int fd1;
int fd2;
size_t ret;
size_t ret = 0;
int e;
/* Load paths */
@@ -2452,7 +2452,7 @@ copyrange_f(
if (ret < 0) {
if (errno != EAGAIN || tries++ >= 300)
break;
} else if (ret > len)
} else if (ret > len || ret == 0)
break;
else if (ret > 0)
len -= ret;
@@ -2890,7 +2890,7 @@ splice_f(int opno, long r)
while (len > 0) {
/* move to pipe buffer */
ret1 = splice(fd1, &off1, filedes[1], NULL, len, 0);
if (ret1 < 0) {
if (ret1 <= 0) {
break;
}
bytes = ret1;