[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] stubdom: complete libxc support



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1211531723 -3600
# Node ID 90c37c32182ce8e1b8362000fac3c61ec68c2c2e
# Parent  2e6a51378451a225b20acee90bcd171996251fb4
stubdom: complete libxc support

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
---
 extras/mini-os/Config.mk             |    5 --
 extras/mini-os/Makefile              |    2 -
 extras/mini-os/arch/ia64/mm.c        |    8 ++++
 extras/mini-os/include/lib.h         |    1 
 extras/mini-os/include/mm.h          |    3 +
 extras/mini-os/include/x86/arch_mm.h |    5 --
 extras/mini-os/lib/sys.c             |   67 ++++++++++++-----------------------
 tools/libxc/Makefile                 |    8 ----
 tools/libxc/xc_core.c                |   18 ++++-----
 tools/libxc/xc_minios.c              |   17 +++++++-
 xen/common/libelf/libelf-private.h   |    2 -
 11 files changed, 62 insertions(+), 74 deletions(-)

diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/Config.mk
--- a/extras/mini-os/Config.mk  Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/Config.mk  Fri May 23 09:35:23 2008 +0100
@@ -41,10 +41,7 @@ extra_incl := $(foreach dir,$(EXTRA_INC)
 extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
 
 DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include
-
-ifeq ($(stubdom),y)
-DEF_CPPFLAGS += -DCONFIG_STUBDOM
-endif
+DEF_CPPFLAGS += -D__MINIOS__
 
 ifeq ($(libc),y)
 DEF_CPPFLAGS += -DHAVE_LIBC
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/Makefile
--- a/extras/mini-os/Makefile   Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/Makefile   Fri May 23 09:35:23 2008 +0100
@@ -96,7 +96,7 @@ endif
 endif
 
 ifeq ($(libc),y)
-LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -whole-archive -lxenguest -lxenctrl 
-no-whole-archive
 APP_LDLIBS += -lpci
 APP_LDLIBS += -lz
 LDLIBS += -lc
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/arch/ia64/mm.c
--- a/extras/mini-os/arch/ia64/mm.c     Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/arch/ia64/mm.c     Fri May 23 09:35:23 2008 +0100
@@ -131,6 +131,14 @@ arch_init_demand_mapping_area(unsigned l
 }
 
 /* Helper function used in gnttab.c. */
+void do_map_frames(unsigned long addr,
+        unsigned long *f, unsigned long n, unsigned long stride,
+       unsigned long increment, domid_t id, int may_fail, unsigned long prot)
+{
+       /* TODO */
+       ASSERT(0);
+}
+
 void*
 map_frames_ex(unsigned long* frames, unsigned long n, unsigned long stride,
        unsigned long increment, unsigned long alignment, domid_t id,
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/include/lib.h
--- a/extras/mini-os/include/lib.h      Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/include/lib.h      Fri May 23 09:35:23 2008 +0100
@@ -136,6 +136,7 @@ enum fd_type {
     FTYPE_CONSOLE,
     FTYPE_FILE,
     FTYPE_XENBUS,
+    FTYPE_XC,
     FTYPE_EVTCHN,
     FTYPE_SOCKET,
     FTYPE_TAP,
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/include/mm.h
--- a/extras/mini-os/include/mm.h       Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/include/mm.h       Fri May 23 09:35:23 2008 +0100
@@ -67,6 +67,9 @@ void *map_frames_ex(unsigned long *f, un
 void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride,
        unsigned long increment, unsigned long alignment, domid_t id,
        int may_fail, unsigned long prot);
+void do_map_frames(unsigned long addr,
+        unsigned long *f, unsigned long n, unsigned long stride,
+       unsigned long increment, domid_t id, int may_fail, unsigned long prot);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/include/x86/arch_mm.h
--- a/extras/mini-os/include/x86/arch_mm.h      Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/include/x86/arch_mm.h      Fri May 23 09:35:23 2008 +0100
@@ -219,11 +219,6 @@ static __inline__ paddr_t machine_to_phy
 
 #define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT)
 #define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, 
L1_PROT_RO)
-#ifndef __ASSEMBLY__
-void do_map_frames(unsigned long addr,
-        unsigned long *f, unsigned long n, unsigned long stride,
-       unsigned long increment, domid_t id, int may_fail, unsigned long prot);
-#endif
 #define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, 
DOMID_SELF, 0, L1_PROT_RO)
 
 #endif /* _ARCH_MM_H_ */
diff -r 2e6a51378451 -r 90c37c32182c extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Thu May 22 15:11:06 2008 +0100
+++ b/extras/mini-os/lib/sys.c  Fri May 23 09:35:23 2008 +0100
@@ -81,6 +81,7 @@
 
 #define NOFILE 32
 extern int xc_evtchn_close(int fd);
+extern int xc_interface_close(int fd);
 
 pthread_mutex_t fd_lock = PTHREAD_MUTEX_INITIALIZER;
 struct file files[NOFILE] = {
@@ -259,10 +260,7 @@ int read(int fd, void *buf, size_t nbyte
            }
            return ret * sizeof(union xenfb_in_event);
         }
-       case FTYPE_NONE:
-       case FTYPE_XENBUS:
-       case FTYPE_EVTCHN:
-       case FTYPE_BLK:
+       default:
            break;
     }
     printk("read(%d): Bad descriptor\n", fd);
