From patchwork Thu Feb 28 04:36:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 10832527 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E6B31575 for ; Thu, 28 Feb 2019 04:36:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D48D2D1FE for ; Thu, 28 Feb 2019 04:36:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 702E02E2AB; Thu, 28 Feb 2019 04:36:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144F62D1FE for ; Thu, 28 Feb 2019 04:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727725AbfB1Egh (ORCPT ); Wed, 27 Feb 2019 23:36:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58012 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbfB1Egh (ORCPT ); Wed, 27 Feb 2019 23:36:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30BEDB06D6 for ; Thu, 28 Feb 2019 04:36:37 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-138.pek2.redhat.com [10.72.12.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39DDD5D707 for ; Thu, 28 Feb 2019 04:36:35 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v3] fsstress: avoid infinite zero byte reading Date: Thu, 28 Feb 2019 12:36:33 +0800 Message-Id: <20190228043633.15727-1-zlang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 28 Feb 2019 04:36:37 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 -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 --- ltp/fsstress.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 25e0c3e2..7bc0a58a 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -2449,7 +2449,7 @@ copyrange_f( while (len > 0) { ret = syscall(__NR_copy_file_range, fd1, &off1, fd2, &off2, len, 0); - if (ret < 0) { + if (ret <= 0) { if (errno != EAGAIN || tries++ >= 300) break; } else if (ret > len) @@ -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; @@ -2898,12 +2898,12 @@ splice_f(int opno, long r) /* move from pipe buffer to dst file */ while (bytes > 0) { ret2 = splice(filedes[0], NULL, fd2, &off2, bytes, 0); - if (ret2 < 0) { + if (ret2 <= 0) { break; } bytes -= ret2; } - if (ret2 < 0) + if (ret2 <= 0) break; len -= ret1;