Skip to content

Commit a2e8f00

Browse files
authored
Merge pull request #335 from salvete/main
Cleanup and minor fixes. Skip the packing for centos 7 (arm)
2 parents 1b5d2d8 + 04029dc commit a2e8f00

4 files changed

Lines changed: 52 additions & 52 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
matrix:
1717
images: [ubuntu_18.04, ubuntu_20.04, ubuntu_22.04, centos_7, centos_8, mcr.microsoft.com/cbl-mariner/base/core_2.0]
1818
platforms: [linux/amd64, linux/arm64]
19+
exclude:
20+
- images: centos_7
21+
platforms: linux/arm64
1922
steps:
2023
- name: Set Release Version
2124
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

.github/workflows/release/build.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,23 @@ if [[ ${OS} =~ "ubuntu" ]]; then
3939
PACKAGE_RELEASE="-DPACKAGE_RELEASE=${RELEASE_NO}.${DISTRO}"
4040
elif [[ ${OS} =~ "centos" ]]; then
4141
if [[ ${OS} == "centos:7" ]]; then
42+
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
43+
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
44+
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
45+
yum clean all
46+
rm -rf /var/cache/yum
47+
yum -y update
48+
4249
yum install -y centos-release-scl
43-
yum install -y devtoolset-7-gcc-c++
4450

51+
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
52+
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
53+
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
54+
yum clean all
55+
rm -rf /var/cache/yum
56+
yum -y update
57+
58+
yum install -y devtoolset-7-gcc-c++
4559
export PATH="/opt/rh/devtoolset-7/root/usr/bin:$PATH"
4660
PACKAGE_RELEASE="-DPACKAGE_RELEASE=${RELEASE_NO}.el7"
4761
COMPILER="-DCMAKE_C_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++"

src/overlaybd/tar/erofs/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(FetchContent)
33
FetchContent_Declare(
44
erofs-utils
55
GIT_REPOSITORY https://gitee.com/anolis/erofs-utils.git
6-
GIT_TAG overlaybd-dev-3
6+
GIT_TAG 6ae5eb64136aeea90bda46d286af4628ea35d974
77
)
88

