From patchwork Thu Oct 18 10:31:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10646979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6C413B73 for ; Thu, 18 Oct 2018 10:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7CAF286A9 for ; Thu, 18 Oct 2018 10:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BE4D286AC; Thu, 18 Oct 2018 10:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D41F286A9 for ; Thu, 18 Oct 2018 10:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727575AbeJRScT (ORCPT ); Thu, 18 Oct 2018 14:32:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:35964 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727523AbeJRScT (ORCPT ); Thu, 18 Oct 2018 14:32:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5465BB0B7; Thu, 18 Oct 2018 10:31:56 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id C3E501E050D; Thu, 18 Oct 2018 12:31:55 +0200 (CEST) From: Jan Kara To: Omar Sandoval Cc: , Johannes Thumshirn , Jan Kara Subject: [PATCH 1/2] loop/006: Add test for setting partscan flag Date: Thu, 18 Oct 2018 12:31:46 +0200 Message-Id: <20181018103147.3567-2-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181018103147.3567-1-jack@suse.cz> References: <20181018103147.3567-1-jack@suse.cz> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add test for setting partscan flag. Signed-off-by: Jan Kara Reviewed-by: Johannes Thumshirn --- src/Makefile | 3 ++- src/loop_set_status_partscan.c | 45 ++++++++++++++++++++++++++++++++++++++++++ tests/loop/006 | 33 +++++++++++++++++++++++++++++++ tests/loop/006.out | 2 ++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/loop_set_status_partscan.c create mode 100755 tests/loop/006 create mode 100644 tests/loop/006.out diff --git a/src/Makefile b/src/Makefile index f89f61701179..6dadcbec8beb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,8 @@ C_TARGETS := \ openclose \ sg/dxfer-from-dev \ sg/syzkaller1 \ - nbdsetsize + nbdsetsize \ + loop_set_status_partscan CXX_TARGETS := \ discontiguous-io diff --git a/src/loop_set_status_partscan.c b/src/loop_set_status_partscan.c new file mode 100644 index 000000000000..8873a12e4334 --- /dev/null +++ b/src/loop_set_status_partscan.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(const char *progname) +{ + fprintf(stderr, "usage: %s PATH\n", progname); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + int ret; + int fd; + struct loop_info64 info; + + if (argc != 2) + usage(argv[0]); + + fd = open(argv[1], O_RDONLY); + if (fd == -1) { + perror("open"); + return EXIT_FAILURE; + } + + memset(&info, 0, sizeof(info)); + info.lo_flags = LO_FLAGS_PARTSCAN; + memcpy(info.lo_file_name, "part", 5); + + ret = ioctl(fd, LOOP_SET_STATUS64, &info); + if (ret == -1) { + perror("ioctl"); + close(fd); + return EXIT_FAILURE; + } + close(fd); + return EXIT_SUCCESS; +} diff --git a/tests/loop/006 b/tests/loop/006 new file mode 100755 index 000000000000..e468d3a20210 --- /dev/null +++ b/tests/loop/006 @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2018 Jan Kara +# +# Regression test for patch "loop: Fix deadlock when calling +# blkdev_reread_part()". We check whether setting partscan flag +# and thus forcing partition reread won't trigger lockdep warning. +# + +. tests/loop/rc + +DESCRIPTION="check for partition rereading deadlock" + +QUICK=1 + +requires() { + _have_src_program loop_set_status_partscan +} + +test() { + local loop_dev + echo "Running ${TEST_NAME}" + + truncate -s 1M "$TMPDIR/file" + if ! loop_dev="$(losetup -f --show "$TMPDIR/file")"; then + return 1 + fi + + src/loop_set_status_partscan "$loop_dev" + losetup -d "$loop_dev" + + echo "Test complete" +} diff --git a/tests/loop/006.out b/tests/loop/006.out new file mode 100644 index 000000000000..50bf833f77b0 --- /dev/null +++ b/tests/loop/006.out @@ -0,0 +1,2 @@ +Running loop/006 +Test complete