From e114cbffcc72bdfc6c2c1b6b39bb8bbabf17d8b8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 3 Oct 2012 15:09:25 -0700 Subject: [PATCH] librbd/ImageCtx: accessors Signed-off-by: Sage Weil --- src/librbd/ImageCtx.cc | 22 ++++++++++++++++++++++ src/librbd/ImageCtx.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 50845524e6bbd..1b673e18ac40f 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -256,6 +256,16 @@ namespace librbd { return -ENOENT; } + uint64_t ImageCtx::get_size() const + { + return size; + } + + uint64_t ImageCtx::get_object_size() const + { + return 1ull << order; + } + uint64_t ImageCtx::get_stripe_unit() const { return stripe_unit; @@ -266,6 +276,18 @@ namespace librbd { return stripe_count; } + uint64_t ImageCtx::get_stripe_period() const + { + return stripe_count * (1ull << order); + } + + uint64_t ImageCtx::get_num_objects() const + { + uint64_t period = get_stripe_period(); + uint64_t num_periods = (size + period - 1) / period; + return num_periods * stripe_count; + } + int ImageCtx::is_snap_protected(string in_snap_name, bool *is_protected) const { assert(snap_lock.is_locked()); diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 0e2f4b3780f2e..f952ef621defc 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -103,8 +103,14 @@ namespace librbd { int get_parent_spec(snapid_t snap_id, parent_spec *pspec); int get_snap_size(std::string in_snap_name, uint64_t *out_size) const; int is_snap_protected(string in_snap_name, bool *is_protected) const; + + uint64_t get_size() const; + uint64_t get_object_size() const; + uint64_t get_num_objects() const; uint64_t get_stripe_unit() const; uint64_t get_stripe_count() const; + uint64_t get_stripe_period() const; + void add_snap(std::string in_snap_name, librados::snap_t id, uint64_t in_size, uint64_t features, parent_info parent, uint8_t protection_status); -- 2.39.5