qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body.
@ 2014-06-19  1:36 Peter Crosthwaite
  2014-06-19  1:36 ` [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs Peter Crosthwaite
  2014-06-19  3:21 ` [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Crosthwaite @ 2014-06-19  1:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

sync_page() was conditionalizing it's whole fn body on the bdrv being
non-null. Just return for the function immediately on NULL brdv and
get rid of the big if.

Makes implementation consistent with flash_zynq_area().

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/block/m25p80.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 4076114..e4ef733 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -288,18 +288,20 @@ static void bdrv_sync_complete(void *opaque, int ret)
 
 static void flash_sync_page(Flash *s, int page)
 {
-    if (s->bdrv) {
-        int bdrv_sector, nb_sectors;
-        QEMUIOVector iov;
-
-        bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
-        nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE);
-        qemu_iovec_init(&iov, 1);
-        qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE,
-                                                nb_sectors * BDRV_SECTOR_SIZE);
-        bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors,
-                                                bdrv_sync_complete, NULL);
+    int bdrv_sector, nb_sectors;
+    QEMUIOVector iov;
+
+    if (!s->bdrv) {
+        return;
     }
+
+    bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
+    nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE);
+    qemu_iovec_init(&iov, 1);
+    qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE,
+                   nb_sectors * BDRV_SECTOR_SIZE);
+    bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors, bdrv_sync_complete,
+                    NULL);
 }
 
 static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
-- 
2.0.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs.
  2014-06-19  1:36 [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Peter Crosthwaite
@ 2014-06-19  1:36 ` Peter Crosthwaite
  2014-06-19  9:08   ` Paolo Bonzini
  2014-06-19  3:21 ` [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Crosthwaite @ 2014-06-19  1:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

By just never doing write-backs. This is completely invisible to the
guest, as the entire storage area is implemented as device state (at
realize time the entire drive is read in).

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/block/m25p80.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index e4ef733..5893773 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -291,7 +291,7 @@ static void flash_sync_page(Flash *s, int page)
     int bdrv_sector, nb_sectors;
     QEMUIOVector iov;
 
-    if (!s->bdrv) {
+    if (!s->bdrv || bdrv_is_read_only(s->bdrv)) {
         return;
     }
 
@@ -309,7 +309,7 @@ static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
     int64_t start, end, nb_sectors;
     QEMUIOVector iov;
 
-    if (!s->bdrv) {
+    if (!s->bdrv || bdrv_is_read_only(s->bdrv)) {
         return;
     }
 
@@ -627,10 +627,6 @@ static int m25p80_init(SSISlave *ss)
     if (dinfo && dinfo->bdrv) {
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
         s->bdrv = dinfo->bdrv;
-        if (bdrv_is_read_only(s->bdrv)) {
-            fprintf(stderr, "Can't use a read-only drive");
-            return 1;
-        }
 
         /* FIXME: Move to late init */
         if (bdrv_read(s->bdrv, 0, s->storage, DIV_ROUND_UP(s->size,
-- 
2.0.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body.
  2014-06-19  1:36 [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Peter Crosthwaite
  2014-06-19  1:36 ` [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs Peter Crosthwaite
@ 2014-06-19  3:21 ` Stefan Hajnoczi
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-06-19  3:21 UTC (permalink / raw)
  To: Peter Crosthwaite; +Cc: qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

On Wed, Jun 18, 2014 at 06:36:03PM -0700, Peter Crosthwaite wrote:
> sync_page() was conditionalizing it's whole fn body on the bdrv being
> non-null. Just return for the function immediately on NULL brdv and
> get rid of the big if.
> 
> Makes implementation consistent with flash_zynq_area().
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/block/m25p80.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)

I don't know the hardware in question but from a block layer standpoint,
this series is fine.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs.
  2014-06-19  1:36 ` [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs Peter Crosthwaite
@ 2014-06-19  9:08   ` Paolo Bonzini
  2014-06-21  9:06     ` Stefan Hajnoczi
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-06-19  9:08 UTC (permalink / raw)
  To: Peter Crosthwaite, qemu-devel; +Cc: stefanha

> static void bdrv_sync_complete(void *opaque, int ret)
> {
>     /* do nothing. Masters do not directly interact with the backing store,
>      * only the working copy so no mutexing required.
>      */
> }
>
> static void flash_sync_page(Flash *s, int page)
> {
>     if (s->bdrv) {
>         int bdrv_sector, nb_sectors;
>         QEMUIOVector iov;
>
>         bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
>         nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE);
>         qemu_iovec_init(&iov, 1);
>         qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE,
>                                                 nb_sectors * BDRV_SECTOR_SIZE);
>         bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors,
>                                                 bdrv_sync_complete, NULL);
>     }
> }

Using AIO is a good idea, but you could have overlapping writes here if 
you get close calls to flash_sync_page.  It can be bad.

Serializing can be done in fancy manners, but it can be as easy as 
adding bdrv_drain(s->bdrv) before the bdrv_aio_writev.

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs.
  2014-06-19  9:08   ` Paolo Bonzini
@ 2014-06-21  9:06     ` Stefan Hajnoczi
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-06-21  9:06 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Peter Crosthwaite, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]

On Thu, Jun 19, 2014 at 11:08:42AM +0200, Paolo Bonzini wrote:
> >static void bdrv_sync_complete(void *opaque, int ret)
> >{
> >    /* do nothing. Masters do not directly interact with the backing store,
> >     * only the working copy so no mutexing required.
> >     */
> >}
> >
> >static void flash_sync_page(Flash *s, int page)
> >{
> >    if (s->bdrv) {
> >        int bdrv_sector, nb_sectors;
> >        QEMUIOVector iov;
> >
> >        bdrv_sector = (page * s->pi->page_size) / BDRV_SECTOR_SIZE;
> >        nb_sectors = DIV_ROUND_UP(s->pi->page_size, BDRV_SECTOR_SIZE);
> >        qemu_iovec_init(&iov, 1);
> >        qemu_iovec_add(&iov, s->storage + bdrv_sector * BDRV_SECTOR_SIZE,
> >                                                nb_sectors * BDRV_SECTOR_SIZE);
> >        bdrv_aio_writev(s->bdrv, bdrv_sector, &iov, nb_sectors,
> >                                                bdrv_sync_complete, NULL);
> >    }
> >}
> 
> Using AIO is a good idea, but you could have overlapping writes here if you
> get close calls to flash_sync_page.  It can be bad.
> 
> Serializing can be done in fancy manners, but it can be as easy as adding
> bdrv_drain(s->bdrv) before the bdrv_aio_writev.

Since this issue was present before the patch and not caused by this
series I'm keeping it in the block queue.

It would be nice to address this in a separate series.

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-21  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19  1:36 [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Peter Crosthwaite
2014-06-19  1:36 ` [Qemu-devel] [PATCH block v1 2/2] block: m25p80: Support read only bdrvs Peter Crosthwaite
2014-06-19  9:08   ` Paolo Bonzini
2014-06-21  9:06     ` Stefan Hajnoczi
2014-06-19  3:21 ` [Qemu-devel] [PATCH block v1 1/2] block: m25p80: sync_page(): Deindent function body Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).