qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PULL 43/45] scsi: always call notifier on async cancel


From: Fam Zheng
Subject: Re: [Qemu-devel] [PULL 43/45] scsi: always call notifier on async cancellation
Date: Fri, 18 Dec 2015 15:51:37 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, 12/18 07:05, Paolo Bonzini wrote:
> 
> 
> On 18/12/2015 01:57, Fam Zheng wrote:
> > Oh hang on, in scsi_req_dequeue, if req->enqueued is already false, the
> > matching scsi_req_unref is never called.
> 
> The matching unref for scsi_req_cancel_async's ref is in 
> scsi_req_cancel_complete.  You're right that there is a leak if
> we get to the second cancellation with req->aiocb, and we should
> never get there with !req->aiocb.  So the patch is wrong, but
> we should add some documentation instead of plainly reverting it:
> 
> diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
> index 00bddc9..378bf4d 100644
> --- a/hw/scsi/scsi-bus.c
> +++ b/hw/scsi/scsi-bus.c
> @@ -1759,6 +1759,17 @@ void scsi_req_cancel_async(SCSIRequest *req, Notifier 
> *notifier)
>      if (notifier) {
>          notifier_list_add(&req->cancel_notifiers, notifier);
>      }
> +    if (req->io_canceled) {
> +        /* Canceling a second time after scsi_req_cancel_complete
> +         * is a programming error, hence a blk_aio_cancel_async is
> +         * pending; when it finishes, scsi_req_cancel_complete
> +         * will be called and will call the notifier we just
> +         * added.  Just wait for that.
> +         */
> +        assert(req->aiocb);
> +        return;
> +    }
> +    /* Dropped in scsi_req_cancel_complete.  */
>      scsi_req_ref(req);
>      scsi_req_dequeue(req);
>      req->io_canceled = true;
> @@ -1775,6 +1784,8 @@ void scsi_req_cancel(SCSIRequest *req)
>      if (!req->enqueued) {
>          return;
>      }
> +    assert(!req->io_canceled);
> +    /* Dropped in scsi_req_cancel_complete.  */
>      scsi_req_ref(req);
>      scsi_req_dequeue(req);
>      req->io_canceled = true;
> 
> Does this look sane?
> 

Yes, it looks correct to me.

Fam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]