VFS: nonblocking interface

The VFS library can be used in single-threaded or multi-threaded
environments and depending on that, signals are handled by the same thread
which uses the VFS library or possibly by a different thread. If a VFS
plugin needs to block to wait for a signal, there is currently no way
which works reliably in both environments.

For this reason, this commit makes the interface of the VFS library
nonblocking, similar to the File_system session interface.

The most important changes are:

- Directories are created and opened with the 'opendir()' function and the
  directory entries are read with the recently introduced 'queue_read()'
  and 'complete_read()' functions.

- Symbolic links are created and opened with the 'openlink()' function and
  the link target is read with the 'queue_read()' and 'complete_read()'
  functions and written with the 'write()' function.

- The 'write()' function does not wait for signals anymore. This can have
  the effect that data written by a VFS library user has not been
  processed by a file system server yet when the library user asks for the
  size of the file or closes it (both done with RPC functions at the file
  system server). For this reason, a user of the VFS library should
  request synchronization before calling 'stat()' or 'close()'. To make
  sure that a file system server has processed all write request packets
  which a client submitted before the synchronization request,
  synchronization is now requested at the file system server with a
  synchronization packet instead of an RPC function. Because of this
  change, the synchronization interface of the VFS library is now split
  into 'queue_sync()' and 'complete_sync()' functions.

Fixes #2399
This commit is contained in:
Christian Prochaska
2017-08-15 20:51:53 +02:00
committed by Christian Helmuth
parent 8312950e2f
commit b0935ef9b2
49 changed files with 4361 additions and 2307 deletions

View File

@ -40,6 +40,12 @@ struct Vfs::File_io_service
** Write **
***********/
/*
* Exception, thrown when 'alloc_packet()' or 'submit_packet()' failed in the
* VFS plugin and the caller should wait for an IO response and try again.
*/
struct Insufficient_buffer { };
enum Write_result { WRITE_ERR_AGAIN, WRITE_ERR_WOULD_BLOCK,
WRITE_ERR_INVALID, WRITE_ERR_IO,
WRITE_ERR_INTERRUPT, WRITE_OK };
@ -58,25 +64,19 @@ struct Vfs::File_io_service
READ_ERR_INTERRUPT, READ_QUEUED,
READ_OK };
virtual Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) = 0;
/**
* Read from handle with potential queueing of operation
* Queue read operation
*
* \return false if queue is full
*/
virtual bool queue_read(Vfs_handle *vfs_handle, char *dst, file_size count,
Read_result &out_result, file_size &out_count)
virtual bool queue_read(Vfs_handle *vfs_handle, file_size count)
{
out_result = read(vfs_handle, dst, count, out_count);
return true;
}
virtual Read_result complete_read(Vfs_handle *vfs_handle,
char *dst, file_size count,
file_size &out_count)
{ return read(vfs_handle, dst, count, out_count); }
file_size &out_count) = 0;
/**
* Return true if the handle has readable data
@ -163,6 +163,27 @@ struct Vfs::File_io_service
virtual void register_read_ready_sigh(Vfs_handle *vfs_handle,
Signal_context_capability sigh)
{ }
/**********
** Sync **
**********/
enum Sync_result { SYNC_QUEUED, SYNC_OK };
/**
* Queue sync operation
*
* \return false if queue is full
*/
virtual bool queue_sync(Vfs_handle *vfs_handle)
{
return true;
}
virtual Sync_result complete_sync(Vfs_handle *vfs_handle)
{
return SYNC_OK;
}
};
#endif /* _INCLUDE__VFS__FILE_IO_SERVICE_H_ */