diff mbox series

[1/2] sheepdog: cleanup repeated expression

Message ID 20180522201056.1442-2-pbonzini@redhat.com
State New
Headers show
Series [1/2] sheepdog: cleanup repeated expression | expand

Commit Message

Paolo Bonzini May 22, 2018, 8:10 p.m. UTC
The expression "SD_INODE_SIZE - sizeof(inode.data_vdi_id)" already has a macro
defined for the same value (though with a nicer definition using offsetof).
Replace it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/sheepdog.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Philippe Mathieu-Daudé May 22, 2018, 8:25 p.m. UTC | #1
On 05/22/2018 05:10 PM, Paolo Bonzini wrote:
> The expression "SD_INODE_SIZE - sizeof(inode.data_vdi_id)" already has a macro
> defined for the same value (though with a nicer definition using offsetof).
> Replace it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  block/sheepdog.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 4237132419..23cf5a8430 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2337,7 +2337,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset,
>      }
>  
>      /* we don't need to update entire object */
> -    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
> +    datalen = SD_INODE_HEADER_SIZE;
>      s->inode.vdi_size = offset;
>      ret = write_object(fd, s->bs, (char *)&s->inode,
>                         vid_to_vdi_oid(s->inode.vdi_id), s->inode.nr_copies,
> @@ -2705,7 +2705,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
>       */
>      strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag));
>      /* we don't need to update entire object */
> -    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
> +    datalen = SD_INODE_HEADER_SIZE;
>      inode = g_malloc(datalen);
>  
>      /* refresh inode. */
> @@ -2991,7 +2991,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
>          /* we don't need to read entire object */
>          ret = read_object(fd, s->bs, (char *)&inode,
>                            vid_to_vdi_oid(vid),
> -                          0, SD_INODE_SIZE - sizeof(inode.data_vdi_id), 0,
> +                          0, SD_INODE_HEADER_SIZE, 0,
>                            s->cache_flags);
>  
>          if (ret) {
>
Fam Zheng May 23, 2018, 2:12 a.m. UTC | #2
On Tue, 05/22 22:10, Paolo Bonzini wrote:
> The expression "SD_INODE_SIZE - sizeof(inode.data_vdi_id)" already has a macro
> defined for the same value (though with a nicer definition using offsetof).
> Replace it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Fam Zheng <famz@redhat.com>
Jeff Cody May 23, 2018, 3:30 p.m. UTC | #3
On Tue, May 22, 2018 at 10:10:55PM +0200, Paolo Bonzini wrote:
> The expression "SD_INODE_SIZE - sizeof(inode.data_vdi_id)" already has a macro
> defined for the same value (though with a nicer definition using offsetof).
> Replace it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/sheepdog.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 4237132419..23cf5a8430 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2337,7 +2337,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset,
>      }
>  
>      /* we don't need to update entire object */
> -    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
> +    datalen = SD_INODE_HEADER_SIZE;
>      s->inode.vdi_size = offset;
>      ret = write_object(fd, s->bs, (char *)&s->inode,
>                         vid_to_vdi_oid(s->inode.vdi_id), s->inode.nr_copies,
> @@ -2705,7 +2705,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
>       */
>      strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag));
>      /* we don't need to update entire object */
> -    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
> +    datalen = SD_INODE_HEADER_SIZE;
>      inode = g_malloc(datalen);
>  
>      /* refresh inode. */
> @@ -2991,7 +2991,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
>          /* we don't need to read entire object */
>          ret = read_object(fd, s->bs, (char *)&inode,
>                            vid_to_vdi_oid(vid),
> -                          0, SD_INODE_SIZE - sizeof(inode.data_vdi_id), 0,
> +                          0, SD_INODE_HEADER_SIZE, 0,
>                            s->cache_flags);
>  
>          if (ret) {
> -- 
> 2.17.0
> 
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>
diff mbox series

Patch

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 4237132419..23cf5a8430 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2337,7 +2337,7 @@  static int sd_truncate(BlockDriverState *bs, int64_t offset,
     }
 
     /* we don't need to update entire object */
-    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
+    datalen = SD_INODE_HEADER_SIZE;
     s->inode.vdi_size = offset;
     ret = write_object(fd, s->bs, (char *)&s->inode,
                        vid_to_vdi_oid(s->inode.vdi_id), s->inode.nr_copies,
@@ -2705,7 +2705,7 @@  static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
      */
     strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag));
     /* we don't need to update entire object */
-    datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
+    datalen = SD_INODE_HEADER_SIZE;
     inode = g_malloc(datalen);
 
     /* refresh inode. */
@@ -2991,7 +2991,7 @@  static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
         /* we don't need to read entire object */
         ret = read_object(fd, s->bs, (char *)&inode,
                           vid_to_vdi_oid(vid),
-                          0, SD_INODE_SIZE - sizeof(inode.data_vdi_id), 0,
+                          0, SD_INODE_HEADER_SIZE, 0,
                           s->cache_flags);
 
         if (ret) {