]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
Slightly modify the way balloon initialization is done in fdo.c
authorPaul Durrant <pdurrant@amazon.com>
Thu, 19 Nov 2020 09:58:11 +0000 (09:58 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Tue, 24 Nov 2020 09:53:20 +0000 (09:53 +0000)
Currently only one system start option "XEN:BALLOON=" modifies the behaviour
of FDO creation. A subsequent patch will add another option. This patch is
to avoid inconsistency in the code when that is done.

The FdoIsBalloonEnabled() function is replaced with FdoBalloonInitialize(),
which inlines what FdoCreate() would previously have done when
FdoIsBalloonEnabled() returned TRUE. A matching FdoBalloonTeardown()
function is also introduced for the sake of symmetry.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
src/xenbus/fdo.c

index 831ff463d6ce7537912e35090994396620d681ca..231748f14bdf20fee5bfca5cd83ad7cb7861fa3d 100644 (file)
@@ -5431,8 +5431,8 @@ __FdoFreeBuffer(
     Fdo->Buffer = NULL;
 }
 
-static BOOLEAN
-FdoIsBalloonEnabled(
+static NTSTATUS
+FdoBalloonInitialize(
     IN  PXENBUS_FDO Fdo
     )
 {
@@ -5442,8 +5442,6 @@ FdoIsBalloonEnabled(
     BOOLEAN         Enabled;
     NTSTATUS        status;
 
-    UNREFERENCED_PARAMETER(Fdo);
-
     Enabled = TRUE;
 
     status = RegistryQuerySystemStartOption(Key, &Option);
@@ -5458,9 +5456,22 @@ FdoIsBalloonEnabled(
     RegistryFreeSzValue(Option);
 
 done:
-    return Enabled;
+    return Enabled ?
+           BalloonInitialize(Fdo, &Fdo->BalloonContext) :
+           STATUS_SUCCESS;
 }
 
+static VOID
+FdoBalloonTeardown(
+    IN  PXENBUS_FDO Fdo
+    )
+{
+    if (Fdo->BalloonContext == NULL)
+        return;
+
+    BalloonTeardown(Fdo->BalloonContext);
+    Fdo->BalloonContext = NULL;
+}
 NTSTATUS
 FdoCreate(
     IN  PDEVICE_OBJECT          PhysicalDeviceObject
@@ -5581,11 +5592,9 @@ FdoCreate(
     if (!NT_SUCCESS(status))
         goto fail19;
 
-    if (FdoIsBalloonEnabled(Fdo)) {
-        status = BalloonInitialize(Fdo, &Fdo->BalloonContext);
-        if (!NT_SUCCESS(status))
-            goto fail20;
-    }
+    status = FdoBalloonInitialize(Fdo);
+    if (!NT_SUCCESS(status))
+        goto fail20;
 
     status = DebugGetInterface(__FdoGetDebugContext(Fdo),
                                XENBUS_DEBUG_INTERFACE_VERSION_MAX,
@@ -5826,10 +5835,7 @@ FdoDestroy(
         RtlZeroMemory(&Fdo->DebugInterface,
                       sizeof (XENBUS_DEBUG_INTERFACE));
 
-        if (Fdo->BalloonContext != NULL) {
-            BalloonTeardown(Fdo->BalloonContext);
-            Fdo->BalloonContext = NULL;
-        }
+        FdoBalloonTeardown(Fdo);
 
         UnplugTeardown(Fdo->UnplugContext);
         Fdo->UnplugContext = NULL;