librbd/LibrbdAdminSocketHook.cc
librbd/LibrbdWriteback.cc
librbd/ObjectMap.cc
+ librbd/Utils.cc
librbd/object_map/InvalidateRequest.cc
librbd/object_map/Request.cc
librbd/object_map/ResizeRequest.cc
#include "librbd/AsyncRequest.h"
#include "librbd/ImageCtx.h"
#include "librbd/internal.h"
+#include "librbd/Utils.h"
namespace librbd
{
const AsyncRequest<T>* async_request, T &image_ctx,
const ContextFactory& context_factory, Context *ctx,
ProgressContext *prog_ctx, uint64_t object_no, uint64_t end_object_no)
- : m_lock(unique_lock_name("librbd::AsyncThrottle::m_lock", this)),
+ : m_lock(util::unique_lock_name("librbd::AsyncThrottle::m_lock", this)),
m_async_request(async_request), m_image_ctx(image_ctx),
m_context_factory(context_factory), m_ctx(ctx), m_prog_ctx(prog_ctx),
m_object_no(object_no), m_end_object_no(end_object_no), m_current_ops(0),
#include "librbd/LibrbdAdminSocketHook.h"
#include "librbd/ObjectMap.h"
#include "librbd/operation/ResizeRequest.h"
+#include "librbd/Utils.h"
#include <boost/bind.hpp>
journal(NULL),
refresh_seq(0),
last_refresh(0),
- owner_lock(unique_lock_name("librbd::ImageCtx::owner_lock", this)),
- md_lock(unique_lock_name("librbd::ImageCtx::md_lock", this)),
- cache_lock(unique_lock_name("librbd::ImageCtx::cache_lock", this)),
- snap_lock(unique_lock_name("librbd::ImageCtx::snap_lock", this)),
- parent_lock(unique_lock_name("librbd::ImageCtx::parent_lock", this)),
- refresh_lock(unique_lock_name("librbd::ImageCtx::refresh_lock", this)),
- object_map_lock(unique_lock_name("librbd::ImageCtx::object_map_lock", this)),
- async_ops_lock(unique_lock_name("librbd::ImageCtx::async_ops_lock", this)),
- copyup_list_lock(unique_lock_name("librbd::ImageCtx::copyup_list_lock", this)),
- completed_reqs_lock(unique_lock_name("librbd::ImageCtx::completed_reqs_lock", this)),
+ owner_lock(util::unique_lock_name("librbd::ImageCtx::owner_lock", this)),
+ md_lock(util::unique_lock_name("librbd::ImageCtx::md_lock", this)),
+ cache_lock(util::unique_lock_name("librbd::ImageCtx::cache_lock", this)),
+ snap_lock(util::unique_lock_name("librbd::ImageCtx::snap_lock", this)),
+ parent_lock(util::unique_lock_name("librbd::ImageCtx::parent_lock", this)),
+ refresh_lock(util::unique_lock_name("librbd::ImageCtx::refresh_lock", this)),
+ object_map_lock(util::unique_lock_name("librbd::ImageCtx::object_map_lock", this)),
+ async_ops_lock(util::unique_lock_name("librbd::ImageCtx::async_ops_lock", this)),
+ copyup_list_lock(util::unique_lock_name("librbd::ImageCtx::copyup_list_lock", this)),
+ completed_reqs_lock(util::unique_lock_name("librbd::ImageCtx::completed_reqs_lock", this)),
extra_read_flags(0),
old_format(true),
order(0), size(0), features(0),
if (!old_format) {
if (!id.length()) {
- r = cls_client::get_id(&md_ctx, id_obj_name(name), &id);
+ r = cls_client::get_id(&md_ctx, util::id_obj_name(name), &id);
if (r < 0) {
lderr(cct) << "error reading image id: " << cpp_strerror(r)
<< dendl;
}
}
- header_oid = header_name(id);
+ header_oid = util::header_name(id);
apply_metadata_confs();
r = cls_client::get_immutable_metadata(&md_ctx, header_oid,
&object_prefix, &order);
init_layout();
} else {
apply_metadata_confs();
- header_oid = old_header_name(name);
+ header_oid = util::old_header_name(name);
}
string pname = string("librbd-") + id + string("-") +
#include "librbd/internal.h"
#include "librbd/ObjectMap.h"
#include "librbd/TaskFinisher.h"
+#include "librbd/Utils.h"
#include "cls/lock/cls_lock_client.h"
#include "cls/lock/cls_lock_types.h"
#include "include/encoding.h"
ImageWatcher::ImageWatcher(ImageCtx &image_ctx)
: m_image_ctx(image_ctx),
- m_watch_lock(unique_lock_name("librbd::ImageWatcher::m_watch_lock", this)),
+ m_watch_lock(util::unique_lock_name("librbd::ImageWatcher::m_watch_lock", this)),
m_watch_ctx(*this), m_watch_handle(0),
m_watch_state(WATCH_STATE_UNREGISTERED),
- m_refresh_lock(unique_lock_name("librbd::ImageWatcher::m_refresh_lock",
- this)),
+ m_refresh_lock(util::unique_lock_name("librbd::ImageWatcher::m_refresh_lock", this)),
m_lock_supported(false), m_lock_owner_state(LOCK_OWNER_STATE_NOT_LOCKED),
- m_listeners_lock(unique_lock_name("librbd::ImageWatcher::m_listeners_lock", this)),
+ m_listeners_lock(util::unique_lock_name("librbd::ImageWatcher::m_listeners_lock", this)),
m_listeners_in_use(false),
m_task_finisher(new TaskFinisher<Task>(*m_image_ctx.cct)),
- m_async_request_lock(unique_lock_name("librbd::ImageWatcher::m_async_request_lock", this)),
- m_owner_client_id_lock(unique_lock_name("librbd::ImageWatcher::m_owner_client_id_lock", this))
+ m_async_request_lock(util::unique_lock_name("librbd::ImageWatcher::m_async_request_lock", this)),
+ m_owner_client_id_lock(util::unique_lock_name("librbd::ImageWatcher::m_owner_client_id_lock", this))
{
}
librbd/LibrbdAdminSocketHook.cc \
librbd/LibrbdWriteback.cc \
librbd/ObjectMap.cc \
+ librbd/Utils.cc \
librbd/object_map/InvalidateRequest.cc \
librbd/object_map/Request.cc \
librbd/object_map/ResizeRequest.cc \
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/Utils.h"
+#include "include/rbd_types.h"
+#include "include/stringify.h"
+
+namespace librbd {
+namespace util {
+
+const std::string id_obj_name(const std::string &name)
+{
+ return RBD_ID_PREFIX + name;
+}
+
+const std::string header_name(const std::string &image_id)
+{
+ return RBD_HEADER_PREFIX + image_id;
+}
+
+const std::string old_header_name(const std::string &image_name)
+{
+ return image_name + RBD_SUFFIX;
+}
+
+std::string unique_lock_name(const std::string &name, void *address) {
+ return name + " (" + stringify(address) + ")";
+}
+
+} // namespace util
+} // namespace librbd
} // namespace detail
+const std::string id_obj_name(const std::string &name);
+const std::string header_name(const std::string &image_id);
+const std::string old_header_name(const std::string &image_name);
+std::string unique_lock_name(const std::string &name, void *address);
+
template <typename T>
librados::AioCompletion *create_rados_ack_callback(T *obj) {
return librados::Rados::aio_create_completion(
} // anonymous namespace
- const string id_obj_name(const string &name)
- {
- return RBD_ID_PREFIX + name;
- }
-
- const string header_name(const string &image_id)
- {
- return RBD_HEADER_PREFIX + image_id;
- }
-
- const string old_header_name(const string &image_name)
- {
- return image_name + RBD_SUFFIX;
- }
-
- std::string unique_lock_name(const std::string &name, void *address) {
- return name + " (" + stringify(address) + ")";
- }
-
int detect_format(IoCtx &io_ctx, const string &name,
bool *old_format, uint64_t *size)
{
CephContext *cct = (CephContext *)io_ctx.cct();
if (old_format)
*old_format = true;
- int r = io_ctx.stat(old_header_name(name), size, NULL);
+ int r = io_ctx.stat(util::old_header_name(name), size, NULL);
if (r == -ENOENT) {
if (old_format)
*old_format = false;
- r = io_ctx.stat(id_obj_name(name), size, NULL);
+ r = io_ctx.stat(util::id_obj_name(name), size, NULL);
if (r < 0)
return r;
} else if (r < 0) {
bufferlist bl;
bl.append((const char *)&header, sizeof(header));
- string header_oid = old_header_name(imgname);
+ string header_oid = util::old_header_name(imgname);
r = io_ctx.write(header_oid, bl, bl.length(), 0);
if (r < 0) {
lderr(cct) << "Error writing image header: " << cpp_strerror(r)
return r;
}
- id_obj = id_obj_name(imgname);
+ id_obj = util::id_obj_name(imgname);
r = io_ctx.create(id_obj, true);
if (r < 0) {
}
oss << RBD_DATA_PREFIX << id;
- header_oid = header_name(id);
+ header_oid = util::header_name(id);
r = cls_client::create_image(&io_ctx, header_oid, size, order,
features, oss.str());
if (r < 0) {
}
ldout(cct, 2) << "removing id object..." << dendl;
- r = io_ctx.remove(id_obj_name(imgname));
+ r = io_ctx.remove(util::id_obj_name(imgname));
if (r < 0 && r != -ENOENT) {
lderr(cct) << "error removing id object: " << cpp_strerror(r) << dendl;
return r;
}
};
- const std::string id_obj_name(const std::string &name);
- const std::string header_name(const std::string &image_id);
- const std::string old_header_name(const std::string &image_name);
- std::string unique_lock_name(const std::string &name, void *address);
-
int detect_format(librados::IoCtx &io_ctx, const std::string &name,
bool *old_format, uint64_t *size);
#include "include/rados/librados.hpp"
#include "librbd/ImageCtx.h"
#include "librbd/internal.h"
+#include "librbd/Utils.h"
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
RenameRequest<I>::RenameRequest(I &image_ctx, Context *on_finish,
const std::string &dest_name)
: Request<I>(image_ctx, on_finish), m_dest_name(dest_name),
- m_source_oid(image_ctx.old_format ? old_header_name(image_ctx.name) :
- id_obj_name(image_ctx.name)),
- m_dest_oid(image_ctx.old_format ? old_header_name(dest_name) :
- id_obj_name(dest_name)) {
+ m_source_oid(image_ctx.old_format ? util::old_header_name(image_ctx.name) :
+ util::id_obj_name(image_ctx.name)),
+ m_dest_oid(image_ctx.old_format ? util::old_header_name(dest_name) :
+ util::id_obj_name(dest_name)) {
}
template <typename I>