From 57271df55ecfe609b5543eb3270e5ad8ae755009 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 5 Jun 2009 21:15:38 -0700 Subject: [PATCH] librados: clean up snap and ctx a bit Define PoolCtx constructor, methods. --- src/librados.cc | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/librados.cc b/src/librados.cc index 6ca9d42a3c8e5..85ed67d6887a6 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -68,16 +68,22 @@ public: struct PoolCtx { int poolid; - SnapContext snapc; snapid_t snap_seq; + SnapContext snapc; + + PoolCtx(int pid, snapid_t s) : poolid(pid), snap_seq(CEPH_NOSNAP) {} + + void set_snap(snapid_t s) { + if (!s) + s = CEPH_NOSNAP; + snap_seq = s; + } }; int lookup_pool(const char *name) { return osdmap.lookup_pg_pool_name(name); } - void set_snap(PoolCtx& pool, snapid_t seq); - int write(PoolCtx& pool, const object_t& oid, off_t off, bufferlist& bl, size_t len); int read(PoolCtx& pool, const object_t& oid, off_t off, bufferlist& bl, size_t len); int remove(PoolCtx& pool, const object_t& oid); @@ -416,14 +422,6 @@ retry: return r; } -void RadosClient::set_snap(PoolCtx& pool, snapid_t seq) -{ - if (!seq) { - seq = CEPH_NOSNAP; - } - pool.snap_seq = seq; -} - int RadosClient::write(PoolCtx& pool, const object_t& oid, off_t off, bufferlist& bl, size_t len) { #if 0 @@ -643,8 +641,7 @@ void Rados::set_snap(rados_pool_t pool, snapid_t seq) return; RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool; - - client->set_snap(*ctx, seq); + ctx->set_snap(seq); } int Rados::list(rados_pool_t pool, int max, std::list& entries, Rados::ListCtx& ctx) @@ -701,13 +698,10 @@ int Rados::open_pool(const char *name, rados_pool_t *pool) { int poolid = client->lookup_pool(name); if (poolid >= 0) { - RadosClient::PoolCtx *ctx = new RadosClient::PoolCtx; + RadosClient::PoolCtx *ctx = new RadosClient::PoolCtx(poolid, CEPH_NOSNAP); if (!ctx) return -ENOMEM; - ctx->poolid = poolid; - ctx->snap_seq = CEPH_NOSNAP; - *pool = (rados_pool_t)ctx; return 0; } @@ -843,11 +837,9 @@ extern "C" int rados_open_pool(const char *name, rados_pool_t *pool) { int poolid = radosp->lookup_pool(name); if (poolid >= 0) { - RadosClient::PoolCtx *ctx = new RadosClient::PoolCtx; + RadosClient::PoolCtx *ctx = new RadosClient::PoolCtx(poolid, CEPH_NOSNAP); if (!ctx) return -ENOMEM; - ctx->poolid = poolid; - ctx->snap_seq = CEPH_NOSNAP; *pool = ctx; return 0; } @@ -864,11 +856,9 @@ extern "C" int rados_close_pool(rados_pool_t pool) extern "C" void rados_set_snap(rados_pool_t pool, int seq) { RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool; - - radosp->set_snap(*ctx, (snapid_t)seq); + ctx->set_snap((snapid_t)seq); } - extern "C" int rados_write(rados_pool_t pool, const char *o, off_t off, const char *buf, size_t len) { RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool; -- 2.39.5