[PATCH] part-list: add support for show partition type
by Chen Hanxiao
We lack of showing parttition type for part-list command.
This patch will add support for this.
Also 'parted -m' did not provide partition type info,
remove code section for 'parted -m' process.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/parted.c | 155 ++++++++++++++++++++++++++-------------------------
generator/structs.ml | 1 +
resize/resize.ml | 2 +-
3 files changed, 82 insertions(+), 76 deletions(-)
diff --git a/daemon/parted.c b/daemon/parted.c
index a7bcb99..312b15f 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -33,6 +33,10 @@ GUESTFSD_EXT_CMD(str_parted, parted);
GUESTFSD_EXT_CMD(str_sfdisk, sfdisk);
GUESTFSD_EXT_CMD(str_sgdisk, sgdisk);
+#ifndef PARTED_NO_M
+# define PARTED_NO_M 0
+#endif
+
/* Notes:
*
* Parted 1.9 sends error messages to stdout, hence use of the
@@ -451,11 +455,7 @@ do_part_get_parttype (const char *device)
guestfs_int_partition_list *
do_part_list (const char *device)
{
- int parted_has_m_opt = test_parted_m_opt ();
- if (parted_has_m_opt == -1)
- return NULL;
-
- CLEANUP_FREE char *out = print_partition_table (device, parted_has_m_opt);
+ CLEANUP_FREE char *out = print_partition_table (device, PARTED_NO_M);
if (!out)
return NULL;
@@ -466,88 +466,86 @@ do_part_list (const char *device)
guestfs_int_partition_list *r;
- if (parted_has_m_opt) {
- /* New-style parsing using the "machine-readable" format from
- * 'parted -m'.
- *
- * lines[0] is "BYT;", lines[1] is the device line which we ignore,
- * lines[2..] are the partitions themselves. Count how many.
- */
- size_t nr_rows = 0, row;
- for (row = 2; lines[row] != NULL; ++row)
- ++nr_rows;
-
- r = malloc (sizeof *r);
- if (r == NULL) {
- reply_with_perror ("malloc");
- return NULL;
+ /* Old-style. Start at the line following "^Number", up to the
+ * next blank line.
+ */
+ size_t start = 0, end = 0, has_type = 0, row;
+
+ for (row = 0; lines[row] != NULL; ++row)
+ if (STRPREFIX (lines[row], "Number")) {
+ start = row+1;
+ /* check whether output of parted has 'Type' field */
+ if (strstr (lines[row], "Type"))
+ has_type = 1;
+ break;
}
- r->guestfs_int_partition_list_len = nr_rows;
- r->guestfs_int_partition_list_val =
- malloc (nr_rows * sizeof (guestfs_int_partition));
- if (r->guestfs_int_partition_list_val == NULL) {
- reply_with_perror ("malloc");
- goto error2;
+
+ if (start == 0) {
+ reply_with_error ("parted output has no \"Number\" line");
+ return NULL;
+ }
+
+ for (row = start; lines[row] != NULL; ++row)
+ if (STREQ (lines[row], "")) {
+ end = row;
+ break;
}
- /* Now parse the lines. */
- size_t i;
- for (i = 0, row = 2; lines[row] != NULL; ++i, ++row) {
- if (sscanf (lines[row], "%d:%" SCNi64 "B:%" SCNi64 "B:%" SCNi64 "B",
+ if (end == 0) {
+ reply_with_error ("parted output has no blank after end of table");
+ return NULL;
+ }
+
+ size_t nr_rows = end - start;
+
+ r = malloc (sizeof *r);
+ if (r == NULL) {
+ reply_with_perror ("malloc");
+ return NULL;
+ }
+ r->guestfs_int_partition_list_len = nr_rows;
+ r->guestfs_int_partition_list_val =
+ malloc (nr_rows * sizeof (guestfs_int_partition));
+ if (r->guestfs_int_partition_list_val == NULL) {
+ reply_with_perror ("malloc");
+ goto error2;
+ }
+
+ /* Now parse the lines. */
+ size_t i, k;
+ if (has_type) {
+ /* hold type such as primary, logical and extended */
+ char type_temp[16];
+ for (i = 0, row = start; row < end; ++i, ++row) {
+ if (sscanf (lines[row], " %d %" SCNi64 "B %" SCNi64 "B %" SCNi64 "B" "%s",
&r->guestfs_int_partition_list_val[i].part_num,
&r->guestfs_int_partition_list_val[i].part_start,
&r->guestfs_int_partition_list_val[i].part_end,
- &r->guestfs_int_partition_list_val[i].part_size) != 4) {
+ &r->guestfs_int_partition_list_val[i].part_size,
+ type_temp) != 5) {
reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
goto error3;
}
- }
- }
- else {
- /* Old-style. Start at the line following "^Number", up to the
- * next blank line.
- */
- size_t start = 0, end = 0, row;
- for (row = 0; lines[row] != NULL; ++row)
- if (STRPREFIX (lines[row], "Number")) {
- start = row+1;
- break;
+ if (STRPREFIX (type_temp, "primary")) {
+ r->guestfs_int_partition_list_val[i].part_type = strdup("primary");
+ if (r->guestfs_int_partition_list_val[i].part_type == NULL)
+ goto error4;
+ } else if (STRPREFIX (type_temp, "logical")) {
+ r->guestfs_int_partition_list_val[i].part_type = strdup("logical");
+ if (r->guestfs_int_partition_list_val[i].part_type == NULL)
+ goto error4;
+ } else if (STRPREFIX (type_temp, "extended")) {
+ r->guestfs_int_partition_list_val[i].part_type = strdup("extended");
+ if (r->guestfs_int_partition_list_val[i].part_type == NULL)
+ goto error4;
+ } else {
+ r->guestfs_int_partition_list_val[i].part_type = strdup("");
+ if (r->guestfs_int_partition_list_val[i].part_type == NULL)
+ goto error4;
}
-
- if (start == 0) {
- reply_with_error ("parted output has no \"Number\" line");
- return NULL;
}
-
- for (row = start; lines[row] != NULL; ++row)
- if (STREQ (lines[row], "")) {
- end = row;
- break;
- }
-
- if (end == 0) {
- reply_with_error ("parted output has no blank after end of table");
- return NULL;
- }
-
- size_t nr_rows = end - start;
-
- r = malloc (sizeof *r);
- if (r == NULL) {
- reply_with_perror ("malloc");
- return NULL;
- }
- r->guestfs_int_partition_list_len = nr_rows;
- r->guestfs_int_partition_list_val =
- malloc (nr_rows * sizeof (guestfs_int_partition));
- if (r->guestfs_int_partition_list_val == NULL) {
- reply_with_perror ("malloc");
- goto error2;
- }
-
- /* Now parse the lines. */
- size_t i;
+ } else {
for (i = 0, row = start; row < end; ++i, ++row) {
if (sscanf (lines[row], " %d %" SCNi64 "B %" SCNi64 "B %" SCNi64 "B",
&r->guestfs_int_partition_list_val[i].part_num,
@@ -557,11 +555,18 @@ do_part_list (const char *device)
reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
goto error3;
}
+
+ r->guestfs_int_partition_list_val[i].part_type = strdup("");
+ if (r->guestfs_int_partition_list_val[i].part_type == NULL)
+ goto error4;
}
}
return r;
+ error4:
+ for (k = 0; k <= i; k++)
+ free (r->guestfs_int_partition_list_val[k].part_type);
error3:
free (r->guestfs_int_partition_list_val);
error2:
diff --git a/generator/structs.ml b/generator/structs.ml
index ea110a1..e7a9fa6 100644
--- a/generator/structs.ml
+++ b/generator/structs.ml
@@ -240,6 +240,7 @@ let structs = [
"part_start", FBytes;
"part_end", FBytes;
"part_size", FBytes;
+ "part_type", FString;
];
s_camel_name = "Partition" };
diff --git a/resize/resize.ml b/resize/resize.ml
index 84fd6d4..8f8f67f 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -1078,7 +1078,7 @@ read the man page virt-resize(1).
*)
p_name = "";
p_part = { G.part_num = 0l; part_start = 0L; part_end = 0L;
- part_size = 0L };
+ part_size = 0L; part_type = "" };
p_bootable = false; p_id = No_ID; p_type = ContentUnknown;
p_label = None; p_guid = None;
--
2.1.0
9 years, 8 months
Re: [Libguestfs] Name resolution not working inside virt-customize
by Richard W.M. Jones
[Please keep replies on the list]
On Mon, Mar 16, 2015 at 09:28:28AM -0400, Lee Revell wrote:
> On 03/16/2015 09:14 AM, Lee Revell wrote:
> >>This explains why the network doesn't work and why dhclient doesn't
> >>work too. I don't know why virtio-net isn't used -- perhaps it isn't
> >>compiled into your host kernel.
> >
>
> leer@eng-leer:~$ grep VIRTIO_NET /boot/config-3.16.0-31-generic
> CONFIG_VIRTIO_NET=y
If you look at the logs you provided, ethX isn't appearing in the
guest, so something is wrong.
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
9 years, 8 months
Name resolution not working inside virt-customize
by Lee Revell
Hi!
I am trying to use virt-customize to add packages to an image. However
it seems that there is a problem where a resolv.conf is not being
installed and thus package installation fails.
The command is:
virt-customize -v -x -a trusty-server-cloudimg-amd64-disk1.img
--run-command "host openstack.org"
I am having a hard time gathering complete output as the command seems
to corrupt my terminal somehow but I think the relevant lines may be:
[ 3.0] Running: host openstack.org
running command:
exec >>'/tmp/builder.log' 2>&1
host openstack.org
libguestfs: trace: sh "exec >>'/tmp/builder.log' 2>&1\n\n\nhost
openstack.org\n"
guestfsd: main_loop: new request, len 0x60
mount --bind /dev /sysroot/dev
mount --bind /dev/pts /sysroot/dev/pts
mount: mount point /sysroot/dev/pts does not exist
mount --bind /proc /sysroot/proc
mount --bind /sys/fs/selinux /sysroot/selinux
mount: mount point /sysroot/selinux does not exist
mount --bind /sys /sysroot/sys
mount --bind /sys/fs/selinux /sysroot/sys/fs/selinux
mount: mount point /sysroot/sys/fs/selinux does not exist
renaming /sysroot/etc/resolv.conf to /sysroot/etc/g1fbx1fs
cp /etc/resolv.conf /sysroot/etc/resolv.conf
cp: cannot stat '/etc/resolv.conf': No such file or directory
/bin/sh -c exec >>'/tmp/builder.log' 2>&1
host openstack.org
And the command fails due to the missing resolv.conf.
I am using version 1.28.6 build from source on ubuntu 14.04. The same
image file listed above works perfectly when launched as an openstack
instance.
Thanks,
Lee Revell
9 years, 8 months
[PATCH] btrfs-qgroup-show: add check for "--raw"
by Chen Hanxiao
btrfs-prog commit:
58a39524619f38d193b8adc3d57888ec07b612aa
change the default output to binary prefix,
and introduced a new option '--raw'
to keep the traditional behaviour.
This patch will add a check function to determine
whether to add '--raw' option to 'btrfs show qgroup'.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index d4b3207..ddaf15b 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1210,12 +1210,43 @@ do_btrfs_qgroup_destroy (const char *qgroupid, const char *subvolume)
return 0;
}
+/* btrfs qgroup show command change default output to
+ * binary prefix since v3.18.2, such as KiB;
+ * also introduced '--raw' to keep traditional behaviour.
+ * We could check wheter 'btrfs qgroup show' support '--raw'
+ * option by checking the output of
+ * 'btrfs qgroup show' support --help' command.
+ */
+static int
+test_btrfs_qgroup_show_raw_opt (void)
+{
+ static int result = -1;
+ if (result > 0)
+ return result;
+
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+
+ int r = commandr (&out, &err, str_btrfs, "qgroup", "show", "--help", NULL);
+
+ if (r == -1) {
+ reply_with_error ("btrfs qgroup show --help: %s", err);
+ return -1;
+ }
+
+ if (!strstr (out, "--raw"))
+ result = 0;
+
+ return result;
+}
+
guestfs_int_btrfsqgroup_list *
do_btrfs_qgroup_show (const char *path)
{
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
size_t i = 0;
+ int btrfs_qgroup_show_raw_opt = test_btrfs_qgroup_show_raw_opt ();
CLEANUP_FREE char *path_buf = NULL;
CLEANUP_FREE char *err = NULL;
CLEANUP_FREE char *out = NULL;
@@ -1231,6 +1262,8 @@ do_btrfs_qgroup_show (const char *path)
ADD_ARG (argv, i, str_btrfs);
ADD_ARG (argv, i, "qgroup");
ADD_ARG (argv, i, "show");
+ if (btrfs_qgroup_show_raw_opt)
+ ADD_ARG (argv, i, "--raw");
ADD_ARG (argv, i, path_buf);
ADD_ARG (argv, i, NULL);
--
2.1.0
9 years, 8 months
[PATCH] generator: small optimization of pod2text cache memoization
by Pino Toscano
Instead of save every time there's a new element in the cache, batch the
saving to disk every 100 changes, saving the unsaved remainder at the
exit.
While not a big optimization, this reduces a bit the disk usage during
generator run.
---
generator/utils.ml | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/generator/utils.ml b/generator/utils.ml
index 3a62084..1b00ce5 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -291,10 +291,22 @@ let pod2text_memo : (memo_key, memo_value) Hashtbl.t =
v
with
_ -> Hashtbl.create 13
-let pod2text_memo_updated () =
+let pod2text_memo_unsaved_count = ref 0
+let pod2text_memo_atexit = ref false
+let pod2text_memo_save () =
let chan = open_out pod2text_memo_filename in
output_value chan pod2text_memo;
close_out chan
+let pod2text_memo_updated () =
+ if not (!pod2text_memo_atexit) then (
+ at_exit pod2text_memo_save;
+ pod2text_memo_atexit := true;
+ );
+ pod2text_memo_unsaved_count := !pod2text_memo_unsaved_count + 1;
+ if !pod2text_memo_unsaved_count >= 100 then (
+ pod2text_memo_save ();
+ pod2text_memo_unsaved_count := 0;
+ )
(* Useful if you need the longdesc POD text as plain text. Returns a
* list of lines.
--
2.1.0
9 years, 8 months
Invalid module format errors, supermin waits forever for /sys/block/sdb/dev to appear
by Lee Revell
After failing to get things to work on a Ubuntu 14.04 host I build a
fedora 21 environment to see if Ubuntu may have been the problem and
didn't get quite as far so here's an official report per the FAQ directions:
- Trying to get guests to build and have network access so package
management actions can be done before uploading to openstack image service.
- I ran ./run virt-builder fedora-18 -v -x (also tried fedora-21, same
issue)
- Using supermin 5.1.2, libguestfs 1.29.29 both built from source on
fedora 21 host with all updates. "yum-builddep libguestfs" was run first
to pull dependencies.
Short version is that I get a bunch of Invalid module format errors then
supermin waiting for /sys/block/sdb/dev to appear and it never does.
Full output attached.
Thanks,
Lee
9 years, 8 months
[PATCH] maint.mk: remove error_message_period check
by Chen Hanxiao
As discussed at:
https://www.redhat.com/archives/libguestfs/2014-September/msg00215.html
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
maint.mk | 7 -------
1 file changed, 7 deletions(-)
diff --git a/maint.mk b/maint.mk
index b6ec1b5..76759d4 100644
--- a/maint.mk
+++ b/maint.mk
@@ -408,13 +408,6 @@ sc_error_message_uppercase:
{ echo '$(ME): found capitalized error message' 1>&2; \
exit 1; } || :
-# Error messages should not end with a period
-sc_error_message_period:
- @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
- | grep -E '[^."]\."' && \
- { echo '$(ME): found error message ending in period' 1>&2; \
- exit 1; } || :
-
sc_file_system:
@prohibit=file''system \
ignore_case=1 \
--
2.1.0
9 years, 8 months
[PATCH] guestfs.pod: fix a typo
by Chen Hanxiao
s/applicance/appliance
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/guestfs.pod | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 9749349..377db21 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -2461,7 +2461,7 @@ indicates a bug in libguestfs.
=back
-Libguestfs tries to convert the errno from inside the applicance into
+Libguestfs tries to convert the errno from inside the appliance into
a corresponding errno for the caller (not entirely trivial: the
appliance might be running a completely different operating system
from the library and error numbers are not standardized across
--
2.1.0
9 years, 8 months
[PATCH 0/1] v2v: Add the test-harness used by external tests.
by Richard W.M. Jones
As I'm now working through the enormous virt-v2v/virt-p2v bug list, we
need a high quality set of tests to ensure that we don't accidentally
regress some old OS/hypervisor combination while making changes.
The test cases are going to be huge, so we cannot possibly distribute
them in libguestfs. Furthermore many of them have licensing problems
which means we cannot redistribute them at all.
This commit adds a test harness which can be used by two external test
suites - a free one containing the redistributable test cases, and a
proprietary one. Both will link to the same test harness provided by
this commit.
For more information, see the 'virt-v2v-test-harness(1)' man page.
Rich.
9 years, 8 months