From patchwork Thu Apr 9 10:44:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (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 48yd7k66w9z9sP7 for ; Thu, 9 Apr 2020 20:44:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B53F13C2CC6 for ; Thu, 9 Apr 2020 12:44:47 +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 934083C03CC for ; Thu, 9 Apr 2020 12:44:44 +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 55B47601430 for ; Thu, 9 Apr 2020 12:44:42 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748932" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:38 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 6172E406AB15 for ; Thu, 9 Apr 2020 18:34:10 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:33 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:37 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:36 +0800 Message-ID: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20200409075506.GA2828@yuki.lan> References: <20200409075506.GA2828@yuki.lan> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 6172E406AB15.AC01E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 01/10] lapi/loop.h: Add fallback for loop ioctl and flag 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- include/lapi/loop.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/lapi/loop.h diff --git a/include/lapi/loop.h b/include/lapi/loop.h new file mode 100644 index 000000000..bc6d9950d --- /dev/null +++ b/include/lapi/loop.h @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ +#ifndef LAPI_LOOP_H +#define LAPI_LOOP_H + +#include +#ifdef HAVE_LINUX_LOOP_H +# include +#endif + +#ifndef LO_FLAGS_PARTSCAN +# define LO_FLAGS_PARTSCAN 8 +#endif + +#ifndef LO_FLAGS_DIRECT_IO +# define LO_FLAGS_DIRECT_IO 16 +#endif + +#ifndef LOOP_SET_CAPACITY +# define LOOP_SET_CAPACITY 0x4C07 +#endif + +#ifndef LOOP_SET_DIRECT_IO +# define LOOP_SET_DIRECT_IO 0x4C08 +#endif + +#ifndef LOOP_SET_BLOCK_SIZE +# define LOOP_SET_BLOCK_SIZE 0x4C09 +#endif + +#endif + From patchwork Thu Apr 9 10:44:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd7x2FqZz9sP7 for ; Thu, 9 Apr 2020 20:45:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A0C6A3C2CD0 for ; Thu, 9 Apr 2020 12:44:58 +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 9C6D33C2CE3 for ; Thu, 9 Apr 2020 12:44:48 +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 678ED600CED for ; Thu, 9 Apr 2020 12:44:45 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748934" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:38 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 31F4050A9999 for ; Thu, 9 Apr 2020 18:34:14 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:38 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:41 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:37 +0800 Message-ID: <1586429086-22975-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 31F4050A9999.ABDF8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 02/10] syscalls/ioctl:add common c file for loop ioctl 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- testcases/kernel/syscalls/ioctl/Makefile | 5 +++ .../syscalls/ioctl/ioctl_loop_support.c | 40 +++++++++++++++++++ .../syscalls/ioctl/ioctl_loop_support.h | 12 ++++++ 3 files changed, 57 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.c create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop_support.h diff --git a/testcases/kernel/syscalls/ioctl/Makefile b/testcases/kernel/syscalls/ioctl/Makefile index c2ff6c8e7..7bdc7daf0 100644 --- a/testcases/kernel/syscalls/ioctl/Makefile +++ b/testcases/kernel/syscalls/ioctl/Makefile @@ -7,6 +7,11 @@ include $(top_srcdir)/include/mk/testcases.mk INSTALL_TARGETS += test_ioctl +FILTER_OUT_MAKE_TARGETS += ioctl_loop_support + +LOOP_TARGETS := $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/ioctl_loop[0-9]*.c)) +$(LOOP_TARGETS): %: ioctl_loop_support.o + ifeq ($(ANDROID),1) FILTER_OUT_MAKE_TARGETS += ioctl02 endif diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop_support.c b/testcases/kernel/syscalls/ioctl/ioctl_loop_support.c new file mode 100644 index 000000000..75c7b1b9a --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop_support.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ +#define TST_NO_DEFAULT_MAIN +#include "ioctl_loop_support.h" +#include "tst_test.h" + +void check_sys_value(char *path, int setvalue) +{ + int getvalue; + + SAFE_FILE_SCANF(path, "%d", &getvalue); + if (setvalue == getvalue) + tst_res(TPASS, "%s value is %d", path, setvalue); + else + tst_res(TFAIL, "%s value expected %d got %d", path, setvalue, getvalue); +} + +void check_sys_string(char *path, char *setmessage) +{ + char getmessage[1024]; + + SAFE_FILE_SCANF(path, "%s", getmessage); + if (strcmp(setmessage, getmessage)) + tst_res(TFAIL, "%s expected %s got %s", path, setmessage, getmessage); + else + tst_res(TPASS, "%s string is %s", path, getmessage); +} + +void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message) +{ + int ret = 0; + + ret = ioctl(dev_fd, ioctl_flag, value); + if (ret && errno == EINVAL) + tst_brk(TCONF, "Current environment doesn't support this flag(%s)", + message); +} diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop_support.h b/testcases/kernel/syscalls/ioctl/ioctl_loop_support.h new file mode 100644 index 000000000..ade64e82e --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop_support.h @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ +#ifndef IOCTL_LOOP_H +#define IOCTL_lOOP_H +#include +void check_sys_value(char *path, int setvalue); +void check_sys_string(char *path, char *setmessage); +void check_support_cmd(int dev_fd, int ioctl_flag, int value, char *message); +#endif From patchwork Thu Apr 9 10:44:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd8n4JWzz9sP7 for ; Thu, 9 Apr 2020 20:45:45 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C09D93C2CED for ; Thu, 9 Apr 2020 12:45:42 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 9ABAF3C2CDA for ; Thu, 9 Apr 2020 12:44:55 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 6AFFF14010FD for ; Thu, 9 Apr 2020 12:44:47 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748938" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:44 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 5F09D406AB15 for ; Thu, 9 Apr 2020 18:34:17 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:42 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:44 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:38 +0800 Message-ID: <1586429086-22975-3-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 5F09D406AB15.AE186 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 03/10] syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys directory and also get lo_flags by using LOOP_GET_STATUS. For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. But we also check whether we can scan partition table correctly ie check whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed. Signed-off-by: Yang Xu --- runtest/syscalls | 3 +- testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop01.c | 140 ++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c diff --git a/runtest/syscalls b/runtest/syscalls index 44254d7da..8d1ce0c9a 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -525,10 +525,11 @@ ioctl03 ioctl03 ioctl04 ioctl04 ioctl05 ioctl05 ioctl06 ioctl06 - ioctl07 ioctl07 ioctl08 ioctl08 +ioctl_loop01 ioctl_loop01 + ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 ioctl_ns03 ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 97fbb9681..4cfef2839 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -6,6 +6,7 @@ /ioctl06 /ioctl07 /ioctl08 +/ioctl_loop01 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c new file mode 100644 index 000000000..fb71b7b1e --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice. + * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag. + * + * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys + * directory and also get lo_flags by using LOOP_GET_STATUS. + * + * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag. + * But we also check whether we can scan partition table correctly ie check + * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed. + */ + +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static char dev_path[1024], backing_path[1024], backing_file_path[1024]; +static int dev_num, attach_flag, dev_fd, parted_sup; +/* + *In drivers/block/loop.c code, set status function doesn't handle + *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly + *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY. + */ +#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO) +#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN) + +static char partscan_path[1024], autoclear_path[1024]; +static char loop_partpath[1026], sys_loop_partpath[1026]; + +static void verify_ioctl_loop(void) +{ + int ret; + struct loop_info loopinfo, loopinfoget; + + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + + check_sys_value(partscan_path, 0); + check_sys_value(autoclear_path, 0); + check_sys_string(backing_path, backing_file_path); + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + memset(&loopinfo, 0, sizeof(loopinfo)); + memset(&loopinfoget, 0, sizeof(loopinfoget)); + + loopinfo.lo_flags = set_flags; + SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo); + + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); + + if (loopinfoget.lo_flags & ~get_flags) + tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags); + else + tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags); + + check_sys_value(partscan_path, 1); + check_sys_value(autoclear_path, 1); + + if (!parted_sup) { + tst_res(TINFO, "Current environment doesn't have parted disk, skip it"); + goto detach_device; + } + + ret = access(loop_partpath, F_OK); + if (ret == 0) + tst_res(TPASS, "access %s succeeds", loop_partpath); + else + tst_res(TFAIL, "access %s fails", loop_partpath); + + ret = access(sys_loop_partpath, F_OK); + if (ret == 0) + tst_res(TPASS, "access %s succeeds", sys_loop_partpath); + else + tst_res(TFAIL, "access %s fails", sys_loop_partpath); + +detach_device: + SAFE_CLOSE(dev_fd); + tst_detach_device(dev_path); + attach_flag = 0; +} + +static void setup(void) +{ + int ret; + const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart", + "primary", "ext4", "1M", "10M", NULL}; + + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + tst_fill_file("test.img", 0, 1024 * 1024, 10); + + ret = tst_cmd(cmd_parted, NULL, NULL, TST_CMD_PASS_RETVAL); + switch (ret) { + case 0: + parted_sup = 1; + break; + case 255: + tst_res(TCONF, "parted binary not installed or failed"); + break; + default: + tst_res(TCONF, "parted exited with %i", ret); + break; + } + + sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num); + sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num); + sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num); + sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num); + sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir()); + sprintf(loop_partpath, "%sp1", dev_path); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + }, + .needs_tmpdir = 1, +}; From patchwork Thu Apr 9 10:44:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd8b3Wx8z9sP7 for ; Thu, 9 Apr 2020 20:45:35 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BCA5C3C2CE1 for ; Thu, 9 Apr 2020 12:45:32 +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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 2708B3C2CD3 for ; Thu, 9 Apr 2020 12:44:55 +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 3BA0A600CED for ; Thu, 9 Apr 2020 12:44:52 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748940" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:50 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 85F5650A999E for ; Thu, 9 Apr 2020 18:34:20 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:44 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:47 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:39 +0800 Message-ID: <1586429086-22975-4-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 85F5650A999E.ACFB6 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 04/10] syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" For LOOP_CHANGE_FD, this operation is possible only if the loop device is read-only and the new backing store is the same size and type as the old backing store. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop02.c | 150 ++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop02.c diff --git a/runtest/syscalls b/runtest/syscalls index 8d1ce0c9a..80005227d 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -529,6 +529,7 @@ ioctl07 ioctl07 ioctl08 ioctl08 ioctl_loop01 ioctl_loop01 +ioctl_loop02 ioctl_loop02 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 4cfef2839..534c4ab34 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -7,6 +7,7 @@ /ioctl07 /ioctl08 /ioctl_loop01 +/ioctl_loop02 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop02.c b/testcases/kernel/syscalls/ioctl/ioctl_loop02.c new file mode 100644 index 000000000..683171501 --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop02.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice. + * + * It is designed to test LO_FLAGS_READ_ONLY(similar as losetup -r) + * and LOOP_CHANGE_FD. + * + * For LOOP_CHANGE_FD, this operation is possible only if the loop device + * is read-only and the new backing store is the same size and type as the + * old backing store. + */ + +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static int file_fd, file_change_fd, file_fd_invalid; +static char backing_path[1024], backing_file_path[1024], backing_file_change_path[1024]; +static int attach_flag, dev_fd, file_fd; +static char loop_ro_path[1024], dev_path[1024]; + +/* + * This function is different from tst_attach_dev lib/tst_device.c. + * It only opens file_path with O_RDONLY mode before loop_set_fd. + * So we can generate LO_FLAGS_READ_ONLY flag. + */ +static void attach_device(char *img) +{ + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + file_fd = SAFE_OPEN(img, O_RDONLY); + + SAFE_IOCTL(dev_fd, LOOP_SET_FD, file_fd); + + SAFE_CLOSE(dev_fd); + SAFE_CLOSE(file_fd); +} + +static void verify_ioctl_loop(void) +{ + struct loop_info loopinfoget; + + attach_device("test.img"); + attach_flag = 1; + + check_sys_value(loop_ro_path, 1); + check_sys_string(backing_path, backing_file_path); + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + file_change_fd = SAFE_OPEN("test1.img", O_RDWR); + file_fd_invalid = SAFE_OPEN("test2.img", O_RDWR); + + memset(&loopinfoget, 0, sizeof(loopinfoget)); + + /* + * In drivers/block/loop.c code, set status function doesn't handle + * LO_FLAGS_READ_ONLY flag and ignore it. Only loop_set_fd with readonly + * mode, lo_flags will include LO_FLAGS_READ_ONLY. + */ + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); + + if (loopinfoget.lo_flags & ~LO_FLAGS_READ_ONLY) + tst_res(TFAIL, "lo_flags has unexpected %d flag", loopinfoget.lo_flags); + else + tst_res(TPASS, "lo_flags only has default LO_FLAGS_READ_ONLY flag"); + + TEST(write(dev_fd, "xx", 2)); + if (TST_RET != -1) + tst_res(TFAIL, "write succeed unexpectedly"); + else + tst_res(TPASS | TTERRNO, "Can not write data in RO mode"); + + TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_change_fd)); + if (TST_RET) { + tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed"); + } else { + tst_res(TPASS, "LOOP_CHANGE_FD succeeded"); + check_sys_value(loop_ro_path, 1); + check_sys_string(backing_path, backing_file_change_path); + } + + TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd_invalid)); + if (TST_RET) { + if (TST_ERR == EINVAL) + tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected"); + else + tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got"); + } else { + tst_res(TFAIL, "LOOP_CHANGE_FD succeeded"); + } + + SAFE_CLOSE(dev_fd); + SAFE_CLOSE(file_change_fd); + SAFE_CLOSE(file_fd_invalid); + tst_detach_device(dev_path); + attach_flag = 0; +} + +static void setup(void) +{ + int dev_num; + + char *tmpdir = tst_get_tmpdir(); + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + tst_fill_file("test.img", 0, 1024, 10); + tst_fill_file("test1.img", 0, 1024, 10); + tst_fill_file("test2.img", 0, 2048, 20); + + sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num); + sprintf(backing_file_path, "%s/test.img", tmpdir); + sprintf(backing_file_change_path, "%s/test1.img", tmpdir); + sprintf(loop_ro_path, "/sys/block/loop%d/ro", dev_num); + if (tmpdir) + free(tmpdir); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (file_fd > 0) + SAFE_CLOSE(file_fd); + if (file_change_fd > 0) + SAFE_CLOSE(file_change_fd); + if (file_fd_invalid > 0) + SAFE_CLOSE(file_fd_invalid); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd881HxJz9sSj for ; Thu, 9 Apr 2020 20:45:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2385E3C2CD4 for ; Thu, 9 Apr 2020 12:45:09 +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 [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 524D03C2CE1 for ; Thu, 9 Apr 2020 12:44:52 +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 E8441600CED for ; Thu, 9 Apr 2020 12:44:50 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748941" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:50 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 1BB3B406AB15 for ; Thu, 9 Apr 2020 18:34:23 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:47 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:50 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:40 +0800 Message-ID: <1586429086-22975-5-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 1BB3B406AB15.AD0EA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 05/10] syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" It is designed to test LOOP_CHANGE_FD can not succeed(get EINAL error) when loop_dev is not read only. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop03.c | 76 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop03.c diff --git a/runtest/syscalls b/runtest/syscalls index 80005227d..46d877fa3 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -530,6 +530,7 @@ ioctl08 ioctl08 ioctl_loop01 ioctl_loop01 ioctl_loop02 ioctl_loop02 +ioctl_loop03 ioctl_loop03 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 534c4ab34..1501c2779 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -8,6 +8,7 @@ /ioctl08 /ioctl_loop01 /ioctl_loop02 +/ioctl_loop03 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop03.c b/testcases/kernel/syscalls/ioctl/ioctl_loop03.c new file mode 100644 index 000000000..4e7c29cde --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop03.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice. + * + * It is designed to test LOOP_CHANGE_FD can not succeed(get EINAL error) + * when loop_dev is not read only. + */ + +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static char dev_path[1024]; +static int dev_num, dev_fd, file_fd, attach_flag; + +static void verify_ioctl_loop(void) +{ + TEST(ioctl(dev_fd, LOOP_CHANGE_FD, file_fd)); + if (TST_RET == 0) { + tst_res(TFAIL, "LOOP_CHANGE_FD succeeded unexpectedly"); + return; + } + if (TST_ERR == EINVAL) + tst_res(TPASS | TTERRNO, "LOOP_CHANGE_FD failed as expected"); + else + tst_res(TFAIL | TTERRNO, "LOOP_CHANGE_FD failed expected EINVAL got"); +} + +static void setup(void) +{ + struct loop_info loopinfoget; + + memset(&loopinfoget, 0, sizeof(loopinfoget)); + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + tst_fill_file("test.img", 0, 1024, 10); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + file_fd = SAFE_OPEN("test.img", O_RDWR); + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); + + if (loopinfoget.lo_flags & LO_FLAGS_READ_ONLY) + tst_brk(TCONF, "Current environment has unexpected LO_FLAGS_READ_ONLY flag"); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (file_fd > 0) + SAFE_CLOSE(file_fd); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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 48yd8N4Bcnz9sP7 for ; Thu, 9 Apr 2020 20:45:24 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8BE593C2CD3 for ; Thu, 9 Apr 2020 12:45:21 +0200 (CEST) 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 031663C220D for ; Thu, 9 Apr 2020 12:44:54 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id D43F11000A24 for ; Thu, 9 Apr 2020 12:44:50 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748942" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:50 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 4983550A9971 for ; Thu, 9 Apr 2020 18:34:25 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:50 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:52 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:41 +0800 Message-ID: <1586429086-22975-6-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 4983550A9971.AC1F3 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 06/10] syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" LOOP_SET_CAPACITY can update a live loop device size when we change the size of the underlying backing file. Also check sys value. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop04.c | 97 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop04.c diff --git a/runtest/syscalls b/runtest/syscalls index 46d877fa3..51ad8ff69 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -531,6 +531,7 @@ ioctl08 ioctl08 ioctl_loop01 ioctl_loop01 ioctl_loop02 ioctl_loop02 ioctl_loop03 ioctl_loop03 +ioctl_loop04 ioctl_loop04 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 1501c2779..039a5251c 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -9,6 +9,7 @@ /ioctl_loop01 /ioctl_loop02 /ioctl_loop03 +/ioctl_loop04 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop04.c b/testcases/kernel/syscalls/ioctl/ioctl_loop04.c new file mode 100644 index 000000000..ae110570e --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop04.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice. + * + * It is designed to test LOOP_SET_CAPACITY can update a live + * loop device size when we change the size of the underlying + * backing file. Also check sys value. + */ +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +#define OLD_SIZE 10240 +#define NEW_SIZE 5120 + +static char dev_path[1024], sys_loop_sizepath[1024]; +static char *wrbuf; +static int dev_num, dev_fd, file_fd, attach_flag; + +static void verify_ioctl_loop(void) +{ + struct loop_info loopinfoget; + + memset(&loopinfoget, 0, sizeof(loopinfoget)); + tst_fill_file("test.img", 0, 1024, OLD_SIZE/1024); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + + check_sys_value(sys_loop_sizepath, OLD_SIZE/512); + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + file_fd = SAFE_OPEN("test.img", O_RDWR); + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); + + if (loopinfoget.lo_flags & LO_FLAGS_READ_ONLY) + tst_brk(TCONF, "Current environment has unexpected LO_FLAGS_READ_ONLY flag"); + + SAFE_TRUNCATE("test.img", NEW_SIZE); + SAFE_IOCTL(dev_fd, LOOP_SET_CAPACITY); + + /*check that we can't write data beyond 5K into loop device*/ + TEST(write(dev_fd, wrbuf, OLD_SIZE)); + if (TST_RET == NEW_SIZE) { + tst_res(TPASS, "LOOP_SET_CAPACITY has updated loop size(%d) to %d", OLD_SIZE, NEW_SIZE); + check_sys_value(sys_loop_sizepath, NEW_SIZE/512); + } else { + tst_res(TFAIL, "LOOP_SET_CAPACITY doesn't updated loop size to %d, its size is %ld", + NEW_SIZE, TST_RET); + } + + SAFE_CLOSE(file_fd); + SAFE_CLOSE(dev_fd); + tst_detach_device(dev_path); + unlink("test.img"); + attach_flag = 0; +} + +static void setup(void) +{ + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + wrbuf = SAFE_MALLOC(OLD_SIZE); + memset(wrbuf, 'x', OLD_SIZE); + sprintf(sys_loop_sizepath, "/sys/block/loop%d/size", dev_num); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (file_fd > 0) + SAFE_CLOSE(file_fd); + if (wrbuf) + free(wrbuf); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd905RHdz9sSj for ; Thu, 9 Apr 2020 20:45:56 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4DE1A3C220D for ; Thu, 9 Apr 2020 12:45:53 +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 969673C2CC7 for ; Thu, 9 Apr 2020 12:45:04 +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 41048601430 for ; Thu, 9 Apr 2020 12:45:00 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748946" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:56 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id 93DF5406AB15 for ; Thu, 9 Apr 2020 18:34:27 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:51 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:54 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:42 +0800 Message-ID: <1586429086-22975-7-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 93DF5406AB15.AFC24 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 07/10] syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO ioctl 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" LOOP_SET_DIRECT_IO can update a live loop device dio mode. It needs the backing file also supports dio mode and the lo_offset is aligned with the logical block size(getting by BLKSSZGET ioctl). It was introduced into kernel since 4.10 commit ab1cb278bc70 ("block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO"). Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop05.c | 125 ++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop05.c diff --git a/runtest/syscalls b/runtest/syscalls index 51ad8ff69..8b120b43a 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -532,6 +532,7 @@ ioctl_loop01 ioctl_loop01 ioctl_loop02 ioctl_loop02 ioctl_loop03 ioctl_loop03 ioctl_loop04 ioctl_loop04 +ioctl_loop05 ioctl_loop05 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 039a5251c..f484d98d6 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -10,6 +10,7 @@ /ioctl_loop02 /ioctl_loop03 /ioctl_loop04 +/ioctl_loop05 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c new file mode 100644 index 000000000..16c7a468c --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice. + * + * It is designed to test LOOP_SET_DIRECT_IO can updata a live + * loop device dio mode. It need the backing file also supports + * dio mode and the lo_offset is aligned with the logical block size. + */ +#include +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +#define DIO_MESSAGE "In dio mode" +#define NON_DIO_MESSAGE "In non dio mode" + +static char dev_path[1024], sys_loop_diopath[1024]; +static int dev_num, dev_fd, attach_flag, logical_block_size; + +static void check_dio_value(int flag) +{ + struct loop_info loopinfoget; + + memset(&loopinfoget, 0, sizeof(loopinfoget)); + + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget); + tst_res(TINFO, "%s", flag ? DIO_MESSAGE : NON_DIO_MESSAGE); + + if (loopinfoget.lo_flags & LO_FLAGS_DIRECT_IO) + tst_res(flag ? TPASS : TFAIL, "lo_flags has LO_FLAGS_DIRECT_IO flag"); + else + tst_res(flag ? TFAIL : TPASS, "lo_flags doesn't have LO_FLAGS_DIRECT_IO flag"); + + check_sys_value(sys_loop_diopath, flag); +} + +static void verify_ioctl_loop(void) +{ + struct loop_info loopinfo; + + memset(&loopinfo, 0, sizeof(loopinfo)); + + tst_res(TINFO, "Without setting lo_offset or sizelimit"); + SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 1); + check_dio_value(1); + + SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0); + check_dio_value(0); + + tst_res(TINFO, "With offset equal to logical_block_size"); + loopinfo.lo_offset = logical_block_size; + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0); + TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1)); + if (TST_RET == 0) { + tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded"); + check_dio_value(1); + SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0); + } else { + tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed"); + } + + tst_res(TINFO, "With offset less than or unalign logical_block_size"); + loopinfo.lo_offset = logical_block_size / 2; + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0); + + TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1)); + if (TST_RET == 0) { + tst_res(TFAIL, "LOOP_SET_DIRECT_IO succeeded unexpectedly"); + SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0); + return; + } + if (TST_ERR == EINVAL) + tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected"); + else + tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got"); + + loopinfo.lo_offset = 0; + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0); +} + +static void setup(void) +{ + if (tst_fs_type(".") == TST_TMPFS_MAGIC) + tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag, skip it"); + + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num); + tst_fill_file("test.img", 0, 1024, 1024); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + check_support_cmd(dev_fd, LOOP_SET_DIRECT_IO, 0, "LOOP_SET_DIRECT_IO"); + SAFE_IOCTL(dev_fd, BLKSSZGET, &logical_block_size); + tst_res(TINFO, "%s default logical_block_size is %d", dev_path, logical_block_size); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd9S1lBwz9sP7 for ; Thu, 9 Apr 2020 20:46:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 66DF53C2CE0 for ; Thu, 9 Apr 2020 12:46:17 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 4DAB63C2CF5 for ; Thu, 9 Apr 2020 12:45:07 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id A70BC14013B1 for ; Thu, 9 Apr 2020 12:44:56 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748945" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:56 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id DB2EE50A9984 for ; Thu, 9 Apr 2020 18:34:29 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:54 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:56 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:43 +0800 Message-ID: <1586429086-22975-8-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: DB2EE50A9984.A0C64 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 08/10] syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop06.c | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop06.c diff --git a/runtest/syscalls b/runtest/syscalls index 8b120b43a..e9b0a8f60 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -533,6 +533,7 @@ ioctl_loop02 ioctl_loop02 ioctl_loop03 ioctl_loop03 ioctl_loop04 ioctl_loop04 ioctl_loop05 ioctl_loop05 +ioctl_loop06 ioctl_loop06 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index f484d98d6..ec19b4901 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -11,6 +11,7 @@ /ioctl_loop03 /ioctl_loop04 /ioctl_loop05 +/ioctl_loop06 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop06.c b/testcases/kernel/syscalls/ioctl/ioctl_loop06.c new file mode 100644 index 000000000..ef98efbca --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop06.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl error test about loopdevice + * LOOP_SET_BLOCK_SIZE. + */ + +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static char dev_path[1024], sys_loop_logicalpath[1024]; +static int dev_num, dev_fd, attach_flag; +static unsigned int invalid_value, half_value, unalign_value; + +static struct tcase { + unsigned int *setvalue; + int exp_err; + char *message; +} tcases[] = { + {&half_value, EINVAL, "arg < 512"}, + {&invalid_value, EINVAL, "arg > PAGE_SIZE"}, + {&unalign_value, EINVAL, "arg != power_of_2"}, +}; + +static void verify_ioctl_loop(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + tst_res(TINFO, "%s", tc->message); + TEST(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, *(tc->setvalue))); + if (TST_RET == 0) { + tst_res(TFAIL, "LOOP_SET_BLOCK_SIZE succeed unexpectedly"); + return; + } + if (TST_ERR == tc->exp_err) + tst_res(TPASS | TTERRNO, "LOOP_SET_BLOCK_SIZE failed as expected"); + else + tst_res(TFAIL | TTERRNO, "LOOP_SET_BLOCK_SIZE failed expected %s got", + tst_strerrno(tc->exp_err)); +} + +static void setup(void) +{ + unsigned int pg_size; + + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + sprintf(sys_loop_logicalpath, "/sys/block/loop%d/logical_block_size", dev_num); + tst_fill_file("test.img", 0, 1024, 1024); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + half_value = 256; + pg_size = getpagesize(); + invalid_value = pg_size * 2 ; + unalign_value = pg_size - 1; + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + check_support_cmd(dev_fd, LOOP_SET_BLOCK_SIZE, 512, "LOOP_SET_BLOCK_SIZE"); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (attach_flag) + tst_detach_device(dev_path); + unlink("test.img"); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = verify_ioctl_loop, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd9g40jwz9sP7 for ; Thu, 9 Apr 2020 20:46:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D6A183C2CE9 for ; Thu, 9 Apr 2020 12:46:28 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 1A2E03C2CE7 for ; Thu, 9 Apr 2020 12:45:09 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 76B1E1400DDF for ; Thu, 9 Apr 2020 12:45:01 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748947" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:44:56 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 39D2D50A9984 for ; Thu, 9 Apr 2020 18:34:32 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:56 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:44:59 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:44 +0800 Message-ID: <1586429086-22975-9-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 39D2D50A9984.AD0E8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 09/10] syscalls/ioctl_loop07: Add dio with logic block size error 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE and LOOP_SET_DIRECT_IO. When logical blocksize is 1024, set dio with 512 offset will fail. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop07.c | 85 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c diff --git a/runtest/syscalls b/runtest/syscalls index e9b0a8f60..f83561724 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -534,6 +534,7 @@ ioctl_loop03 ioctl_loop03 ioctl_loop04 ioctl_loop04 ioctl_loop05 ioctl_loop05 ioctl_loop06 ioctl_loop06 +ioctl_loop07 ioctl_loop07 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index ec19b4901..3a3d49adc 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -12,6 +12,7 @@ /ioctl_loop04 /ioctl_loop05 /ioctl_loop06 +/ioctl_loop07 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop07.c b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c new file mode 100644 index 000000000..c58a92b3c --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE + * and LOOP_SET_DIRECT_IO. + * When blocksize is 1024(default align size is 512), set dio with + * 512 offset will fail. + */ + +#include +#include +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static char dev_path[1024], sys_loop_logicalpath[1024]; +static int dev_num, dev_fd, attach_flag, logical_block_size; + +static void verify_ioctl_loop(void) +{ + check_sys_value(sys_loop_logicalpath, 1024); + SAFE_IOCTL(dev_fd, BLKSSZGET, &logical_block_size); + if (logical_block_size == 1024) + tst_res(TPASS, "logical block size is 1024 by using BLKSSZGET ioctl"); + else + tst_res(TFAIL, "expected logical block size is 1024 but got %d by using BLKSSZGET ioctl", + logical_block_size); + TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1)); + if (TST_RET == 0) { + tst_res(TFAIL, "LOOP_SET_DIRECT_IO succeeded unexpectedly"); + return; + } + if (TST_ERR == EINVAL) + tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected"); + else + tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got"); +} + +static void setup(void) +{ + struct loop_info loopinfo; + + memset(&loopinfo, 0, sizeof(loopinfo)); + loopinfo.lo_offset = 512; + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + sprintf(sys_loop_logicalpath, "/sys/block/loop%d/queue/logical_block_size", dev_num); + tst_fill_file("test.img", 0, 1024 * 1024, 1); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0); + check_support_cmd(dev_fd, LOOP_SET_DIRECT_IO, 0, "LOOP_SET_DIRECT_IO"); + check_support_cmd(dev_fd, LOOP_SET_BLOCK_SIZE, 512, "LOOP_SET_BLOCK_SIZE"); + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, 1024), TST_RETVAL_EQ0); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = verify_ioctl_loop, + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +}; From patchwork Thu Apr 9 10:44:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1268558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48yd9G5fjKz9sSq for ; Thu, 9 Apr 2020 20:46:10 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1C83D3C2CDA for ; Thu, 9 Apr 2020 12:46:07 +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 D2C643C2CF2 for ; Thu, 9 Apr 2020 12:45:06 +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 7A150600EB1 for ; Thu, 9 Apr 2020 12:45:05 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.72,362,1580745600"; d="scan'208";a="88748964" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Apr 2020 18:45:02 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id B4006406AB15 for ; Thu, 9 Apr 2020 18:34:34 +0800 (CST) Received: from G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 9 Apr 2020 18:44:58 +0800 Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 18:45:01 +0800 From: Yang Xu To: Date: Thu, 9 Apr 2020 18:44:45 +0800 Message-ID: <1586429086-22975-10-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20200409075506.GA2828@yuki.lan> <1586429086-22975-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: B4006406AB15.AC743 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.3 required=7.0 tests=KHOP_HELO_FCRDNS, 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 v2 10/10] syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Test its lo_sizelimit field. If lo_sizelimit is 0, it means max available. If sizelimit is less than loop_size, loopsize will be truncated. Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/ioctl/.gitignore | 1 + .../kernel/syscalls/ioctl/ioctl_loop08.c | 96 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop08.c diff --git a/runtest/syscalls b/runtest/syscalls index f83561724..d77c191d2 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -535,6 +535,7 @@ ioctl_loop04 ioctl_loop04 ioctl_loop05 ioctl_loop05 ioctl_loop06 ioctl_loop06 ioctl_loop07 ioctl_loop07 +ioctl_loop08 ioctl_loop08 ioctl_ns01 ioctl_ns01 ioctl_ns02 ioctl_ns02 diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 3a3d49adc..97134aa0b 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -13,6 +13,7 @@ /ioctl_loop05 /ioctl_loop06 /ioctl_loop07 +/ioctl_loop08 /ioctl_ns01 /ioctl_ns02 /ioctl_ns03 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop08.c b/testcases/kernel/syscalls/ioctl/ioctl_loop08.c new file mode 100644 index 000000000..150cfa0ef --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop08.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This is a basic ioctl test about loopdevice LOOP_SET_STATUS64 + * and LOOP_GET_STATUS64. + * Test its lo_sizelimit field. If lo_sizelimit is 0,it means max + * available. If sizelimit is less than loop_size, loopsize will + * be truncated. + */ + +#include +#include +#include +#include +#include "ioctl_loop_support.h" +#include "lapi/loop.h" +#include "tst_test.h" + +static char dev_path[1024], sys_loop_sizepath[1024], sys_loop_sizelimitpath[1024]; +static int dev_num, dev_fd, file_fd, attach_flag; + +static struct tcase { + unsigned int set_sizelimit; + unsigned int exp_loopsize; + char *message; +} tcases[] = { + {1024 * 4096, 2048, "When sizelimit is greater than loopsize "}, + {1024 * 512, 1024, "When sizelimit is less than loopsize"}, +}; + +static void verify_ioctl_loop(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + struct loop_info64 loopinfo, loopinfoget; + + tst_res(TINFO, "%s", tc->message); + memset(&loopinfo, 0, sizeof(loopinfo)); + memset(&loopinfoget, 0, sizeof(loopinfoget)); + + loopinfo.lo_sizelimit = tc->set_sizelimit; + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS64, &loopinfo), TST_RETVAL_EQ0); + + check_sys_value(sys_loop_sizepath, tc->exp_loopsize); + check_sys_value(sys_loop_sizelimitpath, tc->set_sizelimit); + SAFE_IOCTL(dev_fd, LOOP_GET_STATUS64, &loopinfoget); + if (loopinfoget.lo_sizelimit == tc->set_sizelimit) + tst_res(TPASS, "LOOP_GET_STATUS64 gets correct lo_sizelimit(%d)", tc->set_sizelimit); + else + tst_res(TFAIL, "LOOP_GET_STATUS64 gets wrong lo_sizelimit(%llu), expect %d", + loopinfoget.lo_sizelimit, tc->set_sizelimit); + /*Reset*/ + loopinfo.lo_sizelimit = 0; + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0); +} + +static void setup(void) +{ + dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path)); + if (dev_num < 0) + tst_brk(TBROK, "Failed to find free loop device"); + + tst_fill_file("test.img", 0, 1024 * 1024, 1); + tst_attach_device(dev_path, "test.img"); + attach_flag = 1; + + sprintf(sys_loop_sizepath, "/sys/block/loop%d/size", dev_num); + sprintf(sys_loop_sizelimitpath, "/sys/block/loop%d/loop/sizelimit", dev_num); + + dev_fd = SAFE_OPEN(dev_path, O_RDWR); + tst_res(TINFO, "original loop size 2048 sectors"); +} + +static void cleanup(void) +{ + if (dev_fd > 0) + SAFE_CLOSE(dev_fd); + if (file_fd > 0) + SAFE_CLOSE(file_fd); + if (attach_flag) + tst_detach_device(dev_path); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = verify_ioctl_loop, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_tmpdir = 1, + .needs_drivers = (const char *const []) { + "loop", + NULL + } +};