 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH v2] launch: add support for autodetection of appliance image format
                                
                                
                                
                                    
                                        by Pavel Butsykin
                                    
                                
                                
                                        This feature allows you to use different image formats for the fixed
appliance. The raw format is used by default.
Signed-off-by: Pavel Butsykin <pbutsykin(a)virtuozzo.com>
---
 lib/launch-direct.c     |  2 ++
 lib/launch-libvirt.c    | 19 ++++++++++++-------
 m4/guestfs_appliance.m4 | 11 +++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
index 0be662e25..b9b54857a 100644
--- a/lib/launch-direct.c
+++ b/lib/launch-direct.c
@@ -592,7 +592,9 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
       append_list ("id=appliance");
       append_list ("cache=unsafe");
       append_list ("if=none");
+#ifndef APPLIANCE_FMT_AUTO
       append_list ("format=raw");
+#endif
     } end_list ();
     start_list ("-device") {
       append_list ("scsi-hd");
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index 4adb2cfb3..030ea6911 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -212,9 +212,10 @@ get_source_format_or_autodetect (guestfs_h *g, struct drive *drv)
 
 /**
  * Create a qcow2 format overlay, with the given C<backing_drive>
- * (file).  The C<format> parameter, which must be non-NULL, is the
- * backing file format.  This is used to create the appliance overlay,
- * and also for read-only drives.
+ * (file).  The C<format> parameter is the backing file format.
+ * The C<format> parameter can be NULL, in this case the backing
+ * format will be determined automatically.  This is used to create
+ * the appliance overlay, and also for read-only drives.
  */
 static char *
 make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
@@ -223,8 +224,6 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
   char *overlay;
   struct guestfs_disk_create_argv optargs;
 
-  assert (format != NULL);
-
   if (guestfs_int_lazy_make_tmpdir (g) == -1)
     return NULL;
 
@@ -232,8 +231,10 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
 
   optargs.bitmask = GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK;
   optargs.backingfile = backing_drive;
-  optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
-  optargs.backingformat = format;
+  if (format) {
+    optargs.bitmask |= GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK;
+    optargs.backingformat = format;
+  }
 
   if (guestfs_disk_create_argv (g, overlay, "qcow2", -1, &optargs) == -1) {
     free (overlay);
@@ -461,7 +462,11 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
 
   /* Note that appliance can be NULL if using the old-style appliance. */
   if (appliance) {
+#ifdef APPLIANCE_FMT_AUTO
+    params.appliance_overlay = make_qcow2_overlay (g, appliance, NULL);
+#else
     params.appliance_overlay = make_qcow2_overlay (g, appliance, "raw");
+#endif
     if (!params.appliance_overlay)
       goto cleanup;
   }
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4
index 81c43879f..4e1ec8135 100644
--- a/m4/guestfs_appliance.m4
+++ b/m4/guestfs_appliance.m4
@@ -139,3 +139,14 @@ AC_SUBST([GUESTFS_DEFAULT_PATH])
 
 AC_DEFINE_UNQUOTED([GUESTFS_DEFAULT_PATH], ["$GUESTFS_DEFAULT_PATH"],
     [Define guestfs default path.])
+
+AC_ARG_ENABLE([appliance-fmt-auto],
+    [AS_HELP_STRING([--enable-appliance-fmt-auto],
+        [enable autodetection of appliance image format @<:@default=no@:>@])],
+        [ENABLE_APPLIANCE_FMT_AUTO="$enableval"],
+        [ENABLE_APPLIANCE_FMT_AUTO=no])
+
+if test "x$ENABLE_APPLIANCE_FMT_AUTO" = "xyes"; then
+    AC_DEFINE([APPLIANCE_FMT_AUTO], [1],
+        [Define to 1 if enabled autodetection of appliance image format.])
+fi
-- 
2.13.0
                                
                         
                        
                                
                                5 years, 8 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        1.39 proposal: Let's split up the libguestfs git repo and tarballs
                                
                                
                                
                                    
                                        by Richard W.M. Jones
                                    
                                
                                
                                        My contention is that the libguestfs git repository is too large and
unwieldy.  There are too many separate, unrelated projects and as a
result of that the source has too many dependencies and takes too long
to build and test.
The project divides (sort of) naturally into layers -- the library,
the bindings, the various virt tools -- and could be split along those
lines into separate projects which can then be released and evolve at
their own pace.
My suggested split would be something like this:
* libguestfs: The library, daemon and appliance.  That would include
  the following directories in a single project:
       appliance
       bash
       contrib
       daemon
       docs
       examples
       gnulib
       lib
       logo
       test-tool
       tmp
       utils
       website
* 1 project for each language binding:
       csharp
       erlang
       gobject
       golang
       haskell
       java
       lua
       ocaml
       php
       perl
       python
       ruby
* virt-customize and related tools, we'd probably call this subproject
  "virt-builder".  It would include virt-builder, virt-customize and
  virt-sysprep, since they share a lot of common code.
* 1 project for each of the following items:
       small tools written in C
          (virt-cat, virt-filesystems, virt-log, virt-ls, virt-tail,
	   virt-diff, virt-edit, virt-format, guestmount, virt-inspector,
	   virt-make-fs, virt-rescue)
       guestfish
       virt-alignment-scan and virt-df
       virt-dib	   
       virt-get-kernel
       virt-resize
       virt-sparsify
       virt-v2v and virt-p2v
       virt-win-reg
* I'd be inclined to drop the legacy Perl tools virt-tar,
  virt-list-filesystems, virt-list-partitions unless someone
  especially wished to step forward to maintain them.
* common code and generator: Off to the side we'd somehow need to
  package up the common code and the generator for use by all of the
  above projects.  It wouldn't be a separate project for downstream
  packagers, but instead the code would be included (ie. duplicated)
  in tarballs and upstream available as a side git repo that you'd
  need to include when building (git submodule?).  This is somewhat
  unspecified.
M4, PO, and tests would be split between the projects as appropriate.
My proposal would be to do this incrementally, rather than all at
once, moving the easier things out first.
Thoughts?
Rich.
-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
                                
                         
                        
                                
                                5 years, 11 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 4/4] daemon: simplify string allocation
                                
                                
                                
                                    
                                        by Pino Toscano
                                    
                                
                                
                                        When creating an helper string for do_aug_match(), use a simpler
asprintf() with manual free(), since the code block is small enough.
This slightly helps static code analyzers.
---
 daemon/augeas.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index bd54c4849..453251337 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -420,17 +420,15 @@ do_aug_ls (const char *path)
   if (STREQ (path, "/"))
     matches = do_aug_match ("/*");
   else {
-    CLEANUP_FREE char *buf = NULL;
+    char *buf = NULL;
 
-    len += 3;			/* / * + terminating \0 */
-    buf = malloc (len);
-    if (buf == NULL) {
-      reply_with_perror ("malloc");
+    if (asprintf (&buf, "%s/*", path) == -1) {
+      reply_with_perror ("asprintf");
       return NULL;
     }
 
-    snprintf (buf, len, "%s/*", path);
     matches = do_aug_match (buf);
+    free (buf);
   }
 
   if (matches == NULL)
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [nbdkit PATCH v2] tests: Skip guestfs code on CentOS 6
                                
                                
                                
                                    
                                        by Eric Blake
                                    
                                
                                
                                        CentOS 6 has libguestfs-devel 1.20.11, which predates the support
in guestfs_add_drive_opts() for requesting an nbd drive instead
of a local file (annoyingly, guestfs documentation merely states
the function was available since 0.3, without saying which later
releases added new options); causing a compilation failure during
'make check'.  Maybe the guestfs plugin should still be built,
even though the tests that use guestfs can't work without support
for GUESTFS_ADD_DRIVE_OPTS_PROTOCOL; but it's easier to just
declare that on this old platform, we'll just disable guestfs
integration altogether.  With that in place, 'make check' now
runs to completion, passing 14 and skipping 5 remaining tests.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
 configure.ac | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/configure.ac b/configure.ac
index c9a6948..d498d05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -403,10 +403,20 @@ AC_ARG_WITH([libguestfs],[
     [with_libguestfs=check])
 AS_IF([test "$with_libguestfs" != "no"],[
     PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs],[
+        # Although the library was found, we want to make sure it supports nbd
+        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <guestfs.h>
+        ]], [[
+#ifndef GUESTFS_ADD_DRIVE_OPTS_PROTOCOL
+#error unsupported
+#endif
+        ]])], [
         AC_SUBST([LIBGUESTFS_CFLAGS])
         AC_SUBST([LIBGUESTFS_LIBS])
         AC_DEFINE([HAVE_LIBGUESTFS],[1],[libguestfs found at compile time.])
+        ],[
+        LIBGUESTFS_LIBS=
+        AC_MSG_WARN([libguestfs too old, guestfs plugin and tests will be disabled])])
     ],
     [AC_MSG_WARN([libguestfs not found, guestfs plugin and tests will be disabled])])
 ])
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH v5 0/3] libguestfs: guestfs_list_filesystems: skip block devices which cannot hold file system
                                
                                
                                
                                    
                                        by Mykola Ivanets
                                    
                                
                                
                                        This patch series:
