From patchwork Tue Feb 19 09:28:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158703 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3447526jaa; Tue, 19 Feb 2019 01:29:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IYBwvnFP8SHHrxrotguufiz01KmBiGf8q7w7TUYNjQkFWI0MITkPH/FsxFcNx3HX5hkJmD3 X-Received: by 2002:a17:906:4595:: with SMTP id t21mr11570098ejq.120.1550568587689; Tue, 19 Feb 2019 01:29:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550568587; cv=none; d=google.com; s=arc-20160816; b=ETm7Dm7HwDBscUdCuLH/ovA0N9weUiEdrkVAl7mzqvl1BR0KdOjiTRmOjkVXGlGuBc 0Ow5G0FQHJKIjPlVbrSa9XVuFZaZS9Pp0GTPYNpmPTFesx77knwY8hFXUswjmZ052Fyt qa5aT/ghZfgZpnlbUo9tQexHtgZlwplI70f3Yau1nw59as+qFrFygtxg+SCGJoLb00gk 6fF3jnQilTMy1+RARX3J/1w5h/5lwZK1GV3jabuTY8b/t3VH77Nq9MMxP9LFw0+1brMJ xf6PNJZqxHAxFjtR2onxWUnlSwImVTLHNcCduEKsTw7uoOoT9FPI2PMHWZqqLfSlL44+ advA== 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=/Q37++CKeyo5LOah7tsSLtcewFkWKnxGcPHziUgwmGQ=; b=oFA5nANXgRPg/QKeYoF4teL5nDBC57dDO/G9fZsxaWesu6uftAf/O7HnG7Jp6lqKr3 WGpQ1ByGthYv6MvozS4Hia6jSla9TpWTP4c/cGS0ETKYNBDF/nkzrUTn8M+1n/Tp+3Kd CWvYu7dloVjGLxFz2NS2NHUKBzuKkovb98RDjC86xzldO+XPZHn2/ORCHSUgF/7dzyJS oNkdm7WFT4AUDNOhKZSI9nYhkvppTGqD+fUzJxFYzVQuprDKDRYRF2/9r7qiTmBff15s O45Ur8PfzRTsdbBw2pYgMLEqB7xNWpUdIgo2UvrEQx+nG287+jCRjre3aRIwUPXI9vnl dO2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=J+Dvw8Ac; 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 t29si1493794edt.450.2019.02.19.01.29.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 01:29:47 -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=J+Dvw8Ac; 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 3AA8D3EA37C for ; Tue, 19 Feb 2019 10:29:41 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id E1E093EA469 for ; Tue, 19 Feb 2019 10:29:26 +0100 (CET) Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 4C15A1000D09 for ; Tue, 19 Feb 2019 10:29:24 +0100 (CET) Received: by mail-pg1-x542.google.com with SMTP id u9so6333613pgo.7 for ; Tue, 19 Feb 2019 01:29:25 -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=xrJPZVZPVkPf9eAXCvb6K4lwL+3WNWEF1qx7slYUZX0=; b=J+Dvw8Ac0fgyZ9zuQ8w0vwf5bIrtEbIcOY/ssgwCiHjkZu3mdUfbuJTIwdxWWiCqRj nAxt3DKvlUyYhogF8oyIUai1vB9swvfYI2SGildAIY7hrzPkJaKTbhel+Wcx4H4/5R4+ lppWc+U3CisWGBF9M8D9/vyKioq+YY8zUSa53104+Ce8zi4DFRZQJ+O4kOE84W/AcDSl X2kWbGvfaGX44R0a/2rZQ/+5wtoJMXEc6p5y+/vVTFhA+9vGaRBNYNkED1++Bk6Vuz0x 8GhG+5/ECnAVZuJ/phtpmvw3+D/axxNdjSuw/90CC7lDN5zWvC8GQTNl+0frz8VrJAvT dt6A== 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=xrJPZVZPVkPf9eAXCvb6K4lwL+3WNWEF1qx7slYUZX0=; b=HpDCV9M1YIT2m6USCGKAQOIL7h6NVBhrbHjDHVxDPJaMSAO6cWpHcHzyAlMb9n0pzm qfh+a+Q1X3h21TAZV/cPPIEhgXKrtmtAqm0VpGxXOajDf+wU1jQJzdf8uRkwGddovM9N ODXY2rwvfTbnNmcblyBJ7wLKZVtquL5VHjmbdmVw6+sBGuut6kkp6YBvrF4ceV4PAFZ8 v+LBLNpJmH13KqRRu57yjzFO/rU3RKcAKaRCM0sjJ36GriJplZ6HQGFxPPPdZCYG5GRO jyAQuuedmmygLd2U0KhJfQMhmePVnHxci4PnD+5Fxl9al9wb00DFZzi7a3KnB0gz/uay 0f6g== X-Gm-Message-State: AHQUAubPsFtolCDl10SDYCkM3b/fzthfSd0YlVcDKYVmjlMwuRcAeMsH uw5yA6boog6JVYnooXWSLYaJhrwkkqK8Hw== X-Received: by 2002:a63:c40a:: with SMTP id h10mr23251296pgd.131.1550568563603; Tue, 19 Feb 2019 01:29:23 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id n19sm34442229pfg.67.2019.02.19.01.29.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Feb 2019 01:29:23 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Tue, 19 Feb 2019 14:58:19 +0530 Message-Id: <1550568500-10871-7-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550568500-10871-1-git-send-email-sumit.garg@linaro.org> References: <1550568500-10871-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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-4.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH v3 6/7] 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 | 64 ++++++++++++++++++++++ m4/ltp-sync_file_range.m4 | 10 ++++ .../sync_file_range/check_sync_file_range.h | 23 ++++++++ .../syscalls/sync_file_range/sync_file_range01.c | 62 ++------------------- 5 files changed, 103 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..7b0ef69 --- /dev/null +++ b/include/lapi/sync_file_range.h @@ -0,0 +1,64 @@ +// 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) +{ +/* arm and powerpc */ +#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 + +/* s390 */ +#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); + +/* mips */ +#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 + +/* other */ +#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..3d932f6 --- /dev/null +++ b/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h @@ -0,0 +1,23 @@ +// 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 + +#include + +bool check_sync_file_range(void) +{ + int ret; + + ret = sync_file_range(-1, 0, 0, 0); + if (ret == -1 && errno == EINVAL) + return false; + + return true; +} + +#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,