Skip to contentSkip to conversation

SCSI passthrough: DVD support

PATCH In review Laurent Vivier 2 participants 3 messages Jan 6, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SCSI passthrough: DVD support

This patch allows to use SCSI passthrough to read movies from DVD. It has been tested with PowerDVD and XP.

It also introduces some comments in block-raw-posix.c to explain behavior of negative offset and negative nb_sectors.
It restores original value of aio_num and aio_threads.

Laurent

---
 block-raw-posix.c |    7 +++++--
 hw/scsi-generic.c |   14 ++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
hw/scsi-generic.c +12 -2
Index: qemu/hw/scsi-generic.c
===================================================================
@@ -44,9 +44,12 @@ do { fprintf(stderr, "scsi-generic: " fm
 #include <scsi/sg.h>
 #include <scsi/scsi.h>
 
+#define BLANK 0xa1
+#define SEND_KEY 0xa3
+#define REPORT_KEY 0xa4
 #define LOAD_UNLOAD 0xa6
+#define READ_DVD_STRUCTURE 0xad
 #define SET_CD_SPEED 0xbb
-#define BLANK 0xa1
 
 #define SCSI_CMD_BUF_SIZE     16
 #define SCSI_SENSE_BUF_SIZE 32
@@ -166,7 +169,7 @@ static void scsi_command_complete(void *
             sense = s->sensebuf[2] & 0x0f;
     }
 
-    DPRINTF("Command complete 0x%p tag=0x%x sense=%d\n", r, r->tag, sense);
+    DPRINTF("Command complete %p tag=0x%x sense=%d\n", r, r->tag, sense);
     tag = r->tag;
     scsi_remove_request(r);
     s->completion(s->opaque, SCSI_REASON_DONE, tag, sense);
@@ -427,6 +430,12 @@ static int scsi_length(uint8_t *cmd, int
     case READ_12:
         *len *= blocksize;
         break;
+  case READ_DVD_STRUCTURE:
+  case SEND_KEY:
+  case REPORT_KEY:
+      *len &= 0xffff;
+      break;
+
     }
     return 0;
 }
@@ -464,6 +473,7 @@ static int is_write(int command)
     case MEDIUM_SCAN:
     case SEND_VOLUME_TAG:
     case WRITE_LONG_2:
+    case SEND_KEY:
         return 1;
     }
     return 0;
