Re: K3b 1.0.1 eject problem

Sebastian Trüg <[email protected]>
Newsgroups gmane.comp.kde.k3b
Message-ID <[email protected]>
On Thursday 21 June 2007 04:01:15 [email protected] wrote:
> I suppose the error (why the DVD+R VIDEO is not ejected)
> lies at the line "ooo_x5a" (in K3b output: x72_x1_K3b-user):
>
> k3b: (K3bDevice::DeviceHandler) ***ooo_x4_in   DeviceHandlerThread: run() 
> dev = 0x835a2d0
> k3b: (K3bDevice::DeviceHandler) ***ooo_x4_in   DeviceHandlerThread: if( dev
> ) (K3bDevice::Device) ***ooo_x5_in  ::open( bool write ) const  --->  write
> = 0 d->openedReadWrite = 0
> (K3bDevice::Device) ***ooo_x5a             <-- ERROR ?!
>
> Explanation:
> "ooo_x5a" lies directly above: d->mutex.lock();
> "ooo_x5b" lies directly after:   d->mutex.lock();
>
> So one sees that K3b enters "::open( bool write ) const" and leaves it
> before "d->mutex.lock()" (K3b doesn't go through the whole method).

actually K3b never leaves the method and that is the problem. The mutex is 
locked from some other thread and is not unlocked and I cannot figure out 
where it is locked and why it is not unlocked. Especially since it works 
here.... but I will continue the search.

Please find attached a different patch with a bunch of debugging messages that 
I hope will provide the necessary information. Please apply it to the plain 
k3b code without your patches so I can see which thread blocks the device.

Thanks a LOT for your help on this one.

> Compare the counterpart (the K3b output) in x76_x1_K3b-user.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> K3b-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/k3b-user

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
K3b-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/k3b-user
k3b-thread-lock-debug.diff (text/x-diff, 7.7 KB)
Index: libk3bdevice/k3bscsicommand_linux.cpp
===================================================================
--- libk3bdevice/k3bscsicommand_linux.cpp	(revision 665632)
+++ libk3bdevice/k3bscsicommand_linux.cpp	(working copy)
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/utsname.h>
 
+#include <qthread.h>
 
 #if !defined(SG_FLAG_LUN_INHIBIT)
 # if defined(SG_FLAG_UNUSED_LUN_INHIBIT)
@@ -124,12 +125,17 @@
     else
       d->sgIo.dxfer_direction = SG_DXFER_NONE;
 
+
     if ( m_device ) {
+        kdDebug() << "(K3bDevice::ScsiCommand) Locking device: " << m_device->blockDeviceName() << " in thread "
+                  << QThread::currentThread() << endl;
         m_device->usageLock();
     }
     i = ::ioctl( m_deviceHandle, SG_IO, &d->sgIo );
     if ( m_device ) {
         m_device->usageUnlock();
+        kdDebug() << "(K3bDevice::ScsiCommand) Unlocked device: " << m_device->blockDeviceName() << " in thread "
+                  << QThread::currentThread() << endl;
     }
 
     if( ( d->sgIo.info&SG_INFO_OK_MASK ) != SG_INFO_OK )
@@ -145,21 +151,25 @@
       d->cmd.data_direction = CGC_DATA_WRITE;
     else
       d->cmd.data_direction = CGC_DATA_NONE;
-    
+
     if ( m_device ) {
+        kdDebug() << "(K3bDevice::ScsiCommand) Locking device: " << m_device->blockDeviceName() << " in thread "
+                  << QThread::currentThread() << endl;
         m_device->usageLock();
     }
     i = ::ioctl( m_deviceHandle, CDROM_SEND_PACKET, &d->cmd );
     if ( m_device ) {
+        kdDebug() << "(K3bDevice::ScsiCommand) Unlocked device: " << m_device->blockDeviceName() << " in thread "
+                  << QThread::currentThread() << endl;
         m_device->usageUnlock();
     }
 #ifdef SG_IO
   }
-#endif    
+#endif
 
   if( needToClose )
     m_device->close();
-    
+
   if( i ) {
     debugError( d->cmd.cmd[0],
 		d->sense.error_code,
@@ -167,7 +177,7 @@
 		d->sense.asc,
 		d->sense.ascq );
 
-    int errCode = 
+    int errCode =
       (d->sense.error_code<<24) & 0xF000 |
       (d->sense.sense_key<<16)  & 0x0F00 |
       (d->sense.asc<<8)         & 0x00F0 |
Index: libk3bdevice/k3bdevice.cpp
===================================================================
--- libk3bdevice/k3bdevice.cpp	(revision 665632)
+++ libk3bdevice/k3bdevice.cpp	(working copy)
@@ -30,6 +30,7 @@
 #include <qglobal.h>
 #include <qvaluevector.h>
 #include <qmutex.h>
+#include <qthread.h>
 
 #include <k3bdebug.h>
 
@@ -1348,6 +1349,9 @@
     // cdth_trk0: First Track Number
     // cdth_trk1: Last Track Number
     //
+      kdDebug() << "(K3bDevice::Device) Starting readTocLinux( " << blockDeviceName() << " ) in thread "
+                << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
+
     usageLock();
     if( ::ioctl(d->deviceFd,CDROMREADTOCHDR,&tochdr) ) {
       k3bDebug() << "(K3bDevice::Device) could not get toc header !" << endl;
@@ -1419,6 +1423,8 @@
       }
     }
     usageUnlock();
