]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
loop: add ioctl lock imbalance regression test
authorOmar Sandoval <osandov@fb.com>
Fri, 6 Apr 2018 16:58:43 +0000 (09:58 -0700)
committerOmar Sandoval <osandov@fb.com>
Fri, 6 Apr 2018 16:58:43 +0000 (09:58 -0700)
Signed-off-by: Omar Sandoval <osandov@fb.com>
src/.gitignore
src/Makefile
src/loop_get_status_null.c [new file with mode: 0644]
tests/loop/005 [new file with mode: 0755]
tests/loop/005.out [new file with mode: 0644]

index 3bb6b7f54a7ef6246e5ba71ad3be6704353d574c..bdb2585705999f76d86f847cbef29c13913e2e8e 100644 (file)
@@ -1,4 +1,5 @@
 /loblksize
+/loop_get_status_null
 /openclose
-/sg/syzkaller1
 /sg/dxfer-from-dev
+/sg/syzkaller1
index b94fa719d05f765dbb416a4ad4a493f90de0eb5c..787df37dae21f560953b66fb63e7996c93c5932d 100644 (file)
@@ -1,4 +1,9 @@
-TARGETS := sg/dxfer-from-dev sg/syzkaller1 loblksize openclose
+TARGETS := \
+       loblksize \
+       loop_get_status_null \
+       openclose \
+       sg/dxfer-from-dev \
+       sg/syzkaller1
 
 CFLAGS := -O2
 
diff --git a/src/loop_get_status_null.c b/src/loop_get_status_null.c
new file mode 100644 (file)
index 0000000..c233847
--- /dev/null
@@ -0,0 +1,57 @@
+#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 [64]\n", progname);
+       exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+       unsigned long cmd;
+       int ret;
+       int fd;
+
+       if (argc != 2 && argc != 3)
+               usage(argv[0]);
+
+       if (argc == 3) {
+               if (strcmp(argv[2], "64") == 0)
+                       cmd = LOOP_GET_STATUS64;
+               else
+                       usage(argv[0]);
+       } else {
+               cmd = LOOP_GET_STATUS;
+       }
+
+       fd = open(argv[1], O_RDONLY);
+       if (fd == -1) {
+               perror("open");
+               return EXIT_FAILURE;
+       }
+
+       ret = ioctl(fd, cmd, NULL);
+       if (ret == -1) {
+               if (errno == EINVAL) {
+                       printf("Got EINVAL\n");
+               } else {
+                       perror("ioctl");
+                       close(fd);
+                       return EXIT_FAILURE;
+               }
+       } else {
+               printf("Did not get EINVAL\n");
+       }
+
+       close(fd);
+       return EXIT_SUCCESS;
+}
diff --git a/tests/loop/005 b/tests/loop/005
new file mode 100755 (executable)
index 0000000..41cf5a3
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Test the LOOP_GET_STATUS{,64} error case where the passed argument is NULL.
+# Regression test for patch "loop: fix LOOP_GET_STATUS lock imbalance".
+#
+# Copyright (C) 2018 Omar Sandoval
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
+
+QUICK=1
+
+requires() {
+       _have_src_program loop_get_status_null
+}
+
+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
+
+       "$SRCDIR/loop_get_status_null" "$loop_dev"
+       "$SRCDIR/loop_get_status_null" "$loop_dev" 64
+
+       losetup -d "$loop_dev"
+
+       echo "Test complete"
+}
diff --git a/tests/loop/005.out b/tests/loop/005.out
new file mode 100644 (file)
index 0000000..6354da5
--- /dev/null
@@ -0,0 +1,4 @@
+Running loop/005
+Got EINVAL
+Got EINVAL
+Test complete