On Fri, Nov 28, 2014 at 03:42:58PM +0100, Pino Toscano wrote:
On Friday 28 November 2014 14:31:01 Richard W.M. Jones wrote:
How about the attached patch? It's basically the same as your patch but I moved the code between files and tidied up some whitespace issues.
Present in both the patches:
+/* On *BSD systems, sometimes /dev/sda[1234] is a shadow of the real root + * filesystem that is probably /dev/sda5 + * (see: http://www.freebsd.org/doc/handbook/disk-organization.html) + */ +static void +check_for_duplicated_bsd_root (guestfs_h *g) +{ + size_t i; + bool is_primary, is_bsd; + struct inspect_fs *fs, *bsd_primary = NULL; + + for (i = 0; i < g->nr_fses; ++i) { + fs = &g->fses[i]; + + is_primary = match (g, fs->mountable, re_primary_partition); + is_bsd = + fs->type == OS_TYPE_FREEBSD || + fs->type == OS_TYPE_NETBSD || + fs->type == OS_TYPE_OPENBSD; + + if (fs->is_root && is_primary && is_bsd) { + bsd_primary = fs; + continue; + }
This will run the regexp matching for every filesystem found; what about inlining the match call as last part of the if, like:
is_bsd = fs->type == OS_TYPE_FREEBSD || fs->type == OS_TYPE_NETBSD || fs->type == OS_TYPE_OPENBSD;
if (fs->is_root && is_bsd && is_primary && match (g, fs->mountable, re_primary_partition)) { bsd_primary = fs; continue; }
This way it is done only for *BSD filesystems, and is_primary is used only in that if anyway.
Also, is_bsd and fs could be declared just inside the for, as they are not needed outside of it.
Good points. See updated patch below. Rich. -- 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/