[Pkg-libvirt-commits] [libguestfs] 105/266: p2v: Find ACPI, APIC and PAE flags and add them to target libvirt XML.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:41:48 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 991c4e36dd52fccc1883a3b7a8aca071f9d20901
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Thu Aug 14 17:32:27 2014 +0100
p2v: Find ACPI, APIC and PAE flags and add them to target libvirt XML.
---
p2v/conversion.c | 10 +++++++---
p2v/main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
p2v/p2v.h | 5 +++++
3 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/p2v/conversion.c b/p2v/conversion.c
index f3674c2..09cd774 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -360,12 +360,14 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns)
" <os>\n"
" <type arch='" host_cpu "'>hvm</type>\n"
" </os>\n"
+ " <features>%s%s%s</features>\n"
" <devices>\n",
config->guestname,
memkb, memkb,
- config->vcpus);
-
- /* XXX features: acpi, apic, pae */
+ config->vcpus,
+ config->flags & FLAG_ACPI ? "<acpi/>" : "",
+ config->flags & FLAG_APIC ? "<apic/>" : "",
+ config->flags & FLAG_PAE ? "<pae/>" : "");
for (i = 0; config->disks[i] != NULL; ++i) {
fprintf (fp,
@@ -419,6 +421,8 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns)
}
}
+ /* Old virt-p2v didn't try to model the graphics hardware. */
+
fprintf (fp,
" </devices>\n"
"</domain>\n");
diff --git a/p2v/main.c b/p2v/main.c
index c07ed86..df4f10c 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -46,6 +46,7 @@ static void set_config_defaults (struct config *config);
static void find_all_disks (void);
static void find_all_interfaces (void);
static char *read_cmdline (void);
+static int cpuinfo_flags (void);
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "Vv";
@@ -186,6 +187,7 @@ set_config_defaults (struct config *config)
{
long i;
char hostname[257];
+ int flags;
/* Default guest name is derived from the source hostname. If we
* assume that the p2v ISO gets its IP address and hostname from
@@ -251,6 +253,12 @@ set_config_defaults (struct config *config)
config->memory |= config->memory >> 32;
config->memory++;
+ flags = cpuinfo_flags ();
+ if (flags >= 0)
+ config->flags = flags;
+ else
+ config->flags = 0;
+
find_all_disks ();
config->disks = guestfs___copy_string_list (all_disks);
if (all_removable)
@@ -506,3 +514,49 @@ read_cmdline (void)
return ret;
}
+
+/* Read the list of flags from /proc/cpuinfo. */
+static int
+cpuinfo_flags (void)
+{
+ const char *cmd;
+ CLEANUP_PCLOSE FILE *fp = NULL;
+ CLEANUP_FREE char *flag = NULL;
+ ssize_t len;
+ size_t buflen = 0;
+ int ret = 0;
+
+ /* Get the flags, one per line. */
+ cmd = "< /proc/cpuinfo "
+#if defined(__arm__)
+ "grep ^Features"
+#else
+ "grep ^flags"
+#endif
+ " | awk '{ for (i = 3; i <= NF; ++i) { print $i }; exit }'";
+
+ fp = popen (cmd, "re");
+ if (fp == NULL) {
+ perror ("/proc/cpuinfo");
+ return -1;
+ }
+
+ while (errno = 0, (len = getline (&flag, &buflen, fp)) != -1) {
+ if (len > 0 && flag[len-1] == '\n')
+ flag[len-1] = '\0';
+
+ if (STREQ (flag, "acpi"))
+ ret |= FLAG_ACPI;
+ else if (STREQ (flag, "apic"))
+ ret |= FLAG_APIC;
+ else if (STREQ (flag, "pae"))
+ ret |= FLAG_PAE;
+ }
+
+ if (errno) {
+ perror ("getline");
+ return -1;
+ }
+
+ return ret;
+}
diff --git a/p2v/p2v.h b/p2v/p2v.h
index 8e5ec43..2d0249f 100644
--- a/p2v/p2v.h
+++ b/p2v/p2v.h
@@ -61,11 +61,16 @@ struct config {
char *guestname;
int vcpus;
uint64_t memory;
+ int flags;
char **disks;
char **removable;
char **interfaces;
};
+#define FLAG_ACPI 1
+#define FLAG_APIC 2
+#define FLAG_PAE 4
+
extern struct config *new_config (void);
extern struct config *copy_config (struct config *);
extern void free_config (struct config *);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list