* read / write / close sync for device files @ 2011-07-04 12:43 Amit Nagal 2011-07-04 16:10 ` Greg KH 0 siblings, 1 reply; 4+ messages in thread From: Amit Nagal @ 2011-07-04 12:43 UTC (permalink / raw) To: kernelnewbies Hi , if a application is doing read /write I/O with a usb device , in 2 different threads in userspace , and at usb disconnect event , read thread returns with error and application calls close() subsequently without waiting for write thread to finish . Do the VFS upper layers maintain locks that take care that until both read and write methods in usb driver donot finish and return with error in kernel space close will pend and usb driver release method will not be called ? Regards Amit Nagal ^ permalink raw reply [flat|nested] 4+ messages in thread
* read / write / close sync for device files 2011-07-04 12:43 read / write / close sync for device files Amit Nagal @ 2011-07-04 16:10 ` Greg KH 2011-07-05 7:07 ` Amit Nagal 0 siblings, 1 reply; 4+ messages in thread From: Greg KH @ 2011-07-04 16:10 UTC (permalink / raw) To: kernelnewbies On Mon, Jul 04, 2011 at 06:13:49PM +0530, Amit Nagal wrote: > Hi , > > if a application is doing read /write I/O with a usb device , in 2 > different threads in userspace , What type of USB device? > and at usb disconnect event , read thread returns with error and > application calls close() subsequently without waiting for write > thread to finish . > > Do the VFS upper layers maintain locks that take care that until > both read and write methods in usb driver donot finish and return with > error in kernel space > > close will pend and usb driver release method will not be called ? No, close will succeed, and then all will be cleaned up properly. Try it yourself and see :) greg k-h ^ permalink raw reply [flat|nested] 4+ messages in thread
* read / write / close sync for device files 2011-07-04 16:10 ` Greg KH @ 2011-07-05 7:07 ` Amit Nagal 2011-07-05 13:34 ` Greg KH 0 siblings, 1 reply; 4+ messages in thread From: Amit Nagal @ 2011-07-05 7:07 UTC (permalink / raw) To: kernelnewbies On Mon, Jul 4, 2011 at 9:40 PM, Greg KH <greg@kroah.com> wrote: > On Mon, Jul 04, 2011 at 06:13:49PM +0530, Amit Nagal wrote: >> Hi , >> >> if ?a application is ?doing read /write I/O with a ?usb device , ?in 2 >> different threads in userspace , > > What type of USB device? Thanx for reply . i am using USB hid interface and using USBHID driver with hid-raw device interface . Actually i have 2 threads in userspace app : one for read and another one for write . my problem is like this : In case of usb disconnect , if read() returns first with error and application calls close() in read thread itself in userspace , while write() is still in progress() in usb driver in a separate thread , is this ok and safe ? or shall the application be designed such that both until read and write return with error , it should not call close in userspace ? Also to test this , i applied a 10 seconds delay at the end of hidraw_read() function in hidraw driver like : static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { ............................................ /********************* test block starts */ printk(KERN_EMERG "[%s] - sleep start\n" , __func__); mdelay(10000); /* 10s delay */ printk(KERN_EMERG "[%s] - sleep end\n" , __func__); /***************** test block ends */ mutex_unlock(&list->read_mutex); return ret; } now while hidraw_read is executing 10s delay , i disconnects usb device , calls close(fd) . i observed , while close(fd) returns with 0 successfully immediately , usb driver release() function corresponding to close() was called only when hidraw_read returns after completing delay which is approx 9s later calling to close() in userspace . so do the usb-core layers or VFS layers maintains some locks that take care that if read / write is in progress and application calls close() , corresponding release() method in usb driver will be called only upon completion of all read / writes ? Regards Amit Nagal ^ permalink raw reply [flat|nested] 4+ messages in thread
* read / write / close sync for device files 2011-07-05 7:07 ` Amit Nagal @ 2011-07-05 13:34 ` Greg KH 0 siblings, 0 replies; 4+ messages in thread From: Greg KH @ 2011-07-05 13:34 UTC (permalink / raw) To: kernelnewbies On Tue, Jul 05, 2011 at 12:37:26PM +0530, Amit Nagal wrote: > so do the usb-core layers or VFS layers maintains some locks that take > care that if read / write is in progress > and application calls close() , corresponding release() method in usb > driver will be called only upon completion > of all read / writes ? No, release will be called when all of the userspace file handles call close(), and not before. hope this helps, greg k-h ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-05 13:34 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-07-04 12:43 read / write / close sync for device files Amit Nagal 2011-07-04 16:10 ` Greg KH 2011-07-05 7:07 ` Amit Nagal 2011-07-05 13:34 ` Greg KH
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.