drivers/md/persistent-data/dm-bitset.c
Source file repositories/reference/linux-study-clean/drivers/md/persistent-data/dm-bitset.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/persistent-data/dm-bitset.c- Extension
.c- Size
- 7180 bytes
- Lines
- 320
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dm-bitset.hdm-transaction-manager.hlinux/export.hlinux/device-mapper.h
Detected Declarations
struct packer_contextfunction dm_disk_bitset_initfunction dm_bitset_emptyfunction pack_bitsfunction dm_bitset_newfunction dm_bitset_resizefunction dm_bitset_delfunction dm_bitset_flushfunction read_bitsfunction get_array_entryfunction dm_bitset_set_bitfunction dm_bitset_clear_bitfunction dm_bitset_test_bitfunction cursor_next_array_entryfunction dm_bitset_cursor_beginfunction dm_bitset_cursor_endfunction dm_bitset_cursor_nextfunction dm_bitset_cursor_skipfunction dm_bitset_cursor_get_valueexport dm_disk_bitset_initexport dm_bitset_emptyexport dm_bitset_newexport dm_bitset_resizeexport dm_bitset_delexport dm_bitset_flushexport dm_bitset_set_bitexport dm_bitset_clear_bitexport dm_bitset_test_bitexport dm_bitset_cursor_beginexport dm_bitset_cursor_endexport dm_bitset_cursor_nextexport dm_bitset_cursor_skipexport dm_bitset_cursor_get_value
Annotated Snippet
struct packer_context {
bit_value_fn fn;
unsigned int nr_bits;
void *context;
};
static int pack_bits(uint32_t index, void *value, void *context)
{
int r;
struct packer_context *p = context;
unsigned int bit, nr = min(64u, p->nr_bits - (index * 64));
uint64_t word = 0;
bool bv;
for (bit = 0; bit < nr; bit++) {
r = p->fn(index * 64 + bit, &bv, p->context);
if (r)
return r;
if (bv)
set_bit(bit, (unsigned long *) &word);
else
clear_bit(bit, (unsigned long *) &word);
}
*((__le64 *) value) = cpu_to_le64(word);
return 0;
}
int dm_bitset_new(struct dm_disk_bitset *info, dm_block_t *root,
uint32_t size, bit_value_fn fn, void *context)
{
struct packer_context p;
p.fn = fn;
p.nr_bits = size;
p.context = context;
return dm_array_new(&info->array_info, root, dm_div_up(size, 64), pack_bits, &p);
}
EXPORT_SYMBOL_GPL(dm_bitset_new);
int dm_bitset_resize(struct dm_disk_bitset *info, dm_block_t root,
uint32_t old_nr_entries, uint32_t new_nr_entries,
bool default_value, dm_block_t *new_root)
{
uint32_t old_blocks = dm_div_up(old_nr_entries, BITS_PER_ARRAY_ENTRY);
uint32_t new_blocks = dm_div_up(new_nr_entries, BITS_PER_ARRAY_ENTRY);
__le64 value = default_value ? cpu_to_le64(~0) : cpu_to_le64(0);
__dm_bless_for_disk(&value);
return dm_array_resize(&info->array_info, root, old_blocks, new_blocks,
&value, new_root);
}
EXPORT_SYMBOL_GPL(dm_bitset_resize);
int dm_bitset_del(struct dm_disk_bitset *info, dm_block_t root)
{
return dm_array_del(&info->array_info, root);
}
EXPORT_SYMBOL_GPL(dm_bitset_del);
int dm_bitset_flush(struct dm_disk_bitset *info, dm_block_t root,
dm_block_t *new_root)
{
int r;
__le64 value;
if (!info->current_index_set || !info->dirty)
return 0;
value = cpu_to_le64(info->current_bits);
__dm_bless_for_disk(&value);
r = dm_array_set_value(&info->array_info, root, info->current_index,
&value, new_root);
if (r)
return r;
info->current_index_set = false;
info->dirty = false;
return 0;
}
EXPORT_SYMBOL_GPL(dm_bitset_flush);
static int read_bits(struct dm_disk_bitset *info, dm_block_t root,
uint32_t array_index)
{
Annotation
- Immediate include surface: `dm-bitset.h`, `dm-transaction-manager.h`, `linux/export.h`, `linux/device-mapper.h`.
- Detected declarations: `struct packer_context`, `function dm_disk_bitset_init`, `function dm_bitset_empty`, `function pack_bits`, `function dm_bitset_new`, `function dm_bitset_resize`, `function dm_bitset_del`, `function dm_bitset_flush`, `function read_bits`, `function get_array_entry`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: integration 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.