From: Christoph Hellwig <hch@lst.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/6] bochs: use qemu block API
Date: Tue, 4 May 2010 12:44:21 +0200 [thread overview]
Message-ID: <20100504104421.GB6388@lst.de> (raw)
In-Reply-To: <20100504104351.GA6342@lst.de>
Use bdrv_pwrite to access the backing device instead of pread, and
convert the driver to implementing the bdrv_open method which gives
it an already opened BlockDriverState for the underlying device.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: qemu-kevin/block/bochs.c
===================================================================
--- qemu-kevin.orig/block/bochs.c 2010-05-03 12:42:19.385274599 +0200
+++ qemu-kevin/block/bochs.c 2010-05-03 12:48:54.434007033 +0200
@@ -80,8 +80,6 @@ struct bochs_header {
};
typedef struct BDRVBochsState {
- int fd;
-
uint32_t *catalog_bitmap;
int catalog_size;
@@ -109,23 +107,16 @@ static int bochs_probe(const uint8_t *bu
return 0;
}
-static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
+static int bochs_open(BlockDriverState *bs, int flags)
{
BDRVBochsState *s = bs->opaque;
- int fd, i;
+ int i;
struct bochs_header bochs;
struct bochs_header_v1 header_v1;
- fd = open(filename, O_RDONLY | O_BINARY);
- if (fd < 0) {
- return -1;
- }
-
bs->read_only = 1; // no write support yet
- s->fd = fd;
-
- if (pread(fd, &bochs, sizeof(bochs), 0) != sizeof(bochs)) {
+ if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) {
goto fail;
}
@@ -146,8 +137,8 @@ static int bochs_open(BlockDriverState *
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (pread(s->fd, s->catalog_bitmap, s->catalog_size * 4,
- le32_to_cpu(bochs.header)) != s->catalog_size * 4)
+ if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
+ s->catalog_size * 4) != s->catalog_size * 4)
goto fail;
for (i = 0; i < s->catalog_size; i++)
le32_to_cpus(&s->catalog_bitmap[i]);
@@ -161,7 +152,6 @@ static int bochs_open(BlockDriverState *
return 0;
fail:
- close(fd);
return -1;
}
@@ -184,8 +174,8 @@ static int64_t seek_to_sector(BlockDrive
(s->extent_blocks + s->bitmap_blocks));
/* read in bitmap for current extent */
- if (pread(s->fd, &bitmap_entry, 1, bitmap_offset + (extent_offset / 8))
- != 1) {
+ if (bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
+ &bitmap_entry, 1) != 1) {
return -1;
}
@@ -199,13 +189,12 @@ static int64_t seek_to_sector(BlockDrive
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
- BDRVBochsState *s = bs->opaque;
int ret;
while (nb_sectors > 0) {
int64_t block_offset = seek_to_sector(bs, sector_num);
if (block_offset >= 0) {
- ret = pread(s->fd, buf, 512, block_offset);
+ ret = bdrv_pread(bs->file, block_offset, buf, 512);
if (ret != 512) {
return -1;
}
@@ -222,14 +211,13 @@ static void bochs_close(BlockDriverState
{
BDRVBochsState *s = bs->opaque;
qemu_free(s->catalog_bitmap);
- close(s->fd);
}
static BlockDriver bdrv_bochs = {
.format_name = "bochs",
.instance_size = sizeof(BDRVBochsState),
.bdrv_probe = bochs_probe,
- .bdrv_file_open = bochs_open,
+ .bdrv_open = bochs_open,
.bdrv_read = bochs_read,
.bdrv_close = bochs_close,
};
next prev parent reply other threads:[~2010-05-04 10:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-04 10:43 [Qemu-devel] simple block driver cleanups Christoph Hellwig
2010-05-04 10:44 ` Christoph Hellwig [this message]
2010-05-04 10:44 ` [Qemu-devel] [PATCH 3/6] cloop: use pread Christoph Hellwig
2010-05-04 10:44 ` [Qemu-devel] [PATCH 4/6] cloop: use qemu block API Christoph Hellwig
2010-05-04 10:45 ` [Qemu-devel] [PATCH 5/6] parallels: use pread Christoph Hellwig
2010-05-05 14:19 ` Kevin Wolf
2010-05-05 18:11 ` Christoph Hellwig
2010-05-04 10:45 ` [Qemu-devel] [PATCH 6/6] parallels: use qemu block API Christoph Hellwig
2010-05-04 12:38 ` [Qemu-devel] simple block driver cleanups Kevin Wolf
2010-05-04 13:22 ` Christoph Hellwig
2010-05-05 14:28 ` Kevin Wolf
2010-05-05 18:10 ` Christoph Hellwig
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=20100504104421.GB6388@lst.de \
--to=hch@lst.de \
--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).