All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: C Smith <csmithquestions@gmail.com>, xenomai@xenomai.org
Subject: Re: [Xenomai] Unable to Read from Pipe
Date: Tue, 21 Jul 2015 10:26:02 +0200	[thread overview]
Message-ID: <55AE021A.5050603@xenomai.org> (raw)
In-Reply-To: <CA+K1mPH_C5aW60rBsRhqueVZi3K=XqzFFTwLU7+umCT1Q=90xg@mail.gmail.com>

On 07/20/2015 11:31 PM, C Smith wrote:
> I found a workaround for this, but I believe it illustrates a bug in
> xenomai 3.0rc5, which is also present in in xenomai 2.6.4.
> 
> The problem is that if the userspace writer of a pipe closes the pipe
> immediately after writing, the data does not get into the pipe reliably and
> the real-time reader process usually doesn't get the data. This is true
> even though the write() returns the expected number of bytes indicating
> success.
> 

This is intended. We must allow the regular side to force a shutdown on
the pipe since this is a valid use case, which would not be possible if
waiting for the rt input to drain was the only option before the kernel
actually closes the channel.

O_SYNC can be passed to open() to have the writer wait for the rt side
to start consuming the messages on the other end. In addition, we could
make the close() call wait until the rt input is fully consumed with
O_SYNC too, which is not the case so far (we currently sync on write()
only). This patch has been scrupulously untested.

diff --git a/ksrc/nucleus/pipe.c b/ksrc/nucleus/pipe.c
index df587ab..5367c4c 100644
--- a/ksrc/nucleus/pipe.c
+++ b/ksrc/nucleus/pipe.c
@@ -697,6 +697,14 @@ static int xnpipe_release(struct inode *inode,
struct file *file)

 	xnlock_get_irqsave(&nklock, s);

+	if ((file->f_flags & O_SYNC) != 0 && !emptyq_p(&state->inq)) {
+		if (xnpipe_wait(state, XNPIPE_USER_WSYNC, s,
+				emptyq_p(&state->inq))) {
+			xnlock_put_irqrestore(&nklock, s);
+			return -ERESTARTSYS;
+		}
+	}
+
 	xnpipe_dequeue_all(state, XNPIPE_USER_WREAD);
 	xnpipe_dequeue_all(state, XNPIPE_USER_WSYNC);

-- 
Philippe.


  reply	other threads:[~2015-07-21  8:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 23:57 [Xenomai] Unable to Read from Pipe C Smith
2015-06-30  0:19 ` Gilles Chanteperdrix
     [not found]   ` <CA+K1mPG9OKH9FReQoC8jLRAipJ3F=vSdRMmtrxFaZEJjyfHArg@mail.gmail.com>
2015-07-01 17:54     ` Gilles Chanteperdrix
2015-07-02 23:14       ` C Smith
2015-07-20 21:31         ` C Smith
2015-07-21  8:26           ` Philippe Gerum [this message]
2015-07-23 16:27             ` C Smith

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=55AE021A.5050603@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=csmithquestions@gmail.com \
    --cc=xenomai@xenomai.org \
    /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 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.