qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl
@ 2015-04-03 11:01 Bogdan Purcareata
  2015-04-03 14:15 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Bogdan Purcareata @ 2015-04-03 11:01 UTC (permalink / raw)
  To: qemu-devel

This fixes ioctl behavior on powerpc e6500 platforms with 64bit kernel and 32bit
userspace. The current type cast has no effect there and the value passed to the
kernel is still 0. Probably an issue related to the compiler, since I'm assuming
the same configuration works on a similar setup on x86.

Also ensure consistency with previous type cast in TRACE message.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
---
 nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nbd.c b/nbd.c
index 91b7d56..da81a5b 100644
--- a/nbd.c
+++ b/nbd.c
@@ -681,7 +681,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size)
 
     TRACE("Setting size to %zd block(s)", (size_t)(size / BDRV_SECTOR_SIZE));
 
-    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / (size_t)BDRV_SECTOR_SIZE) < 0) {
+    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0)) {
         int serrno = errno;
         LOG("Failed setting size (in blocks)");
         return -serrno;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl
  2015-04-03 11:01 [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl Bogdan Purcareata
@ 2015-04-03 14:15 ` Paolo Bonzini
  2015-04-03 14:44   ` Michael Tokarev
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2015-04-03 14:15 UTC (permalink / raw)
  To: Bogdan Purcareata, qemu-devel, qemu-stable



On 03/04/2015 13:01, Bogdan Purcareata wrote:
> This fixes ioctl behavior on powerpc e6500 platforms with 64bit kernel and 32bit
> userspace. The current type cast has no effect there and the value passed to the
> kernel is still 0. Probably an issue related to the compiler, since I'm assuming
> the same configuration works on a similar setup on x86.
> 
> Also ensure consistency with previous type cast in TRACE message.
> 
> Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
> ---
>  nbd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/nbd.c b/nbd.c
> index 91b7d56..da81a5b 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -681,7 +681,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size)
>  
>      TRACE("Setting size to %zd block(s)", (size_t)(size / BDRV_SECTOR_SIZE));
>  
> -    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / (size_t)BDRV_SECTOR_SIZE) < 0) {
> +    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0)) {
>          int serrno = errno;
>          LOG("Failed setting size (in blocks)");
>          return -serrno;
> 

Thanks, queued for 2.4.

Cc: qemu-stable@nongnu.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl
  2015-04-03 14:15 ` Paolo Bonzini
@ 2015-04-03 14:44   ` Michael Tokarev
  2015-04-06  7:15     ` Purcareata Bogdan
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Tokarev @ 2015-04-03 14:44 UTC (permalink / raw)
  To: Paolo Bonzini, Bogdan Purcareata, qemu-devel, qemu-stable

03.04.2015 17:15, Paolo Bonzini wrote:
> On 03/04/2015 13:01, Bogdan Purcareata wrote:
...
>> -    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / (size_t)BDRV_SECTOR_SIZE) < 0) {
>> +    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0)) {
>>          int serrno = errno;

Hmm..  I don't think this is right at all.  Now we compare size_t with zero,
the result is always false, and set error if ioctl return anything other than 0,
including any positive value.

Compare:

  if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0))
  if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE)) < 0)

I think the latter is the right version.

So much for trivial... ;)

Thanks,

/mjt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl
  2015-04-03 14:44   ` Michael Tokarev
@ 2015-04-06  7:15     ` Purcareata Bogdan
  0 siblings, 0 replies; 4+ messages in thread
From: Purcareata Bogdan @ 2015-04-06  7:15 UTC (permalink / raw)
  To: Michael Tokarev, Paolo Bonzini, Bogdan Purcareata, qemu-devel,
	qemu-stable

On 03.04.2015 17:44, Michael Tokarev wrote:
> 03.04.2015 17:15, Paolo Bonzini wrote:
>> On 03/04/2015 13:01, Bogdan Purcareata wrote:
> ...
>>> -    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / (size_t)BDRV_SECTOR_SIZE) < 0) {
>>> +    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0)) {
>>>           int serrno = errno;
>
> Hmm..  I don't think this is right at all.  Now we compare size_t with zero,
> the result is always false, and set error if ioctl return anything other than 0,
> including any positive value.
>
> Compare:
>
>    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE) < 0))
>    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, (size_t)(size / BDRV_SECTOR_SIZE)) < 0)
>
> I think the latter is the right version.

Yes, the latter is indeed the right version. Great catch!

> So much for trivial... ;)

Me and my slippery fingers. Sorry for the mishap.

Bogdan P.

> Thanks,
>
> /mjt
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-06  7:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-03 11:01 [Qemu-devel] [PATCH] nbd/trivial: fix type cast for ioctl Bogdan Purcareata
2015-04-03 14:15 ` Paolo Bonzini
2015-04-03 14:44   ` Michael Tokarev
2015-04-06  7:15     ` Purcareata Bogdan

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).