[PATCH] appliance: Make sure /tmp and /var/tmp are real directories.
by Richard W.M. Jones
Currently if /tmp (on the host) is a symlink, then the symlink is
copied into the appliance, probably pointing to a non-existent
directory, and everything goes downhill from there.
Avoid this by making sure that /tmp and /var/tmp are real directories.
---
appliance/init | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/appliance/init b/appliance/init
index 3c5ef1b..3973f18 100755
--- a/appliance/init
+++ b/appliance/init
@@ -10,6 +10,11 @@ RUNLEVEL=S
PREVLEVEL=N
export RUNLEVEL PREVLEVEL
+# Make sure /tmp /var/tmp are real directories, not symlinks.
+rm -f /tmp /var/tmp
+mkdir /tmp /var/tmp
+chmod 1777 /tmp /var/tmp
+
# Make sure to find all the libraries, also those in non-standard place
# but with a proper ld.so configuration pointing at them
ldconfig
--
2.3.1
9 years, 5 months
[PATCH] inspector: tests: Enable the Arch Linux test
by Nikos Skalkotos
---
inspector/test-virt-inspector.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inspector/test-virt-inspector.sh b/inspector/test-virt-inspector.sh
index 86d70a8..02bbcad 100755
--- a/inspector/test-virt-inspector.sh
+++ b/inspector/test-virt-inspector.sh
@@ -29,7 +29,7 @@ fi
# ntfs-3g can't set UUIDs right now, so ignore just that <uuid>.
diff_ignore="-I <uuid>[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]</uuid>"
-for f in ../tests/guests/{debian,fedora,ubuntu,coreos,windows}.img; do
+for f in ../tests/guests/{debian,fedora,ubuntu,archlinux,coreos,windows}.img; do
# Ignore zero-sized windows.img if ntfs-3g is not installed.
if [ -s "$f" ]; then
b=$(basename "$f" .xml)
--
2.1.0
9 years, 5 months
[PATCH] mllib: use Unix.gettimeofday instead of Unix.time
by Pino Toscano
Unix.gettimeofday returns a finer resolution than seconds, which is what
we need since deciseconds of timestamps are printed.
---
mllib/common_utils.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 32e908d..516cff3 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -282,11 +282,11 @@ let verbose () = !verbose
(* Timestamped progress messages, used for ordinary messages when not
* --quiet.
*)
-let start_t = Unix.time ()
+let start_t = Unix.gettimeofday ()
let message fs =
let display str =
if not (quiet ()) then (
- let t = sprintf "%.1f" (Unix.time () -. start_t) in
+ let t = sprintf "%.1f" (Unix.gettimeofday () -. start_t) in
printf "[%6s] " t;
ansi_green ();
printf "%s" str;
--
2.1.0
9 years, 5 months
[PATCH 1/3] inspection: Add func for merging fs inspections
by Nikos Skalkotos
Add a new guestfs_int_merge_fs_inspections() function that merges the OS
inspection information of two inspect_fs instances into one. This
function is useful if the inspection information for an OS are gathered
by inspecting multiple filesystems.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/guestfs-internal.h | 1 +
src/inspect-fs.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 4f06c37..7d30e8e 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -788,6 +788,7 @@ extern char *guestfs_int_first_line_of_file (guestfs_h *g, const char *filename)
extern int guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename, const char *eregex, int iflag, char **ret);
extern void guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs);
extern void guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs);
+extern void guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst, struct inspect_fs *src);
/* inspect-fs-unix.c */
extern int guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs);
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 932e5e7..a2913d6 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -655,3 +655,105 @@ guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename,
return 1;
}
+
+/* Merge the missing OS inspection information found on the src inspect_fs into
+ * the ones of the dst inspect_fs. This function is useful if the inspection
+ * information for an OS are gathered by inspecting multiple filesystems.
+ */
+void
+guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst, struct inspect_fs *src)
+{
+ size_t n, i, old;
+ struct inspect_fstab_entry *fstab = NULL;
+ char ** mappings = NULL;
+
+ if (dst->type == 0)
+ dst->type = src->type;
+
+ if (dst->distro == 0)
+ dst->distro = src->distro;
+
+ if (dst->package_format == 0)
+ dst->package_format = src->package_format;
+
+ if (dst->package_management == 0)
+ dst->package_management = src->package_management;
+
+ if (dst->product_name == NULL) {
+ dst->product_name = src->product_name;
+ src->product_name = NULL;
+ }
+
+ if (dst->product_variant == NULL) {
+ dst->product_variant= src->product_variant;
+ src->product_variant = NULL;
+ }
+
+ if (dst->major_version == 0 && dst->minor_version == 0) {
+ dst->major_version = src->major_version;
+ dst->minor_version = src->minor_version;
+ }
+
+ if (dst->arch == NULL) {
+ dst->arch = src->arch;
+ src->arch = NULL;
+ }
+
+ if (dst->hostname == NULL) {
+ dst->hostname = src->hostname;
+ src->hostname = NULL;
+ }
+
+ if (dst->windows_systemroot == NULL) {
+ dst->windows_systemroot = src->windows_systemroot;
+ src->windows_systemroot = NULL;
+ }
+
+ if (dst->windows_current_control_set == NULL) {
+ dst->windows_current_control_set = src->windows_current_control_set;
+ src->windows_current_control_set = NULL;
+ }
+
+ if (src->drive_mappings != NULL) {
+ if (dst->drive_mappings == NULL) {
+ /* Adopt the drive mappings of src */
+ dst->drive_mappings = src->drive_mappings;
+ src->drive_mappings = NULL;
+ } else {
+ n = 0;
+ for (; dst->drive_mappings[n] != NULL; n++)
+ ;
+ old = n;
+ for (; src->drive_mappings[n] != NULL; n++)
+ ;
+
+ /* Merge the src mappings to dst */
+ mappings = safe_realloc (g, dst->drive_mappings,(n + 1) * sizeof (char *));
+
+ for (i = old; i < n; i++)
+ mappings[i] = src->drive_mappings[i - old];
+
+ mappings[n] = NULL;
+ dst->drive_mappings = mappings;
+
+ free(src->drive_mappings);
+ src->drive_mappings = NULL;
+ }
+ }
+
+ if (src->nr_fstab > 0) {
+ n = dst->nr_fstab + src->nr_fstab;
+ fstab = safe_realloc (g, dst->fstab, n * sizeof (struct inspect_fstab_entry));
+
+ for (i = 0; i < src->nr_fstab; i++) {
+ fstab[dst->nr_fstab + i].mountable = src->fstab[i].mountable;
+ fstab[dst->nr_fstab + i].mountpoint = src->fstab[i].mountpoint;
+ }
+ free(src->fstab);
+ src->fstab = NULL;
+ src->nr_fstab = 0;
+
+ dst->fstab = fstab;
+ dst->nr_fstab = n;
+ }
+}
--
2.1.0
9 years, 5 months
[PATCH 2/3] inspection: Add support for CoreOS
by Nikos Skalkotos
* Implement coreos distro
* Detect CoreOS images
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
generator/actions.ml | 4 +++
src/guestfs-internal.h | 3 +++
src/inspect-fs-unix.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---
src/inspect-fs.c | 21 +++++++++++++++
src/inspect-icon.c | 1 +
src/inspect.c | 59 ++++++++++++++++++++++++++++++++++++++++++
6 files changed, 154 insertions(+), 3 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index e9374a3..e1b14ca 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1073,6 +1073,10 @@ Cirros.
=item \"debian\"
+CoreOS.
+
+=item \"coreos\"
+
Debian.
=item \"fedora\"
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 7d30e8e..bbd7fb4 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -551,6 +551,7 @@ enum inspect_os_distro {
OS_DISTRO_ORACLE_LINUX,
OS_DISTRO_FREEBSD,
OS_DISTRO_NETBSD,
+ OS_DISTRO_COREOS,
};
enum inspect_os_package_format {
@@ -797,6 +798,8 @@ extern int guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_openbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs);
/* inspect-fs-windows.c */
extern char *guestfs_int_case_sensitive_path_silently (guestfs_h *g, const char *);
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 2abbf24..ff50b2a 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -160,11 +160,16 @@ parse_release_file (guestfs_h *g, struct inspect_fs *fs,
* DISTRIB_CODENAME=Henry_Farman
* DISTRIB_DESCRIPTION="Mandriva Linux 2010.1"
* Mandriva also has a normal release file called /etc/mandriva-release.
+ *
+ * CoreOS has a /etc/lsb-release link to /usr/share/coreos/lsb-release containing:
+ * DISTRIB_ID=CoreOS
+ * DISTRIB_RELEASE=647.0.0
+ * DISTRIB_CODENAME="Red Dog"
+ * DISTRIB_DESCRIPTION="CoreOS 647.0.0"
*/
static int
-parse_lsb_release (guestfs_h *g, struct inspect_fs *fs)
+parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
{
- const char *filename = "/etc/lsb-release";
int64_t size;
CLEANUP_FREE_STRING_LIST char **lines = NULL;
size_t i;
@@ -208,6 +213,11 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs)
fs->distro = OS_DISTRO_MAGEIA;
r = 1;
}
+ else if (fs->distro == 0 &&
+ STREQ (lines[i], "DISTRIB_ID=CoreOS")) {
+ fs->distro = OS_DISTRO_COREOS;
+ r = 1;
+ }
else if (STRPREFIX (lines[i], "DISTRIB_RELEASE=")) {
char *major, *minor;
if (match2 (g, &lines[i][16], re_major_minor, &major, &minor)) {
@@ -338,7 +348,7 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (guestfs_is_file_opts (g, "/etc/lsb-release",
GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
- r = parse_lsb_release (g, fs);
+ r = parse_lsb_release (g, fs, "/etc/lsb-release");
if (r == -1) /* error */
return -1;
if (r == 1) /* ok - detected the release from this file */
@@ -795,6 +805,59 @@ guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs)
return 0;
}
+/* The currently mounted device is a CoreOS root. From this partition we can
+ * only determine the hostname. All immutable OS files are under a separate
+ * read-only /usr partition.
+ */
+int
+guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs)
+{
+ fs->type = OS_TYPE_LINUX;
+ fs->distro = OS_DISTRO_COREOS;
+
+ /* Determine hostname. */
+ if (check_hostname_unix (g, fs) == -1)
+ return -1;
+
+ /* 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;
+
+ return 0;
+}
+
+/* The currently mounted device looks like a CoreOS /usr. In CoreOS
+ * the read-only /usr contains the OS version. The /etc/os-release is a
+ * link to /usr/share/coreos/os-release.
+ */
+int
+guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs)
+{
+ int r;
+
+ fs->type = OS_TYPE_LINUX;
+ fs->distro = OS_DISTRO_COREOS;
+ if (guestfs_is_file_opts (g, "/share/coreos/lsb-release",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ r = parse_lsb_release (g, fs, "/share/coreos/lsb-release");
+ if (r == -1) /* error */
+ return -1;
+ }
+
+ /* Determine the architecture. */
+ check_architecture (g, 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;
+
+ return 0;
+}
+
static void
check_architecture (guestfs_h *g, struct inspect_fs *fs)
{
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index a2913d6..0fbd26c 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -232,6 +232,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs_int_check_linux_root (g, fs) == -1)
return -1;
}
+ /* CoreOS root? */
+ else if (is_dir_etc &&
+ guestfs_is_dir (g, "/root") > 0 &&
+ guestfs_is_dir (g, "/home") > 0 &&
+ guestfs_is_dir (g, "/usr") > 0 &&
+ guestfs_is_file (g, "/etc/coreos/update.conf") > 0) {
+ fs->is_root = 1;
+ fs->format = OS_FORMAT_INSTALLED;
+ if (guestfs_int_check_coreos_root (g, fs) == -1)
+ return -1;
+ }
/* Linux /usr/local? */
else if (is_dir_etc &&
is_dir_bin &&
@@ -246,6 +257,14 @@ check_filesystem (guestfs_h *g, const char *mountable,
guestfs_is_dir (g, "/local") > 0 &&
guestfs_is_file (g, "/etc/fstab") == 0)
;
+ /* CoreOS /usr? */
+ else if (is_dir_bin &&
+ is_dir_share &&
+ guestfs_is_dir (g, "/local") > 0 &&
+ guestfs_is_dir (g, "/share/coreos") > 0) {
+ if (guestfs_int_check_coreos_usr (g, fs) == -1)
+ return -1;
+ }
/* Linux /var? */
else if (guestfs_is_dir (g, "/log") > 0 &&
guestfs_is_dir (g, "/run") > 0 &&
@@ -476,6 +495,7 @@ guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_WINDOWS:
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
@@ -546,6 +566,7 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_WINDOWS:
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index fb998c2..57b2ce3 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -169,6 +169,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
/* These are just to keep gcc warnings happy. */
case OS_DISTRO_ARCHLINUX:
case OS_DISTRO_BUILDROOT:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_FREEDOS:
case OS_DISTRO_GENTOO:
case OS_DISTRO_LINUX_MINT:
diff --git a/src/inspect.c b/src/inspect.c
index f528bf2..abe9087 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -42,6 +42,7 @@
COMPILE_REGEXP (re_primary_partition, "^/dev/(?:h|s|v)d.[1234]$", 0)
static void check_for_duplicated_bsd_root (guestfs_h *g);
+static void collect_coreos_inspection_info (guestfs_h *g);
/* The main inspection code. */
char **
@@ -70,6 +71,12 @@ guestfs_impl_inspect_os (guestfs_h *g)
}
}
+ /* The OS inspection information for CoreOS are gathered by inspecting
+ * multiple filesystems. Gather all the inspected information in the
+ * inspect_fs struct of the root filesystem.
+ */
+ collect_coreos_inspection_info (g);
+
/* Check if the same filesystem was listed twice as root in g->fses.
* This may happen for the *BSD root partition where an MBR partition
* is a shadow of the real root partition probably /dev/sda5
@@ -87,6 +94,57 @@ guestfs_impl_inspect_os (guestfs_h *g)
return ret;
}
+/* Traverse through the filesystem list and find out if it contains the
+ * "/" and "/usr" filesystems of a CoreOS image. If this is the case,
+ * sum up all the collected information on the root fs.
+ */
+static void
+collect_coreos_inspection_info (guestfs_h *g)
+{
+ size_t i;
+ struct inspect_fs *root = NULL, *usr = NULL;
+
+ for (i = 0; i < g->nr_fses; ++i) {
+ struct inspect_fs *fs = &g->fses[i];
+
+ if (fs->distro == OS_DISTRO_COREOS && fs->is_root)
+ root = fs;
+ }
+
+ if (root == NULL)
+ return;
+
+ for (i = 0; i < g->nr_fses; ++i) {
+ struct inspect_fs *fs = &g->fses[i];
+
+ if (fs->distro != OS_DISTRO_COREOS || fs->is_root != 0)
+ continue;
+
+ /* CoreOS is designed to contain 2 /usr partitions (USR-A, USR-B):
+ * https://coreos.com/docs/sdk-distributors/sdk/disk-partitions/
+ * One is active and one passive. During the initial boot, the passive
+ * partition is empty and it gets filled up when an update is performed.
+ * Then, when the system reboots, the boot loader is instructed to boot
+ * from the passive partition. If both partitions are valid, we cannot
+ * determine which the active and which the passive is, unless we peep into
+ * the boot loader. As a workaround, we check the OS versions and pick the
+ * one with the higher version as active.
+ */
+ if (usr &&
+ (usr->major_version > fs->major_version ||
+ (usr->major_version == fs->major_version &&
+ usr->minor_version > fs->minor_version)))
+ continue;
+
+ usr = fs;
+ }
+
+ if (usr == NULL)
+ return;
+
+ guestfs_int_merge_fs_inspections (g, root, usr);
+}
+
/* 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)
@@ -201,6 +259,7 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char *root)
case OS_DISTRO_BUILDROOT: ret = safe_strdup (g, "buildroot"); break;
case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
case OS_DISTRO_CIRROS: ret = safe_strdup (g, "cirros"); break;
+ case OS_DISTRO_COREOS: ret = safe_strdup (g, "coreos"); break;
case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
case OS_DISTRO_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
--
2.1.0
9 years, 5 months
[PATCH 2/3] inspection: Add support for CoreOS
by Nikos Skalkotos
* Implement coreos distro
* Detect CoreOS images
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
generator/actions.ml | 4 +++
src/guestfs-internal.h | 3 +++
src/inspect-fs-unix.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---
src/inspect-fs.c | 21 +++++++++++++++
src/inspect-icon.c | 1 +
src/inspect.c | 62 +++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 157 insertions(+), 3 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index e9374a3..e1b14ca 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1073,6 +1073,10 @@ Cirros.
=item \"debian\"
+CoreOS.
+
+=item \"coreos\"
+
Debian.
=item \"fedora\"
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 01cbca7..1462673 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -551,6 +551,7 @@ enum inspect_os_distro {
OS_DISTRO_ORACLE_LINUX,
OS_DISTRO_FREEBSD,
OS_DISTRO_NETBSD,
+ OS_DISTRO_COREOS,
};
enum inspect_os_package_format {
@@ -797,6 +798,8 @@ extern int guestfs_int_check_netbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_openbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs);
/* inspect-fs-windows.c */
extern char *guestfs_int_case_sensitive_path_silently (guestfs_h *g, const char *);
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 2abbf24..ff50b2a 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -160,11 +160,16 @@ parse_release_file (guestfs_h *g, struct inspect_fs *fs,
* DISTRIB_CODENAME=Henry_Farman
* DISTRIB_DESCRIPTION="Mandriva Linux 2010.1"
* Mandriva also has a normal release file called /etc/mandriva-release.
+ *
+ * CoreOS has a /etc/lsb-release link to /usr/share/coreos/lsb-release containing:
+ * DISTRIB_ID=CoreOS
+ * DISTRIB_RELEASE=647.0.0
+ * DISTRIB_CODENAME="Red Dog"
+ * DISTRIB_DESCRIPTION="CoreOS 647.0.0"
*/
static int
-parse_lsb_release (guestfs_h *g, struct inspect_fs *fs)
+parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char *filename)
{
- const char *filename = "/etc/lsb-release";
int64_t size;
CLEANUP_FREE_STRING_LIST char **lines = NULL;
size_t i;
@@ -208,6 +213,11 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs)
fs->distro = OS_DISTRO_MAGEIA;
r = 1;
}
+ else if (fs->distro == 0 &&
+ STREQ (lines[i], "DISTRIB_ID=CoreOS")) {
+ fs->distro = OS_DISTRO_COREOS;
+ r = 1;
+ }
else if (STRPREFIX (lines[i], "DISTRIB_RELEASE=")) {
char *major, *minor;
if (match2 (g, &lines[i][16], re_major_minor, &major, &minor)) {
@@ -338,7 +348,7 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
if (guestfs_is_file_opts (g, "/etc/lsb-release",
GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
- r = parse_lsb_release (g, fs);
+ r = parse_lsb_release (g, fs, "/etc/lsb-release");
if (r == -1) /* error */
return -1;
if (r == 1) /* ok - detected the release from this file */
@@ -795,6 +805,59 @@ guestfs_int_check_minix_root (guestfs_h *g, struct inspect_fs *fs)
return 0;
}
+/* The currently mounted device is a CoreOS root. From this partition we can
+ * only determine the hostname. All immutable OS files are under a separate
+ * read-only /usr partition.
+ */
+int
+guestfs_int_check_coreos_root (guestfs_h *g, struct inspect_fs *fs)
+{
+ fs->type = OS_TYPE_LINUX;
+ fs->distro = OS_DISTRO_COREOS;
+
+ /* Determine hostname. */
+ if (check_hostname_unix (g, fs) == -1)
+ return -1;
+
+ /* 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;
+
+ return 0;
+}
+
+/* The currently mounted device looks like a CoreOS /usr. In CoreOS
+ * the read-only /usr contains the OS version. The /etc/os-release is a
+ * link to /usr/share/coreos/os-release.
+ */
+int
+guestfs_int_check_coreos_usr (guestfs_h *g, struct inspect_fs *fs)
+{
+ int r;
+
+ fs->type = OS_TYPE_LINUX;
+ fs->distro = OS_DISTRO_COREOS;
+ if (guestfs_is_file_opts (g, "/share/coreos/lsb-release",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ r = parse_lsb_release (g, fs, "/share/coreos/lsb-release");
+ if (r == -1) /* error */
+ return -1;
+ }
+
+ /* Determine the architecture. */
+ check_architecture (g, 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;
+
+ return 0;
+}
+
static void
check_architecture (guestfs_h *g, struct inspect_fs *fs)
{
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 5f55f1d..64f904f 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -232,6 +232,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs_int_check_linux_root (g, fs) == -1)
return -1;
}
+ /* CoreOS root? */
+ else if (is_dir_etc &&
+ guestfs_is_dir (g, "/root") > 0 &&
+ guestfs_is_dir (g, "/home") > 0 &&
+ guestfs_is_dir (g, "/usr") > 0 &&
+ guestfs_is_file (g, "/etc/coreos/update.conf") > 0) {
+ fs->is_root = 1;
+ fs->format = OS_FORMAT_INSTALLED;
+ if (guestfs_int_check_coreos_root (g, fs) == -1)
+ return -1;
+ }
/* Linux /usr/local? */
else if (is_dir_etc &&
is_dir_bin &&
@@ -246,6 +257,14 @@ check_filesystem (guestfs_h *g, const char *mountable,
guestfs_is_dir (g, "/local") > 0 &&
guestfs_is_file (g, "/etc/fstab") == 0)
;
+ /* CoreOS /usr? */
+ else if (is_dir_bin &&
+ is_dir_share &&
+ guestfs_is_dir (g, "/local") > 0 &&
+ guestfs_is_dir (g, "/share/coreos") > 0) {
+ if (guestfs_int_check_coreos_usr (g, fs) == -1)
+ return -1;
+ }
/* Linux /var? */
else if (guestfs_is_dir (g, "/log") > 0 &&
guestfs_is_dir (g, "/run") > 0 &&
@@ -476,6 +495,7 @@ guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_WINDOWS:
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
@@ -546,6 +566,7 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_WINDOWS:
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index fb998c2..57b2ce3 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -169,6 +169,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
/* These are just to keep gcc warnings happy. */
case OS_DISTRO_ARCHLINUX:
case OS_DISTRO_BUILDROOT:
+ case OS_DISTRO_COREOS:
case OS_DISTRO_FREEDOS:
case OS_DISTRO_GENTOO:
case OS_DISTRO_LINUX_MINT:
diff --git a/src/inspect.c b/src/inspect.c
index f528bf2..dd6a06f 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -42,6 +42,7 @@
COMPILE_REGEXP (re_primary_partition, "^/dev/(?:h|s|v)d.[1234]$", 0)
static void check_for_duplicated_bsd_root (guestfs_h *g);
+static int collect_coreos_inspection_info (guestfs_h *g);
/* The main inspection code. */
char **
@@ -70,6 +71,15 @@ guestfs_impl_inspect_os (guestfs_h *g)
}
}
+ /* The OS inspection information for CoreOS are gathered by inspecting
+ * multiple filesystems. Gather all the inspected information in the
+ * inspect_fs struct of the root filesystem.
+ */
+ if (collect_coreos_inspection_info (g)) {
+ guestfs_int_free_inspect_info (g);
+ return NULL;
+ }
+
/* Check if the same filesystem was listed twice as root in g->fses.
* This may happen for the *BSD root partition where an MBR partition
* is a shadow of the real root partition probably /dev/sda5
@@ -87,6 +97,57 @@ guestfs_impl_inspect_os (guestfs_h *g)
return ret;
}
+/* Traverse through the filesystem list and find out if it contains the
+ * "/" and "/usr" filesystems of a CoreOS image. If this is the case,
+ * sum up all the collected information on the root fs.
+ */
+static int
+collect_coreos_inspection_info (guestfs_h *g)
+{
+ size_t i;
+ struct inspect_fs *root = NULL, *usr = NULL;
+
+ for (i = 0; i < g->nr_fses; ++i) {
+ struct inspect_fs *fs = &g->fses[i];
+
+ if (fs->distro == OS_DISTRO_COREOS && fs->is_root)
+ root = fs;
+ }
+
+ if (root == NULL)
+ return 0;
+
+ for (i = 0; i < g->nr_fses; ++i) {
+ struct inspect_fs *fs = &g->fses[i];
+
+ if (fs->distro != OS_DISTRO_COREOS || fs->is_root != 0)
+ continue;
+
+ /* CoreOS is designed to contain 2 /usr partitions (USR-A, USR-B):
+ * https://coreos.com/docs/sdk-distributors/sdk/disk-partitions/
+ * One is active and one passive. During the initial boot, the passive
+ * partition is empty and it gets filled up when an update is performed.
+ * Then, when the system reboots, the boot loader is instructed to boot
+ * from the passive partition. If both partitions are valid, we cannot
+ * determine which the active and which the passive is, unless we peep into
+ * the boot loader. As a workaround, we check the OS versions and pick the
+ * one with the higher version as active.
+ */
+ if (usr &&
+ (usr->major_version > fs->major_version ||
+ (usr->major_version == fs->major_version &&
+ usr->minor_version > fs->minor_version)))
+ continue;
+
+ usr = fs;
+ }
+
+ if (usr == NULL)
+ return 0;
+
+ return guestfs_int_merge_fs_inspections (g, root, usr);
+}
+
/* 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)
@@ -201,6 +262,7 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char *root)
case OS_DISTRO_BUILDROOT: ret = safe_strdup (g, "buildroot"); break;
case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
case OS_DISTRO_CIRROS: ret = safe_strdup (g, "cirros"); break;
+ case OS_DISTRO_COREOS: ret = safe_strdup (g, "coreos"); break;
case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
case OS_DISTRO_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
--
2.1.0
9 years, 5 months
[PATCH 3/3] Add tests for CoreOS
by Nikos Skalkotos
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
.gitignore | 1 +
inspector/Makefile.am | 1 +
inspector/expected-coreos.img.xml | 30 +++++++++++
inspector/test-virt-inspector.sh | 2 +-
tests/guests/Makefile.am | 6 +++
tests/guests/guest-aux/make-coreos-img.sh | 83 +++++++++++++++++++++++++++++++
tests/guests/guests.xml.in | 16 ++++++
7 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 inspector/expected-coreos.img.xml
create mode 100755 tests/guests/guest-aux/make-coreos-img.sh
diff --git a/.gitignore b/.gitignore
index 29f9d6d..096cdfc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -536,6 +536,7 @@ Makefile.in
/tests/guests/stamp-fedora-md.img
/tests/guests/ubuntu.img
/tests/guests/archlinux.img
+/tests/guests/coreos.img
/tests/guests/windows.img
/tests/mount-local/test-parallel-mount-local
/tests/mountable/test-internal-parse-mountable
diff --git a/inspector/Makefile.am b/inspector/Makefile.am
index 9d8303c..9c79bed 100644
--- a/inspector/Makefile.am
+++ b/inspector/Makefile.am
@@ -38,6 +38,7 @@ EXTRA_DIST = \
expected-fedora.img.xml \
expected-ubuntu.img.xml \
expected-archlinux.img.xml \
+ expected-coreos.img.xml \
expected-windows.img.xml \
test-virt-inspector.sh \
test-xmllint.sh.in \
diff --git a/inspector/expected-coreos.img.xml b/inspector/expected-coreos.img.xml
new file mode 100644
index 0000000..723a853
--- /dev/null
+++ b/inspector/expected-coreos.img.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<operatingsystems>
+ <operatingsystem>
+ <root>/dev/sda5</root>
+ <name>linux</name>
+ <distro>coreos</distro>
+ <product_name>CoreOS 647.0.0</product_name>
+ <major_version>647</major_version>
+ <minor_version>0</minor_version>
+ <hostname>coreos.invalid</hostname>
+ <format>installed</format>
+ <mountpoints>
+ <mountpoint dev="/dev/sda5">/</mountpoint>
+ <mountpoint dev="/dev/sda3">/usr</mountpoint>
+ </mountpoints>
+ <filesystems>
+ <filesystem dev="/dev/sda3">
+ <type>ext4</type>
+ <label>USR-A</label>
+ <uuid>01234567-0123-0123-0123-012345678901</uuid>
+ </filesystem>
+ <filesystem dev="/dev/sda5">
+ <type>ext4</type>
+ <label>ROOT</label>
+ <uuid>01234567-0123-0123-0123-012345678902</uuid>
+ </filesystem>
+ </filesystems>
+ <applications/>
+ </operatingsystem>
+</operatingsystems>
diff --git a/inspector/test-virt-inspector.sh b/inspector/test-virt-inspector.sh
index 592347c..86d70a8 100755
--- a/inspector/test-virt-inspector.sh
+++ b/inspector/test-virt-inspector.sh
@@ -29,7 +29,7 @@ fi
# ntfs-3g can't set UUIDs right now, so ignore just that <uuid>.
diff_ignore="-I <uuid>[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]</uuid>"
-for f in ../tests/guests/{debian,fedora,ubuntu,windows}.img; do
+for f in ../tests/guests/{debian,fedora,ubuntu,coreos,windows}.img; do
# Ignore zero-sized windows.img if ntfs-3g is not installed.
if [ -s "$f" ]; then
b=$(basename "$f" .xml)
diff --git a/tests/guests/Makefile.am b/tests/guests/Makefile.am
index b752bb1..6ada4ec 100644
--- a/tests/guests/Makefile.am
+++ b/tests/guests/Makefile.am
@@ -30,6 +30,7 @@ EXTRA_DIST = \
guest-aux/make-ubuntu-img.sh \
guest-aux/make-archlinux-img.sh \
guest-aux/archlinux-package \
+ guest-aux/make-coreos-img.sh \
guest-aux/make-windows-img.sh \
guest-aux/windows-software \
guest-aux/windows-software.reg \
@@ -52,6 +53,7 @@ disk_images = \
fedora-btrfs.img \
ubuntu.img \
archlinux.img \
+ coreos.img \
windows.img
# This is 'check_DATA' because we don't need it until 'make check'
@@ -109,6 +111,10 @@ ubuntu.img: guest-aux/make-ubuntu-img.sh
archlinux.img: guest-aux/make-archlinux-img.sh
SRCDIR=$(srcdir) $(top_builddir)/run --test $<
+# Make a (dummy) CoreOS image.
+coreos.img: guest-aux/make-coreos-img.sh
+ SRCDIR=$(srcdir) $(top_builddir)/run --test $<
+
# Make a (dummy) Windows image.
windows.img: guest-aux/make-windows-img.sh \
guest-aux/windows-software guest-aux/windows-system
diff --git a/tests/guests/guest-aux/make-coreos-img.sh b/tests/guests/guest-aux/make-coreos-img.sh
new file mode 100755
index 0000000..b8e0816
--- /dev/null
+++ b/tests/guests/guest-aux/make-coreos-img.sh
@@ -0,0 +1,83 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2015 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Make a CoreOS image which is enough to fool the inspection heuristics.
+
+export LANG=C
+set -e
+
+# lsb-release file.
+cat > release.tmp.$$ <<'EOF'
+DISTRIB_ID=CoreOS
+DISTRIB_RELEASE=647.0.0
+DISTRIB_CODENAME="Red Dog"
+DISTRIB_DESCRIPTION="CoreOS 647.0.0"
+EOF
+
+# Create a disk image.
+guestfish <<EOF
+sparse coreos.img.tmp.$$ 512M
+run
+
+part-init /dev/sda gpt
+part-add /dev/sda p 4096 266239
+part-add /dev/sda p 266240 270335
+part-add /dev/sda p 270336 532479
+part-add /dev/sda p 532480 794623
+part-add /dev/sda p 794624 -4096
+
+part-set-name /dev/sda 1 EFI_SYSTEM
+part-set-bootable /dev/sda 1 true
+part-set-name /dev/sda 2 BIOS-BOOT
+part-set-name /dev/sda 3 USR-A
+part-set-name /dev/sda 4 USR-B
+part-set-name /dev/sda 5 ROOT
+
+mkfs fat /dev/sda1
+mkfs ext4 /dev/sda3
+set-label /dev/sda3 USR-A
+set-uuid /dev/sda3 01234567-0123-0123-0123-012345678901
+mkfs ext4 /dev/sda5
+set-label /dev/sda5 ROOT
+set-uuid /dev/sda5 01234567-0123-0123-0123-012345678902
+
+# Enough to fool inspection API.
+mount /dev/sda5 /
+mkdir-p /etc/coreos
+mkdir /usr
+mount /dev/sda3 /usr
+mkdir /usr/bin
+mkdir /usr/lib64
+mkdir /usr/local
+mkdir-p /usr/share/coreos/
+
+ln-s usr/bin /bin
+ln-s usr/lib64 /lib64
+ln-s lib64 /lib
+mkdir /root
+mkdir /home
+
+write /etc/coreos/update.conf "GROUP=stable"
+upload release.tmp.$$ /usr/share/coreos/lsb-release
+ln-s ../usr/share/coreos/lsb-release /etc/lsb-release
+write /etc/hostname "coreos.invalid"
+
+EOF
+
+rm release.tmp.$$
+mv coreos.img.tmp.$$ coreos.img
diff --git a/tests/guests/guests.xml.in b/tests/guests/guests.xml.in
index 451d3fa..8f7ac81 100644
--- a/tests/guests/guests.xml.in
+++ b/tests/guests/guests.xml.in
@@ -248,6 +248,22 @@
</domain>
<domain type='test'>
+ <name>coreos</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='@abs_builddir(a)/coreos.img'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+
+ <domain type='test'>
<name>windows</name>
<memory>1048576</memory>
<os>
--
2.1.0
9 years, 5 months
[PATCH 1/3] inspection: Add func for merging fs inspections
by Nikos Skalkotos
Add a new guestfs_int_merge_fs_inspections() function that merges the OS
inspection information of two inspect_fs instances into one. This
function is useful if the inspection information for an OS are gathered
by inspecting multiple filesystems.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/guestfs-internal.h | 1 +
src/inspect-fs.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 4f06c37..01cbca7 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -788,6 +788,7 @@ extern char *guestfs_int_first_line_of_file (guestfs_h *g, const char *filename)
extern int guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename, const char *eregex, int iflag, char **ret);
extern void guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs);
extern void guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst, struct inspect_fs *src);
/* inspect-fs-unix.c */
extern int guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs);
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index 932e5e7..5f55f1d 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -655,3 +655,118 @@ guestfs_int_first_egrep_of_file (guestfs_h *g, const char *filename,
return 1;
}
+
+/* Merge the missing OS inspection information found on the src inspect_fs into
+ * the ones of the dst inspect_fs. This function is useful if the inspection
+ * information for an OS are gathered by inspecting multiple file systems.
+ *
+ * Returns: 0 = success
+ * -1 = error
+ */
+int
+guestfs_int_merge_fs_inspections (guestfs_h *g, struct inspect_fs *dst, struct inspect_fs *src)
+{
+ size_t n, i, old;
+ struct inspect_fstab_entry *fstab = NULL;
+ char ** mappings = NULL;
+
+ if (dst->type == 0)
+ dst->type = src->type;
+
+ if (dst->distro == 0)
+ dst->distro = src->distro;
+
+ if (dst->package_format == 0)
+ dst->package_format = src->package_format;
+
+ if (dst->package_management == 0)
+ dst->package_management = src->package_management;
+
+ if (dst->product_name == NULL) {
+ dst->product_name = src->product_name;
+ src->product_name = NULL;
+ }
+
+ if (dst->product_variant == NULL) {
+ dst->product_variant= src->product_variant;
+ src->product_variant = NULL;
+ }
+
+ if (dst->major_version == 0 && dst->minor_version == 0) {
+ dst->major_version = src->major_version;
+ dst->minor_version = src->minor_version;
+ }
+
+ if (dst->arch == NULL) {
+ dst->arch = src->arch;
+ src->arch = NULL;
+ }
+
+ if (dst->hostname == NULL) {
+ dst->hostname = src->hostname;
+ src->hostname = NULL;
+ }
+
+ if (dst->windows_systemroot == NULL) {
+ dst->windows_systemroot = src->windows_systemroot;
+ src->windows_systemroot = NULL;
+ }
+
+ if (dst->windows_current_control_set == NULL) {
+ dst->windows_current_control_set = src->windows_current_control_set;
+ src->windows_current_control_set = NULL;
+ }
+
+ if (src->drive_mappings != NULL) {
+ if (dst->drive_mappings == NULL) {
+ /* Adopt the drive mappings of src */
+ dst->drive_mappings = src->drive_mappings;
+ src->drive_mappings = NULL;
+ } else {
+ n = 0;
+ for (; dst->drive_mappings[n] != NULL; n++)
+ ;
+ old = n;
+ for (; src->drive_mappings[n] != NULL; n++)
+ ;
+
+ /* Merge the src mappings to dst */
+ mappings = realloc (dst->drive_mappings, (n + 1) * sizeof (char *));
+ if (mappings == NULL) {
+ perrorf (g, "realloc");
+ return -1;
+ }
+
+ for (i = old; i < n; i++)
+ mappings[i] = src->drive_mappings[i - old];
+
+ mappings[n] = NULL;
+ dst->drive_mappings = mappings;
+
+ free(src->drive_mappings);
+ src->drive_mappings = NULL;
+ }
+ }
+
+ if (src->nr_fstab > 0) {
+ n = dst->nr_fstab + src->nr_fstab;
+ fstab = realloc (dst->fstab, n * sizeof (struct inspect_fstab_entry));
+ if (fstab == NULL) {
+ perrorf (g, "realloc");
+ return -1;
+ }
+
+ for (i = 0; i < src->nr_fstab; i++) {
+ fstab[dst->nr_fstab + i].mountable = src->fstab[i].mountable;
+ fstab[dst->nr_fstab + i].mountpoint = src->fstab[i].mountpoint;
+ }
+ free(src->fstab);
+ src->fstab = NULL;
+ src->nr_fstab = 0;
+
+ dst->fstab = fstab;
+ dst->nr_fstab = n;
+ }
+
+ return 0;
+}
--
2.1.0
9 years, 5 months
[PATCH] inspection: fix CentOS 7 detection
by Pino Toscano
In newer CentOS 7 versions /etc/redhat-release says that the distro is
derived from RHEL, so we need to look at /etc/centos-release for
actually identifying it as CentOS.
The old code is needed as sub-case of /etc/redhat-release, as on
CentOS < 7 that file is a symlink to /etc/centos-release.
---
src/inspect-fs-unix.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 2abbf24..f0fe141 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -345,8 +345,8 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
goto skip_release_checks;
}
- /* Oracle Linux includes a "/etc/redhat-release" file, hence the Oracle check
- * needs to be performed before the Red-Hat one.
+ /* RHEL-based distros include a "/etc/redhat-release" file, hence their
+ * checks need to be performed before the Red-Hat one.
*/
if (guestfs_is_file_opts (g, "/etc/oracle-release",
GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
@@ -376,6 +376,34 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
fs->minor_version = 0;
}
}
+ else if (guestfs_is_file_opts (g, "/etc/centos-release",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ fs->distro = OS_DISTRO_CENTOS;
+
+ if (parse_release_file (g, fs, "/etc/centos-release") == -1)
+ return -1;
+
+ if (match2 (g, fs->product_name, re_centos_old, &major, &minor) ||
+ match2 (g, fs->product_name, re_centos, &major, &minor)) {
+ fs->major_version = guestfs_int_parse_unsigned_int (g, major);
+ free (major);
+ if (fs->major_version == -1) {
+ free (minor);
+ return -1;
+ }
+ fs->minor_version = guestfs_int_parse_unsigned_int (g, minor);
+ free (minor);
+ if (fs->minor_version == -1)
+ return -1;
+ }
+ else if ((major = match1 (g, fs->product_name, re_centos_no_minor)) != NULL) {
+ fs->major_version = guestfs_int_parse_unsigned_int (g, major);
+ free (major);
+ if (fs->major_version == -1)
+ return -1;
+ fs->minor_version = 0;
+ }
+ }
else if (guestfs_is_file_opts (g, "/etc/redhat-release",
GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
--
2.1.0
9 years, 5 months
[PATCH] inspection: lift size limit for RHEL icons
by Pino Toscano
In RHEL-based distros, the provided icons have (obviously) different
sizes than the RHEL ones, used in icon_rhel as reference.
Since 100K should be a reasonable threshold for avoid keeping a
per-distro list of limits, just use it as only size limit.
---
src/inspect-icon.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index fb998c2..c83ba13 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -318,24 +318,21 @@ icon_fedora (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
*
* Conveniently the RHEL clones also have the same file with the
* same name, but containing their own logos. Sense prevails!
+ *
+ * Use a generic 100K limit for all the images, as logos in the
+ * RHEL clones have different sizes.
*/
static char *
icon_rhel (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
{
- size_t max_size = 0;
const char *shadowman;
- if (fs->major_version >= 5 && fs->major_version <= 6)
- max_size = 17000;
- else
- max_size = 66000;
-
if (fs->major_version <= 6)
shadowman = "/usr/share/pixmaps/redhat/shadowman-transparent.png";
else
shadowman = "/usr/share/pixmaps/fedora-logo-sprite.png";
- return get_png (g, fs, shadowman, size_r, max_size);
+ return get_png (g, fs, shadowman, size_r, 102400);
}
#define DEBIAN_ICON "/usr/share/pixmaps/debian-logo.png"
--
2.1.0
9 years, 5 months