kernel/liveupdate/luo_file.c
Source file repositories/reference/linux-study-clean/kernel/liveupdate/luo_file.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/liveupdate/luo_file.c- Extension
.c- Size
- 31545 bytes
- Lines
- 929
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/compiler.hlinux/err.hlinux/errno.hlinux/file.hlinux/fs.hlinux/io.hlinux/kexec_handover.hlinux/kho/abi/luo.hlinux/list_private.hlinux/liveupdate.hlinux/module.hlinux/sizes.hlinux/xarray.hlinux/slab.hlinux/string.hluo_internal.h
Detected Declarations
struct luo_filefunction luo_get_idfunction luo_token_is_usedfunction list_for_each_entryfunction luo_preserve_filefunction luo_preserve_filefunction luo_file_freeze_onefunction luo_file_unfreeze_onefunction __luo_file_unfreezefunction list_for_each_entryfunction rebootfunction list_for_each_entryfunction luo_file_freezefunction luo_retrieve_filefunction list_for_each_entryfunction luo_file_can_finish_onefunction luo_file_finish_onefunction get_filefunction list_for_each_entryfunction luo_file_deserialize_onefunction luo_retrieve_filefunction luo_file_set_initfunction luo_file_set_destroyfunction liveupdate_register_file_handlerfunction liveupdate_register_file_handler
Annotated Snippet
struct luo_file {
struct liveupdate_file_handler *fh;
struct file *file;
u64 serialized_data;
void *private_data;
int retrieve_status;
struct mutex mutex;
struct list_head list;
u64 token;
};
static unsigned long luo_get_id(struct liveupdate_file_handler *fh,
struct file *file)
{
return fh->ops->get_id ? fh->ops->get_id(file) : (unsigned long)file;
}
static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
{
struct luo_file *iter;
list_for_each_entry(iter, &file_set->files_list, list) {
if (iter->token == token)
return true;
}
return false;
}
/**
* luo_preserve_file - Initiate the preservation of a file descriptor.
* @file_set: The file_set to which the preserved file will be added.
* @token: A unique, user-provided identifier for the file.
* @fd: The file descriptor to be preserved.
*
* This function orchestrates the first phase of preserving a file. Upon entry,
* it takes a reference to the 'struct file' via fget(), effectively making LUO
* a co-owner of the file. This reference is held until the file is either
* unpreserved or successfully finished in the next kernel, preventing the file
* from being prematurely destroyed.
*
* This function orchestrates the first phase of preserving a file. It performs
* the following steps:
*
* 1. Validates that the @token is not already in use within the file_set.
* 2. Ensures the file_set's memory for files serialization is allocated
* (allocates if needed).
* 3. Iterates through registered handlers, calling can_preserve() to find one
* compatible with the given @fd.
* 4. Calls the handler's .preserve() operation, which saves the file's state
* and returns an opaque private data handle.
* 5. Adds the new instance to the file_set's internal list.
*
* On success, LUO takes a reference to the 'struct file' and considers it
* under its management until it is unpreserved or finished.
*
* In case of any failure, all intermediate allocations (file reference, memory
* for the 'luo_file' struct, etc.) are cleaned up before returning an error.
*
* Context: Can be called from an ioctl handler during normal system operation.
* Return: 0 on success. Returns a negative errno on failure:
* -EEXIST if the token is already used.
* -EBUSY if the file descriptor is already preserved by another session.
* -EBADF if the file descriptor is invalid.
* -ENOSPC if the file_set is full.
* -ENOENT if no compatible handler is found.
* -ENOMEM on memory allocation failure.
* Other erros might be returned by .preserve().
*/
int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
{
struct liveupdate_file_op_args args = {0};
struct liveupdate_file_handler *fh;
struct luo_file *luo_file;
struct file *file;
int err;
if (luo_token_is_used(file_set, token))
return -EEXIST;
err = kho_block_set_grow(&file_set->block_set, file_set->count + 1);
if (err)
return err;
file = fget(fd);
if (!file) {
err = -EBADF;
goto err_shrink;
}
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/compiler.h`, `linux/err.h`, `linux/errno.h`, `linux/file.h`, `linux/fs.h`, `linux/io.h`, `linux/kexec_handover.h`.
- Detected declarations: `struct luo_file`, `function luo_get_id`, `function luo_token_is_used`, `function list_for_each_entry`, `function luo_preserve_file`, `function luo_preserve_file`, `function luo_file_freeze_one`, `function luo_file_unfreeze_one`, `function __luo_file_unfreeze`, `function list_for_each_entry`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.