[PATCH] inspect: Include more information for augeas parse errors (RHBZ#1229119)
by Richard W.M. Jones
If Augeas fails to parse a file, more information is available in at
least these fields:
><fs> aug-ls /augeas/files/etc/fstab/error
/augeas/files/etc/fstab/error/char
/augeas/files/etc/fstab/error/lens
/augeas/files/etc/fstab/error/line
/augeas/files/etc/fstab/error/message
/augeas/files/etc/fstab/error/pos
Pull out some of these fields and add them to the error message.
The new error message looks like this:
virt-v2v: error: libguestfs error: /etc/fstab:17:4: augeas parse failure:
Iterated lens matched less than it should
This updates commit 279addeb7dd4f5f2446a3995eb7704980c08b5ff.
---
src/inspect-fs-unix.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 968aa40..4fac7f4 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1985,7 +1985,6 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
CLEANUP_FREE char *pathexpr = NULL;
CLEANUP_FREE_STRING_LIST char **matches = NULL;
char **match;
- size_t len;
/* Security: Refuse to do this if a config file is too large. */
for (i = 0; configfiles[i] != NULL; ++i) {
@@ -2023,16 +2022,33 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
goto out;
/* Check that augeas did not get a parse error for any of the configfiles,
- * otherwise we are silently missing information. */
+ * otherwise we are silently missing information.
+ */
matches = guestfs_aug_match (g, "/augeas/files//error");
for (match = matches; *match != NULL; ++match) {
for (i = 0; configfiles[i] != NULL; ++i) {
- len = strlen (configfiles[i]);
- if (strlen (*match) == (13 /* len(/augeas/files) */ + len + 6 /* len(/error) */) &&
- STRPREFIX(*match, "/augeas/files") &&
- STREQLEN(*match + 13, configfiles[i], len) &&
- STREQ(*match + 13 + len, "/error")) {
- error (g, _("augeas could not parse %s"), configfiles[i]);
+ CLEANUP_FREE char *errorpath =
+ safe_asprintf (g, "/augeas/files%s/error", configfiles[i]);
+
+ if (STREQ (*match, errorpath)) {
+ /* Get the various error details. */
+ guestfs_push_error_handler (g, NULL, NULL);
+ CLEANUP_FREE char *messagepath =
+ safe_asprintf (g, "%s/message", errorpath);
+ CLEANUP_FREE char *message = guestfs_aug_get (g, messagepath);
+ CLEANUP_FREE char *linepath =
+ safe_asprintf (g, "%s/line", errorpath);
+ CLEANUP_FREE char *line = guestfs_aug_get (g, linepath);
+ CLEANUP_FREE char *charpath =
+ safe_asprintf (g, "%s/char", errorpath);
+ CLEANUP_FREE char *charp = guestfs_aug_get (g, charpath);
+ guestfs_pop_error_handler (g);
+
+ error (g, _("%s:%s:%s: augeas parse failure: %s"),
+ configfiles[i],
+ line ? : "<none>",
+ charp ? : "<none>",
+ message ? : "<none>");
goto out;
}
}
--
2.5.0
9 years, 2 months
[PATCH v2] inspect: check for errors in files parsed with augeas (RHBZ#1229119)
by Pino Toscano
During the inspection phase, check for errors after aug_load: if any of
the errors happened in any of the requested files, then report the error
straight away; ignoring the error means that information would be
silently lost. For example, a malformed /etc/fstab would have caused
the inspection to not handle any of the additional mount points, giving
cryptic errors later on when trying to access files in any of the mount
points.
Now guests with invalid files such as /etc/fstab, /etc/mdadm.conf, and
/etc/sysconfig/network will cause the inspection to fail, instead of
being reported with a single mount point ('/').
---
src/inspect-fs-unix.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 3d19276..968aa40 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1983,6 +1983,9 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
int64_t size;
int r;
CLEANUP_FREE char *pathexpr = NULL;
+ CLEANUP_FREE_STRING_LIST char **matches = NULL;
+ char **match;
+ size_t len;
/* Security: Refuse to do this if a config file is too large. */
for (i = 0; configfiles[i] != NULL; ++i) {
@@ -2019,6 +2022,22 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
if (guestfs_aug_load (g) == -1)
goto out;
+ /* Check that augeas did not get a parse error for any of the configfiles,
+ * otherwise we are silently missing information. */
+ matches = guestfs_aug_match (g, "/augeas/files//error");
+ for (match = matches; *match != NULL; ++match) {
+ for (i = 0; configfiles[i] != NULL; ++i) {
+ len = strlen (configfiles[i]);
+ if (strlen (*match) == (13 /* len(/augeas/files) */ + len + 6 /* len(/error) */) &&
+ STRPREFIX(*match, "/augeas/files") &&
+ STREQLEN(*match + 13, configfiles[i], len) &&
+ STREQ(*match + 13 + len, "/error")) {
+ error (g, _("augeas could not parse %s"), configfiles[i]);
+ goto out;
+ }
+ }
+ }
+
r = f (g, fs);
out:
--
2.1.0
9 years, 2 months
Re: [Libguestfs] Build libguestfs error with undefined reference to `guestfs_int_init_libvirt_backend'
by Richard W.M. Jones
[Please keep all replies on the list.]
On Fri, Oct 16, 2015 at 03:01:42AM +0300, Efstratios Skleparis wrote:
> Dear Richard,
>
> Yes I do have libvirt-dev installed already and virsh --version was : 0.9.8
> !
>
> - I tried to comment out the lines but still i got some errors due to that
> [ undeclared variables etc. ]
>
> - Made changes to files :
>
> src/guestfs-internal.h
>
> src/launch-libvirt.c
>
> src/launch.c
>
> As you mentioned on the patch but still had errors on building the
> library..
>
> Didn't save the error output because the solution was just to update
> libvirt , 0.9.8 version to a latter one has that bug as it seemed..
>
> I chose to update from 0.9.8 to 1.2.20 from tarball and finally I could
> build the library -> ./configure && make worked like charm [took like 6-8
> mins though : P] !!
>
> Thanks again for your time and your fast response !
--
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/
9 years, 2 months
Build libguestfs error with undefined reference to `guestfs_int_init_libvirt_backend'
by Efstratios Skleparis
Dear all,
I am trying to build libguestfs library on my system : Ubuntu Server 12.04
x64bit on XEN hypervisor.
I have followed all instructions on their homepage but whey i am trying to
build the library make -> gives me the following error: libguestfs.so:
undefined reference to `guestfs_int_init_libvirt_backend'
Here is a sample code of the error :
make[2]: Entering directory `/home/str/libguestfs-1.30.3/examples'
CCLD create-disk
../src/.libs/libguestfs.so: undefined reference to
`guestfs_int_init_libvirt_backend'
collect2: ld returned 1 exit status
make[2]: *** [create-disk] Error 1
make[2]: Leaving directory `/home/str/libguestfs-1.30.3/examples'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/str/libguestfs-1.30.3'
make: *** [all] Error 2
I have already installed all the dependencies for the library [sudo apt-get
build-dep libguestfs] and updated my automake version to 1.13[latest for
ubuntu 12.04] as i have read on another redhat list post [this one :
https://www.redhat.com/archives/libguestfs/2014-January/msg00015.html ] but
still nothing.. I must be missing something !
I haven't done anything rather than ./configure && make
Any tips/help would be appreciated.
Stratos
9 years, 2 months
[PATCH] inspect: check for errors in files parsed with augeas (RHBZ#1229119)
by Pino Toscano
During the inspection phase, check for errors after aug_load: if any of
the errors happened in any of the requested files, then report the error
straight away; ignoring the error means that information would be
silently lost. For example, a malformed /etc/fstab would have caused
the inspection to not handle any of the additional mount points, giving
cryptic errors later on when trying to access files in any of the mount
points.
Now guests with invalid files such as /etc/fstab, /etc/mdadm.conf, and
/etc/sysconfig/network will cause the inspection to fail, instead of
being reported with a single mount point ('/').
---
src/inspect-fs-unix.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 3d19276..e9822ca 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1983,6 +1983,9 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
int64_t size;
int r;
CLEANUP_FREE char *pathexpr = NULL;
+ CLEANUP_FREE_STRING_LIST char **matches = NULL;
+ char **match;
+ size_t len;
/* Security: Refuse to do this if a config file is too large. */
for (i = 0; configfiles[i] != NULL; ++i) {
@@ -2019,6 +2022,22 @@ inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs,
if (guestfs_aug_load (g) == -1)
goto out;
+ /* Check that augeas did not get a parse error for any of the configfiles,
+ * otherwise we are silently missing information. */
+ matches = guestfs_aug_match (g, "/augeas/files//error");
+ for (match = matches; *match != NULL; ++match) {
+ for (i = 0; configfiles[i] != NULL; ++i) {
+ len = strlen (configfiles[i]);
+ if (strlen (*match) == (13 /* len(/augeas/files) */ + len + 6 /* len(/error) */) &&
+ STRPREFIX(*match, "/augeas/files") &&
+ STREQLEN(*match + 13, configfiles[i], len) &&
+ STREQ(*match + 13 + len, "/error")) {
+ error (g, _("augeas could not parse %s"), configfiles[i]);
+ return -1;
+ }
+ }
+ }
+
r = f (g, fs);
out:
--
2.1.0
9 years, 2 months
[PATCH] Chop final '/' in output directory (RHBZ#1146753)
by Pino Toscano
If the specified output directory ends with a slash, chop it then;
leaving it in will create problems later, like creating the temporary
directory inside the output directory (and not aside it), and trying to
rename it to the directory containing it (which will fail indeed).
---
src/supermin.ml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/supermin.ml b/src/supermin.ml
index 9623229..3070b6b 100644
--- a/src/supermin.ml
+++ b/src/supermin.ml
@@ -186,6 +186,11 @@ let main () =
eprintf "supermin: output directory (-o option) must be supplied\n";
exit 1
);
+ (* Chop final '/' in output directory (RHBZ#1146753). *)
+ let outputdir =
+ let len = String.length outputdir in
+ if outputdir.[len - 1] == '/' then String.sub outputdir 0 (len - 1)
+ else outputdir in
debug, mode, if_newer, inputs, lockfile, outputdir,
(copy_kernel, dtb_wildcard, format, host_cpu,
--
2.1.0
9 years, 2 months
[PATCH 0/4] v2v: simplify driver copying from virtio-win iso
by Roman Kagan
Libguestfs supports passing an ISO image as a source of virtio windows
drivers to v2v.
That support, however, looks too heavy-weight: in order to access those
drivers, a separate guestfs handle is created (and thus a new emulator
process is started), which runs until v2v completes.
This series attempts to make it simpler and lighter-weight, by making
the relevant code more local, and by hot-adding the image into the main
guestfs handle.
Roman Kagan (4):
v2v: drop useless forced gc
v2v: consolidate virtio-win file copying
v2v: copy virtio drivers without guestfs handle leak
v2v: reuse main guestfs for virtio win drivers iso
v2v/convert_windows.ml | 184 ++++++++++++++++++++--------------------
v2v/utils.ml | 224 ++++++++++++++++---------------------------------
v2v/v2v.ml | 8 --
3 files changed, 163 insertions(+), 253 deletions(-)
--
2.4.3
9 years, 2 months
[PATCH 1/2] lib: info: Move common code for setting child rlimits.
by Richard W.M. Jones
This is almost just refactoring, but I also set the memory
limit to really 1 GB, and not 1×10⁹.
---
src/info.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/info.c b/src/info.c
index d7f45f0..616ef50 100644
--- a/src/info.c
+++ b/src/info.c
@@ -56,6 +56,7 @@ static yajl_val get_json_output (guestfs_h *g, const char *filename);
static char *old_parser_disk_format (guestfs_h *g, const char *filename);
static int64_t old_parser_disk_virtual_size (guestfs_h *g, const char *filename);
static int old_parser_disk_has_backing_file (guestfs_h *g, const char *filename);
+static void set_child_rlimits (struct command *);
char *
guestfs_impl_disk_format (guestfs_h *g, const char *filename)
@@ -276,12 +277,7 @@ get_json_output (guestfs_h *g, const char *filename)
guestfs_int_cmd_add_arg (cmd, fdpath);
guestfs_int_cmd_set_stdout_callback (cmd, parse_json, &tree,
CMD_STDOUT_FLAG_WHOLE_BUFFER);
-#ifdef RLIMIT_AS
- guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_AS, 1000000000 /* 1GB */);
-#endif
-#ifdef RLIMIT_CPU
- guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_CPU, 10 /* seconds */);
-#endif
+ set_child_rlimits (cmd);
r = guestfs_int_cmd_run (cmd);
close (fd);
if (r == -1)
@@ -560,12 +556,7 @@ old_parser_run_qemu_img_info (guestfs_h *g, const char *filename,
guestfs_int_cmd_add_arg (cmd, "info");
guestfs_int_cmd_add_arg (cmd, safe_filename);
guestfs_int_cmd_set_stdout_callback (cmd, fn, data, 0);
-#ifdef RLIMIT_AS
- guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_AS, 1000000000 /* 1GB */);
-#endif
-#ifdef RLIMIT_CPU
- guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_CPU, 10 /* seconds */);
-#endif
+ set_child_rlimits (cmd);
r = guestfs_int_cmd_run (cmd);
if (r == -1)
return -1;
@@ -576,3 +567,15 @@ old_parser_run_qemu_img_info (guestfs_h *g, const char *filename,
return 0;
}
+
+static void
+set_child_rlimits (struct command *cmd)
+{
+#ifdef RLIMIT_AS
+ const long one_gb = 1024L * 1024 * 1024;
+ guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_AS, one_gb);
+#endif
+#ifdef RLIMIT_CPU
+ guestfs_int_cmd_set_child_rlimit (cmd, RLIMIT_CPU, 10 /* seconds */);
+#endif
+}
--
2.5.0
9 years, 2 months
[PATCH] New API: resize2fs_P
by Maxim Perevedentsev
Added support for getting ext2/3/4 filesystem minimum size.
This is needed primarily for shrinking images.
---
daemon/ext2.c | 35 +++++++++++++++++++++++++++++++++++
generator/actions.ml | 10 ++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c
index ebaf0f0..3dae40f 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -279,6 +279,41 @@ do_resize2fs_M (const char *device)
return 0;
}
+int64_t
+do_resize2fs_P (const char *device)
+{
+ CLEANUP_FREE char *err = NULL, *out = NULL;
+ CLEANUP_FREE_STRING_LIST char **lines = NULL;
+ int r;
+ size_t i;
+ char *p;
+ int64_t ret;
+ char pattern[] = "Estimated minimum size of the filesystem: ";
+
+ r = command (&out, &err, str_resize2fs, "-P", device, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ return -1;
+ }
+
+ lines = split_lines (out);
+ if (lines == NULL)
+ return -1;
+
+ for (i = 0; lines[i] != NULL; ++i) {
+ if (verbose)
+ fprintf (stderr, "resize2fs-P: lines[%zu] = \"%s\"\n", i, lines[i]);
+
+ if ((p = strstr (lines[i], pattern))) {
+ if (sscanf (p + strlen(pattern), "%" SCNu64, &ret) != 1)
+ return -1;
+ return ret;
+ }
+ }
+
+ return -1;
+}
+
/* Takes optional arguments, consult optargs_bitmask. */
int
do_e2fsck (const char *device,
diff --git a/generator/actions.ml b/generator/actions.ml
index a76b466..7e2bfac 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12751,6 +12751,16 @@ Only some filesystem types support setting UUIDs.
To read the UUID on a filesystem, call C<guestfs_vfs_uuid>." };
+ { defaults with
+ name = "resize2fs_P"; added = (1, 31, 17);
+ style = RInt64 "sizeinblocks", [Device "device"], [];
+ proc_nr = Some 457;
+ shortdesc = "get minimum filesystem size in blocks";
+ longdesc = "\
+Get the minimum filesystem size in blocks.
+
+See also L<resize2fs(8)>." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 8d38505..de2a00c 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-456
+457
--
1.8.3.1
9 years, 2 months
[PATCH v2] New API: resize2fs_P
by Maxim Perevedentsev
Added support for getting ext2/3/4 filesystem minimum size.
This is needed primarily for shrinking images.
Difference to v1: added test, style fixes.
---
daemon/ext2.c | 35 +++++++++++++++++++++++++++++++++++
generator/actions.ml | 14 ++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c
index ebaf0f0..0cd6a66 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -279,6 +279,41 @@ do_resize2fs_M (const char *device)
return 0;
}
+int64_t
+do_resize2fs_P (const char *device)
+{
+ CLEANUP_FREE char *err = NULL, *out = NULL;
+ CLEANUP_FREE_STRING_LIST char **lines = NULL;
+ int r;
+ size_t i;
+ char *p;
+ int64_t ret;
+ const char *pattern = "Estimated minimum size of the filesystem: ";
+
+ r = command (&out, &err, str_resize2fs, "-P", device, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ return -1;
+ }
+
+ lines = split_lines (out);
+ if (lines == NULL)
+ return -1;
+
+ for (i = 0; lines[i] != NULL; ++i) {
+ if (verbose)
+ fprintf (stderr, "resize2fs_P: lines[%zu] = \"%s\"\n", i, lines[i]);
+
+ if ((p = strstr (lines[i], pattern))) {
+ if (sscanf (p + strlen(pattern), "%" SCNd64, &ret) != 1)
+ return -1;
+ return ret;
+ }
+ }
+
+ return -1;
+}
+
/* Takes optional arguments, consult optargs_bitmask. */
int
do_e2fsck (const char *device,
diff --git a/generator/actions.ml b/generator/actions.ml
index a76b466..78de100 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12751,6 +12751,20 @@ Only some filesystem types support setting UUIDs.
To read the UUID on a filesystem, call C<guestfs_vfs_uuid>." };
+ { defaults with
+ name = "resize2fs_P"; added = (1, 31, 17);
+ style = RInt64 "sizeinblocks", [Device "device"], [];
+ proc_nr = Some 457;
+ tests = [
+ InitBasicFS, Always, TestRun (
+ [["resize2fs_P"; "/dev/sda1"]]), [];
+ ];
+ shortdesc = "get minimum filesystem size in blocks";
+ longdesc = "\
+Get the minimum filesystem size in blocks.
+
+See also L<resize2fs(8)>." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 8d38505..de2a00c 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-456
+457
--
1.8.3.1
9 years, 2 months