libceph: enable ceph in a non-default network namespace
Grab a reference on a network namespace of the 'rbd map' (in case of rbd) or 'mount' (in case of ceph) process and use that to open sockets instead of always using init_net and bailing if network namespace is anything but init_net. Be careful to not share struct ceph_client instances between different namespaces and don't add any code in the !CONFIG_NET_NS case. This is based on a patch from Hong Zhiguo <zhiguohong@tencent.com>. Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <linux/inet.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/net.h>
|
||||
#include <linux/nsproxy.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/socket.h>
|
||||
#include <linux/string.h>
|
||||
@@ -479,7 +480,7 @@ static int ceph_tcp_connect(struct ceph_connection *con)
|
||||
int ret;
|
||||
|
||||
BUG_ON(con->sock);
|
||||
ret = sock_create_kern(&init_net, con->peer_addr.in_addr.ss_family,
|
||||
ret = sock_create_kern(read_pnet(&con->msgr->net), paddr->ss_family,
|
||||
SOCK_STREAM, IPPROTO_TCP, &sock);
|
||||
if (ret)
|
||||
return ret;
|
||||
@@ -2944,11 +2945,18 @@ void ceph_messenger_init(struct ceph_messenger *msgr,
|
||||
msgr->tcp_nodelay = tcp_nodelay;
|
||||
|
||||
atomic_set(&msgr->stopping, 0);
|
||||
write_pnet(&msgr->net, get_net(current->nsproxy->net_ns));
|
||||
|
||||
dout("%s %p\n", __func__, msgr);
|
||||
}
|
||||
EXPORT_SYMBOL(ceph_messenger_init);
|
||||
|
||||
void ceph_messenger_fini(struct ceph_messenger *msgr)
|
||||
{
|
||||
put_net(read_pnet(&msgr->net));
|
||||
}
|
||||
EXPORT_SYMBOL(ceph_messenger_fini);
|
||||
|
||||
static void clear_standby(struct ceph_connection *con)
|
||||
{
|
||||
/* come back from STANDBY? */
|
||||
|
Reference in New Issue
Block a user