drivers/md/bcache/sysfs.c
Source file repositories/reference/linux-study-clean/drivers/md/bcache/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/bcache/sysfs.c- Extension
.c- Size
- 30509 bytes
- Lines
- 1184
- 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
bcache.hsysfs.hbtree.hrequest.hwriteback.hfeatures.hlinux/blkdev.hlinux/sort.hlinux/sched/clock.h
Detected Declarations
struct bset_stats_opfunction bch_snprint_string_listfunction list_for_each_entryfunction bch_btree_bset_statsfunction bch_bset_print_statsfunction bch_root_usagefunction bch_cache_sizefunction bch_cache_max_chainfunction bch_btree_usedfunction bch_average_key_sizefunction bch_cache_set_internal_releasefunction __bch_cache_cmpfunction for_each_bucket
Annotated Snippet
struct bset_stats_op {
struct btree_op op;
size_t nodes;
struct bset_stats stats;
};
static int bch_btree_bset_stats(struct btree_op *b_op, struct btree *b)
{
struct bset_stats_op *op = container_of(b_op, struct bset_stats_op, op);
op->nodes++;
bch_btree_keys_stats(&b->keys, &op->stats);
return MAP_CONTINUE;
}
static int bch_bset_print_stats(struct cache_set *c, char *buf)
{
struct bset_stats_op op;
int ret;
memset(&op, 0, sizeof(op));
bch_btree_op_init(&op.op, -1);
ret = bch_btree_map_nodes(&op.op, c, &ZERO_KEY, bch_btree_bset_stats);
if (ret < 0)
return ret;
return snprintf(buf, PAGE_SIZE,
"btree nodes: %zu\n"
"written sets: %zu\n"
"unwritten sets: %zu\n"
"written key bytes: %zu\n"
"unwritten key bytes: %zu\n"
"floats: %zu\n"
"failed: %zu\n",
op.nodes,
op.stats.sets_written, op.stats.sets_unwritten,
op.stats.bytes_written, op.stats.bytes_unwritten,
op.stats.floats, op.stats.failed);
}
static unsigned int bch_root_usage(struct cache_set *c)
{
unsigned int bytes = 0;
struct bkey *k;
struct btree *b;
struct btree_iter_stack iter;
goto lock_root;
do {
rw_unlock(false, b);
lock_root:
b = c->root;
rw_lock(false, b, b->level);
} while (b != c->root);
for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad)
bytes += bkey_bytes(k);
rw_unlock(false, b);
return (bytes * 100) / btree_bytes(c);
}
static size_t bch_cache_size(struct cache_set *c)
{
size_t ret = 0;
struct btree *b;
mutex_lock(&c->bucket_lock);
list_for_each_entry(b, &c->btree_cache, list)
ret += 1 << (b->keys.page_order + PAGE_SHIFT);
mutex_unlock(&c->bucket_lock);
return ret;
}
static unsigned int bch_cache_max_chain(struct cache_set *c)
{
unsigned int ret = 0;
struct hlist_head *h;
mutex_lock(&c->bucket_lock);
for (h = c->bucket_hash;
h < c->bucket_hash + (1 << BUCKET_HASH_BITS);
h++) {
ret = max(ret, hlist_count_nodes(h));
Annotation
- Immediate include surface: `bcache.h`, `sysfs.h`, `btree.h`, `request.h`, `writeback.h`, `features.h`, `linux/blkdev.h`, `linux/sort.h`.
- Detected declarations: `struct bset_stats_op`, `function bch_snprint_string_list`, `function list_for_each_entry`, `function bch_btree_bset_stats`, `function bch_bset_print_stats`, `function bch_root_usage`, `function bch_cache_size`, `function bch_cache_max_chain`, `function bch_btree_used`, `function bch_average_key_size`.
- 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.