Skip to contentSkip to conversation

erofs-utils: add dm-persistent file delta support

RFC PATCH New Yifan Zhao 1 participant 3 messages Sep 16 Library code

lore
Share & tools
lore

Yifan Zhao

author
#0 lore raw

cover erofs-utils: add dm-persistent file delta support

This series adds a file-delta framework and a dm-persistent backend to mkfs.erofs. Unchanged data is referenced from the parent image; changed nonzero data is stored in the new image.

Example: rootfs/disk.img is the baseline file, and epoch1.cow is a sealed dm-persistent v1 snapshot exception store for that file, using 4096-byte (8-sector) chunks.

  # Create the parent image containing /disk.img.
  mkfs.erofs -Eforce-chunk-indexes --chunksize=4096 \
    parent.erofs rootfs/

  # Apply epoch1.cow to /disk.img and write next.erofs.
  mkfs.erofs -Eforce-chunk-indexes --chunksize=4096 \
    --file-delta=dm-persistent:/disk.img:epoch1.cow \
    next.erofs parent.erofs

  # Check the new image using the parent as its external data device.
  fsck.erofs --device=parent.erofs next.erofs

The update --chunksize must match the exception store's chunk size.

Yifan Zhao (2):
erofs-utils: mkfs: add file-delta framework
erofs-utils: mkfs: support dm-persistent file deltas

 include/erofs/internal.h     |   2 +
 lib/Makefile.am              |   5 +-
 lib/blobchunk.c              |  25 +++
 lib/dm_persistent.c          | 396 +++++++++++++++++++++++++++++++++++
 lib/file_delta.c             | 214 +++++++++++++++++++
 lib/file_delta_chunk.c       | 203 ++++++++++++++++++
 lib/liberofs_chunk.h         |   2 +
 lib/liberofs_dm_persistent.h |   9 +
 lib/liberofs_file_delta.h    |  81 +++++++
 lib/rebuild.c                |  34 ++-
 man/mkfs.erofs.1             |  71 +++++++
 mkfs/main.c                  | 113 +++++++++-
 12 files changed, 1148 insertions(+), 7 deletions(-)
 create mode 100644 lib/dm_persistent.c
 create mode 100644 lib/file_delta.c
 create mode 100644 lib/file_delta_chunk.c
 create mode 100644 lib/liberofs_dm_persistent.h
 create mode 100644 lib/liberofs_file_delta.h

base-commit: 2429baa75a5278ddaf8221740a6a65dd390acb08

Signature · 1 line
2.55.0
author
#2 lore raw

RFC PATCH 2/2 erofs-utils: mkfs: support dm-persistent file deltas

Parse and validate version 1 dm-persistent snapshot exception stores, then expose their logical update units through the file-delta source operations. The source unit size is independent of the parent chunk geometry.

Assisted-by Codex:gpt-5.6-sol
---
 lib/Makefile.am              |   3 +-
 lib/dm_persistent.c          | 396 +++++++++++++++++++++++++++++++++++
 lib/liberofs_dm_persistent.h |   9 +
 man/mkfs.erofs.1             |  15 ++
 mkfs/main.c                  |   2 +
 5 files changed, 424 insertions(+), 1 deletion(-)
 create mode 100644 lib/dm_persistent.c
 create mode 100644 lib/liberofs_dm_persistent.h
lib/Makefile.am +2 -1
index 3d562f4..24e7d0b 100644
@@ -24,6 +24,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \
       $(top_srcdir)/lib/liberofs_cache.h \
       $(top_srcdir)/lib/liberofs_chunk.h \
       $(top_srcdir)/lib/liberofs_compress.h \
+      $(top_srcdir)/lib/liberofs_dm_persistent.h \
       $(top_srcdir)/lib/liberofs_file_delta.h \
       $(top_srcdir)/lib/liberofs_fragments.h \
       $(top_srcdir)/lib/liberofs_private.h \
@@ -46,7 +47,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
 		      fragments.c dedupe.c uuid_unparse.c uuid.c tar.c \
 		      block_list.c rebuild.c diskbuf.c bitops.c dedupe_ext.c \
 		      vmdk.c metabox.c global.c importer.c base64.c file_delta.c \
