Nikos Skalkotos
2015-Jun-04 08:56 UTC
[Libguestfs] [PATCH] Use safe_realloc() in favor of realloc overall.
--- src/inspect-fs-unix.c | 22 +++++++--------------- src/inspect-fs.c | 21 ++++++--------------- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index 8ffd85d..c9bbad9 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -90,8 +90,8 @@ static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs); static int check_hostname_redhat (guestfs_h *g, struct inspect_fs *fs); static int check_hostname_freebsd (guestfs_h *g, struct inspect_fs *fs); static int check_fstab (guestfs_h *g, struct inspect_fs *fs); -static int add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, - const char *mountable, const char *mp); +static void add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, + const char *mountable, const char *mp); static char *resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, enum inspect_os_type os_type); @@ -850,8 +850,7 @@ guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs) /* CoreOS does not contain /etc/fstab to determine the mount points. * Associate this filesystem with the "/" mount point. */ - if (add_fstab_entry (g, fs, fs->mountable, "/") == -1) - return -1; + add_fstab_entry (g, fs, fs->mountable, "/"); return 0; } @@ -880,8 +879,7 @@ guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs) /* CoreOS does not contain /etc/fstab to determine the mount points. * Associate this filesystem with the "/usr" mount point. */ - if (add_fstab_entry (g, fs, fs->mountable, "/usr") == -1) - return -1; + add_fstab_entry (g, fs, fs->mountable, "/usr"); return 0; } @@ -1197,7 +1195,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs) } } - if (add_fstab_entry (g, fs, mountable, mp) == -1) return -1; + add_fstab_entry (g, fs, mountable, mp); } return 0; @@ -1211,7 +1209,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs) * * 'mp' is the mount point, which could also be 'swap' or 'none'. */ -static int +static void add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, const char *mountable, const char *mountpoint) { @@ -1222,11 +1220,7 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, size_t n = fs->nr_fstab + 1; struct inspect_fstab_entry *p; - p = realloc (fs->fstab, n * sizeof (struct inspect_fstab_entry)); - if (p == NULL) { - perrorf (g, "realloc"); - return -1; - } + p = safe_realloc (g, fs->fstab, n * sizeof (struct inspect_fstab_entry)); fs->fstab = p; fs->nr_fstab = n; @@ -1236,8 +1230,6 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, fs->fstab[n-1].mountpoint = safe_strdup (g, mountpoint); debug (g, "fstab: mountable=%s mountpoint=%s", mountable, mountpoint); - - return 0; } /* Compute a uuid hash as a simple xor of of its 4 32bit components */ diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 09a7005..073ae57 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -47,7 +47,7 @@ COMPILE_REGEXP (re_major_minor, "(\\d+)\\.(\\d+)", 0) static int check_filesystem (guestfs_h *g, const char *mountable, const struct guestfs_internal_mountable *m, int whole_device); -static int extend_fses (guestfs_h *g); +static void extend_fses (guestfs_h *g); static int get_partition_context (guestfs_h *g, const char *partition, int *partnum_ret, int *nr_partitions_ret); /* Find out if 'device' contains a filesystem. If it does, add @@ -75,8 +75,7 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char *mountable) mountable, vfs_type ? vfs_type : "failed to get vfs type"); if (is_swap) { - if (extend_fses (g) == -1) - return -1; + extend_fses (g); fs = &g->fses[g->nr_fses-1]; fs->mountable = safe_strdup (g, mountable); return 0; @@ -95,8 +94,7 @@ guestfs_int_check_for_filesystem_on (guestfs_h *g, const char *mountable) } if (whole_device) { - if (extend_fses (g) == -1) - return -1; + extend_fses (g); fs = &g->fses[g->nr_fses-1]; r = guestfs_int_check_installer_iso (g, fs, m->im_device); @@ -145,8 +143,7 @@ check_filesystem (guestfs_h *g, const char *mountable, /* Not CLEANUP_FREE, as it will be cleaned up with inspection info */ char *windows_systemroot = NULL; - if (extend_fses (g) == -1) - return -1; + extend_fses (g); if (!whole_device && m->im_type == MOUNTABLE_DEVICE && guestfs_int_is_partition (g, m->im_device)) { @@ -331,24 +328,18 @@ check_filesystem (guestfs_h *g, const char *mountable, return 0; } -static int +static void extend_fses (guestfs_h *g) { size_t n = g->nr_fses + 1; struct inspect_fs *p; - p = realloc (g->fses, n * sizeof (struct inspect_fs)); - if (p == NULL) { - perrorf (g, "realloc"); - return -1; - } + p = safe_realloc (g, g->fses, n * sizeof (struct inspect_fs)); g->fses = p; g->nr_fses = n; memset (&g->fses[n-1], 0, sizeof (struct inspect_fs)); - - return 0; } /* Given a partition (eg. /dev/sda2) then return the partition number -- 2.1.0
Pino
2015-Jun-04 09:25 UTC
[Libguestfs] Help: host system got very slow when run guestfish
Hi there, Recently, I got a strange phenomenon, when I run: ./run guestfish -a xxx.img -a xxx.img My host system got to be very very slow for several minites, sometimes can`t even move my mouse. I am not sure what I have done made it this way. How should I investigate this issue? Because I don`t see anyone got this kind of problem in FAQ Thanks in advance. Yours Sinerely, Pino Tsao
Richard W.M. Jones
2015-Jun-04 10:31 UTC
Re: [Libguestfs] Help: host system got very slow when run guestfish
On Thu, Jun 04, 2015 at 05:25:34PM +0800, Pino wrote:> Hi there, > Recently, I got a strange phenomenon, when I run: > > ./run guestfish -a xxx.img -a xxx.img > > My host system got to be very very slow for several minites, > sometimes can`t even move my mouse. I am not sure what I have done > made it this way. > How should I investigate this issue? Because I don`t see anyone > got this kind of problem in FAQThis happens because of a bug in 'libtool' (or 'sed'/'grep'). The './run' script runs 'libtool --mode=execute', which runs 'sed' and 'grep' on each argument specified on the command line. If some of those files are very large (multi-gigabyte) sparse files, then 'sed'/'grep' takes a very long time to run, and can "hang" your system just as you described. The bug is: https://bugzilla.redhat.com/show_bug.cgi?id=636045 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2015-Jun-06 13:47 UTC
Re: [Libguestfs] [PATCH] Use safe_realloc() in favor of realloc overall.
Thanks - I will push this soon. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top