qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: john cooper <john.cooper@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: john.cooper@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] Add serial number support for virtio_blk
Date: Tue, 23 Jun 2009 08:42:32 -0400	[thread overview]
Message-ID: <4A40CDB8.8030906@redhat.com> (raw)
In-Reply-To: <4A3FD176.4010600@codemonkey.ws>

Anthony Liguori wrote:
> john cooper wrote:
>>
>>      s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk",
>>                                         PCI_VENDOR_ID_REDHAT_QUMRANET,
>> @@ -369,6 +420,10 @@ void *virtio_blk_init(PCIBus *bus,
>> BlockDriverState *bs)
>>      s->vdev.reset = virtio_blk_reset;
>>      s->bs = bs;
>>      s->rq = NULL;
>> +    if (strlen(ps = (char *)drive_get_serial(bs)))
>> +        strncpy(s->serial_str, ps, sizeof(s->serial_str));
>> +    else
>> +        snprintf(s->serial_str, sizeof(s->serial_str), "0");
>>   
> 
> ps = drive_get_serial(bs);
> snprintf(s->serial_str, sizeof(s->serial_str), "%s", *ps ? ps : "0");
> 
> strncpy() doesn't do what you think it does.  It doesn't always null
> terminate.

In general yes, but here it is contrived to copy a
terminating nul.  The string is maintained as a 21
byte [BLOCK_SERIAL_STRLEN + 1] char[] and the
incoming cmdline serial string is hard null terminated
by get_opt_value().  Above, strncpy() into a sizeof(21)
byte s->serial_str, will copy the trailing nul.
However when this data is exported by the guest driver
in a char[20] sized structure the trailing nul may be
omitted.

The same logic may be found in IDE and SCSI counterparts.
I agree it's not the most obvious approach, and this
clause should ideally be factored out as common to
all cases once we have the patch under discussion
resolved.

> Doesn't serial_str need to be saved in the savevm format?

Possibly, but currently it isn't being captured in
IDE nor SCSI AFAICT.  I'll take a closer look.

-john

-- 
john.cooper@redhat.com

  reply	other threads:[~2009-06-23 12:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 18:26 [Qemu-devel] [PATCH] Add serial number support for virtio_blk john cooper
2009-06-22 18:46 ` [Qemu-devel] " Anthony Liguori
2009-06-23 12:42   ` john cooper [this message]
2009-06-22 19:05 ` Anthony Liguori
2009-06-22 19:30   ` Gleb Natapov
2009-06-22 20:28     ` Anthony Liguori
2009-06-22 20:38       ` Gleb Natapov
2009-06-22 20:42         ` Daniel P. Berrange
2009-06-23  8:22           ` Gleb Natapov
2009-06-23 12:44   ` john cooper

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=4A40CDB8.8030906@redhat.com \
    --to=john.cooper@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /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).