Skip to contentSkip to conversation

Error on O_DIRECT for physical CDROM/DVD drives

PATCH Superseded [email protected] 3 participants 5 messages Jul 20, 2010 – Jul 21, 2010 Block layer

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Error on O_DIRECT for physical CDROM/DVD drives

From: Jes Sorensen <[email protected]>

O_DIRECT (cache=none) requires sector alignment, however the physical sector size of CDROM/DVD drives is 2048, as opposed to most disk devices which use 512. QEMU is hard coding 512 all over the place, so allowing O_DIRECT for CDROM/DVD devices does not work. Exit with an error!

---
 block/raw-posix.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
block/raw-posix.c +5 -0
index 291699f..1b840c4 100644
@@ -1139,6 +1139,11 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
     BDRVRawState *s = bs->opaque;
 
     s->type = FTYPE_CD;
+    if (flags & BDRV_O_NOCACHE) {
+        fprintf(stderr, "O_DIRECT (cache=none) for CDROM/DVD device (%s) "
+                "is unsupported\n", filename);
+        exit(1);
+    }
 
     /* open will not fail even if no CD is inserted, so add O_NONBLOCK */
     return raw_open_common(bs, filename, flags, O_NONBLOCK);
Signature · 1 line
1.7.1.1
#1 lore raw
Quoted 18 lines · On 07/20/10 10:09, [email protected] wrote:

From: Jes Sorensen <[email protected]>

O_DIRECT (cache=none) requires sector alignment, however the physical sector size of CDROM/DVD drives is 2048, as opposed to most disk devices which use 512. QEMU is hard coding 512 all over the place, so allowing O_DIRECT for CDROM/DVD devices does not work. Exit with an error!

---
 block/raw-posix.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
block/raw-posix.c +0 -0
index 291699f..1b840c4 100644

block/raw-posix.c static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) · line 1146

Quoted 8 lines
block/raw-posix.c +5 -0
@@ -1139,6 +1139,11 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
     BDRVRawState *s = bs->opaque;
 
     s->type = FTYPE_CD;
+    if (flags & BDRV_O_NOCACHE) {
+        fprintf(stderr, "O_DIRECT (cache=none) for CDROM/DVD device (%s) "
+                "is unsupported\n", filename);
+        exit(1);
+    }

If a cdrom is added via the monitor this would abruptly terminate the VM
- which is not good.

David

Quoted 3 lines
block/raw-posix.c +0 -0
     /* open will not fail even if no CD is inserted, so add O_NONBLOCK */
     return raw_open_common(bs, filename, flags, O_NONBLOCK);
#2 lore raw
Quoted 8 lines · David S. Ahern
Quoted 7 lines · On 07/20/10 10:09, [email protected] wrote:
block/raw-posix.c +0 -0
index 291699f..1b840c4 100644
@@ -1139,6 +1139,11 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
     BDRVRawState *s = bs->opaque;
 
Quoted 9 lines

block/raw-posix.c static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) · line 1146

Quoted 6 lines
block/raw-posix.c +5 -0
     s->type = FTYPE_CD;
+    if (flags & BDRV_O_NOCACHE) {
+        fprintf(stderr, "O_DIRECT (cache=none) for CDROM/DVD device (%s) "
+                "is unsupported\n", filename);
+        exit(1);
+    }

If a cdrom is added via the monitor this would abruptly terminate the VM
- which is not good.

True, but this would only happen if the user explicitly marks it cache=none which is not the default value for a new drive, so it would be a corner case.

Cheers,
Jes

#3 lore raw
Quoted 19 lines · Jes Sorensen
Quoted 8 lines · David S. Ahern
Quoted 7 lines · On 07/20/10 10:09, [email protected] wrote:
block/raw-posix.c +0 -0
index 291699f..1b840c4 100644
@@ -1139,6 +1139,11 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
     BDRVRawState *s = bs->opaque;
 
Quoted 9 lines

block/raw-posix.c static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) · line 1146

Quoted 6 lines
block/raw-posix.c +5 -0
     s->type = FTYPE_CD;
+    if (flags & BDRV_O_NOCACHE) {
+        fprintf(stderr, "O_DIRECT (cache=none) for CDROM/DVD device (%s) "
+                "is unsupported\n", filename);
+        exit(1);
+    }

If a cdrom is added via the monitor this would abruptly terminate the VM
- which is not good.

Quoted 3 lines

True, but this would only happen if the user explicitly marks it cache=none which is not the default value for a new drive, so it would be a corner case.

Why not return -ENOTSUP?

#4 lore raw
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Jes Sorensen
Quoted 3 lines · David S. Ahern

On 07/20/10 10:09, [email protected] wrote:
If a cdrom is added via the monitor this would abruptly terminate the VM
- which is not good.

Quoted 5 lines
Quoted 3 lines

True, but this would only happen if the user explicitly marks it cache=none which is not the default value for a new drive, so it would be a corner case.

Why not return -ENOTSUP?

Good point, just posted v3 of the patch that does this instead of exit()

Jes