[PATCH 0/4] common: Add a simple mini-library for handling qemu command and config files.
by Richard W.M. Jones
Currently we have an OCaml library for generating the qemu command
line (used only by ‘virt-v2v -o qemu’). However we also generate a
qemu command line in ‘lib/launch-direct.c’, and we might in future
need to generate a ‘-readconfig’-compatible configuration file if we
want to go beyond 10,000 drives for scalability testing.
Therefore this patch series reimplements the qemu command line code as
a small C library (common/qemuopts), extends it to support qemu config
files, and then reimplements both ‘lib/launch-direct.c’ and ‘virt-v2v
-o qemu’ to use it.
It also fixes a few bugs. In particular we don't properly comma-quote
qemu parameters in multiple places. This fixes all of those places
properly.
It also drops support for ‘./configure --with-qemu-options’ which is
broken (see commit message).
Rich.
7 years, 7 months
[PATCH v6 00/10] Add a virt-builder-repository tool
by Cédric Bosdonnat
Hi all,
Here is an updated version of that patch series.
Diff to v5:
* Apply Pino's comments
* Fix indentation issues
* Add a default value for arch in builder/index_parser.ml if template
is set
* Improved new images filtering: don't process image that didn't
change. This has been uncovered by introduction of --no-compression
Cédric Bosdonnat (10):
lib/osinfo.c: Extract xml processing into a callback
lib: extract osinfo DB traversing API
mllib: ocaml wrapper for lib/osinfo
builder: rename docs test script
builder: add a template parameter to get_index
builder: add Index.write_entry function
dib: move do_cp to mllib.Commun_utils
mllib: add do_mv helper function to Common_utils
mllib: add XPath helper xpath_get_nodes()
Add a virt-builder-repository tool
.gitignore | 4 +
builder/Makefile.am | 124 ++++-
builder/builder.ml | 2 +-
builder/index.mli | 3 +
builder/index_parser.ml | 80 ++-
builder/index_parser.mli | 8 +-
builder/index_parser_tests.ml | 129 +++++
builder/repository_main.ml | 570 +++++++++++++++++++++
.../{test-virt-builder-docs.sh => test-docs.sh} | 2 +
builder/virt-builder-repository.pod | 209 ++++++++
dib/utils.ml | 4 -
lib/Makefile.am | 2 +
lib/osinfo-iso.c | 462 +++++++++++++++++
lib/osinfo.c | 489 ++----------------
lib/osinfo.h | 27 +
mllib/Makefile.am | 11 +-
mllib/common_utils.ml | 11 +
mllib/common_utils.mli | 6 +
mllib/osinfo-c.c | 103 ++++
mllib/osinfo.ml | 26 +
mllib/osinfo.mli | 31 ++
mllib/xpath_helpers.ml | 9 +
mllib/xpath_helpers.mli | 4 +
23 files changed, 1859 insertions(+), 457 deletions(-)
create mode 100644 builder/index_parser_tests.ml
create mode 100644 builder/repository_main.ml
rename builder/{test-virt-builder-docs.sh => test-docs.sh} (93%)
create mode 100644 builder/virt-builder-repository.pod
create mode 100644 lib/osinfo-iso.c
create mode 100644 lib/osinfo.h
create mode 100644 mllib/osinfo-c.c
create mode 100644 mllib/osinfo.ml
create mode 100644 mllib/osinfo.mli
--
2.12.0
7 years, 7 months
[PATCH supermin] init: Support root=UUID=... to specify the appliance disk by volume UUID.
by Richard W.M. Jones
Instead of specifying a device name (eg. root=/dev/sdb), this permits
specifying an ext4 volume UUID (root=UUID=12345678-...). This allows
the appliance to be robust against the non-determinism of SCSI device
enumeration.
---
init/init.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 192 insertions(+), 34 deletions(-)
diff --git a/init/init.c b/init/init.c
index ddfc437..3885cc6 100644
--- a/init/init.c
+++ b/init/init.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
@@ -89,6 +90,11 @@ static void read_cmdline (void);
static void insmod (const char *filename);
static void delete_initramfs_files (void);
static void show_directory (const char *dir);
+static void parse_root_uuid (const char *uuid, unsigned char *raw_uuid);
+static int hexdigit (char d);
+static int find_fs_uuid (const unsigned char *raw_uuid, int *major, int *minor);
+static int parse_dev_file (const char *path, int *major, int *minor);
+static void virtio_warning (uint64_t delay_ns, const char *what);
static char cmdline[1024];
static char line[1024];
@@ -98,13 +104,11 @@ main ()
{
FILE *fp;
size_t n;
- char *root, *path;
+ char *root;
size_t len;
int dax = 0;
uint64_t delay_ns;
- int virtio_message = 0;
int major, minor;
- char *p;
const char *mount_options = "";
#define NANOSLEEP(ns) do { \
@@ -181,46 +185,59 @@ main ()
exit (EXIT_FAILURE);
}
root += 5;
- if (strncmp (root, "/dev/", 5) == 0)
- root += 5;
- if (strncmp (root, "pmem", 4) == 0)
- dax = 1;
- len = strcspn (root, " ");
- root[len] = '\0';
-
- asprintf (&path, "/sys/block/%s/dev", root);
- for (delay_ns = 250000;
- delay_ns <= MAX_ROOT_WAIT * UINT64_C(1000000000);
- delay_ns *= 2) {
- fp = fopen (path, "r");
- if (fp != NULL)
- break;
+ if (strncmp (root, "/dev/", 5) == 0) {
+ char *path;
- if (delay_ns > 1000000000) {
- fprintf (stderr,
- "supermin: waiting another %" PRIu64 " ns for %s to appear\n",
- delay_ns, path);
- if (!virtio_message) {
- fprintf (stderr,
- "This usually means your kernel doesn't support virtio, or supermin was unable\n"
- "to load some kernel modules (see module loading messages above).\n");
- virtio_message = 1;
+ root += 5;
+ if (strncmp (root, "pmem", 4) == 0)
+ dax = 1;
+ len = strcspn (root, " ");
+ root[len] = '\0';
+
+ asprintf (&path, "/sys/block/%s/dev", root);
+
+ for (delay_ns = 250000;
+ delay_ns <= MAX_ROOT_WAIT * UINT64_C(1000000000);
+ delay_ns *= 2) {
+ if (parse_dev_file (path, &major, &minor) != -1) {
+ if (!quiet)
+ fprintf (stderr, "supermin: picked %s (%d:%d) as root device\n",
+ path, major, minor);
+ break;
}
+
+ virtio_warning (delay_ns, path);
+ NANOSLEEP (delay_ns);
}
- NANOSLEEP (delay_ns);
+ free (path);
}
+ else if (strncmp (root, "UUID=", 5) == 0) {
+ unsigned char raw_uuid[16];
- if (!quiet)
- fprintf (stderr, "supermin: picked %s as root device\n", path);
+ root += 5;
+ parse_root_uuid (root, raw_uuid);
+
+ for (delay_ns = 250000;
+ delay_ns <= MAX_ROOT_WAIT * UINT64_C(1000000000);
+ delay_ns *= 2) {
+ if (find_fs_uuid (raw_uuid, &major, &minor) != -1) {
+ if (!quiet)
+ fprintf (stderr, "supermin: picked %d:%d as root device\n",
+ major, minor);
+ break;
+ }
- fgets (line, sizeof line, fp);
- major = atoi (line);
- p = line + strcspn (line, ":") + 1;
- minor = atoi (p);
+ virtio_warning (delay_ns, "root UUID");
+ NANOSLEEP (delay_ns);
+ }
+ }
+ else {
+ fprintf (stderr, "supermin: unknown root= parameter on the command line\n");
+ exit (EXIT_FAILURE);
+ }
- fclose (fp);
if (umount ("/sys") == -1) {
perror ("umount: /sys");
exit (EXIT_FAILURE);
@@ -493,3 +510,144 @@ show_directory (const char *dirname)
closedir (dir);
chdir ("/");
}
+
+static void
+parse_root_uuid (const char *root, unsigned char *raw_uuid)
+{
+ size_t i;
+
+ i = 0;
+ while (i < 16) {
+ if (*root == '-') {
+ ++root;
+ continue;
+ }
+ if (!isxdigit (root[0]) || !isxdigit (root[1])) {
+ fprintf (stderr, "supermin: root UUID is not a 16 byte UUID string\n");
+ exit (EXIT_FAILURE);
+ }
+ raw_uuid[i++] = hexdigit (root[0]) * 0x10 + hexdigit (root[1]);
+ root += 2;
+ }
+
+ if (i < 16) {
+ fprintf (stderr, "supermin: root UUID should be 16 bytes\n");
+ exit (EXIT_FAILURE);
+ }
+}
+
+static int
+hexdigit (char d)
+{
+ switch (d) {
+ case '0'...'9': return d - '0';
+ case 'a'...'f': return d - 'a' + 10;
+ case 'A'...'F': return d - 'A' + 10;
+ default: return -1;
+ }
+}
+
+/* Search every block device under /sys/block to see if we can find
+ * one which contains a filesystem with the matching volume UUID.
+ */
+static int
+find_fs_uuid (const unsigned char *raw_uuid, int *major, int *minor)
+{
+ DIR *dir;
+ struct dirent *d;
+ unsigned char uuid[16];
+
+ dir = opendir ("/sys/block");
+ if (!dir) {
+ perror ("/sys/block");
+ return -1;
+ }
+
+ while ((d = readdir (dir)) != NULL) {
+ int fd = -1;
+ char *path = NULL;
+
+ if (d->d_name[0] == '.')
+ goto cont;
+
+ asprintf (&path, "/sys/block/%s/dev", d->d_name);
+
+ if (parse_dev_file (path, major, minor) == -1)
+ goto cont;
+
+ /* We have to make a dummy inode so we can open the device. */
+ unlink ("/dev/disk");
+ if (mknod ("/dev/disk", S_IFBLK|0700, makedev (*major, *minor)) == -1) {
+ perror ("mknod");
+ goto cont;
+ }
+
+ fd = open ("/dev/disk", O_RDONLY);
+ if (fd == -1) {
+ perror ("open");
+ goto cont;
+ }
+
+ if (pread (fd, uuid, sizeof uuid, 0x468) != sizeof uuid) {
+ /*perror ("pread"); - not an error, the device might just be small */
+ goto cont;
+ }
+
+ if (memcmp (uuid, raw_uuid, sizeof uuid) != 0)
+ goto cont;
+
+ close (fd);
+ free (path);
+ closedir (dir);
+ unlink ("/dev/disk");
+ return 0;
+
+ cont:
+ if (fd >= 0) close (fd);
+ free (path);
+ }
+
+ closedir (dir);
+
+ return -1;
+}
+
+/* Parse a /sys/block/X/dev file and extract the major:minor numbers. */
+static int
+parse_dev_file (const char *path, int *major, int *minor)
+{
+ FILE *fp;
+ char *p;
+
+ fp = fopen (path, "r");
+ if (fp == NULL)
+ return -1;
+
+ fgets (line, sizeof line, fp);
+ *major = atoi (line);
+ p = line + strcspn (line, ":") + 1;
+ *minor = atoi (p);
+
+ fclose (fp);
+
+ return 0;
+}
+
+static void
+virtio_warning (uint64_t delay_ns, const char *what)
+{
+ static int virtio_message = 0;
+
+ if (delay_ns > 1000000000) {
+ fprintf (stderr,
+ "supermin: waiting another %" PRIu64 " ns for %s to appear\n",
+ delay_ns, what);
+
+ if (!virtio_message) {
+ fprintf (stderr,
+ "This usually means your kernel doesn't support virtio, or supermin was unable\n"
+ "to load some kernel modules (see module loading messages above).\n");
+ virtio_message = 1;
+ }
+ }
+}
--
2.12.0
7 years, 7 months
[PATCH] daemon: Use CLEANUP_* functions to avoid an explicit free in stub functions.
by Richard W.M. Jones
---
generator/daemon.ml | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/generator/daemon.ml b/generator/daemon.ml
index b00627063..9d5ba00b2 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -155,13 +155,13 @@ let generate_daemon_stubs actions () =
| RBool _ -> pr " int r;\n"
| RConstString _ | RConstOptString _ ->
failwithf "RConstString|RConstOptString cannot be used by daemon functions"
- | RString _ -> pr " char *r;\n"
- | RStringList _ | RHashtable _ -> pr " char **r;\n"
- | RStruct (_, typ) -> pr " guestfs_int_%s *r;\n" typ
- | RStructList (_, typ) -> pr " guestfs_int_%s_list *r;\n" typ
+ | RString _ -> pr " CLEANUP_FREE char *r = NULL;\n"
+ | RStringList _ | RHashtable _ -> pr " CLEANUP_FREE_STRING_LIST char **r = NULL;\n"
+ | RStruct (_, typ) -> pr " CLEANUP_FREE guestfs_int_%s *r = NULL;\n" typ
+ | RStructList (_, typ) -> pr " CLEANUP_FREE guestfs_int_%s_list *r = NULL;\n" typ
| RBufferOut _ ->
pr " size_t size = 1;\n";
- pr " char *r;\n"
+ pr " CLEANUP_FREE char *r = NULL;\n"
);
if args_passed_to_daemon <> [] then (
@@ -384,19 +384,16 @@ let generate_daemon_stubs actions () =
pr " struct guestfs_%s_ret ret;\n" name;
pr " ret.%s = r;\n" n;
pr " reply ((xdrproc_t) &xdr_guestfs_%s_ret, (char *) &ret);\n"
- name;
- pr " free (r);\n"
+ name
| RStringList n | RHashtable n ->
pr " struct guestfs_%s_ret ret;\n" name;
pr " ret.%s.%s_len = count_strings (r);\n" n n;
pr " ret.%s.%s_val = r;\n" n n;
pr " reply ((xdrproc_t) &xdr_guestfs_%s_ret, (char *) &ret);\n"
- name;
- pr " free_strings (r);\n"
+ name
| RStruct (n, _) ->
pr " struct guestfs_%s_ret ret;\n" name;
pr " ret.%s = *r;\n" n;
- pr " free (r);\n";
pr " reply ((xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret);\n"
name;
pr " xdr_free ((xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret);\n"
@@ -404,7 +401,6 @@ let generate_daemon_stubs actions () =
| RStructList (n, _) ->
pr " struct guestfs_%s_ret ret;\n" name;
pr " ret.%s = *r;\n" n;
- pr " free (r);\n";
pr " reply ((xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret);\n"
name;
pr " xdr_free ((xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret);\n"
@@ -414,8 +410,7 @@ let generate_daemon_stubs actions () =
pr " ret.%s.%s_val = r;\n" n n;
pr " ret.%s.%s_len = size;\n" n n;
pr " reply ((xdrproc_t) &xdr_guestfs_%s_ret, (char *) &ret);\n"
- name;
- pr " free (r);\n"
+ name
);
pr "}\n\n";
) (actions |> daemon_functions |> sort)
--
2.12.0
7 years, 7 months
[PATCH v8 0/8] Feature: Yara file scanning
by Matteo Cafasso
v8:
- Ignore returned value in daemon/upload.c
- Report serialization errors in lib/yara.c
Matteo Cafasso (8):
daemon: ignore unused return value in upload function
daemon: expose file upload logic
appliance: add yara dependency
New API: yara_load
New API: yara_destroy
New API: internal_yara_scan
New API: yara_scan
yara_scan: added API tests
appliance/packagelist.in | 4 +
configure.ac | 1 +
daemon/Makefile.am | 4 +-
daemon/cleanups.c | 9 +
daemon/cleanups.h | 2 +
daemon/daemon.h | 3 +
daemon/upload.c | 72 ++++---
daemon/yara.c | 313 +++++++++++++++++++++++++++++++
docs/guestfs-building.pod | 4 +
generator/Makefile.am | 3 +
generator/actions.ml | 6 +-
generator/actions_yara.ml | 92 +++++++++
generator/actions_yara.mli | 22 +++
generator/proc_nr.ml | 3 +
generator/structs.ml | 9 +
gobject/Makefile.inc | 2 +
java/Makefile.inc | 1 +
java/com/redhat/et/libguestfs/.gitignore | 1 +
lib/MAX_PROC_NR | 2 +-
lib/Makefile.am | 1 +
lib/yara.c | 132 +++++++++++++
m4/guestfs_daemon.m4 | 14 ++
tests/yara/Makefile.am | 26 +++
tests/yara/test-yara-scan.sh | 61 ++++++
24 files changed, 752 insertions(+), 35 deletions(-)
create mode 100644 daemon/yara.c
create mode 100644 generator/actions_yara.ml
create mode 100644 generator/actions_yara.mli
create mode 100644 lib/yara.c
create mode 100644 tests/yara/Makefile.am
create mode 100755 tests/yara/test-yara-scan.sh
--
2.11.0
7 years, 7 months
[PATCH v7 0/7] Feature: Yara file scanning
by Matteo Cafasso
v7:
- Fixes according to comments
- Rebase on top of 1.37.12
Matteo Cafasso (7):
daemon: expose file upload logic
appliance: add yara dependency
New API: yara_load
New API: yara_destroy
New API: internal_yara_scan
New API: yara_scan
yara_scan: added API tests
appliance/packagelist.in | 4 +
configure.ac | 1 +
daemon/Makefile.am | 4 +-
daemon/cleanups.c | 9 +
daemon/cleanups.h | 2 +
daemon/daemon.h | 3 +
daemon/upload.c | 66 ++++---
daemon/yara.c | 313 +++++++++++++++++++++++++++++++
docs/guestfs-building.pod | 4 +
generator/Makefile.am | 3 +
generator/actions.ml | 6 +-
generator/actions_yara.ml | 92 +++++++++
generator/actions_yara.mli | 22 +++
generator/proc_nr.ml | 3 +
generator/structs.ml | 9 +
gobject/Makefile.inc | 2 +
java/Makefile.inc | 1 +
java/com/redhat/et/libguestfs/.gitignore | 1 +
lib/MAX_PROC_NR | 2 +-
lib/Makefile.am | 1 +
lib/yara.c | 130 +++++++++++++
m4/guestfs_daemon.m4 | 14 ++
tests/yara/Makefile.am | 26 +++
tests/yara/test-yara-scan.sh | 61 ++++++
24 files changed, 746 insertions(+), 33 deletions(-)
create mode 100644 daemon/yara.c
create mode 100644 generator/actions_yara.ml
create mode 100644 generator/actions_yara.mli
create mode 100644 lib/yara.c
create mode 100644 tests/yara/Makefile.am
create mode 100755 tests/yara/test-yara-scan.sh
--
2.11.0
7 years, 7 months
[PATCH] tests: Replace test-max-disks with several tests.
by Richard W.M. Jones
Replace the monolithic 'test-max-disks.pl' script with a test program
written in C. The program is completely equivalent to the old script,
except for the enhancement that it is able to detect if disks are
added to the appliance in the wrong order.
The tests themselves are split out into some shell scripts:
- test-27-disks: Fully tests 27 disks.
This is the minimum supported configuration for all backends.
- test-255-disks: Fully tests 255 disks.
This is the most disks that libguestfs up to 1.36 supported.
- test-add-lots-of-disks: Add ‘a lot’ of disks and exit (without
any further testing). This is meant to try to exercise > 255
disk case but without being as slow as a test of the max number
of disks (which takes ages, even for as few as 4000 disks).
- test-max-disks: Test the maximum possible number of disks.
The maximum depends on several factors, notably which backend
is in use, and the limit on the number of open files.
‘test-max-disks’ is a slow test.
---
.gitignore | 1 +
tests/disks/Makefile.am | 37 ++-
tests/disks/test-255-disks.sh | 25 ++
tests/disks/test-27-disks.sh | 26 ++
tests/disks/test-add-disks.c | 510 ++++++++++++++++++++++++++++++++++
tests/disks/test-add-lots-of-disks.sh | 25 ++
tests/disks/test-max-disks.pl | 149 ----------
tests/disks/test-max-disks.sh | 24 ++
8 files changed, 645 insertions(+), 152 deletions(-)
create mode 100755 tests/disks/test-255-disks.sh
create mode 100755 tests/disks/test-27-disks.sh
create mode 100644 tests/disks/test-add-disks.c
create mode 100755 tests/disks/test-add-lots-of-disks.sh
delete mode 100755 tests/disks/test-max-disks.pl
create mode 100755 tests/disks/test-max-disks.sh
diff --git a/.gitignore b/.gitignore
index 3b50afdcd..152a40051 100644
--- a/.gitignore
+++ b/.gitignore
@@ -560,6 +560,7 @@ Makefile.in
/tests/c-api/test-user-cancel
/tests/charsets/test-charset-fidelity
/tests/daemon/captive-daemon.pm
+/tests/disks/test-add-disks
/tests/disks/test-qemu-drive-libvirt.xml
/tests/events/test-libvirt-auth-callbacks
/tests/mount-local/test-parallel-mount-local
diff --git a/tests/disks/Makefile.am b/tests/disks/Makefile.am
index 8cc5bdcb0..779871aff 100644
--- a/tests/disks/Makefile.am
+++ b/tests/disks/Makefile.am
@@ -17,17 +17,48 @@
include $(top_srcdir)/subdir-rules.mk
+TESTS_ENVIRONMENT = \
+ $(top_builddir)/run --test
+
TESTS = \
- test-max-disks.pl \
test-qemu-drive.sh
if HAVE_LIBVIRT
TESTS += \
test-qemu-drive-libvirt.sh
+
+if ENABLE_APPLIANCE
+TESTS += \
+ test-27-disks.sh \
+ test-255-disks.sh \
+ test-add-lots-of-disks.sh
+endif
endif
-TESTS_ENVIRONMENT = \
- $(top_builddir)/run --test
+SLOW_TESTS = \
+ test-max-disks.sh
+
+TESTS += \
+ $(SLOW_TESTS)
+
+check-slow:
+ $(MAKE) check TESTS="$(SLOW_TESTS)" SLOW=1
+
+check_PROGRAMS = test-add-disks
+
+test_add_disks_SOURCES = \
+ test-add-disks.c
+test_add_disks_CPPFLAGS = \
+ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+ -I$(top_srcdir)/lib -I$(top_builddir)/lib \
+ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib
+test_add_disks_CFLAGS = \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS)
+test_add_disks_LDADD = \
+ $(top_builddir)/common/utils/libutils.la \
+ $(top_builddir)/lib/libguestfs.la \
+ $(top_builddir)/gnulib/lib/libgnu.la \
+ $(LIBXML2_LIBS)
EXTRA_DIST = \
debug-qemu.sh \
diff --git a/tests/disks/test-255-disks.sh b/tests/disks/test-255-disks.sh
new file mode 100755
index 000000000..3c75dab19
--- /dev/null
+++ b/tests/disks/test-255-disks.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Copyright (C) 2012-2017 Red Hat Inc.
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+
+skip_unless_backend libvirt
+
+./test-add-disks -n 255
diff --git a/tests/disks/test-27-disks.sh b/tests/disks/test-27-disks.sh
new file mode 100755
index 000000000..c2cf7b223
--- /dev/null
+++ b/tests/disks/test-27-disks.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# Copyright (C) 2012-2017 Red Hat Inc.
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# The significance of 27 is that it's the minimum number of disks
+# supported by every known backend in every supported configuration.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+
+./test-add-disks -n 27
diff --git a/tests/disks/test-add-disks.c b/tests/disks/test-add-disks.c
new file mode 100644
index 000000000..b968bd352
--- /dev/null
+++ b/tests/disks/test-add-disks.c
@@ -0,0 +1,510 @@
+/* Test libguestfs with large/maximum number of disks.
+ * Copyright (C) 2012-2017 Red Hat Inc.
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <getopt.h>
+#include <errno.h>
+#include <error.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <assert.h>
+
+#include <guestfs.h>
+#include "guestfs-internal-frontend.h"
+
+#include "getprogname.h"
+
+static ssize_t get_max_disks (guestfs_h *g);
+static void do_test (guestfs_h *g, size_t ndisks, bool just_add);
+static void make_disks (const char *tmpdir);
+static void rm_disks (void);
+
+static size_t ndisks;
+static char **disks;
+
+static void __attribute__((noreturn))
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ fprintf (stderr, "Try ‘%s --help’ for more information.\n",
+ getprogname ());
+ else {
+ printf ("Test libguestfs with large/maximum number of disks.\n"
+ "\n"
+ "Usage:\n"
+ " %s -n NR_DISKS\n"
+ " Do a full test with NR_DISKS.\n"
+ " %s --max\n"
+ " Do a full test with the max number of disks *.\n"
+ " %s --just-add [-n N | --max]\n"
+ " Don't do a full test, only add the disks and exit.\n"
+ "\n"
+ "Options:\n"
+ " --help Display this help and exit.\n"
+ " --just-add Only add the disks and exit if successful.\n"
+ " --max Test max disks possible *.\n"
+ " -n NR_DISKS Test NR_DISKS.\n"
+ " -v | --verbose Enable libguestfs debugging.\n"
+ " -x | --trace Enable libguestfs tracing.\n"
+ "\n"
+ "* Note that the max number of disks depends on the backend and\n"
+ " limit on the number of open file descriptors (ulimit -n).\n",
+ getprogname (), getprogname (), getprogname ());
+ }
+ exit (status);
+}
+
+int
+main (int argc, char *argv[])
+{
+ enum { HELP_OPTION = CHAR_MAX + 1 };
+ static const char options[] = "amn:vVx";
+ static const struct option long_options[] = {
+ { "help", 0, 0, HELP_OPTION },
+ { "just-add", 0, 0, 0 },
+ { "max", 0, 0, 'm' },
+ { "trace", 0, 0, 'x' },
+ { "verbose", 0, 0, 'v' },
+ { "version", 0, 0, 'V' },
+ { 0, 0, 0, 0 }
+ };
+ int c;
+ int option_index;
+ bool just_add = false;
+ guestfs_h *g;
+ char *tmpdir;
+ ssize_t n = -1; /* -1: not set 0: max > 0: specific value */
+
+ g = guestfs_create ();
+ if (g == NULL)
+ error (EXIT_FAILURE, errno, "guestfs_create");
+
+ for (;;) {
+ c = getopt_long (argc, argv, options, long_options, &option_index);
+ if (c == -1) break;
+
+ switch (c) {
+ case 0: /* options which are long only */
+ if (STREQ (long_options[option_index].name, "just-add"))
+ just_add = true;
+ else
+ error (EXIT_FAILURE, 0,
+ "unknown long option: %s (%d)",
+ long_options[option_index].name, option_index);
+ break;
+
+ case 'm':
+ n = 0;
+ break;
+
+ case 'n':
+ if (sscanf (optarg, "%zd", &n) != 1 || n <= 0)
+ error (EXIT_FAILURE, 0, "cannot parse -n option");
+ break;
+
+ case 'x':
+ guestfs_set_trace (g, 1);
+ break;
+
+ case 'v':
+ guestfs_set_verbose (g, 1);
+ break;
+
+ case 'V':
+ printf ("%s %s\n",
+ getprogname (),
+ PACKAGE_VERSION_FULL);
+ exit (EXIT_SUCCESS);
+
+ case HELP_OPTION:
+ usage (EXIT_SUCCESS);
+
+ default:
+ usage (EXIT_FAILURE);
+ }
+ }
+
+ if (n == -1)
+ error (EXIT_FAILURE, 0, "either -n NR_DISKS or --max must be specified");
+
+ if (n == 0) {
+ n = get_max_disks (g);
+ if (n == -1)
+ error (EXIT_FAILURE, 0, "cannot calculate --max disks");
+ }
+ ndisks = n;
+
+ tmpdir = guestfs_get_cachedir (g);
+ if (tmpdir == NULL)
+ exit (EXIT_FAILURE);
+ make_disks (tmpdir);
+ free (tmpdir);
+ atexit (rm_disks);
+
+ do_test (g, ndisks, just_add);
+
+ if (guestfs_shutdown (g) == -1)
+ exit (EXIT_FAILURE);
+ guestfs_close (g);
+
+ exit (EXIT_SUCCESS);
+}
+
+/**
+ * Work out the maximum number of disks that could be added to the
+ * libguestfs appliance, based on these factors:
+ *
+ * =over 4
+ *
+ * =item the current backend
+ *
+ * =item the max number of open file descriptors (RLIMIT_NOFILE)
+ *
+ * =back
+ */
+static ssize_t
+get_max_disks (guestfs_h *g)
+{
+ ssize_t ret;
+ struct rlimit rlim;
+ /* We reserve a little bit of "headroom" because qemu uses more
+ * file descriptors than just the disk files.
+ */
+ const unsigned fd_headroom = 32;
+
+ ret = guestfs_max_disks (g);
+ if (ret == -1)
+ return -1;
+
+ if (getrlimit (RLIMIT_NOFILE, &rlim) == -1) {
+ perror ("getrlimit: RLIMIT_NOFILE");
+ return -1;
+ }
+ if (rlim.rlim_cur > fd_headroom) {
+ if ((size_t) ret > rlim.rlim_cur - fd_headroom) {
+ if (rlim.rlim_max > rlim.rlim_cur)
+ fprintf (stderr,
+ "%s: warning: to get more complete testing, increase\n"
+ "file limit up to hard limit:\n"
+ "\n"
+ "$ ulimit -Hn %lu\n"
+ "\n",
+ getprogname (), (unsigned long) rlim.rlim_max);
+ else {
+ struct passwd *pw;
+ unsigned long suggested_limit = ret + fd_headroom;
+
+ pw = getpwuid (geteuid ());
+ fprintf (stderr,
+ "%s: warning: to get more complete testing, increase\n"
+ "file descriptor limit to >= %lu.\n"
+ "\n"
+ "To do this, add this line to /etc/security/limits.conf:\n"
+ "\n"
+ "%s hard nofile %lu\n"
+ "\n",
+ getprogname (), suggested_limit,
+ pw ? pw->pw_name : "your_username",
+ suggested_limit);
+ }
+
+ ret = rlim.rlim_cur - fd_headroom;
+ }
+ }
+
+ printf ("max_disks = %zd\n", ret);
+ return ret;
+}
+
+static void
+do_test (guestfs_h *g, size_t ndisks, bool just_add)
+{
+ size_t i, j, k, n;
+ unsigned errors;
+ CLEANUP_FREE_STRING_LIST char **devices = NULL;
+ CLEANUP_FREE_STRING_LIST char **partitions = NULL;
+
+ for (i = 0; i < ndisks; ++i) {
+ if (guestfs_add_drive_opts (g, disks[i],
+ GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
+ GUESTFS_ADD_DRIVE_OPTS_CACHEMODE, "unsafe",
+ -1) == -1)
+ exit (EXIT_FAILURE);
+ }
+
+ if (guestfs_launch (g) == -1)
+ exit (EXIT_FAILURE);
+
+ /* Check the disks were added. */
+ devices = guestfs_list_devices (g);
+ n = guestfs_int_count_strings (devices);
+ if (n != ndisks) {
+ fprintf (stderr, "%s: incorrect number of devices returned by guestfs_list_devices:\n",
+ getprogname ());
+ fprintf (stderr, "counted %zu, expecting %zu\n", n, ndisks);
+ fprintf (stderr, "devices:\n");
+ for (i = 0; i < n; ++i)
+ fprintf (stderr, "\t%s\n", devices[i]);
+ exit (EXIT_FAILURE);
+ }
+
+ /* If the --just-add option was given, we're done. */
+ if (just_add)
+ return;
+
+ /* Check each device has the expected drive name, eg. /dev/sda,
+ * /dev/sdb, ..., /dev/sdaa, ...
+ */
+ for (i = 0; i < ndisks; ++i) {
+ char expected[64];
+
+ guestfs_int_drive_name (i, expected);
+ if (!STRSUFFIX (devices[i], expected)) {
+ fprintf (stderr,
+ "%s: incorrect device name at index %zu: "
+ "%s (expected suffix %s)\n",
+ getprogname (), i, devices[i], expected);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ /* Check drive index. */
+ for (i = 0; i < ndisks; ++i) {
+ int idx;
+
+ idx = guestfs_device_index (g, devices[i]);
+ if (idx == -1)
+ exit (EXIT_FAILURE);
+ if ((int) i != idx) {
+ fprintf (stderr,
+ "%s: incorrect device index for %s: "
+ "expected %zu by got %d\n",
+ getprogname (), devices[i], i, idx);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ /* Check the disk index written at the start of each disk. This
+ * ensures that disks are added to the appliance in the same order
+ * that we called guestfs_add_drive.
+ */
+ errors = 0;
+ for (i = 0; i < ndisks; ++i) {
+ CLEANUP_FREE char *buf = NULL;
+ size_t j, r;
+
+ buf = guestfs_pread_device (g, devices[i], sizeof j, 0, &r);
+ if (buf == NULL)
+ exit (EXIT_FAILURE);
+ if (r != sizeof j)
+ error (EXIT_FAILURE, 0, "pread_device read incorrect number of bytes");
+ memcpy (&j, buf, r);
+ if (i != j) {
+ if (errors == 0)
+ fprintf (stderr, "%s: incorrect device enumeration\n",
+ getprogname ());
+ errors++;
+ fprintf (stderr, "%s at device index %zu was added with index %zu\n",
+ devices[i], i, j);
+ }
+ }
+ if (errors > 0)
+ exit (EXIT_FAILURE);
+
+ /* Put some data on each disk to check they are writable and
+ * mountable.
+ */
+ for (i = 0; i < ndisks; ++i) {
+ CLEANUP_FREE char *mp = NULL;
+ CLEANUP_FREE char *part = NULL;
+ CLEANUP_FREE char *file = NULL;
+ CLEANUP_FREE char *data = NULL;
+
+ if (asprintf (&mp, "/mp%zu", i) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+
+ if (guestfs_mkmountpoint (g, mp) == -1)
+ exit (EXIT_FAILURE);
+
+ /* To save time in the test, add 15 partitions to the first disk
+ * and last disks only, and 1 partition to every other disk. Note
+ * that 15 partitions is the max allowed by virtio-blk.
+ */
+ if (i == 0 || i == ndisks-1) {
+ if (guestfs_part_init (g, devices[i], "gpt") == -1)
+ exit (EXIT_FAILURE);
+ for (j = 1; j <= 14; ++j) {
+ if (guestfs_part_add (g, devices[i], "p", 64*j, 64*j+63) == -1)
+ exit (EXIT_FAILURE);
+ }
+ if (guestfs_part_add (g, devices[i], "p", 64*15, -64) == -1)
+ exit (EXIT_FAILURE);
+ if (asprintf (&part, "%s15", devices[i]) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ }
+ else {
+ if (guestfs_part_disk (g, devices[i], "mbr") == -1)
+ exit (EXIT_FAILURE);
+ if (asprintf (&part, "%s1", devices[i]) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ }
+
+ if (guestfs_mkfs (g, "ext2", part) == -1)
+ exit (EXIT_FAILURE);
+ if (guestfs_mount (g, part, mp) == -1)
+ exit (EXIT_FAILURE);
+
+ if (asprintf (&file, "%s/disk%zu", mp, i) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ if (asprintf (&data, "This is disk %zu.", i) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+
+ if (guestfs_write (g, file, data, strlen (data)) == -1)
+ exit (EXIT_FAILURE);
+ }
+
+ for (i = 0; i < ndisks; ++i) {
+ CLEANUP_FREE char *file = NULL, *expected = NULL, *actual = NULL;
+
+ if (asprintf (&file, "/mp%zu/disk%zu", i, i) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ if (asprintf (&expected, "This is disk %zu.", i) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+
+ actual = guestfs_cat (g, file);
+ if (actual == NULL)
+ exit (EXIT_FAILURE);
+
+ if (STRNEQ (expected, actual)) {
+ fprintf (stderr,
+ "%s: unexpected content in file %s: "
+ "expected \"%s\", actual \"%s\"\n",
+ getprogname (), file,
+ expected, actual);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ /* Finally check the partition list. */
+ partitions = guestfs_list_partitions (g);
+ if (partitions == NULL)
+ exit (EXIT_FAILURE);
+
+ k = 0;
+ for (i = 0; i < ndisks; ++i) {
+ char dev[64];
+
+ guestfs_int_drive_name (i, dev);
+
+ if (i == 0 || i == ndisks-1) {
+ for (j = 1; j <= 15; ++j) {
+ CLEANUP_FREE char *expected = NULL;
+ const char *p;
+
+ if (asprintf (&expected, "%s%zu", dev, j) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ p = partitions[k++];
+ if (!STRSUFFIX (p, expected)) {
+ fprintf (stderr,
+ "%s: incorrect partition name at index %zu, %zu: "
+ "%s (expected suffix %s)\n",
+ getprogname (), i, j, p, expected);
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+ else {
+ CLEANUP_FREE char *expected = NULL;
+ const char *p;
+
+ if (asprintf (&expected, "%s1", dev) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ p = partitions[k++];
+ if (!STRSUFFIX (p, expected)) {
+ fprintf (stderr,
+ "%s: incorrect partition name at index %zu: "
+ "%s (expected suffix %s)\n",
+ getprogname (), i, p, expected);
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+}
+
+static void
+make_disks (const char *tmpdir)
+{
+ size_t i;
+ int fd;
+
+ assert (ndisks > 0);
+
+ disks = calloc (ndisks, sizeof (char *));
+ if (disks == NULL)
+ error (EXIT_FAILURE, errno, "calloc");
+
+ for (i = 0; i < ndisks; ++i) {
+ if (asprintf (&disks[i], "%s/testdiskXXXXXX", tmpdir) == -1)
+ error (EXIT_FAILURE, errno, "asprintf");
+ fd = mkstemp (disks[i]);
+ if (fd == -1)
+ error (EXIT_FAILURE, errno, "mkstemp: %s", disks[i]);
+
+ /* Create a raw format 1MB disk, and write the disk number at the
+ * start of the disk, so that we can later check that disks are
+ * added in the right order to the appliance.
+ *
+ * Note that we write the disk number in whatever is the current
+ * endian/integer size, which is fine because we'll only check it
+ * from the same program.
+ */
+ if (ftruncate (fd, 1024*1024) == -1)
+ error (EXIT_FAILURE, errno, "ftruncate: %s", disks[i]);
+ if (write (fd, &i, sizeof i) != sizeof i)
+ error (EXIT_FAILURE, errno, "write: %s", disks[i]);
+ if (close (fd) == -1)
+ error (EXIT_FAILURE, errno, "close: %s", disks[i]);
+ }
+}
+
+/* Called by an atexit handler. */
+static void
+rm_disks (void)
+{
+ size_t i;
+
+ if (disks == NULL)
+ return;
+
+ for (i = 0; i < ndisks; ++i) {
+ unlink (disks[i]);
+ free (disks[i]);
+ }
+
+ free (disks);
+ disks = NULL;
+}
diff --git a/tests/disks/test-add-lots-of-disks.sh b/tests/disks/test-add-lots-of-disks.sh
new file mode 100755
index 000000000..d59753338
--- /dev/null
+++ b/tests/disks/test-add-lots-of-disks.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Copyright (C) 2012-2017 Red Hat Inc.
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+N=255
+
+$TEST_FUNCTIONS
+skip_if_skipped
+
+./test-add-disks --just-add -n $N
diff --git a/tests/disks/test-max-disks.pl b/tests/disks/test-max-disks.pl
deleted file mode 100755
index 11d465189..000000000
--- a/tests/disks/test-max-disks.pl
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/usr/bin/env perl
-# Copyright (C) 2012 Red Hat Inc.
-#
-# 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 2 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, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-# Test adding maximum number of disks to the guest.
-
-use strict;
-use warnings;
-
-use Sys::Guestfs;
-
-my $errors = 0;
-
-my $g = Sys::Guestfs->new ();
-
-my $max_disks = $g->max_disks ();
-printf "max_disks is %d\n", $max_disks;
-
-# Create large number of disks.
-my ($name, $i, $j);
-for ($i = 0; $i < $max_disks; ++$i) {
- $g->add_drive_scratch (1024*1024);
-}
-
-$g->launch ();
-
-# Check the disks were added.
-my @devices = $g->list_devices ();
-if (@devices != $max_disks) {
- print STDERR "$0: incorrect number of devices returned by \$g->list_devices:\n";
- print STDERR "$0: \@devices = ", join (" ", @devices), "\n";
- $errors++;
-}
-
-for ($i = 0; $i < $max_disks; ++$i) {
- my $expected = drive_name ($i);
- unless ($devices[$i] =~ m{/dev/[abce-ln-z]+d$expected$}) {
- print STDERR "$0: incorrect device name at index $i: ",
- "expected /dev/sd$expected, but got $devices[$i]\n";
- $errors++;
- }
-}
-
-# Check device_index.
-for ($i = 0; $i < $max_disks; ++$i) {
- if ($i != $g->device_index ($devices[$i])) {
- print STDERR "$0: incorrect device index for $devices[$i]\n";
- $errors++;
- }
-}
-
-# Put some data on each disk to check they are mountable, writable etc.
-for ($i = 0; $i < $max_disks; ++$i) {
- my $dev = $devices[$i];
- $g->mkmountpoint ("/mp$i");
-
- # To save time in the test, add 15 partitions to the first disk
- # and last disks only, and 1 partition to every other disk. Note
- # that 15 partitions is the max allowed by virtio-blk.
- my $part;
- if ($i == 0 || $i == $max_disks-1) {
- $g->part_init ($dev, "gpt");
- for ($j = 1; $j <= 14; ++$j) {
- $g->part_add ($dev, "p", 64*$j, 64*$j+63);
- }
- $g->part_add ($dev, "p", 64*15, -64);
- $part = $dev . "15";
- }
- else {
- $g->part_disk ($dev, "mbr");
- $part = $dev . "1";
- }
- $g->mkfs ("ext2", "$part");
- $g->mount ("$part", "/mp$i");
- $g->write ("/mp$i/disk$i", "This is disk #$i.\n");
-}
-
-for ($i = 0; $i < $max_disks; ++$i) {
- if ($g->cat ("/mp$i/disk$i") ne "This is disk #$i.\n") {
- print STDERR "$0: unexpected content in file /mp$i/disk$i\n";
- $errors++;
- }
-}
-
-# Enumerate and check partition names.
-my @partitions = $g->list_partitions ();
-if (@partitions != $max_disks + 14*2) {
- print STDERR "$0: incorrect number of partitions returned by \$g->list_partitions:\n";
- print STDERR "$0: \@partitions = ", join (" ", @partitions), "\n";
- $errors++;
-}
-
-for ($i = 0, $j = 0; $i < $max_disks; ++$i) {
- my $expected = drive_name ($i);
- if ($i == 0 || $i == $max_disks-1) {
- unless ($partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}1$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}2$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}3$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}4$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}5$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}6$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}7$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}8$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}9$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}10$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}11$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}12$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}13$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}14$} &&
- $partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}15$}) {
- print STDERR "$0: incorrect partition name at index $i\n";
- $errors++;
- }
- } else {
- unless ($partitions[$j++] =~ m{/dev/[abce-ln-z]+d${expected}1$}) {
- print STDERR "$0: incorrect partition name at index $i\n";
- $errors++;
- }
- }
-}
-
-$g->shutdown ();
-$g->close ();
-
-exit ($errors == 0 ? 0 : 1);
-
-sub drive_name
-{
- my $index = shift;
- my $prefix = "";
- if ($index >= 26) {
- $prefix = drive_name ($index/26 - 1);
- }
- $index %= 26;
- return $prefix . chr (97 + $index);
-}
diff --git a/tests/disks/test-max-disks.sh b/tests/disks/test-max-disks.sh
new file mode 100755
index 000000000..61ea95644
--- /dev/null
+++ b/tests/disks/test-max-disks.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# Copyright (C) 2012-2017 Red Hat Inc.
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+$TEST_FUNCTIONS
+skip_if_skipped
+slow_test
+
+./test-add-disks --max
--
2.12.0
7 years, 7 months