~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/vsock/msg_zerocopy_common.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Some common code for MSG_ZEROCOPY logic
  3  *
  4  * Copyright (C) 2023 SberDevices.
  5  *
  6  * Author: Arseniy Krasnov <avkrasnov@salutedevices.com>
  7  */
  8 
  9 #include <stdio.h>
 10 #include <stdlib.h>
 11 #include <sys/types.h>
 12 #include <sys/socket.h>
 13 #include <linux/errqueue.h>
 14 
 15 #include "msg_zerocopy_common.h"
 16 
 17 void enable_so_zerocopy(int fd)
 18 {
 19         int val = 1;
 20 
 21         if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) {
 22                 perror("setsockopt");
 23                 exit(EXIT_FAILURE);
 24         }
 25 }
 26 
 27 void vsock_recv_completion(int fd, const bool *zerocopied)
 28 {
 29         struct sock_extended_err *serr;
 30         struct msghdr msg = { 0 };
 31         char cmsg_data[128];
 32         struct cmsghdr *cm;
 33         ssize_t res;
 34 
 35         msg.msg_control = cmsg_data;
 36         msg.msg_controllen = sizeof(cmsg_data);
 37 
 38         res = recvmsg(fd, &msg, MSG_ERRQUEUE);
 39         if (res) {
 40                 fprintf(stderr, "failed to read error queue: %zi\n", res);
 41                 exit(EXIT_FAILURE);
 42         }
 43 
 44         cm = CMSG_FIRSTHDR(&msg);
 45         if (!cm) {
 46                 fprintf(stderr, "cmsg: no cmsg\n");
 47                 exit(EXIT_FAILURE);
 48         }
 49 
 50         if (cm->cmsg_level != SOL_VSOCK) {
 51                 fprintf(stderr, "cmsg: unexpected 'cmsg_level'\n");
 52                 exit(EXIT_FAILURE);
 53         }
 54 
 55         if (cm->cmsg_type != VSOCK_RECVERR) {
 56                 fprintf(stderr, "cmsg: unexpected 'cmsg_type'\n");
 57                 exit(EXIT_FAILURE);
 58         }
 59 
 60         serr = (void *)CMSG_DATA(cm);
 61         if (serr->ee_origin != SO_EE_ORIGIN_ZEROCOPY) {
 62                 fprintf(stderr, "serr: wrong origin: %u\n", serr->ee_origin);
 63                 exit(EXIT_FAILURE);
 64         }
 65 
 66         if (serr->ee_errno) {
 67                 fprintf(stderr, "serr: wrong error code: %u\n", serr->ee_errno);
 68                 exit(EXIT_FAILURE);
 69         }
 70 
 71         /* This flag is used for tests, to check that transmission was
 72          * performed as expected: zerocopy or fallback to copy. If NULL
 73          * - don't care.
 74          */
 75         if (!zerocopied)
 76                 return;
 77 
 78         if (*zerocopied && (serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) {
 79                 fprintf(stderr, "serr: was copy instead of zerocopy\n");
 80                 exit(EXIT_FAILURE);
 81         }
 82 
 83         if (!*zerocopied && !(serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) {
 84                 fprintf(stderr, "serr: was zerocopy instead of copy\n");
 85                 exit(EXIT_FAILURE);
 86         }
 87 }
 88 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php