Skip to content

Commit

Permalink
librados: implement aio_stat
Browse files Browse the repository at this point in the history
Implement aio stat and also export this functionality to the C API.

Signed-off-by: Filippos Giannakos <philipgian@grnet.gr>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
philipgian authored and Sage Weil committed Jan 9, 2013
1 parent 5b12b51 commit 879578c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/include/rados/librados.h
Expand Up @@ -23,7 +23,7 @@ extern "C" {
#endif

#define LIBRADOS_VER_MAJOR 0
#define LIBRADOS_VER_MINOR 48
#define LIBRADOS_VER_MINOR 49
#define LIBRADOS_VER_EXTRA 0

#define LIBRADOS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
Expand Down Expand Up @@ -1444,6 +1444,20 @@ int rados_aio_read(rados_ioctx_t io, const char *oid,
*/
int rados_aio_flush(rados_ioctx_t io);


/**
* Asynchronously get object stats (size/mtime)
*
* @param io ioctx
* @param o object name
* @param psize where to store object size
* @param pmtime where to store modification time
* @returns 0 on success, negative error code on failure
*/
int rados_aio_stat(rados_ioctx_t io, const char *o,
rados_completion_t completion,
uint64_t *psize, time_t *pmtime);

/** @} Asynchronous I/O */

/**
Expand Down
4 changes: 3 additions & 1 deletion src/include/rados/librados.hpp
Expand Up @@ -478,9 +478,11 @@ namespace librados
* other than CEPH_NOSNAP
*/
int aio_remove(const std::string& oid, AioCompletion *c);

int aio_flush();

int aio_stat(const std::string& oid, AioCompletion *c, uint64_t *psize, time_t *pmtime);

int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method,
bufferlist& inbl, bufferlist *outbl);

Expand Down
42 changes: 42 additions & 0 deletions src/librados/IoCtxImpl.cc
Expand Up @@ -851,6 +851,21 @@ int librados::IoCtxImpl::aio_remove(const object_t &oid, AioCompletionImpl *c)
return 0;
}


int librados::IoCtxImpl::aio_stat(const object_t& oid, AioCompletionImpl *c,
uint64_t *psize, time_t *pmtime)
{
c->io = this;
C_aio_stat_Ack *onack = new C_aio_stat_Ack(c, pmtime);

Mutex::Locker l(*lock);
objecter->stat(oid, oloc,
snap_seq, psize, &onack->mtime, 0,
onack, &c->objver);

return 0;
}

int librados::IoCtxImpl::remove(const object_t& oid)
{
utime_t ut = ceph_clock_now(client->cct);
Expand Down Expand Up @@ -1564,6 +1579,33 @@ void librados::IoCtxImpl::C_aio_Ack::finish(int r)
c->put_unlock();
}

///////////////////////////// C_aio_stat_Ack ////////////////////////////

librados::IoCtxImpl::C_aio_stat_Ack::C_aio_stat_Ack(AioCompletionImpl *_c,
time_t *pm)
: c(_c), pmtime(pm)
{
c->get();
}

void librados::IoCtxImpl::C_aio_stat_Ack::finish(int r)
{
c->lock.Lock();
c->rval = r;
c->ack = true;
c->cond.Signal();

if (r >= 0 && pmtime) {
*pmtime = mtime.sec();
}

if (c->callback_complete) {
c->io->client->finisher.queue(new C_AioComplete(c));
}

c->put_unlock();
}

/////////////////////// C_aio_sparse_read_Ack //////////////////////////

librados::IoCtxImpl::C_aio_sparse_read_Ack::C_aio_sparse_read_Ack(AioCompletionImpl *_c,
Expand Down
9 changes: 9 additions & 0 deletions src/librados/IoCtxImpl.h
Expand Up @@ -145,6 +145,14 @@ struct librados::IoCtxImpl {
void finish(int r);
};

struct C_aio_stat_Ack : public Context {
librados::AioCompletionImpl *c;
time_t *pmtime;
utime_t mtime;
C_aio_stat_Ack(AioCompletionImpl *_c, time_t *pm);
void finish(int r);
};

struct C_aio_sparse_read_Ack : public Context {
AioCompletionImpl *c;
bufferlist *data_bl;
Expand Down Expand Up @@ -177,6 +185,7 @@ struct librados::IoCtxImpl {
int aio_remove(const object_t &oid, AioCompletionImpl *c);
int aio_exec(const object_t& oid, AioCompletionImpl *c, const char *cls,
const char *method, bufferlist& inbl, bufferlist *outbl);
int aio_stat(const object_t& oid, AioCompletionImpl *c, uint64_t *psize, time_t *pmtime);

int pool_change_auid(unsigned long long auid);
int pool_change_auid_async(unsigned long long auid, PoolAsyncCompletionImpl *c);
Expand Down
18 changes: 18 additions & 0 deletions src/librados/librados.cc
Expand Up @@ -978,6 +978,14 @@ int librados::IoCtx::aio_flush()
return 0;
}

int librados::IoCtx::aio_stat(const std::string& oid, librados::AioCompletion *c,
uint64_t *psize, time_t *pmtime)
{
object_t obj(oid);
return io_ctx_impl->aio_stat(oid, c->pc, psize, pmtime);
}


int librados::IoCtx::watch(const string& oid, uint64_t ver, uint64_t *cookie,
librados::WatchCtx *ctx)
{
Expand Down Expand Up @@ -2173,6 +2181,16 @@ extern "C" int rados_aio_flush(rados_ioctx_t io)
return 0;
}

extern "C" int rados_aio_stat(rados_ioctx_t io, const char *o,
rados_completion_t completion,
uint64_t *psize, time_t *pmtime)
{
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
object_t oid(o);
return ctx->aio_stat(oid, (librados::AioCompletionImpl*)completion,
psize, pmtime);
}

struct C_WatchCB : public librados::WatchCtx {
rados_watchcb_t wcb;
void *arg;
Expand Down

0 comments on commit 879578c

Please sign in to comment.