repo
stringlengths 1
152
⌀ | file
stringlengths 14
221
| code
stringlengths 501
25k
| file_length
int64 501
25k
| avg_line_length
float64 20
99.5
| max_line_length
int64 21
134
| extension_type
stringclasses 2
values |
---|---|---|---|---|---|---|
null | ceph-main/src/librbd/image/CreateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_CREATE_REQUEST_H
#define CEPH_LIBRBD_IMAGE_CREATE_REQUEST_H
#include "common/config_fwd.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/ImageCtx.h"
class Context;
using librados::IoCtx;
namespace journal { class Journaler; }
namespace librbd {
namespace asio { struct ContextWQ; }
namespace image {
template <typename ImageCtxT = ImageCtx>
class CreateRequest {
public:
static CreateRequest *create(const ConfigProxy& config, IoCtx &ioctx,
const std::string &image_name,
const std::string &image_id, uint64_t size,
const ImageOptions &image_options,
uint32_t create_flags,
cls::rbd::MirrorImageMode mirror_image_mode,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
asio::ContextWQ *op_work_queue,
Context *on_finish) {
return new CreateRequest(config, ioctx, image_name, image_id, size,
image_options, create_flags,
mirror_image_mode, non_primary_global_image_id,
primary_mirror_uuid, op_work_queue, on_finish);
}
static int validate_order(CephContext *cct, uint8_t order);
void send();
private:
/**
* @verbatim
*
* <start> . . . . > . . . . .
* | .
* v .
* VALIDATE DATA POOL v (pool validation
* | . disabled)
* v .
* (error: bottom up) ADD IMAGE TO DIRECTORY < . . . .
* _______<_______ |
* | | v
* | | CREATE ID OBJECT
* | | / |
* | REMOVE FROM DIR <-------/ v
* | | NEGOTIATE FEATURES (when using default features)
* | | |
* | | v (stripingv2 disabled)
* | | CREATE IMAGE. . . . > . . . .
* v | / | .
* | REMOVE ID OBJ <---------/ v .
* | | SET STRIPE UNIT COUNT .
* | | / | \ . . . . . > . . . .
* | REMOVE HEADER OBJ<------/ v /. (object-map
* | |\ OBJECT MAP RESIZE . . < . . * v disabled)
* | | \ / | \ . . . . . > . . . .
* | | *<-----------/ v /. (journaling
* | | FETCH MIRROR MODE. . < . . * v disabled)
* | | / | .
* | REMOVE OBJECT MAP<--------/ v .
* | |\ JOURNAL CREATE .
* | | \ / | .
* v | *<------------/ v .
* | | MIRROR IMAGE ENABLE .
* | | / | .
* | JOURNAL REMOVE*<-------/ | .
* | v .
* |_____________>___________________<finish> . . . . < . . . .
*
* @endverbatim
*/
CreateRequest(const ConfigProxy& config, IoCtx &ioctx,
const std::string &image_name,
const std::string &image_id, uint64_t size,
const ImageOptions &image_options,
uint32_t create_flags,
cls::rbd::MirrorImageMode mirror_image_mode,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
asio::ContextWQ *op_work_queue, Context *on_finish);
const ConfigProxy& m_config;
IoCtx m_io_ctx;
IoCtx m_data_io_ctx;
std::string m_image_name;
std::string m_image_id;
uint64_t m_size;
uint8_t m_order = 0;
uint64_t m_features = 0;
uint64_t m_stripe_unit = 0;
uint64_t m_stripe_count = 0;
uint8_t m_journal_order = 0;
uint8_t m_journal_splay_width = 0;
std::string m_journal_pool;
std::string m_data_pool;
int64_t m_data_pool_id = -1;
uint32_t m_create_flags;
cls::rbd::MirrorImageMode m_mirror_image_mode;
const std::string m_non_primary_global_image_id;
const std::string m_primary_mirror_uuid;
bool m_negotiate_features = false;
asio::ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct;
int m_r_saved = 0; // used to return actual error after cleanup
file_layout_t m_layout;
std::string m_id_obj, m_header_obj, m_objmap_name;
bufferlist m_outbl;
cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
cls::rbd::MirrorImage m_mirror_image_internal;
void validate_data_pool();
void handle_validate_data_pool(int r);
void add_image_to_directory();
void handle_add_image_to_directory(int r);
void create_id_object();
void handle_create_id_object(int r);
void negotiate_features();
void handle_negotiate_features(int r);
void create_image();
void handle_create_image(int r);
void set_stripe_unit_count();
void handle_set_stripe_unit_count(int r);
void object_map_resize();
void handle_object_map_resize(int r);
void fetch_mirror_mode();
void handle_fetch_mirror_mode(int r);
void journal_create();
void handle_journal_create(int r);
void mirror_image_enable();
void handle_mirror_image_enable(int r);
void complete(int r);
// cleanup
void journal_remove();
void handle_journal_remove(int r);
void remove_object_map();
void handle_remove_object_map(int r);
void remove_header_object();
void handle_remove_header_object(int r);
void remove_id_object();
void handle_remove_id_object(int r);
void remove_from_dir();
void handle_remove_from_dir(int r);
};
} //namespace image
} //namespace librbd
extern template class librbd::image::CreateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_CREATE_REQUEST_H
| 6,757 | 34.197917 | 82 | h |
null | ceph-main/src/librbd/image/DetachChildRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_DETACH_CHILD_REQUEST_H
#define CEPH_LIBRBD_IMAGE_DETACH_CHILD_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "librbd/Types.h"
#include "librbd/internal.h"
class Context;
namespace librbd {
class ImageCtx;
namespace image {
template <typename ImageCtxT = ImageCtx>
class DetachChildRequest {
public:
static DetachChildRequest* create(ImageCtxT& image_ctx, Context* on_finish) {
return new DetachChildRequest(image_ctx, on_finish);
}
DetachChildRequest(ImageCtxT& image_ctx, Context* on_finish)
: m_image_ctx(image_ctx), m_on_finish(on_finish) {
}
~DetachChildRequest();
void send();
private:
/**
* @verbatim
*
* <start>
* |
* (v1) | (v2)
* /--------------/ \--------------\
* | |
* v v
* REMOVE_CHILD CHILD_DETACH
* | |
* | v
* | GET_SNAPSHOT
* | (snapshot in-use) . |
* |/. . . . . . . . . . . . . . . |
* | v
* | OPEN_PARENT
* | |
* | v (has more children)
* | REMOVE_SNAPSHOT ---------------\
* | | |
* | v (noent) |
* | (auto-delete when GET_PARENT_TRASH_ENTRY . . . .\|
* | last child detached) | |
* | v v
* | REMOVE_PARENT_FROM_TRASH CLOSE_PARENT
* | | |
* |/------------------------------/--------------------------/
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT& m_image_ctx;
Context* m_on_finish;
librados::IoCtx m_parent_io_ctx;
cls::rbd::ParentImageSpec m_parent_spec;
std::string m_parent_header_name;
cls::rbd::SnapshotNamespace m_parent_snap_namespace;
std::string m_parent_snap_name;
ImageCtxT* m_parent_image_ctx = nullptr;
ceph::bufferlist m_out_bl;
NoOpProgressContext m_no_op;
void clone_v2_child_detach();
void handle_clone_v2_child_detach(int r);
void clone_v2_get_snapshot();
void handle_clone_v2_get_snapshot(int r);
void clone_v2_open_parent();
void handle_clone_v2_open_parent(int r);
void clone_v2_remove_snapshot();
void handle_clone_v2_remove_snapshot(int r);
void clone_v2_get_parent_trash_entry();
void handle_clone_v2_get_parent_trash_entry(int r);
void clone_v2_remove_parent_from_trash();
void handle_clone_v2_remove_parent_from_trash(int r);
void clone_v2_close_parent();
void handle_clone_v2_close_parent(int r);
void clone_v1_remove_child();
void handle_clone_v1_remove_child(int r);
void finish(int r);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::DetachChildRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_DETACH_CHILD_REQUEST_H
| 3,437 | 27.65 | 79 | h |
null | ceph-main/src/librbd/image/GetMetadataRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_GET_METADATA_REQUEST_H
#define CEPH_LIBRBD_IMAGE_GET_METADATA_REQUEST_H
#include "include/common_fwd.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include <string>
#include <map>
class Context;
namespace librbd {
struct ImageCtx;
namespace image {
template <typename ImageCtxT = ImageCtx>
class GetMetadataRequest {
public:
typedef std::map<std::string, bufferlist> KeyValues;
static GetMetadataRequest* create(
IoCtx &io_ctx, const std::string &oid, bool filter_internal,
const std::string& filter_key_prefix, const std::string& last_key,
uint32_t max_results, KeyValues* key_values, Context *on_finish) {
return new GetMetadataRequest(io_ctx, oid, filter_internal,
filter_key_prefix, last_key, max_results,
key_values, on_finish);
}
GetMetadataRequest(
IoCtx &io_ctx, const std::string &oid, bool filter_internal,
const std::string& filter_key_prefix, const std::string& last_key,
uint32_t max_results, KeyValues* key_values, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* | /-------\
* | | |
* v v |
* METADATA_LIST ---/
* |
* v
* <finish>
*
* @endverbatim
*/
librados::IoCtx m_io_ctx;
std::string m_oid;
bool m_filter_internal;
std::string m_filter_key_prefix;
std::string m_last_key;
uint32_t m_max_results;
KeyValues* m_key_values;
Context* m_on_finish;
CephContext* m_cct;
bufferlist m_out_bl;
uint32_t m_expected_results = 0;
void metadata_list();
void handle_metadata_list(int r);
void finish(int r);
};
} //namespace image
} //namespace librbd
extern template class librbd::image::GetMetadataRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_GET_METADATA_REQUEST_H
| 2,014 | 22.988095 | 75 | h |
null | ceph-main/src/librbd/image/ListWatchersRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_LIST_WATCHERS_REQUEST_H
#define CEPH_LIBRBD_IMAGE_LIST_WATCHERS_REQUEST_H
#include "include/rados/rados_types.hpp"
#include <list>
class Context;
namespace librbd {
class ImageCtx;
namespace image {
enum {
LIST_WATCHERS_FILTER_OUT_MY_INSTANCE = 1 << 0,
LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES = 1 << 1,
LIST_WATCHERS_MIRROR_INSTANCES_ONLY = 1 << 3,
};
template<typename ImageCtxT = ImageCtx>
class ListWatchersRequest {
public:
static ListWatchersRequest *create(ImageCtxT &image_ctx, int flags,
std::list<obj_watch_t> *watchers,
Context *on_finish) {
return new ListWatchersRequest(image_ctx, flags, watchers, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* LIST_IMAGE_WATCHERS
* |
* v
* LIST_MIRROR_WATCHERS (skip if not needed)
* |
* v
* <finish>
*
* @endverbatim
*/
ListWatchersRequest(ImageCtxT &image_ctx, int flags, std::list<obj_watch_t> *watchers,
Context *on_finish);
ImageCtxT& m_image_ctx;
int m_flags;
std::list<obj_watch_t> *m_watchers;
Context *m_on_finish;
CephContext *m_cct;
int m_ret_val;
bufferlist m_out_bl;
std::list<obj_watch_t> m_object_watchers;
std::list<obj_watch_t> m_mirror_watchers;
void list_image_watchers();
void handle_list_image_watchers(int r);
void list_mirror_watchers();
void handle_list_mirror_watchers(int r);
void finish(int r);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::ListWatchersRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_LIST_WATCHERS_REQUEST_H
| 1,824 | 20.987952 | 88 | h |
null | ceph-main/src/librbd/image/OpenRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H
#define CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H
#include "include/buffer.h"
#include <map>
#include <string>
class Context;
namespace librbd {
class ImageCtx;
namespace image {
template <typename ImageCtxT = ImageCtx>
class OpenRequest {
public:
static OpenRequest *create(ImageCtxT *image_ctx, uint64_t flags,
Context *on_finish) {
return new OpenRequest(image_ctx, flags, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* | (v1)
* |-----> V1_DETECT_HEADER
* | |
* | \-------------------------------\
* | (v2) |
* \-----> V2_DETECT_HEADER |
* | |
* v |
* V2_GET_ID|NAME |
* | |
* v (skip if have name) |
* V2_GET_NAME_FROM_TRASH |
* | |
* v |
* V2_GET_INITIAL_METADATA |
* | |
* v |
* V2_GET_STRIPE_UNIT_COUNT (skip if |
* | disabled) |
* v |
* V2_GET_CREATE_TIMESTAMP |
* | |
* v |
* V2_GET_ACCESS_MODIFY_TIMESTAMP |
* | |
* v |
* V2_GET_DATA_POOL --------------> REFRESH
* |
* v
* INIT_PLUGIN_REGISTRY
* |
* v
* INIT_CACHE
* |
* v
* REGISTER_WATCH (skip if
* | read-only)
* v
* SET_SNAP (skip if no snap)
* |
* v
* <finish>
* ^
* (on error) |
* * * * * * * > CLOSE ------------------------/
*
* @endverbatim
*/
OpenRequest(ImageCtxT *image_ctx, uint64_t flags, Context *on_finish);
ImageCtxT *m_image_ctx;
bool m_skip_open_parent_image;
Context *m_on_finish;
bufferlist m_out_bl;
int m_error_result;
void send_v1_detect_header();
Context *handle_v1_detect_header(int *result);
void send_v2_detect_header();
Context *handle_v2_detect_header(int *result);
void send_v2_get_id();
Context *handle_v2_get_id(int *result);
void send_v2_get_name();
Context *handle_v2_get_name(int *result);
void send_v2_get_name_from_trash();
Context *handle_v2_get_name_from_trash(int *result);
void send_v2_get_initial_metadata();
Context *handle_v2_get_initial_metadata(int *result);
void send_v2_get_stripe_unit_count();
Context *handle_v2_get_stripe_unit_count(int *result);
void send_v2_get_create_timestamp();
Context *handle_v2_get_create_timestamp(int *result);
void send_v2_get_access_modify_timestamp();
Context *handle_v2_get_access_modify_timestamp(int *result);
void send_v2_get_data_pool();
Context *handle_v2_get_data_pool(int *result);
void send_refresh();
Context *handle_refresh(int *result);
void send_init_plugin_registry();
Context* handle_init_plugin_registry(int *result);
Context *send_init_cache(int *result);
Context *send_register_watch(int *result);
Context *handle_register_watch(int *result);
Context *send_set_snap(int *result);
Context *handle_set_snap(int *result);
Context *finalize(int r);
void send_close_image(int error_result);
Context *handle_close_image(int *result);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::OpenRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H
| 4,830 | 31.206667 | 75 | h |
null | ceph-main/src/librbd/image/PreRemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_PRE_REMOVE_REQUEST_H
#define CEPH_LIBRBD_IMAGE_PRE_REMOVE_REQUEST_H
#include "include/rados/librados.hpp"
#include "include/buffer.h"
#include "librbd/ImageCtx.h"
#include <list>
#include <map>
class Context;
namespace librbd {
namespace image {
template <typename ImageCtxT>
class PreRemoveRequest {
public:
static PreRemoveRequest *create(ImageCtxT *image_ctx, bool force,
Context *on_finish) {
return new PreRemoveRequest(image_ctx, force, on_finish);
}
PreRemoveRequest(ImageCtxT *image_ctx, bool force, Context *on_finish)
: m_image_ctx(image_ctx), m_force(force), m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* | (skip if
* v not needed) (error)
* ACQUIRE EXCLUSIVE LOCK * * * * * * > SHUT DOWN EXCLUSIVE LOCK
* | |
* v |
* CHECK IMAGE WATCHERS <------------------/
* |
* v
* CHECK GROUP
* |
* | /------\
* | | |
* v v |
* REMOVE SNAPS ----/
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT* m_image_ctx;
bool m_force;
Context* m_on_finish;
decltype(m_image_ctx->exclusive_lock) m_exclusive_lock = nullptr;
bufferlist m_out_bl;
std::list<obj_watch_t> m_watchers;
std::map<uint64_t, SnapInfo> m_snap_infos;
int m_ret_val = 0;
void acquire_exclusive_lock();
void handle_exclusive_lock(int r);
void shut_down_exclusive_lock();
void handle_shut_down_exclusive_lock(int r);
void validate_image_removal();
void check_image_snaps();
void list_image_watchers();
void handle_list_image_watchers(int r);
void check_image_watchers();
void check_group();
void handle_check_group(int r);
void remove_snapshot();
void handle_remove_snapshot(int r);
void finish(int r);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::PreRemoveRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_PRE_REMOVE_REQUEST_H
| 2,292 | 21.70297 | 72 | h |
null | ceph-main/src/librbd/image/RefreshParentRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
#define CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
#include "include/int_types.h"
#include "librbd/Types.h"
class Context;
namespace librbd {
class ImageCtx;
namespace image {
template <typename ImageCtxT = ImageCtx>
class RefreshParentRequest {
public:
static RefreshParentRequest *create(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info,
Context *on_finish) {
return new RefreshParentRequest(child_image_ctx, parent_md, migration_info,
on_finish);
}
static bool is_refresh_required(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info);
void send();
void apply();
void finalize(Context *on_finish);
private:
/**
* @verbatim
*
* <start>
* |
* | (open required)
* |----------------> OPEN_PARENT * * * * * * * * * * * * * * *
* | | *
* | v (on error) *
* \----------------> <apply> *
* | *
* | (close required) *
* |-----------------> CLOSE_PARENT *
* | | *
* | v *
* | RESET_EXISTENCE *
* | | *
* | v *
* \-----------------> <finish> < * * * *
*
* @endverbatim
*/
RefreshParentRequest(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info, Context *on_finish);
ImageCtxT &m_child_image_ctx;
ParentImageInfo m_parent_md;
MigrationInfo m_migration_info;
Context *m_on_finish;
ImageCtxT *m_parent_image_ctx;
uint64_t m_parent_snap_id;
int m_error_result;
static bool is_close_required(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info);
static bool is_open_required(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info);
static bool does_parent_exist(ImageCtxT &child_image_ctx,
const ParentImageInfo &parent_md,
const MigrationInfo &migration_info);
void send_open_parent();
Context *handle_open_parent(int *result);
void send_close_parent();
Context *handle_close_parent(int *result);
void send_reset_existence_cache();
Context *handle_reset_existence_cache(int *result);
void send_complete(int r);
void save_result(int *result) {
if (m_error_result == 0 && *result < 0) {
m_error_result = *result;
}
}
};
} // namespace image
} // namespace librbd
extern template class librbd::image::RefreshParentRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
| 3,653 | 32.218182 | 80 | h |
null | ceph-main/src/librbd/image/RefreshRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
#define CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/utime.h"
#include "common/snap_types.h"
#include "cls/lock/cls_lock_types.h"
#include "librbd/ImageCtx.h"
#include "librbd/Types.h"
#include <string>
#include <vector>
class Context;
namespace librbd {
class ImageCtx;
namespace image {
template<typename> class RefreshParentRequest;
template<typename ImageCtxT = ImageCtx>
class RefreshRequest {
public:
static constexpr int MAX_ENOENT_RETRIES = 10;
static RefreshRequest *create(ImageCtxT &image_ctx, bool acquiring_lock,
bool skip_open_parent, Context *on_finish) {
return new RefreshRequest(image_ctx, acquiring_lock, skip_open_parent,
on_finish);
}
RefreshRequest(ImageCtxT &image_ctx, bool acquiring_lock,
bool skip_open_parent, Context *on_finish);
~RefreshRequest();
void send();
private:
/**
* @verbatim
*
* <start> < * * * * * * * * * * * * * * * * * * * * * * * * * * (ENOENT)
* ^ | *
* * | (v1) *
* * |-----> V1_READ_HEADER -------------> GET_MIGRATION_HEADER (skip if not
* * | | migrating)
* * | (v2) v
* * \-----> V2_GET_MUTABLE_METADATA V1_GET_SNAPSHOTS
* * * | |
* * * | -EOPNOTSUPP v
* * * | * * * V1_GET_LOCKS
* * * | * * |
* * * v v * v
* * * V2_GET_PARENT <apply>
* * * | |
* * v |
* * * * * * GET_MIGRATION_HEADER (skip if not |
* (ENOENT) | migrating) |
* v |
* * V2_GET_METADATA |
* * | |
* * v |
* * V2_GET_POOL_METADATA |
* * | |
* * v (skip if not enabled) |
* * V2_GET_OP_FEATURES |
* * | |
* * v |
* * V2_GET_GROUP |
* * | |
* * | -EOPNOTSUPP |
* * | * * * |
* * | * * |
* * v v * |
* * * V2_GET_SNAPSHOTS (skip if no snaps) |
* (ENOENT) | |
* * v |
* * * V2_REFRESH_PARENT (skip if no parent or |
* (ENOENT) | refresh not needed) |
* v |
* V2_INIT_EXCLUSIVE_LOCK (skip if lock |
* | active or disabled) |
* v |
* V2_OPEN_OBJECT_MAP (skip if map |
* | active or disabled) |
* v |
* V2_OPEN_JOURNAL (skip if journal |
* | active or disabled) |
* v |
* V2_BLOCK_WRITES (skip if journal not |
* | disabled) |
* v |
* <apply> |
* | |
* v |
* V2_FINALIZE_REFRESH_PARENT (skip if refresh |
* | not needed) |
* (error) v |
* * * * * > V2_SHUT_DOWN_EXCLUSIVE_LOCK (skip if lock |
* | active or enabled) |
* v |
* V2_CLOSE_JOURNAL (skip if journal inactive |
* | or enabled) |
* v |
* V2_CLOSE_OBJECT_MAP (skip if map inactive |
* | or enabled) |
* | |
* \-------------------\/--------------------/
* |
* v
* FLUSH (skip if no new
* | snapshots)
* v
* <finish>
*
* @endverbatim
*/
enum LegacySnapshot {
LEGACY_SNAPSHOT_DISABLED,
LEGACY_SNAPSHOT_ENABLED,
LEGACY_SNAPSHOT_ENABLED_NO_TIMESTAMP
};
ImageCtxT &m_image_ctx;
bool m_acquiring_lock;
bool m_skip_open_parent_image;
Context *m_on_finish;
cls::rbd::MigrationSpec m_migration_spec;
int m_error_result;
bool m_flush_aio;
decltype(m_image_ctx.exclusive_lock) m_exclusive_lock;
decltype(m_image_ctx.object_map) m_object_map;
decltype(m_image_ctx.journal) m_journal;
RefreshParentRequest<ImageCtxT> *m_refresh_parent;
bufferlist m_out_bl;
bool m_legacy_parent = false;
LegacySnapshot m_legacy_snapshot = LEGACY_SNAPSHOT_DISABLED;
int m_enoent_retries = 0;
uint8_t m_order = 0;
uint64_t m_size = 0;
uint64_t m_features = 0;
uint64_t m_incompatible_features = 0;
uint64_t m_flags = 0;
uint64_t m_op_features = 0;
uint32_t m_read_only_flags = 0U;
bool m_read_only = false;
librados::IoCtx m_pool_metadata_io_ctx;
std::map<std::string, bufferlist> m_metadata;
std::string m_object_prefix;
ParentImageInfo m_parent_md;
bool m_head_parent_overlap = false;
cls::rbd::GroupSpec m_group_spec;
::SnapContext m_snapc;
std::vector<cls::rbd::SnapshotInfo> m_snap_infos;
std::vector<ParentImageInfo> m_snap_parents;
std::vector<uint8_t> m_snap_protection;
std::vector<uint64_t> m_snap_flags;
std::map<rados::cls::lock::locker_id_t,
rados::cls::lock::locker_info_t> m_lockers;
std::string m_lock_tag;
bool m_exclusive_locked = false;
bool m_blocked_writes = false;
bool m_incomplete_update = false;
void send_get_migration_header();
Context *handle_get_migration_header(int *result);
void send_v1_read_header();
Context *handle_v1_read_header(int *result);
void send_v1_get_snapshots();
Context *handle_v1_get_snapshots(int *result);
void send_v1_get_locks();
Context *handle_v1_get_locks(int *result);
void send_v1_apply();
Context *handle_v1_apply(int *result);
void send_v2_get_mutable_metadata();
Context *handle_v2_get_mutable_metadata(int *result);
void send_v2_get_parent();
Context *handle_v2_get_parent(int *result);
void send_v2_get_metadata();
Context *handle_v2_get_metadata(int *result);
void send_v2_get_pool_metadata();
Context *handle_v2_get_pool_metadata(int *result);
void send_v2_get_op_features();
Context *handle_v2_get_op_features(int *result);
void send_v2_get_group();
Context *handle_v2_get_group(int *result);
void send_v2_get_snapshots();
Context *handle_v2_get_snapshots(int *result);
void send_v2_get_snapshots_legacy();
Context *handle_v2_get_snapshots_legacy(int *result);
void send_v2_refresh_parent();
Context *handle_v2_refresh_parent(int *result);
void send_v2_init_exclusive_lock();
Context *handle_v2_init_exclusive_lock(int *result);
void send_v2_open_journal();
Context *handle_v2_open_journal(int *result);
void send_v2_block_writes();
Context *handle_v2_block_writes(int *result);
void send_v2_open_object_map();
Context *handle_v2_open_object_map(int *result);
void send_v2_apply();
Context *handle_v2_apply(int *result);
Context *send_v2_finalize_refresh_parent();
Context *handle_v2_finalize_refresh_parent(int *result);
Context *send_v2_shut_down_exclusive_lock();
Context *handle_v2_shut_down_exclusive_lock(int *result);
Context *send_v2_close_journal();
Context *handle_v2_close_journal(int *result);
Context *send_v2_close_object_map();
Context *handle_v2_close_object_map(int *result);
Context *send_flush_aio();
Context *handle_flush_aio(int *result);
Context *handle_error(int *result);
void save_result(int *result) {
if (m_error_result == 0 && *result < 0) {
m_error_result = *result;
}
}
void apply();
int get_parent_info(uint64_t snap_id, ParentImageInfo *parent_md,
MigrationInfo *migration_info);
int get_migration_info(ParentImageInfo *parent_md,
MigrationInfo *migration_info,
bool* migration_info_valid);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::RefreshRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
| 10,041 | 35.384058 | 79 | h |
null | ceph-main/src/librbd/image/RemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_REMOVE_REQUEST_H
#define CEPH_LIBRBD_IMAGE_REMOVE_REQUEST_H
#include "include/rados/librados.hpp"
#include "librbd/ImageCtx.h"
#include "librbd/image/TypeTraits.h"
#include "common/Timer.h"
#include <list>
class Context;
namespace librbd {
class ProgressContext;
namespace image {
template<typename ImageCtxT = ImageCtx>
class RemoveRequest {
private:
// mock unit testing support
typedef ::librbd::image::TypeTraits<ImageCtxT> TypeTraits;
typedef typename TypeTraits::ContextWQ ContextWQ;
public:
static RemoveRequest *create(librados::IoCtx &ioctx,
const std::string &image_name,
const std::string &image_id,
bool force, bool from_trash_remove,
ProgressContext &prog_ctx,
ContextWQ *op_work_queue,
Context *on_finish) {
return new RemoveRequest(ioctx, image_name, image_id, force,
from_trash_remove, prog_ctx, op_work_queue,
on_finish);
}
static RemoveRequest *create(librados::IoCtx &ioctx, ImageCtxT *image_ctx,
bool force, bool from_trash_remove,
ProgressContext &prog_ctx,
ContextWQ *op_work_queue,
Context *on_finish) {
return new RemoveRequest(ioctx, image_ctx, force, from_trash_remove,
prog_ctx, op_work_queue, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* (skip if already opened) OPEN IMAGE------------------\
* | |
* v |
* PRE REMOVE IMAGE * * * |
* | * |
* v * |
* (skip if invalid data pool) TRIM IMAGE * * * * * |
* | * |
* v * |
* DETACH CHILD * |
* | * |
* v * v
* CLOSE IMAGE < * * * * |
* | |
* error v |
* /------<--------\ REMOVE HEADER<--------------/
* | | / |
* | |-------<-------/ |
* | | v
* | | REMOVE JOURNAL
* | | / |
* | |-------<-------/ |
* | | v
* v ^ REMOVE OBJECTMAP
* | | / |
* | |-------<-------/ |
* | | v
* | | REMOVE MIRROR IMAGE
* | | / |
* | |-------<-------/ |
* | | v
* | | REMOVE ID OBJECT
* | | / |
* | |-------<-------/ |
* | | v
* | | REMOVE IMAGE
* | | / |
* | \-------<-------/ |
* | v
* \------------------>------------<finish>
*
* @endverbatim
*/
RemoveRequest(librados::IoCtx &ioctx, const std::string &image_name,
const std::string &image_id, bool force, bool from_trash_remove,
ProgressContext &prog_ctx, ContextWQ *op_work_queue,
Context *on_finish);
RemoveRequest(librados::IoCtx &ioctx, ImageCtxT *image_ctx, bool force,
bool from_trash_remove, ProgressContext &prog_ctx,
ContextWQ *op_work_queue, Context *on_finish);
librados::IoCtx &m_ioctx;
std::string m_image_name;
std::string m_image_id;
ImageCtxT *m_image_ctx = nullptr;
bool m_force;
bool m_from_trash_remove;
ProgressContext &m_prog_ctx;
ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct;
std::string m_header_oid;
bool m_old_format = false;
bool m_unknown_format = true;
librados::IoCtx m_parent_io_ctx;
decltype(m_image_ctx->exclusive_lock) m_exclusive_lock = nullptr;
int m_ret_val = 0;
bufferlist m_out_bl;
std::list<obj_watch_t> m_watchers;
std::map<uint64_t, SnapInfo> m_snap_infos;
void open_image();
void handle_open_image(int r);
void send_journal_remove();
void handle_journal_remove(int r);
void send_object_map_remove();
void handle_object_map_remove(int r);
void mirror_image_remove();
void handle_mirror_image_remove(int r);
void pre_remove_image();
void handle_pre_remove_image(int r);
void trim_image();
void handle_trim_image(int r);
void detach_child();
void handle_detach_child(int r);
void send_disable_mirror();
void handle_disable_mirror(int r);
void send_close_image(int r);
void handle_send_close_image(int r);
void remove_header();
void handle_remove_header(int r);
void remove_header_v2();
void handle_remove_header_v2(int r);
void remove_image();
void remove_v1_image();
void handle_remove_v1_image(int r);
void remove_v2_image();
void dir_get_image_id();
void handle_dir_get_image_id(int r);
void dir_get_image_name();
void handle_dir_get_image_name(int r);
void remove_id_object();
void handle_remove_id_object(int r);
void dir_remove_image();
void handle_dir_remove_image(int r);
void finish(int r);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::RemoveRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_REMOVE_REQUEST_H
| 6,373 | 31.191919 | 80 | h |
null | ceph-main/src/librbd/image/SetSnapRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H
#define CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H
#include "cls/rbd/cls_rbd_client.h"
#include <string>
class Context;
namespace librbd {
template <typename> class ExclusiveLock;
class ImageCtx;
template <typename> class ObjectMap;
namespace image {
template <typename> class RefreshParentRequest;
template <typename ImageCtxT = ImageCtx>
class SetSnapRequest {
public:
static SetSnapRequest *create(ImageCtxT &image_ctx, uint64_t snap_id,
Context *on_finish) {
return new SetSnapRequest(image_ctx, snap_id, on_finish);
}
~SetSnapRequest();
void send();
private:
/**
* @verbatim
*
* <start>
* |
* | (set snap)
* |-----------> BLOCK_WRITES
* | |
* | v
* | SHUTDOWN_EXCLUSIVE_LOCK (skip if lock inactive
* | | or disabled)
* | v
* | REFRESH_PARENT (skip if no parent
* | | or refresh not needed)
* | v
* | OPEN_OBJECT_MAP (skip if map disabled)
* | |
* | v
* | <apply>
* | |
* | v
* | FINALIZE_REFRESH_PARENT (skip if no parent
* | | or refresh not needed)
* | v
* | <finish>
* |
* \-----------> INIT_EXCLUSIVE_LOCK (skip if active or
* | disabled)
* v
* REFRESH_PARENT (skip if no parent
* | or refresh not needed)
* v
* <apply>
* |
* v
* FINALIZE_REFRESH_PARENT (skip if no parent
* | or refresh not needed)
* v
* <finish>
*
* @endverbatim
*/
SetSnapRequest(ImageCtxT &image_ctx, uint64_t snap_id, Context *on_finish);
ImageCtxT &m_image_ctx;
uint64_t m_snap_id;
Context *m_on_finish;
ExclusiveLock<ImageCtxT> *m_exclusive_lock;
ObjectMap<ImageCtxT> *m_object_map;
RefreshParentRequest<ImageCtxT> *m_refresh_parent;
bool m_writes_blocked;
void send_block_writes();
Context *handle_block_writes(int *result);
void send_init_exclusive_lock();
Context *handle_init_exclusive_lock(int *result);
Context *send_shut_down_exclusive_lock(int *result);
Context *handle_shut_down_exclusive_lock(int *result);
Context *send_refresh_parent(int *result);
Context *handle_refresh_parent(int *result);
Context *send_open_object_map(int *result);
Context *handle_open_object_map(int *result);
Context *send_finalize_refresh_parent(int *result);
Context *handle_finalize_refresh_parent(int *result);
int apply();
void finalize();
void send_complete();
};
} // namespace image
} // namespace librbd
extern template class librbd::image::SetSnapRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_SNAP_SET_REQUEST_H
| 3,340 | 27.07563 | 77 | h |
null | ceph-main/src/librbd/image/ValidatePoolRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_VALIDATE_POOL_REQUEST_H
#define CEPH_LIBRBD_IMAGE_VALIDATE_POOL_REQUEST_H
#include "include/common_fwd.h"
#include "include/rados/librados.hpp"
#include "include/buffer.h"
class Context;
namespace librbd {
struct ImageCtx;
namespace asio { struct ContextWQ; }
namespace image {
template <typename ImageCtxT>
class ValidatePoolRequest {
public:
static ValidatePoolRequest* create(librados::IoCtx& io_ctx,
Context *on_finish) {
return new ValidatePoolRequest(io_ctx, on_finish);
}
ValidatePoolRequest(librados::IoCtx& io_ctx, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v (overwrites validated)
* READ RBD INFO . . . . . . . . .
* | . .
* | . (snapshots validated) .
* | . . . . . . . . . . .
* v . .
* CREATE SNAPSHOT . .
* | . .
* v . .
* WRITE RBD INFO . .
* | . .
* v . .
* REMOVE SNAPSHOT . .
* | . .
* v . .
* OVERWRITE RBD INFO < . . . .
* | .
* v .
* <finish> < . . . . . . . . . .`
*
* @endverbatim
*/
librados::IoCtx m_io_ctx;
CephContext* m_cct;
Context* m_on_finish;
int m_ret_val = 0;
bufferlist m_out_bl;
uint64_t m_snap_id = 0;
void read_rbd_info();
void handle_read_rbd_info(int r);
void create_snapshot();
void handle_create_snapshot(int r);
void write_rbd_info();
void handle_write_rbd_info(int r);
void remove_snapshot();
void handle_remove_snapshot(int r);
void overwrite_rbd_info();
void handle_overwrite_rbd_info(int r);
void finish(int r);
};
} // namespace image
} // namespace librbd
extern template class librbd::image::ValidatePoolRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IMAGE_VALIDATE_POOL_REQUEST_H
| 2,228 | 22.712766 | 75 | h |
null | ceph-main/src/librbd/image_watcher/NotifyLockOwner.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IMAGE_WATCHER_NOTIFY_LOCK_OWNER_H
#define CEPH_LIBRBD_IMAGE_WATCHER_NOTIFY_LOCK_OWNER_H
#include "include/buffer.h"
#include "librbd/watcher/Types.h"
class Context;
namespace librbd {
struct ImageCtx;
namespace watcher { class Notifier; }
namespace image_watcher {
class NotifyLockOwner {
public:
static NotifyLockOwner *create(ImageCtx &image_ctx,
watcher::Notifier ¬ifier,
bufferlist &&bl, Context *on_finish) {
return new NotifyLockOwner(image_ctx, notifier, std::move(bl), on_finish);
}
NotifyLockOwner(ImageCtx &image_ctx, watcher::Notifier ¬ifier,
bufferlist &&bl, Context *on_finish);
void send();
private:
ImageCtx &m_image_ctx;
watcher::Notifier &m_notifier;
bufferlist m_bl;
watcher::NotifyResponse m_notify_response;
Context *m_on_finish;
void send_notify();
void handle_notify(int r);
void finish(int r);
};
} // namespace image_watcher
} // namespace librbd
#endif // CEPH_LIBRBD_IMAGE_WATCHER_NOTIFY_LOCK_OWNER_H
| 1,179 | 22.137255 | 78 | h |
null | ceph-main/src/librbd/io/AioCompletion.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_AIO_COMPLETION_H
#define CEPH_LIBRBD_IO_AIO_COMPLETION_H
#include "common/ceph_time.h"
#include "include/common_fwd.h"
#include "include/Context.h"
#include "include/utime.h"
#include "include/rbd/librbd.hpp"
#include "librbd/ImageCtx.h"
#include "librbd/io/AsyncOperation.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
#include <atomic>
#include <condition_variable>
#include <mutex>
struct Context;
namespace librbd {
namespace io {
/**
* AioCompletion is the overall completion for a single
* rbd I/O request. It may be composed of many AioObjectRequests,
* which each go to a single object.
*
* The retrying of individual requests is handled at a lower level,
* so all AioCompletion cares about is the count of outstanding
* requests. The number of expected individual requests should be
* set initially using set_request_count() prior to issuing the
* requests. This ensures that the completion will not be completed
* within the caller's thread of execution (instead via a librados
* context or via a thread pool context for cache read hits).
*/
struct AioCompletion {
typedef enum {
AIO_STATE_PENDING = 0,
AIO_STATE_CALLBACK,
AIO_STATE_COMPLETE,
} aio_state_t;
mutable std::mutex lock;
std::condition_variable cond;
callback_t complete_cb = nullptr;
void *complete_arg = nullptr;
rbd_completion_t rbd_comp = nullptr;
/// note: only using atomic for built-in memory barrier
std::atomic<aio_state_t> state{AIO_STATE_PENDING};
std::atomic<ssize_t> rval{0};
std::atomic<int> error_rval{0};
std::atomic<uint32_t> ref{1};
std::atomic<uint32_t> pending_count{0}; ///< number of requests/blocks
std::atomic<bool> released{false};
ImageCtx *ictx = nullptr;
coarse_mono_time start_time;
aio_type_t aio_type = AIO_TYPE_NONE;
ReadResult read_result;
AsyncOperation async_op;
bool event_notify = false;
bool was_armed = false;
bool external_callback = false;
Context* image_dispatcher_ctx = nullptr;
template <typename T, void (T::*MF)(int)>
static void callback_adapter(completion_t cb, void *arg) {
AioCompletion *comp = reinterpret_cast<AioCompletion *>(cb);
T *t = reinterpret_cast<T *>(arg);
(t->*MF)(comp->get_return_value());
comp->release();
}
static AioCompletion *create(void *cb_arg, callback_t cb_complete,
rbd_completion_t rbd_comp) {
AioCompletion *comp = new AioCompletion();
comp->set_complete_cb(cb_arg, cb_complete);
comp->rbd_comp = (rbd_comp != nullptr ? rbd_comp : comp);
return comp;
}
template <typename T, void (T::*MF)(int) = &T::complete>
static AioCompletion *create(T *obj) {
AioCompletion *comp = new AioCompletion();
comp->set_complete_cb(obj, &callback_adapter<T, MF>);
comp->rbd_comp = comp;
return comp;
}
template <typename T, void (T::*MF)(int) = &T::complete>
static AioCompletion *create_and_start(T *obj, ImageCtx *image_ctx,
aio_type_t type) {
AioCompletion *comp = create<T, MF>(obj);
comp->init_time(image_ctx, type);
comp->start_op();
return comp;
}
AioCompletion() {
}
~AioCompletion() {
}
int wait_for_complete();
void finalize();
inline bool is_initialized(aio_type_t type) const {
std::unique_lock<std::mutex> locker(lock);
return ((ictx != nullptr) && (aio_type == type));
}
inline bool is_started() const {
std::unique_lock<std::mutex> locker(lock);
return async_op.started();
}
void block(CephContext* cct);
void unblock(CephContext* cct);
void init_time(ImageCtx *i, aio_type_t t);
void start_op();
void fail(int r);
void complete();
void set_complete_cb(void *cb_arg, callback_t cb) {
complete_cb = cb;
complete_arg = cb_arg;
}
void set_request_count(uint32_t num);
void add_request() {
ceph_assert(pending_count > 0);
get();
}
void complete_request(ssize_t r);
bool is_complete();
ssize_t get_return_value();
void get() {
ceph_assert(ref > 0);
++ref;
}
void release() {
bool previous_released = released.exchange(true);
ceph_assert(!previous_released);
put();
}
void put() {
uint32_t previous_ref = ref--;
ceph_assert(previous_ref > 0);
if (previous_ref == 1) {
delete this;
}
}
void set_event_notify(bool s) {
event_notify = s;
}
void *get_arg() {
return complete_arg;
}
private:
void queue_complete();
void complete_external_callback();
void complete_event_socket();
void notify_callbacks_complete();
};
class C_AioRequest : public Context {
public:
C_AioRequest(AioCompletion *completion) : m_completion(completion) {
m_completion->add_request();
}
~C_AioRequest() override {}
void finish(int r) override {
m_completion->complete_request(r);
}
protected:
AioCompletion *m_completion;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_AIO_COMPLETION_H
| 5,107 | 24.039216 | 74 | h |
null | ceph-main/src/librbd/io/CopyupRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_COPYUP_REQUEST_H
#define CEPH_LIBRBD_IO_COPYUP_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/interval_set.h"
#include "common/ceph_mutex.h"
#include "common/zipkin_trace.h"
#include "librbd/io/AsyncOperation.h"
#include "librbd/io/Types.h"
#include <map>
#include <string>
#include <vector>
namespace ZTracer { struct Trace; }
namespace librbd {
struct ImageCtx;
namespace io {
template <typename I> class AbstractObjectWriteRequest;
template <typename ImageCtxT = librbd::ImageCtx>
class CopyupRequest {
public:
static CopyupRequest* create(ImageCtxT *ictx, uint64_t objectno,
Extents &&image_extents, ImageArea area,
const ZTracer::Trace &parent_trace) {
return new CopyupRequest(ictx, objectno, std::move(image_extents), area,
parent_trace);
}
CopyupRequest(ImageCtxT *ictx, uint64_t objectno,
Extents &&image_extents, ImageArea area,
const ZTracer::Trace &parent_trace);
~CopyupRequest();
void append_request(AbstractObjectWriteRequest<ImageCtxT> *req,
const Extents& object_extents);
void send();
private:
/**
* Copyup requests go through the following state machine to read from the
* parent image, update the object map, and copyup the object:
*
*
* @verbatim
*
* <start>
* |
* /---------/ \---------\
* | |
* v v
* READ_FROM_PARENT DEEP_COPY
* | |
* \---------\ /---------/
* |
* v (skip if not needed)
* UPDATE_OBJECT_MAPS
* |
* v (skip if not needed)
* COPYUP
* |
* v
* <finish>
*
* @endverbatim
*
* The OBJECT_MAP state is skipped if the object map isn't enabled or if
* an object map update isn't required. The COPYUP state is skipped if
* no data was read from the parent *and* there are no additional ops.
*/
typedef std::vector<AbstractObjectWriteRequest<ImageCtxT> *> WriteRequests;
ImageCtxT *m_image_ctx;
uint64_t m_object_no;
Extents m_image_extents;
ImageArea m_image_area;
ZTracer::Trace m_trace;
bool m_flatten = false;
bool m_copyup_required = true;
bool m_copyup_is_zero = true;
bool m_deep_copied = false;
Extents m_copyup_extent_map;
ceph::bufferlist m_copyup_data;
AsyncOperation m_async_op;
std::vector<uint64_t> m_snap_ids;
bool m_first_snap_is_clean = false;
ceph::mutex m_lock = ceph::make_mutex("CopyupRequest", false);
WriteRequests m_pending_requests;
unsigned m_pending_copyups = 0;
int m_copyup_ret_val = 0;
WriteRequests m_restart_requests;
bool m_append_request_permitted = true;
interval_set<uint64_t> m_write_object_extents;
void read_from_parent();
void handle_read_from_parent(int r);
void deep_copy();
void handle_deep_copy(int r);
void update_object_maps();
void handle_update_object_maps(int r);
void copyup();
void handle_copyup(int r);
void finish(int r);
void complete_requests(bool override_restart_retval, int r);
void disable_append_requests();
void remove_from_list();
bool is_copyup_required();
bool is_update_object_map_required(int r);
bool is_deep_copy() const;
void compute_deep_copy_snap_ids();
void convert_copyup_extent_map();
int prepare_copyup_data();
};
} // namespace io
} // namespace librbd
extern template class librbd::io::CopyupRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H
| 3,844 | 25.335616 | 77 | h |
null | ceph-main/src/librbd/io/Dispatcher.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_DISPATCHER_H
#define CEPH_LIBRBD_IO_DISPATCHER_H
#include "include/int_types.h"
#include "include/Context.h"
#include "common/ceph_mutex.h"
#include "common/dout.h"
#include "common/AsyncOpTracker.h"
#include "librbd/Utils.h"
#include "librbd/io/DispatcherInterface.h"
#include "librbd/io/Types.h"
#include <map>
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "librbd::io::Dispatcher: " << this \
<< " " << __func__ << ": "
namespace librbd {
namespace io {
template <typename ImageCtxT, typename DispatchInterfaceT>
class Dispatcher : public DispatchInterfaceT {
public:
typedef typename DispatchInterfaceT::Dispatch Dispatch;
typedef typename DispatchInterfaceT::DispatchLayer DispatchLayer;
typedef typename DispatchInterfaceT::DispatchSpec DispatchSpec;
Dispatcher(ImageCtxT* image_ctx)
: m_image_ctx(image_ctx),
m_lock(ceph::make_shared_mutex(
librbd::util::unique_lock_name("librbd::io::Dispatcher::lock",
this))) {
}
virtual ~Dispatcher() {
ceph_assert(m_dispatches.empty());
}
void shut_down(Context* on_finish) override {
auto cct = m_image_ctx->cct;
ldout(cct, 5) << dendl;
std::map<DispatchLayer, DispatchMeta> dispatches;
{
std::unique_lock locker{m_lock};
std::swap(dispatches, m_dispatches);
}
for (auto it : dispatches) {
shut_down_dispatch(it.second, &on_finish);
}
on_finish->complete(0);
}
void register_dispatch(Dispatch* dispatch) override {
auto cct = m_image_ctx->cct;
auto type = dispatch->get_dispatch_layer();
ldout(cct, 5) << "dispatch_layer=" << type << dendl;
std::unique_lock locker{m_lock};
auto result = m_dispatches.insert(
{type, {dispatch, new AsyncOpTracker()}});
ceph_assert(result.second);
}
bool exists(DispatchLayer dispatch_layer) override {
std::unique_lock locker{m_lock};
return m_dispatches.find(dispatch_layer) != m_dispatches.end();
}
void shut_down_dispatch(DispatchLayer dispatch_layer,
Context* on_finish) override {
auto cct = m_image_ctx->cct;
ldout(cct, 5) << "dispatch_layer=" << dispatch_layer << dendl;
DispatchMeta dispatch_meta;
{
std::unique_lock locker{m_lock};
auto it = m_dispatches.find(dispatch_layer);
if (it == m_dispatches.end()) {
on_finish->complete(0);
return;
}
dispatch_meta = it->second;
m_dispatches.erase(it);
}
shut_down_dispatch(dispatch_meta, &on_finish);
on_finish->complete(0);
}
void send(DispatchSpec* dispatch_spec) {
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "dispatch_spec=" << dispatch_spec << dendl;
auto dispatch_layer = dispatch_spec->dispatch_layer;
// apply the IO request to all layers -- this method will be re-invoked
// by the dispatch layer if continuing / restarting the IO
while (true) {
m_lock.lock_shared();
dispatch_layer = dispatch_spec->dispatch_layer;
auto it = m_dispatches.upper_bound(dispatch_layer);
if (it == m_dispatches.end()) {
// the request is complete if handled by all layers
dispatch_spec->dispatch_result = DISPATCH_RESULT_COMPLETE;
m_lock.unlock_shared();
break;
}
auto& dispatch_meta = it->second;
auto dispatch = dispatch_meta.dispatch;
auto async_op_tracker = dispatch_meta.async_op_tracker;
dispatch_spec->dispatch_result = DISPATCH_RESULT_INVALID;
// prevent recursive locking back into the dispatcher while handling IO
async_op_tracker->start_op();
m_lock.unlock_shared();
// advance to next layer in case we skip or continue
dispatch_spec->dispatch_layer = dispatch->get_dispatch_layer();
bool handled = send_dispatch(dispatch, dispatch_spec);
async_op_tracker->finish_op();
// handled ops will resume when the dispatch ctx is invoked
if (handled) {
return;
}
}
// skipped through to the last layer
dispatch_spec->dispatcher_ctx.complete(0);
}
protected:
struct DispatchMeta {
Dispatch* dispatch = nullptr;
AsyncOpTracker* async_op_tracker = nullptr;
DispatchMeta() {
}
DispatchMeta(Dispatch* dispatch, AsyncOpTracker* async_op_tracker)
: dispatch(dispatch), async_op_tracker(async_op_tracker) {
}
};
ImageCtxT* m_image_ctx;
ceph::shared_mutex m_lock;
std::map<DispatchLayer, DispatchMeta> m_dispatches;
virtual bool send_dispatch(Dispatch* dispatch,
DispatchSpec* dispatch_spec) = 0;
protected:
struct C_LayerIterator : public Context {
Dispatcher* dispatcher;
Context* on_finish;
DispatchLayer dispatch_layer;
C_LayerIterator(Dispatcher* dispatcher,
DispatchLayer start_layer,
Context* on_finish)
: dispatcher(dispatcher), on_finish(on_finish), dispatch_layer(start_layer) {
}
void complete(int r) override {
while (true) {
dispatcher->m_lock.lock_shared();
auto it = dispatcher->m_dispatches.upper_bound(dispatch_layer);
if (it == dispatcher->m_dispatches.end()) {
dispatcher->m_lock.unlock_shared();
Context::complete(r);
return;
}
auto& dispatch_meta = it->second;
auto dispatch = dispatch_meta.dispatch;
// prevent recursive locking back into the dispatcher while handling IO
dispatch_meta.async_op_tracker->start_op();
dispatcher->m_lock.unlock_shared();
// next loop should start after current layer
dispatch_layer = dispatch->get_dispatch_layer();
auto handled = execute(dispatch, this);
dispatch_meta.async_op_tracker->finish_op();
if (handled) {
break;
}
}
}
void finish(int r) override {
on_finish->complete(0);
}
virtual bool execute(Dispatch* dispatch,
Context* on_finish) = 0;
};
struct C_InvalidateCache : public C_LayerIterator {
C_InvalidateCache(Dispatcher* dispatcher, DispatchLayer start_layer, Context* on_finish)
: C_LayerIterator(dispatcher, start_layer, on_finish) {
}
bool execute(Dispatch* dispatch,
Context* on_finish) override {
return dispatch->invalidate_cache(on_finish);
}
};
private:
void shut_down_dispatch(DispatchMeta& dispatch_meta,
Context** on_finish) {
auto dispatch = dispatch_meta.dispatch;
auto async_op_tracker = dispatch_meta.async_op_tracker;
auto ctx = *on_finish;
ctx = new LambdaContext(
[dispatch, async_op_tracker, ctx](int r) {
delete dispatch;
delete async_op_tracker;
ctx->complete(r);
});
ctx = new LambdaContext([dispatch, ctx](int r) {
dispatch->shut_down(ctx);
});
*on_finish = new LambdaContext([async_op_tracker, ctx](int r) {
async_op_tracker->wait_for_ops(ctx);
});
}
};
} // namespace io
} // namespace librbd
#undef dout_subsys
#undef dout_prefix
#define dout_prefix *_dout
#endif // CEPH_LIBRBD_IO_DISPATCHER_H
| 7,351 | 28.059289 | 92 | h |
null | ceph-main/src/librbd/io/DispatcherInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_DISPATCHER_INTERFACE_H
#define CEPH_LIBRBD_IO_DISPATCHER_INTERFACE_H
#include "include/int_types.h"
struct Context;
namespace librbd {
namespace io {
template <typename DispatchT>
struct DispatcherInterface {
public:
typedef DispatchT Dispatch;
typedef typename DispatchT::DispatchLayer DispatchLayer;
typedef typename DispatchT::DispatchSpec DispatchSpec;
virtual ~DispatcherInterface() {
}
virtual void shut_down(Context* on_finish) = 0;
virtual void register_dispatch(Dispatch* dispatch) = 0;
virtual bool exists(DispatchLayer dispatch_layer) = 0;
virtual void shut_down_dispatch(DispatchLayer dispatch_layer,
Context* on_finish) = 0;
virtual void send(DispatchSpec* dispatch_spec) = 0;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_DISPATCHER_INTERFACE_H
| 967 | 24.473684 | 70 | h |
null | ceph-main/src/librbd/io/ImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_IO_IMAGE_DISPATCH_H
#include "librbd/io/ImageDispatchInterface.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/zipkin_trace.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename ImageCtxT>
class ImageDispatch : public ImageDispatchInterface {
public:
ImageDispatch(ImageCtxT* image_ctx) : m_image_ctx(image_ctx) {
}
ImageDispatchLayer get_dispatch_layer() const override {
return IMAGE_DISPATCH_LAYER_CORE;
}
void shut_down(Context* on_finish) override;
bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool invalidate_cache(Context* on_finish) override;
private:
ImageCtxT* m_image_ctx;
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_IMAGE_DISPATCH_H
| 3,345 | 33.854167 | 77 | h |
null | ceph-main/src/librbd/io/ImageDispatchInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_DISPATCH_INTERFACE_H
#define CEPH_LIBRBD_IO_IMAGE_DISPATCH_INTERFACE_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
#include <atomic>
struct Context;
namespace librbd {
namespace io {
struct AioCompletion;
struct ImageDispatchSpec;
struct ImageDispatchInterface {
typedef ImageDispatchLayer DispatchLayer;
typedef ImageDispatchSpec DispatchSpec;
virtual ~ImageDispatchInterface() {
}
virtual ImageDispatchLayer get_dispatch_layer() const = 0;
virtual void shut_down(Context* on_finish) = 0;
virtual bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool invalidate_cache(Context* on_finish) = 0;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_IMAGE_DISPATCH_INTERFACE_H
| 3,262 | 36.079545 | 77 | h |
null | ceph-main/src/librbd/io/ImageDispatchSpec.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_DISPATCH_SPEC_H
#define CEPH_LIBRBD_IO_IMAGE_DISPATCH_SPEC_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/Context.h"
#include "common/zipkin_trace.h"
#include "librbd/io/AioCompletion.h"
#include "librbd/io/Types.h"
#include "librbd/io/ReadResult.h"
#include <boost/variant/variant.hpp>
#include <atomic>
namespace librbd {
class ImageCtx;
namespace io {
struct ImageDispatcherInterface;
class ImageDispatchSpec {
private:
// helper to avoid extra heap allocation per object IO
struct C_Dispatcher : public Context {
ImageDispatchSpec* image_dispatch_spec;
C_Dispatcher(ImageDispatchSpec* image_dispatch_spec)
: image_dispatch_spec(image_dispatch_spec) {
}
void complete(int r) override;
void finish(int r) override;
};
public:
struct Read {
ReadResult read_result;
int read_flags;
Read(ReadResult &&read_result, int read_flags)
: read_result(std::move(read_result)), read_flags(read_flags) {
}
};
struct Discard {
uint32_t discard_granularity_bytes;
Discard(uint32_t discard_granularity_bytes)
: discard_granularity_bytes(discard_granularity_bytes) {
}
};
struct Write {
bufferlist bl;
Write(bufferlist&& bl) : bl(std::move(bl)) {
}
};
struct WriteSame {
bufferlist bl;
WriteSame(bufferlist&& bl) : bl(std::move(bl)) {
}
};
struct CompareAndWrite {
bufferlist cmp_bl;
bufferlist bl;
uint64_t *mismatch_offset;
CompareAndWrite(bufferlist&& cmp_bl, bufferlist&& bl,
uint64_t *mismatch_offset)
: cmp_bl(std::move(cmp_bl)), bl(std::move(bl)),
mismatch_offset(mismatch_offset) {
}
};
struct Flush {
FlushSource flush_source;
Flush(FlushSource flush_source) : flush_source(flush_source) {
}
};
struct ListSnaps {
SnapIds snap_ids;
int list_snaps_flags;
SnapshotDelta* snapshot_delta;
ListSnaps(SnapIds&& snap_ids, int list_snaps_flags,
SnapshotDelta* snapshot_delta)
: snap_ids(std::move(snap_ids)), list_snaps_flags(list_snaps_flags),
snapshot_delta(snapshot_delta) {
}
};
typedef boost::variant<Read,
Discard,
Write,
WriteSame,
CompareAndWrite,
Flush,
ListSnaps> Request;
C_Dispatcher dispatcher_ctx;
ImageDispatcherInterface* image_dispatcher;
ImageDispatchLayer dispatch_layer;
std::atomic<uint32_t> image_dispatch_flags = 0;
DispatchResult dispatch_result = DISPATCH_RESULT_INVALID;
AioCompletion* aio_comp;
Extents image_extents;
Request request;
IOContext io_context;
int op_flags;
ZTracer::Trace parent_trace;
uint64_t tid = 0;
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_read(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
Read{std::move(read_result), read_flags},
io_context, op_flags, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_discard(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
Discard{discard_granularity_bytes},
{}, 0, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_write(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
Write{std::move(bl)},
{}, op_flags, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_write_same(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
bufferlist &&bl, int op_flags, const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
WriteSame{std::move(bl)},
{}, op_flags, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_compare_and_write(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
CompareAndWrite{std::move(cmp_bl),
std::move(bl),
mismatch_offset},
{}, op_flags, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_flush(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp, {},
ImageArea::DATA /* dummy for {} */,
Flush{flush_source}, {}, 0, parent_trace);
}
template <typename ImageCtxT = ImageCtx>
static ImageDispatchSpec* create_list_snaps(
ImageCtxT &image_ctx, ImageDispatchLayer image_dispatch_layer,
AioCompletion *aio_comp, Extents &&image_extents, ImageArea area,
SnapIds&& snap_ids, int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace) {
return new ImageDispatchSpec(image_ctx.io_image_dispatcher,
image_dispatch_layer, aio_comp,
std::move(image_extents), area,
ListSnaps{std::move(snap_ids),
list_snaps_flags, snapshot_delta},
{}, 0, parent_trace);
}
~ImageDispatchSpec() {
aio_comp->put();
}
void send();
void fail(int r);
private:
struct SendVisitor;
struct IsWriteOpVisitor;
struct TokenRequestedVisitor;
ImageDispatchSpec(ImageDispatcherInterface* image_dispatcher,
ImageDispatchLayer image_dispatch_layer,
AioCompletion* aio_comp, Extents&& image_extents,
ImageArea area, Request&& request, IOContext io_context,
int op_flags, const ZTracer::Trace& parent_trace)
: dispatcher_ctx(this), image_dispatcher(image_dispatcher),
dispatch_layer(image_dispatch_layer), aio_comp(aio_comp),
image_extents(std::move(image_extents)), request(std::move(request)),
io_context(io_context), op_flags(op_flags), parent_trace(parent_trace) {
ceph_assert(aio_comp->image_dispatcher_ctx == nullptr);
aio_comp->image_dispatcher_ctx = &dispatcher_ctx;
aio_comp->get();
switch (area) {
case ImageArea::DATA:
break;
case ImageArea::CRYPTO_HEADER:
image_dispatch_flags |= IMAGE_DISPATCH_FLAG_CRYPTO_HEADER;
break;
default:
ceph_abort();
}
}
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_IMAGE_DISPATCH_SPEC_H
| 8,864 | 33.764706 | 79 | h |
null | ceph-main/src/librbd/io/ImageDispatcher.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_DISPATCHER_H
#define CEPH_LIBRBD_IO_IMAGE_DISPATCHER_H
#include "include/int_types.h"
#include "common/ceph_mutex.h"
#include "librbd/io/Dispatcher.h"
#include "librbd/io/ImageDispatchInterface.h"
#include "librbd/io/ImageDispatchSpec.h"
#include "librbd/io/ImageDispatcherInterface.h"
#include "librbd/io/Types.h"
#include <atomic>
#include <map>
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
template <typename> struct QosImageDispatch;
template <typename> struct WriteBlockImageDispatch;
template <typename ImageCtxT = ImageCtx>
class ImageDispatcher : public Dispatcher<ImageCtxT, ImageDispatcherInterface> {
public:
ImageDispatcher(ImageCtxT* image_ctx);
void invalidate_cache(Context* on_finish) override;
void shut_down(Context* on_finish) override;
void apply_qos_schedule_tick_min(uint64_t tick) override;
void apply_qos_limit(uint64_t flag, uint64_t limit, uint64_t burst,
uint64_t burst_seconds) override;
void apply_qos_exclude_ops(uint64_t exclude_ops) override;
bool writes_blocked() const override;
int block_writes() override;
void block_writes(Context *on_blocked) override;
void unblock_writes() override;
void wait_on_writes_unblocked(Context *on_unblocked) override;
void remap_to_physical(Extents& image_extents, ImageArea area) override;
ImageArea remap_to_logical(Extents& image_extents) override;
protected:
bool send_dispatch(
ImageDispatchInterface* image_dispatch,
ImageDispatchSpec* image_dispatch_spec) override;
private:
struct SendVisitor;
struct PreprocessVisitor;
using typename Dispatcher<ImageCtxT, ImageDispatcherInterface>::C_InvalidateCache;
std::atomic<uint64_t> m_next_tid{0};
QosImageDispatch<ImageCtxT>* m_qos_image_dispatch = nullptr;
WriteBlockImageDispatch<ImageCtxT>* m_write_block_dispatch = nullptr;
bool preprocess(ImageDispatchSpec* image_dispatch_spec);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ImageDispatcher<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_IMAGE_DISPATCHER_H
| 2,206 | 27.294872 | 84 | h |
null | ceph-main/src/librbd/io/ImageDispatcherInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_DISPATCHER_INTERFACE_H
#define CEPH_LIBRBD_IO_IMAGE_DISPATCHER_INTERFACE_H
#include "include/int_types.h"
#include "librbd/io/DispatcherInterface.h"
#include "librbd/io/ImageDispatchInterface.h"
#include "librbd/io/Types.h"
struct Context;
namespace librbd {
namespace io {
struct ImageDispatcherInterface
: public DispatcherInterface<ImageDispatchInterface> {
public:
virtual void apply_qos_schedule_tick_min(uint64_t tick) = 0;
virtual void apply_qos_limit(uint64_t flag, uint64_t limit,
uint64_t burst, uint64_t burst_seconds) = 0;
virtual void apply_qos_exclude_ops(uint64_t exclude_ops) = 0;
virtual bool writes_blocked() const = 0;
virtual int block_writes() = 0;
virtual void block_writes(Context *on_blocked) = 0;
virtual void unblock_writes() = 0;
virtual void wait_on_writes_unblocked(Context *on_unblocked) = 0;
virtual void invalidate_cache(Context* on_finish) = 0;
virtual void remap_to_physical(Extents& image_extents, ImageArea area) = 0;
virtual ImageArea remap_to_logical(Extents& image_extents) = 0;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_IMAGE_DISPATCHER_INTERFACE_H
| 1,308 | 30.166667 | 77 | h |
null | ceph-main/src/librbd/io/ImageRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_IMAGE_REQUEST_H
#define CEPH_LIBRBD_IO_IMAGE_REQUEST_H
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "common/zipkin_trace.h"
#include "osd/osd_types.h"
#include "librbd/Utils.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <list>
#include <utility>
#include <vector>
namespace librbd {
class ImageCtx;
namespace io {
class AioCompletion;
class ObjectDispatchSpec;
class ReadResult;
template <typename ImageCtxT = ImageCtx>
class ImageRequest {
public:
virtual ~ImageRequest() {
m_trace.event("finish");
}
static void aio_read(ImageCtxT *ictx, AioCompletion *c,
Extents &&image_extents, ImageArea area,
ReadResult &&read_result, IOContext io_context,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace);
static void aio_write(ImageCtxT *ictx, AioCompletion *c,
Extents &&image_extents, ImageArea area,
bufferlist &&bl, int op_flags,
const ZTracer::Trace &parent_trace);
static void aio_discard(ImageCtxT *ictx, AioCompletion *c,
Extents &&image_extents, ImageArea area,
uint32_t discard_granularity_bytes,
const ZTracer::Trace &parent_trace);
static void aio_flush(ImageCtxT *ictx, AioCompletion *c,
FlushSource flush_source,
const ZTracer::Trace &parent_trace);
static void aio_writesame(ImageCtxT *ictx, AioCompletion *c,
Extents &&image_extents, ImageArea area,
bufferlist &&bl, int op_flags,
const ZTracer::Trace &parent_trace);
static void aio_compare_and_write(ImageCtxT *ictx, AioCompletion *c,
Extents &&image_extents, ImageArea area,
bufferlist &&cmp_bl, bufferlist &&bl,
uint64_t *mismatch_offset, int op_flags,
const ZTracer::Trace &parent_trace);
void send();
inline const ZTracer::Trace &get_trace() const {
return m_trace;
}
protected:
typedef std::list<ObjectDispatchSpec*> ObjectRequests;
ImageCtxT &m_image_ctx;
AioCompletion *m_aio_comp;
Extents m_image_extents;
ImageArea m_image_area;
ZTracer::Trace m_trace;
ImageRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents &&image_extents, ImageArea area, const char *trace_name,
const ZTracer::Trace &parent_trace)
: m_image_ctx(image_ctx), m_aio_comp(aio_comp),
m_image_extents(std::move(image_extents)), m_image_area(area),
m_trace(librbd::util::create_trace(image_ctx, trace_name, parent_trace)) {
m_trace.event("start");
}
virtual void update_timestamp();
virtual void send_request() = 0;
virtual aio_type_t get_aio_type() const = 0;
virtual const char *get_request_type() const = 0;
};
template <typename ImageCtxT = ImageCtx>
class ImageReadRequest : public ImageRequest<ImageCtxT> {
public:
ImageReadRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents &&image_extents, ImageArea area,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace);
protected:
void send_request() override;
aio_type_t get_aio_type() const override {
return AIO_TYPE_READ;
}
const char *get_request_type() const override {
return "aio_read";
}
private:
IOContext m_io_context;
int m_op_flags;
int m_read_flags;
};
template <typename ImageCtxT = ImageCtx>
class AbstractImageWriteRequest : public ImageRequest<ImageCtxT> {
public:
inline void flag_synchronous() {
m_synchronous = true;
}
protected:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
AbstractImageWriteRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents &&image_extents, ImageArea area,
const char *trace_name,
const ZTracer::Trace &parent_trace)
: ImageRequest<ImageCtxT>(image_ctx, aio_comp, std::move(image_extents),
area, trace_name, parent_trace),
m_synchronous(false) {
}
void send_request() override;
virtual int prune_object_extents(
LightweightObjectExtents* object_extents) const {
return 0;
}
void send_object_requests(const LightweightObjectExtents &object_extents,
IOContext io_context, uint64_t journal_tid);
virtual ObjectDispatchSpec *create_object_request(
const LightweightObjectExtent &object_extent, IOContext io_context,
uint64_t journal_tid, bool single_extent, Context *on_finish) = 0;
virtual uint64_t append_journal_event(bool synchronous) = 0;
virtual void update_stats(size_t length) = 0;
private:
bool m_synchronous;
};
template <typename ImageCtxT = ImageCtx>
class ImageWriteRequest : public AbstractImageWriteRequest<ImageCtxT> {
public:
ImageWriteRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents &&image_extents, ImageArea area, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace)
: AbstractImageWriteRequest<ImageCtxT>(
image_ctx, aio_comp, std::move(image_extents), area,
"write", parent_trace),
m_bl(std::move(bl)), m_op_flags(op_flags) {
}
protected:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
aio_type_t get_aio_type() const override {
return AIO_TYPE_WRITE;
}
const char *get_request_type() const override {
return "aio_write";
}
void assemble_extent(const LightweightObjectExtent &object_extent,
bufferlist *bl);
ObjectDispatchSpec *create_object_request(
const LightweightObjectExtent &object_extent, IOContext io_context,
uint64_t journal_tid, bool single_extent, Context *on_finish) override;
uint64_t append_journal_event(bool synchronous) override;
void update_stats(size_t length) override;
private:
bufferlist m_bl;
int m_op_flags;
};
template <typename ImageCtxT = ImageCtx>
class ImageDiscardRequest : public AbstractImageWriteRequest<ImageCtxT> {
public:
ImageDiscardRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents&& image_extents, ImageArea area,
uint32_t discard_granularity_bytes,
const ZTracer::Trace &parent_trace)
: AbstractImageWriteRequest<ImageCtxT>(
image_ctx, aio_comp, std::move(image_extents), area,
"discard", parent_trace),
m_discard_granularity_bytes(discard_granularity_bytes) {
}
protected:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
aio_type_t get_aio_type() const override {
return AIO_TYPE_DISCARD;
}
const char *get_request_type() const override {
return "aio_discard";
}
ObjectDispatchSpec *create_object_request(
const LightweightObjectExtent &object_extent, IOContext io_context,
uint64_t journal_tid, bool single_extent, Context *on_finish) override;
uint64_t append_journal_event(bool synchronous) override;
void update_stats(size_t length) override;
int prune_object_extents(
LightweightObjectExtents* object_extents) const override;
private:
uint32_t m_discard_granularity_bytes;
};
template <typename ImageCtxT = ImageCtx>
class ImageFlushRequest : public ImageRequest<ImageCtxT> {
public:
ImageFlushRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
FlushSource flush_source,
const ZTracer::Trace &parent_trace)
: ImageRequest<ImageCtxT>(image_ctx, aio_comp, {},
ImageArea::DATA /* dummy for {} */,
"flush", parent_trace),
m_flush_source(flush_source) {
}
protected:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
void update_timestamp() override {
}
void send_request() override;
aio_type_t get_aio_type() const override {
return AIO_TYPE_FLUSH;
}
const char *get_request_type() const override {
return "aio_flush";
}
private:
FlushSource m_flush_source;
};
template <typename ImageCtxT = ImageCtx>
class ImageWriteSameRequest : public AbstractImageWriteRequest<ImageCtxT> {
public:
ImageWriteSameRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents&& image_extents, ImageArea area,
bufferlist &&bl, int op_flags,
const ZTracer::Trace &parent_trace)
: AbstractImageWriteRequest<ImageCtxT>(
image_ctx, aio_comp, std::move(image_extents), area,
"writesame", parent_trace),
m_data_bl(std::move(bl)), m_op_flags(op_flags) {
}
protected:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
aio_type_t get_aio_type() const override {
return AIO_TYPE_WRITESAME;
}
const char *get_request_type() const override {
return "aio_writesame";
}
ObjectDispatchSpec *create_object_request(
const LightweightObjectExtent &object_extent, IOContext io_context,
uint64_t journal_tid, bool single_extent, Context *on_finish) override;
uint64_t append_journal_event(bool synchronous) override;
void update_stats(size_t length) override;
private:
bufferlist m_data_bl;
int m_op_flags;
};
template <typename ImageCtxT = ImageCtx>
class ImageCompareAndWriteRequest : public AbstractImageWriteRequest<ImageCtxT> {
public:
using typename ImageRequest<ImageCtxT>::ObjectRequests;
ImageCompareAndWriteRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp,
Extents &&image_extents, ImageArea area,
bufferlist &&cmp_bl, bufferlist &&bl,
uint64_t *mismatch_offset, int op_flags,
const ZTracer::Trace &parent_trace)
: AbstractImageWriteRequest<ImageCtxT>(
image_ctx, aio_comp, std::move(image_extents), area,
"compare_and_write", parent_trace),
m_cmp_bl(std::move(cmp_bl)), m_bl(std::move(bl)),
m_mismatch_offset(mismatch_offset), m_op_flags(op_flags) {
}
protected:
void assemble_extent(const LightweightObjectExtent &object_extent,
bufferlist *bl, bufferlist *cmp_bl);
ObjectDispatchSpec *create_object_request(
const LightweightObjectExtent &object_extent, IOContext io_context,
uint64_t journal_tid, bool single_extent, Context *on_finish) override;
uint64_t append_journal_event(bool synchronous) override;
void update_stats(size_t length) override;
aio_type_t get_aio_type() const override {
return AIO_TYPE_COMPARE_AND_WRITE;
}
const char *get_request_type() const override {
return "aio_compare_and_write";
}
int prune_object_extents(
LightweightObjectExtents* object_extents) const override;
private:
bufferlist m_cmp_bl;
bufferlist m_bl;
uint64_t *m_mismatch_offset;
int m_op_flags;
};
template <typename ImageCtxT = ImageCtx>
class ImageListSnapsRequest : public ImageRequest<ImageCtxT> {
public:
ImageListSnapsRequest(
ImageCtxT& image_ctx, AioCompletion* aio_comp,
Extents&& image_extents, ImageArea area, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace& parent_trace);
protected:
void update_timestamp() override {}
void send_request() override;
aio_type_t get_aio_type() const override {
return AIO_TYPE_GENERIC;
}
const char *get_request_type() const override {
return "list-snaps";
}
private:
SnapIds m_snap_ids;
int m_list_snaps_flags;
SnapshotDelta* m_snapshot_delta;
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ImageRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageReadRequest<librbd::ImageCtx>;
extern template class librbd::io::AbstractImageWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageDiscardRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageFlushRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageWriteSameRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageCompareAndWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ImageListSnapsRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_IMAGE_REQUEST_H
| 12,696 | 32.589947 | 81 | h |
null | ceph-main/src/librbd/io/ObjectDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_DISPATCH_H
#define CEPH_LIBRBD_IO_OBJECT_DISPATCH_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "common/zipkin_trace.h"
#include "librbd/io/Types.h"
#include "librbd/io/ObjectDispatchInterface.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename ImageCtxT = librbd::ImageCtx>
class ObjectDispatch : public ObjectDispatchInterface {
public:
ObjectDispatch(ImageCtxT* image_ctx);
ObjectDispatchLayer get_dispatch_layer() const override {
return OBJECT_DISPATCH_LAYER_CORE;
}
void shut_down(Context* on_finish) override;
bool read(
uint64_t object_no, ReadExtents* extents, IOContext io_context,
int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
uint64_t* version, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags, int write_flags,
std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write_same(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool compare_and_write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
ceph::bufferlist&& write_data, IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
int* object_dispatch_flags, uint64_t* journal_tid,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
FlushSource flush_source, const ZTracer::Trace &parent_trace,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override {
return false;
}
bool list_snaps(
uint64_t object_no, io::Extents&& extents, SnapIds&& snap_ids,
int list_snap_flags, const ZTracer::Trace &parent_trace,
SnapshotDelta* snapshot_delta, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool invalidate_cache(Context* on_finish) override {
return false;
}
bool reset_existence_cache(Context* on_finish) override {
return false;
}
void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) override {
}
int prepare_copyup(
uint64_t object_no,
SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override {
return 0;
}
private:
ImageCtxT* m_image_ctx;
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ObjectDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_OBJECT_DISPATCH_H
| 3,809 | 31.844828 | 75 | h |
null | ceph-main/src/librbd/io/ObjectDispatchInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_DISPATCH_INTERFACE_H
#define CEPH_LIBRBD_IO_OBJECT_DISPATCH_INTERFACE_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
struct Context;
struct RWLock;
namespace librbd {
namespace io {
struct AioCompletion;
struct ObjectDispatchInterface;
struct ObjectDispatchSpec;
struct ObjectDispatchInterface {
typedef ObjectDispatchInterface Dispatch;
typedef ObjectDispatchLayer DispatchLayer;
typedef ObjectDispatchSpec DispatchSpec;
virtual ~ObjectDispatchInterface() {
}
virtual ObjectDispatchLayer get_dispatch_layer() const = 0;
virtual void shut_down(Context* on_finish) = 0;
virtual bool read(
uint64_t object_no, ReadExtents* extents, IOContext io_context,
int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
uint64_t* version, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool discard(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context**on_finish, Context* on_dispatched) = 0;
virtual bool write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags, int write_flags,
std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context**on_finish, Context* on_dispatched) = 0;
virtual bool write_same(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace,
int* object_dispatch_flags, uint64_t* journal_tid,
DispatchResult* dispatch_result, Context**on_finish,
Context* on_dispatched) = 0;
virtual bool compare_and_write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
ceph::bufferlist&& write_data, IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
int* object_dispatch_flags, uint64_t* journal_tid,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool flush(
FlushSource flush_source, const ZTracer::Trace &parent_trace,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) = 0;
virtual bool list_snaps(
uint64_t object_no, Extents&& extents, SnapIds&& snap_ids,
int list_snap_flags, const ZTracer::Trace &parent_trace,
SnapshotDelta* snapshot_delta, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) = 0;
virtual bool invalidate_cache(Context* on_finish) = 0;
virtual bool reset_existence_cache(Context* on_finish) = 0;
virtual void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) = 0;
virtual int prepare_copyup(
uint64_t object_no,
SnapshotSparseBufferlist* snapshot_sparse_bufferlist) = 0;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_OBJECT_DISPATCH_INTERFACE_H
| 3,719 | 35.116505 | 77 | h |
null | ceph-main/src/librbd/io/ObjectDispatchSpec.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_DISPATCH_SPEC_H
#define CEPH_LIBRBD_IO_OBJECT_DISPATCH_SPEC_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/Context.h"
#include "include/rados/librados.hpp"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <boost/variant/variant.hpp>
namespace librbd {
namespace io {
struct ObjectDispatcherInterface;
struct ObjectDispatchSpec {
private:
// helper to avoid extra heap allocation per object IO
struct C_Dispatcher : public Context {
ObjectDispatchSpec* object_dispatch_spec;
Context* on_finish;
C_Dispatcher(ObjectDispatchSpec* object_dispatch_spec, Context* on_finish)
: object_dispatch_spec(object_dispatch_spec), on_finish(on_finish) {
}
void complete(int r) override;
void finish(int r) override;
};
public:
struct RequestBase {
uint64_t object_no;
RequestBase(uint64_t object_no)
: object_no(object_no) {
}
};
struct ReadRequest : public RequestBase {
ReadExtents* extents;
int read_flags;
uint64_t* version;
ReadRequest(uint64_t object_no, ReadExtents* extents, int read_flags,
uint64_t* version)
: RequestBase(object_no), extents(extents), read_flags(read_flags),
version(version) {
}
};
struct WriteRequestBase : public RequestBase {
uint64_t object_off;
uint64_t journal_tid;
WriteRequestBase(uint64_t object_no, uint64_t object_off,
uint64_t journal_tid)
: RequestBase(object_no), object_off(object_off),
journal_tid(journal_tid) {
}
};
struct DiscardRequest : public WriteRequestBase {
uint64_t object_len;
int discard_flags;
DiscardRequest(uint64_t object_no, uint64_t object_off, uint64_t object_len,
int discard_flags, uint64_t journal_tid)
: WriteRequestBase(object_no, object_off, journal_tid),
object_len(object_len), discard_flags(discard_flags) {
}
};
struct WriteRequest : public WriteRequestBase {
ceph::bufferlist data;
int write_flags;
std::optional<uint64_t> assert_version;
WriteRequest(uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& data, int write_flags,
std::optional<uint64_t> assert_version, uint64_t journal_tid)
: WriteRequestBase(object_no, object_off, journal_tid),
data(std::move(data)), write_flags(write_flags),
assert_version(assert_version) {
}
};
struct WriteSameRequest : public WriteRequestBase {
uint64_t object_len;
LightweightBufferExtents buffer_extents;
ceph::bufferlist data;
WriteSameRequest(uint64_t object_no, uint64_t object_off,
uint64_t object_len,
LightweightBufferExtents&& buffer_extents,
ceph::bufferlist&& data, uint64_t journal_tid)
: WriteRequestBase(object_no, object_off, journal_tid),
object_len(object_len), buffer_extents(std::move(buffer_extents)),
data(std::move(data)) {
}
};
struct CompareAndWriteRequest : public WriteRequestBase {
ceph::bufferlist cmp_data;
ceph::bufferlist data;
uint64_t* mismatch_offset;
CompareAndWriteRequest(uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& cmp_data, ceph::bufferlist&& data,
uint64_t* mismatch_offset,
uint64_t journal_tid)
: WriteRequestBase(object_no, object_off, journal_tid),
cmp_data(std::move(cmp_data)), data(std::move(data)),
mismatch_offset(mismatch_offset) {
}
};
struct FlushRequest {
FlushSource flush_source;
uint64_t journal_tid;
FlushRequest(FlushSource flush_source, uint64_t journal_tid)
: flush_source(flush_source), journal_tid(journal_tid) {
}
};
struct ListSnapsRequest : public RequestBase {
Extents extents;
SnapIds snap_ids;
int list_snaps_flags;
SnapshotDelta* snapshot_delta;
ListSnapsRequest(uint64_t object_no, Extents&& extents,
SnapIds&& snap_ids, int list_snaps_flags,
SnapshotDelta* snapshot_delta)
: RequestBase(object_no), extents(std::move(extents)),
snap_ids(std::move(snap_ids)),list_snaps_flags(list_snaps_flags),
snapshot_delta(snapshot_delta) {
}
};
typedef boost::variant<ReadRequest,
DiscardRequest,
WriteRequest,
WriteSameRequest,
CompareAndWriteRequest,
FlushRequest,
ListSnapsRequest> Request;
C_Dispatcher dispatcher_ctx;
ObjectDispatcherInterface* object_dispatcher;
ObjectDispatchLayer dispatch_layer;
int object_dispatch_flags = 0;
DispatchResult dispatch_result = DISPATCH_RESULT_INVALID;
Request request;
IOContext io_context;
int op_flags;
ZTracer::Trace parent_trace;
template <typename ImageCtxT>
static ObjectDispatchSpec* create_read(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, ReadExtents* extents, IOContext io_context,
int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
uint64_t* version, Context* on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
ReadRequest{object_no, extents,
read_flags, version},
io_context, op_flags, parent_trace,
on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_discard(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, uint64_t object_off, uint64_t object_len,
IOContext io_context, int discard_flags, uint64_t journal_tid,
const ZTracer::Trace &parent_trace, Context *on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
DiscardRequest{object_no, object_off,
object_len, discard_flags,
journal_tid},
io_context, 0, parent_trace, on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_write(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags, int write_flags,
std::optional<uint64_t> assert_version, uint64_t journal_tid,
const ZTracer::Trace &parent_trace, Context *on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
WriteRequest{object_no, object_off,
std::move(data), write_flags,
assert_version, journal_tid},
io_context, op_flags, parent_trace,
on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_write_same(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, uint64_t object_off, uint64_t object_len,
LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
IOContext io_context, int op_flags, uint64_t journal_tid,
const ZTracer::Trace &parent_trace, Context *on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
WriteSameRequest{object_no, object_off,
object_len,
std::move(buffer_extents),
std::move(data),
journal_tid},
io_context, op_flags, parent_trace,
on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_compare_and_write(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
ceph::bufferlist&& write_data, IOContext io_context,
uint64_t *mismatch_offset, int op_flags, uint64_t journal_tid,
const ZTracer::Trace &parent_trace, Context *on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
CompareAndWriteRequest{object_no,
object_off,
std::move(cmp_data),
std::move(write_data),
mismatch_offset,
journal_tid},
io_context, op_flags, parent_trace,
on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_flush(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
FlushSource flush_source, uint64_t journal_tid,
const ZTracer::Trace &parent_trace, Context *on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
FlushRequest{flush_source, journal_tid},
{}, 0, parent_trace, on_finish);
}
template <typename ImageCtxT>
static ObjectDispatchSpec* create_list_snaps(
ImageCtxT* image_ctx, ObjectDispatchLayer object_dispatch_layer,
uint64_t object_no, Extents&& extents, SnapIds&& snap_ids,
int list_snaps_flags, const ZTracer::Trace &parent_trace,
SnapshotDelta* snapshot_delta, Context* on_finish) {
return new ObjectDispatchSpec(image_ctx->io_object_dispatcher,
object_dispatch_layer,
ListSnapsRequest{object_no,
std::move(extents),
std::move(snap_ids),
list_snaps_flags,
snapshot_delta},
{}, 0, parent_trace, on_finish);
}
void send();
void fail(int r);
private:
template <typename> friend class ObjectDispatcher;
ObjectDispatchSpec(ObjectDispatcherInterface* object_dispatcher,
ObjectDispatchLayer object_dispatch_layer,
Request&& request, IOContext io_context, int op_flags,
const ZTracer::Trace& parent_trace, Context* on_finish)
: dispatcher_ctx(this, on_finish), object_dispatcher(object_dispatcher),
dispatch_layer(object_dispatch_layer), request(std::move(request)),
io_context(io_context), op_flags(op_flags), parent_trace(parent_trace) {
}
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_OBJECT_DISPATCH_SPEC_H
| 11,715 | 38.581081 | 80 | h |
null | ceph-main/src/librbd/io/ObjectDispatcher.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_DISPATCHER_H
#define CEPH_LIBRBD_IO_OBJECT_DISPATCHER_H
#include "include/int_types.h"
#include "common/ceph_mutex.h"
#include "librbd/io/Dispatcher.h"
#include "librbd/io/ObjectDispatchInterface.h"
#include "librbd/io/ObjectDispatchSpec.h"
#include "librbd/io/ObjectDispatcherInterface.h"
#include "librbd/io/Types.h"
#include <map>
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
template <typename ImageCtxT = ImageCtx>
class ObjectDispatcher
: public Dispatcher<ImageCtxT, ObjectDispatcherInterface> {
public:
ObjectDispatcher(ImageCtxT* image_ctx);
void invalidate_cache(Context* on_finish) override;
void reset_existence_cache(Context* on_finish) override;
void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) override;
int prepare_copyup(
uint64_t object_no,
SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override;
using typename Dispatcher<ImageCtxT, ObjectDispatcherInterface>::C_LayerIterator;
using typename Dispatcher<ImageCtxT, ObjectDispatcherInterface>::C_InvalidateCache;
protected:
bool send_dispatch(ObjectDispatchInterface* object_dispatch,
ObjectDispatchSpec* object_dispatch_spec) override;
private:
struct C_ResetExistenceCache;
struct SendVisitor;
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ObjectDispatcher<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_OBJECT_DISPATCHER_H
| 1,651 | 26.081967 | 85 | h |
null | ceph-main/src/librbd/io/ObjectDispatcherInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_DISPATCHER_INTERFACE_H
#define CEPH_LIBRBD_IO_OBJECT_DISPATCHER_INTERFACE_H
#include "include/int_types.h"
#include "librbd/io/DispatcherInterface.h"
#include "librbd/io/ObjectDispatchInterface.h"
struct Context;
namespace librbd {
namespace io {
struct ObjectDispatcherInterface
: public DispatcherInterface<ObjectDispatchInterface> {
public:
virtual void invalidate_cache(Context* on_finish) = 0;
virtual void reset_existence_cache(Context* on_finish) = 0;
virtual void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) = 0;
virtual int prepare_copyup(
uint64_t object_no,
SnapshotSparseBufferlist* snapshot_sparse_bufferlist) = 0;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_OBJECT_DISPATCHER_INTERFACE_H
| 984 | 26.361111 | 70 | h |
null | ceph-main/src/librbd/io/ObjectRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_OBJECT_REQUEST_H
#define CEPH_LIBRBD_IO_OBJECT_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/neorados/RADOS.hpp"
#include "include/rados/librados.hpp"
#include "common/zipkin_trace.h"
#include "librbd/ObjectMap.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <map>
class Context;
class ObjectExtent;
namespace neorados { struct WriteOp; }
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename> class CopyupRequest;
/**
* This class represents an I/O operation to a single RBD data object.
* Its subclasses encapsulate logic for dealing with special cases
* for I/O due to layering.
*/
template <typename ImageCtxT = ImageCtx>
class ObjectRequest {
public:
static ObjectRequest* create_write(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& data, IOContext io_context, int op_flags,
int write_flags, std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, Context *completion);
static ObjectRequest* create_discard(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
uint64_t object_len, IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, Context *completion);
static ObjectRequest* create_write_same(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
uint64_t object_len, ceph::bufferlist&& data, IOContext io_context,
int op_flags, const ZTracer::Trace &parent_trace, Context *completion);
static ObjectRequest* create_compare_and_write(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& cmp_data, ceph::bufferlist&& write_data,
IOContext io_context, uint64_t *mismatch_offset, int op_flags,
const ZTracer::Trace &parent_trace, Context *completion);
ObjectRequest(ImageCtxT *ictx, uint64_t objectno, IOContext io_context,
const char *trace_name, const ZTracer::Trace &parent_trace,
Context *completion);
virtual ~ObjectRequest() {
m_trace.event("finish");
}
static void add_write_hint(ImageCtxT& image_ctx,
neorados::WriteOp *wr);
virtual void send() = 0;
bool has_parent() const {
return m_has_parent;
}
virtual const char *get_op_type() const = 0;
protected:
bool compute_parent_extents(Extents *parent_extents, ImageArea *area,
bool read_request);
ImageCtxT *m_ictx;
uint64_t m_object_no;
IOContext m_io_context;
Context *m_completion;
ZTracer::Trace m_trace;
void async_finish(int r);
void finish(int r);
private:
bool m_has_parent = false;
};
template <typename ImageCtxT = ImageCtx>
class ObjectReadRequest : public ObjectRequest<ImageCtxT> {
public:
static ObjectReadRequest* create(
ImageCtxT *ictx, uint64_t objectno, ReadExtents* extents,
IOContext io_context, int op_flags, int read_flags,
const ZTracer::Trace &parent_trace, uint64_t* version,
Context *completion) {
return new ObjectReadRequest(ictx, objectno, extents, io_context, op_flags,
read_flags, parent_trace, version, completion);
}
ObjectReadRequest(
ImageCtxT *ictx, uint64_t objectno, ReadExtents* extents,
IOContext io_context, int op_flags, int read_flags,
const ZTracer::Trace &parent_trace, uint64_t* version,
Context *completion);
void send() override;
const char *get_op_type() const override {
return "read";
}
private:
/**
* @verbatim
*
* <start>
* |
* |
* v
* READ_OBJECT
* |
* v (skip if not needed)
* READ_PARENT
* |
* v (skip if not needed)
* COPYUP
* |
* v
* <finish>
*
* @endverbatim
*/
ReadExtents* m_extents;
int m_op_flags;
int m_read_flags;
uint64_t* m_version;
void read_object();
void handle_read_object(int r);
void read_parent();
void handle_read_parent(int r);
void copyup();
};
template <typename ImageCtxT = ImageCtx>
class AbstractObjectWriteRequest : public ObjectRequest<ImageCtxT> {
public:
AbstractObjectWriteRequest(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off, uint64_t len,
IOContext io_context, const char *trace_name,
const ZTracer::Trace &parent_trace, Context *completion);
virtual bool is_empty_write_op() const {
return false;
}
virtual uint8_t get_pre_write_object_map_state() const {
return OBJECT_EXISTS;
}
virtual void add_copyup_ops(neorados::WriteOp *wr) {
add_write_ops(wr);
}
void handle_copyup(int r);
void send() override;
protected:
uint64_t m_object_off;
uint64_t m_object_len;
bool m_full_object = false;
bool m_copyup_enabled = true;
virtual bool is_no_op_for_nonexistent_object() const {
return false;
}
virtual bool is_object_map_update_enabled() const {
return true;
}
virtual bool is_post_copyup_write_required() const {
return false;
}
virtual bool is_non_existent_post_write_object_map_state() const {
return false;
}
virtual void add_write_hint(neorados::WriteOp *wr);
virtual void add_write_ops(neorados::WriteOp *wr) = 0;
virtual int filter_write_result(int r) const {
return r;
}
virtual Extents get_copyup_overwrite_extents() const {
return {{m_object_off, m_object_len}};
}
private:
/**
* @verbatim
*
* <start>
* |
* v (no-op write request)
* DETECT_NO_OP . . . . . . . . . . . . . . . . . . .
* | .
* v (skip if not required/disabled) .
* PRE_UPDATE_OBJECT_MAP .
* | . .
* | . (child dne) .
* | . . . . . . . . . .
* | . .
* | (post-copyup write) . .
* | . . . . . . . . . . . . . .
* | . . . .
* v v . v .
* WRITE . . . . . . . . > COPYUP (if required) .
* | | .
* |/----------------------/ .
* | .
* v (skip if not required/disabled) .
* POST_UPDATE_OBJECT_MAP .
* | .
* v .
* <finish> < . . . . . . . . . . . . . . . . . . . .
*
* @endverbatim
*/
Extents m_parent_extents;
ImageArea m_image_area = ImageArea::DATA;
bool m_object_may_exist = false;
bool m_copyup_in_progress = false;
bool m_guarding_migration_write = false;
void compute_parent_info();
void pre_write_object_map_update();
void handle_pre_write_object_map_update(int r);
void write_object();
void handle_write_object(int r);
void copyup();
void post_write_object_map_update();
void handle_post_write_object_map_update(int r);
};
template <typename ImageCtxT = ImageCtx>
class ObjectWriteRequest : public AbstractObjectWriteRequest<ImageCtxT> {
public:
ObjectWriteRequest(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& data, IOContext io_context, int op_flags,
int write_flags, std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, object_no, object_off,
data.length(), io_context, "write",
parent_trace, completion),
m_write_data(std::move(data)), m_op_flags(op_flags),
m_write_flags(write_flags), m_assert_version(assert_version) {
}
bool is_empty_write_op() const override {
return (m_write_data.length() == 0);
}
const char *get_op_type() const override {
return "write";
}
protected:
void add_write_ops(neorados::WriteOp *wr) override;
void add_write_hint(neorados::WriteOp *wr) override;
private:
ceph::bufferlist m_write_data;
int m_op_flags;
int m_write_flags;
std::optional<uint64_t> m_assert_version;
};
template <typename ImageCtxT = ImageCtx>
class ObjectDiscardRequest : public AbstractObjectWriteRequest<ImageCtxT> {
public:
ObjectDiscardRequest(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
uint64_t object_len, IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, object_no, object_off,
object_len, io_context, "discard",
parent_trace, completion),
m_discard_flags(discard_flags) {
if (this->m_full_object) {
if ((m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_CLONE_REMOVE) != 0 &&
this->has_parent()) {
if (!this->m_copyup_enabled) {
// need to hide the parent object instead of child object
m_discard_action = DISCARD_ACTION_REMOVE_TRUNCATE;
} else {
m_discard_action = DISCARD_ACTION_TRUNCATE;
}
} else {
m_discard_action = DISCARD_ACTION_REMOVE;
}
} else if (object_off + object_len == ictx->layout.object_size) {
m_discard_action = DISCARD_ACTION_TRUNCATE;
} else {
m_discard_action = DISCARD_ACTION_ZERO;
}
}
const char* get_op_type() const override {
switch (m_discard_action) {
case DISCARD_ACTION_REMOVE:
return "remove";
case DISCARD_ACTION_REMOVE_TRUNCATE:
return "remove (create+truncate)";
case DISCARD_ACTION_TRUNCATE:
return "truncate";
case DISCARD_ACTION_ZERO:
return "zero";
}
ceph_abort();
return nullptr;
}
uint8_t get_pre_write_object_map_state() const override {
if (m_discard_action == DISCARD_ACTION_REMOVE) {
return OBJECT_PENDING;
}
return OBJECT_EXISTS;
}
protected:
bool is_no_op_for_nonexistent_object() const override {
return (!this->has_parent());
}
bool is_object_map_update_enabled() const override {
return (
(m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_OBJECT_MAP_UPDATE) == 0);
}
bool is_non_existent_post_write_object_map_state() const override {
return (m_discard_action == DISCARD_ACTION_REMOVE);
}
void add_write_hint(neorados::WriteOp *wr) override {
// no hint for discard
}
void add_write_ops(neorados::WriteOp *wr) override;
private:
enum DiscardAction {
DISCARD_ACTION_REMOVE,
DISCARD_ACTION_REMOVE_TRUNCATE,
DISCARD_ACTION_TRUNCATE,
DISCARD_ACTION_ZERO
};
DiscardAction m_discard_action;
int m_discard_flags;
};
template <typename ImageCtxT = ImageCtx>
class ObjectWriteSameRequest : public AbstractObjectWriteRequest<ImageCtxT> {
public:
ObjectWriteSameRequest(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
uint64_t object_len, ceph::bufferlist&& data, IOContext io_context,
int op_flags, const ZTracer::Trace &parent_trace, Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, object_no, object_off,
object_len, io_context, "writesame",
parent_trace, completion),
m_write_data(std::move(data)), m_op_flags(op_flags) {
}
const char *get_op_type() const override {
return "writesame";
}
protected:
void add_write_ops(neorados::WriteOp *wr) override;
private:
ceph::bufferlist m_write_data;
int m_op_flags;
};
template <typename ImageCtxT = ImageCtx>
class ObjectCompareAndWriteRequest : public AbstractObjectWriteRequest<ImageCtxT> {
public:
ObjectCompareAndWriteRequest(
ImageCtxT *ictx, uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& cmp_bl, ceph::bufferlist&& write_bl,
IOContext io_context, uint64_t *mismatch_offset, int op_flags,
const ZTracer::Trace &parent_trace, Context *completion)
: AbstractObjectWriteRequest<ImageCtxT>(ictx, object_no, object_off,
cmp_bl.length(), io_context,
"compare_and_write", parent_trace,
completion),
m_cmp_bl(std::move(cmp_bl)), m_write_bl(std::move(write_bl)),
m_mismatch_offset(mismatch_offset), m_op_flags(op_flags) {
}
const char *get_op_type() const override {
return "compare_and_write";
}
void add_copyup_ops(neorados::WriteOp *wr) override {
// no-op on copyup
}
protected:
virtual bool is_post_copyup_write_required() const {
return true;
}
void add_write_ops(neorados::WriteOp *wr) override;
int filter_write_result(int r) const override;
Extents get_copyup_overwrite_extents() const override {
return {};
}
private:
ceph::bufferlist m_cmp_bl;
ceph::bufferlist m_write_bl;
uint64_t *m_mismatch_offset;
int m_op_flags;
};
template <typename ImageCtxT = ImageCtx>
class ObjectListSnapsRequest : public ObjectRequest<ImageCtxT> {
public:
static ObjectListSnapsRequest* create(
ImageCtxT *ictx, uint64_t objectno, Extents&& object_extents,
SnapIds&& snap_ids, int list_snaps_flags,
const ZTracer::Trace &parent_trace, SnapshotDelta* snapshot_delta,
Context *completion) {
return new ObjectListSnapsRequest(ictx, objectno,
std::move(object_extents),
std::move(snap_ids), list_snaps_flags,
parent_trace, snapshot_delta, completion);
}
ObjectListSnapsRequest(
ImageCtxT *ictx, uint64_t objectno, Extents&& object_extents,
SnapIds&& snap_ids, int list_snaps_flags,
const ZTracer::Trace &parent_trace, SnapshotDelta* snapshot_delta,
Context *completion);
void send() override;
const char *get_op_type() const override {
return "snap_list";
}
private:
Extents m_object_extents;
SnapIds m_snap_ids;
int m_list_snaps_flags;
SnapshotDelta* m_snapshot_delta;
neorados::SnapSet m_snap_set;
boost::system::error_code m_ec;
ImageArea m_image_area = ImageArea::DATA;
SnapshotDelta m_parent_snapshot_delta;
void list_snaps();
void handle_list_snaps(int r);
void list_from_parent();
void handle_list_from_parent(int r);
void zero_extent(uint64_t snap_id, bool dne);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::ObjectRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectReadRequest<librbd::ImageCtx>;
extern template class librbd::io::AbstractObjectWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectDiscardRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectWriteSameRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectCompareAndWriteRequest<librbd::ImageCtx>;
extern template class librbd::io::ObjectListSnapsRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_OBJECT_REQUEST_H
| 15,444 | 29.523715 | 83 | h |
null | ceph-main/src/librbd/io/QosImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_QOS_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_IO_QOS_IMAGE_DISPATCH_H
#include <list>
#include <memory>
#include "librbd/io/ImageDispatchInterface.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/zipkin_trace.h"
#include "common/Throttle.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename> class FlushTracker;
template <typename ImageCtxT>
class QosImageDispatch : public ImageDispatchInterface {
public:
struct Tag {
std::atomic<uint32_t>* image_dispatch_flags;
Context* on_dispatched;
Tag(std::atomic<uint32_t>* image_dispatch_flags, Context* on_dispatched)
: image_dispatch_flags(image_dispatch_flags),
on_dispatched(on_dispatched) {
}
};
QosImageDispatch(ImageCtxT* image_ctx);
~QosImageDispatch() override;
ImageDispatchLayer get_dispatch_layer() const override {
return IMAGE_DISPATCH_LAYER_QOS;
}
void shut_down(Context* on_finish) override;
void apply_qos_schedule_tick_min(uint64_t tick);
void apply_qos_limit(uint64_t flag, uint64_t limit, uint64_t burst,
uint64_t burst_seconds);
void apply_qos_exclude_ops(uint64_t exclude_ops);
bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool invalidate_cache(Context* on_finish) override {
return false;
}
private:
ImageCtxT* m_image_ctx;
std::list<std::pair<uint64_t, TokenBucketThrottle*> > m_throttles;
uint64_t m_qos_enabled_flag = 0;
uint64_t m_qos_exclude_ops = 0;
std::unique_ptr<FlushTracker<ImageCtxT>> m_flush_tracker;
void handle_finished(int r, uint64_t tid);
bool set_throttle_flag(std::atomic<uint32_t>* image_dispatch_flags,
uint32_t flag);
bool needs_throttle(bool read_op, const Extents& image_extents, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched);
void handle_throttle_ready(Tag&& tag, uint64_t flag);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::QosImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_QOS_IMAGE_DISPATCH_H
| 4,696 | 33.536765 | 79 | h |
null | ceph-main/src/librbd/io/QueueImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_QUEUE_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_IO_QUEUE_IMAGE_DISPATCH_H
#include "librbd/io/ImageDispatchInterface.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/zipkin_trace.h"
#include "common/Throttle.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
#include <list>
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename> class FlushTracker;
template <typename ImageCtxT>
class QueueImageDispatch : public ImageDispatchInterface {
public:
QueueImageDispatch(ImageCtxT* image_ctx);
~QueueImageDispatch();
ImageDispatchLayer get_dispatch_layer() const override {
return IMAGE_DISPATCH_LAYER_QUEUE;
}
void shut_down(Context* on_finish) override;
bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool invalidate_cache(Context* on_finish) override {
return false;
}
private:
ImageCtxT* m_image_ctx;
FlushTracker<ImageCtxT>* m_flush_tracker;
void handle_finished(int r, uint64_t tid);
bool enqueue(bool read_op, uint64_t tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::QueueImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_QUEUE_IMAGE_DISPATCH_H
| 3,749 | 32.783784 | 77 | h |
null | ceph-main/src/librbd/io/ReadResult.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_READ_RESULT_H
#define CEPH_LIBRBD_IO_READ_RESULT_H
#include "include/common_fwd.h"
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/Context.h"
#include "librbd/io/Types.h"
#include "osdc/Striper.h"
#include <sys/uio.h>
#include <boost/variant/variant.hpp>
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename> struct ObjectReadRequest;
class ReadResult {
public:
struct C_ImageReadRequest : public Context {
AioCompletion *aio_completion;
uint64_t buffer_offset = 0;
Extents image_extents;
bufferlist bl;
bool ignore_enoent = false;
C_ImageReadRequest(AioCompletion *aio_completion,
uint64_t buffer_offset,
const Extents image_extents);
void finish(int r) override;
};
struct C_ObjectReadRequest : public Context {
AioCompletion *aio_completion;
ReadExtents extents;
C_ObjectReadRequest(AioCompletion *aio_completion, ReadExtents&& extents);
void finish(int r) override;
};
struct C_ObjectReadMergedExtents : public Context {
CephContext* cct;
ReadExtents* extents;
Context *on_finish;
bufferlist bl;
C_ObjectReadMergedExtents(CephContext* cct, ReadExtents* extents,
Context* on_finish);
void finish(int r) override;
};
ReadResult();
ReadResult(char *buf, size_t buf_len);
ReadResult(const struct iovec *iov, int iov_count);
ReadResult(ceph::bufferlist *bl);
ReadResult(Extents* extent_map, ceph::bufferlist* bl);
void set_image_extents(const Extents& image_extents);
void assemble_result(CephContext *cct);
private:
struct Empty {
};
struct Linear {
char *buf;
size_t buf_len;
Linear(char *buf, size_t buf_len) : buf(buf), buf_len(buf_len) {
}
};
struct Vector {
const struct iovec *iov;
int iov_count;
Vector(const struct iovec *iov, int iov_count)
: iov(iov), iov_count(iov_count) {
}
};
struct Bufferlist {
ceph::bufferlist *bl;
Bufferlist(ceph::bufferlist *bl) : bl(bl) {
}
};
struct SparseBufferlist {
Extents *extent_map;
ceph::bufferlist *bl;
Extents image_extents;
SparseBufferlist(Extents* extent_map, ceph::bufferlist* bl)
: extent_map(extent_map), bl(bl) {
}
};
typedef boost::variant<Empty,
Linear,
Vector,
Bufferlist,
SparseBufferlist> Buffer;
struct SetImageExtentsVisitor;
struct AssembleResultVisitor;
Buffer m_buffer;
Striper::StripedReadResult m_destriper;
};
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_READ_RESULT_H
| 2,875 | 21.123077 | 78 | h |
null | ceph-main/src/librbd/io/RefreshImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_REFRESH_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_IO_REFRESH_IMAGE_DISPATCH_H
#include "librbd/io/ImageDispatchInterface.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/zipkin_trace.h"
#include "common/Throttle.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename ImageCtxT>
class RefreshImageDispatch : public ImageDispatchInterface {
public:
RefreshImageDispatch(ImageCtxT* image_ctx);
ImageDispatchLayer get_dispatch_layer() const override {
return IMAGE_DISPATCH_LAYER_REFRESH;
}
void shut_down(Context* on_finish) override;
bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool invalidate_cache(Context* on_finish) override {
return false;
}
private:
ImageCtxT* m_image_ctx;
bool needs_refresh(DispatchResult* dispatch_result, Context* on_dispatched);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::RefreshImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_REFRESH_IMAGE_DISPATCH_H
| 3,518 | 33.5 | 78 | h |
null | ceph-main/src/librbd/io/SimpleSchedulerObjectDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_SIMPLE_SCHEDULER_OBJECT_DISPATCH_H
#define CEPH_LIBRBD_IO_SIMPLE_SCHEDULER_OBJECT_DISPATCH_H
#include "common/ceph_mutex.h"
#include "include/interval_set.h"
#include "include/utime.h"
#include "librbd/io/ObjectDispatchInterface.h"
#include "librbd/io/TypeTraits.h"
#include <list>
#include <map>
#include <memory>
namespace librbd {
class ImageCtx;
namespace io {
template <typename> class FlushTracker;
class LatencyStats;
/**
* Simple scheduler plugin for object dispatcher layer.
*/
template <typename ImageCtxT = ImageCtx>
class SimpleSchedulerObjectDispatch : public ObjectDispatchInterface {
private:
// mock unit testing support
typedef ::librbd::io::TypeTraits<ImageCtxT> TypeTraits;
typedef typename TypeTraits::SafeTimer SafeTimer;
public:
static SimpleSchedulerObjectDispatch* create(ImageCtxT* image_ctx) {
return new SimpleSchedulerObjectDispatch(image_ctx);
}
SimpleSchedulerObjectDispatch(ImageCtxT* image_ctx);
~SimpleSchedulerObjectDispatch() override;
ObjectDispatchLayer get_dispatch_layer() const override {
return OBJECT_DISPATCH_LAYER_SCHEDULER;
}
void init();
void shut_down(Context* on_finish) override;
bool read(
uint64_t object_no, ReadExtents* extents, IOContext io_context,
int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
uint64_t* version, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags, int write_flags,
std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write_same(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool compare_and_write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
ceph::bufferlist&& write_data, IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
int* object_dispatch_flags, uint64_t* journal_tid,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
FlushSource flush_source, const ZTracer::Trace &parent_trace,
uint64_t* journal_tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool list_snaps(
uint64_t object_no, io::Extents&& extents, SnapIds&& snap_ids,
int list_snap_flags, const ZTracer::Trace &parent_trace,
SnapshotDelta* snapshot_delta, int* object_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool invalidate_cache(Context* on_finish) override {
return false;
}
bool reset_existence_cache(Context* on_finish) override {
return false;
}
void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) override {
}
int prepare_copyup(
uint64_t object_no,
SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override {
return 0;
}
private:
struct MergedRequests {
ceph::bufferlist data;
std::list<Context *> requests;
};
class ObjectRequests {
public:
using clock_t = ceph::real_clock;
ObjectRequests(uint64_t object_no) : m_object_no(object_no) {
}
uint64_t get_object_no() const {
return m_object_no;
}
void set_dispatch_seq(uint64_t dispatch_seq) {
m_dispatch_seq = dispatch_seq;
}
uint64_t get_dispatch_seq() const {
return m_dispatch_seq;
}
clock_t::time_point get_dispatch_time() const {
return m_dispatch_time;
}
void set_scheduled_dispatch(const clock_t::time_point &dispatch_time) {
m_dispatch_time = dispatch_time;
}
bool is_scheduled_dispatch() const {
return !clock_t::is_zero(m_dispatch_time);
}
size_t delayed_requests_size() const {
return m_delayed_requests.size();
}
bool intersects(uint64_t object_off, uint64_t len) const {
return m_delayed_request_extents.intersects(object_off, len);
}
bool try_delay_request(uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags,
int object_dispatch_flags, Context* on_dispatched);
void dispatch_delayed_requests(ImageCtxT *image_ctx,
LatencyStats *latency_stats,
ceph::mutex *latency_stats_lock);
private:
uint64_t m_object_no;
uint64_t m_dispatch_seq = 0;
clock_t::time_point m_dispatch_time;
IOContext m_io_context;
int m_op_flags = 0;
int m_object_dispatch_flags = 0;
std::map<uint64_t, MergedRequests> m_delayed_requests;
interval_set<uint64_t> m_delayed_request_extents;
void try_merge_delayed_requests(
typename std::map<uint64_t, MergedRequests>::iterator &iter,
typename std::map<uint64_t, MergedRequests>::iterator &iter2);
};
typedef std::shared_ptr<ObjectRequests> ObjectRequestsRef;
typedef std::map<uint64_t, ObjectRequestsRef> Requests;
ImageCtxT *m_image_ctx;
FlushTracker<ImageCtxT>* m_flush_tracker;
ceph::mutex m_lock;
SafeTimer *m_timer;
ceph::mutex *m_timer_lock;
uint64_t m_max_delay;
uint64_t m_dispatch_seq = 0;
Requests m_requests;
std::list<ObjectRequestsRef> m_dispatch_queue;
Context *m_timer_task = nullptr;
std::unique_ptr<LatencyStats> m_latency_stats;
bool try_delay_write(uint64_t object_no, uint64_t object_off,
ceph::bufferlist&& data, IOContext io_context,
int op_flags, int object_dispatch_flags,
Context* on_dispatched);
bool intersects(uint64_t object_no, uint64_t object_off, uint64_t len) const;
void dispatch_all_delayed_requests();
void dispatch_delayed_requests(uint64_t object_no);
void dispatch_delayed_requests(ObjectRequestsRef object_requests);
void register_in_flight_request(uint64_t object_no, const utime_t &start_time,
Context** on_finish);
void schedule_dispatch_delayed_requests();
};
} // namespace io
} // namespace librbd
extern template class librbd::io::SimpleSchedulerObjectDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_CACHE_SIMPLE_SCHEDULER_OBJECT_DISPATCH_H
| 7,396 | 31.442982 | 82 | h |
null | ceph-main/src/librbd/io/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_TYPES_H
#define CEPH_LIBRBD_IO_TYPES_H
#include "include/int_types.h"
#include "include/rados/rados_types.hpp"
#include "common/interval_map.h"
#include "osdc/StriperTypes.h"
#include <iosfwd>
#include <map>
#include <vector>
struct Context;
namespace librbd {
namespace io {
typedef enum {
AIO_TYPE_NONE = 0,
AIO_TYPE_GENERIC,
AIO_TYPE_OPEN,
AIO_TYPE_CLOSE,
AIO_TYPE_READ,
AIO_TYPE_WRITE,
AIO_TYPE_DISCARD,
AIO_TYPE_FLUSH,
AIO_TYPE_WRITESAME,
AIO_TYPE_COMPARE_AND_WRITE,
} aio_type_t;
enum FlushSource {
FLUSH_SOURCE_USER,
FLUSH_SOURCE_INTERNAL,
FLUSH_SOURCE_SHUTDOWN,
FLUSH_SOURCE_EXCLUSIVE_LOCK,
FLUSH_SOURCE_EXCLUSIVE_LOCK_SKIP_REFRESH,
FLUSH_SOURCE_REFRESH,
FLUSH_SOURCE_WRITEBACK,
FLUSH_SOURCE_WRITE_BLOCK,
};
enum Direction {
DIRECTION_READ,
DIRECTION_WRITE,
DIRECTION_BOTH
};
enum DispatchResult {
DISPATCH_RESULT_INVALID,
DISPATCH_RESULT_RESTART,
DISPATCH_RESULT_CONTINUE,
DISPATCH_RESULT_COMPLETE
};
enum ImageDispatchLayer {
IMAGE_DISPATCH_LAYER_NONE = 0,
IMAGE_DISPATCH_LAYER_API_START = IMAGE_DISPATCH_LAYER_NONE,
IMAGE_DISPATCH_LAYER_QUEUE,
IMAGE_DISPATCH_LAYER_QOS,
IMAGE_DISPATCH_LAYER_EXCLUSIVE_LOCK,
IMAGE_DISPATCH_LAYER_REFRESH,
IMAGE_DISPATCH_LAYER_INTERNAL_START = IMAGE_DISPATCH_LAYER_REFRESH,
IMAGE_DISPATCH_LAYER_MIGRATION,
IMAGE_DISPATCH_LAYER_JOURNAL,
IMAGE_DISPATCH_LAYER_WRITE_BLOCK,
IMAGE_DISPATCH_LAYER_WRITEBACK_CACHE,
IMAGE_DISPATCH_LAYER_CRYPTO,
IMAGE_DISPATCH_LAYER_CORE,
IMAGE_DISPATCH_LAYER_LAST
};
enum {
IMAGE_DISPATCH_FLAG_QOS_IOPS_THROTTLE = 1 << 0,
IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE = 1 << 1,
IMAGE_DISPATCH_FLAG_QOS_READ_IOPS_THROTTLE = 1 << 2,
IMAGE_DISPATCH_FLAG_QOS_WRITE_IOPS_THROTTLE = 1 << 3,
IMAGE_DISPATCH_FLAG_QOS_READ_BPS_THROTTLE = 1 << 4,
IMAGE_DISPATCH_FLAG_QOS_WRITE_BPS_THROTTLE = 1 << 5,
IMAGE_DISPATCH_FLAG_QOS_BPS_MASK = (
IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_READ_BPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_WRITE_BPS_THROTTLE),
IMAGE_DISPATCH_FLAG_QOS_IOPS_MASK = (
IMAGE_DISPATCH_FLAG_QOS_IOPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_READ_IOPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_WRITE_IOPS_THROTTLE),
IMAGE_DISPATCH_FLAG_QOS_READ_MASK = (
IMAGE_DISPATCH_FLAG_QOS_READ_IOPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_READ_BPS_THROTTLE),
IMAGE_DISPATCH_FLAG_QOS_WRITE_MASK = (
IMAGE_DISPATCH_FLAG_QOS_WRITE_IOPS_THROTTLE |
IMAGE_DISPATCH_FLAG_QOS_WRITE_BPS_THROTTLE),
IMAGE_DISPATCH_FLAG_QOS_MASK = (
IMAGE_DISPATCH_FLAG_QOS_BPS_MASK |
IMAGE_DISPATCH_FLAG_QOS_IOPS_MASK),
// TODO: pass area through ImageDispatchInterface and remove
// this flag
IMAGE_DISPATCH_FLAG_CRYPTO_HEADER = 1 << 6
};
enum {
RBD_IO_OPERATIONS_DEFAULT = 0,
RBD_IO_OPERATION_READ = 1 << 0,
RBD_IO_OPERATION_WRITE = 1 << 1,
RBD_IO_OPERATION_DISCARD = 1 << 2,
RBD_IO_OPERATION_WRITE_SAME = 1 << 3,
RBD_IO_OPERATION_COMPARE_AND_WRITE = 1 << 4,
RBD_IO_OPERATIONS_ALL = (
RBD_IO_OPERATION_READ |
RBD_IO_OPERATION_WRITE |
RBD_IO_OPERATION_DISCARD |
RBD_IO_OPERATION_WRITE_SAME |
RBD_IO_OPERATION_COMPARE_AND_WRITE)
};
enum ObjectDispatchLayer {
OBJECT_DISPATCH_LAYER_NONE = 0,
OBJECT_DISPATCH_LAYER_CACHE,
OBJECT_DISPATCH_LAYER_CRYPTO,
OBJECT_DISPATCH_LAYER_JOURNAL,
OBJECT_DISPATCH_LAYER_PARENT_CACHE,
OBJECT_DISPATCH_LAYER_SCHEDULER,
OBJECT_DISPATCH_LAYER_CORE,
OBJECT_DISPATCH_LAYER_LAST
};
enum {
READ_FLAG_DISABLE_READ_FROM_PARENT = 1UL << 0,
READ_FLAG_DISABLE_CLIPPING = 1UL << 1,
};
enum {
OBJECT_WRITE_FLAG_CREATE_EXCLUSIVE = 1UL << 0
};
enum {
OBJECT_DISCARD_FLAG_DISABLE_CLONE_REMOVE = 1UL << 0,
OBJECT_DISCARD_FLAG_DISABLE_OBJECT_MAP_UPDATE = 1UL << 1
};
enum {
OBJECT_DISPATCH_FLAG_FLUSH = 1UL << 0,
OBJECT_DISPATCH_FLAG_WILL_RETRY_ON_ERROR = 1UL << 1
};
enum {
LIST_SNAPS_FLAG_DISABLE_LIST_FROM_PARENT = 1UL << 0,
LIST_SNAPS_FLAG_WHOLE_OBJECT = 1UL << 1,
LIST_SNAPS_FLAG_IGNORE_ZEROED_EXTENTS = 1UL << 2,
};
enum SparseExtentState {
SPARSE_EXTENT_STATE_DNE, /* does not exist */
SPARSE_EXTENT_STATE_ZEROED,
SPARSE_EXTENT_STATE_DATA
};
std::ostream& operator<<(std::ostream& os, SparseExtentState state);
struct SparseExtent {
SparseExtentState state;
uint64_t length;
SparseExtent(SparseExtentState state, uint64_t length)
: state(state), length(length) {
}
operator SparseExtentState() const {
return state;
}
bool operator==(const SparseExtent& rhs) const {
return state == rhs.state && length == rhs.length;
}
};
std::ostream& operator<<(std::ostream& os, const SparseExtent& state);
struct SparseExtentSplitMerge {
SparseExtent split(uint64_t offset, uint64_t length, SparseExtent &se) const {
return SparseExtent(se.state, se.length);
}
bool can_merge(const SparseExtent& left, const SparseExtent& right) const {
return left.state == right.state;
}
SparseExtent merge(SparseExtent&& left, SparseExtent&& right) const {
SparseExtent se(left);
se.length += right.length;
return se;
}
uint64_t length(const SparseExtent& se) const {
return se.length;
}
};
typedef interval_map<uint64_t,
SparseExtent,
SparseExtentSplitMerge> SparseExtents;
typedef std::vector<uint64_t> SnapIds;
typedef std::pair<librados::snap_t, librados::snap_t> WriteReadSnapIds;
extern const WriteReadSnapIds INITIAL_WRITE_READ_SNAP_IDS;
typedef std::map<WriteReadSnapIds, SparseExtents> SnapshotDelta;
struct SparseBufferlistExtent : public SparseExtent {
ceph::bufferlist bl;
SparseBufferlistExtent(SparseExtentState state, uint64_t length)
: SparseExtent(state, length) {
ceph_assert(state != SPARSE_EXTENT_STATE_DATA);
}
SparseBufferlistExtent(SparseExtentState state, uint64_t length,
ceph::bufferlist&& bl_)
: SparseExtent(state, length), bl(std::move(bl_)) {
ceph_assert(state != SPARSE_EXTENT_STATE_DATA || length == bl.length());
}
bool operator==(const SparseBufferlistExtent& rhs) const {
return (state == rhs.state &&
length == rhs.length &&
bl.contents_equal(rhs.bl));
}
};
struct SparseBufferlistExtentSplitMerge {
SparseBufferlistExtent split(uint64_t offset, uint64_t length,
SparseBufferlistExtent& sbe) const {
ceph::bufferlist bl;
if (sbe.state == SPARSE_EXTENT_STATE_DATA) {
bl.substr_of(bl, offset, length);
}
return SparseBufferlistExtent(sbe.state, length, std::move(bl));
}
bool can_merge(const SparseBufferlistExtent& left,
const SparseBufferlistExtent& right) const {
return left.state == right.state;
}
SparseBufferlistExtent merge(SparseBufferlistExtent&& left,
SparseBufferlistExtent&& right) const {
if (left.state == SPARSE_EXTENT_STATE_DATA) {
ceph::bufferlist bl{std::move(left.bl)};
bl.claim_append(std::move(right.bl));
return SparseBufferlistExtent(SPARSE_EXTENT_STATE_DATA,
bl.length(), std::move(bl));
} else {
return SparseBufferlistExtent(left.state, left.length + right.length, {});
}
}
uint64_t length(const SparseBufferlistExtent& sbe) const {
return sbe.length;
}
};
typedef interval_map<uint64_t,
SparseBufferlistExtent,
SparseBufferlistExtentSplitMerge> SparseBufferlist;
typedef std::map<uint64_t, SparseBufferlist> SnapshotSparseBufferlist;
using striper::LightweightBufferExtents;
using striper::LightweightObjectExtent;
using striper::LightweightObjectExtents;
typedef std::pair<uint64_t,uint64_t> Extent;
typedef std::vector<Extent> Extents;
enum class ImageArea {
DATA,
CRYPTO_HEADER
};
std::ostream& operator<<(std::ostream& os, ImageArea area);
struct ReadExtent {
const uint64_t offset;
const uint64_t length;
const LightweightBufferExtents buffer_extents;
ceph::bufferlist bl;
Extents extent_map;
ReadExtent(uint64_t offset,
uint64_t length) : offset(offset), length(length) {};
ReadExtent(uint64_t offset,
uint64_t length,
const LightweightBufferExtents&& buffer_extents)
: offset(offset),
length(length),
buffer_extents(buffer_extents) {}
ReadExtent(uint64_t offset,
uint64_t length,
const LightweightBufferExtents&& buffer_extents,
ceph::bufferlist&& bl,
Extents&& extent_map) : offset(offset),
length(length),
buffer_extents(buffer_extents),
bl(bl),
extent_map(extent_map) {};
friend inline std::ostream& operator<<(
std::ostream& os,
const ReadExtent &extent) {
os << "offset=" << extent.offset << ", "
<< "length=" << extent.length << ", "
<< "buffer_extents=" << extent.buffer_extents << ", "
<< "bl.length=" << extent.bl.length() << ", "
<< "extent_map=" << extent.extent_map;
return os;
}
};
typedef std::vector<ReadExtent> ReadExtents;
typedef std::map<uint64_t, uint64_t> ExtentMap;
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_TYPES_H
| 9,779 | 28.726444 | 80 | h |
null | ceph-main/src/librbd/io/Utils.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_UTILS_H
#define CEPH_LIBRBD_IO_UTILS_H
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/rados/rados_types.hpp"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <map>
class ObjectExtent;
namespace neorados { struct Op; }
namespace librbd {
struct ImageCtx;
namespace io {
namespace util {
void apply_op_flags(uint32_t op_flags, uint32_t flags, neorados::Op* op);
bool assemble_write_same_extent(const LightweightObjectExtent &object_extent,
const ceph::bufferlist& data,
ceph::bufferlist *ws_data,
bool force_write);
template <typename ImageCtxT = librbd::ImageCtx>
void read_parent(ImageCtxT *image_ctx, uint64_t object_no,
ReadExtents* read_extents, librados::snap_t snap_id,
const ZTracer::Trace &trace, Context* on_finish);
template <typename ImageCtxT = librbd::ImageCtx>
int clip_request(ImageCtxT* image_ctx, Extents* image_extents, ImageArea area);
inline uint64_t get_extents_length(const Extents &extents) {
uint64_t total_bytes = 0;
for (auto [_, extent_length] : extents) {
total_bytes += extent_length;
}
return total_bytes;
}
void unsparsify(CephContext* cct, ceph::bufferlist* bl,
const Extents& extent_map, uint64_t bl_off,
uint64_t out_bl_len);
template <typename ImageCtxT = librbd::ImageCtx>
bool trigger_copyup(ImageCtxT *image_ctx, uint64_t object_no,
IOContext io_context, Context* on_finish);
template <typename ImageCtxT = librbd::ImageCtx>
void area_to_object_extents(ImageCtxT* image_ctx, uint64_t offset,
uint64_t length, ImageArea area,
uint64_t buffer_offset,
striper::LightweightObjectExtents* object_extents);
template <typename ImageCtxT = librbd::ImageCtx>
std::pair<Extents, ImageArea> object_to_area_extents(
ImageCtxT* image_ctx, uint64_t object_no, const Extents& object_extents);
template <typename ImageCtxT = librbd::ImageCtx>
uint64_t area_to_raw_offset(const ImageCtxT& image_ctx, uint64_t offset,
ImageArea area);
template <typename ImageCtxT = librbd::ImageCtx>
std::pair<uint64_t, ImageArea> raw_to_area_offset(const ImageCtxT& image_ctx,
uint64_t offset);
inline ObjectDispatchLayer get_previous_layer(ObjectDispatchLayer layer) {
return (ObjectDispatchLayer)(((int)layer) - 1);
}
} // namespace util
} // namespace io
} // namespace librbd
#endif // CEPH_LIBRBD_IO_UTILS_H
| 2,803 | 32.380952 | 79 | h |
null | ceph-main/src/librbd/io/WriteBlockImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_IO_WRITE_BLOCK_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_IO_WRITE_BLOCK_IMAGE_DISPATCH_H
#include "librbd/io/ImageDispatchInterface.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/ceph_mutex.h"
#include "common/zipkin_trace.h"
#include "common/Throttle.h"
#include "librbd/io/ReadResult.h"
#include "librbd/io/Types.h"
#include <list>
struct Context;
namespace librbd {
struct ImageCtx;
namespace io {
struct AioCompletion;
template <typename ImageCtxT>
class WriteBlockImageDispatch : public ImageDispatchInterface {
public:
WriteBlockImageDispatch(ImageCtxT* image_ctx);
ImageDispatchLayer get_dispatch_layer() const override {
return IMAGE_DISPATCH_LAYER_WRITE_BLOCK;
}
void shut_down(Context* on_finish) override;
int block_writes();
void block_writes(Context *on_blocked);
void unblock_writes();
inline bool writes_blocked() const {
std::shared_lock locker{m_lock};
return (m_write_blockers > 0);
}
void wait_on_writes_unblocked(Context *on_unblocked);
bool read(
AioCompletion* aio_comp, Extents &&image_extents,
ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool write(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
AioCompletion* aio_comp, Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
AioCompletion* aio_comp, Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
AioCompletion* aio_comp, FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
AioCompletion* aio_comp, Extents&& image_extents, SnapIds&& snap_ids,
int list_snaps_flags, SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
private:
struct C_BlockedWrites;
typedef std::list<Context*> Contexts;
ImageCtxT* m_image_ctx;
mutable ceph::shared_mutex m_lock;
Contexts m_on_dispatches;
uint32_t m_write_blockers = 0;
Contexts m_write_blocker_contexts;
Contexts m_unblocked_write_waiter_contexts;
uint64_t m_in_flight_writes = 0;
void handle_finished(int r, uint64_t tid);
bool process_io(uint64_t tid, DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched);
void flush_io(Context* on_finish);
bool invalidate_cache(Context* on_finish) override {
return false;
}
void handle_blocked_writes(int r);
};
} // namespace io
} // namespace librbd
extern template class librbd::io::WriteBlockImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_IO_WRITE_BLOCK_IMAGE_DISPATCH_H
| 4,333 | 31.103704 | 77 | h |
null | ceph-main/src/librbd/journal/CreateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_CREATE_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_CREATE_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "common/ceph_mutex.h"
#include "common/Timer.h"
#include "librbd/ImageCtx.h"
#include "journal/Journaler.h"
#include "librbd/journal/Types.h"
#include "librbd/journal/TypeTraits.h"
#include "cls/journal/cls_journal_types.h"
using librados::IoCtx;
using journal::Journaler;
class Context;
class ContextWQ;
namespace journal {
class Journaler;
}
namespace librbd {
class ImageCtx;
namespace journal {
template<typename ImageCtxT = ImageCtx>
class CreateRequest {
public:
static CreateRequest *create(IoCtx &ioctx, const std::string &imageid,
uint8_t order, uint8_t splay_width,
const std::string &object_pool,
uint64_t tag_class, TagData &tag_data,
const std::string &client_id,
ContextWQ *op_work_queue, Context *on_finish) {
return new CreateRequest(ioctx, imageid, order, splay_width, object_pool,
tag_class, tag_data, client_id, op_work_queue,
on_finish);
}
void send();
private:
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
CreateRequest(IoCtx &ioctx, const std::string &imageid, uint8_t order,
uint8_t splay_width, const std::string &object_pool,
uint64_t tag_class, TagData &tag_data,
const std::string &client_id, ContextWQ *op_work_queue,
Context *on_finish);
IoCtx &m_ioctx;
std::string m_image_id;
uint8_t m_order;
uint8_t m_splay_width;
std::string m_object_pool;
uint64_t m_tag_class;
TagData m_tag_data;
std::string m_image_client_id;
ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct;
cls::journal::Tag m_tag;
bufferlist m_bl;
Journaler *m_journaler;
SafeTimer *m_timer;
ceph::mutex *m_timer_lock;
int m_r_saved;
int64_t m_pool_id = -1;
void get_pool_id();
void create_journal();
Context *handle_create_journal(int *result);
void allocate_journal_tag();
Context *handle_journal_tag(int *result);
void register_client();
Context *handle_register_client(int *result);
void shut_down_journaler(int r);
Context *handle_journaler_shutdown(int *result);
void remove_journal();
Context *handle_remove_journal(int *result);
void complete(int r);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::CreateRequest<librbd::ImageCtx>;
#endif /* CEPH_LIBRBD_JOURNAL_CREATE_REQUEST_H */
| 2,939 | 26.476636 | 85 | h |
null | ceph-main/src/librbd/journal/DemoteRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_DEMOTE_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_DEMOTE_REQUEST_H
#include "common/ceph_mutex.h"
#include "cls/journal/cls_journal_types.h"
#include "journal/Future.h"
#include "librbd/journal/Types.h"
#include "librbd/journal/TypeTraits.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace journal {
template <typename ImageCtxT = librbd::ImageCtx>
class DemoteRequest {
public:
static DemoteRequest *create(ImageCtxT &image_ctx, Context *on_finish) {
return new DemoteRequest(image_ctx, on_finish);
}
DemoteRequest(ImageCtxT &image_ctx, Context *on_finish);
~DemoteRequest();
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* OPEN_JOURNALER * * * * *
* | *
* v *
* ALLOCATE_TAG * * * * * *
* | *
* v *
* APPEND_EVENT * * * *
* | * *
* v * *
* COMMIT_EVENT * *
* | * *
* v * *
* STOP_APPEND <* * * *
* | *
* v *
* SHUT_DOWN_JOURNALER <* *
* |
* v
* <finish>
*
* @endverbatim
*/
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
typedef typename TypeTraits<ImageCtxT>::Future Future;
ImageCtxT &m_image_ctx;
Context *m_on_finish;
Journaler *m_journaler = nullptr;
int m_ret_val = 0;
ceph::mutex m_lock;
ImageClientMeta m_client_meta;
uint64_t m_tag_tid = 0;
TagData m_tag_data;
cls::journal::Tag m_tag;
Future m_future;
void open_journaler();
void handle_open_journaler(int r);
void allocate_tag();
void handle_allocate_tag(int r);
void append_event();
void handle_append_event(int r);
void commit_event();
void handle_commit_event(int r);
void stop_append();
void handle_stop_append(int r);
void shut_down_journaler();
void handle_shut_down_journaler(int r);
void finish(int r);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::DemoteRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_DEMOTE_REQUEST_H
| 2,305 | 20.351852 | 74 | h |
null | ceph-main/src/librbd/journal/ObjectDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_OBJECT_DISPATCH_H
#define CEPH_LIBRBD_JOURNAL_OBJECT_DISPATCH_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "common/zipkin_trace.h"
#include "librbd/io/Types.h"
#include "librbd/io/ObjectDispatchInterface.h"
struct Context;
namespace librbd {
struct ImageCtx;
template <typename> class Journal;
namespace journal {
template <typename ImageCtxT = librbd::ImageCtx>
class ObjectDispatch : public io::ObjectDispatchInterface {
public:
static ObjectDispatch* create(ImageCtxT* image_ctx,
Journal<ImageCtxT>* journal) {
return new ObjectDispatch(image_ctx, journal);
}
ObjectDispatch(ImageCtxT* image_ctx, Journal<ImageCtxT>* journal);
io::ObjectDispatchLayer get_dispatch_layer() const override {
return io::OBJECT_DISPATCH_LAYER_JOURNAL;
}
void shut_down(Context* on_finish) override;
bool read(
uint64_t object_no, io::ReadExtents* extents, IOContext io_context,
int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
uint64_t* version, int* object_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) {
return false;
}
bool discard(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
IOContext io_context, int discard_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
IOContext io_context, int op_flags, int write_flags,
std::optional<uint64_t> assert_version,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool write_same(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
io::LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
uint64_t* journal_tid, io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool compare_and_write(
uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
ceph::bufferlist&& write_data, IOContext io_context, int op_flags,
const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
int* object_dispatch_flags, uint64_t* journal_tid,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
io::FlushSource flush_source, const ZTracer::Trace &parent_trace,
uint64_t* journal_tid, io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) override;
bool list_snaps(
uint64_t object_no, io::Extents&& extents, io::SnapIds&& snap_ids,
int list_snap_flags, const ZTracer::Trace &parent_trace,
io::SnapshotDelta* snapshot_delta, int* object_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override {
return false;
}
bool invalidate_cache(Context* on_finish) override {
return false;
}
bool reset_existence_cache(Context* on_finish) override {
return false;
}
void extent_overwritten(
uint64_t object_no, uint64_t object_off, uint64_t object_len,
uint64_t journal_tid, uint64_t new_journal_tid) override;
int prepare_copyup(
uint64_t object_no,
io::SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override {
return 0;
}
private:
ImageCtxT* m_image_ctx;
Journal<ImageCtxT>* m_journal;
void wait_or_flush_event(uint64_t journal_tid, int object_dispatch_flags,
Context* on_dispatched);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::ObjectDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_OBJECT_DISPATCH_H
| 4,291 | 33.336 | 77 | h |
null | ceph-main/src/librbd/journal/OpenRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_OPEN_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_OPEN_REQUEST_H
#include "common/ceph_mutex.h"
#include "include/int_types.h"
#include "librbd/journal/TypeTraits.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace journal {
struct ImageClientMeta;
struct TagData;
template <typename ImageCtxT = ImageCtx>
class OpenRequest {
public:
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
static OpenRequest* create(ImageCtxT *image_ctx, Journaler *journaler,
ceph::mutex *lock, journal::ImageClientMeta *client_meta,
uint64_t *tag_tid, journal::TagData *tag_data,
Context *on_finish) {
return new OpenRequest(image_ctx, journaler, lock, client_meta, tag_tid,
tag_data, on_finish);
}
OpenRequest(ImageCtxT *image_ctx, Journaler *journaler, ceph::mutex *lock,
journal::ImageClientMeta *client_meta, uint64_t *tag_tid,
journal::TagData *tag_data, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* INIT
* |
* v
* GET_TAGS
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
Journaler *m_journaler;
ceph::mutex *m_lock;
journal::ImageClientMeta *m_client_meta;
uint64_t *m_tag_tid;
journal::TagData *m_tag_data;
Context *m_on_finish;
uint64_t m_tag_class = 0;
void send_init();
void handle_init(int r);
void send_get_tags();
void handle_get_tags(int r);
void finish(int r);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::OpenRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_OPEN_REQUEST_H
| 1,883 | 20.906977 | 86 | h |
null | ceph-main/src/librbd/journal/PromoteRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_PROMOTE_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_PROMOTE_REQUEST_H
#include "include/int_types.h"
#include "common/ceph_mutex.h"
#include "cls/journal/cls_journal_types.h"
#include "journal/Future.h"
#include "librbd/journal/Types.h"
#include "librbd/journal/TypeTraits.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace journal {
template <typename ImageCtxT = ImageCtx>
class PromoteRequest {
public:
static PromoteRequest* create(ImageCtxT *image_ctx, bool force,
Context *on_finish) {
return new PromoteRequest(image_ctx, force, on_finish);
}
PromoteRequest(ImageCtxT *image_ctx, bool force, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* OPEN * * * * * * * * * *
* | *
* v *
* ALLOCATE_TAG * * * * * *
* | *
* v *
* APPEND_EVENT * * * *
* | * *
* v * *
* COMMIT_EVENT * *
* | * *
* v * *
* STOP_APPEND <* * * *
* | *
* v *
* SHUT_DOWN <* * * * * * *
* |
* v
* <finish>
*
* @endverbatim
*/
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
typedef typename TypeTraits<ImageCtxT>::Future Future;
ImageCtxT *m_image_ctx;
bool m_force;
Context *m_on_finish;
Journaler *m_journaler = nullptr;
int m_ret_val = 0;
ceph::mutex m_lock;
ImageClientMeta m_client_meta;
uint64_t m_tag_tid = 0;
TagData m_tag_data;
cls::journal::Tag m_tag;
Future m_future;
void send_open();
void handle_open(int r);
void allocate_tag();
void handle_allocate_tag(int r);
void append_event();
void handle_append_event(int r);
void commit_event();
void handle_commit_event(int r);
void stop_append();
void handle_stop_append(int r);
void shut_down();
void handle_shut_down(int r);
void finish(int r);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::PromoteRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_PROMOTE_REQUEST_H
| 2,360 | 20.463636 | 72 | h |
null | ceph-main/src/librbd/journal/RemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_REMOVE_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_REMOVE_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "librbd/ImageCtx.h"
#include "journal/Journaler.h"
#include "librbd/journal/TypeTraits.h"
#include "common/Timer.h"
using librados::IoCtx;
using journal::Journaler;
class Context;
class ContextWQ;
namespace journal {
class Journaler;
}
namespace librbd {
class ImageCtx;
namespace journal {
template<typename ImageCtxT = ImageCtx>
class RemoveRequest {
public:
static RemoveRequest *create(IoCtx &ioctx, const std::string &image_id,
const std::string &client_id,
ContextWQ *op_work_queue, Context *on_finish) {
return new RemoveRequest(ioctx, image_id, client_id,
op_work_queue, on_finish);
}
void send();
private:
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
RemoveRequest(IoCtx &ioctx, const std::string &image_id,
const std::string &client_id,
ContextWQ *op_work_queue, Context *on_finish);
IoCtx &m_ioctx;
std::string m_image_id;
std::string m_image_client_id;
ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct;
Journaler *m_journaler;
SafeTimer *m_timer;
ceph::mutex *m_timer_lock;
int m_r_saved;
void stat_journal();
Context *handle_stat_journal(int *result);
void init_journaler();
Context *handle_init_journaler(int *result);
void remove_journal();
Context *handle_remove_journal(int *result);
void shut_down_journaler(int r);
Context *handle_journaler_shutdown(int *result);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::RemoveRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_REMOVE_REQUEST_H
| 2,045 | 23.95122 | 85 | h |
null | ceph-main/src/librbd/journal/Replay.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_REPLAY_H
#define CEPH_LIBRBD_JOURNAL_REPLAY_H
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/Context.h"
#include "common/ceph_mutex.h"
#include "librbd/io/Types.h"
#include "librbd/journal/Types.h"
#include <boost/variant.hpp>
#include <list>
#include <unordered_set>
#include <unordered_map>
namespace librbd {
class ImageCtx;
namespace io { struct AioCompletion; }
namespace journal {
template <typename ImageCtxT = ImageCtx>
class Replay {
public:
static Replay *create(ImageCtxT &image_ctx) {
return new Replay(image_ctx);
}
Replay(ImageCtxT &image_ctx);
~Replay();
int decode(bufferlist::const_iterator *it, EventEntry *event_entry);
void process(const EventEntry &event_entry,
Context *on_ready, Context *on_safe);
void shut_down(bool cancel_ops, Context *on_finish);
void flush(Context *on_finish);
void replay_op_ready(uint64_t op_tid, Context *on_resume);
private:
typedef std::unordered_set<int> ReturnValues;
struct OpEvent {
bool op_in_progress = false;
bool finish_on_ready = false;
Context *on_op_finish_event = nullptr;
Context *on_start_ready = nullptr;
Context *on_start_safe = nullptr;
Context *on_finish_ready = nullptr;
Context *on_finish_safe = nullptr;
Context *on_op_complete = nullptr;
ReturnValues op_finish_error_codes;
ReturnValues ignore_error_codes;
};
typedef std::list<uint64_t> OpTids;
typedef std::list<Context *> Contexts;
typedef std::unordered_set<Context *> ContextSet;
typedef std::unordered_map<uint64_t, OpEvent> OpEvents;
struct C_OpOnComplete : public Context {
Replay *replay;
uint64_t op_tid;
C_OpOnComplete(Replay *replay, uint64_t op_tid)
: replay(replay), op_tid(op_tid) {
}
void finish(int r) override {
replay->handle_op_complete(op_tid, r);
}
};
struct C_AioModifyComplete : public Context {
Replay *replay;
Context *on_ready;
Context *on_safe;
std::set<int> filters;
C_AioModifyComplete(Replay *replay, Context *on_ready,
Context *on_safe, std::set<int> &&filters)
: replay(replay), on_ready(on_ready), on_safe(on_safe),
filters(std::move(filters)) {
}
void finish(int r) override {
replay->handle_aio_modify_complete(on_ready, on_safe, r, filters);
}
};
struct C_AioFlushComplete : public Context {
Replay *replay;
Context *on_flush_safe;
Contexts on_safe_ctxs;
C_AioFlushComplete(Replay *replay, Context *on_flush_safe,
Contexts &&on_safe_ctxs)
: replay(replay), on_flush_safe(on_flush_safe),
on_safe_ctxs(on_safe_ctxs) {
}
void finish(int r) override {
replay->handle_aio_flush_complete(on_flush_safe, on_safe_ctxs, r);
}
};
struct EventVisitor : public boost::static_visitor<void> {
Replay *replay;
Context *on_ready;
Context *on_safe;
EventVisitor(Replay *_replay, Context *_on_ready, Context *_on_safe)
: replay(_replay), on_ready(_on_ready), on_safe(_on_safe) {
}
template <typename Event>
inline void operator()(const Event &event) const {
replay->handle_event(event, on_ready, on_safe);
}
};
ImageCtxT &m_image_ctx;
ceph::mutex m_lock = ceph::make_mutex("Replay<I>::m_lock");
uint64_t m_in_flight_aio_flush = 0;
uint64_t m_in_flight_aio_modify = 0;
Contexts m_aio_modify_unsafe_contexts;
ContextSet m_aio_modify_safe_contexts;
OpEvents m_op_events;
uint64_t m_in_flight_op_events = 0;
bool m_shut_down = false;
Context *m_flush_ctx = nullptr;
Context *m_on_aio_ready = nullptr;
void handle_event(const AioDiscardEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const AioWriteEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const AioWriteSameEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const AioCompareAndWriteEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const AioFlushEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const OpFinishEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapCreateEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapRemoveEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapRenameEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapProtectEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapUnprotectEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapRollbackEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const RenameEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const ResizeEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const FlattenEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const DemotePromoteEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const SnapLimitEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const UpdateFeaturesEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const MetadataSetEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const MetadataRemoveEvent &event, Context *on_ready,
Context *on_safe);
void handle_event(const UnknownEvent &event, Context *on_ready,
Context *on_safe);
void handle_aio_modify_complete(Context *on_ready, Context *on_safe,
int r, std::set<int> &filters);
void handle_aio_flush_complete(Context *on_flush_safe, Contexts &on_safe_ctxs,
int r);
Context *create_op_context_callback(uint64_t op_tid, Context *on_ready,
Context *on_safe, OpEvent **op_event);
void handle_op_complete(uint64_t op_tid, int r);
io::AioCompletion *create_aio_modify_completion(Context *on_ready,
Context *on_safe,
io::aio_type_t aio_type,
bool *flush_required,
std::set<int> &&filters);
io::AioCompletion *create_aio_flush_completion(Context *on_safe);
void handle_aio_completion(io::AioCompletion *aio_comp);
bool clipped_io(uint64_t image_offset, io::AioCompletion *aio_comp);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::Replay<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_REPLAY_H
| 7,233 | 34.116505 | 80 | h |
null | ceph-main/src/librbd/journal/ResetRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_RESET_REQUEST_H
#define CEPH_LIBRBD_JOURNAL_RESET_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "librbd/journal/TypeTraits.h"
#include "common/Timer.h"
#include <string>
class Context;
class ContextWQ;
namespace journal { class Journaler; }
namespace librbd {
class ImageCtx;
namespace journal {
template<typename ImageCtxT = ImageCtx>
class ResetRequest {
public:
static ResetRequest *create(librados::IoCtx &io_ctx,
const std::string &image_id,
const std::string &client_id,
const std::string &mirror_uuid,
ContextWQ *op_work_queue, Context *on_finish) {
return new ResetRequest(io_ctx, image_id, client_id, mirror_uuid,
op_work_queue, on_finish);
}
ResetRequest(librados::IoCtx &io_ctx, const std::string &image_id,
const std::string &client_id, const std::string &mirror_uuid,
ContextWQ *op_work_queue, Context *on_finish)
: m_io_ctx(io_ctx), m_image_id(image_id), m_client_id(client_id),
m_mirror_uuid(mirror_uuid), m_op_work_queue(op_work_queue),
m_on_finish(on_finish),
m_cct(reinterpret_cast<CephContext *>(m_io_ctx.cct())) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* INIT_JOURNALER
* |
* v
* SHUT_DOWN_JOURNALER
* |
* v
* REMOVE_JOURNAL
* |
* v
* CREATE_JOURNAL
* |
* v
* <finish>
*
* @endverbatim
*/
typedef typename TypeTraits<ImageCtxT>::Journaler Journaler;
librados::IoCtx &m_io_ctx;
std::string m_image_id;
std::string m_client_id;
std::string m_mirror_uuid;
ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct;
Journaler *m_journaler = nullptr;
int m_ret_val = 0;
uint8_t m_order = 0;
uint8_t m_splay_width = 0;
std::string m_object_pool_name;
void init_journaler();
void handle_init_journaler(int r);
void shut_down_journaler();
void handle_journaler_shutdown(int r);
void remove_journal();
void handle_remove_journal(int r);
void create_journal();
void handle_create_journal(int r);
void finish(int r);
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::ResetRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_REMOVE_REQUEST_H
| 2,630 | 22.702703 | 77 | h |
null | ceph-main/src/librbd/journal/StandardPolicy.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_STANDARD_POLICY_H
#define CEPH_LIBRBD_JOURNAL_STANDARD_POLICY_H
#include "librbd/journal/Policy.h"
namespace librbd {
struct ImageCtx;
namespace journal {
template<typename ImageCtxT = ImageCtx>
class StandardPolicy : public Policy {
public:
StandardPolicy(ImageCtxT *image_ctx) : m_image_ctx(image_ctx) {
}
bool append_disabled() const override {
return false;
}
bool journal_disabled() const override {
return false;
}
void allocate_tag_on_lock(Context *on_finish) override;
private:
ImageCtxT *m_image_ctx;
};
} // namespace journal
} // namespace librbd
extern template class librbd::journal::StandardPolicy<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_JOURNAL_STANDARD_POLICY_H
| 840 | 20.564103 | 72 | h |
null | ceph-main/src/librbd/journal/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_TYPES_H
#define CEPH_LIBRBD_JOURNAL_TYPES_H
#include "cls/rbd/cls_rbd_types.h"
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/encoding.h"
#include "include/types.h"
#include "include/utime.h"
#include "librbd/Types.h"
#include <iosfwd>
#include <list>
#include <boost/none.hpp>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <boost/mpl/vector.hpp>
namespace ceph {
class Formatter;
}
namespace librbd {
namespace journal {
enum EventType {
EVENT_TYPE_AIO_DISCARD = 0,
EVENT_TYPE_AIO_WRITE = 1,
EVENT_TYPE_AIO_FLUSH = 2,
EVENT_TYPE_OP_FINISH = 3,
EVENT_TYPE_SNAP_CREATE = 4,
EVENT_TYPE_SNAP_REMOVE = 5,
EVENT_TYPE_SNAP_RENAME = 6,
EVENT_TYPE_SNAP_PROTECT = 7,
EVENT_TYPE_SNAP_UNPROTECT = 8,
EVENT_TYPE_SNAP_ROLLBACK = 9,
EVENT_TYPE_RENAME = 10,
EVENT_TYPE_RESIZE = 11,
EVENT_TYPE_FLATTEN = 12,
EVENT_TYPE_DEMOTE_PROMOTE = 13,
EVENT_TYPE_SNAP_LIMIT = 14,
EVENT_TYPE_UPDATE_FEATURES = 15,
EVENT_TYPE_METADATA_SET = 16,
EVENT_TYPE_METADATA_REMOVE = 17,
EVENT_TYPE_AIO_WRITESAME = 18,
EVENT_TYPE_AIO_COMPARE_AND_WRITE = 19,
};
struct AioDiscardEvent {
static const EventType TYPE = EVENT_TYPE_AIO_DISCARD;
uint64_t offset = 0;
uint64_t length = 0;
uint32_t discard_granularity_bytes = 0;
AioDiscardEvent() {
}
AioDiscardEvent(uint64_t _offset, uint64_t _length,
uint32_t discard_granularity_bytes)
: offset(_offset), length(_length),
discard_granularity_bytes(discard_granularity_bytes) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct AioWriteEvent {
static const EventType TYPE = EVENT_TYPE_AIO_WRITE;
uint64_t offset;
uint64_t length;
bufferlist data;
static uint32_t get_fixed_size();
AioWriteEvent() : offset(0), length(0) {
}
AioWriteEvent(uint64_t _offset, uint64_t _length, const bufferlist &_data)
: offset(_offset), length(_length), data(_data) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct AioWriteSameEvent {
static const EventType TYPE = EVENT_TYPE_AIO_WRITESAME;
uint64_t offset;
uint64_t length;
bufferlist data;
AioWriteSameEvent() : offset(0), length(0) {
}
AioWriteSameEvent(uint64_t _offset, uint64_t _length,
const bufferlist &_data)
: offset(_offset), length(_length), data(_data) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct AioCompareAndWriteEvent {
static const EventType TYPE = EVENT_TYPE_AIO_COMPARE_AND_WRITE;
uint64_t offset;
uint64_t length;
bufferlist cmp_data;
bufferlist write_data;
static uint32_t get_fixed_size();
AioCompareAndWriteEvent() : offset(0), length(0) {
}
AioCompareAndWriteEvent(uint64_t _offset, uint64_t _length,
const bufferlist &_cmp_data, const bufferlist &_write_data)
: offset(_offset), length(_length), cmp_data(_cmp_data), write_data(_write_data) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct AioFlushEvent {
static const EventType TYPE = EVENT_TYPE_AIO_FLUSH;
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct OpEventBase {
uint64_t op_tid;
protected:
OpEventBase() : op_tid(0) {
}
OpEventBase(uint64_t op_tid) : op_tid(op_tid) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct OpFinishEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_OP_FINISH;
int r;
OpFinishEvent() : r(0) {
}
OpFinishEvent(uint64_t op_tid, int r) : OpEventBase(op_tid), r(r) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct SnapEventBase : public OpEventBase {
cls::rbd::SnapshotNamespace snap_namespace;
std::string snap_name;
protected:
SnapEventBase() {
}
SnapEventBase(uint64_t op_tid, const cls::rbd::SnapshotNamespace& _snap_namespace,
const std::string &_snap_name)
: OpEventBase(op_tid),
snap_namespace(_snap_namespace),
snap_name(_snap_name) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct SnapCreateEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_CREATE;
SnapCreateEvent() {
}
SnapCreateEvent(uint64_t op_tid, const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name)
: SnapEventBase(op_tid, snap_namespace, snap_name) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct SnapRemoveEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_REMOVE;
SnapRemoveEvent() {
}
SnapRemoveEvent(uint64_t op_tid, const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name)
: SnapEventBase(op_tid, snap_namespace, snap_name) {
}
using SnapEventBase::encode;
using SnapEventBase::decode;
using SnapEventBase::dump;
};
struct SnapRenameEvent : public OpEventBase{
static const EventType TYPE = EVENT_TYPE_SNAP_RENAME;
uint64_t snap_id;
std::string src_snap_name;
std::string dst_snap_name;
SnapRenameEvent() : snap_id(CEPH_NOSNAP) {
}
SnapRenameEvent(uint64_t op_tid, uint64_t src_snap_id,
const std::string &src_snap_name,
const std::string &dest_snap_name)
: OpEventBase(op_tid),
snap_id(src_snap_id),
src_snap_name(src_snap_name),
dst_snap_name(dest_snap_name) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct SnapProtectEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_PROTECT;
SnapProtectEvent() {
}
SnapProtectEvent(uint64_t op_tid, const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name)
: SnapEventBase(op_tid, snap_namespace, snap_name) {
}
using SnapEventBase::encode;
using SnapEventBase::decode;
using SnapEventBase::dump;
};
struct SnapUnprotectEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_UNPROTECT;
SnapUnprotectEvent() {
}
SnapUnprotectEvent(uint64_t op_tid, const cls::rbd::SnapshotNamespace &snap_namespace,
const std::string &snap_name)
: SnapEventBase(op_tid, snap_namespace, snap_name) {
}
using SnapEventBase::encode;
using SnapEventBase::decode;
using SnapEventBase::dump;
};
struct SnapLimitEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_LIMIT;
uint64_t limit;
SnapLimitEvent() {
}
SnapLimitEvent(uint64_t op_tid, const uint64_t _limit)
: OpEventBase(op_tid), limit(_limit) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct SnapRollbackEvent : public SnapEventBase {
static const EventType TYPE = EVENT_TYPE_SNAP_ROLLBACK;
SnapRollbackEvent() {
}
SnapRollbackEvent(uint64_t op_tid, const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name)
: SnapEventBase(op_tid, snap_namespace, snap_name) {
}
using SnapEventBase::encode;
using SnapEventBase::decode;
using SnapEventBase::dump;
};
struct RenameEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_RENAME;
std::string image_name;
RenameEvent() {
}
RenameEvent(uint64_t op_tid, const std::string &_image_name)
: OpEventBase(op_tid), image_name(_image_name) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct ResizeEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_RESIZE;
uint64_t size;
ResizeEvent() : size(0) {
}
ResizeEvent(uint64_t op_tid, uint64_t _size)
: OpEventBase(op_tid), size(_size) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct FlattenEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_FLATTEN;
FlattenEvent() {
}
FlattenEvent(uint64_t op_tid) : OpEventBase(op_tid) {
}
using OpEventBase::encode;
using OpEventBase::decode;
using OpEventBase::dump;
};
struct DemotePromoteEvent {
static const EventType TYPE = static_cast<EventType>(
EVENT_TYPE_DEMOTE_PROMOTE);
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct UpdateFeaturesEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_UPDATE_FEATURES;
uint64_t features;
bool enabled;
UpdateFeaturesEvent() : features(0), enabled(false) {
}
UpdateFeaturesEvent(uint64_t op_tid, uint64_t _features, bool _enabled)
: OpEventBase(op_tid), features(_features), enabled(_enabled) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct MetadataSetEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_METADATA_SET;
std::string key;
std::string value;
MetadataSetEvent() {
}
MetadataSetEvent(uint64_t op_tid, const std::string &_key, const std::string &_value)
: OpEventBase(op_tid), key(_key), value(_value) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct MetadataRemoveEvent : public OpEventBase {
static const EventType TYPE = EVENT_TYPE_METADATA_REMOVE;
std::string key;
MetadataRemoveEvent() {
}
MetadataRemoveEvent(uint64_t op_tid, const std::string &_key)
: OpEventBase(op_tid), key(_key) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct UnknownEvent {
static const EventType TYPE = static_cast<EventType>(-1);
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
typedef boost::mpl::vector<AioDiscardEvent,
AioWriteEvent,
AioFlushEvent,
OpFinishEvent,
SnapCreateEvent,
SnapRemoveEvent,
SnapRenameEvent,
SnapProtectEvent,
SnapUnprotectEvent,
SnapRollbackEvent,
RenameEvent,
ResizeEvent,
FlattenEvent,
DemotePromoteEvent,
SnapLimitEvent,
UpdateFeaturesEvent,
MetadataSetEvent,
MetadataRemoveEvent,
AioWriteSameEvent,
AioCompareAndWriteEvent,
UnknownEvent> EventVector;
typedef boost::make_variant_over<EventVector>::type Event;
struct EventEntry {
static uint32_t get_fixed_size() {
return EVENT_FIXED_SIZE + METADATA_FIXED_SIZE;
}
EventEntry() : event(UnknownEvent()) {
}
EventEntry(const Event &_event, const utime_t &_timestamp = utime_t())
: event(_event), timestamp(_timestamp) {
}
Event event;
utime_t timestamp;
EventType get_event_type() const;
void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& it);
void dump(Formatter *f) const;
static void generate_test_instances(std::list<EventEntry *> &o);
private:
static const uint32_t EVENT_FIXED_SIZE = 14; /// version encoding, type
static const uint32_t METADATA_FIXED_SIZE = 14; /// version encoding, timestamp
void encode_metadata(bufferlist& bl) const;
void decode_metadata(bufferlist::const_iterator& it);
};
// Journal Client data structures
enum ClientMetaType {
IMAGE_CLIENT_META_TYPE = 0,
MIRROR_PEER_CLIENT_META_TYPE = 1,
CLI_CLIENT_META_TYPE = 2
};
struct ImageClientMeta {
static const ClientMetaType TYPE = IMAGE_CLIENT_META_TYPE;
uint64_t tag_class = 0;
bool resync_requested = false;
ImageClientMeta() {
}
ImageClientMeta(uint64_t tag_class) : tag_class(tag_class) {
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct MirrorPeerSyncPoint {
typedef boost::optional<uint64_t> ObjectNumber;
cls::rbd::SnapshotNamespace snap_namespace;
std::string snap_name;
std::string from_snap_name;
ObjectNumber object_number;
MirrorPeerSyncPoint() : MirrorPeerSyncPoint({}, "", "", boost::none) {
}
MirrorPeerSyncPoint(const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name,
const ObjectNumber &object_number)
: MirrorPeerSyncPoint(snap_namespace, snap_name, "", object_number) {
}
MirrorPeerSyncPoint(const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string &snap_name,
const std::string &from_snap_name,
const ObjectNumber &object_number)
: snap_namespace(snap_namespace), snap_name(snap_name),
from_snap_name(from_snap_name), object_number(object_number) {
}
inline bool operator==(const MirrorPeerSyncPoint &sync) const {
return (snap_name == sync.snap_name &&
from_snap_name == sync.from_snap_name &&
object_number == sync.object_number &&
snap_namespace == sync.snap_namespace);
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
enum MirrorPeerState {
MIRROR_PEER_STATE_SYNCING,
MIRROR_PEER_STATE_REPLAYING
};
struct MirrorPeerClientMeta {
typedef std::list<MirrorPeerSyncPoint> SyncPoints;
static const ClientMetaType TYPE = MIRROR_PEER_CLIENT_META_TYPE;
std::string image_id;
MirrorPeerState state = MIRROR_PEER_STATE_SYNCING; ///< replay state
uint64_t sync_object_count = 0; ///< maximum number of objects ever sync'ed
SyncPoints sync_points; ///< max two in-use snapshots for sync
SnapSeqs snap_seqs; ///< local to peer snap seq mapping
MirrorPeerClientMeta() {
}
MirrorPeerClientMeta(const std::string &image_id,
const SyncPoints &sync_points = SyncPoints(),
const SnapSeqs &snap_seqs = SnapSeqs())
: image_id(image_id), sync_points(sync_points), snap_seqs(snap_seqs) {
}
inline bool operator==(const MirrorPeerClientMeta &meta) const {
return (image_id == meta.image_id &&
state == meta.state &&
sync_object_count == meta.sync_object_count &&
sync_points == meta.sync_points &&
snap_seqs == meta.snap_seqs);
}
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct CliClientMeta {
static const ClientMetaType TYPE = CLI_CLIENT_META_TYPE;
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct UnknownClientMeta {
static const ClientMetaType TYPE = static_cast<ClientMetaType>(-1);
void encode(bufferlist& bl) const;
void decode(__u8 version, bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
typedef boost::variant<ImageClientMeta,
MirrorPeerClientMeta,
CliClientMeta,
UnknownClientMeta> ClientMeta;
struct ClientData {
ClientData() {
}
ClientData(const ClientMeta &client_meta) : client_meta(client_meta) {
}
ClientMeta client_meta;
ClientMetaType get_client_meta_type() const;
void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& it);
void dump(Formatter *f) const;
static void generate_test_instances(std::list<ClientData *> &o);
};
// Journal Tag data structures
struct TagPredecessor {
std::string mirror_uuid; // empty if local
bool commit_valid = false;
uint64_t tag_tid = 0;
uint64_t entry_tid = 0;
TagPredecessor() {
}
TagPredecessor(const std::string &mirror_uuid, bool commit_valid,
uint64_t tag_tid, uint64_t entry_tid)
: mirror_uuid(mirror_uuid), commit_valid(commit_valid), tag_tid(tag_tid),
entry_tid(entry_tid) {
}
inline bool operator==(const TagPredecessor &rhs) const {
return (mirror_uuid == rhs.mirror_uuid &&
commit_valid == rhs.commit_valid &&
tag_tid == rhs.tag_tid &&
entry_tid == rhs.entry_tid);
}
void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& it);
void dump(Formatter *f) const;
};
struct TagData {
// owner of the tag (exclusive lock epoch)
std::string mirror_uuid; // empty if local
// mapping to last committed record of previous tag
TagPredecessor predecessor;
TagData() {
}
TagData(const std::string &mirror_uuid) : mirror_uuid(mirror_uuid) {
}
TagData(const std::string &mirror_uuid,
const std::string &predecessor_mirror_uuid,
bool predecessor_commit_valid,
uint64_t predecessor_tag_tid, uint64_t predecessor_entry_tid)
: mirror_uuid(mirror_uuid),
predecessor(predecessor_mirror_uuid, predecessor_commit_valid,
predecessor_tag_tid, predecessor_entry_tid) {
}
void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& it);
void dump(Formatter *f) const;
static void generate_test_instances(std::list<TagData *> &o);
};
std::ostream &operator<<(std::ostream &out, const EventType &type);
std::ostream &operator<<(std::ostream &out, const ClientMetaType &type);
std::ostream &operator<<(std::ostream &out, const ImageClientMeta &meta);
std::ostream &operator<<(std::ostream &out, const MirrorPeerSyncPoint &sync);
std::ostream &operator<<(std::ostream &out, const MirrorPeerState &meta);
std::ostream &operator<<(std::ostream &out, const MirrorPeerClientMeta &meta);
std::ostream &operator<<(std::ostream &out, const TagPredecessor &predecessor);
std::ostream &operator<<(std::ostream &out, const TagData &tag_data);
struct Listener {
virtual ~Listener() {
}
/// invoked when journal close is requested
virtual void handle_close() = 0;
/// invoked when journal is promoted to primary
virtual void handle_promoted() = 0;
/// invoked when journal resync is requested
virtual void handle_resync() = 0;
};
WRITE_CLASS_ENCODER(EventEntry);
WRITE_CLASS_ENCODER(ClientData);
WRITE_CLASS_ENCODER(TagData);
} // namespace journal
} // namespace librbd
#endif // CEPH_LIBRBD_JOURNAL_TYPES_H
| 19,656 | 27.654519 | 88 | h |
null | ceph-main/src/librbd/journal/Utils.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_JOURNAL_UTILS_H
#define CEPH_LIBRBD_JOURNAL_UTILS_H
#include "include/common_fwd.h"
#include "include/int_types.h"
#include "include/Context.h"
#include "cls/journal/cls_journal_types.h"
#include <list>
namespace librbd {
namespace journal {
struct TagData;
namespace util {
struct C_DecodeTag : public Context {
CephContext *cct;
ceph::mutex *lock;
uint64_t *tag_tid;
TagData *tag_data;
Context *on_finish;
cls::journal::Tag tag;
C_DecodeTag(CephContext *cct, ceph::mutex *lock, uint64_t *tag_tid,
TagData *tag_data, Context *on_finish)
: cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
on_finish(on_finish) {
}
void complete(int r) override {
on_finish->complete(process(r));
Context::complete(0);
}
void finish(int r) override {
}
int process(int r);
static int decode(bufferlist::const_iterator *it, TagData *tag_data);
};
struct C_DecodeTags : public Context {
typedef std::list<cls::journal::Tag> Tags;
CephContext *cct;
ceph::mutex *lock;
uint64_t *tag_tid;
TagData *tag_data;
Context *on_finish;
Tags tags;
C_DecodeTags(CephContext *cct, ceph::mutex *lock, uint64_t *tag_tid,
TagData *tag_data, Context *on_finish)
: cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
on_finish(on_finish) {
}
void complete(int r) override {
on_finish->complete(process(r));
Context::complete(0);
}
void finish(int r) override {
}
int process(int r);
};
} // namespace util
} // namespace journal
} // namespace librbd
#endif // CEPH_LIBRBD_JOURNAL_UTILS_H
| 1,729 | 20.358025 | 71 | h |
null | ceph-main/src/librbd/managed_lock/AcquireRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_ACQUIRE_REQUEST_H
#define CEPH_LIBRBD_MANAGED_LOCK_ACQUIRE_REQUEST_H
#include "include/rados/librados.hpp"
#include "include/int_types.h"
#include "include/buffer.h"
#include "msg/msg_types.h"
#include "librbd/managed_lock/Types.h"
#include "librbd/watcher/Types.h"
#include <string>
class Context;
namespace librbd {
class AsioEngine;
class Watcher;
namespace managed_lock {
template <typename ImageCtxT>
class AcquireRequest {
private:
typedef watcher::Traits<ImageCtxT> TypeTraits;
typedef typename TypeTraits::Watcher Watcher;
public:
static AcquireRequest* create(librados::IoCtx& ioctx, Watcher *watcher,
AsioEngine& asio_engine,
const std::string& oid,
const std::string& cookie,
bool exclusive,
bool blocklist_on_break_lock,
uint32_t blocklist_expire_seconds,
Context *on_finish);
~AcquireRequest();
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_LOCKER
* | ^
* | . (EBUSY && no cached locker)
* | .
* | . (EBUSY && cached locker)
* \--> LOCK_IMAGE * * * * * * * * > BREAK_LOCK . . . . .
* | ^ | .
* | | | (success) .
* | \-------------------------/ .
* v .
* <finish> < . . . . . . . . . . . . . . . . . . .
*
* @endverbatim
*/
AcquireRequest(librados::IoCtx& ioctx, Watcher *watcher,
AsioEngine& asio_engine, const std::string& oid,
const std::string& cookie, bool exclusive,
bool blocklist_on_break_lock,
uint32_t blocklist_expire_seconds, Context *on_finish);
librados::IoCtx& m_ioctx;
Watcher *m_watcher;
CephContext *m_cct;
AsioEngine& m_asio_engine;
std::string m_oid;
std::string m_cookie;
bool m_exclusive;
bool m_blocklist_on_break_lock;
uint32_t m_blocklist_expire_seconds;
Context *m_on_finish;
bufferlist m_out_bl;
Locker m_locker;
void send_get_locker();
void handle_get_locker(int r);
void send_lock();
void handle_lock(int r);
void send_break_lock();
void handle_break_lock(int r);
void finish(int r);
};
} // namespace managed_lock
} // namespace librbd
#endif // CEPH_LIBRBD_MANAGED_LOCK_ACQUIRE_REQUEST_H
| 2,727 | 25.485437 | 73 | h |
null | ceph-main/src/librbd/managed_lock/BreakRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H
#define CEPH_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/rados/librados_fwd.hpp"
#include "msg/msg_types.h"
#include <list>
#include <string>
#include <boost/optional.hpp>
#include "librbd/managed_lock/Types.h"
class Context;
class ContextWQ;
class obj_watch_t;
namespace librbd {
class AsioEngine;
class ImageCtx;
template <typename> class Journal;
namespace asio { struct ContextWQ; }
namespace managed_lock {
template <typename ImageCtxT = ImageCtx>
class BreakRequest {
public:
static BreakRequest* create(librados::IoCtx& ioctx,
AsioEngine& asio_engine,
const std::string& oid, const Locker &locker,
bool exclusive, bool blocklist_locker,
uint32_t blocklist_expire_seconds,
bool force_break_lock, Context *on_finish) {
return new BreakRequest(ioctx, asio_engine, oid, locker, exclusive,
blocklist_locker, blocklist_expire_seconds,
force_break_lock, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_WATCHERS
* |
* v
* GET_LOCKER
* |
* v
* BLOCKLIST (skip if disabled)
* |
* v
* WAIT_FOR_OSD_MAP
* |
* v
* BREAK_LOCK
* |
* v
* <finish>
*
* @endvertbatim
*/
librados::IoCtx &m_ioctx;
CephContext *m_cct;
AsioEngine& m_asio_engine;
std::string m_oid;
Locker m_locker;
bool m_exclusive;
bool m_blocklist_locker;
uint32_t m_blocklist_expire_seconds;
bool m_force_break_lock;
Context *m_on_finish;
bufferlist m_out_bl;
std::list<obj_watch_t> m_watchers;
int m_watchers_ret_val;
Locker m_refreshed_locker;
BreakRequest(librados::IoCtx& ioctx, AsioEngine& asio_engine,
const std::string& oid, const Locker &locker,
bool exclusive, bool blocklist_locker,
uint32_t blocklist_expire_seconds, bool force_break_lock,
Context *on_finish);
void send_get_watchers();
void handle_get_watchers(int r);
void send_get_locker();
void handle_get_locker(int r);
void send_blocklist();
void handle_blocklist(int r);
void wait_for_osd_map();
void handle_wait_for_osd_map(int r);
void send_break_lock();
void handle_break_lock(int r);
void finish(int r);
};
} // namespace managed_lock
} // namespace librbd
extern template class librbd::managed_lock::BreakRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MANAGED_LOCK_BREAK_REQUEST_H
| 2,824 | 22.347107 | 75 | h |
null | ceph-main/src/librbd/managed_lock/GetLockerRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_GET_LOCKER_REQUEST_H
#define CEPH_LIBRBD_MANAGED_LOCK_GET_LOCKER_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "include/rados/librados_fwd.hpp"
#include <string>
class Context;
namespace librbd {
struct ImageCtx;
namespace managed_lock {
struct Locker;
template <typename ImageCtxT = ImageCtx>
class GetLockerRequest {
public:
static GetLockerRequest* create(librados::IoCtx& ioctx,
const std::string& oid, bool exclusive,
Locker *locker, Context *on_finish) {
return new GetLockerRequest(ioctx, oid, exclusive, locker, on_finish);
}
void send();
private:
librados::IoCtx &m_ioctx;
CephContext *m_cct;
std::string m_oid;
bool m_exclusive;
Locker *m_locker;
Context *m_on_finish;
bufferlist m_out_bl;
GetLockerRequest(librados::IoCtx& ioctx, const std::string& oid,
bool exclusive, Locker *locker, Context *on_finish);
void send_get_lockers();
void handle_get_lockers(int r);
void finish(int r);
};
} // namespace managed_lock
} // namespace librbd
extern template class librbd::managed_lock::GetLockerRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MANAGED_LOCK_GET_LOCKER_REQUEST_H
| 1,384 | 22.474576 | 79 | h |
null | ceph-main/src/librbd/managed_lock/ReacquireRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_REACQUIRE_REQUEST_H
#define CEPH_LIBRBD_MANAGED_LOCK_REACQUIRE_REQUEST_H
#include "include/rados/librados.hpp"
#include "include/int_types.h"
#include <string>
class Context;
namespace librbd {
class Watcher;
namespace managed_lock {
template <typename ImageCtxT>
class ReacquireRequest {
public:
static ReacquireRequest *create(librados::IoCtx& ioctx,
const std::string& oid,
const std::string& old_cookie,
const std::string &new_cookie,
bool exclusive,
Context *on_finish) {
return new ReacquireRequest(ioctx, oid, old_cookie, new_cookie, exclusive,
on_finish);
}
ReacquireRequest(librados::IoCtx& ioctx, const std::string& oid,
const std::string& old_cookie,
const std::string &new_cookie, bool exclusive,
Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* SET_COOKIE
* |
* v
* <finish>
*
* @endverbatim
*/
librados::IoCtx& m_ioctx;
std::string m_oid;
std::string m_old_cookie;
std::string m_new_cookie;
bool m_exclusive;
Context *m_on_finish;
void set_cookie();
void handle_set_cookie(int r);
};
} // namespace managed_lock
} // namespace librbd
#endif // CEPH_LIBRBD_MANAGED_LOCK_REACQUIRE_REQUEST_H
| 1,618 | 22.128571 | 78 | h |
null | ceph-main/src/librbd/managed_lock/ReleaseRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_RELEASE_REQUEST_H
#define CEPH_LIBRBD_MANAGED_LOCK_RELEASE_REQUEST_H
#include "include/rados/librados.hpp"
#include "librbd/watcher/Types.h"
#include <string>
class Context;
class ContextWQ;
namespace librbd {
class Watcher;
namespace asio { struct ContextWQ; }
namespace managed_lock {
template <typename ImageCtxT>
class ReleaseRequest {
private:
typedef watcher::Traits<ImageCtxT> TypeTraits;
typedef typename TypeTraits::Watcher Watcher;
public:
static ReleaseRequest* create(librados::IoCtx& ioctx, Watcher *watcher,
asio::ContextWQ *work_queue,
const std::string& oid,
const std::string& cookie,
Context *on_finish);
~ReleaseRequest();
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* UNLOCK
* |
* v
* <finish>
*
* @endverbatim
*/
ReleaseRequest(librados::IoCtx& ioctx, Watcher *watcher,
asio::ContextWQ *work_queue, const std::string& oid,
const std::string& cookie, Context *on_finish);
librados::IoCtx& m_ioctx;
Watcher *m_watcher;
std::string m_oid;
std::string m_cookie;
Context *m_on_finish;
void send_unlock();
void handle_unlock(int r);
void finish();
};
} // namespace managed_lock
} // namespace librbd
#endif // CEPH_LIBRBD_MANAGED_LOCK_RELEASE_REQUEST_H
| 1,571 | 20.534247 | 73 | h |
null | ceph-main/src/librbd/managed_lock/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_TYPES_H
#define CEPH_LIBRBD_MANAGED_LOCK_TYPES_H
#include "msg/msg_types.h"
#include <string>
namespace librbd {
namespace managed_lock {
struct Locker {
entity_name_t entity;
std::string cookie;
std::string address;
uint64_t handle = 0;
Locker() {
}
Locker(const entity_name_t& entity, const std::string &cookie,
const std::string &address, uint64_t handle)
: entity(entity), cookie(cookie), address(address), handle(handle) {
}
inline bool operator==(const Locker &rhs) const {
return (entity == rhs.entity &&
cookie == rhs.cookie &&
address == rhs.address &&
handle == rhs.handle);
}
inline bool operator!=(const Locker &rhs) const {
return !(*this == rhs);
}
};
enum Mode {
EXCLUSIVE,
SHARED
};
} // namespace managed_lock
} // namespace librbd
#endif // CEPH_LIBRBD_MANAGED_LOCK_TYPES_H
| 1,018 | 20.680851 | 72 | h |
null | ceph-main/src/librbd/managed_lock/Utils.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
#define CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
#include "include/int_types.h"
#include <string>
namespace librbd {
namespace managed_lock {
namespace util {
const std::string &get_watcher_lock_tag();
bool decode_lock_cookie(const std::string &tag, uint64_t *handle);
std::string encode_lock_cookie(uint64_t watch_handle);
} // namespace util
} // namespace managed_lock
} // namespace librbd
#endif // CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
| 575 | 23 | 70 | h |
null | ceph-main/src/librbd/migration/FileStream.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_FILE_STREAM_H
#define CEPH_LIBRBD_MIGRATION_FILE_STREAM_H
#include "include/int_types.h"
#include "librbd/migration/StreamInterface.h"
#include <boost/asio/io_context.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/posix/basic_stream_descriptor.hpp>
#include <json_spirit/json_spirit.h>
#include <memory>
#include <string>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename ImageCtxT>
class FileStream : public StreamInterface {
public:
static FileStream* create(ImageCtxT* image_ctx,
const json_spirit::mObject& json_object) {
return new FileStream(image_ctx, json_object);
}
FileStream(ImageCtxT* image_ctx, const json_spirit::mObject& json_object);
~FileStream() override;
FileStream(const FileStream&) = delete;
FileStream& operator=(const FileStream&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_size(uint64_t* size, Context* on_finish) override;
void read(io::Extents&& byte_extents, bufferlist* data,
Context* on_finish) override;
private:
CephContext* m_cct;
std::shared_ptr<AsioEngine> m_asio_engine;
json_spirit::mObject m_json_object;
boost::asio::strand<boost::asio::io_context::executor_type> m_strand;
#ifdef BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
std::optional<boost::asio::posix::stream_descriptor> m_stream_descriptor;
struct ReadRequest;
#endif // BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
int m_file_no = -1;
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::FileStream<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_FILE_STREAM_H
| 1,846 | 25.768116 | 76 | h |
null | ceph-main/src/librbd/migration/FormatInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_FORMAT_INTERFACE_H
#define CEPH_LIBRBD_MIGRATION_FORMAT_INTERFACE_H
#include "include/buffer_fwd.h"
#include "include/int_types.h"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <map>
struct Context;
namespace librbd {
namespace io {
struct AioCompletion;
struct ReadResult;
} // namespace io
namespace migration {
struct FormatInterface {
typedef std::map<uint64_t, SnapInfo> SnapInfos;
virtual ~FormatInterface() {
}
virtual void open(Context* on_finish) = 0;
virtual void close(Context* on_finish) = 0;
virtual void get_snapshots(SnapInfos* snap_infos, Context* on_finish) = 0;
virtual void get_image_size(uint64_t snap_id, uint64_t* size,
Context* on_finish) = 0;
virtual bool read(io::AioCompletion* aio_comp, uint64_t snap_id,
io::Extents&& image_extents, io::ReadResult&& read_result,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) = 0;
virtual void list_snaps(io::Extents&& image_extents, io::SnapIds&& snap_ids,
int list_snaps_flags,
io::SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace,
Context* on_finish) = 0;
};
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_FORMAT_INTERFACE_H
| 1,563 | 27.962963 | 78 | h |
null | ceph-main/src/librbd/migration/HttpClient.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_HTTP_CLIENT_H
#define CEPH_LIBRBD_MIGRATION_HTTP_CLIENT_H
#include "include/common_fwd.h"
#include "include/int_types.h"
#include "librbd/io/Types.h"
#include "librbd/migration/HttpProcessorInterface.h"
#include "librbd/migration/Types.h"
#include <boost/asio/io_context.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/beast/version.hpp>
#include <boost/beast/core/tcp_stream.hpp>
#include <boost/beast/http/empty_body.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/string_body.hpp>
#include <boost/beast/http/write.hpp>
#include <boost/beast/ssl/ssl_stream.hpp>
#include <functional>
#include <memory>
#include <string>
#include <utility>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename ImageCtxT>
class HttpClient {
public:
using EmptyBody = boost::beast::http::empty_body;
using StringBody = boost::beast::http::string_body;
using Request = boost::beast::http::request<EmptyBody>;
using Response = boost::beast::http::response<StringBody>;
using RequestPreprocessor = std::function<void(Request&)>;
static HttpClient* create(ImageCtxT* image_ctx, const std::string& url) {
return new HttpClient(image_ctx, url);
}
HttpClient(ImageCtxT* image_ctx, const std::string& url);
HttpClient(const HttpClient&) = delete;
HttpClient& operator=(const HttpClient&) = delete;
void open(Context* on_finish);
void close(Context* on_finish);
void get_size(uint64_t* size, Context* on_finish);
void read(io::Extents&& byte_extents, bufferlist* data,
Context* on_finish);
void set_ignore_self_signed_cert(bool ignore) {
m_ignore_self_signed_cert = ignore;
}
void set_http_processor(HttpProcessorInterface* http_processor) {
m_http_processor = http_processor;
}
template <class Body, typename Completion>
void issue(boost::beast::http::request<Body>&& request,
Completion&& completion) {
struct WorkImpl : Work {
HttpClient* http_client;
boost::beast::http::request<Body> request;
Completion completion;
WorkImpl(HttpClient* http_client,
boost::beast::http::request<Body>&& request,
Completion&& completion)
: http_client(http_client), request(std::move(request)),
completion(std::move(completion)) {
}
WorkImpl(const WorkImpl&) = delete;
WorkImpl& operator=(const WorkImpl&) = delete;
bool need_eof() const override {
return request.need_eof();
}
bool header_only() const override {
return (request.method() == boost::beast::http::verb::head);
}
void complete(int r, Response&& response) override {
completion(r, std::move(response));
}
void operator()(boost::beast::tcp_stream& stream) override {
preprocess_request();
boost::beast::http::async_write(
stream, request,
[http_session=http_client->m_http_session.get(),
work=this->shared_from_this()]
(boost::beast::error_code ec, std::size_t) mutable {
http_session->handle_issue(ec, std::move(work));
});
}
void operator()(
boost::beast::ssl_stream<boost::beast::tcp_stream>& stream) override {
preprocess_request();
boost::beast::http::async_write(
stream, request,
[http_session=http_client->m_http_session.get(),
work=this->shared_from_this()]
(boost::beast::error_code ec, std::size_t) mutable {
http_session->handle_issue(ec, std::move(work));
});
}
void preprocess_request() {
if (http_client->m_http_processor) {
http_client->m_http_processor->process_request(request);
}
}
};
initialize_default_fields(request);
issue(std::make_shared<WorkImpl>(this, std::move(request),
std::move(completion)));
}
private:
struct Work;
struct HttpSessionInterface {
virtual ~HttpSessionInterface() {}
virtual void init(Context* on_finish) = 0;
virtual void shut_down(Context* on_finish) = 0;
virtual void issue(std::shared_ptr<Work>&& work) = 0;
virtual void handle_issue(boost::system::error_code ec,
std::shared_ptr<Work>&& work) = 0;
};
struct Work : public std::enable_shared_from_this<Work> {
virtual ~Work() {}
virtual bool need_eof() const = 0;
virtual bool header_only() const = 0;
virtual void complete(int r, Response&&) = 0;
virtual void operator()(boost::beast::tcp_stream& stream) = 0;
virtual void operator()(
boost::beast::ssl_stream<boost::beast::tcp_stream>& stream) = 0;
};
template <typename D> struct HttpSession;
struct PlainHttpSession;
struct SslHttpSession;
CephContext* m_cct;
ImageCtxT* m_image_ctx;
std::shared_ptr<AsioEngine> m_asio_engine;
std::string m_url;
UrlSpec m_url_spec;
bool m_ignore_self_signed_cert = false;
HttpProcessorInterface* m_http_processor = nullptr;
boost::asio::strand<boost::asio::io_context::executor_type> m_strand;
boost::asio::ssl::context m_ssl_context;
std::unique_ptr<HttpSessionInterface> m_http_session;
template <typename Fields>
void initialize_default_fields(Fields& fields) const {
fields.target(m_url_spec.path);
fields.set(boost::beast::http::field::host, m_url_spec.host);
fields.set(boost::beast::http::field::user_agent,
BOOST_BEAST_VERSION_STRING);
}
void handle_get_size(int r, Response&& response, uint64_t* size,
Context* on_finish);
void handle_read(int r, Response&& response, uint64_t byte_offset,
uint64_t byte_length, bufferlist* data, Context* on_finish);
void issue(std::shared_ptr<Work>&& work);
void create_http_session(Context* on_finish);
void shut_down_http_session(Context* on_finish);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::HttpClient<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_HTTP_CLIENT_H
| 6,322 | 29.694175 | 80 | h |
null | ceph-main/src/librbd/migration/HttpProcessorInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_HTTP_PROCESSOR_INTERFACE_H
#define CEPH_LIBRBD_MIGRATION_HTTP_PROCESSOR_INTERFACE_H
#include <boost/beast/http/empty_body.hpp>
#include <boost/beast/http/message.hpp>
namespace librbd {
namespace migration {
struct HttpProcessorInterface {
using EmptyBody = boost::beast::http::empty_body;
using EmptyRequest = boost::beast::http::request<EmptyBody>;
virtual ~HttpProcessorInterface() {
}
virtual void process_request(EmptyRequest& request) = 0;
};
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_HTTP_PROCESSOR_INTERFACE_H
| 702 | 24.107143 | 70 | h |
null | ceph-main/src/librbd/migration/HttpStream.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_HTTP_STREAM_H
#define CEPH_LIBRBD_MIGRATION_HTTP_STREAM_H
#include "include/int_types.h"
#include "librbd/migration/StreamInterface.h"
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/string_body.hpp>
#include <json_spirit/json_spirit.h>
#include <memory>
#include <string>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename> class HttpClient;
template <typename ImageCtxT>
class HttpStream : public StreamInterface {
public:
static HttpStream* create(ImageCtxT* image_ctx,
const json_spirit::mObject& json_object) {
return new HttpStream(image_ctx, json_object);
}
HttpStream(ImageCtxT* image_ctx, const json_spirit::mObject& json_object);
~HttpStream() override;
HttpStream(const HttpStream&) = delete;
HttpStream& operator=(const HttpStream&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_size(uint64_t* size, Context* on_finish) override;
void read(io::Extents&& byte_extents, bufferlist* data,
Context* on_finish) override;
private:
using HttpResponse = boost::beast::http::response<
boost::beast::http::string_body>;
ImageCtxT* m_image_ctx;
CephContext* m_cct;
std::shared_ptr<AsioEngine> m_asio_engine;
json_spirit::mObject m_json_object;
std::string m_url;
std::unique_ptr<HttpClient<ImageCtxT>> m_http_client;
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::HttpStream<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_HTTP_STREAM_H
| 1,750 | 24.376812 | 76 | h |
null | ceph-main/src/librbd/migration/ImageDispatch.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_IMAGE_DISPATCH_H
#define CEPH_LIBRBD_MIGRATION_IMAGE_DISPATCH_H
#include "librbd/io/ImageDispatchInterface.h"
#include <memory>
struct Context;
namespace librbd {
struct ImageCtx;
namespace migration {
struct FormatInterface;
template <typename ImageCtxT>
class ImageDispatch : public io::ImageDispatchInterface {
public:
static ImageDispatch* create(ImageCtxT* image_ctx,
std::unique_ptr<FormatInterface> source) {
return new ImageDispatch(image_ctx, std::move(source));
}
ImageDispatch(ImageCtxT* image_ctx, std::unique_ptr<FormatInterface> source);
void shut_down(Context* on_finish) override;
io::ImageDispatchLayer get_dispatch_layer() const override {
return io::IMAGE_DISPATCH_LAYER_MIGRATION;
}
bool read(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
io::ReadResult &&read_result, IOContext io_context, int op_flags,
int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write(
io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool discard(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool write_same(
io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool compare_and_write(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool flush(
io::AioCompletion* aio_comp, io::FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool list_snaps(
io::AioCompletion* aio_comp, io::Extents&& image_extents,
io::SnapIds&& snap_ids, int list_snaps_flags,
io::SnapshotDelta* snapshot_delta, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) override;
bool invalidate_cache(Context* on_finish) override {
return false;
}
private:
ImageCtxT* m_image_ctx;
std::unique_ptr<FormatInterface> m_format;
void fail_io(int r, io::AioCompletion* aio_comp,
io::DispatchResult* dispatch_result);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::ImageDispatch<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_IMAGE_DISPATCH_H
| 3,741 | 35.686275 | 80 | h |
null | ceph-main/src/librbd/migration/NativeFormat.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_NATIVE_FORMAT_H
#define CEPH_LIBRBD_MIGRATION_NATIVE_FORMAT_H
#include "include/int_types.h"
#include "librbd/Types.h"
#include "librbd/migration/FormatInterface.h"
#include "json_spirit/json_spirit.h"
#include <memory>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename ImageCtxT>
class NativeFormat : public FormatInterface {
public:
static std::string build_source_spec(int64_t pool_id,
const std::string& pool_namespace,
const std::string& image_name,
const std::string& image_id);
static NativeFormat* create(ImageCtxT* image_ctx,
const json_spirit::mObject& json_object,
bool import_only) {
return new NativeFormat(image_ctx, json_object, import_only);
}
NativeFormat(ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
bool import_only);
NativeFormat(const NativeFormat&) = delete;
NativeFormat& operator=(const NativeFormat&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_snapshots(SnapInfos* snap_infos, Context* on_finish) override;
void get_image_size(uint64_t snap_id, uint64_t* size,
Context* on_finish) override;
bool read(io::AioCompletion* aio_comp, uint64_t snap_id,
io::Extents&& image_extents, io::ReadResult&& read_result,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) override {
return false;
}
void list_snaps(io::Extents&& image_extents, io::SnapIds&& snap_ids,
int list_snaps_flags, io::SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace,
Context* on_finish) override;
private:
ImageCtxT* m_image_ctx;
json_spirit::mObject m_json_object;
bool m_import_only;
int64_t m_pool_id = -1;
std::string m_pool_namespace;
std::string m_image_name;
std::string m_image_id;
std::string m_snap_name;
uint64_t m_snap_id = CEPH_NOSNAP;
void handle_open(int r, Context* on_finish);
void handle_snap_set(int r, Context* on_finish);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::NativeFormat<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_NATIVE_FORMAT_H
| 2,579 | 30.084337 | 77 | h |
null | ceph-main/src/librbd/migration/OpenSourceImageRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
#define CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
#include "include/rados/librados_fwd.hpp"
#include "librbd/Types.h"
#include <map>
#include <memory>
struct Context;
namespace librbd {
struct ImageCtx;
namespace migration {
struct FormatInterface;
template <typename ImageCtxT>
class OpenSourceImageRequest {
public:
static OpenSourceImageRequest* create(librados::IoCtx& io_ctx,
ImageCtxT* destination_image_ctx,
uint64_t src_snap_id,
const MigrationInfo &migration_info,
ImageCtxT** source_image_ctx,
Context* on_finish) {
return new OpenSourceImageRequest(io_ctx, destination_image_ctx,
src_snap_id, migration_info,
source_image_ctx, on_finish);
}
OpenSourceImageRequest(librados::IoCtx& io_ctx,
ImageCtxT* destination_image_ctx,
uint64_t src_snap_id,
const MigrationInfo &migration_info,
ImageCtxT** source_image_ctx,
Context* on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* OPEN_SOURCE
* |
* v
* GET_IMAGE_SIZE * * * * * * *
* | *
* v v
* GET_SNAPSHOTS * * * * > CLOSE_IMAGE
* | |
* v |
* <finish> <------------------/
*
* @endverbatim
*/
typedef std::map<uint64_t, SnapInfo> SnapInfos;
CephContext* m_cct;
librados::IoCtx& m_io_ctx;
ImageCtxT* m_dst_image_ctx;
uint64_t m_src_snap_id;
MigrationInfo m_migration_info;
ImageCtxT** m_src_image_ctx;
Context* m_on_finish;
std::unique_ptr<FormatInterface> m_format;
uint64_t m_image_size = 0;
SnapInfos m_snap_infos;
void open_source();
void handle_open_source(int r);
void get_image_size();
void handle_get_image_size(int r);
void get_snapshots();
void handle_get_snapshots(int r);
void close_image(int r);
void register_image_dispatch();
void finish(int r);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::OpenSourceImageRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
| 2,644 | 24.432692 | 82 | h |
null | ceph-main/src/librbd/migration/QCOW.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/* Based on QEMU block/qcow.cc and block/qcow2.h, which has this license: */
/*
* Block driver for the QCOW version 2 format
*
* Copyright (c) 2004-2006 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CEPH_LIBRBD_MIGRATION_QCOW2_H
#define CEPH_LIBRBD_MIGRATION_QCOW2_H
#include "include/ceph_assert.h"
#include "include/int_types.h"
#include "librbd/migration/QCOW.h"
#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
#define QCOW_CRYPT_NONE 0
#define QCOW_CRYPT_AES 1
#define QCOW_CRYPT_LUKS 2
#define QCOW_MAX_CRYPT_CLUSTERS 32
#define QCOW_MAX_SNAPSHOTS 65536
/* Field widths in qcow2 mean normal cluster offsets cannot reach
* 64PB; depending on cluster size, compressed clusters can have a
* smaller limit (64PB for up to 16k clusters, then ramps down to
* 512TB for 2M clusters). */
#define QCOW_MAX_CLUSTER_OFFSET ((1ULL << 56) - 1)
/* 8 MB refcount table is enough for 2 PB images at 64k cluster size
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
#define QCOW_MAX_REFTABLE_SIZE (1ULL << 23)
/* 32 MB L1 table is enough for 2 PB images at 64k cluster size
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
#define QCOW_MAX_L1_SIZE (1ULL << 25)
/* Allow for an average of 1k per snapshot table entry, should be plenty of
* space for snapshot names and IDs */
#define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
/* Maximum amount of extra data per snapshot table entry to accept */
#define QCOW_MAX_SNAPSHOT_EXTRA_DATA 1024
/* Bitmap header extension constraints */
#define QCOW2_MAX_BITMAPS 65535
#define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
/* Maximum of parallel sub-request per guest request */
#define QCOW2_MAX_WORKERS 8
/* indicate that the refcount of the referenced cluster is exactly one. */
#define QCOW_OFLAG_COPIED (1ULL << 63)
/* indicate that the cluster is compressed (they never have the copied flag) */
#define QCOW_OFLAG_COMPRESSED (1ULL << 62)
/* The cluster reads as all zeros */
#define QCOW_OFLAG_ZERO (1ULL << 0)
#define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32
/* The subcluster X [0..31] is allocated */
#define QCOW_OFLAG_SUB_ALLOC(X) (1ULL << (X))
/* The subcluster X [0..31] reads as zeroes */
#define QCOW_OFLAG_SUB_ZERO(X) (QCOW_OFLAG_SUB_ALLOC(X) << 32)
/* Subclusters [X, Y) (0 <= X <= Y <= 32) are allocated */
#define QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) \
(QCOW_OFLAG_SUB_ALLOC(Y) - QCOW_OFLAG_SUB_ALLOC(X))
/* Subclusters [X, Y) (0 <= X <= Y <= 32) read as zeroes */
#define QCOW_OFLAG_SUB_ZERO_RANGE(X, Y) \
(QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) << 32)
/* L2 entry bitmap with all allocation bits set */
#define QCOW_L2_BITMAP_ALL_ALLOC (QCOW_OFLAG_SUB_ALLOC_RANGE(0, 32))
/* L2 entry bitmap with all "read as zeroes" bits set */
#define QCOW_L2_BITMAP_ALL_ZEROES (QCOW_OFLAG_SUB_ZERO_RANGE(0, 32))
/* Size of normal and extended L2 entries */
#define QCOW_L2E_SIZE_NORMAL (sizeof(uint64_t))
#define QCOW_L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2)
/* Size of L1 table entries */
#define QCOW_L1E_SIZE (sizeof(uint64_t))
/* Size of reftable entries */
#define QCOW_REFTABLE_ENTRY_SIZE (sizeof(uint64_t))
#define QCOW_MIN_CLUSTER_BITS 9
#define QCOW_MAX_CLUSTER_BITS 21
/* Defined in the qcow2 spec (compressed cluster descriptor) */
#define QCOW2_COMPRESSED_SECTOR_SIZE 512U
#define QCOW2_COMPRESSED_SECTOR_MASK (~(QCOW2_COMPRESSED_SECTOR_SIZE - 1ULL))
#define QCOW_L2_CACHE_SIZE 16
/* Must be at least 2 to cover COW */
#define QCOW_MIN_L2_CACHE_SIZE 2 /* cache entries */
/* Must be at least 4 to cover all cases of refcount table growth */
#define QCOW_MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
#define QCOW_DEFAULT_L2_CACHE_MAX_SIZE (1ULL << 25)
#define QCOW_DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */
#define QCOW_DEFAULT_CLUSTER_SIZE 65536
#define QCOW2_OPT_DATA_FILE "data-file"
#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
#define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
#define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
#define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
#define QCOW2_OPT_OVERLAP "overlap-check"
#define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
#define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
#define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
#define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
#define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
#define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
#define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
#define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
#define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
#define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory"
#define QCOW2_OPT_CACHE_SIZE "cache-size"
#define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
#define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
#define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
#define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
typedef struct QCowHeaderProbe {
uint32_t magic;
uint32_t version;
} __attribute__((__packed__)) QCowHeaderProbe;
typedef struct QCowHeaderV1
{
uint32_t magic;
uint32_t version;
uint64_t backing_file_offset;
uint32_t backing_file_size;
uint32_t mtime;
uint64_t size; /* in bytes */
uint8_t cluster_bits;
uint8_t l2_bits;
uint16_t padding;
uint32_t crypt_method;
uint64_t l1_table_offset;
} __attribute__((__packed__)) QCowHeaderV1;
typedef struct QCowHeader {
uint32_t magic;
uint32_t version;
uint64_t backing_file_offset;
uint32_t backing_file_size;
uint32_t cluster_bits;
uint64_t size; /* in bytes */
uint32_t crypt_method;
uint32_t l1_size; /* XXX: save number of clusters instead ? */
uint64_t l1_table_offset;
uint64_t refcount_table_offset;
uint32_t refcount_table_clusters;
uint32_t nb_snapshots;
uint64_t snapshots_offset;
/* The following fields are only valid for version >= 3 */
uint64_t incompatible_features;
uint64_t compatible_features;
uint64_t autoclear_features;
uint32_t refcount_order;
uint32_t header_length;
/* Additional fields */
uint8_t compression_type;
/* header must be a multiple of 8 */
uint8_t padding[7];
} __attribute__((__packed__)) QCowHeader;
typedef struct QCowSnapshotHeader {
/* header is 8 byte aligned */
uint64_t l1_table_offset;
uint32_t l1_size;
uint16_t id_str_size;
uint16_t name_size;
uint32_t date_sec;
uint32_t date_nsec;
uint64_t vm_clock_nsec;
uint32_t vm_state_size;
uint32_t extra_data_size; /* for extension */
/* extra data follows */
/* id_str follows */
/* name follows */
} __attribute__((__packed__)) QCowSnapshotHeader;
typedef struct QCowSnapshotExtraData {
uint64_t vm_state_size_large;
uint64_t disk_size;
uint64_t icount;
} __attribute__((__packed__)) QCowSnapshotExtraData;
typedef struct QCowSnapshot {
uint64_t l1_table_offset;
uint32_t l1_size;
char *id_str;
char *name;
uint64_t disk_size;
uint64_t vm_state_size;
uint32_t date_sec;
uint32_t date_nsec;
uint64_t vm_clock_nsec;
/* icount value for the moment when snapshot was taken */
uint64_t icount;
/* Size of all extra data, including QCowSnapshotExtraData if available */
uint32_t extra_data_size;
/* Data beyond QCowSnapshotExtraData, if any */
void *unknown_extra_data;
} QCowSnapshot;
typedef struct Qcow2CryptoHeaderExtension {
uint64_t offset;
uint64_t length;
} __attribute__((__packed__)) Qcow2CryptoHeaderExtension;
typedef struct Qcow2UnknownHeaderExtension {
uint32_t magic;
uint32_t len;
uint8_t data[];
} Qcow2UnknownHeaderExtension;
enum {
QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
QCOW2_FEAT_TYPE_COMPATIBLE = 1,
QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
};
/* Incompatible feature bits */
enum {
QCOW2_INCOMPAT_DIRTY_BITNR = 0,
QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
QCOW2_INCOMPAT_DATA_FILE_BITNR = 2,
QCOW2_INCOMPAT_COMPRESSION_BITNR = 3,
QCOW2_INCOMPAT_EXTL2_BITNR = 4,
QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
QCOW2_INCOMPAT_DATA_FILE = 1 << QCOW2_INCOMPAT_DATA_FILE_BITNR,
QCOW2_INCOMPAT_COMPRESSION = 1 << QCOW2_INCOMPAT_COMPRESSION_BITNR,
QCOW2_INCOMPAT_EXTL2 = 1 << QCOW2_INCOMPAT_EXTL2_BITNR,
QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
| QCOW2_INCOMPAT_CORRUPT
| QCOW2_INCOMPAT_DATA_FILE
| QCOW2_INCOMPAT_COMPRESSION
| QCOW2_INCOMPAT_EXTL2,
};
/* Compatible feature bits */
enum {
QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
};
/* Autoclear feature bits */
enum {
QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0,
QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR = 1,
QCOW2_AUTOCLEAR_BITMAPS = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR,
QCOW2_AUTOCLEAR_DATA_FILE_RAW = 1 << QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR,
QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_BITMAPS
| QCOW2_AUTOCLEAR_DATA_FILE_RAW,
};
enum qcow2_discard_type {
QCOW2_DISCARD_NEVER = 0,
QCOW2_DISCARD_ALWAYS,
QCOW2_DISCARD_REQUEST,
QCOW2_DISCARD_SNAPSHOT,
QCOW2_DISCARD_OTHER,
QCOW2_DISCARD_MAX
};
typedef struct Qcow2Feature {
uint8_t type;
uint8_t bit;
char name[46];
} __attribute__((__packed__)) Qcow2Feature;
typedef struct Qcow2DiscardRegion {
uint64_t offset;
uint64_t bytes;
} Qcow2DiscardRegion;
typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
uint64_t index);
typedef void Qcow2SetRefcountFunc(void *refcount_array,
uint64_t index, uint64_t value);
typedef struct Qcow2BitmapHeaderExt {
uint32_t nb_bitmaps;
uint32_t reserved32;
uint64_t bitmap_directory_size;
uint64_t bitmap_directory_offset;
} __attribute__((__packed__)) Qcow2BitmapHeaderExt;
#define QCOW_RC_CACHE_SIZE QCOW_L2_CACHE_SIZE;
typedef struct Qcow2COWRegion {
/**
* Offset of the COW region in bytes from the start of the first cluster
* touched by the request.
*/
unsigned offset;
/** Number of bytes to copy */
unsigned nb_bytes;
} Qcow2COWRegion;
/**
* Describes an in-flight (part of a) write request that writes to clusters
* that are not referenced in their L2 table yet.
*/
typedef struct QCowL2Meta
{
/** Guest offset of the first newly allocated cluster */
uint64_t offset;
/** Host offset of the first newly allocated cluster */
uint64_t alloc_offset;
/** Number of newly allocated clusters */
int nb_clusters;
/** Do not free the old clusters */
bool keep_old_clusters;
/**
* The COW Region between the start of the first allocated cluster and the
* area the guest actually writes to.
*/
Qcow2COWRegion cow_start;
/**
* The COW Region between the area the guest actually writes to and the
* end of the last allocated cluster.
*/
Qcow2COWRegion cow_end;
/*
* Indicates that COW regions are already handled and do not require
* any more processing.
*/
bool skip_cow;
/**
* Indicates that this is not a normal write request but a preallocation.
* If the image has extended L2 entries this means that no new individual
* subclusters will be marked as allocated in the L2 bitmap (but any
* existing contents of that bitmap will be kept).
*/
bool prealloc;
/** Pointer to next L2Meta of the same write request */
struct QCowL2Meta *next;
} QCowL2Meta;
typedef enum QCow2ClusterType {
QCOW2_CLUSTER_UNALLOCATED,
QCOW2_CLUSTER_ZERO_PLAIN,
QCOW2_CLUSTER_ZERO_ALLOC,
QCOW2_CLUSTER_NORMAL,
QCOW2_CLUSTER_COMPRESSED,
} QCow2ClusterType;
typedef enum QCow2MetadataOverlap {
QCOW2_OL_MAIN_HEADER_BITNR = 0,
QCOW2_OL_ACTIVE_L1_BITNR = 1,
QCOW2_OL_ACTIVE_L2_BITNR = 2,
QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
QCOW2_OL_INACTIVE_L1_BITNR = 6,
QCOW2_OL_INACTIVE_L2_BITNR = 7,
QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8,
QCOW2_OL_MAX_BITNR = 9,
QCOW2_OL_NONE = 0,
QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
/* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
* reads. */
QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR),
} QCow2MetadataOverlap;
/* Perform all overlap checks which can be done in constant time */
#define QCOW2_OL_CONSTANT \
(QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY)
/* Perform all overlap checks which don't require disk access */
#define QCOW2_OL_CACHED \
(QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
QCOW2_OL_INACTIVE_L1)
/* Perform all overlap checks */
#define QCOW2_OL_ALL \
(QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
#define QCOW_L1E_OFFSET_MASK 0x00fffffffffffe00ULL
#define QCOW_L2E_OFFSET_MASK 0x00fffffffffffe00ULL
#define QCOW_L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
#define INV_OFFSET (-1ULL)
static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
{
return m->offset + m->cow_start.offset;
}
static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
{
return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
}
static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
{
return r1 > r2 ? r1 - r2 : r2 - r1;
}
#endif // CEPH_LIBRBD_MIGRATION_QCOW2_H
| 15,822 | 32.882227 | 83 | h |
null | ceph-main/src/librbd/migration/QCOWFormat.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_QCOW_FORMAT_H
#define CEPH_LIBRBD_MIGRATION_QCOW_FORMAT_H
#include "include/int_types.h"
#include "librbd/Types.h"
#include "librbd/migration/FormatInterface.h"
#include "librbd/migration/QCOW.h"
#include "acconfig.h"
#include "json_spirit/json_spirit.h"
#include <boost/asio/io_context_strand.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <deque>
#include <vector>
#include <memory>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename> struct SourceSpecBuilder;
struct StreamInterface;
namespace qcow_format {
struct LookupTable {
LookupTable() {}
LookupTable(uint32_t size) : size(size) {}
bufferlist bl;
uint64_t* cluster_offsets = nullptr;
uint32_t size = 0;
bool decoded = false;
void init();
void decode();
};
} // namespace qcow_format
template <typename ImageCtxT>
class QCOWFormat : public FormatInterface {
public:
static QCOWFormat* create(
ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder) {
return new QCOWFormat(image_ctx, json_object, source_spec_builder);
}
QCOWFormat(ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder);
QCOWFormat(const QCOWFormat&) = delete;
QCOWFormat& operator=(const QCOWFormat&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_snapshots(SnapInfos* snap_infos, Context* on_finish) override;
void get_image_size(uint64_t snap_id, uint64_t* size,
Context* on_finish) override;
bool read(io::AioCompletion* aio_comp, uint64_t snap_id,
io::Extents&& image_extents, io::ReadResult&& read_result,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) override;
void list_snaps(io::Extents&& image_extents, io::SnapIds&& snap_ids,
int list_snaps_flags, io::SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace,
Context* on_finish) override;
private:
/**
* @verbatim
*
* <start>
* |
* v
* OPEN
* |
* v
* PROBE
* |
* |\---> READ V1 HEADER ----------\
* | |
* \----> READ V2 HEADER |
* | |
* | /----------\ |
* | | | |
* v v | |
* READ SNAPSHOT | |
* | | |
* v | |
* READ SNAPSHOT EXTRA | |
* | | |
* v | |
* READ SNAPSHOT L1 TABLE |
* | |
* \--------------------\|
* |
* v
* READ L1 TABLE
* |
* v
* READ BACKING FILE
* |
* /-------------------------------/
* |
* v
* <opened>
*
* @endverbatim
*/
struct Cluster;
struct ClusterCache;
struct L2TableCache;
struct ReadRequest;
struct ListSnapsRequest;
struct Snapshot {
std::string id;
std::string name;
utime_t timestamp;
uint64_t size = 0;
uint64_t l1_table_offset = 0;
qcow_format::LookupTable l1_table;
uint32_t extra_data_size = 0;
};
ImageCtxT* m_image_ctx;
json_spirit::mObject m_json_object;
const SourceSpecBuilder<ImageCtxT>* m_source_spec_builder;
boost::asio::io_context::strand m_strand;
std::shared_ptr<StreamInterface> m_stream;
bufferlist m_bl;
uint64_t m_size = 0;
uint64_t m_backing_file_offset = 0;
uint32_t m_backing_file_size = 0;
uint32_t m_cluster_bits = 0;
uint32_t m_cluster_size = 0;
uint64_t m_cluster_offset_mask = 0;
uint64_t m_cluster_mask = 0;
uint32_t m_l1_shift = 0;
uint64_t m_l1_table_offset = 0;
qcow_format::LookupTable m_l1_table;
uint32_t m_l2_bits = 0;
uint32_t m_l2_size = 0;
uint32_t m_snapshot_count = 0;
uint64_t m_snapshots_offset = 0;
std::map<uint64_t, Snapshot> m_snapshots;
std::unique_ptr<L2TableCache> m_l2_table_cache;
std::unique_ptr<ClusterCache> m_cluster_cache;
void handle_open(int r, Context* on_finish);
void probe(Context* on_finish);
void handle_probe(int r, Context* on_finish);
#ifdef WITH_RBD_MIGRATION_FORMAT_QCOW_V1
void read_v1_header(Context* on_finish);
void handle_read_v1_header(int r, Context* on_finish);
#endif // WITH_RBD_MIGRATION_FORMAT_QCOW_V1
void read_v2_header(Context* on_finish);
void handle_read_v2_header(int r, Context* on_finish);
void read_snapshot(Context* on_finish);
void handle_read_snapshot(int r, Context* on_finish);
void read_snapshot_extra(Context* on_finish);
void handle_read_snapshot_extra(int r, Context* on_finish);
void read_snapshot_l1_table(Context* on_finish);
void handle_read_snapshot_l1_table(int r, Context* on_finish);
void read_l1_table(Context* on_finish);
void handle_read_l1_table(int r, Context* on_finish);
void read_backing_file(Context* on_finish);
void handle_list_snaps(int r, io::Extents&& image_extents,
io::SnapIds&& snap_ids,
io::SnapshotDelta* snapshot_delta, Context* on_finish);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::QCOWFormat<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_QCOW_FORMAT_H
| 5,918 | 26.919811 | 80 | h |
null | ceph-main/src/librbd/migration/RawFormat.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_RAW_FORMAT_H
#define CEPH_LIBRBD_MIGRATION_RAW_FORMAT_H
#include "include/int_types.h"
#include "librbd/Types.h"
#include "librbd/migration/FormatInterface.h"
#include "json_spirit/json_spirit.h"
#include <map>
#include <memory>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename> struct SourceSpecBuilder;
struct SnapshotInterface;
template <typename ImageCtxT>
class RawFormat : public FormatInterface {
public:
static RawFormat* create(
ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder) {
return new RawFormat(image_ctx, json_object, source_spec_builder);
}
RawFormat(ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder);
RawFormat(const RawFormat&) = delete;
RawFormat& operator=(const RawFormat&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_snapshots(SnapInfos* snap_infos, Context* on_finish) override;
void get_image_size(uint64_t snap_id, uint64_t* size,
Context* on_finish) override;
bool read(io::AioCompletion* aio_comp, uint64_t snap_id,
io::Extents&& image_extents, io::ReadResult&& read_result,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) override;
void list_snaps(io::Extents&& image_extents, io::SnapIds&& snap_ids,
int list_snaps_flags, io::SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace,
Context* on_finish) override;
private:
typedef std::shared_ptr<SnapshotInterface> Snapshot;
typedef std::map<uint64_t, Snapshot> Snapshots;
ImageCtxT* m_image_ctx;
json_spirit::mObject m_json_object;
const SourceSpecBuilder<ImageCtxT>* m_source_spec_builder;
Snapshots m_snapshots;
void handle_open(int r, Context* on_finish);
void handle_list_snaps(int r, io::SnapIds&& snap_ids,
io::SnapshotDelta* snapshot_delta, Context* on_finish);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::RawFormat<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_RAW_FORMAT_H
| 2,455 | 30.088608 | 80 | h |
null | ceph-main/src/librbd/migration/RawSnapshot.h | // -*- mode:c++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_RAW_SNAPSHOT_H
#define CEPH_LIBRBD_MIGRATION_RAW_SNAPSHOT_H
#include "include/buffer_fwd.h"
#include "include/int_types.h"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include "librbd/migration/SnapshotInterface.h"
#include "json_spirit/json_spirit.h"
#include <memory>
namespace librbd {
struct ImageCtx;
namespace migration {
template <typename> struct SourceSpecBuilder;
struct StreamInterface;
template <typename ImageCtxT>
class RawSnapshot : public SnapshotInterface {
public:
static RawSnapshot* create(
ImageCtx* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder, uint64_t index) {
return new RawSnapshot(image_ctx, json_object, source_spec_builder, index);
}
RawSnapshot(ImageCtxT* image_ctx, const json_spirit::mObject& json_object,
const SourceSpecBuilder<ImageCtxT>* source_spec_builder,
uint64_t index);
RawSnapshot(const RawSnapshot&) = delete;
RawSnapshot& operator=(const RawSnapshot&) = delete;
void open(SnapshotInterface* previous_snapshot, Context* on_finish) override;
void close(Context* on_finish) override;
const SnapInfo& get_snap_info() const override {
return m_snap_info;
}
void read(io::AioCompletion* aio_comp, io::Extents&& image_extents,
io::ReadResult&& read_result, int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) override;
void list_snap(io::Extents&& image_extents, int list_snaps_flags,
io::SparseExtents* sparse_extents,
const ZTracer::Trace &parent_trace,
Context* on_finish) override;
private:
struct OpenRequest;
ImageCtxT* m_image_ctx;
json_spirit::mObject m_json_object;
const SourceSpecBuilder<ImageCtxT>* m_source_spec_builder;
uint64_t m_index = 0;
SnapInfo m_snap_info;
std::shared_ptr<StreamInterface> m_stream;
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::RawSnapshot<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_RAW_SNAPSHOT_H
| 2,256 | 28.697368 | 80 | h |
null | ceph-main/src/librbd/migration/S3Stream.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_S3_STREAM_H
#define CEPH_LIBRBD_MIGRATION_S3_STREAM_H
#include "include/int_types.h"
#include "librbd/migration/StreamInterface.h"
#include <boost/beast/http/empty_body.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/string_body.hpp>
#include <json_spirit/json_spirit.h>
#include <memory>
#include <string>
struct Context;
namespace librbd {
struct AsioEngine;
struct ImageCtx;
namespace migration {
template <typename> class HttpClient;
template <typename ImageCtxT>
class S3Stream : public StreamInterface {
public:
static S3Stream* create(ImageCtxT* image_ctx,
const json_spirit::mObject& json_object) {
return new S3Stream(image_ctx, json_object);
}
S3Stream(ImageCtxT* image_ctx, const json_spirit::mObject& json_object);
~S3Stream() override;
S3Stream(const S3Stream&) = delete;
S3Stream& operator=(const S3Stream&) = delete;
void open(Context* on_finish) override;
void close(Context* on_finish) override;
void get_size(uint64_t* size, Context* on_finish) override;
void read(io::Extents&& byte_extents, bufferlist* data,
Context* on_finish) override;
private:
using HttpRequest = boost::beast::http::request<
boost::beast::http::empty_body>;
using HttpResponse = boost::beast::http::response<
boost::beast::http::string_body>;
struct HttpProcessor;
ImageCtxT* m_image_ctx;
CephContext* m_cct;
std::shared_ptr<AsioEngine> m_asio_engine;
json_spirit::mObject m_json_object;
std::string m_url;
std::string m_access_key;
std::string m_secret_key;
std::unique_ptr<HttpProcessor> m_http_processor;
std::unique_ptr<HttpClient<ImageCtxT>> m_http_client;
void process_request(HttpRequest& http_request);
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::S3Stream<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_S3_STREAM_H
| 2,039 | 24.822785 | 74 | h |
null | ceph-main/src/librbd/migration/SnapshotInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_SNAPSHOT_INTERFACE_H
#define CEPH_LIBRBD_MIGRATION_SNAPSHOT_INTERFACE_H
#include "include/buffer_fwd.h"
#include "include/int_types.h"
#include "common/zipkin_trace.h"
#include "librbd/Types.h"
#include "librbd/io/Types.h"
#include <string>
struct Context;
namespace librbd {
namespace io {
struct AioCompletion;
struct ReadResult;
} // namespace io
namespace migration {
struct SnapshotInterface {
virtual ~SnapshotInterface() {
}
virtual void open(SnapshotInterface* previous_snapshot,
Context* on_finish) = 0;
virtual void close(Context* on_finish) = 0;
virtual const SnapInfo& get_snap_info() const = 0;
virtual void read(io::AioCompletion* aio_comp, io::Extents&& image_extents,
io::ReadResult&& read_result, int op_flags, int read_flags,
const ZTracer::Trace &parent_trace) = 0;
virtual void list_snap(io::Extents&& image_extents, int list_snaps_flags,
io::SparseExtents* sparse_extents,
const ZTracer::Trace &parent_trace,
Context* on_finish) = 0;
};
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_SNAPSHOT_INTERFACE_H
| 1,348 | 26.530612 | 79 | h |
null | ceph-main/src/librbd/migration/SourceSpecBuilder.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_SOURCE_SPEC_BUILDER_H
#define CEPH_LIBRBD_MIGRATION_SOURCE_SPEC_BUILDER_H
#include "include/int_types.h"
#include <json_spirit/json_spirit.h>
#include <memory>
#include <optional>
#include <string>
struct Context;
namespace librbd {
struct ImageCtx;
namespace migration {
struct FormatInterface;
struct SnapshotInterface;
struct StreamInterface;
template <typename ImageCtxT>
class SourceSpecBuilder {
public:
SourceSpecBuilder(ImageCtxT* image_ctx) : m_image_ctx(image_ctx) {
}
int parse_source_spec(const std::string& source_spec,
json_spirit::mObject* source_spec_object) const;
int build_format(const json_spirit::mObject& format_object, bool import_only,
std::unique_ptr<FormatInterface>* format) const;
int build_snapshot(const json_spirit::mObject& source_spec_object,
uint64_t index,
std::shared_ptr<SnapshotInterface>* snapshot) const;
int build_stream(const json_spirit::mObject& source_spec_object,
std::shared_ptr<StreamInterface>* stream) const;
private:
ImageCtxT* m_image_ctx;
};
} // namespace migration
} // namespace librbd
extern template class librbd::migration::SourceSpecBuilder<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIGRATION_SOURCE_SPEC_BUILDER_H
| 1,437 | 25.145455 | 79 | h |
null | ceph-main/src/librbd/migration/StreamInterface.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_STREAM_INTERFACE_H
#define CEPH_LIBRBD_MIGRATION_STREAM_INTERFACE_H
#include "include/buffer_fwd.h"
#include "include/int_types.h"
#include "librbd/io/Types.h"
struct Context;
namespace librbd {
namespace migration {
struct StreamInterface {
virtual ~StreamInterface() {
}
virtual void open(Context* on_finish) = 0;
virtual void close(Context* on_finish) = 0;
virtual void get_size(uint64_t* size, Context* on_finish) = 0;
virtual void read(io::Extents&& byte_extents, bufferlist* data,
Context* on_finish) = 0;
};
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_STREAM_INTERFACE_H
| 783 | 22.757576 | 70 | h |
null | ceph-main/src/librbd/migration/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_TYPES_H
#define CEPH_LIBRBD_MIGRATION_TYPES_H
#include <string>
#include <utility>
namespace librbd {
namespace migration {
enum UrlScheme {
URL_SCHEME_HTTP,
URL_SCHEME_HTTPS,
};
struct UrlSpec {
UrlSpec() {}
UrlSpec(UrlScheme scheme, const std::string& host, const std::string& port,
const std::string& path)
: scheme(scheme), host(host), port(port), path(path) {
}
UrlScheme scheme = URL_SCHEME_HTTP;
std::string host;
std::string port = "80";
std::string path = "/";
};
inline bool operator==(const UrlSpec& lhs, const UrlSpec& rhs) {
return (lhs.scheme == rhs.scheme &&
lhs.host == rhs.host &&
lhs.port == rhs.port &&
lhs.path == rhs.path);
}
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_TYPES_H
| 936 | 20.790698 | 77 | h |
null | ceph-main/src/librbd/migration/Utils.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIGRATION_UTILS_H
#define CEPH_LIBRBD_MIGRATION_UTILS_H
#include "include/common_fwd.h"
#include "librbd/io/Types.h"
#include "librbd/migration/Types.h"
#include <optional>
#include <string>
namespace librbd {
namespace migration {
namespace util {
int parse_url(CephContext* cct, const std::string& url, UrlSpec* url_spec);
void zero_shrunk_snapshot(CephContext* cct, const io::Extents& image_extents,
uint64_t snap_id, uint64_t new_size,
std::optional<uint64_t> *previous_size,
io::SparseExtents* sparse_extents);
void merge_snapshot_delta(const io::SnapIds& snap_ids,
io::SnapshotDelta* snapshot_delta);
} // namespace util
} // namespace migration
} // namespace librbd
#endif // CEPH_LIBRBD_MIGRATION_UTILS_H
| 943 | 29.451613 | 77 | h |
null | ceph-main/src/librbd/mirror/DisableRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_DISABLE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_DISABLE_REQUEST_H
#include "include/buffer.h"
#include "common/ceph_mutex.h"
#include "cls/journal/cls_journal_types.h"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/mirror/Types.h"
#include <map>
#include <string>
class Context;
namespace librbd {
class ImageCtx;
namespace mirror {
template <typename ImageCtxT = ImageCtx>
class DisableRequest {
public:
static DisableRequest *create(ImageCtxT *image_ctx, bool force,
bool remove, Context *on_finish) {
return new DisableRequest(image_ctx, force, remove, on_finish);
}
DisableRequest(ImageCtxT *image_ctx, bool force, bool remove,
Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_MIRROR_INFO * * * * * * * * * * * * * * * * * * * * * * *
* | *
* v *
* IMAGE_STATE_UPDATE * * * * * * * * * * * * * * * * * * * * * *
* | *
* v *
* PROMOTE_IMAGE (skip if primary) *
* | *
* v *
* REFRESH_IMAGE (skip if necessary) *
* | *
* v *
* GET_CLIENTS <----------------------------------------\ * * * *
* | | (unregister clients) | * (on error)
* | |/----------------------------\ | *
* | | | | *
* | | /-----------\ (repeat | (repeat | (repeat
* | | | | as needed) | as needed) | as needed)
* | v v | | | *
* | REMOVE_SYNC_SNAP --/ * * * * * * | * * * * * * | * * * *
* | | | | *
* | v | | *
* | UNREGISTER_CLIENT ---------------/-------------/ * * * *
* | *
* | (no more clients *
* | to unregister) *
* v *
* REMOVE_MIRROR_IMAGE * * * * * * * * * * * * * * * * * * * * *
* | (skip if no remove) *
* v *
* <finish> < * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
bool m_force;
bool m_remove;
Context *m_on_finish;
bool m_is_primary = false;
cls::rbd::MirrorImage m_mirror_image;
PromotionState m_promotion_state = PROMOTION_STATE_NON_PRIMARY;
std::string m_primary_mirror_uuid;
std::set<cls::journal::Client> m_clients;
std::map<std::string, int> m_ret;
std::map<std::string, int> m_current_ops;
int m_error_result = 0;
mutable ceph::mutex m_lock =
ceph::make_mutex("mirror::DisableRequest::m_lock");
void send_get_mirror_info();
Context *handle_get_mirror_info(int *result);
void send_image_state_update();
Context *handle_image_state_update(int *result);
void send_notify_mirroring_watcher();
Context *handle_notify_mirroring_watcher(int *result);
void send_promote_image();
Context *handle_promote_image(int *result);
void send_refresh_image();
Context* handle_refresh_image(int* result);
void clean_mirror_state();
void send_get_clients();
Context *handle_get_clients(int *result);
void remove_mirror_snapshots();
void send_remove_snap(const std::string &client_id,
const cls::rbd::SnapshotNamespace &snap_namespace,
const std::string &snap_name);
Context *handle_remove_snap(int *result, const std::string &client_id);
void send_unregister_client(const std::string &client_id);
Context *handle_unregister_client(int *result, const std::string &client_id);
void send_remove_mirror_image();
Context *handle_remove_mirror_image(int *result);
void send_notify_mirroring_watcher_removed();
Context *handle_notify_mirroring_watcher_removed(int *result);
Context *create_context_callback(
Context*(DisableRequest<ImageCtxT>::*handle)(
int*, const std::string &client_id),
const std::string &client_id);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::DisableRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_DISABLE_REQUEST_H
| 5,050 | 34.076389 | 79 | h |
null | ceph-main/src/librbd/mirror/EnableRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H
#include "include/buffer_fwd.h"
#include "include/rados/librados_fwd.hpp"
#include "include/rbd/librbd.hpp"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/ImageCtx.h"
#include "librbd/mirror/Types.h"
#include <map>
#include <string>
class Context;
namespace librbd {
namespace asio { struct ContextWQ; }
namespace mirror {
template <typename ImageCtxT = ImageCtx>
class EnableRequest {
public:
static EnableRequest *create(ImageCtxT *image_ctx,
cls::rbd::MirrorImageMode mode,
const std::string &non_primary_global_image_id,
bool image_clean, Context *on_finish) {
return new EnableRequest(image_ctx->md_ctx, image_ctx->id, image_ctx, mode,
non_primary_global_image_id, image_clean,
image_ctx->op_work_queue, on_finish);
}
static EnableRequest *create(librados::IoCtx &io_ctx,
const std::string &image_id,
cls::rbd::MirrorImageMode mode,
const std::string &non_primary_global_image_id,
bool image_clean, asio::ContextWQ *op_work_queue,
Context *on_finish) {
return new EnableRequest(io_ctx, image_id, nullptr, mode,
non_primary_global_image_id, image_clean,
op_work_queue, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_MIRROR_IMAGE * * * * * * *
* | * (on error)
* v (skip if not needed) *
* GET_TAG_OWNER * * * * * * * *
* | *
* v (skip if not needed) *
* OPEN_IMAGE *
* | *
* v (skip if not needed) *
* CREATE_PRIMARY_SNAPSHOT * * *
* | *
* v (skip of not opened) *
* CLOSE_IMAGE *
* | *
* v (skip if not needed) *
* ENABLE_NON_PRIMARY_FEATURE *
* | *
* v (skip if not needed) *
* IMAGE_STATE_UPDATE * * * * * *
* | *
* v *
* <finish> < * * * * * * * * *
*
* @endverbatim
*/
EnableRequest(librados::IoCtx &io_ctx, const std::string &image_id,
ImageCtxT* image_ctx, cls::rbd::MirrorImageMode mode,
const std::string &non_primary_global_image_id,
bool image_clean, asio::ContextWQ *op_work_queue,
Context *on_finish);
librados::IoCtx &m_io_ctx;
std::string m_image_id;
ImageCtxT* m_image_ctx;
cls::rbd::MirrorImageMode m_mode;
std::string m_non_primary_global_image_id;
bool m_image_clean;
asio::ContextWQ *m_op_work_queue;
Context *m_on_finish;
CephContext *m_cct = nullptr;
bufferlist m_out_bl;
cls::rbd::MirrorImage m_mirror_image;
int m_ret_val = 0;
bool m_close_image = false;
bool m_is_primary = false;
uint64_t m_snap_id = CEPH_NOSNAP;
void get_mirror_image();
void handle_get_mirror_image(int r);
void get_tag_owner();
void handle_get_tag_owner(int r);
void open_image();
void handle_open_image(int r);
void create_primary_snapshot();
void handle_create_primary_snapshot(int r);
void close_image();
void handle_close_image(int r);
void enable_non_primary_feature();
void handle_enable_non_primary_feature(int r);
void image_state_update();
void handle_image_state_update(int r);
void finish(int r);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::EnableRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H
| 4,018 | 28.551471 | 80 | h |
null | ceph-main/src/librbd/mirror/GetInfoRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H
#define CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H
#include "common/snap_types.h"
#include "include/buffer.h"
#include "include/common_fwd.h"
#include "include/rados/librados.hpp"
#include "librbd/Types.h"
#include "librbd/mirror/Types.h"
#include <string>
struct Context;
namespace cls { namespace rbd { struct MirrorImage; } }
namespace librbd {
struct ImageCtx;
namespace asio { struct ContextWQ; }
namespace mirror {
template <typename ImageCtxT = librbd::ImageCtx>
class GetInfoRequest {
public:
static GetInfoRequest *create(librados::IoCtx &io_ctx,
asio::ContextWQ *op_work_queue,
const std::string &image_id,
cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state,
std::string* primary_mirror_uuid,
Context *on_finish) {
return new GetInfoRequest(io_ctx, op_work_queue, image_id, mirror_image,
promotion_state, primary_mirror_uuid, on_finish);
}
static GetInfoRequest *create(ImageCtxT &image_ctx,
cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state,
std::string* primary_mirror_uuid,
Context *on_finish) {
return new GetInfoRequest(image_ctx, mirror_image, promotion_state,
primary_mirror_uuid, on_finish);
}
GetInfoRequest(librados::IoCtx& io_ctx, asio::ContextWQ *op_work_queue,
const std::string &image_id,
cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state,
std::string* primary_mirror_uuid, Context *on_finish);
GetInfoRequest(ImageCtxT &image_ctx, cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state,
std::string* primary_mirror_uuid, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_MIRROR_IMAGE
* |
* (journal /--------/ \--------\ (snapshot
* mode) | | mode)
* v v
* GET_JOURNAL_TAG_OWNER GET_SNAPCONTEXT (skip if
* | | cached)
* | v
* | GET_SNAPSHOTS (skip if
* | | cached)
* \--------\ /--------/
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx = nullptr;
librados::IoCtx &m_io_ctx;
asio::ContextWQ *m_op_work_queue;
std::string m_image_id;
cls::rbd::MirrorImage *m_mirror_image;
PromotionState *m_promotion_state;
std::string* m_primary_mirror_uuid;
Context *m_on_finish;
CephContext *m_cct;
bufferlist m_out_bl;
std::string m_mirror_uuid;
::SnapContext m_snapc;
void get_mirror_image();
void handle_get_mirror_image(int r);
void get_journal_tag_owner();
void handle_get_journal_tag_owner(int r);
void get_snapcontext();
void handle_get_snapcontext(int r);
void get_snapshots();
void handle_get_snapshots(int r);
void finish(int r);
void calc_promotion_state(
const std::map<librados::snap_t, SnapInfo> &snap_info);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::GetInfoRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_GET_INFO_REQUEST_H
| 3,844 | 30.008065 | 79 | h |
null | ceph-main/src/librbd/mirror/GetStatusRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_GET_STATUS_REQUEST_H
#define CEPH_LIBRBD_MIRROR_GET_STATUS_REQUEST_H
#include "include/buffer.h"
#include "librbd/mirror/Types.h"
#include <string>
struct Context;
namespace cls { namespace rbd { struct MirrorImage; } }
namespace cls { namespace rbd { struct MirrorImageStatus; } }
namespace librbd {
struct ImageCtx;
namespace mirror {
template <typename ImageCtxT = librbd::ImageCtx>
class GetStatusRequest {
public:
static GetStatusRequest *create(ImageCtxT &image_ctx,
cls::rbd::MirrorImageStatus *status,
cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state,
Context *on_finish) {
return new GetStatusRequest(image_ctx, status, mirror_image,
promotion_state, on_finish);
}
GetStatusRequest(ImageCtxT &image_ctx, cls::rbd::MirrorImageStatus *status,
cls::rbd::MirrorImage *mirror_image,
PromotionState *promotion_state, Context *on_finish)
: m_image_ctx(image_ctx), m_mirror_image_status(status),
m_mirror_image(mirror_image), m_promotion_state(promotion_state),
m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_INFO
* |
* v
* GET_STATUS
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT &m_image_ctx;
cls::rbd::MirrorImageStatus *m_mirror_image_status;
cls::rbd::MirrorImage *m_mirror_image;
PromotionState *m_promotion_state;
Context *m_on_finish;
bufferlist m_out_bl;
std::string m_primary_mirror_uuid;
void get_info();
void handle_get_info(int r);
void get_status();
void handle_get_status(int r);
void finish(int r);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::GetStatusRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_GET_STATUS_REQUEST_H
| 2,124 | 23.425287 | 77 | h |
null | ceph-main/src/librbd/mirror/ImageRemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_IMAGE_REMOVE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_IMAGE_REMOVE_REQUEST_H
#include "include/rados/librados.hpp"
#include "common/ceph_mutex.h"
#include "cls/rbd/cls_rbd_types.h"
#include <string>
class Context;
namespace librbd {
class ImageCtx;
namespace mirror {
template <typename ImageCtxT = ImageCtx>
class ImageRemoveRequest {
public:
static ImageRemoveRequest *create(librados::IoCtx& io_ctx,
const std::string& global_image_id,
const std::string& image_id,
Context* on_finish) {
return new ImageRemoveRequest(io_ctx, global_image_id, image_id, on_finish);
}
ImageRemoveRequest(librados::IoCtx& io_ctx,
const std::string& global_image_id,
const std::string& image_id,
Context* on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* REMOVE_MIRROR_IMAGE
* |
* v
* NOTIFY_MIRRORING_WATCHER
* |
* v
* <finish>
*
* @endverbatim
*/
librados::IoCtx& m_io_ctx;
std::string m_global_image_id;
std::string m_image_id;
Context* m_on_finish;
CephContext* m_cct;
void remove_mirror_image();
void handle_remove_mirror_image(int r);
void notify_mirroring_watcher();
void handle_notify_mirroring_watcher(int r);
void finish(int r);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::ImageRemoveRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_IMAGE_REMOVE_REQUEST_H
| 1,717 | 21.025641 | 80 | h |
null | ceph-main/src/librbd/mirror/ImageStateUpdateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_IMAGE_STATE_UPDATE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_IMAGE_STATE_UPDATE_REQUEST_H
#include "include/rados/librados.hpp"
#include "common/ceph_mutex.h"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/mirror/Types.h"
#include <string>
class Context;
namespace librbd {
class ImageCtx;
namespace mirror {
template <typename ImageCtxT = ImageCtx>
class ImageStateUpdateRequest {
public:
static ImageStateUpdateRequest *create(
librados::IoCtx& io_ctx,
const std::string& image_id,
cls::rbd::MirrorImageState mirror_image_state,
const cls::rbd::MirrorImage& mirror_image,
Context* on_finish) {
return new ImageStateUpdateRequest(
io_ctx, image_id, mirror_image_state, mirror_image, on_finish);
}
ImageStateUpdateRequest(
librados::IoCtx& io_ctx,
const std::string& image_id,
cls::rbd::MirrorImageState mirror_image_state,
const cls::rbd::MirrorImage& mirror_image,
Context* on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v (skip if provided)
* GET_MIRROR_IMAGE
* |
* v
* SET_MIRROR_IMAGE
* |
* v
* NOTIFY_MIRRORING_WATCHER
* |
* v
* <finish>
*
* @endverbatim
*/
librados::IoCtx& m_io_ctx;
std::string m_image_id;
cls::rbd::MirrorImageState m_mirror_image_state;
cls::rbd::MirrorImage m_mirror_image;
Context* m_on_finish;
CephContext* m_cct;
bufferlist m_out_bl;
void get_mirror_image();
void handle_get_mirror_image(int r);
void set_mirror_image();
void handle_set_mirror_image(int r);
void notify_mirroring_watcher();
void handle_notify_mirroring_watcher(int r);
void finish(int r);
};
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::ImageStateUpdateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_IMAGE_STATE_UPDATE_REQUEST_H
| 2,026 | 20.795699 | 80 | h |
null | ceph-main/src/librbd/mirror/snapshot/CreateNonPrimaryRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H
#include "include/buffer.h"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/Types.h"
#include "librbd/internal.h"
#include "librbd/mirror/snapshot/Types.h"
#include <string>
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class CreateNonPrimaryRequest {
public:
static CreateNonPrimaryRequest *create(ImageCtxT *image_ctx,
bool demoted,
const std::string &primary_mirror_uuid,
uint64_t primary_snap_id,
const SnapSeqs& snap_seqs,
const ImageState &image_state,
uint64_t *snap_id,
Context *on_finish) {
return new CreateNonPrimaryRequest(image_ctx, demoted, primary_mirror_uuid,
primary_snap_id, snap_seqs, image_state,
snap_id, on_finish);
}
CreateNonPrimaryRequest(ImageCtxT *image_ctx,
bool demoted,
const std::string &primary_mirror_uuid,
uint64_t primary_snap_id,
const SnapSeqs& snap_seqs,
const ImageState &image_state, uint64_t *snap_id,
Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* REFRESH_IMAGE
* |
* v
* GET_MIRROR_IMAGE
* |
* v (skip if not needed)
* GET_MIRROR_PEERS
* |
* v
* CREATE_SNAPSHOT
* |
* v
* WRITE_IMAGE_STATE
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
bool m_demoted;
std::string m_primary_mirror_uuid;
uint64_t m_primary_snap_id;
SnapSeqs m_snap_seqs;
ImageState m_image_state;
uint64_t *m_snap_id;
Context *m_on_finish;
librados::IoCtx m_default_ns_ctx;
std::set<std::string> m_mirror_peer_uuids;
std::string m_snap_name;
bufferlist m_out_bl;
NoOpProgressContext m_prog_ctx;
bool is_orphan() const {
return m_primary_mirror_uuid.empty();
}
void refresh_image();
void handle_refresh_image(int r);
void get_mirror_image();
void handle_get_mirror_image(int r);
void get_mirror_peers();
void handle_get_mirror_peers(int r);
void create_snapshot();
void handle_create_snapshot(int r);
void write_image_state();
void handle_write_image_state(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::CreateNonPrimaryRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H
| 3,139 | 24.322581 | 90 | h |
null | ceph-main/src/librbd/mirror/snapshot/CreatePrimaryRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/internal.h"
#include "librbd/mirror/snapshot/Types.h"
#include <string>
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class CreatePrimaryRequest {
public:
static CreatePrimaryRequest *create(ImageCtxT *image_ctx,
const std::string& global_image_id,
uint64_t clean_since_snap_id,
uint64_t snap_create_flags,
uint32_t flags, uint64_t *snap_id,
Context *on_finish) {
return new CreatePrimaryRequest(image_ctx, global_image_id,
clean_since_snap_id, snap_create_flags, flags,
snap_id, on_finish);
}
CreatePrimaryRequest(ImageCtxT *image_ctx,
const std::string& global_image_id,
uint64_t clean_since_snap_id, uint64_t snap_create_flags,
uint32_t flags, uint64_t *snap_id, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_MIRROR_PEERS
* |
* v
* CREATE_SNAPSHOT
* |
* v
* REFRESH_IMAGE
* |
* v
* UNLINK_PEER (skip if not needed,
* | repeat if needed)
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
std::string m_global_image_id;
uint64_t m_clean_since_snap_id;
const uint64_t m_snap_create_flags;
const uint32_t m_flags;
uint64_t *m_snap_id;
Context *m_on_finish;
librados::IoCtx m_default_ns_ctx;
std::set<std::string> m_mirror_peer_uuids;
std::string m_snap_name;
bufferlist m_out_bl;
NoOpProgressContext m_prog_ctx;
void get_mirror_peers();
void handle_get_mirror_peers(int r);
void create_snapshot();
void handle_create_snapshot(int r);
void refresh_image();
void handle_refresh_image(int r);
void unlink_peer();
void handle_unlink_peer(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::CreatePrimaryRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
| 2,689 | 24.140187 | 87 | h |
null | ceph-main/src/librbd/mirror/snapshot/GetImageStateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_GET_IMAGE_STATE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_GET_IMAGE_STATE_REQUEST_H
#include "include/buffer.h"
#include "include/types.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
struct ImageState;
template <typename ImageCtxT = librbd::ImageCtx>
class GetImageStateRequest {
public:
static GetImageStateRequest *create(ImageCtxT *image_ctx, uint64_t snap_id,
ImageState *image_state,
Context *on_finish) {
return new GetImageStateRequest(image_ctx, snap_id, image_state, on_finish);
}
GetImageStateRequest(ImageCtxT *image_ctx, uint64_t snap_id,
ImageState *image_state, Context *on_finish)
: m_image_ctx(image_ctx), m_snap_id(snap_id), m_image_state(image_state),
m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* READ_OBJECT (repeat for
* | every object)
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
uint64_t m_snap_id;
ImageState *m_image_state;
Context *m_on_finish;
bufferlist m_bl;
bufferlist m_state_bl;
size_t m_object_count = 0;
size_t m_object_index = 0;
void read_object();
void handle_read_object(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::GetImageStateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_GET_IMAGE_STATE_REQUEST_H
| 1,724 | 21.402597 | 87 | h |
null | ceph-main/src/librbd/mirror/snapshot/PromoteRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
#include "include/buffer.h"
#include "include/rbd/librbd.hpp"
#include "common/ceph_mutex.h"
#include "common/Timer.h"
#include "librbd/internal.h"
#include <string>
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class PromoteRequest {
public:
static PromoteRequest *create(ImageCtxT *image_ctx,
const std::string& global_image_id,
Context *on_finish) {
return new PromoteRequest(image_ctx, global_image_id, on_finish);
}
PromoteRequest(ImageCtxT *image_ctx, const std::string& global_image_id,
Context *on_finish)
: m_image_ctx(image_ctx), m_global_image_id(global_image_id),
m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* | (can promote)
* |\----------------------------------------\
* | |
* | |
* v (skip if not needed) |
* CREATE_ORPHAN_SNAPSHOT |
* | |
* | /-- UNREGISTER_UPDATE_WATCHER <-\ |
* v v | |
* LIST_WATCHERS ----> WAIT_UPDATE_NOTIFY --/ |
* | |
* | (no watchers) |
* v |
* ACQUIRE_EXCLUSIVE_LOCK |
* | (skip if not needed) |
* v |
* ROLLBACK |
* | |
* v |
* CREATE_PROMOTE_SNAPSHOT <--------------------/
* |
* v
* DISABLE_NON_PRIMARY_FEATURE
* |
* v
* RELEASE_EXCLUSIVE_LOCK (skip if not needed)
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
std::string m_global_image_id;
Context *m_on_finish;
uint64_t m_rollback_snap_id = CEPH_NOSNAP;
bool m_lock_acquired = false;
NoOpProgressContext m_progress_ctx;
class UpdateWatchCtx : public librbd::UpdateWatchCtx {
public:
UpdateWatchCtx(PromoteRequest *promote_request)
: promote_request(promote_request) {
}
void handle_notify() {
promote_request->handle_update_notify();
}
private:
PromoteRequest *promote_request;
} m_update_watch_ctx = {this};
std::list<obj_watch_t> m_watchers;
uint64_t m_update_watcher_handle = 0;
uint64_t m_scheduler_ticks = 0;
SafeTimer *m_timer = nullptr;
ceph::mutex *m_timer_lock = nullptr;
void refresh_image();
void handle_refresh_image(int r);
void create_orphan_snapshot();
void handle_create_orphan_snapshot(int r);
void list_watchers();
void handle_list_watchers(int r);
void wait_update_notify();
void handle_update_notify();
void scheduler_unregister_update_watcher();
void unregister_update_watcher();
void handle_unregister_update_watcher(int r);
void acquire_exclusive_lock();
void handle_acquire_exclusive_lock(int r);
void rollback();
void handle_rollback(int r);
void create_promote_snapshot();
void handle_create_promote_snapshot(int r);
void disable_non_primary_feature();
void handle_disable_non_primary_feature(int r);
void release_exclusive_lock();
void handle_release_exclusive_lock(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::PromoteRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_PROMOTE_REQUEST_H
| 4,036 | 25.559211 | 81 | h |
null | ceph-main/src/librbd/mirror/snapshot/RemoveImageStateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_REMOVE_IMAGE_STATE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_REMOVE_IMAGE_STATE_REQUEST_H
#include "include/buffer.h"
#include "include/types.h"
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class RemoveImageStateRequest {
public:
static RemoveImageStateRequest *create(ImageCtxT *image_ctx, uint64_t snap_id,
Context *on_finish) {
return new RemoveImageStateRequest(image_ctx, snap_id, on_finish);
}
RemoveImageStateRequest(ImageCtxT *image_ctx, uint64_t snap_id,
Context *on_finish)
: m_image_ctx(image_ctx), m_snap_id(snap_id), m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_OBJECT_COUNT
* |
* v
* REMOVE_OBJECT (repeat for
* | every object)
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
uint64_t m_snap_id;
Context *m_on_finish;
bufferlist m_bl;
size_t m_object_count = 0;
void get_object_count();
void handle_get_object_count(int r);
void remove_object();
void handle_remove_object(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::RemoveImageStateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_REMOVE_IMAGE_STATE_REQUEST_H
| 1,635 | 20.526316 | 90 | h |
null | ceph-main/src/librbd/mirror/snapshot/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_TYPES_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_TYPES_H
#include "cls/rbd/cls_rbd_types.h"
#include "include/buffer.h"
#include "include/types.h"
#include <map>
#include <string>
namespace librbd {
namespace mirror {
namespace snapshot {
enum CreatePrimaryFlags {
CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS = (1 << 0),
CREATE_PRIMARY_FLAG_DEMOTED = (1 << 1),
CREATE_PRIMARY_FLAG_FORCE = (1 << 2)
};
struct ImageStateHeader {
uint32_t object_count = 0;
ImageStateHeader() {
}
ImageStateHeader(uint32_t object_count) : object_count(object_count) {
}
void encode(bufferlist &bl) const;
void decode(bufferlist::const_iterator &it);
};
WRITE_CLASS_ENCODER(ImageStateHeader);
struct SnapState {
cls::rbd::SnapshotNamespace snap_namespace;
std::string name;
uint8_t protection_status = 0;
SnapState() {
}
SnapState(const cls::rbd::SnapshotNamespace &snap_namespace,
const std::string &name, uint8_t protection_status)
: snap_namespace(snap_namespace), name(name),
protection_status(protection_status) {
}
bool operator==(const SnapState& rhs) const {
return snap_namespace == rhs.snap_namespace &&
name == rhs.name && protection_status == rhs.protection_status;
}
bool operator<(const SnapState& rhs) const {
if (snap_namespace != rhs.snap_namespace) {
return snap_namespace < rhs.snap_namespace;
}
if (name != rhs.name) {
return name < rhs.name;
}
return protection_status < rhs.protection_status;
}
void encode(bufferlist &bl) const;
void decode(bufferlist::const_iterator &it);
void dump(Formatter *f) const;
};
std::ostream& operator<<(std::ostream& os, const SnapState& snap_state);
WRITE_CLASS_ENCODER(SnapState);
struct ImageState {
std::string name;
uint64_t features = 0;
uint64_t snap_limit = 0;
std::map<uint64_t, SnapState> snapshots;
std::map<std::string, bufferlist> metadata;
ImageState() {
}
ImageState(const std::string &name, uint64_t features, uint64_t snap_limit,
const std::map<uint64_t, SnapState> &snapshots,
const std::map<std::string, bufferlist> &metadata)
: name(name), features(features), snap_limit(snap_limit),
snapshots(snapshots), metadata(metadata) {
}
bool operator==(const ImageState& rhs) const {
return name == rhs.name && features == rhs.features &&
snap_limit == rhs.snap_limit && snapshots == rhs.snapshots;
}
bool operator<(const ImageState& rhs) const {
if (name != rhs.name) {
return name < rhs.name;
}
if (features != rhs.features) {
return features < rhs.features;
}
if (snap_limit != rhs.snap_limit) {
return snap_limit < rhs.snap_limit;
}
return snapshots < rhs.snapshots;
}
void encode(bufferlist &bl) const;
void decode(bufferlist::const_iterator &it);
void dump(Formatter *f) const;
};
std::ostream& operator<<(std::ostream& os, const ImageState& image_state);
WRITE_CLASS_ENCODER(ImageState);
} // namespace snapshot
} // namespace mirror
} // namespace librbd
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_TYPES_H
| 3,272 | 25.609756 | 77 | h |
null | ceph-main/src/librbd/mirror/snapshot/UnlinkPeerRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_UNLINK_PEER_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_UNLINK_PEER_REQUEST_H
#include "include/buffer.h"
#include "cls/rbd/cls_rbd_client.h"
#include <string>
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class UnlinkPeerRequest {
public:
static UnlinkPeerRequest *create(ImageCtxT *image_ctx, uint64_t snap_id,
const std::string &mirror_peer_uuid,
bool allow_remove, Context *on_finish) {
return new UnlinkPeerRequest(image_ctx, snap_id, mirror_peer_uuid,
allow_remove, on_finish);
}
UnlinkPeerRequest(ImageCtxT *image_ctx, uint64_t snap_id,
const std::string &mirror_peer_uuid, bool allow_remove,
Context *on_finish)
: m_image_ctx(image_ctx), m_snap_id(snap_id),
m_mirror_peer_uuid(mirror_peer_uuid), m_allow_remove(allow_remove),
m_on_finish(on_finish) {
}
void send();
private:
/*
* @verbatim
*
* <start>
* |
* v
* REFRESH_IMAGE <--------------------------\
* | ^ (not found |
* | * or last) |
* | * |
* |\---------------> UNLINK_PEER --> NOTIFY_UPDATE
* | (not last peer or
* | no newer mirror
* | snap exists)
* |
* |\---------------> REMOVE_SNAPSHOT
* | (last peer and |
* | newer mirror |
* | snap exists) |
* | |
* |(peer not found) |
* v |
* <finish> <---------------/
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
uint64_t m_snap_id;
std::string m_mirror_peer_uuid;
bool m_allow_remove;
Context *m_on_finish;
void refresh_image();
void handle_refresh_image(int r);
void unlink_peer();
void handle_unlink_peer(int r);
void notify_update();
void handle_notify_update(int r);
void remove_snapshot(const cls::rbd::SnapshotNamespace& snap_namespace,
const std::string& snap_name);
void handle_remove_snapshot(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::UnlinkPeerRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_UNLINK_PEER_REQUEST_H
| 2,629 | 25.565657 | 84 | h |
null | ceph-main/src/librbd/mirror/snapshot/Utils.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_UTILS_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_UTILS_H
#include "include/int_types.h"
#include "include/stringify.h"
#include <string>
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
namespace util {
std::string get_image_meta_key(const std::string& mirror_uuid);
template <typename ImageCtxT = librbd::ImageCtx>
bool can_create_primary_snapshot(ImageCtxT *image_ctx, bool demoted, bool force,
bool* requires_orphan,
uint64_t *rollback_snap_id);
template <typename ImageCtxT = librbd::ImageCtx>
bool can_create_non_primary_snapshot(ImageCtxT *image_ctx);
template <typename ImageCtxT = librbd::ImageCtx>
std::string image_state_object_name(ImageCtxT *image_ctx, uint64_t snap_id,
uint64_t index);
} // namespace util
} // namespace snapshot
} // namespace mirror
} // namespace librbd
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_UTILS_H
| 1,103 | 27.307692 | 80 | h |
null | ceph-main/src/librbd/mirror/snapshot/WriteImageStateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRROR_SNAPSHOT_WRITE_IMAGE_STATE_REQUEST_H
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_WRITE_IMAGE_STATE_REQUEST_H
#include "librbd/mirror/snapshot/Types.h"
#include <map>
#include <string>
struct Context;
namespace librbd {
struct ImageCtx;
namespace mirror {
namespace snapshot {
template <typename ImageCtxT = librbd::ImageCtx>
class WriteImageStateRequest {
public:
static WriteImageStateRequest *create(ImageCtxT *image_ctx, uint64_t snap_id,
const ImageState &image_state,
Context *on_finish) {
return new WriteImageStateRequest(image_ctx, snap_id, image_state,
on_finish);
}
WriteImageStateRequest(ImageCtxT *image_ctx, uint64_t snap_id,
const ImageState &image_state, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start>
* |
* v
* WRITE_OBJECT (repeat for
* | every object)
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT *m_image_ctx;
uint64_t m_snap_id;
ImageState m_image_state;
Context *m_on_finish;
bufferlist m_bl;
const size_t m_object_size;
size_t m_object_count = 0;
void write_object();
void handle_write_object(int r);
void finish(int r);
};
} // namespace snapshot
} // namespace mirror
} // namespace librbd
extern template class librbd::mirror::snapshot::WriteImageStateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_WRITE_IMAGE_STATE_REQUEST_H
| 1,664 | 21.5 | 89 | h |
null | ceph-main/src/librbd/mirroring_watcher/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_MIRRORING_WATCHER_TYPES_H
#define CEPH_LIBRBD_MIRRORING_WATCHER_TYPES_H
#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/encoding.h"
#include "cls/rbd/cls_rbd_types.h"
#include <iosfwd>
#include <list>
#include <string>
#include <boost/variant.hpp>
namespace ceph { class Formatter; }
namespace librbd {
namespace mirroring_watcher {
enum NotifyOp {
NOTIFY_OP_MODE_UPDATED = 0,
NOTIFY_OP_IMAGE_UPDATED = 1
};
struct ModeUpdatedPayload {
static const NotifyOp NOTIFY_OP = NOTIFY_OP_MODE_UPDATED;
cls::rbd::MirrorMode mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
ModeUpdatedPayload() {
}
ModeUpdatedPayload(cls::rbd::MirrorMode mirror_mode)
: mirror_mode(mirror_mode) {
}
void encode(bufferlist &bl) const;
void decode(__u8 version, bufferlist::const_iterator &iter);
void dump(Formatter *f) const;
};
struct ImageUpdatedPayload {
static const NotifyOp NOTIFY_OP = NOTIFY_OP_IMAGE_UPDATED;
cls::rbd::MirrorImageState mirror_image_state =
cls::rbd::MIRROR_IMAGE_STATE_ENABLED;
std::string image_id;
std::string global_image_id;
ImageUpdatedPayload() {
}
ImageUpdatedPayload(cls::rbd::MirrorImageState mirror_image_state,
const std::string &image_id,
const std::string &global_image_id)
: mirror_image_state(mirror_image_state), image_id(image_id),
global_image_id(global_image_id) {
}
void encode(bufferlist &bl) const;
void decode(__u8 version, bufferlist::const_iterator &iter);
void dump(Formatter *f) const;
};
struct UnknownPayload {
static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1);
UnknownPayload() {
}
void encode(bufferlist &bl) const;
void decode(__u8 version, bufferlist::const_iterator &iter);
void dump(Formatter *f) const;
};
typedef boost::variant<ModeUpdatedPayload,
ImageUpdatedPayload,
UnknownPayload> Payload;
struct NotifyMessage {
NotifyMessage(const Payload &payload = UnknownPayload()) : payload(payload) {
}
Payload payload;
void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& it);
void dump(Formatter *f) const;
static void generate_test_instances(std::list<NotifyMessage *> &o);
};
WRITE_CLASS_ENCODER(NotifyMessage);
std::ostream &operator<<(std::ostream &out, const NotifyOp &op);
} // namespace mirroring_watcher
} // namespace librbd
using librbd::mirroring_watcher::encode;
using librbd::mirroring_watcher::decode;
#endif // CEPH_LIBRBD_MIRRORING_WATCHER_TYPES_H
| 2,681 | 25.038835 | 79 | h |
null | ceph-main/src/librbd/object_map/DiffRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_DIFF_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_DIFF_REQUEST_H
#include "include/int_types.h"
#include "common/bit_vector.hpp"
#include "common/ceph_mutex.h"
#include "librbd/object_map/Types.h"
#include <set>
struct Context;
namespace librbd {
struct ImageCtx;
namespace object_map {
template <typename ImageCtxT>
class DiffRequest {
public:
static DiffRequest* create(ImageCtxT* image_ctx, uint64_t snap_id_start,
uint64_t snap_id_end,
BitVector<2>* object_diff_state,
Context* on_finish) {
return new DiffRequest(image_ctx, snap_id_start, snap_id_end,
object_diff_state, on_finish);
}
DiffRequest(ImageCtxT* image_ctx, uint64_t snap_id_start,
uint64_t snap_id_end, BitVector<2>* object_diff_state,
Context* on_finish)
: m_image_ctx(image_ctx), m_snap_id_start(snap_id_start),
m_snap_id_end(snap_id_end), m_object_diff_state(object_diff_state),
m_on_finish(on_finish) {
}
void send();
private:
/**
* @verbatim
*
* <start>
* |
* | /---------\
* | | |
* v v |
* LOAD_OBJECT_MAP ---/
* |
* v
* <finish>
*
* @endverbatim
*/
ImageCtxT* m_image_ctx;
uint64_t m_snap_id_start;
uint64_t m_snap_id_end;
BitVector<2>* m_object_diff_state;
Context* m_on_finish;
std::set<uint64_t> m_snap_ids;
uint64_t m_current_snap_id = 0;
bool m_ignore_enoent = false;
uint64_t m_current_size = 0;
BitVector<2> m_object_map;
bool m_object_diff_state_valid = false;
bufferlist m_out_bl;
void load_object_map(std::shared_lock<ceph::shared_mutex>* image_locker);
void handle_load_object_map(int r);
void finish(int r);
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::DiffRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_DIFF_REQUEST_H
| 2,104 | 22.920455 | 75 | h |
null | ceph-main/src/librbd/object_map/InvalidateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_INVALIDATE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_INVALIDATE_REQUEST_H
#include "include/int_types.h"
#include "librbd/AsyncRequest.h"
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
template <typename ImageCtxT = ImageCtx>
class InvalidateRequest : public AsyncRequest<ImageCtxT> {
public:
static InvalidateRequest* create(ImageCtxT &image_ctx, uint64_t snap_id,
bool force, Context *on_finish);
InvalidateRequest(ImageCtxT &image_ctx, uint64_t snap_id, bool force,
Context *on_finish)
: AsyncRequest<ImageCtxT>(image_ctx, on_finish),
m_snap_id(snap_id), m_force(force) {
}
void send() override;
protected:
bool should_complete(int r) override;
private:
uint64_t m_snap_id;
bool m_force;
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::InvalidateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_INVALIDATE_REQUEST_H
| 1,122 | 23.413043 | 78 | h |
null | ceph-main/src/librbd/object_map/LockRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H
#include "include/buffer.h"
#include "cls/lock/cls_lock_types.h"
#include <map>
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
template <typename ImageCtxT = ImageCtx>
class LockRequest {
public:
static LockRequest* create(ImageCtxT &image_ctx, Context *on_finish) {
return new LockRequest(image_ctx, on_finish);
}
LockRequest(ImageCtxT &image_ctx, Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start> /------------------------------------- BREAK_LOCKS * * *
* | | ^ *
* | | | *
* | | | *
* | v (EBUSY && !broke_lock) | *
* \---------> LOCK_OBJECT_MAP * * * * * * * * * * * > GET_LOCK_INFO * *
* | * ^ * *
* | * * * *
* | * * (ENOENT) * *
* | * * * * * * * * * * * * * * * * * *
* | * *
* | * (other errors) *
* | * *
* v v (other errors) *
* <finish> < * * * * * * * * * * * * * * * * * * * * * * * *
*
* @endverbatim
*/
ImageCtxT &m_image_ctx;
Context *m_on_finish;
bool m_broke_lock;
std::map<rados::cls::lock::locker_id_t,
rados::cls::lock::locker_info_t> m_lockers;
bufferlist m_out_bl;
void send_lock();
Context *handle_lock(int *ret_val);
void send_get_lock_info();
Context *handle_get_lock_info(int *ret_val);
void send_break_locks();
Context *handle_break_locks(int *ret_val);
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::LockRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H
| 2,431 | 31 | 77 | h |
null | ceph-main/src/librbd/object_map/RefreshRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/bit_vector.hpp"
#include "common/ceph_mutex.h"
class Context;
class RWLock;
namespace librbd {
class ImageCtx;
namespace object_map {
template <typename ImageCtxT = ImageCtx>
class RefreshRequest {
public:
static RefreshRequest *create(ImageCtxT &image_ctx,
ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map,
uint64_t snap_id, Context *on_finish) {
return new RefreshRequest(image_ctx, object_map_lock, object_map, snap_id,
on_finish);
}
RefreshRequest(ImageCtxT &image_ctx, ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map, uint64_t snap_id,
Context *on_finish);
void send();
private:
/**
* @verbatim
*
* <start> -----> LOCK (skip if snapshot)
* * |
* * v (other errors)
* * LOAD * * * * * * * > INVALIDATE ------------\
* * | * |
* * | * (-EINVAL or too small) |
* * | * * * * * * > INVALIDATE_AND_RESIZE |
* * | | * |
* * | | * |
* * | v * |
* * | RESIZE * |
* * | | * |
* * | | * * * * * * * |
* * | | * |
* * | v v |
* * \--------------------> LOCK <-------------/
* * |
* v v
* INVALIDATE_AND_CLOSE ---------------> <finish>
*
* @endverbatim
*/
ImageCtxT &m_image_ctx;
ceph::shared_mutex* m_object_map_lock;
ceph::BitVector<2> *m_object_map;
uint64_t m_snap_id;
Context *m_on_finish;
uint64_t m_object_count;
ceph::BitVector<2> m_on_disk_object_map;
bool m_truncate_on_disk_object_map;
bufferlist m_out_bl;
void send_lock();
Context *handle_lock(int *ret_val);
void send_load();
Context *handle_load(int *ret_val);
void send_invalidate();
Context *handle_invalidate(int *ret_val);
void send_resize_invalidate();
Context *handle_resize_invalidate(int *ret_val);
void send_resize();
Context *handle_resize(int *ret_val);
void send_invalidate_and_close();
Context *handle_invalidate_and_close(int *ret_val);
void apply();
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::RefreshRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H
| 3,126 | 29.359223 | 78 | h |
null | ceph-main/src/librbd/object_map/RemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_REMOVE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_REMOVE_REQUEST_H
#include "include/buffer.h"
#include "common/ceph_mutex.h"
#include <map>
#include <string>
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
template <typename ImageCtxT = ImageCtx>
class RemoveRequest {
public:
static RemoveRequest *create(ImageCtxT *image_ctx, Context *on_finish) {
return new RemoveRequest(image_ctx, on_finish);
}
void send();
private:
/**
* @verbatim
*
* <start>
* | . . .
* v v .
* REMOVE_OBJECT_MAP . (for every snapshot)
* | . .
* v . . .
* <finis>
*
* @endverbatim
*/
RemoveRequest(ImageCtxT *image_ctx, Context *on_finish);
ImageCtxT *m_image_ctx;
Context *m_on_finish;
int m_error_result = 0;
int m_ref_counter = 0;
mutable ceph::mutex m_lock =
ceph::make_mutex("object_map::RemoveRequest::m_lock");
void send_remove_object_map();
Context *handle_remove_object_map(int *result);
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::RemoveRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_REMOVE_REQUEST_H
| 1,347 | 20.0625 | 74 | h |
null | ceph-main/src/librbd/object_map/ResizeRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_RESIZE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_RESIZE_REQUEST_H
#include "include/int_types.h"
#include "librbd/object_map/Request.h"
#include "common/bit_vector.hpp"
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
class ResizeRequest : public Request {
public:
ResizeRequest(ImageCtx &image_ctx, ceph::shared_mutex *object_map_lock,
ceph::BitVector<2> *object_map, uint64_t snap_id,
uint64_t new_size, uint8_t default_object_state,
Context *on_finish)
: Request(image_ctx, snap_id, on_finish),
m_object_map_lock(object_map_lock), m_object_map(object_map),
m_num_objs(0), m_new_size(new_size),
m_default_object_state(default_object_state)
{
}
static void resize(ceph::BitVector<2> *object_map, uint64_t num_objs,
uint8_t default_state);
void send() override;
protected:
void finish_request() override;
private:
ceph::shared_mutex* m_object_map_lock;
ceph::BitVector<2> *m_object_map;
uint64_t m_num_objs;
uint64_t m_new_size;
uint8_t m_default_object_state;
};
} // namespace object_map
} // namespace librbd
#endif // CEPH_LIBRBD_OBJECT_MAP_RESIZE_REQUEST_H
| 1,340 | 24.788462 | 73 | h |
null | ceph-main/src/librbd/object_map/SnapshotCreateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_CREATE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_CREATE_REQUEST_H
#include "include/int_types.h"
#include "common/bit_vector.hpp"
#include "librbd/object_map/Request.h"
class Context;
class RWLock;
namespace librbd {
class ImageCtx;
namespace object_map {
class SnapshotCreateRequest : public Request {
public:
/**
* Snapshot create goes through the following state machine:
*
* @verbatim
*
* <start>
* |
* v
* STATE_READ_MAP
* |
* v (skip)
* STATE_WRITE_MAP . . . . . . .
* | .
* v v
* STATE_ADD_SNAPSHOT ---> <finish>
*
* @endverbatim
*
* The _ADD_SNAPSHOT state is skipped if the FAST_DIFF feature isn't enabled.
*/
enum State {
STATE_READ_MAP,
STATE_WRITE_MAP,
STATE_ADD_SNAPSHOT
};
SnapshotCreateRequest(ImageCtx &image_ctx, ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map, uint64_t snap_id,
Context *on_finish)
: Request(image_ctx, snap_id, on_finish),
m_object_map_lock(object_map_lock), m_object_map(*object_map),
m_ret_val(0) {
}
void send() override;
protected:
bool should_complete(int r) override;
private:
ceph::shared_mutex* m_object_map_lock;
ceph::BitVector<2> &m_object_map;
State m_state = STATE_READ_MAP;
bufferlist m_read_bl;
int m_ret_val;
void send_read_map();
void send_write_map();
bool send_add_snapshot();
void update_object_map();
};
} // namespace object_map
} // namespace librbd
#endif // CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_CREATE_REQUEST_H
| 1,791 | 21.123457 | 81 | h |
null | ceph-main/src/librbd/object_map/SnapshotRemoveRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H
#include "include/int_types.h"
#include "include/buffer.h"
#include "common/bit_vector.hpp"
#include "librbd/AsyncRequest.h"
namespace librbd {
namespace object_map {
class SnapshotRemoveRequest : public AsyncRequest<> {
public:
/**
* Snapshot rollback goes through the following state machine:
*
* @verbatim
*
* <start> -----------> STATE_LOAD_MAP ----\
* . * |
* . * (error) |
* . (invalid object map) v |
* . . . > STATE_INVALIDATE_NEXT_MAP |
* . | |
* . | |
* . (fast diff disabled) v v
* . . . . . . . . . . > STATE_REMOVE_MAP
* |
* v
* <finish>
*
* @endverbatim
*
* The _LOAD_MAP state is skipped if the fast diff feature is disabled.
* If the fast diff feature is enabled and the snapshot is flagged as
* invalid, the next snapshot / HEAD object mapis flagged as invalid;
* otherwise, the state machine proceeds to remove the object map.
*/
SnapshotRemoveRequest(ImageCtx &image_ctx, ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map, uint64_t snap_id,
Context *on_finish)
: AsyncRequest(image_ctx, on_finish),
m_object_map_lock(object_map_lock), m_object_map(*object_map),
m_snap_id(snap_id), m_next_snap_id(CEPH_NOSNAP) {
}
void send() override;
protected:
bool should_complete(int r) override {
return true;
}
private:
ceph::shared_mutex* m_object_map_lock;
ceph::BitVector<2> &m_object_map;
uint64_t m_snap_id;
uint64_t m_next_snap_id;
uint64_t m_flags = 0;
ceph::BitVector<2> m_snap_object_map;
bufferlist m_out_bl;
void load_map();
void handle_load_map(int r);
void remove_snapshot();
void handle_remove_snapshot(int r);
void invalidate_next_map();
void handle_invalidate_next_map(int r);
void remove_map();
void handle_remove_map(int r);
void compute_next_snap_id();
void update_object_map();
};
} // namespace object_map
} // namespace librbd
#endif // CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_REMOVE_REQUEST_H
| 2,517 | 27.292135 | 81 | h |
null | ceph-main/src/librbd/object_map/SnapshotRollbackRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_ROLLBACK_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_ROLLBACK_REQUEST_H
#include "include/int_types.h"
#include "librbd/object_map/Request.h"
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
class SnapshotRollbackRequest : public Request {
public:
/**
* Snapshot rollback goes through the following state machine:
*
* @verbatim
*
* <start>
* |
* v (error)
* STATE_READ_MAP * * * * > STATE_INVALIDATE_MAP
* | |
* v v
* STATE_WRITE_MAP -------> <finish>
*
* @endverbatim
*
* If an error occurs within the READ_MAP state, the associated snapshot's
* object map will be flagged as invalid. Otherwise, an error from any state
* will result in the HEAD object map being flagged as invalid via the base
* class.
*/
enum State {
STATE_READ_MAP,
STATE_INVALIDATE_MAP,
STATE_WRITE_MAP
};
SnapshotRollbackRequest(ImageCtx &image_ctx, uint64_t snap_id,
Context *on_finish)
: Request(image_ctx, CEPH_NOSNAP, on_finish),
m_snap_id(snap_id), m_ret_val(0) {
ceph_assert(snap_id != CEPH_NOSNAP);
}
void send() override;
protected:
bool should_complete(int r) override;
private:
State m_state = STATE_READ_MAP;
uint64_t m_snap_id;
int m_ret_val;
bufferlist m_read_bl;
void send_read_map();
void send_invalidate_map();
void send_write_map();
};
} // namespace object_map
} // namespace librbd
#endif // CEPH_LIBRBD_OBJECT_MAP_SNAPSHOT_ROLLBACK_REQUEST_H
| 1,727 | 22.04 | 79 | h |
null | ceph-main/src/librbd/object_map/Types.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_TYPES_H
#define CEPH_LIBRBD_OBJECT_MAP_TYPES_H
namespace librbd {
namespace object_map {
enum DiffState {
DIFF_STATE_HOLE = 0, /* unchanged hole */
DIFF_STATE_DATA = 1, /* unchanged data */
DIFF_STATE_HOLE_UPDATED = 2, /* new hole */
DIFF_STATE_DATA_UPDATED = 3 /* new data */
};
} // namespace object_map
} // namespace librbd
#endif // CEPH_LIBRBD_OBJECT_MAP_TYPES_H
| 528 | 24.190476 | 70 | h |
null | ceph-main/src/librbd/object_map/UpdateRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OBJECT_MAP_UPDATE_REQUEST_H
#define CEPH_LIBRBD_OBJECT_MAP_UPDATE_REQUEST_H
#include "include/int_types.h"
#include "librbd/object_map/Request.h"
#include "common/bit_vector.hpp"
#include "common/zipkin_trace.h"
#include "librbd/Utils.h"
#include <boost/optional.hpp>
class Context;
namespace librbd {
class ImageCtx;
namespace object_map {
template <typename ImageCtxT = librbd::ImageCtx>
class UpdateRequest : public Request {
public:
static UpdateRequest *create(ImageCtx &image_ctx,
ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map,
uint64_t snap_id, uint64_t start_object_no,
uint64_t end_object_no, uint8_t new_state,
const boost::optional<uint8_t> ¤t_state,
const ZTracer::Trace &parent_trace,
bool ignore_enoent, Context *on_finish) {
return new UpdateRequest(image_ctx, object_map_lock, object_map, snap_id,
start_object_no, end_object_no, new_state,
current_state, parent_trace, ignore_enoent,
on_finish);
}
UpdateRequest(ImageCtx &image_ctx, ceph::shared_mutex* object_map_lock,
ceph::BitVector<2> *object_map, uint64_t snap_id,
uint64_t start_object_no, uint64_t end_object_no,
uint8_t new_state,
const boost::optional<uint8_t> ¤t_state,
const ZTracer::Trace &parent_trace, bool ignore_enoent,
Context *on_finish)
: Request(image_ctx, snap_id, on_finish),
m_object_map_lock(object_map_lock), m_object_map(*object_map),
m_start_object_no(start_object_no), m_end_object_no(end_object_no),
m_update_start_object_no(start_object_no), m_new_state(new_state),
m_current_state(current_state),
m_trace(util::create_trace(image_ctx, "update object map", parent_trace)),
m_ignore_enoent(ignore_enoent)
{
m_trace.event("start");
}
virtual ~UpdateRequest() {
m_trace.event("finish");
}
void send() override;
protected:
void finish_request() override;
private:
/**
* @verbatim
*
* <start>
* |
* |/------------------\
* v | (repeat in batches)
* UPDATE_OBJECT_MAP -----/
* |
* v
* <finish>
*
* @endverbatim
*/
ceph::shared_mutex* m_object_map_lock;
ceph::BitVector<2> &m_object_map;
uint64_t m_start_object_no;
uint64_t m_end_object_no;
uint64_t m_update_start_object_no;
uint64_t m_update_end_object_no = 0;
uint8_t m_new_state;
boost::optional<uint8_t> m_current_state;
ZTracer::Trace m_trace;
bool m_ignore_enoent;
int m_ret_val = 0;
void update_object_map();
void handle_update_object_map(int r);
void update_in_memory_object_map();
};
} // namespace object_map
} // namespace librbd
extern template class librbd::object_map::UpdateRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OBJECT_MAP_UPDATE_REQUEST_H
| 3,250 | 29.383178 | 80 | h |
null | ceph-main/src/librbd/operation/DisableFeaturesRequest.h | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_OPERATION_DISABLE_FEATURES_REQUEST_H
#define CEPH_LIBRBD_OPERATION_DISABLE_FEATURES_REQUEST_H
#include "librbd/ImageCtx.h"
#include "librbd/operation/Request.h"
#include "cls/rbd/cls_rbd_client.h"
class Context;
namespace librbd {
class ImageCtx;
namespace operation {
template <typename ImageCtxT = ImageCtx>
class DisableFeaturesRequest : public Request<ImageCtxT> {
public:
static DisableFeaturesRequest *create(ImageCtxT &image_ctx, Context *on_finish,
uint64_t journal_op_tid,
uint64_t features, bool force) {
return new DisableFeaturesRequest(image_ctx, on_finish, journal_op_tid,
features, force);
}
DisableFeaturesRequest(ImageCtxT &image_ctx, Context *on_finish,
uint64_t journal_op_tid, uint64_t features, bool force);
protected:
void send_op() override;
bool should_complete(int r) override;
bool can_affect_io() const override {
return true;
}
journal::Event create_event(uint64_t op_tid) const override {
return journal::UpdateFeaturesEvent(op_tid, m_features, false);
}
private:
/**
* DisableFeatures goes through the following state machine:
*
* @verbatim
*
* <start>
* |
* v
* STATE_PREPARE_LOCK
* |
* v
* STATE_BLOCK_WRITES
* |
* v
* STATE_ACQUIRE_EXCLUSIVE_LOCK (skip if not
* | required)
* | (disabling journaling)
* \-------------------\
* | |
* | V
* | STATE_GET_MIRROR_MODE
* |(not |
* | disabling v
* | journaling) STATE_GET_MIRROR_IMAGE
* | |
* | v
* | STATE_DISABLE_MIRROR_IMAGE (skip if not
* | | required)
* | v
* | STATE_CLOSE_JOURNAL
* | |
* | v
* | STATE_REMOVE_JOURNAL
* | |
* |/-------------------/
* |
* v
* STATE_APPEND_OP_EVENT (skip if journaling
* | disabled)
* v
* STATE_REMOVE_OBJECT_MAP (skip if not
* | disabling object map)
* v
* STATE_SET_FEATURES
* |
* v
* STATE_UPDATE_FLAGS
* |
* v
* STATE_NOTIFY_UPDATE
* |
* v
* STATE_RELEASE_EXCLUSIVE_LOCK (skip if not
* | required)
* | (unblock writes)
* v
* <finish>
*
* @endverbatim
*
*/
uint64_t m_features;
bool m_force;
bool m_acquired_lock = false;
bool m_writes_blocked = false;
bool m_image_lock_acquired = false;
bool m_requests_blocked = false;
uint64_t m_new_features = 0;
uint64_t m_disable_flags = 0;
uint64_t m_features_mask = 0;
decltype(ImageCtxT::journal) m_journal = nullptr;
cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
bufferlist m_out_bl;
void send_prepare_lock();
Context *handle_prepare_lock(int *result);
void send_block_writes();
Context *handle_block_writes(int *result);
Context *send_acquire_exclusive_lock(int *result);
Context *handle_acquire_exclusive_lock(int *result);
void send_get_mirror_mode();
Context *handle_get_mirror_mode(int *result);
void send_get_mirror_image();
Context *handle_get_mirror_image(int *result);
void send_disable_mirror_image();
Context *handle_disable_mirror_image(int *result);
void send_close_journal();
Context *handle_close_journal(int *result);
void send_remove_journal();
Context *handle_remove_journal(int *result);
void send_append_op_event();
Context *handle_append_op_event(int *result);
void send_remove_object_map();
Context *handle_remove_object_map(int *result);
void send_set_features();
Context *handle_set_features(int *result);
void send_update_flags();
Context *handle_update_flags(int *result);
void send_notify_update();
Context *handle_notify_update(int *result);
void send_release_exclusive_lock();
Context *handle_release_exclusive_lock(int *result);
Context *handle_finish(int r);
};
} // namespace operation
} // namespace librbd
extern template class librbd::operation::DisableFeaturesRequest<librbd::ImageCtx>;
#endif // CEPH_LIBRBD_OPERATION_DISABLE_FEATURES_REQUEST_H
| 4,650 | 26.040698 | 82 | h |