vsock: add local transport support in the vsock core
This patch allows to register a transport able to handle local communication (loopback). Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
ef343b35d4
commit
0e12190578
@@ -98,6 +98,8 @@ struct vsock_transport_send_notify_data {
|
|||||||
#define VSOCK_TRANSPORT_F_G2H 0x00000002
|
#define VSOCK_TRANSPORT_F_G2H 0x00000002
|
||||||
/* Transport provides DGRAM communication */
|
/* Transport provides DGRAM communication */
|
||||||
#define VSOCK_TRANSPORT_F_DGRAM 0x00000004
|
#define VSOCK_TRANSPORT_F_DGRAM 0x00000004
|
||||||
|
/* Transport provides local (loopback) communication */
|
||||||
|
#define VSOCK_TRANSPORT_F_LOCAL 0x00000008
|
||||||
|
|
||||||
struct vsock_transport {
|
struct vsock_transport {
|
||||||
struct module *module;
|
struct module *module;
|
||||||
|
@@ -136,6 +136,8 @@ static const struct vsock_transport *transport_h2g;
|
|||||||
static const struct vsock_transport *transport_g2h;
|
static const struct vsock_transport *transport_g2h;
|
||||||
/* Transport used for DGRAM communication */
|
/* Transport used for DGRAM communication */
|
||||||
static const struct vsock_transport *transport_dgram;
|
static const struct vsock_transport *transport_dgram;
|
||||||
|
/* Transport used for local communication */
|
||||||
|
static const struct vsock_transport *transport_local;
|
||||||
static DEFINE_MUTEX(vsock_register_mutex);
|
static DEFINE_MUTEX(vsock_register_mutex);
|
||||||
|
|
||||||
/**** UTILS ****/
|
/**** UTILS ****/
|
||||||
@@ -2137,7 +2139,7 @@ EXPORT_SYMBOL_GPL(vsock_core_get_transport);
|
|||||||
|
|
||||||
int vsock_core_register(const struct vsock_transport *t, int features)
|
int vsock_core_register(const struct vsock_transport *t, int features)
|
||||||
{
|
{
|
||||||
const struct vsock_transport *t_h2g, *t_g2h, *t_dgram;
|
const struct vsock_transport *t_h2g, *t_g2h, *t_dgram, *t_local;
|
||||||
int err = mutex_lock_interruptible(&vsock_register_mutex);
|
int err = mutex_lock_interruptible(&vsock_register_mutex);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
@@ -2146,6 +2148,7 @@ int vsock_core_register(const struct vsock_transport *t, int features)
|
|||||||
t_h2g = transport_h2g;
|
t_h2g = transport_h2g;
|
||||||
t_g2h = transport_g2h;
|
t_g2h = transport_g2h;
|
||||||
t_dgram = transport_dgram;
|
t_dgram = transport_dgram;
|
||||||
|
t_local = transport_local;
|
||||||
|
|
||||||
if (features & VSOCK_TRANSPORT_F_H2G) {
|
if (features & VSOCK_TRANSPORT_F_H2G) {
|
||||||
if (t_h2g) {
|
if (t_h2g) {
|
||||||
@@ -2171,9 +2174,18 @@ int vsock_core_register(const struct vsock_transport *t, int features)
|
|||||||
t_dgram = t;
|
t_dgram = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (features & VSOCK_TRANSPORT_F_LOCAL) {
|
||||||
|
if (t_local) {
|
||||||
|
err = -EBUSY;
|
||||||
|
goto err_busy;
|
||||||
|
}
|
||||||
|
t_local = t;
|
||||||
|
}
|
||||||
|
|
||||||
transport_h2g = t_h2g;
|
transport_h2g = t_h2g;
|
||||||
transport_g2h = t_g2h;
|
transport_g2h = t_g2h;
|
||||||
transport_dgram = t_dgram;
|
transport_dgram = t_dgram;
|
||||||
|
transport_local = t_local;
|
||||||
|
|
||||||
err_busy:
|
err_busy:
|
||||||
mutex_unlock(&vsock_register_mutex);
|
mutex_unlock(&vsock_register_mutex);
|
||||||
@@ -2194,6 +2206,9 @@ void vsock_core_unregister(const struct vsock_transport *t)
|
|||||||
if (transport_dgram == t)
|
if (transport_dgram == t)
|
||||||
transport_dgram = NULL;
|
transport_dgram = NULL;
|
||||||
|
|
||||||
|
if (transport_local == t)
|
||||||
|
transport_local = NULL;
|
||||||
|
|
||||||
mutex_unlock(&vsock_register_mutex);
|
mutex_unlock(&vsock_register_mutex);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vsock_core_unregister);
|
EXPORT_SYMBOL_GPL(vsock_core_unregister);
|
||||||
|
Reference in New Issue
Block a user