From patchwork Thu Feb 21 09:00:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158885 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp243270jaa; Thu, 21 Feb 2019 01:01:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IZsMDcxjO6KbScTfA7PNNOnFeCOxCbJK674JtFA5EcbBju2gBqFrWt2EQqHG7ejJhQf9E65 X-Received: by 2002:a17:906:5e0d:: with SMTP id n13mr8531401eju.139.1550739692206; Thu, 21 Feb 2019 01:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550739692; cv=none; d=google.com; s=arc-20160816; b=kxJpesEFPm/SRfWRJWzsrLSm9SYFWofZN8LU8yM4T3l5jier9EBF1ifRr/LCnVWHxC yrFVjdmTirJEZXTAZlxevwrO0a6ui5Tt36/7OGLgAdTkUiR2Wfpu5WFNApkzUII5T32y RltvkVZYL5dUuM/krzFDA+h0TE3mBlHpp4uGUS/othAlU4nY9fkIFfKBbOIGkWQqTj4h +aPjFjMX7ipz0jYujc6fND2jetpTGVmKW2Q0uoIo4OIhUt2UgnlKMWAq5mwHg/46m6MY 2X/LilXopweZeFYM8MJeMKwW74nAIeLVeBM4t4amn690ZT9zejpKynHGxu5i/UVhNd4h JHpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Ny1J9SuFdQsLYWMoMqhJ4HKt0skzqGaFUXR0q2TICbM=; b=CfNJEMYjG7p089BuJX9ltG2XSpP33fQDvIPweKWQkWgZvg/YStxJuANgTL3XKMM/+/ Qo/IUW1MMbA8eEWfhK4uuo3hME8ln9jb1S2jsz/IFKNRJ3CeOuLC5K5H5HpdJsv0czPG GiCoLxDPz7dqv30HzEDpf5wgE8tqkpoU2VuZ1Je6DouM641fZKOIWFcZfncWTlDb2OY7 mvY0Ead1/8KBfyEWysYG5NfEBIfs2oDZMPWMrDMnWoc8CpQHOnaa58Tp6hRm0qtgYBzl TIjI7nkRr0JmdNiZtrw8gs1pbP85WjU4JnKZc0qc1gIQX7xumvnqo5eX30/HZWQYDc0p 7U5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=tXs9MEkW; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id n11si3615588edn.99.2019.02.21.01.01.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 01:01:32 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=tXs9MEkW; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 183C8294A94 for ; Thu, 21 Feb 2019 10:01:30 +0100 (CET) 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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 9F8D7294AD7 for ; Thu, 21 Feb 2019 10:01:20 +0100 (CET) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 0475860165D for ; Thu, 21 Feb 2019 10:01:18 +0100 (CET) Received: by mail-pf1-x441.google.com with SMTP id h1so13425230pfo.7 for ; Thu, 21 Feb 2019 01:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NX61GZqQlo6N8y0MvlFka7W8ofBR2MpVX39i7sy/+SY=; b=tXs9MEkWjUngtjdt2VMAd/Zd1iM6yk7h1X5NeqTu/uhOal6GKTwFm0IluJfR92a6Y2 YUwi0QMybr/G1HgMrzzM2kUlZdZp33bYI5HNqOfwUd0Kr58RPXLn5E2tEXfk+pypWspJ TqP5CGD+suzZ84noJLXg6CU/5Ua0LL4c6MoJiQtpk2TwmSYWaw+lih5BAGGDaqEBbCi3 uUuKxLXN1OiXK7yCO/nOCV1igkzmk94vLxtC20JWIcmcptruQw+st+1ip1gA1w4RK/4v QVaNjAgBToF1K5LjSPEni6O6knzFP1968T1Swp4+ZHgZNAkS7sYbHVAcqOCGSQrEiKuV QPNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NX61GZqQlo6N8y0MvlFka7W8ofBR2MpVX39i7sy/+SY=; b=ITcedZZhYs2XZXHrwwZJer3ziR9EwfVk4W9dTfnglaPLNfmdVnaGtU5WuacuVQq9fG yRe+EhjFPb+LEk/zfnwQGKRYr2Q0KnmzJHyv0oYAL2CGyzQonbypEYftg27p+g4Cim2f lyV+V7mz8tJU30gH0tDzYzRtelyEPW3pbCdZ8gp7ecRkXM2TytqshhO0NGER1P4cnEJR FxotB6DXHsXptJqDH/ygsSpiWIRonrTYi1Xahce0lU318Qi6py06BwlAB9uoI4Ln77+l EP8DnOvFXwgL8DtkQ6RpQe2AsxhT0nHF5Yf3YFqIvJ2kl0Y7Z7gZfxOivojyAONDbRVu KDrw== X-Gm-Message-State: AHQUAuZ1LhZ/twhBLzVMCzXUcRkh/oqqvS8oz9r14epT38jjF+xrynle Z/Ijvi9PCTsReAodnagKXmpprQ== X-Received: by 2002:a62:1981:: with SMTP id 123mr39089783pfz.69.1550739676380; Thu, 21 Feb 2019 01:01:16 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id v4sm27703948pff.77.2019.02.21.01.01.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Feb 2019 01:01:15 -0800 (PST) From: Sumit Garg To: chrubis@suse.cz, ltp@lists.linux.it Date: Thu, 21 Feb 2019 14:30:15 +0530 Message-Id: <1550739616-24054-9-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> References: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH v4 8/9] syscalls/sync_file_range: Use C library wrapper if present X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Add config check for C library wrapper for sync_file_range() syscall. Also, check for sync_file_range() presence via dummy call rather than kernel version check. And move fallback api to: include/lapi/sync_file_range.h Signed-off-by: Sumit Garg --- configure.ac | 1 + include/lapi/sync_file_range.h | 57 ++++++++++++++++++++ m4/ltp-sync_file_range.m4 | 10 ++++ .../sync_file_range/check_sync_file_range.h | 21 ++++++++ .../syscalls/sync_file_range/sync_file_range01.c | 62 ++-------------------- 5 files changed, 94 insertions(+), 57 deletions(-) create mode 100644 include/lapi/sync_file_range.h create mode 100644 m4/ltp-sync_file_range.m4 create mode 100644 testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h diff --git a/configure.ac b/configure.ac index 9122b6d..d15bff3 100644 --- a/configure.ac +++ b/configure.ac @@ -232,6 +232,7 @@ LTP_CHECK_RLIMIT64 LTP_DETECT_HOST_CPU LTP_CHECK_PERF_EVENT LTP_CHECK_SYNCFS +LTP_CHECK_SYNC_FILE_RANGE if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA diff --git a/include/lapi/sync_file_range.h b/include/lapi/sync_file_range.h new file mode 100644 index 0000000..e2d35fc --- /dev/null +++ b/include/lapi/sync_file_range.h @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2008 + */ + +#ifndef SYNC_FILE_RANGE_H +#define SYNC_FILE_RANGE_H + +#include +#include "config.h" +#include "lapi/syscalls.h" + +#if !defined(HAVE_SYNC_FILE_RANGE) + +#ifdef TST_TEST_H__ +# define TST_SYSCALL tst_syscall +#else +# define TST_SYSCALL ltp_syscall +#endif + +/***************************************************************************** + * Wraper function to call sync_file_range system call + ******************************************************************************/ +static inline long sync_file_range(int fd, off64_t offset, off64_t nbytes, + unsigned int flags) +{ +#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__)) +# if (__WORDSIZE == 32) +# if __BYTE_ORDER == __BIG_ENDIAN + return TST_SYSCALL(__NR_sync_file_range2, fd, flags, + (int)(offset >> 32), (int)offset, (int)(nbytes >> 32), + (int)nbytes); +# elif __BYTE_ORDER == __LITTLE_ENDIAN + return TST_SYSCALL(__NR_sync_file_range2, fd, flags, (int)offset, + (int)(offset >> 32), nbytes, (int)(nbytes >> 32)); +# endif +# else + return TST_SYSCALL(__NR_sync_file_range2, fd, flags, offset, nbytes); +# endif +#elif (defined(__s390__) || defined(__s390x__)) && __WORDSIZE == 32 + return TST_SYSCALL(__NR_sync_file_range, fd, (int)(offset >> 32), + (int)offset, (int)(nbytes >> 32), (int)nbytes, flags); +#elif defined(__mips__) && __WORDSIZE == 32 +# if __BYTE_ORDER == __BIG_ENDIAN + return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)(offset >> 32), + (int)offset, (int)(nbytes >> 32), (int)nbytes, flags); +# elif __BYTE_ORDER == __LITTLE_ENDIAN + return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)offset, + (int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags); +# endif +#else + return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags); +#endif +} +#endif + +#endif /* SYNC_FILE_RANGE_H */ diff --git a/m4/ltp-sync_file_range.m4 b/m4/ltp-sync_file_range.m4 new file mode 100644 index 0000000..b47a091 --- /dev/null +++ b/m4/ltp-sync_file_range.m4 @@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 Linaro Limited. All rights reserved. + +dnl +dnl LTP_CHECK_SYNC_FILE_RANGE +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_SYNC_FILE_RANGE],[ +AC_CHECK_FUNCS(sync_file_range,,) +]) diff --git a/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h b/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file mode 100644 index 0000000..4698c55 --- /dev/null +++ b/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Sumit Garg + */ + +#ifndef CHECK_SYNC_FILE_RANGE_H +#define CHECK_SYNC_FILE_RANGE_H + +int check_sync_file_range(void) +{ + int ret; + + ret = sync_file_range(-1, 0, 0, 0); + if (ret == -1 && errno == EINVAL) + return 0; + + return 1; +} + +#endif /* CHECK_SYNC_FILE_RANGE_H */ diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c index cebb919..3a97183 100644 --- a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c @@ -92,7 +92,8 @@ #include #include "test.h" -#include "lapi/syscalls.h" +#include "lapi/sync_file_range.h" +#include "check_sync_file_range.h" #ifndef SYNC_FILE_RANGE_WAIT_BEFORE #define SYNC_FILE_RANGE_WAIT_BEFORE 1 @@ -190,48 +191,6 @@ void setup(void) sfd = open(spl_file, O_RDWR | O_CREAT, 0700); } -/***************************************************************************** - * Wraper function to call sync_file_range system call - ******************************************************************************/ -static inline long syncfilerange(int fd, off64_t offset, off64_t nbytes, - unsigned int flags) -{ -/* arm and powerpc */ -#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__)) -#if (__WORDSIZE == 32) -#if __BYTE_ORDER == __BIG_ENDIAN - return ltp_syscall(__NR_sync_file_range2, fd, flags, - (int)(offset >> 32), (int)offset, (int)(nbytes >> 32), - (int)nbytes); -#elif __BYTE_ORDER == __LITTLE_ENDIAN - return ltp_syscall(__NR_sync_file_range2, fd, flags, (int)offset, - (int)(offset >> 32), nbytes, (int)(nbytes >> 32)); -#endif -#else - return ltp_syscall(__NR_sync_file_range2, fd, flags, offset, nbytes); -#endif - -/* s390 */ -#elif (defined(__s390__) || defined(__s390x__)) && __WORDSIZE == 32 - return ltp_syscall(__NR_sync_file_range, fd, (int)(offset >> 32), - (int)offset, (int)(nbytes >> 32), (int)nbytes, flags); - -/* mips */ -#elif defined(__mips__) && __WORDSIZE == 32 -#if __BYTE_ORDER == __BIG_ENDIAN - return ltp_syscall(__NR_sync_file_range, fd, 0, (int)(offset >> 32), - (int)offset, (int)(nbytes >> 32), (int)nbytes, flags); -#elif __BYTE_ORDER == __LITTLE_ENDIAN - return ltp_syscall(__NR_sync_file_range, fd, 0, (int)offset, - (int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags); -#endif - -/* other */ -#else - return ltp_syscall(__NR_sync_file_range, fd, offset, nbytes, flags); -#endif -} - /******************************************************************************/ /* */ /* Function: main */ @@ -258,24 +217,13 @@ int main(int ac, char **av) tst_parse_opts(ac, av, NULL, NULL); -#if defined(__powerpc__) || defined(__powerpc64__) /* for PPC, kernel version > 2.6.21 needed */ - if (tst_kvercmp(2, 16, 22) < 0) { - tst_brkm(TCONF, NULL, - "System doesn't support execution of the test"); - } -#else - /* For other archs, need kernel version > 2.6.16 */ - - if (tst_kvercmp(2, 6, 17) < 0) { - tst_brkm(TCONF, NULL, - "System doesn't support execution of the test"); - } -#endif + if (!check_sync_file_range()) + tst_brkm(TCONF, NULL, "sync_file_range() not supported"); setup(); for (test_index = 0; test_index < TST_TOTAL; test_index++) { - TEST(syncfilerange + TEST(sync_file_range (*(test_data[test_index].fd), test_data[test_index].offset, test_data[test_index].nbytes,