@@ -295,12 +293,7 @@ int write(int fd, const void *buf, size_
        case FTYPE_TAP:
            netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
            return nbytes;
-       case FTYPE_NONE:
-       case FTYPE_XENBUS:
-       case FTYPE_EVTCHN:
-       case FTYPE_BLK:
-       case FTYPE_KBD:
-       case FTYPE_FB:
+       default:
            break;
     }
     printk("write(%d): Bad descriptor\n", fd);
@@ -351,15 +344,7 @@ int fsync(int fd) {
            }
            return 0;
        }
-       case FTYPE_NONE:
-       case FTYPE_CONSOLE:
-       case FTYPE_SOCKET:
-       case FTYPE_XENBUS:
-       case FTYPE_EVTCHN:
-       case FTYPE_TAP:
-       case FTYPE_BLK:
-       case FTYPE_KBD:
-       case FTYPE_FB:
+       default:
            break;
     }
     printk("fsync(%d): Bad descriptor\n", fd);
@@ -391,6 +376,9 @@ int close(int fd)
            files[fd].type = FTYPE_NONE;
            return res;
        }
+       case FTYPE_XC:
+           xc_interface_close(fd);
+           return 0;
        case FTYPE_EVTCHN:
             xc_evtchn_close(fd);
             return 0;
@@ -495,13 +483,7 @@ int fstat(int fd, struct stat *buf)
            stat_from_fs(buf, &stat);
            return 0;
        }
-       case FTYPE_NONE:
-       case FTYPE_XENBUS:
-       case FTYPE_EVTCHN:
-       case FTYPE_TAP:
-       case FTYPE_BLK:
-       case FTYPE_KBD:
-       case FTYPE_FB:
+       default:
            break;
     }
 
@@ -522,15 +504,7 @@ int ftruncate(int fd, off_t length)
            }
            return 0;
        }
-       case FTYPE_NONE:
-       case FTYPE_CONSOLE:
-       case FTYPE_SOCKET:
-       case FTYPE_XENBUS:
-       case FTYPE_EVTCHN:
-       case FTYPE_TAP:
-       case FTYPE_BLK:
-       case FTYPE_KBD:
-       case FTYPE_FB:
+       default:
            break;
     }
 
