From patchwork Wed Jul 10 10:53:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1130334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45kGJM381Kz9s00 for ; Wed, 10 Jul 2019 20:53:39 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 495553C1C9A for ; Wed, 10 Jul 2019 12:53:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id A28643C1CF5 for ; Wed, 10 Jul 2019 12:53:29 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 3FF55600B6E for ; Wed, 10 Jul 2019 12:53:27 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.63,474,1557158400"; d="scan'208";a="71103680" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Jul 2019 18:53:27 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id AF3424B41EDC; Wed, 10 Jul 2019 18:53:23 +0800 (CST) Received: from localhost.localdomain (10.167.215.46) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 10 Jul 2019 18:53:21 +0800 From: Yang Xu To: Date: Wed, 10 Jul 2019 18:53:16 +0800 Message-ID: <1562755997-5626-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1562755997-5626-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <5D25B05A.8000600@cn.fujitsu.com> <1562755997-5626-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.215.46] X-yoursite-MailScanner-ID: AF3424B41EDC.AE3B8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/3] syscalls/copy_file_range01: add cross-device test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Amir has relaxed cross-device constraint since commit(vfs: allow copy_file_range to copy across devices), I think we can remove it in copy_file_range02 and test it in copy_file_range01. Signed-off-by: Yang Xu Reviewed-by: Amir Goldstein --- .../copy_file_range/copy_file_range01.c | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c index a5bd5e7f7..e1aa06c3e 100644 --- a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c +++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c @@ -24,7 +24,17 @@ static int page_size; static int errcount, numcopies; -static int fd_in, fd_out; +static int fd_in, fd_out, cross_sup; +char FILE_TARGET_PATH[40]; + +static struct tcase { + char *path; + int flags; + char *message; +} tcases[] = { + {FILE_DEST_PATH, 0, "non cross-device"}, + {FILE_MNTED_PATH, 1, "cross-device"}, +}; static int check_file_content(const char *fname1, const char *fname2, loff_t *off1, loff_t *off2, size_t len) @@ -131,7 +141,7 @@ static void test_one(size_t len, loff_t *off_in, loff_t *off_out) to_copy -= TST_RET; } while (to_copy > 0); - ret = check_file_content(FILE_SRC_PATH, FILE_DEST_PATH, + ret = check_file_content(FILE_SRC_PATH, FILE_TARGET_PATH, off_in, off_out, len); if (ret) { tst_res(TFAIL, "file contents do not match"); @@ -152,7 +162,7 @@ static void test_one(size_t len, loff_t *off_in, loff_t *off_out) static void open_files(void) { fd_in = SAFE_OPEN(FILE_SRC_PATH, O_RDONLY); - fd_out = SAFE_OPEN(FILE_DEST_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0644); + fd_out = SAFE_OPEN(FILE_TARGET_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0644); } static void close_files(void) @@ -163,9 +173,18 @@ static void close_files(void) SAFE_CLOSE(fd_in); } -static void copy_file_range_verify(void) +static void copy_file_range_verify(unsigned int n) { int i, j, k; + struct tcase *tc = &tcases[n]; + + if (tc->flags && !cross_sup) { + tst_res(TCONF, + "copy_file_range doesn't support cross-device, skip it"); + return; + } + + strcpy(FILE_TARGET_PATH, tc->path); errcount = numcopies = 0; size_t len_arr[] = {11, page_size-1, page_size, page_size+1}; @@ -190,25 +209,33 @@ static void copy_file_range_verify(void) if (errcount == 0) tst_res(TPASS, - "copy_file_range completed all %d copy jobs successfully!", - numcopies); + "%s copy_file_range completed all %d copy jobs successfully!", + tc->message, numcopies); else - tst_res(TFAIL, "copy_file_range failed %d of %d copy jobs.", - errcount, numcopies); + tst_res(TFAIL, "%s copy_file_range failed %d of %d copy jobs.", + tc->message, errcount, numcopies); } static void setup(void) { - int i, fd; + int i, fd, fd_test; syscall_info(); page_size = getpagesize(); - + cross_sup = 1; fd = SAFE_OPEN(FILE_SRC_PATH, O_RDWR | O_CREAT, 0664); /* Writing page_size * 4 of data into test file */ for (i = 0; i < (int)(page_size * 4); i++) SAFE_WRITE(1, fd, CONTENT, CONTSIZE); + + fd_test = SAFE_OPEN(FILE_MNTED_PATH, O_RDWR | O_CREAT, 0664); + TEST(sys_copy_file_range(fd, 0, fd_test, 0, CONTSIZE, 0)); + if (TST_ERR == EXDEV) + cross_sup = 0; + + SAFE_CLOSE(fd_test); + remove(FILE_MNTED_PATH); SAFE_CLOSE(fd); } @@ -220,7 +247,11 @@ static void cleanup(void) static struct tst_test test = { .setup = setup, .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tcases), .needs_tmpdir = 1, - .test_all = copy_file_range_verify, + .mount_device = 1, + .mntpoint = MNTPOINT, + .all_filesystems = 1, + .test = copy_file_range_verify, .test_variants = TEST_VARIANTS, };