]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/migration/HttpStream.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "librbd/migration/HttpStream.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "librbd/AsioEngine.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/asio/Utils.h"
10 #include "librbd/migration/HttpClient.h"
11 #include <boost/beast/http.hpp>
18 const std::string URL_KEY
{"url"};
20 } // anonymous namespace
22 #define dout_subsys ceph_subsys_rbd
24 #define dout_prefix *_dout << "librbd::migration::HttpStream: " << this \
25 << " " << __func__ << ": "
28 HttpStream
<I
>::HttpStream(I
* image_ctx
, const json_spirit::mObject
& json_object
)
29 : m_image_ctx(image_ctx
), m_cct(image_ctx
->cct
),
30 m_asio_engine(image_ctx
->asio_engine
), m_json_object(json_object
) {
34 HttpStream
<I
>::~HttpStream() {
38 void HttpStream
<I
>::open(Context
* on_finish
) {
39 auto& url_value
= m_json_object
[URL_KEY
];
40 if (url_value
.type() != json_spirit::str_type
) {
41 lderr(m_cct
) << "failed to locate '" << URL_KEY
<< "' key" << dendl
;
42 on_finish
->complete(-EINVAL
);
46 m_url
= url_value
.get_str();
47 ldout(m_cct
, 10) << "url=" << m_url
<< dendl
;
49 m_http_client
.reset(HttpClient
<I
>::create(m_image_ctx
, m_url
));
50 m_http_client
->open(on_finish
);
54 void HttpStream
<I
>::close(Context
* on_finish
) {
55 ldout(m_cct
, 10) << dendl
;
58 on_finish
->complete(0);
62 m_http_client
->close(on_finish
);
66 void HttpStream
<I
>::get_size(uint64_t* size
, Context
* on_finish
) {
67 ldout(m_cct
, 10) << dendl
;
69 m_http_client
->get_size(size
, on_finish
);
73 void HttpStream
<I
>::read(io::Extents
&& byte_extents
, bufferlist
* data
,
75 ldout(m_cct
, 20) << "byte_extents=" << byte_extents
<< dendl
;
77 m_http_client
->read(std::move(byte_extents
), data
, on_finish
);
80 } // namespace migration
83 template class librbd::migration::HttpStream
<librbd::ImageCtx
>;