From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:45169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOrFj-0000Zy-AP for qemu-devel@nongnu.org; Tue, 24 May 2011 09:02:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOrFi-0001cW-JJ for qemu-devel@nongnu.org; Tue, 24 May 2011 09:02:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOrFi-0001cO-8w for qemu-devel@nongnu.org; Tue, 24 May 2011 09:02:26 -0400 Message-ID: <4DDBAD07.6070904@redhat.com> Date: Tue, 24 May 2011 15:05:11 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <1305630067-2119-1-git-send-email-pbonzini@redhat.com> <1305630067-2119-14-git-send-email-pbonzini@redhat.com> <20110520160422.GM4466@lst.de> <4DD6A839.1020104@redhat.com> In-Reply-To: <4DD6A839.1020104@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 13/21] scsi: do not call send_command directly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Christoph Hellwig , qemu-devel@nongnu.org Am 20.05.2011 19:43, schrieb Paolo Bonzini: > On 05/20/2011 06:04 PM, Christoph Hellwig wrote: >>> -void scsi_req_enqueue(SCSIRequest *req) >>> +int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf) >>> { >>> + int32_t rc; >>> assert(!req->enqueued); >>> scsi_req_ref(req); >>> req->enqueued = true; >>> QTAILQ_INSERT_TAIL(&req->dev->requests, req, next); >>> + >>> + /* Make sure the request doesn't disappear under send_command's feet. */ >>> + scsi_req_ref(req); >>> + rc = req->dev->info->send_command(req, buf); >>> + scsi_req_unref(req); >>> + return rc; >> >> How would it disappear given that we grabbed another reference just before? > > Welcome to the wonderful world of nested callbacks. :( > > Suppose send_command completes a request. scsi_req_complete then > dequeues it (which undoes the reference above), and calls the device who > owned it. The device who owned the request then presumably NULLs a > pointer and drops the last reference. The request is then freed. Maybe the callback should be done from a BH then? It sounds like this could cause more bugs than what you're fixing here. Kevin