Skip to contentSkip to conversation

use int64_t for return values from rbd instead of int

PATCH In review Stefan Priebe 5 participants 14 messages Nov 20, 2012 – Nov 22, 2012 3 messages not in the archive Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use int64_t for return values from rbd instead of int

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
 block/rbd.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/rbd.c +2 -2
index f57d0c6..6bf9c2e 100644
@@ -69,7 +69,7 @@ typedef enum {
 typedef struct RBDAIOCB {
     BlockDriverAIOCB common;
     QEMUBH *bh;
-    int ret;
+    int64_t ret;
     QEMUIOVector *qiov;
     char *bounce;
     RBDAIOCmd cmd;
@@ -87,7 +87,7 @@ typedef struct RADOSCB {
     int done;
     int64_t size;
     char *buf;
-    int ret;
+    int64_t ret;
 } RADOSCB;
 
 #define RBD_FD_READ 0
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Stefan Priebe

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
 block/rbd.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good but I want to check whether this fixes an bug you've hit? Please indicate details of the bug and how to reproduce it in the commit message.

Stefan

#2 lore raw

Hi Stefan,

Am 20.11.2012 17:29, schrieb Stefan Hajnoczi:

Quoted 12 lines · Stefan Priebe
Quoted 7 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
  block/rbd.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Looks good but I want to check whether this fixes an bug you've hit? Please indicate details of the bug and how to reproduce it in the commit message.

you get various I/O errors in client. As negative return values indicate I/O errors. When now a big positive value is returned by librbd block/rbd tries to store this one in acb->ret which is an int. Then it wraps around and is negative. After that block/rbd thinks this is an I/O error and report this to the guest.

Stefan

#3 lore raw
Quoted 20 lines · Stefan Priebe

Hi Stefan,

Am 20.11.2012 17:29, schrieb Stefan Hajnoczi:

Quoted 11 lines · Stefan Priebe
Quoted 8 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
  block/rbd.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines

Looks good but I want to check whether this fixes an bug you've hit? Please indicate details of the bug and how to reproduce it in the commit message.

Quoted 5 lines

you get various I/O errors in client. As negative return values indicate I/O errors. When now a big positive value is returned by librbd block/rbd tries to store this one in acb->ret which is an int. Then it wraps around and is negative. After that block/rbd thinks this is an I/O error and report this to the guest.

It's still not clear whether this is a bug that you can reproduce. After all, the ret value would have to be >2^31 which is a 2+ GB request!

I'm asking if this is a critical bug fix that needs to go into QEMU 1.3-rc1 because of a real-world issue?

Stefan

#4 lore raw

Am 21.11.2012 07:41, schrieb Stefan Hajnoczi:

Quoted 27 lines · Stefan Priebe
Quoted 20 lines

Hi Stefan,

Am 20.11.2012 17:29, schrieb Stefan Hajnoczi:

Quoted 11 lines · Stefan Priebe
Quoted 8 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
   block/rbd.c |    4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines

Looks good but I want to check whether this fixes an bug you've hit? Please indicate details of the bug and how to reproduce it in the commit message.

Quoted 5 lines

you get various I/O errors in client. As negative return values indicate I/O errors. When now a big positive value is returned by librbd block/rbd tries to store this one in acb->ret which is an int. Then it wraps around and is negative. After that block/rbd thinks this is an I/O error and report this to the guest.

Quoted 3 lines

It's still not clear whether this is a bug that you can reproduce. After all, the ret value would have to be >2^31 which is a 2+ GB request!

Yes and that is the fact.

Look here:
if (acb->cmd == RBD_AIO_WRITE ||

        acb->cmd == RBD_AIO_DISCARD) {
        if (r < 0) {
            acb->ret = r;
            acb->error = 1;
        } else if (!acb->error) {
            acb->ret = rcb->size;
        }

It sets acb->ret to rcb->size. But the size from a DISCARD if you DISCARD a whole device might be 500GB or today even some TB.

Greets,
Stefan

#5 lore raw
Quoted 43 lines · Stefan Priebe - Profihost AG

Am 21.11.2012 07:41, schrieb Stefan Hajnoczi:

Quoted 27 lines · Stefan Priebe
Quoted 20 lines

Hi Stefan,

Am 20.11.2012 17:29, schrieb Stefan Hajnoczi:

Quoted 11 lines · Stefan Priebe
Quoted 8 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
  block/rbd.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines

Looks good but I want to check whether this fixes an bug you've hit? Please indicate details of the bug and how to reproduce it in the commit message.

Quoted 5 lines

you get various I/O errors in client. As negative return values indicate I/O errors. When now a big positive value is returned by librbd block/rbd tries to store this one in acb->ret which is an int. Then it wraps around and is negative. After that block/rbd thinks this is an I/O error and report this to the guest.

Quoted 3 lines

It's still not clear whether this is a bug that you can reproduce. After all, the ret value would have to be >2^31 which is a 2+ GB request!

Yes and that is the fact.

Look here:

   if (acb->cmd == RBD_AIO_WRITE ||
        acb->cmd == RBD_AIO_DISCARD) {
        if (r < 0) {
            acb->ret = r;
            acb->error = 1;
        } else if (!acb->error) {
            acb->ret = rcb->size;
        }
Quoted 2 lines

It sets acb->ret to rcb->size. But the size from a DISCARD if you DISCARD a whole device might be 500GB or today even some TB.

We're going in circles here. I know the types are wrong in the code and your patch fixes it, that's why I said it looks good in my first reply.

QEMU is currently in hard freeze and only critical patches should go in. Providing steps to reproduce the bug helps me decide that this patch should still be merged for QEMU 1.3-rc1.

Anyway, the patch is straightforward, I have applied it to my block tree and it will be in QEMU 1.3-rc1:
https://github.com/stefanha/qemu/commits/block

Stefan

A message that is not in the archive (sent off-list or not yet received): 20121121082616.GB13504-lxVrvc10SDTaErKTczak/[email protected]

#7 lore raw

Am 21.11.2012 09:26, schrieb Stefan Hajnoczi:

Quoted 4 lines · Stefan Priebe - Profihost AG
Quoted 1 line

Am 21.11.2012 07:41, schrieb Stefan Hajnoczi:

We're going in circles here. I know the types are wrong in the code and your patch fixes it, that's why I said it looks good in my first reply.

Sorry not so familiar with processes like these.

Quoted 7 lines

QEMU is currently in hard freeze and only critical patches should go in. Providing steps to reproduce the bug helps me decide that this patch should still be merged for QEMU 1.3-rc1.

Anyway, the patch is straightforward, I have applied it to my block tree and it will be in QEMU 1.3-rc1:
https://github.com/stefanha/qemu/commits/block

Thanks!

The steps to reproduce are:
mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.

Might you have a look at my other rbd fix too? It fixes a race between task cancellation and writes. The same race was fixed in iscsi this summer.

Greets,
Stefan

#8 lore raw
Quoted 11 lines · Stefan Priebe - Profihost AG

Am 21.11.2012 09:26, schrieb Stefan Hajnoczi:

Quoted 9 lines · Stefan Priebe - Profihost AG
Quoted 1 line

Am 21.11.2012 07:41, schrieb Stefan Hajnoczi:

QEMU is currently in hard freeze and only critical patches should go in. Providing steps to reproduce the bug helps me decide that this patch should still be merged for QEMU 1.3-rc1.

Anyway, the patch is straightforward, I have applied it to my block tree and it will be in QEMU 1.3-rc1:
https://github.com/stefanha/qemu/commits/block

Quoted 6 lines

Thanks!

The steps to reproduce are:
mkfs.xfs -f a whole device bigger than int in bytes. mkfs.xfs sends a discard. Important is that you use scsi-hd and set discard_granularity=512. Otherwise rbd disabled discard support.

Excellent, thanks! I will add it to the commit description.

Quoted 3 lines

Might you have a look at my other rbd fix too? It fixes a race between task cancellation and writes. The same race was fixed in iscsi this summer.

Yes.

Stefan

#9 lore raw
In reply to Stefan Priebe

Am 20.11.2012 13:44, schrieb Stefan Priebe:

Quoted 22 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
  block/rbd.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
block/rbd.c +1 -1
index f57d0c6..6bf9c2e 100644
@@ -69,7 +69,7 @@ typedef enum {
  typedef struct RBDAIOCB {
      BlockDriverAIOCB common;
      QEMUBH *bh;
-    int ret;
+    int64_t ret;
      QEMUIOVector *qiov;
      char *bounce;
      RBDAIOCmd cmd;

block/rbd.c typedef struct RADOSCB { · line 93

Quoted 8 lines
block/rbd.c +1 -1
@@ -87,7 +87,7 @@ typedef struct RADOSCB {
      int done;
      int64_t size;
      char *buf;
-    int ret;
+    int64_t ret;
  } RADOSCB;
 
  #define RBD_FD_READ 0

Why do you use int64_t instead of off_t?
If the value is related to file sizes, off_t would be a good choice.

Stefan W.

#10 lore raw

Not sure about off_t. What is min and max size?

Stefan

Am 21.11.2012 um 18:03 schrieb Stefan Weil <[email protected]>:

Quoted 42 lines

Am 20.11.2012 13:44, schrieb Stefan Priebe:

Quoted 22 lines

rbd / rados tends to return pretty often length of writes or discarded blocks. These values might be bigger than int.

---
 block/rbd.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/rbd.c +1 -1
index f57d0c6..6bf9c2e 100644
@@ -69,7 +69,7 @@ typedef enum {
 typedef struct RBDAIOCB {
     BlockDriverAIOCB common;
     QEMUBH *bh;
-    int ret;
+    int64_t ret;
     QEMUIOVector *qiov;
     char *bounce;
     RBDAIOCmd cmd;

block/rbd.c typedef struct RADOSCB { · line 92

Quoted 7 lines
block/rbd.c +1 -1
@@ -87,7 +87,7 @@ typedef struct RADOSCB {
     int done;
     int64_t size;
     char *buf;
-    int ret;
+    int64_t ret;
 } RADOSCB;
   #define RBD_FD_READ 0

Why do you use int64_t instead of off_t?
If the value is related to file sizes, off_t would be a good choice.

Stefan W.

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw
In reply to Stefan Weil
Quoted 2 lines · Stefan Weil

Why do you use int64_t instead of off_t?
If the value is related to file sizes, off_t would be a good choice.

Looking at the librbd API (which is what the size and ret values come from), it uses size_t and ssize_t for these. So I think probably ssize_t is the right type for ret (and size) in our structs here.

-- PMM

A message that is not in the archive (sent off-list or not yet received): CAFEAcA-cAx88UZRQjHT7uk_oj8P+tXBJ+hb9v0N1Wym8FUMkHQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#13 lore raw

Am 21.11.2012 23:32, schrieb Peter Maydell:

Quoted 8 lines · Stefan Weil
Quoted 2 lines

Why do you use int64_t instead of off_t?
If the value is related to file sizes, off_t would be a good choice.

Looking at the librbd API (which is what the size and ret values come from), it uses size_t and ssize_t for these. So I think probably ssize_t is the right type for ret (and size) in our structs here.

This sounds reasonable but does ssize_t support negative values? For error values.

Greets,
Stefan

#14 lore raw
Quoted 9 lines · Stefan Priebe - Profihost AG

Am 21.11.2012 23:32, schrieb Peter Maydell:

Quoted 4 lines

Looking at the librbd API (which is what the size and ret values come from), it uses size_t and ssize_t for these. So I think probably ssize_t is the right type for ret (and size) in our structs here.

This sounds reasonable but does ssize_t support negative values? For error values.

Yes, the first 's' in ssize_t means 'signed' and is the difference between it and size_t.

-- PMM

A message that is not in the archive (sent off-list or not yet received): CAFEAcA86AomWmobTObpw80rMNWM30JzAKqHZXWxmB48+GU3VYQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#16 lore raw

Hello,

i send a new patch using ssize_t. (Subject [PATCH] overflow of int ret: use ssize_t for ret)

Stefan

Am 22.11.2012 09:40, schrieb Peter Maydell:

Quoted 17 lines
Quoted 9 lines · Stefan Priebe - Profihost AG

Am 21.11.2012 23:32, schrieb Peter Maydell:

Quoted 4 lines

Looking at the librbd API (which is what the size and ret values come from), it uses size_t and ssize_t for these. So I think probably ssize_t is the right type for ret (and size) in our structs here.

This sounds reasonable but does ssize_t support negative values? For error values.

Yes, the first 's' in ssize_t means 'signed' and is the difference between it and size_t.

-- PMM