1. Addresses comments from last review:
     part_get_mbr_part_type doesn't break original implementation in C.
2. Rebased on top of master and little bit refactored for readability.
Mykola Ivanets (1):
  tests: md: Test guestfish list-filesystems command skips partitioned
    md devices.
Nikolay Ivanets (2):
  daemon: Reimplement 'part_get_mbr_part_type' API in OCaml.
  daemon: list-filesystems: Don't list partitions which cannot hold file
    system.
 daemon/listfs.ml                        | 130 +++++++++++++++---------
 daemon/parted.c                         | 106 -------------------
 daemon/parted.ml                        |  13 +++
 generator/actions_core.ml               |   1 +
 tests/md/Makefile.am                    |   3 +-
 tests/md/test-partitioned-md-devices.sh |  79 ++++++++++++++
 6 files changed, 176 insertions(+), 156 deletions(-)
 create mode 100755 tests/md/test-partitioned-md-devices.sh
-- 
2.17.0
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 3/4] common/qemuopts: use the old pointer as realloc pointer
                                
                                
                                
                                    
                                        by Pino Toscano
                                    
                                
                                
                                        Call realloc() directly with the pointer to the old data, instead of
assigning it to the destination variable, and using that one.  The rest
of the code is the same, already properly checking for the results of
realloc(), so this mostly help static code analyzers.
---
 common/qemuopts/qemuopts.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/common/qemuopts/qemuopts.c b/common/qemuopts/qemuopts.c
