mirror of https://github.com/xemu-project/xemu.git
80 lines
1.8 KiB
C
80 lines
1.8 KiB
C
/*
|
|
* virtio-fs glue for FUSE
|
|
* Copyright (C) 2018 Red Hat, Inc. and/or its affiliates
|
|
*
|
|
* Authors:
|
|
* Dave Gilbert <dgilbert@redhat.com>
|
|
*
|
|
* Implements the glue between libfuse and libvhost-user
|
|
*
|
|
* This program can be distributed under the terms of the GNU LGPLv2.
|
|
* See the file COPYING.LIB
|
|
*/
|
|
|
|
#include "fuse_i.h"
|
|
#include "standard-headers/linux/fuse.h"
|
|
#include "fuse_misc.h"
|
|
#include "fuse_opt.h"
|
|
#include "fuse_virtio.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <sys/un.h>
|
|
#include <unistd.h>
|
|
|
|
/* From spec */
|
|
struct virtio_fs_config {
|
|
char tag[36];
|
|
uint32_t num_queues;
|
|
};
|
|
|
|
int virtio_session_mount(struct fuse_session *se)
|
|
{
|
|
struct sockaddr_un un;
|
|
mode_t old_umask;
|
|
|
|
if (strlen(se->vu_socket_path) >= sizeof(un.sun_path)) {
|
|
fuse_log(FUSE_LOG_ERR, "Socket path too long\n");
|
|
return -1;
|
|
}
|
|
|
|
se->fd = -1;
|
|
|
|
/*
|
|
* Create the Unix socket to communicate with qemu
|
|
* based on QEMU's vhost-user-bridge
|
|
*/
|
|
unlink(se->vu_socket_path);
|
|
strcpy(un.sun_path, se->vu_socket_path);
|
|
size_t addr_len = sizeof(un);
|
|
|
|
int listen_sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
if (listen_sock == -1) {
|
|
fuse_log(FUSE_LOG_ERR, "vhost socket creation: %m\n");
|
|
return -1;
|
|
}
|
|
un.sun_family = AF_UNIX;
|
|
|
|
/*
|
|
* Unfortunately bind doesn't let you set the mask on the socket,
|
|
* so set umask to 077 and restore it later.
|
|
*/
|
|
old_umask = umask(0077);
|
|
if (bind(listen_sock, (struct sockaddr *)&un, addr_len) == -1) {
|
|
fuse_log(FUSE_LOG_ERR, "vhost socket bind: %m\n");
|
|
umask(old_umask);
|
|
return -1;
|
|
}
|
|
umask(old_umask);
|
|
|
|
if (listen(listen_sock, 1) == -1) {
|
|
fuse_log(FUSE_LOG_ERR, "vhost socket listen: %m\n");
|
|
return -1;
|
|
}
|
|
|
|
return -1;
|
|
}
|