All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13
@ 2010-09-13 12:42 Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 01/13] scsi-disk: fix the mode data length field returned by the MODE SENSE command Kevin Wolf
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

The following changes since commit 72230c523bda18d4dd2f7d16f96cc59e8fbbd6c9:

  Update version for 0.13.0-rc1 (2010-08-31 08:19:23 -0500)

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

Bernhard Kohl (6):
      scsi-disk: fix the mode data length field returned by the MODE SENSE command
      scsi-disk: fix the mode data header returned by the MODE SENSE(10) command
      scsi-disk: respect the page control (PC) field in the MODE SENSE command
      scsi-disk: fix the block descriptor returned by the MODE SENSE command
      scsi-disk: return CHECK CONDITION for unknown page codes in the MODE SENSE command
      scsi-disk: fix the check of the DBD bit in the MODE SENSE command

Kevin Wolf (7):
      raw-posix: Don't use file name for host_cdrom detection on Linux
      qemu-img convert: Use cache=unsafe for output image
      block: Fix BDRV_O_CACHE_MASK
      qcow2: Remove unnecessary flush after L2 write
      vvfat: Fix segfault on write to read-only disk
      vvfat: Fix double free for opening the image rw
      vvfat: Use cache=unsafe

 block.h               |    2 +-
 block/qcow2-cluster.c |   16 ++++++--
 block/raw-posix.c     |    3 --
 block/vvfat.c         |   26 ++++++++++----
 hw/scsi-disk.c        |   90 ++++++++++++++++++++++++++++++++++++++----------
 qemu-img.c            |    3 +-
 6 files changed, 105 insertions(+), 35 deletions(-)

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

* [Qemu-devel] [STABLE 0.13][PATCH 01/13] scsi-disk: fix the mode data length field returned by the MODE SENSE command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 02/13] scsi-disk: fix the mode data header returned by the MODE SENSE(10) command Kevin Wolf
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

The MODE DATA LENGTH field indicates the length in bytes of the following
data that is available to be transferred. The mode data length does not include
the number of bytes in the MODE DATA LENGTH field.

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 78e70c30612833fd0017cfa5b519bc23df808927)
---
 hw/scsi-disk.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f43f2d0..57439f4 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -652,7 +652,7 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
     }
 
     buflen = p - outbuf;
-    outbuf[0] = buflen - 4;
+    outbuf[0] = buflen - 1;
     if (buflen > req->cmd.xfer)
         buflen = req->cmd.xfer;
     return buflen;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 02/13] scsi-disk: fix the mode data header returned by the MODE SENSE(10) command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 01/13] scsi-disk: fix the mode data length field returned by the MODE SENSE command Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 03/13] scsi-disk: respect the page control (PC) field in the MODE SENSE command Kevin Wolf
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

The header for the  MODE SENSE(10) command is 8 bytes long.

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit ce512ee115b20bfc8a562d528a3f14eeff9ddf64)
---
 hw/scsi-disk.c |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 57439f4..22489b8 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -606,6 +606,7 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
     uint64_t nb_sectors;
     int page, dbd, buflen;
     uint8_t *p;
+    uint8_t dev_specific_param;
 
     dbd = req->cmd.buf[1]  & 0x8;
     page = req->cmd.buf[2] & 0x3f;
@@ -613,16 +614,31 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
     memset(outbuf, 0, req->cmd.xfer);
     p = outbuf;
 
-    p[1] = 0; /* Default media type.  */
-    p[3] = 0; /* Block descriptor length.  */
     if (bdrv_is_read_only(s->bs)) {
-        p[2] = 0x80; /* Readonly.  */
+        dev_specific_param = 0x80; /* Readonly.  */
+    } else {
+        dev_specific_param = 0x00;
+    }
+
+    if (req->cmd.buf[0] == MODE_SENSE) {
+        p[1] = 0; /* Default media type.  */
+        p[2] = dev_specific_param;
+        p[3] = 0; /* Block descriptor length.  */
+        p += 4;
+    } else { /* MODE_SENSE_10 */
+        p[2] = 0; /* Default media type.  */
+        p[3] = dev_specific_param;
+        p[6] = p[7] = 0; /* Block descriptor length.  */
+        p += 8;
     }
