fs/ceph/metric.c
Source file repositories/reference/linux-study-clean/fs/ceph/metric.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ceph/metric.c- Extension
.c- Size
- 15692 bytes
- Lines
- 534
- 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/types.hlinux/percpu_counter.hlinux/math64.hlinux/ratelimit.hlinux/ceph/decode.hmetric.hmds_client.h
Detected Declarations
function ceph_subvolume_entry_payload_lenfunction ceph_subvolume_entry_encoded_lenfunction ceph_subvolume_outer_payload_lenfunction ceph_subvolume_metric_data_lenfunction ceph_subvolume_clamp_u32function ceph_init_subvolume_wire_entryfunction ceph_encode_subvolume_metricsfunction ktime_to_ceph_timespecfunction ceph_mdsc_send_metricsfunction metric_get_sessionfunction metric_delayed_workfunction ceph_metric_initfunction ceph_metric_destroyfunction __update_mean_and_stdevfunction ceph_update_metrics
Annotated Snippet
test_bit(CEPHFS_FEATURE_SUBVOLUME_METRICS, &s->s_features)) {
int ret;
ret = ceph_subvolume_metrics_snapshot(&mdsc->subvol_metrics,
&subvols, &nr_subvols,
true);
if (ret) {
pr_warn_client(cl, "failed to snapshot subvolume metrics: %d\n",
ret);
/*
* On error, ceph_subvolume_metrics_snapshot() guarantees
* *out = NULL and *nr = 0 at function entry, so subvols
* is already NULL here - no cleanup needed.
*/
nr_subvols = 0;
subvols = NULL;
}
}
if (nr_subvols) {
/* type (le32) + ENCODE_START payload - no metric header */
subvol_len = sizeof(__le32) +
ceph_subvolume_metric_data_len(nr_subvols);
}
len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
+ sizeof(*meta) + sizeof(*dlease) + sizeof(*files)
+ sizeof(*icaps) + sizeof(*inodes) + sizeof(*rsize)
+ sizeof(*wsize) + subvol_len;
msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true);
if (!msg) {
pr_err_client(cl, "to mds%d, failed to allocate message\n",
s->s_mds);
kfree(subvols);
return false;
}
head = msg->front.iov_base;
/* encode the cap metric */
cap = (struct ceph_metric_cap *)(head + 1);
cap->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_CAP_INFO);
cap->header.ver = 1;
cap->header.compat = 1;
cap->header.data_len = cpu_to_le32(sizeof(*cap) - header_len);
cap->hit = cpu_to_le64(percpu_counter_sum(&m->i_caps_hit));
cap->mis = cpu_to_le64(percpu_counter_sum(&m->i_caps_mis));
cap->total = cpu_to_le64(nr_caps);
items++;
/* encode the read latency metric */
read = (struct ceph_metric_read_latency *)(cap + 1);
read->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_READ_LATENCY);
read->header.ver = 2;
read->header.compat = 1;
read->header.data_len = cpu_to_le32(sizeof(*read) - header_len);
sum = m->metric[METRIC_READ].latency_sum;
ktime_to_ceph_timespec(&read->lat, sum);
ktime_to_ceph_timespec(&read->avg, m->metric[METRIC_READ].latency_avg);
read->sq_sum = cpu_to_le64(m->metric[METRIC_READ].latency_sq_sum);
read->count = cpu_to_le64(m->metric[METRIC_READ].total);
items++;
/* encode the write latency metric */
write = (struct ceph_metric_write_latency *)(read + 1);
write->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_WRITE_LATENCY);
write->header.ver = 2;
write->header.compat = 1;
write->header.data_len = cpu_to_le32(sizeof(*write) - header_len);
sum = m->metric[METRIC_WRITE].latency_sum;
ktime_to_ceph_timespec(&write->lat, sum);
ktime_to_ceph_timespec(&write->avg, m->metric[METRIC_WRITE].latency_avg);
write->sq_sum = cpu_to_le64(m->metric[METRIC_WRITE].latency_sq_sum);
write->count = cpu_to_le64(m->metric[METRIC_WRITE].total);
items++;
/* encode the metadata latency metric */
meta = (struct ceph_metric_metadata_latency *)(write + 1);
meta->header.type = cpu_to_le32(CLIENT_METRIC_TYPE_METADATA_LATENCY);
meta->header.ver = 2;
meta->header.compat = 1;
meta->header.data_len = cpu_to_le32(sizeof(*meta) - header_len);
sum = m->metric[METRIC_METADATA].latency_sum;
ktime_to_ceph_timespec(&meta->lat, sum);
ktime_to_ceph_timespec(&meta->avg, m->metric[METRIC_METADATA].latency_avg);
meta->sq_sum = cpu_to_le64(m->metric[METRIC_METADATA].latency_sq_sum);
meta->count = cpu_to_le64(m->metric[METRIC_METADATA].total);
items++;
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/types.h`, `linux/percpu_counter.h`, `linux/math64.h`, `linux/ratelimit.h`, `linux/ceph/decode.h`, `metric.h`, `mds_client.h`.
- Detected declarations: `function ceph_subvolume_entry_payload_len`, `function ceph_subvolume_entry_encoded_len`, `function ceph_subvolume_outer_payload_len`, `function ceph_subvolume_metric_data_len`, `function ceph_subvolume_clamp_u32`, `function ceph_init_subvolume_wire_entry`, `function ceph_encode_subvolume_metrics`, `function ktime_to_ceph_timespec`, `function ceph_mdsc_send_metrics`, `function metric_get_session`.
- 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.