[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 2/5] raw-posix: Factor block size detection out o
From: |
Ekaterina Tumanova |
Subject: |
[Qemu-devel] [PATCH v6 2/5] raw-posix: Factor block size detection out of raw_probe_alignment() |
Date: |
Mon, 19 Jan 2015 15:34:58 +0100 |
Put it in new probe_logical_blocksize().
Signed-off-by: Ekaterina Tumanova <address@hidden>
Reviewed-by: Markus Armbruster <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 e51293a..48525f8 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -217,39 +217,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.4
- [Qemu-devel] [PATCH v6 0/5] Geometry and blocksize detection for backing devices., Ekaterina Tumanova, 2015/01/19
- [Qemu-devel] [PATCH v6 3/5] block: Add driver methods to probe blocksizes and geometry, Ekaterina Tumanova, 2015/01/19
- [Qemu-devel] [PATCH v6 2/5] raw-posix: Factor block size detection out of raw_probe_alignment(),
Ekaterina Tumanova <=
- [Qemu-devel] [PATCH v6 1/5] block: add bdrv functions for geometry and blocksize, Ekaterina Tumanova, 2015/01/19
- [Qemu-devel] [PATCH v6 4/5] block-backend: Add wrappers for blocksizes and geometry probing, Ekaterina Tumanova, 2015/01/19
- [Qemu-devel] [PATCH v6 5/5] BlockConf: Call backend functions to detect geometry and blocksizes, Ekaterina Tumanova, 2015/01/19
- Re: [Qemu-devel] [PATCH v6 0/5] Geometry and blocksize detection for backing devices., Christian Borntraeger, 2015/01/22