Skip to contentSkip to conversation

erofs-utils: add --hardlink-dereference option

PATCH Superseded Paul Meyer 2 participants 2 messages Dec 12, 2024 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Paul Meyer

author
#0 lore raw

PATCH v2 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.

---

v1: https://lore.kernel.org/all/[email protected]/
change since v1:
- rename option to --hard-dereference
- add usage

 include/erofs/config.h | 1 +
 lib/inode.c            | 2 +-
 mkfs/main.c            | 5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
include/erofs/config.h +1 -0
index cff4cea..bb03e70 100644
@@ -58,6 +58,7 @@ struct erofs_configure {
 	bool c_extra_ea_name_prefixes;
 	bool c_xattr_name_filter;
 	bool c_ovlfs_strip;
+	bool c_hard_dereference;
 
 #ifdef HAVE_LIBSELINUX
 	struct selabel_handle *sehnd;
lib/inode.c +1 -1
index 7e5c581..0404a8d 100644
@@ -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_hard_dereference)) {
 		inode = erofs_iget(st.st_dev, st.st_ino);
 		if (inode)
 			return inode;
mkfs/main.c +5 -0
index d422787..7eb86f5 100644
@@ -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},
+	{"hard-dereference", no_argument, NULL, 528},
 	{0, 0, 0, 0},
 };
 
@@ -214,6 +215,7 @@ static void usage(int argc, char **argv)
 #ifdef EROFS_MT_ENABLED
 		, erofs_get_available_processors() /* --workers= */
 #endif
+		" --hard-dereference    dereference hardlinks, add links as separate inodes\n"
 	);
 }
 
@@ -846,6 +848,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_hard_dereference = true;
+			break;
 		case 'V':
 			version();
 			exit(0);
Signature · 1 line
2.47.0
#1 lore raw
Quoted 6 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.

The subject and commit message is still unchanged...

Quoted 52 lines

---

v1: https://lore.kernel.org/all/[email protected]/
change since v1:
- rename option to --hard-dereference
- add usage

  include/erofs/config.h | 1 +
  lib/inode.c            | 2 +-
  mkfs/main.c            | 5 +++++
  3 files changed, 7 insertions(+), 1 deletion(-)
include/erofs/config.h +1 -0
index cff4cea..bb03e70 100644
@@ -58,6 +58,7 @@ struct erofs_configure {
  	bool c_extra_ea_name_prefixes;
  	bool c_xattr_name_filter;
  	bool c_ovlfs_strip;
+	bool c_hard_dereference;
 
  #ifdef HAVE_LIBSELINUX
  	struct selabel_handle *sehnd;
lib/inode.c +1 -1
index 7e5c581..0404a8d 100644
@@ -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_hard_dereference)) {
  		inode = erofs_iget(st.st_dev, st.st_ino);
  		if (inode)
  			return inode;
mkfs/main.c +1 -0
index d422787..7eb86f5 100644
@@ -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},
+	{"hard-dereference", no_argument, NULL, 528},
  	{0, 0, 0, 0},
  };
 

mkfs/main.c static void usage(int argc, char **argv) · line 218

Quoted 4 lines
mkfs/main.c +1 -0
@@ -214,6 +215,7 @@ static void usage(int argc, char **argv)
  #ifdef EROFS_MT_ENABLED
  		, erofs_get_available_processors() /* --workers= */
  #endif
+		" --hard-dereference    dereference hardlinks, add links as separate inodes\n"

Does it compile with EROFS_MT_ENABLED?...

Also --hard-dereference should be moved upwards to match alphabetical order.

Thanks,
Gao Xiang

Quoted 13 lines
mkfs/main.c +3 -0
  	);
  }
 
@@ -846,6 +848,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_hard_dereference = true;
+			break;
  		case 'V':
  			version();
  			exit(0);