]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
blktests: add nbd test for online resize
authorJosef Bacik <jbacik@fb.com>
Fri, 13 Apr 2018 16:07:48 +0000 (12:07 -0400)
committerOmar Sandoval <osandov@fb.com>
Fri, 13 Apr 2018 20:47:11 +0000 (13:47 -0700)
This tests resizing a connected nbd device.  We connect to the existing
10gig device, and resize it online to 1gig, and make sure lsblk and
parted (which use different size determination methods) both report the
correctly updated size.

Signed-off-by: Josef Bacik <jbacik@fb.com>
[Omar: squash commits, add note on required patches]
Signed-off-by: Omar Sandoval <osandov@fb.com>
src/.gitignore
src/Makefile
src/nbdsetsize.c [new file with mode: 0644]
tests/nbd/001 [new file with mode: 0644]
tests/nbd/001.out [new file with mode: 0644]
tests/nbd/group [new file with mode: 0644]

index bdb2585705999f76d86f847cbef29c13913e2e8e..68da6e6fa69ea82218e55aca06eb37462a4f15f4 100644 (file)
@@ -1,5 +1,6 @@
 /loblksize
 /loop_get_status_null
 /openclose
+/nbdsetsize
 /sg/dxfer-from-dev
 /sg/syzkaller1
index 787df37dae21f560953b66fb63e7996c93c5932d..612282d14af8364af6fd3ca2a313c64c3918cc01 100644 (file)
@@ -3,7 +3,8 @@ TARGETS := \
        loop_get_status_null \
        openclose \
        sg/dxfer-from-dev \
-       sg/syzkaller1
+       sg/syzkaller1 \
+       nbdsetsize
 
 CFLAGS := -O2
 
diff --git a/src/nbdsetsize.c b/src/nbdsetsize.c
new file mode 100644 (file)
index 0000000..fe73ed3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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/>.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <linux/nbd.h>
+
+int main(int argc, char **argv)
+{
+       unsigned long long size;
+       char *end;
+       int fd = -1;
+
+       if (argc != 3) {
+               fprintf(stderr, "usage: %s DEV SIZE\n", argv[0]);
+               return 1;
+       }
+
+       errno = 0;
+       size = strtoull(argv[2], &end, 0);
+       if (errno || *end) {
+               fprintf(stderr, "invalid size\n");
+               return 1;
+       }
+
+       fd = open(argv[1], O_RDWR);
+       if (fd == -1) {
+               perror("open");
+               return 1;
+       }
+
+       if (ioctl(fd, NBD_SET_SIZE, size) == -1) {
+               int status = errno == EINVAL ? 2 : 1;
+
+               perror("NBD_SET_SIZE");
+               close(fd);
+               return status;
+       }
+
+       close(fd);
+       return 0;
+}
diff --git a/tests/nbd/001 b/tests/nbd/001
new file mode 100644 (file)
index 0000000..8be760e
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Test nbd device resizing. Regression test for patches "nbd: update size when
+# connected" and "nbd: use bd_set_size when updating disk size".
+#
+# 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/>.
+
+. common/nbd
+
+DESCRIPTION="resize a connected nbd device"
+QUICK=1
+
+requires() {
+       _have_nbd && _have_program parted && _have_src_program nbdsetsize
+}
+
+test() {
+       echo "Running ${TEST_NAME}"
+       _start_nbd_server
+       nbd-client -N export localhost /dev/nbd0 > /dev/null 2>&1
+       parted -s /dev/nbd0 print 2> /dev/null | grep 'Disk /dev/nbd0'
+       lsblk -n /dev/nbd0
+
+       echo "Setting size to 1gib"
+       src/nbdsetsize /dev/nbd0 1073741824
+
+       lsblk -n /dev/nbd0
+       parted -s /dev/nbd0 print 2> /dev/null | grep 'Disk /dev/nbd0'
+
+       nbd-client -d /dev/nbd0 > /dev/null 2>&1
+       _stop_nbd_server
+}
diff --git a/tests/nbd/001.out b/tests/nbd/001.out
new file mode 100644 (file)
index 0000000..2f2aff0
--- /dev/null
@@ -0,0 +1,6 @@
+Running nbd/001
+Disk /dev/nbd0: 10.7GB
+nbd0  43:0    0  10G  0 disk 
+Setting size to 1gib
+nbd0  43:0    0   1G  0 disk 
+Disk /dev/nbd0: 1074MB
diff --git a/tests/nbd/group b/tests/nbd/group
new file mode 100644 (file)
index 0000000..46739a0
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# NBD tests.
+#
+# 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/>.
+
+group_requires() {
+       _have_root && _have_nbd && modprobe nbd
+}