All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Schmitt" <scdbackup@gmx.net>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] Do you have a use for a tester of virtio-scsi with CD drives ?
Date: Thu, 03 Nov 2011 23:30:24 +0100	[thread overview]
Message-ID: <9745359965177@192.168.2.69> (raw)
In-Reply-To: <9746334627355@192.168.2.69>

Hi,

i could track down the reason for sense code B 00 06 to an ioctl(SG_IO)
which returns -1.  errno is 1.
The host system has in /usr/include/asm-generic/errno-base.h
  #define EPERM            1      /* Operation not permitted */

The user who runs qemu is able to perform e.g. 
  PREVENT/ALLOW MEDIA REMOVAL
  1e 00 00 00 00 00 
via ioctl(SG_IO) on /dev/sg1.
So it can hardly be the permissions of the device file:
  crw-rw---- 1 root cdrom 21, 1 Nov  2 12:44 /dev/sg1
The user is member of group cdrom.

For today, i close my shop. Maybe i get an idea tomorrow, how
to further investigate the problem.

---------------------------------------------------------------------

B 00 06 comes from hw/scsi-generic.c:scsi_command_complete()

  static void scsi_command_complete(void *opaque, int ret)
  {
  ...
      if (ret != 0) {
          switch (ret) {
          ...
          default:
              status = CHECK_CONDITION;
              scsi_req_build_sense(&r->req, SENSE_CODE(IO_ERROR));

SENSE_CODE is defined in hw/scsi.h
  #define SENSE_CODE(x) sense_code_ ## x

so that SENSE_CODE(IO_ERROR) yields this struct from hw/scsi-bus.c
  /* Command aborted, I/O process terminated */
  const struct SCSISense sense_code_IO_ERROR = {
      .key = ABORTED_COMMAND, .asc = 0x00, .ascq = 0x06
  };


I tried to activate DPRINTF in hw/scsi-generic.c by removing the "//"
before
  #define DEBUG_SCSI

make yields:
  .../hw/scsi-generic.c: In function 'scsi_send_command':
  .../hw/scsi-generic.c:286: error: 'lun' undeclared (first use in this function)
  .../hw/scsi-generic.c:286: error: 'tag' undeclared (first use in this function)

So i had to change in scsi_send_command():

  -     DPRINTF("Command: lun=%d tag=0x%x len %zd data=0x%02x", lun, tag,
  +     DPRINTF("Command: len %zd data=0x%02x",

Further i added DPRINTFs to the suspected thrower of B 00 06:

        if (ret < 0) {
            DPRINTF("scsi_send_command: calling scsi_command_complete(%d)\n", 
                    ret);
            scsi_command_complete(r, ret);
            return 0;
        }
        DPRINTF("scsi_send_command: returning 0\n");

This yields with boot-time command
  1e 00 00 00 00 00 
in the qemu start terminal:

  scsi-generic: Command: len 0 data=0x1e 0x00 0x00 0x00 0x00 0x00
  scsi-generic: scsi_send_command: returning 0
  scsi-generic: scsi_command_complete: ret= -1

I.e. it went through scsi_send_command() and got 0 as return value from
  ret = execute_command(s->conf.bs, r, SG_DXFER_NONE, scsi_command_complete);
Nevertheless there happens a call to scsi_command_complete() with ret==-1.

I added more DPRINTF and printf. 
It turns out that the offending call comes from
  posix-aio-compat.c: posix_aio_process_queue
after the ioctl(SG_IO) failed.

My print points report:
  scsi-generic: Command: len 0 data=0x1e 0x00 0x00 0x00 0x00 0x00
  block.c: bdrv_aio_ioctl: drv= 0x961f00 , drv->bdrv_aio_ioctl= 0x42bc30
  block.c: bdrv_aio_ioctl: drv= 0x9619e0 , drv->bdrv_aio_ioctl= 0x42b2d0
  block/raw-posix.c: hdev_aio_ioctl: calling paio_ioctl()
  scsi-generic: scsi_send_command: returning 0
  posix-aio-compat.c: handle_aiocb_ioctl: ioctl(12, 0x2285, ), ret= -1 , errno= 1
  posix-aio-compat.c: qemu_paio_error: ret= -1
  posix-aio-compat.c: qemu_paio_error: returning 1
  posix-aio-compat.c: posix_aio_process_queue: ret= 1 -> -1
  posix-aio-compat.c: posix_aio_process_queue: calling acb->common.cb(,-1)
  scsi-generic: scsi_command_complete: ret= -1
  scsi-generic: Command complete 0x0x16c0e60 tag=0x0 status=2

ioctl command 0x2285 is defined in /usr/include/scsi/sg.h of host:
  #define SG_IO 0x2285

---------------------------------------------------------------------

Since i inserted the last few of the new printf() calls, i occasionaly
suffer qemu abort by SIGSEGV during guest boot. It happens before the
first DPRINTF happens in scsi_send_command(). 

But "git diff" reveils no changes towards the original state, which
would be to blame.
The printf format codes and the types match good enough to cause
no warnings at compile time.

Is it a known problem, that adding DPRINTF() or printf() can cause this ?
Or am i just too tired to see my fault ?

+    printf("block.c: bdrv_aio_ioctl: drv= 0x%lx , drv->bdrv_aio_ioctl= 0x%lx\n"
,
+           (unsigned long) drv,
+           (unsigned long) (drv ? drv->bdrv_aio_ioctl : NULL));

+    printf("block/raw-posix.c: hdev_aio_ioctl: calling paio_ioctl()\n");

+            DPRINTF("scsi_command_complete: ret= %d\n", ret);

+        DPRINTF("scsi_read_data: calling scsi_command_complete(%d)\n", ret);

+    DPRINTF("scsi_write_complete: calling scsi_command_complete(%d)\n", ret);

+        DPRINTF("scsi_write_data: calling scsi_command_complete(%d)\n",
+                ret);

+    DPRINTF("Command: len %zd data=0x%02x",
             r->req.cmd.xfer, cmd[0]);

+            DPRINTF("scsi_send_command: calling scsi_command_complete(%d)\n",
+                    ret);

+        DPRINTF("scsi_send_command: returning 0\n");

+    DPRINTF("scsi_send_command: not through execute_command()\n");

+        if(ret)
+           printf("linux-aio.c: qemu_laio_process_completion: ret= %d\n",
+                  ret);

+    if(ret)
+      printf("posix-aio-compat.c: handle_aiocb_ioctl: ioctl(%d, 0x%lx, ), ret= %d , errno= %d\n",
+         aiocb->aio_fildes, (unsigned long) aiocb->aio_ioctl_cmd, ret, errno);

+    if(ret)
+      printf("posix-aio-compat.c: qemu_paio_error: ret= %ld\n", (long int) ret);

+    if(ret)
+      printf("posix-aio-compat.c: qemu_paio_error: returning %ld\n", (long int) ret);

+                    if(ret)
+                      printf("posix-aio-compat.c: posix_aio_process_queue: ret= %d -> %d\n", ret, -ret);

+                if(ret)
+                  printf("posix-aio-compat.c: posix_aio_process_queue: calling acb->common.cb(,%d)\n", ret);

---------------------------------------------------------------------

Have a nice day :)

Thomas

  reply	other threads:[~2011-11-03 22:30 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-01 17:27 [Qemu-devel] Do you have a use for a tester of virtio-scsi with CD drives ? Thomas Schmitt
2011-11-01 21:03 ` Thomas Schmitt
2011-11-02 11:25   ` Stefan Hajnoczi
2011-11-02 12:08     ` Paolo Bonzini
2011-11-02 16:26       ` Thomas Schmitt
2011-11-02 16:34         ` Paolo Bonzini
2011-11-02 18:05           ` Thomas Schmitt
2011-11-02 19:50             ` Paolo Bonzini
2011-11-02 21:22               ` Thomas Schmitt
2011-11-02 22:08                 ` Thomas Schmitt
2011-11-02 22:16                   ` [Qemu-devel] Compile error Frans de Boer
2011-11-02 22:19                     ` Anthony Liguori
2011-11-02 22:31                       ` Frans de Boer
2011-11-03  7:49                 ` [Qemu-devel] Do you have a use for a tester of virtio-scsi with CD drives ? Paolo Bonzini
2011-11-03  9:15                   ` Thomas Schmitt
2011-11-03  9:36                     ` Paolo Bonzini
2011-11-03 13:10                   ` Thomas Schmitt
2011-11-03 22:30                     ` Thomas Schmitt [this message]
2011-11-04  9:18                       ` Thomas Schmitt
2011-11-04  9:38                         ` Paolo Bonzini
2011-11-04 11:09                           ` Thomas Schmitt
2011-11-04 11:31                             ` Paolo Bonzini
2011-11-04 13:03                               ` Thomas Schmitt
2011-11-04 20:28                                 ` Thomas Schmitt
2011-11-05  8:33                                   ` Paolo Bonzini
2011-11-05 13:00                                     ` Thomas Schmitt
2011-11-05 14:37                                   ` Thomas Schmitt
2011-11-05 15:53                                     ` Paolo Bonzini
2011-11-05 16:38                                       ` Thomas Schmitt
2011-11-05 20:47                                     ` Thomas Schmitt
2011-11-06  8:17                                       ` Paolo Bonzini
2011-11-06 10:35                                         ` Thomas Schmitt
2011-11-06 20:14                                         ` Thomas Schmitt
2011-11-07  8:02                                           ` Paolo Bonzini
2011-11-07 10:04                                             ` Thomas Schmitt
2011-11-07 11:13                                               ` Paolo Bonzini
2011-11-07 11:24                                                 ` Zhi Yong Wu
2011-11-07 11:29                                                   ` Paolo Bonzini
2011-11-07 11:40                                                     ` Zhi Yong Wu
2011-11-06  9:31                                       ` Thomas Schmitt
2011-11-04 13:26                       ` Andreas Färber
2011-11-04 14:46                         ` Thomas Schmitt
2011-11-07  8:48             ` Zhi Yong Wu
2011-11-02 15:15     ` Thomas Schmitt
2011-11-02 16:22       ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9745359965177@192.168.2.69 \
    --to=scdbackup@gmx.net \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.