Merge pipes and socket pairs.

Now that CloudABI's sockets API has been changed to be addressless and
only connected socket instances are used (e.g., socket pairs), they have
become fairly similar to pipes. The only differences on CloudABI is that
socket pairs additionally support shutdown(), send() and recv().

To simplify the ABI, we've therefore decided to remove pipes as a
separate file descriptor type and just let pipe() return a socket pair
of type SOCK_STREAM. S_ISFIFO() and S_ISSOCK() are now defined
identically.
This commit is contained in:
Ed Schouten 2017-09-05 07:46:45 +00:00
parent 7f1e5ebba8
commit 733ba7f881
4 changed files with 12 additions and 42 deletions

View File

@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$");
MAPPING(CLOUDABI_RIGHT_FILE_ALLOCATE, CAP_WRITE) \
MAPPING(CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY, CAP_MKDIRAT) \
MAPPING(CLOUDABI_RIGHT_FILE_CREATE_FILE, CAP_CREATE) \
MAPPING(CLOUDABI_RIGHT_FILE_CREATE_FIFO, CAP_MKFIFOAT) \
MAPPING(CLOUDABI_RIGHT_FILE_LINK_SOURCE, CAP_LINKAT_SOURCE) \
MAPPING(CLOUDABI_RIGHT_FILE_LINK_TARGET, CAP_LINKAT_TARGET) \
MAPPING(CLOUDABI_RIGHT_FILE_OPEN, CAP_LOOKUP) \
@ -110,34 +109,21 @@ int
cloudabi_sys_fd_create2(struct thread *td,
struct cloudabi_sys_fd_create2_args *uap)
{
struct filecaps fcaps1 = {}, fcaps2 = {};
int fds[2];
int error;
int error, type;
switch (uap->type) {
case CLOUDABI_FILETYPE_FIFO:
/*
* CloudABI pipes are unidirectional. Restrict rights on
* the pipe to simulate this.
*/
cap_rights_init(&fcaps1.fc_rights, CAP_EVENT, CAP_FCNTL,
CAP_FSTAT, CAP_READ);
fcaps1.fc_fcntls = CAP_FCNTL_SETFL;
cap_rights_init(&fcaps2.fc_rights, CAP_EVENT, CAP_FCNTL,
CAP_FSTAT, CAP_WRITE);
fcaps2.fc_fcntls = CAP_FCNTL_SETFL;
error = kern_pipe(td, fds, 0, &fcaps1, &fcaps2);
break;
case CLOUDABI_FILETYPE_SOCKET_DGRAM:
error = kern_socketpair(td, AF_UNIX, SOCK_DGRAM, 0, fds);
type = SOCK_DGRAM;
break;
case CLOUDABI_FILETYPE_SOCKET_STREAM:
error = kern_socketpair(td, AF_UNIX, SOCK_STREAM, 0, fds);
type = SOCK_STREAM;
break;
default:
return (EINVAL);
}
error = kern_socketpair(td, AF_UNIX, type, 0, fds);
if (error == 0) {
td->td_retval[0] = fds[0];
td->td_retval[1] = fds[1];
@ -214,11 +200,11 @@ cloudabi_convert_filetype(const struct file *fp)
switch (fp->f_type) {
case DTYPE_FIFO:
return (CLOUDABI_FILETYPE_FIFO);
return (CLOUDABI_FILETYPE_SOCKET_STREAM);
case DTYPE_KQUEUE:
return (CLOUDABI_FILETYPE_POLL);
case DTYPE_PIPE:
return (CLOUDABI_FILETYPE_FIFO);
return (CLOUDABI_FILETYPE_SOCKET_STREAM);
case DTYPE_PROCDESC:
return (CLOUDABI_FILETYPE_PROCESS);
case DTYPE_SHM:
@ -243,7 +229,7 @@ cloudabi_convert_filetype(const struct file *fp)
case VDIR:
return (CLOUDABI_FILETYPE_DIRECTORY);
case VFIFO:
return (CLOUDABI_FILETYPE_FIFO);
return (CLOUDABI_FILETYPE_SOCKET_STREAM);
case VLNK:
return (CLOUDABI_FILETYPE_SYMBOLIC_LINK);
case VREG:
@ -286,7 +272,6 @@ cloudabi_remove_conflicting_rights(cloudabi_filetype_t filetype,
CLOUDABI_RIGHT_FD_SYNC | CLOUDABI_RIGHT_FILE_ADVISE |
CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY |
CLOUDABI_RIGHT_FILE_CREATE_FILE |
CLOUDABI_RIGHT_FILE_CREATE_FIFO |
CLOUDABI_RIGHT_FILE_LINK_SOURCE |
CLOUDABI_RIGHT_FILE_LINK_TARGET |
CLOUDABI_RIGHT_FILE_OPEN |
@ -312,7 +297,6 @@ cloudabi_remove_conflicting_rights(cloudabi_filetype_t filetype,
CLOUDABI_RIGHT_FILE_ALLOCATE |
CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY |
CLOUDABI_RIGHT_FILE_CREATE_FILE |
CLOUDABI_RIGHT_FILE_CREATE_FIFO |
CLOUDABI_RIGHT_FILE_LINK_SOURCE |
CLOUDABI_RIGHT_FILE_LINK_TARGET |
CLOUDABI_RIGHT_FILE_OPEN |
@ -332,14 +316,6 @@ cloudabi_remove_conflicting_rights(cloudabi_filetype_t filetype,
CLOUDABI_RIGHT_POLL_FD_READWRITE |
CLOUDABI_RIGHT_PROC_EXEC;
break;
case CLOUDABI_FILETYPE_FIFO:
*base &= CLOUDABI_RIGHT_FD_READ |
CLOUDABI_RIGHT_FD_STAT_PUT_FLAGS |
CLOUDABI_RIGHT_FD_WRITE |
CLOUDABI_RIGHT_FILE_STAT_FGET |
CLOUDABI_RIGHT_POLL_FD_READWRITE;
*inheriting = 0;
break;
case CLOUDABI_FILETYPE_POLL:
*base &= ~CLOUDABI_RIGHT_FILE_ADVISE;
*inheriting = 0;

View File

@ -159,9 +159,6 @@ cloudabi_sys_file_create(struct thread *td,
case CLOUDABI_FILETYPE_DIRECTORY:
error = kern_mkdirat(td, uap->fd, path, UIO_SYSSPACE, 0777);
break;
case CLOUDABI_FILETYPE_FIFO:
error = kern_mkfifoat(td, uap->fd, path, UIO_SYSSPACE, 0666);
break;
default:
error = EINVAL;
break;
@ -346,7 +343,7 @@ write_dirent(struct dirent *bde, cloudabi_dircookie_t cookie, struct uio *uio)
cde.d_type = CLOUDABI_FILETYPE_DIRECTORY;
break;
case DT_FIFO:
cde.d_type = CLOUDABI_FILETYPE_FIFO;
cde.d_type = CLOUDABI_FILETYPE_SOCKET_STREAM;
break;
case DT_LNK:
cde.d_type = CLOUDABI_FILETYPE_SYMBOLIC_LINK;
@ -673,7 +670,7 @@ cloudabi_sys_file_stat_get(struct thread *td,
else if (S_ISDIR(sb.st_mode))
csb.st_filetype = CLOUDABI_FILETYPE_DIRECTORY;
else if (S_ISFIFO(sb.st_mode))
csb.st_filetype = CLOUDABI_FILETYPE_FIFO;
csb.st_filetype = CLOUDABI_FILETYPE_SOCKET_STREAM;
else if (S_ISREG(sb.st_mode))
csb.st_filetype = CLOUDABI_FILETYPE_REGULAR_FILE;
else if (S_ISSOCK(sb.st_mode)) {

View File

@ -191,7 +191,6 @@ typedef uint8_t cloudabi_filetype_t;
#define CLOUDABI_FILETYPE_BLOCK_DEVICE 16
#define CLOUDABI_FILETYPE_CHARACTER_DEVICE 17
#define CLOUDABI_FILETYPE_DIRECTORY 32
#define CLOUDABI_FILETYPE_FIFO 48
#define CLOUDABI_FILETYPE_POLL 64
#define CLOUDABI_FILETYPE_PROCESS 80
#define CLOUDABI_FILETYPE_REGULAR_FILE 96
@ -260,7 +259,6 @@ typedef uint64_t cloudabi_rights_t;
#define CLOUDABI_RIGHT_FILE_ALLOCATE 0x0000000000000100
#define CLOUDABI_RIGHT_FILE_CREATE_DIRECTORY 0x0000000000000200
#define CLOUDABI_RIGHT_FILE_CREATE_FILE 0x0000000000000400
#define CLOUDABI_RIGHT_FILE_CREATE_FIFO 0x0000000000000800
#define CLOUDABI_RIGHT_FILE_LINK_SOURCE 0x0000000000001000
#define CLOUDABI_RIGHT_FILE_LINK_TARGET 0x0000000000002000
#define CLOUDABI_RIGHT_FILE_OPEN 0x0000000000004000

View File

@ -734,10 +734,9 @@ static struct xlat cloudabi_fdsflags[] = {
static struct xlat cloudabi_filetype[] = {
X(FILETYPE_UNKNOWN) X(FILETYPE_BLOCK_DEVICE)
X(FILETYPE_CHARACTER_DEVICE) X(FILETYPE_DIRECTORY)
X(FILETYPE_FIFO) X(FILETYPE_POLL) X(FILETYPE_PROCESS)
X(FILETYPE_REGULAR_FILE) X(FILETYPE_SHARED_MEMORY)
X(FILETYPE_SOCKET_DGRAM) X(FILETYPE_SOCKET_STREAM)
X(FILETYPE_SYMBOLIC_LINK)
X(FILETYPE_POLL) X(FILETYPE_PROCESS) X(FILETYPE_REGULAR_FILE)
X(FILETYPE_SHARED_MEMORY) X(FILETYPE_SOCKET_DGRAM)
X(FILETYPE_SOCKET_STREAM) X(FILETYPE_SYMBOLIC_LINK)
XEND
};