File: enospc.stp

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (71 lines) | stat: -rwxr-xr-x 2,234 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env stap

// Enospc notification script
// Copyright (C) 2012 Red Hat Inc., Lukas Czerner <lczerner@redhat.com>
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

// This tapset is used to watch for ENOSPC on file system operation, print
// notification and send message to the syslog using logger. Supported file
// systems so far are ext3, ext4, xfs and btrfs


/*
 * Print the warning message to the stdout and send it
 * to the syslog via logger.
 */
function warnlog(fsname:string, dev:long) {
	message = sprintf("%s (%d, %d) - no space left on the file system (uid: %d, %s:%d)\n",
			   fsname, MAJOR(dev), MINOR(dev), uid(), execname(), pid());
	/* Print the message to the output */
	printf("[%s]: %s", ctime(gettimeofday_s()), message);
	/* Log the message with logger */
	command = sprintf("/usr/bin/logger '%s'", message);
	system(command);
}

/* Catch ENOSPC in ext4 file system */
probe {kernel,module("ext4")}.function("ext4_should_retry_alloc").return ?
{
	if (0 == $return)
          warnlog("ext4", @entry($sb->s_dev));
}

/* Catch ENOSPC in ext3 file system */
probe {kernel,module("ext3")}.function("ext3_should_retry_alloc").return ?
{
	if (0 == $return)
          warnlog("ext3", @entry($sb->s_dev));
}

/* Catch ENOSPC in xfs file system on write */
probe {kernel,module("xfs")}.function("xfs_file_aio_write").return ?
{
	if (-28 == $return)
          warnlog("xfs", @entry($iocb->ki_filp->f_mapping->host->i_sb->s_dev));
}

/* Catch ENOSPC in xfs file system on inode creation */
probe {kernel,module("xfs")}.function("xfs_vn_mknod").return ?
{
	if (-28 == $return)
          warnlog("xfs", @entry($dir->i_sb->s_dev));
}

/* Catch ENOSPC in xfs file system on fallocate */
probe {kernel,module("xfs")}.function("xfs_vn_fallocate").return ?
{
	if (-28 == $return)
          warnlog("xfs", @entry($inode->i_sb->s_dev));
}

/* Catch ENOSPC in btrfs file system */
probe {kernel,module("btrfs")}.function("btrfs_check_data_free_space").return ?
{
	if (-28 == $return)
          warnlog("btrfs", @entry($inode->i_sb->s_dev));
}