/loblksize
/loop_get_status_null
/openclose
+/nbdsetsize
/sg/dxfer-from-dev
/sg/syzkaller1
loop_get_status_null \
openclose \
sg/dxfer-from-dev \
- sg/syzkaller1
+ sg/syzkaller1 \
+ nbdsetsize
CFLAGS := -O2
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+#!/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
+}
--- /dev/null
+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
--- /dev/null
+#!/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
+}