@@ -636,9 +610,10 @@ static const char file_types[] = {
     [FTYPE_NONE]       = 'N',
     [FTYPE_CONSOLE]    = 'C',
     [FTYPE_FILE]       = 'F',
-    [FTYPE_XENBUS]     = 'X',
+    [FTYPE_XENBUS]     = 'S',
+    [FTYPE_XC]         = 'X',
     [FTYPE_EVTCHN]     = 'E',
-    [FTYPE_SOCKET]     = 'S',
+    [FTYPE_SOCKET]     = 's',
     [FTYPE_TAP]                = 'T',
     [FTYPE_BLK]                = 'B',
     [FTYPE_KBD]                = 'K',
@@ -722,7 +697,7 @@ static int select_poll(int nfds, fd_set 
     /* Then see others as well. */
     for (i = 0; i < nfds; i++) {
        switch(files[i].type) {
-       case FTYPE_NONE:
+       default:
            if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, 
exceptfds))
                printk("bogus fd %d in select\n", i);
            /* Fallthrough.  */
@@ -1083,14 +1058,20 @@ int clock_gettime(clockid_t clk_id, stru
 
 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t 
offset)
 {
+    unsigned long n = (length + PAGE_SIZE - 1) / PAGE_SIZE;
+
     ASSERT(!start);
-    length = (length + PAGE_SIZE - 1) & PAGE_MASK;
     ASSERT(prot == (PROT_READ|PROT_WRITE));
-    ASSERT(flags == (MAP_SHARED|MAP_ANON) || flags == (MAP_PRIVATE|MAP_ANON));
-    ASSERT(fd == -1);
+    ASSERT((fd == -1 && (flags == (MAP_SHARED|MAP_ANON) || flags == 
(MAP_PRIVATE|MAP_ANON)))
+        || (fd != -1 && flags == MAP_SHARED));
     ASSERT(offset == 0);
 
-    return map_zero(length / PAGE_SIZE, 1);
+    if (fd == -1)
+        return map_zero(n, 1);
+    else if (files[fd].type == FTYPE_XC) {
+        unsigned long zero = 0;
+        return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0);
+    } else ASSERT(0);
 }
 #if defined(__x86_64__) || defined(__ia64__)
 __typeof__(mmap) mmap64 __attribute__((__alias__("mmap")));
@@ -1110,7 +1091,7 @@ int munmap(void *start, size_t length)
        call[i].args[0] = (unsigned long) &data[i];
        call[i].args[1] = 0;
        call[i].args[2] = 0;
-       call[i].args[3] = UVMF_INVLPG | UVMF_ALL;
+       call[i].args[3] = UVMF_INVLPG;
     }
 
     ret = HYPERVISOR_multicall(call, n);
diff -r 2e6a51378451 -r 90c37c32182c tools/libxc/Makefile
--- a/tools/libxc/Makefile      Thu May 22 15:11:06 2008 +0100
+++ b/tools/libxc/Makefile      Fri May 23 09:35:23 2008 +0100
@@ -5,11 +5,9 @@ MINOR    = 0
 MINOR    = 0
 
 CTRL_SRCS-y       :=
-ifneq ($(stubdom),y)
 CTRL_SRCS-y       += xc_core.c
 CTRL_SRCS-$(CONFIG_X86) += xc_core_x86.c
 CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
-endif
 CTRL_SRCS-y       += xc_domain.c
 CTRL_SRCS-y       += xc_evtchn.c
 CTRL_SRCS-y       += xc_misc.c
@@ -21,9 +19,7 @@ CTRL_SRCS-y       += xc_csched.c
 CTRL_SRCS-y       += xc_csched.c
 CTRL_SRCS-y       += xc_tbuf.c
 CTRL_SRCS-y       += xc_pm.c
-ifneq ($(stubdom),y)
 CTRL_SRCS-y       += xc_resume.c
-endif
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
@@ -33,15 +29,12 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c
-ifneq ($(stubdom),y)
 GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
 GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
-endif
 
 VPATH = ../../xen/common/libelf
 CFLAGS += -I../../xen/common/libelf
 
-ifneq ($(stubdom),y)
 GUEST_SRCS-y += libelf-tools.c libelf-loader.c
 GUEST_SRCS-y += libelf-dominfo.c libelf-relocate.c
 
@@ -55,7 +48,6 @@ GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_cpuid_x86.c
 GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
-endif
 
 -include $(XEN_TARGET_ARCH)/Makefile
 
diff -r 2e6a51378451 -r 90c37c32182c tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Thu May 22 15:11:06 2008 +0100
+++ b/tools/libxc/xc_core.c     Fri May 23 09:35:23 2008 +0100
@@ -64,7 +64,7 @@
 /* string table */
 struct xc_core_strtab {
     char       *strings;
-    uint16_t    current;
+    uint16_t    length;
     uint16_t    max;
 };
 
