public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* read() on relayfs channel returns premature 0
@ 2005-03-23  9:02 kingsley
  2005-03-23 15:29 ` Tom Zanussi
  2005-04-18  1:29 ` Relayfs Question: Use of relay_reset(). Potential race? Kingsley Cheung
  0 siblings, 2 replies; 12+ messages in thread
From: kingsley @ 2005-03-23  9:02 UTC (permalink / raw)
  To: Tom Zanussi, Karim Yaghmour; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

Hi 

I'm using relayfs to relay data from a kernel module to user space on
a SuSE 2.6.5 kernel.  I'm not absolutely sure what version of relayfs
has been back ported to it.

While reading data from the channel I've been seeing read() return 0
prematurely.  However, the 0 does not signify that the file is being
closed for there is still data available afterwards.  

I've noticed that zeros occur when roughly one page of data has been
read.  I suspect that they occur whenever there is a read across the
relayfs sub-buffers.

Now I understand that this is not the latest release of relayfs (there
are the redux patches, which I have yet to try).  Nonetheless I'd like
to know whether this behaviour is deliberate.  Is it? 

Thanks,
-- 
		Kingsley

P.S. I've been able to get around this by deliberately modifying
do_read() with the attached patch.  I'm not absolutely sure its
correct but it seems to work.

[-- Attachment #2: relayfs-premature-zero.patch --]
[-- Type: text/plain, Size: 1340 bytes --]

Index: fs/relayfs/relay.c
===================================================================
RCS file: /export/cvsroot/SuSE-Kernel-2.4.21/fs/relayfs/Attic/relay.c,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 relay.c
--- fs/relayfs/relay.c	18 Feb 2005 00:00:51 -0000	1.1.2.1
+++ fs/relayfs/relay.c	23 Mar 2005 09:00:42 -0000
@@ -1445,26 +1445,22 @@
 
 	avail_offset = cur_idx = relay_get_offset(rchan, &max_offset);
 
+	last_buf_byte_offset = (read_bufno + 1) * buf_size - 1;
 	if (cur_idx == read_offset) {
 		if (atomic_read(&rchan->suspended) == 1) {
-			read_offset += 1;
+			read_offset = last_buf_byte_offset + 1;
 			if (read_offset >= max_offset)
 				read_offset = 0;
 			*actual_read_offset = read_offset;
 		} else {
-			*new_offset = read_offset;
+			*new_offset = read_offset; 
 			return 0;
 		}
-	} else {
-		last_buf_byte_offset = (read_bufno + 1) * buf_size - 1;
-		if (read_offset == last_buf_byte_offset) {
-			if (unused_bytes != 1) {
-				read_offset += 1;
-				if (read_offset >= max_offset)
-					read_offset = 0;
-				*actual_read_offset = read_offset;
-			}
-		}
+	} else if ((read_offset + unused_bytes) > last_buf_byte_offset) {
+		read_offset = last_buf_byte_offset + 1;
+		if (read_offset >= max_offset)
+			read_offset = 0;
+		*actual_read_offset = read_offset;
 	}
 
 	read_bufno = read_offset / buf_size;

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-05-04  9:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-23  9:02 read() on relayfs channel returns premature 0 kingsley
2005-03-23 15:29 ` Tom Zanussi
2005-03-24  1:29   ` Kingsley Cheung
2005-03-24  6:56     ` Jan Engelhardt
2005-03-24 19:11     ` Tom Zanussi
2005-03-24 19:45       ` Jan Engelhardt
2005-03-25 12:27         ` Karim Yaghmour
2005-03-28 23:43       ` Kingsley Cheung
2005-04-18  1:29 ` Relayfs Question: Use of relay_reset(). Potential race? Kingsley Cheung
2005-04-18 15:56   ` Tom Zanussi
2005-04-19  0:40     ` Kingsley Cheung
2005-05-04  9:04       ` kingsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox