drivers/md/dm-pcache/pcache_internal.h
Source file repositories/reference/linux-study-clean/drivers/md/dm-pcache/pcache_internal.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-pcache/pcache_internal.h- Extension
.h- Size
- 3547 bytes
- Lines
- 118
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/crc32c.h
Detected Declarations
struct pcache_meta_headerfunction pcache_meta_crcfunction pcache_meta_seq_after
Annotated Snippet
struct pcache_meta_header {
__u32 crc;
__u8 seq;
__u8 version;
__u16 res;
};
/*
* pcache_meta_crc - Calculate CRC for the given metadata header.
* @header: Pointer to the metadata header.
* @meta_size: Size of the metadata structure.
*
* Returns the CRC checksum calculated by excluding the CRC field itself.
*/
static inline u32 pcache_meta_crc(struct pcache_meta_header *header, u32 meta_size)
{
return crc32c(PCACHE_CRC_SEED, (void *)header + 4, meta_size - 4);
}
/*
* pcache_meta_seq_after - Check if a sequence number is more recent, accounting for overflow.
* @seq1: First sequence number.
* @seq2: Second sequence number.
*
* Determines if @seq1 is more recent than @seq2 by calculating the signed
* difference between them. This approach allows handling sequence number
* overflow correctly because the difference wraps naturally, and any value
* greater than zero indicates that @seq1 is "after" @seq2. This method
* assumes 8-bit unsigned sequence numbers, where the difference wraps
* around if seq1 overflows past seq2.
*
* Returns:
* - true if @seq1 is more recent than @seq2, indicating it comes "after"
* - false otherwise.
*/
static inline bool pcache_meta_seq_after(u8 seq1, u8 seq2)
{
return (s8)(seq1 - seq2) > 0;
}
/*
* pcache_meta_find_latest - Find the latest valid metadata.
* @header: Pointer to the metadata header.
* @meta_size: Size of each metadata block.
*
* Finds the latest valid metadata by checking sequence numbers. If a
* valid entry with the highest sequence number is found, its pointer
* is returned. Returns NULL if no valid metadata is found.
*/
static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_header *header,
u32 meta_size, u32 meta_max_size,
void *meta_ret)
{
struct pcache_meta_header *meta, *latest = NULL;
u32 i, seq_latest = 0;
void *meta_addr;
meta = meta_ret;
for (i = 0; i < PCACHE_META_INDEX_MAX; i++) {
meta_addr = (void *)header + (i * meta_max_size);
if (copy_mc_to_kernel(meta, meta_addr, meta_size)) {
pcache_err("hardware memory error when copy meta");
return ERR_PTR(-EIO);
}
/* Skip if CRC check fails, which means corrupted */
if (meta->crc != pcache_meta_crc(meta, meta_size))
continue;
/* Update latest if a more recent sequence is found */
if (!latest || pcache_meta_seq_after(meta->seq, seq_latest)) {
seq_latest = meta->seq;
latest = meta_addr;
}
}
if (!latest)
return NULL;
if (copy_mc_to_kernel(meta_ret, latest, meta_size)) {
pcache_err("hardware memory error");
return ERR_PTR(-EIO);
}
return latest;
}
#endif /* _PCACHE_INTERNAL_H */
Annotation
- Immediate include surface: `linux/delay.h`, `linux/crc32c.h`.
- Detected declarations: `struct pcache_meta_header`, `function pcache_meta_crc`, `function pcache_meta_seq_after`.
- Atlas domain: Driver Families / drivers/md.
- 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.