Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4821
b: refs/heads/master
c: 46906c4
h: refs/heads/master
i:
  4819: 0392819
v: v3
  • Loading branch information
Ian Wienand authored and Tony Luck committed Jul 14, 2005
1 parent d107269 commit 233dc97
Show file tree
Hide file tree
Showing 37 changed files with 383 additions and 451 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 38d84c3bd6dd22bdb1f797c87006931133d71aea
refs/heads/master: 46906c4415f88cebfad530917bada0835d651824
77 changes: 32 additions & 45 deletions trunk/Documentation/filesystems/inotify.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
inotify
a powerful yet simple file change notification system
inotify
a powerful yet simple file change notification system



Document started 15 Mar 2005 by Robert Love <rml@novell.com>


(i) User Interface

Inotify is controlled by a set of three system calls and normal file I/O on a
returned file descriptor.
Inotify is controlled by a set of three sys calls

First step in using inotify is to initialise an inotify instance:
First step in using inotify is to initialise an inotify instance

int fd = inotify_init ();

Each instance is associated with a unique, ordered queue.

Change events are managed by "watches". A watch is an (object,mask) pair where
the object is a file or directory and the mask is a bit mask of one or more
inotify events that the application wishes to receive. See <linux/inotify.h>
Expand All @@ -26,60 +22,51 @@ Watches are added via a path to the file.

Watches on a directory will return events on any files inside of the directory.

Adding a watch is simple:
Adding a watch is simple,

int wd = inotify_add_watch (fd, path, mask);

Where "fd" is the return value from inotify_init(), path is the path to the
object to watch, and mask is the watch mask (see <linux/inotify.h>).
You can add a large number of files via something like

for each file to watch {
int wd = inotify_add_watch (fd, file, mask);
}

You can update an existing watch in the same manner, by passing in a new mask.

An existing watch is removed via
An existing watch is removed via the INOTIFY_IGNORE ioctl, for example

int ret = inotify_rm_watch (fd, wd);
inotify_rm_watch (fd, wd);

Events are provided in the form of an inotify_event structure that is read(2)
from a given inotify instance. The filename is of dynamic length and follows
the struct. It is of size len. The filename is padded with null bytes to
ensure proper alignment. This padding is reflected in len.
from a inotify instance fd. The filename is of dynamic length and follows the
struct. It is of size len. The filename is padded with null bytes to ensure
proper alignment. This padding is reflected in len.

You can slurp multiple events by passing a large buffer, for example

size_t len = read (fd, buf, BUF_LEN);

Where "buf" is a pointer to an array of "inotify_event" structures at least
BUF_LEN bytes in size. The above example will return as many events as are
available and fit in BUF_LEN.
Will return as many events as are available and fit in BUF_LEN.

Each inotify instance fd is also select()- and poll()-able.
each inotify instance fd is also select()- and poll()-able.

You can find the size of the current event queue via the standard FIONREAD
ioctl on the fd returned by inotify_init().
You can find the size of the current event queue via the FIONREAD ioctl.

All watches are destroyed and cleaned up on close.


(ii)

Prototypes:

int inotify_init (void);
int inotify_add_watch (int fd, const char *path, __u32 mask);
int inotify_rm_watch (int fd, __u32 mask);

(ii) Internal Kernel Implementation

(iii) Internal Kernel Implementation

Each inotify instance is associated with an inotify_device structure.
Each open inotify instance is associated with an inotify_device structure.

Each watch is associated with an inotify_watch structure. Watches are chained
off of each associated device and each associated inode.

See fs/inotify.c for the locking and lifetime rules.


(iv) Rationale
(iii) Rationale

Q: What is the design decision behind not tying the watch to the open fd of
the watched object?
Expand All @@ -88,9 +75,9 @@ A: Watches are associated with an open inotify device, not an open file.
This solves the primary problem with dnotify: keeping the file open pins
the file and thus, worse, pins the mount. Dnotify is therefore infeasible
for use on a desktop system with removable media as the media cannot be
unmounted. Watching a file should not require that it be open.
unmounted.

