Skip to content

Commit b700963

Browse files
Merge pull request iovisor#1615 from palmtenor/lua_biosnoop
Port fixes of biosnoop from Python to Lua
2 parents bfec33a + 1469877 commit b700963

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tools/biosnoop.lua

100644100755
+15-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,21 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
9494
req->rq_disk->disk_name);
9595
}
9696
97-
if (req->cmd_flags & REQ_WRITE) {
98-
data.rwflag=1;
99-
} else {
100-
data.rwflag=0;
101-
}
97+
/*
98+
* The following deals with a kernel version change (in mainline 4.7, although
99+
* it may be backported to earlier kernels) with how block request write flags
100+
* are tested. We handle both pre- and post-change versions here. Please avoid
101+
* kernel version tests like this as much as possible: they inflate the code,
102+
* test, and maintenance burden.
103+
*/
104+
#ifdef REQ_WRITE
105+
data.rwflag = !!(req->cmd_flags & REQ_WRITE);
106+
#elif defined(REQ_OP_SHIFT)
107+
data.rwflag = !!((req->cmd_flags >> REQ_OP_SHIFT) == REQ_OP_WRITE);
108+
#else
109+
data.rwflag = !!((req->cmd_flags & REQ_OP_MASK) == REQ_OP_WRITE);
110+
#endif
111+
102112
events.perf_submit(ctx,&data,sizeof(data));
103113
start.delete(&req);
104114
infobyreq.delete(&req);

0 commit comments

Comments
 (0)