Revision 347fa0f1 lib/hypervisor/hv_xen.py
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
43 | 43 |
_DOM0_NAME = "Domain-0" |
44 | 44 |
|
45 | 45 |
|
46 |
def _CreateConfigCpus(cpu_mask): |
|
47 |
"""Create a CPU config string for Xen's config file. |
|
48 |
|
|
49 |
""" |
|
50 |
# Convert the string CPU mask to a list of list of int's |
|
51 |
cpu_list = utils.ParseMultiCpuMask(cpu_mask) |
|
52 |
|
|
53 |
if len(cpu_list) == 1: |
|
54 |
all_cpu_mapping = cpu_list[0] |
|
55 |
if all_cpu_mapping == constants.CPU_PINNING_OFF: |
|
56 |
# If CPU pinning has 1 entry that's "all", then remove the |
|
57 |
# parameter from the config file |
|
58 |
return None |
|
59 |
else: |
|
60 |
# If CPU pinning has one non-all entry, mapping all vCPUS (the entire |
|
61 |
# VM) to one physical CPU, using format 'cpu = "C"' |
|
62 |
return "cpu = \"%s\"" % ",".join(map(str, all_cpu_mapping)) |
|
63 |
else: |
|
64 |
|
|
65 |
def _GetCPUMap(vcpu): |
|
66 |
if vcpu[0] == constants.CPU_PINNING_ALL_VAL: |
|
67 |
cpu_map = constants.CPU_PINNING_ALL_XEN |
|
68 |
else: |
|
69 |
cpu_map = ",".join(map(str, vcpu)) |
|
70 |
return "\"%s\"" % cpu_map |
|
71 |
|
|
72 |
# build the result string in format 'cpus = [ "c", "c", "c" ]', |
|
73 |
# where each c is a physical CPU number, a range, a list, or any |
|
74 |
# combination |
|
75 |
return "cpus = [ %s ]" % ", ".join(map(_GetCPUMap, cpu_list)) |
|
76 |
|
|
77 |
|
|
46 | 78 |
class XenHypervisor(hv_base.BaseHypervisor): |
47 | 79 |
"""Xen generic hypervisor interface |
48 | 80 |
|
... | ... | |
119 | 151 |
""" |
120 | 152 |
utils.RemoveFile(XenHypervisor._ConfigFileName(instance_name)) |
121 | 153 |
|
122 |
@classmethod |
|
123 |
def _CreateConfigCpus(cls, cpu_mask): |
|
124 |
"""Create a CPU config string that's compatible with Xen's |
|
125 |
configuration file. |
|
126 |
|
|
127 |
""" |
|
128 |
# Convert the string CPU mask to a list of list of int's |
|
129 |
cpu_list = utils.ParseMultiCpuMask(cpu_mask) |
|
130 |
|
|
131 |
if len(cpu_list) == 1: |
|
132 |
all_cpu_mapping = cpu_list[0] |
|
133 |
if all_cpu_mapping == constants.CPU_PINNING_OFF: |
|
134 |
# If CPU pinning has 1 entry that's "all", then remove the |
|
135 |
# parameter from the config file |
|
136 |
return None |
|
137 |
else: |
|
138 |
# If CPU pinning has one non-all entry, mapping all vCPUS (the entire |
|
139 |
# VM) to one physical CPU, using format 'cpu = "C"' |
|
140 |
return "cpu = \"%s\"" % ",".join(map(str, all_cpu_mapping)) |
|
141 |
else: |
|
142 |
|
|
143 |
def _GetCPUMap(vcpu): |
|
144 |
if vcpu[0] == constants.CPU_PINNING_ALL_VAL: |
|
145 |
cpu_map = constants.CPU_PINNING_ALL_XEN |
|
146 |
else: |
|
147 |
cpu_map = ",".join(map(str, vcpu)) |
|
148 |
return "\"%s\"" % cpu_map |
|
149 |
|
|
150 |
# build the result string in format 'cpus = [ "c", "c", "c" ]', |
|
151 |
# where each c is a physical CPU number, a range, a list, or any |
|
152 |
# combination |
|
153 |
return "cpus = [ %s ]" % ", ".join(map(_GetCPUMap, cpu_list)) |
|
154 |
|
|
155 | 154 |
@staticmethod |
156 | 155 |
def _RunXmList(xmlist_errors): |
157 | 156 |
"""Helper function for L{_GetXMList} to run "xm list". |
... | ... | |
676 | 675 |
config.write("memory = %d\n" % startup_memory) |
677 | 676 |
config.write("maxmem = %d\n" % instance.beparams[constants.BE_MAXMEM]) |
678 | 677 |
config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS]) |
679 |
cpu_pinning = cls._CreateConfigCpus(hvp[constants.HV_CPU_MASK])
|
|
678 |
cpu_pinning = _CreateConfigCpus(hvp[constants.HV_CPU_MASK]) |
|
680 | 679 |
if cpu_pinning: |
681 | 680 |
config.write("%s\n" % cpu_pinning) |
682 | 681 |
cpu_cap = hvp[constants.HV_CPU_CAP] |
... | ... | |
779 | 778 |
config.write("memory = %d\n" % startup_memory) |
780 | 779 |
config.write("maxmem = %d\n" % instance.beparams[constants.BE_MAXMEM]) |
781 | 780 |
config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS]) |
782 |
cpu_pinning = cls._CreateConfigCpus(hvp[constants.HV_CPU_MASK])
|
|
781 |
cpu_pinning = _CreateConfigCpus(hvp[constants.HV_CPU_MASK]) |
|
783 | 782 |
if cpu_pinning: |
784 | 783 |
config.write("%s\n" % cpu_pinning) |
785 | 784 |
cpu_cap = hvp[constants.HV_CPU_CAP] |
Also available in: Unified diff