From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] Add an in-memory block device
Date: Wed, 05 Dec 2007 16:05:18 -0600 [thread overview]
Message-ID: <4757209E.4020102@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 102 bytes --]
This is a generic in-memory block device. It is needed by the next patch.
Regards,
Anthony Liguori
[-- Attachment #2: mem-block-dev.diff --]
[-- Type: text/x-patch, Size: 3553 bytes --]
Index: qemu/Makefile
===================================================================
--- qemu.orig/Makefile 2007-12-05 15:39:09.000000000 -0600
+++ qemu/Makefile 2007-12-05 15:39:39.000000000 -0600
@@ -40,7 +40,7 @@
BLOCK_OBJS=cutils.o
BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o
BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
-BLOCK_OBJS+=block-qcow2.o block-parallels.o
+BLOCK_OBJS+=block-qcow2.o block-parallels.o block-mem.o
######################################################################
# libqemu_common.a: Target indepedent part of system emulation. The
Index: qemu/block-mem.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ qemu/block-mem.c 2007-12-05 15:54:02.000000000 -0600
@@ -0,0 +1,99 @@
+/*
+ * In-memory block driver
+ *
+ * Copyright IBM, Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "block_int.h"
+
+typedef struct BDRVMemState {
+ void *mem;
+ size_t size;
+} BDRVMemState;
+
+static int mem_probe(const uint8_t *buf, int buf_size, const char *filename)
+{
+ return 0;
+}
+
+static int mem_open(BlockDriverState *bs, const char *filename, int flags)
+{
+ return -1;
+}
+
+int bdrv_mem_open(BlockDriverState *bs, size_t size)
+{
+ BDRVMemState *s;
+
+ bs->read_only = 0;
+ bs->is_temporary = 0;
+ bs->encrypted = 0;
+ pstrcpy(bs->filename, sizeof(bs->filename), "<mem>");
+ bs->drv = &bdrv_mem;
+ bs->total_sectors = ((size + 511) & ~511) / 512;
+
+ bs->opaque = qemu_mallocz(bdrv_mem.instance_size);
+ if (bs->opaque == NULL)
+ return -1;
+
+ s = bs->opaque;
+ s->mem = qemu_mallocz(size);
+ if (s->mem == NULL)
+ return -1;
+ s->size = size;
+
+ return 0;
+}
+
+static int mem_read(BlockDriverState *bs, int64_t sector_num,
+ uint8_t *buf, int nb_sectors)
+{
+ BDRVMemState *s = bs->opaque;
+ size_t size;
+
+ sector_num = MIN(sector_num, bs->total_sectors - 1);
+ size = MIN(s->size - (sector_num * 512), nb_sectors * 512);
+
+ memcpy(buf, s->mem + (sector_num * 512), size);
+
+ return 0;
+}
+
+static int mem_write(BlockDriverState *bs, int64_t sector_num,
+ const uint8_t *buf, int nb_sectors)
+{
+ BDRVMemState *s = bs->opaque;
+ size_t size;
+
+ sector_num = MIN(sector_num, bs->total_sectors - 1);
+ size = MIN(s->size - (sector_num * 512), nb_sectors * 512);
+
+ memcpy(s->mem + (sector_num * 512), buf, size);
+
+ return 0;
+}
+
+static void mem_close(BlockDriverState *bs)
+{
+ BDRVMemState *s = bs->opaque;
+
+ qemu_free(s->mem);
+}
+
+BlockDriver bdrv_mem = {
+ "mem",
+ sizeof(BDRVMemState),
+ mem_probe,
+ mem_open,
+ mem_read,
+ mem_write,
+ mem_close,
+};
Index: qemu/block.h
===================================================================
--- qemu.orig/block.h 2007-12-05 15:38:48.000000000 -0600
+++ qemu/block.h 2007-12-05 15:47:36.000000000 -0600
@@ -16,6 +16,7 @@
extern BlockDriver bdrv_vvfat;
extern BlockDriver bdrv_qcow2;
extern BlockDriver bdrv_parallels;
+extern BlockDriver bdrv_mem;
typedef struct BlockDriverInfo {
/* in bytes, 0 if irrelevant */
@@ -155,4 +156,6 @@
const char *base_path,
const char *filename);
+int bdrv_mem_open(BlockDriverState *bs, size_t size);
+
#endif
next reply other threads:[~2007-12-05 22:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-05 22:05 Anthony Liguori [this message]
2007-12-05 22:07 ` [Qemu-devel] [PATCH 2/2] Use extboot to support -kernel Anthony Liguori
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=4757209E.4020102@us.ibm.com \
--to=aliguori@us.ibm.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.