From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKdZg-000885-UZ for qemu-devel@nongnu.org; Thu, 21 Aug 2014 21:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKdZa-0005EA-Pr for qemu-devel@nongnu.org; Thu, 21 Aug 2014 21:23:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25507) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKdZa-0005Dz-I5 for qemu-devel@nongnu.org; Thu, 21 Aug 2014 21:23:22 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7M1NL2m029681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 21 Aug 2014 21:23:21 -0400 Date: Fri, 22 Aug 2014 09:23:36 +0800 From: Fam Zheng Message-ID: <20140822012336.GB3410@T430.redhat.com> References: <1408622216-9578-1-git-send-email-famz@redhat.com> <1408622216-9578-2-git-send-email-famz@redhat.com> <53F5E289.8050703@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53F5E289.8050703@redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH 1/9] block: Add bdrv_aio_cancel_async List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi On Thu, 08/21 14:14, Paolo Bonzini wrote: > Il 21/08/2014 13:56, Fam Zheng ha scritto: > > + BlockDriverAIOCB *save = g_new(BlockDriverAIOCB, 1); > > + save->cb = acb->cb; > > + save->opaque = acb->opaque; > > + acb->cb = bdrv_aio_cancel_async_cb; > > + acb->opaque = acb; > > + acb->cancel_acb_save = save; > > No need for this extra field. You can make a struct with {acb->cb, > acb->opaque, acb} and pass it as the opaque. You also do not need to > allocate it on the heap, since everything is synchronous. > > > + > > + /* Use the synchronous version and hope our cb is called. */ > > + acb->aiocb_info->cancel(acb); > > Unfortunately, acb has been freed at this point Oops! > , so you'll be accessing > a dangling pointer. I think you need to modify all cancel > implementations. For example: > > - return whether they have called the callback > > - only free the acb if they have called the callback > > - otherwise, free the acb in bdrv_aio_cancel What about we save cb and opaque locally, and set acb->cb to a nop. When cancel is done we can call the original cb? Fam