@@ -89,7 +89,7 @@ xc_core_strtab_init(void)
 
     /* index 0 represents none */
     strtab->strings[0] = '\0';
-    strtab->current = 1;
+    strtab->length = 1;
 
     return strtab;
 }
@@ -107,14 +107,14 @@ xc_core_strtab_get(struct xc_core_strtab
     uint16_t ret = 0;
     uint16_t len = strlen(name) + 1;
 
-    if ( strtab->current > UINT16_MAX - len )
+    if ( strtab->length > UINT16_MAX - len )
     {
         PERROR("too long string table");
         errno = E2BIG;
         return ret;
     }
     
-    if ( strtab->current + len > strtab->max )
+    if ( strtab->length + len > strtab->max )
     {
         char *tmp;
         if ( strtab->max > UINT16_MAX / 2 )
@@ -135,9 +135,9 @@ xc_core_strtab_get(struct xc_core_strtab
         strtab->max *= 2;
     }
 
-    ret = strtab->current;
-    strcpy(strtab->strings + strtab->current, name);
-    strtab->current += len;
+    ret = strtab->length;
+    strcpy(strtab->strings + strtab->length, name);
+    strtab->length += len;
     return ret;
 }
 
@@ -669,7 +669,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     offset += filesz;
 
     /* fixing up section header string table section header */
-    filesz = strtab->current;
+    filesz = strtab->length;
     sheaders->shdrs[strtab_idx].sh_offset = offset;
     sheaders->shdrs[strtab_idx].sh_size = filesz;
 
@@ -829,7 +829,7 @@ copy_done:
         goto out;
 
     /* elf section header string table: .shstrtab */
-    sts = dump_rtn(args, strtab->strings, strtab->current);
+    sts = dump_rtn(args, strtab->strings, strtab->length);
     if ( sts != 0 )
         goto out;
 
diff -r 2e6a51378451 -r 90c37c32182c tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c   Thu May 22 15:11:06 2008 +0100
+++ b/tools/libxc/xc_minios.c   Fri May 23 09:35:23 2008 +0100
@@ -35,11 +35,12 @@ extern struct wait_queue_head event_queu
 
 int xc_interface_open(void)
 {
-    return 0;
+    return alloc_fd(FTYPE_XC);
 }
 
 int xc_interface_close(int xc_handle)
 {
+    files[xc_handle].type = FTYPE_NONE;
     return 0;
 }
 
@@ -79,8 +80,12 @@ int xc_map_foreign_ranges(int xc_handle,
 int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
                           privcmd_mmap_entry_t *entries, int nr)
 {
-    printf("xc_map_foreign_ranges, TODO\n");
-    do_exit();
+    int i;
+    for (i = 0; i < nr; i++) {
+       unsigned long mfn = entries[i].mfn;
+        do_map_frames(entries[i].va, &mfn, entries[i].npages, 0, 1, dom, 0, 
L1_PROT);
+    }
+    return 0;
 }
 
 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
@@ -294,6 +299,12 @@ int xc_evtchn_unmask(int xce_handle, evt
     return 0;
 }
 
+/* Optionally flush file to disk and discard page cache */
+void discard_file_cache(int fd, int flush)
+{
+    if (flush)
+        fsync(fd);
+}
 /*
  * Local variables:
  * mode: C
diff -r 2e6a51378451 -r 90c37c32182c xen/common/libelf/libelf-private.h
--- a/xen/common/libelf/libelf-private.h        Thu May 22 15:11:06 2008 +0100
+++ b/xen/common/libelf/libelf-private.h        Fri May 23 09:35:23 2008 +0100
@@ -43,7 +43,7 @@
 #define bswap_16(x) swap16(x)
 #define bswap_32(x) swap32(x)
 #define bswap_64(x) swap64(x)
-#elif defined(__linux__) || defined(__Linux__)
+#elif defined(__linux__) || defined(__Linux__) || defined(__MINIOS__)
 #include <byteswap.h>
 #else
 #error Unsupported OS

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.