On 2025/9/10 14:13, ChengyuZhu6 wrote:
From: Chengyu Zhu <hudson...@tencent.com>
This commit implements recovery support for OCI-based NBD mounts,
allowing the system to properly reattach NBD devices after
NBD disconnection.
Signed-off-by: Chengyu Zhu <hudson...@tencent.com>
---
lib/liberofs_oci.h | 3 +
lib/remotes/oci.c | 71 ++++++++++++++++++++++
mount/main.c | 143 ++++++++++++++++++++++++++++++++++++---------
3 files changed, 189 insertions(+), 28 deletions(-)
diff --git a/lib/liberofs_oci.h b/lib/liberofs_oci.h
index 01a83aa..aa41141 100644
--- a/lib/liberofs_oci.h
+++ b/lib/liberofs_oci.h
@@ -71,6 +71,9 @@ int ocierofs_build_trees(struct erofs_importer *importer,
const struct ocierofs_config *cfg);
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);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/remotes/oci.c b/lib/remotes/oci.c
index de18daa..a00c04a 100644
--- a/lib/remotes/oci.c
+++ b/lib/remotes/oci.c
@@ -24,6 +24,7 @@
#include "erofs/io.h"
#include "erofs/print.h"
#include "erofs/tar.h"
+#include "liberofs_base64.h"
#include "liberofs_oci.h"
#include "liberofs_private.h"
@@ -1471,6 +1472,76 @@ int ocierofs_io_open(struct erofs_vfile *vfile, const struct ocierofs_config *cf
*(struct ocierofs_iostream **)vfile->payload = oci_iostream;
return 0;
}
+
+char *ocierofs_encode_userpass(const char *username, const char *password)
+{
+ char *buf;
+ char *out;
+ int ret;
+ size_t outlen;
+ size_t inlen;
+
+ if (asprintf(&buf, "%s:%s", username ?: "", password ?: "") == -1)
+ return ERR_PTR(-ENOMEM);
inlen can be gotten from the return value of `asprintf`...
+
+ inlen = strlen(buf);
+ outlen = 4 * DIV_ROUND_UP(inlen, 3);
+ out = malloc(outlen + 1);
+ if (!out) {
+ free(buf);
+ return ERR_PTR(-ENOMEM);
+ }
+ ret = erofs_base64_encode((unsigned char *)buf, inlen, out);
+ if (ret < 0) {
+ free(buf);
+ free(out);
+ return ERR_PTR(ret);
+ }
if (!out) {
ret = -ENOMEM;
} else {
ret = erofs_base64_encode((unsigned char *)buf, inlen, out);
if (ret < 0)
free(out);
}
free(buf);
return ret < 0 ? ERR_PTR(ret) : out;
Otherwise it looks good to me.
Thanks,
Gao Xiang