+      kdDebug() << "(K3bDevice::Device) Finished readTocLinux( " << blockDeviceName() << " ) in thread "
+                << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
 
     if( needToClose )
       close();
@@ -1484,9 +1490,14 @@
   bool needToClose = !isOpen();
 
   if( open() ) {
+          kdDebug() << "(K3bDevice::Device) Starting block( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
+
         usageLock();
     bool success = ( ::ioctl( d->deviceFd, CDROM_LOCKDOOR, b ? 1 : 0 ) == 0 );
         usageUnlock();
+          kdDebug() << "(K3bDevice::Device) Finished block( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
     if( needToClose )
       close();
     return success;
@@ -1562,10 +1573,15 @@
   bool needToClose = !isOpen();
 
   if( open() ) {
+      kdDebug() << "(K3bDevice::Device) Starting eject( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
+
         usageLock();
         if( ::ioctl( d->deviceFd, CDROMEJECT ) >= 0 )
       success = true;
         usageUnlock();
+      kdDebug() << "(K3bDevice::Device) Finished eject( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
     if( needToClose )
       close();
   }
@@ -1611,10 +1627,15 @@
   bool needToClose = !isOpen();
 
   if( open() ) {
+            kdDebug() << "(K3bDevice::Device) Starting load( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
+
         usageLock();
         if( ::ioctl( d->deviceFd, CDROMCLOSETRAY ) >= 0 )
       success = true;
         usageUnlock();
+            kdDebug() << "(K3bDevice::Device) Finsihed load( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
     if( needToClose )
       close();
   }
@@ -1674,7 +1695,10 @@
 
 bool K3bDevice::Device::open( bool write ) const
 {
-  if( d->openedReadWrite != write )
+    kdDebug() << "(K3bDevice::Device) Starting open( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << endl;
+
+      if( d->openedReadWrite != write )
     close();
 
   d->mutex.lock();
@@ -1698,6 +1722,8 @@
 
   d->mutex.unlock();
 
+    kdDebug() << "(K3bDevice::Device) Finished open( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
   return ( d->deviceFd != -1 );
 #endif
 }
@@ -1705,6 +1731,8 @@
 
 void K3bDevice::Device::close() const
 {
+    kdDebug() << "(K3bDevice::Device) Starting close( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
   d->mutex.lock();
 
 #ifdef Q_OS_FREEBSD
@@ -1721,6 +1749,8 @@
 #endif
 
   d->mutex.unlock();
+    kdDebug() << "(K3bDevice::Device) Finished close( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << endl;
 }
 
 
@@ -3597,11 +3627,16 @@
 
 void K3bDevice::Device::usageLock() const
 {
+    kdDebug() << "(K3bDevice::Device) usageLock( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
+
     d->mutex.lock();
 }
 
 
 void K3bDevice::Device::usageUnlock() const
 {
+    kdDebug() << "(K3bDevice::Device) usageUnlock( " << blockDeviceName() << " ) in thread "
+              << QThread::currentThread() << " - deviceFd: " << d->deviceFd << endl;
     d->mutex.unlock();
 }
Index: libk3b/tools/k3bdevicehandler.cpp
===================================================================
--- libk3b/tools/k3bdevicehandler.cpp	(revision 665632)
+++ libk3b/tools/k3bdevicehandler.cpp	(working copy)
@@ -25,14 +25,17 @@
 class K3bDevice::DeviceHandler::DeviceHandlerThread : public K3bThread
 {
 public:
-  DeviceHandlerThread() 
+  DeviceHandlerThread()
     : K3bThread(),
       dev(0) {
   }
 
 
   void run() {
-    success = false;
+      kdDebug() << "(K3bDevice::DeviceHandler) Starting thread " <<
+          QThread::currentThread() << " for device " << dev->blockDeviceName() << endl;
+
+      success = false;
     m_bCanceled = false;
 
     // clear data
@@ -106,7 +109,7 @@
 
       if( !m_bCanceled && command & BUFFER_CAPACITY )
 	success = dev->readBufferCapacity( bufferCapacity, availableBufferCapacity );
-	
+
       dev->close();
     }
 
@@ -116,8 +119,11 @@
     //
     if( !m_bCanceled )
       emitFinished(success);
-  }
 
+    kdDebug() << "(K3bDevice::DeviceHandler) Finished thread " <<
+        QThread::currentThread() << " for device " << dev->blockDeviceName() << endl;
+}
+
   void cancel() {
     m_bCanceled = true;
   }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.