* [Qemu-devel] [PATCH for-2.9 v2] block/file-posix.c: Fix unused variable warning on OpenBSD
@ 2017-03-23 14:36 Peter Maydell
2017-03-27 15:29 ` Max Reitz
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2017-03-23 14:36 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, Kevin Wolf, Max Reitz, qemu-block
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 <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Jeff Cody <jcody@redhat.com>
---
v2: add (int) cast to avoid compiler warnings on some
systems when the array is empty; use 'static const'.
---
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 53febd3..db8f0a8 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -219,28 +219,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.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9 v2] block/file-posix.c: Fix unused variable warning on OpenBSD
2017-03-23 14:36 [Qemu-devel] [PATCH for-2.9 v2] block/file-posix.c: Fix unused variable warning on OpenBSD Peter Maydell
@ 2017-03-27 15:29 ` Max Reitz
0 siblings, 0 replies; 2+ messages in thread
From: Max Reitz @ 2017-03-27 15:29 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: patches, Kevin Wolf, qemu-block
[-- Attachment #1: Type: text/plain, Size: 735 bytes --]
On 23.03.2017 15:36, Peter Maydell wrote:
> 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 <peter.maydell@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Jeff Cody <jcody@redhat.com>
> ---
> v2: add (int) cast to avoid compiler warnings on some
> systems when the array is empty; use 'static const'.
> ---
> block/file-posix.c | 28 ++++++++++++++--------------
> 1 file changed, 14 insertions(+), 14 deletions(-)
Thanks, applied to my block branch for 2.9:
https://github.com/XanClic/qemu/commits/block
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-27 15:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-23 14:36 [Qemu-devel] [PATCH for-2.9 v2] block/file-posix.c: Fix unused variable warning on OpenBSD Peter Maydell
2017-03-27 15:29 ` Max Reitz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.