]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
nbd/002: add a partition table test
authorJosef Bacik <jbacik@fb.com>
Wed, 16 May 2018 16:04:50 +0000 (12:04 -0400)
committerOmar Sandoval <osandov@fb.com>
Mon, 11 Jun 2018 20:18:38 +0000 (13:18 -0700)
Partition tables are hard, add a test to make sure we create/delete them
properly.

Signed-off-by: Josef Bacik <jbacik@fb.com>
[Omar: clean up helpers, use udevadm settle instead of stat, etc.]
Signed-off-by: Omar Sandoval <osandov@fb.com>
common/nbd
tests/nbd/002 [new file with mode: 0644]
tests/nbd/002.out [new file with mode: 0644]

index e3e173909db4b85eae8467934508047763549b10..320f456e0bd8599a3d9996b959b82d2192ec524e 100644 (file)
@@ -48,6 +48,26 @@ _have_nbd_netlink() {
        return 0
 }
 
+_wait_for_nbd_connect() {
+       for ((i = 0; i < 3; i++)); do
+               if [[ -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+                       return 0
+               fi
+               sleep 1
+       done
+       return 1
+}
+
+_wait_for_nbd_disconnect() {
+       for ((i = 0; i < 3; i++)); do
+               if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+                       return 0
+               fi
+               sleep 1
+       done
+       return 1
+}
+
 _start_nbd_server() {
        truncate -s 10G "${TMPDIR}/export"
        cat > "${TMPDIR}/nbd.conf" << EOF
diff --git a/tests/nbd/002 b/tests/nbd/002
new file mode 100644 (file)
index 0000000..b1a4b3c
--- /dev/null
@@ -0,0 +1,133 @@
+#!/bin/bash
+#
+# Test nbd device resizing. Regression test for the following commits:
+#
+# 8364da4751cf ("nbd: fix nbd device deletion")
+# c3f7c9397609 ("nbd: update size when connected")
+# 9e2b19675d13 ("nbd: use bd_set_size when updating disk size")
+# 96d97e17828f ("nbd: clear_sock on netlink disconnect")
+# fe1f9e6659ca ("nbd: fix how we set bd_invalidated")
+# 76aa1d341257 ("nbd: call nbd_bdev_reset instead of bd_set_size on disconnect")
+#
+# Copyright (C) 2018 Josef Bacik
+#
+# 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="tests on partition handling for an nbd device"
+QUICK=1
+
+requires() {
+       _have_nbd_netlink && _have_program parted
+}
+
+test() {
+       echo "Running ${TEST_NAME}"
+       _start_nbd_server
+       nbd-client -N export localhost /dev/nbd0 >> "$FULL" 2>&1
+
+       parted -s /dev/nbd0 mklabel msdos >> "$FULL" 2>&1
+       parted -s /dev/nbd0 mkpart primary 0 100 >> "$FULL" 2>&1
+
+       # We need to wait for udev to do its thing before we disconnect or else
+       # we'll get timed out requests.
+       udevadm settle
+
+       nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+
+       if ! _wait_for_nbd_disconnect; then
+               echo "Disconnect didn't happen?"
+               _stop_nbd_server
+               return 1
+       fi
+
+       udevadm settle
+
+       if stat /dev/nbd0p1 >> "$FULL" 2>&1; then
+               echo "Had partition after disconnect?"
+               _stop_nbd_server
+               return 1
+       fi
+
+       # Do it with ioctls
+
+       echo "Testing IOCTL path"
+
+       nbd-client -N export localhost /dev/nbd0 >> "$FULL" 2>&1
+
+       if ! _wait_for_nbd_connect; then
+               echo "Connect didn't happen?"
+               nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+               _stop_nbd_server
+               return 1
+       fi
+
+       udevadm settle
+
+       if ! stat /dev/nbd0p1 >> "$FULL" 2>&1; then
+               echo "Didn't have partition on ioctl path"
+               nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+               _stop_nbd_server
+               return 1
+       fi
+
+       nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+
+       udevadm settle
+
+       if stat /dev/nbd0p1 >> "$FULL" 2>&1; then
+               echo "Partition still exists after disconnect"
+               _stop_nbd_server
+               return 1
+       fi
+
+       # Do it with netlink
+       echo "Testing the netlink path"
+       nbd-client -L -N export localhost /dev/nbd0 >> "$FULL" 2>&1
+
+       if ! _wait_for_nbd_connect; then
+               echo "Connect didn't happen?"
+               nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+               _stop_nbd_server
+               return 1
+       fi
+
+       udevadm settle
+
+       if  ! stat /dev/nbd0p1 >/dev/null 2>&1; then
+               echo "Didn't have parition on the netlink path"
+               nbd-client -L -d /dev/nbd0 >> "$FULL" 2>&1
+               _stop_nbd_server
+               return 1
+       fi
+
+       nbd-client -L -d /dev/nbd0 >> "$FULL" 2>&1
+
+       if ! _wait_for_nbd_disconnect; then
+               echo "Disconnect didn't happen?"
+               _stop_nbd_server
+               return 1
+       fi
+
+       udevadm settle
+
+       if stat /dev/nbd0p1 >> "$FULL" 2>&1; then
+               echo "Partition still exists after netlink disconnect"
+               _stop_nbd_server
+               return 1
+       fi
+
+       echo "Test complete"
+       _stop_nbd_server
+       return 0
+}
diff --git a/tests/nbd/002.out b/tests/nbd/002.out
new file mode 100644 (file)
index 0000000..f2aec55
--- /dev/null
@@ -0,0 +1,4 @@
+Running nbd/002
+Testing IOCTL path
+Testing the netlink path
+Test complete