]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: correct the return code and perf counter in discard op
authorZhiqiang Wang <zhiqiang.wang@intel.com>
Fri, 20 Mar 2015 07:54:32 +0000 (15:54 +0800)
committerZhiqiang Wang <zhiqiang.wang@intel.com>
Mon, 23 Mar 2015 03:03:03 +0000 (11:03 +0800)
If length is clipped in aio_discard, the actual discarded length would
be less than the passed in argument.

Signed-off-by: Zhiqiang Wang <zhiqiang.wang@intel.com>
src/librbd/internal.cc

index 30a0e3f6fcb1a346171be3f8cb3c989426ff10e7..714c3b3ef381095147171d098c77c16e8ec4979b 100644 (file)
@@ -3121,9 +3121,17 @@ reprotect_and_return_err:
     bool done;
     int ret;
 
+    uint64_t mylen = len;
+    ictx->snap_lock.get_read();
+    int r = clip_io(ictx, off, &mylen);
+    ictx->snap_lock.put_read();
+    if (r < 0) {
+      return r;
+    }
+
     Context *ctx = new C_SafeCond(&mylock, &cond, &done, &ret);
     AioCompletion *c = aio_create_completion_internal(ctx, rbd_ctx_cb);
-    int r = aio_discard(ictx, off, len, c);
+    r = aio_discard(ictx, off, mylen, c);
     if (r < 0) {
       c->release();
       delete ctx;
@@ -3142,8 +3150,8 @@ reprotect_and_return_err:
     elapsed = ceph_clock_now(ictx->cct) - start_time;
     ictx->perfcounter->inc(l_librbd_discard_latency, elapsed);
     ictx->perfcounter->inc(l_librbd_discard);
-    ictx->perfcounter->inc(l_librbd_discard_bytes, len);
-    return len;
+    ictx->perfcounter->inc(l_librbd_discard_bytes, mylen);
+    return mylen;
   }
 
   ssize_t handle_sparse_read(CephContext *cct,