@@ -1023,7 +1023,8 @@ int erdma_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)
return -ENOENT;
erdma_qp_get(qp);
- ret = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &s);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ AF_INET, SOCK_STREAM, IPPROTO_TCP, &s);
if (ret < 0)
goto error_put_qp;
@@ -1299,7 +1300,8 @@ int erdma_create_listen(struct iw_cm_id *id, int backlog)
if (addr_family != AF_INET)
return -EAFNOSUPPORT;
- ret = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
if (ret < 0)
return ret;
@@ -1391,7 +1391,8 @@ int siw_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)
siw_dbg_qp(qp, "pd_len %d, laddr %pISp, raddr %pISp\n", pd_len, laddr,
raddr);
- rv = sock_create(v4 ? AF_INET : AF_INET6, SOCK_STREAM, IPPROTO_TCP, &s);
+ rv = sock_create_net(current->nsproxy->net_ns,
+ v4 ? AF_INET : AF_INET6, SOCK_STREAM, IPPROTO_TCP, &s);
if (rv < 0)
goto error;
@@ -1766,7 +1767,8 @@ int siw_create_listen(struct iw_cm_id *id, int backlog)
if (addr_family != AF_INET && addr_family != AF_INET6)
return -EAFNOSUPPORT;
- rv = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
+ rv = sock_create_net(current->nsproxy->net_ns,
+ addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
if (rv < 0)
return rv;
@@ -659,7 +659,8 @@ l1oip_socket_thread(void *data)
allow_signal(SIGTERM);
/* create socket */
- if (sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) {
+ if (sock_create_net(current->nsproxy->net_ns,
+ PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) {
printk(KERN_ERR "%s: Failed to create socket.\n", __func__);
ret = -EIO;
goto fail;
@@ -1682,8 +1682,9 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
queue->cmnd_capsule_len = sizeof(struct nvme_command) +
NVME_TCP_ADMIN_CCSZ;
- ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM,
- IPPROTO_TCP, &queue->sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ ctrl->addr.ss_family, SOCK_STREAM,
+ IPPROTO_TCP, &queue->sock);
if (ret) {
dev_err(nctrl->device,
"failed to create socket: %d\n", ret);
@@ -2042,8 +2042,9 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
if (port->nport->inline_data_size < 0)
port->nport->inline_data_size = NVMET_TCP_DEF_INLINE_DATA_SIZE;
- ret = sock_create(port->addr.ss_family, SOCK_STREAM,
- IPPROTO_TCP, &port->sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ port->addr.ss_family, SOCK_STREAM,
+ IPPROTO_TCP, &port->sock);
if (ret) {
pr_err("failed to create a socket\n");
goto err_port;
@@ -837,10 +837,11 @@ int iscsit_setup_np(
return -EINVAL;
}
- ret = sock_create(sockaddr->ss_family, np->np_sock_type,
- np->np_ip_proto, &sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ sockaddr->ss_family, np->np_sock_type,
+ np->np_ip_proto, &sock);
if (ret < 0) {
- pr_err("sock_create() failed.\n");
+ pr_err("sock_create_net() failed.\n");
return ret;
}
np->np_socket = sock;
@@ -406,7 +406,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev,
sa->sa_family != AF_INET)
goto out;
- ret = sock_create(AF_INET, SOCK_STREAM, 0, &sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ AF_INET, SOCK_STREAM, 0, &sock);
if (ret < 0)
goto out;
ret = inet_stream_connect(sock, sa, req->u.connect.len, 0);
@@ -647,7 +648,8 @@ static int pvcalls_back_bind(struct xenbus_device *dev,
goto out;
}
- ret = sock_create(AF_INET, SOCK_STREAM, 0, &map->sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ AF_INET, SOCK_STREAM, 0, &map->sock);
if (ret < 0)
goto out;
@@ -1558,7 +1558,7 @@ static void o2net_start_connect(struct work_struct *work)
unsigned int nofs_flag;
/*
- * sock_create allocates the sock with GFP_KERNEL. We must
+ * sock_create_net() allocates the sock with GFP_KERNEL. We must
* prevent the filesystem from being reentered by memory reclaim.
*/
nofs_flag = memalloc_nofs_save();
@@ -1600,7 +1600,8 @@ static void o2net_start_connect(struct work_struct *work)
goto out;
}
- ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
if (ret < 0) {
mlog(0, "can't create socket: %d\n", ret);
goto out;
@@ -1986,7 +1987,8 @@ static int o2net_open_listening_sock(__be32 addr, __be16 port)
.sin_port = port,
};
- ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
+ ret = sock_create_net(current->nsproxy->net_ns,
+ PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
if (ret < 0) {
printk(KERN_ERR "o2net: Error %d while creating socket\n", ret);
goto out;
@@ -423,18 +423,19 @@ static void tcp_destroy_socket(struct socket *ksmbd_socket)
*/
static int create_socket(struct interface *iface)
{
+ struct net *net = current->nsproxy->net_ns;
int ret;
struct sockaddr_in6 sin6;
struct sockaddr_in sin;
struct socket *ksmbd_socket;
bool ipv4 = false;
- ret = sock_create(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &ksmbd_socket);
+ ret = sock_create_net(net, PF_INET6, SOCK_STREAM, IPPROTO_TCP, &ksmbd_socket);
if (ret) {
if (ret != -EAFNOSUPPORT)
pr_err("Can't create socket for ipv6, fallback to ipv4: %d\n", ret);
- ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP,
- &ksmbd_socket);
+ ret = sock_create_net(net, PF_INET, SOCK_STREAM, IPPROTO_TCP,
+ &ksmbd_socket);
if (ret) {
pr_err("Can't create socket for ipv4: %d\n", ret);
goto out_clear;
sock_create() is a bad name, and no one really cares about what it's for. In fact, except for only one user, sctp_do_peeloff(), all sockets created by drivers and fs are not tied to userspace processes nor exposed via file descriptors. Let's use sock_create_net() for such in-kernel use cases. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- drivers/infiniband/hw/erdma/erdma_cm.c | 6 ++++-- drivers/infiniband/sw/siw/siw_cm.c | 6 ++++-- drivers/isdn/mISDN/l1oip_core.c | 3 ++- drivers/nvme/host/tcp.c | 5 +++-- drivers/nvme/target/tcp.c | 5 +++-- drivers/target/iscsi/iscsi_target_login.c | 7 ++++--- drivers/xen/pvcalls-back.c | 6 ++++-- fs/ocfs2/cluster/tcp.c | 8 +++++--- fs/smb/server/transport_tcp.c | 7 ++++--- 9 files changed, 33 insertions(+), 20 deletions(-)