99
FetchContent_MakeAvailable(erofs-utils)
@@ -13,7 +13,7 @@ execute_process(
1313
WORKING_DIRECTORY ${erofs-utils_SOURCE_DIR}
1414
)
1515
execute_process(
16-
COMMAND ./configure --disable-lz4 --without-liblzma --without-libzstd --without-uuid
16+
COMMAND ./configure --disable-lz4 --disable-lzma --without-libzstd --without-uuid --disable-multithreading
1717
WORKING_DIRECTORY ${erofs-utils_SOURCE_DIR}
1818
)
1919
execute_process(

src/overlaybd/tar/erofs/liberofs.cpp

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define round_down_blk(addr) ((addr) & (~(SECTOR_SIZE - 1)))
1717
#define round_up_blk(addr) (round_down_blk((addr) + SECTOR_SIZE - 1))
1818
#define min(a, b) (a) < (b) ? (a) : (b)
19-
#define MAP_FILE_NAME "upper.map"
2019

2120
#define EROFS_UNIMPLEMENTED 1
2221

@@ -257,7 +256,7 @@ static ssize_t erofs_read_photon_file(void *buf, u64 offset, size_t len,
257256
LOG_ERROR("Fail to read sector %lld.", end - SECTOR_SIZE);
258257
return -1;
259258
}
260-
memcpy(extra_buf, buf + end - SECTOR_SIZE - offset,
259+
memcpy(extra_buf, (char*)buf + end - SECTOR_SIZE - offset,
261260
offset + len + SECTOR_SIZE - end);
262261
if (cache->write_sector(end - SECTOR_SIZE, extra_buf)
263262
!= SECTOR_SIZE)
@@ -377,28 +376,13 @@ static int erofs_source_fallocate(struct erofs_vfile *vf,
377376

378377
static int erofs_source_ftruncate(struct erofs_vfile *vf, u64 length)
379378
{
380-
return EROFS_UNIMPLEMENTED;
379+
return -EROFS_UNIMPLEMENTED;
381380
}
382381

383382
static ssize_t erofs_source_read(struct erofs_vfile *vf, void *buf,
384383
size_t bytes)
385384
{
386-
u64 i = 0;
387-
while (bytes) {
388-
u64 len = bytes > INT_MAX ? INT_MAX : bytes;
389-
u64 ret;
390-
391-
ret = _source->read(buf + i, len);
392-
if (ret < 1) {
393-
if (ret == 0)
394-
break;
395-
else
396-
return -1;
397-
}
398-
bytes -= ret;
399-
i += ret;
400-
}
401-
return i;
385+
return _source->read(buf, bytes);
402386
}
403387

404388
static off_t erofs_source_lseek(struct erofs_vfile *vf, u64 offset, int whence)
@@ -411,6 +395,7 @@ struct erofs_mkfs_cfg {
411395
struct erofs_tarfile *erofstar;
412396
bool incremental;
413397
bool ovlfs_strip;
398+
FILE *mp_fp;
414399
};
415400

416401
static int rebuild_src_count;
@@ -421,18 +406,18 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
421406
struct erofs_tarfile *erofstar;
422407
struct erofs_sb_info *sbi;
423408
struct erofs_buffer_head *sb_bh;
424-
struct erofs_inode *root;
409+
struct erofs_inode *root = NULL;
425410
erofs_blk_t nblocks;
426411

427412
erofstar = cfg->erofstar;
428413
sbi = cfg->sbi;
429414
if (!erofstar || !sbi)
430415
return -EINVAL;
431416

432-
if (!erofstar->mapfile)
417+
if (!cfg->mp_fp)
433418
return -EINVAL;
434419

435-
err = erofs_blocklist_open(erofstar->mapfile, true);
420+
err = erofs_blocklist_open(cfg->mp_fp, true);
436421
if (err) {
437422
LOG_ERROR("[erofs] Fail to open erofs blocklist.");
438423
return -EINVAL;
@@ -444,7 +429,12 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
444429
}
445430

446431
if (!cfg->incremental) {
447-
sb_bh = erofs_reserve_sb(sbi);
432+
sbi->bmgr = erofs_buffer_init(sbi, 0);
433+
if (!sbi->bmgr) {
434+
err = -ENOMEM;
435+
goto exit;
436+
}
437+
sb_bh = erofs_reserve_sb(sbi->bmgr);
448438
if (IS_ERR(sb_bh)) {
449439
LOG_ERROR("[erofs] Fail to reseve space for superblock.");
450440
err = PTR_ERR(sb_bh);
@@ -456,7 +446,11 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
456446
LOG_ERROR("[erofs] Fail to read superblock.");
457447
goto exit;
458448
}
459-
erofs_buffer_init(sbi, sbi->primarydevice_blocks);
449+
sbi->bmgr = erofs_buffer_init(sbi, sbi->primarydevice_blocks);
450+
if (!sbi->bmgr) {
451+
err = -ENOMEM;
452+
goto exit;
453+
}
460454
sb_bh = NULL;
461455
}
462456

@@ -471,17 +465,17 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
471465

472466
while (!(err = tarerofs_parse_tar(root, erofstar)));
473467
if (err < 0) {
474-
LOG_ERROR("[erofs] Fail to parse tar file.");
468+
LOG_ERROR("[erofs] Fail to parse tar file.", err);
475469
goto exit;
476470
}
477471

478472
err = erofs_rebuild_dump_tree(root, cfg->incremental);
479473
if (err < 0) {
480-
LOG_ERROR("[erofs] Fail to dump tree.");
474+
LOG_ERROR("[erofs] Fail to dump tree.", err);
481475
goto exit;
482476
}
483477

484-
err = erofs_bflush(NULL);
478+
err = erofs_bflush(sbi->bmgr, NULL);
485479
if (err) {
486480
LOG_ERROR("[erofs] Bflush failed.");
487481
goto exit;
@@ -498,23 +492,22 @@ int erofs_mkfs(struct erofs_mkfs_cfg *cfg)
498492
}
499493

500494
/* flush all remaining buffers */
501-
err = erofs_bflush(NULL);
495+
err = erofs_bflush(sbi->bmgr, NULL);
502496
if (err)
503497
goto exit;
504498

505499
err = erofs_dev_resize(sbi, nblocks);
506500
exit:
507501
if (root)
508502
erofs_iput(root);
503+
erofs_buffer_exit(sbi->bmgr);
509504
erofs_blocklist_close();
510505
return err;
511506
}
512507

513508
static int erofs_init_sbi(struct erofs_sb_info *sbi, photon::fs::IFile *fout,
514509
struct erofs_vfops *ops, int blkbits)
515510
{
516-
int err;
517-
518511
sbi->blkszbits = (char)blkbits;
519512
sbi->bdev.ops = ops;
520513
fout->lseek(0, 0);
@@ -524,26 +517,17 @@ static int erofs_init_sbi(struct erofs_sb_info *sbi, photon::fs::IFile *fout,
524517
}
525518

526519
static int erofs_init_tar(struct erofs_tarfile *erofstar,
527-
photon::fs::IFile *tar_file, struct erofs_vfops *ops)
520+
struct erofs_vfops *ops)
528521
{
529-
int err;
530-
struct stat st;
531-
532522
erofstar->global.xattrs = LIST_HEAD_INIT(erofstar->global.xattrs);
533-
erofstar->mapfile = MAP_FILE_NAME;
534523
erofstar->aufs = true;
535524
erofstar->rvsp_mode = true;
536525
erofstar->dev = rebuild_src_count + 1;
537526

538527
erofstar->ios.feof = false;
539528
erofstar->ios.tail = erofstar->ios.head = 0;
540529
erofstar->ios.dumpfd = -1;
541-
err = tar_file->fstat(&st);
542-
if (err) {
543-
LOG_ERROR("Fail to fstat tar file.");
544-
return err;
545-
}
546-
erofstar->ios.sz = st.st_size;
530+
erofstar->ios.sz = 0;
547531
erofstar->ios.bufsize = 16384;
548532
do {
549533
erofstar->ios.buffer = (char*)malloc(erofstar->ios.bufsize);
@@ -560,18 +544,16 @@ static int erofs_init_tar(struct erofs_tarfile *erofstar,
560544
return 0;
561545
}
562546

563-
static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz)
547+
static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz, FILE *fp)
564548
{
565-
FILE *fp;
566549
uint64_t blkaddr, toff;
567550
uint32_t nblocks;
568551

569-
fp = fopen(MAP_FILE_NAME, "r");
570552
if (fp == NULL) {
571553
LOG_ERROR("unable to get upper.map, ignored");
572554
return -1;
573555
}
574-
556+
rewind(fp);
575557
while (fscanf(fp, "%" PRIx64" %x %" PRIx64 "\n", &blkaddr, &nblocks, &toff)
576558
>= 3)
577559
{
@@ -584,9 +566,8 @@ static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz)
584566
LOG_ERRNO_RETURN(0, -1, "failed to write lba");
585567
}
586568
}
587-
fclose(fp);
588569

589-
return unlink(MAP_FILE_NAME);
570+
return 0;
590571
}
591572

