read() on relayfs channel returns premature 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
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;

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux