sort out blockdev_direct_IO variants

Move the call to vmtruncate to get rid of accessive blocks to the
callers
in prepearation of the new truncate calling sequence.  This was only
done
for DIO_LOCKING filesystems, so the __blockdev_direct_IO_newtrunc
variant
was not needed anyway.  Get rid of blockdev_direct_IO_no_locking and
its _newtrunc variant while at it as just opencoding the two additional
paramters is shorted than the name suffix.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
get rid of nobh_write_begin_newtrunc

Move the call to vmtruncate to get rid of accessive blocks to the only
remaining caller and rename the non-truncating version to
nobh_write_begin.

Get rid of the superflous file argument to it while we're at it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
get rid of cont_write_begin_newtrunc

Move the call to vmtruncate to get rid of accessive blocks to the
callers
in preparation of the new truncate sequence and rename the
non-truncating
version to cont_write_begin.

Signed-off-by: Christoph Hellwig <hch@lst.de>
clean up write_begin usage for directories in pagecache

For filesystem that implement directories in pagecache we call
block_write_begin with an already allocated page for this code, while
the
normal regular file write path uses the default block_write_begin
behaviour.

Get rid of the __foofs_write_begin helper and opencode the normal
write_begin
call in foofs_write_begin, while adding a new foofs_prepare_chunk helper
for
the directory code.  The added benefit is that foofs_prepare_chunk has
a much saner calling convention.

Note that the interruptible flag passed into block_write_begin is always
ignored if we already pass in a page (see next patch for details), and
we never were doing truncations of exessive blocks for this case either
so we
can switch directly to block_write_begin_newtrunc.

Signed-off-by: Christoph Hellwig <hch@lst.de>
introduce __block_write_begin

Split up the block_write_begin implementation - __block_write_begin is a
new
trivial wrapper for block_prepare_write that always takes an already
allocated page and can be either called from block_write_begin or
filesystem
code that already has a page allocated.  Remove the handling of already
allocated pages from block_write_begin after switching all callers that
do it to __block_write_begin.

Signed-off-by: Christoph Hellwig <hch@lst.de>
get rid of block_write_begin_newtrunc

Move the call to vmtruncate to get rid of accessive blocks to the
callers
in preparation of the new truncate sequence and rename the
non-truncating
version to block_write_begin.

While we're at it also remove several unused arguments to
block_write_begin.

Signed-off-by: Christoph Hellwig <hch@lst.de>
add missing setattr methods

For the new truncate sequence every filesystem that wants to truncate
on-disk
state needs a seattr method.  Convert the remaining filesystems that
implement
the truncate inode operation to have its own setattr method.

Signed-off-by: Christoph Hellwig <hch@lst.de>
rename generic_setattr

Despite its name it's now a generic implementation of ->setattr, but
rather a helper to copy attributes from a struct iattr to the inode.
Rename it to setattr_copy to reflect this fact.

Signed-off-by: Christoph Hellwig <hch@lst.de>
default to simple_setattr

With the new truncate sequence every filesystem that wants to support
file
size changes on disk needs to implement its own ->setattr.  So instead
of calling inode_setattr which supports size changes call into a simple
method that doesn't support this.  simple_setattr is almost what we
want except that it does not mark the inode dirty after changes.  Given
that marking the inode dirty is a no-op for the simple in-memory
filesystems
that use simple_setattr currently just add the mark_inode_dirty call.

Also add a WARN_ON for the presence of a truncate method to
simple_setattr
to catch new instances of it during the transition period.

Signed-off-by: Christoph Hellwig <hch@lst.de>
remove inode_setattr

Replace inode_setattr with opencoded variants of it in all callers.
This
moves the remaining call to vmtruncate into the filesystem methods where
it
can be replaced with the proper truncate sequence.

In a few cases it was obvious that we would never end up calling
vmtruncate
so it was left out in the opencoded variant:

spufs: explicitly checks for ATTR_SIZE earlier
btrfs,hugetlbfs,logfs,dlmfs: explicitly clears ATTR_SIZE earlier
ufs: contains an opencoded simple_seattr + truncate that sets the
filesize just above

In addition to that ncpfs called inode_setattr with handcrafted iattrs,
which allowed to trim down the opencoded variant.

Signed-off-by: Christoph Hellwig <hch@lst.de>
always call inode_change_ok early in ->setattr

Make sure we call inode_change_ok before doing any changes in ->setattr,
and make sure to call it even if our fs wants to ignore normal UNIX
permissions, but use the ATTR_FORCE to skip those.

Signed-off-by: Christoph Hellwig <hch@lst.de>
check ATTR_SIZE contraints in inode_change_ok

Make sure we check the truncate constraints early on in ->setattr by
adding
those checks to inode_change_ok.  Also clean up and document
inode_change_ok
to make this obvious.

As a fallout we don't have to call inode_newsize_ok from simple_setsize
and
simplify it down to a truncate_setsize which doesn't return an error.
This
simplifies a lot of setattr implementations and means we use
truncate_setsize
almost everywhere.  Get rid of fat_setsize now that it's trivial and
mark
ext2_setsize static to make the calling convention obvious.

Keep the inode_newsize_ok in vmtruncate for now as all callers need an
audit for its removal anyway.

Note: setattr code in ecryptfs doesn't call inode_change_ok at all and
needs a deeper audit, but that is left for later.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Audit: clean up the audit_watch split

No real changes, just cleanup to the audit_watch split patch which we
done
with minimal code changes for easy review.  Now fix interfaces to make
things work better.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: convert audit watches to use fsnotify instead of inotify

Audit currently uses inotify to pin inodes in core and to detect when
watched inodes are deleted or unmounted.  This patch uses fsnotify
instead
of inotify.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: redo audit watch locking and refcnt in light of fsnotify

fsnotify can handle mutexes to be held across all fsnotify operations
since
it deals strickly in spinlocks.  This can simplify and reduce some of
the
audit_filter_mutex taking and dropping.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: do not get and put just to free a watch

deleting audit watch rules is not currently done under
audit_filter_mutex.
It was done this way because we could not hold the mutex during inotify
manipulation.  Since we are using fsnotify we don't need to do the extra
get/put pair nor do we need the private list on which to store the
parents
while they are about to be freed.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: reimplement audit_trees using fsnotify rather than inotify

Simply switch audit_trees from using inotify to using fsnotify for it's
inode pinning and disappearing act information.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: audit watches depend on fsnotify

CONFIG_AUDIT builds audit_watches which depend on fsnotify.  Make
CONFIG_AUDIT select fsnotify.

Reported-by: Alexander Beregalov <a.beregalov@gmail.com>
Audit: split audit watch Kconfig

Audit watch should depend on CONFIG_AUDIT_SYSCALL and should select
FSNOTIFY.  This splits the spagetti like mixing of audit_watch and
audit_filter code so they can be configured seperately.

Signed-off-by: Eric Paris <eparis@redhat.com>
Audit: audit watch init should not be before fsnotify init

Audit watch init and fsnotify init both use subsys_initcall() but since
the
audit watch code is linked in before the fsnotify code the audit watch
code
would be using the fsnotify srcu struct before it was initialized.  This
patch fixes that problem by moving audit watch init to device_initcall()
so
it happens after fsnotify is ready.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Eric Paris <eparis@redhat.com>