-    p += 4;
 
     bdrv_get_geometry(s->bs, &nb_sectors);
     if ((~dbd) & nb_sectors) {
-        outbuf[3] = 8; /* Block descriptor length  */
+        if (req->cmd.buf[0] == MODE_SENSE) {
+            outbuf[3] = 8; /* Block descriptor length  */
+        } else { /* MODE_SENSE_10 */
+            outbuf[7] = 8; /* Block descriptor length  */
+        }
         nb_sectors /= s->cluster_size;
         nb_sectors--;
         if (nb_sectors > 0xffffff)
@@ -652,7 +668,17 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
     }
 
     buflen = p - outbuf;
-    outbuf[0] = buflen - 1;
+    /*
+     * The mode data length field specifies the length in bytes of the
+     * following data that is available to be transferred. The mode data
+     * length does not include itself.
+     */
+    if (req->cmd.buf[0] == MODE_SENSE) {
+        outbuf[0] = buflen - 1;
+    } else { /* MODE_SENSE_10 */
+        outbuf[0] = ((buflen - 2) >> 8) & 0xff;
+        outbuf[1] = (buflen - 2) & 0xff;
+    }
     if (buflen > req->cmd.xfer)
         buflen = req->cmd.xfer;
     return buflen;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 03/13] scsi-disk: respect the page control (PC) field in the MODE SENSE command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 01/13] scsi-disk: fix the mode data length field returned by the MODE SENSE command Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 02/13] scsi-disk: fix the mode data header returned by the MODE SENSE(10) command Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 04/13] scsi-disk: fix the block descriptor returned by " Kevin Wolf
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

The page control (PC) field defines the type of mode parameter values
to be returned in the mode pages:

PC=0 : Current values
PC=1 : Changeable values
PC=2 : Default values
PC=3 : Saved values

The current implementation always returns the same type of parameters.
This is OK for Current and Default values as we don't support changes
to be done by the MODE SELECT command.

For Saved values the following applies (implemented by this patch):
"A PC field value of 3h requests that the target return the saved
values of the mode parameters. Implementation of saved page parameters
is optional. Mode parameters not supported by the target shall be set
to zero. If saved values are not implemented, the command shall be
terminated with CHECK CONDITION status, the sense key set to
ILLEGAL REQUEST and the additional sense code set to
SAVING PARAMETERS NOT SUPPORTED."

For Changeable values the following applies (implemented by this patch):
"A PC field value of 1h requests that the target return a mask denoting
those mode parameters that are changeable. In the mask, the fields of
the mode parameters that are changeable shall be set to all one bits and
the fields of the mode parameters that are non-changeable (i.e. defined
by the target) shall be set to all zero bits."

In newer versions of the SCSI-2 spec the following clause was added.
"If the logical unit does not implement changeable parameters mode pages
and the device server receives a MODE SENSE command with 01b in the PC
field, then the command shall be terminated with CHECK CONDITION status,
with the sense key set to ILLEGAL REQUEST, and the additional sense code
set to INVALID FIELD IN CDB."

This was not yet included in the SCSI-2 Working Drafts from 1986-1993.
I assume that the variant to return CHECK CONDITION for PC=1 is not
widely implemented by real devices. I have a legacy OS which fails,
if MODE_SENSE returns non GOOD for PC=1. So for highest compatibility I
implemented the former variant with this patch.

The last Working Draft X3T9.2 Rev. 10L 7-SEP-93 can be found here:
http://ldkelley.com/SCSI2/SCSI2/SCSI2-08.html#8.2.10

In mode_sense_page() this patch also avoids multiple hard coded
definitions of the same mode page length. Instead I use the varable
p[1]. In fact the returned length of the mode pages 4 and 5 were wrong
(2 bytes less).

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 282ab04eb1e6f4faa6c5d2827e3209c4a1eec40e)
---
 hw/scsi-disk.c |   45 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 22489b8..384d19f 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -485,16 +485,26 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
     return buflen;
 }
 
-static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p)
+static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p,
+                           int page_control)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
     BlockDriverState *bdrv = s->bs;
     int cylinders, heads, secs;
 
+    /*
+     * If Changeable Values are requested, a mask denoting those mode parameters
+     * that are changeable shall be returned. As we currently don't support
+     * parameter changes via MODE_SELECT all bits are returned set to zero.
+     * The buffer was already menset to zero by the caller of this function.
+     */
     switch (page) {
     case 4: /* Rigid disk device geometry page. */
         p[0] = 4;
         p[1] = 0x16;
+        if (page_control == 1) { /* Changeable Values */
+            return p[1] + 2;
+        }
         /* if a geometry hint is available, use it */
         bdrv_get_geometry_hint(bdrv, &cylinders, &heads, &secs);
         p[2] = (cylinders >> 16) & 0xff;
@@ -519,11 +529,14 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p)
         /* Medium rotation rate [rpm], 5400 rpm */
         p[20] = (5400 >> 8) & 0xff;
         p[21] = 5400 & 0xff;
