xen-vtx-unstable
changeset 6529:cc5f88b719d0
Merge.
line diff
1.1 --- a/.hgignore Mon Aug 22 11:37:48 2005 -0700 1.2 +++ b/.hgignore Tue Aug 23 12:03:21 2005 -0700 1.3 @@ -147,6 +147,7 @@ 1.4 ^tools/xcs/xcsdump$ 1.5 ^tools/xcutils/xc_restore$ 1.6 ^tools/xcutils/xc_save$ 1.7 +^tools/xenstat/xentop/xentop$ 1.8 ^tools/xenstore/testsuite/tmp/.*$ 1.9 ^tools/xenstore/xen$ 1.10 ^tools/xenstore/xenstored$
2.1 --- a/Config.mk Mon Aug 22 11:37:48 2005 -0700 2.2 +++ b/Config.mk Tue Aug 23 12:03:21 2005 -0700 2.3 @@ -14,6 +14,7 @@ LD = $(CROSS_COMPILE)ld 2.4 CC = $(CROSS_COMPILE)gcc 2.5 CPP = $(CROSS_COMPILE)gcc -E 2.6 AR = $(CROSS_COMPILE)ar 2.7 +RANLIB = $(CROSS_COMPILE)ranlib 2.8 NM = $(CROSS_COMPILE)nm 2.9 STRIP = $(CROSS_COMPILE)strip 2.10 OBJCOPY = $(CROSS_COMPILE)objcopy 2.11 @@ -43,3 +44,7 @@ KERNEL_REPO = http://www.kernel.org 2.12 # ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY 2.13 # ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY 2.14 ACM_USE_SECURITY_POLICY ?= ACM_NULL_POLICY 2.15 + 2.16 +# Optional components 2.17 +XENSTAT_XENTOP ?= y 2.18 +
41.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 Mon Aug 22 11:37:48 2005 -0700 41.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 Tue Aug 23 12:03:21 2005 -0700 41.3 @@ -807,7 +807,107 @@ CONFIG_DUMMY_CONSOLE=y 41.4 # 41.5 CONFIG_USB_ARCH_HAS_HCD=y 41.6 CONFIG_USB_ARCH_HAS_OHCI=y 41.7 -# CONFIG_USB is not set 41.8 +CONFIG_USB=y 41.9 +# CONFIG_USB_DEBUG is not set 41.10 + 41.11 +# 41.12 +# Miscellaneous USB options 41.13 +# 41.14 +# CONFIG_USB_DEVICEFS is not set 41.15 +# CONFIG_USB_BANDWIDTH is not set 41.16 +# CONFIG_USB_DYNAMIC_MINORS is not set 41.17 +# CONFIG_USB_OTG is not set 41.18 + 41.19 +# 41.20 +# USB Host Controller Drivers 41.21 +# 41.22 +# CONFIG_USB_EHCI_HCD is not set 41.23 +CONFIG_USB_OHCI_HCD=y 41.24 +# CONFIG_USB_OHCI_BIG_ENDIAN is not set 41.25 +CONFIG_USB_OHCI_LITTLE_ENDIAN=y 41.26 +CONFIG_USB_UHCI_HCD=y 41.27 +# CONFIG_USB_SL811_HCD is not set 41.28 + 41.29 +# 41.30 +# USB Device Class drivers 41.31 +# 41.32 +# CONFIG_USB_BLUETOOTH_TTY is not set 41.33 +# CONFIG_USB_ACM is not set 41.34 +# CONFIG_USB_PRINTER is not set 41.35 + 41.36 +# 41.37 +# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information 41.38 +# 41.39 +# CONFIG_USB_STORAGE is not set 41.40 + 41.41 +# 41.42 +# USB Input Devices 41.43 +# 41.44 +CONFIG_USB_HID=y 41.45 +CONFIG_USB_HIDINPUT=y 41.46 +# CONFIG_HID_FF is not set 41.47 +# CONFIG_USB_HIDDEV is not set 41.48 +# CONFIG_USB_AIPTEK is not set 41.49 +# CONFIG_USB_WACOM is not set 41.50 +# CONFIG_USB_KBTAB is not set 41.51 +# CONFIG_USB_POWERMATE is not set 41.52 +# CONFIG_USB_MTOUCH is not set 41.53 +# CONFIG_USB_EGALAX is not set 41.54 +# CONFIG_USB_XPAD is not set 41.55 +# CONFIG_USB_ATI_REMOTE is not set 41.56 + 41.57 +# 41.58 +# USB Imaging devices 41.59 +# 41.60 +# CONFIG_USB_MDC800 is not set 41.61 +# CONFIG_USB_MICROTEK is not set 41.62 + 41.63 +# 41.64 +# USB Multimedia devices 41.65 +# 41.66 +# CONFIG_USB_DABUSB is not set 41.67 + 41.68 +# 41.69 +# Video4Linux support is needed for USB Multimedia device support 41.70 +# 41.71 + 41.72 +# 41.73 +# USB Network Adapters 41.74 +# 41.75 +# CONFIG_USB_CATC is not set 41.76 +# CONFIG_USB_KAWETH is not set 41.77 +# CONFIG_USB_PEGASUS is not set 41.78 +# CONFIG_USB_RTL8150 is not set 41.79 +# CONFIG_USB_USBNET is not set 41.80 +CONFIG_USB_MON=y 41.81 + 41.82 +# 41.83 +# USB port drivers 41.84 +# 41.85 + 41.86 +# 41.87 +# USB Serial Converter support 41.88 +# 41.89 +# CONFIG_USB_SERIAL is not set 41.90 + 41.91 +# 41.92 +# USB Miscellaneous drivers 41.93 +# 41.94 +# CONFIG_USB_EMI62 is not set 41.95 +# CONFIG_USB_EMI26 is not set 41.96 +# CONFIG_USB_AUERSWALD is not set 41.97 +# CONFIG_USB_RIO500 is not set 41.98 +# CONFIG_USB_LEGOTOWER is not set 41.99 +# CONFIG_USB_LCD is not set 41.100 +# CONFIG_USB_LED is not set 41.101 +# CONFIG_USB_CYTHERM is not set 41.102 +# CONFIG_USB_PHIDGETKIT is not set 41.103 +# CONFIG_USB_PHIDGETSERVO is not set 41.104 +# CONFIG_USB_IDMOUSE is not set 41.105 + 41.106 +# 41.107 +# USB ATM/DSL drivers 41.108 +# 41.109 41.110 # 41.111 # USB Gadget Support
56.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/mpparse.c Mon Aug 22 11:37:48 2005 -0700 56.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/mpparse.c Tue Aug 23 12:03:21 2005 -0700 56.3 @@ -784,7 +784,9 @@ static int __init smp_scan_config (unsig 56.4 56.5 void __init find_smp_config (void) 56.6 { 56.7 +#ifndef CONFIG_XEN 56.8 unsigned int address; 56.9 +#endif 56.10 56.11 /* 56.12 * FIXME: Linux assumes you have 640K of base ram..
58.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c Mon Aug 22 11:37:48 2005 -0700 58.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c Tue Aug 23 12:03:21 2005 -0700 58.3 @@ -149,12 +149,12 @@ void cpu_idle (void) 58.4 58.5 if (cpu_is_offline(cpu)) { 58.6 local_irq_disable(); 58.7 +#if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU) 58.8 /* Ack it. From this point on until 58.9 we get woken up, we're not allowed 58.10 to take any locks. In particular, 58.11 don't printk. */ 58.12 __get_cpu_var(cpu_state) = CPU_DEAD; 58.13 -#if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU) 58.14 /* Tell hypervisor to take vcpu down. */ 58.15 HYPERVISOR_vcpu_down(cpu); 58.16 #endif
59.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c Mon Aug 22 11:37:48 2005 -0700 59.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c Tue Aug 23 12:03:21 2005 -0700 59.3 @@ -1575,19 +1575,20 @@ void __init setup_arch(char **cmdline_p) 59.4 /* Make sure we have a correctly sized P->M table. */ 59.5 if (max_pfn != xen_start_info.nr_pages) { 59.6 phys_to_machine_mapping = alloc_bootmem_low_pages( 59.7 - max_pfn * sizeof(unsigned long)); 59.8 + max_pfn * sizeof(unsigned int)); 59.9 59.10 if (max_pfn > xen_start_info.nr_pages) { 59.11 /* set to INVALID_P2M_ENTRY */ 59.12 memset(phys_to_machine_mapping, ~0, 59.13 - max_pfn * sizeof(unsigned long)); 59.14 + max_pfn * sizeof(unsigned int)); 59.15 memcpy(phys_to_machine_mapping, 59.16 - (unsigned long *)xen_start_info.mfn_list, 59.17 - xen_start_info.nr_pages * sizeof(unsigned long)); 59.18 + (unsigned int *)xen_start_info.mfn_list, 59.19 + xen_start_info.nr_pages * sizeof(unsigned int)); 59.20 } else { 59.21 memcpy(phys_to_machine_mapping, 59.22 - (unsigned long *)xen_start_info.mfn_list, 59.23 - max_pfn * sizeof(unsigned long)); 59.24 + (unsigned int *)xen_start_info.mfn_list, 59.25 + max_pfn * sizeof(unsigned int)); 59.26 + /* N.B. below relies on sizeof(int) == sizeof(long). */ 59.27 if (HYPERVISOR_dom_mem_op( 59.28 MEMOP_decrease_reservation, 59.29 (unsigned long *)xen_start_info.mfn_list + max_pfn, 59.30 @@ -1597,11 +1598,11 @@ void __init setup_arch(char **cmdline_p) 59.31 free_bootmem( 59.32 __pa(xen_start_info.mfn_list), 59.33 PFN_PHYS(PFN_UP(xen_start_info.nr_pages * 59.34 - sizeof(unsigned long)))); 59.35 + sizeof(unsigned int)))); 59.36 } 59.37 59.38 pfn_to_mfn_frame_list = alloc_bootmem_low_pages(PAGE_SIZE); 59.39 - for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ ) 59.40 + for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned int)), j++ ) 59.41 { 59.42 pfn_to_mfn_frame_list[j] = 59.43 virt_to_mfn(&phys_to_machine_mapping[i]);
61.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c Mon Aug 22 11:37:48 2005 -0700 61.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c Tue Aug 23 12:03:21 2005 -0700 61.3 @@ -1604,6 +1604,9 @@ static void smp_intr_exit(void) 61.4 unbind_ipi_from_irq(CALL_FUNCTION_VECTOR); 61.5 } 61.6 61.7 +extern void local_setup_timer_irq(void); 61.8 +extern void local_teardown_timer_irq(void); 61.9 + 61.10 void smp_suspend(void) 61.11 { 61.12 /* XXX todo: take down time and ipi's on all cpus */
65.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c Mon Aug 22 11:37:48 2005 -0700 65.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c Tue Aug 23 12:03:21 2005 -0700 65.3 @@ -281,7 +281,7 @@ fastcall void do_page_fault(struct pt_re 65.4 siginfo_t info; 65.5 65.6 /* Set the "privileged fault" bit to something sane. */ 65.7 - error_code &= 3; 65.8 + error_code &= ~4; 65.9 error_code |= (regs->xcs & 2) << 1; 65.10 if (regs->eflags & X86_EFLAGS_VM) 65.11 error_code |= 4;
68.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Mon Aug 22 11:37:48 2005 -0700 68.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Tue Aug 23 12:03:21 2005 -0700 68.3 @@ -348,9 +348,12 @@ static void __init pagetable_init (void) 68.4 { 68.5 unsigned long vaddr; 68.6 pgd_t *pgd_base = (pgd_t *)xen_start_info.pt_base; 68.7 + int i; 68.8 68.9 swapper_pg_dir = pgd_base; 68.10 init_mm.pgd = pgd_base; 68.11 + for (i = 0; i < NR_CPUS; i++) 68.12 + per_cpu(cur_pgd, i) = pgd_base; 68.13 68.14 /* Enable PSE if available */ 68.15 if (cpu_has_pse) {
69.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c Mon Aug 22 11:37:48 2005 -0700 69.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c Tue Aug 23 12:03:21 2005 -0700 69.3 @@ -36,6 +36,8 @@ void iounmap(volatile void __iomem *addr 69.4 { 69.5 } 69.6 69.7 +#ifdef __i386__ 69.8 + 69.9 void __init *bt_ioremap(unsigned long phys_addr, unsigned long size) 69.10 { 69.11 return NULL; 69.12 @@ -45,6 +47,8 @@ void __init bt_iounmap(void *addr, unsig 69.13 { 69.14 } 69.15 69.16 +#endif /* __i386__ */ 69.17 + 69.18 #else 69.19 69.20 /* 69.21 @@ -58,7 +62,7 @@ static inline int is_local_lowmem(unsign 69.22 extern unsigned long max_low_pfn; 69.23 unsigned long mfn = address >> PAGE_SHIFT; 69.24 unsigned long pfn = mfn_to_pfn(mfn); 69.25 - return ((pfn < max_low_pfn) && (pfn_to_mfn(pfn) == mfn)); 69.26 + return ((pfn < max_low_pfn) && (phys_to_machine_mapping[pfn] == mfn)); 69.27 } 69.28 69.29 /* 69.30 @@ -126,10 +130,12 @@ void __iomem * __ioremap(unsigned long p 69.31 return NULL; 69.32 area->phys_addr = phys_addr; 69.33 addr = (void __iomem *) area->addr; 69.34 + flags |= _PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED; 69.35 +#ifdef __x86_64__ 69.36 + flags |= _PAGE_USER; 69.37 +#endif 69.38 if (direct_remap_area_pages(&init_mm, (unsigned long) addr, phys_addr, 69.39 - size, __pgprot(_PAGE_PRESENT | _PAGE_RW | 69.40 - _PAGE_DIRTY | _PAGE_ACCESSED 69.41 - | flags), domid)) { 69.42 + size, __pgprot(flags), domid)) { 69.43 vunmap((void __force *) addr); 69.44 return NULL; 69.45 } 69.46 @@ -218,6 +224,8 @@ void iounmap(volatile void __iomem *addr 69.47 kfree(p); 69.48 } 69.49 69.50 +#ifdef __i386__ 69.51 + 69.52 void __init *bt_ioremap(unsigned long phys_addr, unsigned long size) 69.53 { 69.54 unsigned long offset, last_addr; 69.55 @@ -289,6 +297,8 @@ void __init bt_iounmap(void *addr, unsig 69.56 } 69.57 } 69.58 69.59 +#endif /* __i386__ */ 69.60 + 69.61 #endif /* CONFIG_XEN_PHYSDEV_ACCESS */ 69.62 69.63 /* These hacky macros avoid phys->machine translations. */ 69.64 @@ -346,7 +356,7 @@ int direct_remap_area_pages(struct mm_st 69.65 * Fill in the machine address: PTE ptr is done later by 69.66 * __direct_remap_area_pages(). 69.67 */ 69.68 - v->val = (machine_addr & PAGE_MASK) | pgprot_val(prot); 69.69 + v->val = pte_val_ma(pfn_pte_ma(machine_addr >> PAGE_SHIFT, prot)); 69.70 69.71 machine_addr += PAGE_SIZE; 69.72 address += PAGE_SIZE; 69.73 @@ -368,35 +378,37 @@ int direct_remap_area_pages(struct mm_st 69.74 69.75 EXPORT_SYMBOL(direct_remap_area_pages); 69.76 69.77 +static int lookup_pte_fn( 69.78 + pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 69.79 +{ 69.80 + unsigned long *ptep = (unsigned long *)data; 69.81 + if (ptep) 69.82 + *ptep = (pfn_to_mfn(page_to_pfn(pte_page)) << 69.83 + PAGE_SHIFT) | 69.84 + ((unsigned long)pte & ~PAGE_MASK); 69.85 + return 0; 69.86 +} 69.87 + 69.88 int create_lookup_pte_addr(struct mm_struct *mm, 69.89 unsigned long address, 69.90 unsigned long *ptep) 69.91 { 69.92 - int f(pte_t *pte, struct page *pte_page, unsigned long addr, 69.93 - void *data) { 69.94 - unsigned long *ptep = (unsigned long *)data; 69.95 - if (ptep) 69.96 - *ptep = (pfn_to_mfn(page_to_pfn(pte_page)) << 69.97 - PAGE_SHIFT) | 69.98 - ((unsigned long)pte & ~PAGE_MASK); 69.99 - return 0; 69.100 - } 69.101 - 69.102 - return generic_page_range(mm, address, PAGE_SIZE, f, ptep); 69.103 + return generic_page_range(mm, address, PAGE_SIZE, lookup_pte_fn, ptep); 69.104 } 69.105 69.106 EXPORT_SYMBOL(create_lookup_pte_addr); 69.107 69.108 +static int noop_fn( 69.109 + pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 69.110 +{ 69.111 + return 0; 69.112 +} 69.113 + 69.114 int touch_pte_range(struct mm_struct *mm, 69.115 unsigned long address, 69.116 unsigned long size) 69.117 { 69.118 - int f(pte_t *pte, struct page *pte_page, unsigned long addr, 69.119 - void *data) { 69.120 - return 0; 69.121 - } 69.122 - 69.123 - return generic_page_range(mm, address, size, f, NULL); 69.124 + return generic_page_range(mm, address, size, noop_fn, NULL); 69.125 } 69.126 69.127 EXPORT_SYMBOL(touch_pte_range);
73.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c Mon Aug 22 11:37:48 2005 -0700 73.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c Tue Aug 23 12:03:21 2005 -0700 73.3 @@ -435,9 +435,11 @@ void unbind_evtchn_from_irqhandler(unsig 73.4 unbind_evtchn_from_irq(evtchn); 73.5 } 73.6 73.7 +#ifdef CONFIG_SMP 73.8 static void do_nothing_function(void *ign) 73.9 { 73.10 } 73.11 +#endif 73.12 73.13 /* Rebind an evtchn so that it gets delivered to a specific cpu */ 73.14 static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
74.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c Mon Aug 22 11:37:48 2005 -0700 74.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c Tue Aug 23 12:03:21 2005 -0700 74.3 @@ -40,38 +40,82 @@ EXPORT_SYMBOL(gnttab_grant_foreign_trans 74.4 EXPORT_SYMBOL(gnttab_end_foreign_transfer); 74.5 EXPORT_SYMBOL(gnttab_alloc_grant_references); 74.6 EXPORT_SYMBOL(gnttab_free_grant_references); 74.7 +EXPORT_SYMBOL(gnttab_free_grant_reference); 74.8 EXPORT_SYMBOL(gnttab_claim_grant_reference); 74.9 EXPORT_SYMBOL(gnttab_release_grant_reference); 74.10 EXPORT_SYMBOL(gnttab_grant_foreign_access_ref); 74.11 EXPORT_SYMBOL(gnttab_grant_foreign_transfer_ref); 74.12 74.13 -static grant_ref_t gnttab_free_list[NR_GRANT_ENTRIES]; 74.14 +#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t)) 74.15 +#define GNTTAB_LIST_END (NR_GRANT_ENTRIES + 1) 74.16 + 74.17 +static grant_ref_t gnttab_list[NR_GRANT_ENTRIES]; 74.18 +static int gnttab_free_count = NR_GRANT_ENTRIES; 74.19 static grant_ref_t gnttab_free_head; 74.20 +static spinlock_t gnttab_list_lock = SPIN_LOCK_UNLOCKED; 74.21 74.22 static grant_entry_t *shared; 74.23 74.24 -/* 74.25 - * Lock-free grant-entry allocator 74.26 - */ 74.27 +static struct gnttab_free_callback *gnttab_free_callback_list = NULL; 74.28 74.29 -static inline int 74.30 -get_free_entry( 74.31 - void) 74.32 +static int 74.33 +get_free_entries(int count) 74.34 { 74.35 - grant_ref_t fh, nfh = gnttab_free_head; 74.36 - do { if ( unlikely((fh = nfh) == NR_GRANT_ENTRIES) ) return -1; } 74.37 - while ( unlikely((nfh = cmpxchg(&gnttab_free_head, fh, 74.38 - gnttab_free_list[fh])) != fh) ); 74.39 - return fh; 74.40 + unsigned long flags; 74.41 + int ref; 74.42 + grant_ref_t head; 74.43 + spin_lock_irqsave(&gnttab_list_lock, flags); 74.44 + if (gnttab_free_count < count) { 74.45 + spin_unlock_irqrestore(&gnttab_list_lock, flags); 74.46 + return -1; 74.47 + } 74.48 + ref = head = gnttab_free_head; 74.49 + gnttab_free_count -= count; 74.50 + while (count-- > 1) 74.51 + head = gnttab_list[head]; 74.52 + gnttab_free_head = gnttab_list[head]; 74.53 + gnttab_list[head] = GNTTAB_LIST_END; 74.54 + spin_unlock_irqrestore(&gnttab_list_lock, flags); 74.55 + return ref; 74.56 +} 74.57 + 74.58 +#define get_free_entry() get_free_entries(1) 74.59 + 74.60 +static void 74.61 +do_free_callbacks(void) 74.62 +{ 74.63 + struct gnttab_free_callback *callback = gnttab_free_callback_list, *next; 74.64 + gnttab_free_callback_list = NULL; 74.65 + while (callback) { 74.66 + next = callback->next; 74.67 + if (gnttab_free_count >= callback->count) { 74.68 + callback->next = NULL; 74.69 + callback->fn(callback->arg); 74.70 + } else { 74.71 + callback->next = gnttab_free_callback_list; 74.72 + gnttab_free_callback_list = callback; 74.73 + } 74.74 + callback = next; 74.75 + } 74.76 } 74.77 74.78 static inline void 74.79 -put_free_entry( 74.80 - grant_ref_t ref) 74.81 +check_free_callbacks(void) 74.82 { 74.83 - grant_ref_t fh, nfh = gnttab_free_head; 74.84 - do { gnttab_free_list[ref] = fh = nfh; wmb(); } 74.85 - while ( unlikely((nfh = cmpxchg(&gnttab_free_head, fh, ref)) != fh) ); 74.86 + if (unlikely(gnttab_free_callback_list)) 74.87 + do_free_callbacks(); 74.88 +} 74.89 + 74.90 +static void 74.91 +put_free_entry(grant_ref_t ref) 74.92 +{ 74.93 + unsigned long flags; 74.94 + spin_lock_irqsave(&gnttab_list_lock, flags); 74.95 + gnttab_list[ref] = gnttab_free_head; 74.96 + gnttab_free_head = ref; 74.97 + gnttab_free_count++; 74.98 + check_free_callbacks(); 74.99 + spin_unlock_irqrestore(&gnttab_list_lock, flags); 74.100 } 74.101 74.102 /* 74.103 @@ -79,8 +123,7 @@ put_free_entry( 74.104 */ 74.105 74.106 int 74.107 -gnttab_grant_foreign_access( 74.108 - domid_t domid, unsigned long frame, int readonly) 74.109 +gnttab_grant_foreign_access(domid_t domid, unsigned long frame, int readonly) 74.110 { 74.111 int ref; 74.112 74.113 @@ -96,8 +139,8 @@ gnttab_grant_foreign_access( 74.114 } 74.115 74.116 void 74.117 -gnttab_grant_foreign_access_ref( 74.118 - grant_ref_t ref, domid_t domid, unsigned long frame, int readonly) 74.119 +gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 74.120 + unsigned long frame, int readonly) 74.121 { 74.122 shared[ref].frame = frame; 74.123 shared[ref].domid = domid; 74.124 @@ -107,7 +150,7 @@ gnttab_grant_foreign_access_ref( 74.125 74.126 74.127 int 74.128 -gnttab_query_foreign_access( grant_ref_t ref ) 74.129 +gnttab_query_foreign_access(grant_ref_t ref) 74.130 { 74.131 u16 nflags; 74.132 74.133 @@ -117,7 +160,7 @@ gnttab_query_foreign_access( grant_ref_t 74.134 } 74.135 74.136 void 74.137 -gnttab_end_foreign_access( grant_ref_t ref, int readonly ) 74.138 +gnttab_end_foreign_access(grant_ref_t ref, int readonly) 74.139 { 74.140 u16 flags, nflags; 74.141 74.142 @@ -132,8 +175,7 @@ gnttab_end_foreign_access( grant_ref_t r 74.143 } 74.144 74.145 int 74.146 -gnttab_grant_foreign_transfer( 74.147 - domid_t domid, unsigned long pfn ) 74.148 +gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn) 74.149 { 74.150 int ref; 74.151 74.152 @@ -149,8 +191,8 @@ gnttab_grant_foreign_transfer( 74.153 } 74.154 74.155 void 74.156 -gnttab_grant_foreign_transfer_ref( 74.157 - grant_ref_t ref, domid_t domid, unsigned long pfn ) 74.158 +gnttab_grant_foreign_transfer_ref(grant_ref_t ref, domid_t domid, 74.159 + unsigned long pfn) 74.160 { 74.161 shared[ref].frame = pfn; 74.162 shared[ref].domid = domid; 74.163 @@ -159,8 +201,7 @@ gnttab_grant_foreign_transfer_ref( 74.164 } 74.165 74.166 unsigned long 74.167 -gnttab_end_foreign_transfer( 74.168 - grant_ref_t ref) 74.169 +gnttab_end_foreign_transfer(grant_ref_t ref) 74.170 { 74.171 unsigned long frame = 0; 74.172 u16 flags; 74.173 @@ -189,59 +230,79 @@ gnttab_end_foreign_transfer( 74.174 } 74.175 74.176 void 74.177 -gnttab_free_grant_references( u16 count, grant_ref_t head ) 74.178 +gnttab_free_grant_reference(grant_ref_t ref) 74.179 { 74.180 - /* TODO: O(N)...? */ 74.181 - grant_ref_t to_die = 0, next = head; 74.182 - int i; 74.183 + 74.184 + put_free_entry(ref); 74.185 +} 74.186 74.187 - for ( i = 0; i < count; i++ ) 74.188 - { 74.189 - to_die = next; 74.190 - next = gnttab_free_list[next]; 74.191 - put_free_entry( to_die ); 74.192 +void 74.193 +gnttab_free_grant_references(grant_ref_t head) 74.194 +{ 74.195 + grant_ref_t ref; 74.196 + unsigned long flags; 74.197 + int count = 1; 74.198 + if (head == GNTTAB_LIST_END) 74.199 + return; 74.200 + spin_lock_irqsave(&gnttab_list_lock, flags); 74.201 + ref = head; 74.202 + while (gnttab_list[ref] != GNTTAB_LIST_END) { 74.203 + ref = gnttab_list[ref]; 74.204 + count++; 74.205 } 74.206 + gnttab_list[ref] = gnttab_free_head; 74.207 + gnttab_free_head = head; 74.208 + gnttab_free_count += count; 74.209 + check_free_callbacks(); 74.210 + spin_unlock_irqrestore(&gnttab_list_lock, flags); 74.211 } 74.212 74.213 int 74.214 -gnttab_alloc_grant_references( u16 count, 74.215 - grant_ref_t *head, 74.216 - grant_ref_t *terminal ) 74.217 +gnttab_alloc_grant_references(u16 count, grant_ref_t *head) 74.218 { 74.219 - int i; 74.220 - grant_ref_t h = gnttab_free_head; 74.221 + int h = get_free_entries(count); 74.222 74.223 - for ( i = 0; i < count; i++ ) 74.224 - if ( unlikely(get_free_entry() == -1) ) 74.225 - goto not_enough_refs; 74.226 + if (h == -1) 74.227 + return -ENOSPC; 74.228 74.229 *head = h; 74.230 - *terminal = gnttab_free_head; 74.231 74.232 return 0; 74.233 - 74.234 -not_enough_refs: 74.235 - gnttab_free_head = h; 74.236 - return -ENOSPC; 74.237 } 74.238 74.239 int 74.240 -gnttab_claim_grant_reference( grant_ref_t *private_head, 74.241 - grant_ref_t terminal ) 74.242 +gnttab_claim_grant_reference(grant_ref_t *private_head) 74.243 { 74.244 - grant_ref_t g; 74.245 - if ( unlikely((g = *private_head) == terminal) ) 74.246 + grant_ref_t g = *private_head; 74.247 + if (unlikely(g == GNTTAB_LIST_END)) 74.248 return -ENOSPC; 74.249 - *private_head = gnttab_free_list[g]; 74.250 + *private_head = gnttab_list[g]; 74.251 return g; 74.252 } 74.253 74.254 void 74.255 -gnttab_release_grant_reference( grant_ref_t *private_head, 74.256 - grant_ref_t release ) 74.257 +gnttab_release_grant_reference(grant_ref_t *private_head, grant_ref_t release) 74.258 +{ 74.259 + gnttab_list[release] = *private_head; 74.260 + *private_head = release; 74.261 +} 74.262 + 74.263 +void 74.264 +gnttab_request_free_callback(struct gnttab_free_callback *callback, 74.265 + void (*fn)(void *), void *arg, u16 count) 74.266 { 74.267 - gnttab_free_list[release] = *private_head; 74.268 - *private_head = release; 74.269 + unsigned long flags; 74.270 + spin_lock_irqsave(&gnttab_list_lock, flags); 74.271 + if (callback->next) 74.272 + goto out; 74.273 + callback->fn = fn; 74.274 + callback->arg = arg; 74.275 + callback->count = count; 74.276 + callback->next = gnttab_free_callback_list; 74.277 + gnttab_free_callback_list = callback; 74.278 + check_free_callbacks(); 74.279 + out: 74.280 + spin_unlock_irqrestore(&gnttab_list_lock, flags); 74.281 } 74.282 74.283 /* 74.284 @@ -252,8 +313,9 @@ gnttab_release_grant_reference( grant_re 74.285 74.286 static struct proc_dir_entry *grant_pde; 74.287 74.288 -static int grant_ioctl(struct inode *inode, struct file *file, 74.289 - unsigned int cmd, unsigned long data) 74.290 +static int 74.291 +grant_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 74.292 + unsigned long data) 74.293 { 74.294 int ret; 74.295 privcmd_hypercall_t hypercall; 74.296 @@ -291,8 +353,9 @@ static struct file_operations grant_file 74.297 ioctl: grant_ioctl, 74.298 }; 74.299 74.300 -static int grant_read(char *page, char **start, off_t off, 74.301 - int count, int *eof, void *data) 74.302 +static int 74.303 +grant_read(char *page, char **start, off_t off, int count, int *eof, 74.304 + void *data) 74.305 { 74.306 int len; 74.307 unsigned int i; 74.308 @@ -321,8 +384,9 @@ static int grant_read(char *page, char * 74.309 return len; 74.310 } 74.311 74.312 -static int grant_write(struct file *file, const char __user *buffer, 74.313 - unsigned long count, void *data) 74.314 +static int 74.315 +grant_write(struct file *file, const char __user *buffer, unsigned long count, 74.316 + void *data) 74.317 { 74.318 /* TODO: implement this */ 74.319 return -ENOSYS; 74.320 @@ -330,7 +394,8 @@ static int grant_write(struct file *file 74.321 74.322 #endif /* CONFIG_PROC_FS */ 74.323 74.324 -int gnttab_resume(void) 74.325 +int 74.326 +gnttab_resume(void) 74.327 { 74.328 gnttab_setup_table_t setup; 74.329 unsigned long frames[NR_GRANT_FRAMES]; 74.330 @@ -349,7 +414,8 @@ int gnttab_resume(void) 74.331 return 0; 74.332 } 74.333 74.334 -int gnttab_suspend(void) 74.335 +int 74.336 +gnttab_suspend(void) 74.337 { 74.338 int i; 74.339 74.340 @@ -359,7 +425,8 @@ int gnttab_suspend(void) 74.341 return 0; 74.342 } 74.343 74.344 -static int __init gnttab_init(void) 74.345 +static int __init 74.346 +gnttab_init(void) 74.347 { 74.348 int i; 74.349 74.350 @@ -368,7 +435,7 @@ static int __init gnttab_init(void) 74.351 shared = (grant_entry_t *)fix_to_virt(FIX_GNTTAB_END); 74.352 74.353 for ( i = 0; i < NR_GRANT_ENTRIES; i++ ) 74.354 - gnttab_free_list[i] = i + 1; 74.355 + gnttab_list[i] = i + 1; 74.356 74.357 #ifdef CONFIG_PROC_FS 74.358 /*
80.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile Mon Aug 22 11:37:48 2005 -0700 80.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile Tue Aug 23 12:03:21 2005 -0700 80.3 @@ -44,7 +44,7 @@ obj-$(CONFIG_X86_PM_TIMER) += pmtimer.o 80.4 80.5 c-obj-$(CONFIG_MODULES) += module.o 80.6 80.7 -#obj-y += topology.o 80.8 +obj-y += topology.o 80.9 c-obj-y += intel_cacheinfo.o 80.10 80.11 bootflag-y += ../../../i386/kernel/bootflag.o
91.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c Mon Aug 22 11:37:48 2005 -0700 91.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c Tue Aug 23 12:03:21 2005 -0700 91.3 @@ -778,21 +778,21 @@ void __init setup_arch(char **cmdline_p) 91.4 /* Make sure we have a large enough P->M table. */ 91.5 if (end_pfn > xen_start_info.nr_pages) { 91.6 phys_to_machine_mapping = alloc_bootmem( 91.7 - max_pfn * sizeof(unsigned long)); 91.8 + max_pfn * sizeof(u32)); 91.9 memset(phys_to_machine_mapping, ~0, 91.10 - max_pfn * sizeof(unsigned long)); 91.11 + max_pfn * sizeof(u32)); 91.12 memcpy(phys_to_machine_mapping, 91.13 - (unsigned long *)xen_start_info.mfn_list, 91.14 - xen_start_info.nr_pages * sizeof(unsigned long)); 91.15 + (u32 *)xen_start_info.mfn_list, 91.16 + xen_start_info.nr_pages * sizeof(u32)); 91.17 free_bootmem( 91.18 __pa(xen_start_info.mfn_list), 91.19 PFN_PHYS(PFN_UP(xen_start_info.nr_pages * 91.20 - sizeof(unsigned long)))); 91.21 + sizeof(u32)))); 91.22 } 91.23 91.24 pfn_to_mfn_frame_list = alloc_bootmem(PAGE_SIZE); 91.25 91.26 - for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ ) 91.27 + for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(u32)), j++ ) 91.28 { 91.29 pfn_to_mfn_frame_list[j] = 91.30 virt_to_mfn(&phys_to_machine_mapping[i]);
98.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile Mon Aug 22 11:37:48 2005 -0700 98.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile Tue Aug 23 12:03:21 2005 -0700 98.3 @@ -6,10 +6,10 @@ XENARCH := $(subst ",,$(CONFIG_XENARCH)) 98.4 98.5 CFLAGS += -Iarch/$(XENARCH)/mm 98.6 98.7 -obj-y := init.o fault.o ioremap.o pageattr.o 98.8 +obj-y := init.o fault.o pageattr.o 98.9 c-obj-y := extable.o 98.10 98.11 -i386-obj-y := hypervisor.o 98.12 +i386-obj-y := hypervisor.o ioremap.o 98.13 98.14 #obj-y := init.o fault.o ioremap.o extable.o pageattr.o 98.15 #c-obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
100.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c Mon Aug 22 11:37:48 2005 -0700 100.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c Tue Aug 23 12:03:21 2005 -0700 100.3 @@ -559,6 +559,11 @@ static void xen_copy_pt(void) 100.4 100.5 void __init xen_init_pt(void) 100.6 { 100.7 + int i; 100.8 + 100.9 + for (i = 0; i < NR_CPUS; i++) 100.10 + per_cpu(cur_pgd, i) = init_mm.pgd; 100.11 + 100.12 memcpy((void *)init_level4_pgt, 100.13 (void *)xen_start_info.pt_base, PAGE_SIZE); 100.14
101.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/ioremap.c Mon Aug 22 11:37:48 2005 -0700 101.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 101.3 @@ -1,497 +0,0 @@ 101.4 -/* 101.5 - * arch/x86_64/mm/ioremap.c 101.6 - * 101.7 - * Re-map IO memory to kernel address space so that we can access it. 101.8 - * This is needed for high PCI addresses that aren't mapped in the 101.9 - * 640k-1MB IO memory area on PC's 101.10 - * 101.11 - * (C) Copyright 1995 1996 Linus Torvalds 101.12 - */ 101.13 - 101.14 -#include <linux/vmalloc.h> 101.15 -#include <linux/init.h> 101.16 -#include <linux/slab.h> 101.17 -#include <linux/module.h> 101.18 -#include <asm/io.h> 101.19 -#include <asm/fixmap.h> 101.20 -#include <asm/cacheflush.h> 101.21 -#include <asm/tlbflush.h> 101.22 -#include <asm/pgtable.h> 101.23 -#include <asm/pgalloc.h> 101.24 - 101.25 -/* 101.26 - * Reuse arch/xen/i396/mm/ioremap.c. Need to merge later 101.27 - */ 101.28 -#ifndef CONFIG_XEN_PHYSDEV_ACCESS 101.29 - 101.30 -void * __ioremap(unsigned long phys_addr, unsigned long size, 101.31 - unsigned long flags) 101.32 -{ 101.33 - return NULL; 101.34 -} 101.35 - 101.36 -void *ioremap_nocache (unsigned long phys_addr, unsigned long size) 101.37 -{ 101.38 - return NULL; 101.39 -} 101.40 - 101.41 -void iounmap(volatile void __iomem *addr) 101.42 -{ 101.43 -} 101.44 - 101.45 -void __init *bt_ioremap(unsigned long phys_addr, unsigned long size) 101.46 -{ 101.47 - return NULL; 101.48 -} 101.49 - 101.50 -void __init bt_iounmap(void *addr, unsigned long size) 101.51 -{ 101.52 -} 101.53 - 101.54 -#else 101.55 - 101.56 -#if defined(__i386__) 101.57 -/* 101.58 - * Does @address reside within a non-highmem page that is local to this virtual 101.59 - * machine (i.e., not an I/O page, nor a memory page belonging to another VM). 101.60 - * See the comment that accompanies pte_pfn() in pgtable-2level.h to understand 101.61 - * why this works. 101.62 - */ 101.63 -static inline int is_local_lowmem(unsigned long address) 101.64 -{ 101.65 - extern unsigned long max_low_pfn; 101.66 - unsigned long mfn = address >> PAGE_SHIFT; 101.67 - unsigned long pfn = mfn_to_pfn(mfn); 101.68 - return ((pfn < max_low_pfn) && (pfn_to_mfn(pfn) == mfn)); 101.69 -} 101.70 -#elif defined(__x86_64__) 101.71 -/* 101.72 - * 101.73 - */ 101.74 -static inline int is_local_lowmem(unsigned long address) 101.75 -{ 101.76 - return 0; 101.77 -} 101.78 -#endif 101.79 - 101.80 -/* 101.81 - * Generic mapping function (not visible outside): 101.82 - */ 101.83 - 101.84 -/* 101.85 - * Remap an arbitrary physical address space into the kernel virtual 101.86 - * address space. Needed when the kernel wants to access high addresses 101.87 - * directly. 101.88 - * 101.89 - * NOTE! We need to allow non-page-aligned mappings too: we will obviously 101.90 - * have to convert them into an offset in a page-aligned mapping, but the 101.91 - * caller shouldn't need to know that small detail. 101.92 - */ 101.93 -void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags) 101.94 -{ 101.95 - void __iomem * addr; 101.96 - struct vm_struct * area; 101.97 - unsigned long offset, last_addr; 101.98 - domid_t domid = DOMID_IO; 101.99 - 101.100 - /* Don't allow wraparound or zero size */ 101.101 - last_addr = phys_addr + size - 1; 101.102 - if (!size || last_addr < phys_addr) 101.103 - return NULL; 101.104 - 101.105 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST 101.106 - /* 101.107 - * Don't remap the low PCI/ISA area, it's always mapped.. 101.108 - */ 101.109 - if (phys_addr >= 0x0 && last_addr < 0x100000) 101.110 - return isa_bus_to_virt(phys_addr); 101.111 -#endif 101.112 - 101.113 - /* 101.114 - * Don't allow anybody to remap normal RAM that we're using.. 101.115 - */ 101.116 - if (is_local_lowmem(phys_addr)) { 101.117 - char *t_addr, *t_end; 101.118 - struct page *page; 101.119 - 101.120 - t_addr = bus_to_virt(phys_addr); 101.121 - t_end = t_addr + (size - 1); 101.122 - 101.123 - for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++) 101.124 - if(!PageReserved(page)) 101.125 - return NULL; 101.126 - 101.127 - domid = DOMID_LOCAL; 101.128 - } 101.129 - 101.130 - /* 101.131 - * Mappings have to be page-aligned 101.132 - */ 101.133 - offset = phys_addr & ~PAGE_MASK; 101.134 - phys_addr &= PAGE_MASK; 101.135 - size = PAGE_ALIGN(last_addr+1) - phys_addr; 101.136 - 101.137 - /* 101.138 - * Ok, go for it.. 101.139 - */ 101.140 - area = get_vm_area(size, VM_IOREMAP | (flags << 20)); 101.141 - if (!area) 101.142 - return NULL; 101.143 - area->phys_addr = phys_addr; 101.144 - addr = (void __iomem *) area->addr; 101.145 - if (direct_remap_area_pages(&init_mm, (unsigned long) addr, phys_addr, 101.146 - size, __pgprot(_PAGE_PRESENT | _PAGE_RW | 101.147 - _PAGE_DIRTY | _PAGE_ACCESSED 101.148 -#if defined(__x86_64__) 101.149 - | _PAGE_USER 101.150 -#endif 101.151 - | flags), domid)) { 101.152 - vunmap((void __force *) addr); 101.153 - return NULL; 101.154 - } 101.155 - return (void __iomem *) (offset + (char __iomem *)addr); 101.156 -} 101.157 - 101.158 - 101.159 -/** 101.160 - * ioremap_nocache - map bus memory into CPU space 101.161 - * @offset: bus address of the memory 101.162 - * @size: size of the resource to map 101.163 - * 101.164 - * ioremap_nocache performs a platform specific sequence of operations to 101.165 - * make bus memory CPU accessible via the readb/readw/readl/writeb/ 101.166 - * writew/writel functions and the other mmio helpers. The returned 101.167 - * address is not guaranteed to be usable directly as a virtual 101.168 - * address. 101.169 - * 101.170 - * This version of ioremap ensures that the memory is marked uncachable 101.171 - * on the CPU as well as honouring existing caching rules from things like 101.172 - * the PCI bus. Note that there are other caches and buffers on many 101.173 - * busses. In particular driver authors should read up on PCI writes 101.174 - * 101.175 - * It's useful if some control registers are in such an area and 101.176 - * write combining or read caching is not desirable: 101.177 - * 101.178 - * Must be freed with iounmap. 101.179 - */ 101.180 - 101.181 -void __iomem *ioremap_nocache (unsigned long phys_addr, unsigned long size) 101.182 -{ 101.183 - unsigned long last_addr; 101.184 - void __iomem *p = __ioremap(phys_addr, size, _PAGE_PCD); 101.185 - if (!p) 101.186 - return p; 101.187 - 101.188 - /* Guaranteed to be > phys_addr, as per __ioremap() */ 101.189 - last_addr = phys_addr + size - 1; 101.190 - 101.191 - if (is_local_lowmem(last_addr)) { 101.192 - struct page *ppage = virt_to_page(bus_to_virt(phys_addr)); 101.193 - unsigned long npages; 101.194 - 101.195 - phys_addr &= PAGE_MASK; 101.196 - 101.197 - /* This might overflow and become zero.. */ 101.198 - last_addr = PAGE_ALIGN(last_addr); 101.199 - 101.200 - /* .. but that's ok, because modulo-2**n arithmetic will make 101.201 - * the page-aligned "last - first" come out right. 101.202 - */ 101.203 - npages = (last_addr - phys_addr) >> PAGE_SHIFT; 101.204 - 101.205 - if (change_page_attr(ppage, npages, PAGE_KERNEL_NOCACHE) < 0) { 101.206 - iounmap(p); 101.207 - p = NULL; 101.208 - } 101.209 - global_flush_tlb(); 101.210 - } 101.211 - 101.212 - return p; 101.213 -} 101.214 - 101.215 -void iounmap(volatile void __iomem *addr) 101.216 -{ 101.217 - struct vm_struct *p; 101.218 - if ((void __force *) addr <= high_memory) 101.219 - return; 101.220 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST 101.221 - if ((unsigned long) addr >= fix_to_virt(FIX_ISAMAP_BEGIN)) 101.222 - return; 101.223 -#endif 101.224 - p = remove_vm_area((void *) (PAGE_MASK & (unsigned long __force) addr)); 101.225 - if (!p) { 101.226 - printk("__iounmap: bad address %p\n", addr); 101.227 - return; 101.228 - } 101.229 - 101.230 - if ((p->flags >> 20) && is_local_lowmem(p->phys_addr)) { 101.231 - /* p->size includes the guard page, but cpa doesn't like that */ 101.232 - change_page_attr(virt_to_page(bus_to_virt(p->phys_addr)), 101.233 - (p->size - PAGE_SIZE) >> PAGE_SHIFT, 101.234 - PAGE_KERNEL); 101.235 - global_flush_tlb(); 101.236 - } 101.237 - kfree(p); 101.238 -} 101.239 - 101.240 -#if defined(__i386__) 101.241 -void __init *bt_ioremap(unsigned long phys_addr, unsigned long size) 101.242 -{ 101.243 - unsigned long offset, last_addr; 101.244 - unsigned int nrpages; 101.245 - enum fixed_addresses idx; 101.246 - 101.247 - /* Don't allow wraparound or zero size */ 101.248 - last_addr = phys_addr + size - 1; 101.249 - if (!size || last_addr < phys_addr) 101.250 - return NULL; 101.251 - 101.252 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST 101.253 - /* 101.254 - * Don't remap the low PCI/ISA area, it's always mapped.. 101.255 - */ 101.256 - if (phys_addr >= 0x0 && last_addr < 0x100000) 101.257 - return isa_bus_to_virt(phys_addr); 101.258 -#endif 101.259 - 101.260 - /* 101.261 - * Mappings have to be page-aligned 101.262 - */ 101.263 - offset = phys_addr & ~PAGE_MASK; 101.264 - phys_addr &= PAGE_MASK; 101.265 - size = PAGE_ALIGN(last_addr) - phys_addr; 101.266 - 101.267 - /* 101.268 - * Mappings have to fit in the FIX_BTMAP area. 101.269 - */ 101.270 - nrpages = size >> PAGE_SHIFT; 101.271 - if (nrpages > NR_FIX_BTMAPS) 101.272 - return NULL; 101.273 - 101.274 - /* 101.275 - * Ok, go for it.. 101.276 - */ 101.277 - idx = FIX_BTMAP_BEGIN; 101.278 - while (nrpages > 0) { 101.279 - set_fixmap(idx, phys_addr); 101.280 - phys_addr += PAGE_SIZE; 101.281 - --idx; 101.282 - --nrpages; 101.283 - } 101.284 - return (void*) (offset + fix_to_virt(FIX_BTMAP_BEGIN)); 101.285 -} 101.286 - 101.287 -void __init bt_iounmap(void *addr, unsigned long size) 101.288 -{ 101.289 - unsigned long virt_addr; 101.290 - unsigned long offset; 101.291 - unsigned int nrpages; 101.292 - enum fixed_addresses idx; 101.293 - 101.294 - virt_addr = (unsigned long)addr; 101.295 - if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)) 101.296 - return; 101.297 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST 101.298 - if (virt_addr >= fix_to_virt(FIX_ISAMAP_BEGIN)) 101.299 - return; 101.300 -#endif 101.301 - offset = virt_addr & ~PAGE_MASK; 101.302 - nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT; 101.303 - 101.304 - idx = FIX_BTMAP_BEGIN; 101.305 - while (nrpages > 0) { 101.306 - clear_fixmap(idx); 101.307 - --idx; 101.308 - --nrpages; 101.309 - } 101.310 -} 101.311 -#endif /* defined(__i386__) */ 101.312 - 101.313 -#endif /* CONFIG_XEN_PHYSDEV_ACCESS */ 101.314 - 101.315 -/* These hacky macros avoid phys->machine translations. */ 101.316 -#define __direct_pte(x) ((pte_t) { (x) } ) 101.317 -#define __direct_mk_pte(page_nr,pgprot) \ 101.318 - __direct_pte(((page_nr) << PAGE_SHIFT) | pgprot_val(pgprot)) 101.319 -#define direct_mk_pte_phys(physpage, pgprot) \ 101.320 - __direct_mk_pte((physpage) >> PAGE_SHIFT, pgprot) 101.321 - 101.322 -static inline void direct_remap_area_pte(pte_t *pte, 101.323 - unsigned long address, 101.324 - unsigned long size, 101.325 - mmu_update_t **v) 101.326 -{ 101.327 - unsigned long end; 101.328 - 101.329 - address &= ~PMD_MASK; 101.330 - end = address + size; 101.331 - if (end > PMD_SIZE) 101.332 - end = PMD_SIZE; 101.333 - if (address >= end) 101.334 - BUG(); 101.335 - 101.336 - do { 101.337 - (*v)->ptr = virt_to_machine(pte); 101.338 - (*v)++; 101.339 - address += PAGE_SIZE; 101.340 - pte++; 101.341 - } while (address && (address < end)); 101.342 -} 101.343 - 101.344 -static inline int direct_remap_area_pmd(struct mm_struct *mm, 101.345 - pmd_t *pmd, 101.346 - unsigned long address, 101.347 - unsigned long size, 101.348 - mmu_update_t **v) 101.349 -{ 101.350 - unsigned long end; 101.351 - 101.352 - address &= ~PGDIR_MASK; 101.353 - end = address + size; 101.354 - if (end > PGDIR_SIZE) 101.355 - end = PGDIR_SIZE; 101.356 - if (address >= end) 101.357 - BUG(); 101.358 - do { 101.359 - pte_t *pte = (mm == &init_mm) ? 101.360 - pte_alloc_kernel(mm, pmd, address) : 101.361 - pte_alloc_map(mm, pmd, address); 101.362 - if (!pte) 101.363 - return -ENOMEM; 101.364 - direct_remap_area_pte(pte, address, end - address, v); 101.365 - pte_unmap(pte); 101.366 - address = (address + PMD_SIZE) & PMD_MASK; 101.367 - pmd++; 101.368 - } while (address && (address < end)); 101.369 - return 0; 101.370 -} 101.371 - 101.372 -int __direct_remap_area_pages(struct mm_struct *mm, 101.373 - unsigned long address, 101.374 - unsigned long size, 101.375 - mmu_update_t *v) 101.376 -{ 101.377 - pgd_t * dir; 101.378 - unsigned long end = address + size; 101.379 - int error; 101.380 - 101.381 -#if defined(__i386__) 101.382 - dir = pgd_offset(mm, address); 101.383 -#elif defined (__x86_64) 101.384 - dir = (mm == &init_mm) ? 101.385 - pgd_offset_k(address): 101.386 - pgd_offset(mm, address); 101.387 -#endif 101.388 - if (address >= end) 101.389 - BUG(); 101.390 - spin_lock(&mm->page_table_lock); 101.391 - do { 101.392 - pud_t *pud; 101.393 - pmd_t *pmd; 101.394 - 101.395 - error = -ENOMEM; 101.396 - pud = pud_alloc(mm, dir, address); 101.397 - if (!pud) 101.398 - break; 101.399 - pmd = pmd_alloc(mm, pud, address); 101.400 - if (!pmd) 101.401 - break; 101.402 - error = 0; 101.403 - direct_remap_area_pmd(mm, pmd, address, end - address, &v); 101.404 - address = (address + PGDIR_SIZE) & PGDIR_MASK; 101.405 - dir++; 101.406 - 101.407 - } while (address && (address < end)); 101.408 - spin_unlock(&mm->page_table_lock); 101.409 - return error; 101.410 -} 101.411 - 101.412 - 101.413 -int direct_remap_area_pages(struct mm_struct *mm, 101.414 - unsigned long address, 101.415 - unsigned long machine_addr, 101.416 - unsigned long size, 101.417 - pgprot_t prot, 101.418 - domid_t domid) 101.419 -{ 101.420 - int i; 101.421 - unsigned long start_address; 101.422 -#define MAX_DIRECTMAP_MMU_QUEUE 130 101.423 - mmu_update_t u[MAX_DIRECTMAP_MMU_QUEUE], *v = u; 101.424 - 101.425 - start_address = address; 101.426 - 101.427 - flush_cache_all(); 101.428 - 101.429 - for (i = 0; i < size; i += PAGE_SIZE) { 101.430 - if ((v - u) == MAX_DIRECTMAP_MMU_QUEUE) { 101.431 - /* Fill in the PTE pointers. */ 101.432 - __direct_remap_area_pages(mm, 101.433 - start_address, 101.434 - address-start_address, 101.435 - u); 101.436 - 101.437 - if (HYPERVISOR_mmu_update(u, v - u, NULL, domid) < 0) 101.438 - return -EFAULT; 101.439 - v = u; 101.440 - start_address = address; 101.441 - } 101.442 - 101.443 - /* 101.444 - * Fill in the machine address: PTE ptr is done later by 101.445 - * __direct_remap_area_pages(). 101.446 - */ 101.447 - v->val = (machine_addr & PAGE_MASK) | pgprot_val(prot); 101.448 - 101.449 - machine_addr += PAGE_SIZE; 101.450 - address += PAGE_SIZE; 101.451 - v++; 101.452 - } 101.453 - 101.454 - if (v != u) { 101.455 - /* get the ptep's filled in */ 101.456 - __direct_remap_area_pages(mm, 101.457 - start_address, 101.458 - address-start_address, 101.459 - u); 101.460 - if (unlikely(HYPERVISOR_mmu_update(u, v - u, NULL, domid) < 0)) 101.461 - return -EFAULT; 101.462 - } 101.463 - 101.464 - flush_tlb_all(); 101.465 - 101.466 - return 0; 101.467 -} 101.468 - 101.469 -EXPORT_SYMBOL(direct_remap_area_pages); 101.470 - 101.471 -int create_lookup_pte_addr(struct mm_struct *mm, 101.472 - unsigned long address, 101.473 - unsigned long *ptep) 101.474 -{ 101.475 - int f(pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 101.476 - { 101.477 - unsigned long *ptep = (unsigned long *)data; 101.478 - if (ptep) *ptep = (pfn_to_mfn(page_to_pfn(pte_page)) << PAGE_SHIFT) 101.479 - | ((unsigned long)pte & ~PAGE_MASK); 101.480 - return 0; 101.481 - } 101.482 - 101.483 - return generic_page_range(mm, address, PAGE_SIZE, f, ptep); 101.484 -} 101.485 - 101.486 -EXPORT_SYMBOL(create_lookup_pte_addr); 101.487 - 101.488 -int touch_pte_range(struct mm_struct *mm, 101.489 - unsigned long address, 101.490 - unsigned long size) 101.491 -{ 101.492 - int f(pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 101.493 - { 101.494 - return 0; 101.495 - } 101.496 - 101.497 - return generic_page_range(mm, address, size, f, NULL); 101.498 -} 101.499 - 101.500 -EXPORT_SYMBOL(touch_pte_range);
104.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Mon Aug 22 11:37:48 2005 -0700 104.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c Tue Aug 23 12:03:21 2005 -0700 104.3 @@ -434,20 +434,20 @@ void balloon_update_driver_allowance(lon 104.4 balloon_unlock(flags); 104.5 } 104.6 104.7 +static int dealloc_pte_fn( 104.8 + pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 104.9 +{ 104.10 + unsigned long mfn = pte_mfn(*pte); 104.11 + set_pte(pte, __pte_ma(0)); 104.12 + phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] = 104.13 + INVALID_P2M_ENTRY; 104.14 + BUG_ON(HYPERVISOR_dom_mem_op( 104.15 + MEMOP_decrease_reservation, &mfn, 1, 0) != 1); 104.16 + return 0; 104.17 +} 104.18 + 104.19 struct page *balloon_alloc_empty_page_range(unsigned long nr_pages) 104.20 { 104.21 - int f(pte_t *pte, struct page *pte_page, 104.22 - unsigned long addr, void *data) 104.23 - { 104.24 - unsigned long mfn = pte_mfn(*pte); 104.25 - set_pte(pte, __pte_ma(0)); 104.26 - phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] = 104.27 - INVALID_P2M_ENTRY; 104.28 - BUG_ON(HYPERVISOR_dom_mem_op( 104.29 - MEMOP_decrease_reservation, &mfn, 1, 0) != 1); 104.30 - return 0; 104.31 - } 104.32 - 104.33 unsigned long vstart, flags; 104.34 unsigned int order = get_order(nr_pages * PAGE_SIZE); 104.35 104.36 @@ -459,7 +459,7 @@ struct page *balloon_alloc_empty_page_ra 104.37 104.38 balloon_lock(flags); 104.39 BUG_ON(generic_page_range( 104.40 - &init_mm, vstart, PAGE_SIZE << order, f, NULL) != 0); 104.41 + &init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL)); 104.42 current_pages -= 1UL << order; 104.43 balloon_unlock(flags); 104.44
106.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Mon Aug 22 11:37:48 2005 -0700 106.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Tue Aug 23 12:03:21 2005 -0700 106.3 @@ -11,6 +11,8 @@ 106.4 * Copyright (c) 2005, Christopher Clark 106.5 */ 106.6 106.7 +#include <linux/spinlock.h> 106.8 +#include <asm-xen/balloon.h> 106.9 #include "common.h" 106.10 106.11 /* 106.12 @@ -63,9 +65,6 @@ typedef unsigned int PEND_RING_IDX; 106.13 static PEND_RING_IDX pending_prod, pending_cons; 106.14 #define NR_PENDING_REQS (MAX_PENDING_REQS - pending_prod + pending_cons) 106.15 106.16 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.17 -static kmem_cache_t *buffer_head_cachep; 106.18 -#else 106.19 static request_queue_t *plugged_queue; 106.20 static inline void flush_plugged_queue(void) 106.21 { 106.22 @@ -78,7 +77,6 @@ static inline void flush_plugged_queue(v 106.23 plugged_queue = NULL; 106.24 } 106.25 } 106.26 -#endif 106.27 106.28 /* When using grant tables to map a frame for device access then the 106.29 * handle returned must be used to unmap the frame. This is needed to 106.30 @@ -182,11 +180,7 @@ static int blkio_schedule(void *arg) 106.31 blkif_t *blkif; 106.32 struct list_head *ent; 106.33 106.34 - daemonize( 106.35 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 106.36 - "xenblkd" 106.37 -#endif 106.38 - ); 106.39 + daemonize("xenblkd"); 106.40 106.41 for ( ; ; ) 106.42 { 106.43 @@ -213,11 +207,7 @@ static int blkio_schedule(void *arg) 106.44 } 106.45 106.46 /* Push the batch through to disc. */ 106.47 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.48 - run_task_queue(&tq_disk); 106.49 -#else 106.50 flush_plugged_queue(); 106.51 -#endif 106.52 } 106.53 } 106.54 106.55 @@ -266,13 +256,6 @@ static void __end_block_io_op(pending_re 106.56 } 106.57 } 106.58 106.59 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.60 -static void end_block_io_op(struct buffer_head *bh, int uptodate) 106.61 -{ 106.62 - __end_block_io_op(bh->b_private, uptodate); 106.63 - kmem_cache_free(buffer_head_cachep, bh); 106.64 -} 106.65 -#else 106.66 static int end_block_io_op(struct bio *bio, unsigned int done, int error) 106.67 { 106.68 if ( bio->bi_size != 0 ) 106.69 @@ -281,7 +264,6 @@ static int end_block_io_op(struct bio *b 106.70 bio_put(bio); 106.71 return error; 106.72 } 106.73 -#endif 106.74 106.75 106.76 /****************************************************************************** 106.77 @@ -355,13 +337,9 @@ static void dispatch_rw_block_io(blkif_t 106.78 unsigned long buf; unsigned int nsec; 106.79 } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 106.80 unsigned int nseg; 106.81 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.82 - struct buffer_head *bh; 106.83 -#else 106.84 struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 106.85 int nbio = 0; 106.86 request_queue_t *q; 106.87 -#endif 106.88 106.89 /* Check that number of segments is sane. */ 106.90 nseg = req->nr_segments; 106.91 @@ -433,49 +411,6 @@ static void dispatch_rw_block_io(blkif_t 106.92 pending_req->status = BLKIF_RSP_OKAY; 106.93 pending_req->nr_pages = nseg; 106.94 106.95 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.96 - 106.97 - atomic_set(&pending_req->pendcnt, nseg); 106.98 - pending_cons++; 106.99 - blkif_get(blkif); 106.100 - 106.101 - for ( i = 0; i < nseg; i++ ) 106.102 - { 106.103 - bh = kmem_cache_alloc(buffer_head_cachep, GFP_KERNEL); 106.104 - if ( unlikely(bh == NULL) ) 106.105 - { 106.106 - __end_block_io_op(pending_req, 0); 106.107 - continue; 106.108 - } 106.109 - 106.110 - memset(bh, 0, sizeof (struct buffer_head)); 106.111 - 106.112 - init_waitqueue_head(&bh->b_wait); 106.113 - bh->b_size = seg[i].nsec << 9; 106.114 - bh->b_dev = preq.dev; 106.115 - bh->b_rdev = preq.dev; 106.116 - bh->b_rsector = (unsigned long)preq.sector_number; 106.117 - bh->b_data = (char *)MMAP_VADDR(pending_idx, i) + 106.118 - (seg[i].buf & ~PAGE_MASK); 106.119 - bh->b_page = virt_to_page(MMAP_VADDR(pending_idx, i)); 106.120 - bh->b_end_io = end_block_io_op; 106.121 - bh->b_private = pending_req; 106.122 - 106.123 - bh->b_state = (1 << BH_Mapped) | (1 << BH_Lock) | 106.124 - (1 << BH_Req) | (1 << BH_Launder); 106.125 - if ( operation == WRITE ) 106.126 - bh->b_state |= (1 << BH_JBD) | (1 << BH_Req) | (1 << BH_Uptodate); 106.127 - 106.128 - atomic_set(&bh->b_count, 1); 106.129 - 106.130 - /* Dispatch a single request. We'll flush it to disc later. */ 106.131 - generic_make_request(operation, bh); 106.132 - 106.133 - preq.sector_number += seg[i].nsec; 106.134 - } 106.135 - 106.136 -#else 106.137 - 106.138 for ( i = 0; i < nseg; i++ ) 106.139 { 106.140 if ( ((int)preq.sector_number|(int)seg[i].nsec) & 106.141 @@ -524,8 +459,6 @@ static void dispatch_rw_block_io(blkif_t 106.142 for ( i = 0; i < nbio; i++ ) 106.143 submit_bio(operation, biolist[i]); 106.144 106.145 -#endif 106.146 - 106.147 return; 106.148 106.149 bad_descriptor: 106.150 @@ -593,12 +526,6 @@ static int __init blkif_init(void) 106.151 if ( kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0 ) 106.152 BUG(); 106.153 106.154 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 106.155 - buffer_head_cachep = kmem_cache_create( 106.156 - "buffer_head_cache", sizeof(struct buffer_head), 106.157 - 0, SLAB_HWCACHE_ALIGN, NULL, NULL); 106.158 -#endif 106.159 - 106.160 blkif_xenbus_init(); 106.161 106.162 memset( pending_grant_handles, BLKBACK_INVALID_HANDLE, MMAP_PAGES );
107.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Mon Aug 22 11:37:48 2005 -0700 107.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Tue Aug 23 12:03:21 2005 -0700 107.3 @@ -5,7 +5,6 @@ 107.4 #include <linux/config.h> 107.5 #include <linux/version.h> 107.6 #include <linux/module.h> 107.7 -#include <linux/rbtree.h> 107.8 #include <linux/interrupt.h> 107.9 #include <linux/slab.h> 107.10 #include <linux/blkdev.h> 107.11 @@ -30,12 +29,13 @@ 107.12 #define DPRINTK(_f, _a...) ((void)0) 107.13 #endif 107.14 107.15 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 107.16 -typedef struct rb_root rb_root_t; 107.17 -typedef struct rb_node rb_node_t; 107.18 -#else 107.19 -struct block_device; 107.20 -#endif 107.21 +struct vbd { 107.22 + blkif_vdev_t handle; /* what the domain refers to this vbd as */ 107.23 + unsigned char readonly; /* Non-zero -> read-only */ 107.24 + unsigned char type; /* VDISK_xxx */ 107.25 + blkif_pdev_t pdevice; /* phys device that this vbd maps to */ 107.26 + struct block_device *bdev; 107.27 +}; 107.28 107.29 typedef struct blkif_st { 107.30 /* Unique identifier for this interface. */ 107.31 @@ -48,25 +48,18 @@ typedef struct blkif_st { 107.32 /* Comms information. */ 107.33 blkif_back_ring_t blk_ring; 107.34 /* VBDs attached to this interface. */ 107.35 - rb_root_t vbd_rb; /* Mapping from 16-bit vdevices to VBDs.*/ 107.36 - spinlock_t vbd_lock; /* Protects VBD mapping. */ 107.37 + struct vbd vbd; 107.38 /* Private fields. */ 107.39 enum { DISCONNECTED, CONNECTED } status; 107.40 - /* 107.41 - * DISCONNECT response is deferred until pending requests are ack'ed. 107.42 - * We therefore need to store the id from the original request. 107.43 - */ 107.44 - u8 disconnect_rspid; 107.45 #ifdef CONFIG_XEN_BLKDEV_TAP_BE 107.46 /* Is this a blktap frontend */ 107.47 unsigned int is_blktap; 107.48 #endif 107.49 - struct blkif_st *hash_next; 107.50 struct list_head blkdev_list; 107.51 spinlock_t blk_ring_lock; 107.52 atomic_t refcnt; 107.53 107.54 - struct work_struct work; 107.55 + struct work_struct free_work; 107.56 u16 shmem_handle; 107.57 unsigned long shmem_vaddr; 107.58 grant_ref_t shmem_ref; 107.59 @@ -77,30 +70,25 @@ void blkif_destroy(blkif_be_destroy_t *d 107.60 void blkif_connect(blkif_be_connect_t *connect); 107.61 int blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id); 107.62 void blkif_disconnect_complete(blkif_t *blkif); 107.63 -blkif_t *blkif_find(domid_t domid); 107.64 -void free_blkif(blkif_t *blkif); 107.65 +blkif_t *alloc_blkif(domid_t domid); 107.66 +void free_blkif_callback(blkif_t *blkif); 107.67 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn); 107.68 107.69 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) 107.70 #define blkif_put(_b) \ 107.71 do { \ 107.72 if ( atomic_dec_and_test(&(_b)->refcnt) ) \ 107.73 - free_blkif(_b); \ 107.74 + free_blkif_callback(_b); \ 107.75 } while (0) 107.76 107.77 -struct vbd; 107.78 -void vbd_free(blkif_t *blkif, struct vbd *vbd); 107.79 - 107.80 -/* Creates inactive vbd. */ 107.81 -struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, blkif_pdev_t pdevice, int readonly); 107.82 -int vbd_is_active(struct vbd *vbd); 107.83 -void vbd_activate(blkif_t *blkif, struct vbd *vbd); 107.84 +/* Create a vbd. */ 107.85 +int vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, blkif_pdev_t pdevice, 107.86 + int readonly); 107.87 +void vbd_free(struct vbd *vbd); 107.88 107.89 unsigned long vbd_size(struct vbd *vbd); 107.90 unsigned int vbd_info(struct vbd *vbd); 107.91 unsigned long vbd_secsize(struct vbd *vbd); 107.92 -void vbd_destroy(blkif_be_vbd_destroy_t *delete); 107.93 -void destroy_all_vbds(blkif_t *blkif); 107.94 107.95 struct phys_req { 107.96 unsigned short dev;
108.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Mon Aug 22 11:37:48 2005 -0700 108.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Tue Aug 23 12:03:21 2005 -0700 108.3 @@ -9,27 +9,11 @@ 108.4 #include "common.h" 108.5 #include <asm-xen/evtchn.h> 108.6 108.7 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 108.8 -#define VMALLOC_VMADDR(x) ((unsigned long)(x)) 108.9 -#endif 108.10 - 108.11 -#define BLKIF_HASHSZ 1024 108.12 -#define BLKIF_HASH(_d) (((int)(_d))&(BLKIF_HASHSZ-1)) 108.13 - 108.14 static kmem_cache_t *blkif_cachep; 108.15 -static blkif_t *blkif_hash[BLKIF_HASHSZ]; 108.16 108.17 -blkif_t *blkif_find(domid_t domid) 108.18 +blkif_t *alloc_blkif(domid_t domid) 108.19 { 108.20 - blkif_t *blkif = blkif_hash[BLKIF_HASH(domid)]; 108.21 - 108.22 - while (blkif) { 108.23 - if (blkif->domid == domid) { 108.24 - blkif_get(blkif); 108.25 - return blkif; 108.26 - } 108.27 - blkif = blkif->hash_next; 108.28 - } 108.29 + blkif_t *blkif; 108.30 108.31 blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL); 108.32 if (!blkif) 108.33 @@ -38,12 +22,9 @@ blkif_t *blkif_find(domid_t domid) 108.34 memset(blkif, 0, sizeof(*blkif)); 108.35 blkif->domid = domid; 108.36 blkif->status = DISCONNECTED; 108.37 - spin_lock_init(&blkif->vbd_lock); 108.38 spin_lock_init(&blkif->blk_ring_lock); 108.39 atomic_set(&blkif->refcnt, 1); 108.40 108.41 - blkif->hash_next = blkif_hash[BLKIF_HASH(domid)]; 108.42 - blkif_hash[BLKIF_HASH(domid)] = blkif; 108.43 return blkif; 108.44 } 108.45 108.46 @@ -55,7 +36,7 @@ static int map_frontend_page(blkif_t *bl 108.47 op.flags = GNTMAP_host_map; 108.48 op.ref = shared_page; 108.49 op.dom = blkif->domid; 108.50 - 108.51 + 108.52 BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) ); 108.53 108.54 if (op.handle < 0) { 108.55 @@ -91,7 +72,7 @@ int blkif_map(blkif_t *blkif, unsigned l 108.56 if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL ) 108.57 return -ENOMEM; 108.58 108.59 - err = map_frontend_page(blkif, VMALLOC_VMADDR(vma->addr), shared_page); 108.60 + err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page); 108.61 if (err) { 108.62 vfree(vma->addr); 108.63 return err; 108.64 @@ -123,10 +104,10 @@ int blkif_map(blkif_t *blkif, unsigned l 108.65 return 0; 108.66 } 108.67 108.68 -void free_blkif(blkif_t *blkif) 108.69 +static void free_blkif(void *arg) 108.70 { 108.71 - blkif_t **pblkif; 108.72 evtchn_op_t op = { .cmd = EVTCHNOP_close }; 108.73 + blkif_t *blkif = (blkif_t *)arg; 108.74 108.75 op.u.close.port = blkif->evtchn; 108.76 op.u.close.dom = DOMID_SELF; 108.77 @@ -135,6 +116,8 @@ void free_blkif(blkif_t *blkif) 108.78 op.u.close.dom = blkif->domid; 108.79 HYPERVISOR_event_channel_op(&op); 108.80 108.81 + vbd_free(&blkif->vbd); 108.82 + 108.83 if (blkif->evtchn) 108.84 unbind_evtchn_from_irqhandler(blkif->evtchn, blkif); 108.85 108.86 @@ -143,20 +126,17 @@ void free_blkif(blkif_t *blkif) 108.87 vfree(blkif->blk_ring.sring); 108.88 } 108.89 108.90 - pblkif = &blkif_hash[BLKIF_HASH(blkif->domid)]; 108.91 - while ( *pblkif != blkif ) 108.92 - { 108.93 - BUG_ON(!*pblkif); 108.94 - pblkif = &(*pblkif)->hash_next; 108.95 - } 108.96 - *pblkif = blkif->hash_next; 108.97 - destroy_all_vbds(blkif); 108.98 kmem_cache_free(blkif_cachep, blkif); 108.99 } 108.100 108.101 +void free_blkif_callback(blkif_t *blkif) 108.102 +{ 108.103 + INIT_WORK(&blkif->free_work, free_blkif, (void *)blkif); 108.104 + schedule_work(&blkif->free_work); 108.105 +} 108.106 + 108.107 void __init blkif_interface_init(void) 108.108 { 108.109 blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t), 108.110 0, 0, NULL, NULL); 108.111 - memset(blkif_hash, 0, sizeof(blkif_hash)); 108.112 }
109.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Mon Aug 22 11:37:48 2005 -0700 109.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Tue Aug 23 12:03:21 2005 -0700 109.3 @@ -3,38 +3,19 @@ 109.4 * 109.5 * Routines for managing virtual block devices (VBDs). 109.6 * 109.7 - * NOTE: vbd_lock protects updates to the rb_tree against concurrent lookups 109.8 - * in vbd_translate. All other lookups are implicitly protected because the 109.9 - * only caller (the control message dispatch routine) serializes the calls. 109.10 - * 109.11 * Copyright (c) 2003-2005, Keir Fraser & Steve Hand 109.12 */ 109.13 109.14 #include "common.h" 109.15 #include <asm-xen/xenbus.h> 109.16 109.17 -struct vbd { 109.18 - blkif_vdev_t handle; /* what the domain refers to this vbd as */ 109.19 - unsigned char readonly; /* Non-zero -> read-only */ 109.20 - unsigned char type; /* VDISK_xxx */ 109.21 - blkif_pdev_t pdevice; /* phys device that this vbd maps to */ 109.22 - struct block_device *bdev; 109.23 - 109.24 - int active; 109.25 - rb_node_t rb; /* for linking into R-B tree lookup struct */ 109.26 -}; 109.27 - 109.28 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 109.29 static inline dev_t vbd_map_devnum(blkif_pdev_t cookie) 109.30 -{ return MKDEV(cookie>>8, cookie&0xff); } 109.31 +{ 109.32 + return MKDEV(BLKIF_MAJOR(cookie), BLKIF_MINOR(cookie)); 109.33 +} 109.34 #define vbd_sz(_v) ((_v)->bdev->bd_part ? \ 109.35 (_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity) 109.36 #define bdev_put(_b) blkdev_put(_b) 109.37 -#else 109.38 -#define vbd_sz(_v) (blk_size[MAJOR((_v)->pdevice)][MINOR((_v)->pdevice)]*2) 109.39 -#define bdev_put(_b) ((void)0) 109.40 -#define bdev_hardsect_size(_b) 512 109.41 -#endif 109.42 109.43 unsigned long vbd_size(struct vbd *vbd) 109.44 { 109.45 @@ -51,45 +32,32 @@ unsigned long vbd_secsize(struct vbd *vb 109.46 return bdev_hardsect_size(vbd->bdev); 109.47 } 109.48 109.49 -int vbd_is_active(struct vbd *vbd) 109.50 -{ 109.51 - return vbd->active; 109.52 -} 109.53 - 109.54 -struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t handle, 109.55 - blkif_pdev_t pdevice, int readonly) 109.56 +int vbd_create(blkif_t *blkif, blkif_vdev_t handle, 109.57 + blkif_pdev_t pdevice, int readonly) 109.58 { 109.59 - struct vbd *vbd; 109.60 + struct vbd *vbd; 109.61 109.62 - if ( unlikely((vbd = kmalloc(sizeof(struct vbd), GFP_KERNEL)) == NULL) ) 109.63 - { 109.64 - DPRINTK("vbd_create: out of memory\n"); 109.65 - return ERR_PTR(-ENOMEM); 109.66 - } 109.67 - 109.68 + vbd = &blkif->vbd; 109.69 vbd->handle = handle; 109.70 vbd->readonly = readonly; 109.71 vbd->type = 0; 109.72 - vbd->active = 0; 109.73 109.74 vbd->pdevice = pdevice; 109.75 109.76 - /* FIXME: Who frees vbd on failure? --RR */ 109.77 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 109.78 vbd->bdev = open_by_devnum( 109.79 vbd_map_devnum(vbd->pdevice), 109.80 vbd->readonly ? FMODE_READ : FMODE_WRITE); 109.81 if ( IS_ERR(vbd->bdev) ) 109.82 { 109.83 DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 109.84 - return ERR_PTR(-ENOENT); 109.85 + return -ENOENT; 109.86 } 109.87 109.88 if ( (vbd->bdev->bd_disk == NULL) ) 109.89 { 109.90 DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 109.91 - bdev_put(vbd->bdev); 109.92 - return ERR_PTR(-ENOENT); 109.93 + vbd_free(vbd); 109.94 + return -ENOENT; 109.95 } 109.96 109.97 if ( vbd->bdev->bd_disk->flags & GENHD_FL_CD ) 109.98 @@ -97,121 +65,27 @@ struct vbd *vbd_create(blkif_t *blkif, b 109.99 if ( vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE ) 109.100 vbd->type |= VDISK_REMOVABLE; 109.101 109.102 -#else 109.103 - if ( (blk_size[MAJOR(vbd->pdevice)] == NULL) || (vbd_sz(vbd) == 0) ) 109.104 - { 109.105 - DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 109.106 - return ERR_PTR(-ENOENT); 109.107 - } 109.108 -#endif 109.109 - 109.110 DPRINTK("Successful creation of handle=%04x (dom=%u)\n", 109.111 handle, blkif->domid); 109.112 - return vbd; 109.113 + return 0; 109.114 } 109.115 109.116 -void vbd_activate(blkif_t *blkif, struct vbd *vbd) 109.117 +void vbd_free(struct vbd *vbd) 109.118 { 109.119 - rb_node_t **rb_p, *rb_parent = NULL; 109.120 - struct vbd *i; 109.121 - BUG_ON(vbd_is_active(vbd)); 109.122 - 109.123 - /* Find where to put it. */ 109.124 - rb_p = &blkif->vbd_rb.rb_node; 109.125 - while ( *rb_p != NULL ) 109.126 - { 109.127 - rb_parent = *rb_p; 109.128 - i = rb_entry(rb_parent, struct vbd, rb); 109.129 - if ( vbd->handle < i->handle ) 109.130 - { 109.131 - rb_p = &rb_parent->rb_left; 109.132 - } 109.133 - else if ( vbd->handle > i->handle ) 109.134 - { 109.135 - rb_p = &rb_parent->rb_right; 109.136 - } 109.137 - else 109.138 - { 109.139 - /* We never create two of same vbd, so not possible. */ 109.140 - BUG(); 109.141 - } 109.142 - } 109.143 - 109.144 - /* Now we're active. */ 109.145 - vbd->active = 1; 109.146 - blkif_get(blkif); 109.147 - 109.148 - spin_lock(&blkif->vbd_lock); 109.149 - rb_link_node(&vbd->rb, rb_parent, rb_p); 109.150 - rb_insert_color(&vbd->rb, &blkif->vbd_rb); 109.151 - spin_unlock(&blkif->vbd_lock); 109.152 -} 109.153 - 109.154 -void vbd_free(blkif_t *blkif, struct vbd *vbd) 109.155 -{ 109.156 - if (vbd_is_active(vbd)) { 109.157 - spin_lock(&blkif->vbd_lock); 109.158 - rb_erase(&vbd->rb, &blkif->vbd_rb); 109.159 - spin_unlock(&blkif->vbd_lock); 109.160 - blkif_put(blkif); 109.161 - } 109.162 - bdev_put(vbd->bdev); 109.163 - kfree(vbd); 109.164 -} 109.165 - 109.166 -void destroy_all_vbds(blkif_t *blkif) 109.167 -{ 109.168 - struct vbd *vbd; 109.169 - rb_node_t *rb; 109.170 - 109.171 - spin_lock(&blkif->vbd_lock); 109.172 - 109.173 - while ( (rb = blkif->vbd_rb.rb_node) != NULL ) 109.174 - { 109.175 - vbd = rb_entry(rb, struct vbd, rb); 109.176 - rb_erase(rb, &blkif->vbd_rb); 109.177 - spin_unlock(&blkif->vbd_lock); 109.178 - bdev_put(vbd->bdev); 109.179 - kfree(vbd); 109.180 - spin_lock(&blkif->vbd_lock); 109.181 - blkif_put(blkif); 109.182 - } 109.183 - 109.184 - spin_unlock(&blkif->vbd_lock); 109.185 + if (vbd->bdev) 109.186 + bdev_put(vbd->bdev); 109.187 + vbd->bdev = NULL; 109.188 } 109.189 109.190 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation) 109.191 { 109.192 - struct vbd *vbd; 109.193 - rb_node_t *rb; 109.194 - int rc = -EACCES; 109.195 - 109.196 - /* Take the vbd_lock because another thread could be updating the tree. */ 109.197 - spin_lock(&blkif->vbd_lock); 109.198 + struct vbd *vbd = &blkif->vbd; 109.199 + int rc = -EACCES; 109.200 109.201 - rb = blkif->vbd_rb.rb_node; 109.202 - while ( rb != NULL ) 109.203 - { 109.204 - vbd = rb_entry(rb, struct vbd, rb); 109.205 - if ( req->dev < vbd->handle ) 109.206 - rb = rb->rb_left; 109.207 - else if ( req->dev > vbd->handle ) 109.208 - rb = rb->rb_right; 109.209 - else 109.210 - goto found; 109.211 - } 109.212 - 109.213 - DPRINTK("vbd_translate; domain %u attempted to access " 109.214 - "non-existent VBD.\n", blkif->domid); 109.215 - rc = -ENODEV; 109.216 - goto out; 109.217 - 109.218 - found: 109.219 - 109.220 - if ( (operation == WRITE) && vbd->readonly ) 109.221 + if ((operation == WRITE) && vbd->readonly) 109.222 goto out; 109.223 109.224 - if ( unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)) ) 109.225 + if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd))) 109.226 goto out; 109.227 109.228 req->dev = vbd->pdevice; 109.229 @@ -219,6 +93,5 @@ int vbd_translate(struct phys_req *req, 109.230 rc = 0; 109.231 109.232 out: 109.233 - spin_unlock(&blkif->vbd_lock); 109.234 return rc; 109.235 }
110.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Mon Aug 22 11:37:48 2005 -0700 110.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Tue Aug 23 12:03:21 2005 -0700 110.3 @@ -26,7 +26,6 @@ struct backend_info 110.4 110.5 /* our communications channel */ 110.6 blkif_t *blkif; 110.7 - struct vbd *vbd; 110.8 110.9 long int frontend_id; 110.10 long int pdev; 110.11 @@ -47,8 +46,6 @@ static int blkback_remove(struct xenbus_ 110.12 if (be->watch.node) 110.13 unregister_xenbus_watch(&be->watch); 110.14 unregister_xenbus_watch(&be->backend_watch); 110.15 - if (be->vbd) 110.16 - vbd_free(be->blkif, be->vbd); 110.17 if (be->blkif) 110.18 blkif_put(be->blkif); 110.19 if (be->frontpath) 110.20 @@ -72,7 +69,7 @@ static void frontend_changed(struct xenb 110.21 device_unregister(&be->dev->dev); 110.22 return; 110.23 } 110.24 - if (vbd_is_active(be->vbd)) 110.25 + if (be->blkif->status == CONNECTED) 110.26 return; 110.27 110.28 err = xenbus_gather(be->frontpath, "grant-id", "%lu", &sharedmfn, 110.29 @@ -85,9 +82,8 @@ static void frontend_changed(struct xenb 110.30 } 110.31 110.32 /* Domains must use same shared frame for all vbds. */ 110.33 - if (be->blkif->status == CONNECTED && 110.34 - (evtchn != be->blkif->remote_evtchn || 110.35 - sharedmfn != be->blkif->shmem_frame)) { 110.36 + if (evtchn != be->blkif->remote_evtchn || 110.37 + sharedmfn != be->blkif->shmem_frame) { 110.38 xenbus_dev_error(be->dev, err, 110.39 "Shared frame/evtchn %li/%u not same as" 110.40 " old %li/%u", 110.41 @@ -105,7 +101,7 @@ static void frontend_changed(struct xenb 110.42 } 110.43 110.44 err = xenbus_printf(be->dev->nodename, "sectors", "%lu", 110.45 - vbd_size(be->vbd)); 110.46 + vbd_size(&be->blkif->vbd)); 110.47 if (err) { 110.48 xenbus_dev_error(be->dev, err, "writing %s/sectors", 110.49 be->dev->nodename); 110.50 @@ -114,34 +110,29 @@ static void frontend_changed(struct xenb 110.51 110.52 /* FIXME: use a typename instead */ 110.53 err = xenbus_printf(be->dev->nodename, "info", "%u", 110.54 - vbd_info(be->vbd)); 110.55 + vbd_info(&be->blkif->vbd)); 110.56 if (err) { 110.57 xenbus_dev_error(be->dev, err, "writing %s/info", 110.58 be->dev->nodename); 110.59 goto abort; 110.60 } 110.61 err = xenbus_printf(be->dev->nodename, "sector-size", "%lu", 110.62 - vbd_secsize(be->vbd)); 110.63 + vbd_secsize(&be->blkif->vbd)); 110.64 if (err) { 110.65 xenbus_dev_error(be->dev, err, "writing %s/sector-size", 110.66 be->dev->nodename); 110.67 goto abort; 110.68 } 110.69 110.70 - /* First vbd? We need to map the shared frame, irq etc. */ 110.71 - if (be->blkif->status != CONNECTED) { 110.72 - err = blkif_map(be->blkif, sharedmfn, evtchn); 110.73 - if (err) { 110.74 - xenbus_dev_error(be->dev, err, 110.75 - "mapping shared-frame %lu port %u", 110.76 - sharedmfn, evtchn); 110.77 - goto abort; 110.78 - } 110.79 + /* Map the shared frame, irq etc. */ 110.80 + err = blkif_map(be->blkif, sharedmfn, evtchn); 110.81 + if (err) { 110.82 + xenbus_dev_error(be->dev, err, 110.83 + "mapping shared-frame %lu port %u", 110.84 + sharedmfn, evtchn); 110.85 + goto abort; 110.86 } 110.87 110.88 - /* We're ready, activate. */ 110.89 - vbd_activate(be->blkif, be->vbd); 110.90 - 110.91 xenbus_transaction_end(0); 110.92 xenbus_dev_ok(be->dev); 110.93 110.94 @@ -228,20 +219,16 @@ static void backend_changed(struct xenbu 110.95 p = strrchr(be->frontpath, '/') + 1; 110.96 handle = simple_strtoul(p, NULL, 0); 110.97 110.98 - be->blkif = blkif_find(be->frontend_id); 110.99 + be->blkif = alloc_blkif(be->frontend_id); 110.100 if (IS_ERR(be->blkif)) { 110.101 err = PTR_ERR(be->blkif); 110.102 be->blkif = NULL; 110.103 goto device_fail; 110.104 } 110.105 110.106 - be->vbd = vbd_create(be->blkif, handle, be->pdev, 110.107 - be->readonly); 110.108 - if (IS_ERR(be->vbd)) { 110.109 - err = PTR_ERR(be->vbd); 110.110 - be->vbd = NULL; 110.111 + err = vbd_create(be->blkif, handle, be->pdev, be->readonly); 110.112 + if (err) 110.113 goto device_fail; 110.114 - } 110.115 110.116 frontend_changed(&be->watch, be->frontpath); 110.117 }
111.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Mon Aug 22 11:37:48 2005 -0700 111.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Tue Aug 23 12:03:21 2005 -0700 111.3 @@ -63,25 +63,16 @@ typedef unsigned char byte; /* from linu 111.4 /* Control whether runtime update of vbds is enabled. */ 111.5 #define ENABLE_VBD_UPDATE 1 111.6 111.7 -#define BLKIF_STATE_CLOSED 0 111.8 -#define BLKIF_STATE_DISCONNECTED 1 111.9 -#define BLKIF_STATE_CONNECTED 2 111.10 +#define BLKIF_STATE_DISCONNECTED 0 111.11 +#define BLKIF_STATE_CONNECTED 1 111.12 111.13 -static unsigned int blkif_state = BLKIF_STATE_CLOSED; 111.14 -static unsigned int blkif_evtchn = 0; 111.15 -static unsigned int blkif_vbds = 0; 111.16 -static unsigned int blkif_vbds_connected = 0; 111.17 - 111.18 -static blkif_front_ring_t blk_ring; 111.19 +static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED; 111.20 111.21 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE) 111.22 111.23 -static domid_t rdomid = 0; 111.24 -static grant_ref_t gref_head, gref_terminal; 111.25 #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ 111.26 (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) 111.27 #define GRANTREF_INVALID (1<<15) 111.28 -static int shmem_ref; 111.29 111.30 static struct blk_shadow { 111.31 blkif_request_t req; 111.32 @@ -92,7 +83,7 @@ unsigned long blk_shadow_free; 111.33 111.34 static int recovery = 0; /* Recovery in progress: protected by blkif_io_lock */ 111.35 111.36 -static void kick_pending_request_queues(void); 111.37 +static void kick_pending_request_queues(struct blkfront_info *info); 111.38 111.39 static int __init xlblk_init(void); 111.40 111.41 @@ -119,7 +110,7 @@ static inline void ADD_ID_TO_FREELIST(un 111.42 111.43 /* Kernel-specific definitions used in the common code */ 111.44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 111.45 -#define DISABLE_SCATTERGATHER() 111.46 +#define DISABLE_SCATTERGATHER() 111.47 #else 111.48 static int sg_operation = -1; 111.49 #define DISABLE_SCATTERGATHER() (sg_operation = -1) 111.50 @@ -138,11 +129,11 @@ static inline void unpickle_request(blki 111.51 } 111.52 111.53 111.54 -static inline void flush_requests(void) 111.55 +static inline void flush_requests(struct blkfront_info *info) 111.56 { 111.57 DISABLE_SCATTERGATHER(); 111.58 - RING_PUSH_REQUESTS(&blk_ring); 111.59 - notify_via_evtchn(blkif_evtchn); 111.60 + RING_PUSH_REQUESTS(&info->ring); 111.61 + notify_via_evtchn(info->evtchn); 111.62 } 111.63 111.64 111.65 @@ -152,30 +143,39 @@ static inline void flush_requests(void) 111.66 111.67 module_init(xlblk_init); 111.68 111.69 -static struct xlbd_disk_info *head_waiting = NULL; 111.70 -static void kick_pending_request_queues(void) 111.71 +static void kick_pending_request_queues(struct blkfront_info *info) 111.72 { 111.73 - struct xlbd_disk_info *di; 111.74 - while ( ((di = head_waiting) != NULL) && !RING_FULL(&blk_ring) ) 111.75 - { 111.76 - head_waiting = di->next_waiting; 111.77 - di->next_waiting = NULL; 111.78 - /* Re-enable calldowns. */ 111.79 - blk_start_queue(di->rq); 111.80 - /* Kick things off immediately. */ 111.81 - do_blkif_request(di->rq); 111.82 - } 111.83 + if (!RING_FULL(&info->ring)) { 111.84 + /* Re-enable calldowns. */ 111.85 + blk_start_queue(info->rq); 111.86 + /* Kick things off immediately. */ 111.87 + do_blkif_request(info->rq); 111.88 + } 111.89 +} 111.90 + 111.91 +static void blkif_restart_queue(void *arg) 111.92 +{ 111.93 + struct blkfront_info *info = (struct blkfront_info *)arg; 111.94 + spin_lock_irq(&blkif_io_lock); 111.95 + kick_pending_request_queues(info); 111.96 + spin_unlock_irq(&blkif_io_lock); 111.97 +} 111.98 + 111.99 +static void blkif_restart_queue_callback(void *arg) 111.100 +{ 111.101 + struct blkfront_info *info = (struct blkfront_info *)arg; 111.102 + schedule_work(&info->work); 111.103 } 111.104 111.105 int blkif_open(struct inode *inode, struct file *filep) 111.106 { 111.107 - struct gendisk *gd = inode->i_bdev->bd_disk; 111.108 - struct xlbd_disk_info *di = (struct xlbd_disk_info *)gd->private_data; 111.109 + // struct gendisk *gd = inode->i_bdev->bd_disk; 111.110 + // struct xlbd_disk_info *di = (struct xlbd_disk_info *)gd->private_data; 111.111 111.112 - /* Update of usage count is protected by per-device semaphore. */ 111.113 - di->mi->usage++; 111.114 - 111.115 - return 0; 111.116 + /* Update of usage count is protected by per-device semaphore. */ 111.117 + // di->mi->usage++; 111.118 + 111.119 + return 0; 111.120 } 111.121 111.122 111.123 @@ -192,8 +192,8 @@ int blkif_ioctl(struct inode *inode, str 111.124 int i; 111.125 111.126 DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n", 111.127 - command, (long)argument, inode->i_rdev); 111.128 - 111.129 + command, (long)argument, inode->i_rdev); 111.130 + 111.131 switch ( command ) 111.132 { 111.133 case HDIO_GETGEO: 111.134 @@ -219,7 +219,7 @@ int blkif_ioctl(struct inode *inode, str 111.135 /* 111.136 * blkif_queue_request 111.137 * 111.138 - * request block io 111.139 + * request block io 111.140 * 111.141 * id: for guest use only. 111.142 * operation: BLKIF_OP_{READ,WRITE,PROBE} 111.143 @@ -228,7 +228,7 @@ int blkif_ioctl(struct inode *inode, str 111.144 */ 111.145 static int blkif_queue_request(struct request *req) 111.146 { 111.147 - struct xlbd_disk_info *di = req->rq_disk->private_data; 111.148 + struct blkfront_info *info = req->rq_disk->private_data; 111.149 unsigned long buffer_ma; 111.150 blkif_request_t *ring_req; 111.151 struct bio *bio; 111.152 @@ -237,20 +237,28 @@ static int blkif_queue_request(struct re 111.153 unsigned long id; 111.154 unsigned int fsect, lsect; 111.155 int ref; 111.156 + grant_ref_t gref_head; 111.157 111.158 - if ( unlikely(blkif_state != BLKIF_STATE_CONNECTED) ) 111.159 + if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) 111.160 return 1; 111.161 111.162 + if (gnttab_alloc_grant_references(BLKIF_MAX_SEGMENTS_PER_REQUEST, 111.163 + &gref_head) < 0) { 111.164 + gnttab_request_free_callback(&info->callback, 111.165 + blkif_restart_queue_callback, info, 111.166 + BLKIF_MAX_SEGMENTS_PER_REQUEST); 111.167 + return 1; 111.168 + } 111.169 + 111.170 /* Fill out a communications ring structure. */ 111.171 - ring_req = RING_GET_REQUEST(&blk_ring, blk_ring.req_prod_pvt); 111.172 + ring_req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt); 111.173 id = GET_ID_FROM_FREELIST(); 111.174 blk_shadow[id].request = (unsigned long)req; 111.175 111.176 ring_req->id = id; 111.177 - ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE : 111.178 - BLKIF_OP_READ; 111.179 + ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE : BLKIF_OP_READ; 111.180 ring_req->sector_number = (blkif_sector_t)req->sector; 111.181 - ring_req->handle = di->handle; 111.182 + ring_req->handle = info->handle; 111.183 111.184 ring_req->nr_segments = 0; 111.185 rq_for_each_bio(bio, req) 111.186 @@ -263,56 +271,61 @@ static int blkif_queue_request(struct re 111.187 fsect = bvec->bv_offset >> 9; 111.188 lsect = fsect + (bvec->bv_len >> 9) - 1; 111.189 /* install a grant reference. */ 111.190 - ref = gnttab_claim_grant_reference(&gref_head, gref_terminal); 111.191 + ref = gnttab_claim_grant_reference(&gref_head); 111.192 ASSERT( ref != -ENOSPC ); 111.193 111.194 gnttab_grant_foreign_access_ref( 111.195 ref, 111.196 - rdomid, 111.197 + info->backend_id, 111.198 buffer_ma >> PAGE_SHIFT, 111.199 rq_data_dir(req) ); 111.200 111.201 blk_shadow[id].frame[ring_req->nr_segments] = 111.202 buffer_ma >> PAGE_SHIFT; 111.203 111.204 - ring_req->frame_and_sects[ring_req->nr_segments++] = 111.205 + ring_req->frame_and_sects[ring_req->nr_segments] = 111.206 blkif_fas_from_gref(ref, fsect, lsect); 111.207 + 111.208 + ring_req->nr_segments++; 111.209 } 111.210 } 111.211 111.212 - blk_ring.req_prod_pvt++; 111.213 - 111.214 + info->ring.req_prod_pvt++; 111.215 + 111.216 /* Keep a private copy so we can reissue requests when recovering. */ 111.217 pickle_request(&blk_shadow[id], ring_req); 111.218 111.219 + gnttab_free_grant_references(gref_head); 111.220 + 111.221 return 0; 111.222 } 111.223 111.224 - 111.225 /* 111.226 * do_blkif_request 111.227 * read a block; request is in a request queue 111.228 */ 111.229 void do_blkif_request(request_queue_t *rq) 111.230 { 111.231 - struct xlbd_disk_info *di; 111.232 + struct blkfront_info *info = NULL; 111.233 struct request *req; 111.234 int queued; 111.235 111.236 - DPRINTK("Entered do_blkif_request\n"); 111.237 + DPRINTK("Entered do_blkif_request\n"); 111.238 111.239 queued = 0; 111.240 111.241 while ( (req = elv_next_request(rq)) != NULL ) 111.242 { 111.243 + info = req->rq_disk->private_data; 111.244 + 111.245 if ( !blk_fs_request(req) ) 111.246 { 111.247 end_request(req, 0); 111.248 continue; 111.249 } 111.250 111.251 - if ( RING_FULL(&blk_ring) ) 111.252 - goto wait; 111.253 + if (RING_FULL(&info->ring)) 111.254 + goto wait; 111.255 111.256 DPRINTK("do_blk_req %p: cmd %p, sec %lx, (%u/%li) buffer:%p [%s]\n", 111.257 req, req->cmd, req->sector, req->current_nr_sectors, 111.258 @@ -320,25 +333,19 @@ void do_blkif_request(request_queue_t *r 111.259 rq_data_dir(req) ? "write" : "read"); 111.260 111.261 blkdev_dequeue_request(req); 111.262 - if ( blkif_queue_request(req) ) 111.263 - { 111.264 + if (blkif_queue_request(req)) { 111.265 + blk_requeue_request(rq, req); 111.266 wait: 111.267 - di = req->rq_disk->private_data; 111.268 - if ( di->next_waiting == NULL ) 111.269 - { 111.270 - di->next_waiting = head_waiting; 111.271 - head_waiting = di; 111.272 - /* Avoid pointless unplugs. */ 111.273 - blk_stop_queue(rq); 111.274 - } 111.275 - break; 111.276 + /* Avoid pointless unplugs. */ 111.277 + blk_stop_queue(rq); 111.278 + break; 111.279 } 111.280 111.281 queued++; 111.282 } 111.283 111.284 if ( queued != 0 ) 111.285 - flush_requests(); 111.286 + flush_requests(info); 111.287 } 111.288 111.289 111.290 @@ -347,25 +354,24 @@ static irqreturn_t blkif_int(int irq, vo 111.291 struct request *req; 111.292 blkif_response_t *bret; 111.293 RING_IDX i, rp; 111.294 - unsigned long flags; 111.295 - 111.296 - spin_lock_irqsave(&blkif_io_lock, flags); 111.297 + unsigned long flags; 111.298 + struct blkfront_info *info = (struct blkfront_info *)dev_id; 111.299 111.300 - if ( unlikely(blkif_state == BLKIF_STATE_CLOSED) || 111.301 - unlikely(recovery) ) 111.302 - { 111.303 + spin_lock_irqsave(&blkif_io_lock, flags); 111.304 + 111.305 + if (unlikely(info->connected != BLKIF_STATE_CONNECTED || recovery)) { 111.306 spin_unlock_irqrestore(&blkif_io_lock, flags); 111.307 return IRQ_HANDLED; 111.308 } 111.309 - 111.310 - rp = blk_ring.sring->rsp_prod; 111.311 + 111.312 + rp = info->ring.sring->rsp_prod; 111.313 rmb(); /* Ensure we see queued responses up to 'rp'. */ 111.314 111.315 - for ( i = blk_ring.rsp_cons; i != rp; i++ ) 111.316 + for ( i = info->ring.rsp_cons; i != rp; i++ ) 111.317 { 111.318 unsigned long id; 111.319 111.320 - bret = RING_GET_RESPONSE(&blk_ring, i); 111.321 + bret = RING_GET_RESPONSE(&info->ring, i); 111.322 id = bret->id; 111.323 req = (struct request *)blk_shadow[id].request; 111.324 111.325 @@ -382,7 +388,7 @@ static irqreturn_t blkif_int(int irq, vo 111.326 bret->status); 111.327 111.328 if ( unlikely(end_that_request_first 111.329 - (req, 111.330 + (req, 111.331 (bret->status == BLKIF_RSP_OKAY), 111.332 req->hard_nr_sectors)) ) 111.333 BUG(); 111.334 @@ -394,9 +400,9 @@ static irqreturn_t blkif_int(int irq, vo 111.335 } 111.336 } 111.337 111.338 - blk_ring.rsp_cons = i; 111.339 + info->ring.rsp_cons = i; 111.340 111.341 - kick_pending_request_queues(); 111.342 + kick_pending_request_queues(info); 111.343 111.344 spin_unlock_irqrestore(&blkif_io_lock, flags); 111.345 111.346 @@ -425,31 +431,31 @@ static int nr_pending; 111.347 static void kick_pending_request_queues(void) 111.348 { 111.349 /* We kick pending request queues if the ring is reasonably empty. */ 111.350 - if ( (nr_pending != 0) && 111.351 - (RING_PENDING_REQUESTS(&blk_ring) < (BLK_RING_SIZE >> 1)) ) 111.352 + if ( (nr_pending != 0) && 111.353 + (RING_PENDING_REQUESTS(&info->ring) < (BLK_RING_SIZE >> 1)) ) 111.354 { 111.355 /* Attempt to drain the queue, but bail if the ring becomes full. */ 111.356 - while ( (nr_pending != 0) && !RING_FULL(&blk_ring) ) 111.357 + while ( (nr_pending != 0) && !RING_FULL(&info->ring) ) 111.358 do_blkif_request(pending_queues[--nr_pending]); 111.359 } 111.360 } 111.361 111.362 int blkif_open(struct inode *inode, struct file *filep) 111.363 { 111.364 - short xldev = inode->i_rdev; 111.365 + short xldev = inode->i_rdev; 111.366 struct gendisk *gd = get_gendisk(xldev); 111.367 xl_disk_t *disk = xldev_to_xldisk(inode->i_rdev); 111.368 - short minor = MINOR(xldev); 111.369 + short minor = MINOR(xldev); 111.370 111.371 if ( gd->part[minor].nr_sects == 0 ) 111.372 - { 111.373 + { 111.374 /* 111.375 * Device either doesn't exist, or has zero capacity; we use a few 111.376 * cheesy heuristics to return the relevant error code 111.377 */ 111.378 if ( (gd->sizes[minor >> gd->minor_shift] != 0) || 111.379 ((minor & (gd->max_p - 1)) != 0) ) 111.380 - { 111.381 + { 111.382 /* 111.383 * We have a real device, but no such partition, or we just have a 111.384 * partition number so guess this is the problem. 111.385 @@ -458,16 +464,16 @@ int blkif_open(struct inode *inode, stru 111.386 } 111.387 else if ( gd->flags[minor >> gd->minor_shift] & GENHD_FL_REMOVABLE ) 111.388 { 111.389 - /* This is a removable device => assume that media is missing. */ 111.390 + /* This is a removable device => assume that media is missing. */ 111.391 return -ENOMEDIUM; /* media not present (this is a guess) */ 111.392 - } 111.393 + } 111.394 else 111.395 - { 111.396 + { 111.397 /* Just go for the general 'no such device' error. */ 111.398 return -ENODEV; /* no such device */ 111.399 } 111.400 } 111.401 - 111.402 + 111.403 /* Update of usage count is protected by per-device semaphore. */ 111.404 disk->usage++; 111.405 111.406 @@ -496,24 +502,24 @@ int blkif_ioctl(struct inode *inode, str 111.407 { 111.408 kdev_t dev = inode->i_rdev; 111.409 struct hd_geometry *geo = (struct hd_geometry *)argument; 111.410 - struct gendisk *gd; 111.411 - struct hd_struct *part; 111.412 + struct gendisk *gd; 111.413 + struct hd_struct *part; 111.414 int i; 111.415 unsigned short cylinders; 111.416 byte heads, sectors; 111.417 111.418 /* NB. No need to check permissions. That is done for us. */ 111.419 - 111.420 + 111.421 DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n", 111.422 - command, (long) argument, dev); 111.423 - 111.424 + command, (long) argument, dev); 111.425 + 111.426 gd = get_gendisk(dev); 111.427 - part = &gd->part[MINOR(dev)]; 111.428 + part = &gd->part[MINOR(dev)]; 111.429 111.430 switch ( command ) 111.431 { 111.432 case BLKGETSIZE: 111.433 - DPRINTK_IOCTL(" BLKGETSIZE: %x %lx\n", BLKGETSIZE, part->nr_sects); 111.434 + DPRINTK_IOCTL(" BLKGETSIZE: %x %lx\n", BLKGETSIZE, part->nr_sects); 111.435 return put_user(part->nr_sects, (unsigned long *) argument); 111.436 111.437 case BLKGETSIZE64: 111.438 @@ -526,7 +532,7 @@ int blkif_ioctl(struct inode *inode, str 111.439 return blkif_revalidate(dev); 111.440 111.441 case BLKSSZGET: 111.442 - return hardsect_size[MAJOR(dev)][MINOR(dev)]; 111.443 + return hardsect_size[MAJOR(dev)][MINOR(dev)]; 111.444 111.445 case BLKBSZGET: /* get block size */ 111.446 DPRINTK_IOCTL(" BLKBSZGET: %x\n", BLKBSZGET); 111.447 @@ -552,7 +558,7 @@ int blkif_ioctl(struct inode *inode, str 111.448 values consistent with the size of the device */ 111.449 111.450 heads = 0xff; 111.451 - sectors = 0x3f; 111.452 + sectors = 0x3f; 111.453 cylinders = part->nr_sects / (heads * sectors); 111.454 111.455 if (put_user(0x00, (unsigned long *) &geo->start)) return -EFAULT; 111.456 @@ -562,7 +568,7 @@ int blkif_ioctl(struct inode *inode, str 111.457 111.458 return 0; 111.459 111.460 - case HDIO_GETGEO_BIG: 111.461 + case HDIO_GETGEO_BIG: 111.462 DPRINTK_IOCTL(" HDIO_GETGEO_BIG: %x\n", HDIO_GETGEO_BIG); 111.463 if (!argument) return -EINVAL; 111.464 111.465 @@ -570,7 +576,7 @@ int blkif_ioctl(struct inode *inode, str 111.466 values consistent with the size of the device */ 111.467 111.468 heads = 0xff; 111.469 - sectors = 0x3f; 111.470 + sectors = 0x3f; 111.471 cylinders = part->nr_sects / (heads * sectors); 111.472 111.473 if (put_user(0x00, (unsigned long *) &geo->start)) return -EFAULT; 111.474 @@ -594,7 +600,7 @@ int blkif_ioctl(struct inode *inode, str 111.475 WPRINTK("ioctl %08x not supported by XL blkif\n", command); 111.476 return -ENOSYS; 111.477 } 111.478 - 111.479 + 111.480 return 0; 111.481 } 111.482 111.483 @@ -614,7 +620,7 @@ int blkif_revalidate(kdev_t dev) 111.484 xl_disk_t *disk; 111.485 unsigned long capacity; 111.486 int i, rc = 0; 111.487 - 111.488 + 111.489 if ( (bd = bdget(dev)) == NULL ) 111.490 return -EINVAL; 111.491 111.492 @@ -662,7 +668,7 @@ int blkif_revalidate(kdev_t dev) 111.493 /* 111.494 * blkif_queue_request 111.495 * 111.496 - * request block io 111.497 + * request block io 111.498 * 111.499 * id: for guest use only. 111.500 * operation: BLKIF_OP_{READ,WRITE,PROBE} 111.501 @@ -696,7 +702,7 @@ static int blkif_queue_request(unsigned 111.502 111.503 buffer_ma &= PAGE_MASK; 111.504 111.505 - if ( unlikely(blkif_state != BLKIF_STATE_CONNECTED) ) 111.506 + if (unlikely(info->connected != BLKIF_STATE_CONNECTED)) 111.507 return 1; 111.508 111.509 switch ( operation ) 111.510 @@ -704,7 +710,7 @@ static int blkif_queue_request(unsigned 111.511 111.512 case BLKIF_OP_READ: 111.513 case BLKIF_OP_WRITE: 111.514 - gd = get_gendisk(device); 111.515 + gd = get_gendisk(device); 111.516 111.517 /* 111.518 * Update the sector_number we'll pass down as appropriate; note that 111.519 @@ -714,10 +720,10 @@ static int blkif_queue_request(unsigned 111.520 sector_number += gd->part[MINOR(device)].start_sect; 111.521 111.522 /* 111.523 - * If this unit doesn't consist of virtual partitions then we clear 111.524 + * If this unit doesn't consist of virtual partitions then we clear 111.525 * the partn bits from the device number. 111.526 */ 111.527 - if ( !(gd->flags[MINOR(device)>>gd->minor_shift] & 111.528 + if ( !(gd->flags[MINOR(device)>>gd->minor_shift] & 111.529 GENHD_FL_VIRT_PARTNS) ) 111.530 device &= ~(gd->max_p - 1); 111.531 111.532 @@ -725,20 +731,20 @@ static int blkif_queue_request(unsigned 111.533 (sg_dev == device) && 111.534 (sg_next_sect == sector_number) ) 111.535 { 111.536 - req = RING_GET_REQUEST(&blk_ring, 111.537 - blk_ring.req_prod_pvt - 1); 111.538 + req = RING_GET_REQUEST(&info->ring, 111.539 + info->ring.req_prod_pvt - 1); 111.540 bh = (struct buffer_head *)id; 111.541 - 111.542 + 111.543 bh->b_reqnext = (struct buffer_head *)blk_shadow[req->id].request; 111.544 blk_shadow[req->id].request = (unsigned long)id; 111.545 111.546 /* install a grant reference. */ 111.547 - ref = gnttab_claim_grant_reference(&gref_head, gref_terminal); 111.548 + ref = gnttab_claim_grant_reference(&gref_head); 111.549 ASSERT( ref != -ENOSPC ); 111.550 111.551 gnttab_grant_foreign_access_ref( 111.552 ref, 111.553 - rdomid, 111.554 + info->backend_id, 111.555 buffer_ma >> PAGE_SHIFT, 111.556 ( operation == BLKIF_OP_WRITE ? 1 : 0 ) ); 111.557 111.558 @@ -757,7 +763,7 @@ static int blkif_queue_request(unsigned 111.559 111.560 return 0; 111.561 } 111.562 - else if ( RING_FULL(&blk_ring) ) 111.563 + else if ( RING_FULL(&info->ring) ) 111.564 { 111.565 return 1; 111.566 } 111.567 @@ -774,7 +780,7 @@ static int blkif_queue_request(unsigned 111.568 } 111.569 111.570 /* Fill out a communications ring structure. */ 111.571 - req = RING_GET_REQUEST(&blk_ring, blk_ring.req_prod_pvt); 111.572 + req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt); 111.573 111.574 xid = GET_ID_FROM_FREELIST(); 111.575 blk_shadow[xid].request = (unsigned long)id; 111.576 @@ -782,15 +788,15 @@ static int blkif_queue_request(unsigned 111.577 req->id = xid; 111.578 req->operation = operation; 111.579 req->sector_number = (blkif_sector_t)sector_number; 111.580 - req->handle = handle; 111.581 + req->handle = handle; 111.582 req->nr_segments = 1; 111.583 /* install a grant reference. */ 111.584 - ref = gnttab_claim_grant_reference(&gref_head, gref_terminal); 111.585 + ref = gnttab_claim_grant_reference(&gref_head); 111.586 ASSERT( ref != -ENOSPC ); 111.587 111.588 gnttab_grant_foreign_access_ref( 111.589 ref, 111.590 - rdomid, 111.591 + info->backend_id, 111.592 buffer_ma >> PAGE_SHIFT, 111.593 ( operation == BLKIF_OP_WRITE ? 1 : 0 ) ); 111.594 111.595 @@ -798,11 +804,11 @@ static int blkif_queue_request(unsigned 111.596 111.597 req->frame_and_sects[0] = blkif_fas_from_gref(ref, fsect, lsect); 111.598 111.599 - /* Keep a private copy so we can reissue requests when recovering. */ 111.600 + /* Keep a private copy so we can reissue requests when recovering. */ 111.601 pickle_request(&blk_shadow[xid], req); 111.602 111.603 - blk_ring.req_prod_pvt++; 111.604 - 111.605 + info->ring.req_prod_pvt++; 111.606 + 111.607 return 0; 111.608 } 111.609 111.610 @@ -817,13 +823,13 @@ void do_blkif_request(request_queue_t *r 111.611 struct buffer_head *bh, *next_bh; 111.612 int rw, nsect, full, queued = 0; 111.613 111.614 - DPRINTK("Entered do_blkif_request\n"); 111.615 + DPRINTK("Entered do_blkif_request\n"); 111.616 111.617 while ( !rq->plugged && !list_empty(&rq->queue_head)) 111.618 { 111.619 - if ( (req = blkdev_entry_next_request(&rq->queue_head)) == NULL ) 111.620 + if ( (req = blkdev_entry_next_request(&rq->queue_head)) == NULL ) 111.621 goto out; 111.622 - 111.623 + 111.624 DPRINTK("do_blkif_request %p: cmd %i, sec %lx, (%li/%li) bh:%p\n", 111.625 req, req->cmd, req->sector, 111.626 req->current_nr_sectors, req->nr_sectors, req->bh); 111.627 @@ -844,16 +850,16 @@ void do_blkif_request(request_queue_t *r 111.628 111.629 full = blkif_queue_request( 111.630 (unsigned long)bh, 111.631 - (rw == READ) ? BLKIF_OP_READ : BLKIF_OP_WRITE, 111.632 + (rw == READ) ? BLKIF_OP_READ : BLKIF_OP_WRITE, 111.633 bh->b_data, bh->b_rsector, bh->b_size>>9, bh->b_rdev); 111.634 111.635 if ( full ) 111.636 - { 111.637 + { 111.638 bh->b_reqnext = next_bh; 111.639 pending_queues[nr_pending++] = rq; 111.640 if ( unlikely(nr_pending >= MAX_PENDING) ) 111.641 BUG(); 111.642 - goto out; 111.643 + goto out; 111.644 } 111.645 111.646 queued++; 111.647 @@ -861,7 +867,7 @@ void do_blkif_request(request_queue_t *r 111.648 /* Dequeue the buffer head from the request. */ 111.649 nsect = bh->b_size >> 9; 111.650 bh = req->bh = next_bh; 111.651 - 111.652 + 111.653 if ( bh != NULL ) 111.654 { 111.655 /* There's another buffer head to do. Update the request. */ 111.656 @@ -891,27 +897,27 @@ void do_blkif_request(request_queue_t *r 111.657 111.658 static void blkif_int(int irq, void *dev_id, struct pt_regs *ptregs) 111.659 { 111.660 - RING_IDX i, rp; 111.661 - unsigned long flags; 111.662 + RING_IDX i, rp; 111.663 + unsigned long flags; 111.664 struct buffer_head *bh, *next_bh; 111.665 - 111.666 - spin_lock_irqsave(&io_request_lock, flags); 111.667 111.668 - if ( unlikely(blkif_state == BLKIF_STATE_CLOSED || recovery) ) 111.669 + spin_lock_irqsave(&io_request_lock, flags); 111.670 + 111.671 + if ( unlikely(info->connected != BLKIF_STATE_CONNECTED || recovery) ) 111.672 { 111.673 spin_unlock_irqrestore(&io_request_lock, flags); 111.674 return; 111.675 } 111.676 111.677 - rp = blk_ring.sring->rsp_prod; 111.678 + rp = info->ring.sring->rsp_prod; 111.679 rmb(); /* Ensure we see queued responses up to 'rp'. */ 111.680 111.681 - for ( i = blk_ring.rsp_cons; i != rp; i++ ) 111.682 + for ( i = info->ring.rsp_cons; i != rp; i++ ) 111.683 { 111.684 unsigned long id; 111.685 blkif_response_t *bret; 111.686 - 111.687 - bret = RING_GET_RESPONSE(&blk_ring, i); 111.688 + 111.689 + bret = RING_GET_RESPONSE(&info->ring, i); 111.690 id = bret->id; 111.691 bh = (struct buffer_head *)blk_shadow[id].request; 111.692 111.693 @@ -943,8 +949,8 @@ static void blkif_int(int irq, void *dev 111.694 } 111.695 111.696 } 111.697 - blk_ring.rsp_cons = i; 111.698 - 111.699 + info->ring.rsp_cons = i; 111.700 + 111.701 kick_pending_request_queues(); 111.702 111.703 spin_unlock_irqrestore(&io_request_lock, flags); 111.704 @@ -954,24 +960,24 @@ static void blkif_int(int irq, void *dev 111.705 111.706 /***************************** COMMON CODE *******************************/ 111.707 111.708 -static void blkif_free(void) 111.709 +static void blkif_free(struct blkfront_info *info) 111.710 { 111.711 /* Prevent new requests being issued until we fix things up. */ 111.712 spin_lock_irq(&blkif_io_lock); 111.713 - blkif_state = BLKIF_STATE_DISCONNECTED; 111.714 + info->connected = BLKIF_STATE_DISCONNECTED; 111.715 spin_unlock_irq(&blkif_io_lock); 111.716 111.717 /* Free resources associated with old device channel. */ 111.718 - if ( blk_ring.sring != NULL ) 111.719 + if ( info->ring.sring != NULL ) 111.720 { 111.721 - free_page((unsigned long)blk_ring.sring); 111.722 - blk_ring.sring = NULL; 111.723 + free_page((unsigned long)info->ring.sring); 111.724 + info->ring.sring = NULL; 111.725 } 111.726 - unbind_evtchn_from_irqhandler(blkif_evtchn, NULL); 111.727 - blkif_evtchn = 0; 111.728 + unbind_evtchn_from_irqhandler(info->evtchn, NULL); 111.729 + info->evtchn = 0; 111.730 } 111.731 111.732 -static void blkif_recover(void) 111.733 +static void blkif_recover(struct blkfront_info *info) 111.734 { 111.735 int i; 111.736 blkif_request_t *req; 111.737 @@ -987,7 +993,7 @@ static void blkif_recover(void) 111.738 memset(&blk_shadow, 0, sizeof(blk_shadow)); 111.739 for ( i = 0; i < BLK_RING_SIZE; i++ ) 111.740 blk_shadow[i].req.id = i+1; 111.741 - blk_shadow_free = blk_ring.req_prod_pvt; 111.742 + blk_shadow_free = info->ring.req_prod_pvt; 111.743 blk_shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; 111.744 111.745 /* Stage 3: Find pending requests and requeue them. */ 111.746 @@ -999,7 +1005,7 @@ static void blkif_recover(void) 111.747 111.748 /* Grab a request slot and unpickle shadow state into it. */ 111.749 req = RING_GET_REQUEST( 111.750 - &blk_ring, blk_ring.req_prod_pvt); 111.751 + &info->ring, info->ring.req_prod_pvt); 111.752 unpickle_request(req, ©[i]); 111.753 111.754 /* We get a new request id, and must reset the shadow state. */ 111.755 @@ -1012,7 +1018,7 @@ static void blkif_recover(void) 111.756 if ( req->frame_and_sects[j] & GRANTREF_INVALID ) 111.757 gnttab_grant_foreign_access_ref( 111.758 blkif_gref_from_fas(req->frame_and_sects[j]), 111.759 - rdomid, 111.760 + info->backend_id, 111.761 blk_shadow[req->id].frame[j], 111.762 rq_data_dir((struct request *) 111.763 blk_shadow[req->id].request)); 111.764 @@ -1020,32 +1026,31 @@ static void blkif_recover(void) 111.765 } 111.766 blk_shadow[req->id].req = *req; 111.767 111.768 - blk_ring.req_prod_pvt++; 111.769 + info->ring.req_prod_pvt++; 111.770 } 111.771 111.772 kfree(copy); 111.773 111.774 recovery = 0; 111.775 111.776 - /* blk_ring->req_prod will be set when we flush_requests().*/ 111.777 + /* info->ring->req_prod will be set when we flush_requests().*/ 111.778 wmb(); 111.779 111.780 /* Kicks things back into life. */ 111.781 - flush_requests(); 111.782 + flush_requests(info); 111.783 111.784 /* Now safe to left other people use the interface. */ 111.785 - blkif_state = BLKIF_STATE_CONNECTED; 111.786 + info->connected = BLKIF_STATE_CONNECTED; 111.787 } 111.788 111.789 -static void blkif_connect(u16 evtchn, domid_t domid) 111.790 +static void blkif_connect(struct blkfront_info *info, u16 evtchn) 111.791 { 111.792 int err = 0; 111.793 111.794 - blkif_evtchn = evtchn; 111.795 - rdomid = domid; 111.796 + info->evtchn = evtchn; 111.797 111.798 err = bind_evtchn_to_irqhandler( 111.799 - blkif_evtchn, blkif_int, SA_SAMPLE_RANDOM, "blkif", NULL); 111.800 + info->evtchn, blkif_int, SA_SAMPLE_RANDOM, "blkif", info); 111.801 if ( err != 0 ) 111.802 { 111.803 WPRINTK("bind_evtchn_to_irqhandler failed (err=%d)\n", err); 111.804 @@ -1059,17 +1064,6 @@ static struct xenbus_device_id blkfront_ 111.805 { "" } 111.806 }; 111.807 111.808 -struct blkfront_info 111.809 -{ 111.810 - /* We watch the backend */ 111.811 - struct xenbus_watch watch; 111.812 - int vdevice; 111.813 - u16 handle; 111.814 - int connected; 111.815 - struct xenbus_device *dev; 111.816 - char *backend; 111.817 -}; 111.818 - 111.819 static void watch_for_status(struct xenbus_watch *watch, const char *node) 111.820 { 111.821 struct blkfront_info *info; 111.822 @@ -1081,35 +1075,33 @@ static void watch_for_status(struct xenb 111.823 node += strlen(watch->node); 111.824 111.825 /* FIXME: clean up when error on the other end. */ 111.826 - if (info->connected) 111.827 + if (info->connected == BLKIF_STATE_CONNECTED) 111.828 return; 111.829 111.830 - err = xenbus_gather(watch->node, 111.831 + err = xenbus_gather(watch->node, 111.832 "sectors", "%lu", §ors, 111.833 "info", "%u", &binfo, 111.834 "sector-size", "%lu", §or_size, 111.835 NULL); 111.836 if (err) { 111.837 - xenbus_dev_error(info->dev, err, "reading backend fields"); 111.838 + xenbus_dev_error(info->xbdev, err, "reading backend fields"); 111.839 return; 111.840 } 111.841 111.842 - xlvbd_add(sectors, info->vdevice, info->handle, binfo, sector_size); 111.843 - info->connected = 1; 111.844 + xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); 111.845 + info->connected = BLKIF_STATE_CONNECTED; 111.846 111.847 - /* First to connect? blkif is now connected. */ 111.848 - if (blkif_vbds_connected++ == 0) 111.849 - blkif_state = BLKIF_STATE_CONNECTED; 111.850 + blkif_state = BLKIF_STATE_CONNECTED; 111.851 111.852 - xenbus_dev_ok(info->dev); 111.853 + xenbus_dev_ok(info->xbdev); 111.854 111.855 /* Kick pending requests. */ 111.856 spin_lock_irq(&blkif_io_lock); 111.857 - kick_pending_request_queues(); 111.858 + kick_pending_request_queues(info); 111.859 spin_unlock_irq(&blkif_io_lock); 111.860 } 111.861 111.862 -static int setup_blkring(struct xenbus_device *dev, unsigned int backend_id) 111.863 +static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info) 111.864 { 111.865 blkif_sring_t *sring; 111.866 evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound }; 111.867 @@ -1121,25 +1113,28 @@ static int setup_blkring(struct xenbus_d 111.868 return -ENOMEM; 111.869 } 111.870 SHARED_RING_INIT(sring); 111.871 - FRONT_RING_INIT(&blk_ring, sring, PAGE_SIZE); 111.872 + FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); 111.873 111.874 - shmem_ref = gnttab_claim_grant_reference(&gref_head, 111.875 - gref_terminal); 111.876 - ASSERT(shmem_ref != -ENOSPC); 111.877 - gnttab_grant_foreign_access_ref(shmem_ref, 111.878 - backend_id, 111.879 - virt_to_mfn(blk_ring.sring), 111.880 - 0); 111.881 + err = gnttab_grant_foreign_access(info->backend_id, 111.882 + virt_to_mfn(info->ring.sring), 0); 111.883 + if (err == -ENOSPC) { 111.884 + free_page((unsigned long)info->ring.sring); 111.885 + info->ring.sring = 0; 111.886 + xenbus_dev_error(dev, err, "granting access to ring page"); 111.887 + return err; 111.888 + } 111.889 + info->grant_id = err; 111.890 111.891 - op.u.alloc_unbound.dom = backend_id; 111.892 + op.u.alloc_unbound.dom = info->backend_id; 111.893 err = HYPERVISOR_event_channel_op(&op); 111.894 if (err) { 111.895 - free_page((unsigned long)blk_ring.sring); 111.896 - blk_ring.sring = 0; 111.897 + gnttab_end_foreign_access(info->grant_id, 0); 111.898 + free_page((unsigned long)info->ring.sring); 111.899 + info->ring.sring = 0; 111.900 xenbus_dev_error(dev, err, "allocating event channel"); 111.901 return err; 111.902 } 111.903 - blkif_connect(op.u.alloc_unbound.port, backend_id); 111.904 + blkif_connect(info, op.u.alloc_unbound.port); 111.905 return 0; 111.906 } 111.907 111.908 @@ -1149,11 +1144,11 @@ static int talk_to_backend(struct xenbus 111.909 { 111.910 char *backend; 111.911 const char *message; 111.912 - int err, backend_id; 111.913 + int err; 111.914 111.915 backend = NULL; 111.916 err = xenbus_gather(dev->nodename, 111.917 - "backend-id", "%i", &backend_id, 111.918 + "backend-id", "%i", &info->backend_id, 111.919 "backend", NULL, &backend, 111.920 NULL); 111.921 if (XENBUS_EXIST_ERR(err)) 111.922 @@ -1168,12 +1163,10 @@ static int talk_to_backend(struct xenbus 111.923 goto out; 111.924 } 111.925 111.926 - /* First device? We create shared ring, alloc event channel. */ 111.927 - if (blkif_vbds == 0) { 111.928 - err = setup_blkring(dev, backend_id); 111.929 - if (err) 111.930 - goto out; 111.931 - } 111.932 + /* Create shared ring, alloc event channel. */ 111.933 + err = setup_blkring(dev, info); 111.934 + if (err) 111.935 + goto out; 111.936 111.937 err = xenbus_transaction_start(dev->nodename); 111.938 if (err) { 111.939 @@ -1181,13 +1174,13 @@ static int talk_to_backend(struct xenbus 111.940 goto destroy_blkring; 111.941 } 111.942 111.943 - err = xenbus_printf(dev->nodename, "grant-id","%u", shmem_ref); 111.944 + err = xenbus_printf(dev->nodename, "grant-id","%u", info->grant_id); 111.945 if (err) { 111.946 message = "writing grant-id"; 111.947 goto abort_transaction; 111.948 } 111.949 err = xenbus_printf(dev->nodename, 111.950 - "event-channel", "%u", blkif_evtchn); 111.951 + "event-channel", "%u", info->evtchn); 111.952 if (err) { 111.953 message = "writing event-channel"; 111.954 goto abort_transaction; 111.955 @@ -1220,8 +1213,7 @@ static int talk_to_backend(struct xenbus 111.956 /* Have to do this *outside* transaction. */ 111.957 xenbus_dev_error(dev, err, "%s", message); 111.958 destroy_blkring: 111.959 - if (blkif_vbds == 0) 111.960 - blkif_free(); 111.961 + blkif_free(info); 111.962 goto out; 111.963 } 111.964 111.965 @@ -1250,9 +1242,11 @@ static int blkfront_probe(struct xenbus_ 111.966 xenbus_dev_error(dev, err, "allocating info structure"); 111.967 return err; 111.968 } 111.969 - info->dev = dev; 111.970 + info->xbdev = dev; 111.971 info->vdevice = vdevice; 111.972 - info->connected = 0; 111.973 + info->connected = BLKIF_STATE_DISCONNECTED; 111.974 + info->mi = NULL; 111.975 + INIT_WORK(&info->work, blkif_restart_queue, (void *)info); 111.976 111.977 /* Front end dir is a number, which is used as the id. */ 111.978 info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0); 111.979 @@ -1266,7 +1260,6 @@ static int blkfront_probe(struct xenbus_ 111.980 111.981 /* Call once in case entries already there. */ 111.982 watch_for_status(&info->watch, info->watch.node); 111.983 - blkif_vbds++; 111.984 return 0; 111.985 } 111.986 111.987 @@ -1277,16 +1270,14 @@ static int blkfront_remove(struct xenbus 111.988 if (info->backend) 111.989 unregister_xenbus_watch(&info->watch); 111.990 111.991 - if (info->connected) { 111.992 - xlvbd_del(info->handle); 111.993 - blkif_vbds_connected--; 111.994 - } 111.995 + if (info->mi) 111.996 + xlvbd_del(info); 111.997 + 111.998 + blkif_free(info); 111.999 + 111.1000 kfree(info->backend); 111.1001 kfree(info); 111.1002 111.1003 - if (--blkif_vbds == 0) 111.1004 - blkif_free(); 111.1005 - 111.1006 return 0; 111.1007 } 111.1008 111.1009 @@ -1298,10 +1289,8 @@ static int blkfront_suspend(struct xenbu 111.1010 kfree(info->backend); 111.1011 info->backend = NULL; 111.1012 111.1013 - if (--blkif_vbds == 0) { 111.1014 - recovery = 1; 111.1015 - blkif_free(); 111.1016 - } 111.1017 + recovery = 1; 111.1018 + blkif_free(info); 111.1019 111.1020 return 0; 111.1021 } 111.1022 @@ -1314,8 +1303,7 @@ static int blkfront_resume(struct xenbus 111.1023 /* FIXME: Check geometry hasn't changed here... */ 111.1024 err = talk_to_backend(dev, info); 111.1025 if (!err) { 111.1026 - if (blkif_vbds++ == 0) 111.1027 - blkif_recover(); 111.1028 + blkif_recover(info); 111.1029 } 111.1030 return err; 111.1031 } 111.1032 @@ -1363,11 +1351,6 @@ static int __init xlblk_init(void) 111.1033 { 111.1034 int i; 111.1035 111.1036 - /* A grant for every ring slot, plus one for the ring itself. */ 111.1037 - if (gnttab_alloc_grant_references(MAXIMUM_OUTSTANDING_BLOCK_REQS + 1, 111.1038 - &gref_head, &gref_terminal) < 0) 111.1039 - return 1; 111.1040 - 111.1041 if ( (xen_start_info.flags & SIF_INITDOMAIN) || 111.1042 (xen_start_info.flags & SIF_BLK_BE_DOMAIN) ) 111.1043 return 0; 111.1044 @@ -1391,6 +1374,6 @@ static void blkif_completion(struct blk_ 111.1045 { 111.1046 int i; 111.1047 for ( i = 0; i < s->req.nr_segments; i++ ) 111.1048 - gnttab_release_grant_reference( 111.1049 - &gref_head, blkif_gref_from_fas(s->req.frame_and_sects[i])); 111.1050 + gnttab_free_grant_reference( 111.1051 + blkif_gref_from_fas(s->req.frame_and_sects[i])); 111.1052 }
112.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Mon Aug 22 11:37:48 2005 -0700 112.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Tue Aug 23 12:03:21 2005 -0700 112.3 @@ -46,6 +46,7 @@ 112.4 #include <linux/major.h> 112.5 #include <linux/devfs_fs_kernel.h> 112.6 #include <asm-xen/hypervisor.h> 112.7 +#include <asm-xen/xenbus.h> 112.8 #include <asm-xen/xen-public/xen.h> 112.9 #include <asm-xen/xen-public/io/blkif.h> 112.10 #include <asm-xen/xen-public/io/ring.h> 112.11 @@ -79,11 +80,20 @@ 112.12 #define DPRINTK_IOCTL(_f, _a...) ((void)0) 112.13 #endif 112.14 112.15 -struct xlbd_type_info { 112.16 - int partn_shift; 112.17 - int disks_per_major; 112.18 - char *devname; 112.19 - char *diskname; 112.20 +struct xlbd_type_info 112.21 +{ 112.22 + int partn_shift; 112.23 + int disks_per_major; 112.24 + char *devname; 112.25 + char *diskname; 112.26 +}; 112.27 + 112.28 +struct xlbd_major_info 112.29 +{ 112.30 + int major; 112.31 + int index; 112.32 + int usage; 112.33 + struct xlbd_type_info *type; 112.34 }; 112.35 112.36 /* 112.37 @@ -91,27 +101,28 @@ struct xlbd_type_info { 112.38 * hang in private_data off the gendisk structure. We may end up 112.39 * putting all kinds of interesting stuff here :-) 112.40 */ 112.41 -struct xlbd_major_info { 112.42 - int major; 112.43 - int index; 112.44 - int usage; 112.45 - struct xlbd_type_info *type; 112.46 +struct blkfront_info 112.47 +{ 112.48 + struct xenbus_device *xbdev; 112.49 + /* We watch the backend */ 112.50 + struct xenbus_watch watch; 112.51 + dev_t dev; 112.52 + int vdevice; 112.53 + blkif_vdev_t handle; 112.54 + int connected; 112.55 + char *backend; 112.56 + int backend_id; 112.57 + int grant_id; 112.58 + blkif_front_ring_t ring; 112.59 + unsigned int evtchn; 112.60 + struct xlbd_major_info *mi; 112.61 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 112.62 + request_queue_t *rq; 112.63 +#endif 112.64 + struct work_struct work; 112.65 + struct gnttab_free_callback callback; 112.66 }; 112.67 112.68 -struct xlbd_disk_info { 112.69 - int xd_device; 112.70 - blkif_vdev_t handle; 112.71 - struct xlbd_major_info *mi; 112.72 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 112.73 - struct xlbd_disk_info *next_waiting; 112.74 - request_queue_t *rq; 112.75 -#endif 112.76 -}; 112.77 - 112.78 -typedef struct xen_block { 112.79 - int usage; 112.80 -} xen_block_t; 112.81 - 112.82 extern spinlock_t blkif_io_lock; 112.83 112.84 extern int blkif_open(struct inode *inode, struct file *filep); 112.85 @@ -123,7 +134,7 @@ extern int blkif_revalidate(dev_t dev); 112.86 extern void do_blkif_request (request_queue_t *rq); 112.87 112.88 /* Virtual block-device subsystem. */ 112.89 -int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle, 112.90 - u16 info, u16 sector_size); 112.91 -void xlvbd_del(blkif_vdev_t handle); 112.92 +int xlvbd_add(blkif_sector_t capacity, int device, 112.93 + u16 vdisk_info, u16 sector_size, struct blkfront_info *info); 112.94 +void xlvbd_del(struct blkfront_info *info); 112.95 #endif /* __XEN_DRIVERS_BLOCK_H__ */
113.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Mon Aug 22 11:37:48 2005 -0700 113.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Tue Aug 23 12:03:21 2005 -0700 113.3 @@ -43,325 +43,269 @@ 113.4 #define NUM_SCSI_MAJORS 9 113.5 #define NUM_VBD_MAJORS 1 113.6 113.7 -struct lvdisk 113.8 -{ 113.9 - blkif_sector_t capacity; /* 0: Size in terms of 512-byte sectors. */ 113.10 - blkif_vdev_t handle; /* 8: Device number (opaque 16 bit value). */ 113.11 - u16 info; 113.12 - dev_t dev; 113.13 - struct list_head list; 113.14 -}; 113.15 - 113.16 static struct xlbd_type_info xlbd_ide_type = { 113.17 - .partn_shift = 6, 113.18 - .disks_per_major = 2, 113.19 - .devname = "ide", 113.20 - .diskname = "hd", 113.21 + .partn_shift = 6, 113.22 + .disks_per_major = 2, 113.23 + .devname = "ide", 113.24 + .diskname = "hd", 113.25 }; 113.26 113.27 static struct xlbd_type_info xlbd_scsi_type = { 113.28 - .partn_shift = 4, 113.29 - .disks_per_major = 16, 113.30 - .devname = "sd", 113.31 - .diskname = "sd", 113.32 + .partn_shift = 4, 113.33 + .disks_per_major = 16, 113.34 + .devname = "sd", 113.35 + .diskname = "sd", 113.36 }; 113.37 113.38 static struct xlbd_type_info xlbd_vbd_type = { 113.39 - .partn_shift = 4, 113.40 - .disks_per_major = 16, 113.41 - .devname = "xvd", 113.42 - .diskname = "xvd", 113.43 + .partn_shift = 4, 113.44 + .disks_per_major = 16, 113.45 + .devname = "xvd", 113.46 + .diskname = "xvd", 113.47 }; 113.48 113.49 static struct xlbd_major_info *major_info[NUM_IDE_MAJORS + NUM_SCSI_MAJORS + 113.50 - NUM_VBD_MAJORS]; 113.51 + NUM_VBD_MAJORS]; 113.52 113.53 -#define XLBD_MAJOR_IDE_START 0 113.54 -#define XLBD_MAJOR_SCSI_START (NUM_IDE_MAJORS) 113.55 -#define XLBD_MAJOR_VBD_START (NUM_IDE_MAJORS + NUM_SCSI_MAJORS) 113.56 +#define XLBD_MAJOR_IDE_START 0 113.57 +#define XLBD_MAJOR_SCSI_START (NUM_IDE_MAJORS) 113.58 +#define XLBD_MAJOR_VBD_START (NUM_IDE_MAJORS + NUM_SCSI_MAJORS) 113.59 113.60 -#define XLBD_MAJOR_IDE_RANGE XLBD_MAJOR_IDE_START ... XLBD_MAJOR_SCSI_START - 1 113.61 -#define XLBD_MAJOR_SCSI_RANGE XLBD_MAJOR_SCSI_START ... XLBD_MAJOR_VBD_START - 1 113.62 -#define XLBD_MAJOR_VBD_RANGE XLBD_MAJOR_VBD_START ... XLBD_MAJOR_VBD_START + NUM_VBD_MAJORS - 1 113.63 +#define XLBD_MAJOR_IDE_RANGE XLBD_MAJOR_IDE_START ... XLBD_MAJOR_SCSI_START - 1 113.64 +#define XLBD_MAJOR_SCSI_RANGE XLBD_MAJOR_SCSI_START ... XLBD_MAJOR_VBD_START - 1 113.65 +#define XLBD_MAJOR_VBD_RANGE XLBD_MAJOR_VBD_START ... XLBD_MAJOR_VBD_START + NUM_VBD_MAJORS - 1 113.66 113.67 /* Information about our VBDs. */ 113.68 #define MAX_VBDS 64 113.69 static LIST_HEAD(vbds_list); 113.70 113.71 -#define MAJOR_XEN(dev) ((dev)>>8) 113.72 -#define MINOR_XEN(dev) ((dev) & 0xff) 113.73 - 113.74 -static struct block_device_operations xlvbd_block_fops = 113.75 +static struct block_device_operations xlvbd_block_fops = 113.76 { 113.77 - .owner = THIS_MODULE, 113.78 - .open = blkif_open, 113.79 - .release = blkif_release, 113.80 - .ioctl = blkif_ioctl, 113.81 + .owner = THIS_MODULE, 113.82 + .open = blkif_open, 113.83 + .release = blkif_release, 113.84 + .ioctl = blkif_ioctl, 113.85 }; 113.86 113.87 spinlock_t blkif_io_lock = SPIN_LOCK_UNLOCKED; 113.88 113.89 -static struct lvdisk *xlvbd_device_alloc(void) 113.90 -{ 113.91 - struct lvdisk *disk; 113.92 - 113.93 - disk = kmalloc(sizeof(*disk), GFP_KERNEL); 113.94 - if (disk != NULL) { 113.95 - memset(disk, 0, sizeof(*disk)); 113.96 - INIT_LIST_HEAD(&disk->list); 113.97 - } 113.98 - return disk; 113.99 -} 113.100 - 113.101 -static void xlvbd_device_free(struct lvdisk *disk) 113.102 +static struct xlbd_major_info * 113.103 +xlbd_alloc_major_info(int major, int minor, int index) 113.104 { 113.105 - list_del(&disk->list); 113.106 - kfree(disk); 113.107 -} 113.108 + struct xlbd_major_info *ptr; 113.109 113.110 -static struct xlbd_major_info *xlbd_alloc_major_info( 113.111 - int major, int minor, int index) 113.112 -{ 113.113 - struct xlbd_major_info *ptr; 113.114 + ptr = kmalloc(sizeof(struct xlbd_major_info), GFP_KERNEL); 113.115 + if (ptr == NULL) 113.116 + return NULL; 113.117 113.118 - ptr = kmalloc(sizeof(struct xlbd_major_info), GFP_KERNEL); 113.119 - if (ptr == NULL) 113.120 - return NULL; 113.121 + memset(ptr, 0, sizeof(struct xlbd_major_info)); 113.122 113.123 - memset(ptr, 0, sizeof(struct xlbd_major_info)); 113.124 + ptr->major = major; 113.125 113.126 - ptr->major = major; 113.127 + switch (index) { 113.128 + case XLBD_MAJOR_IDE_RANGE: 113.129 + ptr->type = &xlbd_ide_type; 113.130 + ptr->index = index - XLBD_MAJOR_IDE_START; 113.131 + break; 113.132 + case XLBD_MAJOR_SCSI_RANGE: 113.133 + ptr->type = &xlbd_scsi_type; 113.134 + ptr->index = index - XLBD_MAJOR_SCSI_START; 113.135 + break; 113.136 + case XLBD_MAJOR_VBD_RANGE: 113.137 + ptr->type = &xlbd_vbd_type; 113.138 + ptr->index = index - XLBD_MAJOR_VBD_START; 113.139 + break; 113.140 + } 113.141 113.142 - switch (index) { 113.143 - case XLBD_MAJOR_IDE_RANGE: 113.144 - ptr->type = &xlbd_ide_type; 113.145 - ptr->index = index - XLBD_MAJOR_IDE_START; 113.146 - break; 113.147 - case XLBD_MAJOR_SCSI_RANGE: 113.148 - ptr->type = &xlbd_scsi_type; 113.149 - ptr->index = index - XLBD_MAJOR_SCSI_START; 113.150 - break; 113.151 - case XLBD_MAJOR_VBD_RANGE: 113.152 - ptr->type = &xlbd_vbd_type; 113.153 - ptr->index = index - XLBD_MAJOR_VBD_START; 113.154 - break; 113.155 - } 113.156 - 113.157 - printk("Registering block device major %i\n", ptr->major); 113.158 - if (register_blkdev(ptr->major, ptr->type->devname)) { 113.159 - WPRINTK("can't get major %d with name %s\n", 113.160 - ptr->major, ptr->type->devname); 113.161 - kfree(ptr); 113.162 - return NULL; 113.163 - } 113.164 + printk("Registering block device major %i\n", ptr->major); 113.165 + if (register_blkdev(ptr->major, ptr->type->devname)) { 113.166 + WPRINTK("can't get major %d with name %s\n", 113.167 + ptr->major, ptr->type->devname); 113.168 + kfree(ptr); 113.169 + return NULL; 113.170 + } 113.171 113.172 - devfs_mk_dir(ptr->type->devname); 113.173 - major_info[index] = ptr; 113.174 - return ptr; 113.175 + devfs_mk_dir(ptr->type->devname); 113.176 + major_info[index] = ptr; 113.177 + return ptr; 113.178 } 113.179 113.180 -static struct xlbd_major_info *xlbd_get_major_info(int device) 113.181 +static struct xlbd_major_info * 113.182 +xlbd_get_major_info(int vdevice) 113.183 { 113.184 - int major, minor, index; 113.185 + struct xlbd_major_info *mi; 113.186 + int major, minor, index; 113.187 113.188 - major = MAJOR_XEN(device); 113.189 - minor = MINOR_XEN(device); 113.190 + major = BLKIF_MAJOR(vdevice); 113.191 + minor = BLKIF_MINOR(vdevice); 113.192 113.193 - switch (major) { 113.194 - case IDE0_MAJOR: index = 0; break; 113.195 - case IDE1_MAJOR: index = 1; break; 113.196 - case IDE2_MAJOR: index = 2; break; 113.197 - case IDE3_MAJOR: index = 3; break; 113.198 - case IDE4_MAJOR: index = 4; break; 113.199 - case IDE5_MAJOR: index = 5; break; 113.200 - case IDE6_MAJOR: index = 6; break; 113.201 - case IDE7_MAJOR: index = 7; break; 113.202 - case IDE8_MAJOR: index = 8; break; 113.203 - case IDE9_MAJOR: index = 9; break; 113.204 - case SCSI_DISK0_MAJOR: index = 10; break; 113.205 - case SCSI_DISK1_MAJOR ... SCSI_DISK7_MAJOR: 113.206 - index = 11 + major - SCSI_DISK1_MAJOR; 113.207 - break; 113.208 - case SCSI_CDROM_MAJOR: index = 18; break; 113.209 - default: index = 19; break; 113.210 - } 113.211 + switch (major) { 113.212 + case IDE0_MAJOR: index = 0; break; 113.213 + case IDE1_MAJOR: index = 1; break; 113.214 + case IDE2_MAJOR: index = 2; break; 113.215 + case IDE3_MAJOR: index = 3; break; 113.216 + case IDE4_MAJOR: index = 4; break; 113.217 + case IDE5_MAJOR: index = 5; break; 113.218 + case IDE6_MAJOR: index = 6; break; 113.219 + case IDE7_MAJOR: index = 7; break; 113.220 + case IDE8_MAJOR: index = 8; break; 113.221 + case IDE9_MAJOR: index = 9; break; 113.222 + case SCSI_DISK0_MAJOR: index = 10; break; 113.223 + case SCSI_DISK1_MAJOR ... SCSI_DISK7_MAJOR: 113.224 + index = 11 + major - SCSI_DISK1_MAJOR; 113.225 + break; 113.226 + case SCSI_CDROM_MAJOR: index = 18; break; 113.227 + default: index = 19; break; 113.228 + } 113.229 113.230 - return ((major_info[index] != NULL) ? major_info[index] : 113.231 - xlbd_alloc_major_info(major, minor, index)); 113.232 + mi = ((major_info[index] != NULL) ? major_info[index] : 113.233 + xlbd_alloc_major_info(major, minor, index)); 113.234 + mi->usage++; 113.235 + return mi; 113.236 } 113.237 113.238 -static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) 113.239 +static void 113.240 +xlbd_put_major_info(struct xlbd_major_info *mi) 113.241 { 113.242 - request_queue_t *rq; 113.243 - 113.244 - rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 113.245 - if (rq == NULL) 113.246 - return -1; 113.247 - 113.248 - elevator_init(rq, "noop"); 113.249 - 113.250 - /* Hard sector size and max sectors impersonate the equiv. hardware. */ 113.251 - blk_queue_hardsect_size(rq, sector_size); 113.252 - blk_queue_max_sectors(rq, 512); 113.253 - 113.254 - /* Each segment in a request is up to an aligned page in size. */ 113.255 - blk_queue_segment_boundary(rq, PAGE_SIZE - 1); 113.256 - blk_queue_max_segment_size(rq, PAGE_SIZE); 113.257 - 113.258 - /* Ensure a merged request will fit in a single I/O ring slot. */ 113.259 - blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST); 113.260 - blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST); 113.261 - 113.262 - /* Make sure buffer addresses are sector-aligned. */ 113.263 - blk_queue_dma_alignment(rq, 511); 113.264 - 113.265 - gd->queue = rq; 113.266 - 113.267 - return 0; 113.268 + mi->usage--; 113.269 + /* XXX: release major if 0 */ 113.270 } 113.271 113.272 -static struct gendisk *xlvbd_alloc_gendisk( 113.273 - struct xlbd_major_info *mi, int minor, blkif_sector_t capacity, 113.274 - int device, blkif_vdev_t handle, u16 info, u16 sector_size) 113.275 +static int 113.276 +xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) 113.277 { 113.278 - struct gendisk *gd; 113.279 - struct xlbd_disk_info *di; 113.280 - int nr_minors = 1; 113.281 + request_queue_t *rq; 113.282 113.283 - di = kmalloc(sizeof(struct xlbd_disk_info), GFP_KERNEL); 113.284 - if (di == NULL) 113.285 - return NULL; 113.286 - memset(di, 0, sizeof(*di)); 113.287 - di->mi = mi; 113.288 - di->xd_device = device; 113.289 - di->handle = handle; 113.290 + rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 113.291 + if (rq == NULL) 113.292 + return -1; 113.293 113.294 - if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0) 113.295 - nr_minors = 1 << mi->type->partn_shift; 113.296 + elevator_init(rq, "noop"); 113.297 113.298 - gd = alloc_disk(nr_minors); 113.299 - if (gd == NULL) 113.300 - goto out; 113.301 + /* Hard sector size and max sectors impersonate the equiv. hardware. */ 113.302 + blk_queue_hardsect_size(rq, sector_size); 113.303 + blk_queue_max_sectors(rq, 512); 113.304 113.305 - if (nr_minors > 1) 113.306 - sprintf(gd->disk_name, "%s%c", mi->type->diskname, 113.307 - 'a' + mi->index * mi->type->disks_per_major + 113.308 - (minor >> mi->type->partn_shift)); 113.309 - else 113.310 - sprintf(gd->disk_name, "%s%c%d", mi->type->diskname, 113.311 - 'a' + mi->index * mi->type->disks_per_major + 113.312 - (minor >> mi->type->partn_shift), 113.313 - minor & ((1 << mi->type->partn_shift) - 1)); 113.314 - 113.315 - gd->major = mi->major; 113.316 - gd->first_minor = minor; 113.317 - gd->fops = &xlvbd_block_fops; 113.318 - gd->private_data = di; 113.319 - set_capacity(gd, capacity); 113.320 + /* Each segment in a request is up to an aligned page in size. */ 113.321 + blk_queue_segment_boundary(rq, PAGE_SIZE - 1); 113.322 + blk_queue_max_segment_size(rq, PAGE_SIZE); 113.323 113.324 - if (xlvbd_init_blk_queue(gd, sector_size)) { 113.325 - del_gendisk(gd); 113.326 - goto out; 113.327 - } 113.328 - 113.329 - di->rq = gd->queue; 113.330 - 113.331 - if (info & VDISK_READONLY) 113.332 - set_disk_ro(gd, 1); 113.333 + /* Ensure a merged request will fit in a single I/O ring slot. */ 113.334 + blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST); 113.335 + blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST); 113.336 113.337 - if (info & VDISK_REMOVABLE) 113.338 - gd->flags |= GENHD_FL_REMOVABLE; 113.339 - 113.340 - if (info & VDISK_CDROM) 113.341 - gd->flags |= GENHD_FL_CD; 113.342 + /* Make sure buffer addresses are sector-aligned. */ 113.343 + blk_queue_dma_alignment(rq, 511); 113.344 113.345 - add_disk(gd); 113.346 - 113.347 - return gd; 113.348 + gd->queue = rq; 113.349 113.350 -out: 113.351 - kfree(di); 113.352 - return NULL; 113.353 + return 0; 113.354 } 113.355 113.356 -int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle, 113.357 - u16 info, u16 sector_size) 113.358 +static int 113.359 +xlvbd_alloc_gendisk(int minor, blkif_sector_t capacity, int vdevice, 113.360 + u16 vdisk_info, u16 sector_size, 113.361 + struct blkfront_info *info) 113.362 { 113.363 - struct lvdisk *new; 113.364 - struct block_device *bd; 113.365 - struct gendisk *gd; 113.366 - struct xlbd_major_info *mi; 113.367 + struct gendisk *gd; 113.368 + struct xlbd_major_info *mi; 113.369 + int nr_minors = 1; 113.370 + int err = -ENODEV; 113.371 113.372 - mi = xlbd_get_major_info(device); 113.373 - if (mi == NULL) 113.374 - return -EPERM; 113.375 + mi = xlbd_get_major_info(vdevice); 113.376 + if (mi == NULL) 113.377 + goto out; 113.378 + info->mi = mi; 113.379 + 113.380 + if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0) 113.381 + nr_minors = 1 << mi->type->partn_shift; 113.382 + 113.383 + gd = alloc_disk(nr_minors); 113.384 + if (gd == NULL) 113.385 + goto out; 113.386 113.387 - new = xlvbd_device_alloc(); 113.388 - if (new == NULL) 113.389 - return -ENOMEM; 113.390 - new->capacity = capacity; 113.391 - new->info = info; 113.392 - new->handle = handle; 113.393 - new->dev = MKDEV(MAJOR_XEN(device), MINOR_XEN(device)); 113.394 + if (nr_minors > 1) 113.395 + sprintf(gd->disk_name, "%s%c", mi->type->diskname, 113.396 + 'a' + mi->index * mi->type->disks_per_major + 113.397 + (minor >> mi->type->partn_shift)); 113.398 + else 113.399 + sprintf(gd->disk_name, "%s%c%d", mi->type->diskname, 113.400 + 'a' + mi->index * mi->type->disks_per_major + 113.401 + (minor >> mi->type->partn_shift), 113.402 + minor & ((1 << mi->type->partn_shift) - 1)); 113.403 + 113.404 + gd->major = mi->major; 113.405 + gd->first_minor = minor; 113.406 + gd->fops = &xlvbd_block_fops; 113.407 + gd->private_data = info; 113.408 + set_capacity(gd, capacity); 113.409 113.410 - bd = bdget(new->dev); 113.411 - if (bd == NULL) 113.412 - goto out; 113.413 - 113.414 - gd = xlvbd_alloc_gendisk(mi, MINOR_XEN(device), capacity, device, handle, 113.415 - info, sector_size); 113.416 - if (gd == NULL) 113.417 - goto out_bd; 113.418 + if (xlvbd_init_blk_queue(gd, sector_size)) { 113.419 + del_gendisk(gd); 113.420 + goto out; 113.421 + } 113.422 + 113.423 + info->rq = gd->queue; 113.424 + 113.425 + if (vdisk_info & VDISK_READONLY) 113.426 + set_disk_ro(gd, 1); 113.427 113.428 - list_add(&new->list, &vbds_list); 113.429 -out_bd: 113.430 - bdput(bd); 113.431 -out: 113.432 - return 0; 113.433 + if (vdisk_info & VDISK_REMOVABLE) 113.434 + gd->flags |= GENHD_FL_REMOVABLE; 113.435 + 113.436 + if (vdisk_info & VDISK_CDROM) 113.437 + gd->flags |= GENHD_FL_CD; 113.438 + 113.439 + add_disk(gd); 113.440 + 113.441 + return 0; 113.442 + 113.443 + out: 113.444 + if (mi) 113.445 + xlbd_put_major_info(mi); 113.446 + return err; 113.447 } 113.448 113.449 -static int xlvbd_device_del(struct lvdisk *disk) 113.450 +int 113.451 +xlvbd_add(blkif_sector_t capacity, int vdevice, u16 vdisk_info, 113.452 + u16 sector_size, struct blkfront_info *info) 113.453 { 113.454 - struct block_device *bd; 113.455 - struct gendisk *gd; 113.456 - struct xlbd_disk_info *di; 113.457 - int ret = 0, unused; 113.458 - request_queue_t *rq; 113.459 + struct block_device *bd; 113.460 + int err = 0; 113.461 113.462 - bd = bdget(disk->dev); 113.463 - if (bd == NULL) 113.464 - return -1; 113.465 - 113.466 - gd = get_gendisk(disk->dev, &unused); 113.467 - di = gd->private_data; 113.468 + info->dev = MKDEV(BLKIF_MAJOR(vdevice), BLKIF_MINOR(vdevice)); 113.469 113.470 -#if 0 /* This is wrong: hda and hdb share same major, for example. */ 113.471 - if (di->mi->usage != 0) { 113.472 - WPRINTK("disk removal failed: used [dev=%x]\n", disk->dev); 113.473 - ret = -1; 113.474 - goto out; 113.475 - } 113.476 -#endif 113.477 + bd = bdget(info->dev); 113.478 + if (bd == NULL) 113.479 + return -ENODEV; 113.480 113.481 - rq = gd->queue; 113.482 - del_gendisk(gd); 113.483 - put_disk(gd); 113.484 - blk_cleanup_queue(rq); 113.485 + err = xlvbd_alloc_gendisk(BLKIF_MINOR(vdevice), capacity, vdevice, 113.486 + vdisk_info, sector_size, info); 113.487 113.488 - xlvbd_device_free(disk); 113.489 - bdput(bd); 113.490 - return ret; 113.491 + bdput(bd); 113.492 + return err; 113.493 } 113.494 113.495 -void xlvbd_del(blkif_vdev_t handle) 113.496 +void 113.497 +xlvbd_del(struct blkfront_info *info) 113.498 { 113.499 - struct lvdisk *i; 113.500 + struct block_device *bd; 113.501 + struct gendisk *gd; 113.502 + int unused; 113.503 + request_queue_t *rq; 113.504 + 113.505 + bd = bdget(info->dev); 113.506 + if (bd == NULL) 113.507 + return; 113.508 113.509 - list_for_each_entry(i, &vbds_list, list) { 113.510 - if (i->handle == handle) { 113.511 - xlvbd_device_del(i); 113.512 - return; 113.513 - } 113.514 - } 113.515 - BUG(); 113.516 + gd = get_gendisk(info->dev, &unused); 113.517 + rq = gd->queue; 113.518 + 113.519 + del_gendisk(gd); 113.520 + put_disk(gd); 113.521 + xlbd_put_major_info(info->mi); 113.522 + info->mi = NULL; 113.523 + blk_cleanup_queue(rq); 113.524 + 113.525 + bdput(bd); 113.526 }
123.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Mon Aug 22 11:37:48 2005 -0700 123.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Tue Aug 23 12:03:21 2005 -0700 123.3 @@ -102,12 +102,12 @@ dump_packet(int tag, void *addr, u32 ap) 123.4 #endif 123.5 123.6 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 123.7 -static grant_ref_t gref_tx_head, gref_tx_terminal; 123.8 +static grant_ref_t gref_tx_head; 123.9 static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1]; 123.10 #endif 123.11 123.12 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 123.13 -static grant_ref_t gref_rx_head, gref_rx_terminal; 123.14 +static grant_ref_t gref_rx_head; 123.15 static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1]; 123.16 #endif 123.17 123.18 @@ -441,8 +441,8 @@ static void network_alloc_rx_buffers(str 123.19 123.20 np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.id = id; 123.21 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 123.22 - if (unlikely((ref = gnttab_claim_grant_reference(&gref_rx_head, 123.23 - gref_rx_terminal)) < 0)) { 123.24 + ref = gnttab_claim_grant_reference(&gref_rx_head); 123.25 + if (unlikely(ref < 0)) { 123.26 printk(KERN_ALERT "#### netfront can't claim rx reference\n"); 123.27 BUG(); 123.28 } 123.29 @@ -537,8 +537,8 @@ static int network_start_xmit(struct sk_ 123.30 123.31 tx->id = id; 123.32 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 123.33 - if (unlikely((ref = gnttab_claim_grant_reference(&gref_tx_head, 123.34 - gref_tx_terminal)) < 0)) { 123.35 + ref = gnttab_claim_grant_reference(&gref_tx_head); 123.36 + if (unlikely(ref < 0)) { 123.37 printk(KERN_ALERT "#### netfront can't claim tx grant reference\n"); 123.38 BUG(); 123.39 } 123.40 @@ -929,8 +929,7 @@ static void send_interface_connect(struc 123.41 msg->handle = np->handle; 123.42 msg->tx_shmem_frame = virt_to_mfn(np->tx); 123.43 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 123.44 - msg->tx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_tx_head, 123.45 - gref_tx_terminal); 123.46 + msg->tx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_tx_head); 123.47 if(msg->tx_shmem_ref < 0) { 123.48 printk(KERN_ALERT "#### netfront can't claim tx_shmem reference\n"); 123.49 BUG(); 123.50 @@ -941,8 +940,7 @@ static void send_interface_connect(struc 123.51 123.52 msg->rx_shmem_frame = virt_to_mfn(np->rx); 123.53 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 123.54 - msg->rx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_rx_head, 123.55 - gref_rx_terminal); 123.56 + msg->rx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_rx_head); 123.57 if(msg->rx_shmem_ref < 0) { 123.58 printk(KERN_ALERT "#### netfront can't claim rx_shmem reference\n"); 123.59 BUG(); 123.60 @@ -1420,7 +1418,7 @@ static int __init netif_init(void) 123.61 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 123.62 /* A grant for every ring slot, plus one for the ring itself */ 123.63 if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE + 1, 123.64 - &gref_tx_head, &gref_tx_terminal) < 0) { 123.65 + &gref_tx_head) < 0) { 123.66 printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n"); 123.67 return 1; 123.68 } 123.69 @@ -1429,7 +1427,7 @@ static int __init netif_init(void) 123.70 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 123.71 /* A grant for every ring slot, plus one for the ring itself */ 123.72 if (gnttab_alloc_grant_references(NETIF_RX_RING_SIZE + 1, 123.73 - &gref_rx_head, &gref_rx_terminal) < 0) { 123.74 + &gref_rx_head) < 0) { 123.75 printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n"); 123.76 return 1; 123.77 } 123.78 @@ -1457,10 +1455,10 @@ static int __init netif_init(void) 123.79 static void netif_exit(void) 123.80 { 123.81 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 123.82 - gnttab_free_grant_references(NETIF_TX_RING_SIZE + 1, gref_tx_head); 123.83 + gnttab_free_grant_references(gref_tx_head); 123.84 #endif 123.85 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 123.86 - gnttab_free_grant_references(NETIF_RX_RING_SIZE + 1, gref_rx_head); 123.87 + gnttab_free_grant_references(gref_rx_head); 123.88 #endif 123.89 } 123.90
124.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c Mon Aug 22 11:37:48 2005 -0700 124.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c Tue Aug 23 12:03:21 2005 -0700 124.3 @@ -167,7 +167,7 @@ static int privcmd_ioctl(struct inode *i 124.4 if (ret) 124.5 goto batch_err; 124.6 124.7 - u.val = (mfn << PAGE_SHIFT) | pgprot_val(vma->vm_page_prot); 124.8 + u.val = pte_val_ma(pfn_pte_ma(mfn, vma->vm_page_prot)); 124.9 u.ptr = ptep; 124.10 124.11 if ( unlikely(HYPERVISOR_mmu_update(&u, 1, NULL, m.dom) < 0) )
144.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h Mon Aug 22 11:37:48 2005 -0700 144.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h Tue Aug 23 12:03:21 2005 -0700 144.3 @@ -60,9 +60,13 @@ 144.4 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 144.5 144.6 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/ 144.7 +#define INVALID_P2M_ENTRY (~0U) 144.8 +#define FOREIGN_FRAME(m) ((m) | 0x80000000U) 144.9 extern unsigned int *phys_to_machine_mapping; 144.10 -#define pfn_to_mfn(_pfn) ((unsigned long)(phys_to_machine_mapping[(_pfn)])) 144.11 -#define mfn_to_pfn(_mfn) ((unsigned long)(machine_to_phys_mapping[(_mfn)])) 144.12 +#define pfn_to_mfn(pfn) \ 144.13 +((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL) 144.14 +#define mfn_to_pfn(mfn) \ 144.15 +((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)]) 144.16 144.17 /* Definitions for machine and pseudophysical addresses. */ 144.18 #ifdef CONFIG_X86_PAE
147.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h Mon Aug 22 11:37:48 2005 -0700 147.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h Tue Aug 23 12:03:21 2005 -0700 147.3 @@ -63,17 +63,15 @@ inline static void set_pte_at_sync(struc 147.4 * 147.5 * NB2. When deliberately mapping foreign pages into the p2m table, you *must* 147.6 * use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we 147.7 - * require. In all the cases we care about, the high bit gets shifted out 147.8 - * (e.g., phys_to_machine()) so behaviour there is correct. 147.9 + * require. In all the cases we care about, the FOREIGN_FRAME bit is 147.10 + * masked (e.g., pfn_to_mfn()) so behaviour there is correct. 147.11 */ 147.12 -#define INVALID_P2M_ENTRY (~0U) 147.13 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1))) 147.14 #define pte_mfn(_pte) ((_pte).pte_low >> PAGE_SHIFT) 147.15 #define pte_pfn(_pte) \ 147.16 ({ \ 147.17 unsigned long mfn = pte_mfn(_pte); \ 147.18 unsigned long pfn = mfn_to_pfn(mfn); \ 147.19 - if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn)) \ 147.20 + if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\ 147.21 pfn = max_mapnr; /* special: force !pfn_valid() */ \ 147.22 pfn; \ 147.23 })
148.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h Mon Aug 22 11:37:48 2005 -0700 148.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h Tue Aug 23 12:03:21 2005 -0700 148.3 @@ -150,15 +150,13 @@ static inline int pte_none(pte_t pte) 148.4 return !pte.pte_low && !pte.pte_high; 148.5 } 148.6 148.7 -#define INVALID_P2M_ENTRY (~0U) 148.8 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1))) 148.9 #define pte_mfn(_pte) ( ((_pte).pte_low >> PAGE_SHIFT) |\ 148.10 (((_pte).pte_high & 0xfff) << (32-PAGE_SHIFT)) ) 148.11 #define pte_pfn(_pte) \ 148.12 ({ \ 148.13 unsigned long mfn = pte_mfn(_pte); \ 148.14 unsigned long pfn = mfn_to_pfn(mfn); \ 148.15 - if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn)) \ 148.16 + if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\ 148.17 pfn = max_mapnr; /* special: force !pfn_valid() */ \ 148.18 pfn; \ 148.19 })
157.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h Mon Aug 22 11:37:48 2005 -0700 157.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h Tue Aug 23 12:03:21 2005 -0700 157.3 @@ -62,9 +62,13 @@ void copy_page(void *, void *); 157.4 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE 157.5 157.6 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/ 157.7 +#define INVALID_P2M_ENTRY (~0U) 157.8 +#define FOREIGN_FRAME(m) ((m) | 0x80000000U) 157.9 extern u32 *phys_to_machine_mapping; 157.10 -#define pfn_to_mfn(_pfn) ((unsigned long) phys_to_machine_mapping[(unsigned int)(_pfn)]) 157.11 -#define mfn_to_pfn(_mfn) ((unsigned long) machine_to_phys_mapping[(unsigned int)(_mfn)]) 157.12 +#define pfn_to_mfn(pfn) \ 157.13 +((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL) 157.14 +#define mfn_to_pfn(mfn) \ 157.15 +((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)]) 157.16 157.17 /* Definitions for machine and pseudophysical addresses. */ 157.18 typedef unsigned long paddr_t;
159.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h Mon Aug 22 11:37:48 2005 -0700 159.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h Tue Aug 23 12:03:21 2005 -0700 159.3 @@ -300,17 +300,15 @@ inline static void set_pte_at(struct mm_ 159.4 * 159.5 * NB2. When deliberately mapping foreign pages into the p2m table, you *must* 159.6 * use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we 159.7 - * require. In all the cases we care about, the high bit gets shifted out 159.8 - * (e.g., phys_to_machine()) so behaviour there is correct. 159.9 + * require. In all the cases we care about, the FOREIGN_FRAME bit is 159.10 + * masked (e.g., pfn_to_mfn()) so behaviour there is correct. 159.11 */ 159.12 -#define INVALID_P2M_ENTRY (~0U) 159.13 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1))) 159.14 #define pte_mfn(_pte) (((_pte).pte & PTE_MASK) >> PAGE_SHIFT) 159.15 #define pte_pfn(_pte) \ 159.16 ({ \ 159.17 unsigned long mfn = pte_mfn(_pte); \ 159.18 unsigned pfn = mfn_to_pfn(mfn); \ 159.19 - if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn)) \ 159.20 + if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\ 159.21 pfn = max_mapnr; /* special: force !pfn_valid() */ \ 159.22 pfn; \ 159.23 })
164.1 --- a/linux-2.6-xen-sparse/include/asm-xen/gnttab.h Mon Aug 22 11:37:48 2005 -0700 164.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/gnttab.h Tue Aug 23 12:03:21 2005 -0700 164.3 @@ -19,54 +19,46 @@ 164.4 164.5 /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ 164.6 #define NR_GRANT_FRAMES 4 164.7 -#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t)) 164.8 164.9 -int 164.10 -gnttab_grant_foreign_access( 164.11 - domid_t domid, unsigned long frame, int readonly); 164.12 - 164.13 -void 164.14 -gnttab_end_foreign_access( 164.15 - grant_ref_t ref, int readonly); 164.16 +struct gnttab_free_callback { 164.17 + struct gnttab_free_callback *next; 164.18 + void (*fn)(void *); 164.19 + void *arg; 164.20 + u16 count; 164.21 +}; 164.22 164.23 -int 164.24 -gnttab_grant_foreign_transfer( 164.25 - domid_t domid, unsigned long pfn); 164.26 +int gnttab_grant_foreign_access(domid_t domid, unsigned long frame, 164.27 + int readonly); 164.28 + 164.29 +void gnttab_end_foreign_access(grant_ref_t ref, int readonly); 164.30 164.31 -unsigned long 164.32 -gnttab_end_foreign_transfer( 164.33 - grant_ref_t ref); 164.34 +int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn); 164.35 164.36 -int 164.37 -gnttab_query_foreign_access( 164.38 - grant_ref_t ref ); 164.39 +unsigned long gnttab_end_foreign_transfer(grant_ref_t ref); 164.40 + 164.41 +int gnttab_query_foreign_access(grant_ref_t ref); 164.42 164.43 /* 164.44 * operations on reserved batches of grant references 164.45 */ 164.46 -int 164.47 -gnttab_alloc_grant_references( 164.48 - u16 count, grant_ref_t *pprivate_head, grant_ref_t *private_terminal ); 164.49 +int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head); 164.50 + 164.51 +void gnttab_free_grant_reference(grant_ref_t ref); 164.52 164.53 -void 164.54 -gnttab_free_grant_references( 164.55 - u16 count, grant_ref_t private_head ); 164.56 +void gnttab_free_grant_references(grant_ref_t head); 164.57 164.58 -int 164.59 -gnttab_claim_grant_reference( grant_ref_t *pprivate_head, grant_ref_t terminal 164.60 -); 164.61 +int gnttab_claim_grant_reference(grant_ref_t *pprivate_head); 164.62 164.63 -void 164.64 -gnttab_release_grant_reference( 164.65 - grant_ref_t *private_head, grant_ref_t release ); 164.66 +void gnttab_release_grant_reference(grant_ref_t *private_head, 164.67 + grant_ref_t release); 164.68 + 164.69 +void gnttab_request_free_callback(struct gnttab_free_callback *callback, 164.70 + void (*fn)(void *), void *arg, u16 count); 164.71 164.72 -void 164.73 -gnttab_grant_foreign_access_ref( 164.74 - grant_ref_t ref, domid_t domid, unsigned long frame, int readonly); 164.75 +void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, 164.76 + unsigned long frame, int readonly); 164.77 164.78 -void 164.79 -gnttab_grant_foreign_transfer_ref( 164.80 - grant_ref_t, domid_t domid, unsigned long pfn); 164.81 - 164.82 +void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, 164.83 + unsigned long pfn); 164.84 164.85 #endif /* __ASM_GNTTAB_H__ */
176.1 --- a/tools/Makefile Mon Aug 22 11:37:48 2005 -0700 176.2 +++ b/tools/Makefile Tue Aug 23 12:03:21 2005 -0700 176.3 @@ -14,6 +14,7 @@ SUBDIRS += xcutils 176.4 SUBDIRS += firmware 176.5 SUBDIRS += security 176.6 SUBDIRS += console 176.7 +SUBDIRS += xenstat 176.8 176.9 .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean 176.10
177.1 --- a/tools/Rules.mk Mon Aug 22 11:37:48 2005 -0700 177.2 +++ b/tools/Rules.mk Tue Aug 23 12:03:21 2005 -0700 177.3 @@ -6,6 +6,7 @@ XEN_XC = $(XEN_ROOT)/tools/p 177.4 XEN_LIBXC = $(XEN_ROOT)/tools/libxc 177.5 XEN_XCS = $(XEN_ROOT)/tools/xcs 177.6 XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore 177.7 +XEN_LIBXENSTAT = $(XEN_ROOT)/tools/xenstat/libxenstat/src 177.8 177.9 ifeq ($(XEN_TARGET_ARCH),x86_32) 177.10 CFLAGS += -m32 -march=i686
318.1 --- a/tools/python/xen/xm/main.py Mon Aug 22 11:37:48 2005 -0700 318.2 +++ b/tools/python/xen/xm/main.py Tue Aug 23 12:03:21 2005 -0700 318.3 @@ -49,6 +49,7 @@ xm common subcommands: 318.4 restore <File> create a domain from a saved state file 318.5 save <DomId> <File> save domain state (and config) to file 318.6 shutdown <DomId> shutdown a domain 318.7 + top monitor system and domains in real-time 318.8 unpause <DomId> unpause a paused domain 318.9 318.10 For a complete list of subcommands run 'xm help --long' 318.11 @@ -87,6 +88,7 @@ xm full list of subcommands: 318.12 dmesg [--clear] read or clear Xen's message buffer 318.13 info get information about the xen host 318.14 log print the xend log 318.15 + top monitor system and domains in real-time 318.16 318.17 Scheduler Commands: 318.18 bvt <options> set BVT scheduler parameters 318.19 @@ -457,6 +459,9 @@ def xm_console(args): 318.20 os.execvp('/usr/libexec/xen/xenconsole', cmd.split()) 318.21 console = sxp.child(info, "console") 318.22 318.23 +def xm_top(args): 318.24 + os.execv('/usr/sbin/xentop', ['/usr/sbin/xentop']) 318.25 + 318.26 def xm_dmesg(args): 318.27 318.28 gopts = Opts(use="""[-c|--clear] 318.29 @@ -545,6 +550,8 @@ def xm_block_destroy(args): 318.30 commands = { 318.31 # console commands 318.32 "console": xm_console, 318.33 + # xenstat commands 318.34 + "top": xm_top, 318.35 # domain commands 318.36 "domid": xm_domid, 318.37 "domname": xm_domname,
361.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 361.2 +++ b/tools/xenstat/Makefile Tue Aug 23 12:03:21 2005 -0700 361.3 @@ -0,0 +1,13 @@ 361.4 +XEN_ROOT = ../.. 361.5 +include $(XEN_ROOT)/tools/Rules.mk 361.6 + 361.7 +SUBDIRS := 361.8 +SUBDIRS += libxenstat 361.9 +SUBDIRS += xentop 361.10 + 361.11 +.PHONY: all install clean 361.12 + 361.13 +all install clean: 361.14 + @set -e; for subdir in $(SUBDIRS); do \ 361.15 + $(MAKE) -C $$subdir $@; \ 361.16 + done
362.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 362.2 +++ b/tools/xenstat/libxenstat/COPYING Tue Aug 23 12:03:21 2005 -0700 362.3 @@ -0,0 +1,510 @@ 362.4 + 362.5 + GNU LESSER GENERAL PUBLIC LICENSE 362.6 + Version 2.1, February 1999 362.7 + 362.8 + Copyright (C) 1991, 1999 Free Software Foundation, Inc. 362.9 + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 362.10 + Everyone is permitted to copy and distribute verbatim copies 362.11 + of this license document, but changing it is not allowed. 362.12 + 362.13 +[This is the first released version of the Lesser GPL. It also counts 362.14 + as the successor of the GNU Library Public License, version 2, hence 362.15 + the version number 2.1.] 362.16 + 362.17 + Preamble 362.18 + 362.19 + The licenses for most software are designed to take away your 362.20 +freedom to share and change it. By contrast, the GNU General Public 362.21 +Licenses are intended to guarantee your freedom to share and change 362.22 +free software--to make sure the software is free for all its users. 362.23 + 362.24 + This license, the Lesser General Public License, applies to some 362.25 +specially designated software packages--typically libraries--of the 362.26 +Free Software Foundation and other authors who decide to use it. You 362.27 +can use it too, but we suggest you first think carefully about whether 362.28 +this license or the ordinary General Public License is the better 362.29 +strategy to use in any particular case, based on the explanations 362.30 +below. 362.31 + 362.32 + When we speak of free software, we are referring to freedom of use, 362.33 +not price. Our General Public Licenses are designed to make sure that 362.34 +you have the freedom to distribute copies of free software (and charge 362.35 +for this service if you wish); that you receive source code or can get 362.36 +it if you want it; that you can change the software and use pieces of 362.37 +it in new free programs; and that you are informed that you can do 362.38 +these things. 362.39 + 362.40 + To protect your rights, we need to make restrictions that forbid 362.41 +distributors to deny you these rights or to ask you to surrender these 362.42 +rights. These restrictions translate to certain responsibilities for 362.43 +you if you distribute copies of the library or if you modify it. 362.44 + 362.45 + For example, if you distribute copies of the library, whether gratis 362.46 +or for a fee, you must give the recipients all the rights that we gave 362.47 +you. You must make sure that they, too, receive or can get the source 362.48 +code. If you link other code with the library, you must provide 362.49 +complete object files to the recipients, so that they can relink them 362.50 +with the library after making changes to the library and recompiling 362.51 +it. And you must show them these terms so they know their rights. 362.52 + 362.53 + We protect your rights with a two-step method: (1) we copyright the 362.54 +library, and (2) we offer you this license, which gives you legal 362.55 +permission to copy, distribute and/or modify the library. 362.56 + 362.57 + To protect each distributor, we want to make it very clear that 362.58 +there is no warranty for the free library. Also, if the library is 362.59 +modified by someone else and passed on, the recipients should know 362.60 +that what they have is not the original version, so that the original 362.61 +author's reputation will not be affected by problems that might be 362.62 +introduced by others. 362.63 + 362.64 + Finally, software patents pose a constant threat to the existence of 362.65 +any free program. We wish to make sure that a company cannot 362.66 +effectively restrict the users of a free program by obtaining a 362.67 +restrictive license from a patent holder. Therefore, we insist that 362.68 +any patent license obtained for a version of the library must be 362.69 +consistent with the full freedom of use specified in this license. 362.70 + 362.71 + Most GNU software, including some libraries, is covered by the 362.72 +ordinary GNU General Public License. This license, the GNU Lesser 362.73 +General Public License, applies to certain designated libraries, and 362.74 +is quite different from the ordinary General Public License. We use 362.75 +this license for certain libraries in order to permit linking those 362.76 +libraries into non-free programs. 362.77 + 362.78 + When a program is linked with a library, whether statically or using 362.79 +a shared library, the combination of the two is legally speaking a 362.80 +combined work, a derivative of the original library. The ordinary 362.81 +General Public License therefore permits such linking only if the 362.82 +entire combination fits its criteria of freedom. The Lesser General 362.83 +Public License permits more lax criteria for linking other code with 362.84 +the library. 362.85 + 362.86 + We call this license the "Lesser" General Public License because it 362.87 +does Less to protect the user's freedom than the ordinary General 362.88 +Public License. It also provides other free software developers Less 362.89 +of an advantage over competing non-free programs. These disadvantages 362.90 +are the reason we use the ordinary General Public License for many 362.91 +libraries. However, the Lesser license provides advantages in certain 362.92 +special circumstances. 362.93 + 362.94 + For example, on rare occasions, there may be a special need to 362.95 +encourage the widest possible use of a certain library, so that it 362.96 +becomes a de-facto standard. To achieve this, non-free programs must 362.97 +be allowed to use the library. A more frequent case is that a free 362.98 +library does the same job as widely used non-free libraries. In this 362.99 +case, there is little to gain by limiting the free library to free 362.100 +software only, so we use the Lesser General Public License. 362.101 + 362.102 + In other cases, permission to use a particular library in non-free 362.103 +programs enables a greater number of people to use a large body of 362.104 +free software. For example, permission to use the GNU C Library in 362.105 +non-free programs enables many more people to use the whole GNU 362.106 +operating system, as well as its variant, the GNU/Linux operating 362.107 +system. 362.108 + 362.109 + Although the Lesser General Public License is Less protective of the 362.110 +users' freedom, it does ensure that the user of a program that is 362.111 +linked with the Library has the freedom and the wherewithal to run 362.112 +that program using a modified version of the Library. 362.113 + 362.114 + The precise terms and conditions for copying, distribution and 362.115 +modification follow. Pay close attention to the difference between a 362.116 +"work based on the library" and a "work that uses the library". The 362.117 +former contains code derived from the library, whereas the latter must 362.118 +be combined with the library in order to run. 362.119 + 362.120 + GNU LESSER GENERAL PUBLIC LICENSE 362.121 + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 362.122 + 362.123 + 0. This License Agreement applies to any software library or other 362.124 +program which contains a notice placed by the copyright holder or 362.125 +other authorized party saying it may be distributed under the terms of 362.126 +this Lesser General Public License (also called "this License"). 362.127 +Each licensee is addressed as "you". 362.128 + 362.129 + A "library" means a collection of software functions and/or data 362.130 +prepared so as to be conveniently linked with application programs 362.131 +(which use some of those functions and data) to form executables. 362.132 + 362.133 + The "Library", below, refers to any such software library or work 362.134 +which has been distributed under these terms. A "work based on the 362.135 +Library" means either the Library or any derivative work under 362.136 +copyright law: that is to say, a work containing the Library or a 362.137 +portion of it, either verbatim or with modifications and/or translated 362.138 +straightforwardly into another language. (Hereinafter, translation is 362.139 +included without limitation in the term "modification".) 362.140 + 362.141 + "Source code" for a work means the preferred form of the work for 362.142 +making modifications to it. For a library, complete source code means 362.143 +all the source code for all modules it contains, plus any associated 362.144 +interface definition files, plus the scripts used to control 362.145 +compilation and installation of the library. 362.146 + 362.147 + Activities other than copying, distribution and modification are not 362.148 +covered by this License; they are outside its scope. The act of 362.149 +running a program using the Library is not restricted, and output from 362.150 +such a program is covered only if its contents constitute a work based 362.151 +on the Library (independent of the use of the Library in a tool for 362.152 +writing it). Whether that is true depends on what the Library does 362.153 +and what the program that uses the Library does. 362.154 + 362.155 + 1. You may copy and distribute verbatim copies of the Library's 362.156 +complete source code as you receive it, in any medium, provided that 362.157 +you conspicuously and appropriately publish on each copy an 362.158 +appropriate copyright notice and disclaimer of warranty; keep intact 362.159 +all the notices that refer to this License and to the absence of any 362.160 +warranty; and distribute a copy of this License along with the 362.161 +Library. 362.162 + 362.163 + You may charge a fee for the physical act of transferring a copy, 362.164 +and you may at your option offer warranty protection in exchange for a 362.165 +fee. 362.166 + 362.167 + 2. You may modify your copy or copies of the Library or any portion 362.168 +of it, thus forming a work based on the Library, and copy and 362.169 +distribute such modifications or work under the terms of Section 1 362.170 +above, provided that you also meet all of these conditions: 362.171 + 362.172 + a) The modified work must itself be a software library. 362.173 + 362.174 + b) You must cause the files modified to carry prominent notices 362.175 + stating that you changed the files and the date of any change. 362.176 + 362.177 + c) You must cause the whole of the work to be licensed at no 362.178 + charge to all third parties under the terms of this License. 362.179 + 362.180 + d) If a facility in the modified Library refers to a function or a 362.181 + table of data to be supplied by an application program that uses 362.182 + the facility, other than as an argument passed when the facility 362.183 + is invoked, then you must make a good faith effort to ensure that, 362.184 + in the event an application does not supply such function or 362.185 + table, the facility still operates, and performs whatever part of 362.186 + its purpose remains meaningful. 362.187 + 362.188 + (For example, a function in a library to compute square roots has 362.189 + a purpose that is entirely well-defined independent of the 362.190 + application. Therefore, Subsection 2d requires that any 362.191 + application-supplied function or table used by this function must 362.192 + be optional: if the application does not supply it, the square 362.193 + root function must still compute square roots.) 362.194 + 362.195 +These requirements apply to the modified work as a whole. If 362.196 +identifiable sections of that work are not derived from the Library, 362.197 +and can be reasonably considered independent and separate works in 362.198 +themselves, then this License, and its terms, do not apply to those 362.199 +sections when you distribute them as separate works. But when you 362.200 +distribute the same sections as part of a whole which is a work based 362.201 +on the Library, the distribution of the whole must be on the terms of 362.202 +this License, whose permissions for other licensees extend to the 362.203 +entire whole, and thus to each and every part regardless of who wrote 362.204 +it. 362.205 + 362.206 +Thus, it is not the intent of this section to claim rights or contest 362.207 +your rights to work written entirely by you; rather, the intent is to 362.208 +exercise the right to control the distribution of derivative or 362.209 +collective works based on the Library. 362.210 + 362.211 +In addition, mere aggregation of another work not based on the Library 362.212 +with the Library (or with a work based on the Library) on a volume of 362.213 +a storage or distribution medium does not bring the other work under 362.214 +the scope of this License. 362.215 + 362.216 + 3. You may opt to apply the terms of the ordinary GNU General Public 362.217 +License instead of this License to a given copy of the Library. To do 362.218 +this, you must alter all the notices that refer to this License, so 362.219 +that they refer to the ordinary GNU General Public License, version 2, 362.220 +instead of to this License. (If a newer version than version 2 of the 362.221 +ordinary GNU General Public License has appeared, then you can specify 362.222 +that version instead if you wish.) Do not make any other change in 362.223 +these notices. 362.224 + 362.225 + Once this change is made in a given copy, it is irreversible for 362.226 +that copy, so the ordinary GNU General Public License applies to all 362.227 +subsequent copies and derivative works made from that copy. 362.228 + 362.229 + This option is useful when you wish to copy part of the code of 362.230 +the Library into a program that is not a library. 362.231 + 362.232 + 4. You may copy and distribute the Library (or a portion or 362.233 +derivative of it, under Section 2) in object code or executable form 362.234 +under the terms of Sections 1 and 2 above provided that you accompany 362.235 +it with the complete corresponding machine-readable source code, which 362.236 +must be distributed under the terms of Sections 1 and 2 above on a 362.237 +medium customarily used for software interchange. 362.238 + 362.239 + If distribution of object code is made by offering access to copy 362.240 +from a designated place, then offering equivalent access to copy the 362.241 +source code from the same place satisfies the requirement to 362.242 +distribute the source code, even though third parties are not 362.243 +compelled to copy the source along with the object code. 362.244 + 362.245 + 5. A program that contains no derivative of any portion of the 362.246 +Library, but is designed to work with the Library by being compiled or 362.247 +linked with it, is called a "work that uses the Library". Such a 362.248 +work, in isolation, is not a derivative work of the Library, and 362.249 +therefore falls outside the scope of this License. 362.250 + 362.251 + However, linking a "work that uses the Library" with the Library 362.252 +creates an executable that is a derivative of the Library (because it 362.253 +contains portions of the Library), rather than a "work that uses the 362.254 +library". The executable is therefore covered by this License. 362.255 +Section 6 states terms for distribution of such executables. 362.256 + 362.257 + When a "work that uses the Library" uses material from a header file 362.258 +that is part of the Library, the object code for the work may be a 362.259 +derivative work of the Library even though the source code is not. 362.260 +Whether this is true is especially significant if the work can be 362.261 +linked without the Library, or if the work is itself a library. The 362.262 +threshold for this to be true is not precisely defined by law. 362.263 + 362.264 + If such an object file uses only numerical parameters, data 362.265 +structure layouts and accessors, and small macros and small inline 362.266 +functions (ten lines or less in length), then the use of the object 362.267 +file is unrestricted, regardless of whether it is legally a derivative 362.268 +work. (Executables containing this object code plus portions of the 362.269 +Library will still fall under Section 6.) 362.270 + 362.271 + Otherwise, if the work is a derivative of the Library, you may 362.272 +distribute the object code for the work under the terms of Section 6. 362.273 +Any executables containing that work also fall under Section 6, 362.274 +whether or not they are linked directly with the Library itself. 362.275 + 362.276 + 6. As an exception to the Sections above, you may also combine or 362.277 +link a "work that uses the Library" with the Library to produce a 362.278 +work containing portions of the Library, and distribute that work 362.279 +under terms of your choice, provided that the terms permit 362.280 +modification of the work for the customer's own use and reverse 362.281 +engineering for debugging such modifications. 362.282 + 362.283 + You must give prominent notice with each copy of the work that the 362.284 +Library is used in it and that the Library and its use are covered by 362.285 +this License. You must supply a copy of this License. If the work 362.286 +during execution displays copyright notices, you must include the 362.287 +copyright notice for the Library among them, as well as a reference 362.288 +directing the user to the copy of this License. Also, you must do one 362.289 +of these things: 362.290 + 362.291 + a) Accompany the work with the complete corresponding 362.292 + machine-readable source code for the Library including whatever 362.293 + changes were used in the work (which must be distributed under 362.294 + Sections 1 and 2 above); and, if the work is an executable linked 362.295 + with the Library, with the complete machine-readable "work that 362.296 + uses the Library", as object code and/or source code, so that the 362.297 + user can modify the Library and then relink to produce a modified 362.298 + executable containing the modified Library. (It is understood 362.299 + that the user who changes the contents of definitions files in the 362.300 + Library will not necessarily be able to recompile the application 362.301 + to use the modified definitions.) 362.302 + 362.303 + b) Use a suitable shared library mechanism for linking with the 362.304 + Library. A suitable mechanism is one that (1) uses at run time a 362.305 + copy of the library already present on the user's computer system, 362.306 + rather than copying library functions into the executable, and (2) 362.307 + will operate properly with a modified version of the library, if 362.308 + the user installs one, as long as the modified version is 362.309 + interface-compatible with the version that the work was made with. 362.310 + 362.311 + c) Accompany the work with a written offer, valid for at least 362.312 + three years, to give the same user the materials specified in 362.313 + Subsection 6a, above, for a charge no more than the cost of 362.314 + performing this distribution. 362.315 + 362.316 + d) If distribution of the work is made by offering access to copy 362.317 + from a designated place, offer equivalent access to copy the above 362.318 + specified materials from the same place. 362.319 + 362.320 + e) Verify that the user has already received a copy of these 362.321 + materials or that you have already sent this user a copy. 362.322 + 362.323 + For an executable, the required form of the "work that uses the 362.324 +Library" must include any data and utility programs needed for 362.325 +reproducing the executable from it. However, as a special exception, 362.326 +the materials to be distributed need not include anything that is 362.327 +normally distributed (in either source or binary form) with the major 362.328 +components (compiler, kernel, and so on) of the operating system on 362.329 +which the executable runs, unless that component itself accompanies 362.330 +the executable. 362.331 + 362.332 + It may happen that this requirement contradicts the license 362.333 +restrictions of other proprietary libraries that do not normally 362.334 +accompany the operating system. Such a contradiction means you cannot 362.335 +use both them and the Library together in an executable that you 362.336 +distribute. 362.337 + 362.338 + 7. You may place library facilities that are a work based on the 362.339 +Library side-by-side in a single library together with other library 362.340 +facilities not covered by this License, and distribute such a combined 362.341 +library, provided that the separate distribution of the work based on 362.342 +the Library and of the other library facilities is otherwise 362.343 +permitted, and provided that you do these two things: 362.344 + 362.345 + a) Accompany the combined library with a copy of the same work 362.346 + based on the Library, uncombined with any other library 362.347 + facilities. This must be distributed under the terms of the 362.348 + Sections above. 362.349 + 362.350 + b) Give prominent notice with the combined library of the fact 362.351 + that part of it is a work based on the Library, and explaining 362.352 + where to find the accompanying uncombined form of the same work. 362.353 + 362.354 + 8. You may not copy, modify, sublicense, link with, or distribute 362.355 +the Library except as expressly provided under this License. Any 362.356 +attempt otherwise to copy, modify, sublicense, link with, or 362.357 +distribute the Library is void, and will automatically terminate your 362.358 +rights under this License. However, parties who have received copies, 362.359 +or rights, from you under this License will not have their licenses 362.360 +terminated so long as such parties remain in full compliance. 362.361 + 362.362 + 9. You are not required to accept this License, since you have not 362.363 +signed it. However, nothing else grants you permission to modify or 362.364 +distribute the Library or its derivative works. These actions are 362.365 +prohibited by law if you do not accept this License. Therefore, by 362.366 +modifying or distributing the Library (or any work based on the 362.367 +Library), you indicate your acceptance of this License to do so, and 362.368 +all its terms and conditions for copying, distributing or modifying 362.369 +the Library or works based on it. 362.370 + 362.371 + 10. Each time you redistribute the Library (or any work based on the 362.372 +Library), the recipient automatically receives a license from the 362.373 +original licensor to copy, distribute, link with or modify the Library 362.374 +subject to these terms and conditions. You may not impose any further 362.375 +restrictions on the recipients' exercise of the rights granted herein. 362.376 +You are not responsible for enforcing compliance by third parties with 362.377 +this License. 362.378 + 362.379 + 11. If, as a consequence of a court judgment or allegation of patent 362.380 +infringement or for any other reason (not limited to patent issues), 362.381 +conditions are imposed on you (whether by court order, agreement or 362.382 +otherwise) that contradict the conditions of this License, they do not 362.383 +excuse you from the conditions of this License. If you cannot 362.384 +distribute so as to satisfy simultaneously your obligations under this 362.385 +License and any other pertinent obligations, then as a consequence you 362.386 +may not distribute the Library at all. For example, if a patent 362.387 +license would not permit royalty-free redistribution of the Library by 362.388 +all those who receive copies directly or indirectly through you, then 362.389 +the only way you could satisfy both it and this License would be to 362.390 +refrain entirely from distribution of the Library. 362.391 + 362.392 +If any portion of this section is held invalid or unenforceable under 362.393 +any particular circumstance, the balance of the section is intended to 362.394 +apply, and the section as a whole is intended to apply in other 362.395 +circumstances. 362.396 + 362.397 +It is not the purpose of this section to induce you to infringe any 362.398 +patents or other property right claims or to contest validity of any 362.399 +such claims; this section has the sole purpose of protecting the 362.400 +integrity of the free software distribution system which is 362.401 +implemented by public license practices. Many people have made 362.402 +generous contributions to the wide range of software distributed 362.403 +through that system in reliance on consistent application of that 362.404 +system; it is up to the author/donor to decide if he or she is willing 362.405 +to distribute software through any other system and a licensee cannot 362.406 +impose that choice. 362.407 + 362.408 +This section is intended to make thoroughly clear what is believed to 362.409 +be a consequence of the rest of this License. 362.410 + 362.411 + 12. If the distribution and/or use of the Library is restricted in 362.412 +certain countries either by patents or by copyrighted interfaces, the 362.413 +original copyright holder who places the Library under this License 362.414 +may add an explicit geographical distribution limitation excluding those 362.415 +countries, so that distribution is permitted only in or among 362.416 +countries not thus excluded. In such case, this License incorporates 362.417 +the limitation as if written in the body of this License. 362.418 + 362.419 + 13. The Free Software Foundation may publish revised and/or new 362.420 +versions of the Lesser General Public License from time to time. 362.421 +Such new versions will be similar in spirit to the present version, 362.422 +but may differ in detail to address new problems or concerns. 362.423 + 362.424 +Each version is given a distinguishing version number. If the Library 362.425 +specifies a version number of this License which applies to it and 362.426 +"any later version", you have the option of following the terms and 362.427 +conditions either of that version or of any later version published by 362.428 +the Free Software Foundation. If the Library does not specify a 362.429 +license version number, you may choose any version ever published by 362.430 +the Free Software Foundation. 362.431 + 362.432 + 14. If you wish to incorporate parts of the Library into other free 362.433 +programs whose distribution conditions are incompatible with these, 362.434 +write to the author to ask for permission. For software which is 362.435 +copyrighted by the Free Software Foundation, write to the Free 362.436 +Software Foundation; we sometimes make exceptions for this. Our 362.437 +decision will be guided by the two goals of preserving the free status 362.438 +of all derivatives of our free software and of promoting the sharing 362.439 +and reuse of software generally. 362.440 + 362.441 + NO WARRANTY 362.442 + 362.443 + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 362.444 +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 362.445 +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 362.446 +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 362.447 +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 362.448 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 362.449 +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 362.450 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 362.451 +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 362.452 + 362.453 + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 362.454 +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 362.455 +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 362.456 +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 362.457 +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 362.458 +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 362.459 +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 362.460 +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 362.461 +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 362.462 +DAMAGES. 362.463 + 362.464 + END OF TERMS AND CONDITIONS 362.465 + 362.466 + How to Apply These Terms to Your New Libraries 362.467 + 362.468 + If you develop a new library, and you want it to be of the greatest 362.469 +possible use to the public, we recommend making it free software that 362.470 +everyone can redistribute and change. You can do so by permitting 362.471 +redistribution under these terms (or, alternatively, under the terms 362.472 +of the ordinary General Public License). 362.473 + 362.474 + To apply these terms, attach the following notices to the library. 362.475 +It is safest to attach them to the start of each source file to most 362.476 +effectively convey the exclusion of warranty; and each file should 362.477 +have at least the "copyright" line and a pointer to where the full 362.478 +notice is found. 362.479 + 362.480 + 362.481 + <one line to give the library's name and a brief idea of what it does.> 362.482 + Copyright (C) <year> <name of author> 362.483 + 362.484 + This library is free software; you can redistribute it and/or 362.485 + modify it under the terms of the GNU Lesser General Public 362.486 + License as published by the Free Software Foundation; either 362.487 + version 2.1 of the License, or (at your option) any later version. 362.488 + 362.489 + This library is distributed in the hope that it will be useful, 362.490 + but WITHOUT ANY WARRANTY; without even the implied warranty of 362.491 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 362.492 + Lesser General Public License for more details. 362.493 + 362.494 + You should have received a copy of the GNU Lesser General Public 362.495 + License along with this library; if not, write to the Free Software 362.496 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 362.497 + 362.498 +Also add information on how to contact you by electronic and paper mail. 362.499 + 362.500 +You should also get your employer (if you work as a programmer) or 362.501 +your school, if any, to sign a "copyright disclaimer" for the library, 362.502 +if necessary. Here is a sample; alter the names: 362.503 + 362.504 + Yoyodyne, Inc., hereby disclaims all copyright interest in the 362.505 + library `Frob' (a library for tweaking knobs) written by James 362.506 + Random Hacker. 362.507 + 362.508 + <signature of Ty Coon>, 1 April 1990 362.509 + Ty Coon, President of Vice 362.510 + 362.511 +That's all there is to it! 362.512 + 362.513 +
363.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 363.2 +++ b/tools/xenstat/libxenstat/Makefile Tue Aug 23 12:03:21 2005 -0700 363.3 @@ -0,0 +1,142 @@ 363.4 +# libxenstat: statistics-collection library for Xen 363.5 +# Copyright (C) International Business Machines Corp., 2005 363.6 +# Author: Josh Triplett <josht@us.ibm.com> 363.7 +# 363.8 +# This library is free software; you can redistribute it and/or 363.9 +# modify it under the terms of the GNU Lesser General Public 363.10 +# License as published by the Free Software Foundation; either 363.11 +# version 2.1 of the License, or (at your option) any later version. 363.12 +# 363.13 +# This library is distributed in the hope that it will be useful, 363.14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 363.15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 363.16 +# Lesser General Public License for more details. 363.17 + 363.18 +XEN_ROOT=../../.. 363.19 +include $(XEN_ROOT)/tools/Rules.mk 363.20 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 363.21 + 363.22 +INSTALL = install 363.23 +INSTALL_PROG = $(INSTALL) -m0755 -D 363.24 +INSTALL_DATA = $(INSTALL) -m0644 -D 363.25 + 363.26 +prefix=/usr 363.27 +includedir=$(prefix)/include 363.28 +libdir=$(prefix)/lib 363.29 + 363.30 +LDCONFIG=ldconfig 363.31 +MAKE_LINK=ln -sf 363.32 + 363.33 +MAJOR=0 363.34 +MINOR=0 363.35 + 363.36 +LIB=src/libxenstat.a 363.37 +SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR) 363.38 +SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so 363.39 +OBJECTS=src/xenstat.o src/xen-interface.o 363.40 +SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR) 363.41 + 363.42 +WARN_FLAGS=-Wall -Werror 363.43 + 363.44 +CFLAGS+=-Isrc 363.45 +CFLAGS+=-I$(XEN_ROOT)/xen/include/public 363.46 +CFLAGS+=-I$(LINUX_ROOT)/include/asm-xen/linux-public/ 363.47 +LDFLAGS+=-Lsrc 363.48 + 363.49 +all: $(LIB) 363.50 + 363.51 +$(LIB): $(OBJECTS) 363.52 + $(AR) rc $@ $^ 363.53 + $(RANLIB) $@ 363.54 + 363.55 +$(SHLIB): $(OBJECTS) 363.56 + $(CC) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) 363.57 + 363.58 +src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h 363.59 + $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< 363.60 + 363.61 +src/xen-interface.o: src/xen-interface.c src/xen-interface.h 363.62 + $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $< 363.63 + 363.64 +src/libxenstat.so.$(MAJOR): $(LIB) 363.65 + $(MAKE_LINK) $(<F) $@ 363.66 + 363.67 +src/libxenstat.so: src/libxenstat.so.$(MAJOR) 363.68 + $(MAKE_LINK) $(<F) $@ 363.69 + 363.70 +install: all 363.71 +#install: all 363.72 +# $(INSTALL_DATA) src/xenstat.h $(DESTDIR)$(includedir)/xenstat.h 363.73 +# $(INSTALL_PROG) $(LIB) $(DESTDIR)$(libdir)/libxenstat.a 363.74 +# $(INSTALL_PROG) $(SHLIB) \ 363.75 +# $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR).$(MINOR) 363.76 +# $(MAKE_LINK) libxenstat.so.$(MAJOR).$(MINOR) \ 363.77 +# $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR) 363.78 +# $(MAKE_LINK) libxenstat.so.$(MAJOR) \ 363.79 +# $(DESTDIR)$(libdir)/libxenstat.so 363.80 +# -$(LDCONFIG) 363.81 + 363.82 +PYLIB=bindings/swig/python/_xenstat.so 363.83 +PYMOD=bindings/swig/python/xenstat.py 363.84 +PYSRC=bindings/swig/python/_xenstat.c 363.85 +PERLLIB=bindings/swig/perl/xenstat.so 363.86 +PERLMOD=bindings/swig/perl/xenstat.pm 363.87 +PERLSRC=bindings/swig/perl/xenstat.c 363.88 +BINDINGS=$(PYLIB) $(PYMOD) $(PERLLIB) $(PERLMOD) 363.89 +BINDINGSRC=$(PYSRC) $(PERLSRC) 363.90 + 363.91 +# The all-bindings target builds all the language bindings 363.92 +all-bindings: perl-bindings python-bindings 363.93 + 363.94 +# The install-bindings target installs all the language bindings 363.95 +install-bindings: install-perl-bindings install-python-bindings 363.96 + 363.97 +$(BINDINGS): $(SHLIB) $(SHLIB_LINKS) src/xenstat.h 363.98 + 363.99 +SWIG_FLAGS=-module xenstat -Isrc 363.100 + 363.101 +# Python bindings 363.102 +PYTHON_VERSION=2.3 363.103 +PYTHON_FLAGS=-I/usr/include/python$(PYTHON_VERSION) -lpython$(PYTHON_VERSION) 363.104 +$(PYSRC) $(PYMOD): bindings/swig/xenstat.i 363.105 + swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $< 363.106 + 363.107 +$(PYLIB): $(PYSRC) 363.108 + $(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) -shared -lxenstat -o $@ $< 363.109 + 363.110 +python-bindings: $(PYLIB) $(PYMOD) 363.111 + 363.112 +pythonlibdir=$(prefix)/lib/python$(PYTHON_VERSION)/site-packages 363.113 +install-python-bindings: $(PYLIB) $(PYMOD) 363.114 + $(INSTALL_PROG) $(PYLIB) $(DESTDIR)$(pythonlibdir)/_xenstat.so 363.115 + $(INSTALL_PROG) $(PYMOD) $(DESTDIR)$(pythonlibdir)/xenstat.py 363.116 + 363.117 +ifeq ($(XENSTAT_PYTHON_BINDINGS),y) 363.118 +all: python-bindings 363.119 +install: install-python-bindings 363.120 +endif 363.121 + 363.122 +# Perl bindings 363.123 +PERL_FLAGS=`perl -MConfig -e 'print "$$Config{ccflags} -I$$Config{archlib}/CORE";'` 363.124 +$(PERLSRC) $(PERLMOD): bindings/swig/xenstat.i 363.125 + swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $< 363.126 + 363.127 +$(PERLLIB): $(PERLSRC) 363.128 + $(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) -shared -lxenstat -o $@ $< 363.129 + 363.130 +perl-bindings: $(PERLLIB) $(PERLMOD) 363.131 + 363.132 +perllibdir=$(prefix)/lib/perl5 363.133 +perlmoddir=$(prefix)/share/perl5 363.134 +install-perl-bindings: $(PERLLIB) $(PERLMOD) 363.135 + $(INSTALL_PROG) $(PERLLIB) $(DESTDIR)$(perllibdir)/xenstat.so 363.136 + $(INSTALL_PROG) $(PERLMOD) $(DESTDIR)$(perlmoddir)/xenstat.pm 363.137 + 363.138 +ifeq ($(XENSTAT_PERL_BINDINGS),y) 363.139 +all: perl-bindings 363.140 +install: install-perl-bindings 363.141 +endif 363.142 + 363.143 +clean: 363.144 + rm -f $(LIB) $(SHLIB) $(SHLIB_LINKS) $(OBJECTS) \ 363.145 + $(BINDINGS) $(BINDINGSRC)
364.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 364.2 +++ b/tools/xenstat/libxenstat/bindings/swig/perl/.empty Tue Aug 23 12:03:21 2005 -0700 364.3 @@ -0,0 +1,1 @@ 364.4 +This directory is empty; this file is included to prevent version control systems from removing the directory.
365.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 365.2 +++ b/tools/xenstat/libxenstat/bindings/swig/python/.empty Tue Aug 23 12:03:21 2005 -0700 365.3 @@ -0,0 +1,1 @@ 365.4 +This directory is empty; this file is included to prevent version control systems from removing the directory.
366.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 366.2 +++ b/tools/xenstat/libxenstat/bindings/swig/xenstat.i Tue Aug 23 12:03:21 2005 -0700 366.3 @@ -0,0 +1,8 @@ 366.4 +%module xenstat_swig 366.5 +%{ 366.6 +/* Includes the header in the wrapper code */ 366.7 +#include "xenstat.h" 366.8 +%} 366.9 + 366.10 +/* Parse the header file to generate wrappers */ 366.11 +%include "xenstat.h"
367.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 367.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.c Tue Aug 23 12:03:21 2005 -0700 367.3 @@ -0,0 +1,204 @@ 367.4 +/* xen-interface.c 367.5 + * 367.6 + * Copyright (C) International Business Machines Corp., 2005 367.7 + * Authors: Josh Triplett <josht@us.ibm.com> 367.8 + * Judy Fischbach <jfisch@us.ibm.com> 367.9 + * 367.10 + * This library is free software; you can redistribute it and/or 367.11 + * modify it under the terms of the GNU Lesser General Public 367.12 + * License as published by the Free Software Foundation; either 367.13 + * version 2.1 of the License, or (at your option) any later version. 367.14 + * 367.15 + * This library is distributed in the hope that it will be useful, 367.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 367.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 367.18 + * Lesser General Public License for more details. 367.19 + */ 367.20 + 367.21 +#include "xen-interface.h" 367.22 +#include <fcntl.h> 367.23 +#include <sys/ioctl.h> 367.24 +#include <sys/mman.h> 367.25 +#include <stdio.h> 367.26 +#include <stdlib.h> 367.27 +#include <string.h> 367.28 +#include <unistd.h> 367.29 +#include "version.h" 367.30 +#include "privcmd.h" 367.31 +#include "xen.h" 367.32 + 367.33 +struct xi_handle { 367.34 + int fd; 367.35 +}; 367.36 + 367.37 +/* Initialize for xen-interface. Returns a handle to be used with subsequent 367.38 + * calls to the xen-interface functions or NULL if an error occurs. */ 367.39 +xi_handle *xi_init() 367.40 +{ 367.41 + xi_handle *handle; 367.42 + 367.43 + handle = (xi_handle *)calloc(1, sizeof(xi_handle)); 367.44 + if (handle == NULL) 367.45 + return NULL; 367.46 + 367.47 + handle->fd = open("/proc/xen/privcmd", O_RDWR); 367.48 + if (handle->fd < 0) { 367.49 + perror("Couldn't open /proc/xen/privcmd"); 367.50 + free(handle); 367.51 + return NULL; 367.52 + } 367.53 + 367.54 + return handle; 367.55 +} 367.56 + 367.57 +/* Release the handle to libxc, free resources, etc. */ 367.58 +void xi_uninit(xi_handle *handle) 367.59 +{ 367.60 + close (handle->fd); 367.61 + free (handle); 367.62 +} 367.63 + 367.64 +/* Make simple xen version hypervisor calls */ 367.65 +static int xi_make_xen_version_hypercall(xi_handle *handle, long *vnum, xen_extraversion_t *ver) 367.66 +{ 367.67 + privcmd_hypercall_t privcmd; 367.68 + multicall_entry_t multicall[2]; 367.69 + int ret = 0; 367.70 + 367.71 + /* set up for doing hypercall */ 367.72 + privcmd.op = __HYPERVISOR_multicall; 367.73 + privcmd.arg[0] = (unsigned long)multicall; 367.74 + privcmd.arg[1] = 2; 367.75 + 367.76 + /* first one to get xen version number */ 367.77 + multicall[0].op = __HYPERVISOR_xen_version; 367.78 + multicall[0].args[0] = (unsigned long)XENVER_version; 367.79 + 367.80 + /* second to get xen version flag */ 367.81 + multicall[1].op = __HYPERVISOR_xen_version; 367.82 + multicall[1].args[0] = (unsigned long)XENVER_extraversion; 367.83 + multicall[1].args[1] = (unsigned long)ver; 367.84 + 367.85 + if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { 367.86 + perror("Failed to mlock privcmd structure"); 367.87 + return -1; 367.88 + } 367.89 + 367.90 + if (mlock( multicall, sizeof(multicall_entry_t)) < 0) { 367.91 + perror("Failed to mlock multicall_entry structure"); 367.92 + munlock( &multicall, sizeof(multicall_entry_t)); 367.93 + return -1; 367.94 + } 367.95 + 367.96 + if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { 367.97 + perror("Hypercall failed"); 367.98 + ret = -1; 367.99 + } 367.100 + 367.101 + *vnum = multicall[0].result; 367.102 + 367.103 + munlock( &privcmd, sizeof(privcmd_hypercall_t)); 367.104 + munlock( &multicall, sizeof(multicall_entry_t)); 367.105 + 367.106 + return ret; 367.107 +} 367.108 + 367.109 +/* Make Xen Dom0 op hypervisor call */ 367.110 +static int xi_make_dom0_op(xi_handle *handle, dom0_op_t *dom_op, int dom_opcode) 367.111 +{ 367.112 + privcmd_hypercall_t privcmd; 367.113 + int ret = 0; 367.114 + 367.115 + /* set up for doing hypercall */ 367.116 + privcmd.op = __HYPERVISOR_dom0_op; 367.117 + privcmd.arg[0] = (unsigned long)dom_op; 367.118 + dom_op->cmd = dom_opcode; 367.119 + dom_op->interface_version = DOM0_INTERFACE_VERSION; 367.120 + 367.121 + if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) { 367.122 + perror("Failed to mlock privcmd structure"); 367.123 + return -1; 367.124 + } 367.125 + 367.126 + if (mlock( dom_op, sizeof(dom0_op_t)) < 0) { 367.127 + perror("Failed to mlock dom0_op structure"); 367.128 + munlock( &privcmd, sizeof(privcmd_hypercall_t)); 367.129 + return -1; 367.130 + } 367.131 + 367.132 + if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) { 367.133 + perror("Hypercall failed"); 367.134 + ret = -1; 367.135 + } 367.136 + 367.137 + munlock( &privcmd, sizeof(privcmd_hypercall_t)); 367.138 + munlock( dom_op, sizeof(dom0_op_t)); 367.139 + 367.140 + return ret; 367.141 +} 367.142 + 367.143 +/* Obtain domain data from dom0 */ 367.144 +int xi_get_physinfo(xi_handle *handle, dom0_physinfo_t *physinfo) 367.145 +{ 367.146 + dom0_op_t op; 367.147 + 367.148 + if (xi_make_dom0_op(handle, &op, DOM0_PHYSINFO) < 0) { 367.149 + perror("DOM0_PHYSINFO Hypercall failed"); 367.150 + return -1; 367.151 + } 367.152 + 367.153 + *physinfo = op.u.physinfo; 367.154 + return 0; 367.155 +} 367.156 + 367.157 +/* Obtain domain data from dom0 */ 367.158 +int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info, 367.159 + unsigned int first_domain, unsigned int max_domains) 367.160 +{ 367.161 + dom0_op_t op; 367.162 + op.u.getdomaininfolist.first_domain = first_domain; 367.163 + op.u.getdomaininfolist.max_domains = max_domains; 367.164 + op.u.getdomaininfolist.buffer = info; 367.165 + 367.166 + if (mlock( info, max_domains * sizeof(dom0_getdomaininfo_t)) < 0) { 367.167 + perror("Failed to mlock domaininfo array"); 367.168 + return -1; 367.169 + } 367.170 + 367.171 + if (xi_make_dom0_op(handle, &op, DOM0_GETDOMAININFOLIST) < 0) { 367.172 + perror("DOM0_GETDOMAININFOLIST Hypercall failed"); 367.173 + return -1; 367.174 + } 367.175 + 367.176 + return op.u.getdomaininfolist.num_domains; 367.177 +} 367.178 + 367.179 +/* Returns cpu usage data from dom0 */ 367.180 +long long xi_get_vcpu_usage(xi_handle *handle, unsigned int domain, 367.181 + unsigned int vcpu) 367.182 +{ 367.183 + dom0_op_t op; 367.184 + op.u.getvcpucontext.domain = domain; 367.185 + op.u.getvcpucontext.vcpu = vcpu; 367.186 + op.u.getvcpucontext.ctxt = NULL; 367.187 + 367.188 + if (xi_make_dom0_op(handle, &op, DOM0_GETVCPUCONTEXT) < 0) { 367.189 + perror("DOM0_GETVCPUCONTEXT Hypercall failed"); 367.190 + return -1; 367.191 + } 367.192 + 367.193 + return op.u.getvcpucontext.cpu_time; 367.194 +} 367.195 + 367.196 +/* gets xen version information from hypervisor */ 367.197 +int xi_get_xen_version(xi_handle *handle, long *vnum, xen_extraversion_t *ver) 367.198 +{ 367.199 + 367.200 + /* gets the XENVER_version and XENVER_extraversion */ 367.201 + if (xi_make_xen_version_hypercall( handle, vnum, ver) < 0) {; 367.202 + perror("XEN VERSION Hypercall failed"); 367.203 + return -1; 367.204 + } 367.205 + 367.206 + return 0; 367.207 +}
368.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 368.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.h Tue Aug 23 12:03:21 2005 -0700 368.3 @@ -0,0 +1,53 @@ 368.4 +/* xen-interface.h 368.5 + * 368.6 + * Copyright (C) International Business Machines Corp., 2005 368.7 + * Authors: Josh Triplett <josht@us.ibm.com> 368.8 + * Judy Fischbach <jfisch@us.ibm.com> 368.9 + * 368.10 + * This library is free software; you can redistribute it and/or 368.11 + * modify it under the terms of the GNU Lesser General Public 368.12 + * License as published by the Free Software Foundation; either 368.13 + * version 2.1 of the License, or (at your option) any later version. 368.14 + * 368.15 + * This library is distributed in the hope that it will be useful, 368.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 368.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 368.18 + * Lesser General Public License for more details. 368.19 + */ 368.20 + 368.21 +#include <stdint.h> 368.22 + 368.23 +typedef int8_t s8; 368.24 +typedef int16_t s16; 368.25 +typedef int32_t s32; 368.26 +typedef int64_t s64; 368.27 +typedef uint8_t u8; 368.28 +typedef uint16_t u16; 368.29 +typedef uint32_t u32; 368.30 +typedef uint64_t u64; 368.31 + 368.32 +#include "dom0_ops.h" 368.33 +#include "version.h" 368.34 + 368.35 +/* Opaque handles */ 368.36 +typedef struct xi_handle xi_handle; 368.37 + 368.38 +/* Initialize for xen-interface. Returns a handle to be used with subsequent 368.39 + * calls to the xen-interface functions or NULL if an error occurs. */ 368.40 +xi_handle *xi_init(); 368.41 + 368.42 +/* Release the handle to libxc, free resources, etc. */ 368.43 +void xi_uninit(xi_handle *handle); 368.44 + 368.45 +/* Obtain xen version information from hypervisor */ 368.46 +int xi_get_xen_version(xi_handle *, long *vnum, xen_extraversion_t *ver); 368.47 + 368.48 +/* Obtain physinfo data from dom0 */ 368.49 +int xi_get_physinfo(xi_handle *, dom0_physinfo_t *); 368.50 + 368.51 +/* Obtain domain data from dom0 */ 368.52 +int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int, 368.53 + unsigned int); 368.54 + 368.55 +/* Returns cpu usage data from dom0 */ 368.56 +long long xi_get_vcpu_usage(xi_handle *, unsigned int, unsigned int);
369.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 369.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c Tue Aug 23 12:03:21 2005 -0700 369.3 @@ -0,0 +1,640 @@ 369.4 +/* libxenstat: statistics-collection library for Xen 369.5 + * Copyright (C) International Business Machines Corp., 2005 369.6 + * Authors: Josh Triplett <josht@us.ibm.com> 369.7 + * Judy Fischbach <jfisch@us.ibm.com> 369.8 + * David Hendricks <dhendrix@us.ibm.com> 369.9 + * 369.10 + * This library is free software; you can redistribute it and/or 369.11 + * modify it under the terms of the GNU Lesser General Public 369.12 + * License as published by the Free Software Foundation; either 369.13 + * version 2.1 of the License, or (at your option) any later version. 369.14 + * 369.15 + * This library is distributed in the hope that it will be useful, 369.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 369.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 369.18 + * Lesser General Public License for more details. 369.19 + */ 369.20 + 369.21 +#include <limits.h> 369.22 +#include <stdlib.h> 369.23 +#include <stdio.h> 369.24 +#include <string.h> 369.25 +#include <unistd.h> 369.26 +#include <xen-interface.h> 369.27 +#include "xenstat.h" 369.28 +#include "version.h" 369.29 + 369.30 +/* 369.31 + * Types 369.32 + */ 369.33 +struct xenstat_handle { 369.34 + xi_handle *xihandle; 369.35 + int page_size; 369.36 + FILE *procnetdev; 369.37 +}; 369.38 + 369.39 +#define SHORT_ASC_LEN 5 /* length of 65535 */ 369.40 +#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1) 369.41 + 369.42 +struct xenstat_node { 369.43 + unsigned int flags; 369.44 + unsigned long long cpu_hz; 369.45 + unsigned int num_cpus; 369.46 + unsigned long long tot_mem; 369.47 + unsigned long long free_mem; 369.48 + unsigned int num_domains; 369.49 + char xen_version[VERSION_SIZE]; /* xen version running on this node */ 369.50 + xenstat_domain *domains; /* Array of length num_domains */ 369.51 +}; 369.52 + 369.53 +struct xenstat_domain { 369.54 + unsigned int id; 369.55 + unsigned int state; 369.56 + unsigned long long cpu_ns; 369.57 + unsigned int num_vcpus; 369.58 + xenstat_vcpu *vcpus; /* Array of length num_vcpus */ 369.59 + unsigned long long cur_mem; /* Current memory reservation */ 369.60 + unsigned long long max_mem; /* Total memory allowed */ 369.61 + unsigned int ssid; 369.62 + unsigned int num_networks; 369.63 + xenstat_network *networks; /* Array of length num_networks */ 369.64 +}; 369.65 + 369.66 +struct xenstat_vcpu { 369.67 + unsigned long long ns; 369.68 +}; 369.69 + 369.70 +struct xenstat_network { 369.71 + unsigned int id; 369.72 + /* Received */ 369.73 + unsigned long long rbytes; 369.74 + unsigned long long rpackets; 369.75 + unsigned long long rerrs; 369.76 + unsigned long long rdrop; 369.77 + /* Transmitted */ 369.78 + unsigned long long tbytes; 369.79 + unsigned long long tpackets; 369.80 + unsigned long long terrs; 369.81 + unsigned long long tdrop; 369.82 +}; 369.83 + 369.84 +/* 369.85 + * Data-collection types 369.86 + */ 369.87 +/* Called to collect the information for the node and all the domains on 369.88 + * it. When called, the domain information has already been collected. */ 369.89 +typedef int (*xenstat_collect_func)(xenstat_handle * handle, 369.90 + xenstat_node * node); 369.91 +/* Called to free the information collected by the collect function. The free 369.92 + * function will only be called on a xenstat_node if that node includes 369.93 + * information collected by the corresponding collector. */ 369.94 +typedef void (*xenstat_free_func)(xenstat_node * node); 369.95 +/* Called to free any information stored in the handle. Note the lack of a 369.96 + * matching init function; the collect functions should initialize on first 369.97 + * use. Also, the uninit function must handle the case that the collector has 369.98 + * never been initialized. */ 369.99 +typedef void (*xenstat_uninit_func)(xenstat_handle * handle); 369.100 +typedef struct xenstat_collector { 369.101 + unsigned int flag; 369.102 + xenstat_collect_func collect; 369.103 + xenstat_free_func free; 369.104 + xenstat_uninit_func uninit; 369.105 +} xenstat_collector; 369.106 + 369.107 +static int xenstat_collect_vcpus(xenstat_handle * handle, 369.108 + xenstat_node * node); 369.109 +static int xenstat_collect_networks(xenstat_handle * handle, 369.110 + xenstat_node * node); 369.111 +static void xenstat_free_vcpus(xenstat_node * node); 369.112 +static void xenstat_free_networks(xenstat_node * node); 369.113 +static void xenstat_uninit_vcpus(xenstat_handle * handle); 369.114 +static void xenstat_uninit_networks(xenstat_handle * handle); 369.115 + 369.116 +static xenstat_collector collectors[] = { 369.117 + { XENSTAT_VCPU, xenstat_collect_vcpus, 369.118 + xenstat_free_vcpus, xenstat_uninit_vcpus }, 369.119 + { XENSTAT_NETWORK, xenstat_collect_networks, 369.120 + xenstat_free_networks, xenstat_uninit_networks } 369.121 +}; 369.122 + 369.123 +#define NUM_COLLECTORS (sizeof(collectors)/sizeof(xenstat_collector)) 369.124 + 369.125 +/* 369.126 + * libxenstat API 369.127 + */ 369.128 +xenstat_handle *xenstat_init() 369.129 +{ 369.130 + xenstat_handle *handle; 369.131 + 369.132 + handle = (xenstat_handle *) calloc(1, sizeof(xenstat_handle)); 369.133 + if (handle == NULL) 369.134 + return NULL; 369.135 + 369.136 +#if defined(PAGESIZE) 369.137 + handle->page_size = PAGESIZE; 369.138 +#elif defined(PAGE_SIZE) 369.139 + handle->page_size = PAGE_SIZE; 369.140 +#else 369.141 + handle->page_size = sysconf(_SC_PAGE_SIZE); 369.142 + if (handle->page_size < 0) { 369.143 + perror("Failed to retrieve page size."); 369.144 + free(handle); 369.145 + return NULL; 369.146 + } 369.147 +#endif 369.148 + 369.149 + handle->xihandle = xi_init(); 369.150 + if (handle->xihandle == NULL) { 369.151 + perror("xi_init"); 369.152 + free(handle); 369.153 + return NULL; 369.154 + } 369.155 + 369.156 + return handle; 369.157 +} 369.158 + 369.159 +void xenstat_uninit(xenstat_handle * handle) 369.160 +{ 369.161 + unsigned int i; 369.162 + if (handle) { 369.163 + for (i = 0; i < NUM_COLLECTORS; i++) 369.164 + collectors[i].uninit(handle); 369.165 + xi_uninit(handle->xihandle); 369.166 + free(handle); 369.167 + } 369.168 +} 369.169 + 369.170 +xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) 369.171 +{ 369.172 +#define DOMAIN_CHUNK_SIZE 256 369.173 + xenstat_node *node; 369.174 + dom0_physinfo_t physinfo; 369.175 + xen_extraversion_t version; 369.176 + long vnum = 0; 369.177 + dom0_getdomaininfo_t domaininfo[DOMAIN_CHUNK_SIZE]; 369.178 + unsigned int num_domains, new_domains; 369.179 + unsigned int i; 369.180 + 369.181 + /* Create the node */ 369.182 + node = (xenstat_node *) calloc(1, sizeof(xenstat_node)); 369.183 + if (node == NULL) 369.184 + return NULL; 369.185 + 369.186 + /* Get information about the physical system */ 369.187 + if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) { 369.188 + free(node); 369.189 + return NULL; 369.190 + } 369.191 + 369.192 + /* Get the xen version number and xen version tag */ 369.193 + if (xi_get_xen_version(handle->xihandle, &vnum, &version) < 0) { 369.194 + free(node); 369.195 + return NULL; 369.196 + } 369.197 + snprintf(node->xen_version, VERSION_SIZE, 369.198 + "%ld.%ld%s\n", ((vnum >> 16) & 0xFFFF), vnum & 0xFFFF, (char *)version); 369.199 + 369.200 + node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL; 369.201 + node->num_cpus = 369.202 + (physinfo.threads_per_core * physinfo.cores_per_socket * 369.203 + physinfo.sockets_per_node * physinfo.nr_nodes); 369.204 + node->tot_mem = ((unsigned long long)physinfo.total_pages) 369.205 + * handle->page_size; 369.206 + node->free_mem = ((unsigned long long)physinfo.free_pages) 369.207 + * handle->page_size; 369.208 + 369.209 + /* malloc(0) is not portable, so allocate a single domain. This will 369.210 + * be resized below. */ 369.211 + node->domains = malloc(sizeof(xenstat_domain)); 369.212 + if (node->domains == NULL) { 369.213 + free(node); 369.214 + return NULL; 369.215 + } 369.216 + 369.217 + num_domains = 0; 369.218 + do { 369.219 + xenstat_domain *domain; 369.220 + 369.221 + new_domains = xi_get_domaininfolist(handle->xihandle, 369.222 + domaininfo, num_domains, 369.223 + DOMAIN_CHUNK_SIZE); 369.224 + 369.225 + node->domains = realloc(node->domains, 369.226 + (num_domains + new_domains) 369.227 + * sizeof(xenstat_domain)); 369.228 + if (node->domains == NULL) { 369.229 + free(node); 369.230 + return NULL; 369.231 + } 369.232 + 369.233 + domain = node->domains + num_domains; 369.234 + 369.235 + for (i = 0; i < new_domains; i++) { 369.236 + /* Fill in domain using domaininfo[i] */ 369.237 + domain->id = domaininfo[i].domain; 369.238 + domain->state = domaininfo[i].flags; 369.239 + domain->cpu_ns = domaininfo[i].cpu_time; 369.240 + domain->num_vcpus = domaininfo[i].n_vcpu; 369.241 + domain->vcpus = NULL; 369.242 + domain->cur_mem = 369.243 + ((unsigned long long)domaininfo[i].tot_pages) 369.244 + * handle->page_size; 369.245 + domain->max_mem = 369.246 + domaininfo[i].max_pages == UINT_MAX 369.247 + ? (unsigned long long)-1 369.248 + : (unsigned long long)(domaininfo[i].max_pages 369.249 + * handle->page_size); 369.250 + domain->ssid = domaininfo[i].ssidref; 369.251 + domain->num_networks = 0; 369.252 + domain->networks = NULL; 369.253 + 369.254 + domain++; 369.255 + } 369.256 + num_domains += new_domains; 369.257 + } while (new_domains == DOMAIN_CHUNK_SIZE); 369.258 + node->num_domains = num_domains; 369.259 + 369.260 + /* Run all the extra data collectors requested */ 369.261 + node->flags = 0; 369.262 + for (i = 0; i < NUM_COLLECTORS; i++) { 369.263 + if ((flags & collectors[i].flag) == collectors[i].flag) { 369.264 + node->flags |= collectors[i].flag; 369.265 + if(collectors[i].collect(handle, node) == 0) { 369.266 + xenstat_free_node(node); 369.267 + return NULL; 369.268 + } 369.269 + } 369.270 + } 369.271 + 369.272 + return node; 369.273 +} 369.274 + 369.275 +void xenstat_free_node(xenstat_node * node) 369.276 +{ 369.277 + int i; 369.278 + 369.279 + if (node) { 369.280 + if (node->domains) { 369.281 + for (i = 0; i < NUM_COLLECTORS; i++) 369.282 + if((node->flags & collectors[i].flag) 369.283 + == collectors[i].flag) 369.284 + collectors[i].free(node); 369.285 + free(node->domains); 369.286 + } 369.287 + free(node); 369.288 + } 369.289 +} 369.290 + 369.291 +xenstat_domain *xenstat_node_domain(xenstat_node * node, unsigned int domid) 369.292 +{ 369.293 + unsigned int i; 369.294 + 369.295 + /* FIXME: binary search */ 369.296 + /* Find the appropriate domain entry in the node struct. */ 369.297 + for (i = 0; i < node->num_domains; i++) { 369.298 + if (node->domains[i].id == domid) 369.299 + return &(node->domains[i]); 369.300 + } 369.301 + return NULL; 369.302 +} 369.303 + 369.304 +xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node, 369.305 + unsigned int index) 369.306 +{ 369.307 + if (0 <= index && index < node->num_domains) 369.308 + return &(node->domains[index]); 369.309 + return NULL; 369.310 +} 369.311 + 369.312 +const char *xenstat_node_xen_ver(xenstat_node * node) 369.313 +{ 369.314 + return node->xen_version; 369.315 +} 369.316 + 369.317 +unsigned long long xenstat_node_tot_mem(xenstat_node * node) 369.318 +{ 369.319 + return node->tot_mem; 369.320 +} 369.321 + 369.322 +unsigned long long xenstat_node_free_mem(xenstat_node * node) 369.323 +{ 369.324 + return node->free_mem; 369.325 +} 369.326 + 369.327 +unsigned int xenstat_node_num_domains(xenstat_node * node) 369.328 +{ 369.329 + return node->num_domains; 369.330 +} 369.331 + 369.332 +unsigned int xenstat_node_num_cpus(xenstat_node * node) 369.333 +{ 369.334 + return node->num_cpus; 369.335 +} 369.336 + 369.337 +/* Get information about the CPU speed */ 369.338 +unsigned long long xenstat_node_cpu_hz(xenstat_node * node) 369.339 +{ 369.340 + return node->cpu_hz; 369.341 +} 369.342 + 369.343 +/* Get the domain ID for this domain */ 369.344 +unsigned xenstat_domain_id(xenstat_domain * domain) 369.345 +{ 369.346 + return domain->id; 369.347 +} 369.348 + 369.349 +/* Get information about how much CPU time has been used */ 369.350 +unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain) 369.351 +{ 369.352 + return domain->cpu_ns; 369.353 +} 369.354 + 369.355 +/* Find the number of VCPUs allocated to a domain */ 369.356 +unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain) 369.357 +{ 369.358 + return domain->num_vcpus; 369.359 +} 369.360 + 369.361 +xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain, unsigned int vcpu) 369.362 +{ 369.363 + if (0 <= vcpu && vcpu < domain->num_vcpus) 369.364 + return &(domain->vcpus[vcpu]); 369.365 + return NULL; 369.366 +} 369.367 + 369.368 +/* Find the current memory reservation for this domain */ 369.369 +unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain) 369.370 +{ 369.371 + return domain->cur_mem; 369.372 +} 369.373 + 369.374 +/* Find the maximum memory reservation for this domain */ 369.375 +unsigned long long xenstat_domain_max_mem(xenstat_domain * domain) 369.376 +{ 369.377 + return domain->max_mem; 369.378 +} 369.379 + 369.380 +/* Find the domain's SSID */ 369.381 +unsigned int xenstat_domain_ssid(xenstat_domain * domain) 369.382 +{ 369.383 + return domain->ssid; 369.384 +} 369.385 + 369.386 +/* Get domain states */ 369.387 +unsigned int xenstat_domain_dying(xenstat_domain * domain) 369.388 +{ 369.389 + return (domain->state & DOMFLAGS_DYING) == DOMFLAGS_DYING; 369.390 +} 369.391 + 369.392 +unsigned int xenstat_domain_crashed(xenstat_domain * domain) 369.393 +{ 369.394 + return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN) 369.395 + && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT) 369.396 + & DOMFLAGS_SHUTDOWNMASK) == SHUTDOWN_crash); 369.397 +} 369.398 + 369.399 +unsigned int xenstat_domain_shutdown(xenstat_domain * domain) 369.400 +{ 369.401 + return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN) 369.402 + && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT) 369.403 + & DOMFLAGS_SHUTDOWNMASK) != SHUTDOWN_crash); 369.404 +} 369.405 + 369.406 +unsigned int xenstat_domain_paused(xenstat_domain * domain) 369.407 +{ 369.408 + return (domain->state & DOMFLAGS_PAUSED) == DOMFLAGS_PAUSED; 369.409 +} 369.410 + 369.411 +unsigned int xenstat_domain_blocked(xenstat_domain * domain) 369.412 +{ 369.413 + return (domain->state & DOMFLAGS_BLOCKED) == DOMFLAGS_BLOCKED; 369.414 +} 369.415 + 369.416 +unsigned int xenstat_domain_running(xenstat_domain * domain) 369.417 +{ 369.418 + return (domain->state & DOMFLAGS_RUNNING) == DOMFLAGS_RUNNING; 369.419 +} 369.420 + 369.421 +/* Get the number of networks for a given domain */ 369.422 +unsigned int xenstat_domain_num_networks(xenstat_domain * domain) 369.423 +{ 369.424 + return domain->num_networks; 369.425 +} 369.426 + 369.427 +/* Get the network handle to obtain network stats */ 369.428 +xenstat_network *xenstat_domain_network(xenstat_domain * domain, 369.429 + unsigned int network) 369.430 +{ 369.431 + if (domain->networks && 0 <= network && network < domain->num_networks) 369.432 + return &(domain->networks[network]); 369.433 + return NULL; 369.434 +} 369.435 + 369.436 +/* 369.437 + * VCPU functions 369.438 + */ 369.439 +/* Collect information about VCPUs */ 369.440 +static int xenstat_collect_vcpus(xenstat_handle * handle, xenstat_node * node) 369.441 +{ 369.442 + unsigned int i, vcpu; 369.443 + /* Fill in VCPU information */ 369.444 + for (i = 0; i < node->num_domains; i++) { 369.445 + node->domains[i].vcpus = malloc(node->domains[i].num_vcpus 369.446 + * sizeof(xenstat_vcpu)); 369.447 + if (node->domains[i].vcpus == NULL) 369.448 + return 0; 369.449 + 369.450 + for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) { 369.451 + /* FIXME: need to be using a more efficient mechanism*/ 369.452 + long long vcpu_time; 369.453 + vcpu_time = 369.454 + xi_get_vcpu_usage(handle->xihandle, 369.455 + node->domains[i].id, 369.456 + vcpu); 369.457 + if (vcpu_time < 0) 369.458 + return 0; 369.459 + node->domains[i].vcpus[vcpu].ns = vcpu_time; 369.460 + } 369.461 + } 369.462 + return 1; 369.463 +} 369.464 + 369.465 +/* Free VCPU information */ 369.466 +static void xenstat_free_vcpus(xenstat_node * node) 369.467 +{ 369.468 + unsigned int i; 369.469 + for (i = 0; i < node->num_domains; i++) 369.470 + free(node->domains[i].vcpus); 369.471 +} 369.472 + 369.473 +/* Free VCPU information in handle - nothing to do */ 369.474 +static void xenstat_uninit_vcpus(xenstat_handle * handle) 369.475 +{ 369.476 +} 369.477 + 369.478 +/* Get VCPU usage */ 369.479 +unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu) 369.480 +{ 369.481 + return vcpu->ns; 369.482 +} 369.483 + 369.484 +/* 369.485 + * Network functions 369.486 + */ 369.487 + 369.488 +/* Expected format of /proc/net/dev */ 369.489 +static const char PROCNETDEV_HEADER[] = 369.490 + "Inter-| Receive |" 369.491 + " Transmit\n" 369.492 + " face |bytes packets errs drop fifo frame compressed multicast|" 369.493 + "bytes packets errs drop fifo colls carrier compressed\n"; 369.494 + 369.495 +/* Collect information about networks */ 369.496 +static int xenstat_collect_networks(xenstat_handle * handle, 369.497 + xenstat_node * node) 369.498 +{ 369.499 + /* Open and validate /proc/net/dev if we haven't already */ 369.500 + if (handle->procnetdev == NULL) { 369.501 + char header[sizeof(PROCNETDEV_HEADER)]; 369.502 + handle->procnetdev = fopen("/proc/net/dev", "r"); 369.503 + if (handle->procnetdev == NULL) { 369.504 + perror("Error opening /proc/net/dev"); 369.505 + return 1; 369.506 + } 369.507 + 369.508 + /* Validate the format of /proc/net/dev */ 369.509 + if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1, 369.510 + handle->procnetdev) != 1) { 369.511 + perror("Error reading /proc/net/dev header"); 369.512 + return 1; 369.513 + } 369.514 + header[sizeof(PROCNETDEV_HEADER) - 1] = '\0'; 369.515 + if (strcmp(header, PROCNETDEV_HEADER) != 0) { 369.516 + fprintf(stderr, 369.517 + "Unexpected /proc/net/dev format\n"); 369.518 + return 1; 369.519 + } 369.520 + } 369.521 + 369.522 + /* Fill in networks */ 369.523 + /* FIXME: optimize this */ 369.524 + fseek(handle->procnetdev, sizeof(PROCNETDEV_HEADER) - 1, SEEK_SET); 369.525 + while (1) { 369.526 + xenstat_domain *domain; 369.527 + xenstat_network net; 369.528 + unsigned int domid; 369.529 + int ret = fscanf(handle->procnetdev, 369.530 + "vif%u.%u:%llu%llu%llu%llu%*u%*u%*u%*u" 369.531 + "%llu%llu%llu%llu%*u%*u%*u%*u\n", 369.532 + &domid, &net.id, 369.533 + &net.tbytes, &net.tpackets, &net.terrs, 369.534 + &net.tdrop, 369.535 + &net.rbytes, &net.rpackets, &net.rerrs, 369.536 + &net.rdrop); 369.537 + if (ret == EOF) 369.538 + break; 369.539 + if (ret != 10) { 369.540 + unsigned int c; 369.541 + do { 369.542 + c = fgetc(handle->procnetdev); 369.543 + } while (c != '\n' && c != EOF); 369.544 + if (c == EOF) 369.545 + break; 369.546 + continue; 369.547 + } 369.548 + 369.549 + /* FIXME: this does a search for the domid */ 369.550 + domain = xenstat_node_domain(node, domid); 369.551 + if (domain == NULL) { 369.552 + fprintf(stderr, 369.553 + "Found interface vif%u.%u but domain %u" 369.554 + " does not exist.\n", domid, net.id, 369.555 + domid); 369.556 + continue; 369.557 + } 369.558 + if (domain->networks == NULL) { 369.559 + domain->num_networks = 1; 369.560 + domain->networks = malloc(sizeof(xenstat_network)); 369.561 + } else { 369.562 + domain->num_networks++; 369.563 + domain->networks = 369.564 + realloc(domain->networks, 369.565 + domain->num_networks * 369.566 + sizeof(xenstat_network)); 369.567 + } 369.568 + if (domain->networks == NULL) 369.569 + return 1; 369.570 + domain->networks[domain->num_networks - 1] = net; 369.571 + } 369.572 + 369.573 + return 1; 369.574 +} 369.575 + 369.576 +/* Free network information */ 369.577 +static void xenstat_free_networks(xenstat_node * node) 369.578 +{ 369.579 + unsigned int i; 369.580 + for (i = 0; i < node->num_domains; i++) 369.581 + free(node->domains[i].networks); 369.582 +} 369.583 + 369.584 +/* Free network information in handle */ 369.585 +static void xenstat_uninit_networks(xenstat_handle * handle) 369.586 +{ 369.587 + if(handle->procnetdev) 369.588 + fclose(handle->procnetdev); 369.589 +} 369.590 + 369.591 +/* Get the network ID */ 369.592 +unsigned int xenstat_network_id(xenstat_network * network) 369.593 +{ 369.594 + return network->id; 369.595 +} 369.596 + 369.597 +/* Get the number of receive bytes */ 369.598 +unsigned long long xenstat_network_rbytes(xenstat_network * network) 369.599 +{ 369.600 + return network->rbytes; 369.601 +} 369.602 + 369.603 +/* Get the number of receive packets */ 369.604 +unsigned long long xenstat_network_rpackets(xenstat_network * network) 369.605 +{ 369.606 + return network->rpackets; 369.607 +} 369.608 + 369.609 +/* Get the number of receive errors */ 369.610 +unsigned long long xenstat_network_rerrs(xenstat_network * network) 369.611 +{ 369.612 + return network->rerrs; 369.613 +} 369.614 + 369.615 +/* Get the number of receive drops */ 369.616 +unsigned long long xenstat_network_rdrop(xenstat_network * network) 369.617 +{ 369.618 + return network->rdrop; 369.619 +} 369.620 + 369.621 +/* Get the number of transmit bytes */ 369.622 +unsigned long long xenstat_network_tbytes(xenstat_network * network) 369.623 +{ 369.624 + return network->tbytes; 369.625 +} 369.626 + 369.627 +/* Get the number of transmit packets */ 369.628 +unsigned long long xenstat_network_tpackets(xenstat_network * network) 369.629 +{ 369.630 + return network->tpackets; 369.631 +} 369.632 + 369.633 +/* Get the number of transmit errors */ 369.634 +unsigned long long xenstat_network_terrs(xenstat_network * network) 369.635 +{ 369.636 + return network->terrs; 369.637 +} 369.638 + 369.639 +/* Get the number of transmit dropped packets */ 369.640 +unsigned long long xenstat_network_tdrop(xenstat_network * network) 369.641 +{ 369.642 + return network->tdrop; 369.643 +}
370.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 370.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h Tue Aug 23 12:03:21 2005 -0700 370.3 @@ -0,0 +1,150 @@ 370.4 +/* libxenstat: statistics-collection library for Xen 370.5 + * Copyright (C) International Business Machines Corp., 2005 370.6 + * Authors: Josh Triplett <josht@us.ibm.com> 370.7 + * Judy Fischbach <jfisch@us.ibm.com> 370.8 + * David Hendricks <dhendrix@us.ibm.com> 370.9 + * 370.10 + * This library is free software; you can redistribute it and/or 370.11 + * modify it under the terms of the GNU Lesser General Public 370.12 + * License as published by the Free Software Foundation; either 370.13 + * version 2.1 of the License, or (at your option) any later version. 370.14 + * 370.15 + * This library is distributed in the hope that it will be useful, 370.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 370.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 370.18 + * Lesser General Public License for more details. 370.19 + */ 370.20 + 370.21 +/* libxenstat API */ 370.22 + 370.23 +/* Opaque handles */ 370.24 +typedef struct xenstat_handle xenstat_handle; 370.25 +typedef struct xenstat_domain xenstat_domain; 370.26 +typedef struct xenstat_node xenstat_node; 370.27 +typedef struct xenstat_vcpu xenstat_vcpu; 370.28 +typedef struct xenstat_network xenstat_network; 370.29 + 370.30 +/* Initialize the xenstat library. Returns a handle to be used with 370.31 + * subsequent calls to the xenstat library, or NULL if an error occurs. */ 370.32 +xenstat_handle *xenstat_init(); 370.33 + 370.34 +/* Release the handle to libxc, free resources, etc. */ 370.35 +void xenstat_uninit(xenstat_handle * handle); 370.36 + 370.37 +/* Get all available information about a node */ 370.38 +#define XENSTAT_VCPU 0x1 370.39 +#define XENSTAT_NETWORK 0x2 370.40 +#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK) 370.41 +xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags); 370.42 + 370.43 +/* Free the information */ 370.44 +void xenstat_free_node(xenstat_node * node); 370.45 + 370.46 +/* 370.47 + * Node functions - extract information from a xenstat_node 370.48 + */ 370.49 + 370.50 +/* Get information about the domain with the given domain ID */ 370.51 +xenstat_domain *xenstat_node_domain(xenstat_node * node, 370.52 + unsigned int domid); 370.53 + 370.54 +/* Get the domain with the given index; used to loop over all domains. */ 370.55 +xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node, 370.56 + unsigned index); 370.57 +/* Get xen version of the node */ 370.58 +const char *xenstat_node_xen_ver(xenstat_node * node); 370.59 + 370.60 +/* Get amount of total memory on a node */ 370.61 +unsigned long long xenstat_node_tot_mem(xenstat_node * node); 370.62 + 370.63 +/* Get amount of free memory on a node */ 370.64 +unsigned long long xenstat_node_free_mem(xenstat_node * node); 370.65 + 370.66 +/* Find the number of domains existing on a node */ 370.67 +unsigned int xenstat_node_num_domains(xenstat_node * node); 370.68 + 370.69 +/* Find the number of CPUs existing on a node */ 370.70 +unsigned int xenstat_node_num_cpus(xenstat_node * node); 370.71 + 370.72 +/* Get information about the CPU speed */ 370.73 +unsigned long long xenstat_node_cpu_hz(xenstat_node * node); 370.74 + 370.75 +/* 370.76 + * Domain functions - extract information from a xenstat_domain 370.77 + */ 370.78 + 370.79 +/* Get the domain ID for this domain */ 370.80 +unsigned xenstat_domain_id(xenstat_domain * domain); 370.81 + 370.82 +/* Get information about how much CPU time has been used */ 370.83 +unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain); 370.84 + 370.85 +/* Find the number of VCPUs allocated to a domain */ 370.86 +unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain); 370.87 + 370.88 +/* Get the VCPU handle to obtain VCPU stats */ 370.89 +xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain, 370.90 + unsigned int vcpu); 370.91 + 370.92 +/* Find the current memory reservation for this domain */ 370.93 +unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain); 370.94 + 370.95 +/* Find the maximum memory reservation for this domain */ 370.96 +unsigned long long xenstat_domain_max_mem(xenstat_domain * domain); 370.97 + 370.98 +/* Find the domain's SSID */ 370.99 +unsigned int xenstat_domain_ssid(xenstat_domain * domain); 370.100 + 370.101 +/* Get domain states */ 370.102 +unsigned int xenstat_domain_dying(xenstat_domain * domain); 370.103 +unsigned int xenstat_domain_crashed(xenstat_domain * domain); 370.104 +unsigned int xenstat_domain_shutdown(xenstat_domain * domain); 370.105 +unsigned int xenstat_domain_paused(xenstat_domain * domain); 370.106 +unsigned int xenstat_domain_blocked(xenstat_domain * domain); 370.107 +unsigned int xenstat_domain_running(xenstat_domain * domain); 370.108 + 370.109 +/* Get the number of networks for a given domain */ 370.110 +unsigned int xenstat_domain_num_networks(xenstat_domain *); 370.111 + 370.112 +/* Get the network handle to obtain network stats */ 370.113 +xenstat_network *xenstat_domain_network(xenstat_domain * domain, 370.114 + unsigned int network); 370.115 + 370.116 +/* 370.117 + * VCPU functions - extract information from a xenstat_vcpu 370.118 + */ 370.119 + 370.120 +/* Get VCPU usage */ 370.121 +unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu); 370.122 + 370.123 + 370.124 +/* 370.125 + * Network functions - extract information from a xenstat_network 370.126 + */ 370.127 + 370.128 +/* Get the ID for this network */ 370.129 +unsigned int xenstat_network_id(xenstat_network * network); 370.130 + 370.131 +/* Get the number of receive bytes for this network */ 370.132 +unsigned long long xenstat_network_rbytes(xenstat_network * network); 370.133 + 370.134 +/* Get the number of receive packets for this network */ 370.135 +unsigned long long xenstat_network_rpackets(xenstat_network * network); 370.136 + 370.137 +/* Get the number of receive errors for this network */ 370.138 +unsigned long long xenstat_network_rerrs(xenstat_network * network); 370.139 + 370.140 +/* Get the number of receive drops for this network */ 370.141 +unsigned long long xenstat_network_rdrop(xenstat_network * network); 370.142 + 370.143 +/* Get the number of transmit bytes for this network */ 370.144 +unsigned long long xenstat_network_tbytes(xenstat_network * network); 370.145 + 370.146 +/* Get the number of transmit packets for this network */ 370.147 +unsigned long long xenstat_network_tpackets(xenstat_network * network); 370.148 + 370.149 +/* Get the number of transmit errors for this network */ 370.150 +unsigned long long xenstat_network_terrs(xenstat_network * network); 370.151 + 370.152 +/* Get the number of transmit drops for this network */ 370.153 +unsigned long long xenstat_network_tdrop(xenstat_network * network);
371.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 371.2 +++ b/tools/xenstat/xentop/Makefile Tue Aug 23 12:03:21 2005 -0700 371.3 @@ -0,0 +1,44 @@ 371.4 +# Copyright (C) International Business Machines Corp., 2005 371.5 +# Author: Josh Triplett <josht@us.ibm.com> 371.6 +# 371.7 +# This program is free software; you can redistribute it and/or modify 371.8 +# it under the terms of the GNU General Public License as published by 371.9 +# the Free Software Foundation; under version 2 of the License. 371.10 +# 371.11 +# This program is distributed in the hope that it will be useful, 371.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 371.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 371.14 +# GNU General Public License for more details. 371.15 + 371.16 +XEN_ROOT=../../.. 371.17 +include $(XEN_ROOT)/tools/Rules.mk 371.18 + 371.19 +ifneq ($(XENSTAT_XENTOP),y) 371.20 +all install xentop: 371.21 +else 371.22 + 371.23 +INSTALL = install 371.24 +INSTALL_PROG = $(INSTALL) -m0755 -D 371.25 +INSTALL_DATA = $(INSTALL) -m0644 -D 371.26 + 371.27 +prefix=/usr 371.28 +mandir=$(prefix)/share/man 371.29 +man1dir=$(mandir)/man1 371.30 +sbindir=$(prefix)/sbin 371.31 + 371.32 +CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT) 371.33 +LDFLAGS += -L$(XEN_LIBXENSTAT) 371.34 +LDLIBS += -lxenstat -lncurses 371.35 + 371.36 +all: xentop 371.37 + 371.38 +xentop: xentop.o 371.39 + 371.40 +install: xentop xentop.1 371.41 + $(INSTALL_PROG) xentop $(DESTDIR)$(sbindir)/xentop 371.42 + $(INSTALL_DATA) xentop.1 $(DESTDIR)$(man1dir)/xentop.1 371.43 + 371.44 +endif 371.45 + 371.46 +clean: 371.47 + rm -f xentop xentop.o
372.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 372.2 +++ b/tools/xenstat/xentop/TODO Tue Aug 23 12:03:21 2005 -0700 372.3 @@ -0,0 +1,34 @@ 372.4 +Display error messages on the help line after bad input at a prompt. 372.5 +Fractional delay times 372.6 +Use prompting to search for domains 372.7 +Better line editing? 372.8 + 372.9 +* Make CPU in % more accurate 372.10 +* Domain total network TX % and RX % 372.11 + 372.12 +Like Top, f feature, field select of domain columns, toggle the display of 372.13 +field by typing the letter associated with field, if displayed it shows in 372.14 +bold and the letter is Capitalized along with a leading asterisk for the 372.15 +field, if not selected for display letter is lowercase, no leading asterisk 372.16 +and field is not bolded. 372.17 + 372.18 +Like Top, ordering of domain columns, o feature Capital letter shifts left, 372.19 +lowercase letter shifts right? 372.20 + 372.21 +Color 372.22 +Full management: pause, destroy, create domains 372.23 + 372.24 +Add support for Virtual Block Devices (vbd) 372.25 + 372.26 +To think about: 372.27 +Support for one than one node display (distributed monitoring 372.28 +from any node of all other nodes in a cluster) 372.29 +Bottom line option (Switch node, Search node [tab completion?]) 372.30 + 372.31 +Capture/Logging of resource information generated during a time interval. 372.32 +-b batch mode dump snapshots to standard output (used with -n) 372.33 +-n number of iterations to dump to standard output (unlimited if not specified) 372.34 +-d monitor DomIDs as -dD1,-dD2 or -dD1,D2... 372.35 + Monitor only domains with specified domain IDs 372.36 +-m monitor nodeIDs as -mN1,-mN2 or -mN1,N2... 372.37 + Monitor only domains with specified node IDs
373.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 373.2 +++ b/tools/xenstat/xentop/xentop.1 Tue Aug 23 12:03:21 2005 -0700 373.3 @@ -0,0 +1,88 @@ 373.4 +.\" Copyright (C) International Business Machines Corp., 2005 373.5 +.\" Author: Josh Triplett <josht@us.ibm.com> 373.6 +.\" 373.7 +.\" This program is free software; you can redistribute it and/or modify 373.8 +.\" it under the terms of the GNU General Public License as published by 373.9 +.\" the Free Software Foundation; under version 2 of the License. 373.10 +.\" 373.11 +.\" This program is distributed in the hope that it will be useful, 373.12 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of 373.13 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 373.14 +.\" GNU General Public License for more details. 373.15 +.\" 373.16 +.\" You should have received a copy of the GNU General Public License 373.17 +.\" along with this program; if not, write to the Free Software 373.18 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 373.19 +.TH xentop 1 "August 2005" 373.20 +.SH NAME 373.21 +\fBxentop\fR \- displays real-time information about a Xen system and domains 373.22 + 373.23 +.SH SYNOPSIS 373.24 +.B xentop 373.25 +[\fB\-h\fR] 373.26 +[\fB\-V\fR] 373.27 +[\fB\-d\fRSECONDS] 373.28 +[\fB\-n\fR] 373.29 +[\fB\-r\fR] 373.30 +[\fB\-v\fR] 373.31 + 373.32 +.SH DESCRIPTION 373.33 +\fBxentop\fR displays information about the Xen system and domains, in a 373.34 +continually-updating manner. Command-line options and interactive commands 373.35 +can change the detail and format of the information displayed by \fBxentop\fR. 373.36 + 373.37 +.SH OPTIONS 373.38 +.TP 373.39 +\fB\-h\fR, \fB\-\-help\fR 373.40 +display help and exit 373.41 +.TP 373.42 +\fB\-V\fR, \fB\-\-version\fR 373.43 +output version information and exit 373.44 +.TP 373.45 +\fB\-d\fR, \fB\-\-delay\fR=\fISECONDS\fR 373.46 +seconds between updates (default 3) 373.47 +.TP 373.48 +\fB\-n\fR, \fB\-\-networks\fR 373.49 +output network information 373.50 +.TP 373.51 +\fB\-r\fR, \fB\-\-repeat\-header\fR 373.52 +repeat table header before each domain 373.53 +.TP 373.54 +\fB\-v\fR, \fB\-\-vcpus\fR 373.55 +output VCPU data 373.56 + 373.57 +.SH "INTERACTIVE COMMANDS" 373.58 +All interactive commands are case-insensitive. 373.59 +.TP 373.60 +.B D 373.61 +set delay between updates 373.62 +.TP 373.63 +.B N 373.64 +toggle display of network information 373.65 +.TP 373.66 +.B Q, Esc 373.67 +quit 373.68 +.TP 373.69 +.B R 373.70 +toggle table header before each domain 373.71 +.TP 373.72 +.B S 373.73 +cycle sort order 373.74 +.TP 373.75 +.B V 373.76 +toggle display of VCPU information 373.77 +.TP 373.78 +.B Arrows 373.79 +scroll domain display 373.80 + 373.81 +.SH AUTHORS 373.82 +Written by Judy Fischbach, David Hendricks, and Josh Triplett 373.83 + 373.84 +.SH "REPORTING BUGS" 373.85 +Report bugs to <dsteklof@us.ibm.com>. 373.86 + 373.87 +.SH COPYRIGHT 373.88 +Copyright \(co 2005 International Business Machines Corp 373.89 +.br 373.90 +This is free software; see the source for copying conditions. There is NO 373.91 +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
374.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 374.2 +++ b/tools/xenstat/xentop/xentop.c Tue Aug 23 12:03:21 2005 -0700 374.3 @@ -0,0 +1,876 @@ 374.4 +/* 374.5 + * Copyright (C) International Business Machines Corp., 2005 374.6 + * Author(s): Judy Fischbach <jfisch@us.ibm.com> 374.7 + * David Hendricks <dhendrix@us.ibm.com> 374.8 + * Josh Triplett <josht@us.ibm.com> 374.9 + * based on code from Anthony Liguori <aliguori@us.ibm.com> 374.10 + * 374.11 + * This program is free software; you can redistribute it and/or modify 374.12 + * it under the terms of the GNU General Public License as published by 374.13 + * the Free Software Foundation; under version 2 of the License. 374.14 + * 374.15 + * This program is distributed in the hope that it will be useful, 374.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 374.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 374.18 + * GNU General Public License for more details. 374.19 + * 374.20 + * You should have received a copy of the GNU General Public License 374.21 + * along with this program; if not, write to the Free Software 374.22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 374.23 + */ 374.24 +#include <curses.h> 374.25 +#include <ctype.h> 374.26 +#include <errno.h> 374.27 +#include <stdio.h> 374.28 +#include <stdlib.h> 374.29 +#include <string.h> 374.30 +#include <sys/time.h> 374.31 +#include <time.h> 374.32 +#include <unistd.h> 374.33 + 374.34 +#include <xenstat.h> 374.35 + 374.36 +#define XENTOP_VERSION "1.0" 374.37 + 374.38 +#define XENTOP_DISCLAIMER \ 374.39 +"Copyright (C) 2005 International Business Machines Corp\n"\ 374.40 +"This is free software; see the source for copying conditions.There is NO\n"\ 374.41 +"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" 374.42 +#define XENTOP_BUGSTO "Report bugs to <dsteklof@us.ibm.com>.\n" 374.43 + 374.44 +#define _GNU_SOURCE 374.45 +#include <getopt.h> 374.46 + 374.47 +#if !defined(__GNUC__) && !defined(__GNUG__) 374.48 +#define __attribute__(arg) /* empty */ 374.49 +#endif 374.50 + 374.51 +#define KEY_ESCAPE '\x1B' 374.52 + 374.53 +/* 374.54 + * Function prototypes 374.55 + */ 374.56 +/* Utility functions */ 374.57 +static void usage(const char *); 374.58 +static void version(void); 374.59 +static void cleanup(void); 374.60 +static void fail(const char *); 374.61 +static int current_row(void); 374.62 +static int lines(void); 374.63 +static void print(const char *, ...) __attribute__((format(printf,1,2))); 374.64 +static void attr_addstr(int attr, const char *str); 374.65 +static void set_delay(char *value); 374.66 +static void set_prompt(char *new_prompt, void (*func)(char *)); 374.67 +static int handle_key(int); 374.68 +static int compare(unsigned long long, unsigned long long); 374.69 +static int compare_domains(xenstat_domain **, xenstat_domain **); 374.70 +static unsigned long long tot_net_bytes( xenstat_domain *, int); 374.71 + 374.72 +/* Field functions */ 374.73 +static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2); 374.74 +static void print_domid(xenstat_domain *domain); 374.75 +static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2); 374.76 +static void print_state(xenstat_domain *domain); 374.77 +static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2); 374.78 +static void print_cpu(xenstat_domain *domain); 374.79 +static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2); 374.80 +static void print_cpu_pct(xenstat_domain *domain); 374.81 +static int compare_mem(xenstat_domain *domain1, xenstat_domain *domain2); 374.82 +static void print_mem(xenstat_domain *domain); 374.83 +static void print_mem_pct(xenstat_domain *domain); 374.84 +static int compare_maxmem(xenstat_domain *domain1, xenstat_domain *domain2); 374.85 +static void print_maxmem(xenstat_domain *domain); 374.86 +static void print_max_pct(xenstat_domain *domain); 374.87 +static int compare_vcpus(xenstat_domain *domain1, xenstat_domain *domain2); 374.88 +static void print_vcpus(xenstat_domain *domain); 374.89 +static int compare_nets(xenstat_domain *domain1, xenstat_domain *domain2); 374.90 +static void print_nets(xenstat_domain *domain); 374.91 +static int compare_net_tx(xenstat_domain *domain1, xenstat_domain *domain2); 374.92 +static void print_net_tx(xenstat_domain *domain); 374.93 +static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2); 374.94 +static void print_net_rx(xenstat_domain *domain); 374.95 +static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2); 374.96 +static void print_ssid(xenstat_domain *domain); 374.97 + 374.98 +/* Section printing functions */ 374.99 +static void do_summary(void); 374.100 +static void do_header(void); 374.101 +static void do_bottom_line(void); 374.102 +static void do_domain(xenstat_domain *); 374.103 +static void do_vcpu(xenstat_domain *); 374.104 +static void do_network(xenstat_domain *); 374.105 +static void top(void); 374.106 + 374.107 +/* Field types */ 374.108 +typedef enum field_id { 374.109 + FIELD_DOMID, 374.110 + FIELD_STATE, 374.111 + FIELD_CPU, 374.112 + FIELD_CPU_PCT, 374.113 + FIELD_MEM, 374.114 + FIELD_MEM_PCT, 374.115 + FIELD_MAXMEM, 374.116 + FIELD_MAX_PCT, 374.117 + FIELD_VCPUS, 374.118 + FIELD_NETS, 374.119 + FIELD_NET_TX, 374.120 + FIELD_NET_RX, 374.121 + FIELD_SSID 374.122 +} field_id; 374.123 + 374.124 +typedef struct field { 374.125 + field_id num; 374.126 + const char *header; 374.127 + unsigned int default_width; 374.128 + int (*compare)(xenstat_domain *domain1, xenstat_domain *domain2); 374.129 + void (*print)(xenstat_domain *domain); 374.130 +} field; 374.131 + 374.132 +field fields[] = { 374.133 + { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, 374.134 + { FIELD_STATE, "STATE", 6, compare_state, print_state }, 374.135 + { FIELD_CPU, "CPU(sec)", 10, compare_cpu, print_cpu }, 374.136 + { FIELD_CPU_PCT, "CPU(%)", 6, compare_cpu_pct, print_cpu_pct }, 374.137 + { FIELD_MEM, "MEM(k)", 10, compare_mem, print_mem }, 374.138 + { FIELD_MEM_PCT, "MEM(%)", 6, compare_mem, print_mem_pct }, 374.139 + { FIELD_MAXMEM, "MAXMEM(k)", 10, compare_maxmem, print_maxmem }, 374.140 + { FIELD_MAX_PCT, "MAXMEM(%)", 9, compare_maxmem, print_max_pct }, 374.141 + { FIELD_VCPUS, "VCPUS", 5, compare_vcpus, print_vcpus }, 374.142 + { FIELD_NETS, "NETS", 4, compare_nets, print_nets }, 374.143 + { FIELD_NET_TX, "NETTX(k)", 8, compare_net_tx, print_net_tx }, 374.144 + { FIELD_NET_RX, "NETRX(k)", 8, compare_net_rx, print_net_rx }, 374.145 + { FIELD_SSID, "SSID", 4, compare_ssid, print_ssid } 374.146 +}; 374.147 + 374.148 +const unsigned int NUM_FIELDS = sizeof(fields)/sizeof(field); 374.149 + 374.150 +/* Globals */ 374.151 +struct timeval curtime, oldtime; 374.152 +xenstat_handle *xhandle = NULL; 374.153 +xenstat_node *prev_node = NULL; 374.154 +xenstat_node *cur_node = NULL; 374.155 +field_id sort_field = FIELD_DOMID; 374.156 +unsigned int first_domain_index = 0; 374.157 +unsigned int delay = 3; 374.158 +int show_vcpus = 0; 374.159 +int show_networks = 0; 374.160 +int repeat_header = 0; 374.161 +#define PROMPT_VAL_LEN 80 374.162 +char *prompt = NULL; 374.163 +char prompt_val[PROMPT_VAL_LEN]; 374.164 +int prompt_val_len = 0; 374.165 +void (*prompt_complete_func)(char *); 374.166 + 374.167 +/* 374.168 + * Function definitions 374.169 + */ 374.170 + 374.171 +/* Utility functions */ 374.172 + 374.173 +/* Print usage message, using given program name */ 374.174 +static void usage(const char *program) 374.175 +{ 374.176 + printf("Usage: %s [OPTION]\n" 374.177 + "Displays ongoing information about xen vm resources \n\n" 374.178 + "-h, --help display this help and exit\n" 374.179 + "-V, --version output version information and exit\n" 374.180 + "-d, --delay=SECONDS seconds between updates (default 3)\n" 374.181 + "-n, --networks output vif network data\n" 374.182 + "-r, --repeat-header repeat table header before each domain\n" 374.183 + "-v, --vcpus output vcpu data\n" 374.184 + "\n" XENTOP_BUGSTO, 374.185 + program); 374.186 + return; 374.187 +} 374.188 + 374.189 +/* Print program version information */ 374.190 +static void version(void) 374.191 +{ 374.192 + printf("xentop " XENTOP_VERSION "\n" 374.193 + "Written by Judy Fischbach, David Hendricks, Josh Triplett\n" 374.194 + "\n" XENTOP_DISCLAIMER); 374.195 +} 374.196 + 374.197 +/* Clean up any open resources */ 374.198 +static void cleanup(void) 374.199 +{ 374.200 + if(!isendwin()) 374.201 + endwin(); 374.202 + if(prev_node != NULL) 374.203 + xenstat_free_node(prev_node); 374.204 + if(cur_node != NULL) 374.205 + xenstat_free_node(cur_node); 374.206 + if(xhandle != NULL) 374.207 + xenstat_uninit(xhandle); 374.208 +} 374.209 + 374.210 +/* Display the given message and gracefully exit */ 374.211 +static void fail(const char *str) 374.212 +{ 374.213 + if(!isendwin()) 374.214 + endwin(); 374.215 + fprintf(stderr, str); 374.216 + exit(1); 374.217 +} 374.218 + 374.219 +/* Return the row containing the cursor. */ 374.220 +static int current_row(void) 374.221 +{ 374.222 + int y, x; 374.223 + getyx(stdscr, y, x); 374.224 + return y; 374.225 +} 374.226 + 374.227 +/* Return the number of lines on the screen. */ 374.228 +static int lines(void) 374.229 +{ 374.230 + int y, x; 374.231 + getmaxyx(stdscr, y, x); 374.232 + return y; 374.233 +} 374.234 + 374.235 +/* printf-style print function which calls printw, but only if the cursor is 374.236 + * not on the last line. */ 374.237 +static void print(const char *fmt, ...) 374.238 +{ 374.239 + va_list args; 374.240 + 374.241 + if(current_row() < lines()-1) { 374.242 + va_start(args, fmt); 374.243 + vw_printw(stdscr, fmt, args); 374.244 + va_end(args); 374.245 + } 374.246 +} 374.247 + 374.248 +/* Print a string with the given attributes set. */ 374.249 +static void attr_addstr(int attr, const char *str) 374.250 +{ 374.251 + attron(attr); 374.252 + addstr(str); 374.253 + attroff(attr); 374.254 +} 374.255 + 374.256 +/* Handle setting the delay from the user-supplied value in prompt_val */ 374.257 +static void set_delay(char *value) 374.258 +{ 374.259 + int new_delay; 374.260 + new_delay = atoi(value); 374.261 + if(new_delay > 0) 374.262 + delay = new_delay; 374.263 +} 374.264 + 374.265 +/* Enable prompting mode with the given prompt string; call the given function 374.266 + * when a value is available. */ 374.267 +static void set_prompt(char *new_prompt, void (*func)(char *)) 374.268 +{ 374.269 + prompt = new_prompt; 374.270 + prompt_val[0] = '\0'; 374.271 + prompt_val_len = 0; 374.272 + prompt_complete_func = func; 374.273 +} 374.274 + 374.275 +/* Handle user input, return 0 if the program should quit, or 1 if not */ 374.276 +static int handle_key(int ch) 374.277 +{ 374.278 + if(prompt == NULL) { 374.279 + /* Not prompting for input; handle interactive commands */ 374.280 + switch(ch) { 374.281 + case 'n': case 'N': 374.282 + show_networks ^= 1; 374.283 + break; 374.284 + case 'r': case 'R': 374.285 + repeat_header ^= 1; 374.286 + break; 374.287 + case 's': case 'S': 374.288 + sort_field = (sort_field + 1) % NUM_FIELDS; 374.289 + break; 374.290 + case 'v': case 'V': 374.291 + show_vcpus ^= 1; 374.292 + break; 374.293 + case KEY_DOWN: 374.294 + first_domain_index++; 374.295 + break; 374.296 + case KEY_UP: 374.297 + if(first_domain_index > 0) 374.298 + first_domain_index--; 374.299 + break; 374.300 + case 'd': case 'D': 374.301 + set_prompt("Delay(sec)", set_delay); 374.302 + break; 374.303 + case 'q': case 'Q': case KEY_ESCAPE: 374.304 + return 0; 374.305 + } 374.306 + } else { 374.307 + /* Prompting for input; handle line editing */ 374.308 + switch(ch) { 374.309 + case '\r': 374.310 + prompt_complete_func(prompt_val); 374.311 + set_prompt(NULL, NULL); 374.312 + break; 374.313 + case KEY_ESCAPE: 374.314 + set_prompt(NULL, NULL); 374.315 + break; 374.316 + case KEY_BACKSPACE: 374.317 + if(prompt_val_len > 0) 374.318 + prompt_val[--prompt_val_len] = '\0'; 374.319 + default: 374.320 + if((prompt_val_len+1) < PROMPT_VAL_LEN 374.321 + && isprint(ch)) { 374.322 + prompt_val[prompt_val_len++] = (char)ch; 374.323 + prompt_val[prompt_val_len] = '\0'; 374.324 + } 374.325 + } 374.326 + } 374.327 + 374.328 + return 1; 374.329 +} 374.330 + 374.331 +/* Compares two integers, returning -1,0,1 for <,=,> */ 374.332 +static int compare(unsigned long long i1, unsigned long long i2) 374.333 +{ 374.334 + if(i1 < i2) 374.335 + return -1; 374.336 + if(i1 > i2) 374.337 + return 1; 374.338 + return 0; 374.339 +} 374.340 + 374.341 +/* Comparison function for use with qsort. Compares two domains using the 374.342 + * current sort field. */ 374.343 +static int compare_domains(xenstat_domain **domain1, xenstat_domain **domain2) 374.344 +{ 374.345 + return fields[sort_field].compare(*domain1, *domain2); 374.346 +} 374.347 + 374.348 +/* Field functions */ 374.349 + 374.350 +/* Compares domain ids of two domains, returning -1,0,1 for <,=,> */ 374.351 +int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2) 374.352 +{ 374.353 + return compare(xenstat_domain_id(domain1), xenstat_domain_id(domain2)); 374.354 +} 374.355 + 374.356 +/* Prints domain identification number */ 374.357 +void print_domid(xenstat_domain *domain) 374.358 +{ 374.359 + print("%5u", xenstat_domain_id(domain)); 374.360 +} 374.361 + 374.362 +struct { 374.363 + unsigned int (*get)(xenstat_domain *); 374.364 + char ch; 374.365 +} state_funcs[] = { 374.366 + { xenstat_domain_dying, 'd' }, 374.367 + { xenstat_domain_shutdown, 's' }, 374.368 + { xenstat_domain_blocked, 'b' }, 374.369 + { xenstat_domain_crashed, 'c' }, 374.370 + { xenstat_domain_paused, 'p' }, 374.371 + { xenstat_domain_running, 'r' } 374.372 +}; 374.373 +const unsigned int NUM_STATES = sizeof(state_funcs)/sizeof(*state_funcs); 374.374 + 374.375 +/* Compare states of two domains, returning -1,0,1 for <,=,> */ 374.376 +static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2) 374.377 +{ 374.378 + unsigned int i, d1s, d2s; 374.379 + for(i = 0; i < NUM_STATES; i++) { 374.380 + d1s = state_funcs[i].get(domain1); 374.381 + d2s = state_funcs[i].get(domain2); 374.382 + if(d1s && !d2s) 374.383 + return -1; 374.384 + if(d2s && !d1s) 374.385 + return 1; 374.386 + } 374.387 + return 0; 374.388 +} 374.389 + 374.390 +/* Prints domain state in abbreviated letter format */ 374.391 +static void print_state(xenstat_domain *domain) 374.392 +{ 374.393 + unsigned int i; 374.394 + for(i = 0; i < NUM_STATES; i++) 374.395 + print("%c", state_funcs[i].get(domain) ? state_funcs[i].ch 374.396 + : '-'); 374.397 +} 374.398 + 374.399 +/* Compares cpu usage of two domains, returning -1,0,1 for <,=,> */ 374.400 +static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2) 374.401 +{ 374.402 + return -compare(xenstat_domain_cpu_ns(domain1), 374.403 + xenstat_domain_cpu_ns(domain2)); 374.404 +} 374.405 + 374.406 +/* Prints domain cpu usage in seconds */ 374.407 +static void print_cpu(xenstat_domain *domain) 374.408 +{ 374.409 + print("%10llu", xenstat_domain_cpu_ns(domain)/1000000000); 374.410 +} 374.411 + 374.412 +/* Computes the CPU percentage used for a specified domain */ 374.413 +static double get_cpu_pct(xenstat_domain *domain) 374.414 +{ 374.415 + xenstat_domain *old_domain; 374.416 + double us_elapsed; 374.417 + 374.418 + /* Can't calculate CPU percentage without a previous sample. */ 374.419 + if(prev_node == NULL) 374.420 + return 0.0; 374.421 + 374.422 + old_domain = xenstat_node_domain(prev_node, xenstat_domain_id(domain)); 374.423 + if(old_domain == NULL) 374.424 + return 0.0; 374.425 + 374.426 + /* Calculate the time elapsed in microseconds */ 374.427 + us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0 374.428 + +(curtime.tv_usec - oldtime.tv_usec)); 374.429 + 374.430 + /* In the following, nanoseconds must be multiplied by 1000.0 to 374.431 + * convert to microseconds, then divided by 100.0 to get a percentage, 374.432 + * resulting in a multiplication by 10.0 */ 374.433 + return ((xenstat_domain_cpu_ns(domain) 374.434 + -xenstat_domain_cpu_ns(old_domain))/10.0)/us_elapsed; 374.435 +} 374.436 + 374.437 +static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2) 374.438 +{ 374.439 + return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2)); 374.440 +} 374.441 + 374.442 +/* Prints cpu percentage statistic */ 374.443 +static void print_cpu_pct(xenstat_domain *domain) 374.444 +{ 374.445 + print("%6.1f", get_cpu_pct(domain)); 374.446 +} 374.447 + 374.448 +/* Compares current memory of two domains, returning -1,0,1 for <,=,> */ 374.449 +static int compare_mem(xenstat_domain *domain1, xenstat_domain *domain2) 374.450 +{ 374.451 + return -compare(xenstat_domain_cur_mem(domain1), 374.452 + xenstat_domain_cur_mem(domain2)); 374.453 +} 374.454 + 374.455 +/* Prints current memory statistic */ 374.456 +static void print_mem(xenstat_domain *domain) 374.457 +{ 374.458 + print("%10llu", xenstat_domain_cur_mem(domain)/1024); 374.459 +} 374.460 + 374.461 +/* Prints memory percentage statistic, ratio of current domain memory to total 374.462 + * node memory */ 374.463 +static void print_mem_pct(xenstat_domain *domain) 374.464 +{ 374.465 + print("%6.1f", (double)xenstat_domain_cur_mem(domain) / 374.466 + (double)xenstat_node_tot_mem(cur_node) * 100); 374.467 +} 374.468 + 374.469 +/* Compares maximum memory of two domains, returning -1,0,1 for <,=,> */ 374.470 +static int compare_maxmem(xenstat_domain *domain1, xenstat_domain *domain2) 374.471 +{ 374.472 + return -compare(xenstat_domain_max_mem(domain1), 374.473 + xenstat_domain_max_mem(domain2)); 374.474 +} 374.475 + 374.476 +/* Prints maximum domain memory statistic in KB */ 374.477 +static void print_maxmem(xenstat_domain *domain) 374.478 +{ 374.479 + unsigned long long max_mem = xenstat_domain_max_mem(domain); 374.480 + if(max_mem == ((unsigned long long)-1)) 374.481 + print("%10s", "no limit"); 374.482 + else 374.483 + print("%10llu", max_mem/1024); 374.484 +} 374.485 + 374.486 +/* Prints memory percentage statistic, ratio of current domain memory to total 374.487 + * node memory */ 374.488 +static void print_max_pct(xenstat_domain *domain) 374.489 +{ 374.490 + if (xenstat_domain_max_mem(domain) == (unsigned long long)-1) 374.491 + print("%9s", "n/a"); 374.492 + else 374.493 + print("%9.1f", (double)xenstat_domain_max_mem(domain) / 374.494 + (double)xenstat_node_tot_mem(cur_node) * 100); 374.495 +} 374.496 + 374.497 +/* Compares number of virtual CPUs of two domains, returning -1,0,1 for 374.498 + * <,=,> */ 374.499 +static int compare_vcpus(xenstat_domain *domain1, xenstat_domain *domain2) 374.500 +{ 374.501 + return -compare(xenstat_domain_num_vcpus(domain1), 374.502 + xenstat_domain_num_vcpus(domain2)); 374.503 +} 374.504 + 374.505 +/* Prints number of virtual CPUs statistic */ 374.506 +static void print_vcpus(xenstat_domain *domain) 374.507 +{ 374.508 + print("%5u", xenstat_domain_num_vcpus(domain)); 374.509 +} 374.510 + 374.511 +/* Compares number of virtual networks of two domains, returning -1,0,1 for 374.512 + * <,=,> */ 374.513 +static int compare_nets(xenstat_domain *domain1, xenstat_domain *domain2) 374.514 +{ 374.515 + return -compare(xenstat_domain_num_networks(domain1), 374.516 + xenstat_domain_num_networks(domain2)); 374.517 +} 374.518 + 374.519 +/* Prints number of virtual networks statistic */ 374.520 +static void print_nets(xenstat_domain *domain) 374.521 +{ 374.522 + print("%4u", xenstat_domain_num_networks(domain)); 374.523 +} 374.524 + 374.525 +/* Compares number of total network tx bytes of two domains, returning -1,0,1 for 374.526 + * <,=,> */ 374.527 +static int compare_net_tx(xenstat_domain *domain1, xenstat_domain *domain2) 374.528 +{ 374.529 + return -compare(tot_net_bytes(domain1, FALSE), 374.530 + tot_net_bytes(domain2, FALSE)); 374.531 +} 374.532 + 374.533 +/* Prints number of total network tx bytes statistic */ 374.534 +static void print_net_tx(xenstat_domain *domain) 374.535 +{ 374.536 + print("%8llu", tot_net_bytes(domain, FALSE)/1024); 374.537 +} 374.538 + 374.539 +/* Compares number of total network rx bytes of two domains, returning -1,0,1 for 374.540 + * <,=,> */ 374.541 +static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2) 374.542 +{ 374.543 + return -compare(tot_net_bytes(domain1, TRUE), 374.544 + tot_net_bytes(domain2, TRUE)); 374.545 +} 374.546 + 374.547 +/* Prints number of total network rx bytes statistic */ 374.548 +static void print_net_rx(xenstat_domain *domain) 374.549 +{ 374.550 + print("%8llu", tot_net_bytes(domain, TRUE)/1024); 374.551 +} 374.552 + 374.553 +/* Gets number of total network bytes statistic, if rx true, then rx bytes 374.554 + * otherwise tx bytes 374.555 + */ 374.556 +static unsigned long long tot_net_bytes(xenstat_domain *domain, int rx_flag) 374.557 +{ 374.558 + int i = 0; 374.559 + xenstat_network *network; 374.560 + unsigned num_networks = 0; 374.561 + unsigned long long total = 0; 374.562 + 374.563 + /* How many networks? */ 374.564 + num_networks = xenstat_domain_num_networks(domain); 374.565 + 374.566 + /* Dump information for each network */ 374.567 + for (i=0; i < num_networks; i++) { 374.568 + /* Next get the network information */ 374.569 + network = xenstat_domain_network(domain,i); 374.570 + if (rx_flag) 374.571 + total += xenstat_network_rbytes(network); 374.572 + else 374.573 + total += xenstat_network_tbytes(network); 374.574 + } 374.575 + return (total); 374.576 +} 374.577 + 374.578 +/* Compares security id (ssid) of two domains, returning -1,0,1 for <,=,> */ 374.579 +static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2) 374.580 +{ 374.581 + return compare(xenstat_domain_ssid(domain1), 374.582 + xenstat_domain_ssid(domain2)); 374.583 +} 374.584 + 374.585 +/* Prints ssid statistic */ 374.586 +static void print_ssid(xenstat_domain *domain) 374.587 +{ 374.588 + print("%4u", xenstat_domain_ssid(domain)); 374.589 +} 374.590 + 374.591 +/* Section printing functions */ 374.592 +/* Prints the top summary, above the domain table */ 374.593 +void do_summary(void) 374.594 +{ 374.595 +#define TIME_STR_LEN 9 374.596 + const char *TIME_STR_FORMAT = "%H:%M:%S"; 374.597 + char time_str[TIME_STR_LEN]; 374.598 + unsigned run = 0, block = 0, pause = 0, 374.599 + crash = 0, dying = 0, shutdown = 0; 374.600 + unsigned i, num_domains = 0; 374.601 + unsigned long long used = 0; 374.602 + xenstat_domain *domain; 374.603 + 374.604 + /* Print program name, current time, and number of domains */ 374.605 + strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT, 374.606 + localtime(&curtime.tv_sec)); 374.607 + num_domains = xenstat_node_num_domains(cur_node); 374.608 + print("xentop - %s\n", time_str); 374.609 + 374.610 + /* Tabulate what states domains are in for summary */ 374.611 + for (i=0; i < num_domains; i++) { 374.612 + domain = xenstat_node_domain_by_index(cur_node,i); 374.613 + if (xenstat_domain_running(domain)) run++; 374.614 + else if (xenstat_domain_blocked(domain)) block++; 374.615 + else if (xenstat_domain_paused(domain)) pause++; 374.616 + else if (xenstat_domain_shutdown(domain)) shutdown++; 374.617 + else if (xenstat_domain_crashed(domain)) crash++; 374.618 + else if (xenstat_domain_dying(domain)) dying++; 374.619 + } 374.620 + 374.621 + print("%u domains: %u running, %u blocked, %u paused, " 374.622 + "%u crashed, %u dying, %u shutdown \n", 374.623 + num_domains, run, block, pause, crash, dying, shutdown); 374.624 + 374.625 + used = xenstat_node_tot_mem(cur_node)-xenstat_node_free_mem(cur_node); 374.626 + 374.627 + /* Dump node memory and cpu information */ 374.628 + print("Mem: %lluk total, %lluk used, %lluk free " 374.629 + "CPUs: %u @ %lluMHz\n", 374.630 + xenstat_node_tot_mem(cur_node)/1024, used/1024, 374.631 + xenstat_node_free_mem(cur_node)/1024, 374.632 + xenstat_node_num_cpus(cur_node), 374.633 + xenstat_node_cpu_hz(cur_node)/1000000); 374.634 +} 374.635 + 374.636 +/* Display the top header for the domain table */ 374.637 +void do_header(void) 374.638 +{ 374.639 + field_id i; 374.640 + 374.641 + /* Turn on REVERSE highlight attribute for headings */ 374.642 + attron(A_REVERSE); 374.643 + for(i = 0; i < NUM_FIELDS; i++) { 374.644 + if(i != 0) 374.645 + print(" "); 374.646 + /* The BOLD attribute is turned on for the sort column */ 374.647 + if(i == sort_field) 374.648 + attron(A_BOLD); 374.649 + print("%*s", fields[i].default_width, fields[i].header); 374.650 + if(i == sort_field) 374.651 + attroff(A_BOLD); 374.652 + } 374.653 + attroff(A_REVERSE); 374.654 + print("\n"); 374.655 +} 374.656 + 374.657 +/* Displays bottom status line or current prompt */ 374.658 +void do_bottom_line(void) 374.659 +{ 374.660 + move(lines()-1, 2); 374.661 + 374.662 + if (prompt != NULL) { 374.663 + printw("%s: %s", prompt, prompt_val); 374.664 + } else { 374.665 + addch(A_REVERSE | 'D'); addstr("elay "); 374.666 + 374.667 + /* network */ 374.668 + addch(A_REVERSE | 'N'); 374.669 + attr_addstr(show_networks ? COLOR_PAIR(1) : 0, "etworks"); 374.670 + addstr(" "); 374.671 + 374.672 + /* vcpus */ 374.673 + addch(A_REVERSE | 'V'); 374.674 + attr_addstr(show_vcpus ? COLOR_PAIR(1) : 0, "CPUs"); 374.675 + addstr(" "); 374.676 + 374.677 + /* repeat */ 374.678 + addch(A_REVERSE | 'R'); 374.679 + attr_addstr(repeat_header ? COLOR_PAIR(1) : 0, "epeat header"); 374.680 + addstr(" "); 374.681 + 374.682 + /* sort order */ 374.683 + addch(A_REVERSE | 'S'); addstr("ort order "); 374.684 + 374.685 + addch(A_REVERSE | 'Q'); addstr("uit "); 374.686 + } 374.687 +} 374.688 + 374.689 +/* Prints Domain information */ 374.690 +void do_domain(xenstat_domain *domain) 374.691 +{ 374.692 + unsigned int i; 374.693 + for(i = 0; i < NUM_FIELDS; i++) { 374.694 + if(i != 0) 374.695 + print(" "); 374.696 + if(i == sort_field) 374.697 + attron(A_BOLD); 374.698 + fields[i].print(domain); 374.699 + if(i == sort_field) 374.700 + attroff(A_BOLD); 374.701 + } 374.702 + print("\n"); 374.703 +} 374.704 + 374.705 +/* Output all vcpu information */ 374.706 +void do_vcpu(xenstat_domain *domain) 374.707 +{ 374.708 + int i = 0; 374.709 + unsigned num_vcpus = 0; 374.710 + xenstat_vcpu *vcpu; 374.711 + 374.712 + print("VCPUs(sec): "); 374.713 + 374.714 + num_vcpus = xenstat_domain_num_vcpus(domain); 374.715 + 374.716 + /* for all vcpus dump out values */ 374.717 + for (i=0; i< num_vcpus; i++) { 374.718 + vcpu = xenstat_domain_vcpu(domain,i); 374.719 + 374.720 + if (i != 0 && (i%5)==0) 374.721 + print("\n "); 374.722 + print(" %2u: %10llus", i, xenstat_vcpu_ns(vcpu)/1000000000); 374.723 + } 374.724 + print("\n"); 374.725 +} 374.726 + 374.727 +/* Output all network information */ 374.728 +void do_network(xenstat_domain *domain) 374.729 +{ 374.730 + int i = 0; 374.731 + xenstat_network *network; 374.732 + unsigned num_networks = 0; 374.733 + 374.734 + /* How many networks? */ 374.735 + num_networks = xenstat_domain_num_networks(domain); 374.736 + 374.737 + /* Dump information for each network */ 374.738 + for (i=0; i < num_networks; i++) { 374.739 + /* Next get the network information */ 374.740 + network = xenstat_domain_network(domain,i); 374.741 + 374.742 + print("Net%d RX: %8llubytes %8llupkts %8lluerr %8lludrop ", 374.743 + i, 374.744 + xenstat_network_rbytes(network), 374.745 + xenstat_network_rpackets(network), 374.746 + xenstat_network_rerrs(network), 374.747 + xenstat_network_rdrop(network)); 374.748 + 374.749 + print("TX: %8llubytes %8llupkts %8lluerr %8lludrop\n", 374.750 + xenstat_network_tbytes(network), 374.751 + xenstat_network_tpackets(network), 374.752 + xenstat_network_terrs(network), 374.753 + xenstat_network_tdrop(network)); 374.754 + } 374.755 +} 374.756 + 374.757 +static void top(void) 374.758 +{ 374.759 + xenstat_domain **domains; 374.760 + unsigned int i, num_domains = 0; 374.761 + 374.762 + /* Now get the node information */ 374.763 + if (prev_node != NULL) 374.764 + xenstat_free_node(prev_node); 374.765 + prev_node = cur_node; 374.766 + cur_node = xenstat_get_node(xhandle, XENSTAT_ALL); 374.767 + if (cur_node == NULL) 374.768 + fail("Failed to retrieve statistics from libxenstat\n"); 374.769 + 374.770 + /* dump summary top information */ 374.771 + do_summary(); 374.772 + 374.773 + /* Count the number of domains for which to report data */ 374.774 + num_domains = xenstat_node_num_domains(cur_node); 374.775 + 374.776 + domains = malloc(num_domains*sizeof(xenstat_domain *)); 374.777 + if(domains == NULL) 374.778 + fail("Failed to allocate memory\n"); 374.779 + 374.780 + for (i=0; i < num_domains; i++) 374.781 + domains[i] = xenstat_node_domain_by_index(cur_node, i); 374.782 + 374.783 + /* Sort */ 374.784 + qsort(domains, num_domains, sizeof(xenstat_domain *), 374.785 + (int(*)(const void *, const void *))compare_domains); 374.786 + 374.787 + if(first_domain_index >= num_domains) 374.788 + first_domain_index = num_domains-1; 374.789 + 374.790 + for (i = first_domain_index; i < num_domains; i++) { 374.791 + if(current_row() == lines()-1) 374.792 + break; 374.793 + if (i == first_domain_index || repeat_header) 374.794 + do_header(); 374.795 + do_domain(domains[i]); 374.796 + if (show_vcpus) 374.797 + do_vcpu(domains[i]); 374.798 + if (show_networks) 374.799 + do_network(domains[i]); 374.800 + } 374.801 + 374.802 + do_bottom_line(); 374.803 +} 374.804 + 374.805 +int main(int argc, char **argv) 374.806 +{ 374.807 + int opt, optind = 0; 374.808 + int ch = ERR; 374.809 + 374.810 + struct option lopts[] = { 374.811 + { "help", no_argument, NULL, 'h' }, 374.812 + { "version", no_argument, NULL, 'V' }, 374.813 + { "networks", no_argument, NULL, 'n' }, 374.814 + { "repeat-header", no_argument, NULL, 'r' }, 374.815 + { "vcpus", no_argument, NULL, 'v' }, 374.816 + { "delay", required_argument, NULL, 'd' }, 374.817 + { 0, 0, 0, 0 }, 374.818 + }; 374.819 + const char *sopts = "hVbnvd:"; 374.820 + 374.821 + if (atexit(cleanup) != 0) 374.822 + fail("Failed to install cleanup handler.\n"); 374.823 + 374.824 + while ((opt = getopt_long(argc, argv, sopts, lopts, &optind)) != -1) { 374.825 + switch (opt) { 374.826 + case 'h': 374.827 + case '?': 374.828 + default: 374.829 + usage(argv[0]); 374.830 + exit(0); 374.831 + case 'V': 374.832 + version(); 374.833 + exit(0); 374.834 + case 'n': 374.835 + show_networks = 1; 374.836 + break; 374.837 + case 'r': 374.838 + repeat_header = 1; 374.839 + break; 374.840 + case 'v': 374.841 + show_vcpus = 1; 374.842 + break; 374.843 + case 'd': 374.844 + delay = atoi(optarg); 374.845 + break; 374.846 + } 374.847 + } 374.848 + 374.849 + /* Get xenstat handle */ 374.850 + xhandle = xenstat_init(); 374.851 + if (xhandle == NULL) 374.852 + fail("Failed to initialize xenstat library\n"); 374.853 + 374.854 + /* Begin curses stuff */ 374.855 + initscr(); 374.856 + start_color(); 374.857 + cbreak(); 374.858 + noecho(); 374.859 + nonl(); 374.860 + keypad(stdscr, TRUE); 374.861 + halfdelay(5); 374.862 + use_default_colors(); 374.863 + init_pair(1, -1, COLOR_YELLOW); 374.864 + 374.865 + do { 374.866 + gettimeofday(&curtime, NULL); 374.867 + if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= delay) { 374.868 + clear(); 374.869 + top(); 374.870 + oldtime = curtime; 374.871 + refresh(); 374.872 + } 374.873 + ch = getch(); 374.874 + } while (handle_key(ch)); 374.875 + 374.876 + /* Cleanup occurs in cleanup(), so no work to do here. */ 374.877 + 374.878 + return 0; 374.879 +}
441.1 --- a/xen/arch/x86/io_apic.c Mon Aug 22 11:37:48 2005 -0700 441.2 +++ b/xen/arch/x86/io_apic.c Tue Aug 23 12:03:21 2005 -0700 441.3 @@ -1751,8 +1751,30 @@ int ioapic_guest_write(int apicid, int a 441.4 441.5 pin = (address - 0x10) >> 1; 441.6 441.7 + *(u32 *)&rte = val; 441.8 rte.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS); 441.9 - *(int *)&rte = val; 441.10 + 441.11 + /* 441.12 + * What about weird destination types? 441.13 + * SMI: Ignore? Ought to be set up by the BIOS. 441.14 + * NMI: Ignore? Watchdog functionality is Xen's concern. 441.15 + * INIT: Definitely ignore: probably a guest OS bug. 441.16 + * ExtINT: Ignore? Linux only asserts this at start of day. 441.17 + * For now, print a message and return an error. We can fix up on demand. 441.18 + */ 441.19 + if ( rte.delivery_mode > dest_LowestPrio ) 441.20 + { 441.21 + printk("ERROR: Attempt to write weird IOAPIC destination mode!\n"); 441.22 + printk(" APIC=%d/%d, lo-reg=%x\n", apicid, pin, val); 441.23 + return -EINVAL; 441.24 + } 441.25 + 441.26 + /* 441.27 + * The guest does not know physical APIC arrangement (flat vs. cluster). 441.28 + * Apply genapic conventions for this platform. 441.29 + */ 441.30 + rte.delivery_mode = INT_DELIVERY_MODE; 441.31 + rte.dest_mode = INT_DEST_MODE; 441.32 441.33 if ( rte.vector >= FIRST_DEVICE_VECTOR ) 441.34 {
442.1 --- a/xen/arch/x86/mm.c Mon Aug 22 11:37:48 2005 -0700 442.2 +++ b/xen/arch/x86/mm.c Tue Aug 23 12:03:21 2005 -0700 442.3 @@ -444,7 +444,7 @@ get_page_from_l1e( 442.4 442.5 if ( unlikely(l1e_get_flags(l1e) & L1_DISALLOW_MASK) ) 442.6 { 442.7 - MEM_LOG("Bad L1 flags %x\n", l1e_get_flags(l1e) & L1_DISALLOW_MASK); 442.8 + MEM_LOG("Bad L1 flags %x", l1e_get_flags(l1e) & L1_DISALLOW_MASK); 442.9 return 0; 442.10 } 442.11 442.12 @@ -490,7 +490,7 @@ get_page_from_l2e( 442.13 442.14 if ( unlikely((l2e_get_flags(l2e) & L2_DISALLOW_MASK)) ) 442.15 { 442.16 - MEM_LOG("Bad L2 flags %x\n", l2e_get_flags(l2e) & L2_DISALLOW_MASK); 442.17 + MEM_LOG("Bad L2 flags %x", l2e_get_flags(l2e) & L2_DISALLOW_MASK); 442.18 return 0; 442.19 } 442.20 442.21 @@ -523,7 +523,7 @@ get_page_from_l3e( 442.22 442.23 if ( unlikely((l3e_get_flags(l3e) & L3_DISALLOW_MASK)) ) 442.24 { 442.25 - MEM_LOG("Bad L3 flags %x\n", l3e_get_flags(l3e) & L3_DISALLOW_MASK); 442.26 + MEM_LOG("Bad L3 flags %x", l3e_get_flags(l3e) & L3_DISALLOW_MASK); 442.27 return 0; 442.28 } 442.29 442.30 @@ -557,7 +557,7 @@ get_page_from_l4e( 442.31 442.32 if ( unlikely((l4e_get_flags(l4e) & L4_DISALLOW_MASK)) ) 442.33 { 442.34 - MEM_LOG("Bad L4 flags %x\n", l4e_get_flags(l4e) & L4_DISALLOW_MASK); 442.35 + MEM_LOG("Bad L4 flags %x", l4e_get_flags(l4e) & L4_DISALLOW_MASK); 442.36 return 0; 442.37 } 442.38 442.39 @@ -1025,7 +1025,7 @@ static inline int update_l1e(l1_pgentry_ 442.40 unlikely(o != l1e_get_intpte(ol1e)) ) 442.41 { 442.42 MEM_LOG("Failed to update %" PRIpte " -> %" PRIpte 442.43 - ": saw %" PRIpte "\n", 442.44 + ": saw %" PRIpte, 442.45 l1e_get_intpte(ol1e), 442.46 l1e_get_intpte(nl1e), 442.47 o); 442.48 @@ -1051,7 +1051,7 @@ static int mod_l1_entry(l1_pgentry_t *pl 442.49 { 442.50 if ( unlikely(l1e_get_flags(nl1e) & L1_DISALLOW_MASK) ) 442.51 { 442.52 - MEM_LOG("Bad L1 flags %x\n", 442.53 + MEM_LOG("Bad L1 flags %x", 442.54 l1e_get_flags(nl1e) & L1_DISALLOW_MASK); 442.55 return 0; 442.56 } 442.57 @@ -1113,7 +1113,7 @@ static int mod_l2_entry(l2_pgentry_t *pl 442.58 { 442.59 if ( unlikely(l2e_get_flags(nl2e) & L2_DISALLOW_MASK) ) 442.60 { 442.61 - MEM_LOG("Bad L2 flags %x\n", 442.62 + MEM_LOG("Bad L2 flags %x", 442.63 l2e_get_flags(nl2e) & L2_DISALLOW_MASK); 442.64 return 0; 442.65 } 442.66 @@ -1175,7 +1175,7 @@ static int mod_l3_entry(l3_pgentry_t *pl 442.67 { 442.68 if ( unlikely(l3e_get_flags(nl3e) & L3_DISALLOW_MASK) ) 442.69 { 442.70 - MEM_LOG("Bad L3 flags %x\n", 442.71 + MEM_LOG("Bad L3 flags %x", 442.72 l3e_get_flags(nl3e) & L3_DISALLOW_MASK); 442.73 return 0; 442.74 } 442.75 @@ -1237,7 +1237,7 @@ static int mod_l4_entry(l4_pgentry_t *pl 442.76 { 442.77 if ( unlikely(l4e_get_flags(nl4e) & L4_DISALLOW_MASK) ) 442.78 { 442.79 - MEM_LOG("Bad L4 flags %x\n", 442.80 + MEM_LOG("Bad L4 flags %x", 442.81 l4e_get_flags(nl4e) & L4_DISALLOW_MASK); 442.82 return 0; 442.83 } 442.84 @@ -1598,7 +1598,7 @@ static int set_foreigndom(unsigned int c 442.85 percpu_info[cpu].foreign = dom_io; 442.86 break; 442.87 default: 442.88 - MEM_LOG("Dom %u cannot set foreign dom\n", d->domain_id); 442.89 + MEM_LOG("Dom %u cannot set foreign dom", d->domain_id); 442.90 okay = 0; 442.91 break; 442.92 } 442.93 @@ -1831,7 +1831,7 @@ int do_mmuext_op( 442.94 case MMUEXT_FLUSH_CACHE: 442.95 if ( unlikely(!IS_CAPABLE_PHYSDEV(d)) ) 442.96 { 442.97 - MEM_LOG("Non-physdev domain tried to FLUSH_CACHE.\n"); 442.98 + MEM_LOG("Non-physdev domain tried to FLUSH_CACHE."); 442.99 okay = 0; 442.100 } 442.101 else 442.102 @@ -1845,7 +1845,7 @@ int do_mmuext_op( 442.103 if ( shadow_mode_external(d) ) 442.104 { 442.105 MEM_LOG("ignoring SET_LDT hypercall from external " 442.106 - "domain %u\n", d->domain_id); 442.107 + "domain %u", d->domain_id); 442.108 okay = 0; 442.109 break; 442.110 } 442.111 @@ -1916,7 +1916,7 @@ int do_mmuext_op( 442.112 unlikely(IS_XEN_HEAP_FRAME(page)) ) 442.113 { 442.114 MEM_LOG("Transferee has no reservation headroom (%d,%d), or " 442.115 - "page is in Xen heap (%lx), or dom is dying (%ld).\n", 442.116 + "page is in Xen heap (%lx), or dom is dying (%ld).", 442.117 e->tot_pages, e->max_pages, op.mfn, e->domain_flags); 442.118 okay = 0; 442.119 goto reassign_fail; 442.120 @@ -1937,7 +1937,7 @@ int do_mmuext_op( 442.121 unlikely(_nd != _d) ) 442.122 { 442.123 MEM_LOG("Bad page values %lx: ed=%p(%u), sd=%p," 442.124 - " caf=%08x, taf=%" PRtype_info "\n", 442.125 + " caf=%08x, taf=%" PRtype_info, 442.126 page_to_pfn(page), d, d->domain_id, 442.127 unpickle_domptr(_nd), x, page->u.inuse.type_info); 442.128 okay = 0; 442.129 @@ -2301,7 +2301,7 @@ int update_grant_pte_mapping( 442.130 if ( ((type_info & PGT_type_mask) != PGT_l1_page_table) || 442.131 !get_page_type(page, type_info & (PGT_type_mask|PGT_va_mask)) ) 442.132 { 442.133 - DPRINTK("Grant map attempted to update a non-L1 page\n"); 442.134 + MEM_LOG("Grant map attempted to update a non-L1 page"); 442.135 rc = GNTST_general_error; 442.136 goto failed; 442.137 } 442.138 @@ -2363,7 +2363,7 @@ int clear_grant_pte_mapping( 442.139 if ( ((type_info & PGT_type_mask) != PGT_l1_page_table) || 442.140 !get_page_type(page, type_info & (PGT_type_mask|PGT_va_mask)) ) 442.141 { 442.142 - DPRINTK("Grant map attempted to update a non-L1 page\n"); 442.143 + MEM_LOG("Grant map attempted to update a non-L1 page"); 442.144 rc = GNTST_general_error; 442.145 goto failed; 442.146 } 442.147 @@ -2378,7 +2378,7 @@ int clear_grant_pte_mapping( 442.148 /* Check that the virtual address supplied is actually mapped to frame. */ 442.149 if ( unlikely((l1e_get_intpte(ol1e) >> PAGE_SHIFT) != frame) ) 442.150 { 442.151 - DPRINTK("PTE entry %lx for address %lx doesn't match frame %lx\n", 442.152 + MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx", 442.153 (unsigned long)l1e_get_intpte(ol1e), addr, frame); 442.154 put_page_type(page); 442.155 rc = GNTST_general_error; 442.156 @@ -2388,7 +2388,7 @@ int clear_grant_pte_mapping( 442.157 /* Delete pagetable entry. */ 442.158 if ( unlikely(__put_user(0, (intpte_t *)va))) 442.159 { 442.160 - DPRINTK("Cannot delete PTE entry at %p.\n", va); 442.161 + MEM_LOG("Cannot delete PTE entry at %p", va); 442.162 put_page_type(page); 442.163 rc = GNTST_general_error; 442.164 goto failed; 442.165 @@ -2452,7 +2452,7 @@ int clear_grant_va_mapping(unsigned long 442.166 442.167 if ( unlikely(__get_user(ol1e.l1, &pl1e->l1) != 0) ) 442.168 { 442.169 - DPRINTK("Could not find PTE entry for address %lx\n", addr); 442.170 + MEM_LOG("Could not find PTE entry for address %lx", addr); 442.171 return GNTST_general_error; 442.172 } 442.173 442.174 @@ -2462,7 +2462,7 @@ int clear_grant_va_mapping(unsigned long 442.175 */ 442.176 if ( unlikely(l1e_get_pfn(ol1e) != frame) ) 442.177 { 442.178 - DPRINTK("PTE entry %lx for address %lx doesn't match frame %lx\n", 442.179 + MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx", 442.180 l1e_get_pfn(ol1e), addr, frame); 442.181 return GNTST_general_error; 442.182 } 442.183 @@ -2470,7 +2470,7 @@ int clear_grant_va_mapping(unsigned long 442.184 /* Delete pagetable entry. */ 442.185 if ( unlikely(__put_user(0, &pl1e->l1)) ) 442.186 { 442.187 - DPRINTK("Cannot delete PTE entry at %p.\n", (unsigned long *)pl1e); 442.188 + MEM_LOG("Cannot delete PTE entry at %p", (unsigned long *)pl1e); 442.189 return GNTST_general_error; 442.190 } 442.191 442.192 @@ -2930,7 +2930,7 @@ int revalidate_l1( 442.193 442.194 if ( unlikely(!get_page_from_l1e(nl1e, d)) ) 442.195 { 442.196 - MEM_LOG("ptwr: Could not re-validate l1 page\n"); 442.197 + MEM_LOG("ptwr: Could not re-validate l1 page"); 442.198 /* 442.199 * Make the remaining p.t's consistent before crashing, so the 442.200 * reference counts are correct. 442.201 @@ -3056,7 +3056,7 @@ static int ptwr_emulated_update( 442.202 /* Aligned access only, thank you. */ 442.203 if ( !access_ok(addr, bytes) || ((addr & (bytes-1)) != 0) ) 442.204 { 442.205 - MEM_LOG("ptwr_emulate: Unaligned or bad size ptwr access (%d, %lx)\n", 442.206 + MEM_LOG("ptwr_emulate: Unaligned or bad size ptwr access (%d, %lx)", 442.207 bytes, addr); 442.208 return X86EMUL_UNHANDLEABLE; 442.209 } 442.210 @@ -3089,7 +3089,7 @@ static int ptwr_emulated_update( 442.211 if (__copy_from_user(&pte, &linear_pg_table[l1_linear_offset(addr)], 442.212 sizeof(pte))) 442.213 { 442.214 - MEM_LOG("ptwr_emulate: Cannot read thru linear_pg_table\n"); 442.215 + MEM_LOG("ptwr_emulate: Cannot read thru linear_pg_table"); 442.216 return X86EMUL_UNHANDLEABLE; 442.217 } 442.218 442.219 @@ -3102,7 +3102,7 @@ static int ptwr_emulated_update( 442.220 (page_get_owner(page) != d) ) 442.221 { 442.222 MEM_LOG("ptwr_emulate: Page is mistyped or bad pte " 442.223 - "(%lx, %" PRtype_info ")\n", 442.224 + "(%lx, %" PRtype_info ")", 442.225 l1e_get_pfn(pte), page->u.inuse.type_info); 442.226 return X86EMUL_UNHANDLEABLE; 442.227 }
452.1 --- a/xen/arch/x86/vmx.c Mon Aug 22 11:37:48 2005 -0700 452.2 +++ b/xen/arch/x86/vmx.c Tue Aug 23 12:03:21 2005 -0700 452.3 @@ -1712,8 +1712,6 @@ asmlinkage void vmx_vmexit_handler(struc 452.4 default: 452.5 __vmx_bug(®s); /* should not happen */ 452.6 } 452.7 - 452.8 - return; 452.9 } 452.10 452.11 asmlinkage void load_cr2(void)
454.1 --- a/xen/arch/x86/vmx_io.c Mon Aug 22 11:37:48 2005 -0700 454.2 +++ b/xen/arch/x86/vmx_io.c Tue Aug 23 12:03:21 2005 -0700 454.3 @@ -631,7 +631,7 @@ static inline int irq_masked(unsigned lo 454.4 return ((eflags & X86_EFLAGS_IF) == 0); 454.5 } 454.6 454.7 -asmlinkage void vmx_intr_assist() 454.8 +asmlinkage void vmx_intr_assist(void) 454.9 { 454.10 int intr_type = 0; 454.11 int highest_vector; 454.12 @@ -714,8 +714,6 @@ void vmx_do_resume(struct vcpu *d) 454.13 454.14 /* We can't resume the guest if we're waiting on I/O */ 454.15 ASSERT(!test_bit(ARCH_VMX_IO_WAIT, &d->arch.arch_vmx.flags)); 454.16 - 454.17 - /* We always check for interrupts before resuming guest */ 454.18 } 454.19 454.20 #endif /* CONFIG_VMX */
459.1 --- a/xen/arch/x86/x86_32/traps.c Mon Aug 22 11:37:48 2005 -0700 459.2 +++ b/xen/arch/x86/x86_32/traps.c Tue Aug 23 12:03:21 2005 -0700 459.3 @@ -1,5 +1,6 @@ 459.4 459.5 #include <xen/config.h> 459.6 +#include <xen/domain_page.h> 459.7 #include <xen/init.h> 459.8 #include <xen/sched.h> 459.9 #include <xen/lib.h> 459.10 @@ -86,24 +87,33 @@ void show_registers(struct cpu_user_regs 459.11 459.12 void show_page_walk(unsigned long addr) 459.13 { 459.14 - l2_pgentry_t pmd; 459.15 - l1_pgentry_t *pte; 459.16 - 459.17 - if ( addr < PAGE_OFFSET ) 459.18 - return; 459.19 + unsigned long pfn = read_cr3() >> PAGE_SHIFT; 459.20 + intpte_t *ptab, ent; 459.21 459.22 printk("Pagetable walk from %08lx:\n", addr); 459.23 - 459.24 - pmd = idle_pg_table_l2[l2_linear_offset(addr)]; 459.25 - printk(" L2 = %"PRIpte" %s\n", l2e_get_intpte(pmd), 459.26 - (l2e_get_flags(pmd) & _PAGE_PSE) ? "(2/4MB)" : ""); 459.27 - if ( !(l2e_get_flags(pmd) & _PAGE_PRESENT) || 459.28 - (l2e_get_flags(pmd) & _PAGE_PSE) ) 459.29 + 459.30 +#ifdef CONFIG_X86_PAE 459.31 + ptab = map_domain_page(pfn); 459.32 + ent = ptab[l3_table_offset(addr)]; 459.33 + printk(" L3 = %"PRIpte"\n", ent); 459.34 + unmap_domain_page(ptab); 459.35 + if ( !(ent & _PAGE_PRESENT) ) 459.36 return; 459.37 + pfn = ent >> PAGE_SHIFT; 459.38 +#endif 459.39 459.40 - pte = __va(l2e_get_paddr(pmd)); 459.41 - pte += l1_table_offset(addr); 459.42 - printk(" L1 = %"PRIpte"\n", l1e_get_intpte(*pte)); 459.43 + ptab = map_domain_page(pfn); 459.44 + ent = ptab[l2_table_offset(addr)]; 459.45 + printk(" L2 = %"PRIpte" %s\n", ent, (ent & _PAGE_PSE) ? "(PSE)" : ""); 459.46 + unmap_domain_page(ptab); 459.47 + if ( !(ent & _PAGE_PRESENT) || (ent & _PAGE_PSE) ) 459.48 + return; 459.49 + pfn = ent >> PAGE_SHIFT; 459.50 + 459.51 + ptab = map_domain_page(ent >> PAGE_SHIFT); 459.52 + ent = ptab[l2_table_offset(addr)]; 459.53 + printk(" L1 = %"PRIpte"\n", ent); 459.54 + unmap_domain_page(ptab); 459.55 } 459.56 459.57 #define DOUBLEFAULT_STACK_SIZE 1024
516.1 --- a/xen/include/asm-x86/vmx.h Mon Aug 22 11:37:48 2005 -0700 516.2 +++ b/xen/include/asm-x86/vmx.h Tue Aug 23 12:03:21 2005 -0700 516.3 @@ -31,7 +31,7 @@ 516.4 extern void vmx_asm_vmexit_handler(struct cpu_user_regs); 516.5 extern void vmx_asm_do_resume(void); 516.6 extern void vmx_asm_do_launch(void); 516.7 -extern void vmx_intr_assist(); 516.8 +extern void vmx_intr_assist(void); 516.9 516.10 extern void arch_vmx_do_launch(struct vcpu *); 516.11 extern void arch_vmx_do_resume(struct vcpu *); 516.12 @@ -355,7 +355,7 @@ static inline int __vmxon (u64 addr) 516.13 } 516.14 516.15 /* Make sure that xen intercepts any FP accesses from current */ 516.16 -static inline void vmx_stts() 516.17 +static inline void vmx_stts(void) 516.18 { 516.19 unsigned long cr0; 516.20
527.1 --- a/xen/include/public/io/blkif.h Mon Aug 22 11:37:48 2005 -0700 527.2 +++ b/xen/include/public/io/blkif.h Tue Aug 23 12:03:21 2005 -0700 527.3 @@ -58,6 +58,9 @@ typedef struct blkif_response { 527.4 #define BLKIF_RSP_ERROR -1 /* non-specific 'error' */ 527.5 #define BLKIF_RSP_OKAY 0 /* non-specific 'okay' */ 527.6 527.7 +#define BLKIF_MAJOR(dev) ((dev)>>8) 527.8 +#define BLKIF_MINOR(dev) ((dev) & 0xff) 527.9 + 527.10 /* 527.11 * Generate blkif ring structures and types. 527.12 */