[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/6] block/file-posix.c: Fix unused variable warning
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PULL 6/6] block/file-posix.c: Fix unused variable warning on OpenBSD |
Date: |
Mon, 27 Mar 2017 17:52:34 +0200 |
From: Peter Maydell <address@hidden>
On OpenBSD none of the ioctls probe_logical_blocksize() tries
exist, so the variable sector_size is unused. Refactor the
code to avoid this (and reduce the duplicated code).
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/file-posix.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index beb7a4f728..0841a08785 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -220,28 +220,28 @@ static int probe_logical_blocksize(int fd, unsigned int
*sector_size_p)
{
unsigned int sector_size;
bool success = false;
+ int i;
errno = ENOTSUP;
-
- /* Try a few ioctls to get the right size */
+ static const unsigned long ioctl_list[] = {
#ifdef BLKSSZGET
- if (ioctl(fd, BLKSSZGET, §or_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ BLKSSZGET,
#endif
#ifdef DKIOCGETBLOCKSIZE
- if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ DKIOCGETBLOCKSIZE,
#endif
#ifdef DIOCGSECTORSIZE
- if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) {
- *sector_size_p = sector_size;
- success = true;
- }
+ DIOCGSECTORSIZE,
#endif
+ };
+
+ /* Try a few ioctls to get the right size */
+ for (i = 0; i < (int)ARRAY_SIZE(ioctl_list); i++) {
+ if (ioctl(fd, ioctl_list[i], §or_size) >= 0) {
+ *sector_size_p = sector_size;
+ success = true;
+ }
+ }
return success ? 0 : -errno;
}
--
2.12.1
- [Qemu-devel] [PULL 0/6] Block patches for rc2, Max Reitz, 2017/03/27
- [Qemu-devel] [PULL 1/6] qemu-img: show help for invalid global options, Max Reitz, 2017/03/27
- [Qemu-devel] [PULL 4/6] nbd-client: fix handling of hungup connections, Max Reitz, 2017/03/27
- [Qemu-devel] [PULL 2/6] qemu-img: fix switch indentation in img_amend(), Max Reitz, 2017/03/27
- [Qemu-devel] [PULL 3/6] qemu-img: print short help on getopt failure, Max Reitz, 2017/03/27
- [Qemu-devel] [PULL 6/6] block/file-posix.c: Fix unused variable warning on OpenBSD,
Max Reitz <=
- [Qemu-devel] [PULL 5/6] file-posix: Make bdrv_flush() failure permanent without O_DIRECT, Max Reitz, 2017/03/27
- Re: [Qemu-devel] [PULL 0/6] Block patches for rc2, Peter Maydell, 2017/03/27