-        return 0x16;
+        return p[1] + 2;
 
     case 5: /* Flexible disk device geometry page. */
         p[0] = 5;
         p[1] = 0x1e;
+        if (page_control == 1) { /* Changeable Values */
+            return p[1] + 2;
+        }
         /* Transfer rate [kbit/s], 5Mbit/s */
         p[2] = 5000 >> 8;
         p[3] = 5000 & 0xff;
@@ -555,21 +568,27 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p)
         /* Medium rotation rate [rpm], 5400 rpm */
         p[28] = (5400 >> 8) & 0xff;
         p[29] = 5400 & 0xff;
-        return 0x1e;
+        return p[1] + 2;
 
     case 8: /* Caching page.  */
         p[0] = 8;
         p[1] = 0x12;
+        if (page_control == 1) { /* Changeable Values */
+            return p[1] + 2;
+        }
         if (bdrv_enable_write_cache(s->bs)) {
             p[2] = 4; /* WCE */
         }
-        return 20;
+        return p[1] + 2;
 
     case 0x2a: /* CD Capabilities and Mechanical Status page. */
         if (bdrv_get_type_hint(bdrv) != BDRV_TYPE_CDROM)
             return 0;
         p[0] = 0x2a;
         p[1] = 0x14;
+        if (page_control == 1) { /* Changeable Values */
+            return p[1] + 2;
+        }
         p[2] = 3; // CD-R & CD-RW read
         p[3] = 0; // Writing not supported
         p[4] = 0x7f; /* Audio, composite, digital out,
@@ -593,7 +612,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p)
         p[19] = (16 * 176) & 0xff;
         p[20] = (16 * 176) >> 8; // 16x write speed current
         p[21] = (16 * 176) & 0xff;
-        return 22;
+        return p[1] + 2;
 
     default:
         return 0;
@@ -604,13 +623,15 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
     uint64_t nb_sectors;
-    int page, dbd, buflen;
+    int page, dbd, buflen, page_control;
     uint8_t *p;
     uint8_t dev_specific_param;
 
     dbd = req->cmd.buf[1]  & 0x8;
     page = req->cmd.buf[2] & 0x3f;
-    DPRINTF("Mode Sense (page %d, len %zd)\n", page, req->cmd.xfer);
+    page_control = (req->cmd.buf[2] & 0xc0) >> 6;
+    DPRINTF("Mode Sense(%d) (page %d, len %d, page_control %d)\n",
+        (req->cmd.buf[0] == MODE_SENSE) ? 6 : 10, page, len, page_control);
     memset(outbuf, 0, req->cmd.xfer);
     p = outbuf;
 
@@ -654,16 +675,20 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
         p += 8;
     }
 
+    if (page_control == 3) { /* Saved Values */
+        return -1; /* ILLEGAL_REQUEST */
+    }
+
     switch (page) {
     case 0x04:
     case 0x05:
     case 0x08:
     case 0x2a:
-        p += mode_sense_page(req, page, p);
+        p += mode_sense_page(req, page, p, page_control);
         break;
     case 0x3f:
-        p += mode_sense_page(req, 0x08, p);
-        p += mode_sense_page(req, 0x2a, p);
+        p += mode_sense_page(req, 0x08, p, page_control);
+        p += mode_sense_page(req, 0x2a, p, page_control);
         break;
     }
 
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 04/13] scsi-disk: fix the block descriptor returned by the MODE SENSE command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (2 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 03/13] scsi-disk: respect the page control (PC) field in the MODE SENSE command Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 05/13] scsi-disk: return CHECK CONDITION for unknown page codes in " Kevin Wolf
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

The block descriptor contains the number of blocks, not the highest LBA.
Real hard disks return 0 if the number of blocks exceed the maximum 0xFFFFFF.

