mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0028-v2v-o-rhv-upload-Always-fetch-server-options-when-op.patch

d0ea73
From 1d2058c08b9eff607127d199b574273100e9ba55 Mon Sep 17 00:00:00 2001
d0ea73
From: "Richard W.M. Jones" <rjones@redhat.com>
d0ea73
Date: Tue, 19 Jun 2018 18:02:21 +0100
d0ea73
Subject: [PATCH] v2v: -o rhv-upload: Always fetch server options when opening
d0ea73
 the connection.
d0ea73
MIME-Version: 1.0
d0ea73
Content-Type: text/plain; charset=UTF-8
d0ea73
Content-Transfer-Encoding: 8bit
d0ea73
d0ea73
Previously we lazily requested the server options in the can_*
d0ea73
callbacks.  The can_* callbacks are always called by nbdkit straight
d0ea73
after open, so this just adds complexity for no benefit.  This change
d0ea73
simply makes the code always fetch the server options during the open
d0ea73
callback.
d0ea73
d0ea73
This is — functionally at least — mostly just refactoring.  However I
d0ea73
also added a useful debug message so we can see what features the
d0ea73
imageio server is offering.
d0ea73
d0ea73
(cherry picked from commit a1e1f6ec887c2a7973612d2edf7066fd3194ba0b)
d0ea73
---
d0ea73
 v2v/rhv-upload-plugin.py | 63 +++++++++++++++++++---------------------
d0ea73
 1 file changed, 30 insertions(+), 33 deletions(-)
d0ea73
d0ea73
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
d0ea73
index 5c036c46a..f215eaecf 100644
d0ea73
--- a/v2v/rhv-upload-plugin.py
d0ea73
+++ b/v2v/rhv-upload-plugin.py
d0ea73
@@ -165,34 +165,13 @@ def open(readonly):
d0ea73
         context = context
d0ea73
     )
d0ea73
 
d0ea73
-    # Save everything we need to make requests in the handle.
d0ea73
-    return {
d0ea73
-        'can_flush': False,
d0ea73
-        'can_trim': False,
d0ea73
-        'can_zero': False,
d0ea73
-        'connection': connection,
d0ea73
-        'disk': disk,
d0ea73
-        'disk_service': disk_service,
d0ea73
-        'failed': False,
d0ea73
-        'got_options': False,
d0ea73
-        'highestwrite': 0,
d0ea73
-        'http': http,
d0ea73
-        'needs_auth': not params['rhv_direct'],
d0ea73
-        'path': destination_url.path,
d0ea73
-        'transfer': transfer,
d0ea73
-        'transfer_service': transfer_service,
d0ea73
-    }
d0ea73
+    # The first request is to fetch the features of the server.
d0ea73
+    needs_auth = not params['rhv_direct']
d0ea73
+    can_flush = False
d0ea73
+    can_trim = False
d0ea73
+    can_zero = False
d0ea73
 
d0ea73
-# Can we issue zero, trim or flush requests?
d0ea73
-def get_options(h):
d0ea73
-    if h['got_options']:
d0ea73
-        return
d0ea73
-    h['got_options'] = True
d0ea73
-
d0ea73
-    http = h['http']
d0ea73
-    transfer = h['transfer']
d0ea73
-
d0ea73
-    http.putrequest("OPTIONS", h['path'])
d0ea73
+    http.putrequest("OPTIONS", destination_url.path)
d0ea73
     http.putheader("Authorization", transfer.signed_ticket)
d0ea73
     http.endheaders()
d0ea73
 
d0ea73
@@ -201,12 +180,12 @@ def get_options(h):
d0ea73
 
d0ea73
     if r.status == 200:
d0ea73
         # New imageio never needs authentication.
d0ea73
-        h['needs_auth'] = False
d0ea73
+        needs_auth = False
d0ea73
 
d0ea73
         j = json.loads(data)
d0ea73
-        h['can_zero'] = "zero" in j['features']
d0ea73
-        h['can_trim'] = "trim" in j['features']
d0ea73
-        h['can_flush'] = "flush" in j['features']
d0ea73
+        can_flush = "flush" in j['features']
d0ea73
+        can_trim = "trim" in j['features']
d0ea73
+        can_zero = "zero" in j['features']
d0ea73
 
d0ea73
     # Old imageio servers returned either 405 Method Not Allowed or
d0ea73
     # 204 No Content (with an empty body).  If we see that we leave
d0ea73
@@ -218,12 +197,30 @@ def get_options(h):
d0ea73
         raise RuntimeError("could not use OPTIONS request: %d: %s" %
d0ea73
                            (r.status, r.reason))
d0ea73
 
d0ea73
+    debug("imageio features: flush=%r trim=%r zero=%r" %
d0ea73
+          (can_flush, can_trim, can_zero))
d0ea73
+
d0ea73
+    # Save everything we need to make requests in the handle.
d0ea73
+    return {
d0ea73
+        'can_flush': can_flush,
d0ea73
+        'can_trim': can_trim,
d0ea73
+        'can_zero': can_zero,
d0ea73
+        'connection': connection,
d0ea73
+        'disk': disk,
d0ea73
+        'disk_service': disk_service,
d0ea73
+        'failed': False,
d0ea73
+        'highestwrite': 0,
d0ea73
+        'http': http,
d0ea73
+        'needs_auth': needs_auth,
d0ea73
+        'path': destination_url.path,
d0ea73
+        'transfer': transfer,
d0ea73
+        'transfer_service': transfer_service,
d0ea73
+    }
d0ea73
+
d0ea73
 def can_trim(h):
d0ea73
-    get_options(h)
d0ea73
     return h['can_trim']
d0ea73
 
d0ea73
 def can_flush(h):
d0ea73
-    get_options(h)
d0ea73
     return h['can_flush']
d0ea73
 
d0ea73
 def get_size(h):
d0ea73
-- 
d0ea73
2.20.1
d0ea73