592573
static int erofs_close_sbi(struct erofs_sb_info *sbi, ErofsCache *cache)
@@ -643,7 +624,7 @@ int LibErofs::extract_tar(photon::fs::IFile *source, bool meta_only, bool first_
643624
return err;
644625
}
645626
/* initialization of erofstar */
646-
err = erofs_init_tar(&erofstar, _source, &source_vfops);
627+
err = erofs_init_tar(&erofstar, &source_vfops);
647628
if (err) {
648629
LOG_ERROR("Failed to init tarerofs");
649630
goto exit;
@@ -654,6 +635,7 @@ int LibErofs::extract_tar(photon::fs::IFile *source, bool meta_only, bool first_
654635
cfg.incremental = !first_layer;
655636
erofs_cfg = erofs_get_configure();
656637
erofs_cfg->c_ovlfs_strip = true;
638+
cfg.mp_fp = std::tmpfile();
657639

658640
err = erofs_mkfs(&cfg);
659641
if (err) {
@@ -662,14 +644,15 @@ int LibErofs::extract_tar(photon::fs::IFile *source, bool meta_only, bool first_
662644
}
663645

664646
/* write mapfile */
665-
err = erofs_write_map_file(_target, blksize);
647+
err = erofs_write_map_file(_target, blksize, cfg.mp_fp);
666648
if (err) {
667649
LOG_ERROR("Failed to write mapfile.");
668650
goto exit;
669651
}
670652
exit:
671653
err = erofs_close_sbi(&sbi, &erofs_cache);
672654
erofs_close_tar(&erofstar);
655+
std::fclose(cfg.mp_fp);
673656
return err;
674657
}
675658

0 commit comments

Comments
 (0)