| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
// Enospc notification script |
| 4 |
// Copyright (C) 2012 Red Hat Inc., Lukas Czerner <[email protected]> |
| 5 |
// |
| 6 |
// This file is part of systemtap, and is free software. You can |
| 7 |
// redistribute it and/or modify it under the terms of the GNU General |
| 8 |
// Public License (GPL); either version 2, or (at your option) any |
| 9 |
// later version. |
| 10 |
|
| 11 |
// This tapset is used to watch for ENOSPC on file system operation, print |
| 12 |
// notification and send message to the syslog using logger. Supported file |
| 13 |
// systems so far are ext3, ext4, xfs and btrfs |
| 14 |
|
| 15 |
|
| 16 |
/* |
| 17 |
* Print the warning message to the stdout and send it |
| 18 |
* to the syslog via logger. |
| 19 |
*/ |
| 20 |
function warnlog(fsname:string, dev:long) { |
| 21 |
message = sprintf("%s (%d, %d) - no space left on the file system (uid: %d, %s:%d)\n", |
| 22 |
fsname, MAJOR(dev), MINOR(dev), uid(), execname(), pid()); |
| 23 |
/* Print the message to the output */ |
| 24 |
printf("[%s]: %s", ctime(gettimeofday_s()), message); |
| 25 |
/* Log the message with logger */ |
| 26 |
command = sprintf("/usr/bin/logger '%s'", message); |
| 27 |
system(command); |
| 28 |
} |
| 29 |
|
| 30 |
/* Catch ENOSPC in ext4 file system */ |
| 31 |
probe {kernel,module("ext4")}.function("ext4_should_retry_alloc").return ? |
| 32 |
{ |
| 33 |
if (0 == $return) |
| 34 |
warnlog("ext4", @entry($sb->s_dev)); |
| 35 |
} |
| 36 |
|
| 37 |
/* Catch ENOSPC in ext3 file system */ |
| 38 |
probe {kernel,module("ext3")}.function("ext3_should_retry_alloc").return ? |
| 39 |
{ |
| 40 |
if (0 == $return) |
| 41 |
warnlog("ext3", @entry($sb->s_dev)); |
| 42 |
} |
| 43 |
|
| 44 |
/* Catch ENOSPC in xfs file system on write */ |
| 45 |
probe {kernel,module("xfs")}.function("xfs_file_aio_write").return ? |
| 46 |
{ |
| 47 |
if (-28 == $return) |
| 48 |
warnlog("xfs", @entry($iocb->ki_filp->f_mapping->host->i_sb->s_dev)); |
| 49 |
} |
| 50 |
|
| 51 |
/* Catch ENOSPC in xfs file system on inode creation */ |
| 52 |
probe {kernel,module("xfs")}.function("xfs_vn_mknod").return ? |
| 53 |
{ |
| 54 |
if (-28 == $return) |
| 55 |
warnlog("xfs", @entry($dir->i_sb->s_dev)); |
| 56 |
} |
| 57 |
|
| 58 |
/* Catch ENOSPC in xfs file system on fallocate */ |
| 59 |
probe {kernel,module("xfs")}.function("xfs_vn_fallocate").return ? |
| 60 |
{ |
| 61 |
if (-28 == $return) |
| 62 |
warnlog("xfs", @entry($inode->i_sb->s_dev)); |
| 63 |
} |
| 64 |
|
| 65 |
/* Catch ENOSPC in btrfs file system */ |
| 66 |
probe {kernel,module("btrfs")}.function("btrfs_check_data_free_space").return ? |
| 67 |
{ |
| 68 |
if (-28 == $return) |
| 69 |
warnlog("btrfs", (@defined(@entry($inode->root))? |
| 70 |
@entry($inode->root->fs_info->sb->s_dev): |
| 71 |
@entry($inode->i_sb->s_dev))); |
| 72 |
} |