From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
Sasha Levin <levinsasha928@gmail.com>,
Prasad Joshi <prasadjoshi124@gmail.com>,
kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH 03/14] kvm tools: Split raw image and blk device code from disk/core.c
Date: Wed, 18 May 2011 16:19:04 +0800 [thread overview]
Message-ID: <1305706755-2816-3-git-send-email-asias.hejun@gmail.com> (raw)
In-Reply-To: <1305706755-2816-1-git-send-email-asias.hejun@gmail.com>
This patch moves raw image and blk device code into disk/raw.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/Makefile | 3 +-
tools/kvm/disk/core.c | 101 +-----------------------------------
tools/kvm/disk/raw.c | 84 ++++++++++++++++++++++++++++++
tools/kvm/include/kvm/disk-image.h | 15 +++++
4 files changed, 102 insertions(+), 101 deletions(-)
create mode 100644 tools/kvm/disk/raw.c
diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index d7b1233..a19fbe8 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -15,7 +15,6 @@ TAGS = ctags
OBJS += 8250-serial.o
OBJS += cpuid.o
OBJS += read-write.o
-OBJS += disk/core.o
OBJS += interrupt.o
OBJS += ioport.o
OBJS += kvm.o
@@ -38,6 +37,8 @@ OBJS += kvm-help.o
OBJS += kvm-cmd.o
OBJS += kvm-run.o
OBJS += disk/qcow.o
+OBJS += disk/core.o
+OBJS += disk/raw.o
OBJS += mptable.o
OBJS += threadpool.o
OBJS += irq.o
diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c
index 4172b05..4622e99 100644
--- a/tools/kvm/disk/core.c
+++ b/tools/kvm/disk/core.c
@@ -1,21 +1,5 @@
#include "kvm/disk-image.h"
-
-#include "kvm/read-write.h"
#include "kvm/qcow.h"
-#include "kvm/util.h"
-
-#include <linux/fs.h> /* for BLKGETSIZE64 */
-
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <linux/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops)
{
@@ -45,89 +29,6 @@ struct disk_image *disk_image__new_readonly(int fd, u64 size, struct disk_image_
return disk;
}
-static ssize_t raw_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
-{
- u64 offset = sector << SECTOR_SHIFT;
-
- return preadv_in_full(disk->fd, iov, iovcount, offset);
-}
-
-static ssize_t raw_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
-{
- u64 offset = sector << SECTOR_SHIFT;
-
- return pwritev_in_full(disk->fd, iov, iovcount, offset);
-}
-
-static int raw_image__read_sector_ro_mmap(struct disk_image *disk, u64 sector, void *dst, u32 dst_len)
-{
- u64 offset = sector << SECTOR_SHIFT;
-
- if (offset + dst_len > disk->size)
- return -1;
-
- memcpy(dst, disk->priv + offset, dst_len);
-
- return 0;
-}
-
-static int raw_image__write_sector_ro_mmap(struct disk_image *disk, u64 sector, void *src, u32 src_len)
-{
- u64 offset = sector << SECTOR_SHIFT;
-
- if (offset + src_len > disk->size)
- return -1;
-
- memcpy(disk->priv + offset, src, src_len);
-
- return 0;
-}
-
-static void raw_image__close_ro_mmap(struct disk_image *disk)
-{
- if (disk->priv != MAP_FAILED)
- munmap(disk->priv, disk->size);
-}
-
-static struct disk_image_operations raw_image_ops = {
- .read_sector_iov = raw_image__read_sector_iov,
- .write_sector_iov = raw_image__write_sector_iov
-};
-
-static struct disk_image_operations raw_image_ro_mmap_ops = {
- .read_sector = raw_image__read_sector_ro_mmap,
- .write_sector = raw_image__write_sector_ro_mmap,
- .close = raw_image__close_ro_mmap,
-};
-
-static struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly)
-{
- if (readonly)
- return disk_image__new_readonly(fd, st->st_size, &raw_image_ro_mmap_ops);
- else
- return disk_image__new(fd, st->st_size, &raw_image_ops);
-}
-
-static struct disk_image *blkdev__probe(const char *filename, struct stat *st)
-{
- u64 size;
- int fd;
-
- if (!S_ISBLK(st->st_mode))
- return NULL;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- if (ioctl(fd, BLKGETSIZE64, &size) < 0) {
- close(fd);
- return NULL;
- }
-
- return disk_image__new_readonly(fd, size, &raw_image_ro_mmap_ops);
-}
-
struct disk_image *disk_image__open(const char *filename, bool readonly)
{
struct disk_image *disk;
@@ -209,4 +110,4 @@ ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const
}
return (sector - first_sector) << SECTOR_SHIFT;
-}
\ No newline at end of file
+}
diff --git a/tools/kvm/disk/raw.c b/tools/kvm/disk/raw.c
new file mode 100644
index 0000000..b1a484d
--- /dev/null
+++ b/tools/kvm/disk/raw.c
@@ -0,0 +1,84 @@
+#include "kvm/disk-image.h"
+
+static ssize_t raw_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
+{
+ u64 offset = sector << SECTOR_SHIFT;
+
+ return preadv_in_full(disk->fd, iov, iovcount, offset);
+}
+
+static ssize_t raw_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
+{
+ u64 offset = sector << SECTOR_SHIFT;
+
+ return pwritev_in_full(disk->fd, iov, iovcount, offset);
+}
+
+static int raw_image__read_sector_ro_mmap(struct disk_image *disk, u64 sector, void *dst, u32 dst_len)
+{
+ u64 offset = sector << SECTOR_SHIFT;
+
+ if (offset + dst_len > disk->size)
+ return -1;
+
+ memcpy(dst, disk->priv + offset, dst_len);
+
+ return 0;
+}
+
+static int raw_image__write_sector_ro_mmap(struct disk_image *disk, u64 sector, void *src, u32 src_len)
+{
+ u64 offset = sector << SECTOR_SHIFT;
+
+ if (offset + src_len > disk->size)
+ return -1;
+
+ memcpy(disk->priv + offset, src, src_len);
+
+ return 0;
+}
+
+static void raw_image__close_ro_mmap(struct disk_image *disk)
+{
+ if (disk->priv != MAP_FAILED)
+ munmap(disk->priv, disk->size);
+}
+
+static struct disk_image_operations raw_image_ops = {
+ .read_sector_iov = raw_image__read_sector_iov,
+ .write_sector_iov = raw_image__write_sector_iov
+};
+
+static struct disk_image_operations raw_image_ro_mmap_ops = {
+ .read_sector = raw_image__read_sector_ro_mmap,
+ .write_sector = raw_image__write_sector_ro_mmap,
+ .close = raw_image__close_ro_mmap,
+};
+
+struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly)
+{
+ if (readonly)
+ return disk_image__new_readonly(fd, st->st_size, &raw_image_ro_mmap_ops);
+ else
+ return disk_image__new(fd, st->st_size, &raw_image_ops);
+}
+
+struct disk_image *blkdev__probe(const char *filename, struct stat *st)
+{
+ u64 size;
+ int fd;
+
+ if (!S_ISBLK(st->st_mode))
+ return NULL;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ if (ioctl(fd, BLKGETSIZE64, &size) < 0) {
+ close(fd);
+ return NULL;
+ }
+
+ return disk_image__new_readonly(fd, size, &raw_image_ro_mmap_ops);
+}
diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h
index cc83f38..87bebd3 100644
--- a/tools/kvm/include/kvm/disk-image.h
+++ b/tools/kvm/include/kvm/disk-image.h
@@ -1,10 +1,22 @@
#ifndef KVM__DISK_IMAGE_H
#define KVM__DISK_IMAGE_H
+#include "kvm/read-write.h"
+#include "kvm/util.h"
+
#include <linux/types.h>
+#include <linux/fs.h> /* for BLKGETSIZE64 */
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
#include <stdbool.h>
#include <sys/uio.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1UL << SECTOR_SHIFT)
@@ -52,4 +64,7 @@ static inline int disk_image__flush(struct disk_image *disk)
return fsync(disk->fd);
}
+struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly);
+struct disk_image *blkdev__probe(const char *filename, struct stat *st);
+
#endif /* KVM__DISK_IMAGE_H */
--
1.7.5.1
next prev parent reply other threads:[~2011-05-18 8:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-18 8:19 [PATCH 01/14] kvm tools: Move disk image related code under disk directory Asias He
2011-05-18 8:19 ` [PATCH 02/14] kvm tools: Rename disk-image.c to core.c Asias He
2011-05-18 8:19 ` Asias He [this message]
2011-05-18 8:19 ` [PATCH 04/14] kvm tools: Rename disk_image__{read, write}_sector_iov Asias He
2011-05-18 8:19 ` [PATCH 05/14] kvm tools: Remove dead coe disk_image__{read, write}_sector Asias He
2011-05-18 8:19 ` [PATCH 06/14] kvm tools: Consolidate disk_image__{new, new_readonly} Asias He
2011-05-18 8:19 ` [PATCH 07/14] kvm tools: Split blk device code from raw.c to blk.c Asias He
2011-05-18 8:19 ` [PATCH 08/14] kvm tools: Tune up ops in 'struct disk_image_operations' Asias He
2011-05-18 8:19 ` [PATCH 09/14] kvm tools: Rename struct disk_image_operations ops name for raw image Asias He
2011-05-18 8:19 ` [PATCH 10/14] kvm tools: Rename raw_image_ops to blk_dev_ops Asias He
2011-05-18 8:51 ` Ingo Molnar
2011-05-18 8:19 ` [PATCH 11/14] kvm tools: Remove unnecessary S_ISBLK check Asias He
2011-05-18 8:19 ` [PATCH 12/14] kvm tools: Do not use 'inline' for disk_image__flush Asias He
2011-05-18 8:19 ` [PATCH 13/14] kvm tools: Add debug info for disk_image__{read, write} Asias He
2011-05-18 8:19 ` [PATCH 14/14] kvm tools: Print debug info for qcow1_nowrite_sector Asias He
2011-05-18 8:45 ` Ingo Molnar
2011-05-18 8:46 ` Ingo Molnar
2011-05-18 8:47 ` Cyrill Gorcunov
2011-05-18 8:42 ` [PATCH 01/14] kvm tools: Move disk image related code under disk directory Ingo Molnar
2011-05-18 8:43 ` Ingo Molnar
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=1305706755-2816-3-git-send-email-asias.hejun@gmail.com \
--to=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
/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