Skip to content

Commit

Permalink
Add new version 1 that uses the new xwhiteout marking approach
Browse files Browse the repository at this point in the history
Linux upstream is making some change to how xwhiteout directories
are marked. They are now marked with an opaque xattr with content "x".

See:
 https://lore.kernel.org/linux-unionfs/CAOQ4uxh5x_-1j8HViCutVkghA1Uh-va+kJshCuvB+ep7WjmOFg@mail.gmail.com/T/#t

This creates a new image format version, 1, which adds these xattrs
(and the old ones for backwards compat with linux 6.7).

In addition, the tests are updated to handle this, and we create a new testcase that validates both v0 and v1 keeps working for whiteout files.

Note: This changes the output of the CLI tools to use the new version
by default, and you need to pass --verison-format=0 to get the old
version. This is ok at this point, as most images are unaffected by
the version due to lack of whiteouts, and not many people use
composefs yet.
  • Loading branch information
alexlarsson committed Jan 22, 2024
1 parent 8f159aa commit 562b779
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 10 deletions.
3 changes: 3 additions & 0 deletions libcomposefs/lcfs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ typedef int errint_t;

#define OVERLAY_XATTR_ESCAPED_WHITEOUT OVERLAY_XATTR_ESCAPE_PREFIX "whiteout"
#define OVERLAY_XATTR_ESCAPED_WHITEOUTS OVERLAY_XATTR_ESCAPE_PREFIX "whiteouts"
#define OVERLAY_XATTR_ESCAPED_OPAQUE OVERLAY_XATTR_ESCAPE_PREFIX "opaque"

#define OVERLAY_XATTR_USERXATTR_WHITEOUT \
OVERLAY_XATTR_USERXATTR_PREFIX "whiteout"
#define OVERLAY_XATTR_USERXATTR_WHITEOUTS \
OVERLAY_XATTR_USERXATTR_PREFIX "whiteouts"
#define OVERLAY_XATTR_USERXATTR_OPAQUE \
OVERLAY_XATTR_USERXATTR_PREFIX "opaque"

#define ALIGN_TO(_offset, _align_size) \
(((_offset) + _align_size - 1) & ~(_align_size - 1))
Expand Down
29 changes: 22 additions & 7 deletions libcomposefs/lcfs-writer-erofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ static int write_erofs_shared_xattrs(struct lcfs_ctx_s *ctx)
return 0;
}

static int add_overlayfs_xattrs(struct lcfs_node_s *node)
static int add_overlayfs_xattrs(struct lcfs_ctx_s *ctx,
struct lcfs_node_s *node)
{
int type = node->inode.st_mode & S_IFMT;
int ret;
Expand Down Expand Up @@ -1148,6 +1149,18 @@ static int add_overlayfs_xattrs(struct lcfs_node_s *node)
"", 0);
if (ret < 0)
return ret;

/* Mark dir containing whiteouts with new format as of version 1 */
if (ctx->options->version >= 1) {
ret = lcfs_node_set_xattr(parent,
OVERLAY_XATTR_ESCAPED_OPAQUE, "x", 1);
if (ret < 0)
return ret;
ret = lcfs_node_set_xattr(parent, OVERLAY_XATTR_USERXATTR_OPAQUE,
"x", 1);
if (ret < 0)
return ret;
}
}

return 0;
Expand Down Expand Up @@ -1206,12 +1219,13 @@ static int add_overlay_whiteouts(struct lcfs_node_s *root)
return 0;
}

static int rewrite_tree_node_for_erofs(struct lcfs_node_s *node,
static int rewrite_tree_node_for_erofs(struct lcfs_ctx_s *ctx,
struct lcfs_node_s *node,
struct lcfs_node_s *parent)
{
int ret;

ret = add_overlayfs_xattrs(node);
ret = add_overlayfs_xattrs(ctx, node);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -1256,7 +1270,7 @@ static int rewrite_tree_node_for_erofs(struct lcfs_node_s *node,
continue;
}

ret = rewrite_tree_node_for_erofs(child, node);
ret = rewrite_tree_node_for_erofs(ctx, child, node);
if (ret < 0) {
return -1;
}
Expand All @@ -1277,11 +1291,12 @@ static int set_overlay_opaque(struct lcfs_node_s *node)
return 0;
}

static int rewrite_tree_for_erofs(struct lcfs_node_s *root)
static int rewrite_tree_for_erofs(struct lcfs_ctx_s *ctx,
struct lcfs_node_s *root)
{
int res;

res = rewrite_tree_node_for_erofs(root, root);
res = rewrite_tree_node_for_erofs(ctx, root, root);
if (res < 0)
return res;

Expand Down Expand Up @@ -1320,7 +1335,7 @@ int lcfs_write_erofs_to(struct lcfs_ctx_s *ctx)
root = ctx->root; /* After we cloned it */

/* Rewrite cloned tree as needed for erofs */
ret = rewrite_tree_for_erofs(root);
ret = rewrite_tree_for_erofs(ctx, root);
if (ret < 0)
return ret;

Expand Down
6 changes: 5 additions & 1 deletion libcomposefs/lcfs-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ enum lcfs_flags_t {
LCFS_FLAGS_MASK = 0,
};

#define LCFS_VERSION_MAX 0
#define LCFS_VERSION_MAX 1
/* Version history:
* 0 - Initial version
* 1 - Mark xwhitouts using the new opaque=x format as needed by Linux 6.8
*/

typedef ssize_t (*lcfs_read_cb)(void *file, void *buf, size_t count);
typedef ssize_t (*lcfs_write_cb)(void *file, void *buf, size_t count);
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST_ASSETS_SMALL = \
config.dump.gz config-with-hard-link.dump.gz special.dump
config.dump.gz config-with-hard-link.dump.gz special.dump special_v1.dump

TEST_ASSETS = ${TEST_ASSETS_SMALL} \
cs9-x86_64-developer.dump.gz cs9-x86_64-minimal.dump.gz \
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/special.dump.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d344782ff962ab7d1c5533755c19c5bf3c3485f55bfaf228fc89524c7e2ba61e
d344782ff962ab7d1c5533755c19c5bf3c3485f55bfaf228fc89524c7e2ba61e
1 change: 1 addition & 0 deletions tests/assets/special.dump.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions tests/assets/special_v1.dump
1 change: 1 addition & 0 deletions tests/assets/special_v1.dump.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ee8028939ca3151a50bbbbd377c52c46ab183013610c8909e624840bf496975f
1 change: 1 addition & 0 deletions tests/assets/special_v1.dump.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
2 changes: 2 additions & 0 deletions tests/dumpdir
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def dumpfile(file, root):
if stat.S_ISDIR(st_mode) and has_whiteout_child(file):
xattrs["trusted.overlay.overlay.whiteouts"] = b''
xattrs["user.overlay.whiteouts"] = b''
xattrs["trusted.overlay.overlay.opaque"] = b'x'
xattrs["user.overlay.opaque"] = b'x'

nlink = s.st_nlink;
if args.no_nlink or (args.no_root_nlink and file == root):
Expand Down

0 comments on commit 562b779

Please sign in to comment.