It takes too long time for guestfish to launch
by Zhang Qian
Hi,
I am using guestfish, and found subcommand "launch" took about 20
seconds to finish for a 4GB disk image.
Is there any way to improve the performance? Thanks!
Regards,
Qian
15 years, 3 months
[PATCH] Fix errno check in readdir in devsparts.c
by Matthew Booth
---
daemon/devsparts.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index b89682c..e9c5e8f 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -40,7 +40,6 @@ foreach_block_device (block_dev_func_t func)
int size = 0, alloc = 0;
DIR *dir;
- struct dirent *d;
int err = 0;
dir = opendir ("/sys/block");
@@ -49,8 +48,11 @@ foreach_block_device (block_dev_func_t func)
return NULL;
}
- errno = 0;
- while ((d = readdir (dir)) != NULL) {
+ while(1) {
+ errno = 0;
+ struct dirent *d = readdir(dir);
+ if(NULL == d) break;
+
if (strncmp (d->d_name, "sd", 2) == 0 ||
strncmp (d->d_name, "hd", 2) == 0 ||
strncmp (d->d_name, "vd", 2) == 0 ||
--
1.6.2.5
15 years, 3 months
using gnulib from daemon/
by Jim Meyering
Hi Rich,
Prompted by your "New commands to list devices by UUID and label"
patch, I've adjusted it to use gnulib.
While just compiling hash.[ch] is probably ok, in general (given the
strict requirements of libguestfs) using the C files of a module is
usually not an option, since you don't get the benefit of the module's
m4 tests or automake snippets. For other modules, those pieces
are often required.
To integrate gnulib into a project like this is not hard at all:
I ran this one-time command:
../.gnulib/gnulib-tool --import --with-tests hash
That created the file, daemon/m4/gnulib-cache.m4,
which I've git-added in the patch below.
It records the names of modules we're using
(currently only "hash") as well as a few other things,
including the fact that I told it to include unit tests.
That latter option creates and populates the tests/ directory.
The other new directory is lib/.
I added the SUBDIRS line in Makefile.am to build in those
directories and the corresponding */Makefile names in configure.ac.
Now that gnulib-cache.m4 records state, to update from gnulib
in the future, you'd just run this, perhaps from an ./autogen.sh script:
(I haven't done that yet)
../.gnulib/gnulib-tool --update
Also, I added the usual AC_CONFIG_AUX_DIR([build-aux])
directive to configure.ac so that all of the auxilliary
files pulled in by autoreconf don't clutter the daemon/ directory.
The only other change was the always-required-with-gnulib one
to add these two lines to configure.ac:
gl_EARLY
gl_INIT
If you apply this on top of yours, it should still build,
with no change in binary size, and it will then be trivial
to add a few more gnulib modules.
>From 21c185b04a41f61c06a64d1d4076aff4a98d0d40 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 5 Aug 2009 05:59:19 -0400
Subject: [PATCH] daemon: use gnulib
* Makefile.am (SUBDIRS): Define.
(AM_CPPFLAGS): Define, to include from gnulib's lib/
(LDADD): Define, to link with gnulib's libgnu.a.
* configure.ac: Use AC_CONFIG_AUX_DIR([build-aux]), gl_EARLY, gl_INIT.
(AC_CONFIG_FILES): Add lib/Makefile and tests/Makefile
* m4/gnulib-cache.m4: New file, generated by running
../.gnulib/gnulib-tool --import --with-tests hash
* .gitignore: Ignore all of the imported files.
---
daemon/.gitignore | 29 +++++++++++++++++++++++++++++
daemon/Makefile.am | 10 ++++++----
daemon/configure.ac | 6 +++++-
daemon/m4/gnulib-cache.m4 | 35 +++++++++++++++++++++++++++++++++++
4 files changed, 75 insertions(+), 5 deletions(-)
create mode 100644 daemon/.gitignore
create mode 100644 daemon/m4/gnulib-cache.m4
diff --git a/daemon/.gitignore b/daemon/.gitignore
new file mode 100644
index 0000000..7f60faf
--- /dev/null
+++ b/daemon/.gitignore
@@ -0,0 +1,29 @@
+build-aux
+lib
+link-warning.h
+m4/00gnulib.m4
+m4/errno_h.m4
+m4/error.m4
+m4/exitfail.m4
+m4/extensions.m4
+m4/gnulib-common.m4
+m4/gnulib-comp.m4
+m4/gnulib-tool.m4
+m4/hash.m4
+m4/include_next.m4
+m4/inline.m4
+m4/inttostr.m4
+m4/longlong.m4
+m4/multiarch.m4
+m4/onceonly.m4
+m4/stdbool.m4
+m4/stdint.m4
+m4/stdlib_h.m4
+m4/strerror.m4
+m4/string_h.m4
+m4/unistd_h.m4
+m4/wchar.m4
+m4/wchar_t.m4
+m4/wint_t.m4
+m4/xalloc.m4
+tests
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 0fec611..090338d 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -17,6 +17,8 @@
ACLOCAL_AMFLAGS = -I m4
+SUBDIRS = lib tests .
+
noinst_PROGRAMS = guestfsd
guestfsd_SOURCES = \
actions.h \
@@ -75,8 +77,8 @@ guestfsd_SOURCES = \
zero.c \
zerofree.c \
$(top_builddir)/../src/guestfs_protocol.h \
- $(top_builddir)/../src/guestfs_protocol.c \
- $(srcdir)/../.gnulib/lib/hash.h \
- $(srcdir)/../.gnulib/lib/hash.c
+ $(top_builddir)/../src/guestfs_protocol.c
-guestfsd_CFLAGS = -Wall -I$(srcdir)/../.gnulib/lib
+AM_CPPFLAGS = -I$(srcdir)/lib -Ilib
+guestfsd_CFLAGS = -Wall
+LDADD = lib/libgnu.a
diff --git a/daemon/configure.ac b/daemon/configure.ac
index 3bfd2ed..126e125 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -16,6 +16,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
AC_INIT([libguestfs-daemon],[1.0.0])
+AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_MACRO_DIR([m4])
@@ -41,6 +42,9 @@ AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_CPP
+gl_EARLY
+gl_INIT
+
AC_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
@@ -86,5 +90,5 @@ AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])
dnl Produce output files.
AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile lib/Makefile tests/Makefile])
AC_OUTPUT
diff --git a/daemon/m4/gnulib-cache.m4 b/daemon/m4/gnulib-cache.m4
new file mode 100644
index 0000000..8aa504a
--- /dev/null
+++ b/daemon/m4/gnulib-cache.m4
@@ -0,0 +1,35 @@
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
+#
+# This file is free software, distributed under the terms of the GNU
+# General Public License. As a special exception to the GNU General
+# Public License, this file may be distributed as part of a program
+# that contains a configuration script generated by Autoconf, under
+# the same distribution terms as the rest of that program.
+#
+# Generated by gnulib-tool.
+#
+# This file represents the specification of how gnulib-tool is used.
+# It acts as a cache: It is written and read by gnulib-tool.
+# In projects using CVS, this file is meant to be stored in CVS,
+# like the configure.ac and various Makefile.am files.
+
+
+# Specification in the form of a command-line invocation:
+# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=gl hash
+
+# Specification in the form of a few gnulib-tool.m4 macro invocations:
+gl_LOCAL_DIR([])
+gl_MODULES([
+ hash
+])
+gl_AVOID([])
+gl_SOURCE_BASE([lib])
+gl_M4_BASE([m4])
+gl_PO_BASE([])
+gl_DOC_BASE([doc])
+gl_TESTS_BASE([tests])
+gl_WITH_TESTS
+gl_LIB([libgnu])
+gl_MAKEFILE_NAME([])
+gl_MACRO_PREFIX([gl])
+gl_PO_DOMAIN([])
--
1.6.4.226.g08063
15 years, 3 months
[PATCH] Recognise cd-rom devices in devsparts.c
by Matthew Booth
Also:
* Un-duplicate device detection code by creating a common mapping function.
* Add some more comments.
---
daemon/devsparts.c | 209 +++++++++++++++++++++++++++++-----------------------
1 files changed, 116 insertions(+), 93 deletions(-)
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 33579ba..0e056a1 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -29,57 +29,38 @@
#include "daemon.h"
#include "actions.h"
+typedef int (*block_dev_func_t)(const char *dev);
+
+static int foreach_block_device (block_dev_func_t func);
+
char **
do_list_devices (void)
{
char **r = NULL;
int size = 0, alloc = 0;
- DIR *dir;
- struct dirent *d;
- char buf[256];
-
- dir = opendir ("/sys/block");
- if (!dir) {
- reply_with_perror ("opendir: /sys/block");
- return NULL;
- }
- while ((d = readdir (dir)) != NULL) {
- if (strncmp (d->d_name, "sd", 2) == 0 ||
- strncmp (d->d_name, "hd", 2) == 0 ||
- strncmp (d->d_name, "vd", 2) == 0) {
- snprintf (buf, sizeof buf, "/dev/%s", d->d_name);
+ /* Add a device to the list of devices */
+ int add_to_device_list(const char *device) {
+ char dev_path[256];
+ snprintf (dev_path, sizeof dev_path, "/dev/%s", device);
- /* RHBZ#514505: Some versions of qemu <= 0.10 add a
- * CD-ROM device even though we didn't request it. Try to
- * detect this by seeing if the device contains media.
- */
- int fd = open (buf, O_RDONLY);
- if (fd == -1) {
- perror (buf);
- continue;
+ if (add_string (&r, &size, &alloc, dev_path) == -1) {
+ return 0;
}
- close (fd);
- if (add_string (&r, &size, &alloc, buf) == -1) {
- closedir (dir);
- return NULL;
- }
- }
+ return 1;
}
- if (add_string (&r, &size, &alloc, NULL) == -1) {
- closedir (dir);
- return NULL;
- }
+ if(!foreach_block_device(add_to_device_list)) return NULL;
- if (closedir (dir) == -1) {
- reply_with_perror ("closedir: /sys/block");
- free_strings (r);
+ /* Sort the devices */
+ sort_strings (r, size);
+
+ /* NULL terminate the list */
+ if (add_string (&r, &size, &alloc, NULL) == -1) {
return NULL;
}
- sort_strings (r, size-1);
return r;
}
@@ -88,76 +69,63 @@ do_list_partitions (void)
{
char **r = NULL;
int size = 0, alloc = 0;
- DIR *dir, *dir2;
- struct dirent *d;
- char buf[256], devname[256];
- dir = opendir ("/sys/block");
- if (!dir) {
- reply_with_perror ("opendir: /sys/block");
- return NULL;
- }
+ int find_partitions(const char *device) {
+ struct dirent *d;
+ char devdir[256];
- while ((d = readdir (dir)) != NULL) {
- if (strncmp (d->d_name, "sd", 2) == 0 ||
- strncmp (d->d_name, "hd", 2) == 0 ||
- strncmp (d->d_name, "vd", 2) == 0) {
- snprintf (buf, sizeof buf, "/dev/%s", d->d_name);
+ /* Open the device's directory under /sys/block */
+ snprintf (devdir, sizeof devdir, "/sys/block/%s", device);
- /* RHBZ#514505: Some versions of qemu <= 0.10 add a
- * CD-ROM device even though we didn't request it. Try to
- * detect this by seeing if the device contains media.
- */
- int fd = open (buf, O_RDONLY);
- if (fd == -1) {
- perror (buf);
- continue;
- }
- close (fd);
-
- strncpy (devname, d->d_name, sizeof devname);
- devname[sizeof devname - 1] = '\0';
-
- snprintf (buf, sizeof buf, "/sys/block/%s", devname);
+ DIR *dir = opendir (devdir);
+ if (!dir) {
+ reply_with_perror ("opendir: %s", devdir);
+ free_stringslen (r, size);
+ return 0;
+ }
- dir2 = opendir (buf);
- if (!dir2) {
- reply_with_perror ("opendir: %s", buf);
- free_stringslen (r, size);
- return NULL;
- }
- while ((d = readdir (dir2)) != NULL) {
- if (strncmp (d->d_name, devname, strlen (devname)) == 0) {
- snprintf (buf, sizeof buf, "/dev/%s", d->d_name);
-
- if (add_string (&r, &size, &alloc, buf) == -1) {
- closedir (dir2);
- closedir (dir);
- return NULL;
- }
- }
+ /* Look in /sys/block/<device>/ for entries starting with <device>
+ * e.g. /sys/block/sda/sda1
+ */
+ errno = 0;
+ while ((d = readdir (dir)) != NULL) {
+ if (strncmp (d->d_name, device, strlen (device)) == 0) {
+ char part[256];
+ snprintf (part, sizeof part, "/dev/%s", d->d_name);
+
+ if (add_string (&r, &size, &alloc, part) == -1) {
+ closedir (dir);
+ return 0;
+ }
}
+ }
- if (closedir (dir2) == -1) {
- reply_with_perror ("closedir: /sys/block/%s", devname);
- free_stringslen (r, size);
- return NULL;
- }
+ /* Check if readdir failed */
+ if(0 != errno) {
+ reply_with_perror ("readdir: %s", devdir);
+ free_stringslen(r, size);
+ return 0;
}
- }
- if (add_string (&r, &size, &alloc, NULL) == -1) {
- closedir (dir);
- return NULL;
+ if (closedir (dir) == -1) {
+ reply_with_perror ("closedir: /sys/block/%s", device);
+ free_stringslen (r, size);
+ return 0;
+ }
+
+ return 1;
}
- if (closedir (dir) == -1) {
- reply_with_perror ("closedir: /sys/block");
- free_strings (r);
+ if(!foreach_block_device(find_partitions)) return NULL;
+
+ /* Sort the partition list */
+ sort_strings (r, size-1);
+
+ /* NULL-terminate the partition list */
+ if (add_string (&r, &size, &alloc, NULL) == -1) {
return NULL;
}
- sort_strings (r, size-1);
return r;
}
@@ -179,3 +147,58 @@ do_mkfs (char *fstype, char *device)
free (err);
return 0;
}
+
+static int
+foreach_block_device (block_dev_func_t func)
+{
+ DIR *dir;
+ struct dirent *d;
+ int success = 1;
+
+ dir = opendir ("/sys/block");
+ if (!dir) {
+ reply_with_perror ("opendir: /sys/block");
+ return 0;
+ }
+
+ errno = 0;
+ while ((d = readdir (dir)) != NULL) {
+ if (strncmp (d->d_name, "sd", 2) == 0 ||
+ strncmp (d->d_name, "hd", 2) == 0 ||
+ strncmp (d->d_name, "vd", 2) == 0 ||
+ strncmp (d->d_name, "sr", 2) == 0) {
+ char dev_path[256];
+ snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
+
+ /* RHBZ#514505: Some versions of qemu <= 0.10 add a
+ * CD-ROM device even though we didn't request it. Try to
+ * detect this by seeing if the device contains media.
+ */
+ int fd = open (dev_path, O_RDONLY);
+ if (fd == -1) {
+ perror (dev_path);
+ continue;
+ }
+ close (fd);
+
+ /* Call the map function for this device */
+ if(!(*func)(d->d_name)) {
+ success = 0;
+ break;
+ }
+ }
+ }
+
+ /* Check readdir didn't fail */
+ if(0 != errno) {
+ reply_with_perror ("readdir: /sys/block");
+ return 0;
+ }
+
+ if (closedir (dir) == -1) {
+ reply_with_perror ("closedir: /sys/block");
+ return 0;
+ }
+
+ return success;
+}
--
1.6.2.5
15 years, 3 months
[PATCH] Compute MD5 of COPYING.LIB used in upload and download tests
by Matthew Booth
As suggested by rjones.
---
src/generator.ml | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index 94dc268..7ac4ac8 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -1756,7 +1756,8 @@ This uses the L<blockdev(8)> command.");
[InitBasicFS, Always, TestOutput (
(* Pick a file from cwd which isn't likely to change. *)
[["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
- ["checksum"; "md5"; "/COPYING.LIB"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
+ ["checksum"; "md5"; "/COPYING.LIB"]],
+ Digest.to_hex (Digest.file "COPYING.LIB"))],
"upload a file from the local machine",
"\
Upload local file C<filename> to C<remotefilename> on the
@@ -1772,7 +1773,8 @@ See also C<guestfs_download>.");
[["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
["download"; "/COPYING.LIB"; "testdownload.tmp"];
["upload"; "testdownload.tmp"; "/upload"];
- ["checksum"; "md5"; "/upload"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
+ ["checksum"; "md5"; "/upload"]],
+ Digest.to_hex (Digest.file "COPYING.LIB"))],
"download a file to the local machine",
"\
Download file C<remotefilename> and save it as C<filename>
--
1.6.2.5
15 years, 3 months
[PATCH] Add some newly-untracked files to .gitignore
by Matthew Booth
---
.gitignore | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 147e1cb..dcea811 100644
--- a/.gitignore
+++ b/.gitignore
@@ -154,10 +154,21 @@ po/POTFILES
po/remove-potcdate.sed
po/stamp-it
po/stamp-po
+po/LINGUAS
+po/Makefile.in.in
+po/Makevars
+po/Rules-quot
+po/boldquot.sed
+po/en(a)boldquot.header
+po/en(a)quot.header
+po/insert-header.sin
+po/quot.sed
+po/remove-potcdate.sin
python/bindtests.py
python/guestfs.py
python/guestfs-py.c
python/guestfs.pyc
+regressions/test1.img
ruby/bindtests.rb
ruby/ext/guestfs/extconf.h
ruby/ext/guestfs/_guestfs.c
--
1.6.2.5
15 years, 3 months