File: io.d.in

package info (click to toggle)
dtrace 2.0.5-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 24,408 kB
  • sloc: ansic: 61,247; sh: 17,997; asm: 1,717; lex: 947; awk: 754; yacc: 695; perl: 37; sed: 17; makefile: 15
file content (216 lines) | stat: -rw-r--r-- 7,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * Oracle Linux DTrace.
 * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */

#pragma D depends_on module vmlinux
#pragma D depends_on provider sched

typedef char	*caddr_t;

typedef struct bufinfo {
	int b_flags;			/* buffer status */
	size_t b_bcount;		/* number of bytes */
	caddr_t b_addr;			/* buffer address */
	uint64_t b_lblkno;		/* block # on device */
	uint64_t b_blkno;		/* expanded block # on device */
	size_t b_resid;			/* # of bytes not transferred */
	size_t b_bufsize;		/* size of allocated buffer */
	caddr_t b_iodone;		/* I/O completion routine */
	int b_error;			/* expanded error field */
	dev_t b_edev;			/* extended device */
} bufinfo_t;

inline int B_BUSY = 0x000001;
#pragma D binding "1.0" B_BUSY
inline int B_DONE = 0x000002;
#pragma D binding "1.0" B_DONE
inline int B_ERROR = 0x000004;
#pragma D binding "1.0" B_ERROR
inline int B_PAGEIO = 0x000010;
#pragma D binding "1.0" B_PAGEIO
inline int B_PHYS = 0x000020;
#pragma D binding "1.0" B_PHYS
inline int B_READ = 0x000040;
#pragma D binding "1.0" B_READ
inline int B_WRITE = 0x000100;
#pragma D binding "1.0" B_WRITE
inline int B_ASYNC = 0x000400;
#pragma D binding "1.0" B_ASYNC

#pragma D binding "1.0" translator
translator bufinfo_t < struct buffer_head *B > {
	b_flags = (int)arg1 & 0x01 ? B_WRITE : B_READ;
	b_addr = B->b_data;
	b_bcount = B->b_size;
	b_lblkno = B->b_blocknr;
	b_blkno = B->b_blocknr;
	b_resid = 0;
	b_bufsize = B->b_size;
	b_iodone = (caddr_t)B->b_end_io;
	b_error = 0;			/* b_state ?? */
	b_edev = B->b_bdev->bd_dev;
};

/*
 * From linux/blk_types.h.
 */

/* bit # in bi_flags */
inline int BIO_USER_MAPPED = 6;

/* bit mask in bi_rw */
inline int REQ_WRITE = 0x01;
define_for_kernel([[REQ_SYNC_VAL]], [[(m4_kver(4,10,0), [[0x800]])]], [[0x10]])
inline int REQ_SYNC = REQ_SYNC_VAL;

define_for_kernel([[__bi_rw]], [[(m4_kver(4,8,0), [[bi_opf]])]], [[bi_rw]])
define_for_kernel([[__disk]], [[(m4_kver(5,12,0), [[bi_bdev->bd_disk]]), (m4_kver(4,14,0), [[bi_disk]])]], [[bi_bdev->bd_disk]])
define_for_kernel([[__disk_chk]], [[(m4_kver(5,12,0), [[bi_bdev]]), (m4_kver(4,14,0), [[bi_disk]])]], [[bi_bdev]])
define_for_kernel([[__bio_partno]], [[(m4_kver(6,10,0), [[bi_bdev->__bd_flags.counter & BD_PARTNO]]), (m4_kver(5,12,0), [[bi_bdev->bd_partno]]), (m4_kver(4,14,0), [[bi_partno]])]], [[bi_bdev->bd_part->partno]])
define_for_kernel([[__bio_part_dev]], [[(m4_kver(5,12,0), [[bi_bdev->bd_dev]]), (m4_kver(5,11,0), [[bi_disk->part_tbl->part[B->bi_partno]->bd_dev]]), (m4_kver(4,14,0), [[bi_disk->part_tbl->part[B->bi_partno]->__dev.devt]])]], [[bi_bdev->bd_part->__dev.devt]])

#pragma D binding "1.6.3" translator
translator bufinfo_t < struct bio *B > {
	b_flags = ((int)B->__bi_rw & REQ_WRITE ? B_WRITE : B_READ) |
		((int)B->__bi_rw & REQ_SYNC ? 0 : B_ASYNC) |
		((int)B->bi_flags & (1 << BIO_USER_MAPPED) ? B_PAGEIO : B_PHYS);
	b_addr = 0;
	b_bcount = B->bi_iter.bi_size;
	b_lblkno = B->bi_iter.bi_sector;
	b_blkno = B->bi_iter.bi_sector;
	b_resid = 0;
	b_bufsize = B->bi_iter.bi_size;
	b_iodone = (caddr_t)B->bi_end_io;
	b_error = 0;
	b_edev = B->__disk_chk == NULL ? 0 : B->__bio_part_dev;
};

typedef struct devinfo {
	int dev_major;			/* major number */
	int dev_minor;			/* minor number */
	int dev_instance;		/* instance number */
	string dev_name;		/* name of device */
	string dev_statname;		/* name of device + instance/minor */
	string dev_pathname;		/* pathname of device */
} devinfo_t;

