Skip to contentSkip to conversation

erofs-utils: fix build error without lz4 library

PATCH In review Gao Xiang 2 participants 8 messages Oct 30, 2020 – Nov 1, 2020 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/4 erofs-utils: fix build error without lz4 library

This fixes a recent build error if lz4 library doesn't install,

/bin/sh ../libtool --tag=CC --mode=link gcc -Wall -Werror -I../include -g -O2 -o mkfs.erofs mkfs_erofs-main.o -luuid ../lib/liberofs.la -llz4
libtool: link: gcc -Wall -Werror -I../include -g -O2 -o mkfs.erofs mkfs_erofs-main.o -luuid ../lib/.libs/liberofs.a -llz4 /usr/bin/ld: cannot find -llz4

Fixes c497d89e5eac ("erofs-utils: enhance static linking for lz4 1.8.x")
---
 configure.ac     | 2 ++
 mkfs/Makefile.am | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
configure.ac +2 -0
index 0f40a84..bff1e29 100644
@@ -240,7 +240,9 @@ if test "x${have_lz4}" = "xyes"; then
   else
     test -z "${with_lz4_libdir}" || LZ4_LIBS="-R${with_lz4_libdir} $LZ4_LIBS"
   fi
+  liblz4_LIBS="${LZ4_LIBS}"
 fi
+AC_SUBST([liblz4_LIBS])
 
 AC_CONFIG_FILES([Makefile
 		 man/Makefile
mkfs/Makefile.am +1 -1
index ecc468c..8b8e051 100644
@@ -6,5 +6,5 @@ bin_PROGRAMS     = mkfs.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS} ${libselinux_CFLAGS}
 mkfs_erofs_SOURCES = main.c
 mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include
-mkfs_erofs_LDADD = ${libuuid_LIBS} $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} ${LZ4_LIBS}
+mkfs_erofs_LDADD = ${libuuid_LIBS} $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} ${liblz4_LIBS}
 
Signature · 1 line
2.18.1
author
#1 lore raw

PATCH 2/4 erofs-utils: support $SOURCE_DATE_EPOCH

Currently, we use -T to set a given UNIX timestamp for all files, yet reproducible builds [1] requires what is called "timestamp clamping", IOW, a timestamp must be used no later than the value of this variable.

Let's support $SOURCE_DATE_EPOCH as well.

[1] https://reproducible-builds.org/specs/source-date-epoch/

---
 include/erofs/config.h |  7 +++++++
 lib/inode.c            | 15 +++++++++++++--
 mkfs/main.c            | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 2 deletions(-)
include/erofs/config.h +7 -0
index e425ce2..02ddf59 100644
@@ -29,11 +29,18 @@ enum {
 	FORCE_INODE_EXTENDED,
 };
 
