All of lore.kernel.org
 help / color / mirror / Atom feed
* seekable pipes
@ 2005-06-07 10:23 Frederik Eaton
  2005-06-07 20:31 ` Bryan Henderson
  2005-06-07 21:56 ` x
  0 siblings, 2 replies; 16+ messages in thread
From: Frederik Eaton @ 2005-06-07 10:23 UTC (permalink / raw)
  To: fsdevel; +Cc: Richard Patterson, Linux-userfs

Wow, what happened to Ian Turner's "seekable pipes" proposal? 

http://marc.theaimsgroup.com/?l=linux-kernel&m=110153524529112&w=2

I have wanted to propose something very similar. I think it would be a
great way of implementing a lot of functionality that we think of as
belonging to more complicated userspace filesystems. For instance, if
the kernel had seekable pipes then I could write a command that just
serialized the protocol and allowed me to read and write files over an
'ssh' session, with very simple syntax:

some-editor <(ssh-file host:path)
some-editor <(cmd-file ssh host open-file path)

or inside a tar file (maybe reading only), or on an FTP site, etc.

some-editor <(url-file ftp://host:path)

It might even make more sense than the AVFS way of doing things,
because commands can take multiple file arguments:

some-editor <(patched-file file.c file.patch) # writes changes to file.patch

- difficult to do with AVFS file system modules which are "mounted" on
a single base file.

Kernel support could mean support for mmap and exec, which you
couldn't easily get from a library implementation.

Something like this could be the basis and core of a more complete
userspace file system protocol. But since the seekable pipe concept
also has independent applications I think it would be a good thing to
factor out and focus on getting right independently of
namespace-dependent functionality. Plus even without kernel support
for allowing processes to export virtual directories to each other,
seekable pipes would still give shared-library based userspace
filesystems such as AVFS-preload a way to present host processes with
a much more complete file system interface, by solving their mmap and
exec problems.

Ian admits that his idea of a protocol was too simple, since - if you
will allow me to use the terms 'master' and 'slave' - it didn't allow
multiple slaves for one master. And it didn't allow the slave half of
the pipe to write data, which I think would be an important feature;
also, for good random-access performance I think the master should be
able to provide a block of data with an expiration time which is
cached independently of slave seek position.

But aside from that, the protocol need not be complex. Except for the
problem of creating the special file descriptors, the rest could be
done on the master side with read/write (read a request for data,
write a block of data with a description header). Creating the
descriptor pair could be done with an ioctl "promoting" the pipe
descriptors as in Ian's proposal, although since seekable pipes
wouldn't share much in common with regular pipes, the kernel pipe data
structures would probably be created and then destroyed unnecessarily
in this case - ugly if not a performance issue. I guess there are
several other possibilities. Being able to name the slave as with a
devpts-like solution could have advantages but perhaps not enough to
justify the complexity.

I feel that this kind of feature, in some form, could be the shortest
path to a lot of neat applications. What do other people think?

Frederik

-- 
http://ofb.net/~frederik/

^ permalink raw reply	[flat|nested] 16+ messages in thread
[parent not found: <20041128120006.312.69326.Mailman@lists.us.dell.com>]
* Seekable pipes
@ 2004-11-27  5:48 Richard Patterson
  2004-11-27 19:45 ` Jan Engelhardt
  0 siblings, 1 reply; 16+ messages in thread
From: Richard Patterson @ 2004-11-27  5:48 UTC (permalink / raw)
  To: linux-kernel

Hello,

I want to implement an interface for seekable pipes
(and FIFOs) in the Linux kernel.  The basic idea of
this is that when the reader issues a seek(), this
information can be passed onto the writer, who will
continue writing from the new location. Since the
reader doesn't have to do anything special, this
allows user-space programs to simulate real files,
providing features such as network filesystems and
database large-objects, all in user space.

However, I have a few questions. On looking through
fs/pipe.c, I see inode fields READERS and WRITERS.
Similarly, I see open functions independent of
do_pipe() -- such as pipe_read_open(). Does that mean
it is possible to have multiple writers and readers on
a single pipe, or is this just to implement of dup
and dup2? Obviously my idea is much more complex in
the event of multiple actors on a single pipe.

My other question relates to pipefs -- is this just a
dummy filesystem to give a home to pipe inodes, or
something more? Can you open existing pipes using
pipefs?

Finally, let me propose how I would modify the syscall
interface to implement this behavior:
1) New IOCTL SEEKPIPE_START, when called on the
writing
   fd, makes the entire pipe seekable. This must be 
   called before any data has been written to the
   pipe. At this time the writer also provides an 
   initial file size, to be used in case of fstat() 
   or SEEK_END. Note, however, that this length is not

   actually enforced, if the writer cares to provide 
   data past it.
2) When reader calls lseek() on a seekable pipe, any
   buffer data is discarded. Write()s to the pipe fail
   with EINVAL until --
3) The writer calls lseek twice in response. The first
   call is of the form lseek(fd, SEEK_CUR, 0), and 
   returns the new index requested by the reader. The 
   second is of the form lseek(fd, SEEK_SET, x) and 
   should confirm this number. If the requested 
   location is beyond the writer's idea of 
   end-of-file, the writer may so indicate by calling 
   lseek(fd, SEEK_END, 0) followed by write(fd, buf,
0).

There are a few other miscellaneous interface issues
to
address. If the writer uses select() or poll(), the
seek-pending condition is considered an uncleared
error. The writer may update it's idea of the file
size
with the same SEEKPIPE_START system call, and the
reader may access this value with fstat -- we just
store it in the inode. If anyone can think of other
points, feel free.
 
An strace-style example may make this paradigm
clearer. R and W indicate Reader and Writer,
respectively.

  pipe([5, 6])                       = 0
R close(6)                           = 0
R read(5, buf, 32768)                = (unfinished...)
W close(5)                           = 0
W ioctl(6, SEEKPIPE_START, 20480)    = 0
W write(6, bigbuf, 4096)             = 4096
R (read resumed)                     = 4096
W write(6, bigbuf+4096, 4096)        = 4096
W write(6, bigbuf+8192, 4096)        = (unfinished...)
-- The ioctl aside, so far this is just another pipe.
-- Then the reader seeks...
R lseek(5, SEEK_SET, 10000)          = 10000
W (write resumed)                    = -1 (EINVAL)
-- which wakes the writer...
R read(5, buf, 32768)                = (unfinished...)
W lseek(6, SEEK_CUR, 0)              = 10000
W write(6, bigbuf+10000, 4096)       = -1 (EINVAL)
W lseek(6, SEEK_SET, 10000)          = 10000
W write(6, bigbuf+10000, 4096)       = 4096
-- If the writer tries to write before confirming the
-- seek, it gets back EINVAL. Once the writer seeks to
-- match the reader, we go back into standard pipe 
-- mode.
R (read resumed)                     = 4096
W write(6, bigbuf+14096, 4096)       = 4096
W write(6, bigbuf+18192, 4096)       = (unfinished...)
-- Next, the reader tries to seek past the end of the
-- file. Note that, just as with a regular file, the
-- seek is allowed.
R lseek(5, SEEK_SET, 50000)          = 50000
R read(5, buf, 32768)                = (unfinished...)
W (write resumed)                    = -1 (EINVAL)
W lseek(6, SEEK_CUR, 0)              = 50000
W lseek(6, SEEK_END, 0)              = 50000
W write(6, buf, 0)                   = (unfinished...)
-- The combination of the second lseek and the write 
-- tell the kernel the reader has seeked too far. So
-- we wake the reader up with 0 bytes.
R (read resumed)                     = 0

Any comments or suggestions on this idea or its 
implementation are strongly requested.

Thanks in advance,

--Ian Turner



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


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

end of thread, other threads:[~2005-06-24  5:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-07 10:23 seekable pipes Frederik Eaton
2005-06-07 20:31 ` Bryan Henderson
2005-06-07 21:56 ` x
2005-06-16  4:37   ` Frederik Eaton
2005-06-20 22:24     ` Bryan Henderson
2005-06-21  5:02       ` Frederik Eaton
2005-06-21 17:47         ` Bryan Henderson
2005-06-21 22:41           ` x
2005-06-22  0:53             ` Bryan Henderson
2005-06-23 15:05               ` x
2005-06-23 15:58                 ` Jeff Anderson-Lee
2005-06-23 17:03                   ` Bryan Henderson
2005-06-24  5:43           ` Frederik Eaton
     [not found] <20041128120006.312.69326.Mailman@lists.us.dell.com>
2004-11-29  5:02 ` Seekable pipes Richard Patterson
  -- strict thread matches above, loose matches on Subject: below --
2004-11-27  5:48 Richard Patterson
2004-11-27 19:45 ` Jan Engelhardt

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.