]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fix ictx_check pointer weirdness by using std::string
authorSage Weil <sage@newdream.net>
Sat, 21 Apr 2012 00:13:08 +0000 (17:13 -0700)
committerSage Weil <sage@newdream.net>
Sat, 21 Apr 2012 00:13:08 +0000 (17:13 -0700)
I was seeing failures of LibRBD.TestIOToSnapshot where we would fail to
refresh after rollback, even though the snap existed.  I assume it is
because the std::string whose c_str() we were pointing to was reallocated.

Use a std::string here instead.

This code is weird.

Signed-off-by: Sage Weil <sage@newdream.net>
src/librbd.cc

index 79382b8e547d762c5735ea23e1183b5896ecbc2a..265df1ad3a3dbc0f030e904155eacf27c312cb58 100644 (file)
@@ -1087,18 +1087,19 @@ int ictx_check(ImageCtx *ictx)
 
   if (needs_refresh) {
     Mutex::Locker l(ictx->lock);
-    const char *snap = NULL;
+
+    string snap;
     if (ictx->snapid != CEPH_NOSNAP)
-      snap = ictx->snapname.c_str();
+      snap = ictx->snapname;
 
-    int r = ictx_refresh(ictx, snap);
+    int r = ictx_refresh(ictx, snap.length() ? snap.c_str() : NULL);
     if (r < 0) {
       lderr(cct) << "Error re-reading rbd header: " << cpp_strerror(-r) << dendl;
       return r;
     }
 
     // check if the snapshot at which we were reading was removed
-    if (snap && ictx->snapname != snap) {
+    if (ictx->snapname != snap) {
       lderr(cct) << "tried to read from a snapshot that no longer exists: " << snap << dendl;
       return -ENOENT;
     }