Q: What is the design decision behind using an-fd-per-instance as opposed to
Q: What is the design decision behind using an-fd-per-device as opposed to
an fd-per-watch?

A: An fd-per-watch quickly consumes more file descriptors than are allowed,
Expand All @@ -99,8 +86,8 @@ A: An fd-per-watch quickly consumes more file descriptors than are allowed,
can use epoll, but requiring both is a silly and extraneous requirement.
A watch consumes less memory than an open file, separating the number
spaces is thus sensible. The current design is what user-space developers
want: Users initialize inotify, once, and add n watches, requiring but one
fd and no twiddling with fd limits. Initializing an inotify instance two
want: Users initialize inotify, once, and add n watches, requiring but one fd
and no twiddling with fd limits. Initializing an inotify instance two
thousand times is silly. If we can implement user-space's preferences
cleanly--and we can, the idr layer makes stuff like this trivial--then we
should.
Expand All @@ -124,6 +111,9 @@ A: An fd-per-watch quickly consumes more file descriptors than are allowed,
example, love it. Trust me, I asked. It is not a surprise: Who'd want
to manage and block on 1000 fd's via select?

- You'd have to manage the fd's, as an example: Call close() when you
received a delete event.

- No way to get out of band data.

- 1024 is still too low. ;-)
Expand All @@ -132,11 +122,6 @@ A: An fd-per-watch quickly consumes more file descriptors than are allowed,
scales to 1000s of directories, juggling 1000s of fd's just does not seem
the right interface. It is too heavy.

Additionally, it _is_ possible to more than one instance and
juggle more than one queue and thus more than one associated fd. There
need not be a one-fd-per-process mapping; it is one-fd-per-queue and a
process can easily want more than one queue.

Q: Why the system call approach?

A: The poor user-space interface is the second biggest problem with dnotify.
Expand All @@ -146,6 +131,8 @@ A: The poor user-space interface is the second biggest problem with dnotify.
Obtaining the fd and managing the watches could have been done either via a
device file or a family of new system calls. We decided to implement a
family of system calls because that is the preffered approach for new kernel
interfaces. The only real difference was whether we wanted to use open(2)
and ioctl(2) or a couple of new system calls. System calls beat ioctls.
features and it means our user interface requirements.

Additionally, it _is_ possible to more than one instance and
juggle more than one queue and thus more than one associated fd.

12 changes: 0 additions & 12 deletions trunk/MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,6 @@ L: linux-input@atrey.karlin.mff.cuni.cz
L: linux-joystick@atrey.karlin.mff.cuni.cz
S: Maintained

INOTIFY
P: John McCutchan and Robert Love
M: ttb@tentacle.dhs.org and rml@novell.com
L: linux-kernel@vger.kernel.org
S: Maintained

INTEL 810/815 FRAMEBUFFER DRIVER
P: Antonino Daplas
M: adaplas@pol.net
Expand Down Expand Up @@ -2426,12 +2420,6 @@ L: linux-usb-users@lists.sourceforge.net
L: linux-usb-devel@lists.sourceforge.net
S: Maintained

USB OPTION-CARD DRIVER
P: Matthias Urlichs
M: smurf@smurf.noris.de
L: linux-usb-devel@lists.sourceforge.net
S: Maintained

USB OV511 DRIVER
P: Mark McClelland
M: mmcclell@bigfoot.com
Expand Down
1 change: 0 additions & 1 deletion trunk/arch/i386/mach-visws/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "piix4.h"

void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);

