public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: kingsley@aurema.com
To: Tom Zanussi <zanussi@us.ibm.com>, Karim Yaghmour <karim@opersys.com>
Cc: linux-kernel@vger.kernel.org
Subject: read() on relayfs channel returns premature 0
Date: Wed, 23 Mar 2005 20:02:54 +1100	[thread overview]
Message-ID: <20050323090254.GA10630@aurema.com> (raw)

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

             reply	other threads:[~2005-03-23  9:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23  9:02 kingsley [this message]
2005-03-23 15:29 ` read() on relayfs channel returns premature 0 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

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=20050323090254.GA10630@aurema.com \
    --to=kingsley@aurema.com \
    --cc=karim@opersys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zanussi@us.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox