Skip to content

Commit

Permalink
async file I/O API
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2075 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
bellard committed Aug 1, 2006
1 parent 7954c73 commit 83f6409
Show file tree
Hide file tree
Showing 16 changed files with 1,898 additions and 456 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
version 0.8.3:

- Support for relative paths in backing files for disk images
- Async file I/O API

version 0.8.2:

- ACPI support
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ else
DOCS=
endif

ifndef CONFIG_DARWIN
ifndef CONFIG_WIN32
ifndef CONFIG_SOLARIS
LIBS+=-lrt
endif
endif
endif

all: $(TOOLS) $(DOCS) recurse-all

subdir-%: dyngen$(EXESUF)
$(MAKE) -C $(subst subdir-,,$@) all

recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS))
qemu-img$(EXESUF): qemu-img.c block.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c

qemu-img$(EXESUF): qemu-img.c block.c block-raw.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c
$(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)

dyngen$(EXESUF): dyngen.c
Expand Down
3 changes: 2 additions & 1 deletion Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ ifeq ($(ARCH),alpha)
endif

# must use static linking to avoid leaving stuff in virtual address space
VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o loader.o
VL_OBJS=vl.o osdep.o readline.o monitor.o pci.o console.o loader.o
VL_OBJS+=block.o block-raw.o
VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
ifdef CONFIG_WIN32
VL_OBJS+=tap-win32.o
Expand Down
6 changes: 3 additions & 3 deletions block-bochs.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ static int bochs_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0;
}

static int bochs_open(BlockDriverState *bs, const char *filename)
static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVBochsState *s = bs->opaque;
int fd, i;
struct bochs_header bochs;

fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
fd = open(filename, O_RDWR | O_BINARY);
if (fd < 0) {
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions block-cloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ static int cloop_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0;
}

static int cloop_open(BlockDriverState *bs, const char *filename)
static int cloop_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVCloopState *s = bs->opaque;
uint32_t offsets_size,max_compressed_block_size=1,i;

s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
s->fd = open(filename, O_RDONLY | O_BINARY);
if (s->fd < 0)
return -1;
return -errno;
bs->read_only = 1;

/* read header */
Expand Down
38 changes: 17 additions & 21 deletions block-cow.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0;
}

static int cow_open(BlockDriverState *bs, const char *filename)
static int cow_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVCowState *s = bs->opaque;
int fd;
Expand Down Expand Up @@ -93,22 +93,6 @@ static int cow_open(BlockDriverState *bs, const char *filename)
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
cow_header.backing_file);

#if 0
if (cow_header.backing_file[0] != '\0') {
if (stat(cow_header.backing_file, &st) != 0) {
fprintf(stderr, "%s: could not find original disk image '%s'\n", filename, cow_header.backing_file);
goto fail;
}
if (st.st_mtime != be32_to_cpu(cow_header.mtime)) {
fprintf(stderr, "%s: original raw disk image '%s' does not match saved timestamp\n", filename, cow_header.backing_file);
goto fail;
}
fd = open(cow_header.backing_file, O_RDONLY | O_LARGEFILE);
if (fd < 0)
goto fail;
bs->fd = fd;
}
#endif
/* mmap the bitmap */
s->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
s->cow_bitmap_addr = mmap(get_mmap_addr(s->cow_bitmap_size),
Expand Down Expand Up @@ -179,8 +163,15 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num,
if (ret != n * 512)
return -1;
} else {
if (bs->backing_hd) {
/* read from the base image */
ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
if (ret < 0)
return -1;
} else {
memset(buf, 0, n * 512);
}
}
nb_sectors -= n;
sector_num += n;
buf += n * 512;
Expand Down Expand Up @@ -220,26 +211,31 @@ static int cow_create(const char *filename, int64_t image_sectors,
if (flags)
return -ENOTSUP;

cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
if (cow_fd < 0)
return -1;
memset(&cow_header, 0, sizeof(cow_header));
cow_header.magic = cpu_to_be32(COW_MAGIC);
cow_header.version = cpu_to_be32(COW_VERSION);
if (image_filename) {
/* Note: if no file, we put a dummy mtime */
cow_header.mtime = cpu_to_be32(0);

fd = open(image_filename, O_RDONLY | O_BINARY);
if (fd < 0) {
close(cow_fd);
return -1;
goto mtime_fail;
}
if (fstat(fd, &st) != 0) {
close(fd);
return -1;
goto mtime_fail;
}
close(fd);
cow_header.mtime = cpu_to_be32(st.st_mtime);
realpath(image_filename, cow_header.backing_file);
mtime_fail:
pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file),
image_filename);
}
cow_header.sectorsize = cpu_to_be32(512);
cow_header.size = cpu_to_be64(image_sectors * 512);
Expand Down
8 changes: 4 additions & 4 deletions block-dmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ static off_t read_uint32(int fd)
return be32_to_cpu(buffer);
}

static int dmg_open(BlockDriverState *bs, const char *filename)
static int dmg_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVDMGState *s = bs->opaque;
off_t info_begin,info_end,last_in_offset,last_out_offset;
uint32_t count;
uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;

s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
s->fd = open(filename, O_RDONLY | O_BINARY);
if (s->fd < 0)
return -1;
return -errno;
bs->read_only = 1;
s->n_chunks = 0;
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
Expand All @@ -93,7 +93,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename)
close(s->fd);
/* open raw instead */
bs->drv=&bdrv_raw;
return bs->drv->bdrv_open(bs,filename);
return bs->drv->bdrv_open(bs, filename, flags);
}
info_begin=read_off(s->fd);
if(info_begin==0)
Expand Down
Loading

0 comments on commit 83f6409

Please sign in to comment.