[Devel] [PATCH RHEL7 COMMIT] netlink: allow to set peeking offset for sockets
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Jun 17 03:27:30 PDT 2016
The commit is pushed to "branch-rh7-3.10.0-327.18.2.vz7.14.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.18.2.vz7.14.15
------>
commit 0ea1e7e20330b9acf644be7344d9742fbe1cf0e9
Author: Andrey Vagin <avagin at openvz.org>
Date: Fri Jun 17 14:27:30 2016 +0400
netlink: allow to set peeking offset for sockets
Patchset description:
netlink: prepare to dump and restore data from a receive queue
CRIU can dump queued data for unix and tcp sockets,
now it's time for netlink sockets.
Here are there questions.
* How to dump data from a receive queue
We can set peeking offset like we do for unix sockets.
* How to restore data back to a receive queue
I suggest to add a repair mode like we do for tcp sockets.
* When we can dump data from a receive queue.
I think we can do this only if a socket doesn't have a running callback.
Andrey Vagin (3):
netlink: allow to set peeking offset for sockets
netlink: add an ability to restore messages in a receive queue
netlink/diag: report flags for netlink sockets
https://jira.sw.ru/browse/PSBM-28386
khorenko@: there is no locking right now, but while we are the only
user for this interface, this is not essential at the moment, we'll add
locking on top later in the scope of:
https://jira.sw.ru/browse/PSBM-48484
===========================================================
This patch description:
This allows us to read socket's queue without removing skbs from it.
The same logic was implemented for unix and inet sockets and we use this
to dump and restore sockets in CRIU.
Here is a question whether sk_peek_off has to be protected by locks.
Currently it isn't protected and an user who uses sk_peek_off has to be
sure that nobody calls recvmsg for a socket except him.
https://jira.sw.ru/browse/PSBM-28386
Signed-off-by: Andrey Vagin <avagin at virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
net/netlink/af_netlink.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index ad65bdd..79526e5 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2372,17 +2372,18 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
struct scm_cookie scm;
struct sock *sk = sock->sk;
struct netlink_sock *nlk = nlk_sk(sk);
- int noblock = flags&MSG_DONTWAIT;
size_t copied;
struct sk_buff *skb, *data_skb;
+ int peeked, skip;
int err, ret;
if (flags&MSG_OOB)
return -EOPNOTSUPP;
copied = 0;
+ skip = sk_peek_offset(sk, flags);
- skb = skb_recv_datagram(sk, flags, noblock, &err);
+ skb = __skb_recv_datagram(sk, flags, &peeked, &skip, &err);
if (skb == NULL)
goto out;
@@ -2410,14 +2411,19 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
nlk->max_recvmsg_len = min_t(size_t, nlk->max_recvmsg_len,
16384);
- copied = data_skb->len;
+ copied = data_skb->len - skip;
if (len < copied) {
msg->msg_flags |= MSG_TRUNC;
copied = len;
}
skb_reset_transport_header(data_skb);
- err = skb_copy_datagram_iovec(data_skb, 0, msg->msg_iov, copied);
+ err = skb_copy_datagram_iovec(data_skb, skip, msg->msg_iov, copied);
+
+ if (flags & MSG_PEEK)
+ sk_peek_offset_fwd(sk, copied);
+ else
+ sk_peek_offset_bwd(sk, skb->len);
if (msg->msg_name) {
struct sockaddr_nl *addr = (struct sockaddr_nl *)msg->msg_name;
@@ -2439,7 +2445,7 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
}
siocb->scm->creds = *NETLINK_CREDS(skb);
if (flags & MSG_TRUNC)
- copied = data_skb->len;
+ copied = data_skb->len - skip;
skb_free_datagram(sk, skb);
@@ -3086,6 +3092,13 @@ int netlink_unregister_notifier(struct notifier_block *nb)
}
EXPORT_SYMBOL(netlink_unregister_notifier);
+static int netlink_set_peek_off(struct sock *sk, int val)
+{
+ sk->sk_peek_off = val;
+
+ return 0;
+}
+
static const struct proto_ops netlink_ops = {
.family = PF_NETLINK,
.owner = THIS_MODULE,
@@ -3105,6 +3118,7 @@ static const struct proto_ops netlink_ops = {
.recvmsg = netlink_recvmsg,
.mmap = netlink_mmap,
.sendpage = sock_no_sendpage,
+ .set_peek_off = netlink_set_peek_off,
};
static const struct net_proto_family netlink_family_ops = {
More information about the Devel
mailing list