SCSI-Spec:
http://ldkelley.com/SCSI2/SCSI2/SCSI2-08.html#8.3.3
"The number of blocks field specifies the number of logical blocks on the
medium to which the density code and block length fields apply. A value
of zero indicates that all of the remaining logical blocks of the logical
unit shall have the medium characteristics specified."

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 2488b74081650a5312fe1515660b6cb095244c34)
---
 hw/scsi-disk.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 384d19f..2a107b1 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -661,9 +661,8 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
             outbuf[7] = 8; /* Block descriptor length  */
         }
         nb_sectors /= s->cluster_size;
-        nb_sectors--;
         if (nb_sectors > 0xffffff)
-            nb_sectors = 0xffffff;
+            nb_sectors = 0;
         p[0] = 0; /* media density code */
         p[1] = (nb_sectors >> 16) & 0xff;
         p[2] = (nb_sectors >> 8) & 0xff;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 05/13] scsi-disk: return CHECK CONDITION for unknown page codes in the MODE SENSE command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (3 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 04/13] scsi-disk: fix the block descriptor returned by " Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 06/13] scsi-disk: fix the check of the DBD bit " Kevin Wolf
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

SCSI-Spec:
http://ldkelley.com/SCSI2/SCSI2/SCSI2-08.html#8.2.10
"An initiator may request any one or all of the supported mode pages
from a target. If an initiator issues a MODE SENSE command with a
page code value not implemented by the target, the target shall return
CHECK CONDITION status and shall set the sense key to ILLEGAL REQUEST
and the additional sense code to INVALID FIELD IN CDB."

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit a9c17b2bf3639662fbdeb736289ebabfda9fa21a)
---
 hw/scsi-disk.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2a107b1..70c7a08 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -689,6 +689,8 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
         p += mode_sense_page(req, 0x08, p, page_control);
         p += mode_sense_page(req, 0x2a, p, page_control);
         break;
+    default:
+        return -1; /* ILLEGAL_REQUEST */
     }
 
     buflen = p - outbuf;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 06/13] scsi-disk: fix the check of the DBD bit in the MODE SENSE command
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (4 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 05/13] scsi-disk: return CHECK CONDITION for unknown page codes in " Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 07/13] raw-posix: Don't use file name for host_cdrom detection on Linux Kevin Wolf
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Bernhard Kohl <bernhard.kohl@nsn.com>

The DBD bit does not work as expected.

SCSI-Spec:
http://ldkelley.com/SCSI2/SCSI2/SCSI2-08.html#8.2.10
"A disable block descriptors (DBD) bit of zero indicates that the target
may return zero or more block descriptors in the returned MODE SENSE
data (see 8.3.3), at the target's discretion. A DBD bit of one
specifies that the target shall not return any block descriptors in the
returned MODE SENSE data."

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 333d50fe3d9a1ff0a6a1a44ef42a0d3a2a7f2abe)
---
 hw/scsi-disk.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 70c7a08..b64dd31 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -654,7 +654,7 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf)
     }
 
     bdrv_get_geometry(s->bs, &nb_sectors);
-    if ((~dbd) & nb_sectors) {
+    if (!dbd && nb_sectors) {
         if (req->cmd.buf[0] == MODE_SENSE) {
             outbuf[3] = 8; /* Block descriptor length  */
         } else { /* MODE_SENSE_10 */
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 07/13] raw-posix: Don't use file name for host_cdrom detection on Linux
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (5 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 06/13] scsi-disk: fix the check of the DBD bit " Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 08/13] qemu-img convert: Use cache=unsafe for output image Kevin Wolf
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

On Linux, we have code to detect CD-ROMs using an ioctl. We shouldn't lose
anything but false positives by removing the check for a /dev/cd* path.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 897804d6299af372a43110799cbe1d6804d5e1bc)
---
 block/raw-posix.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 72fb8ce..0fce449 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1154,9 +1154,6 @@ static int cdrom_probe_device(const char *filename)
     int fd, ret;
     int prio = 0;
 
-    if (strstart(filename, "/dev/cd", NULL))
-        prio = 50;
-
     fd = open(filename, O_RDONLY | O_NONBLOCK);
     if (fd < 0) {
         goto out;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 08/13] qemu-img convert: Use cache=unsafe for output image
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (6 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 07/13] raw-posix: Don't use file name for host_cdrom detection on Linux Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 09/13] block: Fix BDRV_O_CACHE_MASK Kevin Wolf
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

If qemu-img crashes during the conversion, the user will throw away the broken
output file anyway and start over. So no need to be too cautious.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 1bd8e175580a87c7b9e6791faca7626f9bc3ceeb)
---
 qemu-img.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index d2a978b..4e035e4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -783,7 +783,8 @@ static int img_convert(int argc, char **argv)
         goto out;
     }
 
