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

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