[16/18] skqueue: Split the packets sending code

Submitted by Pavel Emelyanov on July 10, 2017, 9:41 a.m.

Details

Message ID c3893f85-5595-c06d-f56d-7989638510fe@virtuozzo.com
State Accepted
Series "Support descriptors sent over unix sockets"
Headers show

Commit Message

Pavel Emelyanov July 10, 2017, 9:41 a.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/sk-queue.c | 50 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 19 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-queue.c b/criu/sk-queue.c
index 28578b4..057c0bf 100644
--- a/criu/sk-queue.c
+++ b/criu/sk-queue.c
@@ -197,6 +197,34 @@  err_brk:
 	return ret;
 }
 
+static int send_one_pkt(int fd, struct sk_packet *pkt)
+{
+	int ret;
+	SkPacketEntry *entry = pkt->entry;
+
+	/*
+	 * Don't try to use sendfile here, because it use sendpage() and
+	 * all data are split on pages and a new skb is allocated for
+	 * each page. It creates a big overhead on SNDBUF.
+	 * sendfile() isn't suitable for DGRAM sockets, because message
+	 * boundaries messages should be saved.
+	 */
+
+	ret = write(fd, pkt->data, entry->length);
+	xfree(pkt->data);
+	if (ret < 0) {
+		pr_perror("Failed to send packet");
+		return -1;
+	}
+	if (ret != entry->length) {
+		pr_err("Restored skb trimmed to %d/%d\n",
+				ret, (unsigned int)entry->length);
+		return -1;
+	}
+
+	return 0;
+}
+
 int restore_sk_queue(int fd, unsigned int peer_id)
 {
 	struct sk_packet *pkt, *tmp;
@@ -216,26 +244,10 @@  int restore_sk_queue(int fd, unsigned int peer_id)
 		pr_info("\tRestoring %d-bytes skb for %u\n",
 			(unsigned int)entry->length, peer_id);
 
-		/*
-		 * Don't try to use sendfile here, because it use sendpage() and
-		 * all data are split on pages and a new skb is allocated for
-		 * each page. It creates a big overhead on SNDBUF.
-		 * sendfile() isn't suitable for DGRAM sockets, because message
-		 * boundaries messages should be saved.
-		 */
-
-		ret = write(fd, pkt->data, entry->length);
-		xfree(pkt->data);
-		if (ret < 0) {
-			pr_perror("Failed to send packet");
-			goto out;
-		}
-		if (ret != entry->length) {
-			pr_err("Restored skb trimmed to %d/%d\n",
-			       ret, (unsigned int)entry->length);
-			ret = -1;
+		ret = send_one_pkt(fd, pkt);
+		if (ret)
 			goto out;
-		}
+
 		list_del(&pkt->list);
 		sk_packet_entry__free_unpacked(entry, NULL);
 		xfree(pkt);