[PATCH] python: Set program name to the true name instead of 'python'.
by Richard W.M. Jones
As in commit e102bcf3cfcbcb2b47ad88334f03d5abf636f1e5 (for Perl), any
Python program has the handle program name field set to 'python'. Set
it to the true name (derived from sys.argv[0]).
---
generator/python.ml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/generator/python.ml b/generator/python.ml
index c1128f8..1e043fc 100644
--- a/generator/python.ml
+++ b/generator/python.ml
@@ -671,6 +671,8 @@ logvols = g.lvs ()
\"\"\"
+import os
+import sys
import libguestfsmod
";
@@ -714,6 +716,10 @@ class GuestFS(object):
self._o = libguestfsmod.create (flags)
self._python_return_dict = python_return_dict
+ # If we don't do this, the program name is always set to 'python'.
+ program = os.path.basename (sys.argv[0])
+ libguestfsmod.set_program (self._o, program)
+
def __del__ (self):
if self._o:
libguestfsmod.close (self._o)
--
2.5.0
9 years, 1 month
Re: [Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
by Richard W.M. Jones
On Tue, Sep 15, 2015 at 05:17:16PM +0300, Maxim Perevedentsev wrote:
> On 09/15/2015 04:57 PM, Richard W.M. Jones wrote:
> >>2) More general, how to execute commands from appliance but make
> >>them run over image (which may not have anything but filesystem) - I
> >>saw something like that in source.
> >Not sure I understand the question?
>
> As I understand, guestfs runs its own kernel-like daemon that can
> run its own commands. It is used to run e.g. resize2fs or e2fsck
> over loaded disk images. But those two utilities require the
> partition not to be mounted, so they are run by daemon and do not
> require anything to exists on partition.
>
> In API I found only the 'command' command which requires the
> partition to be mounted and have kernel image on it. This cannot
> operate on empty or non-mounted partition.
You probably want to use the guestfs_debug API, ie:
char *cmd[] = { "resize2fs", "-P", ..., NULL };
char *ret = guestfs_debug (g, "sh", cmd);
It's better to add a new API however, and not difficult either:
http://libguestfs.org/guestfs.3.html#adding-a-new-api-action
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
9 years, 1 month
Question: running appliance commands over guest fs (resize2fs -P).
by Maxim Perevedentsev
Hello everyone!
I am working on resizing qcow2 images using virt-resize+liguestfs. E.g.
I when shrinking a partition, I have to resize filesystem using
resize2fs-size. The problem is that I cannot find out minimal partition
size (aka resize2fs -P). The only way is calling "resize2fs-size 1K",
wait for resize2fs to claim "resize2fs: New size smaller than minimum
(510050)" and parse this output.
It is known that resize2fs carries out complex calculations (no always
correct) to get minimal size, so statvfs/tune2fs-l cannot help.
The questions are:
1) How to get minimal partition size (equal to resize2fs -P)?
2) More general, how to execute commands from appliance but make them
run over image (which may not have anything but filesystem) - I saw
something like that in source.
Thanks in advance!
--
Your sincerely,
Maxim Perevedentsev
9 years, 1 month
Fwd: Re: Question: running appliance commands over guest fs (resize2fs -P).
by Maxim Perevedentsev
-------- Forwarded Message --------
Subject: Re: [Libguestfs] Question: running appliance commands over
guest fs (resize2fs -P).
Date: Tue, 15 Sep 2015 17:17:16 +0300
From: Maxim Perevedentsev <mperevedentsev(a)virtuozzo.com>
To: Richard W.M. Jones <rjones(a)redhat.com>
On 09/15/2015 04:57 PM, Richard W.M. Jones wrote:
>> 2) More general, how to execute commands from appliance but make
>> them run over image (which may not have anything but filesystem) - I
>> saw something like that in source.
> Not sure I understand the question?
>
> Rich.
As I understand, guestfs runs its own kernel-like daemon that can run
its own commands. It is used to run e.g. resize2fs or e2fsck over loaded
disk images. But those two utilities require the partition not to be
mounted, so they are run by daemon and do not require anything to exists
on partition.
In API I found only the 'command' command which requires the partition
to be mounted and have kernel image on it. This cannot operate on empty
or non-mounted partition.
So I wonder if there is a legal way to run arbitrary commands from
daemon but make them operate on non-mounted, possibly empty
images/partitions.
(Maybe I am missing something, I just run guestfish in verbose mode and
executed e2fsck and resize2fs).
--
Your sincerely,
Maxim Perevedentsev
9 years, 1 month
[PATCH] daemon: initrd: print return value from failing process
by Pino Toscano
If either zcat or cpio fails when spawned in initrd-list, pclose will
return the actual return value of it, but reply_with_perror still uses
errno regardless; thus, the reported error is:
libguestfs: error: initrd_list: pclose: Success
which is not much helpful.
Instead, when pclose returns > 0, extract the actual return value of the
subprocess, and print that. Thus now we get for example:
libguestfs: error: initrd_list: pclose: command failed with return code 1
---
daemon/initrd.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/daemon/initrd.c b/daemon/initrd.c
index ac14826..c9fc2dd 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -43,6 +43,7 @@ do_initrd_list (const char *path)
CLEANUP_FREE char *filename = NULL;
size_t allocsize;
ssize_t len;
+ int ret;
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */
if (asprintf_nowarn (&cmd, "%s %R | %s --quiet -it", str_zcat, path, str_cpio) == -1) {
@@ -74,8 +75,15 @@ do_initrd_list (const char *path)
return NULL;
}
- if (pclose (fp) != 0) {
- reply_with_perror ("pclose");
+ ret = pclose (fp);
+ if (ret != 0) {
+ if (ret == -1)
+ reply_with_perror ("pclose");
+ else {
+ if (WEXITSTATUS (ret) != 0)
+ ret = WEXITSTATUS (ret);
+ reply_with_error ("pclose: command failed with return code %d", ret);
+ }
free_stringslen (filenames.argv, filenames.size);
return NULL;
}
--
2.1.0
9 years, 1 month
Issue with python pip install
by John McDowall
I am trying to build a Python application installer that is using libguestfs. I using the instructions to create the python package posted at
https://github.com/libguestfs/libguestfs/commit/fcbfc4775fa2a440209740735...
I am getting errors in the compile when I do the "pip install”. I have attached the output from pip. I looked at the code and I do not see anything obvious)
When I do a yum install of python-libguestds.x86_64 the python interface works correctly.
Version/Platform Information
Platform: Centos-7
libguestfs version: 1.31..6
$ uname -a
Linux localhost.localdomain 3.10.0-229.11.1.el7.x86_64 #1 SMP Thu Aug 6 01:06:18 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ python --version
Python 2.7.5
Any help or suggestions would be appreciated.
Regards
John
9 years, 1 month
[PATCH] v2v: fix provides list whitespace trim
by Shahar Lev
Tabs should not be doubly-escaped in regexp.
Signed-off-by: Shahar Lev <shahar(a)stratoscale.com>
---
v2v/convert_linux.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index adbcaa2..1e9e689 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -581,7 +581,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source =
List.filter (fun s -> string_find s library = -1) provides in
(* Trim whitespace. *)
- let rex = Str.regexp "^[ \\t]*\\([^ \\t]+\\)[ \\t]*$" in
+ let rex = Str.regexp "^[ \t]*\\([^ \t]+\\)[ \t]*$" in
let provides = List.map (Str.replace_first rex "\\1") provides in
(* Install the dependencies with yum. Use yum explicitly
--
2.1.0
9 years, 1 month
libguestfs failure
by Todd Wright
This is a brand new CentOS7 with RDO allinone build. We can't launch any
instances.. Any help is greatly appreciated@!
Output from
libguestfs-test-tool
___________________________________
************************************************************
* IMPORTANT NOTICE
*
* When reporting bugs, include the COMPLETE, UNEDITED
* output below in your bug report.
*
************************************************************
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
SELinux: Enforcing
guestfs_get_append: (null)
guestfs_get_autosync: 1
guestfs_get_backend: libvirt
guestfs_get_backend_settings: []
guestfs_get_cachedir: /var/tmp
guestfs_get_direct: 0
guestfs_get_hv: /usr/libexec/qemu-kvm
guestfs_get_memsize: 500
guestfs_get_network: 0
guestfs_get_path: /usr/lib64/guestfs
guestfs_get_pgroup: 0
guestfs_get_program: libguestfs-test-tool
guestfs_get_recovery_proc: 1
guestfs_get_selinux: 0
guestfs_get_smp: 1
guestfs_get_tmpdir: /tmp
guestfs_get_trace: 0
guestfs_get_verbose: 1
host_cpu: x86_64
Launching appliance, timeout set to 600 seconds.
libguestfs: launch: program=libguestfs-test-tool
libguestfs: launch: version=1.28.1rhel=7,release=1.18.el7,libvirt
libguestfs: launch: backend registered: unix
libguestfs: launch: backend registered: uml
libguestfs: launch: backend registered: libvirt
libguestfs: launch: backend registered: direct
libguestfs: launch: backend=libvirt
libguestfs: launch: tmpdir=/tmp/libguestfsCiXvwb
libguestfs: launch: umask=0022
libguestfs: launch: euid=0
libguestfs: libvirt version = 1002008 (1.2.8)
libguestfs: guest random name = guestfs-ecwkqdns6qyvh9v5
libguestfs: [00000ms] connect to libvirt
libguestfs: opening libvirt handle: URI = qemu:///system, auth =
default+wrapper, flags = 0
libguestfs: successfully opened libvirt handle: conn = 0x7f7db27ccaa0
libguestfs: qemu version (reported by libvirt) = 1005003 (1.5.3)
libguestfs: [00034ms] get libvirt capabilities
libguestfs: [00056ms] parsing capabilities XML
libguestfs: [00056ms] build appliance
libguestfs: [00060ms] begin building supermin appliance
libguestfs: [00060ms] run supermin
libguestfs: command: run: /usr/bin/supermin5
libguestfs: command: run: \ --build
libguestfs: command: run: \ --verbose
libguestfs: command: run: \ --if-newer
libguestfs: command: run: \ --lock /var/tmp/.guestfs-0/lock
libguestfs: command: run: \ --copy-kernel
libguestfs: command: run: \ -f ext2
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib64/guestfs/supermin.d
libguestfs: command: run: \ -o /var/tmp/.guestfs-0/appliance.d
supermin: version: 5.1.10
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: acquiring lock on /var/tmp/.guestfs-0/lock
supermin: build: /usr/lib64/guestfs/supermin.d
supermin: build: visiting /usr/lib64/guestfs/supermin.d/base.tar.gz
type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/daemon.tar.gz
type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/excludefiles
type uncompressed excludefiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/hostfiles type
uncompressed hostfiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/init.tar.gz
type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/packages type
uncompressed packages
supermin: build: visiting
/usr/lib64/guestfs/supermin.d/udev-rules.tar.gz type gzip base image
(tar)
supermin: build: 185 packages, including dependencies
supermin: build: 30478 files
supermin: build: 17307 files, after removing unreadable files
supermin: build: 8695 files, after matching excludefiles
supermin: build: 8701 files, after adding hostfiles
supermin: build: 8731 files, after munging
supermin: kernel: picked kernel vmlinuz-3.10.0-229.el7.x86_64
supermin: kernel: picked modules path /lib/modules/3.10.0-229.el7.x86_64
supermin: kernel: kernel_version 3.10.0-229.el7.x86_64
supermin: kernel: modules /lib/modules/3.10.0-229.el7.x86_64
supermin: ext2: creating empty ext2 filesystem
'/var/tmp/.guestfs-0/appliance.d.uis3crjp/root'
supermin: ext2: populating from base image
supermin: ext2: copying files from host filesystem
supermin: ext2: copying kernel modules
supermin: ext2: creating minimal initrd
'/var/tmp/.guestfs-0/appliance.d.uis3crjp/initrd'
supermin: ext2: wrote 33 modules to minimal initrd
supermin: renaming /var/tmp/.guestfs-0/appliance.d.uis3crjp to
/var/tmp/.guestfs-0/appliance.d
libguestfs: [70256ms] finished building supermin appliance
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o
backing_file=/var/tmp/.guestfs-0/appliance.d/root,backing_fmt=raw
libguestfs: command: run: \ /tmp/libguestfsCiXvwb/overlay2
Formatting '/tmp/libguestfsCiXvwb/overlay2', fmt=qcow2 size=4294967296
backing_file='/var/tmp/.guestfs-0/appliance.d/root' backing_fmt='raw'
encryption=off cluster_size=65536 lazy_refcounts=off
libguestfs: [70525ms] create libvirt XML
libguestfs: command: run: dmesg | grep -Eoh 'lpj=[[:digit:]]+'
libguestfs: read_lpj_from_dmesg: calculated lpj=2811527
libguestfs: libvirt XML:\n<?xml version="1.0"?>\n<domain type="qemu"
xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">\n
<name>guestfs-ecwkqdns6qyvh9v5</name>\n <memory
unit="MiB">500</memory>\n <currentMemory
unit="MiB">500</currentMemory>\n <vcpu>1</vcpu>\n <clock
offset="utc">\n <timer name="rtc" tickpolicy="catchup"/>\n
<timer name="pit" tickpolicy="delay"/>\n <timer name="hpet"
present="no"/>\n </clock>\n <os>\n <type>hvm</type>\n
<kernel>/var/tmp/.guestfs-0/appliance.d/kernel</kernel>\n
<initrd>/var/tmp/.guestfs-0/appliance.d/initrd</initrd>\n
<cmdline>panic=1 console=ttyS0 udevtimeout=6000
udev.event-timeout=6000 no_timer_check lpj=2811527 acpi=off
printk.time=1 cgroup_disable=memory root=/dev/sdb selinux=0
guestfs_verbose=1 TERM=xterm-256color</cmdline>\n <bios
useserial="yes"/>\n </os>\n <on_reboot>destroy</on_reboot>\n
<devices>\n <controller type="scsi" index="0"
model="virtio-scsi"/>\n <disk device="disk" type="file">\n
<source file="/tmp/libguestfsCiXvwb/scratch.1"/>\n <target
dev="sda" bus="scsi"/>\n <driver name="qemu" type="raw"
cache="unsafe"/>\n <address type="drive" controller="0" bus="0"
target="0" unit="0"/>\n </disk>\n <disk type="file"
device="disk">\n <source
file="/tmp/libguestfsCiXvwb/overlay2"/>\n <target dev="sdb"
bus="scsi"/>\n <driver name="qemu" type="qcow2"
cache="unsafe"/>\n <address type="drive" controller="0" bus="0"
target="1" unit="0"/>\n <shareable/>\n </disk>\n <serial
type="unix">\n <source mode="connect"
path="/tmp/libguestfsCiXvwb/console.sock"/>\n <target
port="0"/>\n </serial>\n <channel type="unix">\n <source
mode="connect" path="/tmp/libguestfsCiXvwb/guestfsd.sock"/>\n
<target type="virtio" name="org.libguestfs.channel.0"/>\n
</channel>\n </devices>\n <qemu:commandline>\n <qemu:env
name="TMPDIR" value="/var/tmp"/>\n </qemu:commandline>\n</domain>\n
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -Z /var/tmp/.guestfs-0
libguestfs: drwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0 .
libguestfs: drwxrwxrwt. root root system_u:object_r:tmp_t:s0 ..
libguestfs: drwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0
appliance.d
libguestfs: -rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 lock
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -Z /tmp/libguestfsCiXvwb
libguestfs: drwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0 .
libguestfs: drwxrwxrwt. root root system_u:object_r:tmp_t:s0 ..
libguestfs: srw-rw----. root qemu unconfined_u:object_r:user_tmp_t:s0
console.sock
libguestfs: srw-rw----. root qemu unconfined_u:object_r:user_tmp_t:s0
guestfsd.sock
libguestfs: -rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 overlay2
libguestfs: -rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 scratch.1
libguestfs: -rwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0
umask-check
libguestfs: [70671ms] launch libvirt guest
libguestfs: error: could not create appliance through libvirt.
Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct
Original error from libvirt: internal error: process exited while
connecting to monitor: Cannot set up guest memory 'pc.ram': Cannot
allocate memory
[code=1 domain=10]
libguestfs-test-tool: failed to launch appliance
libguestfs: closing guestfs handle 0x7f7db27cc400 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsCiXvwb
9 years, 1 month