1. 28 7月, 2010 40 次提交
    • E
      fsnotify: send fsnotify_mark to groups in event handling functions · 3a9b16b4
      Eric Paris 提交于
      With the change of fsnotify to use srcu walking the marks list instead of
      walking the global groups list we now know the mark in question.  The code can
      send the mark to the group's handling functions and the groups won't have to
      find those marks themselves.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      3a9b16b4
    • E
      fsnotify: srcu to protect read side of inode and vfsmount locks · 75c1be48
      Eric Paris 提交于
      Currently reading the inode->i_fsnotify_marks or
      vfsmount->mnt_fsnotify_marks lists are protected by a spinlock on both the
      read and the write side.  This patch protects the read side of those lists
      with a new single srcu.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      75c1be48
    • E
      fsnotify: use an explicit flag to indicate fsnotify_destroy_mark has been called · 700307a2
      Eric Paris 提交于
      Currently fsnotify check is mark->group is NULL to decide if
      fsnotify_destroy_mark() has already been called or not.  With the upcoming
      rcu work it is a heck of a lot easier to use an explicit flag than worry
      about group being set to NULL.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      700307a2
    • E
      fsnotify: store struct file not struct path · 3bcf3860
      Eric Paris 提交于
      Al explains that calling dentry_open() with a mnt/dentry pair is only
      garunteed to be safe if they are already used in an open struct file.  To
      make sure this is the case don't store and use a struct path in fsnotify,
      always use a struct file.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      3bcf3860
    • E
      fsnotify: fsnotify_add_notify_event should return an event · f70ab54c
      Eric Paris 提交于
      Rather than the horrific void ** argument and such just to pass the
      fanotify_merge event back to the caller of fsnotify_add_notify_event() have
      those things return an event if it was different than the event suggusted to
      be added.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      f70ab54c
    • E
      fanotify: groups can specify their f_flags for new fd · 80af2588
      Eric Paris 提交于
      Currently fanotify fds opened for thier listeners are done with f_flags
      equal to O_RDONLY | O_LARGEFILE.  This patch instead takes f_flags from the
      fanotify_init syscall and uses those when opening files in the context of
      the listener.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      80af2588
    • E
      fsnotify: check to make sure all fsnotify bits are unique · 20dee624
      Eric Paris 提交于
      This patch adds a check to make sure that all fsnotify bits are unique and we
      cannot accidentally use the same bit for 2 different fsnotify event types.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      20dee624
    • E
      inotify: force inotify and fsnotify use same bits · f874e1ac
      Eric Paris 提交于
      inotify uses bits called IN_* and fsnotify uses bits called FS_*.  These
      need to line up.  This patch adds build time checks to make sure noone can
      change these bits so they are not the same.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      f874e1ac
    • E
      inotify: allow users to request not to recieve events on unlinked children · 8c1934c8
      Eric Paris 提交于
      An inotify watch on a directory will send events for children even if those
      children have been unlinked.  This patch add a new inotify flag IN_EXCL_UNLINK
      which allows a watch to specificy they don't care about unlinked children.
      This should fix performance problems seen by tasks which add a watch to
      /tmp and then are overrun with events when other processes are reading and
      writing to unlinked files they created in /tmp.
      
      https://bugzilla.kernel.org/show_bug.cgi?id=16296Requested-by: NMatthias Clasen <mclasen@redhat.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      8c1934c8
    • E
      fanotify: drop the useless priority argument · 08ae8938
      Eric Paris 提交于
      The priority argument in fanotify is useless.  Kill it.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      08ae8938
    • E
      fsnotify: initialize mask in fsnotify_perm · fb1cfb88
      Eric Paris 提交于
      akpm got a warning the fsnotify_mask could be used uninitialized in
      fsnotify_perm().  It's not actually possible but his compiler complained
      about it.  This patch just initializes it to 0 to shut up the compiler.
      Reported-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      fb1cfb88
    • E
      fanotify: userspace interface for permission responses · b2d87909
      Eric Paris 提交于
      fanotify groups need to respond to events which include permissions types.
      To do so groups will send a response using write() on the fanotify_fd they
      have open.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      b2d87909
    • E
      fanotify: permissions and blocking · 9e66e423
      Eric Paris 提交于
      This is the backend work needed for fanotify to support the new
      FS_OPEN_PERM and FS_ACCESS_PERM fsnotify events.  This is done using the
      new fsnotify secondary queue.  No userspace interface is provided actually
      respond to or request these events.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      9e66e423
    • E
      fsnotify: new fsnotify hooks and events types for access decisions · c4ec54b4
      Eric Paris 提交于
      introduce a new fsnotify hook, fsnotify_perm(), which is called from the
      security code.  This hook is used to allow fsnotify groups to make access
      control decisions about events on the system.  We also must change the
      generic fsnotify function to return an error code if we intend these hooks
      to be in any way useful.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      c4ec54b4
    • D
      sysctl extern cleanup: inotify · d14f1729
      Dave Young 提交于
      Extern declarations in sysctl.c should be move to their own head file, and
      then include them in relavant .c files.
      
      Move inotify_table extern declaration to linux/inotify.h
      Signed-off-by: NDave Young <hidave.darkstar@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      d14f1729
    • A
      dnotify: move dir_notify_enable declaration · 6e006701
      Alexey Dobriyan 提交于
      Move dir_notify_enable declaration to where it belongs -- dnotify.h .
      Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      6e006701
    • E
      fsnotify: use unsigned char * for dentry->d_name.name · 59b0df21
      Eric Paris 提交于
      fsnotify was using char * when it passed around the d_name.name string
      internally but it is actually an unsigned char *.  This patch switches
      fsnotify to use unsigned and should silence some pointer signess warnings
      which have popped out of xfs.  I do not add -Wpointer-sign to the fsnotify
      code as there are still issues with kstrdup and strlen which would pop
      out needless warnings.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      59b0df21
    • E
      fsnotify: intoduce a notification merge argument · 6e5f77b3
      Eric Paris 提交于
      Each group can define their own notification (and secondary_q) merge
      function.  Inotify does tail drop, fanotify does matching and drop which
      can actually allocate a completely new event.  But for fanotify to properly
      deal with permissions events it needs to know the new event which was
      ultimately added to the notification queue.  This patch just implements a
      void ** argument which is passed to the merge function.  fanotify can use
      this field to pass the new event back to higher layers.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      for fanotify to properly deal with permissions events
      6e5f77b3
    • E
      fsnotify: add group priorities · cb2d429f
      Eric Paris 提交于
      This introduces an ordering to fsnotify groups.  With purely asynchronous
      notification based "things" implementing fsnotify (inotify, dnotify) ordering
      isn't particularly important.  But if people want to use fsnotify for the
      basis of sycronous notification or blocking notification ordering becomes
      important.
      
      eg. A Hierarchical Storage Management listener would need to get its event
      before an AV scanner could get its event (since the HSM would need to
      bring the data in for the AV scanner to scan.)  Typically asynchronous notification
      would want to run after the AV scanner made any relevant access decisions
      so as to not send notification about an event that was denied.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      cb2d429f
    • E
      fanotify: clear all fanotify marks · 4d92604c
      Eric Paris 提交于
      fanotify listeners may want to clear all marks.  They may want to do this
      to destroy all of their inode marks which have nothing but ignores.
      Realistically this is useful for av vendors who update policy and want to
      clear all of their cached allows.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      4d92604c
    • E
      fanotify: allow ignored_masks to survive modify · c9778a98
      Eric Paris 提交于
      Some users may want to truely ignore an inode even if it has been modified.
      Say you are wanting a mount which contains a log file and you really don't
      want any notification about that file.  This patch allows the listener to
      do that.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      c9778a98
    • 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