From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 1/3] block: add bdrv_get_alignment, use it
Date: Wed, 23 Nov 2011 17:51:25 +0100 [thread overview]
Message-ID: <1322067087-16884-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1322067087-16884-1-git-send-email-pbonzini@redhat.com>
We cannot simply use the guest logical block size on the host; we need
to ask the protocol driver about the minimum required alignment.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block.c | 26 ++++++++++++++++++++++++--
block.h | 1 +
block/raw-posix.c | 3 ++-
block_int.h | 1 +
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/block.c b/block.c
index d015887..aba92ad 100644
--- a/block.c
+++ b/block.c
@@ -476,7 +476,7 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
bs->sg = 0;
bs->open_flags = flags;
bs->growable = 0;
- bs->buffer_alignment = 512;
+ bs->buffer_alignment = 0;
pstrcpy(bs->filename, sizeof(bs->filename), filename);
bs->backing_file[0] = '\0';
@@ -1361,6 +1361,27 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
}
/**
+ * Required buffer alignment for a file or device. Return < 0 if error or unknown.
+ */
+int bdrv_get_alignment(BlockDriverState *bs)
+{
+ BlockDriver *drv = bs->drv;
+ if (!drv) {
+ return -ENOMEDIUM;
+ }
+ if (bs->buffer_alignment == 0) {
+ if (drv->bdrv_get_alignment) {
+ bs->buffer_alignment = drv->bdrv_get_alignment(bs);
+ } else if (bs->file) {
+ bs->buffer_alignment = bdrv_get_alignment(bs->file);
+ } else {
+ bs->buffer_alignment = BDRV_SECTOR_SIZE;
+ }
+ }
+ return bs->buffer_alignment;
+}
+
+/**
* Length of a file in bytes. Return < 0 if error or unknown.
*/
int64_t bdrv_getlength(BlockDriverState *bs)
@@ -3025,7 +3046,8 @@ void bdrv_set_buffer_alignment(BlockDriverState *bs, int align)
void *qemu_blockalign(BlockDriverState *bs, size_t size)
{
- return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size);
+ int alignment = bs ? bdrv_get_alignment(bs) : 512;
+ return qemu_memalign(alignment, size);
}
void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable)
diff --git a/block.h b/block.h
index a826059..5fa632c 100644
--- a/block.h
+++ b/block.h
@@ -294,6 +294,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
char *options, uint64_t img_size, int flags);
+int bdrv_get_alignment(BlockDriverState *bs);
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
void *qemu_blockalign(BlockDriverState *bs, size_t size);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index a3de373..3482fc8 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -301,10 +301,11 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
*/
static int qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov)
{
+ int alignment = bdrv_get_alignment(bs);
int i;
for (i = 0; i < qiov->niov; i++) {
- if ((uintptr_t) qiov->iov[i].iov_base % bs->buffer_alignment) {
+ if ((uintptr_t) qiov->iov[i].iov_base % alignment) {
return 0;
}
}
diff --git a/block_int.h b/block_int.h
index 77c0187..6caf063 100644
--- a/block_int.h
+++ b/block_int.h
@@ -113,6 +113,7 @@ struct BlockDriver {
const char *protocol_name;
int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
+ int (*bdrv_get_alignment)(BlockDriverState *bs);
int64_t (*bdrv_getlength)(BlockDriverState *bs);
int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
--
1.7.7.1
next prev parent reply other threads:[~2011-11-23 16:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-23 16:51 [Qemu-devel] [RFC PATCH 0/3] block: add support for 4k logical blocks Paolo Bonzini
2011-11-23 16:51 ` Paolo Bonzini [this message]
2011-11-23 16:51 ` [Qemu-devel] [RFC PATCH 2/3] raw: implement raw_get_alignment Paolo Bonzini
2011-11-23 16:51 ` [Qemu-devel] [RFC PATCH 3/3] block: do not rely on the buffer alignment passed to the guest Paolo Bonzini
2011-11-25 7:26 ` [Qemu-devel] [RFC PATCH 0/3] block: add support for 4k logical blocks Mark Wu
2011-11-25 8:27 ` Paolo Bonzini
2011-11-25 11:13 ` Christoph Hellwig
2011-11-28 3:05 ` Mark Wu
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=1322067087-16884-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.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 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).