Patchwork [RFC,07/24] qed: make qed_alloc_clusters round up offset to nearest cluster

login
register
mail settings
Submitter Devin Nakamura
Date July 29, 2011, 4:49 a.m.
Message ID <1311914994-20482-8-git-send-email-devin122@gmail.com>
Download mbox | patch
Permalink /patch/107330/
State New
Headers show

Comments

Devin Nakamura - July 29, 2011, 4:49 a.m.
Signed-off-by: Devin Nakamura <devin122@gmail.com>
---
 block/qed.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Kevin Wolf - Aug. 1, 2011, 1:51 p.m.
Am 29.07.2011 06:49, schrieb Devin Nakamura:
> Signed-off-by: Devin Nakamura <devin122@gmail.com>
> ---
>  block/qed.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/block/qed.c b/block/qed.c
> index 3970379..00cf895 100644
> --- a/block/qed.c
> +++ b/block/qed.c
> @@ -263,6 +263,9 @@ static int qed_read_string(BlockDriverState *file, uint64_t offset, size_t n,
>   */
>  static uint64_t qed_alloc_clusters(BDRVQEDState *s, unsigned int n)
>  {
> +    s->file_size = (s->file_size + s->header.cluster_size -1)
> +        / s->header.cluster_size;
> +    s->file_size *= s->header.cluster_size;

This looks a bit simpler:

s->file_size = qed_start_of_cluster(s->file_size +
s->header.cluster_size - 1);

Kevin

Patch

diff --git a/block/qed.c b/block/qed.c
index 3970379..00cf895 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -263,6 +263,9 @@  static int qed_read_string(BlockDriverState *file, uint64_t offset, size_t n,
  */
 static uint64_t qed_alloc_clusters(BDRVQEDState *s, unsigned int n)
 {
+    s->file_size = (s->file_size + s->header.cluster_size -1)
+        / s->header.cluster_size;
+    s->file_size *= s->header.cluster_size;
     uint64_t offset = s->file_size;
     s->file_size += n * s->header.cluster_size;
     return offset;