public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	Carlo Marcelo Arenas Belon
	<carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
Subject: Re: [PATCH] qemu: use statically allocate 512 byte	buffer in the stack for sector in bdrv_commit
Date: Mon, 07 Jan 2008 11:22:38 +0100	[thread overview]
Message-ID: <1199701358.19008.1.camel@frecb07144> (raw)
In-Reply-To: <4781F08E.8060407-atKUWr5tajBWk0Htik3J/w@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 2483 bytes --]

Le lundi 07 janvier 2008 à 11:27 +0200, Avi Kivity a écrit :
> Carlo Marcelo Arenas Belon wrote:
> > revert a merge conflict from 075da586c92f09bd9a7401f1e80d72fde27c173 that
> > redefined sector as an array of pointers to char, instead of a statically
> > allocated buffer of chars, that was triggering the following warnings :
> >
> > block.c: In function `bdrv_commit':
> > block.c:480: warning: passing arg 3 of `bdrv_read' from incompatible pointer type
> > block.c:484: warning: passing arg 3 of `bdrv_write' from incompatible pointer type
> >
> > Signed-off-by: Carlo Marcelo Arenas Belon <carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
> >   
> 
> Doesn't the cache=off option warrant an allocation here to ensure 
> alignment (or perhaps a 1K stack buffer with runtime adjustment)?

You're right, a good patch should be something like this (it is not
tested or even compiled) :

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
diff --git a/qemu/block.c b/qemu/block.c
index 519be24..c198659 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -460,7 +460,7 @@ int bdrv_commit(BlockDriverState *bs)
     BlockDriver *drv = bs->drv;
     int64_t i, total_sectors;
     int n, j;
-    unsigned char *sector[512];
+    unsigned char *sector;
 
     if (!drv)
         return -ENOMEDIUM;
@@ -473,15 +473,21 @@ int bdrv_commit(BlockDriverState *bs)
        return -ENOTSUP;
     }
 
+    sector = qemu_memalign(512,512);
+    if (sector == NULL)
+        return -ENOMEM;
+
     total_sectors = bdrv_getlength(bs) >> SECTOR_BITS;
     for (i = 0; i < total_sectors;) {
         if (drv->bdrv_is_allocated(bs, i, 65536, &n)) {
             for(j = 0; j < n; j++) {
                 if (bdrv_read(bs, i, sector, 1) != 0) {
+                    qemu_free(sector);
                     return -EIO;
                 }
 
                 if (bdrv_write(bs->backing_hd, i, sector, 1) != 0) {
+                    qemu_free(sector);
                     return -EIO;
                 }
                 i++;
@@ -491,6 +497,7 @@ int bdrv_commit(BlockDriverState *bs)
         }
     }
 
+    qemu_free(sector);
     if (drv->bdrv_make_empty)
        return drv->bdrv_make_empty(bs);

-- 
----------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry

[-- Attachment #1.2: Ceci est une partie de message numériquement signée --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

  parent reply	other threads:[~2008-01-07 10:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-04  7:11 [PATCH] qemu: use statically allocate 512 byte buffer in the stack for sector in bdrv_commit Carlo Marcelo Arenas Belon
2008-01-07  9:27 ` Avi Kivity
     [not found]   ` <4781F08E.8060407-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-07 10:22     ` Laurent Vivier [this message]
2008-01-07 10:47       ` Avi Kivity
     [not found]         ` <4782034C.4000805-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-07 12:08           ` Laurent Vivier
2008-01-07 15:16           ` Laurent Vivier
2008-01-07 15:34             ` Javier Guerra
     [not found]               ` <90eb1dc70801070734l2062cac6r7a7bed1d6d3d2c0c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-01-07 15:45                 ` Laurent Vivier
2008-01-07 16:03                   ` Javier Guerra
     [not found]                     ` <90eb1dc70801070803w1a863acs75677e707446f79a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-01-07 16:30                       ` Laurent Vivier
2008-01-07 16:42                         ` Javier Guerra
     [not found]                           ` <90eb1dc70801070842g585cd92dr8a8a383e2f3274df-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-01-07 17:05                             ` Laurent Vivier
2008-01-07 18:32                       ` Avi Kivity
2008-01-07 18:29                 ` Avi Kivity
2008-01-07 18:27             ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1199701358.19008.1.camel@frecb07144 \
    --to=laurent.vivier-6ktuutfb/bm@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox