Blame SOURCES/0018-librbd-internal-AIO-methods-no-longer-return-result.patch

545b23
From df42b802cfb5df6cea9015abcc3ea91a5f903009 Mon Sep 17 00:00:00 2001
545b23
From: Jason Dillaman <dillaman@redhat.com>
545b23
Date: Wed, 8 Apr 2015 21:37:50 -0400
545b23
Subject: [PATCH 18/22] librbd: internal AIO methods no longer return result
545b23
545b23
All failures should be returned via the AioCompletion.
545b23
545b23
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
545b23
(cherry picked from commit 9ab42d613128ab08c688ddbea93df4c95068b9cd)
545b23
(cherry picked from commit 04eea0add8bc5501b125bb8d5e716d70abcf9dcc)
545b23
---
545b23
 src/librbd/internal.cc | 167 ++++++++++++++++++++-----------------------------
545b23
 src/librbd/internal.h  |  17 ++---
545b23
 2 files changed, 76 insertions(+), 108 deletions(-)
545b23
545b23
diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc
545b23
index b0c8ebc..477d936 100644
545b23
--- a/src/librbd/internal.cc
545b23
+++ b/src/librbd/internal.cc
545b23
@@ -1982,13 +1982,7 @@ reprotect_and_return_err:
545b23
 
545b23
       Context *ctx = new C_CopyWrite(m_throttle, m_bl);
545b23
       AioCompletion *comp = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-      r = aio_write(m_dest, m_offset, m_bl->length(), m_bl->c_str(), comp);
545b23
-      if (r < 0) {
545b23
-	ctx->complete(r);
545b23
-	comp->release();
545b23
-	lderr(m_dest->cct) << "error writing to destination image at offset "
545b23
-			   << m_offset << ": " << cpp_strerror(r) << dendl;
545b23
-      }
545b23
+      aio_write(m_dest, m_offset, m_bl->length(), m_bl->c_str(), comp);
545b23
     }
545b23
   private:
545b23
     SimpleThrottle *m_throttle;
545b23
@@ -2021,20 +2015,15 @@ reprotect_and_return_err:
545b23
     SimpleThrottle throttle(cct->_conf->rbd_concurrent_management_ops, false);
545b23
     uint64_t period = src->get_stripe_period();
545b23
     for (uint64_t offset = 0; offset < src_size; offset += period) {
545b23
+      if (throttle.pending_error()) {
545b23
+        return throttle.wait_for_ret();
545b23
+      }
545b23
+
545b23
       uint64_t len = min(period, src_size - offset);
545b23
       bufferlist *bl = new bufferlist();
545b23
       Context *ctx = new C_CopyRead(&throttle, dest, offset, bl);
545b23
       AioCompletion *comp = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-      r = aio_read(src, offset, len, NULL, bl, comp);
545b23
-      if (r < 0) {
545b23
-	ctx->complete(r);
545b23
-	comp->release();
545b23
-	throttle.wait_for_ret();
545b23
-	lderr(cct) << "could not read from source image from "
545b23
-		   << offset << " to " << offset + len << ": "
545b23
-		   << cpp_strerror(r) << dendl;
545b23
-	return r;
545b23
-      }
545b23
+      aio_read(src, offset, len, NULL, bl, comp);
545b23
       prog_ctx.update_progress(offset, src_size);
545b23
     }
545b23
 
545b23
@@ -2408,12 +2397,7 @@ reprotect_and_return_err:
545b23
 