+enum {
+	TIMESTAMP_NONE,
+	TIMESTAMP_FIXED,
+	TIMESTAMP_CLAMPING,
+};
+
 struct erofs_configure {
 	const char *c_version;
 	int c_dbg_lvl;
 	bool c_dry_run;
 	bool c_legacy_compress;
+	char c_timeinherit;
 
 #ifdef HAVE_LIBSELINUX
 	struct selabel_handle *sehnd;
lib/inode.c +13 -2
index 5695bbc..fee5c96 100644
@@ -729,8 +729,19 @@ int erofs_fill_inode(struct erofs_inode *inode,
 	inode->i_mode = st->st_mode;
 	inode->i_uid = st->st_uid;
 	inode->i_gid = st->st_gid;
-	inode->i_ctime = sbi.build_time;
-	inode->i_ctime_nsec = sbi.build_time_nsec;
+	inode->i_ctime = st->st_ctime;
+	inode->i_ctime_nsec = st->st_ctim.tv_nsec;
+
+	switch (cfg.c_timeinherit) {
+	case TIMESTAMP_CLAMPING:
+		if (st->st_ctime < sbi.build_time)
+			break;
+	case TIMESTAMP_FIXED:
+		inode->i_ctime = sbi.build_time;
+		inode->i_ctime_nsec = sbi.build_time_nsec;
+	default:
+		break;
+	}
 	inode->i_nlink = 1;	/* fix up later if needed */
 
 	switch (inode->i_mode & S_IFMT) {
mkfs/main.c +34 -0
index 6dda9e3..5c41fc0 100644
@@ -198,6 +198,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 				erofs_err("invalid UNIX timestamp %s", optarg);
 				return -EINVAL;
 			}
+			cfg.c_timeinherit = TIMESTAMP_FIXED;
 			break;
 		case 2:
 			opt = erofs_parse_exclude_path(optarg, false);
@@ -381,6 +382,33 @@ static void erofs_mkfs_generate_uuid(void)
 	erofs_info("filesystem UUID: %s", uuid_str);
 }
 
+/* https://reproducible-builds.org/specs/source-date-epoch/ for more details */
+int parse_source_date_epoch(void)
+{
+	char *source_date_epoch;
+	unsigned long long epoch = -1ULL;
+	char *endptr;
+
+	source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+	if (!source_date_epoch)
+		return 0;
+
+	epoch = strtoull(source_date_epoch, &endptr, 10);
+	if (epoch == -1ULL || *endptr != '\0') {
+		erofs_err("Environment variable $SOURCE_DATE_EPOCH %s is invalid",
+			  source_date_epoch);
+		return -EINVAL;
+	}
+
+	if (cfg.c_force_inodeversion != FORCE_INODE_EXTENDED)
+		erofs_info("SOURCE_DATE_EPOCH is set, forcely generate extended inodes instead");
+
+	cfg.c_force_inodeversion = FORCE_INODE_EXTENDED;
+	cfg.c_unix_timestamp = epoch;
+	cfg.c_timeinherit = TIMESTAMP_CLAMPING;
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	int err = 0;
@@ -405,6 +433,12 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
+	err = parse_source_date_epoch();
+	if (err) {
+		usage();
+		return 1;
+	}
+
 	err = lstat64(cfg.c_src_path, &st);
 	if (err)
 		return 1;
Signature · 1 line
2.18.1
Reviewed-by Li Guifu on v1 2/4
#2 lore raw

Re: [PATCH 2/4] erofs-utils: support $SOURCE_DATE_EPOCH

Quoted 10 lines · Gao Xiang

Currently, we use -T to set a given UNIX timestamp for all files, yet reproducible builds [1] requires what is called "timestamp clamping", IOW, a timestamp must be used no later than the value of this variable.

Let's support $SOURCE_DATE_EPOCH as well.

[1] https://reproducible-builds.org/specs/source-date-epoch/

It looks good

Thanks,

author
#3 lore raw

PATCH 3/4 mkfs: introduce erofs_mkfs_default_options()

In reply to Gao Xiang

Gather all default settings, and generate UUID before parse_options_cfg(), therefore the UUID can be overridden later by command line for reproducible images.

---
 mkfs/main.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
mkfs/main.c +12 -9
index 5c41fc0..0e17314 100644
@@ -368,18 +368,18 @@ static int erofs_mkfs_superblock_csum_set(void)
 	return 0;
 }
 
-static void erofs_mkfs_generate_uuid(void)
+static void erofs_mkfs_default_options(void)
 {
-	char uuid_str[37] = "not available";
+	cfg.c_legacy_compress = false;
+	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
+	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM;
 
+	/* generate a default uuid first */
 #ifdef HAVE_LIBUUID
 	do {
 		uuid_generate(sbi.uuid);
 	} while (uuid_is_null(sbi.uuid));
-
-	uuid_unparse_lower(sbi.uuid, uuid_str);
 #endif
-	erofs_info("filesystem UUID: %s", uuid_str);
 }
 
 /* https://reproducible-builds.org/specs/source-date-epoch/ for more details */
@@ -418,13 +418,12 @@ int main(int argc, char **argv)
 	struct stat64 st;
 	erofs_blk_t nblocks;
 	struct timeval t;
+	char uuid_str[37] = "not available";
 
 	erofs_init_configure();
 	fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version);
 
-	cfg.c_legacy_compress = false;
-	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
-	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM;
+	erofs_mkfs_default_options();
 
 	err = mkfs_parse_options_cfg(argc, argv);
 	if (err) {
@@ -495,7 +494,11 @@ int main(int argc, char **argv)
 		goto exit;
 	}
 