-		      file_delta_chunk.c
+		      file_delta_chunk.c dm_persistent.c
 
 liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include
 liberofs_la_LIBADD = $(LIBEROFS_LIBS)
lib/dm_persistent.c new file +396 -0

396 lines not on this page · raw message

lib/liberofs_dm_persistent.h new file +9 -0
new file mode 100644
index 0000000..1a0f476
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ OR MIT */
+#ifndef __EROFS_LIB_LIBEROFS_DM_PERSISTENT_H
+#define __EROFS_LIB_LIBEROFS_DM_PERSISTENT_H
+
+#include "liberofs_file_delta.h"
+
+extern const struct erofs_file_delta_source_ops erofs_file_delta_dm_persistent_ops;
+
+#endif
man/mkfs.erofs.1 +15 -0
index dcac6f0..e38355d 100644
@@ -394,6 +394,21 @@ parent and delta chunk geometries do not require a redundant \fB-b\fR option.
 The source specification is the remainder after the second colon, so it may
 itself contain colons.  Repeated file-delta options must refer to distinct target
 files.  A source may be reused when the selected backend permits it.
+.RS
+.TP
+.B dm-persistent
+Treat \fISOURCE\fR as a Linux dm-persistent snapshot exception store version
+1.  Each exception replaces the logical update unit identified by
+\fBold_chunk\fR with the payload at \fBnew_chunk\fR.  The dm chunk size and
+\fB\-\-chunksize\fR must be equal.  An update to the last partial unit is
+clipped to the target file size.
+
+The source can be a regular file or block device and must remain unchanged for
+the complete build.  Its header must have magic \fB0x70416e53\fR,
+\fBvalid=1\fR, version 1, and a power-of-two chunk size.
+FIFOs and other unsupported source object types are rejected without waiting
+for a peer to open them.
+.RE
 .TP
 .BI "\-\-max-extent-bytes=" #
 Specify maximum decompressed extent size in bytes. The default is unlimited.
mkfs/main.c +2 -0
index 7598f0a..d6d3e9d 100644
@@ -26,6 +26,7 @@
 #include "erofs/compress_hints.h"
 #include "../lib/compressor.h"
 #include "../lib/liberofs_chunk.h"
+#include "../lib/liberofs_dm_persistent.h"
 #include "../lib/liberofs_file_delta.h"
 #include "../lib/liberofs_gzran.h"
 #include "../lib/liberofs_metabox.h"
@@ -335,6 +336,7 @@ static struct erofs_file_delta_manager file_delta_mgr = {
 	.deltas = LIST_HEAD_INIT(file_delta_mgr.deltas),
 };
 static const struct erofs_file_delta_source_ops * const file_delta_backends[] = {
+	&erofs_file_delta_dm_persistent_ops,
 	NULL,
 };
 static u8 fixeduuid[16];
Signature · 1 line
2.55.0
author
#1 lore raw

RFC PATCH 1/2 erofs-utils: mkfs: add file-delta framework

In reply to Yifan Zhao

Add source operations for reading logical updates and layout operations for inheriting parent mappings, writing updates and publishing output indexes. Keep the parent read view separate from the output inode and its superblock.

Implement the Chunk layout backend with independent parent, update and output granularities. Split inherited large chunks without copying their data, retain historical device references and allow parent chunk merging. Store changed nonzero data in the output primary and zero updates as holes.

Match targets by parent inode, including hard-linked files. Reject unsupported 48-bit layouts and block ranges.

Assisted-by Codex:gpt-5.6-sol
---
 include/erofs/internal.h  |   2 +
 lib/Makefile.am           |   4 +-
 lib/blobchunk.c           |  25 +++++
 lib/file_delta.c          | 214 ++++++++++++++++++++++++++++++++++++++
 lib/file_delta_chunk.c    | 203 ++++++++++++++++++++++++++++++++++++
 lib/liberofs_chunk.h      |   2 +
 lib/liberofs_file_delta.h |  81 +++++++++++++++
 lib/rebuild.c             |  34 +++++-
 man/mkfs.erofs.1          |  56 ++++++++++
 mkfs/main.c               | 111 +++++++++++++++++++-
 10 files changed, 725 insertions(+), 7 deletions(-)
 create mode 100644 lib/file_delta.c
 create mode 100644 lib/file_delta_chunk.c
 create mode 100644 lib/liberofs_file_delta.h