545b23
       Context *ctx = new C_SafeCond(&mylock, &cond, &done, &ret;;
545b23
       AioCompletion *c = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-      r = aio_read(ictx, off, read_len, NULL, &bl, c);
545b23
-      if (r < 0) {
545b23
-	c->release();
545b23
-	delete ctx;
545b23
-	return r;
545b23
-      }
545b23
+      aio_read(ictx, off, read_len, NULL, &bl, c);
545b23
 
545b23
       mylock.Lock();
545b23
       while (!done)
545b23
@@ -2643,12 +2627,7 @@ reprotect_and_return_err:
545b23
 
545b23
     Context *ctx = new C_SafeCond(&mylock, &cond, &done, &ret;;
545b23
     AioCompletion *c = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-    int r = aio_read(ictx, image_extents, buf, pbl, c);
545b23
-    if (r < 0) {
545b23
-      c->release();
545b23
-      delete ctx;
545b23
-      return r;
545b23
-    }
545b23
+    aio_read(ictx, image_extents, buf, pbl, c);
545b23
 
545b23
     mylock.Lock();
545b23
     while (!done)
545b23
@@ -2677,12 +2656,7 @@ reprotect_and_return_err:
545b23
 
545b23
     Context *ctx = new C_SafeCond(&mylock, &cond, &done, &ret;;
545b23
     AioCompletion *c = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-    r = aio_write(ictx, off, mylen, buf, c);
545b23
-    if (r < 0) {
545b23
-      c->release();
545b23
-      delete ctx;
545b23
-      return r;
545b23
-    }
545b23
+    aio_write(ictx, off, mylen, buf, c);
545b23
 
545b23
     mylock.Lock();
545b23
     while (!done)
545b23
@@ -2713,12 +2687,7 @@ reprotect_and_return_err:
545b23
 
545b23
     Context *ctx = new C_SafeCond(&mylock, &cond, &done, &ret;;
545b23
     AioCompletion *c = aio_create_completion_internal(ctx, rbd_ctx_cb);
545b23
-    int r = aio_discard(ictx, off, len, c);
545b23
-    if (r < 0) {
545b23
-      c->release();
545b23
-      delete ctx;
545b23
-      return r;
545b23
-    }
545b23
+    aio_discard(ictx, off, len, c);
545b23
 
545b23
     mylock.Lock();
545b23
     while (!done)
545b23
@@ -2836,18 +2805,20 @@ reprotect_and_return_err:
545b23
     return 0;
545b23
   }
545b23
 
545b23
-  int aio_flush(ImageCtx *ictx, AioCompletion *c)
545b23
+  void aio_flush(ImageCtx *ictx, AioCompletion *c)
545b23
   {
545b23
     CephContext *cct = ictx->cct;
545b23
     ldout(cct, 20) << "aio_flush " << ictx << " completion " << c <<  dendl;
545b23
 
545b23
+    c->get();
545b23
     int r = ictx_check(ictx);
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     ictx->user_flushed();
545b23
 
545b23
-    c->get();
545b23
     c->add_request();
545b23
     c->init_time(ictx, AIO_TYPE_FLUSH);
545b23
     C_AioWrite *req_comp = new C_AioWrite(cct, c);
545b23
@@ -2862,8 +2833,6 @@ reprotect_and_return_err:
545b23
     c->finish_adding_requests(cct);
545b23
     c->put();
545b23
     ictx->perfcounter->inc(l_librbd_aio_flush);
545b23
-
545b23
-    return 0;
545b23
   }
545b23
 
545b23
   int flush(ImageCtx *ictx)
545b23
@@ -2911,21 +2880,26 @@ reprotect_and_return_err:
545b23
     return ictx->invalidate_cache();
545b23
   }
545b23
 
545b23
-  int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
545b23
-		AioCompletion *c)
545b23
+  void aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
545b23
+		 AioCompletion *c)
545b23
   {
545b23
     CephContext *cct = ictx->cct;
545b23
     ldout(cct, 20) << "aio_write " << ictx << " off = " << off << " len = "
545b23
 		   << len << " buf = " << (void*)buf << dendl;
545b23
 
545b23
+    c->get();
545b23
     int r = ictx_check(ictx);
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     uint64_t mylen = len;
545b23
     r = clip_io(ictx, off, &mylen);
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     ictx->snap_lock.get_read();
545b23
     snapid_t snap_id = ictx->snap_id;
545b23
@@ -2936,8 +2910,10 @@ reprotect_and_return_err:
545b23
     ictx->parent_lock.put_read();
545b23
     ictx->snap_lock.put_read();
545b23
 
545b23
-    if (snap_id != CEPH_NOSNAP || ictx->read_only)
545b23
-      return -EROFS;
545b23
+    if (snap_id != CEPH_NOSNAP || ictx->read_only) {
545b23
+      c->fail(cct, -EROFS);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     ldout(cct, 20) << "  parent overlap " << overlap << dendl;
545b23
 
545b23
@@ -2948,7 +2924,6 @@ reprotect_and_return_err:
545b23
 			       &ictx->layout, off, mylen, 0, extents);
545b23
     }
545b23
 
545b23
-    c->get();
545b23
     c->init_time(ictx, AIO_TYPE_WRITE);
545b23
     for (vector<ObjectExtent>::iterator p = extents.begin(); p != extents.end(); ++p) {
545b23
       ldout(cct, 20) << " oid " << p->oid << " " << p->offset << "~" << p->length
545b23
@@ -2978,34 +2953,35 @@ reprotect_and_return_err:
545b23
 				     bl, snapc, snap_id, req_comp);
545b23
 	c->add_request();
545b23
 	r = req->send();
545b23
-	if (r < 0)
545b23
-	  goto done;
545b23
+        assert(r == 0);
545b23
       }
545b23
     }
545b23
-  done:
545b23
+
545b23
     c->finish_adding_requests(ictx->cct);
