From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MJ5Nw-0004cU-Db for qemu-devel@nongnu.org; Tue, 23 Jun 2009 08:46:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MJ5Nr-0004ai-AA for qemu-devel@nongnu.org; Tue, 23 Jun 2009 08:45:59 -0400 Received: from [199.232.76.173] (port=40431 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MJ5Nr-0004aZ-6h for qemu-devel@nongnu.org; Tue, 23 Jun 2009 08:45:55 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59567) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MJ5Nq-0006Zm-JR for qemu-devel@nongnu.org; Tue, 23 Jun 2009 08:45:54 -0400 Message-ID: <4A40CDB8.8030906@redhat.com> Date: Tue, 23 Jun 2009 08:42:32 -0400 From: john cooper MIME-Version: 1.0 References: <4A3FCCEB.1080603@redhat.com> <4A3FD176.4010600@codemonkey.ws> In-Reply-To: <4A3FD176.4010600@codemonkey.ws> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] Add serial number support for virtio_blk List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: john.cooper@redhat.com, qemu-devel@nongnu.org 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