Skip to content

Commit 8241fdd

Browse files
committed
erofs: clean up zmap.c
Several trivial cleanups which aren't quite necessary to split: - Rename lcluster load functions as well as justify full indexes since they are typically used for global deduplication for compressed data; - Avoid unnecessary lines, comments for simplicity. No logic changes. Reviewed-by: Guo Xuenan <guoxuenan@huaweicloud.com> Reviewed-by: Yue Hu <huyue2@coolpad.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230615064421.103178-1-hsiangkao@linux.alibaba.com
1 parent 1990595 commit 8241fdd

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

fs/erofs/zmap.c

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ struct z_erofs_maprecorder {
2222
bool partialref;
2323
};
2424

25-
static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
26-
unsigned long lcn)
25+
static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
26+
unsigned long lcn)
2727
{
2828
struct inode *const inode = m->inode;
2929
struct erofs_inode *const vi = EROFS_I(inode);
@@ -226,8 +226,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
226226
return 0;
227227
}
228228

229-
static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
230-
unsigned long lcn, bool lookahead)
229+
static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
230+
unsigned long lcn, bool lookahead)
231231
{
232232
struct inode *const inode = m->inode;
233233
struct erofs_inode *const vi = EROFS_I(inode);
@@ -277,45 +277,39 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
277277
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
278278
}
279279

280-
static int z_erofs_load_cluster_from_disk(struct z_erofs_maprecorder *m,
281-
unsigned int lcn, bool lookahead)
280+
static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
281+
unsigned int lcn, bool lookahead)
282282
{
283-
const unsigned int datamode = EROFS_I(m->inode)->datalayout;
284-
285-
if (datamode == EROFS_INODE_COMPRESSED_FULL)
286-
return legacy_load_cluster_from_disk(m, lcn);
287-
288-
if (datamode == EROFS_INODE_COMPRESSED_COMPACT)
289-
return compacted_load_cluster_from_disk(m, lcn, lookahead);
290-
291-
return -EINVAL;
283+
switch (EROFS_I(m->inode)->datalayout) {
284+
case EROFS_INODE_COMPRESSED_FULL:
285+
return z_erofs_load_full_lcluster(m, lcn);
286+
case EROFS_INODE_COMPRESSED_COMPACT:
287+
return z_erofs_load_compact_lcluster(m, lcn, lookahead);
288+
default:
289+
return -EINVAL;
290+
}
292291
}
293292

294293
static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
295294
unsigned int lookback_distance)
296295
{
296+
struct super_block *sb = m->inode->i_sb;
297297
struct erofs_inode *const vi = EROFS_I(m->inode);
298298
const unsigned int lclusterbits = vi->z_logical_clusterbits;
299299

300300
while (m->lcn >= lookback_distance) {
301301
unsigned long lcn = m->lcn - lookback_distance;
302302
int err;
303303

304-
/* load extent head logical cluster if needed */
305-
err = z_erofs_load_cluster_from_disk(m, lcn, false);
304+
err = z_erofs_load_lcluster_from_disk(m, lcn, false);
306305
if (err)
307306
return err;
308307

309308
switch (m->type) {
310309
case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
311-
if (!m->delta[0]) {
312-
erofs_err(m->inode->i_sb,
313-
"invalid lookback distance 0 @ nid %llu",
314-
vi->nid);
315-
DBG_BUGON(1);
316-
return -EFSCORRUPTED;
317-
}
318310
lookback_distance = m->delta[0];
311+
if (!lookback_distance)
312+
goto err_bogus;
319313
continue;
320314
case Z_EROFS_LCLUSTER_TYPE_PLAIN:
321315
case Z_EROFS_LCLUSTER_TYPE_HEAD1:
@@ -324,16 +318,15 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
324318
m->map->m_la = (lcn << lclusterbits) | m->clusterofs;
325319
return 0;
326320
default:
327-
erofs_err(m->inode->i_sb,
328-
"unknown type %u @ lcn %lu of nid %llu",
321+
erofs_err(sb, "unknown type %u @ lcn %lu of nid %llu",
329322
m->type, lcn, vi->nid);
330323
DBG_BUGON(1);
331324
return -EOPNOTSUPP;
332325
}
333326
}
334-
335-
erofs_err(m->inode->i_sb, "bogus lookback distance @ nid %llu",
336-
vi->nid);
327+
err_bogus:
328+
erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu",
329+
lookback_distance, m->lcn, vi->nid);
337330
DBG_BUGON(1);
338331
return -EFSCORRUPTED;
339332
}
@@ -365,7 +358,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
365358
if (m->compressedblks)
366359
goto out;
367360

368-
err = z_erofs_load_cluster_from_disk(m, lcn, false);
361+
err = z_erofs_load_lcluster_from_disk(m, lcn, false);
369362
if (err)
370363
return err;
371364

@@ -397,19 +390,16 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
397390
break;
398391
fallthrough;
399392
default:
400-
erofs_err(m->inode->i_sb,
401-
"cannot found CBLKCNT @ lcn %lu of nid %llu",
402-
lcn, vi->nid);
393+
erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu", lcn,
394+
vi->nid);
403395
DBG_BUGON(1);
404396
return -EFSCORRUPTED;
405397
}
406398
out:
407399
map->m_plen = erofs_pos(sb, m->compressedblks);
408400
return 0;
409401
err_bonus_cblkcnt:
410-
erofs_err(m->inode->i_sb,
411-
"bogus CBLKCNT @ lcn %lu of nid %llu",
412-
lcn, vi->nid);
402+
erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid);
413403
DBG_BUGON(1);
414404
return -EFSCORRUPTED;
415405
}
@@ -430,7 +420,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
430420
return 0;
431421
}
432422

433-
err = z_erofs_load_cluster_from_disk(m, lcn, true);
423+
err = z_erofs_load_lcluster_from_disk(m, lcn, true);
434424
if (err)
435425
return err;
436426

@@ -477,7 +467,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
477467
initial_lcn = ofs >> lclusterbits;
478468
endoff = ofs & ((1 << lclusterbits) - 1);
479469

480-
err = z_erofs_load_cluster_from_disk(&m, initial_lcn, false);
470+
err = z_erofs_load_lcluster_from_disk(&m, initial_lcn, false);
481471
if (err)
482472
goto unmap_out;
483473

@@ -535,8 +525,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
535525
if (flags & EROFS_GET_BLOCKS_FINDTAIL) {
536526
vi->z_tailextent_headlcn = m.lcn;
537527
/* for non-compact indexes, fragmentoff is 64 bits */
538-
if (fragment &&
539-
vi->datalayout == EROFS_INODE_COMPRESSED_FULL)
528+
if (fragment && vi->datalayout == EROFS_INODE_COMPRESSED_FULL)
540529
vi->z_fragmentoff |= (u64)m.pblk << 32;
541530
}
542531
if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) {

0 commit comments

Comments
 (0)