tools/testing/vsock/msg_zerocopy_common.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/msg_zerocopy_common.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/msg_zerocopy_common.c- Extension
.c- Size
- 1840 bytes
- Lines
- 78
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hsys/types.hsys/socket.hlinux/errqueue.hmsg_zerocopy_common.h
Detected Declarations
function Copyright
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/* Some common code for MSG_ZEROCOPY logic
*
* Copyright (C) 2023 SberDevices.
*
* Author: Arseniy Krasnov <avkrasnov@salutedevices.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/errqueue.h>
#include "msg_zerocopy_common.h"
void vsock_recv_completion(int fd, const bool *zerocopied)
{
struct sock_extended_err *serr;
struct msghdr msg = { 0 };
char cmsg_data[128];
struct cmsghdr *cm;
ssize_t res;
msg.msg_control = cmsg_data;
msg.msg_controllen = sizeof(cmsg_data);
res = recvmsg(fd, &msg, MSG_ERRQUEUE);
if (res) {
fprintf(stderr, "failed to read error queue: %zi\n", res);
exit(EXIT_FAILURE);
}
cm = CMSG_FIRSTHDR(&msg);
if (!cm) {
fprintf(stderr, "cmsg: no cmsg\n");
exit(EXIT_FAILURE);
}
if (cm->cmsg_level != SOL_VSOCK) {
fprintf(stderr, "cmsg: unexpected 'cmsg_level'\n");
exit(EXIT_FAILURE);
}
if (cm->cmsg_type != VSOCK_RECVERR) {
fprintf(stderr, "cmsg: unexpected 'cmsg_type'\n");
exit(EXIT_FAILURE);
}
serr = (void *)CMSG_DATA(cm);
if (serr->ee_origin != SO_EE_ORIGIN_ZEROCOPY) {
fprintf(stderr, "serr: wrong origin: %u\n", serr->ee_origin);
exit(EXIT_FAILURE);
}
if (serr->ee_errno) {
fprintf(stderr, "serr: wrong error code: %u\n", serr->ee_errno);
exit(EXIT_FAILURE);
}
/* This flag is used for tests, to check that transmission was
* performed as expected: zerocopy or fallback to copy. If NULL
* - don't care.
*/
if (!zerocopied)
return;
if (*zerocopied && (serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) {
fprintf(stderr, "serr: was copy instead of zerocopy\n");
exit(EXIT_FAILURE);
}
if (!*zerocopied && !(serr->ee_code & SO_EE_CODE_ZEROCOPY_COPIED)) {
fprintf(stderr, "serr: was zerocopy instead of copy\n");
exit(EXIT_FAILURE);
}
}
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `sys/types.h`, `sys/socket.h`, `linux/errqueue.h`, `msg_zerocopy_common.h`.
- Detected declarations: `function Copyright`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.