]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: re-read image header in get_snapc, and call it after snap create and remove
authorJosh Durgin <josh.durgin@dreamhost.com>
Wed, 2 Feb 2011 02:53:49 +0000 (18:53 -0800)
committerYehuda Sadeh <yehuda.sadeh@dreamhost.com>
Mon, 7 Feb 2011 23:13:01 +0000 (15:13 -0800)
This fixes a bug with image context in which the snap info
in the image header showed fewer snapshots than it should have.

src/librbd.cc

index 2a4dc9c70380ec5df5efc797fa7f6706c919fd6f..8816f162b020ba35571598ada8d1b10a75e5e2dd 100644 (file)
@@ -406,6 +406,8 @@ int librbd::RBDClient::create_snap(PoolCtx *pp, ImageCtx *ictx, const char *snap
 
   rados.set_snap(pp->data, 0);
   r = add_snap(pp, ictx, snap_name);
+  get_snapc(pp, md_oid, NULL, ictx);
+
   return r;
 }
 
@@ -426,6 +428,8 @@ int librbd::RBDClient::remove_snap(PoolCtx *pp, ImageCtx *ictx, const char *snap
 
   r = rm_snap(pp, md_oid, snap_name);
   r = rados.selfmanaged_snap_remove(pp->data, ictx->snapid);
+  get_snapc(pp, md_oid, NULL, ictx);
+
   return r;
 }
 
@@ -655,11 +659,12 @@ int librbd::RBDClient::get_snapc(PoolCtx *pp, string& md_oid, const char *snap_n
 {
   bufferlist bl, bl2;
 
-  int r = rados.exec(pp->md, md_oid, "rbd", "snap_list", bl, bl2);
-  if (r < 0) {
-    cerr << "list_snaps failed: " << strerror(-r) << std::endl;
+  int r = read_header(pp->md, md_oid, &(ictx->header), NULL);
+  if (r < 0)
+    return r;
+  r = rados.exec(pp->md, md_oid, "rbd", "snap_list", bl, bl2);
+  if (r < 0)
     return r;
-  }
 
   ictx->snaps.clear();
   ictx->snapc.snaps.clear();
@@ -1020,11 +1025,7 @@ int librbd::RBD::open_image(pool_t pool, const char *name, image_t *image, const
   string md_oid = name;
   md_oid += RBD_SUFFIX;
 
-  int r = client->read_header(pctx->md, md_oid, &(ictx->header), NULL);
-  if (r < 0)
-    return r;
-
-  r = client->get_snapc(pctx, md_oid, snap_name, ictx);
+  int r = client->get_snapc(pctx, md_oid, snap_name, ictx);
   if (!snap_name && r == -ENOENT)
     r = 0;
   if (r < 0)