545b23
     c->put();
545b23
 
545b23
     ictx->perfcounter->inc(l_librbd_aio_wr);
545b23
     ictx->perfcounter->inc(l_librbd_aio_wr_bytes, mylen);
545b23
-
545b23
-    /* FIXME: cleanup all the allocated stuff */
545b23
-    return r;
545b23
   }
545b23
 
545b23
-  int aio_discard(ImageCtx *ictx, uint64_t off, uint64_t len, AioCompletion *c)
545b23
+  void aio_discard(ImageCtx *ictx, uint64_t off, uint64_t len, AioCompletion *c)
545b23
   {
545b23
     CephContext *cct = ictx->cct;
545b23
     ldout(cct, 20) << "aio_discard " << ictx << " off = " << off << " len = "
545b23
 		   << len << dendl;
545b23
 
545b23
+    c->get();
545b23
     int r = ictx_check(ictx);
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     r = clip_io(ictx, off, &len;;
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     // TODO: check for snap
545b23
     ictx->snap_lock.get_read();
545b23
@@ -3017,8 +2993,10 @@ reprotect_and_return_err:
545b23
     ictx->parent_lock.put_read();
545b23
     ictx->snap_lock.put_read();
545b23
 
545b23
-    if (snap_id != CEPH_NOSNAP || ictx->read_only)
545b23
-      return -EROFS;
545b23
+    if (snap_id != CEPH_NOSNAP || ictx->read_only) {
545b23
+      c->fail(cct, -EROFS);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     // map
545b23
     vector<ObjectExtent> extents;
545b23
@@ -3027,7 +3005,6 @@ reprotect_and_return_err:
545b23
 			       &ictx->layout, off, len, 0, extents);
545b23
     }
545b23
 
545b23
-    c->get();
545b23
     c->init_time(ictx, AIO_TYPE_DISCARD);
545b23
     for (vector<ObjectExtent>::iterator p = extents.begin(); p != extents.end(); ++p) {
545b23
       ldout(cct, 20) << " oid " << p->oid << " " << p->offset << "~" << p->length
545b23
@@ -3059,11 +3036,9 @@ reprotect_and_return_err:
545b23
       }
545b23
 
545b23
       r = req->send();
545b23
-      if (r < 0)
545b23
-	goto done;
545b23
+      assert(r == 0);
545b23
     }
545b23
-    r = 0;
545b23
-  done:
545b23
+
545b23
     if (ictx->object_cacher) {
545b23
       Mutex::Locker l(ictx->cache_lock);
545b23
       ictx->object_cacher->discard_set(ictx->object_set, extents);
545b23
@@ -3074,9 +3049,6 @@ reprotect_and_return_err:
545b23
 
545b23
     ictx->perfcounter->inc(l_librbd_aio_discard);
545b23
     ictx->perfcounter->inc(l_librbd_aio_discard_bytes, len);
545b23
-
545b23
-    /* FIXME: cleanup all the allocated stuff */
545b23
-    return r;
545b23
   }
545b23
 
545b23
   void rbd_req_cb(completion_t cb, void *arg)
545b23
@@ -3086,23 +3058,27 @@ reprotect_and_return_err:
545b23
     req->complete(comp->get_return_value());
545b23
   }
545b23
 
