#include <linux/miscdevice.h>
#include <linux/atomic.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/vmalloc.h>
#include <net/sock.h>
#include <linux/virtio_vsock.h>
#include <linux/vhost.h>
#include <linux/hashtable.h>
#include <net/af_vsock.h>
#include "vhost.h"
#define VHOST_VSOCK_DEFAULT_HOST_CID …
#define VHOST_VSOCK_WEIGHT …
#define VHOST_VSOCK_PKT_WEIGHT …
enum { … };
enum { … };
static DEFINE_MUTEX(vhost_vsock_mutex);
static DEFINE_READ_MOSTLY_HASHTABLE(vhost_vsock_hash, 8);
struct vhost_vsock { … };
static u32 vhost_transport_get_local_cid(void)
{ … }
static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)
{ … }
static void
vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
struct vhost_virtqueue *vq)
{ … }
static void vhost_transport_send_pkt_work(struct vhost_work *work)
{ … }
static int
vhost_transport_send_pkt(struct sk_buff *skb)
{ … }
static int
vhost_transport_cancel_pkt(struct vsock_sock *vsk)
{ … }
static struct sk_buff *
vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,
unsigned int out, unsigned int in)
{ … }
static bool vhost_vsock_more_replies(struct vhost_vsock *vsock)
{ … }
static bool vhost_transport_msgzerocopy_allow(void)
{ … }
static bool vhost_transport_seqpacket_allow(u32 remote_cid);
static struct virtio_transport vhost_transport = …;
static bool vhost_transport_seqpacket_allow(u32 remote_cid)
{ … }
static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
{ … }
static void vhost_vsock_handle_rx_kick(struct vhost_work *work)
{ … }
static int vhost_vsock_start(struct vhost_vsock *vsock)
{ … }
static int vhost_vsock_stop(struct vhost_vsock *vsock, bool check_owner)
{ … }
static void vhost_vsock_free(struct vhost_vsock *vsock)
{ … }
static int vhost_vsock_dev_open(struct inode *inode, struct file *file)
{ … }
static void vhost_vsock_flush(struct vhost_vsock *vsock)
{ … }
static void vhost_vsock_reset_orphans(struct sock *sk)
{ … }
static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
{ … }
static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid)
{ … }
static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
{ … }
static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
unsigned long arg)
{ … }
static ssize_t vhost_vsock_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
{ … }
static ssize_t vhost_vsock_chr_write_iter(struct kiocb *iocb,
struct iov_iter *from)
{ … }
static __poll_t vhost_vsock_chr_poll(struct file *file, poll_table *wait)
{ … }
static const struct file_operations vhost_vsock_fops = …;
static struct miscdevice vhost_vsock_misc = …;
static int __init vhost_vsock_init(void)
{
int ret;
ret = vsock_core_register(&vhost_transport.transport,
VSOCK_TRANSPORT_F_H2G);
if (ret < 0)
return ret;
ret = misc_register(&vhost_vsock_misc);
if (ret) {
vsock_core_unregister(&vhost_transport.transport);
return ret;
}
return 0;
};
static void __exit vhost_vsock_exit(void)
{
misc_deregister(&vhost_vsock_misc);
vsock_core_unregister(&vhost_transport.transport);
};
module_init(…) …;
module_exit(vhost_vsock_exit);
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_ALIAS_MISCDEV(…);
MODULE_ALIAS(…) …;