[PATCH] fish: Set program name correctly for virt-{copy, tar}-{in, out} programs.
by Richard W.M. Jones
Set the (libguestfs handle) program name correctly when running
programs like virt-copy-in, so the program name is not "guestfish" but
"virt-copy-in".
Note this feature cannot be tested using the ./run script, since
libtool (buggily) resets the program name to "lt-guestfish". However
I tested it on the installed copy and it worked there.
---
fish/virt-copy-in | 2 +-
fish/virt-copy-out | 2 +-
fish/virt-tar-in | 2 +-
fish/virt-tar-out | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fish/virt-copy-in b/fish/virt-copy-in
index d1be1b2..4bdccfb 100755
--- a/fish/virt-copy-in
+++ b/fish/virt-copy-in
@@ -24,4 +24,4 @@ for arg in $@; do
esac
done
-exec guestfish --rw -i copy-in "$@"
+exec -a "$0" guestfish --rw -i copy-in "$@"
diff --git a/fish/virt-copy-out b/fish/virt-copy-out
index 2648a4d..ff69388 100755
--- a/fish/virt-copy-out
+++ b/fish/virt-copy-out
@@ -24,4 +24,4 @@ for arg in $@; do
esac
done
-exec guestfish --ro -i copy-out "$@"
+exec -a "$0" guestfish --ro -i copy-out "$@"
diff --git a/fish/virt-tar-in b/fish/virt-tar-in
index dca1bbe..066f27d 100755
--- a/fish/virt-tar-in
+++ b/fish/virt-tar-in
@@ -24,4 +24,4 @@ for arg in $@; do
esac
done
-exec guestfish --rw -i tar-in "$@"
+exec -a "$0" guestfish --rw -i tar-in "$@"
diff --git a/fish/virt-tar-out b/fish/virt-tar-out
index 4a83e40..9cc6d7e 100755
--- a/fish/virt-tar-out
+++ b/fish/virt-tar-out
@@ -24,4 +24,4 @@ for arg in $@; do
esac
done
-exec guestfish --ro -i tar-out "$@"
+exec -a "$0" guestfish --ro -i tar-out "$@"
--
2.5.0
8 years, 9 months
[PATCH 1/2] v2v: -o libvirt: Refactor video and graphics elements.
by Richard W.M. Jones
This is just a refactoring and doesn't change the meaning of the code.
---
v2v/output_libvirt.ml | 60 +++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 31 deletions(-)
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 68af3de..d1cbaa1 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -222,46 +222,44 @@ let create_libvirt_xml ?pool source target_buses guestcaps
(* Same as old virt-v2v, we always add a display here even if it was
* missing from the old metadata.
*)
- let video, graphics =
- let video_model, graphics =
+ let video =
+ let video_model =
match guestcaps.gcaps_video with
- | QXL ->
- e "model" [ "type", "qxl"; "ram", "65536" ] [],
- e "graphics" [ "type", "vnc" ] []
- | Cirrus ->
- e "model" [ "type", "cirrus"; "vram", "9216" ] [],
- e "graphics" [ "type", "spice" ] [] in
-
+ | QXL -> e "model" [ "type", "qxl"; "ram", "65536" ] []
+ | Cirrus -> e "model" [ "type", "cirrus"; "vram", "9216" ] [] in
append_attr ("heads", "1") video_model;
- let video = e "video" [] [ video_model ] in
+ e "video" [] [ video_model ] in
- (match source.s_display with
- | Some { s_keymap = Some km } -> append_attr ("keymap", km) graphics
- | _ -> ());
- (match source.s_display with
- | Some { s_password = Some pw } -> append_attr ("passwd", pw) graphics
- | _ -> ());
- (match source.s_display with
- | Some { s_listen = listen } ->
+ let graphics =
+ match guestcaps.gcaps_video with
+ | QXL -> e "graphics" [ "type", "vnc" ] []
+ | Cirrus -> e "graphics" [ "type", "spice" ] [] in
+
+ (match source.s_display with
+ | Some { s_keymap = Some km } -> append_attr ("keymap", km) graphics
+ | _ -> ());
+ (match source.s_display with
+ | Some { s_password = Some pw } -> append_attr ("passwd", pw) graphics
+ | _ -> ());
+ (match source.s_display with
+ | Some { s_listen = listen } ->
(match listen with
- | LAddress a ->
- let sub = e "listen" [ "type", "address"; "address", a ] [] in
- append_child sub graphics
- | LNetwork n ->
- let sub = e "listen" [ "type", "network"; "network", n ] [] in
- append_child sub graphics
- | LNone -> ())
- | _ -> ());
- (match source.s_display with
- | Some { s_port = Some p } ->
+ | LAddress a ->
+ let sub = e "listen" [ "type", "address"; "address", a ] [] in
+ append_child sub graphics
+ | LNetwork n ->
+ let sub = e "listen" [ "type", "network"; "network", n ] [] in
+ append_child sub graphics
+ | LNone -> ())
+ | _ -> ());
+ (match source.s_display with
+ | Some { s_port = Some p } ->
append_attr ("autoport", "no") graphics;
append_attr ("port", string_of_int p) graphics
- | _ ->
+ | _ ->
append_attr ("autoport", "yes") graphics;
append_attr ("port", "-1") graphics);
- video, graphics in
-
let sound =
match source.s_sound with
| None -> []
--
2.5.0
8 years, 9 months
[PATCH] listfs: ignore the default btrfs subvolume
by Pino Toscano
When listing the subvolumes of a btrfs filesystem, ignore the default
subvolume: we get the content of it when mounting the whole device
(without specifying any particular subvolume), so avoid listing it
twice.
---
src/listfs.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/listfs.c b/src/listfs.c
index 98e74c7..de3b6f5 100644
--- a/src/listfs.c
+++ b/src/listfs.c
@@ -169,8 +169,17 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct stringsbuf *sb)
if (vols == NULL)
return -1;
+ int64_t default_volume = guestfs_btrfs_subvolume_get_default (g, device);
+
for (size_t i = 0; i < vols->len; i++) {
struct guestfs_btrfssubvolume *this = &vols->val[i];
+
+ /* Ignore the default subvolume. We get it by simply mounting
+ * the whole device of this btrfs filesystem.
+ */
+ if (this->btrfssubvolume_id == (uint64_t) default_volume)
+ continue;
+
guestfs_int_add_sprintf (g, sb,
"btrfsvol:%s/%s",
device, this->btrfssubvolume_path);
--
2.5.0
8 years, 9 months
New committer: Roman Kagan
by Richard W.M. Jones
I'm happy to announce that I've added Roman Kagan as a committer to
the https://github.com/libguestfs/libguestfs repo. Roman has
contributed many high quality patches over a period of one year.
Roman, the rules are:
- Post patches first on the mailing list.
- Uncontroversial patches should receive one ACK before being pushed
upstream.
- Very complex or "controversial" changes should get two ACKs and
general agreement before being pushed upstream.
Thank you for your contributions to the project,
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
8 years, 9 months
[PATCH 1/3] src: generate code for printing contents of structs
by Pino Toscano
Extend the generator to generate a source (and the header for it) with
functions that print the content of a guestfs struct. The code is
modelled after the code for it in fish.ml, although made a bit more
generic (destination FILE*, line separator) so it can be used also in
the library, when tracing.
This just introduces the new code and builds it as part of the helper
libutils.la.
---
.gitignore | 2 +
generator/c.ml | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
generator/c.mli | 2 +
generator/main.ml | 2 +
po/POTFILES | 1 +
src/Makefile.am | 6 ++-
6 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 40bebb3..1493011 100644
--- a/.gitignore
+++ b/.gitignore
@@ -468,6 +468,8 @@ Makefile.in
/src/structs-compare.c
/src/structs-copy.c
/src/structs-free.c
+/src/structs-print.c
+/src/structs-print.h
/src/test-utils
/stamp-h1
/sysprep/.depend
diff --git a/generator/c.ml b/generator/c.ml
index 417e2bc..9af4529 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -1204,6 +1204,130 @@ and generate_client_structs_cleanup () =
) structs
+(* Generate structs-print.c file. *)
+and generate_client_structs_print_c () =
+ generate_header CStyle LGPLv2plus;
+
+ pr "\
+#include <config.h>
+
+#include <inttypes.h>
+
+#include \"c-ctype.h\"
+
+#include \"guestfs.h\"
+#include \"structs-print.h\"
+
+";
+
+ let write_structs =
+ List.iter (
+ fun { s_name = typ; s_cols = cols } ->
+ let needs_i =
+ List.exists (function (_, (FUUID|FBuffer)) -> true | _ -> false) cols in
+
+ pr "void\n";
+ pr "guestfs_int_print_%s_indent (struct guestfs_%s *%s, FILE *dest, const char *linesep, const char *indent)\n"
+ typ typ typ;
+ pr "{\n";
+ if needs_i then (
+ pr " size_t i;\n";
+ pr "\n"
+ );
+ List.iter (
+ function
+ | name, FString ->
+ pr " fprintf (dest, \"%%s%s: %%s%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FUUID ->
+ pr " fprintf (dest, \"%%s%s: \", indent);\n" name;
+ pr " for (i = 0; i < 32; ++i)\n";
+ pr " fprintf (dest, \"%%c\", %s->%s[i]);\n" typ name;
+ pr " fprintf (dest, \"%%s\", linesep);\n"
+ | name, FBuffer ->
+ pr " fprintf (dest, \"%%s%s: \", indent);\n" name;
+ pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name;
+ pr " if (c_isprint (%s->%s[i]))\n" typ name;
+ pr " fprintf (dest, \"%%c\", %s->%s[i]);\n" typ name;
+ pr " else\n";
+ pr " fprintf (dest, \"\\\\x%%02x\", (unsigned) %s->%s[i]);\n"
+ typ name;
+ pr " fprintf (dest, \"%%s\", linesep);\n"
+ | name, (FUInt64|FBytes) ->
+ pr " fprintf (dest, \"%%s%s: %%\" PRIu64 \"%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FInt64 ->
+ pr " fprintf (dest, \"%%s%s: %%\" PRIi64 \"%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FUInt32 ->
+ pr " fprintf (dest, \"%%s%s: %%\" PRIu32 \"%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FInt32 ->
+ pr " fprintf (dest, \"%%s%s: %%\" PRIi32 \"%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FChar ->
+ pr " fprintf (dest, \"%%s%s: %%c%%s\", indent, %s->%s, linesep);\n"
+ name typ name
+ | name, FOptPercent ->
+ pr " if (%s->%s >= 0)\n" typ name;
+ pr " fprintf (dest, \"%%s%s: %%g %%%%%%s\", indent, (double) %s->%s, linesep);\n"
+ name typ name;
+ pr " else\n";
+ pr " fprintf (dest, \"%%s%s: %%s\", indent, linesep);\n" name
+ ) cols;
+ pr "}\n";
+ pr "\n";
+ ) in
+
+ write_structs external_structs;
+
+ pr "\
+#if GUESTFS_PRIVATE
+
+";
+
+ write_structs internal_structs;
+
+ pr "\
+#endif /* End of GUESTFS_PRIVATE. */
+"
+
+(* Generate structs-print.h file. *)
+and generate_client_structs_print_h () =
+ generate_header CStyle LGPLv2plus;
+
+ pr "\
+#ifndef GUESTFS_INTERNAL_STRUCTS_PRINT_H_
+#define GUESTFS_INTERNAL_STRUCTS_PRINT_H_
+
+#include <stdio.h>
+
+";
+
+ let write_structs =
+ List.iter (
+ fun { s_name = name } ->
+ pr "extern void guestfs_int_print_%s_indent (struct guestfs_%s *%s, FILE *dest, const char *linesep, const char *indent);\n"
+ name name name
+ ) in
+
+ write_structs external_structs;
+
+ pr "\
+
+#if GUESTFS_PRIVATE
+
+";
+
+ write_structs internal_structs;
+
+ pr "\
+
+#endif /* End of GUESTFS_PRIVATE. */
+
+#endif /* GUESTFS_INTERNAL_STRUCTS_PRINT_H_ */
+"
+
(* Generate the client-side dispatch stubs. *)
and generate_client_actions hash () =
generate_header CStyle LGPLv2plus;
diff --git a/generator/c.mli b/generator/c.mli
index 9a261a4..156b244 100644
--- a/generator/c.mli
+++ b/generator/c.mli
@@ -32,6 +32,8 @@ val generate_client_structs_cleanup : unit -> unit
val generate_client_structs_compare : unit -> unit
val generate_client_structs_copy : unit -> unit
val generate_client_structs_free : unit -> unit
+val generate_client_structs_print_h : unit -> unit
+val generate_client_structs_print_c : unit -> unit
val generate_event_string_c : unit -> unit
val generate_guestfs_h : unit -> unit
val generate_internal_actions_h : unit -> unit
diff --git a/generator/main.ml b/generator/main.ml
index 63a5d25..8d08d83 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -99,6 +99,8 @@ Run it from the top source directory using the command
output_to "src/structs-copy.c" generate_client_structs_copy;
output_to "src/structs-free.c" generate_client_structs_free;
output_to "src/structs-cleanup.c" generate_client_structs_cleanup;
+ output_to "src/structs-print.c" generate_client_structs_print_c;
+ output_to "src/structs-print.h" generate_client_structs_print_h;
output_to "src/actions-variants.c" generate_client_actions_variants;
for i = 0 to nr_actions_files-1 do
diff --git a/po/POTFILES b/po/POTFILES
index 2a1e313..0fb99b0 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -353,6 +353,7 @@ src/structs-cleanup.c
src/structs-compare.c
src/structs-copy.c
src/structs-free.c
+src/structs-print.c
src/test-utils.c
src/tmpdirs.c
src/utils.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 3ebb7f5..60641bf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,7 +46,9 @@ generator_built = \
structs-cleanup.c \
structs-compare.c \
structs-copy.c \
- structs-free.c
+ structs-free.c \
+ structs-print.c \
+ structs-print.h
BUILT_SOURCES = \
$(generator_built) \
@@ -226,6 +228,8 @@ endif
libutils_la_SOURCES = \
cleanup.c \
structs-cleanup.c \
+ structs-print.c \
+ structs-print.h \
utils.c
libutils_la_CPPFLAGS = $(libguestfs_la_CPPFLAGS)
libutils_la_CFLAGS = $(libguestfs_la_CFLAGS)
--
2.5.0
8 years, 9 months
Re: [Libguestfs] guestmount without fstab
by Richard W.M. Jones
[A question about whether it is possible to use guestmount on a guest
which does not have /etc/fstab. I've no reproduced this because I'm
CC-ing my reply to a public mailing list]
It's definitely possible. I would suggest first using
$ virt-filesystems -a disk.img --all --long -h
to get an idea of what's inside your disk image, then you
use a command such as:
$ guestmount -a disk.img -m /dev/sda1 /tmp/mnt
As for the particular question about lack of /etc/fstab. Are you
getting some kind of error when using the guestmount -i option? It
used to be (a long time ago) that libguestfs inspection[1] could not
handle guests that did not have /etc/fstab, but that should be fixed
in recent versions.
If you mean, something which isn't a virtual machine disk image, then
of course libguestfs can handle these. See reference [2].
Rich.
[1] http://libguestfs.org/guestfs.3.html#inspection
[2] http://libguestfs.org/guestfs-faq.1.html#whats-the-deal-with-guestfish--i
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
8 years, 9 months
[PATCH] inspect: use /etc/hosts for detecting Linux root (RHBZ#1203898)
by Pino Toscano
Use /etc/hosts instead of /etc/fstab to detect whether a partition
represents the root of a Linux installation; the latter might not exist
in smaller/special installations like Docker images.
Put an empty /etc/hosts in all the phony Linux guests to keep them
detected as we want.
---
src/inspect-fs.c | 2 +-
test-data/phony-guests/make-archlinux-img.sh | 1 +
test-data/phony-guests/make-coreos-img.sh | 1 +
test-data/phony-guests/make-debian-img.sh | 1 +
test-data/phony-guests/make-fedora-img.pl | 1 +
test-data/phony-guests/make-ubuntu-img.sh | 1 +
6 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 02fdb2a..82e1254 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -217,7 +217,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
(is_dir_bin ||
(guestfs_is_symlink (g, "/bin") > 0 &&
guestfs_is_dir (g, "/usr/bin") > 0)) &&
- guestfs_is_file (g, "/etc/fstab") > 0) {
+ guestfs_is_file (g, "/etc/hosts") > 0) {
fs->is_root = 1;
fs->format = OS_FORMAT_INSTALLED;
if (guestfs_int_check_linux_root (g, fs) == -1)
diff --git a/test-data/phony-guests/make-archlinux-img.sh b/test-data/phony-guests/make-archlinux-img.sh
index 066df09..f748171 100755
--- a/test-data/phony-guests/make-archlinux-img.sh
+++ b/test-data/phony-guests/make-archlinux-img.sh
@@ -45,6 +45,7 @@ mkdir-p /var/lib/pacman/local/test-package-1:0.1-1
write /etc/fstab "/dev/sda1 / ext4 rw,relatime,data=ordered 0 1"
touch /etc/arch-release
+touch /etc/hosts
write /etc/hostname "archlinux.test"
upload $SRCDIR/archlinux-package /var/lib/pacman/local/test-package-1:0.1-1/desc
diff --git a/test-data/phony-guests/make-coreos-img.sh b/test-data/phony-guests/make-coreos-img.sh
index 1de2f25..e229926 100755
--- a/test-data/phony-guests/make-coreos-img.sh
+++ b/test-data/phony-guests/make-coreos-img.sh
@@ -76,6 +76,7 @@ write /etc/coreos/update.conf "GROUP=stable"
upload archlinux.release /usr/share/coreos/lsb-release
ln-s ../usr/share/coreos/lsb-release /etc/lsb-release
write /etc/hostname "coreos.invalid"
+touch /etc/hosts
EOF
diff --git a/test-data/phony-guests/make-debian-img.sh b/test-data/phony-guests/make-debian-img.sh
index 637bd4b..0b4f75e 100755
--- a/test-data/phony-guests/make-debian-img.sh
+++ b/test-data/phony-guests/make-debian-img.sh
@@ -81,6 +81,7 @@ mkdir /var/log
upload debian.fstab /etc/fstab
write /etc/debian_version "5.0.1"
write /etc/hostname "debian.invalid"
+touch /etc/hosts
upload $SRCDIR/debian-packages /var/lib/dpkg/status
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index 192f48f..b1098ba 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -211,6 +211,7 @@ $g->write ('/etc/motd', "Welcome to Fedora release 14 (Phony)\n");
$g->write ('/etc/redhat-release', 'Fedora release 14 (Phony)');
$g->write ('/etc/fedora-release', 'Fedora release 14 (Phony)');
$g->write ('/etc/sysconfig/network', 'HOSTNAME=fedora.invalid');
+$g->touch ('/etc/hosts');
if (-f "fedora.mdadm") {
$g->upload ("fedora.mdadm", '/etc/mdadm.conf');
diff --git a/test-data/phony-guests/make-ubuntu-img.sh b/test-data/phony-guests/make-ubuntu-img.sh
index a3aa610..b49e8ff 100755
--- a/test-data/phony-guests/make-ubuntu-img.sh
+++ b/test-data/phony-guests/make-ubuntu-img.sh
@@ -72,6 +72,7 @@ upload ubuntu.fstab /etc/fstab
write /etc/debian_version "5.0.1"
upload ubuntu.release /etc/lsb-release
write /etc/hostname "ubuntu.invalid"
+touch /etc/hosts
upload $SRCDIR/debian-packages /var/lib/dpkg/status
--
2.5.0
8 years, 9 months
[PATCH] inspect: check also /etc/hosts for detecting Linux root (RHBZ#1203898)
by Pino Toscano
Use /etc/hosts as alternative of /etc/fstab to detect whether a partition
represents the root of a Linux installation; the latter might not exist
in smaller/special installations like Docker images.
---
src/inspect-fs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 02fdb2a..ad175f8 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -217,7 +217,8 @@ check_filesystem (guestfs_h *g, const char *mountable,
(is_dir_bin ||
(guestfs_is_symlink (g, "/bin") > 0 &&
guestfs_is_dir (g, "/usr/bin") > 0)) &&
- guestfs_is_file (g, "/etc/fstab") > 0) {
+ (guestfs_is_file (g, "/etc/fstab") > 0 ||
+ guestfs_is_file (g, "/etc/hosts") > 0)) {
fs->is_root = 1;
fs->format = OS_FORMAT_INSTALLED;
if (guestfs_int_check_linux_root (g, fs) == -1)
--
2.5.0
8 years, 9 months
Re: [Libguestfs] virt-customize network issue
by Richard W.M. Jones
[Please send all questions to the mailing list]
On Tue, Feb 23, 2016 at 08:48:50PM -0600, Brendan Hoffmann wrote:
> Hello there,
>
> I seem to be having some issue using virt-customize to update a virtual
> machine. Im using CentOS 7 on the host and guest with the latest packages.
Which version exactly?
> When I run virt-customize with the update parameter, I get output from yum
> stating there are resolution issues. My virbr0 network uses forwarding and
> another virtual machine handles the nat and dhcp for it. This network is
> also set as the 'default' and it works fine when i boot the machine as
> normal.
We would need to see the exact error messages. See:
http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
But at a guess you might try setting this:
http://libguestfs.org/guestfs.3.html#network_bridge
> Can you provide me some insight or at least point me in the right direction
> on how to set up the host machine to handle the networking for
> virt-customize and the other great utilities with it? I have been able to
> find very little information on Google.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
8 years, 9 months