Commit 6e434967 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

net: add sock_set_priority

Add a helper to directly set the SO_PRIORITY sockopt from kernel space
without going through a fake uaccess.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c433594c
...@@ -1362,16 +1362,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, ...@@ -1362,16 +1362,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
*/ */
sock_no_linger(queue->sock->sk); sock_no_linger(queue->sock->sk);
if (so_priority > 0) { if (so_priority > 0)
ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_PRIORITY, sock_set_priority(queue->sock->sk, so_priority);
(char *)&so_priority, sizeof(so_priority));
if (ret) {
dev_err(ctrl->ctrl.device,
"failed to set SO_PRIORITY sock opt, ret %d\n",
ret);
goto err_sock;
}
}
/* Set socket type of service */ /* Set socket type of service */
if (nctrl->opts->tos >= 0) { if (nctrl->opts->tos >= 0) {
......
...@@ -1448,12 +1448,8 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) ...@@ -1448,12 +1448,8 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
*/ */
sock_no_linger(sock->sk); sock_no_linger(sock->sk);
if (so_priority > 0) { if (so_priority > 0)
ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY, sock_set_priority(sock->sk, so_priority);
(char *)&so_priority, sizeof(so_priority));
if (ret)
return ret;
}
/* Set socket type of service */ /* Set socket type of service */
if (inet->rcv_tos > 0) { if (inet->rcv_tos > 0) {
...@@ -1638,14 +1634,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) ...@@ -1638,14 +1634,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
goto err_sock; goto err_sock;
} }
if (so_priority > 0) { if (so_priority > 0)
ret = kernel_setsockopt(port->sock, SOL_SOCKET, SO_PRIORITY, sock_set_priority(port->sock->sk, so_priority);
(char *)&so_priority, sizeof(so_priority));
if (ret) {
pr_err("failed to set SO_PRIORITY sock opt %d\n", ret);
goto err_sock;
}
}
ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr, ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
sizeof(port->addr)); sizeof(port->addr));
......
...@@ -2689,6 +2689,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif) ...@@ -2689,6 +2689,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
void sock_def_readable(struct sock *sk); void sock_def_readable(struct sock *sk);
void sock_no_linger(struct sock *sk); void sock_no_linger(struct sock *sk);
void sock_set_priority(struct sock *sk, u32 priority);
void sock_set_reuseaddr(struct sock *sk); void sock_set_reuseaddr(struct sock *sk);
#endif /* _SOCK_H */ #endif /* _SOCK_H */
...@@ -729,6 +729,14 @@ void sock_no_linger(struct sock *sk) ...@@ -729,6 +729,14 @@ void sock_no_linger(struct sock *sk)
} }
EXPORT_SYMBOL(sock_no_linger); EXPORT_SYMBOL(sock_no_linger);
void sock_set_priority(struct sock *sk, u32 priority)
{
lock_sock(sk);
sk->sk_priority = priority;
release_sock(sk);
}
EXPORT_SYMBOL(sock_set_priority);
/* /*
* This is meant for all protocols to use and covers goings on * This is meant for all protocols to use and covers goings on
* at the socket level. Everything here is generic. * at the socket level. Everything here is generic.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment