erofs-utils: mount: auto-detect platform for OCI recovery files
PATCH 1/1 erofs-utils: mount: auto-detect platform for OCI recovery files
From: Chengyu Zhu <[email protected]>
erofsmount_write_recovery_oci() writes source->ocicfg.platform into recovery files directly, but it could be NULL when not explicitly configured, causing reattach failures.
Fix this by falling back to ocierofs_get_platform_spec(). Also refactor it to return a compile-time string literal instead of asprintf(), eliminating the need for callers to free() the result.
--- lib/liberofs_oci.h | 1 + lib/remotes/oci.c | 55 +++++++++++++++------------------------------- mount/main.c | 11 +++++++--- 3 files changed, 27 insertions(+), 40 deletions(-)
lib/liberofs_oci.h +1 -0
@@ -80,6 +80,7 @@ int ocierofs_io_open(struct erofs_vfile *vf, const struct ocierofs_config *cfg);char *ocierofs_encode_userpass (const char *username,const char *password);int ocierofs_decode_userpass (const char *b64,char **out_user,char **out_pass); +const char *ocierofs_get_platform_spec (void ); #ifdef __cplusplus }
lib/remotes/oci.c +18 -37
82 lines not on this page · raw message
mount/main.c +8 -3
@@ -717,6 +717,7 @@ out_closefd:static int erofsmount_write_recovery_oci (FILE *f,struct erofs_nbd_source *source) {char *b64cred =NULL ; +const char *platform;int ret;if (source->ocicfg.username || source->ocicfg.password) {
@@ -726,11 +727,15 @@ static int erofsmount_write_recovery_oci(FILE *f, struct erofs_nbd_source *sourcreturn PTR_ERR (b64cred); } + platform = source->ocicfg.platform; +if (!platform || !*platform) + platform =ocierofs_get_platform_spec (); +if ((source->ocicfg.tarindex_path || source->ocicfg.zinfo_path) && source->ocicfg.blob_digest && *source->ocicfg.blob_digest) { ret = fprintf(f, "TARINDEX_OCI_BLOB %s %s %s %s %s %s\n", source->ocicfg.image_ref ?: "", - source->ocicfg.platform ?: "", + platform ?: "", source->ocicfg.blob_digest, b64cred ?: "", source->ocicfg.tarindex_path ?: "",
@@ -742,7 +747,7 @@ static int erofsmount_write_recovery_oci(FILE *f, struct erofs_nbd_source *sourcif (source->ocicfg.blob_digest && *source->ocicfg.blob_digest) { ret =fprintf (f,"OCI_NATIVE_BLOB %s %s %s %s\n" , source->ocicfg.image_ref ?:"" , - source->ocicfg.platform ?:"" , + platform ?:"" , source->ocicfg.blob_digest, b64cred ?:"" );free (b64cred);
@@ -752,7 +757,7 @@ static int erofsmount_write_recovery_oci(FILE *f, struct erofs_nbd_source *sourcif (source->ocicfg.layer_index >=0 ) { ret =fprintf (f,"OCI_LAYER %s %s %d %s\n" , source->ocicfg.image_ref ?:"" , - source->ocicfg.platform ?:"" , + platform ?:"" , source->ocicfg.layer_index, b64cred ?:"" );free (b64cred);
Signature · 1 line
2.47.1
Quoted 11 lines · Chengyu
From: Chengyu Zhu <[email protected]>
erofsmount_write_recovery_oci()writessource->ocicfg.platforminto recovery files directly, but it could be NULL when not explicitly configured, causing reattach failures.Fix this by falling back to
ocierofs_get_platform_spec(). Also refactor it to return a compile-time string literal instead ofasprintf(), eliminating the need for callers tofree()the result.Signed-off-by Chengyu Zhu <[email protected]>
LGTM, will apply.
Thanks,
Gao Xiang