This is the mail archive of the mailing list for the systemtap project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New tapset watchinf ENOSPC on fs operation


I wrote a systemtap script which watch for ENOSPC on file system
operation. So far, supported file systems are ext3, ext4, xfs and btrfs.
It has been tested with direct+buffered write, file+directory creation
and fallocate.

The script, if running, reports the ENOSPC by printing the message to
the stdout as well as sending the message to the syslog via logger. The
message looks like this:

ext4 (8, 50) - no space left on the file system (uid: 500, alloc_test:3203)

I would like to include this script into the systemtap tapsets.

This is for Red Hat bz#613992

Please comment, or let me know if there is any problem with the script
or if there is anything else I can do to get it into systemtap tapsets


Here is the script:


// Enospc notification tapset
// Copyright (C) 2012 Red Hat Inc., Lukas Czerner <>
// 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.
// <tapsetdescription>
// 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
// </tapsetdescription>

#!/usr/bin/env stap

 * Print the warning message to the stdout and send it
 * to the syslog via logger.
function warn(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);

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

/* Catch ENOSPC in ext3 file system */
probe kenrel.function("ext3_should_retry_alloc").return ? ,
      module("ext3").function("ext3_should_retry_alloc").return ?
	if (0 == $return)
		warn("ext3", $sb->s_dev);

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

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

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

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]