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

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