define_for_kernel([[__bh_bdev_dev]], [[(m4_kver(5,11,0), [[b_bdev->bd_disk->part0->bd_device]])]], [[b_bdev->bd_disk->part0.__dev]])
define_for_kernel([[__bdev_partno]], [[(m4_kver(6,10,0), [[__bd_flags.counter & BD_PARTNO]]), (m4_kver(5,11,0), [[bd_partno]])]], [[bd_part->partno]])
#pragma D binding "1.0" translator
translator devinfo_t < struct buffer_head *B > {
	dev_major = getmajor(B->b_bdev->bd_dev);
	dev_minor = getminor(B->b_bdev->bd_dev);
	dev_instance = 0;		/* not used? */
	dev_name = B->__bh_bdev_dev.parent
	    ? B->__bh_bdev_dev.parent->driver->name
		? stringof(B->__bh_bdev_dev.parent->driver->name)
		: "<none>"
	    : B->__bh_bdev_dev.driver->name
		? stringof(B->__bh_bdev_dev.driver->name)
		: "<none>";
	dev_statname = (B->b_bdev->__bdev_partno) == 0
			? stringof(B->b_bdev->bd_disk->disk_name)
			: strjoin(stringof(B->b_bdev->bd_disk->disk_name),
				  lltostr(B->b_bdev->__bdev_partno));
	dev_pathname = strjoin(
			"/dev/",
			B->b_bdev->__bdev_partno == 0
			    ? stringof(B->b_bdev->bd_disk->disk_name)
			    : strjoin(stringof(B->b_bdev->bd_disk->disk_name),
				      lltostr(B->b_bdev->__bdev_partno))
		       );
};

#pragma D binding "1.6.3" translator
translator devinfo_t < struct bio *B > {
	dev_major = B->__disk_chk == NULL ? 0 : getmajor(B->__bio_part_dev);
	dev_minor = B->__disk_chk == NULL ? 0 : getminor(B->__bio_part_dev);
	dev_instance = 0;
	dev_name = B->__disk_chk == NULL
		? "nfs"
		: stringof(((struct blk_major_name **)vmlinux`major_names)[
				getmajor(B->__bio_part_dev) % 255
			   ]->name);
	dev_statname = B->__disk_chk == NULL ? "nfs" :
	    (B->__bio_partno) == 0 ? stringof(B->__disk->disk_name) :
	    strjoin(stringof(B->__disk->disk_name), lltostr(B->__bio_partno));
	dev_pathname = B->__disk_chk == NULL ? "<nfs>" : "<unknown>";
};

typedef struct fileinfo {
	string fi_name;			/* name (basename of fi_pathname) */
	string fi_dirname;		/* directory (dirname of fi_pathname) */
	string fi_pathname;		/* full pathname */
	loff_t fi_offset;		/* offset within file */
	string fi_fs;			/* filesystem */
	string fi_mount;		/* mount point of file system */
	int fi_oflags;			/* open(2) flags for file descriptor */
} fileinfo_t;

#pragma D binding "1.0" translator
translator fileinfo_t < struct buffer_head *B > {
	fi_name = "<unknown>";
	fi_dirname = "<unknown>";
	fi_pathname = "<unknown>";
	fi_offset = 0;
	fi_fs = "<unknown>";
	fi_mount = "<unknown>";
	fi_oflags = 0;
};

def_constant([[O_ACCMODE]],1.1)
def_constant([[O_RDONLY]],1.1)
def_constant([[O_WRONLY]],1.1)
def_constant([[O_RDWR]],1.1)
def_constant([[O_CREAT]],1.1)
def_constant([[O_EXCL]],1.1)
def_constant([[O_NOCTTY]],1.1)
def_constant([[O_TRUNC]],1.1)
def_constant([[O_APPEND]],1.1)
def_constant([[O_NONBLOCK]],1.1)
def_constant([[O_NDELAY]],1.1)
def_constant([[O_SYNC]],1.1)
def_constant([[O_FSYNC]],1.1)
def_constant([[O_ASYNC]],1.1)
def_constant([[O_DIRECTORY]],1.1)
def_constant([[O_NOFOLLOW]],1.1)
def_constant([[O_CLOEXEC]],1.1)
def_constant([[O_DSYNC]],1.1)
def_constant([[O_RSYNC]],1.1)

#pragma D binding "1.1" translator
translator fileinfo_t < struct file *F > {
	fi_name = F == NULL
			? "<none>"
			: stringof(F->f_path.dentry->d_name.name);
	fi_dirname = F == NULL
			? "<none>"
			: dirname(d_path(&(F->f_path)));
	fi_pathname = F == NULL
			? "<none>"
			: d_path(&(F->f_path));
	fi_offset = F == NULL
			? 0
			: F->f_pos;
	fi_fs = F == NULL
			? "<none>"
			: stringof(F->f_path.mnt->mnt_sb->s_type->name);
	fi_mount = F == NULL
			? "<none>"
			: "<unknown>";
	fi_oflags = F == NULL
			? 0
			: F->f_flags;
};

inline fileinfo_t fds[int fd] = xlate <fileinfo_t> (
				 fd >= 0 && fd < curthread->files->fdt->max_fds
					? curthread->files->fdt->fd[fd]
					: NULL
				);

#pragma D attributes Stable/Stable/Common fds
#pragma D binding "1.1" fds