[PATCH] xen: work with ia64 MAX_VIRT_CPUS of 64

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* src/xen/xen_hypervisor.c (MAX_VIRT_CPUS): Move...
* src/xen/xen_driver.h (MAX_VIRT_CPUS): ...so all xen code can see
same value.
* src/xen/xend_internal.c (sexpr_to_xend_domain_info)
(xenDaemonDomainGetVcpusFlags, xenDaemonParseSxpr)
(xenDaemonFormatSxpr): Work if MAX_VIRT_CPUS is 64 on a platform
where long is 64-bits.
* src/xen/xm_internal.c (xenXMDomainConfigParse)
(xenXMDomainConfigFormat): Likewise.
---

On at least the xen/stable branch of
 git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git
we have the case where MAX_VIRT_CPUS is 32 for x86 but 64 for ia64.
That branch does not have XEN_LEGACY_MAX_VCPUS.  But according
to our comments, other branches had only XEN_LEGACY_MAX_VCPUS,
which means that xm_internal.c would fail to compile without this
patch, when targetting xen headers that lack MAX_VIRT_CPUS.

 src/xen/xen_driver.h     |    8 ++++++++
 src/xen/xen_hypervisor.c |    8 --------
 src/xen/xend_internal.c  |   17 +++++++++--------
 src/xen/xm_internal.c    |    9 +++++----
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index 53f97d4..16d22f1 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -29,6 +29,14 @@
 #  include <winsock2.h>
 # endif

+/* xen-unstable changeset 19788 removed MAX_VIRT_CPUS from public
+ * headers.  Its semantic was retained with XEN_LEGACY_MAX_VCPUS.
+ * Ensure MAX_VIRT_CPUS is defined accordingly.
+ */
+# if !defined(MAX_VIRT_CPUS) && defined(XEN_LEGACY_MAX_VCPUS)
+#  define MAX_VIRT_CPUS XEN_LEGACY_MAX_VCPUS
+# endif
+
 extern int xenRegister (void);

 # define XEN_UNIFIED_HYPERVISOR_OFFSET 0
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 3797865..ec726fe 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -109,14 +109,6 @@ typedef privcmd_hypercall_t hypercall_t;
 # define SYS_IFACE_MIN_VERS_NUMA 4
 #endif

-/* xen-unstable changeset 19788 removed MAX_VIRT_CPUS from public
- * headers.  Its semanitc was retained with XEN_LEGACY_MAX_VCPUS.
- * Ensure MAX_VIRT_CPUS is defined accordingly.
- */
-#if !defined(MAX_VIRT_CPUS) && defined(XEN_LEGACY_MAX_VCPUS)
-# define MAX_VIRT_CPUS XEN_LEGACY_MAX_VCPUS
-#endif
-
 static int xen_ioctl_hypercall_cmd = 0;
 static int initialized = 0;
 static int in_init = 0;
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 974e96b..614c036 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2192,7 +2192,7 @@ xenDaemonParseSxpr(virConnectPtr conn,
     }

     def->maxvcpus = sexpr_int(root, "domain/vcpus");
-    def->vcpus = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
+    def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
     if (!def->vcpus || def->maxvcpus < def->vcpus)
         def->vcpus = def->maxvcpus;

@@ -2468,7 +2468,7 @@ sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
     }
     info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
     vcpus = sexpr_int(root, "domain/vcpus");
-    info->nrVirtCpu = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
+    info->nrVirtCpu = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
     if (!info->nrVirtCpu || vcpus < info->nrVirtCpu)
         info->nrVirtCpu = vcpus;

@@ -3706,7 +3706,7 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)

     ret = sexpr_int(root, "domain/vcpus");
     if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM)) {
-        int vcpus = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
+        int vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
         if (vcpus)
             ret = MIN(vcpus, ret);
     }
@@ -5770,10 +5770,11 @@ xenDaemonFormatSxpr(virConnectPtr conn,
     virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)",
                       def->mem.cur_balloon/1024, def->mem.max_balloon/1024);
     virBufferVSprintf(&buf, "(vcpus %u)", def->maxvcpus);
-    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is 32.  */
-    verify(MAX_VIRT_CPUS <= sizeof(1U) * CHAR_BIT);
+    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
+       either 32, or 64 on a platform where long is big enough.  */
+    verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
     if (def->vcpus < def->maxvcpus)
-        virBufferVSprintf(&buf, "(vcpu_avail %u)", (1U << def->vcpus) - 1);
+        virBufferVSprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);

     if (def->cpumask) {
         char *ranges = virDomainCpuSetFormat(def->cpumask, def->cpumasklen);
@@ -5870,8 +5871,8 @@ xenDaemonFormatSxpr(virConnectPtr conn,

             virBufferVSprintf(&buf, "(vcpus %u)", def->maxvcpus);
             if (def->vcpus < def->maxvcpus)
-                virBufferVSprintf(&buf, "(vcpu_avail %u)",
-                                  (1U << def->vcpus) - 1);
+                virBufferVSprintf(&buf, "(vcpu_avail %lu)",
+                                  (1UL << def->vcpus) - 1);

             for (i = 0 ; i < def->os.nBootDevs ; i++) {
                 switch (def->os.bootDevs[i]) {
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index f80e252..6c5df0f 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -776,7 +776,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
     def->maxvcpus = count;
     if (xenXMConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
         goto cleanup;
-    def->vcpus = MIN(count_one_bits(count), def->maxvcpus);
+    def->vcpus = MIN(count_one_bits_l(count), def->maxvcpus);

     if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0)
         goto cleanup;
@@ -2336,10 +2336,11 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,

     if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
         goto no_memory;
-    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is 32.  */
-    verify(MAX_VIRT_CPUS <= sizeof(1U) * CHAR_BIT);
+    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
+       either 32, or 64 on a platform where long is big enough.  */
+    verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
     if (def->vcpus < def->maxvcpus &&
-        xenXMConfigSetInt(conf, "vcpu_avail", (1U << def->vcpus) - 1) < 0)
+        xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
         goto no_memory;

     if ((def->cpumask != NULL) &&
-- 
1.7.2.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]