void machine_restart(char * __unused)
{
Expand Down
2 changes: 2 additions & 0 deletions trunk/arch/ia64/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ int arch_register_cpu(int num)
parent = &sysfs_nodes[cpu_to_node(num)];
#endif /* CONFIG_NUMA */

#ifdef CONFIG_ACPI_BOOT
/*
* If CPEI cannot be re-targetted, and this is
* CPEI target, then dont create the control file
*/
if (!can_cpei_retarget() && is_cpu_cpei_target(num))
sysfs_cpus[num].cpu.no_control = 1;
#endif

return register_cpu(&sysfs_cpus[num].cpu, num, parent);
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/um/Kconfig_net
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ config UML_NET_MCAST

config UML_NET_PCAP
bool "pcap transport"
depends on UML_NET && EXPERIMENTAL
depends on UML_NET && BROKEN
help
The pcap transport makes a pcap packet stream on the host look
like an ethernet device inside UML. This is useful for making
Expand Down
30 changes: 14 additions & 16 deletions trunk/arch/um/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,25 @@ MRPROPER_DIRS += $(ARCH_DIR)/include2
endif
SYS_DIR := $(ARCH_DIR)/include/sysdep-$(SUBARCH)

# -Dvmap=kernel_vmap affects everything, and prevents anything from
# referencing the libpcap.o symbol so named.

CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
$(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap
include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)

USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
$(MODE_INCLUDE)
core-y += $(SUBARCH_CORE)
libs-y += $(SUBARCH_LIBS)

# -Derrno=kernel_errno - This turns all kernel references to errno into
# kernel_errno to separate them from the libc errno. This allows -fno-common
# in CFLAGS. Otherwise, it would cause ld to complain about the two different
# errnos.

CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
$(ARCH_INCLUDE) $(MODE_INCLUDE)

USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
$(MODE_INCLUDE) $(ARCH_USER_CFLAGS)
CFLAGS += -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask
CFLAGS += $(call cc-option,-fno-unit-at-a-time,)

include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)

#This will adjust *FLAGS accordingly to the platform.
include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)

Expand Down Expand Up @@ -117,19 +116,18 @@ CONFIG_KERNEL_STACK_ORDER ?= 2
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )

ifndef START
START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
START = $$(($(TOP_ADDR) - $(SIZE)))
endif

CPPFLAGS_vmlinux.lds = -U$(SUBARCH) \
CPPFLAGS_vmlinux.lds = $(shell echo -U$(SUBARCH) \
-DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
-DELF_FORMAT="$(ELF_FORMAT)" $(CPP_MODE-y) \
-DKERNEL_STACK_SIZE=$(STACK_SIZE) \
-DUNMAP_PATH=arch/um/sys-$(SUBARCH)/unmap_fin.o
-DELF_FORMAT=\"$(ELF_FORMAT)\" $(CPP_MODE-y) \
-DKERNEL_STACK_SIZE=$(STACK_SIZE) -DSUBARCH=$(SUBARCH))

#The wrappers will select whether using "malloc" or the kernel allocator.
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS)
CFLAGS_vmlinux = $(LINK-y) $(LINK_WRAPS)
define cmd_vmlinux__
$(CC) $(CFLAGS_vmlinux) -o $@ \
-Wl,-T,$(vmlinux-lds) $(vmlinux-init) \
Expand Down
31 changes: 10 additions & 21 deletions trunk/arch/um/Makefile-i386
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
core-y += arch/um/sys-i386/ arch/i386/crypto/
SUBARCH_CORE := arch/um/sys-i386/ arch/i386/crypto/

TOP_ADDR := $(CONFIG_TOP_ADDR)

Expand All @@ -8,32 +8,21 @@ ifeq ($(CONFIG_MODE_SKAS),y)
endif
endif

LDFLAGS += -m elf_i386
ELF_ARCH := $(SUBARCH)
ELF_FORMAT := elf32-$(SUBARCH)
OBJCOPYFLAGS := -O binary -R .note -R .comment -S

ifeq ("$(origin SUBARCH)", "command line")
ifneq ("$(shell uname -m | sed -e s/i.86/i386/)", "$(SUBARCH)")
CFLAGS += $(call cc-option,-m32)
USER_CFLAGS += $(call cc-option,-m32)
HOSTCFLAGS += $(call cc-option,-m32)
HOSTLDFLAGS += $(call cc-option,-m32)
AFLAGS += $(call cc-option,-m32)
LINK-y += $(call cc-option,-m32)
UML_OBJCOPYFLAGS += -F $(ELF_FORMAT)