-	erofs_mkfs_generate_uuid();
+#ifdef HAVE_LIBUUID
+	uuid_unparse_lower(sbi.uuid, uuid_str);
+#endif
+	erofs_info("filesystem UUID: %s", uuid_str);
+
 	erofs_inode_manager_init();
 
 	err = erofs_build_shared_xattrs_from_path(cfg.c_src_path);
Signature · 1 line
2.18.1
author
#5 lore raw

PATCH 4/4 mkfs: add option to use a pre-defined UUID

In reply to Gao Xiang

Usage: mkfs.erofs -U<uuid> <imagefile> <srcdir>

The filesystem UUID can now be optionally specified during filesystem creation. The default behavior is still to generate a random UUID.

This is useful for reproducible builds.

---
 man/mkfs.erofs.1 |  6 ++++++
 mkfs/main.c      | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
man/mkfs.erofs.1 +6 -0
index 891c5a8..dcaf9d7 100644
@@ -52,6 +52,12 @@ Forcely generate extended inodes (64-byte inodes) to output.
 Set all files to the given UNIX timestamp. Reproducible builds requires setting
 all to a specific one.
 .TP
+.BI "\-U " UUID
+Set the universally unique identifier (UUID) of the filesystem to
+.IR UUID .
+The format of the UUID is a series of hex digits separated by hyphens,
+like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16".
+.TP
 .BI "\-\-exclude-path=" path
 Ignore file that matches the exact literal path.
 You may give multiple `--exclude-path' options.
mkfs/main.c +12 -1
index 0e17314..c63b274 100644
@@ -66,6 +66,9 @@ static void usage(void)
 	      " -x#                set xattr tolerance to # (< 0, disable xattrs; default 2)\n"
 	      " -EX[,...]          X=extended options\n"
 	      " -T#                set a fixed UNIX timestamp # to all files\n"
+#ifdef HAVE_LIBUUID
+	      " -UX                use a given filesystem UUID\n"
+#endif
 	      " --exclude-path=X   avoid including file X (X = exact literal path)\n"
 	      " --exclude-regex=X  avoid including files that match X (X = regular expression)\n"
 #ifdef HAVE_LIBSELINUX
@@ -149,7 +152,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 	char *endptr;
 	int opt, i;
 
-	while((opt = getopt_long(argc, argv, "d:x:z:E:T:",
+	while((opt = getopt_long(argc, argv, "d:x:z:E:T:U:",
 				 long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'z':
@@ -200,6 +203,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			}
 			cfg.c_timeinherit = TIMESTAMP_FIXED;
 			break;
+#ifdef HAVE_LIBUUID
+		case 'U':
+			if (uuid_parse(optarg, sbi.uuid)) {
+				erofs_err("invalid UUID %s", optarg);
+				return -EINVAL;
+			}
+			break;
+#endif
 		case 2:
 			opt = erofs_parse_exclude_path(optarg, false);
 			if (opt) {
Signature · 1 line
2.18.1
Reviewed-by Li Guifu on v1 4/4
#6 lore raw

Re: [PATCH 4/4] mkfs: add option to use a pre-defined UUID

Quoted 8 lines · Gao Xiang

Usage: mkfs.erofs -U<uuid> <imagefile> <srcdir>

The filesystem UUID can now be optionally specified during filesystem creation. The default behavior is still to generate a random UUID.

This is useful for reproducible builds.

It looks good

Thanks,

Reviewed-by Li Guifu on v1 1/4
#7 lore raw
In reply to Gao Xiang
Quoted 8 lines · Gao Xiang

This fixes a recent build error if lz4 library doesn't install,

/bin/sh ../libtool --tag=CC --mode=link gcc -Wall -Werror -I../include -g -O2 -o mkfs.erofs mkfs_erofs-main.o -luuid ../lib/liberofs.la -llz4
libtool: link: gcc -Wall -Werror -I../include -g -O2 -o mkfs.erofs mkfs_erofs-main.o -luuid ../lib/.libs/liberofs.a -llz4 /usr/bin/ld: cannot find -llz4

Fixes c497d89e5eac ("erofs-utils: enhance static linking for lz4 1.8.x")

It looks good

Thanks,