Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4824
b: refs/heads/master
c: 5d15788
h: refs/heads/master
v: v3
  • Loading branch information
Thomas Gleixner authored and Thomas Gleixner committed Jul 15, 2005
1 parent 362bd5b commit d3fd868
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 285 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: 9fb1759a3102c26cd8f64254a7c3e532782c2bb8
refs/heads/master: 5d157885f383ccc0660c011fa488ae4edb77ab16
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.

6 changes: 0 additions & 6 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
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: 0 additions & 2 deletions trunk/arch/ia64/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ 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
7 changes: 1 addition & 6 deletions trunk/arch/x86_64/ia32/syscall32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
int npages = (VSYSCALL32_END - VSYSCALL32_BASE) >> PAGE_SHIFT;
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
int ret;

vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
if (!vma)
Expand All @@ -79,11 +78,7 @@ int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
vma->vm_mm = mm;

down_write(&mm->mmap_sem);
if ((ret = insert_vm_struct(mm, vma))) {
up_write(&mm->mmap_sem);
kmem_cache_free(vm_area_cachep, vma);
return ret;
}
insert_vm_struct(mm, vma);
mm->total_vm += npages;
up_write(&mm->mmap_sem);
return 0;
Expand Down
3 changes: 1 addition & 2 deletions trunk/drivers/char/rocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ static void rp_do_receive(struct r_port *info,
ToRecv = space;

if (ToRecv <= 0)
goto done;
return;

/*
* if status indicates there are errored characters in the
Expand Down Expand Up @@ -437,7 +437,6 @@ static void rp_do_receive(struct r_port *info,
}
/* Push the data up to the tty layer */
ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
done:
tty_ldisc_deref(ld);
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/char/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ void do_blank_screen(int entering_gfx)
return;

if (vesa_off_interval) {
blank_state = blank_vesa_wait;
blank_state = blank_vesa_wait,
mod_timer(&console_timer, jiffies + vesa_off_interval);
}

Expand Down
9 changes: 3 additions & 6 deletions trunk/drivers/md/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
}
}

int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
int degraded)
int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks)
{
bitmap_counter_t *bmc;
int rv;
Expand All @@ -1363,10 +1362,8 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
rv = 1;
else if (NEEDED(*bmc)) {
rv = 1;
if (!degraded) { /* don't set/clear bits if degraded */
*bmc |= RESYNC_MASK;
*bmc &= ~NEEDED_MASK;
}
*bmc |= RESYNC_MASK;
*bmc &= ~NEEDED_MASK;
}
}
spin_unlock_irq(&bitmap->lock);
Expand Down
8 changes: 4 additions & 4 deletions trunk/drivers/md/raid0.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ static int raid0_run (mddev_t *mddev)
sector_t space = conf->hash_spacing;
int round;
conf->preshift = 0;
if (sizeof(sector_t) > sizeof(u32)) {
if (sizeof(sector_t) > sizeof(unsigned long)) {
/*shift down space and s so that sector_div will work */
while (space > (sector_t) (~(u32)0)) {
while (space > (sector_t) (~(unsigned long)0)) {
s >>= 1;
space >>= 1;
s += 1; /* force round-up */
conf->preshift++;
}
}
round = sector_div(s, (u32)space) ? 1 : 0;
round = sector_div(s, (unsigned long)space) ? 1 : 0;
nb_zone = s + round;
}
printk("raid0 : nb_zone is %d.\n", nb_zone);
Expand Down Expand Up @@ -443,7 +443,7 @@ static int raid0_make_request (request_queue_t *q, struct bio *bio)
volatile
#endif
sector_t x = block >> conf->preshift;
sector_div(x, (u32)conf->hash_spacing);
sector_div(x, (unsigned long)conf->hash_spacing);
zone = conf->hash_table[x];
}

Expand Down
37 changes: 19 additions & 18 deletions trunk/drivers/md/raid1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,19 +1126,21 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
* only be one in raid1 resync.
* We can find the current addess in mddev->curr_resync
*/
if (mddev->curr_resync < max_sector) /* aborted */
bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
if (!conf->fullsync) {
if (mddev->curr_resync < max_sector)
bitmap_end_sync(mddev->bitmap,
mddev->curr_resync,
&sync_blocks, 1);
else /* completed sync */
bitmap_close_sync(mddev->bitmap);
}
if (mddev->curr_resync >= max_sector)
conf->fullsync = 0;

bitmap_close_sync(mddev->bitmap);
close_sync(conf);
return 0;
}

if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, mddev->degraded) &&
!conf->fullsync) {
if (!conf->fullsync &&
!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks)) {
/* We can skip this block, and probably several more */
*skipped = 1;
return sync_blocks;
Expand Down Expand Up @@ -1241,15 +1243,15 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
len = (max_sector - sector_nr) << 9;
if (len == 0)
break;
if (sync_blocks == 0) {
if (!bitmap_start_sync(mddev->bitmap, sector_nr,
&sync_blocks, mddev->degraded) &&
!conf->fullsync)
break;
if (sync_blocks < (PAGE_SIZE>>9))
BUG();
if (len > (sync_blocks<<9))
len = sync_blocks<<9;
if (!conf->fullsync) {
if (sync_blocks == 0) {
if (!bitmap_start_sync(mddev->bitmap,
sector_nr, &sync_blocks))
break;
if (sync_blocks < (PAGE_SIZE>>9))
BUG();
if (len > (sync_blocks<<9)) len = sync_blocks<<9;
}
}

for (i=0 ; i < conf->raid_disks; i++) {
Expand All @@ -1262,8 +1264,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
while (i > 0) {
i--;
bio = r1_bio->bios[i];
if (bio->bi_end_io==NULL)
continue;
if (bio->bi_end_io==NULL) continue;
/* remove last page from this bio */
bio->bi_vcnt--;
bio->bi_size -= len;
Expand Down
8 changes: 4 additions & 4 deletions trunk/drivers/media/video/cx88/cx88-cards.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: cx88-cards.c,v 1.86 2005/07/14 03:06:43 mchehab Exp $
* $Id: cx88-cards.c,v 1.85 2005/07/04 19:35:05 mkrufky Exp $
*
* device driver for Conexant 2388x based TV cards
* card-specific stuff.
Expand Down Expand Up @@ -682,9 +682,9 @@ struct cx88_board cx88_boards[] = {
.name = "PixelView PlayTV Ultra Pro (Stereo)",
/* May be also TUNER_YMEC_TVF_5533MF for NTSC/M or PAL/M */
.tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
.radio_type = UNSET,
.tuner_addr = ADDR_UNSET,
.radio_addr = ADDR_UNSET,
.radio_type = TUNER_TEA5767,
.tuner_addr = 0xc2>>1,
.radio_addr = 0xc0>>1,
.input = {{
.type = CX88_VMUX_TELEVISION,
.vmux = 0,
Expand Down
Loading

0 comments on commit d3fd868

Please sign in to comment.