Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Sep 2014 16:53:09 +0000 (UTC)
From:      Roger Pau Monné <royger@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272312 - head/sys/dev/xen/balloon
Message-ID:  <201409301653.s8UGr9MP097236@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/malloc.h>
 #include <sys/mutex.h>
 #include <sys/sysctl.h>
+#include <sys/module.h>
 
 #include <vm/vm.h>
 #include <vm/vm_page.h>
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409301653.s8UGr9MP097236>