2009-11-21 02:13:39 +07:00
|
|
|
/*
|
|
|
|
* fs/logfs/dir.c - directory-related code
|
|
|
|
*
|
|
|
|
* As should be obvious for Linux kernel code, license is GPLv2
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2008 Joern Engel <joern@logfs.org>
|
|
|
|
*/
|
|
|
|
#include "logfs.h"
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Atomic dir operations
|
|
|
|
*
|
|
|
|
* Directory operations are by default not atomic. Dentries and Inodes are
|
2010-05-10 16:21:19 +07:00
|
|
|
* created/removed/altered in separate operations. Therefore we need to do
|
2009-11-21 02:13:39 +07:00
|
|
|
* a small amount of journaling.
|
|
|
|
*
|
|
|
|
* Create, link, mkdir, mknod and symlink all share the same function to do
|
|
|
|
* the work: __logfs_create. This function works in two atomic steps:
|
|
|
|
* 1. allocate inode (remember in journal)
|
|
|
|
* 2. allocate dentry (clear journal)
|
|
|
|
*
|
|
|
|
* As we can only get interrupted between the two, when the inode we just
|
|
|
|
* created is simply stored in the anchor. On next mount, if we were
|
|
|
|
* interrupted, we delete the inode. From a users point of view the
|
|
|
|
* operation never happened.
|
|
|
|
*
|
|
|
|
* Unlink and rmdir also share the same function: unlink. Again, this
|
|
|
|
* function works in two atomic steps
|
|
|
|
* 1. remove dentry (remember inode in journal)
|
|
|
|
* 2. unlink inode (clear journal)
|
|
|
|
*
|
|
|
|
* And again, on the next mount, if we were interrupted, we delete the inode.
|
|
|
|
* From a users point of view the operation succeeded.
|
|
|
|
*
|
|
|
|
* Rename is the real pain to deal with, harder than all the other methods
|
|
|
|
* combined. Depending on the circumstances we can run into three cases.
|
|
|
|
* A "target rename" where the target dentry already existed, a "local
|
|
|
|
* rename" where both parent directories are identical or a "cross-directory
|
|
|
|
* rename" in the remaining case.
|
|
|
|
*
|
|
|
|
* Local rename is atomic, as the old dentry is simply rewritten with a new
|
|
|
|
* name.
|
|
|
|
*
|
|
|
|
* Cross-directory rename works in two steps, similar to __logfs_create and
|
|
|
|
* logfs_unlink:
|
|
|
|
* 1. Write new dentry (remember old dentry in journal)
|
|
|
|
* 2. Remove old dentry (clear journal)
|
|
|
|
*
|
|
|
|
* Here we remember a dentry instead of an inode. On next mount, if we were
|
|
|
|
* interrupted, we delete the dentry. From a users point of view, the
|
|
|
|
* operation succeeded.
|
|
|
|
*
|
|
|
|
* Target rename works in three atomic steps:
|
|
|
|
* 1. Attach old inode to new dentry (remember old dentry and new inode)
|
|
|
|
* 2. Remove old dentry (still remember the new inode)
|
|
|
|
* 3. Remove victim inode
|
|
|
|
*
|
|
|
|
* Here we remember both an inode an a dentry. If we get interrupted
|
|
|
|
* between steps 1 and 2, we delete both the dentry and the inode. If
|
|
|
|
* we get interrupted between steps 2 and 3, we delete just the inode.
|
|
|
|
* In either case, the remaining objects are deleted on next mount. From
|
|
|
|
* a users point of view, the operation succeeded.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int write_dir(struct inode *dir, struct logfs_disk_dentry *dd,
|
|
|
|
loff_t pos)
|
|
|
|
{
|
|
|
|
return logfs_inode_write(dir, dd, sizeof(*dd), pos, WF_LOCK, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int write_inode(struct inode *inode)
|
|
|
|
{
|
2011-10-03 01:16:51 +07:00
|
|
|
return __logfs_write_inode(inode, NULL, WF_LOCK);
|
2009-11-21 02:13:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static s64 dir_seek_data(struct inode *inode, s64 pos)
|
|
|
|
{
|
|
|
|
s64 new_pos = logfs_seek_data(inode, pos);
|
|
|
|
|
|
|
|
return max(pos, new_pos - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int beyond_eof(struct inode *inode, loff_t bix)
|
|
|
|
{
|
|
|
|
loff_t pos = bix << inode->i_sb->s_blocksize_bits;
|
|
|
|
return pos >= i_size_read(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prime value was chosen to be roughly 256 + 26. r5 hash uses 11,
|
|
|
|
* so short names (len <= 9) don't even occupy the complete 32bit name
|
|
|
|
* space. A prime >256 ensures short names quickly spread the 32bit
|
|
|
|
* name space. Add about 26 for the estimated amount of information
|
2011-03-31 08:57:33 +07:00
|
|
|
* of each character and pick a prime nearby, preferably a bit-sparse
|
2009-11-21 02:13:39 +07:00
|
|
|
* one.
|
|
|
|
*/
|
2016-07-29 02:26:31 +07:00
|
|
|
static u32 logfs_hash_32(const char *s, int len, u32 seed)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
|
|
|
u32 hash = seed;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
hash = hash * 293 + s[i];
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to satisfy several conflicting requirements here. Small
|
|
|
|
* directories should stay fairly compact and not require too many
|
|
|
|
* indirect blocks. The number of possible locations for a given hash
|
|
|
|
* should be small to make lookup() fast. And we should try hard not
|
|
|
|
* to overflow the 32bit name space or nfs and 32bit host systems will
|
|
|
|
* be unhappy.
|
|
|
|
*
|
|
|
|
* So we use the following scheme. First we reduce the hash to 0..15
|
|
|
|
* and try a direct block. If that is occupied we reduce the hash to
|
|
|
|
* 16..255 and try an indirect block. Same for 2x and 3x indirect
|
|
|
|
* blocks. Lastly we reduce the hash to 0x800_0000 .. 0xffff_ffff,
|
|
|
|
* but use buckets containing eight entries instead of a single one.
|
|
|
|
*
|
|
|
|
* Using 16 entries should allow for a reasonable amount of hash
|
|
|
|
* collisions, so the 32bit name space can be packed fairly tight
|
|
|
|
* before overflowing. Oh and currently we don't overflow but return
|
|
|
|
* and error.
|
|
|
|
*
|
|
|
|
* How likely are collisions? Doing the appropriate math is beyond me
|
|
|
|
* and the Bronstein textbook. But running a test program to brute
|
|
|
|
* force collisions for a couple of days showed that on average the
|
|
|
|
* first collision occurs after 598M entries, with 290M being the
|
|
|
|
* smallest result. Obviously 21 entries could already cause a
|
|
|
|
* collision if all entries are carefully chosen.
|
|
|
|
*/
|
|
|
|
static pgoff_t hash_index(u32 hash, int round)
|
|
|
|
{
|
2009-11-28 19:14:08 +07:00
|
|
|
u32 i0_blocks = I0_BLOCKS;
|
|
|
|
u32 i1_blocks = I1_BLOCKS;
|
|
|
|
u32 i2_blocks = I2_BLOCKS;
|
|
|
|
u32 i3_blocks = I3_BLOCKS;
|
|
|
|
|
2009-11-21 02:13:39 +07:00
|
|
|
switch (round) {
|
|
|
|
case 0:
|
2009-11-28 19:14:08 +07:00
|
|
|
return hash % i0_blocks;
|
2009-11-21 02:13:39 +07:00
|
|
|
case 1:
|
2009-11-28 19:14:08 +07:00
|
|
|
return i0_blocks + hash % (i1_blocks - i0_blocks);
|
2009-11-21 02:13:39 +07:00
|
|
|
case 2:
|
2009-11-28 19:14:08 +07:00
|
|
|
return i1_blocks + hash % (i2_blocks - i1_blocks);
|
2009-11-21 02:13:39 +07:00
|
|
|
case 3:
|
2009-11-28 19:14:08 +07:00
|
|
|
return i2_blocks + hash % (i3_blocks - i2_blocks);
|
2009-11-21 02:13:39 +07:00
|
|
|
case 4 ... 19:
|
2009-11-28 19:14:08 +07:00
|
|
|
return i3_blocks + 16 * (hash % (((1<<31) - i3_blocks) / 16))
|
2009-11-21 02:13:39 +07:00
|
|
|
+ round - 4;
|
|
|
|
}
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct page *logfs_get_dd_page(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2016-07-21 03:11:45 +07:00
|
|
|
const struct qstr *name = &dentry->d_name;
|
2009-11-21 02:13:39 +07:00
|
|
|
struct page *page;
|
|
|
|
struct logfs_disk_dentry *dd;
|
2016-07-29 02:26:31 +07:00
|
|
|
u32 hash = logfs_hash_32(name->name, name->len, 0);
|
2009-11-21 02:13:39 +07:00
|
|
|
pgoff_t index;
|
|
|
|
int round;
|
|
|
|
|
|
|
|
if (name->len > LOGFS_MAX_NAMELEN)
|
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
|
|
|
|
|
|
|
for (round = 0; round < 20; round++) {
|
|
|
|
index = hash_index(hash, round);
|
|
|
|
|
|
|
|
if (beyond_eof(dir, index))
|
|
|
|
return NULL;
|
|
|
|
if (!logfs_exist_block(dir, index))
|
|
|
|
continue;
|
|
|
|
page = read_cache_page(dir->i_mapping, index,
|
|
|
|
(filler_t *)logfs_readpage, NULL);
|
|
|
|
if (IS_ERR(page))
|
|
|
|
return page;
|
2011-11-25 22:14:31 +07:00
|
|
|
dd = kmap_atomic(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
BUG_ON(dd->namelen == 0);
|
|
|
|
|
|
|
|
if (name->len != be16_to_cpu(dd->namelen) ||
|
|
|
|
memcmp(name->name, dd->name, name->len)) {
|
2011-11-25 22:14:31 +07:00
|
|
|
kunmap_atomic(dd);
|
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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-25 22:14:31 +07:00
|
|
|
kunmap_atomic(dd);
|
2009-11-21 02:13:39 +07:00
|
|
|
return page;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_remove_inode(struct inode *inode)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-10-28 19:13:28 +07:00
|
|
|
drop_nlink(inode);
|
2009-11-21 02:13:39 +07:00
|
|
|
ret = write_inode(inode);
|
|
|
|
LOGFS_BUG_ON(ret, inode->i_sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void abort_transaction(struct inode *inode, struct logfs_transaction *ta)
|
|
|
|
{
|
|
|
|
if (logfs_inode(inode)->li_block)
|
|
|
|
logfs_inode(inode)->li_block->ta = NULL;
|
|
|
|
kfree(ta);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(dir->i_sb);
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2009-11-21 02:13:39 +07:00
|
|
|
struct logfs_transaction *ta;
|
|
|
|
struct page *page;
|
|
|
|
pgoff_t index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ta = kzalloc(sizeof(*ta), GFP_KERNEL);
|
|
|
|
if (!ta)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ta->state = UNLINK_1;
|
|
|
|
ta->ino = inode->i_ino;
|
|
|
|
|
|
|
|
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
|
|
|
|
|
|
|
|
page = logfs_get_dd_page(dir, dentry);
|
2009-11-23 20:29:12 +07:00
|
|
|
if (!page) {
|
|
|
|
kfree(ta);
|
2009-11-21 02:13:39 +07:00
|
|
|
return -ENOENT;
|
2009-11-23 20:29:12 +07:00
|
|
|
}
|
|
|
|
if (IS_ERR(page)) {
|
|
|
|
kfree(ta);
|
2009-11-21 02:13:39 +07:00
|
|
|
return PTR_ERR(page);
|
2009-11-23 20:29:12 +07:00
|
|
|
}
|
2009-11-21 02:13:39 +07:00
|
|
|
index = page->index;
|
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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
mutex_lock(&super->s_dirop_mutex);
|
|
|
|
logfs_add_transaction(dir, ta);
|
|
|
|
|
|
|
|
ret = logfs_delete(dir, index, NULL);
|
|
|
|
if (!ret)
|
|
|
|
ret = write_inode(dir);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
abort_transaction(dir, ta);
|
|
|
|
printk(KERN_ERR"LOGFS: unable to delete inode\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ta->state = UNLINK_2;
|
|
|
|
logfs_add_transaction(inode, ta);
|
|
|
|
ret = logfs_remove_inode(inode);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&super->s_dirop_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int logfs_empty_dir(struct inode *dir)
|
|
|
|
{
|
|
|
|
u64 data;
|
|
|
|
|
|
|
|
data = logfs_seek_data(dir, 0) << dir->i_sb->s_blocksize_bits;
|
|
|
|
return data >= i_size_read(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
if (!logfs_empty_dir(inode))
|
|
|
|
return -ENOTEMPTY;
|
|
|
|
|
|
|
|
return logfs_unlink(dir, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: readdir currently has it's own dir_walk code. I don't see a good
|
|
|
|
* way to combine the two copies */
|
2013-05-18 04:06:34 +07:00
|
|
|
static int logfs_readdir(struct file *file, struct dir_context *ctx)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *dir = file_inode(file);
|
2013-05-18 04:06:34 +07:00
|
|
|
loff_t pos;
|
2009-11-21 02:13:39 +07:00
|
|
|
struct page *page;
|
|
|
|
struct logfs_disk_dentry *dd;
|
|
|
|
|
2013-05-18 04:06:34 +07:00
|
|
|
if (ctx->pos < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!dir_emit_dots(file, ctx))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pos = ctx->pos - 2;
|
2009-11-21 02:13:39 +07:00
|
|
|
BUG_ON(pos < 0);
|
2013-05-18 04:06:34 +07:00
|
|
|
for (;; pos++, ctx->pos++) {
|
|
|
|
bool full;
|
2009-11-21 02:13:39 +07:00
|
|
|
if (beyond_eof(dir, pos))
|
|
|
|
break;
|
|
|
|
if (!logfs_exist_block(dir, pos)) {
|
|
|
|
/* deleted dentry */
|
|
|
|
pos = dir_seek_data(dir, pos);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
page = read_cache_page(dir->i_mapping, pos,
|
|
|
|
(filler_t *)logfs_readpage, NULL);
|
|
|
|
if (IS_ERR(page))
|
|
|
|
return PTR_ERR(page);
|
2010-03-17 22:00:07 +07:00
|
|
|
dd = kmap(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
BUG_ON(dd->namelen == 0);
|
|
|
|
|
2013-05-18 04:06:34 +07:00
|
|
|
full = !dir_emit(ctx, (char *)dd->name,
|
|
|
|
be16_to_cpu(dd->namelen),
|
|
|
|
be64_to_cpu(dd->ino), dd->type);
|
2010-03-17 22:00:07 +07:00
|
|
|
kunmap(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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
if (full)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-21 03:11:45 +07:00
|
|
|
static void logfs_set_name(struct logfs_disk_dentry *dd, const struct qstr *name)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
|
|
|
dd->namelen = cpu_to_be16(name->len);
|
|
|
|
memcpy(dd->name, name->name, name->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *logfs_lookup(struct inode *dir, struct dentry *dentry,
|
2012-06-11 04:13:09 +07:00
|
|
|
unsigned int flags)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
struct logfs_disk_dentry *dd;
|
|
|
|
pgoff_t index;
|
|
|
|
u64 ino = 0;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
page = logfs_get_dd_page(dir, dentry);
|
|
|
|
if (IS_ERR(page))
|
|
|
|
return ERR_CAST(page);
|
|
|
|
if (!page) {
|
|
|
|
d_add(dentry, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
index = page->index;
|
2011-11-25 22:14:31 +07:00
|
|
|
dd = kmap_atomic(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
ino = be64_to_cpu(dd->ino);
|
2011-11-25 22:14:31 +07:00
|
|
|
kunmap_atomic(dd);
|
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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
inode = logfs_iget(dir->i_sb, ino);
|
2011-07-09 08:20:11 +07:00
|
|
|
if (IS_ERR(inode))
|
2009-11-21 02:13:39 +07:00
|
|
|
printk(KERN_ERR"LogFS: Cannot read inode #%llx for dentry (%lx, %lx)n",
|
|
|
|
ino, dir->i_ino, index);
|
|
|
|
return d_splice_alias(inode, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void grow_dir(struct inode *dir, loff_t index)
|
|
|
|
{
|
|
|
|
index = (index + 1) << dir->i_sb->s_blocksize_bits;
|
|
|
|
if (i_size_read(dir) < index)
|
|
|
|
i_size_write(dir, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_write_dir(struct inode *dir, struct dentry *dentry,
|
|
|
|
struct inode *inode)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
struct logfs_disk_dentry *dd;
|
2016-07-29 02:26:31 +07:00
|
|
|
u32 hash = logfs_hash_32(dentry->d_name.name, dentry->d_name.len, 0);
|
2009-11-21 02:13:39 +07:00
|
|
|
pgoff_t index;
|
|
|
|
int round, err;
|
|
|
|
|
|
|
|
for (round = 0; round < 20; round++) {
|
|
|
|
index = hash_index(hash, round);
|
|
|
|
|
|
|
|
if (logfs_exist_block(dir, index))
|
|
|
|
continue;
|
|
|
|
page = find_or_create_page(dir->i_mapping, index, GFP_KERNEL);
|
|
|
|
if (!page)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-11-25 22:14:31 +07:00
|
|
|
dd = kmap_atomic(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
memset(dd, 0, sizeof(*dd));
|
|
|
|
dd->ino = cpu_to_be64(inode->i_ino);
|
|
|
|
dd->type = logfs_type(inode);
|
|
|
|
logfs_set_name(dd, &dentry->d_name);
|
2011-11-25 22:14:31 +07:00
|
|
|
kunmap_atomic(dd);
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
err = logfs_write_buf(dir, page, WF_LOCK);
|
|
|
|
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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
if (!err)
|
|
|
|
grow_dir(dir, index);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/* FIXME: Is there a better return value? In most cases neither
|
|
|
|
* the filesystem nor the directory are full. But we have had
|
|
|
|
* too many collisions for this particular hash and no fallback.
|
|
|
|
*/
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __logfs_create(struct inode *dir, struct dentry *dentry,
|
|
|
|
struct inode *inode, const char *dest, long destlen)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(dir->i_sb);
|
|
|
|
struct logfs_inode *li = logfs_inode(inode);
|
|
|
|
struct logfs_transaction *ta;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ta = kzalloc(sizeof(*ta), GFP_KERNEL);
|
2010-07-04 15:23:11 +07:00
|
|
|
if (!ta) {
|
2011-10-28 19:13:28 +07:00
|
|
|
drop_nlink(inode);
|
2010-07-04 15:23:11 +07:00
|
|
|
iput(inode);
|
2009-11-21 02:13:39 +07:00
|
|
|
return -ENOMEM;
|
2010-07-04 15:23:11 +07:00
|
|
|
}
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
ta->state = CREATE_1;
|
|
|
|
ta->ino = inode->i_ino;
|
|
|
|
mutex_lock(&super->s_dirop_mutex);
|
|
|
|
logfs_add_transaction(inode, ta);
|
|
|
|
|
|
|
|
if (dest) {
|
|
|
|
/* symlink */
|
|
|
|
ret = logfs_inode_write(inode, dest, destlen, 0, WF_LOCK, NULL);
|
|
|
|
if (!ret)
|
|
|
|
ret = write_inode(inode);
|
|
|
|
} else {
|
|
|
|
/* creat/mkdir/mknod */
|
|
|
|
ret = write_inode(inode);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
abort_transaction(inode, ta);
|
|
|
|
li->li_flags |= LOGFS_IF_STILLBORN;
|
|
|
|
/* FIXME: truncate symlink */
|
2011-10-28 19:13:28 +07:00
|
|
|
drop_nlink(inode);
|
2009-11-21 02:13:39 +07:00
|
|
|
iput(inode);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ta->state = CREATE_2;
|
|
|
|
logfs_add_transaction(dir, ta);
|
|
|
|
ret = logfs_write_dir(dir, dentry, inode);
|
|
|
|
/* sync directory */
|
|
|
|
if (!ret)
|
|
|
|
ret = write_inode(dir);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
logfs_del_transaction(dir, ta);
|
|
|
|
ta->state = CREATE_2;
|
|
|
|
logfs_add_transaction(inode, ta);
|
|
|
|
logfs_remove_inode(inode);
|
|
|
|
iput(inode);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&super->s_dirop_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-26 12:41:39 +07:00
|
|
|
static int logfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: why do we have to fill in S_IFDIR, while the mode is
|
|
|
|
* correct for mknod, creat, etc.? Smells like the vfs *should*
|
|
|
|
* do it for us but for some reason fails to do so.
|
|
|
|
*/
|
|
|
|
inode = logfs_new_inode(dir, S_IFDIR | mode);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
inode->i_op = &logfs_dir_iops;
|
|
|
|
inode->i_fop = &logfs_dir_fops;
|
|
|
|
|
|
|
|
return __logfs_create(dir, dentry, inode, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2011-07-26 12:42:34 +07:00
|
|
|
static int logfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
2012-06-11 05:05:36 +07:00
|
|
|
bool excl)
|
2009-11-21 02:13:39 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
inode = logfs_new_inode(dir, mode);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
inode->i_op = &logfs_reg_iops;
|
|
|
|
inode->i_fop = &logfs_reg_fops;
|
|
|
|
inode->i_mapping->a_ops = &logfs_reg_aops;
|
|
|
|
|
|
|
|
return __logfs_create(dir, dentry, inode, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2011-07-26 12:52:52 +07:00
|
|
|
static int logfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
|
2009-11-21 02:13:39 +07:00
|
|
|
dev_t rdev)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
if (dentry->d_name.len > LOGFS_MAX_NAMELEN)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
inode = logfs_new_inode(dir, mode);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
|
|
|
init_special_inode(inode, mode, rdev);
|
|
|
|
|
|
|
|
return __logfs_create(dir, dentry, inode, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_symlink(struct inode *dir, struct dentry *dentry,
|
|
|
|
const char *target)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
size_t destlen = strlen(target) + 1;
|
|
|
|
|
|
|
|
if (destlen > dir->i_sb->s_blocksize)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
inode = logfs_new_inode(dir, S_IFLNK | 0777);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
|
|
|
|
2015-11-14 05:23:54 +07:00
|
|
|
inode->i_op = &page_symlink_inode_operations;
|
2015-11-17 13:07:57 +07:00
|
|
|
inode_nohighmem(inode);
|
2009-11-21 02:13:39 +07:00
|
|
|
inode->i_mapping->a_ops = &logfs_reg_aops;
|
|
|
|
|
|
|
|
return __logfs_create(dir, dentry, inode, target, destlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(old_dentry);
|
2009-11-21 02:13:39 +07:00
|
|
|
|
|
|
|
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
|
2010-10-23 22:11:40 +07:00
|
|
|
ihold(inode);
|
2011-10-28 19:13:28 +07:00
|
|
|
inc_nlink(inode);
|
2009-11-21 02:13:39 +07:00
|
|
|
mark_inode_dirty_sync(inode);
|
|
|
|
|
|
|
|
return __logfs_create(dir, dentry, inode, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_get_dd(struct inode *dir, struct dentry *dentry,
|
|
|
|
struct logfs_disk_dentry *dd, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
void *map;
|
|
|
|
|
|
|
|
page = logfs_get_dd_page(dir, dentry);
|
|
|
|
if (IS_ERR(page))
|
|
|
|
return PTR_ERR(page);
|
|
|
|
*pos = page->index;
|
2011-11-25 22:14:31 +07:00
|
|
|
map = kmap_atomic(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
memcpy(dd, map, sizeof(*dd));
|
2011-11-25 22:14:31 +07:00
|
|
|
kunmap_atomic(map);
|
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 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-11-21 02:13:39 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_delete_dd(struct inode *dir, loff_t pos)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Getting called with pos somewhere beyond eof is either a goofup
|
|
|
|
* within this file or means someone maliciously edited the
|
|
|
|
* (crc-protected) journal.
|
|
|
|
*/
|
|
|
|
BUG_ON(beyond_eof(dir, pos));
|
|
|
|
dir->i_ctime = dir->i_mtime = CURRENT_TIME;
|
|
|
|
log_dir(" Delete dentry (%lx, %llx)\n", dir->i_ino, pos);
|
|
|
|
return logfs_delete(dir, pos, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cross-directory rename, target does not exist. Just a little nasty.
|
|
|
|
* Create a new dentry in the target dir, then remove the old dentry,
|
|
|
|
* all the while taking care to remember our operation in the journal.
|
|
|
|
*/
|
|
|
|
static int logfs_rename_cross(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(old_dir->i_sb);
|
|
|
|
struct logfs_disk_dentry dd;
|
|
|
|
struct logfs_transaction *ta;
|
|
|
|
loff_t pos;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* 1. locate source dd */
|
|
|
|
err = logfs_get_dd(old_dir, old_dentry, &dd, &pos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ta = kzalloc(sizeof(*ta), GFP_KERNEL);
|
|
|
|
if (!ta)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ta->state = CROSS_RENAME_1;
|
|
|
|
ta->dir = old_dir->i_ino;
|
|
|
|
ta->pos = pos;
|
|
|
|
|
|
|
|
/* 2. write target dd */
|
|
|
|
mutex_lock(&super->s_dirop_mutex);
|
|
|
|
logfs_add_transaction(new_dir, ta);
|
2015-03-18 05:25:59 +07:00
|
|
|
err = logfs_write_dir(new_dir, new_dentry, d_inode(old_dentry));
|
2009-11-21 02:13:39 +07:00
|
|
|
if (!err)
|
|
|
|
err = write_inode(new_dir);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
super->s_rename_dir = 0;
|
|
|
|
super->s_rename_pos = 0;
|
|
|
|
abort_transaction(new_dir, ta);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3. remove source dd */
|
|
|
|
ta->state = CROSS_RENAME_2;
|
|
|
|
logfs_add_transaction(old_dir, ta);
|
|
|
|
err = logfs_delete_dd(old_dir, pos);
|
|
|
|
if (!err)
|
|
|
|
err = write_inode(old_dir);
|
|
|
|
LOGFS_BUG_ON(err, old_dir->i_sb);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&super->s_dirop_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_replace_inode(struct inode *dir, struct dentry *dentry,
|
|
|
|
struct logfs_disk_dentry *dd, struct inode *inode)
|
|
|
|
{
|
|
|
|
loff_t pos;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = logfs_get_dd(dir, dentry, dd, &pos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
dd->ino = cpu_to_be64(inode->i_ino);
|
|
|
|
dd->type = logfs_type(inode);
|
|
|
|
|
|
|
|
err = write_dir(dir, dd, pos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
log_dir("Replace dentry (%lx, %llx) %s -> %llx\n", dir->i_ino, pos,
|
|
|
|
dd->name, be64_to_cpu(dd->ino));
|
|
|
|
return write_inode(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Target dentry exists - the worst case. We need to attach the source
|
|
|
|
* inode to the target dentry, then remove the orphaned target inode and
|
|
|
|
* source dentry.
|
|
|
|
*/
|
|
|
|
static int logfs_rename_target(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(old_dir->i_sb);
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *old_inode = d_inode(old_dentry);
|
|
|
|
struct inode *new_inode = d_inode(new_dentry);
|
2009-11-21 02:13:39 +07:00
|
|
|
int isdir = S_ISDIR(old_inode->i_mode);
|
|
|
|
struct logfs_disk_dentry dd;
|
|
|
|
struct logfs_transaction *ta;
|
|
|
|
loff_t pos;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BUG_ON(isdir != S_ISDIR(new_inode->i_mode));
|
|
|
|
if (isdir) {
|
|
|
|
if (!logfs_empty_dir(new_inode))
|
|
|
|
return -ENOTEMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 1. locate source dd */
|
|
|
|
err = logfs_get_dd(old_dir, old_dentry, &dd, &pos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ta = kzalloc(sizeof(*ta), GFP_KERNEL);
|
|
|
|
if (!ta)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ta->state = TARGET_RENAME_1;
|
|
|
|
ta->dir = old_dir->i_ino;
|
|
|
|
ta->pos = pos;
|
|
|
|
ta->ino = new_inode->i_ino;
|
|
|
|
|
|
|
|
/* 2. attach source inode to target dd */
|
|
|
|
mutex_lock(&super->s_dirop_mutex);
|
|
|
|
logfs_add_transaction(new_dir, ta);
|
|
|
|
err = logfs_replace_inode(new_dir, new_dentry, &dd, old_inode);
|
|
|
|
if (err) {
|
|
|
|
super->s_rename_dir = 0;
|
|
|
|
super->s_rename_pos = 0;
|
|
|
|
super->s_victim_ino = 0;
|
|
|
|
abort_transaction(new_dir, ta);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3. remove source dd */
|
|
|
|
ta->state = TARGET_RENAME_2;
|
|
|
|
logfs_add_transaction(old_dir, ta);
|
|
|
|
err = logfs_delete_dd(old_dir, pos);
|
|
|
|
if (!err)
|
|
|
|
err = write_inode(old_dir);
|
|
|
|
LOGFS_BUG_ON(err, old_dir->i_sb);
|
|
|
|
|
|
|
|
/* 4. remove target inode */
|
|
|
|
ta->state = TARGET_RENAME_3;
|
|
|
|
logfs_add_transaction(new_inode, ta);
|
|
|
|
err = logfs_remove_inode(new_inode);
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&super->s_dirop_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int logfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
|
|
struct inode *new_dir, struct dentry *new_dentry)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
if (d_really_is_positive(new_dentry))
|
2009-11-21 02:13:39 +07:00
|
|
|
return logfs_rename_target(old_dir, old_dentry,
|
|
|
|
new_dir, new_dentry);
|
|
|
|
return logfs_rename_cross(old_dir, old_dentry, new_dir, new_dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No locking done here, as this is called before .get_sb() returns. */
|
|
|
|
int logfs_replay_journal(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct logfs_super *super = logfs_super(sb);
|
|
|
|
struct inode *inode;
|
|
|
|
u64 ino, pos;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (super->s_victim_ino) {
|
|
|
|
/* delete victim inode */
|
|
|
|
ino = super->s_victim_ino;
|
|
|
|
printk(KERN_INFO"LogFS: delete unmapped inode #%llx\n", ino);
|
|
|
|
inode = logfs_iget(sb, ino);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
LOGFS_BUG_ON(i_size_read(inode) > 0, sb);
|
|
|
|
super->s_victim_ino = 0;
|
|
|
|
err = logfs_remove_inode(inode);
|
|
|
|
iput(inode);
|
|
|
|
if (err) {
|
|
|
|
super->s_victim_ino = ino;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (super->s_rename_dir) {
|
|
|
|
/* delete old dd from rename */
|
|
|
|
ino = super->s_rename_dir;
|
|
|
|
pos = super->s_rename_pos;
|
|
|
|
printk(KERN_INFO"LogFS: delete unbacked dentry (%llx, %llx)\n",
|
|
|
|
ino, pos);
|
|
|
|
inode = logfs_iget(sb, ino);
|
|
|
|
if (IS_ERR(inode))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
super->s_rename_dir = 0;
|
|
|
|
super->s_rename_pos = 0;
|
|
|
|
err = logfs_delete_dd(inode, pos);
|
|
|
|
iput(inode);
|
|
|
|
if (err) {
|
|
|
|
super->s_rename_dir = ino;
|
|
|
|
super->s_rename_pos = pos;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
LOGFS_BUG(sb);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct inode_operations logfs_dir_iops = {
|
|
|
|
.create = logfs_create,
|
|
|
|
.link = logfs_link,
|
|
|
|
.lookup = logfs_lookup,
|
|
|
|
.mkdir = logfs_mkdir,
|
|
|
|
.mknod = logfs_mknod,
|
|
|
|
.rename = logfs_rename,
|
|
|
|
.rmdir = logfs_rmdir,
|
|
|
|
.symlink = logfs_symlink,
|
|
|
|
.unlink = logfs_unlink,
|
|
|
|
};
|
|
|
|
const struct file_operations logfs_dir_fops = {
|
|
|
|
.fsync = logfs_fsync,
|
2010-04-28 03:30:06 +07:00
|
|
|
.unlocked_ioctl = logfs_ioctl,
|
2016-05-01 09:37:34 +07:00
|
|
|
.iterate_shared = logfs_readdir,
|
2009-11-21 02:13:39 +07:00
|
|
|
.read = generic_read_dir,
|
2016-05-05 03:24:04 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2009-11-21 02:13:39 +07:00
|
|
|
};
|