mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
erofs: use meta buffers for inode lookup
This converts the remaining inode lookup part by using metabuf in a straight-forward way. Except that it doesn't use kmap_atomic() anymore since we now have to maintain two metabufs together. After this patch, all uncompressed paths are handled with metabuf instead of page structure. Link: https://lore.kernel.org/r/20220316012246.95131-2-hsiangkao@linux.alibaba.com Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
This commit is contained in:
parent
fe5de5859d
commit
500edd0956
@ -2,6 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
||||||
* https://www.huawei.com/
|
* https://www.huawei.com/
|
||||||
|
* Copyright (C) 2022, Alibaba Cloud
|
||||||
*/
|
*/
|
||||||
#include "xattr.h"
|
#include "xattr.h"
|
||||||
|
|
||||||
@ -86,14 +87,14 @@ static struct erofs_dirent *find_target_dirent(struct erofs_qstr *name,
|
|||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct page *find_target_block_classic(struct inode *dir,
|
static void *find_target_block_classic(struct erofs_buf *target,
|
||||||
struct erofs_qstr *name,
|
struct inode *dir,
|
||||||
int *_ndirents)
|
struct erofs_qstr *name,
|
||||||
|
int *_ndirents)
|
||||||
{
|
{
|
||||||
unsigned int startprfx, endprfx;
|
unsigned int startprfx, endprfx;
|
||||||
int head, back;
|
int head, back;
|
||||||
struct address_space *const mapping = dir->i_mapping;
|
void *candidate = ERR_PTR(-ENOENT);
|
||||||
struct page *candidate = ERR_PTR(-ENOENT);
|
|
||||||
|
|
||||||
startprfx = endprfx = 0;
|
startprfx = endprfx = 0;
|
||||||
head = 0;
|
head = 0;
|
||||||
@ -101,10 +102,11 @@ static struct page *find_target_block_classic(struct inode *dir,
|
|||||||
|
|
||||||
while (head <= back) {
|
while (head <= back) {
|
||||||
const int mid = head + (back - head) / 2;
|
const int mid = head + (back - head) / 2;
|
||||||
struct page *page = read_mapping_page(mapping, mid, NULL);
|
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
||||||
|
struct erofs_dirent *de;
|
||||||
|
|
||||||
if (!IS_ERR(page)) {
|
de = erofs_bread(&buf, dir, mid, EROFS_KMAP);
|
||||||
struct erofs_dirent *de = kmap_atomic(page);
|
if (!IS_ERR(de)) {
|
||||||
const int nameoff = nameoff_from_disk(de->nameoff,
|
const int nameoff = nameoff_from_disk(de->nameoff,
|
||||||
EROFS_BLKSIZ);
|
EROFS_BLKSIZ);
|
||||||
const int ndirents = nameoff / sizeof(*de);
|
const int ndirents = nameoff / sizeof(*de);
|
||||||
@ -113,13 +115,12 @@ static struct page *find_target_block_classic(struct inode *dir,
|
|||||||
struct erofs_qstr dname;
|
struct erofs_qstr dname;
|
||||||
|
|
||||||
if (!ndirents) {
|
if (!ndirents) {
|
||||||
kunmap_atomic(de);
|
erofs_put_metabuf(&buf);
|
||||||
put_page(page);
|
|
||||||
erofs_err(dir->i_sb,
|
erofs_err(dir->i_sb,
|
||||||
"corrupted dir block %d @ nid %llu",
|
"corrupted dir block %d @ nid %llu",
|
||||||
mid, EROFS_I(dir)->nid);
|
mid, EROFS_I(dir)->nid);
|
||||||
DBG_BUGON(1);
|
DBG_BUGON(1);
|
||||||
page = ERR_PTR(-EFSCORRUPTED);
|
de = ERR_PTR(-EFSCORRUPTED);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +136,6 @@ static struct page *find_target_block_classic(struct inode *dir,
|
|||||||
|
|
||||||
/* string comparison without already matched prefix */
|
/* string comparison without already matched prefix */
|
||||||
diff = erofs_dirnamecmp(name, &dname, &matched);
|
diff = erofs_dirnamecmp(name, &dname, &matched);
|
||||||
kunmap_atomic(de);
|
|
||||||
|
|
||||||
if (!diff) {
|
if (!diff) {
|
||||||
*_ndirents = 0;
|
*_ndirents = 0;
|
||||||
@ -145,11 +145,12 @@ static struct page *find_target_block_classic(struct inode *dir,
|
|||||||
startprfx = matched;
|
startprfx = matched;
|
||||||
|
|
||||||
if (!IS_ERR(candidate))
|
if (!IS_ERR(candidate))
|
||||||
put_page(candidate);
|
erofs_put_metabuf(target);
|
||||||
candidate = page;
|
*target = buf;
|
||||||
|
candidate = de;
|
||||||
*_ndirents = ndirents;
|
*_ndirents = ndirents;
|
||||||
} else {
|
} else {
|
||||||
put_page(page);
|
erofs_put_metabuf(&buf);
|
||||||
|
|
||||||
back = mid - 1;
|
back = mid - 1;
|
||||||
endprfx = matched;
|
endprfx = matched;
|
||||||
@ -158,8 +159,8 @@ static struct page *find_target_block_classic(struct inode *dir,
|
|||||||
}
|
}
|
||||||
out: /* free if the candidate is valid */
|
out: /* free if the candidate is valid */
|
||||||
if (!IS_ERR(candidate))
|
if (!IS_ERR(candidate))
|
||||||
put_page(candidate);
|
erofs_put_metabuf(target);
|
||||||
return page;
|
return de;
|
||||||
}
|
}
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
@ -169,8 +170,7 @@ int erofs_namei(struct inode *dir,
|
|||||||
erofs_nid_t *nid, unsigned int *d_type)
|
erofs_nid_t *nid, unsigned int *d_type)
|
||||||
{
|
{
|
||||||
int ndirents;
|
int ndirents;
|
||||||
struct page *page;
|
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
||||||
void *data;
|
|
||||||
struct erofs_dirent *de;
|
struct erofs_dirent *de;
|
||||||
struct erofs_qstr qn;
|
struct erofs_qstr qn;
|
||||||
|
|
||||||
@ -181,26 +181,20 @@ int erofs_namei(struct inode *dir,
|
|||||||
qn.end = name->name + name->len;
|
qn.end = name->name + name->len;
|
||||||
|
|
||||||
ndirents = 0;
|
ndirents = 0;
|
||||||
page = find_target_block_classic(dir, &qn, &ndirents);
|
|
||||||
|
|
||||||
if (IS_ERR(page))
|
de = find_target_block_classic(&buf, dir, &qn, &ndirents);
|
||||||
return PTR_ERR(page);
|
if (IS_ERR(de))
|
||||||
|
return PTR_ERR(de);
|
||||||
|
|
||||||
data = kmap_atomic(page);
|
|
||||||
/* the target page has been mapped */
|
/* the target page has been mapped */
|
||||||
if (ndirents)
|
if (ndirents)
|
||||||
de = find_target_dirent(&qn, data, EROFS_BLKSIZ, ndirents);
|
de = find_target_dirent(&qn, (u8 *)de, EROFS_BLKSIZ, ndirents);
|
||||||
else
|
|
||||||
de = (struct erofs_dirent *)data;
|
|
||||||
|
|
||||||
if (!IS_ERR(de)) {
|
if (!IS_ERR(de)) {
|
||||||
*nid = le64_to_cpu(de->nid);
|
*nid = le64_to_cpu(de->nid);
|
||||||
*d_type = de->file_type;
|
*d_type = de->file_type;
|
||||||
}
|
}
|
||||||
|
erofs_put_metabuf(&buf);
|
||||||
kunmap_atomic(data);
|
|
||||||
put_page(page);
|
|
||||||
|
|
||||||
return PTR_ERR_OR_ZERO(de);
|
return PTR_ERR_OR_ZERO(de);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user