diff mbox

block/nfs: fix calculation of allocated file size

Message ID 1440067607-14547-1-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Aug. 20, 2015, 10:46 a.m. UTC
st.st_blocks is always counted in 512 byte units. Do not
use st.st_blksize as multiplicator which may be larger.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/nfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Max Reitz Aug. 21, 2015, 4:33 p.m. UTC | #1
On 2015-08-20 at 03:46, Peter Lieven wrote:
> st.st_blocks is always counted in 512 byte units. Do not
> use st.st_blksize as multiplicator which may be larger.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>   block/nfs.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/nfs.c b/block/nfs.c
> index c026ff6..02eb4e4 100644
> --- a/block/nfs.c
> +++ b/block/nfs.c
> @@ -475,7 +475,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
>           aio_poll(client->aio_context, true);
>       }
>   
> -    return (task.ret < 0 ? task.ret : st.st_blocks * st.st_blksize);
> +    return (task.ret < 0 ? task.ret : st.st_blocks * 512);
>   }
>   
>   static int nfs_file_truncate(BlockDriverState *bs, int64_t offset)

Reviewed-by: Max Reitz <mreitz@redhat.com>
Jeff Cody Aug. 26, 2015, 3:42 p.m. UTC | #2
On Thu, Aug 20, 2015 at 12:46:47PM +0200, Peter Lieven wrote:
> st.st_blocks is always counted in 512 byte units. Do not
> use st.st_blksize as multiplicator which may be larger.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/nfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/nfs.c b/block/nfs.c
> index c026ff6..02eb4e4 100644
> --- a/block/nfs.c
> +++ b/block/nfs.c
> @@ -475,7 +475,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
>          aio_poll(client->aio_context, true);
>      }
>  
> -    return (task.ret < 0 ? task.ret : st.st_blocks * st.st_blksize);
> +    return (task.ret < 0 ? task.ret : st.st_blocks * 512);
>  }
>  
>  static int nfs_file_truncate(BlockDriverState *bs, int64_t offset)
> -- 
> 1.9.1
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>
Jeff Cody Aug. 26, 2015, 6:38 p.m. UTC | #3
On Thu, Aug 20, 2015 at 12:46:47PM +0200, Peter Lieven wrote:
> st.st_blocks is always counted in 512 byte units. Do not
> use st.st_blksize as multiplicator which may be larger.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/nfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/nfs.c b/block/nfs.c
> index c026ff6..02eb4e4 100644
> --- a/block/nfs.c
> +++ b/block/nfs.c
> @@ -475,7 +475,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
>          aio_poll(client->aio_context, true);
>      }
>  
> -    return (task.ret < 0 ? task.ret : st.st_blocks * st.st_blksize);
> +    return (task.ret < 0 ? task.ret : st.st_blocks * 512);
>  }
>  
>  static int nfs_file_truncate(BlockDriverState *bs, int64_t offset)
> -- 
> 1.9.1
>

Thanks, applied to my block tree:

git://github.com/codyprime/qemu-kvm-jtc.git block

-Jeff
diff mbox

Patch

diff --git a/block/nfs.c b/block/nfs.c
index c026ff6..02eb4e4 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -475,7 +475,7 @@  static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
         aio_poll(client->aio_context, true);
     }
 
-    return (task.ret < 0 ? task.ret : st.st_blocks * st.st_blksize);
+    return (task.ret < 0 ? task.ret : st.st_blocks * 512);
 }
 
 static int nfs_file_truncate(BlockDriverState *bs, int64_t offset)