From patchwork Tue Jun 11 07:47:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murphy Zhou X-Patchwork-Id: 1113560 X-Patchwork-Delegate: wangli.ahau@gmail.com 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=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45NMZG4ZpNz9sCJ for ; Tue, 11 Jun 2019 17:48:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8E0BD3EAFF5 for ; Tue, 11 Jun 2019 09:48:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id C9B923EAEBE for ; Tue, 11 Jun 2019 09:48:31 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 9A98A6009B3 for ; Tue, 11 Jun 2019 09:48:33 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C37F30860B7; Tue, 11 Jun 2019 07:48:29 +0000 (UTC) Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8CA85C22E; Tue, 11 Jun 2019 07:48:26 +0000 (UTC) From: Murphy Zhou To: liwang@redhat.com Date: Tue, 11 Jun 2019 15:47:38 +0800 Message-Id: <20190611074741.31903-1-xzhou@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 11 Jun 2019 07:48:29 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: linux-fsdevel@vger.kernel.org, ltp@lists.linux.it Subject: [LTP] [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" To check if FIBMAP ioctl is supported by the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now. Reviewed-by: Li Wang Signed-off-by: Murphy Zhou --- v7: Make tst_fibmap return value more accurate Print errno if fibmap ioctl does not succeed Make swapoff02 use new helper Mute some build warnnings cc linux-fsdevel list Overall diff stat: include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 ++--------- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++++++- testcases/kernel/syscalls/swapon/swapon01.c | 11 ++--------- testcases/kernel/syscalls/swapon/swapon02.c | 13 +++---------- testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++----------- 11 files changed, 112 insertions(+), 51 deletions(-) v6: Modify make_swapfile() to check mkswap support status safely Remove whitelist Remove BTRFS EINVAL check Check mkswap status before testing swapon in helper If swapon pass, following swapoff failure will fail the whole test and break Also modify swapoff02 to remove whitelist completely v5: Split to 4 patches Only take one filename parameter in tst_fibmap Add helper is_swap_supported to check swap operation support status Test fibmap/swapon and swapoff operation in the helper Keep NFS/TMPFS whitelist Keep BTRFS EINVAL handling logic, except above 2 situation: if swapon fails and fibmap is not supported, tst_brk with TCONF if swapon fails and fibmap is supported, tst_brk with TFAIL If swapon test pass in the helper, test swapoff similarly Put is_swap_supported helper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way v4: Fail softly if FIBMAP nit supported, instead of skip entire testcase v3: Fix fs_type undeclared in swapoff01.c v2: Test FIBMAP instead of fstype whitelist include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.c diff --git a/include/tst_fs.h b/include/tst_fs.h index ebca065c6..6d03371ec 100644 --- a/include/tst_fs.h +++ b/include/tst_fs.h @@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void); */ void tst_fill_fs(const char *path, int verbose); +/* + * test if FIBMAP ioctl is supported + */ +int tst_fibmap(const char *filename); + #ifdef TST_TEST_H__ static inline long tst_fs_type(const char *path) { diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c new file mode 100644 index 000000000..364220bcd --- /dev/null +++ b/lib/tst_ioctl.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap(const char *filename) +{ + /* test if FIBMAP ioctl is supported */ + int fd, block = 0; + + fd = open(filename, O_RDWR | O_CREAT, 0666); + if (fd < 0) { + tst_res(TWARN | TERRNO, + "open(%s, O_RDWR | O_CREAT, 0666) failed", filename); + return -1; + } + + if (ioctl(fd, FIBMAP, &block)) { + tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported"); + close(fd); + return 1; + } + tst_res(TINFO, "FIBMAP ioctl is supported"); + + if (close(fd)) { + tst_res(TWARN | TERRNO, "close(fd) failed"); + return -1; + } + return 0; +}