Skip to content

Commit

Permalink
librados: cleanly define SNAP_HEAD, SNAP_DIR constants
Browse files Browse the repository at this point in the history
We were using the internal CEPH_NOSNAP and CEPH_SNAPDIR constants, and
defining a clone_info_t::HEAD (with a different value).  The docs were
referrring to the internal constant names.

Instead, define librados constants (C and C++) with the same values as the
internal types.

Note that this changes the clone_info_t::HEAD value from -1 to -2 so that
it now matches the internal type.

Signed-off-by: Sage Weil <sage@inktank.com>
  • Loading branch information
Sage Weil authored and jdurgin committed Apr 1, 2013
1 parent 10dc0ad commit 6af769a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 25 deletions.
4 changes: 4 additions & 0 deletions doc/PendingReleaseNotes
@@ -0,0 +1,4 @@

* The librados::clone_info_t::HEAD constant has been replaced with librados::SNAP_HEAD, with
a different value that matches the internal constants. This only affects the brand-new
list_snaps() interface that was introduced in v0.59.
16 changes: 11 additions & 5 deletions src/include/rados/librados.h
Expand Up @@ -51,6 +51,12 @@ enum {
/** @endcond */
/** @} */

/*
* snap id contants
*/
#define LIBRADOS_SNAP_HEAD ((uint64_t)(-2))
#define LIBRADOS_SNAP_DIR ((uint64_t)(-1))

/**
* @typedef rados_t
*
Expand Down Expand Up @@ -727,7 +733,7 @@ int rados_rollback(rados_ioctx_t io, const char *oid,
* snapshot.
*
* @param io the io context to change
* @param snap the id of the snapshot to set, or CEPH_NOSNAP for no
* @param snap the id of the snapshot to set, or LIBRADOS_SNAP_HEAD for no
* snapshot (i.e. normal operation)
*/
void rados_ioctx_snap_set_read(rados_ioctx_t io, rados_snap_t snap);
Expand Down Expand Up @@ -1343,7 +1349,7 @@ void rados_aio_release(rados_completion_t c);
* @param len length of the data, in bytes
* @param off byte offset in the object to begin writing at
* @returns 0 on success, -EROFS if the io context specifies a snap_seq
* other than CEPH_NOSNAP
* other than LIBRADOS_SNAP_HEAD
*/
int rados_aio_write(rados_ioctx_t io, const char *oid,
rados_completion_t completion,
Expand All @@ -1363,7 +1369,7 @@ int rados_aio_write(rados_ioctx_t io, const char *oid,
* @param buf the data to append
* @param len length of buf (in bytes)
* @returns 0 on success, -EROFS if the io context specifies a snap_seq
* other than CEPH_NOSNAP
* other than LIBRADOS_SNAP_HEAD
*/
int rados_aio_append(rados_ioctx_t io, const char *oid,
rados_completion_t completion,
Expand All @@ -1385,7 +1391,7 @@ int rados_aio_append(rados_ioctx_t io, const char *oid,
* @param buf data to write
* @param len length of the data, in bytes
* @returns 0 on success, -EROFS if the io context specifies a snap_seq
* other than CEPH_NOSNAP
* other than LIBRADOS_SNAP_HEAD
*/
int rados_aio_write_full(rados_ioctx_t io, const char *oid,
rados_completion_t completion,
Expand All @@ -1403,7 +1409,7 @@ int rados_aio_write_full(rados_ioctx_t io, const char *oid,
* @param oid the name of the object
* @param completion what to do when the remove is safe and complete
* @returns 0 on success, -EROFS if the io context specifies a snap_seq
* other than CEPH_NOSNAP
* other than LIBRADOS_SNAP_HEAD
*/
int rados_aio_remove(rados_ioctx_t io, const char *oid,
rados_completion_t completion);
Expand Down
10 changes: 5 additions & 5 deletions src/include/rados/librados.hpp
Expand Up @@ -333,12 +333,12 @@ namespace librados
* list snapshot clones associated with a logical object
*
* This will include a record for each version of the object,
* include the "HEAD" (which will have a cloneid of
* librados::clone_info_t::HEAD). Each clone includes a vector
* of snap ids for which it is defined to exist.
* include the "HEAD" (which will have a cloneid of SNAP_HEAD).
* Each clone includes a vector of snap ids for which it is
* defined to exist.
*
* NOTE: this operation must be submitted from an IoCtx with a
* read snapid of CEPH_SNAPDIR for reliable results.
* read snapid of SNAP_DIR for reliable results.
*
* @param out_snaps [out] pointer to resulting snap_set_t
* @param prval [out] place error code in prval upon completion
Expand Down Expand Up @@ -538,7 +538,7 @@ namespace librados
* @param oid the name of the object
* @param completion what to do when the remove is safe and complete
* @returns 0 on success, -EROFS if the io context specifies a snap_seq
* other than CEPH_NOSNAP
* other than SNAP_HEAD
*/
int aio_remove(const std::string& oid, AioCompletion *c);

Expand Down
6 changes: 5 additions & 1 deletion src/include/rados/rados_types.hpp
Expand Up @@ -9,8 +9,12 @@ namespace librados {

typedef uint64_t snap_t;

enum {
SNAP_HEAD = (uint64_t)(-2),
SNAP_DIR = (uint64_t)(-1)
};

struct clone_info_t {
static const snap_t HEAD = ((snap_t)-1);
snap_t cloneid;
std::vector<snap_t> snaps; // ascending
std::vector< std::pair<uint64_t,uint64_t> > overlap; // with next newest
Expand Down
2 changes: 1 addition & 1 deletion src/librbd/internal.cc
Expand Up @@ -2387,7 +2387,7 @@ namespace librbd {
bool end_exists;
calc_snap_set_diff(ictx->cct, snap_set,
from_snap_id,
end_snap_id == CEPH_NOSNAP ? librados::clone_info_t::HEAD : end_snap_id,
end_snap_id,
&diff, &end_exists);
ldout(ictx->cct, 20) << " diff " << diff << " end_exists=" << end_exists << dendl;
if (diff.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/osd/ReplicatedPG.cc
Expand Up @@ -2373,7 +2373,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
if (ssc->snapset.head_exists) {
assert(obs.exists);
clone_info ci;
ci.cloneid = clone_info::HEAD;
ci.cloneid = CEPH_NOSNAP;

//Size for HEAD is oi.size
ci.size = oi.size;
Expand Down
2 changes: 0 additions & 2 deletions src/osd/osd_types.cc
Expand Up @@ -20,8 +20,6 @@ extern "C" {
#include "PG.h"
#include "OSDMap.h"

const snapid_t clone_info::HEAD((uint64_t)-1);

// -- osd_reqid_t --
void osd_reqid_t::encode(bufferlist &bl) const
{
Expand Down
8 changes: 3 additions & 5 deletions src/osd/osd_types.h
Expand Up @@ -2114,8 +2114,6 @@ struct obj_list_watch_response_t {
WRITE_CLASS_ENCODER(obj_list_watch_response_t)

struct clone_info {
static const snapid_t HEAD;

snapid_t cloneid;
vector<snapid_t> snaps; // ascending
vector< pair<uint64_t,uint64_t> > overlap;
Expand All @@ -2140,7 +2138,7 @@ struct clone_info {
DECODE_FINISH(bl);
}
void dump(Formatter *f) const {
if (cloneid == HEAD)
if (cloneid == CEPH_NOSNAP)
f->dump_string("cloneid", "HEAD");
else
f->dump_unsigned("cloneid", cloneid.val);
Expand Down Expand Up @@ -2171,7 +2169,7 @@ struct clone_info {
o.back()->overlap.push_back(pair<uint64_t,uint64_t>(8192,4096));
o.back()->size = 16384;
o.push_back(new clone_info);
o.back()->cloneid = HEAD;
o.back()->cloneid = CEPH_NOSNAP;
o.back()->size = 32768;
}
};
Expand Down Expand Up @@ -2220,7 +2218,7 @@ struct obj_list_snap_response_t {
cl.overlap.push_back(pair<uint64_t,uint64_t>(8192,4096));
cl.size = 16384;
o.back()->clones.push_back(cl);
cl.cloneid = clone_info::HEAD;
cl.cloneid = CEPH_NOSNAP;
cl.snaps.clear();
cl.overlap.clear();
cl.size = 32768;
Expand Down
2 changes: 1 addition & 1 deletion src/osdc/snap_set_diff.cc
Expand Up @@ -31,7 +31,7 @@ void calc_snap_set_diff(CephContext *cct, const librados::snap_set_t& snap_set,
// include itself in the snaps list
librados::snap_t a, b;
b = r->cloneid;
if (b == librados::clone_info_t::HEAD) {
if (b == librados::SNAP_HEAD) {
// head is valid starting from right after the last seen seq
a = snap_set.seq + 1;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/rados.cc
Expand Up @@ -2061,7 +2061,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,

if (formatter) formatter->open_object_section("clone");

if (ci->cloneid == clone_info_t::HEAD) {
if (ci->cloneid == librados::SNAP_HEAD) {
if (formatter)
formatter->dump_string("id", "head");
else
Expand Down Expand Up @@ -2110,7 +2110,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
cout << "\t" << ci->size;
}

if (ci->cloneid != clone_info_t::HEAD) {
if (ci->cloneid != librados::SNAP_HEAD) {
if (formatter)
formatter->open_array_section("overlaps");
else
Expand Down
4 changes: 2 additions & 2 deletions src/test/librados/snapshots.cc
Expand Up @@ -332,7 +332,7 @@ TEST(LibRadosSnapshots, SelfManagedSnapRollbackPP) {

snap_set_t ss;

snap_t head = clone_info_t::HEAD;
snap_t head = SNAP_HEAD;
ASSERT_EQ(0, ioctx.list_snaps("foo", &ss));
ASSERT_EQ(1u, ss.clones.size());
ASSERT_EQ(head, ss.clones[0].cloneid);
Expand Down Expand Up @@ -415,7 +415,7 @@ TEST(LibRadosSnapshots, SelfManagedSnapOverlapPP) {
ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl1, sizeof(buf), bufsize*8));

snap_set_t ss;
snap_t head = clone_info_t::HEAD;
snap_t head = SNAP_HEAD;
ASSERT_EQ(0, ioctx.list_snaps("foo", &ss));
ASSERT_EQ(1u, ss.clones.size());
ASSERT_EQ(head, ss.clones[0].cloneid);
Expand Down

0 comments on commit 6af769a

Please sign in to comment.