drivers/md/dm-vdo/physical-zone.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/physical-zone.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/physical-zone.c- Extension
.c- Size
- 20369 bytes
- Lines
- 644
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
physical-zone.hlinux/list.hlogger.hmemory-alloc.hpermassert.hblock-map.hcompletion.hconstants.hdata-vio.hdedupe.hencodings.hflush.hint-map.hslab-depot.hstatus-codes.hvdo.h
Detected Declarations
struct pbn_lock_implementationstruct pbn_lock_poolfunction has_lock_typefunction vdo_is_pbn_read_lockfunction set_pbn_lock_typefunction vdo_downgrade_pbn_write_lockfunction vdo_claim_pbn_lock_incrementfunction vdo_assign_pbn_lock_provisional_referencefunction vdo_unassign_pbn_lock_provisional_referencefunction release_pbn_lock_provisional_referencefunction return_pbn_lock_to_poolfunction make_pbn_lock_poolfunction free_pbn_lock_poolfunction borrow_pbn_lock_from_poolfunction initialize_zonefunction vdo_make_physical_zonesfunction vdo_free_physical_zonesfunction vdo_get_physical_zone_pbn_lockfunction vdo_attempt_physical_zone_pbn_lockfunction allocate_and_lock_blockfunction retry_allocationfunction continue_allocatingfunction vdo_allocate_block_in_zonefunction vdo_release_physical_zone_pbn_lockfunction vdo_dump_physical_zone
Annotated Snippet
struct pbn_lock_implementation {
enum pbn_lock_type type;
const char *name;
const char *release_reason;
};
/* This array must have an entry for every pbn_lock_type value. */
static const struct pbn_lock_implementation LOCK_IMPLEMENTATIONS[] = {
[VIO_READ_LOCK] = {
.type = VIO_READ_LOCK,
.name = "read",
.release_reason = "candidate duplicate",
},
[VIO_WRITE_LOCK] = {
.type = VIO_WRITE_LOCK,
.name = "write",
.release_reason = "newly allocated",
},
[VIO_BLOCK_MAP_WRITE_LOCK] = {
.type = VIO_BLOCK_MAP_WRITE_LOCK,
.name = "block map write",
.release_reason = "block map write",
},
};
static inline bool has_lock_type(const struct pbn_lock *lock, enum pbn_lock_type type)
{
return (lock->implementation == &LOCK_IMPLEMENTATIONS[type]);
}
/**
* vdo_is_pbn_read_lock() - Check whether a pbn_lock is a read lock.
* @lock: The lock to check.
*
* Return: True if the lock is a read lock.
*/
bool vdo_is_pbn_read_lock(const struct pbn_lock *lock)
{
return has_lock_type(lock, VIO_READ_LOCK);
}
static inline void set_pbn_lock_type(struct pbn_lock *lock, enum pbn_lock_type type)
{
lock->implementation = &LOCK_IMPLEMENTATIONS[type];
}
/**
* vdo_downgrade_pbn_write_lock() - Downgrade a PBN write lock to a PBN read lock.
* @lock: The PBN write lock to downgrade.
* @compressed_write: True if the written block was a compressed block.
*
* The lock holder count is cleared and the caller is responsible for setting the new count.
*/
void vdo_downgrade_pbn_write_lock(struct pbn_lock *lock, bool compressed_write)
{
VDO_ASSERT_LOG_ONLY(!vdo_is_pbn_read_lock(lock),
"PBN lock must not already have been downgraded");
VDO_ASSERT_LOG_ONLY(!has_lock_type(lock, VIO_BLOCK_MAP_WRITE_LOCK),
"must not downgrade block map write locks");
VDO_ASSERT_LOG_ONLY(lock->holder_count == 1,
"PBN write lock should have one holder but has %u",
lock->holder_count);
/*
* data_vio write locks are downgraded in place--the writer retains the hold on the lock.
* If this was a compressed write, the holder has not yet journaled its own inc ref,
* otherwise, it has.
*/
lock->increment_limit =
(compressed_write ? MAXIMUM_REFERENCE_COUNT : MAXIMUM_REFERENCE_COUNT - 1);
set_pbn_lock_type(lock, VIO_READ_LOCK);
}
/**
* vdo_claim_pbn_lock_increment() - Try to claim one of the available reference count increments on
* a read lock.
* @lock: The PBN read lock from which to claim an increment.
*
* Claims may be attempted from any thread. A claim is only valid until the PBN lock is released.
*
* Return: true if the claim succeeded, guaranteeing one increment can be made without overflowing
* the PBN's reference count.
*/
bool vdo_claim_pbn_lock_increment(struct pbn_lock *lock)
{
/*
* Claim the next free reference atomically since hash locks from multiple hash zone
* threads might be concurrently deduplicating against a single PBN lock on compressed
* block. As long as hitting the increment limit will lead to the PBN lock being released
* in a sane time-frame, we won't overflow a 32-bit claim counter, allowing a simple add
* instead of a compare-and-swap.
Annotation
- Immediate include surface: `physical-zone.h`, `linux/list.h`, `logger.h`, `memory-alloc.h`, `permassert.h`, `block-map.h`, `completion.h`, `constants.h`.
- Detected declarations: `struct pbn_lock_implementation`, `struct pbn_lock_pool`, `function has_lock_type`, `function vdo_is_pbn_read_lock`, `function set_pbn_lock_type`, `function vdo_downgrade_pbn_write_lock`, `function vdo_claim_pbn_lock_increment`, `function vdo_assign_pbn_lock_provisional_reference`, `function vdo_unassign_pbn_lock_provisional_reference`, `function release_pbn_lock_provisional_reference`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.