2005-04-17 02:20:36 +04:00
/*
* Copyright 2000 by Hans Reiser , licensing governed by reiserfs / README
*/
2006-01-11 23:17:46 +03:00
# include <linux/capability.h>
2005-04-17 02:20:36 +04:00
# include <linux/fs.h>
2008-02-16 01:37:46 +03:00
# include <linux/mount.h>
2012-03-17 09:16:43 +04:00
# include "reiserfs.h"
2005-04-17 02:20:36 +04:00
# include <linux/time.h>
2014-08-09 01:21:12 +04:00
# include <linux/uaccess.h>
2005-04-17 02:20:36 +04:00
# include <linux/pagemap.h>
2006-08-29 22:06:18 +04:00
# include <linux/compat.h>
2021-04-07 15:36:44 +03:00
# include <linux/fileattr.h>
int reiserfs_fileattr_get ( struct dentry * dentry , struct fileattr * fa )
{
struct inode * inode = d_inode ( dentry ) ;
if ( ! reiserfs_attrs ( inode - > i_sb ) )
return - ENOTTY ;
fileattr_fill_flags ( fa , REISERFS_I ( inode ) - > i_attrs ) ;
return 0 ;
}
int reiserfs_fileattr_set ( struct user_namespace * mnt_userns ,
struct dentry * dentry , struct fileattr * fa )
{
struct inode * inode = d_inode ( dentry ) ;
unsigned int flags = fa - > flags ;
int err ;
reiserfs_write_lock ( inode - > i_sb ) ;
err = - ENOTTY ;
if ( ! reiserfs_attrs ( inode - > i_sb ) )
goto unlock ;
err = - EOPNOTSUPP ;
if ( fileattr_has_fsx ( fa ) )
goto unlock ;
/*
* Is it quota file ? Do not allow user to mess with it
*/
err = - EPERM ;
if ( IS_NOQUOTA ( inode ) )
goto unlock ;
if ( ( flags & REISERFS_NOTAIL_FL ) & & S_ISREG ( inode - > i_mode ) ) {
err = reiserfs_unpack ( inode ) ;
if ( err )
goto unlock ;
}
sd_attrs_to_i_attrs ( flags , inode ) ;
REISERFS_I ( inode ) - > i_attrs = flags ;
inode - > i_ctime = current_time ( inode ) ;
mark_inode_dirty ( inode ) ;
err = 0 ;
unlock :
reiserfs_write_unlock ( inode - > i_sb ) ;
return err ;
}
2005-04-17 02:20:36 +04:00
/*
2009-10-15 01:08:43 +04:00
* reiserfs_ioctl - handler for ioctl for inode
* supported commands :
* 1 ) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
2014-04-23 18:00:36 +04:00
* and prevent packing file ( argument arg has t
* be non - zero )
2009-10-15 01:08:43 +04:00
* 2 ) REISERFS_IOC_ [ GS ] ETFLAGS , REISERFS_IOC_ [ GS ] ETVERSION
* 3 ) That ' s all for a while . . .
*/
2009-10-15 01:22:17 +04:00
long reiserfs_ioctl ( struct file * filp , unsigned int cmd , unsigned long arg )
2005-04-17 02:20:36 +04:00
{
2013-01-24 02:07:38 +04:00
struct inode * inode = file_inode ( filp ) ;
2008-02-16 01:37:46 +03:00
int err = 0 ;
2005-04-17 02:20:36 +04:00
2009-10-15 01:08:43 +04:00
reiserfs_write_lock ( inode - > i_sb ) ;
2005-04-17 02:20:36 +04:00
switch ( cmd ) {
2005-07-13 07:21:28 +04:00
case REISERFS_IOC_UNPACK :
if ( S_ISREG ( inode - > i_mode ) ) {
if ( arg )
2021-04-07 15:36:44 +03:00
err = reiserfs_unpack ( inode ) ;
2005-04-17 02:20:36 +04:00
} else
2009-10-15 01:08:43 +04:00
err = - ENOTTY ;
break ;
/*
* following two cases are taken from fs / ext2 / ioctl . c by Remy
* Card ( card @ masi . ibp . fr )
*/
2005-04-17 02:20:36 +04:00
case REISERFS_IOC_GETVERSION :
2009-10-15 01:08:43 +04:00
err = put_user ( inode - > i_generation , ( int __user * ) arg ) ;
break ;
2005-04-17 02:20:36 +04:00
case REISERFS_IOC_SETVERSION :
2021-01-21 16:19:25 +03:00
if ( ! inode_owner_or_capable ( & init_user_ns , inode ) ) {
2009-10-15 01:08:43 +04:00
err = - EPERM ;
break ;
2010-01-07 01:09:50 +03:00
}
2011-11-23 20:57:51 +04:00
err = mnt_want_write_file ( filp ) ;
2008-02-16 01:37:46 +03:00
if ( err )
2009-10-15 01:08:43 +04:00
break ;
2008-02-16 01:37:46 +03:00
if ( get_user ( inode - > i_generation , ( int __user * ) arg ) ) {
err = - EFAULT ;
goto setversion_out ;
}
2016-09-14 17:48:05 +03:00
inode - > i_ctime = current_time ( inode ) ;
2005-04-17 02:20:36 +04:00
mark_inode_dirty ( inode ) ;
2008-02-16 01:37:46 +03:00
setversion_out :
2011-12-09 17:06:57 +04:00
mnt_drop_write_file ( filp ) ;
2009-10-15 01:08:43 +04:00
break ;
2005-04-17 02:20:36 +04:00
default :
2009-10-15 01:08:43 +04:00
err = - ENOTTY ;
2005-04-17 02:20:36 +04:00
}
2009-10-15 01:08:43 +04:00
reiserfs_write_unlock ( inode - > i_sb ) ;
return err ;
2005-04-17 02:20:36 +04:00
}
2006-08-29 22:06:18 +04:00
# ifdef CONFIG_COMPAT
long reiserfs_compat_ioctl ( struct file * file , unsigned int cmd ,
unsigned long arg )
{
2014-04-23 18:00:36 +04:00
/*
* These are just misnamed , they actually
* get / put from / to user an int
*/
2006-08-29 22:06:18 +04:00
switch ( cmd ) {
case REISERFS_IOC32_UNPACK :
cmd = REISERFS_IOC_UNPACK ;
break ;
case REISERFS_IOC32_GETVERSION :
cmd = REISERFS_IOC_GETVERSION ;
break ;
case REISERFS_IOC32_SETVERSION :
cmd = REISERFS_IOC_SETVERSION ;
break ;
default :
return - ENOIOCTLCMD ;
}
reiserfs: kill-the-BKL
This patch is an attempt to remove the Bkl based locking scheme from
reiserfs and is intended.
It is a bit inspired from an old attempt by Peter Zijlstra:
http://lkml.indiana.edu/hypermail/linux/kernel/0704.2/2174.html
The bkl is heavily used in this filesystem to prevent from
concurrent write accesses on the filesystem.
Reiserfs makes a deep use of the specific properties of the Bkl:
- It can be acqquired recursively by a same task
- It is released on the schedule() calls and reacquired when schedule() returns
The two properties above are a roadmap for the reiserfs write locking so it's
very hard to simply replace it with a common mutex.
- We need a recursive-able locking unless we want to restructure several blocks
of the code.
- We need to identify the sites where the bkl was implictly relaxed
(schedule, wait, sync, etc...) so that we can in turn release and
reacquire our new lock explicitly.
Such implicit releases of the lock are often required to let other
resources producer/consumer do their job or we can suffer unexpected
starvations or deadlocks.
So the new lock that replaces the bkl here is a per superblock mutex with a
specific property: it can be acquired recursively by a same task, like the
bkl.
For such purpose, we integrate a lock owner and a lock depth field on the
superblock information structure.
The first axis on this patch is to turn reiserfs_write_(un)lock() function
into a wrapper to manage this mutex. Also some explicit calls to
lock_kernel() have been converted to reiserfs_write_lock() helpers.
The second axis is to find the important blocking sites (schedule...(),
wait_on_buffer(), sync_dirty_buffer(), etc...) and then apply an explicit
release of the write lock on these locations before blocking. Then we can
safely wait for those who can give us resources or those who need some.
Typically this is a fight between the current writer, the reiserfs workqueue
(aka the async commiter) and the pdflush threads.
The third axis is a consequence of the second. The write lock is usually
on top of a lock dependency chain which can include the journal lock, the
flush lock or the commit lock. So it's dangerous to release and trying to
reacquire the write lock while we still hold other locks.
This is fine with the bkl:
T1 T2
lock_kernel()
mutex_lock(A)
unlock_kernel()
// do something
lock_kernel()
mutex_lock(A) -> already locked by T1
schedule() (and then unlock_kernel())
lock_kernel()
mutex_unlock(A)
....
This is not fine with a mutex:
T1 T2
mutex_lock(write)
mutex_lock(A)
mutex_unlock(write)
// do something
mutex_lock(write)
mutex_lock(A) -> already locked by T1
schedule()
mutex_lock(write) -> already locked by T2
deadlock
The solution in this patch is to provide a helper which releases the write
lock and sleep a bit if we can't lock a mutex that depend on it. It's another
simulation of the bkl behaviour.
The last axis is to locate the fs callbacks that are called with the bkl held,
according to Documentation/filesystem/Locking.
Those are:
- reiserfs_remount
- reiserfs_fill_super
- reiserfs_put_super
Reiserfs didn't need to explicitly lock because of the context of these callbacks.
But now we must take care of that with the new locking.
After this patch, reiserfs suffers from a slight performance regression (for now).
On UP, a high volume write with dd reports an average of 27 MB/s instead
of 30 MB/s without the patch applied.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Cc: Jeff Mahoney <jeffm@suse.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Bron Gondwana <brong@fastmail.fm>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
LKML-Reference: <1239070789-13354-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-07 06:19:49 +04:00
2009-10-15 01:22:17 +04:00
return reiserfs_ioctl ( file , cmd , ( unsigned long ) compat_ptr ( arg ) ) ;
2006-08-29 22:06:18 +04:00
}
# endif
2007-10-16 12:25:14 +04:00
int reiserfs_commit_write ( struct file * f , struct page * page ,
unsigned from , unsigned to ) ;
2005-04-17 02:20:36 +04:00
/*
2014-04-23 18:00:36 +04:00
* reiserfs_unpack
* Function try to convert tail from direct item into indirect .
* It set up nopack attribute in the REISERFS_I ( inode ) - > nopack
*/
2021-04-07 15:36:44 +03:00
int reiserfs_unpack ( struct inode * inode )
2005-04-17 02:20:36 +04:00
{
2005-07-13 07:21:28 +04:00
int retval = 0 ;
int index ;
struct page * page ;
struct address_space * mapping ;
unsigned long write_from ;
unsigned long blocksize = inode - > i_sb - > s_blocksize ;
if ( inode - > i_size = = 0 ) {
REISERFS_I ( inode ) - > i_flags | = i_nopack_mask ;
return 0 ;
}
/* ioctl already done */
if ( REISERFS_I ( inode ) - > i_flags & i_nopack_mask ) {
return 0 ;
}
2010-11-24 23:57:15 +03:00
/* we need to make sure nobody is changing the file size beneath us */
2020-04-07 06:11:46 +03:00
{
int depth = reiserfs_write_unlock_nested ( inode - > i_sb ) ;
inode_lock ( inode ) ;
reiserfs_write_lock_nested ( inode - > i_sb , depth ) ;
}
2010-11-24 23:57:15 +03:00
2013-08-09 01:34:46 +04:00
reiserfs_write_lock ( inode - > i_sb ) ;
2005-07-13 07:21:28 +04:00
write_from = inode - > i_size & ( blocksize - 1 ) ;
/* if we are on a block boundary, we are already unpacked. */
if ( write_from = = 0 ) {
REISERFS_I ( inode ) - > i_flags | = i_nopack_mask ;
goto out ;
}
2014-04-23 18:00:36 +04:00
/*
* we unpack by finding the page with the tail , and calling
* __reiserfs_write_begin on that page . This will force a
* reiserfs_get_block to unpack the tail for us .
2005-07-13 07:21:28 +04:00
*/
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
index = inode - > i_size > > PAGE_SHIFT ;
2005-07-13 07:21:28 +04:00
mapping = inode - > i_mapping ;
page = grab_cache_page ( mapping , index ) ;
retval = - ENOMEM ;
if ( ! page ) {
goto out ;
}
2010-10-06 12:47:23 +04:00
retval = __reiserfs_write_begin ( page , write_from , 0 ) ;
2005-07-13 07:21:28 +04:00
if ( retval )
goto out_unlock ;
/* conversion can change page contents, must flush */
flush_dcache_page ( page ) ;
2007-10-16 12:25:14 +04:00
retval = reiserfs_commit_write ( NULL , page , write_from , write_from ) ;
2005-04-17 02:20:36 +04:00
REISERFS_I ( inode ) - > i_flags | = i_nopack_mask ;
2005-07-13 07:21:28 +04:00
2014-04-23 18:00:41 +04:00
out_unlock :
2005-07-13 07:21:28 +04:00
unlock_page ( page ) ;
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
put_page ( page ) ;
2005-07-13 07:21:28 +04:00
2014-04-23 18:00:41 +04:00
out :
2016-01-22 23:40:57 +03:00
inode_unlock ( inode ) ;
2013-08-09 01:34:46 +04:00
reiserfs_write_unlock ( inode - > i_sb ) ;
2005-07-13 07:21:28 +04:00
return retval ;
2005-04-17 02:20:36 +04:00
}