lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-id: <1423666208-10681-1-git-send-email-k.kozlowski@samsung.com>
Date:	Wed, 11 Feb 2015 15:50:07 +0100
From:	Krzysztof Kozlowski <k.kozlowski@...sung.com>
To:	Hugh Dickins <hughd@...gle.com>, linux-mm@...ck.org,
	linux-kernel@...r.kernel.org,
	Alexander Viro <viro@...iv.linux.org.uk>,
	linux-fsdevel@...r.kernel.org
Cc:	Kyungmin Park <kyungmin.park@...sung.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>,
	Marek Szyprowski <m.szyprowski@...sung.com>,
	Krzysztof Kozlowski <k.kozlowski@...sung.com>
Subject: [RFC] shmem: Add eventfd notification on utlilization level

Hi,


We have a need of getting notifications from kernel to user-space
when tmpfs runs out of free space. I used here a term 'utilization'
in the meaning of percent of free space.

The idea I got is to use eventfd. Proof of concept attached:
1. Patch for kernel.
2. Sample C program (at the end of cover letter).

Usage:
$ mount -t tmpfs -o warn_used=1k,nr_blocks=2k none /path
$ ( sleep 5 && dd if=/dev/zero of=/path/file bs=1M count=4 ) &
$ ./eventfd-wait /sys/fs/tmpfs/tmpfs-6/warn_used_blocks_efd


What do you think about this? Maybe there are simpler ways
of achieving this?

Best regards,
Krzysztof


------------[ cut here ]------------
#include <sys/eventfd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>				 /* Definition of uint64_t */

#define handle_error(msg) \
	do { perror(msg); exit(EXIT_FAILURE); } while (0)

int
main(int argc, char *argv[])
{
	int efd;
	uint64_t u;
	ssize_t s;
	int fd;
	char buf[10];

	if (argc != 2) {
		printf("Usage: %s PATH\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	efd = eventfd(0, 0);
	if (efd == -1)
		 handle_error("eventfd");

	fd = open(argv[1], O_WRONLY);
	if (fd < 0)
		handle_error("sysfs open");

	snprintf(buf, sizeof(buf), "%d", efd);

	s = write(fd, buf, strlen(buf));
	if (s < 0)
		handle_error("sysfs write");

	close(fd);
	
	printf("Waiting for usage notification:\n");
	s = read(efd, &u, sizeof(uint64_t));
	if (s != sizeof(uint64_t))
		 handle_error("read");
	printf("Usage threshold reached: %llu\n",
			  (unsigned long long) u, (unsigned long long) u);
	exit(EXIT_SUCCESS);
}
------------[ cut here ]------------


Krzysztof Kozlowski (1):
  shmem: Add eventfd notification on utlilization level

 include/linux/shmem_fs.h |   4 ++
 mm/shmem.c               | 138 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 140 insertions(+), 2 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