]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: add sock_set_priority
authorChristoph Hellwig <hch@lst.de>
Thu, 28 May 2020 05:12:11 +0000 (07:12 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 28 May 2020 18:11:44 +0000 (11:11 -0700)
Add a helper to directly set the SO_PRIORITY sockopt from kernel space
without going through a fake uaccess.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/nvme/host/tcp.c
drivers/nvme/target/tcp.c
include/net/sock.h
net/core/sock.c

index e72d87482eb787f2f01aa1ae8fe029e3a4239e82..a307972d33a02903a85e97aa29cec3ab16894dae 100644 (file)
@@ -1362,16 +1362,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
         */
        sock_no_linger(queue->sock->sk);
 
-       if (so_priority > 0) {
-               ret = kernel_setsockopt(queue->sock, SOL_SOCKET, 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;
-               }
-       }
+       if (so_priority > 0)
+               sock_set_priority(queue->sock->sk, so_priority);
 
        /* Set socket type of service */
        if (nctrl->opts->tos >= 0) {
index e0801494b097f188f173abcee769ffb11fcdf0d1..f3088156d01da4dd6b7d52505fdd0423fedf762b 100644 (file)
@@ -1448,12 +1448,8 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
         */
        sock_no_linger(sock->sk);
 
-       if (so_priority > 0) {
-               ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY,
-                               (char *)&so_priority, sizeof(so_priority));
-               if (ret)
-                       return ret;
-       }
+       if (so_priority > 0)
+               sock_set_priority(sock->sk, so_priority);
 
        /* Set socket type of service */
        if (inet->rcv_tos > 0) {
@@ -1638,14 +1634,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
                goto err_sock;
        }
 
-       if (so_priority > 0) {
-               ret = kernel_setsockopt(port->sock, SOL_SOCKET, 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;
-               }
-       }
+       if (so_priority > 0)
+               sock_set_priority(port->sock->sk, so_priority);
 
        ret = kernel_bind(port->sock, (struct sockaddr *)&port->addr,
                        sizeof(port->addr));
index 6ed00bf009bbe9de94e6386b580e54566bfec138..a3a43141a4be25cc81b92d835f2b4e7be1d64015 100644 (file)
@@ -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_no_linger(struct sock *sk);
+void sock_set_priority(struct sock *sk, u32 priority);
 void sock_set_reuseaddr(struct sock *sk);
 
 #endif /* _SOCK_H */
index f0f09524911c8d2577421e704b20ed310da40e6a..ceda1a9248b3ef9adc02ee52e1abbacf83acd1ec 100644 (file)
@@ -729,6 +729,14 @@ void sock_no_linger(struct sock *sk)
 }
 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
  *     at the socket level. Everything here is generic.