ia64/xen-unstable
changeset 1081:fc798cb43fcb
bitkeeper revision 1.716 (4028ece7eoQBod_jQtuJv99FK7huwA)
xc_netbsd_build.c, xc_vd_tool.py, xc_dom_control.py, README, VBD-HOWTO.txt:
More fixes applied from Xen v1.2.
xc_netbsd_build.c, xc_vd_tool.py, xc_dom_control.py, README, VBD-HOWTO.txt:
More fixes applied from Xen v1.2.
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Tue Feb 10 14:38:31 2004 +0000 (2004-02-10) |
parents | 7fd167963d2f |
children | 143de83a34dd |
files | docs/VBD-HOWTO.txt tools/examples/README tools/examples/xc_dom_control.py tools/examples/xc_vd_tool.py tools/xc/lib/xc_netbsd_build.c |
line diff
1.1 --- a/docs/VBD-HOWTO.txt Mon Feb 09 18:18:17 2004 +0000 1.2 +++ b/docs/VBD-HOWTO.txt Tue Feb 10 14:38:31 2004 +0000 1.3 @@ -225,7 +225,7 @@ vbd_remove dom dev - Removes the VBD 1.4 These scripts are most useful when populating VDs. VDs can't be populated 1.5 directly, since they don't correspond to real devices. Using: 1.6 1.7 - xc_dom_control.py vbd_add vd:your_vd_id /dev/whatever 0 w 1.8 + xc_dom_control.py vbd_add 0 vd:your_vd_id /dev/whatever w 1.9 1.10 You can make a virtual disk available to DOM0. Sensible devices to map VDs to 1.11 in DOM0 are the /dev/xvd* nodes, since that makes it obvious that they are Xen 1.12 @@ -234,7 +234,7 @@ virtual devices that don't correspond to 1.13 You can then format, mount and populate the VD through the nominated device 1.14 node. When you've finished, use: 1.15 1.16 - xc_dom_control.py vbd_remove /dev/whatever 0 1.17 + xc_dom_control.py vbd_remove 0 /dev/whatever 1.18 1.19 To revoke DOM0's access to it. It's then ready for use in a guest domain. 1.20 1.21 @@ -269,7 +269,7 @@ access virtual disks to a running domain 1.22 as "phy:device", where device is the name of the device as seen from domain 0, 1.23 or from normal Linux without Xen. For instance: 1.24 1.25 -> xc_dom_control.py vbd_add phy:hdc /dev/whatever 2 r 1.26 +> xc_dom_control.py vbd_add 2 phy:hdc /dev/whatever r 1.27 1.28 Will grant domain 2 read-only access to the device /dev/hdc (as seen from Dom0 1.29 / normal Linux running on the same machine - i.e. the master drive on the 1.30 @@ -355,7 +355,7 @@ standard Linux root filesystem. You'll 1.31 in order to do this. To give DOM0 r/w access to the VD, use the following 1.32 command line, substituting the ID you got earlier. 1.33 1.34 -> xc_dom_control.py vbd_add vd:<id> /dev/xvda 0 w 1.35 +> xc_dom_control.py vbd_add 0 vd:<id> /dev/xvda w 1.36 1.37 This attaches the VD to the device /dev/xvda in domain zero, with read / write 1.38 privileges - you can use other devices nodes if you choose too. 1.39 @@ -368,7 +368,7 @@ You should now remove the VD from DOM0. 1.40 changing it in DOM0, whilst the guest domain is using it (which could cause 1.41 filesystem corruption, and confuse Linux). 1.42 1.43 -> xc_dom_control.py vbd_remove /dev/xvda 0 1.44 +> xc_dom_control.py vbd_remove 0 /dev/xvda 1.45 1.46 It should now be possible to boot a guest domain from the VD. To do this, you 1.47 should specify the the VD's details in some way so that xc_dom_create.py will
2.1 --- a/tools/examples/README Mon Feb 09 18:18:17 2004 +0000 2.2 +++ b/tools/examples/README Tue Feb 10 14:38:31 2004 +0000 2.3 @@ -35,7 +35,7 @@ xc_dom_control.py 2.4 vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth 2.5 vif_getsched [dom] [vif] -- print vif's scheduling parameters 2.6 vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to 2.7 - domain as dev e.g. 'vbd_add phy:sda3 hda1 rw' 2.8 + domain as dev e.g. 'vbd_add 2 phy:sda3 hda1 w' 2.9 vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' 2.10 2.11
3.1 --- a/tools/examples/xc_dom_control.py Mon Feb 09 18:18:17 2004 +0000 3.2 +++ b/tools/examples/xc_dom_control.py Tue Feb 10 14:38:31 2004 +0000 3.3 @@ -28,7 +28,7 @@ Usage: %s [command] <params> 3.4 vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth 3.5 vif_getsched [dom] [vif] -- print vif's scheduling parameters 3.6 vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to 3.7 - domain as dev e.g. 'vbd_add phy:sda3 hda1 rw' 3.8 + domain as dev e.g. 'vbd_add 2 phy:sda3 hda1 w' 3.9 vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' 3.10 """ % sys.argv[0] 3.11 3.12 @@ -119,14 +119,12 @@ elif cmd == 'unwatch': 3.13 os.kill(pid, signal.SIGTERM) 3.14 3.15 elif cmd == 'listvbds': 3.16 - vbdInfo = xc.vbd_probe() 3.17 - for vbd in vbdInfo: 3.18 - print 'dom:' + str(vbd['dom']) 3.19 - del vbd['dom'] 3.20 - print '-----' 3.21 - for field in vbd: 3.22 - print field + ': ' + str(vbd[field]) 3.23 - print '\n' 3.24 + print 'Dom Dev Perm Size(MB)' 3.25 + 3.26 + for vbd in xc.vbd_probe(): 3.27 + vbd['size_mb'] = vbd['nr_sectors'] / 2048 3.28 + vbd['perm'] = (vbd['writeable'] and 'w') or 'r' 3.29 + print '%(dom)-4d %(vbd)04x %(perm)-1s %(size_mb)d' % vbd 3.30 3.31 elif cmd == 'suspend': 3.32 if len(sys.argv) < 4:
4.1 --- a/tools/examples/xc_vd_tool.py Mon Feb 09 18:18:17 2004 +0000 4.2 +++ b/tools/examples/xc_vd_tool.py Tue Feb 10 14:38:31 2004 +0000 4.3 @@ -110,19 +110,17 @@ elif cmd == 'setexpiry': 4.4 4.5 print "Refreshing a virtual disk" 4.6 print "Id: " + id 4.7 - print "Expiry time (seconds from now [or 0]): " + expiry_time 4.8 + print "Expiry time (seconds from now [or 0]): " + str(expiry_time) 4.9 4.10 rc = XenoUtil.vd_refresh(id, expiry_time) 4.11 4.12 elif cmd == 'list': 4.13 + print 'ID Size(MB) Expiry' 4.14 4.15 for vbd in XenoUtil.vd_list(): 4.16 - print """ID: %s 4.17 -Expires: %s 4.18 -Expiry time: %s 4.19 -Size (MB): %d 4.20 -""" % (vbd['vdisk_id'], vbd['expires'], 4.21 - str(vbd['expiry_time']), vbd['size'] / 2048) 4.22 + vbd['size_mb'] = vbd['size'] / 2048 4.23 + vbd['expiry'] = (vbd['expires'] and vbd['expiry_time']) or 'never' 4.24 + print '%(vdisk_id)-4s %(size_mb)-12d %(expiry)s' % vbd 4.25 4.26 elif cmd == 'freespace': 4.27
5.1 --- a/tools/xc/lib/xc_netbsd_build.c Mon Feb 09 18:18:17 2004 +0000 5.2 +++ b/tools/xc/lib/xc_netbsd_build.c Tue Feb 10 14:38:31 2004 +0000 5.3 @@ -389,16 +389,19 @@ myseek(gzFile gfd, off_t offset, int whe 5.4 unsigned char tmp[MYSEEK_BUFSIZE]; 5.5 int c; 5.6 5.7 - if (offset < 0) { 5.8 + if ( offset < 0 ) 5.9 + { 5.10 ERROR("seek back not supported"); 5.11 return -1; 5.12 } 5.13 5.14 - while (offset) { 5.15 + while ( offset != 0 ) 5.16 + { 5.17 c = offset; 5.18 - if (c > MYSEEK_BUFSIZE) 5.19 + if ( c > MYSEEK_BUFSIZE ) 5.20 c = MYSEEK_BUFSIZE; 5.21 - if (gzread(gfd, tmp, c) != c) { 5.22 + if ( gzread(gfd, tmp, c) != c ) 5.23 + { 5.24 PERROR("Error seeking in image."); 5.25 return -1; 5.26 } 5.27 @@ -459,77 +462,91 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.28 p = NULL; 5.29 maxva = 0; 5.30 5.31 - if (gzread(kernel_gfd, &ehdr, sizeof(Elf_Ehdr)) != sizeof(Elf_Ehdr)) { 5.32 + if ( gzread(kernel_gfd, &ehdr, sizeof(Elf_Ehdr)) != sizeof(Elf_Ehdr) ) 5.33 + { 5.34 PERROR("Error reading kernel image ELF header."); 5.35 goto out; 5.36 } 5.37 curpos = sizeof(Elf_Ehdr); 5.38 5.39 - if (!IS_ELF(ehdr)) { 5.40 + if ( !IS_ELF(ehdr) ) 5.41 + { 5.42 PERROR("Image does not have an ELF header."); 5.43 goto out; 5.44 } 5.45 5.46 *virt_load_addr = ehdr.e_entry; 5.47 5.48 - if ((*virt_load_addr & (PAGE_SIZE-1)) != 0) { 5.49 + if ( (*virt_load_addr & (PAGE_SIZE-1)) != 0 ) 5.50 + { 5.51 ERROR("We can only deal with page-aligned load addresses"); 5.52 goto out; 5.53 } 5.54 5.55 - if ((*virt_load_addr + (tot_pages << PAGE_SHIFT)) > 5.56 - HYPERVISOR_VIRT_START) { 5.57 + if ( (*virt_load_addr + (tot_pages << PAGE_SHIFT)) > 5.58 + HYPERVISOR_VIRT_START ) 5.59 + { 5.60 ERROR("Cannot map all domain memory without hitting Xen space"); 5.61 goto out; 5.62 } 5.63 5.64 5.65 phdr = malloc(ehdr.e_phnum * sizeof(Elf_Phdr)); 5.66 - if (phdr == NULL) { 5.67 + if ( phdr == NULL ) 5.68 + { 5.69 ERROR("Cannot allocate memory for Elf_Phdrs"); 5.70 goto out; 5.71 } 5.72 5.73 - if (myseek(kernel_gfd, ehdr.e_phoff - curpos, SEEK_SET) == -1) { 5.74 + if ( myseek(kernel_gfd, ehdr.e_phoff - curpos, SEEK_SET) == -1 ) 5.75 + { 5.76 ERROR("Seek to program header failed"); 5.77 goto out; 5.78 } 5.79 curpos = ehdr.e_phoff; 5.80 5.81 - if (gzread(kernel_gfd, phdr, ehdr.e_phnum * sizeof(Elf_Phdr)) != 5.82 - ehdr.e_phnum * sizeof(Elf_Phdr)) { 5.83 + if ( gzread(kernel_gfd, phdr, ehdr.e_phnum * sizeof(Elf_Phdr)) != 5.84 + ehdr.e_phnum * sizeof(Elf_Phdr) ) 5.85 + { 5.86 PERROR("Error reading kernel image ELF program header."); 5.87 goto out; 5.88 } 5.89 curpos += ehdr.e_phnum * sizeof(Elf_Phdr); 5.90 5.91 - /* Copy kernel .text .data .bss segments into physical memory */ 5.92 - for (h = 0; h < ehdr.e_phnum; h++) { 5.93 - if (phdr[h].p_type != PT_LOAD || 5.94 - (phdr[h].p_flags & (PF_W|PF_X)) == 0) 5.95 + /* Copy run-time 'load' segments that are writeable and/or executable. */ 5.96 + for ( h = 0; h < ehdr.e_phnum; h++ ) 5.97 + { 5.98 + if ( (phdr[h].p_type != PT_LOAD) || 5.99 + ((phdr[h].p_flags & (PF_W|PF_X)) == 0) ) 5.100 continue; 5.101 5.102 - if (IS_TEXT(phdr[h]) || IS_DATA(phdr[h])) { 5.103 - if (myseek(kernel_gfd, phdr[h].p_offset - curpos, SEEK_SET) == 5.104 - -1) { 5.105 + if ( IS_TEXT(phdr[h]) || IS_DATA(phdr[h]) ) 5.106 + { 5.107 + if ( myseek(kernel_gfd, phdr[h].p_offset - curpos, 5.108 + SEEK_SET) == -1 ) 5.109 + { 5.110 ERROR("Seek to section failed"); 5.111 goto out; 5.112 } 5.113 curpos = phdr[h].p_offset; 5.114 5.115 - for (iva = phdr[h].p_vaddr; 5.116 - iva < phdr[h].p_vaddr + phdr[h].p_filesz; iva += c) { 5.117 + for ( iva = phdr[h].p_vaddr; 5.118 + iva < phdr[h].p_vaddr + phdr[h].p_filesz; 5.119 + iva += c) 5.120 + { 5.121 c = PAGE_SIZE - (iva & (PAGE_SIZE - 1)); 5.122 if (iva + c > phdr[h].p_vaddr + phdr[h].p_filesz) 5.123 c = phdr[h].p_vaddr + phdr[h].p_filesz - iva; 5.124 - if (gzread(kernel_gfd, page, c) != c) { 5.125 + if ( gzread(kernel_gfd, page, c) != c ) 5.126 + { 5.127 PERROR("Error reading kernel image page."); 5.128 goto out; 5.129 } 5.130 curpos += c; 5.131 vaddr = map_pfn(pm_handle, page_array[(iva - *virt_load_addr) 5.132 >> PAGE_SHIFT]); 5.133 - if (vaddr == NULL) { 5.134 + if ( vaddr == NULL ) 5.135 + { 5.136 ERROR("Couldn't map guest memory"); 5.137 goto out; 5.138 } 5.139 @@ -539,11 +556,12 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.140 unmap_pfn(pm_handle, vaddr); 5.141 } 5.142 5.143 - if (phdr[h].p_vaddr + phdr[h].p_filesz > maxva) 5.144 + if ( phdr[h].p_vaddr + phdr[h].p_filesz > maxva ) 5.145 maxva = phdr[h].p_vaddr + phdr[h].p_filesz; 5.146 } 5.147 5.148 - if (IS_BSS(phdr[h])) { 5.149 + if ( IS_BSS(phdr[h]) ) 5.150 + { 5.151 /* XXX maybe clear phdr[h].p_memsz bytes from 5.152 phdr[h].p_vaddr + phdr[h].p_filesz ??? */ 5.153 if (phdr[h].p_vaddr + phdr[h].p_memsz > maxva) 5.154 @@ -557,21 +575,24 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.155 5.156 p = malloc(sizeof(int) + sizeof(Elf_Ehdr) + 5.157 ehdr.e_shnum * sizeof(Elf_Shdr)); 5.158 - if (p == NULL) { 5.159 + if ( p == NULL ) 5.160 + { 5.161 ERROR("Cannot allocate memory for Elf_Shdrs"); 5.162 goto out; 5.163 } 5.164 5.165 shdr = (Elf_Shdr *)(p + sizeof(int) + sizeof(Elf_Ehdr)); 5.166 5.167 - if (myseek(kernel_gfd, ehdr.e_shoff - curpos, SEEK_SET) == -1) { 5.168 + if ( myseek(kernel_gfd, ehdr.e_shoff - curpos, SEEK_SET) == -1 ) 5.169 + { 5.170 ERROR("Seek to symbol header failed"); 5.171 goto out; 5.172 } 5.173 curpos = ehdr.e_shoff; 5.174 5.175 - if (gzread(kernel_gfd, shdr, ehdr.e_shnum * sizeof(Elf_Shdr)) != 5.176 - ehdr.e_shnum * sizeof(Elf_Shdr)) { 5.177 + if ( gzread(kernel_gfd, shdr, ehdr.e_shnum * sizeof(Elf_Shdr)) != 5.178 + ehdr.e_shnum * sizeof(Elf_Shdr) ) 5.179 + { 5.180 PERROR("Error reading kernel image ELF symbol header."); 5.181 goto out; 5.182 } 5.183 @@ -586,35 +607,45 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.184 maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1); 5.185 5.186 /* Copy kernel string / symbol tables into physical memory */ 5.187 - for (h = 0; h < ehdr.e_shnum; h++) { 5.188 - if (shdr[h].sh_type == SHT_STRTAB) { 5.189 - for (i = 0; i < ehdr.e_shnum; i++) 5.190 - if (shdr[i].sh_type == SHT_SYMTAB && 5.191 - shdr[i].sh_link == h) 5.192 + for ( h = 0; h < ehdr.e_shnum; h++ ) 5.193 + { 5.194 + if ( shdr[h].sh_type == SHT_STRTAB ) 5.195 + { 5.196 + /* Look for a strtab @i linked to symtab @h. */ 5.197 + for ( i = 0; i < ehdr.e_shnum; i++ ) 5.198 + if ( (shdr[i].sh_type == SHT_SYMTAB) && 5.199 + (shdr[i].sh_link == h) ) 5.200 break; 5.201 - if (i == ehdr.e_shnum) { 5.202 + /* Skip symtab @h if we found no corresponding strtab @i. */ 5.203 + if ( i == ehdr.e_shnum ) 5.204 + { 5.205 shdr[h].sh_offset = 0; 5.206 - continue; /* Skip string tables which are not for symbol tables */ 5.207 + continue; 5.208 } 5.209 } 5.210 5.211 - if (shdr[h].sh_type == SHT_STRTAB || 5.212 - shdr[h].sh_type == SHT_SYMTAB) { 5.213 - if (myseek(kernel_gfd, shdr[h].sh_offset - curpos, SEEK_SET) == 5.214 - -1) { 5.215 + if ( (shdr[h].sh_type == SHT_STRTAB) || 5.216 + (shdr[h].sh_type == SHT_SYMTAB) ) 5.217 + { 5.218 + if ( myseek(kernel_gfd, shdr[h].sh_offset - curpos, 5.219 + SEEK_SET) == -1 ) 5.220 + { 5.221 ERROR("Seek to symbol section failed"); 5.222 goto out; 5.223 } 5.224 curpos = shdr[h].sh_offset; 5.225 5.226 - shdr[h].sh_offset = maxva - *symtab_addr; /* Mangled to be based on ELF header location */ 5.227 + /* Mangled to be based on ELF header location. */ 5.228 + shdr[h].sh_offset = maxva - *symtab_addr; 5.229 5.230 DPRINTF(("copy section %d, size 0x%x\n", h, shdr[h].sh_size)); 5.231 - for (i = 0; i < shdr[h].sh_size; i += c, maxva += c) { 5.232 + for ( i = 0; i < shdr[h].sh_size; i += c, maxva += c ) 5.233 + { 5.234 c = PAGE_SIZE - (maxva & (PAGE_SIZE - 1)); 5.235 - if (c > (shdr[h].sh_size - i)) 5.236 + if ( c > (shdr[h].sh_size - i) ) 5.237 c = shdr[h].sh_size - i; 5.238 - if (gzread(kernel_gfd, page, c) != c) { 5.239 + if ( gzread(kernel_gfd, page, c) != c ) 5.240 + { 5.241 PERROR("Error reading kernel image page."); 5.242 goto out; 5.243 } 5.244 @@ -622,7 +653,8 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.245 5.246 vaddr = map_pfn(pm_handle, page_array[(maxva - *virt_load_addr) 5.247 >> PAGE_SHIFT]); 5.248 - if (vaddr == NULL) { 5.249 + if ( vaddr == NULL ) 5.250 + { 5.251 ERROR("Couldn't map guest memory"); 5.252 goto out; 5.253 } 5.254 @@ -636,10 +668,11 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.255 maxva = (maxva + ELFROUND - 1) & ~(ELFROUND - 1); 5.256 5.257 } 5.258 - shdr[h].sh_name = 0; /* Name is NULL */ 5.259 + shdr[h].sh_name = 0; /* Name is NULL. */ 5.260 } 5.261 5.262 - if (*symtab_len == 0) { 5.263 + if ( *symtab_len == 0 ) 5.264 + { 5.265 DPRINTF(("no symbol table\n")); 5.266 *symtab_addr = 0; 5.267 ret = 0; 5.268 @@ -659,13 +692,15 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.269 5.270 /* Copy total length, crafted ELF header and section header table */ 5.271 s = sizeof(int) + sizeof(Elf_Ehdr) + ehdr.e_shnum * sizeof(Elf_Shdr); 5.272 - for (i = 0; i < s; i += c, symva += c) { 5.273 + for ( i = 0; i < s; i += c, symva += c ) 5.274 + { 5.275 c = PAGE_SIZE - (symva & (PAGE_SIZE - 1)); 5.276 - if (c > s - i) 5.277 + if ( c > s - i ) 5.278 c = s - i; 5.279 vaddr = map_pfn(pm_handle, page_array[(symva - *virt_load_addr) 5.280 >> PAGE_SHIFT]); 5.281 - if (vaddr == NULL) { 5.282 + if ( vaddr == NULL ) 5.283 + { 5.284 ERROR("Couldn't map guest memory"); 5.285 goto out; 5.286 } 5.287 @@ -681,7 +716,8 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.288 ret = 0; 5.289 5.290 out: 5.291 - if (ret == 0) { 5.292 + if ( ret == 0 ) 5.293 + { 5.294 maxva = (maxva + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); 5.295 *ksize = (maxva - *virt_load_addr) >> PAGE_SHIFT; 5.296 5.297 @@ -690,9 +726,9 @@ loadelfimage(gzFile kernel_gfd, int pm_h 5.298 (void *)*symtab_len)); 5.299 } 5.300 5.301 - if (phdr) 5.302 + if ( phdr != NULL ) 5.303 free(phdr); 5.304 - if (p) 5.305 + if ( p != NULL ) 5.306 free(p); 5.307 return ret; 5.308 }