* [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-18 10:31 [PATCH 0/2] blktests: New loop tests Jan Kara
@ 2018-10-18 10:31 ` Jan Kara
2018-10-18 14:18 ` Johannes Thumshirn
2018-10-22 22:52 ` Omar Sandoval
2018-10-18 10:31 ` [PATCH 2/2] loop/007: Add test for oops during backing file verification Jan Kara
2018-10-25 21:18 ` [PATCH 0/2] blktests: New loop tests Omar Sandoval
2 siblings, 2 replies; 11+ messages in thread
From: Jan Kara @ 2018-10-18 10:31 UTC (permalink / raw)
To: Omar Sandoval; +Cc: linux-block, Johannes Thumshirn, Jan Kara
Add test for setting partscan flag.
Signed-off-by: Jan Kara <jack@suse.cz>
---
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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <linux/loop.h>
+
+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
--
2.16.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-18 10:31 ` [PATCH 1/2] loop/006: Add test for setting partscan flag Jan Kara
@ 2018-10-18 14:18 ` Johannes Thumshirn
2018-10-22 22:52 ` Omar Sandoval
1 sibling, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2018-10-18 14:18 UTC (permalink / raw)
To: Jan Kara, Omar Sandoval; +Cc: linux-block
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn SUSE Labs
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-18 10:31 ` [PATCH 1/2] loop/006: Add test for setting partscan flag Jan Kara
2018-10-18 14:18 ` Johannes Thumshirn
@ 2018-10-22 22:52 ` Omar Sandoval
2018-10-23 10:05 ` Jan Kara
1 sibling, 1 reply; 11+ messages in thread
From: Omar Sandoval @ 2018-10-22 22:52 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-block, Johannes Thumshirn
On Thu, Oct 18, 2018 at 12:31:46PM +0200, Jan Kara wrote:
> Add test for setting partscan flag.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
Sorry I didn't notice this earlier, but loop/001 already does a
partition rescan (via losetup -P). Does that cover this test case?
> ---
> 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 <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/ioctl.h>
> +#include <sys/stat.h>
> +#include <sys/types.h>
> +#include <linux/loop.h>
> +
> +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);
What's the significance of this file name?
> + ret = ioctl(fd, LOOP_SET_STATUS64, &info);
> + if (ret == -1) {
> + perror("ioctl");
> + close(fd);
> + return EXIT_FAILURE;
> + }
> + close(fd);
> + return EXIT_SUCCESS;
> +}
[snip]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-22 22:52 ` Omar Sandoval
@ 2018-10-23 10:05 ` Jan Kara
2018-10-23 18:57 ` Omar Sandoval
0 siblings, 1 reply; 11+ messages in thread
From: Jan Kara @ 2018-10-23 10:05 UTC (permalink / raw)
To: Omar Sandoval; +Cc: Jan Kara, linux-block, Johannes Thumshirn
On Mon 22-10-18 15:52:55, Omar Sandoval wrote:
> On Thu, Oct 18, 2018 at 12:31:46PM +0200, Jan Kara wrote:
> > Add test for setting partscan flag.
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
>
> Sorry I didn't notice this earlier, but loop/001 already does a
> partition rescan (via losetup -P). Does that cover this test case?
Yes I know. But the partition rescanning on device creation has been
handled properly while partition rescanning as a result of LOOP_SET_STATUS
was buggy. That's why I've added this test.
> > +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);
>
> What's the significance of this file name?
Probably none, I guess I can just delete it. I think I've just copy-pasted
it from some other test excercising LOOP_SET_STATUS...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-23 10:05 ` Jan Kara
@ 2018-10-23 18:57 ` Omar Sandoval
2018-10-24 13:14 ` Jan Kara
0 siblings, 1 reply; 11+ messages in thread
From: Omar Sandoval @ 2018-10-23 18:57 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-block, Johannes Thumshirn
On Tue, Oct 23, 2018 at 12:05:12PM +0200, Jan Kara wrote:
> On Mon 22-10-18 15:52:55, Omar Sandoval wrote:
> > On Thu, Oct 18, 2018 at 12:31:46PM +0200, Jan Kara wrote:
> > > Add test for setting partscan flag.
> > >
> > > Signed-off-by: Jan Kara <jack@suse.cz>
> >
> > Sorry I didn't notice this earlier, but loop/001 already does a
> > partition rescan (via losetup -P). Does that cover this test case?
>
> Yes I know. But the partition rescanning on device creation has been
> handled properly while partition rescanning as a result of LOOP_SET_STATUS
> was buggy. That's why I've added this test.
At least here, losetup -P does a LOOP_SET_STATUS:
$ sudo strace -e ioctl losetup -f --show -P test.img
ioctl(3, LOOP_CTL_GET_FREE) = 0
ioctl(4, LOOP_SET_FD, 3) = 0
ioctl(4, LOOP_SET_STATUS64, {lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_PARTSCAN, lo_file_name="/home/osandov/test.img", ...}) = 0
/dev/loop0
+++ exited with 0 +++
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] loop/006: Add test for setting partscan flag
2018-10-23 18:57 ` Omar Sandoval
@ 2018-10-24 13:14 ` Jan Kara
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kara @ 2018-10-24 13:14 UTC (permalink / raw)
To: Omar Sandoval; +Cc: Jan Kara, linux-block, Johannes Thumshirn
On Tue 23-10-18 11:57:50, Omar Sandoval wrote:
> On Tue, Oct 23, 2018 at 12:05:12PM +0200, Jan Kara wrote:
> > On Mon 22-10-18 15:52:55, Omar Sandoval wrote:
> > > On Thu, Oct 18, 2018 at 12:31:46PM +0200, Jan Kara wrote:
> > > > Add test for setting partscan flag.
> > > >
> > > > Signed-off-by: Jan Kara <jack@suse.cz>
> > >
> > > Sorry I didn't notice this earlier, but loop/001 already does a
> > > partition rescan (via losetup -P). Does that cover this test case?
> >
> > Yes I know. But the partition rescanning on device creation has been
> > handled properly while partition rescanning as a result of LOOP_SET_STATUS
> > was buggy. That's why I've added this test.
>
> At least here, losetup -P does a LOOP_SET_STATUS:
>
> $ sudo strace -e ioctl losetup -f --show -P test.img
> ioctl(3, LOOP_CTL_GET_FREE) = 0
> ioctl(4, LOOP_SET_FD, 3) = 0
> ioctl(4, LOOP_SET_STATUS64, {lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_PARTSCAN, lo_file_name="/home/osandov/test.img", ...}) = 0
> /dev/loop0
> +++ exited with 0 +++
Right, my bad. Just discard this test then. Thanks for noticing this!
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/2] loop/007: Add test for oops during backing file verification
2018-10-18 10:31 [PATCH 0/2] blktests: New loop tests Jan Kara
2018-10-18 10:31 ` [PATCH 1/2] loop/006: Add test for setting partscan flag Jan Kara
@ 2018-10-18 10:31 ` Jan Kara
2018-10-18 14:19 ` Johannes Thumshirn
2018-10-22 22:55 ` Omar Sandoval
2018-10-25 21:18 ` [PATCH 0/2] blktests: New loop tests Omar Sandoval
2 siblings, 2 replies; 11+ messages in thread
From: Jan Kara @ 2018-10-18 10:31 UTC (permalink / raw)
To: Omar Sandoval; +Cc: linux-block, Johannes Thumshirn, Jan Kara
Add regression test for patch "block/loop: Use global lock for ioctl()
operation." where we can oops while traversing list of loop devices
backing newly created device.
Signed-off-by: Jan Kara <jack@suse.cz>
---
src/Makefile | 3 ++-
src/loop_change_fd.c | 48 +++++++++++++++++++++++++++++++++
tests/loop/007 | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/loop/007.out | 2 ++
4 files changed, 127 insertions(+), 1 deletion(-)
create mode 100644 src/loop_change_fd.c
create mode 100755 tests/loop/007
create mode 100644 tests/loop/007.out
diff --git a/src/Makefile b/src/Makefile
index 6dadcbec8beb..acd169718b7d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -5,7 +5,8 @@ C_TARGETS := \
sg/dxfer-from-dev \
sg/syzkaller1 \
nbdsetsize \
- loop_set_status_partscan
+ loop_set_status_partscan \
+ loop_change_fd
CXX_TARGETS := \
discontiguous-io
diff --git a/src/loop_change_fd.c b/src/loop_change_fd.c
new file mode 100644
index 000000000000..b124d829f380
--- /dev/null
+++ b/src/loop_change_fd.c
@@ -0,0 +1,48 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <linux/loop.h>
+
+void usage(const char *progname)
+{
+ fprintf(stderr, "usage: %s LOOPDEV PATH\n", progname);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ int fd, filefd;
+
+ if (argc != 3)
+ usage(argv[0]);
+
+ fd = open(argv[1], O_RDWR);
+ if (fd == -1) {
+ perror("open");
+ return EXIT_FAILURE;
+ }
+
+ filefd = open(argv[2], O_RDWR);
+ if (filefd == -1) {
+ perror("open");
+ return EXIT_FAILURE;
+ }
+
+ ret = ioctl(fd, LOOP_CHANGE_FD, filefd);
+ if (ret == -1) {
+ perror("ioctl");
+ close(fd);
+ close(filefd);
+ return EXIT_FAILURE;
+ }
+ close(fd);
+ close(filefd);
+ return EXIT_SUCCESS;
+}
diff --git a/tests/loop/007 b/tests/loop/007
new file mode 100755
index 000000000000..98e4edbe7afa
--- /dev/null
+++ b/tests/loop/007
@@ -0,0 +1,75 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2018 Jan Kara
+#
+# Regression test for patch "block/loop: Use global lock for ioctl() operation."
+# We swap file (through LOOP_CHANGE_FD) under one loopback device while
+# creating and deleting another loopback device pointing to the first one.
+# This checks for races in validation of backing fd.
+
+. tests/loop/rc
+
+DESCRIPTION="check for crash when validating new loop file"
+
+# Try for some time to trigger the race
+TIMED=1
+
+requires() {
+ _have_src_program loop_change_fd
+}
+
+# Setup and tear down loop device pointing to loop_dev
+run_setter() {
+ loop_dev="$1"
+
+ while top_dev=$(losetup -f --show "$loop_dev"); do
+ losetup -d "$top_dev"
+ done
+}
+
+# Switch backing file of loop_dev continuously
+run_switcher() {
+ loop_dev="$1"
+
+ i=1
+ while src/loop_change_fd "$loop_dev" "$TMPDIR/file$i"; do
+ i=$(((i+1)%2))
+ done
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ timeout=${TIMEOUT:-30}
+
+ truncate -s 1M "$TMPDIR/file0"
+ truncate -s 1M "$TMPDIR/file1"
+
+ if ! loop_dev="$(losetup -r -f --show "$TMPDIR/file0")"; then
+ return 1
+ fi
+
+ run_switcher "$loop_dev" &
+ switch_pid=$!
+ run_setter "$loop_dev" &
+ set_pid=$!
+
+ sleep $timeout
+
+ # Discard KILLED messages from bash...
+ {
+ kill -9 $switch_pid
+ kill -9 $set_pid
+ wait
+ sleep 1
+ } 2>/dev/null
+
+ # Clean up devices
+ top_dev=$(losetup -j "$loop_dev" | sed -e 's/\([^:]*\): .*/\1/')
+ if [[ -n "$top_dev" ]]; then
+ losetup -d "$top_dev"
+ fi
+ losetup -d "$loop_dev"
+
+ echo "Test complete"
+}
diff --git a/tests/loop/007.out b/tests/loop/007.out
new file mode 100644
index 000000000000..32752934d48a
--- /dev/null
+++ b/tests/loop/007.out
@@ -0,0 +1,2 @@
+Running loop/007
+Test complete
--
2.16.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] loop/007: Add test for oops during backing file verification
2018-10-18 10:31 ` [PATCH 2/2] loop/007: Add test for oops during backing file verification Jan Kara
@ 2018-10-18 14:19 ` Johannes Thumshirn
2018-10-22 22:55 ` Omar Sandoval
1 sibling, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2018-10-18 14:19 UTC (permalink / raw)
To: Jan Kara, Omar Sandoval; +Cc: linux-block
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn SUSE Labs
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] loop/007: Add test for oops during backing file verification
2018-10-18 10:31 ` [PATCH 2/2] loop/007: Add test for oops during backing file verification Jan Kara
2018-10-18 14:19 ` Johannes Thumshirn
@ 2018-10-22 22:55 ` Omar Sandoval
1 sibling, 0 replies; 11+ messages in thread
From: Omar Sandoval @ 2018-10-22 22:55 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-block, Johannes Thumshirn
On Thu, Oct 18, 2018 at 12:31:47PM +0200, Jan Kara wrote:
> Add regression test for patch "block/loop: Use global lock for ioctl()
> operation." where we can oops while traversing list of loop devices
> backing newly created device.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
Looks good, sans a missing addition to src/.gitignore. I can fix that
and apply this once I hear back regarding the other test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] blktests: New loop tests
2018-10-18 10:31 [PATCH 0/2] blktests: New loop tests Jan Kara
2018-10-18 10:31 ` [PATCH 1/2] loop/006: Add test for setting partscan flag Jan Kara
2018-10-18 10:31 ` [PATCH 2/2] loop/007: Add test for oops during backing file verification Jan Kara
@ 2018-10-25 21:18 ` Omar Sandoval
2 siblings, 0 replies; 11+ messages in thread
From: Omar Sandoval @ 2018-10-25 21:18 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-block, Johannes Thumshirn
On Thu, Oct 18, 2018 at 12:31:45PM +0200, Jan Kara wrote:
>
> Hello,
>
> these two patches create two new tests for blktests as regression tests
> for my recently posted loopback device fixes. More details in individual
> patches.
Thanks, Jan, I applied 007 renamed to 006.
^ permalink raw reply [flat|nested] 11+ messages in thread