From 4e92c9cd0ff6121fc3efc8b2ba248476e3208907 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 30 Nov 2005 12:51:24 +0100 Subject: [PATCH 01/15] Remove some vmx header files from Xen public interfaces. They are not public. Signed-off-by: Keir Fraser --- xen/arch/x86/dm/i8259.c | 2 +- xen/arch/x86/dm/vmx_vioapic.c | 2 +- xen/arch/x86/vmx.c | 4 +- xen/arch/x86/vmx_intercept.c | 2 +- xen/arch/x86/vmx_io.c | 5 +- xen/include/asm-x86/vmx_platform.h | 4 +- xen/include/{public/io => asm-x86}/vmx_vpic.h | 0 .../asm-x86/{vmx_virpit.h => vmx_vpit.h} | 2 +- xen/include/public/io/vmx_vlapic.h | 58 ------------------- 9 files changed, 10 insertions(+), 69 deletions(-) rename xen/include/{public/io => asm-x86}/vmx_vpic.h (100%) rename xen/include/asm-x86/{vmx_virpit.h => vmx_vpit.h} (97%) delete mode 100644 xen/include/public/io/vmx_vlapic.h diff --git a/xen/arch/x86/dm/i8259.c b/xen/arch/x86/dm/i8259.c index 3e7b191d34..c0d735dc52 100644 --- a/xen/arch/x86/dm/i8259.c +++ b/xen/arch/x86/dm/i8259.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/dm/vmx_vioapic.c b/xen/arch/x86/dm/vmx_vioapic.c index b955575e5e..b97a9b4bc2 100644 --- a/xen/arch/x86/dm/vmx_vioapic.c +++ b/xen/arch/x86/dm/vmx_vioapic.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include static void ioapic_enable(vmx_vioapic_t *s, uint8_t enable) diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index 7ae4f612b6..b4878317a0 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -43,8 +43,8 @@ #endif #include #include -#include -#include +#include +#include int hvm_enabled; diff --git a/xen/arch/x86/vmx_intercept.c b/xen/arch/x86/vmx_intercept.c index a7d49cd573..67029c2c95 100644 --- a/xen/arch/x86/vmx_intercept.c +++ b/xen/arch/x86/vmx_intercept.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/vmx_io.c b/xen/arch/x86/vmx_io.c index 7cbdafb277..5557e03474 100644 --- a/xen/arch/x86/vmx_io.c +++ b/xen/arch/x86/vmx_io.c @@ -32,13 +32,12 @@ #include #include #include -#include +#include #include #include - +#include #include #include -#include #ifdef CONFIG_VMX #if defined (__i386__) diff --git a/xen/include/asm-x86/vmx_platform.h b/xen/include/asm-x86/vmx_platform.h index 3e7563fe5c..636fbd9942 100644 --- a/xen/include/asm-x86/vmx_platform.h +++ b/xen/include/asm-x86/vmx_platform.h @@ -22,10 +22,10 @@ #include #include -#include +#include #include #include -#include +#include #define MAX_OPERAND_NUM 2 diff --git a/xen/include/public/io/vmx_vpic.h b/xen/include/asm-x86/vmx_vpic.h similarity index 100% rename from xen/include/public/io/vmx_vpic.h rename to xen/include/asm-x86/vmx_vpic.h diff --git a/xen/include/asm-x86/vmx_virpit.h b/xen/include/asm-x86/vmx_vpit.h similarity index 97% rename from xen/include/asm-x86/vmx_virpit.h rename to xen/include/asm-x86/vmx_vpit.h index fad07a9847..e5fb1bc368 100644 --- a/xen/include/asm-x86/vmx_virpit.h +++ b/xen/include/asm-x86/vmx_vpit.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #define PIT_FREQ 1193181 diff --git a/xen/include/public/io/vmx_vlapic.h b/xen/include/public/io/vmx_vlapic.h deleted file mode 100644 index f63a9aaf16..0000000000 --- a/xen/include/public/io/vmx_vlapic.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _VMX_VLAPIC_H -#define _VMX_VLAPIC_H - -/* - We extended one bit for PIC type - */ -#define VLAPIC_DELIV_MODE_FIXED 0x0 -#define VLAPIC_DELIV_MODE_LPRI 0x1 -#define VLAPIC_DELIV_MODE_SMI 0x2 -#define VLAPIC_DELIV_MODE_NMI 0x4 -#define VLAPIC_DELIV_MODE_INIT 0x5 -#define VLAPIC_DELIV_MODE_STARTUP 0x6 -#define VLAPIC_DELIV_MODE_EXT 0x7 -#define VLAPIC_DELIV_MODE_MASK 0x8 - -#define VLAPIC_MSG_LEVEL 4 - -#define INTR_EXT 0 -#define INTR_APIC 1 -#define INTR_LAPIC 2 - -#define VL_STATE_EOI 1 -#define VL_STATE_EXT_LOCK 2 -#define VL_STATE_MSG_LOCK 3 -#define VL_STATE_EOI_LOCK 3 - -#define VLOCAL_APIC_MAX_INTS 256 -#define VLAPIC_INT_COUNT (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE * sizeof(uint64_t))) -#define VLAPIC_INT_COUNT_32 (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE * sizeof(uint32_t))) - -typedef struct { - /* interrupt for PIC and ext type IOAPIC interrupt */ - uint64_t vl_ext_intr[VLAPIC_INT_COUNT]; - uint64_t vl_ext_intr_mask[VLAPIC_INT_COUNT]; - uint64_t vl_apic_intr[VLAPIC_INT_COUNT]; - uint64_t vl_apic_tmr[VLAPIC_INT_COUNT]; - uint64_t vl_eoi[VLAPIC_INT_COUNT]; - uint32_t vl_lapic_id; - uint32_t direct_intr; - uint32_t vl_apr; - uint32_t vl_logical_dest; - uint32_t vl_dest_format; - uint32_t vl_arb_id; - uint32_t vl_state; - uint32_t apic_msg_count; -} vlapic_info; - -#endif /* _VMX_VLAPIC_H_ */ - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ From b2de462a06e0ab3e05a2b4bf29c39fc2820a2757 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 30 Nov 2005 16:03:05 +0100 Subject: [PATCH 02/15] Public interface cleanups. Widen some fields in public interface defintions for future extensibility. In particular, grant references are now 32 bits and this has some knock-on effects on split-driver interfaces. Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/blkback.c | 15 +++-- .../drivers/xen/blkfront/blkfront.c | 18 +++--- .../drivers/xen/blkfront/vbd.c | 3 + .../drivers/xen/blktap/blktap.c | 4 +- tools/blktap/blkdump.c | 11 ++-- tools/blktap/blktaplib.c | 4 +- tools/blktap/blktaplib.h | 4 +- tools/blktap/parallax/parallax.c | 27 ++++----- tools/blktap/ublkback/ublkbacklib.c | 40 ++++++------- xen/arch/x86/dom0_ops.c | 2 +- xen/include/public/acm_ops.h | 2 +- xen/include/public/dom0_ops.h | 59 +++++++------------ xen/include/public/grant_table.h | 27 +++++---- xen/include/public/io/blkif.h | 30 +++------- xen/include/public/io/tpmif.h | 2 +- xen/include/public/sched_ctl.h | 4 +- xen/include/public/xen.h | 4 +- 17 files changed, 111 insertions(+), 145 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index 34f06a1d86..fe478fe336 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -335,7 +335,6 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) { extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); int operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ; - unsigned long fas = 0; int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)]; pending_req_t *pending_req; struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST]; @@ -362,16 +361,17 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) preq.nr_sects = 0; for (i = 0; i < nseg; i++) { - fas = req->frame_and_sects[i]; - seg[i].nsec = blkif_last_sect(fas) - blkif_first_sect(fas) + 1; + seg[i].nsec = req->seg[i].last_sect - + req->seg[i].first_sect + 1; - if (seg[i].nsec <= 0) + if ((req->seg[i].last_sect >= (PAGE_SIZE >> 9)) || + (seg[i].nsec <= 0)) goto bad_descriptor; preq.nr_sects += seg[i].nsec; map[i].host_addr = MMAP_VADDR(pending_idx, i); map[i].dom = blkif->domid; - map[i].ref = blkif_gref_from_fas(fas); + map[i].ref = req->seg[i].gref; map[i].flags = GNTMAP_host_map; if ( operation == WRITE ) map[i].flags |= GNTMAP_readonly; @@ -390,9 +390,8 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) pending_idx, i)) >> PAGE_SHIFT, FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT)); #endif - fas = req->frame_and_sects[i]; - seg[i].buf = map[i].dev_bus_addr | - (blkif_first_sect(fas) << 9); + seg[i].buf = map[i].dev_bus_addr | + (req->seg[i].first_sect << 9); } else { errors++; } diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c index f204629f4d..447ad6b9b0 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -32,7 +32,6 @@ * IN THE SOFTWARE. */ - #if 1 #define ASSERT(p) \ if (!(p)) { printk("Assertion '%s' failed, line %d, file %s", #p , \ @@ -41,7 +40,6 @@ #define ASSERT(_p) #endif - #include #include "block.h" #include @@ -54,16 +52,14 @@ #include #include - #define BLKIF_STATE_DISCONNECTED 0 #define BLKIF_STATE_CONNECTED 1 #define BLKIF_STATE_SUSPENDED 2 #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ - (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) + (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE) #define GRANT_INVALID_REF 0 - static void connect(struct blkfront_info *); static void blkfront_closing(struct xenbus_device *); static int blkfront_remove(struct xenbus_device *); @@ -551,8 +547,11 @@ static int blkif_queue_request(struct request *req) info->shadow[id].frame[ring_req->nr_segments] = mfn_to_pfn(buffer_mfn); - ring_req->frame_and_sects[ring_req->nr_segments] = - blkif_fas_from_gref(ref, fsect, lsect); + ring_req->seg[ring_req->nr_segments] = + (struct blkif_request_segment) { + .gref = ref, + .first_sect = fsect, + .last_sect = lsect }; ring_req->nr_segments++; } @@ -699,8 +698,7 @@ static void blkif_completion(struct blk_shadow *s) { int i; for (i = 0; i < s->req.nr_segments; i++) - gnttab_end_foreign_access( - blkif_gref_from_fas(s->req.frame_and_sects[i]), 0, 0UL); + gnttab_end_foreign_access(s->req.seg[i].gref, 0, 0UL); } static void blkif_recover(struct blkfront_info *info) @@ -740,7 +738,7 @@ static void blkif_recover(struct blkfront_info *info) /* Rewrite any grant references invalidated by susp/resume. */ for (j = 0; j < req->nr_segments; j++) gnttab_grant_foreign_access_ref( - blkif_gref_from_fas(req->frame_and_sects[j]), + req->seg[j].gref, info->xbdev->otherend_id, pfn_to_mfn(info->shadow[req->id].frame[j]), rq_data_dir( diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c index fdc78c315f..47ebba39f2 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c @@ -33,6 +33,9 @@ #include #include +#define BLKIF_MAJOR(dev) ((dev)>>8) +#define BLKIF_MINOR(dev) ((dev) & 0xff) + /* * For convenience we distinguish between ide, scsi and 'other' (i.e., * potentially combinations of the two) in the naming scheme and in a few other diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c index 9bbf32c135..aa0bdef432 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c @@ -713,7 +713,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) /* Map the remote page to kernel. */ map[op].host_addr = kvaddr; map[op].dom = blkif->domid; - map[op].ref = blkif_gref_from_fas(req->frame_and_sects[i]); + map[op].ref = req->seg[i].gref; map[op].flags = GNTMAP_host_map; /* This needs a bit more thought in terms of interposition: * If we want to be able to modify pages during write using @@ -733,7 +733,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) map[op].host_addr = ptep; map[op].dom = blkif->domid; - map[op].ref = blkif_gref_from_fas(req->frame_and_sects[i]); + map[op].ref = req->seg[i].gref; map[op].flags = GNTMAP_host_map | GNTMAP_application_map | GNTMAP_contains_pte; /* Above interposition comment applies here as well. */ diff --git a/tools/blktap/blkdump.c b/tools/blktap/blkdump.c index 3ba8d1add7..afa2754d2f 100644 --- a/tools/blktap/blkdump.c +++ b/tools/blktap/blkdump.c @@ -11,7 +11,6 @@ int request_print(blkif_request_t *req) { int i; - unsigned long fas; if ( (req->operation == BLKIF_OP_READ) || (req->operation == BLKIF_OP_WRITE) ) @@ -24,12 +23,10 @@ int request_print(blkif_request_t *req) for (i=0; i < req->nr_segments; i++) { - fas = req->frame_and_sects[i]; - printf(" (pf: 0x%8lx start: %lu stop: %lu)\n", - (fas & PAGE_MASK), - blkif_first_sect(fas), - blkif_last_sect(fas) - ); + printf(" (gref: 0x%8x start: %u stop: %u)\n", + req->seg[i].gref, + req->seg[i].first_sect, + req->seg[i].last_sect); } } else { diff --git a/tools/blktap/blktaplib.c b/tools/blktap/blktaplib.c index fbac562127..940d14d83f 100644 --- a/tools/blktap/blktaplib.c +++ b/tools/blktap/blktaplib.c @@ -244,8 +244,8 @@ int blktap_listen(void) RING_IDX rp, i, pfd_count; /* pending rings */ - blkif_request_t req_pending[BLKIF_RING_SIZE]; - /* blkif_response_t rsp_pending[BLKIF_RING_SIZE] */; + blkif_request_t req_pending[BLK_RING_SIZE]; + /* blkif_response_t rsp_pending[BLK_RING_SIZE] */; /* handler hooks: */ request_hook_t *req_hook; diff --git a/tools/blktap/blktaplib.h b/tools/blktap/blktaplib.h index 520165310f..c3e9332e2b 100644 --- a/tools/blktap/blktaplib.h +++ b/tools/blktap/blktaplib.h @@ -18,11 +18,13 @@ #include #include +#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE) + /* /dev/xen/blktap resides at device number major=10, minor=202 */ #define BLKTAP_MINOR 202 /* size of the extra VMA area to map in attached pages. */ -#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE +#define BLKTAP_VMA_PAGES BLK_RING_SIZE /* blktap IOCTLs: */ #define BLKTAP_IOCTL_KICK_FE 1 diff --git a/tools/blktap/parallax/parallax.c b/tools/blktap/parallax/parallax.c index 822604dffa..9664d7d7b8 100644 --- a/tools/blktap/parallax/parallax.c +++ b/tools/blktap/parallax/parallax.c @@ -280,8 +280,7 @@ int parallax_probe(blkif_request_t *req, blkif_t *blkif) goto err; /* Make sure the buffer is page-sized. */ - if ( (blkif_first_sect(req->frame_and_sects[0]) != 0) || - (blkif_last_sect (req->frame_and_sects[0]) != 7) ) + if ( (req->seg[0].first_sect != 0) || (req->seg[0].last_sect != 7) ) goto err; /* fill the list of devices */ @@ -350,17 +349,16 @@ static void read_cb(struct io_ret r, void *in_param) /* Calculate read size and offset within the read block. */ offset = (param->sector << SECTOR_SHIFT) % BLOCK_SIZE; - size = ( blkif_last_sect (req->frame_and_sects[segment]) - - blkif_first_sect(req->frame_and_sects[segment]) + 1 - ) << SECTOR_SHIFT; - start = blkif_first_sect(req->frame_and_sects[segment]) - << SECTOR_SHIFT; + size = (req->seg[segment].last_sect - req->seg[segment].first_sect + 1) << + SECTOR_SHIFT; + start = req->seg[segment].first_sect << SECTOR_SHIFT; DPRINTF("ParallaxRead: sect: %lld (%ld,%ld), " "vblock %llx, " "size %lx\n", - param->sector, blkif_first_sect(p->req->frame_and_sects[segment]), - blkif_last_sect (p->req->frame_and_sects[segment]), + param->sector, + p->req->seg[segment].first_sect, + p->req->seg[segment].last_sect, param->vblock, size); memcpy(dpage + start, spage + offset, size); @@ -506,16 +504,15 @@ int parallax_write(blkif_request_t *req, blkif_t *blkif) /* Calculate read size and offset within the read block. */ offset = (sector << SECTOR_SHIFT) % BLOCK_SIZE; - size = ( blkif_last_sect (req->frame_and_sects[i]) - - blkif_first_sect(req->frame_and_sects[i]) + 1 - ) << SECTOR_SHIFT; - start = blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT; + size = (req->seg[i].last_sect - req->seg[i].first_sect + 1) << + SECTOR_SHIFT; + start = req->seg[i].first_sect << SECTOR_SHIFT; DPRINTF("ParallaxWrite: sect: %lld (%ld,%ld), " "vblock %llx, gblock %llx, " "size %lx\n", - sector, blkif_first_sect(req->frame_and_sects[i]), - blkif_last_sect (req->frame_and_sects[i]), + sector, + req->seg[i].first_sect, req->seg[i].last_sect, vblock, gblock, size); /* XXX: For now we just freak out if they try to write a */ diff --git a/tools/blktap/ublkback/ublkbacklib.c b/tools/blktap/ublkback/ublkbacklib.c index 28b2a92806..ea096697e5 100644 --- a/tools/blktap/ublkback/ublkbacklib.c +++ b/tools/blktap/ublkback/ublkbacklib.c @@ -233,8 +233,7 @@ int ublkback_request(blkif_t *blkif, blkif_request_t *req, int batch_done) case BLKIF_OP_WRITE: { unsigned long size; - - + batch_count++; idx = ID_TO_IDX(req->id); @@ -247,18 +246,17 @@ int ublkback_request(blkif_t *blkif, blkif_request_t *req, int batch_done) sector = req->sector_number + (8*i); - size = blkif_last_sect (req->frame_and_sects[i]) - - blkif_first_sect(req->frame_and_sects[i]) + 1; + size = req->seg[i].last_sect - req->seg[i].first_sect + 1; - if (blkif_first_sect(req->frame_and_sects[i]) != 0) - DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) pos: %15lu\n", - req->sector_number, sector, - blkif_first_sect(req->frame_and_sects[i]), - blkif_last_sect (req->frame_and_sects[i]), - (long)(sector << SECTOR_SHIFT)); + if (req->seg[i].first_sect != 0) + DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) " + "pos: %15lu\n", + req->sector_number, sector, + req->seg[i].first_sect, req->seg[i].last_sect, + (long)(sector << SECTOR_SHIFT)); spage = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i); - spage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT; + spage += req->seg[i].first_sect << SECTOR_SHIFT; /*convert size and sector to byte offsets */ size <<= SECTOR_SHIFT; @@ -297,19 +295,17 @@ int ublkback_request(blkif_t *blkif, blkif_request_t *req, int batch_done) sector = req->sector_number + (8*i); - size = blkif_last_sect (req->frame_and_sects[i]) - - blkif_first_sect(req->frame_and_sects[i]) + 1; - + size = req->seg[i].last_sect - req->seg[i].first_sect + 1; + dpage = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i); - dpage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT; + dpage += req->seg[i].first_sect << SECTOR_SHIFT; - if (blkif_first_sect(req->frame_and_sects[i]) != 0) - DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) " - "pos: %15lu dpage: %p\n", - req->sector_number, sector, - blkif_first_sect(req->frame_and_sects[i]), - blkif_last_sect (req->frame_and_sects[i]), - (long)(sector << SECTOR_SHIFT), dpage); + if (req->seg[i].first_sect != 0) + DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) " + "pos: %15lu dpage: %p\n", + req->sector_number, sector, + req->seg[i].first_sect, req->seg[i].last_sect, + (long)(sector << SECTOR_SHIFT), dpage); /*convert size and sector to byte offsets */ size <<= SECTOR_SHIFT; diff --git a/xen/arch/x86/dom0_ops.c b/xen/arch/x86/dom0_ops.c index 380c01b932..4621057cbe 100644 --- a/xen/arch/x86/dom0_ops.c +++ b/xen/arch/x86/dom0_ops.c @@ -144,7 +144,7 @@ long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op) unsigned int p; ret = -EINVAL; - if ( (fp + np) >= 65536 ) + if ( (fp + np) > 65536 ) break; ret = -ESRCH; diff --git a/xen/include/public/acm_ops.h b/xen/include/public/acm_ops.h index 3b4fd0750f..d6ff4f8771 100644 --- a/xen/include/public/acm_ops.h +++ b/xen/include/public/acm_ops.h @@ -63,7 +63,7 @@ struct acm_getssid { ssidref_t ssidref; } id; void *ssidbuf; - uint16_t ssidbuf_size; + uint32_t ssidbuf_size; }; #define ACM_GETDECISION 8 diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index ae5a4e74a0..4ff18fcd06 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -19,7 +19,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA1012 +#define DOM0_INTERFACE_VERSION 0xAAAA1013 /************************************************************************/ @@ -98,7 +98,7 @@ typedef struct { typedef struct { /* IN variables. */ domid_t domain; - uint16_t vcpu; + uint32_t vcpu; /* IN/OUT parameters */ vcpu_guest_context_t *ctxt; } dom0_setdomaininfo_t; @@ -107,7 +107,7 @@ typedef struct { typedef struct { /* IN variables. */ uint32_t write; - uint32_t cpu_mask; + cpumap_t cpu_mask; uint32_t msr; uint32_t in1; uint32_t in2; @@ -116,21 +116,6 @@ typedef struct { uint32_t out2; } dom0_msr_t; -#define DOM0_DEBUG 16 -typedef struct { - /* IN variables. */ - domid_t domain; - uint8_t opcode; - uint32_t in1; - uint32_t in2; - uint32_t in3; - uint32_t in4; - /* OUT variables. */ - uint32_t status; - uint32_t out1; - uint32_t out2; -} dom0_debug_t; - /* * Set clock such that it would read after 00:00:00 UTC, * 1 January, 1970 if the current system time was . @@ -182,8 +167,8 @@ typedef struct { typedef struct { /* IN variables. */ domid_t domain; - uint16_t vcpu; - cpumap_t cpumap; + uint32_t vcpu; + cpumap_t cpumap; } dom0_pincpudomain_t; /* Get trace buffers machine base address */ @@ -196,9 +181,9 @@ typedef struct { #define DOM0_TBUF_SET_SIZE 3 #define DOM0_TBUF_ENABLE 4 #define DOM0_TBUF_DISABLE 5 - uint8_t op; + uint32_t op; /* IN/OUT variables */ - unsigned long cpu_mask; + cpumap_t cpu_mask; uint32_t evt_mask; /* OUT variables */ unsigned long buffer_mfn; @@ -327,7 +312,7 @@ typedef struct { #define DOM0_PERFCCONTROL_OP_RESET 1 /* Reset all counters to zero. */ #define DOM0_PERFCCONTROL_OP_QUERY 2 /* Get perfctr information. */ typedef struct { - uint8_t name[80]; /* name of perf counter */ + uint8_t name[80]; /* name of perf counter */ uint32_t nr_vals; /* number of values for this counter */ uint32_t vals[64]; /* array of values */ } dom0_perfc_desc_t; @@ -349,16 +334,16 @@ typedef struct { #define DOM0_IOPORT_PERMISSION 36 typedef struct { domid_t domain; /* domain to be affected */ - uint16_t first_port; /* first port int range */ - uint16_t nr_ports; /* size of port range */ - uint16_t allow_access; /* allow or deny access to range? */ + uint32_t first_port; /* first port int range */ + uint32_t nr_ports; /* size of port range */ + uint8_t allow_access; /* allow or deny access to range? */ } dom0_ioport_permission_t; #define DOM0_GETVCPUCONTEXT 37 typedef struct { /* IN variables. */ domid_t domain; /* domain to be affected */ - uint16_t vcpu; /* vcpu # */ + uint32_t vcpu; /* vcpu # */ /* OUT variables. */ vcpu_guest_context_t *ctxt; } dom0_getvcpucontext_t; @@ -367,7 +352,7 @@ typedef struct { typedef struct { /* IN variables. */ domid_t domain; /* domain to be affected */ - uint16_t vcpu; /* vcpu # */ + uint32_t vcpu; /* vcpu # */ /* OUT variables. */ uint8_t online; /* currently online (not hotplugged)? */ uint8_t blocked; /* blocked waiting for an event? */ @@ -381,35 +366,36 @@ typedef struct { typedef struct { /* IN variables. */ domid_t first_domain; - unsigned int max_domains; + uint32_t max_domains; dom0_getdomaininfo_t *buffer; /* OUT variables. */ - unsigned int num_domains; + uint32_t num_domains; } dom0_getdomaininfolist_t; #define DOM0_PLATFORM_QUIRK 39 #define QUIRK_NOIRQBALANCING 1 typedef struct { /* IN variables. */ - int quirk_id; + uint32_t quirk_id; } dom0_platform_quirk_t; #define DOM0_PHYSICAL_MEMORY_MAP 40 typedef struct { /* IN variables. */ - int max_map_entries; + uint32_t max_map_entries; /* OUT variables. */ - int nr_map_entries; + uint32_t nr_map_entries; struct dom0_memory_map_entry { uint64_t start, end; - int is_ram; + uint32_t flags; /* reserved */ + uint8_t is_ram; } *memory_map; } dom0_physical_memory_map_t; #define DOM0_MAX_VCPUS 41 typedef struct { - domid_t domain; /* domain to be affected */ - unsigned int max; /* maximum number of vcpus */ + domid_t domain; /* domain to be affected */ + uint32_t max; /* maximum number of vcpus */ } dom0_max_vcpus_t; #define DOM0_SETDOMAINHANDLE 44 @@ -433,7 +419,6 @@ typedef struct { dom0_getdomaininfo_t getdomaininfo; dom0_getpageframeinfo_t getpageframeinfo; dom0_msr_t msr; - dom0_debug_t debug; dom0_settime_t settime; dom0_readconsole_t readconsole; dom0_pincpudomain_t pincpudomain; diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index 0ee07dd4ff..c5d0f0bc4f 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -73,14 +73,14 @@ */ typedef struct grant_entry { /* GTF_xxx: various type and flag information. [XEN,GST] */ - uint16_t flags; + uint16_t flags; /* The domain being granted foreign privileges. [GST] */ - domid_t domid; + domid_t domid; /* * GTF_permit_access: Frame that @domid is allowed to map and access. [GST] * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN] */ - uint32_t frame; + uint32_t frame; } grant_entry_t; /* @@ -131,7 +131,7 @@ typedef struct grant_entry { /* * Reference to a grant entry in a specified domain's grant table. */ -typedef uint16_t grant_ref_t; +typedef uint32_t grant_ref_t; /* * GNTTABOP_map_grant_ref: Map the grant entry (,) for access @@ -156,9 +156,9 @@ typedef struct gnttab_map_grant_ref { uint64_t host_addr; domid_t dom; grant_ref_t ref; - uint16_t flags; /* GNTMAP_* */ + uint32_t flags; /* GNTMAP_* */ /* OUT parameters. */ - int16_t handle; /* +ve: handle; -ve: GNTST_* */ + int32_t handle; /* +ve: handle; -ve: GNTST_* */ uint64_t dev_bus_addr; } gnttab_map_grant_ref_t; @@ -178,9 +178,9 @@ typedef struct gnttab_unmap_grant_ref { /* IN parameters. */ uint64_t host_addr; uint64_t dev_bus_addr; - uint16_t handle; + uint32_t handle; /* OUT parameters. */ - int16_t status; /* GNTST_* */ + int32_t status; /* GNTST_* */ } gnttab_unmap_grant_ref_t; /* @@ -196,9 +196,9 @@ typedef struct gnttab_unmap_grant_ref { typedef struct gnttab_setup_table { /* IN parameters. */ domid_t dom; - uint16_t nr_frames; + uint32_t nr_frames; /* OUT parameters. */ - int16_t status; /* GNTST_* */ + int32_t status; /* GNTST_* */ unsigned long *frame_list; } gnttab_setup_table_t; @@ -211,7 +211,7 @@ typedef struct gnttab_dump_table { /* IN parameters. */ domid_t dom; /* OUT parameters. */ - int16_t status; /* GNTST_* */ + int32_t status; /* GNTST_* */ } gnttab_dump_table_t; /* @@ -229,7 +229,7 @@ typedef struct { domid_t domid; grant_ref_t ref; /* OUT parameters. */ - int16_t status; + int32_t status; } gnttab_transfer_t; /* @@ -283,7 +283,8 @@ typedef struct { "invalid virtual address", \ "invalid device address", \ "no spare translation slot in the I/O MMU", \ - "permission denied" \ + "permission denied", \ + "bad page" \ } #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ diff --git a/xen/include/public/io/blkif.h b/xen/include/public/io/blkif.h index 0f25768708..3a9bf2e7bb 100644 --- a/xen/include/public/io/blkif.h +++ b/xen/include/public/io/blkif.h @@ -19,9 +19,6 @@ #define BLKIF_OP_READ 0 #define BLKIF_OP_WRITE 1 -/* NB. Ring size must be small enough for sizeof(blkif_ring_t) <= PAGE_SIZE. */ -#define BLKIF_RING_SIZE 64 - /* * Maximum scatter/gather segments per request. * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE. @@ -33,34 +30,25 @@ typedef struct blkif_request { uint8_t operation; /* BLKIF_OP_??? */ uint8_t nr_segments; /* number of segments */ blkif_vdev_t handle; /* only for read/write requests */ - unsigned long id; /* private guest value, echoed in resp */ + uint64_t id; /* private guest value, echoed in resp */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ - /* @f_a_s[4:0]=last_sect ; @f_a_s[9:5]=first_sect */ - /* @f_a_s[:16]= grant reference (16 bits) */ - /* @first_sect: first sector in frame to transfer (inclusive). */ - /* @last_sect: last sector in frame to transfer (inclusive). */ - unsigned long frame_and_sects[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct blkif_request_segment { + grant_ref_t gref; /* reference to I/O buffer frame */ + /* @first_sect: first sector in frame to transfer (inclusive). */ + /* @last_sect: last sector in frame to transfer (inclusive). */ + uint8_t first_sect, last_sect; + } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; } blkif_request_t; -#define blkif_fas(_addr, _fs, _ls) ((_addr)|((_fs)<<5)|(_ls)) -#define blkif_first_sect(_fas) (((_fas)>>5)&31) -#define blkif_last_sect(_fas) ((_fas)&31) - -#define blkif_fas_from_gref(_gref, _fs, _ls) (((_gref)<<16)|((_fs)<<5)|(_ls)) -#define blkif_gref_from_fas(_fas) ((_fas)>>16) - typedef struct blkif_response { - unsigned long id; /* copied from request */ + uint64_t id; /* copied from request */ uint8_t operation; /* copied from request */ - int16_t status; /* BLKIF_RSP_??? */ + int32_t status; /* BLKIF_RSP_??? */ } blkif_response_t; #define BLKIF_RSP_ERROR -1 /* non-specific 'error' */ #define BLKIF_RSP_OKAY 0 /* non-specific 'okay' */ -#define BLKIF_MAJOR(dev) ((dev)>>8) -#define BLKIF_MINOR(dev) ((dev) & 0xff) - /* * Generate blkif ring structures and types. */ diff --git a/xen/include/public/io/tpmif.h b/xen/include/public/io/tpmif.h index 0ad0a1e81e..f84626be9e 100644 --- a/xen/include/public/io/tpmif.h +++ b/xen/include/public/io/tpmif.h @@ -18,7 +18,7 @@ typedef struct { unsigned long addr; /* Machine address of packet. */ - int ref; /* grant table access reference */ + grant_ref_t ref; /* grant table access reference */ uint16_t id; /* Echoed in response message. */ uint16_t size; /* Packet size in bytes. */ } tpmif_tx_request_t; diff --git a/xen/include/public/sched_ctl.h b/xen/include/public/sched_ctl.h index 11b40c06f8..48837cf9b3 100644 --- a/xen/include/public/sched_ctl.h +++ b/xen/include/public/sched_ctl.h @@ -48,8 +48,8 @@ struct sched_adjdom_cmd { uint64_t period; uint64_t slice; uint64_t latency; - uint16_t extratime; - uint16_t weight; + uint32_t extratime; + uint32_t weight; } sedf; } u; diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index b27206caff..d93b4efc72 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -410,9 +410,9 @@ typedef struct start_info { unsigned long shared_info; /* MACHINE address of shared info struct. */ uint32_t flags; /* SIF_xxx flags. */ unsigned long store_mfn; /* MACHINE page number of shared page. */ - uint16_t store_evtchn; /* Event channel for store communication. */ + uint32_t store_evtchn; /* Event channel for store communication. */ unsigned long console_mfn; /* MACHINE address of console page. */ - uint16_t console_evtchn; /* Event channel for console messages. */ + uint32_t console_evtchn; /* Event channel for console messages. */ /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */ unsigned long pt_base; /* VIRTUAL address of page directory. */ unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */ From ba3f55e57acd354e4dde9751a5e585c2694b3338 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 30 Nov 2005 17:24:27 +0100 Subject: [PATCH 03/15] GNTTABOP_map_grant_ref returns error status and handle as separate fields. Update callers for new interface. Also use int16_t as standard error code type on all public interfaces. Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/blkback.c | 8 +++---- .../drivers/xen/blkback/common.h | 4 ++-- .../drivers/xen/blkback/interface.c | 4 ++-- .../drivers/xen/blktap/blktap.c | 16 +++++++------- .../drivers/xen/blktap/common.h | 2 +- .../drivers/xen/blktap/interface.c | 4 ++-- .../drivers/xen/netback/common.h | 4 ++-- .../drivers/xen/netback/interface.c | 8 +++---- .../drivers/xen/netback/netback.c | 8 +++---- .../drivers/xen/tpmback/common.h | 2 +- .../drivers/xen/tpmback/interface.c | 4 ++-- .../drivers/xen/tpmback/tpmback.c | 8 +++---- tools/libxc/xc_domain.c | 6 ++--- tools/libxc/xc_gnttab.c | 8 ++++--- tools/libxc/xenctrl.h | 14 +++++++----- xen/common/grant_table.c | 17 +++++++------- xen/include/public/dom0_ops.h | 2 +- xen/include/public/grant_table.h | 22 ++++++++++++------- xen/include/public/io/blkif.h | 2 +- 19 files changed, 77 insertions(+), 66 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index fe478fe336..586ce79d98 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -88,10 +88,10 @@ static inline void flush_plugged_queue(void) * handle returned must be used to unmap the frame. This is needed to * drop the ref count on the frame. */ -static u16 pending_grant_handles[MMAP_PAGES]; +static grant_handle_t pending_grant_handles[MMAP_PAGES]; #define pending_handle(_idx, _i) \ (pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)]) -#define BLKBACK_INVALID_HANDLE (0xFFFF) +#define BLKBACK_INVALID_HANDLE (~0) #ifdef CONFIG_XEN_BLKDEV_TAP_BE /* @@ -114,7 +114,7 @@ static void fast_flush_area(int idx, int nr_pages) { struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; unsigned int i, invcount = 0; - u16 handle; + grant_handle_t handle; int ret; for (i = 0; i < nr_pages; i++) { @@ -381,7 +381,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) BUG_ON(ret); for (i = 0; i < nseg; i++) { - if (likely(map[i].handle >= 0)) { + if (likely(map[i].status == 0)) { pending_handle(pending_idx, i) = map[i].handle; #ifdef __ia64__ MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h index 96eafda2fe..0926ed0731 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h @@ -66,8 +66,8 @@ typedef struct blkif_st { struct work_struct free_work; - u16 shmem_handle; - grant_ref_t shmem_ref; + grant_handle_t shmem_handle; + grant_ref_t shmem_ref; } blkif_t; blkif_t *alloc_blkif(domid_t domid); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c index 900b482719..15474a3205 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) unlock_vm_area(blkif->blk_ring_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } blkif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c index aa0bdef432..f4c80f22b4 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c @@ -177,8 +177,8 @@ extern inline domid_t ID_TO_DOM(unsigned long id) */ struct grant_handle_pair { - u16 kernel; - u16 user; + grant_handle_t kernel; + grant_handle_t user; }; static struct grant_handle_pair pending_grant_handles[MMAP_PAGES]; #define pending_handle(_idx, _i) \ @@ -755,17 +755,17 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2); kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2); - if (unlikely(map[i].handle < 0)) { + if (unlikely(map[i].status)) { DPRINTK("Error on kernel grant mapping (%d)\n", - map[i].handle); - ret = map[i].handle; + map[i].status); + ret = map[i].status; cancel = 1; } - if (unlikely(map[i+1].handle < 0)) { + if (unlikely(map[i+1].status)) { DPRINTK("Error on user grant mapping (%d)\n", - map[i+1].handle); - ret = map[i+1].handle; + map[i+1].status); + ret = map[i+1].status; cancel = 1; } diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h index 38fa80b557..9571b057e1 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h @@ -64,7 +64,7 @@ typedef struct blkif_st { struct work_struct free_work; - u16 shmem_handle; + grant_handle_t shmem_handle; grant_ref_t shmem_ref; } blkif_t; diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c index 8627c1a488..58f30b0cfd 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) unlock_vm_area(blkif->blk_ring_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } blkif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/common.h b/linux-2.6-xen-sparse/drivers/xen/netback/common.h index 5150cb8844..e1c5bd204f 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h @@ -45,9 +45,9 @@ typedef struct netif_st { u8 fe_dev_addr[6]; /* Physical parameters of the comms window. */ - u16 tx_shmem_handle; + grant_handle_t tx_shmem_handle; grant_ref_t tx_shmem_ref; - u16 rx_shmem_handle; + grant_handle_t rx_shmem_handle; grant_ref_t rx_shmem_ref; unsigned int evtchn; unsigned int irq; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c index 2cd235b222..f4682750cb 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c @@ -127,9 +127,9 @@ static int map_frontend_pages( unlock_vm_area(netif->comms_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Gnttab failure mapping tx_ring_ref!\n"); - return op.handle; + return op.status; } netif->tx_shmem_ref = tx_ring_ref; @@ -145,9 +145,9 @@ static int map_frontend_pages( unlock_vm_area(netif->comms_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Gnttab failure mapping rx_ring_ref!\n"); - return op.handle; + return op.status; } netif->rx_shmem_ref = rx_ring_ref; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 2941119f6b..0440aa4342 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -68,7 +68,7 @@ static PEND_RING_IDX dealloc_prod, dealloc_cons; static struct sk_buff_head tx_queue; -static u16 grant_tx_ref[MAX_PENDING_REQS]; +static grant_handle_t grant_tx_handle[MAX_PENDING_REQS]; static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS]; static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS]; @@ -412,7 +412,7 @@ inline static void net_tx_action_dealloc(void) pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)]; gop->host_addr = MMAP_VADDR(pending_idx); gop->dev_bus_addr = 0; - gop->handle = grant_tx_ref[pending_idx]; + gop->handle = grant_tx_handle[pending_idx]; gop++; } ret = HYPERVISOR_grant_table_op( @@ -592,7 +592,7 @@ static void net_tx_action(unsigned long unused) sizeof(txreq)); /* Check the remap error code. */ - if (unlikely(mop->handle < 0)) { + if (unlikely(mop->status)) { printk(KERN_ALERT "#### netback grant fails\n"); make_tx_response(netif, txreq.id, NETIF_RSP_ERROR); netif_put(netif); @@ -605,7 +605,7 @@ static void net_tx_action(unsigned long unused) set_phys_to_machine( __pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT, FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT)); - grant_tx_ref[pending_idx] = mop->handle; + grant_tx_handle[pending_idx] = mop->handle; data_len = (txreq.size > PKT_PROT_LEN) ? PKT_PROT_LEN : txreq.size; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h index e12d25a1dd..231f28bdb6 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h @@ -54,7 +54,7 @@ typedef struct tpmif_st { struct work_struct work; - u16 shmem_handle; + grant_handle_t shmem_handle; grant_ref_t shmem_ref; } tpmif_t; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c index df33db9bfe..c43fd0d72b 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c @@ -91,9 +91,9 @@ map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) unlock_vm_area(tpmif->tx_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } tpmif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c index dd14f6087c..8667c8d2fb 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c @@ -249,7 +249,7 @@ _packet_write(struct packet *pak, * and send it to the front end. */ tpmif_t *tpmif = pak->tpmif; - u16 handle; + grant_handle_t handle; int rc = 0; unsigned int i = 0; unsigned int offset = 0; @@ -290,7 +290,7 @@ _packet_write(struct packet *pak, handle = map_op.handle; - if (map_op.handle < 0) { + if (map_op.status) { DPRINTK(" Grant table operation failure !\n"); return 0; } @@ -427,7 +427,7 @@ packet_read_shmem(struct packet *pak, u32 i = (last_read / PAGE_SIZE); u32 pg_offset = last_read & (PAGE_SIZE - 1); u32 to_copy; - u16 handle; + grant_handle_t handle; tpmif_tx_request_t *tx; tx = &tpmif->tx->ring[0].req; @@ -455,7 +455,7 @@ packet_read_shmem(struct packet *pak, BUG(); } - if (map_op.handle < 0) { + if (map_op.status) { DPRINTK(" Grant table operation failure !\n"); return -EFAULT; } diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 062006094d..8cba15893d 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -365,9 +365,9 @@ int xc_domain_get_vcpu_info(int xc_handle, int xc_domain_ioport_permission(int xc_handle, uint32_t domid, - uint16_t first_port, - uint16_t nr_ports, - uint16_t allow_access) + uint32_t first_port, + uint32_t nr_ports, + uint32_t allow_access) { DECLARE_DOM0_OP; diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c index 54fb40e6e1..76b7b141c9 100644 --- a/tools/libxc/xc_gnttab.c +++ b/tools/libxc/xc_gnttab.c @@ -42,9 +42,10 @@ do_gnttab_op(int xc_handle, int xc_gnttab_map_grant_ref(int xc_handle, uint64_t host_virt_addr, uint32_t dom, - uint16_t ref, + grant_ref_t ref, uint16_t flags, - int16_t *handle, + int16_t *status, + grant_handle_t *handle, uint64_t *dev_bus_addr) { struct gnttab_map_grant_ref op; @@ -58,6 +59,7 @@ int xc_gnttab_map_grant_ref(int xc_handle, if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, &op, 1)) == 0 ) { + *status = op.status; *handle = op.handle; *dev_bus_addr = op.dev_bus_addr; } @@ -69,7 +71,7 @@ int xc_gnttab_map_grant_ref(int xc_handle, int xc_gnttab_unmap_grant_ref(int xc_handle, uint64_t host_virt_addr, uint64_t dev_bus_addr, - uint16_t handle, + grant_handle_t handle, int16_t *status) { struct gnttab_unmap_grant_ref op; diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 8afd5b01b2..d12ac4993f 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -374,9 +375,9 @@ int xc_domain_memory_decrease_reservation(int xc_handle, int xc_domain_ioport_permission(int xc_handle, uint32_t domid, - uint16_t first_port, - uint16_t nr_ports, - uint16_t allow_access); + uint32_t first_port, + uint32_t nr_ports, + uint32_t allow_access); unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, unsigned long mfn); @@ -475,15 +476,16 @@ int xc_grant_interface_close(int xc_handle); int xc_gnttab_map_grant_ref(int xc_handle, uint64_t host_virt_addr, uint32_t dom, - uint16_t ref, + grant_ref_t ref, uint16_t flags, - int16_t *handle, + int16_t *status, + grant_handle_t *handle, uint64_t *dev_bus_addr); int xc_gnttab_unmap_grant_ref(int xc_handle, uint64_t host_virt_addr, uint64_t dev_bus_addr, - uint16_t handle, + grant_handle_t handle, int16_t *status); int xc_gnttab_setup_table(int xc_handle, diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 46b16e0daf..5d4955196b 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -114,13 +114,13 @@ __gnttab_map_grant_ref( (GNTMAP_device_map|GNTMAP_host_map)) == 0) ) { DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags); - (void)__put_user(GNTST_bad_gntref, &uop->handle); + (void)__put_user(GNTST_bad_gntref, &uop->status); return GNTST_bad_gntref; } if ( acm_pre_grant_map_ref(dom) ) { - (void)__put_user(GNTST_permission_denied, &uop->handle); + (void)__put_user(GNTST_permission_denied, &uop->status); return GNTST_permission_denied; } @@ -130,7 +130,7 @@ __gnttab_map_grant_ref( if ( rd != NULL ) put_domain(rd); DPRINTK("Could not find domain %d\n", dom); - (void)__put_user(GNTST_bad_domain, &uop->handle); + (void)__put_user(GNTST_bad_domain, &uop->status); return GNTST_bad_domain; } @@ -145,7 +145,7 @@ __gnttab_map_grant_ref( { put_domain(rd); DPRINTK("Maptrack table is at maximum size.\n"); - (void)__put_user(GNTST_no_device_space, &uop->handle); + (void)__put_user(GNTST_no_device_space, &uop->status); return GNTST_no_device_space; } @@ -155,7 +155,7 @@ __gnttab_map_grant_ref( { put_domain(rd); DPRINTK("No more map handles available.\n"); - (void)__put_user(GNTST_no_device_space, &uop->handle); + (void)__put_user(GNTST_no_device_space, &uop->status); return GNTST_no_device_space; } @@ -370,6 +370,7 @@ __gnttab_map_grant_ref( (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr); (void)__put_user(handle, &uop->handle); + (void)__put_user(GNTST_okay, &uop->status); put_domain(rd); return rc; @@ -377,7 +378,7 @@ __gnttab_map_grant_ref( unlock_out: spin_unlock(&rd->grant_table->lock); - (void)__put_user(rc, &uop->handle); + (void)__put_user(rc, &uop->status); put_maptrack_handle(ld->grant_table, handle); return rc; } @@ -400,7 +401,7 @@ __gnttab_unmap_grant_ref( { domid_t dom; grant_ref_t ref; - u16 handle; + grant_handle_t handle; struct domain *ld, *rd; active_grant_entry_t *act; grant_entry_t *sha; @@ -957,7 +958,7 @@ gnttab_release_mappings( grant_table_t *gt = d->grant_table; grant_mapping_t *map; grant_ref_t ref; - u16 handle; + grant_handle_t handle; struct domain *rd; active_grant_entry_t *act; grant_entry_t *sha; diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index 4ff18fcd06..5627a441e4 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -19,7 +19,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA1013 +#define DOM0_INTERFACE_VERSION 0xAAAA1014 /************************************************************************/ diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index c5d0f0bc4f..166e4ae327 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -133,6 +133,11 @@ typedef struct grant_entry { */ typedef uint32_t grant_ref_t; +/* + * Handle to track a mapping created via a grant reference. + */ +typedef uint32_t grant_handle_t; + /* * GNTTABOP_map_grant_ref: Map the grant entry (,) for access * by devices and/or host CPUs. If successful, is a tracking number @@ -154,11 +159,12 @@ typedef uint32_t grant_ref_t; typedef struct gnttab_map_grant_ref { /* IN parameters. */ uint64_t host_addr; - domid_t dom; - grant_ref_t ref; uint32_t flags; /* GNTMAP_* */ + grant_ref_t ref; + domid_t dom; /* OUT parameters. */ - int32_t handle; /* +ve: handle; -ve: GNTST_* */ + int16_t status; /* GNTST_* */ + grant_handle_t handle; uint64_t dev_bus_addr; } gnttab_map_grant_ref_t; @@ -178,9 +184,9 @@ typedef struct gnttab_unmap_grant_ref { /* IN parameters. */ uint64_t host_addr; uint64_t dev_bus_addr; - uint32_t handle; + grant_handle_t handle; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ } gnttab_unmap_grant_ref_t; /* @@ -198,7 +204,7 @@ typedef struct gnttab_setup_table { domid_t dom; uint32_t nr_frames; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ unsigned long *frame_list; } gnttab_setup_table_t; @@ -211,7 +217,7 @@ typedef struct gnttab_dump_table { /* IN parameters. */ domid_t dom; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ } gnttab_dump_table_t; /* @@ -229,7 +235,7 @@ typedef struct { domid_t domid; grant_ref_t ref; /* OUT parameters. */ - int32_t status; + int16_t status; } gnttab_transfer_t; /* diff --git a/xen/include/public/io/blkif.h b/xen/include/public/io/blkif.h index 3a9bf2e7bb..9a91ef82f9 100644 --- a/xen/include/public/io/blkif.h +++ b/xen/include/public/io/blkif.h @@ -43,7 +43,7 @@ typedef struct blkif_request { typedef struct blkif_response { uint64_t id; /* copied from request */ uint8_t operation; /* copied from request */ - int32_t status; /* BLKIF_RSP_??? */ + int16_t status; /* BLKIF_RSP_??? */ } blkif_response_t; #define BLKIF_RSP_ERROR -1 /* non-specific 'error' */ From df2ba9e15b85f00c870236d9c2d9375336fa56fd Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 18:38:14 +0000 Subject: [PATCH 04/15] Added the errno to the messages printed with the ERR macro. Tidy the use of this macro where newlines have been appended -- the macro does this itself so there is no need to add another one. Signed-off-by: Ewan Mellor --- tools/libxc/xc_linux_restore.c | 4 ++-- tools/libxc/xc_linux_save.c | 8 ++++---- tools/libxc/xg_save_restore.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index f25c185abc..95ead19389 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -221,7 +221,7 @@ int xc_linux_restore(int xc_handle, int io_fd, if(xc_domain_memory_increase_reservation( xc_handle, dom, max_pfn, 0, 0, NULL) != 0) { - ERR("Failed to increase reservation by %lx KB\n", PFN_TO_KB(max_pfn)); + ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn)); errno = ENOMEM; goto out; } @@ -487,7 +487,7 @@ int xc_linux_restore(int xc_handle, int io_fd, for(k = 0; k < j; k++) { if(!uncanonicalize_pagetable(L1TAB, region_base + k*PAGE_SIZE)) { - ERR("failed uncanonicalize pt!\n"); + ERR("failed uncanonicalize pt!"); goto out; } } diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index f91a30b4f3..2d15ee587d 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -523,13 +523,13 @@ static unsigned long *xc_map_m2p(int xc_handle, xmml.max_extents = m2p_chunks; if (!(xmml.extent_start = malloc(m2p_chunks * sizeof(unsigned long)))) { - ERR("failed to allocate space for m2p mfns!\n"); + ERR("failed to allocate space for m2p mfns"); return NULL; } if (xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) || (xmml.nr_extents != m2p_chunks)) { - ERR("xc_get_m2p_mfns:"); + ERR("xc_get_m2p_mfns"); return NULL; } @@ -540,7 +540,7 @@ static unsigned long *xc_map_m2p(int xc_handle, } if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { - ERR("failed to allocate space for mmap entries!\n"); + ERR("failed to allocate space for mmap entries"); return NULL; } @@ -794,7 +794,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(unsigned long)); if ((pfn_type == NULL) || (pfn_batch == NULL)) { - ERR("failed to alloc memory for pfn_type and/or pfn_batch arays."); + ERR("failed to alloc memory for pfn_type and/or pfn_batch arrays"); errno = ENOMEM; goto out; } diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h index b9a4d38122..7c530b293c 100644 --- a/tools/libxc/xg_save_restore.h +++ b/tools/libxc/xg_save_restore.h @@ -10,7 +10,7 @@ #define PROGRESS 0 #define ERR(_f, _a...) do { \ - fprintf(stderr, _f "\n" , ## _a); \ + fprintf(stderr, _f ": %d\n" , ## _a, errno);\ fflush(stderr); } \ while (0) From 9d72feba41d33fc58dd645f2a711a606431db55b Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 18:38:48 +0000 Subject: [PATCH 05/15] Cope with longs being passed to xstransact.write. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/xenstore/xstransact.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/python/xen/xend/xenstore/xstransact.py b/tools/python/xen/xend/xenstore/xstransact.py index dcdad54a22..1a71035a7c 100644 --- a/tools/python/xen/xend/xenstore/xstransact.py +++ b/tools/python/xen/xend/xenstore/xstransact.py @@ -198,9 +198,10 @@ class xstransact: if len(tup) == 2: (key, val) = tup try: - fmt = { str : "%s", - int : "%i", - float : "%f", + fmt = { str : "%s", + int : "%i", + float : "%f", + long : "%li", type(None) : None }[type(val)] except KeyError: raise TypeError From fa45226f847cf8860e6989d9208cb6cc8ecf510c Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 18:43:00 +0000 Subject: [PATCH 06/15] Move the translation from pages to MiB out of XendNode and into the xc layer. xc has access to the page size for the platform and the Python layer does not, so there was a hardcoded "/ 256" in there. Rename the "memory" physinfo parameter to "total_memory", to match the usage elsewhere. Tidy the code generating the SXP for xm info. Signed-off-by: Ewan Mellor --- tools/python/xen/lowlevel/xc/xc.c | 11 +++- tools/python/xen/xend/XendNode.py | 61 ++++++++++++++-------- tools/xm-test/lib/XmTestReport/OSReport.py | 2 +- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index c63968f424..29f64641d6 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -575,6 +575,13 @@ static PyObject *pyxc_readconsolering(XcObject *self, return PyString_FromStringAndSize(str, count); } + +static unsigned long pages_to_mb(unsigned long pages) +{ + return (pages * (XC_PAGE_SIZE / 1024) + 1023) / 1024; +} + + static PyObject *pyxc_physinfo(XcObject *self) { xc_physinfo_t info; @@ -599,8 +606,8 @@ static PyObject *pyxc_physinfo(XcObject *self) "cores_per_socket", info.cores_per_socket, "sockets_per_node", info.sockets_per_node, "nr_nodes", info.nr_nodes, - "total_pages", info.total_pages, - "free_pages", info.free_pages, + "total_memory", pages_to_mb(info.total_pages), + "free_memory", pages_to_mb(info.free_pages), "cpu_khz", info.cpu_khz, "hw_caps", cpu_cap); } diff --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py index 250d11cece..02899bec27 100644 --- a/tools/python/xen/xend/XendNode.py +++ b/tools/python/xen/xend/XendNode.py @@ -57,30 +57,45 @@ class XendNode: ['machine', mch]] def physinfo(self): - pinfo = self.xc.physinfo() - info = [['nr_cpus', pinfo['nr_nodes']*pinfo['sockets_per_node']*pinfo['cores_per_socket']*pinfo['threads_per_core']], - ['nr_nodes', pinfo['nr_nodes']], - ['sockets_per_node', pinfo['sockets_per_node']], - ['cores_per_socket', pinfo['cores_per_socket']], - ['threads_per_core', pinfo['threads_per_core']], - ['cpu_mhz', pinfo['cpu_khz']/1000], - ['hw_caps', pinfo['hw_caps']], - ['memory', pinfo['total_pages']/256], - ['free_memory', pinfo['free_pages']/256]] - return info - + info = self.xc.physinfo() + + info['nr_cpus'] = (info['nr_nodes'] * + info['sockets_per_node'] * + info['cores_per_socket'] * + info['threads_per_core']) + info['cpu_mhz'] = info['cpu_khz'] / 1000 + + ITEM_ORDER = ['nr_cpus', + 'nr_nodes', + 'sockets_per_node', + 'cores_per_socket', + 'threads_per_core', + 'cpu_mhz', + 'hw_caps', + 'total_memory', + 'free_memory', + ] + + return [[k, info[k]] for k in ITEM_ORDER] + + def xeninfo(self): - xinfo = self.xc.xeninfo() - return [['xen_major', xinfo['xen_major']], - ['xen_minor', xinfo['xen_minor']], - ['xen_extra', xinfo['xen_extra']], - ['xen_caps', xinfo['xen_caps']], - ['platform_params',xinfo['platform_params']], - ['xen_changeset', xinfo['xen_changeset']], - ['cc_compiler', xinfo['cc_compiler']], - ['cc_compile_by', xinfo['cc_compile_by']], - ['cc_compile_domain', xinfo['cc_compile_domain']], - ['cc_compile_date', xinfo['cc_compile_date']]] + info = self.xc.xeninfo() + + ITEM_ORDER = ['xen_major', + 'xen_minor', + 'xen_extra', + 'xen_caps', + 'platform_params', + 'xen_changeset', + 'cc_compiler', + 'cc_compile_by', + 'cc_compile_domain', + 'cc_compile_date', + ] + + return [[k, info[k]] for k in ITEM_ORDER] + def instance(): global inst diff --git a/tools/xm-test/lib/XmTestReport/OSReport.py b/tools/xm-test/lib/XmTestReport/OSReport.py index c1d94b9774..dff20399e2 100644 --- a/tools/xm-test/lib/XmTestReport/OSReport.py +++ b/tools/xm-test/lib/XmTestReport/OSReport.py @@ -97,7 +97,7 @@ class Machine: "cores_per_socket" : "Unknown", "threads_per_core" : "Unknown", "cpu_mhz" : "Unknown", - "memory" : "Unknown"} + "total_memory" : "Unknown"} xen = self.__getXenInfo(xenValues) cpu = self.__getCpuInfo(cpuValues) From f0309906f0c55ef408e039d60955fc5dd14eca3b Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 18:48:27 +0000 Subject: [PATCH 07/15] Don't refuse to clean up after a domain death when the buffer is not empty. If the domain has gone away, then no-one can attach to the pty because Xend will have cleaned up the entries in the store, so the pty will never become ready to write. The buffer will never get emptied, so cleanup will never occur. This leaks ptys, file descriptors, and memory. Simply throw those data away instead. Signed-off-by: Ewan Mellor --- tools/console/daemon/io.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 80e76c416e..9aae032680 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -376,9 +376,6 @@ static void remove_domain(struct domain *dom) static void cleanup_domain(struct domain *d) { - if (!buffer_empty(&d->buffer)) - return; - if (d->tty_fd != -1) { close(d->tty_fd); d->tty_fd = -1; From 667035011d3441b4367e4968bf77171a184bea76 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 18:55:09 +0000 Subject: [PATCH 08/15] Fix the reporting when this test fails (the eyecatcher variables would not be created if the domain creation actually succeeded). Use total_memory not free_memory to determine how big to make the domain -- when ballooning down of dom0 works properly, creating a domain larger than free_memory is possible. Signed-off-by: Ewan Mellor --- tools/xm-test/tests/create/06_create_mem_neg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/xm-test/tests/create/06_create_mem_neg.py b/tools/xm-test/tests/create/06_create_mem_neg.py index d62dca61ae..187495caa0 100644 --- a/tools/xm-test/tests/create/06_create_mem_neg.py +++ b/tools/xm-test/tests/create/06_create_mem_neg.py @@ -31,6 +31,7 @@ domain1=XenDomain(opts1) try: domain1.start() + eyecatcher1 = "Created" except DomainError, e: eyecatcher1 = "Fail" @@ -41,7 +42,7 @@ if eyecatcher1 != "Fail": # Test 2: create a domain with mem>sys_mem -mem = int(getInfo("free_memory")) +mem = int(getInfo("total_memory")) extreme_mem = str(mem + 100) opts2= { @@ -56,6 +57,7 @@ domain2=XenDomain(opts2) try: domain2.start() + eyecatcher2 = "Created" except DomainError, e: eyecatcher2 = "Fail" From fd1b54b4d130a81fcf6a6cddd980d7080b6a8c4b Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 19:25:35 +0000 Subject: [PATCH 09/15] Match rename of xm info field from memory to total_memory. Signed-off-by: Ewan Mellor --- tools/xm-test/tests/info/02_info_compiledata_pos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xm-test/tests/info/02_info_compiledata_pos.py b/tools/xm-test/tests/info/02_info_compiledata_pos.py index 70731baa3a..3224e13b5e 100644 --- a/tools/xm-test/tests/info/02_info_compiledata_pos.py +++ b/tools/xm-test/tests/info/02_info_compiledata_pos.py @@ -24,7 +24,7 @@ for line in lines: map[pieces[0]] = pieces[1] for field in ["cores_per_socket", "threads_per_core", "cpu_mhz", - "memory", "free_memory", "xen_major", "xen_minor"]: + "total_memory", "free_memory", "xen_major", "xen_minor"]: val = map[field] if not val.isdigit(): FAIL("Numeric field %s not all-numbers: %s" % (field, val)) From 57daa6655da8c710e9b75b3286bcdb654d38e9d4 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 19:26:32 +0000 Subject: [PATCH 10/15] Move the relocate.setupRelocation code into XendDomain, removing the mutual dependency between those two classes. Split the XendDomain constructor into two pieces so that XendDomainInfo can call XendDomain.instance even during the initial startup of XendDomain. These two together mean that there is no need for the horrendous hack using XendRoot.get_component to pass the singleton instance of XendDomain around. Both XendRoot.get_component and XendRoot.add_component can go. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendDomain.py | 25 ++++++++++------ tools/python/xen/xend/XendDomainInfo.py | 20 ++++++------- tools/python/xen/xend/XendRoot.py | 36 ------------------------ tools/python/xen/xend/server/relocate.py | 25 ++++------------ 4 files changed, 30 insertions(+), 76 deletions(-) diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 4e76acfdbe..650a500e8f 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -24,6 +24,7 @@ import logging import os +import socket import sys import threading @@ -35,7 +36,6 @@ from xen.xend import XendRoot from xen.xend import XendCheckpoint from xen.xend.XendError import XendError from xen.xend.XendLogging import log -from xen.xend.server import relocate from xen.xend.xenstore.xswatch import xswatch @@ -54,15 +54,16 @@ class XendDomain: ## public: def __init__(self): - # Hack alert. Python does not support mutual imports, but XendDomainInfo - # needs access to the XendDomain instance to look up domains. Attempting - # to import XendDomain from XendDomainInfo causes unbounded recursion. - # So we stuff the XendDomain instance (self) into xroot's components. - xroot.add_component("xen.xend.XendDomain", self) - self.domains = {} self.domains_lock = threading.RLock() + + # This must be called only the once, by instance() below. It is separate + # from the constructor because XendDomainInfo calls back into this class + # in order to check the uniqueness of domain names. This means that + # instance() must be able to return a valid instance of this class even + # during this initialisation. + def init(self): self.domains_lock.acquire() try: self._add_domain( @@ -389,10 +390,15 @@ class XendDomain: dominfo = self.domain_lookup(domid) port = xroot.get_xend_relocation_port() - sock = relocate.setupRelocation(dst, port) + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((dst, port)) + except socket.error, err: + raise XendError("can't connect: %s" % err[1]) + sock.send("receive\n") XendCheckpoint.save(sock.fileno(), dominfo, live) - + def domain_save(self, domid, dst): """Start saving a domain to file. @@ -527,4 +533,5 @@ def instance(): inst except: inst = XendDomain() + inst.init() return inst diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index bbc7287f82..8f01f0aef0 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -33,14 +33,14 @@ import xen.lowlevel.xc from xen.util import asserts from xen.util.blkif import blkdev_uname_to_file -from xen.xend import image -from xen.xend import sxp -from xen.xend import XendRoot +import image +import sxp +import uuid +import XendDomain +import XendRoot + from xen.xend.XendBootloader import bootloader from xen.xend.XendError import XendError, VmError -from xen.xend.XendRoot import get_component - -import uuid from xen.xend.xenstore.xstransact import xstransact from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain @@ -338,9 +338,8 @@ def parseConfig(config): def domain_by_name(name): - # See comment in XendDomain constructor. - xd = get_component('xen.xend.XendDomain') - return xd.domain_lookup_by_name_nr(name) + return XendDomain.instance().domain_lookup_by_name_nr(name) + def shutdown_reason(code): """Get a shutdown reason from a code. @@ -1343,8 +1342,7 @@ class XendDomainInfo: new_dom = None try: - xd = get_component('xen.xend.XendDomain') - new_dom = xd.domain_create(config) + new_dom = XendDomain.instance().domain_create(config) new_dom.unpause() new_dom.removeVm(RESTART_IN_PROGRESS) except: diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py index 29398df901..d94f63a58d 100644 --- a/tools/python/xen/xend/XendRoot.py +++ b/tools/python/xen/xend/XendRoot.py @@ -93,24 +93,6 @@ class XendRoot: self.configure() - def add_component(self, name, val): - """Add a xend component. - - @param name: component name - @param val: component object - """ - self.components[name] = val - - def get_component(self, name): - """Get a xend component from its name. - This is used as a work-round for problems caused by mutually - recursive imports. - - @param name: component name - @return: component object (or None) - """ - return self.components.get(name) - def _logError(self, fmt, *args): """Logging function to log to stderr. We use this for XendRoot log messages because they may be logged before the logger has been @@ -277,21 +259,3 @@ def instance(): except: inst = XendRoot() return inst - -def add_component(name, val): - """Register a component with XendRoot. - This is used to work-round import cycles. - - @param name: component name - @param val: component value (often a module) - """ - return instance().add_component(name, val) - -def get_component(name): - """Get a component. - This is used to work-round import cycles. - - @param name: component name - @return component or None - """ - return instance().get_component(name) diff --git a/tools/python/xen/xend/server/relocate.py b/tools/python/xen/xend/server/relocate.py index f7cda14ec9..c179eaf6f7 100644 --- a/tools/python/xen/xend/server/relocate.py +++ b/tools/python/xen/xend/server/relocate.py @@ -23,16 +23,12 @@ import StringIO from xen.web import protocol, tcp, unix from xen.xend import sxp -from xen.xend.XendError import XendError +from xen.xend import XendDomain from xen.xend import XendRoot +from xen.xend.XendError import XendError from xen.xend.XendLogging import log -xroot = XendRoot.instance() - - -DEBUG = 0 - class RelocationProtocol(protocol.Protocol): """Asynchronous handler for a connected relocation socket. """ @@ -111,8 +107,8 @@ class RelocationProtocol(protocol.Protocol): if self.transport: self.send_reply(["ready", name]) self.transport.sock.setblocking(1) - xd = xroot.get_component("xen.xend.XendDomain") - xd.domain_restore_fd(self.transport.sock.fileno()) + XendDomain.instance().domain_restore_fd( + self.transport.sock.fileno()) self.transport.sock.setblocking(0) else: log.error(name + ": no transport") @@ -120,6 +116,7 @@ class RelocationProtocol(protocol.Protocol): def listenRelocation(): + xroot = XendRoot.instance() if xroot.get_xend_unix_server(): path = '/var/lib/xend/relocation-socket' unix.listenUNIX(path, RelocationProtocol) @@ -128,15 +125,3 @@ def listenRelocation(): interface = xroot.get_xend_relocation_address() l = tcp.listenTCP(port, RelocationProtocol, interface=interface) l.setCloExec() - -def setupRelocation(dst, port): - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((dst, port)) - except socket.error, err: - raise XendError("can't connect: %s" % err[1]) - - sock.send("receive\n") - print sock.recv(80) - - return sock From 3fba743862e569e23f5b895c36b2f6942622e319 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 19:48:21 +0000 Subject: [PATCH 11/15] Fix test following uuid format change in changeset 8089. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/tests/test_uuid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/python/xen/xend/tests/test_uuid.py b/tools/python/xen/xend/tests/test_uuid.py index cc78bd020c..d79ab53e4a 100644 --- a/tools/python/xen/xend/tests/test_uuid.py +++ b/tools/python/xen/xend/tests/test_uuid.py @@ -21,9 +21,9 @@ class test_uuid(unittest.TestCase): self.assertEqual(uuid.toString(inp), expected) self.assertEqual(uuid.fromString(expected), inp) - t([0 for i in range(0, 16)], "00000000-0000-0000-0000-000000000000") + t([0 for _ in range(0, 16)], "00000000-00000000-00000000-00000000") t([185, 158, 125, 206, 250, 178, 125, 57, 2, 6, 162, 74, 178, 236, - 196, 5], "b99e7dce-fab2-7d39-0206-a24ab2ecc405") + 196, 5], "b99e7dce-fab27d39-0206a24a-b2ecc405") def test_suite(): From a0c858f6bf6a10d9ce258c35741c7f5d9aa1ae23 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 19:48:54 +0000 Subject: [PATCH 12/15] Miscellaneous tidying up, no semantic changes. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendCheckpoint.py | 2 -- tools/python/xen/xend/XendProtocol.py | 8 ++++---- tools/python/xen/xend/XendRoot.py | 2 +- tools/python/xen/xend/server/netif.py | 4 ++-- tools/python/xen/xend/server/relocate.py | 1 - tools/python/xen/xend/tests/test_sxp.py | 4 ++-- tools/python/xen/xend/uuid.py | 10 +++++----- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py index a50a7b2cff..06c51ee417 100644 --- a/tools/python/xen/xend/XendCheckpoint.py +++ b/tools/python/xen/xend/XendCheckpoint.py @@ -18,8 +18,6 @@ import xen.util.auxbin import xen.lowlevel.xc -from xen.xend.xenstore.xsutil import IntroduceDomain - from XendError import XendError from XendLogging import log diff --git a/tools/python/xen/xend/XendProtocol.py b/tools/python/xen/xend/XendProtocol.py index 503af1d38b..20b6149577 100644 --- a/tools/python/xen/xend/XendProtocol.py +++ b/tools/python/xen/xend/XendProtocol.py @@ -100,7 +100,7 @@ class XendClientProtocol: """ return self.xendRequest(url, "POST", args) - def handleStatus(self, version, status, message): + def handleStatus(self, _, status, message): """Handle the status returned from the request. """ status = int(status) @@ -114,8 +114,8 @@ class XendClientProtocol: """Handle the data returned in response to the request. """ if data is None: return None - type = self.getHeader('Content-Type') - if type != sxp.mime_type: + typ = self.getHeader('Content-Type') + if typ != sxp.mime_type: return data try: pin = sxp.Parser() @@ -205,5 +205,5 @@ class UnixXendClientProtocol(HttpXendClientProtocol): path = xroot.get_xend_unix_path() self.path = path - def makeConnection(self, url): + def makeConnection(self, _): return UnixConnection(self.path) diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py index d94f63a58d..b61532737a 100644 --- a/tools/python/xen/xend/XendRoot.py +++ b/tools/python/xen/xend/XendRoot.py @@ -171,7 +171,7 @@ class XendRoot: v = self.get_config_value(name, val) try: return int(v) - except Exception, ex: + except Exception: raise XendError("invalid xend config %s: expected int: %s" % (name, v)) def get_xend_http_server(self): diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py index 14b079fdbb..9269d83ae0 100644 --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -71,8 +71,8 @@ class NetifController(DevController): script = os.path.join(xroot.network_script_dir, sxp.child_value(config, 'script', xroot.get_vif_script())) - type = sxp.child_value(config, 'type') - if type == 'ioemu': + typ = sxp.child_value(config, 'type') + if typ == 'ioemu': return (None,{},{}) bridge = sxp.child_value(config, 'bridge') mac = sxp.child_value(config, 'mac') diff --git a/tools/python/xen/xend/server/relocate.py b/tools/python/xen/xend/server/relocate.py index c179eaf6f7..d4480f242e 100644 --- a/tools/python/xen/xend/server/relocate.py +++ b/tools/python/xen/xend/server/relocate.py @@ -16,7 +16,6 @@ # Copyright (C) 2005 XenSource Ltd #============================================================================ -import socket import sys import StringIO diff --git a/tools/python/xen/xend/tests/test_sxp.py b/tools/python/xen/xend/tests/test_sxp.py index b0200b72cc..aad8161f10 100644 --- a/tools/python/xen/xend/tests/test_sxp.py +++ b/tools/python/xen/xend/tests/test_sxp.py @@ -6,8 +6,8 @@ import xen.xend.sxp class test_sxp(unittest.TestCase): def testAllFromString(self): - def t(input, expected): - self.assertEqual(xen.xend.sxp.all_from_string(input), expected) + def t(inp, expected): + self.assertEqual(xen.xend.sxp.all_from_string(inp), expected) t('String', ['String']) t('(String Thing)', [['String', 'Thing']]) diff --git a/tools/python/xen/xend/uuid.py b/tools/python/xen/xend/uuid.py index c471067fdd..2bf514c67d 100644 --- a/tools/python/xen/xend/uuid.py +++ b/tools/python/xen/xend/uuid.py @@ -25,14 +25,14 @@ import commands import random -def getUuidUuidgen(random = True): +def getUuidUuidgen(randomly = True): """Generate a UUID using the command uuidgen. - If random is true (default) generates a random uuid. - If random is false generates a time-based uuid. + If randomly is true (default) generates a random uuid. + If randomly is false generates a time-based uuid. """ cmd = "uuidgen" - if random: + if randomly: cmd += " -r" else: cmd += " -t" @@ -42,7 +42,7 @@ def getUuidUuidgen(random = True): def getUuidRandom(): """Generate a random UUID.""" - return [ random.randint(0, 255) for i in range(0, 16) ] + return [ random.randint(0, 255) for _ in range(0, 16) ] #uuidFactory = getUuidUuidgen From bf5ca2a1fdf6dde74934f0065b8d124c30863240 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 30 Nov 2005 19:54:28 +0000 Subject: [PATCH 13/15] Added xm rename command. Improve the argument checking and error reporting. --- tools/python/xen/xend/XendClient.py | 5 ++ tools/python/xen/xend/server/SrvDomain.py | 4 + tools/python/xen/xm/main.py | 99 +++++++++++++---------- 3 files changed, 66 insertions(+), 42 deletions(-) diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py index 75a106ad54..7e1ec07140 100644 --- a/tools/python/xen/xend/XendClient.py +++ b/tools/python/xen/xend/XendClient.py @@ -232,6 +232,11 @@ class Xend: return self.xendPost(self.domainurl(id), {'op' : 'pause' }) + def xend_domain_rename(self, id, name): + return self.xendPost(self.domainurl(id), + {'op' : 'rename', + 'name' : name}) + def xend_domain_shutdown(self, id, reason): return self.xendPost(self.domainurl(id), {'op' : 'shutdown', diff --git a/tools/python/xen/xend/server/SrvDomain.py b/tools/python/xen/xend/server/SrvDomain.py index a3e1584132..9e8b2d216f 100644 --- a/tools/python/xen/xend/server/SrvDomain.py +++ b/tools/python/xen/xend/server/SrvDomain.py @@ -55,6 +55,10 @@ class SrvDomain(SrvDir): req.setResponseCode(http.ACCEPTED) req.setHeader("Location", "%s/.." % req.prePathURL()) + def op_rename(self, _, req): + self.acceptCommand(req) + return self.dom.setName(req.args['name'][0]) + def op_shutdown(self, _, req): self.acceptCommand(req) return self.dom.shutdown(req.args['reason'][0]) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index e1f8a1a62d..bd4d03da47 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -70,6 +70,7 @@ vcpu_list_help = "vcpu-list List the VCPUs for a domain ( vcpu_pin_help = "vcpu-pin Set which cpus a VCPU can use" dmesg_help = "dmesg [--clear] Read or clear Xen's message buffer" info_help = "info Get information about the xen host" +rename_help = "rename Rename a domain" log_help = "log Print the xend log" sched_bvt_help = """sched-bvt Set Borrowed Virtual Time scheduler parameters""" @@ -125,6 +126,7 @@ domain_commands = [ "migrate", "pause", "reboot", + "rename", "restore", "save", "shutdown", @@ -226,10 +228,20 @@ for command in all_commands: # #################################################################### -def arg_check(args,num,name): - if len(args) < num: - err("'xm %s' requires %s argument(s)!\n" % (name, num)) - usage(name) +def arg_check(args, name, lo, hi = -1): + n = len(args) + + if hi == -1: + if n != lo: + err("'xm %s' requires %d argument%s.\n" % (name, lo, + lo > 1 and 's' or '')) + usage(name) + else: + if n < lo or n > hi: + err("'xm %s' requires between %d and %d arguments.\n" % + (name, lo, hi)) + usage(name) + def unit(c): if not c.isalpha(): @@ -259,14 +271,17 @@ def int_unit(str, dest): def err(msg): print >>sys.stderr, "Error:", msg -def handle_xend_error(cmd, dom, ex): +def handle_xend_error(cmd, args, ex): + non_option = filter(lambda x: x[0] != '-', args) + dom = len(non_option) > 0 and non_option[0] or None + error = str(ex) if error == "Not found" and dom != None: err("Domain '%s' not found when running 'xm %s'" % (dom, cmd)) - sys.exit(1) else: err(error) - sys.exit(1) + + sys.exit(1) ######################################################################### @@ -276,7 +291,7 @@ def handle_xend_error(cmd, dom, ex): ######################################################################### def xm_save(args): - arg_check(args,2,"save") + arg_check(args, "save", 2) dom = args[0] # TODO: should check if this exists savefile = os.path.abspath(args[1]) @@ -289,7 +304,7 @@ def xm_save(args): server.xend_domain_save(dom, savefile) def xm_restore(args): - arg_check(args,1,"restore") + arg_check(args, "restore", 1) savefile = os.path.abspath(args[0]) @@ -479,24 +494,30 @@ def xm_vcpu_list(args): def xm_reboot(args): - arg_check(args,1,"reboot") + arg_check(args, "reboot", 1, 4) from xen.xm import shutdown shutdown.main(["shutdown", "-R"] + args) def xm_pause(args): - arg_check(args, 1, "pause") + arg_check(args, "pause", 1) dom = args[0] from xen.xend.XendClient import server server.xend_domain_pause(dom) def xm_unpause(args): - arg_check(args, 1, "unpause") + arg_check(args, "unpause", 1) dom = args[0] from xen.xend.XendClient import server server.xend_domain_unpause(dom) +def xm_rename(args): + arg_check(args, "rename", 2) + + from xen.xend.XendClient import server + server.xend_domain_rename(args[0], args[1]) + def xm_subcommand(command, args): cmd = __import__(command, globals(), locals(), 'xen.xm') cmd.main([command] + args) @@ -517,7 +538,7 @@ def cpu_make_map(cpulist): return cpus def xm_vcpu_pin(args): - arg_check(args, 3, "vcpu-pin") + arg_check(args, "vcpu-pin", 3) dom = args[0] vcpu = int(args[1]) @@ -527,7 +548,7 @@ def xm_vcpu_pin(args): server.xend_domain_pincpu(dom, vcpu, cpumap) def xm_mem_max(args): - arg_check(args, 2, "mem-max") + arg_check(args, "mem-max", 2) dom = args[0] mem = int_unit(args[1], 'm') @@ -536,7 +557,7 @@ def xm_mem_max(args): server.xend_domain_maxmem_set(dom, mem) def xm_mem_set(args): - arg_check(args, 2, "mem-set") + arg_check(args, "mem-set", 2) dom = args[0] mem_target = int_unit(args[1], 'm') @@ -545,13 +566,13 @@ def xm_mem_set(args): server.xend_domain_mem_target_set(dom, mem_target) def xm_set_vcpus(args): - arg_check(args, 2, "set-vcpus") + arg_check(args, "set-vcpus", 2) from xen.xend.XendClient import server server.xend_domain_set_vcpus(args[0], int(args[1])) def xm_domid(args): - arg_check(args, 1, "domid") + arg_check(args, "domid", 1) name = args[0] @@ -560,7 +581,7 @@ def xm_domid(args): print sxp.child_value(dom, 'domid') def xm_domname(args): - arg_check(args, 1, "domname") + arg_check(args, "domname", 1) name = args[0] @@ -569,21 +590,21 @@ def xm_domname(args): print sxp.child_value(dom, 'name') def xm_sched_bvt(args): - arg_check(args, 6, "sched-bvt") + arg_check(args, "sched-bvt", 6) dom = args[0] v = map(long, args[1:6]) from xen.xend.XendClient import server server.xend_domain_cpu_bvt_set(dom, *v) def xm_sched_bvt_ctxallow(args): - arg_check(args, 1, "sched-bvt-ctxallow") + arg_check(args, "sched-bvt-ctxallow", 1) slice = int(args[0]) from xen.xend.XendClient import server server.xend_node_cpu_bvt_slice_set(slice) def xm_sched_sedf(args): - arg_check(args, 6, "sched-sedf") + arg_check(args, "sched-sedf", 6) dom = args[0] v = map(int, args[1:6]) @@ -600,9 +621,8 @@ def xm_info(args): else: print "%-23s:" % x[0], x[1] -# TODO: remove as soon as console server shows up def xm_console(args): - arg_check(args,1,"console") + arg_check(args, "console", 1) dom = args[0] from xen.xend.XendClient import server @@ -639,11 +659,13 @@ its contents if the [-c|--clear] flag is specified. server.xend_node_clear_dmesg() def xm_log(args): + arg_check(args, 'xm-log', 0) + from xen.xend.XendClient import server print server.xend_node_log() def xm_network_list(args): - arg_check(args,1,"network-list") + arg_check(args, "network-list", 1) dom = args[0] from xen.xend.XendClient import server for x in server.xend_domain_devices(dom, 'vif'): @@ -651,7 +673,7 @@ def xm_network_list(args): print def xm_block_list(args): - arg_check(args,1,"block-list") + arg_check(args, "block-list", 1) dom = args[0] from xen.xend.XendClient import server for x in server.xend_domain_devices(dom, 'vbd'): @@ -659,20 +681,14 @@ def xm_block_list(args): print def xm_block_attach(args): - n = len(args) - if n == 0: - usage("block-attach") - - if n < 4 or n > 5: - err("%s: Invalid argument(s)" % args[0]) - usage("block-attach") + arg_check(args, 'block-attach', 4, 5) dom = args[0] vbd = ['vbd', ['uname', args[1]], ['dev', args[2]], ['mode', args[3]]] - if n == 5: + if len(args) == 5: vbd.append(['backend', args[4]]) from xen.xend.XendClient import server @@ -680,10 +696,8 @@ def xm_block_attach(args): def xm_network_attach(args): - n = len(args) - if n == 0: - usage("network-attach") - + arg_check(args, 'network-attach', 1, 10000) + dom = args[0] vif = ['vif'] @@ -695,7 +709,7 @@ def xm_network_attach(args): def detach(args, command, deviceClass): - arg_check(args, 2, command) + arg_check(args, command, 2) dom = args[0] dev = args[1] @@ -742,7 +756,7 @@ def xm_vnet_list(args): print vnet, ex def xm_vnet_create(args): - arg_check(args, 1, "vnet-create") + arg_check(args, "vnet-create", 1) conf = args[0] if not os.access(conf, os.R_OK): print "File not found: %s" % conf @@ -752,7 +766,7 @@ def xm_vnet_create(args): server.xend_vnet_create(conf) def xm_vnet_delete(args): - arg_check(args, 1, "vnet-delete") + arg_check(args, "vnet-delete", 1) vnet = args[0] from xen.xend.XendClient import server server.xend_vnet_delete(vnet) @@ -765,6 +779,7 @@ commands = { # domain commands "domid": xm_domid, "domname": xm_domname, + "rename": xm_rename, "restore": xm_restore, "save": xm_save, "reboot": xm_reboot, @@ -888,7 +903,7 @@ def main(argv=sys.argv): sys.exit(1) except xen.xend.XendError.XendError, ex: if len(args) > 0: - handle_xend_error(argv[1], args[0], ex) + handle_xend_error(argv[1], args, ex) else: print "Unexpected error:", sys.exc_info()[0] print @@ -896,7 +911,7 @@ def main(argv=sys.argv): raise except xen.xend.XendProtocol.XendError, ex: if len(args) > 0: - handle_xend_error(argv[1], args[0], ex) + handle_xend_error(argv[1], args, ex) else: print "Unexpected error:", sys.exc_info()[0] print From 33ea7cb0ee35ab75f1a1fbf1b62a5131f4d0a381 Mon Sep 17 00:00:00 2001 From: "iap10@freefall.cl.cam.ac.uk" Date: Thu, 1 Dec 2005 02:36:46 +0100 Subject: [PATCH 14/15] Improve the tls warning message to mention that the best soloution is to install a 'xen-friendly' glibc. Signed-off-by: ian@xensource.com --- linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c b/linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c index ccfb39d2d6..5188b23f2f 100644 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/fixup.c @@ -56,9 +56,11 @@ fastcall void do_fixup_4gb_segment(struct pt_regs *regs, long error_code) DP("***************************************************************"); DP("***************************************************************"); DP("** WARNING: Currently emulating unsupported memory accesses **"); - DP("** in /lib/tls libraries. The emulation is very **"); + DP("** in /lib/tls glibc libraries. The emulation is **"); DP("** slow. To ensure full performance you should **"); - DP("** execute the following as root: **"); + DP("** install a 'xen-friendly' (nosegneg) version of **"); + DP("** the library, or disable tls support by executing **"); + DP("** the following as root: **"); DP("** mv /lib/tls /lib/tls.disabled **"); DP("** Offending process: %-38.38s **", info); DP("***************************************************************"); From 8d68c698752c120deab043ff371378e6954a9a29 Mon Sep 17 00:00:00 2001 From: "iap10@freefall.cl.cam.ac.uk" Date: Thu, 1 Dec 2005 02:43:04 +0100 Subject: [PATCH 15/15] Add a new /proc/xen file called 'capabilities'. Currently, when read in dom0 it will return 'control_d', and be empty when read in a guest. This provides a convenient way to allow the root user to detect whether they're running in a guest or dom0, and e.g. gate whether to start xend. In future, when we add more fine grained capabilities we will add other details into this file. Signed-off-by: ian@xensource.com --- .../drivers/xen/privcmd/privcmd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c index dff9343c5f..107f3e8bef 100644 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c @@ -33,6 +33,7 @@ #include static struct proc_dir_entry *privcmd_intf; +static struct proc_dir_entry *capabilities_intf; static int privcmd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data) @@ -234,6 +235,18 @@ static struct file_operations privcmd_file_ops = { .mmap = privcmd_mmap, }; +static int capabilities_read(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = 0; + *page = 0; + + if (xen_start_info->flags & SIF_INITDOMAIN) + len = sprintf( page, "control_d\n" ); + + *eof = 1; + return len; +} static int __init privcmd_init(void) { @@ -241,6 +254,10 @@ static int __init privcmd_init(void) if (privcmd_intf != NULL) privcmd_intf->proc_fops = &privcmd_file_ops; + capabilities_intf = create_xen_proc_entry("capabilities", 0400 ); + if (capabilities_intf != NULL) + capabilities_intf->read_proc = capabilities_read; + return 0; }