Skip to content

Commit

Permalink
Add SnapshotNamespace to ImageCtx methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorDenisov committed Jan 17, 2017
1 parent 17589d5 commit bcacaf6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/cls/rbd/cls_rbd_types.h
Expand Up @@ -237,6 +237,10 @@ struct UserSnapshotNamespace {
return true;
}

inline bool operator<(const UserSnapshotNamespace& usn) const {
return false;
}

};

std::ostream& operator<<(std::ostream& os, const UserSnapshotNamespace& ns);
Expand Down Expand Up @@ -267,6 +271,16 @@ struct GroupSnapshotNamespace {
snapshot_id == gsn.snapshot_id;
}

inline bool operator<(const GroupSnapshotNamespace& gsn) const {
if (group_pool < gsn.group_pool) {
return true;
} else if (group_id < gsn.group_id) {
return true;
} else {
return snapshot_id < gsn.snapshot_id;
}
}

};

std::ostream& operator<<(std::ostream& os, const GroupSnapshotNamespace& ns);
Expand All @@ -282,6 +296,10 @@ struct UnknownSnapshotNamespace {
inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
return true;
}

inline bool operator<(const UnknownSnapshotNamespace& usn) const {
return false;
}
};

std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns);
Expand Down
23 changes: 15 additions & 8 deletions src/librbd/ImageCtx.cc
Expand Up @@ -405,13 +405,15 @@ struct C_InvalidateCache : public Context {
return flags;
}

int ImageCtx::snap_set(string in_snap_name)
int ImageCtx::snap_set(cls::rbd::SnapshotNamespace in_snap_namespace,
string in_snap_name)
{
assert(snap_lock.is_wlocked());
snap_t in_snap_id = get_snap_id(in_snap_name);
snap_t in_snap_id = get_snap_id(in_snap_namespace, in_snap_name);
if (in_snap_id != CEPH_NOSNAP) {
snap_id = in_snap_id;
snap_name = in_snap_name;
snap_namespace = in_snap_namespace;
snap_exists = true;
data_ctx.snap_set_read(snap_id);
return 0;
Expand All @@ -428,11 +430,12 @@ struct C_InvalidateCache : public Context {
data_ctx.snap_set_read(snap_id);
}

snap_t ImageCtx::get_snap_id(string in_snap_name) const
snap_t ImageCtx::get_snap_id(cls::rbd::SnapshotNamespace in_snap_namespace,
string in_snap_name) const
{
assert(snap_lock.is_locked());
map<string, snap_t>::const_iterator it =
snap_ids.find(in_snap_name);
map<pair<cls::rbd::SnapshotNamespace, string>, snap_t>::const_iterator it =
snap_ids.find(make_pair(in_snap_namespace, in_snap_name));
if (it != snap_ids.end())
return it->second;
return CEPH_NOSNAP;
Expand Down Expand Up @@ -552,15 +555,19 @@ struct C_InvalidateCache : public Context {
SnapInfo info(in_snap_name, in_snap_namespace,
in_size, parent, protection_status, flags);
snap_info.insert(pair<snap_t, SnapInfo>(id, info));
snap_ids.insert(pair<string, snap_t>(in_snap_name, id));
snap_ids.insert(pair<pair<cls::rbd::SnapshotNamespace, string>,
snap_t>(make_pair(in_snap_namespace, in_snap_name),
id));
}

void ImageCtx::rm_snap(string in_snap_name, snap_t id)
void ImageCtx::rm_snap(cls::rbd::SnapshotNamespace in_snap_namespace,
string in_snap_name,
snap_t id)
{
assert(snap_lock.is_wlocked());
snaps.erase(std::remove(snaps.begin(), snaps.end(), id), snaps.end());
snap_info.erase(id);
snap_ids.erase(in_snap_name);
snap_ids.erase(make_pair(in_snap_namespace, in_snap_name));
}

uint64_t ImageCtx::get_image_size(snap_t in_snap_id) const
Expand Down
14 changes: 10 additions & 4 deletions src/librbd/ImageCtx.h
Expand Up @@ -67,7 +67,8 @@ namespace librbd {
std::vector<librados::snap_t> snaps; // this mirrors snapc.snaps, but is in
// a format librados can understand
std::map<librados::snap_t, SnapInfo> snap_info;
std::map<std::string, librados::snap_t> snap_ids;
std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
//std::map<std::string, librados::snap_t> snap_ids;
uint64_t snap_id;
bool snap_exists; // false if our snap_id was deleted
// whether the image was opened read-only. cannot be changed after opening
Expand All @@ -81,6 +82,7 @@ namespace librbd {

std::string name;
std::string snap_name;
cls::rbd::SnapshotNamespace snap_namespace;
IoCtx data_ctx, md_ctx;
ImageWatcher<ImageCtx> *image_watcher;
Journal<ImageCtx> *journal;
Expand Down Expand Up @@ -224,9 +226,11 @@ namespace librbd {
void perf_stop();
void set_read_flag(unsigned flag);
int get_read_flags(librados::snap_t snap_id);
int snap_set(std::string in_snap_name);
int snap_set(cls::rbd::SnapshotNamespace in_snap_namespace,
std::string in_snap_name);
void snap_unset();
librados::snap_t get_snap_id(std::string in_snap_name) const;
librados::snap_t get_snap_id(cls::rbd::SnapshotNamespace in_snap_namespace,
std::string in_snap_name) const;
const SnapInfo* get_snap_info(librados::snap_t in_snap_id) const;
int get_snap_name(librados::snap_t in_snap_id,
std::string *out_snap_name) const;
Expand All @@ -251,7 +255,9 @@ namespace librbd {
librados::snap_t id,
uint64_t in_size, parent_info parent,
uint8_t protection_status, uint64_t flags);
void rm_snap(std::string in_snap_name, librados::snap_t id);
void rm_snap(cls::rbd::SnapshotNamespace in_snap_namespace,
std::string in_snap_name,
librados::snap_t id);
uint64_t get_image_size(librados::snap_t in_snap_id) const;
uint64_t get_object_count(librados::snap_t in_snap_id) const;
bool test_features(uint64_t test_features) const;
Expand Down

0 comments on commit bcacaf6

Please sign in to comment.