block-raw-posix.c +5 -2
Index: qemu/block-raw-posix.c
===================================================================
@@ -151,6 +151,8 @@ static int raw_pread(BlockDriverState *b
     if (ret < 0)
         return ret;
 
+    /* if offset < 0, we don't make lseek() */
+
     if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
         ++(s->lseek_err_cnt);
         if(s->lseek_err_cnt <= 10) {
@@ -276,8 +278,8 @@ void qemu_aio_init(void)
            seems to fix the problem. */
         struct aioinit ai;
         memset(&ai, 0, sizeof(ai));
-        ai.aio_threads = 16;
-        ai.aio_num = 16;
+        ai.aio_threads = 1;
+        ai.aio_num = 1;
         ai.aio_idle_time = 365 * 100000;
         aio_init(&ai);
     }
@@ -387,6 +389,7 @@ static RawAIOCB *raw_aio_setup(BlockDriv
     acb->aiocb.aio_sigevent.sigev_signo = aio_sig_num;
     acb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
     acb->aiocb.aio_buf = buf;
+    /* if nb_sectors < 0, -nb_sectors is a number of bytes */
     if (nb_sectors < 0)
         acb->aiocb.aio_nbytes = -nb_sectors;
     else
#1 lore raw

Can you explain why you use the block layer (block-raw-posix.c) to send your low level SCSI commands ? I suggest to remove your patches to block-raw-posix.c and to implement all the SCSI passthough in scsi-generic.c.

Regards,

Fabrice.

Quoted 97 lines · Laurent Vivier

This patch allows to use SCSI passthrough to read movies from DVD. It has been tested with PowerDVD and XP.

It also introduces some comments in block-raw-posix.c to explain behavior of negative offset and negative nb_sectors.
It restores original value of aio_num and aio_threads.

Laurent

---
 block-raw-posix.c |    7 +++++--
 hw/scsi-generic.c |   14 ++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

Index: qemu/hw/scsi-generic.c
===================================================================

hw/scsi-generic.c +12 -2
@@ -44,9 +44,12 @@ do { fprintf(stderr, "scsi-generic: " fm
 #include <scsi/sg.h>
 #include <scsi/scsi.h>
 
+#define BLANK 0xa1
+#define SEND_KEY 0xa3
+#define REPORT_KEY 0xa4
 #define LOAD_UNLOAD 0xa6
+#define READ_DVD_STRUCTURE 0xad
 #define SET_CD_SPEED 0xbb
-#define BLANK 0xa1
 
 #define SCSI_CMD_BUF_SIZE     16
 #define SCSI_SENSE_BUF_SIZE 32
@@ -166,7 +169,7 @@ static void scsi_command_complete(void *
             sense = s->sensebuf[2] & 0x0f;
     }
 
-    DPRINTF("Command complete 0x%p tag=0x%x sense=%d\n", r, r->tag, sense);
+    DPRINTF("Command complete %p tag=0x%x sense=%d\n", r, r->tag, sense);
     tag = r->tag;
     scsi_remove_request(r);
     s->completion(s->opaque, SCSI_REASON_DONE, tag, sense);
@@ -427,6 +430,12 @@ static int scsi_length(uint8_t *cmd, int
     case READ_12:
         *len *= blocksize;
         break;
+  case READ_DVD_STRUCTURE:
+  case SEND_KEY:
+  case REPORT_KEY:
+      *len &= 0xffff;
+      break;
+
     }
     return 0;
 }
@@ -464,6 +473,7 @@ static int is_write(int command)
     case MEDIUM_SCAN:
     case SEND_VOLUME_TAG:
     case WRITE_LONG_2:
+    case SEND_KEY:
         return 1;
     }
     return 0;

Index: qemu/block-raw-posix.c
===================================================================

block-raw-posix.c +5 -2
@@ -151,6 +151,8 @@ static int raw_pread(BlockDriverState *b
     if (ret < 0)
         return ret;
 
+    /* if offset < 0, we don't make lseek() */
+
     if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
         ++(s->lseek_err_cnt);
         if(s->lseek_err_cnt <= 10) {
@@ -276,8 +278,8 @@ void qemu_aio_init(void)
            seems to fix the problem. */
         struct aioinit ai;
         memset(&ai, 0, sizeof(ai));
-        ai.aio_threads = 16;
-        ai.aio_num = 16;
+        ai.aio_threads = 1;
+        ai.aio_num = 1;
         ai.aio_idle_time = 365 * 100000;
         aio_init(&ai);
     }
@@ -387,6 +389,7 @@ static RawAIOCB *raw_aio_setup(BlockDriv
     acb->aiocb.aio_sigevent.sigev_signo = aio_sig_num;
     acb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
     acb->aiocb.aio_buf = buf;
+    /* if nb_sectors < 0, -nb_sectors is a number of bytes */
     if (nb_sectors < 0)
         acb->aiocb.aio_nbytes = -nb_sectors;
     else
#2 lore raw
Quoted 2 lines · Fabrice Bellard

Can you explain why you use the block layer (block-raw-posix.c) to send your low level SCSI commands ?

only because it uses asynchrones AIO and I don't want to rewrite block-raw-posix.c for this special case.

Quoted 1 line

I suggest to remove your patches to

As you want...

Quoted 2 lines

block-raw-posix.c and to implement all the SCSI passthough in scsi-generic.c.

and I'll do as you want.

Quoted 3 lines

Regards,

Fabrice.

Regards,
Laurent

Quoted 101 lines
Quoted 97 lines · Laurent Vivier

This patch allows to use SCSI passthrough to read movies from DVD. It has been tested with PowerDVD and XP.

It also introduces some comments in block-raw-posix.c to explain behavior of negative offset and negative nb_sectors.
It restores original value of aio_num and aio_threads.

Laurent

---
 block-raw-posix.c |    7 +++++--
 hw/scsi-generic.c |   14 ++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

Index: qemu/hw/scsi-generic.c
===================================================================

hw/scsi-generic.c +12 -2
@@ -44,9 +44,12 @@ do { fprintf(stderr, "scsi-generic: " fm
 #include <scsi/sg.h>
 #include <scsi/scsi.h>
 
+#define BLANK 0xa1
+#define SEND_KEY 0xa3
+#define REPORT_KEY 0xa4
 #define LOAD_UNLOAD 0xa6
+#define READ_DVD_STRUCTURE 0xad
 #define SET_CD_SPEED 0xbb
-#define BLANK 0xa1
 
 #define SCSI_CMD_BUF_SIZE     16
 #define SCSI_SENSE_BUF_SIZE 32
@@ -166,7 +169,7 @@ static void scsi_command_complete(void *
             sense = s->sensebuf[2] & 0x0f;
     }
 
-    DPRINTF("Command complete 0x%p tag=0x%x sense=%d\n", r, r->tag, sense);
+    DPRINTF("Command complete %p tag=0x%x sense=%d\n", r, r->tag, sense);
     tag = r->tag;
     scsi_remove_request(r);
     s->completion(s->opaque, SCSI_REASON_DONE, tag, sense);
@@ -427,6 +430,12 @@ static int scsi_length(uint8_t *cmd, int
     case READ_12:
         *len *= blocksize;
         break;
+  case READ_DVD_STRUCTURE:
+  case SEND_KEY:
+  case REPORT_KEY:
+      *len &= 0xffff;
+      break;
+
     }
     return 0;
 }
@@ -464,6 +473,7 @@ static int is_write(int command)
     case MEDIUM_SCAN:
     case SEND_VOLUME_TAG:
     case WRITE_LONG_2:
+    case SEND_KEY:
         return 1;
     }
     return 0;

Index: qemu/block-raw-posix.c
===================================================================

block-raw-posix.c +5 -2
@@ -151,6 +151,8 @@ static int raw_pread(BlockDriverState *b
     if (ret < 0)
         return ret;
 
+    /* if offset < 0, we don't make lseek() */
+
     if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) {
         ++(s->lseek_err_cnt);
         if(s->lseek_err_cnt <= 10) {
@@ -276,8 +278,8 @@ void qemu_aio_init(void)
            seems to fix the problem. */
         struct aioinit ai;
         memset(&ai, 0, sizeof(ai));
-        ai.aio_threads = 16;
-        ai.aio_num = 16;
+        ai.aio_threads = 1;
+        ai.aio_num = 1;
         ai.aio_idle_time = 365 * 100000;
         aio_init(&ai);
     }
@@ -387,6 +389,7 @@ static RawAIOCB *raw_aio_setup(BlockDriv
     acb->aiocb.aio_sigevent.sigev_signo = aio_sig_num;
     acb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
     acb->aiocb.aio_buf = buf;
+    /* if nb_sectors < 0, -nb_sectors is a number of bytes */
     if (nb_sectors < 0)
         acb->aiocb.aio_nbytes = -nb_sectors;
     else
Signature · 3 lines
----------------- [email protected]  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry