drivers/md/dm-dust.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-dust.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-dust.c- Extension
.c- Size
- 13859 bytes
- Lines
- 580
- 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.
- 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/device-mapper.hlinux/module.hlinux/rbtree.h
Detected Declarations
struct badblockstruct dust_devicefunction dust_rb_insertfunction dust_remove_blockfunction dust_add_blockfunction dust_query_blockfunction __dust_map_readfunction dust_map_readfunction __dust_map_writefunction dust_map_writefunction dust_mapfunction __dust_clear_badblocksfunction dust_clear_badblocksfunction dust_list_badblocksfunction dust_ctrfunction dust_dtrfunction dust_messagefunction dust_statusfunction dust_prepare_ioctlfunction dust_iterate_devices
Annotated Snippet
struct badblock {
struct rb_node node;
sector_t bb;
unsigned char wr_fail_cnt;
};
struct dust_device {
struct dm_dev *dev;
struct rb_root badblocklist;
unsigned long long badblock_count;
spinlock_t dust_lock;
unsigned int blksz;
int sect_per_block_shift;
unsigned int sect_per_block;
sector_t start;
bool fail_read_on_bb:1;
bool quiet_mode:1;
};
static struct badblock *dust_rb_search(struct rb_root *root, sector_t blk)
{
struct rb_node *node = root->rb_node;
while (node) {
struct badblock *bblk = rb_entry(node, struct badblock, node);
if (bblk->bb > blk)
node = node->rb_left;
else if (bblk->bb < blk)
node = node->rb_right;
else
return bblk;
}
return NULL;
}
static bool dust_rb_insert(struct rb_root *root, struct badblock *new)
{
struct badblock *bblk;
struct rb_node **link = &root->rb_node, *parent = NULL;
sector_t value = new->bb;
while (*link) {
parent = *link;
bblk = rb_entry(parent, struct badblock, node);
if (bblk->bb > value)
link = &(*link)->rb_left;
else if (bblk->bb < value)
link = &(*link)->rb_right;
else
return false;
}
rb_link_node(&new->node, parent, link);
rb_insert_color(&new->node, root);
return true;
}
static int dust_remove_block(struct dust_device *dd, unsigned long long block)
{
struct badblock *bblock;
unsigned long flags;
spin_lock_irqsave(&dd->dust_lock, flags);
bblock = dust_rb_search(&dd->badblocklist, block);
if (bblock == NULL) {
if (!dd->quiet_mode) {
DMERR("%s: block %llu not found in badblocklist",
__func__, block);
}
spin_unlock_irqrestore(&dd->dust_lock, flags);
return -EINVAL;
}
rb_erase(&bblock->node, &dd->badblocklist);
dd->badblock_count--;
if (!dd->quiet_mode)
DMINFO("%s: badblock removed at block %llu", __func__, block);
kfree(bblock);
spin_unlock_irqrestore(&dd->dust_lock, flags);
return 0;
}
static int dust_add_block(struct dust_device *dd, unsigned long long block,
unsigned char wr_fail_cnt)
Annotation
- Immediate include surface: `linux/device-mapper.h`, `linux/module.h`, `linux/rbtree.h`.
- Detected declarations: `struct badblock`, `struct dust_device`, `function dust_rb_insert`, `function dust_remove_block`, `function dust_add_block`, `function dust_query_block`, `function __dust_map_read`, `function dust_map_read`, `function __dust_map_write`, `function dust_map_write`.
- 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.