]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: tweak C++ API
authorJosh Durgin <josh.durgin@dreamhost.com>
Fri, 25 Feb 2011 18:54:30 +0000 (10:54 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Fri, 25 Feb 2011 18:58:08 +0000 (10:58 -0800)
- rename image_open to open and make it return an int
- remove Image::close, replace with destructor
- make Image constructor private

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
src/include/rbd/librbd.hpp
src/librbd.cc

index a396b5c94a46905b32bf294d585e244b22b01607..1415874bbeb658dba9aacfa2d3bdc28387cd1332 100644 (file)
@@ -57,8 +57,8 @@ public:
 
   void version(int *major, int *minor, int *extra);
 
-  Image *image_open(pool_t pool, const char *name);
-  Image *image_open(pool_t pool, const char *name, const char *snapname);
+  int open(pool_t pool, Image *image, const char *name);
+  int open(pool_t pool, Image *image, const char *name, const char *snapname);
   int list(pool_t pool, std::vector<std::string>& names);
   int create(pool_t pool, const char *name, size_t size, int *order);
   int remove(pool_t pool, const char *name);
@@ -74,11 +74,8 @@ private:
 class Image
 {
 public:
-  Image();
-  Image(image_ctx_t ctx_);
   ~Image();
 
-  void close();
   int resize(size_t size);
   int stat(image_info_t &info, size_t infosize);
 
@@ -99,6 +96,10 @@ public:
   int aio_read(off_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
 
 private:
+  /* Image instances only come from RBD::open */
+  Image(image_ctx_t ctx_);
+  friend class RBD;
+
   Image(const Image& rhs);
   const Image& operator=(const Image& rhs);
 
index 43717718e17a4055c3edf1bac9e819017ab558da..5ef6698ed9a25714b022bce8c1820ce7fa5fd12b 100644 (file)
@@ -1346,22 +1346,23 @@ void RBD::version(int *major, int *minor, int *extra)
   rbd_version(major, minor, extra);
 }
 
-Image *RBD::image_open(pool_t pool, const char *name)
+int RBD::open(pool_t pool, Image *image, const char *name)
 {
-  return image_open(pool, name, NULL);
+  return open(pool, image, name, NULL);
 }
 
-Image *RBD::image_open(pool_t pool, const char *name, const char *snapname)
+int RBD::open(pool_t pool, Image *image, const char *name, const char *snapname)
 {
   ImageCtx *ictx = new ImageCtx(name, pool);
   if (!ictx)
-    return NULL;
+    return -ENOMEM;
+
   int r = librbd::open_image(pool, ictx, name, snapname);
   if (r < 0)
-    return NULL;
+    return r;
 
-  Image *image = new Image((image_ctx_t)ictx);
-  return image;
+  image = new Image((image_ctx_t)ictx);
+  return 0;
 }
 
 int RBD::create(pool_t pool, const char *name, size_t size, int *order)
@@ -1425,19 +1426,11 @@ void RBD::AioCompletion::release()
   Image
 */
 
-Image::Image()
-{
-}
-
 Image::Image(image_ctx_t ctx_) : ctx(ctx_)
 {
 }
 
 Image::~Image()
-{
-}
-
-void Image::close()
 {
   ImageCtx *ictx = (ImageCtx *)ctx;
   close_image(ictx);