index c40d44783..b3e69e306 100644
--- a/common/qemuopts/qemuopts.c
+++ b/common/qemuopts/qemuopts.c
@@ -168,8 +168,7 @@ extend_options (struct qemuopts *qopts)
       qopts->nr_alloc = 1;
     else
       qopts->nr_alloc *= 2;
-    new_options = qopts->options;
-    new_options = realloc (new_options,
+    new_options = realloc (qopts->options,
                            qopts->nr_alloc * sizeof (struct qopt));
     if (new_options == NULL)
       return NULL;
@@ -421,8 +420,7 @@ qemuopts_append_arg_list (struct qemuopts *qopts, const char *value)
   if (value_copy == NULL)
     return -1;
 
-  new_values = qopt->values;
-  new_values = realloc (new_values, (len+2) * sizeof (char *));
+  new_values = realloc (qopt->values, (len+2) * sizeof (char *));
   if (new_values == NULL) {
     free (value_copy);
     return -1;
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 2/4] launch: libvirt: free format string
                                
                                
                                
                                    
                                        by Pino Toscano
                                    
                                
                                
                                        When the result guestfs_disk_format() is not known, free the string
before returning an error.
---
 lib/launch-libvirt.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index e4961f201..844023b80 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -197,6 +197,7 @@ get_source_format_or_autodetect (guestfs_h *g, struct drive *drv)
       error (g, _("could not auto-detect the format.\n"
                   "If the format is known, pass the format to libguestfs, eg. using the\n"
                   "‘--format’ option, or via the optional ‘format’ argument to ‘add-drive’."));
+      free (format);
       return NULL;
     }
 
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 1/4] daemon: upload: fix fd leak on lseek failure
                                
                                
                                
                                    
                                        by Pino Toscano
                                    
                                
                                
                                        Make sure to not leak the file descriptor in the upload() function, in
case lseek() fails.
---
 daemon/upload.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/daemon/upload.c b/daemon/upload.c
index 9de855f86..540a86437 100644
--- a/daemon/upload.c
+++ b/daemon/upload.c
@@ -111,6 +111,7 @@ upload (const char *filename, int flags, int64_t offset)
     if (lseek (fd, offset, SEEK_SET) == -1) {
       err = errno;
       ignore_value (cancel_receive ());
+      close (fd);
       errno = err;
       reply_with_perror ("lseek: %s", filename);
       return -1;
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH] common/mlpcre: fix access to freed memory
                                
                                
                                
                                    
                                        by Pino Toscano
                                    
                                
                                
                                        free_last_match() frees the memory of the match passed as argument, so
accessing it is not possible after free_last_match().  Since all we
need is the return code, save it locally for later usage.
---
 common/mlpcre/pcre-c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/common/mlpcre/pcre-c.c b/common/mlpcre/pcre-c.c
index da982025f..0762a8341 100644
--- a/common/mlpcre/pcre-c.c
+++ b/common/mlpcre/pcre-c.c
@@ -207,8 +207,9 @@ guestfs_int_pcre_matches (value rev, value strv)
 
   m->r = pcre_exec (re, NULL, m->subject, len, 0, 0, m->vec, veclen);
   if (m->r < 0 && m->r != PCRE_ERROR_NOMATCH) {
+    int ret = m->r;
     free_last_match (m);
-    raise_pcre_error ("pcre_exec", m->r);
+    raise_pcre_error ("pcre_exec", ret);
   }
 
   /* This error would indicate that pcre_exec ran out of space in the
-- 
2.14.3
                                
                         
                        
                                
                                7 years, 6 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH] libldm: fix enumeration of partition table entries
                                
                                
                                
                                    
                                        by Mykola Ivanets
                                    
                                
                                
                                        The commit fixes the bug in the code which inspects partition table
entries in order to find LDM Metadata partion:
_read_privhead_gpt function in ldm.c always calls gpt_get_pte
function with 0 (zero) as a second argument which causes the
described bug.
---
 src/ldm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ldm.c b/src/ldm.c
index 4897de9..943f095 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -1345,7 +1345,7 @@ _read_privhead_gpt(const int fd, const gchar * const path, const guint secsize,
 
     for (uint32_t i = 0; i < gpt.pte_array_len; i++) {
         gpt_pte_t pte;
-        r = gpt_get_pte(h, 0, &pte);
+        r = gpt_get_pte(h, i, &pte);
         if (r < 0) {
             _map_gpt_error(r, path, err);
             gpt_close(h);
                                
                         
                        
                                
                                7 years, 6 months