]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
blktests: add nbd infrastructure
authorJosef Bacik <jbacik@fb.com>
Fri, 13 Apr 2018 16:05:12 +0000 (12:05 -0400)
committerOmar Sandoval <osandov@fb.com>
Fri, 13 Apr 2018 20:46:37 +0000 (13:46 -0700)
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 <jbacik@fb.com>
[Omar: fix variable quoting]
Signed-off-by: Omar Sandoval <osandov@fb.com>
common/nbd [new file with mode: 0644]
common/rc

diff --git a/common/nbd b/common/nbd
new file mode 100644 (file)
index 0000000..e888435
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+_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"
+}
index 899c1826a53429853a8c3522bbc4e0c9f710bea3..1bd0374ef84cbb0c714fad15b3d99326d09f9a33 100644 (file)
--- 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.