Skip to content

Commit 500edd0

Browse files
committed
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/[email protected] Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent fe5de58 commit 500edd0

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

fs/erofs/namei.c

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright (C) 2017-2018 HUAWEI, Inc.
44
* https://www.huawei.com/
5+
* Copyright (C) 2022, Alibaba Cloud
56
*/
67
#include "xattr.h"
78

@@ -86,25 +87,26 @@ static struct erofs_dirent *find_target_dirent(struct erofs_qstr *name,
8687
return ERR_PTR(-ENOENT);
8788
}
8889

89-
static struct page *find_target_block_classic(struct inode *dir,
90-
struct erofs_qstr *name,
91-
int *_ndirents)
90+
static void *find_target_block_classic(struct erofs_buf *target,
91+
struct inode *dir,
92+
struct erofs_qstr *name,
93+
int *_ndirents)
9294
{
9395
unsigned int startprfx, endprfx;
9496
int head, back;
95-
struct address_space *const mapping = dir->i_mapping;
96-
struct page *candidate = ERR_PTR(-ENOENT);
97+
void *candidate = ERR_PTR(-ENOENT);
9798

9899
startprfx = endprfx = 0;
99100
head = 0;
100101
back = erofs_inode_datablocks(dir) - 1;
101102

102103
while (head <= back) {
103104
const int mid = head + (back - head) / 2;
104-
struct page *page = read_mapping_page(mapping, mid, NULL);
105+
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
106+
struct erofs_dirent *de;
105107

106-
if (!IS_ERR(page)) {
107-
struct erofs_dirent *de = kmap_atomic(page);
108+
de = erofs_bread(&buf, dir, mid, EROFS_KMAP);
109+
if (!IS_ERR(de)) {
108110
const int nameoff = nameoff_from_disk(de->nameoff,
109111
EROFS_BLKSIZ);
110112
const int ndirents = nameoff / sizeof(*de);
@@ -113,13 +115,12 @@ static struct page *find_target_block_classic(struct inode *dir,
113115
struct erofs_qstr dname;
114116

115117
if (!ndirents) {
116-
kunmap_atomic(de);
117-
put_page(page);
118+
erofs_put_metabuf(&buf);
118119
erofs_err(dir->i_sb,
119120
"corrupted dir block %d @ nid %llu",
120121
mid, EROFS_I(dir)->nid);
121122
DBG_BUGON(1);
122-
page = ERR_PTR(-EFSCORRUPTED);
123+
de = ERR_PTR(-EFSCORRUPTED);
123124
goto out;
124125
}
125126

@@ -135,7 +136,6 @@ static struct page *find_target_block_classic(struct inode *dir,
135136

136137
/* string comparison without already matched prefix */
137138
diff = erofs_dirnamecmp(name, &dname, &matched);
138-
kunmap_atomic(de);
139139

140140
if (!diff) {
141141
*_ndirents = 0;
@@ -145,11 +145,12 @@ static struct page *find_target_block_classic(struct inode *dir,
145145
startprfx = matched;
146146

147147
if (!IS_ERR(candidate))
148-
put_page(candidate);
149-
candidate = page;
148+
erofs_put_metabuf(target);
149+
*target = buf;
150+
candidate = de;
150151
*_ndirents = ndirents;
151152
} else {
152-
put_page(page);
153+
erofs_put_metabuf(&buf);
153154

154155
back = mid - 1;
155156
endprfx = matched;
@@ -158,8 +159,8 @@ static struct page *find_target_block_classic(struct inode *dir,
158159
}
159160
out: /* free if the candidate is valid */
160161
if (!IS_ERR(candidate))
161-
put_page(candidate);
162-
return page;
162+
erofs_put_metabuf(target);
163+
return de;
163164
}
164165
return candidate;
165166
}
@@ -169,8 +170,7 @@ int erofs_namei(struct inode *dir,
169170
erofs_nid_t *nid, unsigned int *d_type)
170171
{
171172
int ndirents;
172-
struct page *page;
173-
void *data;
173+
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
174174
struct erofs_dirent *de;
175175
struct erofs_qstr qn;
176176

@@ -181,26 +181,20 @@ int erofs_namei(struct inode *dir,
181181
qn.end = name->name + name->len;
182182

183183
ndirents = 0;
184-
page = find_target_block_classic(dir, &qn, &ndirents);
185184

186-
if (IS_ERR(page))
187-
return PTR_ERR(page);
185+
de = find_target_block_classic(&buf, dir, &qn, &ndirents);
186+
if (IS_ERR(de))
187+
return PTR_ERR(de);
188188

189-
data = kmap_atomic(page);
190189
/* the target page has been mapped */
191190
if (ndirents)
192-
de = find_target_dirent(&qn, data, EROFS_BLKSIZ, ndirents);
193-
else
194-
de = (struct erofs_dirent *)data;
191+
de = find_target_dirent(&qn, (u8 *)de, EROFS_BLKSIZ, ndirents);
195192

196193
if (!IS_ERR(de)) {
197194
*nid = le64_to_cpu(de->nid);
198195
*d_type = de->file_type;
199196
}
200-
201-
kunmap_atomic(data);
202-
put_page(page);
203-
197+
erofs_put_metabuf(&buf);
204198
return PTR_ERR_OR_ZERO(de);
205199
}
206200

0 commit comments

Comments
 (0)