]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/migration: simplify common http result code handling
authorJason Dillaman <dillaman@redhat.com>
Fri, 13 Nov 2020 16:10:47 +0000 (11:10 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 23 Nov 2020 13:45:50 +0000 (08:45 -0500)
Move the processing of common HTTP result codes (not found, permission
denied, etc) higher up the stack so it can be re-used between all
request paths.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/migration/HttpClient.cc

index b077e93359561353df1b8cd6255c9291aad45f72..fff959cca0012d72e2259d0cc5f2f2c7ce44bfed 100644 (file)
@@ -462,8 +462,27 @@ private:
     }
     response = std::move(m_parser->release());
 
+    // basic response code handling in a common location
+    int r = 0;
+    auto result = response.result();
+    if (result == boost::beast::http::status::not_found) {
+      lderr(cct) << "requested resource does not exist" << dendl;
+      r = -ENOENT;
+    } else if (result == boost::beast::http::status::forbidden) {
+      lderr(cct) << "permission denied attempting to access resource" << dendl;
+      r = -EACCES;
+    } else if (boost::beast::http::to_status_class(result) !=
+                 boost::beast::http::status_class::successful) {
+      lderr(cct) << "failed to retrieve size: HTTP " << result << dendl;
+      r = -EIO;
+    }
+
     bool need_eof = response.need_eof();
-    work->complete(0, std::move(response));
+    if (r < 0) {
+      work->complete(r, {});
+    } else {
+      work->complete(0, std::move(response));
+    }
 
     if (need_eof) {
       ldout(cct, 20) << "reset required for non-pipelined response: "
@@ -794,17 +813,6 @@ void HttpClient<I>::handle_get_size(int r, Response&& response, uint64_t* size,
     lderr(m_cct) << "failed to retrieve size: " << cpp_strerror(r) << dendl;
     on_finish->complete(r);
     return;
-  } else if (response.result() == boost::beast::http::status::not_found) {
-    lderr(m_cct) << "failed to retrieve size: " << cpp_strerror(-ENOENT)
-                 << dendl;
-    on_finish->complete(-ENOENT);
-    return;
-  } else if (boost::beast::http::to_status_class(response.result()) !=
-               boost::beast::http::status_class::successful) {
-    lderr(m_cct) << "failed to retrieve size: HTTP " << response.result()
-                 << dendl;
-    on_finish->complete(-EIO);
-    return;
   } else if (!response.has_content_length()) {
     lderr(m_cct) << "failed to retrieve size: missing content-length" << dendl;
     on_finish->complete(-EINVAL);