tools/hv/hv_kvp_daemon.c
Source file repositories/reference/linux-study-clean/tools/hv/hv_kvp_daemon.c
File Facts
- System
- Linux kernel
- Corpus path
tools/hv/hv_kvp_daemon.c- Extension
.c- Size
- 46998 bytes
- Lines
- 2060
- 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
sys/poll.hsys/utsname.hstdbool.hstdio.hstdlib.hunistd.hstring.hctype.herrno.harpa/inet.hlinux/hyperv.hifaddrs.hnetdb.hsyslog.hsys/stat.hfcntl.hdirent.hnet/if.hlimits.hgetopt.h
Detected Declarations
struct kvp_recordstruct kvp_file_stateenum key_indexfunction kvp_acquire_lockfunction kvp_release_lockfunction kvp_update_filefunction kvp_dump_initial_poolsfunction kvp_update_mem_statefunction kvp_file_initfunction kvp_key_deletefunction kvp_key_add_or_modifyfunction kvp_get_valuefunction kvp_pool_enumeratefunction kvp_get_os_infofunction kvp_process_ipconfig_filefunction kvp_verify_ip_addressfunction kvp_extract_routesfunction kvp_get_gatewayfunction kvp_get_ipconfig_infofunction hweight32function kvp_process_ip_addressfunction kvp_get_ip_infofunction kvp_mac_to_ipfunction expand_ipv6function is_ipv4function parse_ip_val_bufferfunction kvp_write_filefunction process_ip_stringfunction ip_version_checkfunction kvp_subnet_to_plenfunction process_dns_gateway_nmfunction process_ip_string_nmfunction kvp_set_ip_infofunction kvp_get_domain_namefunction print_usagefunction main
Annotated Snippet
struct kvp_record {
char key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
char value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
};
struct kvp_file_state {
int fd;
int num_blocks;
struct kvp_record *records;
int num_records;
char fname[MAX_FILE_NAME];
};
static struct kvp_file_state kvp_file_info[KVP_POOL_COUNT];
static void kvp_acquire_lock(int pool)
{
struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
syslog(LOG_ERR, "Failed to acquire the lock pool: %d; error: %d %s", pool,
errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
static void kvp_release_lock(int pool)
{
struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0};
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
syslog(LOG_ERR, "Failed to release the lock pool: %d; error: %d %s", pool,
errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
static void kvp_update_file(int pool)
{
FILE *filep;
/*
* We are going to write our in-memory registry out to
* disk; acquire the lock first.
*/
kvp_acquire_lock(pool);
filep = fopen(kvp_file_info[pool].fname, "we");
if (!filep) {
syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
errno, strerror(errno));
kvp_release_lock(pool);
exit(EXIT_FAILURE);
}
fwrite(kvp_file_info[pool].records, sizeof(struct kvp_record),
kvp_file_info[pool].num_records, filep);
if (ferror(filep) || fclose(filep)) {
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
exit(EXIT_FAILURE);
}
kvp_release_lock(pool);
}
static void kvp_dump_initial_pools(int pool)
{
int i;
syslog(LOG_DEBUG, "===Start dumping the contents of pool %d ===\n",
pool);
for (i = 0; i < kvp_file_info[pool].num_records; i++)
syslog(LOG_DEBUG, "pool: %d, %d/%d key=%s val=%s\n",
pool, i + 1, kvp_file_info[pool].num_records,
kvp_file_info[pool].records[i].key,
kvp_file_info[pool].records[i].value);
}
static void kvp_update_mem_state(int pool)
{
FILE *filep;
size_t records_read = 0;
struct kvp_record *record = kvp_file_info[pool].records;
struct kvp_record *readp;
int num_blocks = kvp_file_info[pool].num_blocks;
Annotation
- Immediate include surface: `sys/poll.h`, `sys/utsname.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `string.h`, `ctype.h`.
- Detected declarations: `struct kvp_record`, `struct kvp_file_state`, `enum key_index`, `function kvp_acquire_lock`, `function kvp_release_lock`, `function kvp_update_file`, `function kvp_dump_initial_pools`, `function kvp_update_mem_state`, `function kvp_file_init`, `function kvp_key_delete`.
- 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.