From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LjPV4-0001t8-EB for qemu-devel@nongnu.org; Mon, 16 Mar 2009 22:57:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LjPUz-0001sw-IX for qemu-devel@nongnu.org; Mon, 16 Mar 2009 22:57:53 -0400 Received: from [199.232.76.173] (port=50450 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LjPUz-0001st-Dp for qemu-devel@nongnu.org; Mon, 16 Mar 2009 22:57:49 -0400 Received: from phong.sigbus.net ([65.49.35.42]:39748) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LjPUy-0008CI-LX for qemu-devel@nongnu.org; Mon, 16 Mar 2009 22:57:48 -0400 Received: from [192.168.0.3] (c-71-202-202-194.hsd1.ca.comcast.net [71.202.202.194]) by phong.sigbus.net (Postfix) with ESMTPSA id E776095C0DA for ; Mon, 16 Mar 2009 19:57:45 -0700 (PDT) From: Nolan Content-Type: text/plain Date: Mon, 16 Mar 2009 19:57:45 -0700 Message-Id: <1237258665.15350.67.camel@voxel> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] add bdrv->create function for host_device Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" "qemu-img convert" tries to create the destination image by calling it's ->create function. host_devices do not currently have one, since host devices are not created like normal images are. A reasonable analog of create for host devices is verifying that they have the appropriate properties. This patch adds that verification. It also fixes a typo that caused qemu-img to print the wrong device type in the error message informing the user that the destination device did not support creation. Signed-off-by: Nolan Leake sigbus.net> Index: block-raw-posix.c =================================================================== --- block-raw-posix.c (revision 6718) +++ block-raw-posix.c (working copy) @@ -1132,6 +1132,32 @@ return ioctl(s->fd, req, buf); } + +static int hdev_create(const char *filename, int64_t total_size, + const char *backing_file, int flags) +{ + int fd; + int ret = 0; + struct stat stat_buf; + + if (flags || backing_file) + return -ENOTSUP; + + fd = open(filename, O_WRONLY | O_BINARY); + if (fd < 0) + return -EIO; + + if (fstat(fd, &stat_buf) < 0) + ret = -EIO; + else if (!S_ISBLK(stat_buf.st_mode)) + ret = -EIO; + else if (lseek(fd, 0, SEEK_END) < total_size * 512) + ret = -ENOSPC; + + close(fd); + return ret; +} + #else static int fd_open(BlockDriverState *bs) @@ -1163,6 +1189,12 @@ { return -ENOTSUP; } + +static int hdev_create(const char *filename, int64_t total_size, + const char *backing_file, int flags) +{ + return -ENOTSUP; +} #endif /* !linux */ BlockDriver bdrv_host_device = { @@ -1173,7 +1205,7 @@ NULL, NULL, raw_close, - NULL, + hdev_create, raw_flush, #ifdef CONFIG_AIO Index: qemu-img.c =================================================================== --- qemu-img.c (revision 6718) +++ qemu-img.c (working copy) @@ -477,7 +477,7 @@ ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags); if (ret < 0) { if (ret == -ENOTSUP) { - error("Formatting not supported for file format '%s'", fmt); + error("Formatting not supported for file format '%s'", out_fmt); } else { error("Error while formatting '%s'", out_filename); }