erofs-utils: add --hardlink-dereference option
PATCH 1/1 erofs-utils: add --hardlink-dereference option
Add option --hardlink-dereference to dereference hardlinks when creating an image. Instead of reusing the inode, hardlinks are added as separate inodes. This is useful for reproducible builds, when the rootfs is space-optimized using hardlinks on some machines, but not on others.
--- include/erofs/config.h | 1 + lib/inode.c | 2 +- mkfs/main.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-)
include/erofs/config.h +1 -0
@@ -58,6 +58,7 @@ struct erofs_configure {bool c_extra_ea_name_prefixes;bool c_xattr_name_filter;bool c_ovlfs_strip; +bool c_hardlink_dereference;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;
lib/inode.c +1 -1
@@ -1141,7 +1141,7 @@ static struct erofs_inode *erofs_iget_from_srcpath(struct erofs_sb_info *sbi,* hard-link, just return it. Also don't lookup for directories * since hard-link directory isn't allowed. */ -if (!S_ISDIR (st.st_mode)) { +if (!S_ISDIR (st.st_mode) && (!cfg.c_hardlink_dereference)) { inode =erofs_iget (st.st_dev, st.st_ino);if (inode)return inode;
mkfs/main.c +4 -0
@@ -85,6 +85,7 @@ static struct option long_options[] = { {"mkfs-time", no_argument, NULL, 525}, {"all-time", no_argument, NULL, 526}, {"sort", required_argument, NULL, 527}, + {"hardlink-dereference", no_argument, NULL, 528}, {0, 0, 0, 0}, };
@@ -846,6 +847,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])if (!strcmp (optarg,"none" )) erofstar.try_no_reorder = true;break ; +case 528 : + cfg.c_hardlink_dereference = true; +break ;case 'V' :version ();exit (0 );
Signature · 1 line
2.47.0
Hi Paul,
Quoted 5 lines · Paul Meyer
Add option --hardlink-dereference to dereference hardlinks when creating an image. Instead of reusing the inode, hardlinks are added as separate inodes. This is useful for reproducible builds, when the rootfs is space-optimized using hardlinks on some machines, but not on others.
Thanks for the patch!
Yet I fail to parse the feature, why this feature is useful for reproducible builds? IOWs, without this feature (or hardlinks are used), what's the exact impact that you don't want to?
Thanks,
Gao Xiang
Quoted 56 lines
Co-authored-by Leonard Cohnen <[email protected]>Signed-off-by Paul Meyer <[email protected]>--- include/erofs/config.h | 1 + lib/inode.c | 2 +- mkfs/main.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-)include/erofs/config.h +1
-0@@ -58,6 +58,7 @@ struct erofs_configure {bool c_extra_ea_name_prefixes;bool c_xattr_name_filter;bool c_ovlfs_strip; +bool c_hardlink_dereference;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;lib/inode.c +1
-1@@ -1141,7 +1141,7 @@ static struct erofs_inode *erofs_iget_from_srcpath(struct erofs_sb_info *sbi,* hard-link, just return it. Also don't lookup for directories * since hard-link directory isn't allowed. */ -if (!S_ISDIR (st.st_mode)) { +if (!S_ISDIR (st.st_mode) && (!cfg.c_hardlink_dereference)) { inode =erofs_iget (st.st_dev, st.st_ino);if (inode)return inode;mkfs/main.c +4
-0@@ -85,6 +85,7 @@ static struct option long_options[] = { {"mkfs-time", no_argument, NULL, 525}, {"all-time", no_argument, NULL, 526}, {"sort", required_argument, NULL, 527}, + {"hardlink-dereference", no_argument, NULL, 528}, {0, 0, 0, 0}, };@@ -846,6 +847,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])if (!strcmp (optarg,"none" )) erofstar.try_no_reorder = true;break ; +case 528 : + cfg.c_hardlink_dereference = true; +break ;case 'V' :version ();exit (0 );
Hi Gao,
Quoted 10 lines · Gao Xiang
Hi Paul,
Quoted 5 lines · Paul Meyer
Add option --hardlink-dereference to dereference hardlinks when creating an image. Instead of reusing the inode, hardlinks are added as separate inodes. This is useful for reproducible builds, when the rootfs is space-optimized using hardlinks on some machines, but not on others.
Quoted 6 lines
Thanks for the patch!
Yet I fail to parse the feature, why this feature is useful for reproducible builds? IOWs, without this feature (or hardlinks are used), what's the exact impact that you don't want to?
Sure, here is our full use case: We are building an erofs image with Nix. Nix stores the rootfs in the nix store (/nix/store). Now there is an option in nix to enable store optimization via hardlinks. In case optimization is enabled, files with identical content are turned into hardlinks to save space, as nix store paths are read-only anyway. If I create a rootfs with two identical files, those will be hardlinked on systems with optimization enabled, but have different inodes on systems where optimization is disabled. When building an erofs, the resulting image will have one inode less on the system where files are hardlinked.
The goal is to make the image bit-by-bit reproducible on both systems. By dereferencing hardlinks, we get the exact same image no matter whether the system uses hardlink optimizations or not.
There is a comparable tar option with the same name.
Thanks,
Paul
Quoted 61 lines
Thanks,
Gao XiangQuoted 56 lines
Co-authored-by Leonard Cohnen <[email protected]>Signed-off-by Paul Meyer <[email protected]>--- include/erofs/config.h | 1 + lib/inode.c | 2 +- mkfs/main.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-)include/erofs/config.h +1
-0@@ -58,6 +58,7 @@ struct erofs_configure {bool c_extra_ea_name_prefixes;bool c_xattr_name_filter;bool c_ovlfs_strip; +bool c_hardlink_dereference;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;lib/inode.c +1
-1@@ -1141,7 +1141,7 @@ static struct erofs_inode *erofs_iget_from_srcpath(struct erofs_sb_info *sbi,* hard-link, just return it. Also don't lookup for directories * since hard-link directory isn't allowed. */ -if (!S_ISDIR (st.st_mode)) { +if (!S_ISDIR (st.st_mode) && (!cfg.c_hardlink_dereference)) { inode =erofs_iget (st.st_dev, st.st_ino);if (inode)return inode;mkfs/main.c +4
-0@@ -85,6 +85,7 @@ static struct option long_options[] = { {"mkfs-time", no_argument, NULL, 525}, {"all-time", no_argument, NULL, 526}, {"sort", required_argument, NULL, 527}, + {"hardlink-dereference", no_argument, NULL, 528}, {0, 0, 0, 0}, };@@ -846,6 +847,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])if (!strcmp (optarg,"none" )) erofstar.try_no_reorder = true;break ; +case 528 : + cfg.c_hardlink_dereference = true; +break ;case 'V' :version ();exit (0 );
Quoted 33 lines · Paul M
Hi Gao,
Quoted 10 lines · Gao Xiang
Hi Paul,
Quoted 5 lines · Paul Meyer
Add option --hardlink-dereference to dereference hardlinks when creating an image. Instead of reusing the inode, hardlinks are added as separate inodes. This is useful for reproducible builds, when the rootfs is space-optimized using hardlinks on some machines, but not on others.
Quoted 6 lines
Thanks for the patch!
Yet I fail to parse the feature, why this feature is useful for reproducible builds? IOWs, without this feature (or hardlinks are used), what's the exact impact that you don't want to?
Sure, here is our full use case: We are building an erofs image with Nix. Nix stores the rootfs in the nix store (/nix/store). Now there is an option in nix to enable store optimization via hardlinks. In case optimization is enabled, files with identical content are turned into hardlinks to save space, as nix store paths are read-only anyway. If I create a rootfs with two identical files, those will be hardlinked on systems with optimization enabled, but have different inodes on systems where optimization is disabled. When building an erofs, the resulting image will have one inode less on the system where files are hardlinked.
The goal is to make the image bit-by-bit reproducible on both systems. By dereferencing hardlinks, we get the exact same image no matter whether the system uses hardlink optimizations or not.
Quoted 1 line
There is a comparable tar option with the same name.
Ok, thanks for letting me know.
That sounds more meaningful to me, but
could you update the option as --hard-dereference (although I don't verify the tar behavior) and usage() too?
Otherwise it looks good to me.
Thanks,
Gao Xiang
Quoted 65 lines
Thanks,
PaulQuoted 61 lines
Thanks,
Gao XiangQuoted 56 lines
Co-authored-by Leonard Cohnen <[email protected]>Signed-off-by Paul Meyer <[email protected]>--- include/erofs/config.h | 1 + lib/inode.c | 2 +- mkfs/main.c | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-)include/erofs/config.h +1
-0@@ -58,6 +58,7 @@ struct erofs_configure {bool c_extra_ea_name_prefixes;bool c_xattr_name_filter;bool c_ovlfs_strip; +bool c_hardlink_dereference;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;lib/inode.c +1
-1@@ -1141,7 +1141,7 @@ static struct erofs_inode *erofs_iget_from_srcpath(struct erofs_sb_info *sbi,* hard-link, just return it. Also don't lookup for directories * since hard-link directory isn't allowed. */ -if (!S_ISDIR (st.st_mode)) { +if (!S_ISDIR (st.st_mode) && (!cfg.c_hardlink_dereference)) { inode =erofs_iget (st.st_dev, st.st_ino);if (inode)return inode;mkfs/main.c +4
-0@@ -85,6 +85,7 @@ static struct option long_options[] = { {"mkfs-time", no_argument, NULL, 525}, {"all-time", no_argument, NULL, 526}, {"sort", required_argument, NULL, 527}, + {"hardlink-dereference", no_argument, NULL, 528}, {0, 0, 0, 0}, };@@ -846,6 +847,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])if (!strcmp (optarg,"none" )) erofstar.try_no_reorder = true;break ; +case 528 : + cfg.c_hardlink_dereference = true; +break ;case 'V' :version ();exit (0 );