1. 28 7月, 2010 40 次提交
    • E
      fsnotify: allow ignored_mask to survive modification · c908370f
      Eric Paris 提交于
      Some inodes a group may want to never hear about a set of events even if
      the inode is modified.  We add a new mark flag which indicates that these
      marks should not have their ignored_mask cleared on modification.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      c908370f
    • E
      fanotify: allow users to set an ignored_mask · b9e4e3bd
      Eric Paris 提交于
      Change the sys_fanotify_mark() system call so users can set ignored_masks
      on inodes.  Remember, if a user new sets a real mask, and only sets ignored
      masks, the ignore will never be pinned in memory.  Thus ignored_masks can
      be lost under memory pressure and the user may again get events they
      previously thought were ignored.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      b9e4e3bd
    • E
      fsnotify: ignored_mask - excluding notification · 33af5e32
      Eric Paris 提交于
      The ignored_mask is a new mask which is part of fsnotify marks.  A group's
      should_send_event() function can use the ignored mask to determine that
      certain events are not of interest.  In particular if a group registers a
      mask including FS_OPEN on a vfsmount they could add FS_OPEN to the
      ignored_mask for individual inodes and not send open events for those
      inodes.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      33af5e32
    • E
      fsnotify: allow marks to not pin inodes in core · 90b1e7a5
      Eric Paris 提交于
      inotify marks must pin inodes in core.  dnotify doesn't technically need to
      since they are closed when the directory is closed.  fanotify also need to
      pin inodes in core as it works today.  But the next step is to introduce
      the concept of 'ignored masks' which is actually a mask of events for an
      inode of no interest.  I claim that these should be liberally sent to the
      kernel and should not pin the inode in core.  If the inode is brought back
      in the listener will get an event it may have thought excluded, but this is
      not a serious situation and one any listener should deal with.
      
      This patch lays the ground work for non-pinning inode marks by using lazy
      inode pinning.  We do not pin a mark until it has a non-zero mask entry.  If a
      listener new sets a mask we never pin the inode.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      90b1e7a5
    • A
      fanotify: remove fanotify.h declarations · 88380fe6
      Andreas Gruenbacher 提交于
      fanotify_mark_validate functions are all needlessly declared in headers as
      static inlines.  Instead just do the checks where they are needed for code
      readability.
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      88380fe6
    • A
      fanotify: rename FAN_MARK_ON_VFSMOUNT to FAN_MARK_MOUNT · eac8e9e8
      Andreas Gruenbacher 提交于
      the term 'vfsmount' isn't sensicle to userspace.  instead call is 'mount.
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      eac8e9e8
    • E
      fanotify: hooks the fanotify_mark syscall to the vfsmount code · 0ff21db9
      Eric Paris 提交于
      Create a new fanotify_mark flag which indicates we should attach the mark
      to the vfsmount holding the object referenced by dfd and pathname rather
      than the inode itself.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      0ff21db9
    • E
      fanotify: should_send_event needs to handle vfsmounts · 1c529063
      Eric Paris 提交于
      currently should_send_event in fanotify only cares about marks on inodes.
      This patch extends that interface to indicate that it cares about events
      that happened on vfsmounts.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      1c529063
    • A
      fsnotify: Infrastructure for per-mount watches · ca9c726e
      Andreas Gruenbacher 提交于
      Per-mount watches allow groups to listen to fsnotify events on an entire
      mount.  This patch simply adds and initializes the fields needed in the
      vfsmount struct to make this happen.
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ca9c726e
    • E
      fsnotify: vfsmount marks generic functions · 0d48b7f0
      Eric Paris 提交于
      Much like inode-mark.c has all of the code dealing with marks on inodes
      this patch adds a vfsmount-mark.c which has similar code but is intended
      for marks on vfsmounts.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      0d48b7f0
    • A
      fsnotify/vfsmount: add fsnotify fields to struct vfsmount · 2504c5d6
      Andreas Gruenbacher 提交于
      This patch adds the list and mask fields needed to support vfsmount marks.
      These are the same fields fsnotify needs on an inode.  They are not used,
      just declared and we note where the cleanup hook should be (the function is
      not yet defined)
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      2504c5d6
    • E
      fsnotify: split generic and inode specific mark code · 5444e298
      Eric Paris 提交于
      currently all marking is done by functions in inode-mark.c.  Some of this
      is pretty generic and should be instead done in a generic function and we
      should only put the inode specific code in inode-mark.c
      Signed-off-by: NEric Paris <eparis@redhat.com>
      5444e298
    • A
      fanotify: Add pids to events · 32c32632
      Andreas Gruenbacher 提交于
      Pass the process identifiers of the triggering processes to fanotify
      listeners: this information is useful for event filtering and logging.
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      32c32632
    • E
      fanotify: send events using read · a1014f10
      Eric Paris 提交于
      Send events to userspace by reading the file descriptor from fanotify_init().
      One will get blocks of data which look like:
      
      struct fanotify_event_metadata {
      	__u32 event_len;
      	__u32 vers;
      	__s32 fd;
      	__u64 mask;
      	__s64 pid;
      	__u64 cookie;
      } __attribute__ ((packed));
      
      Simple code to retrieve and deal with events is below
      
      	while ((len = read(fan_fd, buf, sizeof(buf))) > 0) {
      		struct fanotify_event_metadata *metadata;
      
      		metadata = (void *)buf;
      		while(FAN_EVENT_OK(metadata, len)) {
      			[PROCESS HERE!!]
      			if (metadata->fd >= 0 && close(metadata->fd) != 0)
      				goto fail;
      			metadata = FAN_EVENT_NEXT(metadata, len);
      		}
      	}
      Signed-off-by: NEric Paris <eparis@redhat.com>
      a1014f10
    • E
      fanotify: fanotify_mark syscall implementation · 2a3edf86
      Eric Paris 提交于
      NAME
      	fanotify_mark - add, remove, or modify an fanotify mark on a
      filesystem object
      
      SYNOPSIS
      	int fanotify_mark(int fanotify_fd, unsigned int flags, u64 mask,
      			  int dfd, const char *pathname)
      
      DESCRIPTION
      	fanotify_mark() is used to add remove or modify a mark on a filesystem
      	object.  Marks are used to indicate that the fanotify group is
      	interested in events which occur on that object.  At this point in
      	time marks may only be added to files and directories.
      
      	fanotify_fd must be a file descriptor returned by fanotify_init()
      
      	The flags field must contain exactly one of the following:
      
      	FAN_MARK_ADD - or the bits in mask and ignored mask into the mark
      	FAN_MARK_REMOVE - bitwise remove the bits in mask and ignored mark
      		from the mark
      
      	The following values can be OR'd into the flags field:
      
      	FAN_MARK_DONT_FOLLOW - same meaning as O_NOFOLLOW as described in open(2)
      	FAN_MARK_ONLYDIR - same meaning as O_DIRECTORY as described in open(2)
      
      	dfd may be any of the following:
      	AT_FDCWD: the object will be lookup up based on pathname similar
      		to open(2)
      
      	file descriptor of a directory: if pathname is not NULL the
      		object to modify will be lookup up similar to openat(2)
      
      	file descriptor of the final object: if pathname is NULL the
      		object to modify will be the object referenced by dfd
      
      	The mask is the bitwise OR of the set of events of interest such as:
      	FAN_ACCESS		- object was accessed (read)
      	FAN_MODIFY		- object was modified (write)
      	FAN_CLOSE_WRITE		- object was writable and was closed
      	FAN_CLOSE_NOWRITE	- object was read only and was closed
      	FAN_OPEN		- object was opened
      	FAN_EVENT_ON_CHILD	- interested in objected that happen to
      				  children.  Only relavent when the object
      				  is a directory
      	FAN_Q_OVERFLOW		- event queue overflowed (not implemented)
      
      RETURN VALUE
      	On success, this system call returns 0. On error, -1 is
      	returned, and errno is set to indicate the error.
      
      ERRORS
      	EINVAL An invalid value was specified in flags.
      
      	EINVAL An invalid value was specified in mask.
      
      	EINVAL An invalid value was specified in ignored_mask.
      
      	EINVAL fanotify_fd is not a file descriptor as returned by
      	fanotify_init()
      
      	EBADF fanotify_fd is not a valid file descriptor
      
      	EBADF dfd is not a valid file descriptor and path is NULL.
      
      	ENOTDIR dfd is not a directory and path is not NULL
      
      	EACCESS no search permissions on some part of the path
      
      	ENENT file not found
      
      	ENOMEM Insufficient kernel memory is available.
      
      CONFORMING TO
      	These system calls are Linux-specific.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      2a3edf86
    • E
      fanotify: sys_fanotify_mark declartion · bbaa4168
      Eric Paris 提交于
      This patch simply declares the new sys_fanotify_mark syscall
      
      int fanotify_mark(int fanotify_fd, unsigned int flags, u64_mask,
      		  int dfd const char *pathname)
      Signed-off-by: NEric Paris <eparis@redhat.com>
      bbaa4168
    • E
      fanotify: fanotify_init syscall implementation · 52c923dd
      Eric Paris 提交于
      NAME
      	fanotify_init - initialize an fanotify group
      
      SYNOPSIS
      	int fanotify_init(unsigned int flags, unsigned int event_f_flags, int priority);
      
      DESCRIPTION
      	fanotify_init() initializes a new fanotify instance and returns a file
      	descriptor associated with the new fanotify event queue.
      
      	The following values can be OR'd into the flags field:
      
      	FAN_NONBLOCK Set the O_NONBLOCK file status flag on the new open file description.
      		Using this flag saves extra calls to fcntl(2) to achieve the same
      		result.
      
      	FAN_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor.
      		See the description of the O_CLOEXEC flag in open(2) for reasons why
      		this may be useful.
      
      	The event_f_flags argument is unused and must be set to 0
      
      	The priority argument is unused and must be set to 0
      
      RETURN VALUE
      	On success, this system call return a new file descriptor. On error, -1 is
      	returned, and errno is set to indicate the error.
      
      ERRORS
      	EINVAL An invalid value was specified in flags.
      
      	EINVAL A non-zero valid was passed in event_f_flags or in priority
      
      	ENFILE The system limit on the total number of file descriptors has been reached.
      
      	ENOMEM Insufficient kernel memory is available.
      
      CONFORMING TO
      	These system calls are Linux-specific.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      52c923dd
    • E
      fanotify: fanotify_init syscall declaration · 11637e4b
      Eric Paris 提交于
      This patch defines a new syscall fanotify_init() of the form:
      
      int sys_fanotify_init(unsigned int flags, unsigned int event_f_flags,
      		      unsigned int priority)
      
      This syscall is used to create and fanotify group.  This is very similar to
      the inotify_init() syscall.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      11637e4b
    • E
      fanotify: fscking all notification system · ff0b16a9
      Eric Paris 提交于
      fanotify is a novel file notification system which bases notification on
      giving userspace both an event type (open, close, read, write) and an open
      file descriptor to the object in question.  This should address a number of
      races and problems with other notification systems like inotify and dnotify
      and should allow the future implementation of blocking or access controlled
      notification.  These are useful for on access scanners or hierachical storage
      management schemes.
      
      This patch just implements the basics of the fsnotify functions.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ff0b16a9
    • S
      fanotify: FMODE_NONOTIFY and __O_SYNC in sparc conflict · 12ed2e36
      Signed-off-by: Wu Fengguang 提交于
      sparc used the same value as FMODE_NONOTIFY so change FMODE_NONOTIFY to be
      something unique.
      Signed-off-by: NWu Fengguang <fengguang.wu@intel.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      12ed2e36
    • E
      vfs: introduce FMODE_NONOTIFY · ecf081d1
      Eric Paris 提交于
      This is a new f_mode which can only be set by the kernel.  It indicates
      that the fd was opened by fanotify and should not cause future fanotify
      events.  This is needed to prevent fanotify livelock.  An example of
      obvious livelock is from fanotify close events.
      
      Process A closes file1
      This creates a close event for file1.
      fanotify opens file1 for Listener X
      Listener X deals with the event and closes its fd for file1.
      This creates a close event for file1.
      fanotify opens file1 for Listener X
      Listener X deals with the event and closes its fd for file1.
      This creates a close event for file1.
      fanotify opens file1 for Listener X
      Listener X deals with the event and closes its fd for file1.
      notice a pattern?
      
      The fix is to add the FMODE_NONOTIFY bit to the open filp done by the kernel
      for fanotify.  Thus when that file is used it will not generate future
      events.
      
      This patch simply defines the bit.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ecf081d1
    • E
      fsnotify: rename mark_entry to just mark · 841bdc10
      Eric Paris 提交于
      previously I used mark_entry when talking about marks on inodes.  The
      _entry is pretty useless.  Just use "mark" instead.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      841bdc10
    • E
      fsnotify: rename fsnotify_find_mark_entry to fsnotify_find_mark · d0775441
      Eric Paris 提交于
      the _entry portion of fsnotify functions is useless.  Drop it.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      d0775441
    • E
      fsnotify: rename fsnotify_mark_entry to just fsnotify_mark · e61ce867
      Eric Paris 提交于
      The name is long and it serves no real purpose.  So rename
      fsnotify_mark_entry to just fsnotify_mark.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      e61ce867
    • A
      fsnotify: kill FSNOTIFY_EVENT_FILE · 72acc854
      Andreas Gruenbacher 提交于
      Some fsnotify operations send a struct file.  This is more information than
      we technically need.  We instead send a struct path in all cases instead of
      sometimes a path and sometimes a file.
      Signed-off-by: NAndreas Gruenbacher <agruen@suse.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      72acc854
    • E
      fsnotify: add flags to fsnotify_mark_entries · 098cf2fc
      Eric Paris 提交于
      To differentiate between inode and vfsmount (or other future) types of
      marks we add a flags field and set the inode bit on inode marks (the only
      currently supported type of mark)
      Signed-off-by: NEric Paris <eparis@redhat.com>
      098cf2fc
    • E
      fsnotify: add vfsmount specific fields to the fsnotify_mark_entry union · 4136510d
      Eric Paris 提交于
      vfsmount marks need mostly the same data as inode specific fields, but for
      consistency and understandability we put that data in a vfsmount specific
      struct inside a union with inode specific data.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      4136510d
    • E
      fsnotify: put inode specific fields in an fsnotify_mark in a union · 2823e04d
      Eric Paris 提交于
      The addition of marks on vfs mounts will be simplified if the inode
      specific parts of a mark and the vfsmnt specific parts of a mark are
      actually in a union so naming can be easy.  This patch just implements the
      inode struct and the union.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      2823e04d
    • E
      fsnotify: include vfsmount in should_send_event when appropriate · 3a9fb89f
      Eric Paris 提交于
      To ensure that a group will not duplicate events when it receives it based
      on the vfsmount and the inode should_send_event test we should distinguish
      those two cases.  We pass a vfsmount to this function so groups can make
      their own determinations.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      3a9fb89f
    • E
      fsnotify: mount point listeners list and global mask · 7131485a
      Eric Paris 提交于
      currently all of the notification systems implemented select which inodes
      they care about and receive messages only about those inodes (or the
      children of those inodes.)  This patch begins to flesh out fsnotify support
      for the concept of listeners that want to hear notification for an inode
      accessed below a given monut point.  This patch implements a second list
      of fsnotify groups to hold these types of groups and a second global mask
      to hold the events of interest for this type of group.
      
      The reason we want a second group list and mask is because the inode based
      notification should_send_event support which makes each group look for a mark
      on the given inode.  With one nfsmount listener that means that every group would
      have to take the inode->i_lock, look for their mark, not find one, and return
      for every operation.   By seperating vfsmount from inode listeners only when
      there is a inode listener will the inode groups have to look for their
      mark and take the inode lock.  vfsmount listeners will have to grab the lock and
      look for a mark but there should be fewer of them, and one vfsmount listener
      won't cause the i_lock to be grabbed and released for every fsnotify group
      on every io operation.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      7131485a
    • E
      fsnotify: rename fsnotify_groups to fsnotify_inode_groups · 19c2a0e1
      Eric Paris 提交于
      Simple renaming patch.  fsnotify is about to support mount point listeners
      so I am renaming fsnotify_groups and fsnotify_mask to indicate these are lists
      used only for groups which have watches on inodes.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      19c2a0e1
    • E
      fsnotify: drop mask argument from fsnotify_alloc_group · 0d2e2a1d
      Eric Paris 提交于
      Nothing uses the mask argument to fsnotify_alloc_group.  This patch drops
      that argument.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      0d2e2a1d
    • E
      fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group · ffab8340
      Eric Paris 提交于
      fsnotify_obtain_group was intended to be able to find an already existing
      group.  Nothing uses that functionality.  This just renames it to
      fsnotify_alloc_group so it is clear what it is doing.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ffab8340
    • E
      fsnotify: remove group_num altogether · 74be0cc8
      Eric Paris 提交于
      The original fsnotify interface has a group-num which was intended to be
      able to find a group after it was added.  I no longer think this is a
      necessary thing to do and so we remove the group_num.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      74be0cc8
    • E
      fsnotify: replace an event on a list · 1201a536
      Eric Paris 提交于
      fanotify would like to clone events already on its notification list, make
      changes to the new event, and then replace the old event on the list with
      the new event.  This patch implements the replace functionality of that
      process.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      1201a536
    • E
      fsnotify: clone existing events · b4e4e140
      Eric Paris 提交于
      fsnotify_clone_event will take an event, clone it, and return the cloned
      event to the caller.  Since events may be in use by multiple fsnotify
      groups simultaneously certain event entries (such as the mask) cannot be
      changed after the event was created.  Since fanotify would like to merge
      events happening on the same file it needs a new clean event to work with
      so it can change any fields it wishes.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      b4e4e140
    • E
      fsnotify: per group notification queue merge types · 74766bbf
      Eric Paris 提交于
      inotify only wishes to merge a new event with the last event on the
      notification fifo.  fanotify is willing to merge any events including by
      means of bitwise OR masks of multiple events together.  This patch moves
      the inotify event merging logic out of the generic fsnotify notification.c
      and into the inotify code.  This allows each use of fsnotify to provide
      their own merge functionality.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      74766bbf
    • E
      fsnotify: send struct file when sending events to parents when possible · 28c60e37
      Eric Paris 提交于
      fanotify needs a path in order to open an fd to the object which changed.
      Currently notifications to inode's parents are done using only the inode.
      For some parental notification we have the entire file, send that so
      fanotify can use it.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      28c60e37
    • E
      fsnotify: pass a file instead of an inode to open, read, and write · 2a12a9d7
      Eric Paris 提交于
      fanotify, the upcoming notification system actually needs a struct path so it can
      do opens in the context of listeners, and it needs a file so it can get f_flags
      from the original process.  Close was the only operation that already was passing
      a struct file to the notification hook.  This patch passes a file for access,
      modify, and open as well as they are easily available to these hooks.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      2a12a9d7
    • E
      fsnotify: include data in should_send calls · 8112e2d6
      Eric Paris 提交于
      fanotify is going to need to look at file->private_data to know if an event
      should be sent or not.  This passes the data (which might be a file,
      dentry, inode, or none) to the should_send function calls so fanotify can
      get that information when available
      Signed-off-by: NEric Paris <eparis@redhat.com>
      8112e2d6