[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 32/69] raw-posix: Factor block size detection out of
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 32/69] raw-posix: Factor block size detection out of raw_probe_alignment() |
Date: |
Fri, 27 Feb 2015 18:18:30 +0000 |
From: Ekaterina Tumanova <address@hidden>
Put it in new probe_logical_blocksize().
Signed-off-by: Ekaterina Tumanova <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/raw-posix.c | 51 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 16 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index c0b46ca..34d403d 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -218,39 +218,58 @@ static int raw_normalize_devicepath(const char **filename)
}
#endif
-static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
+/*
+ * Get logical block size via ioctl. On success store it in @sector_size_p.
+ */
+static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
{
- BDRVRawState *s = bs->opaque;
- char *buf;
unsigned int sector_size;
+ bool success = false;
- /* For /dev/sg devices the alignment is not really used.
- With buffered I/O, we don't have any restrictions. */
- if (bs->sg || !s->needs_alignment) {
- bs->request_alignment = 1;
- s->buf_align = 1;
- return;
- }
+ errno = ENOTSUP;
/* Try a few ioctls to get the right size */
- bs->request_alignment = 0;
- s->buf_align = 0;
-
#ifdef BLKSSZGET
if (ioctl(fd, BLKSSZGET, §or_size) >= 0) {
- bs->request_alignment = sector_size;
+ *sector_size_p = sector_size;
+ success = true;
}
#endif
#ifdef DKIOCGETBLOCKSIZE
if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
- bs->request_alignment = sector_size;
+ *sector_size_p = sector_size;
+ success = true;
}
#endif
#ifdef DIOCGSECTORSIZE
if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) {
- bs->request_alignment = sector_size;
+ *sector_size_p = sector_size;
+ success = true;
}
#endif
+
+ return success ? 0 : -errno;
+}
+
+static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
+{
+ BDRVRawState *s = bs->opaque;
+ char *buf;
+
+ /* For /dev/sg devices the alignment is not really used.
+ With buffered I/O, we don't have any restrictions. */
+ if (bs->sg || !s->needs_alignment) {
+ bs->request_alignment = 1;
+ s->buf_align = 1;
+ return;
+ }
+
+ bs->request_alignment = 0;
+ s->buf_align = 0;
+ /* Let's try to use the logical blocksize for the alignment. */
+ if (probe_logical_blocksize(fd, &bs->request_alignment) < 0) {
+ bs->request_alignment = 0;
+ }
#ifdef CONFIG_XFS
if (s->is_xfs) {
struct dioattr da;
--
2.1.0
- [Qemu-devel] [PULL 30/69] blkdebug: fix "once" rule, (continued)
- [Qemu-devel] [PULL 30/69] blkdebug: fix "once" rule, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 34/69] block-backend: Add wrappers for blocksizes and geometry probing, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 33/69] block: Add driver methods to probe blocksizes and geometry, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 39/69] ide: do not use BMDMA in restart callback, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 36/69] ide: start extracting ide_restart_dma out of bmdma_restart_dma, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 37/69] ide: prepare to move restart to common code, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 38/69] ide: introduce ide_register_restart_cb, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 40/69] ide: pass IDEBus to the restart_cb, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 42/69] ide: remove restart_cb callback, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 41/69] ide: move restart callback to common code, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 32/69] raw-posix: Factor block size detection out of raw_probe_alignment(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 43/69] ide: replace set_unit callback with more IDEBus state, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 44/69] ide: place initial state of the current request to IDEBus, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 35/69] BlockConf: Call backend functions to detect geometry and blocksizes, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 45/69] ide: migrate initial request state via IDEBus, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 46/69] ide: commonize io_buffer_index initialization, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 47/69] ide: make more functions static, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 48/69] ide: support PIO restart for the ISA controller, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 50/69] ahci: add support for restarting non-queued commands, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 49/69] ahci: Migrate IDEStatus, Stefan Hajnoczi, 2015/02/27
- [Qemu-devel] [PULL 53/69] libqos/ahci: Zero-fill AHCI headers, Stefan Hajnoczi, 2015/02/27