[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 11/21] mini-os: make frontends and xenbus optional
This adds compile-time logic to disable certain frontends in mini-os: - pcifront is disabled by default, enabled for ioemu - blkfront, netfront, fbfront, and kbdfront are enabled by default - xenbus is required for any frontend, and is enabled by default If all frontends and xenbus are disabled, mini-os will run without needing to communicate with xenstore, making it suitable to run the xenstore daemon. Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx> --- extras/mini-os/Makefile | 5 +++- extras/mini-os/apps/common.mk | 11 +++++++++ extras/mini-os/apps/ioemu.mk | 1 + extras/mini-os/console/xencons_ring.c | 15 ++++++++++-- extras/mini-os/files.mk | 12 +++++----- extras/mini-os/include/lib.h | 2 + extras/mini-os/kernel.c | 40 +++++++++++++++++++++++++++++++- extras/mini-os/lib/sys.c | 28 +++++++++++++++++++++++ extras/mini-os/main.c | 6 +++- 9 files changed, 106 insertions(+), 14 deletions(-) diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile index af7d0d4..7419211 100644 --- a/extras/mini-os/Makefile +++ b/extras/mini-os/Makefile @@ -70,7 +70,10 @@ ifeq ($(lwip),y) LWC := $(shell find $(LWIPDIR)/ -type f -name '*.c') LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC)) LWO := $(patsubst %.c,%.o,$(LWC)) -LWO += $(addprefix $(OBJ_DIR)/,lwip-arch.o lwip-net.o) +LWO += $(OBJ_DIR)/lwip-arch.o +ifeq ($(CONFIG_NETFRONT),y) +LWO += $(OBJ_DIR)/lwip-net.o +endif $(OBJ_DIR)/lwip.a: $(LWO) $(RM) $@ diff --git a/extras/mini-os/apps/common.mk b/extras/mini-os/apps/common.mk index 12b686d..1fd4c9f 100644 --- a/extras/mini-os/apps/common.mk +++ b/extras/mini-os/apps/common.mk @@ -1,11 +1,22 @@ # Defaults CONFIG_START_NETWORK ?= y CONFIG_SPARSE_BSS ?= y +CONFIG_BLKFRONT ?= y +CONFIG_NETFRONT ?= y +CONFIG_FBFRONT ?= y +CONFIG_KBDFRONT ?= y +CONFIG_XENBUS ?= y # Export items as compiler directives flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS +flags-$(CONFIG_PCIFRONT) += -DCONFIG_PCIFRONT +flags-$(CONFIG_BLKFRONT) += -DCONFIG_BLKFRONT +flags-$(CONFIG_NETFRONT) += -DCONFIG_NETFRONT +flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT +flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT +flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS DEF_CFLAGS += $(flags-y) diff --git a/extras/mini-os/apps/ioemu.mk b/extras/mini-os/apps/ioemu.mk index 7ea1d2f..e3a96da 100644 --- a/extras/mini-os/apps/ioemu.mk +++ b/extras/mini-os/apps/ioemu.mk @@ -1 +1,2 @@ CONFIG_QEMU_XS_ARGS=y +CONFIG_PCIFRONT=y diff --git a/extras/mini-os/console/xencons_ring.c b/extras/mini-os/console/xencons_ring.c index af0afed..c3eba35 100644 --- a/extras/mini-os/console/xencons_ring.c +++ b/extras/mini-os/console/xencons_ring.c @@ -189,6 +189,7 @@ struct consfront_dev *xencons_ring_init(void) void free_consfront(struct consfront_dev *dev) { +#ifdef CONFIG_XENBUS char* err = NULL; XenbusState state; @@ -217,6 +218,7 @@ void free_consfront(struct consfront_dev *dev) close: if (err) free(err); xenbus_unwatch_path_token(XBT_NIL, path, path); +#endif mask_evtchn(dev->evtchn); unbind_evtchn(dev->evtchn); @@ -231,16 +233,18 @@ close: struct consfront_dev *init_consfront(char *_nodename) { + struct consfront_dev *dev; + char nodename[256]; + static int consfrontends = 3; +#ifdef CONFIG_XENBUS xenbus_transaction_t xbt; char* err; char* message=NULL; int retry=0; char* msg = NULL; - char nodename[256]; char path[256]; - static int consfrontends = 3; - struct consfront_dev *dev; int res; +#endif if (!_nodename) snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends); @@ -257,6 +261,7 @@ struct consfront_dev *init_consfront(char *_nodename) dev->fd = -1; #endif +#ifdef CONFIG_XENBUS snprintf(path, sizeof(path), "%s/backend-id", nodename); if ((res = xenbus_read_integer(path)) < 0) return NULL; @@ -351,17 +356,21 @@ done: goto error; } } +#endif + unmask_evtchn(dev->evtchn); printk("**************************\n"); return dev; +#ifdef CONFIG_XENBUS error: free(msg); free(err); free_consfront(dev); return NULL; +#endif } void xencons_resume(void) diff --git a/extras/mini-os/files.mk b/extras/mini-os/files.mk index 5c1c6ef..be37a8b 100644 --- a/extras/mini-os/files.mk +++ b/extras/mini-os/files.mk @@ -1,7 +1,7 @@ -src-y += blkfront.c +src-$(CONFIG_BLKFRONT) += blkfront.c src-y += daytime.c src-y += events.c -src-y += fbfront.c +src-$(CONFIG_FBFRONT) += fbfront.c src-y += gntmap.c src-y += gnttab.c src-y += hypervisor.c @@ -9,8 +9,8 @@ src-y += kernel.c src-y += lock.c src-y += main.c src-y += mm.c -src-y += netfront.c -src-y += pcifront.c +src-$(CONFIG_NETFRONT) += netfront.c +src-$(CONFIG_PCIFRONT) += pcifront.c src-y += sched.c src-y += lib/ctype.c @@ -20,9 +20,9 @@ src-y += lib/stack_chk_fail.c src-y += lib/string.c src-y += lib/sys.c src-y += lib/xmalloc.c -src-y += lib/xs.c +src-$(CONFIG_XENBUS) += lib/xs.c -src-y += xenbus/xenbus.c +src-$(CONFIG_XENBUS) += xenbus/xenbus.c src-y += console/console.c src-y += console/xencons_ring.c diff --git a/extras/mini-os/include/lib.h b/extras/mini-os/include/lib.h index 12070c3..9c69440 100644 --- a/extras/mini-os/include/lib.h +++ b/extras/mini-os/include/lib.h @@ -182,11 +182,13 @@ extern struct file { struct { struct consfront_dev *dev; } cons; +#ifdef CONFIG_XENBUS struct { /* To each xenbus FD is associated a queue of watch events for this * FD. */ xenbus_event_queue events; } xenbus; +#endif }; int read; /* maybe available for read */ } files[]; diff --git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c index 2875bf1..9e490d5 100644 --- a/extras/mini-os/kernel.c +++ b/extras/mini-os/kernel.c @@ -46,8 +46,6 @@ #include <xen/features.h> #include <xen/version.h> -static struct netfront_dev *net_dev; - uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32]; void setup_xen_features(void) @@ -86,11 +84,16 @@ static void periodic_thread(void *p) } } +#ifdef CONFIG_NETFRONT +static struct netfront_dev *net_dev; + static void netfront_thread(void *p) { net_dev = init_netfront(NULL, NULL, NULL, NULL); } +#endif +#ifdef CONFIG_BLKFRONT static struct blkfront_dev *blk_dev; static struct blkfront_info blk_info; static uint64_t blk_size_read; @@ -255,6 +258,9 @@ static void blkfront_thread(void *p) #endif } } +#endif + +#ifdef CONFIG_FBFRONT #define WIDTH 800 #define HEIGHT 600 @@ -347,6 +353,9 @@ static void refresh_cursor(int new_x, int new_y) fbfront_drawhoriz(new_x + 1, new_x + 8, new_y, 0xffffffff); fbfront_update(fb_dev, new_x, new_y, 9, 9); } +#endif + +#ifdef CONFIG_KBDFRONT static struct kbdfront_dev *kbd_dev; static void kbdfront_thread(void *p) @@ -431,7 +440,9 @@ static void kbdfront_thread(void *p) schedule(); } } +#endif +#ifdef CONFIG_PCIFRONT static struct pcifront_dev *pci_dev; static void print_pcidev(unsigned int domain, unsigned int bus, unsigned int slot, unsigned int fun) @@ -455,6 +466,7 @@ static void pcifront_thread(void *p) printk("PCI devices:\n"); pcifront_scan(pci_dev, print_pcidev); } +#endif /* This should be overridden by the application we are linked against. */ __attribute__((weak)) int app_main(start_info_t *si) @@ -462,11 +474,21 @@ __attribute__((weak)) int app_main(start_info_t *si) printk("Dummy main: start_info=%p\n", si); create_thread("xenbus_tester", xenbus_tester, si); create_thread("periodic_thread", periodic_thread, si); +#ifdef CONFIG_NETFRONT create_thread("netfront", netfront_thread, si); +#endif +#ifdef CONFIG_BLKFRONT create_thread("blkfront", blkfront_thread, si); +#endif +#ifdef CONFIG_FBFRONT create_thread("fbfront", fbfront_thread, si); +#endif +#ifdef CONFIG_KBDFRONT create_thread("kbdfront", kbdfront_thread, si); +#endif +#ifdef CONFIG_PCIFRONT create_thread("pcifront", pcifront_thread, si); +#endif return 0; } @@ -522,8 +544,10 @@ void start_kernel(start_info_t *si) /* Init scheduler. */ init_sched(); +#ifdef CONFIG_XENBUS /* Init XenBus */ init_xenbus(); +#endif /* Call (possibly overridden) app_main() */ app_main(&start_info); @@ -534,20 +558,30 @@ void start_kernel(start_info_t *si) void stop_kernel(void) { +#ifdef CONFIG_NETFRONT if (net_dev) shutdown_netfront(net_dev); +#endif +#ifdef CONFIG_BLKFRONT if (blk_dev) shutdown_blkfront(blk_dev); +#endif +#ifdef CONFIG_FBFRONT if (fb_dev) shutdown_fbfront(fb_dev); +#endif +#ifdef CONFIG_KBDFRONT if (kbd_dev) shutdown_kbdfront(kbd_dev); +#endif +#ifdef CONFIG_PCIFRONT if (pci_dev) shutdown_pcifront(pci_dev); +#endif /* TODO: fs import */ @@ -560,8 +594,10 @@ void stop_kernel(void) fini_console(NULL); /* TODO: record new ring mfn & event in start_info */ +#ifdef CONFIG_XENBUS /* Reset XenBus */ fini_xenbus(); +#endif /* Reset timers */ fini_time(); diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c index b7b3aff..14e7780 100644 --- a/extras/mini-os/lib/sys.c +++ b/extras/mini-os/lib/sys.c @@ -241,6 +241,7 @@ int read(int fd, void *buf, size_t nbytes) case FTYPE_SOCKET: return lwip_read(files[fd].socket.fd, buf, nbytes); #endif +#ifdef CONFIG_NETFRONT case FTYPE_TAP: { ssize_t ret; ret = netfront_receive(files[fd].tap.dev, buf, nbytes); @@ -250,6 +251,8 @@ int read(int fd, void *buf, size_t nbytes) } return ret; } +#endif +#ifdef CONFIG_KBDFRONT case FTYPE_KBD: { int ret, n; n = nbytes / sizeof(union xenkbd_in_event); @@ -260,6 +263,8 @@ int read(int fd, void *buf, size_t nbytes) } return ret * sizeof(union xenkbd_in_event); } +#endif +#ifdef CONFIG_FBFRONT case FTYPE_FB: { int ret, n; n = nbytes / sizeof(union xenfb_in_event); @@ -270,6 +275,7 @@ int read(int fd, void *buf, size_t nbytes) } return ret * sizeof(union xenfb_in_event); } +#endif default: break; } @@ -297,9 +303,11 @@ int write(int fd, const void *buf, size_t nbytes) case FTYPE_SOCKET: return lwip_write(files[fd].socket.fd, (void*) buf, nbytes); #endif +#ifdef CONFIG_NETFRONT case FTYPE_TAP: netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes); return nbytes; +#endif default: break; } @@ -326,9 +334,11 @@ int close(int fd) default: files[fd].type = FTYPE_NONE; return 0; +#ifdef CONFIG_XENBUS case FTYPE_XENBUS: xs_daemon_close((void*)(intptr_t) fd); return 0; +#endif #ifdef HAVE_LWIP case FTYPE_SOCKET: { int res = lwip_close(files[fd].socket.fd); @@ -345,22 +355,30 @@ int close(int fd) case FTYPE_GNTMAP: minios_gnttab_close_fd(fd); return 0; +#ifdef CONFIG_NETFRONT case FTYPE_TAP: shutdown_netfront(files[fd].tap.dev); files[fd].type = FTYPE_NONE; return 0; +#endif +#ifdef CONFIG_BLKFRONT case FTYPE_BLK: shutdown_blkfront(files[fd].blk.dev); files[fd].type = FTYPE_NONE; return 0; +#endif +#ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].kbd.dev); files[fd].type = FTYPE_NONE; return 0; +#endif +#ifdef CONFIG_FBFRONT case FTYPE_FB: shutdown_fbfront(files[fd].fb.dev); files[fd].type = FTYPE_NONE; return 0; +#endif case FTYPE_SAVEFILE: case FTYPE_CONSOLE: fini_console(files[fd].cons.dev); @@ -611,6 +629,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; +#ifdef CONFIG_XENBUS case FTYPE_XENBUS: if (FD_ISSET(i, readfds)) { if (files[i].xenbus.events) @@ -621,6 +640,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce FD_CLR(i, writefds); FD_CLR(i, exceptfds); break; +#endif case FTYPE_EVTCHN: case FTYPE_TAP: case FTYPE_BLK: @@ -727,11 +747,19 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, /* Tell people we're going to sleep before looking at what they are * saying, hence letting them wake us if events happen between here and * schedule() */ +#ifdef CONFIG_NETFRONT add_waiter(w1, netfront_queue); +#endif add_waiter(w2, event_queue); +#ifdef CONFIG_BLKFRONT add_waiter(w3, blkfront_queue); +#endif +#ifdef CONFIG_XENBUS add_waiter(w4, xenbus_watch_queue); +#endif +#ifdef CONFIG_KBDFRONT add_waiter(w5, kbdfront_queue); +#endif add_waiter(w6, console_queue); if (readfds) diff --git a/extras/mini-os/main.c b/extras/mini-os/main.c index aeda548..73eb6fb 100644 --- a/extras/mini-os/main.c +++ b/extras/mini-os/main.c @@ -63,10 +63,12 @@ static void call_main(void *p) #ifdef CONFIG_SPARSE_BSS sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start); #endif -#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK) +#if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK) && defined(CONFIG_NETFRONT) start_networking(); #endif +#ifdef CONFIG_PCIFRONT create_thread("pcifront", pcifront_watches, NULL); +#endif #ifdef CONFIG_QEMU_XS_ARGS /* Fetch argc, argv from XenStore */ @@ -169,7 +171,7 @@ void _exit(int ret) close_all_files(); __libc_fini_array(); printk("main returned %d\n", ret); -#ifdef HAVE_LWIP +#if defined(HAVE_LWIP) && defined(CONFIG_NETFRONT) stop_networking(); #endif stop_kernel(); -- 1.7.7.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |