Skip to contentSkip to conversation

erofs-utils: mount: auto-detect platform for OCI recovery files

PATCH In review Chengyu 2 participants 2 messages Feb 27 Library code

lore
Share & tools
lore

Chengyu

author
#0 lore raw

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
index 9e0571f..2243c82 100644
@@ -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
index 3530b2c..b04be5d 100644
@@ -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 *sourc
 			return 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 *sourc
 	if (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 *sourc
 	if (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
#1 lore raw
Quoted 11 lines · Chengyu

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.

LGTM, will apply.

Thanks,
Gao Xiang