From: Josef Bacik Date: Fri, 13 Apr 2018 16:05:12 +0000 (-0400) Subject: blktests: add nbd infrastructure X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=55afc701a9f364ee01c288682eb4af7ce87d23d9;p=users%2Fsagi%2Fblktests.git blktests: add nbd infrastructure NBD needs to setup a server and such, so add all the supporting helpers so we can start building tests for nbd. Signed-off-by: Josef Bacik [Omar: fix variable quoting] Signed-off-by: Omar Sandoval --- diff --git a/common/nbd b/common/nbd new file mode 100644 index 0000000..e888435 --- /dev/null +++ b/common/nbd @@ -0,0 +1,48 @@ +#!/bin/bash +# +# NBD helper functions +# +# 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 . + +_have_nbd_netlink_support() { + if ! _have_program genl-ctrl-list; then + return 1 + fi + if ! genl-ctrl-list | grep -q nbd; then + SKIP_REASON="nbd does not support netlink" + return 1 + fi + return 0 +} + +_have_nbd_netlink() { + _have_nbd && _have_nbd_netlink_support +} + +_start_nbd_server() { + truncate -s 10G "${TMPDIR}/export" + cat > "${TMPDIR}/nbd.conf" << EOF +[generic] +[export] +exportname=${TMPDIR}/export +EOF + nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf" +} + +_stop_nbd_server() { + kill -SIGTERM "$(cat "${TMPDIR}/nbd.pid")" + rm -f "${TMPDIR}/export" +} diff --git a/common/rc b/common/rc index 899c182..1bd0374 100644 --- a/common/rc +++ b/common/rc @@ -85,6 +85,11 @@ _have_loop() { _have_module loop && _have_program losetup } +_have_nbd() { + _have_module nbd && _have_program nbd-server && \ + _have_program nbd-client +} + _have_blktrace() { # CONFIG_BLK_DEV_IO_TRACE might still be disabled, but this is easier # to check. We can fix it if someone complains.