From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33958 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKYA5-0003uY-T8 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 10:46:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKYA4-0000Yz-J3 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 10:46:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58229) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKYA4-0000Ym-B6 for qemu-devel@nongnu.org; Fri, 04 Jun 2010 10:46:16 -0400 Message-ID: <4C091175.4010102@redhat.com> Date: Fri, 04 Jun 2010 16:45:09 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support References: <4BAAF573.5000109@redhat.com> <4C07FDE3.3020905@codemonkey.ws> In-Reply-To: <4C07FDE3.3020905@codemonkey.ws> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: john cooper , Rusty Russell , Marc Haber , qemu-devel@nongnu.org Am 03.06.2010 21:09, schrieb Anthony Liguori: > On 03/25/2010 12:32 AM, john cooper wrote: >> Add virtio-blk device id (s/n) support via virtio request. >> Remove artifacts of pci and ATA_IDENTIFY implementation >> relative to prior versions. >> >> Signed-off-by: john cooper >> --- >> >> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c >> index 9915840..358b0af 100644 >> --- a/hw/virtio-blk.c >> +++ b/hw/virtio-blk.c >> @@ -19,6 +19,8 @@ >> # include >> #endif >> >> +#define min(a,b) ((a)< (b) ? (a) : (b)) >> > > We already have MIN(). > >> + >> typedef struct VirtIOBlock >> { >> VirtIODevice vdev; >> @@ -28,6 +30,7 @@ typedef struct VirtIOBlock >> QEMUBH *bh; >> BlockConf *conf; >> unsigned short sector_mask; >> + char sn[BLOCK_SERIAL_STRLEN]; >> } VirtIOBlock; >> >> static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) >> @@ -317,6 +320,12 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req, >> virtio_blk_handle_flush(req); >> } else if (req->out->type& VIRTIO_BLK_T_SCSI_CMD) { >> virtio_blk_handle_scsi(req); >> + } else if (req->out->type& VIRTIO_BLK_T_GET_ID) { >> + VirtIOBlock *s = req->dev; >> + >> + memcpy(req->elem.in_sg[0].iov_base, s->sn, >> + min(req->elem.in_sg[0].iov_len, sizeof(s->sn))); >> + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); >> } else if (req->out->type& VIRTIO_BLK_T_OUT) { >> qemu_iovec_init_external(&req->qiov,&req->elem.out_sg[1], >> req->elem.out_num - 1); >> @@ -496,6 +505,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf) >> bdrv_guess_geometry(s->bs,&cylinders,&heads,&secs); >> bdrv_set_geometry_hint(s->bs, cylinders, heads, secs); >> >> + strncpy(s->sn, drive_get_serial(s->bs), sizeof (s->sn)); >> + >> > > Friends don't let friends use strncpy(). > > This actually will result in a non-NULL terminated string if > drive_get_serial() returns a string larger than s->sn. Use snprintf() > instead. Isn't this what we have pstrcpy for? Kevin