From: Josef Bacik Date: Wed, 16 May 2018 16:04:50 +0000 (-0400) Subject: nbd/002: add a partition table test X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=55df118fc4c7ddb610331edf30d9929d32a60e7b;p=users%2Fsagi%2Fblktests.git nbd/002: add a partition table test Partition tables are hard, add a test to make sure we create/delete them properly. Signed-off-by: Josef Bacik [Omar: clean up helpers, use udevadm settle instead of stat, etc.] Signed-off-by: Omar Sandoval --- diff --git a/common/nbd b/common/nbd index e3e1739..320f456 100644 --- a/common/nbd +++ b/common/nbd @@ -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 index 0000000..b1a4b3c --- /dev/null +++ b/tests/nbd/002 @@ -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 . + +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 index 0000000..f2aec55 --- /dev/null +++ b/tests/nbd/002.out @@ -0,0 +1,4 @@ +Running nbd/002 +Testing IOCTL path +Testing the netlink path +Test complete