Skip to contentSkip to conversation

Block patches for 1.1

GIT PULL New Kevin Wolf 2 participants 7 messages May 7, 2012 – May 8, 2012 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

The following changes since commit 847c25d01cbe8e4fe457a7426f82daaaf3287aae:

hw/ac97: Mask out the EAPD bit on Powerdown Ctrl/Stat writes (2012-05-07 16:31:40 +0400)

are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony

Hervé Poussineau (1):
fdc: simplify media change handling

Kevin Wolf (1):
qcow2: Limit COW to where it's needed

MORITA Kazutaka (1):
sheepdog: switch to writethrough mode if cluster doesn't support flush

Zhi Yong Wu (2):
block: make bdrv_create adopt coroutine
qcow2: lock on prealloc

 block.c               |   44 ++++++++++++++++++++++++++++++++++++++++++--
 block/qcow2-cluster.c |   14 +++++++++-----
 block/qcow2.c         |    3 +++
 block/sheepdog.c      |    8 ++++++++
 hw/fdc.c              |   29 +++++++++++------------------
 5 files changed, 73 insertions(+), 25 deletions(-)
author
#1 lore raw

PATCH 1/5 sheepdog: switch to writethrough mode if cluster doesn't support flush

From: MORITA Kazutaka <[email protected]>

This is necessary for qemu to work with the older version of Sheepdog which doesn't support SD_OP_FLUSH_VDI.

---
 block/sheepdog.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
block/sheepdog.c +8 -0
index 0ed6b19..e01d371 100644
@@ -1678,6 +1678,14 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
         return ret;
     }
 
+    if (rsp->result == SD_RES_INVALID_PARMS) {
+        dprintf("disable write cache since the server doesn't support it\n");
+
+        s->cache_enabled = 0;
+        closesocket(s->flush_fd);
+        return 0;
+    }
+
     if (rsp->result != SD_RES_SUCCESS) {
         error_report("%s", sd_strerror(rsp->result));
         return -EIO;
Signature · 1 line
1.7.6.5
author
#2 lore raw

PATCH 2/5 qcow2: Limit COW to where it's needed

In reply to Kevin Wolf

This fixes a regression introduced in commit 250196f1. The bug leads to data corruption, found during an Autotest run with a Fedora 8 guest.

Consider a write request whose first part is covered by an already allocated cluster, but additional clusters need to be newly allocated. When counting the number of clusters to allocate, the qcow2 code would decide to do COW for all remaining clusters of the write request, even if some of them are already allocated.

If during this COW operation another write request is issued that touches the same cluster, it will still refer to the old cluster. When the COW completes, the first request will update the L2 table and the second write request will be lost. Note that the requests need not overlap, it's enough for them to touch the same cluster.

This patch ensures that only clusters that really require COW are considered for allocation. In this case any other request writing to the same cluster will be an allocating write and gets serialised.

---
 block/qcow2-cluster.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
block/qcow2-cluster.c +9 -5
index 353889d..10c22fe 100644
@@ -883,15 +883,19 @@ again:
         assert(keep_clusters <= nb_clusters);
         nb_clusters -= keep_clusters;
     } else {
+        keep_clusters = 0;
+        cluster_offset = 0;
+    }
+
+    if (nb_clusters > 0) {
         /* For the moment, overwrite compressed clusters one by one */
-        if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
+        uint64_t entry = be64_to_cpu(l2_table[l2_index + keep_clusters]);
+        if (entry & QCOW_OFLAG_COMPRESSED) {
             nb_clusters = 1;
         } else {
-            nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index);
+            nb_clusters = count_cow_clusters(s, nb_clusters, l2_table,
+                                             l2_index + keep_clusters);
         }
-
-        keep_clusters = 0;
-        cluster_offset = 0;
     }
 
     cluster_offset &= L2E_OFFSET_MASK;
Signature · 1 line
1.7.6.5
author
#3 lore raw

PATCH 3/5 block: make bdrv_create adopt coroutine

In reply to Kevin Wolf

From: Zhi Yong Wu <[email protected]>

The current qemu.git introduces failure with preallocation and some sizes:

