mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-27 06:04:23 +08:00
ubifs: Don't add xattr inode into orphan area
Now, the entire inode with its' xattrs are removed while replaying orphan nodes. There is no need to add xattr inodes into orphan area, which is based on the fact that xattr entries won't be cleared from disk before deleting xattr inodes, in another words, current logic can make sure that xattr inode be deleted in any cases even UBIFS not record xattr inode into orphan area. Let's looking for possible paths that could clear xattr entries from disk but leave the xattr inode on TNC: 1. unlink/tmpfile -> ubifs_jnl_update: inode(nlink=0) is written into bud LEB and added into orphan list, then: a. powercut: ubifs_tnc_remove_ino(xattr entry/inode can be found from TNC and being deleted) is invoked in replaying journal. b. commit + powercut: inode is written into orphan area, and ubifs_tnc_remove_ino is invoked in replaying orphan nodes. c. evicting + powercut: xattr inode(nlink=0) is written on disk, xattr is removed from TNC, gc could clear xattr entries from disk. ubifs_tnc_remove_ino will apply on inode and xattr inode in replaying journal, so lost xattr entries will make no influence. d. evicting + commit + powercut: xattr inode/entry are removed from index tree(on disk) by ubifs_jnl_write_inode, xattr inode is cleared from orphan area by ubifs_jnl_write_inode + commit. e. commit + evicting + powercut: inode is written into orphan area, then equivalent to c. 2. remove xattr -> ubifs_jnl_delete_xattr: xattr entry(inum=0) and xattr inode(nlink=0) is written into bud LEB, xattr entry/inode are removed from TNC, then: a. powercut: gc could clear xattr entries from disk, which won't affect deleting xattr entry from TNC. ubifs_tnc_remove_ino will apply on xattr inode in replaying journal, ubifs_tnc_remove_nm will apply on xattr entry in replaying journal. b. commit + powercut: xattr entry/inode are removed from index tree (on disk). Tracking xattr inode in orphan list is imported by commit988bec4131
("ubifs: orphan: Handle xattrs like files"), it aims to fix the similar problem described in commit7959cf3a75
("ubifs: journal: Handle xattrs like files"). Actually, the problem only exist in journal case but not the orphan case. So, we can remove the orphan tracking for xattr inodes. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
parent
02eb1846b7
commit
354c179663
@ -42,24 +42,30 @@
|
||||
|
||||
static int dbg_check_orphans(struct ubifs_info *c);
|
||||
|
||||
static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum,
|
||||
struct ubifs_orphan *parent_orphan)
|
||||
/**
|
||||
* ubifs_add_orphan - add an orphan.
|
||||
* @c: UBIFS file-system description object
|
||||
* @inum: orphan inode number
|
||||
*
|
||||
* Add an orphan. This function is called when an inodes link count drops to
|
||||
* zero.
|
||||
*/
|
||||
int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
|
||||
{
|
||||
struct ubifs_orphan *orphan, *o;
|
||||
struct rb_node **p, *parent = NULL;
|
||||
|
||||
orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_NOFS);
|
||||
if (!orphan)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
return -ENOMEM;
|
||||
orphan->inum = inum;
|
||||
orphan->new = 1;
|
||||
INIT_LIST_HEAD(&orphan->child_list);
|
||||
|
||||
spin_lock(&c->orphan_lock);
|
||||
if (c->tot_orphans >= c->max_orphans) {
|
||||
spin_unlock(&c->orphan_lock);
|
||||
kfree(orphan);
|
||||
return ERR_PTR(-ENFILE);
|
||||
return -ENFILE;
|
||||
}
|
||||
p = &c->orph_tree.rb_node;
|
||||
while (*p) {
|
||||
@ -73,7 +79,7 @@ static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum,
|
||||
ubifs_err(c, "orphaned twice");
|
||||
spin_unlock(&c->orphan_lock);
|
||||
kfree(orphan);
|
||||
return ERR_PTR(-EINVAL);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
c->tot_orphans += 1;
|
||||
@ -83,14 +89,9 @@ static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum,
|
||||
list_add_tail(&orphan->list, &c->orph_list);
|
||||
list_add_tail(&orphan->new_list, &c->orph_new);
|
||||
|
||||
if (parent_orphan) {
|
||||
list_add_tail(&orphan->child_list,
|
||||
&parent_orphan->child_list);
|
||||
}
|
||||
|
||||
spin_unlock(&c->orphan_lock);
|
||||
dbg_gen("ino %lu", (unsigned long)inum);
|
||||
return orphan;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ubifs_orphan *lookup_orphan(struct ubifs_info *c, ino_t inum)
|
||||
@ -144,59 +145,6 @@ static void orphan_delete(struct ubifs_info *c, struct ubifs_orphan *orph)
|
||||
__orphan_drop(c, orph);
|
||||
}
|
||||
|
||||
/**
|
||||
* ubifs_add_orphan - add an orphan.
|
||||
* @c: UBIFS file-system description object
|
||||
* @inum: orphan inode number
|
||||
*
|
||||
* Add an orphan. This function is called when an inodes link count drops to
|
||||
* zero.
|
||||
*/
|
||||
int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
|
||||
{
|
||||
int err = 0;
|
||||
ino_t xattr_inum;
|
||||
union ubifs_key key;
|
||||
struct ubifs_dent_node *xent, *pxent = NULL;
|
||||
struct fscrypt_name nm = {0};
|
||||
struct ubifs_orphan *xattr_orphan;
|
||||
struct ubifs_orphan *orphan;
|
||||
|
||||
orphan = orphan_add(c, inum, NULL);
|
||||
if (IS_ERR(orphan))
|
||||
return PTR_ERR(orphan);
|
||||
|
||||
lowest_xent_key(c, &key, inum);
|
||||
while (1) {
|
||||
xent = ubifs_tnc_next_ent(c, &key, &nm);
|
||||
if (IS_ERR(xent)) {
|
||||
err = PTR_ERR(xent);
|
||||
if (err == -ENOENT)
|
||||
break;
|
||||
kfree(pxent);
|
||||
return err;
|
||||
}
|
||||
|
||||
fname_name(&nm) = xent->name;
|
||||
fname_len(&nm) = le16_to_cpu(xent->nlen);
|
||||
xattr_inum = le64_to_cpu(xent->inum);
|
||||
|
||||
xattr_orphan = orphan_add(c, xattr_inum, orphan);
|
||||
if (IS_ERR(xattr_orphan)) {
|
||||
kfree(pxent);
|
||||
kfree(xent);
|
||||
return PTR_ERR(xattr_orphan);
|
||||
}
|
||||
|
||||
kfree(pxent);
|
||||
pxent = xent;
|
||||
key_read(c, &xent->key, &key);
|
||||
}
|
||||
kfree(pxent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ubifs_delete_orphan - delete an orphan.
|
||||
* @c: UBIFS file-system description object
|
||||
@ -206,7 +154,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
|
||||
*/
|
||||
void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
|
||||
{
|
||||
struct ubifs_orphan *orph, *child_orph, *tmp_o;
|
||||
struct ubifs_orphan *orph;
|
||||
|
||||
spin_lock(&c->orphan_lock);
|
||||
|
||||
@ -219,11 +167,6 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(child_orph, tmp_o, &orph->child_list, child_list) {
|
||||
list_del(&child_orph->child_list);
|
||||
orphan_delete(c, child_orph);
|
||||
}
|
||||
|
||||
orphan_delete(c, orph);
|
||||
|
||||
spin_unlock(&c->orphan_lock);
|
||||
|
@ -923,8 +923,6 @@ struct ubifs_budget_req {
|
||||
* @rb: rb-tree node of rb-tree of orphans sorted by inode number
|
||||
* @list: list head of list of orphans in order added
|
||||
* @new_list: list head of list of orphans added since the last commit
|
||||
* @child_list: list of xattr children if this orphan hosts xattrs, list head
|
||||
* if this orphan is a xattr, not used otherwise.
|
||||
* @cnext: next orphan to commit
|
||||
* @dnext: next orphan to delete
|
||||
* @inum: inode number
|
||||
@ -936,7 +934,6 @@ struct ubifs_orphan {
|
||||
struct rb_node rb;
|
||||
struct list_head list;
|
||||
struct list_head new_list;
|
||||
struct list_head child_list;
|
||||
struct ubifs_orphan *cnext;
|
||||
struct ubifs_orphan *dnext;
|
||||
ino_t inum;
|
||||
|
Loading…
Reference in New Issue
Block a user