Date: Mon, 16 Feb 2009 17:45:30 +0000 (UTC) From: Doug Rabson <dfr@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r188687 - in user/dfr/xenhvm/7/sys/dev/xen: blkfront console netfront Message-ID: <200902161745.n1GHjUJ8075049@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dfr Date: Mon Feb 16 17:45:29 2009 New Revision: 188687 URL: http://svn.freebsd.org/changeset/base/188687 Log: Diff reduction with user/dfr/xenhvm/6. Modified: user/dfr/xenhvm/7/sys/dev/xen/blkfront/blkfront.c user/dfr/xenhvm/7/sys/dev/xen/console/console.c user/dfr/xenhvm/7/sys/dev/xen/console/xencons_ring.c user/dfr/xenhvm/7/sys/dev/xen/netfront/netfront.c Modified: user/dfr/xenhvm/7/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- user/dfr/xenhvm/7/sys/dev/xen/blkfront/blkfront.c Mon Feb 16 17:43:45 2009 (r188686) +++ user/dfr/xenhvm/7/sys/dev/xen/blkfront/blkfront.c Mon Feb 16 17:45:29 2009 (r188687) @@ -40,17 +40,17 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/vmparam.h> -#include <xen/hypervisor.h> #include <machine/xen/xen-os.h> +#include <machine/xen/xenfunc.h> +#include <xen/hypervisor.h> #include <xen/xen_intr.h> #include <xen/evtchn.h> +#include <xen/gnttab.h> #include <xen/interface/grant_table.h> #include <xen/interface/io/protocols.h> #include <xen/xenbus/xenbusvar.h> #include <geom/geom_disk.h> -#include <machine/xen/xenfunc.h> -#include <xen/gnttab.h> #include <dev/xen/blkfront/block.h> @@ -106,7 +106,7 @@ static char * blkif_status_name[] = { #endif #define WPRINTK(fmt, args...) printf("[XEN] " fmt, ##args) #if 0 -#define DPRINTK(fmt, args...) printf("[XEN] %s:%d" fmt ".\n", __FUNCTION__, __LINE__,##args) +#define DPRINTK(fmt, args...) printf("[XEN] %s:%d: " fmt ".\n", __func__, __LINE__, ##args) #else #define DPRINTK(fmt, args...) #endif @@ -138,7 +138,6 @@ pfn_to_mfn(vm_paddr_t pfn) return (phystomach(pfn << PAGE_SHIFT) >> PAGE_SHIFT); } - /* * Translate Linux major/minor to an appropriate name and unit * number. For HVM guests, this allows us to use the same drive names @@ -323,17 +322,17 @@ blkfront_probe(device_t dev) static int blkfront_attach(device_t dev) { - int err, vdevice, i, unit; + int error, vdevice, i, unit; struct blkfront_info *info; const char *name; /* FIXME: Use dynamic device id if this is not set. */ - err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), + error = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), "virtual-device", NULL, "%i", &vdevice); - if (err) { - xenbus_dev_fatal(dev, err, "reading virtual-device"); + if (error) { + xenbus_dev_fatal(dev, error, "reading virtual-device"); printf("couldn't find virtual device"); - return (err); + return (error); } blkfront_vdevice_to_unit(vdevice, &unit, &name); @@ -362,9 +361,22 @@ blkfront_attach(device_t dev) /* Front end dir is a number, which is used as the id. */ info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0); - err = talk_to_backend(dev, info); - if (err) - return (err); + error = talk_to_backend(dev, info); + if (error) + return (error); + + return (0); +} + +static int +blkfront_suspend(device_t dev) +{ + struct blkfront_info *info = device_get_softc(dev); + + /* Prevent new requests being issued until we fix things up. */ + mtx_lock(&blkif_io_lock); + info->connected = BLKIF_STATE_SUSPENDED; + mtx_unlock(&blkif_io_lock); return (0); } @@ -375,16 +387,14 @@ blkfront_resume(device_t dev) struct blkfront_info *info = device_get_softc(dev); int err; - DPRINTK("blkfront_resume: %s\n", dev->nodename); + DPRINTK("blkfront_resume: %s\n", xenbus_get_node(dev)); blkif_free(info, 1); - err = talk_to_backend(dev, info); - if (info->connected == BLKIF_STATE_SUSPENDED && !err) blkif_recover(info); - return err; + return (err); } /* Common code used when first setting up, and when resuming. */ @@ -425,6 +435,7 @@ talk_to_backend(device_t dev, struct blk message = "writing protocol"; goto abort_transaction; } + err = xenbus_transaction_end(xbt, 0); if (err) { if (err == EAGAIN) @@ -462,8 +473,8 @@ setup_blkring(device_t dev, struct blkfr SHARED_RING_INIT(sring); FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); - error = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT), - &info->ring_ref); + error = xenbus_grant_ring(dev, + (vtomach(info->ring.sring) >> PAGE_SHIFT), &info->ring_ref); if (error) { free(sring, M_DEVBUF); info->ring.sring = NULL; @@ -471,11 +482,11 @@ setup_blkring(device_t dev, struct blkfr } error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), - "xbd", (driver_intr_t *)blkif_int, info, - INTR_TYPE_BIO | INTR_MPSAFE, &info->irq); + "xbd", (driver_intr_t *)blkif_int, info, + INTR_TYPE_BIO | INTR_MPSAFE, &info->irq); if (error) { xenbus_dev_fatal(dev, error, - "bind_evtchn_to_irqhandler failed"); + "bind_evtchn_to_irqhandler failed"); goto fail; } @@ -494,7 +505,7 @@ blkfront_backend_changed(device_t dev, X { struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront:backend_changed.\n"); + DPRINTK("backend_state=%d\n", backend_state); switch (backend_state) { case XenbusStateUnknown: @@ -707,7 +718,7 @@ blkif_open(struct disk *dp) struct xb_softc *sc = (struct xb_softc *)dp->d_drv1; if (sc == NULL) { - printk("xb%d: not found", sc->xb_unit); + printf("xb%d: not found", sc->xb_unit); return (ENXIO); } @@ -1019,9 +1030,11 @@ blkif_recover(struct blkfront_info *info blkif_request_t *req; struct blk_shadow *copy; + if (!info->sc) + return; + /* Stage 1: Make a safe copy of the shadow state. */ copy = (struct blk_shadow *)malloc(sizeof(info->shadow), M_DEVBUF, M_NOWAIT|M_ZERO); - PANIC_IF(copy == NULL); memcpy(copy, info->shadow, sizeof(info->shadow)); /* Stage 2: Set up free list. */ @@ -1084,7 +1097,7 @@ static device_method_t blkfront_methods[ DEVMETHOD(device_attach, blkfront_attach), DEVMETHOD(device_detach, blkfront_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), - DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_suspend, blkfront_suspend), DEVMETHOD(device_resume, blkfront_resume), /* Xenbus interface */ Modified: user/dfr/xenhvm/7/sys/dev/xen/console/console.c ============================================================================== --- user/dfr/xenhvm/7/sys/dev/xen/console/console.c Mon Feb 16 17:43:45 2009 (r188686) +++ user/dfr/xenhvm/7/sys/dev/xen/console/console.c Mon Feb 16 17:45:29 2009 (r188687) @@ -5,6 +5,7 @@ #include <sys/module.h> #include <sys/systm.h> #include <sys/consio.h> +#include <sys/priv.h> #include <sys/proc.h> #include <sys/uio.h> #include <sys/tty.h> @@ -19,7 +20,7 @@ #include <xen/xen_intr.h> #include <sys/cons.h> #include <sys/proc.h> -#include <sys/priv.h> +#include <sys/kdb.h> #include <dev/xen/console/xencons_ring.h> #include <xen/interface/io/console.h> @@ -44,7 +45,7 @@ static void xc_shutdown(void *arg, int h static int xc_mute; static void xcons_force_flush(void); -static int xencons_priv_interrupt(void *); +static void xencons_priv_interrupt(void *); static cn_probe_t xccnprobe; static cn_init_t xccninit; @@ -141,12 +142,17 @@ xccngetc(struct consdev *dev) return 0; do { if ((c = xccncheckc(dev)) == -1) { - /* polling without sleeping in Xen doesn't work well. - * Sleeping gives other things like clock a chance to - * run - */ - tsleep(&cn_mtx, PWAIT | PCATCH, "console sleep", - XC_POLLTIME); +#ifdef KDB + if (!kdb_active) +#endif + /* + * Polling without sleeping in Xen + * doesn't work well. Sleeping gives + * other things like clock a chance to + * run + */ + tsleep(&cn_mtx, PWAIT | PCATCH, + "console sleep", XC_POLLTIME); } } while(c == -1); return c; @@ -156,11 +162,13 @@ int xccncheckc(struct consdev *dev) { int ret = (xc_mute ? 0 : -1); - if (xencons_has_input()) - xencons_handle_input(NULL); + + if (xencons_has_input()) + xencons_handle_input(NULL); CN_LOCK(cn_mtx); if ((rp - rc)) { + if (kdb_active) printf("%s:%d\n", __func__, __LINE__); /* we need to return only one char */ ret = (int)rbuf[RBUF_MASK(rc)]; rc++; @@ -237,7 +245,6 @@ xc_attach(device_t dev) int error; struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev); - if (xen_start_info->flags & SIF_INITDOMAIN) { xc_consdev.cn_putc = xccnputc_dom0; } @@ -265,13 +272,13 @@ xc_attach(device_t dev) VIRQ_CONSOLE, 0, "console", + NULL, xencons_priv_interrupt, - NULL, INTR_TYPE_TTY, NULL); + INTR_TYPE_TTY, NULL); KASSERT(error >= 0, ("can't register console interrupt")); } - /* register handler to flush console on shutdown */ if ((EVENTHANDLER_REGISTER(shutdown_post_sync, xc_shutdown, NULL, SHUTDOWN_PRI_DEFAULT)) == NULL) @@ -303,7 +310,11 @@ xencons_rx(char *buf, unsigned len) HYPERVISOR_shared_info->evtchn_mask[0]); #endif for (i = 0; i < len; i++) { - if (xen_console_up) + if (xen_console_up +#ifdef DDB + && !kdb_active +#endif + ) (*linesw[tp->t_line]->l_rint)(buf[i], tp); else rbuf[RBUF_MASK(rp++)] = buf[i]; @@ -348,7 +359,7 @@ xencons_tx(void) __xencons_tx_flush(); } -static int +static void xencons_priv_interrupt(void *arg) { @@ -359,7 +370,6 @@ xencons_priv_interrupt(void *arg) xencons_rx(rbuf, l); xencons_tx(); - return (FILTER_HANDLED); } int @@ -387,7 +397,7 @@ xcopen(struct cdev *dev, int flag, int m tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; xcparam(tp, &tp->t_termios); ttsetwater(tp); - } else if (tp->t_state & TS_XCLUDE && suser(td)) { + } else if (tp->t_state & TS_XCLUDE && priv_check(td, PRIV_TTY_EXCLUSIVE)) { splx(s); return (EBUSY); } @@ -558,12 +568,3 @@ xcons_force_flush(void) } DRIVER_MODULE(xc, nexus, xc_driver, xc_devclass, 0, 0); -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 8 - * tab-width: 4 - * indent-tabs-mode: t - * End: - */ Modified: user/dfr/xenhvm/7/sys/dev/xen/console/xencons_ring.c ============================================================================== --- user/dfr/xenhvm/7/sys/dev/xen/console/xencons_ring.c Mon Feb 16 17:43:45 2009 (r188686) +++ user/dfr/xenhvm/7/sys/dev/xen/console/xencons_ring.c Mon Feb 16 17:45:29 2009 (r188687) @@ -13,19 +13,24 @@ __FBSDID("$FreeBSD$"); #include <sys/conf.h> #include <sys/kernel.h> #include <sys/bus.h> +#include <sys/cons.h> + #include <machine/stdarg.h> #include <machine/xen/xen-os.h> #include <xen/hypervisor.h> #include <xen/xen_intr.h> #include <sys/cons.h> +#include <xen/xen_intr.h> +#include <xen/evtchn.h> +#include <xen/interface/io/console.h> #include <dev/xen/console/xencons_ring.h> #include <xen/evtchn.h> #include <xen/interface/io/console.h> - #define console_evtchn console.domU.evtchn +static unsigned int console_irq; extern char *console_page; extern struct mtx cn_mtx; @@ -60,7 +65,8 @@ xencons_ring_send(const char *data, unsi sent = 0; mb(); - PANIC_IF((prod - cons) > sizeof(intf->out)); + KASSERT((prod - cons) <= sizeof(intf->out), + ("console send ring inconsistent")); while ((sent < len) && ((prod - cons) < sizeof(intf->out))) intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; @@ -119,15 +125,18 @@ xencons_ring_init(void) return 0; err = bind_caller_port_to_irqhandler(xen_start_info->console_evtchn, - "xencons", xencons_handle_input, NULL, - INTR_TYPE_MISC | INTR_MPSAFE, NULL); + "xencons", xencons_handle_input, NULL, + INTR_TYPE_MISC | INTR_MPSAFE, &console_irq); if (err) { return err; } return 0; } -#ifdef notyet + +extern void xencons_suspend(void); +extern void xencons_resume(void); + void xencons_suspend(void) { @@ -135,7 +144,7 @@ xencons_suspend(void) if (!xen_start_info->console_evtchn) return; - unbind_evtchn_from_irqhandler(xen_start_info->console_evtchn, NULL); + unbind_from_irqhandler(console_irq); } void @@ -144,7 +153,7 @@ xencons_resume(void) (void)xencons_ring_init(); } -#endif + /* * Local variables: * mode: C Modified: user/dfr/xenhvm/7/sys/dev/xen/netfront/netfront.c ============================================================================== --- user/dfr/xenhvm/7/sys/dev/xen/netfront/netfront.c Mon Feb 16 17:43:45 2009 (r188686) +++ user/dfr/xenhvm/7/sys/dev/xen/netfront/netfront.c Mon Feb 16 17:45:29 2009 (r188687) @@ -24,7 +24,6 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/sockio.h> #include <sys/mbuf.h> -#include <sys/lock.h> #include <sys/malloc.h> #include <sys/module.h> #include <sys/kernel.h> @@ -64,18 +63,21 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/xen/xen-os.h> +#include <machine/xen/xenfunc.h> #include <xen/hypervisor.h> #include <xen/xen_intr.h> #include <xen/evtchn.h> #include <xen/gnttab.h> #include <xen/interface/memory.h> -#include <dev/xen/netfront/mbufq.h> -#include <machine/xen/features.h> #include <xen/interface/io/netif.h> #include <xen/xenbus/xenbusvar.h> +#include <dev/xen/netfront/mbufq.h> + #include "xenbus_if.h" +#define XN_CSUM_FEATURES (CSUM_TCP | CSUM_UDP) + #define GRANT_INVALID_REF 0 #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE) @@ -330,9 +332,12 @@ xennet_get_rx_ref(struct netfront_info * printf("[XEN] " fmt, ##args) #define WPRINTK(fmt, args...) \ printf("[XEN] " fmt, ##args) +#if 0 #define DPRINTK(fmt, args...) \ printf("[XEN] %s: " fmt, __func__, ##args) - +#else +#define DPRINTK(fmt, args...) +#endif static __inline struct mbuf* makembuf (struct mbuf *buf) @@ -352,7 +357,7 @@ makembuf (struct mbuf *buf) m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); m->m_ext.ext_args = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT); - + return m; } @@ -490,11 +495,6 @@ talk_to_backend(device_t dev, struct net message = "writing feature-rx-notify"; goto abort_transaction; } - err = xenbus_printf(xbt, node, "feature-no-csum-offload", "%d", 1); - if (err) { - message = "writing feature-no-csum-offload"; - goto abort_transaction; - } err = xenbus_printf(xbt, node, "feature-sg", "%d", 1); if (err) { message = "writing feature-sg"; @@ -570,7 +570,7 @@ setup_device(device_t dev, struct netfro goto fail; error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), - "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, &info->irq); + "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, &info->irq); if (error) { xenbus_dev_fatal(dev, error, @@ -588,6 +588,24 @@ setup_device(device_t dev, struct netfro } /** + * If this interface has an ipv4 address, send an arp for it. This + * helps to get the network going again after migrating hosts. + */ +static void +netfront_send_fake_arp(device_t dev, struct netfront_info *info) +{ + struct ifnet *ifp; + struct ifaddr *ifa; + + ifp = info->xn_ifp; + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family == AF_INET) { + arp_ifinit(ifp, ifa); + } + } +} + +/** * Callback received when the backend's state changes. */ static void @@ -612,9 +630,7 @@ netfront_backend_changed(device_t dev, X if (network_connect(sc) != 0) break; xenbus_set_state(dev, XenbusStateConnected); -#ifdef notyet - (void)send_fake_arp(netdev); -#endif + netfront_send_fake_arp(dev, sc); break; case XenbusStateClosing: xenbus_set_state(dev, XenbusStateClosed); @@ -1236,12 +1252,11 @@ xennet_get_responses(struct netfront_inf gnttab_release_grant_reference(&np->gref_rx_head, ref); next: - if (m == NULL) - break; - - m->m_len = rx->status; - m->m_data += rx->offset; - m0->m_pkthdr.len += rx->status; + if (m != NULL) { + m->m_len = rx->status; + m->m_data += rx->offset; + m0->m_pkthdr.len += rx->status; + } if (!(rx->flags & NETRXF_more_data)) break; @@ -1348,10 +1363,10 @@ xn_start_locked(struct ifnet *ifp) mfn, GNTMAP_readonly); tx->gref = sc->grant_tx_ref[id] = ref; tx->size = new_m->m_pkthdr.len; -#if 0 - tx->flags = (skb->ip_summed == CHECKSUM_HW) ? NETTXF_csum_blank : 0; -#endif - tx->flags = 0; + if (new_m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) + tx->flags = NETTXF_csum_blank | NETTXF_data_validated; + else + tx->flags = 0; new_m->m_next = NULL; new_m->m_nextpkt = NULL; @@ -1446,9 +1461,9 @@ xn_ioctl(struct ifnet *ifp, u_long cmd, if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) xn_ifinit_locked(sc); arp_ifinit(ifp, ifa); - XN_UNLOCK(sc); + XN_UNLOCK(sc); } else { - XN_UNLOCK(sc); + XN_UNLOCK(sc); error = ether_ioctl(ifp, cmd, data); } break; @@ -1716,11 +1731,9 @@ create_netdev(device_t dev) ifp->if_mtu = ETHERMTU; ifp->if_snd.ifq_maxlen = NET_TX_RING_SIZE - 1; -#ifdef notyet ifp->if_hwassist = XN_CSUM_FEATURES; ifp->if_capabilities = IFCAP_HWCSUM; ifp->if_capenable = ifp->if_capabilities; -#endif ether_ifattach(ifp, np->mac); callout_init(&np->xn_stat_ch, CALLOUT_MPSAFE);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902161745.n1GHjUJ8075049>