| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# note use of guru mode, to enable changing of syscall parameters |
| 4 |
//bin/true && exec stap -g $0 ${1+"$@"} |
| 5 |
|
| 6 |
# see also http://www.flamingspork.com/projects/libeatmydata/ |
| 7 |
|
| 8 |
global dummy_fd = -1 # invalid filehandle; to try stdout, run with -G dummy_fd=1 |
| 9 |
global guilt, agony, piety |
| 10 |
|
| 11 |
// Probing do_fsync() the common function called by syscall.{fsync,fdatasync}. |
| 12 |
probe kernel.function("do_fsync") { |
| 13 |
# We can't actually disable the syscall from here, but can try to |
| 14 |
# weaken it by redirecting the work toward a dummy file descriptor |
| 15 |
if (pid() == target()) |
| 16 |
try { |
| 17 |
$fd = dummy_fd |
| 18 |
guilt ++ |
| 19 |
} catch { |
| 20 |
agony ++ |
| 21 |
} |
| 22 |
else |
| 23 |
piety ++ |
| 24 |
} |
| 25 |
|
| 26 |
probe kernel.function("do_fsync").return { |
| 27 |
# override result code, just in case kernel sent back -EINVAL or somesuch |
| 28 |
if (pid() == target()) |
| 29 |
try { $return = 0 } catch { } |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
probe begin { |
| 34 |
printf("Redirecting f*sync by pid %d to fd %d\n", |
| 35 |
target(), dummy_fd) |
| 36 |
} |
| 37 |
probe error,end { |
| 38 |
printf("Redirected f*sync by pid %d to fd %d, success %d times, failed %d times.\n", |
| 39 |
target(), dummy_fd, guilt, agony) |
| 40 |
printf("Preserved f*sync by other processes %d times.\n", piety) |
| 41 |
} |