From owner-svn-src-all@FreeBSD.ORG Tue Sep 30 16:53:09 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A0052FAF; Tue, 30 Sep 2014 16:53:09 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8C01F90F; Tue, 30 Sep 2014 16:53:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8UGr9Y2097237; Tue, 30 Sep 2014 16:53:09 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8UGr9MP097236; Tue, 30 Sep 2014 16:53:09 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201409301653.s8UGr9MP097236@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: Roger Pau Monné Date: Tue, 30 Sep 2014 16:53:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r272312 - head/sys/dev/xen/balloon X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Sep 2014 16:53:09 -0000 Author: royger Date: Tue Sep 30 16:53:08 2014 New Revision: 272312 URL: http://svnweb.freebsd.org/changeset/base/272312 Log: xen: make xen balloon a driver that depends on xenstore This is done so we can prevent the Xen Balloon driver from attaching before xenstore is setup. Sponsored by: Citrix Systems R&D dev/xen/balloon/balloon.c: - Make xen balloon a driver that depends on xenstore. Modified: head/sys/dev/xen/balloon/balloon.c Modified: head/sys/dev/xen/balloon/balloon.c ============================================================================== --- head/sys/dev/xen/balloon/balloon.c Tue Sep 30 16:49:17 2014 (r272311) +++ head/sys/dev/xen/balloon/balloon.c Tue Sep 30 16:53:08 2014 (r272312) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -348,25 +349,50 @@ watch_target(struct xs_watch *watch, set_new_target(new_target >> KB_TO_PAGE_SHIFT); } -static void -balloon_init_watcher(void *arg) +/*------------------ Private Device Attachment Functions --------------------*/ +/** + * \brief Identify instances of this device type in the system. + * + * \param driver The driver performing this identify action. + * \param parent The NewBus parent device for any devices this method adds. + */ +static void +xenballoon_identify(driver_t *driver __unused, device_t parent) { - int err; - - if (!is_running_on_xen()) - return; + /* + * A single device instance for our driver is always present + * in a system operating under Xen. + */ + BUS_ADD_CHILD(parent, 0, driver->name, 0); +} - err = xs_register_watch(&target_watch); - if (err) - printf("Failed to set balloon watcher\n"); +/** + * \brief Probe for the existance of the Xen Balloon device + * + * \param dev NewBus device_t for this Xen control instance. + * + * \return Always returns 0 indicating success. + */ +static int +xenballoon_probe(device_t dev) +{ + device_set_desc(dev, "Xen Balloon Device"); + return (0); } -SYSINIT(balloon_init_watcher, SI_SUB_PSEUDO, SI_ORDER_ANY, - balloon_init_watcher, NULL); -static void -balloon_init(void *arg) +/** + * \brief Attach the Xen Balloon device. + * + * \param dev NewBus device_t for this Xen control instance. + * + * \return On success, 0. Otherwise an errno value indicating the + * type of failure. + */ +static int +xenballoon_attach(device_t dev) { + int err; #ifndef XENHVM vm_page_t page; unsigned long pfn; @@ -374,9 +400,6 @@ balloon_init(void *arg) #define max_pfn HYPERVISOR_shared_info->arch.max_pfn #endif - if (!is_running_on_xen()) - return; - mtx_init(&balloon_mutex, "balloon_mutex", NULL, MTX_DEF); #ifndef XENHVM @@ -403,17 +426,27 @@ balloon_init(void *arg) #endif target_watch.callback = watch_target; - - return; -} -SYSINIT(balloon_init, SI_SUB_PSEUDO, SI_ORDER_ANY, balloon_init, NULL); -void balloon_update_driver_allowance(long delta); + err = xs_register_watch(&target_watch); + if (err) + device_printf(dev, + "xenballon: failed to set balloon watcher\n"); -void -balloon_update_driver_allowance(long delta) -{ - mtx_lock(&balloon_mutex); - bs.driver_pages += delta; - mtx_unlock(&balloon_mutex); + return (err); } + +/*-------------------- Private Device Attachment Data -----------------------*/ +static device_method_t xenballoon_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, xenballoon_identify), + DEVMETHOD(device_probe, xenballoon_probe), + DEVMETHOD(device_attach, xenballoon_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(xenballoon, xenballoon_driver, xenballoon_methods, 0); +devclass_t xenballoon_devclass; + +DRIVER_MODULE(xenballoon, xenstore, xenballoon_driver, xenballoon_devclass, + NULL, NULL);