fs/ceph/subvolume_metrics.c
Source file repositories/reference/linux-study-clean/fs/ceph/subvolume_metrics.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ceph/subvolume_metrics.c- Extension
.c- Size
- 11396 bytes
- Lines
- 417
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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
linux/ceph/ceph_debug.hlinux/math64.hlinux/slab.hlinux/seq_file.hsubvolume_metrics.hmds_client.hsuper.h
Detected Declarations
struct ceph_subvol_metric_rb_entryfunction ceph_subvolume_metrics_initfunction __lookup_entryfunction __insert_entryfunction ceph_subvolume_metrics_clear_lockedfunction ceph_subvolume_metrics_destroyfunction ceph_subvolume_metrics_enablefunction ceph_subvolume_metrics_recordfunction ceph_subvolume_metrics_snapshotfunction ceph_subvolume_metrics_free_snapshotfunction ceph_subvolume_metrics_dumpfunction ceph_subvolume_metrics_record_iofunction ceph_subvolume_metrics_cache_initfunction ceph_subvolume_metrics_cache_destroy
Annotated Snippet
struct ceph_subvol_metric_rb_entry {
struct rb_node node;
u64 subvolume_id;
u64 read_ops;
u64 write_ops;
u64 read_bytes;
u64 write_bytes;
u64 read_latency_us;
u64 write_latency_us;
};
static struct kmem_cache *ceph_subvol_metric_entry_cachep;
void ceph_subvolume_metrics_init(struct ceph_subvolume_metrics_tracker *tracker)
{
spin_lock_init(&tracker->lock);
tracker->tree = RB_ROOT_CACHED;
tracker->nr_entries = 0;
tracker->enabled = false;
atomic64_set(&tracker->snapshot_attempts, 0);
atomic64_set(&tracker->snapshot_empty, 0);
atomic64_set(&tracker->snapshot_failures, 0);
atomic64_set(&tracker->record_calls, 0);
atomic64_set(&tracker->record_disabled, 0);
atomic64_set(&tracker->record_no_subvol, 0);
atomic64_set(&tracker->total_read_ops, 0);
atomic64_set(&tracker->total_read_bytes, 0);
atomic64_set(&tracker->total_write_ops, 0);
atomic64_set(&tracker->total_write_bytes, 0);
}
static struct ceph_subvol_metric_rb_entry *
__lookup_entry(struct ceph_subvolume_metrics_tracker *tracker, u64 subvol_id)
{
struct rb_node *node;
node = tracker->tree.rb_root.rb_node;
while (node) {
struct ceph_subvol_metric_rb_entry *entry =
rb_entry(node, struct ceph_subvol_metric_rb_entry, node);
if (subvol_id < entry->subvolume_id)
node = node->rb_left;
else if (subvol_id > entry->subvolume_id)
node = node->rb_right;
else
return entry;
}
return NULL;
}
static struct ceph_subvol_metric_rb_entry *
__insert_entry(struct ceph_subvolume_metrics_tracker *tracker,
struct ceph_subvol_metric_rb_entry *entry)
{
struct rb_node **link = &tracker->tree.rb_root.rb_node;
struct rb_node *parent = NULL;
bool leftmost = true;
while (*link) {
struct ceph_subvol_metric_rb_entry *cur =
rb_entry(*link, struct ceph_subvol_metric_rb_entry, node);
parent = *link;
if (entry->subvolume_id < cur->subvolume_id)
link = &(*link)->rb_left;
else if (entry->subvolume_id > cur->subvolume_id) {
link = &(*link)->rb_right;
leftmost = false;
} else
return cur;
}
rb_link_node(&entry->node, parent, link);
rb_insert_color_cached(&entry->node, &tracker->tree, leftmost);
tracker->nr_entries++;
return entry;
}
static void ceph_subvolume_metrics_clear_locked(
struct ceph_subvolume_metrics_tracker *tracker)
{
struct rb_node *node = rb_first_cached(&tracker->tree);
while (node) {
struct ceph_subvol_metric_rb_entry *entry =
rb_entry(node, struct ceph_subvol_metric_rb_entry, node);
struct rb_node *next = rb_next(node);
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/math64.h`, `linux/slab.h`, `linux/seq_file.h`, `subvolume_metrics.h`, `mds_client.h`, `super.h`.
- Detected declarations: `struct ceph_subvol_metric_rb_entry`, `function ceph_subvolume_metrics_init`, `function __lookup_entry`, `function __insert_entry`, `function ceph_subvolume_metrics_clear_locked`, `function ceph_subvolume_metrics_destroy`, `function ceph_subvolume_metrics_enable`, `function ceph_subvolume_metrics_record`, `function ceph_subvolume_metrics_snapshot`, `function ceph_subvolume_metrics_free_snapshot`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.