qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Peter Lieven <pl@kamp.de>,
	"open list:iSCSI" <qemu-block@nongnu.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2] iscsi: use scsi_create_task()
Date: Fri, 28 Jul 2017 17:52:08 +0000	[thread overview]
Message-ID: <CAJ+F1CJrki3DvYX_oOR++n_r8_Uai9OB+LiNyDnBtiU5qebtbA@mail.gmail.com> (raw)
In-Reply-To: <ff7e40d0-bf1f-e4e5-1844-f1f61e6ab50f@redhat.com>

On Fri, Jul 28, 2017 at 6:58 PM Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 28/07/2017 18:30, Marc-André Lureau wrote:
> > The function does the same initialization, and matches with
> > scsi_free_scsi_task() usage, and qemu doesn't need to know the
> > allocator details.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  block/iscsi.c | 30 +++++++++++++++---------------
> >  1 file changed, 15 insertions(+), 15 deletions(-)
>
> Stupid question: what's the benefit?


scsi_create/scsi_free is a library API. If they have their own allocator,
we better use it, or it may easily break, no?


> Change malloc to g_new0 in the
> existing code, and we even make it shorter...
>

replacing malloc with g_new is the subject of another upcoming series :) (
https://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/UseGnewCheck.cpp
)


>
> Paolo
>
> > v2:
> >  - set cdb_size if API_VERSION < 20150510
> >
> > diff --git a/block/iscsi.c b/block/iscsi.c
> > index d557c99668..9449c90631 100644
> > --- a/block/iscsi.c
> > +++ b/block/iscsi.c
> > @@ -1013,6 +1013,7 @@ static BlockAIOCB
> *iscsi_aio_ioctl(BlockDriverState *bs,
> >      struct iscsi_context *iscsi = iscsilun->iscsi;
> >      struct iscsi_data data;
> >      IscsiAIOCB *acb;
> > +    int xfer_dir;
> >
> >      acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque);
> >
> > @@ -1034,31 +1035,30 @@ static BlockAIOCB
> *iscsi_aio_ioctl(BlockDriverState *bs,
> >          return NULL;
> >      }
> >
> > -    acb->task = malloc(sizeof(struct scsi_task));
> > -    if (acb->task == NULL) {
> > -        error_report("iSCSI: Failed to allocate task for scsi command.
> %s",
> > -                     iscsi_get_error(iscsi));
> > -        qemu_aio_unref(acb);
> > -        return NULL;
> > -    }
> > -    memset(acb->task, 0, sizeof(struct scsi_task));
> > -
> >      switch (acb->ioh->dxfer_direction) {
> >      case SG_DXFER_TO_DEV:
> > -        acb->task->xfer_dir = SCSI_XFER_WRITE;
> > +        xfer_dir = SCSI_XFER_WRITE;
> >          break;
> >      case SG_DXFER_FROM_DEV:
> > -        acb->task->xfer_dir = SCSI_XFER_READ;
> > +        xfer_dir = SCSI_XFER_READ;
> >          break;
> >      default:
> > -        acb->task->xfer_dir = SCSI_XFER_NONE;
> > +        xfer_dir = SCSI_XFER_NONE;
> >          break;
> >      }
> >
> > -    acb->task->cdb_size = acb->ioh->cmd_len;
> > -    memcpy(&acb->task->cdb[0], acb->ioh->cmdp, acb->ioh->cmd_len);
> > -    acb->task->expxferlen = acb->ioh->dxfer_len;
> > +    acb->task = scsi_create_task(acb->ioh->cmd_len, acb->ioh->cmdp,
> > +                                 xfer_dir, acb->ioh->dxfer_len);
> > +    if (acb->task == NULL) {
> > +        error_report("iSCSI: Failed to allocate task for scsi command.
> %s",
> > +                     iscsi_get_error(iscsi));
> > +        qemu_aio_unref(acb);
> > +        return NULL;
> > +    }
> >
> > +#if LIBISCSI_API_VERSION < 20150510
> > +    acb->task->cdb_size = acb->ioh->cmd_len; /* fixed in libiscsi
> 1.13.0 */
> > +#endif
> >      data.size = 0;
> >      qemu_mutex_lock(&iscsilun->mutex);
> >      if (acb->task->xfer_dir == SCSI_XFER_WRITE) {
> >
>
>
> --
Marc-André Lureau

  reply	other threads:[~2017-07-28 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-28 16:30 [Qemu-devel] [PATCH v2] iscsi: use scsi_create_task() Marc-André Lureau
2017-07-28 16:58 ` Paolo Bonzini
2017-07-28 17:52   ` Marc-André Lureau [this message]
2017-08-01 13:03     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ+F1CJrki3DvYX_oOR++n_r8_Uai9OB+LiNyDnBtiU5qebtbA@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).