From patchwork Wed Sep 25 07:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yanjun X-Patchwork-Id: 11160123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 284CD17D4 for ; Wed, 25 Sep 2019 07:19:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 072D321D7E for ; Wed, 25 Sep 2019 07:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392846AbfIYHTq (ORCPT ); Wed, 25 Sep 2019 03:19:46 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:37792 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390825AbfIYHTq (ORCPT ); Wed, 25 Sep 2019 03:19:46 -0400 X-IronPort-AV: E=Sophos;i="5.64,547,1559491200"; d="scan'208";a="75985947" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Sep 2019 15:19:34 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id E0F884CDFCE9; Wed, 25 Sep 2019 15:19:36 +0800 (CST) Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 25 Sep 2019 15:19:37 +0800 From: Su Yanjun To: CC: , Subject: [PATCH] fsx: add more check for copy_file_range Date: Wed, 25 Sep 2019 15:16:55 +0800 Message-ID: <1569395815-4657-1-git-send-email-suyj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] X-yoursite-MailScanner-ID: E0F884CDFCE9.A3377 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suyj.fnst@cn.fujitsu.com X-Spam-Status: No Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org On some linux distros(RHEL7, centos 7) copy_file_range uses general implementation (splice interface). splice interace uses pipe_to_file. pipe_to_file only work for different page. The userspace cant's be aware of such error because copy_file_range returns ok too. So for such case when copy_file_range return we read back data then check it. Signed-off-by: Su Yanjun --- ltp/fsx.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ltp/fsx.c b/ltp/fsx.c index 06d08e4..0439430 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -1602,6 +1602,7 @@ do_copy_range(unsigned offset, unsigned length, unsigned dest) size_t olen; ssize_t nr; int tries = 0; + int ret = 0; if (length == 0) { if (!quiet && testcalls > simulatedopcount) @@ -1665,6 +1666,37 @@ do_copy_range(unsigned offset, unsigned length, unsigned dest) memset(good_buf + file_size, '\0', dest - file_size); if (dest + length > file_size) file_size = dest + length; + /* + * Although copy_file_range returns ok + * for some linux distros that use general implementation + * (splice interface) such as RHEL 7, centos 7 that use + * pipe_to_file will cause test fail. + * + * Here we add a little more check here for copy_file_range + * We read copied data then check it. If check fail here + * then report it. + */ + ret = lseek(fd, (off_t)dest, SEEK_SET); + if (ret == (off_t)-1) { + prterr("doread: lseek"); + report_failure(140); + } + ret = fsxread(fd, temp_buf, length, dest); + if (ret != length) { + if (ret == -1) + prterr("doread: read"); + else + prt("short read: 0x%x bytes instead of 0x%x\n", + ret, length); + report_failure(141); + } + if (memcmp(good_buf+dest, temp_buf, length) != 0) { + prt("copy range: 0x%x to 0x%x at 0x%x\n", offset, + offset + length, dest); + prterr("do_copy_range:"); + report_failure(161); + + } } #else