545b23
-  int aio_read(ImageCtx *ictx, uint64_t off, size_t len,
545b23
+  void aio_read(ImageCtx *ictx, uint64_t off, size_t len,
545b23
 	       char *buf, bufferlist *bl,
545b23
 	       AioCompletion *c)
545b23
   {
545b23
     vector<pair<uint64_t,uint64_t> > image_extents(1);
545b23
     image_extents[0] = make_pair(off, len);
545b23
-    return aio_read(ictx, image_extents, buf, bl, c);
545b23
+    aio_read(ictx, image_extents, buf, bl, c);
545b23
   }
545b23
 
545b23
-  int aio_read(ImageCtx *ictx, const vector<pair<uint64_t,uint64_t> >& image_extents,
545b23
-	       char *buf, bufferlist *pbl, AioCompletion *c)
545b23
+  void aio_read(ImageCtx *ictx, const vector<pair<uint64_t,uint64_t> >& image_extents,
545b23
+	        char *buf, bufferlist *pbl, AioCompletion *c)
545b23
   {
545b23
-    ldout(ictx->cct, 20) << "aio_read " << ictx << " completion " << c << " " << image_extents << dendl;
545b23
+    CephContext *cct = ictx->cct;
545b23
+    ldout(cct, 20) << "aio_read " << ictx << " completion " << c << " " << image_extents << dendl;
545b23
 
545b23
+    c->get();
545b23
     int r = ictx_check(ictx);
545b23
-    if (r < 0)
545b23
-      return r;
545b23
+    if (r < 0) {
545b23
+      c->fail(cct, r);
545b23
+      return;
545b23
+    }
545b23
 
545b23
     ictx->snap_lock.get_read();
545b23
     snap_t snap_id = ictx->snap_id;
545b23
@@ -3117,8 +3093,10 @@ reprotect_and_return_err:
545b23
 	 ++p) {
545b23
       uint64_t len = p->second;
545b23
       r = clip_io(ictx, p->first, &len;;
545b23
-      if (r < 0)
545b23
-	return r;
545b23
+      if (r < 0) {
545b23
+        c->fail(cct, r);
545b23
+	return;
545b23
+      }
545b23
       if (len == 0)
545b23
 	continue;
545b23
 
545b23
@@ -3127,13 +3105,10 @@ reprotect_and_return_err:
545b23
       buffer_ofs += len;
545b23
     }
545b23
 
545b23
-    int64_t ret;
545b23
-
545b23
     c->read_buf = buf;
545b23
     c->read_buf_len = buffer_ofs;
545b23
     c->read_bl = pbl;
545b23
 
545b23
-    c->get();
545b23
     c->init_time(ictx, AIO_TYPE_READ);
545b23
     for (map<object_t,vector<ObjectExtent> >::iterator p = object_extents.begin(); p != object_extents.end(); ++p) {
545b23
       for (vector<ObjectExtent>::iterator q = p->second.begin(); q != p->second.end(); ++q) {
545b23
@@ -3155,24 +3130,16 @@ reprotect_and_return_err:
545b23
 				    cache_comp);
545b23
 	} else {
545b23
 	  r = req->send();
545b23
-	  if (r < 0 && r == -ENOENT)
545b23
-	    r = 0;
545b23
-	  if (r < 0) {
545b23
-	    ret = r;
545b23
-	    goto done;
545b23
-	  }
545b23
+          assert(r == 0);
545b23
 	}
545b23
       }
545b23
     }
545b23
-    ret = buffer_ofs;
545b23
-  done:
545b23
-    c->finish_adding_requests(ictx->cct);
545b23
+
545b23
+    c->finish_adding_requests(cct);
545b23
     c->put();
545b23
 
545b23
     ictx->perfcounter->inc(l_librbd_aio_rd);
545b23
     ictx->perfcounter->inc(l_librbd_aio_rd_bytes, buffer_ofs);
545b23
-
545b23
-    return ret;
545b23
   }
545b23
 
545b23
   AioCompletion *aio_create_completion() {
545b23
diff --git a/src/librbd/internal.h b/src/librbd/internal.h
545b23
index 1e9fd9a..7712a39 100644
545b23
--- a/src/librbd/internal.h
545b23
+++ b/src/librbd/internal.h
545b23
@@ -179,14 +179,15 @@ namespace librbd {
545b23
 	       char *buf, bufferlist *pbl);
545b23
   ssize_t write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf);
545b23
   int discard(ImageCtx *ictx, uint64_t off, uint64_t len);
545b23
-  int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
545b23
-		AioCompletion *c);
545b23
-  int aio_discard(ImageCtx *ictx, uint64_t off, uint64_t len, AioCompletion *c);
545b23
-  int aio_read(ImageCtx *ictx, uint64_t off, size_t len,
545b23
-	       char *buf, bufferlist *pbl, AioCompletion *c);
545b23
-  int aio_read(ImageCtx *ictx, const vector<pair<uint64_t,uint64_t> >& image_extents,
545b23
-	       char *buf, bufferlist *pbl, AioCompletion *c);
545b23
-  int aio_flush(ImageCtx *ictx, AioCompletion *c);
545b23
+
545b23
+  void aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
545b23
+		 AioCompletion *c);
545b23
+  void aio_discard(ImageCtx *ictx, uint64_t off, uint64_t len, AioCompletion *c);
545b23
+  void aio_read(ImageCtx *ictx, uint64_t off, size_t len,
545b23
+	        char *buf, bufferlist *pbl, AioCompletion *c);
545b23
+  void aio_read(ImageCtx *ictx, const vector<pair<uint64_t,uint64_t> >& image_extents,
545b23
+	        char *buf, bufferlist *pbl, AioCompletion *c);
545b23
+  void aio_flush(ImageCtx *ictx, AioCompletion *c);
545b23
   int flush(ImageCtx *ictx);
545b23
   int _flush(ImageCtx *ictx);
545b23
   int invalidate_cache(ImageCtx *ictx);
545b23
-- 
545b23
2.1.0
545b23