[sheepdog] [PATCH] dog: type cast miss at vdi_show_progress

Liu Yuan namei.unix at gmail.com
Tue Feb 10 10:30:32 CET 2015


On Tue, Feb 10, 2015 at 06:22:33PM +0900, Saeki Masaki wrote:
> On 2015/02/10 16:33, Liu Yuan wrote:
> >On Tue, Feb 10, 2015 at 03:03:56PM +0900, Saeki Masaki wrote:
> >>The result of the multiplication of uint32 and uint64 are rounded to uint32
> >>So, Progress of the command is displayed back to 0%,
> >>when it exceeds the boundaries of 32bit.
> >>
> >>This is only a display issue, command processing can be completed.
> >>
> >>Signed-off-by: Masaki Saeki <saeki.masaki at po.ntts.co.jp>
> >>---
> >>  dog/vdi.c |    8 ++++----
> >>  1 files changed, 4 insertions(+), 4 deletions(-)
> >>
> >>diff --git a/dog/vdi.c b/dog/vdi.c
> >>index 58d4a12..0920936 100644
> >>--- a/dog/vdi.c
> >>+++ b/dog/vdi.c
> >>@@ -532,7 +532,7 @@ static int vdi_create(int argc, char **argv)
> >>  	max_idx = DIV_ROUND_UP(size, object_size);
> >>
> >>  	for (idx = 0; idx < max_idx; idx++) {
> >>-		vdi_show_progress(idx * object_size, inode->vdi_size);
> >>+		vdi_show_progress((uint64_t)idx * object_size, inode->vdi_size);
> >
> >How about making the idx as uint64_t in the definition and comment that why we
> >need unit64_t for it. This would save us from casting everywhere.
> >
> >Thanks
> >Yuan
> 
> Hi Yuan. thank you for your comment.
> 
> I think idx is also used to manage upper limit of the data objects per VDI.
> In the current specification, the upper limit of the object number is 32bit.

Yes, this is why we define idx as unit32_t. But we have assure this by a for
loop and guarde idx by max_idx. And to avoid confusion in the future, so I
suggested to add a comment why make it as uint64_t instead of uint32_t.

> 
> so I think scary side effects if change this definition to uint64_t.
> 
> What do you think about.

Yes, we might risk it the possible side effect in the future, but I hope the
comment and max_idx can help us avoid the side effect.

Anyway, if you insist on the approach of your patch, I can apply it since it is
a valid fix. Do you?

Thanks
Yuan



More information about the sheepdog mailing list