kernel/trace/blktrace.c
Source file repositories/reference/linux-study-clean/kernel/trace/blktrace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/blktrace.c- Extension
.c- Size
- 55868 bytes
- Lines
- 2225
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kernel.hlinux/blkdev.hlinux/blktrace_api.hlinux/percpu.hlinux/init.hlinux/mutex.hlinux/slab.hlinux/debugfs.hlinux/export.hlinux/time.hlinux/uaccess.hlinux/list.hlinux/blk-cgroup.h../../block/blk.htrace/events/block.htrace_output.h
Detected Declarations
function record_blktrace_eventfunction record_blktrace_event2function relay_blktrace_event1function relay_blktrace_event2function relay_blktrace_eventfunction trace_notefunction trace_note_tskfunction trace_note_timefunction __blk_trace_note_messagefunction act_log_checkfunction __blk_add_tracefunction blk_trace_freefunction get_probe_reffunction put_probe_reffunction blk_trace_startfunction blk_trace_stopfunction blk_trace_cleanupfunction __blk_trace_removefunction blk_trace_removefunction blk_dropped_readfunction blk_msg_writefunction blk_remove_buf_file_callbackfunction blk_trace_setup_lbafunction lockdep_is_heldfunction blk_trace_setup_finalizefunction blk_trace_setupfunction blk_trace_setup2function compat_blk_trace_setupfunction __blk_trace_startstopfunction blk_trace_startstopfunction blk_trace_ioctlfunction blk_trace_shutdownfunction blk_trace_bio_get_cgidfunction blk_trace_bio_get_cgidfunction blk_trace_request_get_cgidfunction blk_add_trace_rqfunction blk_add_trace_rq_insertfunction blk_add_trace_rq_issuefunction blk_add_trace_rq_mergefunction blk_add_trace_rq_requeuefunction blk_add_trace_rq_completefunction blk_add_trace_zone_update_requestfunction blk_add_trace_biofunction blk_add_trace_bio_completefunction blk_add_trace_bio_backmergefunction blk_add_trace_bio_frontmergefunction blk_add_trace_bio_queuefunction blk_add_trace_getrq
Annotated Snippet
static const struct file_operations blk_dropped_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = blk_dropped_read,
.llseek = default_llseek,
};
static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *ppos)
{
char *msg;
struct blk_trace *bt;
if (count >= BLK_TN_MAX_MSG)
return -EINVAL;
msg = memdup_user_nul(buffer, count);
if (IS_ERR(msg))
return PTR_ERR(msg);
bt = filp->private_data;
__blk_trace_note_message(bt, NULL, "%s", msg);
kfree(msg);
return count;
}
static const struct file_operations blk_msg_fops = {
.owner = THIS_MODULE,
.open = simple_open,
.write = blk_msg_write,
.llseek = noop_llseek,
};
static int blk_remove_buf_file_callback(struct dentry *dentry)
{
debugfs_remove(dentry);
return 0;
}
static struct dentry *blk_create_buf_file_callback(const char *filename,
struct dentry *parent,
umode_t mode,
struct rchan_buf *buf,
int *is_global)
{
return debugfs_create_file(filename, mode, parent, buf,
&relay_file_operations);
}
static const struct rchan_callbacks blk_relay_callbacks = {
.create_buf_file = blk_create_buf_file_callback,
.remove_buf_file = blk_remove_buf_file_callback,
};
static void blk_trace_setup_lba(struct blk_trace *bt,
struct block_device *bdev)
{
if (bdev) {
bt->start_lba = bdev->bd_start_sect;
bt->end_lba = bdev->bd_start_sect + bdev_nr_sectors(bdev);
} else {
bt->start_lba = 0;
bt->end_lba = -1ULL;
}
}
/*
* Setup everything required to start tracing
*/
static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
char *name, dev_t dev,
u32 buf_size, u32 buf_nr,
struct block_device *bdev)
{
struct blk_trace *bt = NULL;
struct dentry *dir = NULL;
int ret;
lockdep_assert_held(&q->debugfs_mutex);
/*
* bdev can be NULL, as with scsi-generic, this is a helpful as
* we can be.
*/
if (rcu_dereference_protected(q->blk_trace,
lockdep_is_held(&q->debugfs_mutex))) {
pr_warn("Concurrent blktraces are not allowed on %s\n", name);
return ERR_PTR(-EBUSY);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/blkdev.h`, `linux/blktrace_api.h`, `linux/percpu.h`, `linux/init.h`, `linux/mutex.h`, `linux/slab.h`, `linux/debugfs.h`.
- Detected declarations: `function record_blktrace_event`, `function record_blktrace_event2`, `function relay_blktrace_event1`, `function relay_blktrace_event2`, `function relay_blktrace_event`, `function trace_note`, `function trace_note_tsk`, `function trace_note_time`, `function __blk_trace_note_message`, `function act_log_check`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.