Skip to content

Commit

Permalink
librbd, cls_rbd: move parent_info and parent_spec to parent_types.h
Browse files Browse the repository at this point in the history
parent_type.h is a new librbd-scope header containing info
related to parents and children (clones)

Signed-off-by: Dan Mick <[email protected]>
  • Loading branch information
Dan Mick committed Aug 18, 2012
1 parent 9a45ffb commit 31824b6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ noinst_HEADERS = \
librbd/ImageCtx.h\
librbd/internal.h\
librbd/LibrbdWriteback.h\
librbd/parent_types.h\
librbd/SnapInfo.h\
librbd/WatchCtx.h\
logrotate.conf\
Expand Down
2 changes: 1 addition & 1 deletion src/librbd/ImageCtx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace librbd {

void ImageCtx::add_snap(string in_snap_name, snap_t id, uint64_t in_size,
uint64_t features,
cls_client::parent_info parent)
parent_info parent)
{
assert(snap_lock.is_locked());
snaps.push_back(id);
Expand Down
3 changes: 2 additions & 1 deletion src/librbd/ImageCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "librbd/cls_rbd_client.h"
#include "librbd/LibrbdWriteback.h"
#include "librbd/SnapInfo.h"
#include "librbd/parent_types.h"

class CephContext;
class PerfCounters;
Expand Down Expand Up @@ -67,7 +68,7 @@ namespace librbd {
std::string object_prefix;
std::string header_oid;
std::string id; // only used for new-format images
cls_client::parent_info parent_md;
parent_info parent_md;
ImageCtx *parent;

ObjectCacher *object_cacher;
Expand Down
3 changes: 2 additions & 1 deletion src/librbd/SnapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
#include "include/rados/librados.hpp"

#include "librbd/cls_rbd_client.h"
#include "librbd/parent_types.h"

namespace librbd {

struct SnapInfo {
librados::snap_t id;
uint64_t size;
uint64_t features;
cls_client::parent_info parent;
parent_info parent;
SnapInfo(librados::snap_t _id, uint64_t _size, uint64_t _features,
cls_client::parent_info _parent) :
id(_id), size(_size), features(_features), parent(_parent) {}
Expand Down
24 changes: 1 addition & 23 deletions src/librbd/cls_rbd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,13 @@
#include "include/rados.h"
#include "include/rados/librados.hpp"
#include "include/types.h"
#include "librbd/parent_types.h"

#include <string>
#include <vector>

namespace librbd {
namespace cls_client {
struct parent_spec {
int64_t pool_id;
string image_id;
snapid_t snap_id;
parent_spec() : pool_id(-1), snap_id(CEPH_NOSNAP) {}
parent_spec(uint64_t pool_id, string image_id, snapid_t snap_id) :
pool_id(pool_id), image_id(image_id), snap_id(snap_id) {}
bool operator==(const parent_spec &other) {
return ((this->pool_id == other.pool_id) &&
(this->image_id == other.image_id) &&
(this->snap_id == other.snap_id));
}
bool operator!=(const parent_spec &other) {
return !(*this == other);
}
};

struct parent_info {
struct parent_spec spec;
uint64_t overlap;
parent_info() : overlap(0) {}
};

// high-level interface to the header
int get_immutable_metadata(librados::IoCtx *ioctx, const std::string &oid,
std::string *object_prefix, uint8_t *order);
Expand Down
17 changes: 9 additions & 8 deletions src/librbd/internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "librbd/ImageCtx.h"

#include "librbd/internal.h"
#include "librbd/parent_types.h"

#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
Expand Down Expand Up @@ -611,6 +612,9 @@ namespace librbd {
return r;
}

parent_spec pspec(p_ioctx.get_id(), p_imctx->id,
p_imctx->snap_id);

if (p_imctx->old_format) {
lderr(cct) << "parent image must be in new format" << dendl;
return -EINVAL;
Expand All @@ -635,9 +639,6 @@ namespace librbd {
order = p_imctx->order;
}

cls_client::parent_spec pspec(p_ioctx.get_id(), p_imctx->id,
p_imctx->snap_id);

int remove_r;
librbd::NoOpProgressContext no_op;
ImageCtx *c_imctx = NULL;
Expand Down Expand Up @@ -912,7 +913,7 @@ namespace librbd {
Mutex::Locker l(ictx->snap_lock);
Mutex::Locker l2(ictx->parent_lock);

cls_client::parent_info *parent_info;
parent_spec *parent_spec;

if (ictx->snap_id == CEPH_NOSNAP) {
if (!ictx->parent)
Expand Down Expand Up @@ -991,7 +992,7 @@ namespace librbd {

ictx->parent_lock.Lock();
// struct assignment
cls_client::parent_info parent_info = ictx->parent_md;
parent_info parent_info = ictx->parent_md;
ictx->parent_lock.Unlock();

// scan snapshots; if none of them refer to this parent,
Expand Down Expand Up @@ -1278,7 +1279,7 @@ namespace librbd {
vector<string> snap_names;
vector<uint64_t> snap_sizes;
vector<uint64_t> snap_features;
vector<cls_client::parent_info> snap_parents;
vector<parent_info> snap_parents;
{
Mutex::Locker l(ictx->snap_lock);
{
Expand Down Expand Up @@ -1337,7 +1338,7 @@ namespace librbd {

for (size_t i = 0; i < new_snapc.snaps.size(); ++i) {
uint64_t features = ictx->old_format ? 0 : snap_features[i];
cls_client::parent_info parent;
parent_info parent;
if (!ictx->old_format)
parent = snap_parents[i];
vector<snap_t>::const_iterator it =
Expand All @@ -1356,7 +1357,7 @@ namespace librbd {
ictx->snaps_by_name.clear();
for (size_t i = 0; i < new_snapc.snaps.size(); ++i) {
uint64_t features = ictx->old_format ? 0 : snap_features[i];
cls_client::parent_info parent;
parent_info parent;
if (!ictx->old_format)
parent = snap_parents[i];
ictx->add_snap(snap_names[i], new_snapc.snaps[i].val,
Expand Down
34 changes: 34 additions & 0 deletions src/librbd/parent_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_LIBRBD_PARENT_TYPES_H
#define CEPH_LIBRBD_PARENT_TYPES_H

// parent_spec uniquely identifies a parent in the clone relationship
// (clone(parent) creates child, then parent_spec <-> child_imageid)

namespace librbd {
struct parent_spec {
int64_t pool_id;
string image_id;
snapid_t snap_id;
parent_spec() : pool_id(-1), snap_id(CEPH_NOSNAP) {}
parent_spec(uint64_t pool_id, string image_id, snapid_t snap_id) :
pool_id(pool_id), image_id(image_id), snap_id(snap_id) {}
bool operator==(const parent_spec &other) {
return ((this->pool_id == other.pool_id) &&
(this->image_id == other.image_id) &&
(this->snap_id == other.snap_id));
}
bool operator!=(const parent_spec &other) {
return !(*this == other);
}
};

struct parent_info {
parent_spec spec;
uint64_t overlap;
parent_info() : overlap(0) {}
};
}

#endif
4 changes: 2 additions & 2 deletions src/test/rbd/test_cls_rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ using ::librbd::cls_client::dir_list;
using ::librbd::cls_client::dir_add_image;
using ::librbd::cls_client::dir_remove_image;
using ::librbd::cls_client::dir_rename_image;
using ::librbd::cls_client::parent_info;
using ::librbd::cls_client::parent_spec;
using ::librbd::parent_info;
using ::librbd::parent_spec;

static char *random_buf(size_t len)
{
Expand Down

0 comments on commit 31824b6

Please sign in to comment.