-    out_bs = bdrv_new_open(out_filename, out_fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
+    out_bs = bdrv_new_open(out_filename, out_fmt,
+        BDRV_O_FLAGS | BDRV_O_RDWR | BDRV_O_NO_FLUSH);
     if (!out_bs) {
         ret = -1;
         goto out;
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 09/13] block: Fix BDRV_O_CACHE_MASK
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (7 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 08/13] qemu-img convert: Use cache=unsafe for output image Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 10/13] qcow2: Remove unnecessary flush after L2 write Kevin Wolf
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

BDRV_O_CACHE_MASK should have been extended when cache=unsafe introduced a new
flag BDRV_O_NO_FLUSH. There are currently no users that would change their
behaviour because of this, but let's clean it up before things break.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit ceb25e5c7554255931f7f5647d3ad9df36111f53)
---
 block.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block.h b/block.h
index db131a3..5f64380 100644
--- a/block.h
+++ b/block.h
@@ -35,7 +35,7 @@ typedef struct QEMUSnapshotInfo {
 #define BDRV_O_NO_BACKING  0x0100 /* don't open the backing file */
 #define BDRV_O_NO_FLUSH    0x0200 /* disable flushing on this disk */
 
-#define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
+#define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
 
 #define BDRV_SECTOR_BITS   9
 #define BDRV_SECTOR_SIZE   (1ULL << BDRV_SECTOR_BITS)
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 10/13] qcow2: Remove unnecessary flush after L2 write
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (8 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 09/13] block: Fix BDRV_O_CACHE_MASK Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 11/13] vvfat: Fix segfault on write to read-only disk Kevin Wolf
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

