1 | #!/usr/bin/python |
---|
2 | """ |
---|
3 | arch.py - Encapsulate all logic regarding what type of hardware xen |
---|
4 | is running on to make adding new platforms easier. |
---|
5 | |
---|
6 | Copyright (C) 2006 Tony Breeds IBM Corporation |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; under version 2 of the License. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with this program; if not, write to the Free Software |
---|
19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
20 | |
---|
21 | """ |
---|
22 | |
---|
23 | import os |
---|
24 | import re |
---|
25 | import config |
---|
26 | import commands |
---|
27 | |
---|
28 | from Test import * |
---|
29 | |
---|
30 | BLOCK_ROOT_DEV = "hda" |
---|
31 | |
---|
32 | # This isn't truly platform related but it makes the code tidier |
---|
33 | def getRdPath(): |
---|
34 | """Locate the full path to ramdisks needed by domUs""" |
---|
35 | rdpath = os.environ.get("RD_PATH") |
---|
36 | if not rdpath: |
---|
37 | rdpath = "../../ramdisk" |
---|
38 | rdpath = os.path.abspath(rdpath) |
---|
39 | |
---|
40 | return rdpath |
---|
41 | |
---|
42 | # Begin: Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors |
---|
43 | def ia_checkBuffer(buffer): |
---|
44 | return |
---|
45 | |
---|
46 | def ia_minSafeMem(): |
---|
47 | return 32 |
---|
48 | |
---|
49 | def ia_getDeviceModel(): |
---|
50 | """Get the path to the device model based on |
---|
51 | the architecture reported in uname""" |
---|
52 | architecture = os.uname()[4] |
---|
53 | if re.search("64", architecture): |
---|
54 | return "/usr/lib64/xen/bin/qemu-dm" |
---|
55 | else: |
---|
56 | return "/usr/lib/xen/bin/qemu-dm" |
---|
57 | |
---|
58 | def ia_getDefaultKernel(): |
---|
59 | """Get the path to the default DomU kernel""" |
---|
60 | dom0Ver = commands.getoutput("uname -r"); |
---|
61 | domUVer = dom0Ver.replace("xen0", "xenU"); |
---|
62 | |
---|
63 | return "/boot/vmlinuz-" + domUVer; |
---|
64 | |
---|
65 | ia_ParavirtDefaults = {"memory" : 64, |
---|
66 | "vcpus" : 1, |
---|
67 | "kernel" : ia_getDefaultKernel(), |
---|
68 | "root" : "/dev/ram0", |
---|
69 | "ramdisk" : getRdPath() + "/initrd.img", |
---|
70 | } |
---|
71 | ia_HVMDefaults = {"memory" : 64, |
---|
72 | "vcpus" : 1, |
---|
73 | "acpi" : 0, |
---|
74 | "disk" : ["file:%s/disk.img,ioemu:%s,w!" % |
---|
75 | (getRdPath(), BLOCK_ROOT_DEV)], |
---|
76 | "kernel" : "/usr/lib/xen/boot/hvmloader", |
---|
77 | "builder" : "hvm", |
---|
78 | "sdl" : 0, |
---|
79 | "vnc" : 0, |
---|
80 | "vncviewer" : 0, |
---|
81 | "nographic" : 1, |
---|
82 | "serial" : "pty", |
---|
83 | "device_model" : ia_getDeviceModel(), |
---|
84 | } |
---|
85 | # End : Intel ia32 and ia64 as well as AMD 32-bit and 64-bit processors |
---|
86 | |
---|
87 | # Begin: PowerPC |
---|
88 | def ppc_checkBuffer(buffer): |
---|
89 | checks = [ |
---|
90 | {"pattern" : re.compile("^\d+:mon>\s*$", re.MULTILINE), |
---|
91 | "message" : "domain trapped into XMON"}, |
---|
92 | ] |
---|
93 | |
---|
94 | for i in range(0, len(checks)): |
---|
95 | check=checks[i] |
---|
96 | if check.get('pattern').search(buffer): |
---|
97 | FAIL(check.get('message')) |
---|
98 | |
---|
99 | return |
---|
100 | |
---|
101 | def ppc_minSafeMem(): |
---|
102 | return 64 |
---|
103 | |
---|
104 | def ppc_getDefaultKernel(): |
---|
105 | """Get the path to the default DomU kernel""" |
---|
106 | dom0Ver = commands.getoutput("uname -r"); |
---|
107 | domUVer = dom0Ver.replace("xen0", "xenU"); |
---|
108 | |
---|
109 | return "/boot/vmlinux-" + domUVer; |
---|
110 | |
---|
111 | ppc_ParavirtDefaults = {"memory" : 64, |
---|
112 | "vcpus" : 1, |
---|
113 | "kernel" : ppc_getDefaultKernel(), |
---|
114 | "root" : "/dev/ram0", |
---|
115 | "ramdisk" : getRdPath() + "/initrd.img", |
---|
116 | "extra" : "xencons=tty128 console=tty128", |
---|
117 | } |
---|
118 | # End : PowerPC |
---|
119 | |
---|
120 | """Convert from uname specification to a more general platform.""" |
---|
121 | _uname_to_arch_map = { |
---|
122 | "i386" : "x86", |
---|
123 | "i486" : "x86", |
---|
124 | "i586" : "x86", |
---|
125 | "i686" : "x86", |
---|
126 | "x86_64": "x86_64", |
---|
127 | "ia64" : "ia64", |
---|
128 | "ppc" : "powerpc", |
---|
129 | "ppc64" : "powerpc", |
---|
130 | } |
---|
131 | |
---|
132 | # Lookup current platform. |
---|
133 | _arch = _uname_to_arch_map.get(os.uname()[4], "Unknown") |
---|
134 | if _arch == "x86" or _arch == "x86_64" or _arch == "ia64": |
---|
135 | minSafeMem = ia_minSafeMem |
---|
136 | getDefaultKernel = ia_getDefaultKernel |
---|
137 | checkBuffer = ia_checkBuffer |
---|
138 | if config.ENABLE_HVM_SUPPORT: |
---|
139 | configDefaults = ia_HVMDefaults |
---|
140 | else: |
---|
141 | configDefaults = ia_ParavirtDefaults |
---|
142 | elif _arch == "powerpc": |
---|
143 | minSafeMem = ppc_minSafeMem |
---|
144 | getDefaultKernel = ppc_getDefaultKernel |
---|
145 | checkBuffer = ppc_checkBuffer |
---|
146 | configDefaults = ppc_ParavirtDefaults |
---|
147 | else: |
---|
148 | raise ValueError, "Unknown architecture!" |
---|