From: Maxim Levitsky <mlevitsk@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Fam Zheng" <fam@euphon.net>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH v4 9/9] scsi/scsi_bus: fix races in REPORT LUNS
Date: Wed, 09 Sep 2020 11:20:24 +0300 [thread overview]
Message-ID: <b28a5a2bf78fdc563aa3b20d4cd264238545ef04.camel@redhat.com> (raw)
In-Reply-To: <20200908152740.GF7154@stefanha-x1.localdomain>
On Tue, 2020-09-08 at 16:27 +0100, Stefan Hajnoczi wrote:
> On Mon, Aug 31, 2020 at 06:01:24PM +0300, Maxim Levitsky wrote:
> > Currently scsi_target_emulate_report_luns iterates
> > over child devices list twice, and there is guarantee, that
> > it will not be changed meanwhile.
> >
> > This reason for two loops is that it needs to know how much memory
> > to allocate.
> >
> > Avoid this by iterating once, and allocating the memory for the output
> > dynamically with reserving enought memory so that in practice it won't
> > be reallocated often.
> >
> > Bugzilla for reference: https://bugzilla.redhat.com/show_bug.cgi?id=1866707
>
> "Buglink:" is the tag name documented in
> https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_message
Noted
>
> > static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
> > {
> > BusChild *kid;
> > - int i, len, n;
> > int channel, id;
> > - bool found_lun0;
> > + uint8_t tmp[8] = {0};
> > + int len = 0;
> > +
> > + /* reserve space for 63 LUNs*/
> > + GByteArray *buf = g_byte_array_sized_new(512);
> >
> > if (r->req.cmd.xfer < 16) {
> > return false;
>
> buf is leaked.
Oops, will fix
>
> > @@ -460,46 +466,36 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
> > }
> > channel = r->req.dev->channel;
> > id = r->req.dev->id;
> > - found_lun0 = false;
> > - n = 0;
> >
> > - rcu_read_lock();
> >
> > - QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) {
> > - DeviceState *qdev = kid->child;
> > - SCSIDevice *dev = SCSI_DEVICE(qdev);
> > + /* add size (will be updated later to correct value */
> > + g_byte_array_append(buf, tmp, 8);
> > + len += 8;
>
> Can g_byte_array_size() be used instead of keeping a len local variable?
Glib don't seem to have this function, I checked the docs.
Its seems that they want to convert it to GBytes which is basically immutible verion
of GByteArray and it does have g_bytes_get_size.
I decided that a local variable while ugly is still better that this.
I haven't wrote much code that uses Glib, so I might have missed something though.
I had read this reference:
https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Best regards,
Maxim Levitsky
next prev parent reply other threads:[~2020-09-09 8:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 15:01 [PATCH v4 0/9] Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 1/9] scsi/scsi_bus: switch search direction in scsi_device_find Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 2/9] rcu: Implement drain_call_rcu Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 3/9] device_core: use drain_call_rcu in in hmp_device_del/qmp_device_add Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 4/9] device-core: use RCU for list of childs of a bus Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 5/9] device-core: use atomic_set on .realized property Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 6/9] scsi/scsi-bus: scsi_device_find: don't return unrealized devices Maxim Levitsky
2020-09-08 15:00 ` Stefan Hajnoczi
2020-09-09 8:15 ` Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 7/9] scsi/scsi_bus: Add scsi_device_get Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 8/9] virtio-scsi: use scsi_device_get Maxim Levitsky
2020-08-31 15:01 ` [PATCH v4 9/9] scsi/scsi_bus: fix races in REPORT LUNS Maxim Levitsky
2020-09-01 9:15 ` Maxim Levitsky
2020-09-08 15:27 ` Stefan Hajnoczi
2020-09-09 8:20 ` Maxim Levitsky [this message]
2020-09-11 15:12 ` Stefan Hajnoczi
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=b28a5a2bf78fdc563aa3b20d4cd264238545ef04.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).