qemu-img create -f qcow2 new.img 976563K -o preallocation=metadata
qemu-img: qemu-coroutine-lock.c:111: qemu_co_mutex_unlock: Assertion `mutex->locked == 1' failed.

And lock needs to work in coroutine context. So to fix this issue, we need to make bdrv_create adopt coroutine at first.

---
 block.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)
block.c +42 -2
index 43c794c..ee7d8f2 100644
@@ -341,13 +341,53 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name)
     return drv && bdrv_is_whitelisted(drv) ? drv : NULL;
 }
 
+typedef struct CreateCo {
+    BlockDriver *drv;
+    char *filename;
+    QEMUOptionParameter *options;
+    int ret;
+} CreateCo;
+
+static void coroutine_fn bdrv_create_co_entry(void *opaque)
+{
+    CreateCo *cco = opaque;
+    assert(cco->drv);
+
+    cco->ret = cco->drv->bdrv_create(cco->filename, cco->options);
+}
+
 int bdrv_create(BlockDriver *drv, const char* filename,
     QEMUOptionParameter *options)
 {
-    if (!drv->bdrv_create)
+    int ret;
+
+    Coroutine *co;
+    CreateCo cco = {
+        .drv = drv,
+        .filename = g_strdup(filename),
+        .options = options,
+        .ret = NOT_DONE,
+    };
+
+    if (!drv->bdrv_create) {
         return -ENOTSUP;
+    }
 
-    return drv->bdrv_create(filename, options);
+    if (qemu_in_coroutine()) {
+        /* Fast-path if already in coroutine context */
+        bdrv_create_co_entry(&cco);
+    } else {
+        co = qemu_coroutine_create(bdrv_create_co_entry);
+        qemu_coroutine_enter(co, &cco);
+        while (cco.ret == NOT_DONE) {
+            qemu_aio_wait();
+        }
+    }
+
+    ret = cco.ret;
+    g_free(cco.filename);
+
+    return ret;
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
Signature · 1 line
1.7.6.5
author
#4 lore raw

PATCH 4/5 qcow2: lock on prealloc

In reply to Kevin Wolf

From: Zhi Yong Wu <[email protected]>

preallocate() will be locked. This is required because qcow2_alloc_cluster_link_l2() assumes that it runs under a lock that it can drop while COW is being performed.

---
 block/qcow2.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/qcow2.c +3 -0
index 8c60a6f..ee4678f 100644
@@ -1192,7 +1192,10 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
     /* And if we're supposed to preallocate metadata, do that now */
     if (prealloc) {
+        BDRVQcowState *s = bs->opaque;
+        qemu_co_mutex_lock(&s->lock);
         ret = preallocate(bs);
+        qemu_co_mutex_unlock(&s->lock);
         if (ret < 0) {
             goto out;
         }
Signature · 1 line
1.7.6.5
author
#5 lore raw

PATCH 5/5 fdc: simplify media change handling

In reply to Kevin Wolf

From: Hervé Poussineau <[email protected]>

This also (partly) fixes IBM OS/2 Warp 4.0 floppy installation, where not all floppies have the same format (2x80x18 for the first ones, 2x80x23 for the next ones).

---
 hw/fdc.c |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)
hw/fdc.c +11 -18
index 756d4ce..cb4cd25 100644
@@ -705,6 +705,15 @@ static void fdctrl_raise_irq(FDCtrl *fdctrl, uint8_t status0)
         qemu_set_irq(fdctrl->irq, 1);
         fdctrl->sra |= FD_SRA_INTPEND;
     }
+    if (status0 & FD_SR0_SEEK) {
+        FDrive *cur_drv;
+        /* A seek clears the disk change line (if a disk is inserted) */
+        cur_drv = get_cur_drv(fdctrl);
+        if (cur_drv->max_track) {
+            cur_drv->media_changed = 0;
+        }
+    }
+
     fdctrl->reset_sensei = 0;
     fdctrl->status0 = status0;
     FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
@@ -936,23 +945,7 @@ static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value)
 
 static int fdctrl_media_changed(FDrive *drv)
 {
-    int ret;
-
-    if (!drv->bs)
-        return 0;
-    if (drv->media_changed) {
-        drv->media_changed = 0;
-        ret = 1;
-    } else {
-        ret = bdrv_media_changed(drv->bs);
-        if (ret < 0) {
-            ret = 0;            /* we don't know, assume no */
-        }
-    }
-    if (ret) {
-        fd_revalidate(drv);
-    }
-    return ret;
+    return drv->media_changed;
 }
 
 /* Digital input register : 0x07 (read-only) */
@@ -1856,6 +1849,7 @@ static void fdctrl_change_cb(void *opaque, bool load)
     FDrive *drive = opaque;
 
     drive->media_changed = 1;
+    fd_revalidate(drive);
 }
 
 static const BlockDevOps fdctrl_block_ops = {
@@ -1886,7 +1880,6 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)
         fd_init(drive);
         fd_revalidate(drive);
         if (drive->bs) {
-            drive->media_changed = 1;
             bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive);
         }
     }
Signature · 1 line
1.7.6.5
#6 lore raw
In reply to Kevin Wolf
Quoted 6 lines · Kevin Wolf

The following changes since commit 847c25d01cbe8e4fe457a7426f82daaaf3287aae:

hw/ac97: Mask out the EAPD bit on Powerdown Ctrl/Stat writes (2012-05-07 16:31:40 +0400)

are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 22 lines

Hervé Poussineau (1):
fdc: simplify media change handling

Kevin Wolf (1):
qcow2: Limit COW to where it's needed

MORITA Kazutaka (1):
sheepdog: switch to writethrough mode if cluster doesn't support flush

Zhi Yong Wu (2):
block: make bdrv_create adopt coroutine
qcow2: lock on prealloc

  block.c               |   44 ++++++++++++++++++++++++++++++++++++++++++--
  block/qcow2-cluster.c |   14 +++++++++-----
  block/qcow2.c         |    3 +++
  block/sheepdog.c      |    8 ++++++++
  hw/fdc.c              |   29 +++++++++++------------------
  5 files changed, 73 insertions(+), 25 deletions(-)