Skip to contentSkip to conversation

qemu-kvm/rbd: use new librados callback for ack/complete

PATCH In review Christian Brunner 2 participants 4 messages May 6, 2010 – May 7, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 qemu-kvm/rbd: use new librados callback for ack/complete

This patch uses the new librados aio callback function (from the unstable branch of ceph).

Christian

---
 block/rbd.c |   51 ++++++++++++++++++++++++---------------------------
 1 files changed, 24 insertions(+), 27 deletions(-)
block/rbd.c +24 -27
index 12a85dc..dfd2eca 100644
@@ -393,34 +393,31 @@ static void rbd_finish_aiocb(rados_completion_t c, RADOSCB * rcb)
     int64_t r;
     int i;
 
-    if (rados_aio_is_complete(c)) {
-        acb->aiocnt--;
-        r = rados_aio_get_return_value(c);
-        rados_aio_set_callback(c, NULL, NULL);
-        rados_aio_release(c);
-        if (acb->write) {
-            acb->ret += r;
+    acb->aiocnt--;
+    r = rados_aio_get_return_value(c);
+    rados_aio_release(c);
+    if (acb->write) {
+        acb->ret += r;
+    } else {
+        if (r < 0) {
+            memset(rcb->buf, 0, rcb->segsize);
+            acb->ret += rcb->segsize;
+        } else if (r < rcb->segsize) {
+            memset(rcb->buf + r, 0, rcb->segsize - r);
+            acb->ret += rcb->segsize;
         } else {
-            if (r < 0) {
-                memset(rcb->buf, 0, rcb->segsize);
-                acb->ret += rcb->segsize;
-            } else if (r < rcb->segsize) {
-                memset(rcb->buf + r, 0, rcb->segsize - r);
-                acb->ret += rcb->segsize;
-            } else {
-                acb->ret += r;
-            }
-        }
-        qemu_free(rcb);
-        i = 0;
-        while ((acb->aiocnt == 0) && !acb->rccomplete && i < 5) {
-            usleep(100);
-            i++;
-        }
-        if ((acb->aiocnt == 0) && acb->rccomplete && acb->bh) {
-            qemu_bh_schedule(acb->bh);
+            acb->ret += r;
         }
     }
+    qemu_free(rcb);
+    i = 0;
+    while ((acb->aiocnt == 0) && !acb->rccomplete && i < 5) {
+        usleep(100);
+        i++;
+    }
+    if ((acb->aiocnt == 0) && acb->rccomplete && acb->bh) {
+        qemu_bh_schedule(acb->bh);
+    }
 }
 
 static void rbd_aio_bh_cb(void *opaque)
@@ -494,8 +491,8 @@ static BlockDriverAIOCB *rbd_aio_rw_vector(BlockDriverState * bs,
 
         acb->aiocnt++;
 
-        rados_aio_create_completion((rados_callback_t) rbd_finish_aiocb,
-                                    rcb, &c);
+        rados_aio_create_completion(rcb, (rados_callback_t) rbd_finish_aiocb,
+                                    NULL, &c);
         if (write) {
             rados_aio_write(s->pool, n, segoffs, buf, segsize, c);
         } else {
Signature · 7 lines
1.6.6.1


-- 
Christian Brunner                              MUC.DE e.V.
                                               Joseph-Dollinger-Bogen 14
                                               D-80807 Muenchen
#1 lore raw

This one should fix and remove the nasty usleep that handles the acb initialization race. I didn't verify that it actually works, so please let me know if there are any issues with it.

Thanks,
Yehuda

block/rbd.c +0 -1
index 3ebf285..7128e23 100644
@@ -56,7 +56,6 @@ typedef struct RBDAIOCB {
     int write;
     int64_t sector_num;
     int aiocnt;
-    int rccomplete;
 } RBDAIOCB;
 
 typedef struct RADOSCB {
@@ -391,11 +390,7 @@ static void rbd_finish_aiocb(rados_completion_t

c, RADOSCB * rcb)

     }
     qemu_free(rcb);
     i = 0;
-    while ((acb->aiocnt == 0) && !acb->rccomplete && i < 5) {
-        usleep(100);
-        i++;
-    }
-    if ((acb->aiocnt == 0) && acb->rccomplete && acb->bh) {
+    if ((acb->aiocnt == 0) && acb->bh) {
         qemu_bh_schedule(acb->bh);
     }
 }
@@ -425,7 +420,7 @@ static BlockDriverAIOCB
*rbd_aio_rw_vector(BlockDriverState * bs,
     RADOSCB *rcb;
     rados_completion_t c;
     char n[RBD_MAX_SEG_NAME_SIZE];
-    int64_t segnr, segoffs, segsize;
+    int64_t segnr, segoffs, segsize, last_segnr;
     int64_t off, size;
     char *buf;

@@ -437,7 +432,6 @@ static BlockDriverAIOCB
*rbd_aio_rw_vector(BlockDriverState * bs,

     acb->bounce = qemu_blockalign(bs, qiov->size);
     acb->aiocnt = 0;
     acb->ret = 0;

- acb->rccomplete = 0;

     if (!acb->bh) {
         acb->bh = qemu_bh_new(rbd_aio_bh_cb, acb);
@@ -455,6 +449,9 @@ static BlockDriverAIOCB
*rbd_aio_rw_vector(BlockDriverState * bs,
     segoffs = (int64_t) (off % s->objsize);
     segsize = (int64_t) (s->objsize - segoffs);

+ last_segnr = ((off + size - 1) / s->objsize);
+ acb->aiocnt = (last_segnr - segnr) + 1;
+

     while (size > 0) {
         if (size < segsize) {
             segsize = size;
@@ -469,8 +466,6 @@ static BlockDriverAIOCB
*rbd_aio_rw_vector(BlockDriverState * bs,
         rcb->segsize = segsize;
         rcb->buf = buf;

- acb->aiocnt++;
-

         rados_aio_create_completion(rcb, (rados_callback_t) rbd_finish_aiocb,
                                     NULL, &c);
         if (write) {
@@ -486,8 +481,6 @@ static BlockDriverAIOCB
*rbd_aio_rw_vector(BlockDriverState * bs,
         segnr++;
     }

- acb->rccomplete = 1;
-

     return &acb->common;

}

Quoted 85 lines · Christian Brunner

This patch uses the new librados aio callback function (from the unstable branch of ceph).

Christian
---
 block/rbd.c |   51 ++++++++++++++++++++++++---------------------------

 1 files changed, 24 insertions(+), 27 deletions(-)
block/rbd.c +24 -28
index 12a85dc..dfd2eca 100644
@@ -393,34 +393,31 @@ static void rbd_finish_aiocb(rados_completion_t c, RADOSCB * rcb)
     int64_t r;
     int i;
 
-    if (rados_aio_is_complete(c)) {
-        acb->aiocnt--;
-        r = rados_aio_get_return_value(c);
-        rados_aio_set_callback(c, NULL, NULL);
-        rados_aio_release(c);
-        if (acb->write) {
-            acb->ret += r;
+    acb->aiocnt--;
+    r = rados_aio_get_return_value(c);
+    rados_aio_release(c);
+    if (acb->write) {
+        acb->ret += r;
+    } else {
+        if (r < 0) {
+            memset(rcb->buf, 0, rcb->segsize);
+            acb->ret += rcb->segsize;
+        } else if (r < rcb->segsize) {
+            memset(rcb->buf + r, 0, rcb->segsize - r);
+            acb->ret += rcb->segsize;
         } else {
-            if (r < 0) {
-                memset(rcb->buf, 0, rcb->segsize);
-                acb->ret += rcb->segsize;
-            } else if (r < rcb->segsize) {
-                memset(rcb->buf + r, 0, rcb->segsize - r);
-                acb->ret += rcb->segsize;
-            } else {
-                acb->ret += r;
-            }
-        }
-        qemu_free(rcb);
-        i = 0;
-        while ((acb->aiocnt == 0) && !acb->rccomplete && i < 5) {
-            usleep(100);
-            i++;
-        }
-        if ((acb->aiocnt == 0) && acb->rccomplete && acb->bh) {
-            qemu_bh_schedule(acb->bh);
+            acb->ret += r;
         }
     }
+    qemu_free(rcb);
+    i = 0;
+    while ((acb->aiocnt == 0) && !acb->rccomplete && i < 5) {
+        usleep(100);
+        i++;
+    }
+    if ((acb->aiocnt == 0) && acb->rccomplete && acb->bh) {
+        qemu_bh_schedule(acb->bh);
+    }
  }
 
  static void rbd_aio_bh_cb(void *opaque)
@@ -494,8 +491,8 @@ static BlockDriverAIOCB *rbd_aio_rw_vector(BlockDriverState * bs,
 
         acb->aiocnt++;
 
-        rados_aio_create_completion((rados_callback_t) rbd_finish_aiocb,
-                                    rcb, &c);
+        rados_aio_create_completion(rcb, (rados_callback_t) rbd_finish_aiocb,
+                                    NULL, &c);
         if (write) {
             rados_aio_write(s->pool, n, segoffs, buf, segsize, c);
         } else {
--

1.6.6.1

Quoted 8 lines

--
Christian Brunner                              MUC.DE e.V. Joseph-Dollinger-Bogen 14 D-80807 Muenchen --
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Yehuda Sadeh Weinraub

This one should fix and remove the nasty usleep that handles the acb initialization race. I didn't verify that it actually works, so please let me know if there are any issues with it.

Thanks,
Yehuda

Perfect! - I wonder why I didn't think of this... ;-)

I think that you can commit the patches to git now.

Thanks,
Christian

#3 lore raw
Quoted 11 lines · Christian Brunner
Quoted 6 lines · Yehuda Sadeh Weinraub

This one should fix and remove the nasty usleep that handles the acb initialization race. I didn't verify that it actually works, so please let me know if there are any issues with it.

Thanks,
Yehuda

Perfect! - I wonder why I didn't think of this... ;-)

I think that you can commit the patches to git now.

Great, pushed.

Yehuda