mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* inotify 0.23 errno 28 (ENOSPC)
@ 2005-05-24 16:33 Bryan Wilkerson
  2005-05-24 16:35 ` Robert Love
  0 siblings, 1 reply; 4+ messages in thread
From: Bryan Wilkerson @ 2005-05-24 16:33 UTC (permalink / raw)
  To: rlove, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

Hi,  

I read an earlier thread where you said that it was
possible to manually walk a tree and add all
directories to an inotify watch descriptor.  I wrote
some code to do this and the ioctl call fails on my
machine after adding 9,977 directories with ENOSPC.  

I've attached a small repro case.  Just point it at
the base of a large dir tree (e.g. inotify-r ~) to
use. 

My kernel is 2.6.12-rc3 with the inotify 0.23 patch. 
Let me know if you need more information.  

Please cc my e-mail addr in all replies.

Thanks,

-bryan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 1249210018-inotify-r.c --]
[-- Type: text/x-csrc; name="inotify-r.c", Size: 2139 bytes --]


/*  this just demonstrates adding a large number of directories
    to inotify
*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <dirent.h>


#include "inotify.h"

int dirsWatched = 0;
int fd;

static void fatal_error(char *fmt, ...) __attribute__((noreturn));
static void fatal_error(char *fmt, ...) 
{
	fprintf(stderr, "\n\nFATAL ERROR:%d:%s: ", errno, strerror(errno));
	va_list ap;
	va_start(ap, fmt);
	vfprintf(stderr, fmt, ap);
	va_end(ap);
	fprintf(stderr, "\n\nDirs successfully added to watch: %d\n", dirsWatched);
	exit(errno);
}


int add_dir(const char *path)
{
	struct inotify_watch_request iwr;
	iwr.mask = 0xffffffff;
	iwr.fd = open(path, O_RDONLY);
	if( iwr.fd <= 0 )
		fatal_error("Unable to open directory %s for reading", path);
	
	int wd = ioctl(fd, INOTIFY_WATCH, &iwr);
	close(iwr.fd);
	
	if (wd < 0) 
		fatal_error("Unable to create inotify watch on object: %s", path);
	else
		dirsWatched++;

	struct dirent **namelist;
	int i, n;
	struct stat statstruct;
	
	n = scandir(path, &namelist, 0, alphasort);
	if( n < 0 )
		fatal_error("scandir failed");

	for( i = 0; i < n; i++ )
	{
		char fileName[4096];
		int len = sprintf(fileName, "%s/%s", path, namelist[i]->d_name);
		
		if( !(strcmp(&fileName[len-2], "/.")==0 || strcmp(&fileName[len-3], "/..")==0) )
		{
			// most likely cause of not being able to stat is 
			// permissions which we quietly ignore and assume 
			// to be benign
			if( stat(fileName, &statstruct) == 0 )
			{
				if( S_ISDIR(statstruct.st_mode) )
				{
					// recursive add
					add_dir(fileName);
				}
			}
		}
		free(namelist[i]);
	}
	free(namelist);
}

int main(int argc, char **argv)
{
	if( argc < 2 || strcmp(argv[1], "--help") == 0 )
	{
		printf( "inotify-r - tests adding a directory recusively to an inotify descriptor\n"
			"\n"
			"Usage: inotify-r <path>\n");
		exit(1);
	}
	fd = open("/dev/inotify", O_RDONLY);
	if (fd < 0) 
		fatal_error("Unable to open inotify device.");

	add_dir(argv[1]);
	return 0;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inotify 0.23 errno 28 (ENOSPC)
  2005-05-24 16:33 inotify 0.23 errno 28 (ENOSPC) Bryan Wilkerson
@ 2005-05-24 16:35 ` Robert Love
  2005-05-24 16:52   ` Arjan van de Ven
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Love @ 2005-05-24 16:35 UTC (permalink / raw)
  To: bryanwilkerson; +Cc: linux-kernel

On Tue, 2005-05-24 at 09:33 -0700, Bryan Wilkerson wrote:

> I read an earlier thread where you said that it was
> possible to manually walk a tree and add all
> directories to an inotify watch descriptor.  I wrote
> some code to do this and the ioctl call fails on my
> machine after adding 9,977 directories with ENOSPC.  
> 
> I've attached a small repro case.  Just point it at
> the base of a large dir tree (e.g. inotify-r ~) to
> use. 
> 
> My kernel is 2.6.12-rc3 with the inotify 0.23 patch. 
> Let me know if you need more information.  

This is intended.  There is a per-user limit on the number of watches.
By default, that limit is 8192.

You can view and edit the number via
	/sys/class/misc/inotify/max_user_watches

Best,

	Robert Love



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inotify 0.23 errno 28 (ENOSPC)
  2005-05-24 16:35 ` Robert Love
@ 2005-05-24 16:52   ` Arjan van de Ven
  2005-05-24 16:55     ` Robert Love
  0 siblings, 1 reply; 4+ messages in thread
From: Arjan van de Ven @ 2005-05-24 16:52 UTC (permalink / raw)
  To: Robert Love; +Cc: bryanwilkerson, linux-kernel

On Tue, 2005-05-24 at 12:35 -0400, Robert Love wrote:
> On Tue, 2005-05-24 at 09:33 -0700, Bryan Wilkerson wrote:
> 
> > I read an earlier thread where you said that it was
> > possible to manually walk a tree and add all
> > directories to an inotify watch descriptor.  I wrote
> > some code to do this and the ioctl call fails on my
> > machine after adding 9,977 directories with ENOSPC.  
> > 
> > I've attached a small repro case.  Just point it at
> > the base of a large dir tree (e.g. inotify-r ~) to
> > use. 
> > 
> > My kernel is 2.6.12-rc3 with the inotify 0.23 patch. 
> > Let me know if you need more information.  
> 
> This is intended.  There is a per-user limit on the number of watches.
> By default, that limit is 8192.
> 
> You can view and edit the number via
> 	/sys/class/misc/inotify/max_user_watches

why isn't this an rlimit instead ?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inotify 0.23 errno 28 (ENOSPC)
  2005-05-24 16:52   ` Arjan van de Ven
@ 2005-05-24 16:55     ` Robert Love
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Love @ 2005-05-24 16:55 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: bryanwilkerson, linux-kernel

On Tue, 2005-05-24 at 18:52 +0200, Arjan van de Ven wrote:

> why isn't this an rlimit instead ?

Definitely could be.

Since inotify is built as a driver, the sysfs entry made sense, and it
sure is easier to implement.

But I'd have no problem with an rlimit.  We don't seem to add those
frequently, though.

	Robert Love



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-24 17:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-24 16:33 inotify 0.23 errno 28 (ENOSPC) Bryan Wilkerson
2005-05-24 16:35 ` Robert Love
2005-05-24 16:52   ` Arjan van de Ven
2005-05-24 16:55     ` Robert Love

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®