When a new cluster was allocated, we only need a flush after the write to the
L2 table if it was a COW and we need to decrease the refcounts of the old
clusters.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 7ec5e6a4ca43494949465f9f9f3d9e4c7c620503)
---
 block/qcow2-cluster.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 166922f..f562b16 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -655,7 +655,7 @@ static int write_l2_entries(BlockDriverState *bs, uint64_t *l2_table,
     int ret;
 
     BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
-    ret = bdrv_pwrite_sync(bs->file, l2_offset + start_offset,
+    ret = bdrv_pwrite(bs->file, l2_offset + start_offset,
         &l2_table[l2_start_index], len);
     if (ret < 0) {
         return ret;
@@ -718,9 +718,17 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
         goto err;
     }
 
-    for (i = 0; i < j; i++)
-        qcow2_free_any_clusters(bs,
-            be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
+    /*
+     * If this was a COW, we need to decrease the refcount of the old cluster.
+     * Also flush bs->file to get the right order for L2 and refcount update.
+     */
+    if (j != 0) {
+        bdrv_flush(bs->file);
+        for (i = 0; i < j; i++) {
+            qcow2_free_any_clusters(bs,
+                be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
+        }
+    }
 
     ret = 0;
 err:
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 11/13] vvfat: Fix segfault on write to read-only disk
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (9 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 10/13] qcow2: Remove unnecessary flush after L2 write Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 12/13] vvfat: Fix double free for opening the image rw Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 13/13] vvfat: Use cache=unsafe Kevin Wolf
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Kevin Wolf <mail@kevin-wolf.de>

vvfat tries to set the readonly flag in its open function, but nowadays
this is overwritted with the readonly=... command line option. Check in
bdrv_write if the vvfat was opened read-only and return an error in this
case.

Without this check, vvfat tries to access the qcow bs, which is NULL
without enabled write support.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
(cherry picked from commit bfd0049440f53745d31eb93c208f0f3ab6308027)
---
 block/vvfat.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 365332a..5898d66 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2665,6 +2665,11 @@ static int vvfat_write(BlockDriverState *bs, int64_t sector_num,
 
 DLOG(checkpoint());
 
+    /* Check if we're operating in read-only mode */
+    if (s->qcow == NULL) {
+        return -EACCES;
+    }
+
     vvfat_close_current_file(s);
 
     /*
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 12/13] vvfat: Fix double free for opening the image rw
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (10 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 11/13] vvfat: Fix segfault on write to read-only disk Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 13/13] vvfat: Use cache=unsafe Kevin Wolf
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Kevin Wolf <mail@kevin-wolf.de>

Allocation and deallocation of bs->opaque is not in the control of a
block driver. Therefore it should not set bs->opaque to a data structure
used by another bs, or closing the image will lead to a double free.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
(cherry picked from commit 0af1e52e93bf5da63b15f1f9596dd4c076da07dc)
---
 block/vvfat.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 5898d66..0772037 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2768,12 +2768,12 @@ static int vvfat_is_allocated(BlockDriverState *bs,
 
 static int write_target_commit(BlockDriverState *bs, int64_t sector_num,
 	const uint8_t* buffer, int nb_sectors) {
-    BDRVVVFATState* s = bs->opaque;
+    BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
     return try_commit(s);
 }
 
 static void write_target_close(BlockDriverState *bs) {
-    BDRVVVFATState* s = bs->opaque;
+    BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
     bdrv_delete(s->qcow);
     free(s->qcow_filename);
 }
@@ -2816,7 +2816,8 @@ static int enable_write_target(BDRVVVFATState *s)
 
     s->bs->backing_hd = calloc(sizeof(BlockDriverState), 1);
     s->bs->backing_hd->drv = &vvfat_write_target;
-    s->bs->backing_hd->opaque = s;
+    s->bs->backing_hd->opaque = qemu_malloc(sizeof(void*));
+    *(void**)s->bs->backing_hd->opaque = s;
 
     return 0;
 }
-- 
1.7.2.2

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

* [Qemu-devel] [STABLE 0.13][PATCH 13/13] vvfat: Use cache=unsafe
  2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
                   ` (11 preceding siblings ...)
  2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 12/13] vvfat: Fix double free for opening the image rw Kevin Wolf
@ 2010-09-13 12:42 ` Kevin Wolf
  12 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2010-09-13 12:42 UTC (permalink / raw)
  To: anthony; +Cc: kwolf, qemu-devel

From: Kevin Wolf <mail@kevin-wolf.de>

The qcow file used for write support in vvfat is a temporary file,
so we can use cache=unsafe there. Without this, write support is just
too slow to be of any use.

Signed-off-by: Kevin Wolf <mail@kevin-wolf.de>
(cherry picked from commit 35ccd8aed64727dbefa1b274a8000b46318bfea1)
---
 block/vvfat.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 0772037..53e57bf 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2788,6 +2788,7 @@ static int enable_write_target(BDRVVVFATState *s)
 {
     BlockDriver *bdrv_qcow;
     QEMUOptionParameter *options;
+    int ret;
     int size = sector2cluster(s, s->sector_count);
     s->used_clusters = calloc(size, 1);
 
@@ -2803,11 +2804,16 @@ static int enable_write_target(BDRVVVFATState *s)
 
     if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0)
 	return -1;
+
     s->qcow = bdrv_new("");
-    if (s->qcow == NULL ||
-        bdrv_open(s->qcow, s->qcow_filename, BDRV_O_RDWR, bdrv_qcow) < 0)
-    {
-	return -1;
+    if (s->qcow == NULL) {
+        return -1;
+    }
+
+    ret = bdrv_open(s->qcow, s->qcow_filename,
+            BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow);
+    if (ret < 0) {
+	return ret;
     }
 
 #ifndef _WIN32
-- 
1.7.2.2

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

end of thread, other threads:[~2010-09-13 12:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-13 12:42 [Qemu-devel] [STABLE 0.13][PULL 00/13] Block fixes for stable-0.13 Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 01/13] scsi-disk: fix the mode data length field returned by the MODE SENSE command Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 02/13] scsi-disk: fix the mode data header returned by the MODE SENSE(10) command Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 03/13] scsi-disk: respect the page control (PC) field in the MODE SENSE command Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 04/13] scsi-disk: fix the block descriptor returned by " Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 05/13] scsi-disk: return CHECK CONDITION for unknown page codes in " Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 06/13] scsi-disk: fix the check of the DBD bit " Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 07/13] raw-posix: Don't use file name for host_cdrom detection on Linux Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 08/13] qemu-img convert: Use cache=unsafe for output image Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 09/13] block: Fix BDRV_O_CACHE_MASK Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 10/13] qcow2: Remove unnecessary flush after L2 write Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 11/13] vvfat: Fix segfault on write to read-only disk Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 12/13] vvfat: Fix double free for opening the image rw Kevin Wolf
2010-09-13 12:42 ` [Qemu-devel] [STABLE 0.13][PATCH 13/13] vvfat: Use cache=unsafe Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.