export LDFLAGS HOSTCFLAGS HOSTLDFLAGS UML_OBJCOPYFLAGS
endif
endif

CFLAGS += -U__$(SUBARCH)__ -U$(SUBARCH) $(STUB_CFLAGS)
ARCH_USER_CFLAGS :=

ifneq ($(CONFIG_GPROF),y)
ARCH_CFLAGS += -DUM_FASTCALL
endif

SYS_HEADERS := $(SYS_DIR)/sc.h $(SYS_DIR)/thread.h
ELF_ARCH := $(SUBARCH)
ELF_FORMAT := elf32-$(SUBARCH)

OBJCOPYFLAGS := -O binary -R .note -R .comment -S

SYS_UTIL_DIR := $(ARCH_DIR)/sys-i386/util

SYS_HEADERS := $(SYS_DIR)/sc.h $(SYS_DIR)/thread.h

prepare: $(SYS_HEADERS)

Expand Down
6 changes: 2 additions & 4 deletions trunk/arch/um/Makefile-x86_64
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Copyright 2003 - 2004 Pathscale, Inc
# Released under the GPL

libs-y += arch/um/sys-x86_64/
SUBARCH_LIBS := arch/um/sys-x86_64/
START := 0x60000000

#We #undef __x86_64__ for kernelspace, not for userspace where
#it's needed for headers to work!
CFLAGS += -U__$(SUBARCH)__ -fno-builtin $(STUB_CFLAGS)
USER_CFLAGS += -fno-builtin
ARCH_USER_CFLAGS := -D__x86_64__

ELF_ARCH := i386:x86-64
ELF_FORMAT := elf64-x86-64
Expand Down
17 changes: 3 additions & 14 deletions trunk/arch/um/drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@ slip-objs := slip_kern.o slip_user.o
slirp-objs := slirp_kern.o slirp_user.o
daemon-objs := daemon_kern.o daemon_user.o
mcast-objs := mcast_kern.o mcast_user.o
#pcap-objs := pcap_kern.o pcap_user.o $(PCAP)
net-objs := net_kern.o net_user.o
mconsole-objs := mconsole_kern.o mconsole_user.o
hostaudio-objs := hostaudio_kern.o
ubd-objs := ubd_kern.o ubd_user.o
port-objs := port_kern.o port_user.o
harddog-objs := harddog_kern.o harddog_user.o

LDFLAGS_pcap.o := -r $(shell $(CC) $(CFLAGS) -print-file-name=libpcap.a)

$(obj)/pcap.o: $(obj)/pcap_kern.o $(obj)/pcap_user.o
$(LD) -r -dp -o $@ $^ $(LDFLAGS) $(LDFLAGS_pcap.o)
#XXX: The call below does not work because the flags are added before the
# object name, so nothing from the library gets linked.
#$(call if_changed,ld)

# When the above is fixed, don't forget to add this too!
#targets := $(obj)/pcap.o

obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o
obj-$(CONFIG_SSL) += ssl.o
obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
Expand All @@ -36,7 +26,7 @@ obj-$(CONFIG_UML_NET_SLIP) += slip.o slip_common.o
obj-$(CONFIG_UML_NET_SLIRP) += slirp.o slip_common.o
obj-$(CONFIG_UML_NET_DAEMON) += daemon.o
obj-$(CONFIG_UML_NET_MCAST) += mcast.o
obj-$(CONFIG_UML_NET_PCAP) += pcap.o
#obj-$(CONFIG_UML_NET_PCAP) += pcap.o $(PCAP)
obj-$(CONFIG_UML_NET) += net.o
obj-$(CONFIG_MCONSOLE) += mconsole.o
obj-$(CONFIG_MMAPPER) += mmapper_kern.o
Expand All @@ -51,7 +41,6 @@ obj-$(CONFIG_UML_WATCHDOG) += harddog.o
obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
obj-$(CONFIG_UML_RANDOM) += random.o

# pcap_user.o must be added explicitly.
USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o pcap_user.o
USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o

include arch/um/scripts/Makefile.rules
Loading

0 comments on commit 233dc97

Please sign in to comment.