include/erofs/internal.h +2 -0
index 973bb96..6251a3e 100644
@@ -94,6 +94,7 @@ struct erofs_xattrmgr;
 struct z_erofs_mgr;
 struct erofs_metamgr;
 struct erofs_chunkmgr;
+struct erofs_file_delta_manager;
 
 struct erofs_sb_info {
 	struct erofs_sb_lz4_info lz4;
@@ -154,6 +155,7 @@ struct erofs_sb_info {
 	struct erofs_xattrmgr *xamgr;
 	struct z_erofs_mgr *zmgr;
 	struct erofs_chunkmgr *chunkmgr;
+	struct erofs_file_delta_manager *file_delta_mgr;
 	struct erofs_metamgr *m2gr, *mxgr;
 	struct erofs_packed_inode *packedinode;
 	struct erofs_buffer_head *bh_sb;
lib/Makefile.am +3 -1
index 0a82915..3d562f4 100644
@@ -24,6 +24,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \
       $(top_srcdir)/lib/liberofs_cache.h \
       $(top_srcdir)/lib/liberofs_chunk.h \
       $(top_srcdir)/lib/liberofs_compress.h \
+      $(top_srcdir)/lib/liberofs_file_delta.h \
       $(top_srcdir)/lib/liberofs_fragments.h \
       $(top_srcdir)/lib/liberofs_private.h \
       $(top_srcdir)/lib/liberofs_rebuild.h \
@@ -44,7 +45,8 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
 		      compress_hints.c sha256.c blobchunk.c dir.c \
 		      fragments.c dedupe.c uuid_unparse.c uuid.c tar.c \
 		      block_list.c rebuild.c diskbuf.c bitops.c dedupe_ext.c \
-		      vmdk.c metabox.c global.c importer.c base64.c
+		      vmdk.c metabox.c global.c importer.c base64.c file_delta.c \
+		      file_delta_chunk.c
 
 liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include
 liberofs_la_LIBADD = $(LIBEROFS_LIBS)
lib/blobchunk.c +25 -0
index 8f43dd0..8150fd4 100644
@@ -161,6 +161,31 @@ static struct erofs_chunkitem *erofs_get_chunk(struct erofs_sb_info *sbi,
 	return chunk;
 }
 
+struct erofs_chunkitem *erofs_blob_write_chunk(struct erofs_sb_info *sbi,
+		const void *buf, erofs_off_t chunksize, int device_id)
+{
+	struct erofs_chunkmgr *cmgr = sbi->chunkmgr;
+	struct erofs_chunkitem *chunk;
+
+	if (!cmgr || !chunksize || chunksize > INT_MAX || device_id < 0)
+		return ERR_PTR(-EINVAL);
+	if (device_id &&
+	    (device_id > sbi->extra_devices ||
+	     !sbi->devs[device_id - 1].bmgr))
+		return ERR_PTR(-EINVAL);
+	if (!device_id && !sbi->bmgr)
+		return ERR_PTR(-EINVAL);
+	chunk = erofs_get_chunk(sbi, device_id, (u8 *)buf, chunksize);
+	if (IS_ERR(chunk))
+		return chunk;
+	if (chunk->blkaddr >= UINT32_MAX ||
+	    BLK_ROUND_UP(sbi, chunksize) > UINT32_MAX - chunk->blkaddr) {
+		erofs_err("file-delta output exceeds the 32-bit block range");
+		return ERR_PTR(-EFBIG);
+	}
+	return chunk;
+}
+
 void erofs_inode_fixup_chunkformat(struct erofs_inode *inode)
 {
 	unsigned int unit, src;
lib/file_delta.c new file +214 -0

214 lines not on this page · raw message

lib/file_delta_chunk.c new file +203 -0

203 lines not on this page · raw message

lib/liberofs_chunk.h +2 -0
index 16f3d05..8dfeeb2 100644
@@ -17,6 +17,8 @@ extern "C"
 struct erofs_chunkitem *erofs_get_unhashed_chunk(struct erofs_sb_info *sbi,
 		unsigned int device_id, erofs_blk_t blkaddr,
 		erofs_off_t sourceoffset);
+struct erofs_chunkitem *erofs_blob_write_chunk(struct erofs_sb_info *sbi,
+		const void *buf, erofs_off_t chunksize, int device_id);
 void erofs_inode_fixup_chunkformat(struct erofs_inode *inode);
 int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,
 			      erofs_off_t off);
lib/liberofs_file_delta.h new file +81 -0

81 lines not on this page · raw message

lib/rebuild.c +30 -4
index 7d28c1e..9c38204 100644
@@ -15,6 +15,7 @@
 #include "erofs/internal.h"
 #include "erofs/io.h"
 #include "liberofs_chunk.h"
+#include "liberofs_file_delta.h"
 #include "liberofs_rebuild.h"
 #include "liberofs_uuid.h"
 
@@ -198,7 +199,7 @@ static int erofs_rebuild_load_chunk_index(struct erofs_sb_info *dst_sb,
 			.buf = __EROFS_BUF_INITIALIZER,
 		};
 
-		map.m_la = i << chunkbits;
+		map.m_la = (erofs_off_t)i << chunkbits;
 		ret = erofs_map_blocks(inode, &map, 0);
 		if (ret)
 			goto err;
@@ -233,6 +234,28 @@ static int erofs_rebuild_write_blob_index(struct erofs_sb_info *dst_sb,
 	return erofs_rebuild_load_chunk_index(dst_sb, inode);
 }
 
+static int erofs_rebuild_apply_file_delta(struct erofs_sb_info *dst_sb,
+		struct erofs_inode *inode)
+{
+	const struct erofs_file_delta_layout_ops *ops;
+	struct erofs_file_delta *delta;
+	struct erofs_inode parent = *inode;
+
+	switch (parent.datalayout) {
+	case EROFS_INODE_CHUNK_BASED:
+		ops = &erofs_file_delta_chunk_layout_ops;
+		break;
+	default:
+		erofs_err("%s: unsupported file-delta datalayout %u",
+			  inode->i_srcpath, parent.datalayout);
+		return -EOPNOTSUPP;
+	}
+	delta = erofs_file_delta_lookup_target(dst_sb->file_delta_mgr, &parent);
+	inode->sbi = dst_sb;
+	return erofs_file_delta_apply(delta, ops,
+			delta ? &delta->lower_inode : &parent, inode);
+}
+
 static int erofs_rebuild_write_full_data(struct erofs_inode *inode)
 {
 	struct erofs_sb_info *src_sbi = inode->sbi;
@@ -339,9 +362,12 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,
 			inode->u.i_blkaddr = EROFS_NULL_ADDR;
 			break;
 		}
-		if (datamode == EROFS_REBUILD_DATA_BLOB_INDEX)
-			err = erofs_rebuild_write_blob_index(dst_sb, inode);
-		else if (datamode == EROFS_REBUILD_DATA_RESVSP)
+		if (datamode == EROFS_REBUILD_DATA_BLOB_INDEX) {
+			if (dst_sb->file_delta_mgr)
+				err = erofs_rebuild_apply_file_delta(dst_sb, inode);
+			else
+				err = erofs_rebuild_write_blob_index(dst_sb, inode);
+		} else if (datamode == EROFS_REBUILD_DATA_RESVSP)
 			inode->datasource = EROFS_INODE_DATA_SOURCE_RESVSP;
 		else if (datamode == EROFS_REBUILD_DATA_FULL)
 			err = erofs_rebuild_write_full_data(inode);
man/mkfs.erofs.1 +56 -0

62 lines not on this page · raw message

mkfs/main.c +109 -2

183 lines not on this page · raw message

Signature · 1 line
2.55.0