]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
block/nfs: fix potential segfault on early callback
authorPeter Lieven <pl@kamp.de>
Tue, 10 Jun 2014 07:42:47 +0000 (09:42 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 16 Jun 2014 09:23:19 +0000 (17:23 +0800)
it will happen in the future that the callback of a libnfs call
directly invokes the callback. In this case we end up in a segfault
because the NFSRPC is gone when we the BH is scheduled.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/nfs.c

index bd9177f3ae7a85e8de276cdb126cde5dba740d03..e282f8de3794d561d9bcce167dc485482d037632 100644 (file)
@@ -95,6 +95,7 @@ static void nfs_co_init_task(NFSClient *client, NFSRPC *task)
 static void nfs_co_generic_bh_cb(void *opaque)
 {
     NFSRPC *task = opaque;
+    task->complete = 1;
     qemu_bh_delete(task->bh);
     qemu_coroutine_enter(task->co, NULL);
 }
@@ -104,7 +105,6 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data,
                   void *private_data)
 {
     NFSRPC *task = private_data;
-    task->complete = 1;
     task->ret = ret;
     if (task->ret > 0 && task->iov) {
         if (task->ret <= task->iov->size) {
@@ -123,6 +123,8 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data,
         task->bh = aio_bh_new(task->client->aio_context,
                               nfs_co_generic_bh_cb, task);
         qemu_bh_schedule(task->bh);
+    } else {
+        task->complete = 1;
     }
 }