From 62601ef64202a3514cd805936535671eee836448 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 5 Feb 2025 11:18:34 -0500 Subject: [PATCH] libcephfs: add mds_command2 for asynchronous commands Signed-off-by: Patrick Donnelly --- src/include/cephfs/libcephfs.h | 11 ++++++++ src/libcephfs.cc | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index f26eabfbd5c..4fc975801fa 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -319,6 +319,17 @@ int ceph_mount(struct ceph_mount_info *cmount, const char *root); */ int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount); +typedef void (*libcephfs_c_completion_t)(int rc, const void* out, size_t outlen, const void* outs, size_t outslen, void* ud); + +int ceph_mds_command2(struct ceph_mount_info *cmount, + const char *mds_spec, + const char **cmd, + size_t cmdlen, + const char *inbuf, size_t inbuflen, + int one_shot, + libcephfs_c_completion_t c, + void* ud); + /** * Execute a management command remotely on an MDS. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 9cc3fee4d8e..ce06ff7eef0 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -517,6 +517,55 @@ extern "C" int ceph_set_mount_timeout(struct ceph_mount_info *cmount, uint32_t t return ceph_conf_set(cmount, "client_mount_timeout", timeout_str.c_str()); } +class CommandCContext : public Context { +public: + CommandCContext(libcephfs_c_completion_t c, void* ud) : c(c), ud(ud) {} + + void finish(int rc) { + c(rc, outbl.c_str(), outbl.length(), outs.c_str(), outs.size(), ud); + } + + libcephfs_c_completion_t c; + void* ud; + bufferlist outbl; + std::string outs; +}; + +extern "C" int ceph_mds_command2(struct ceph_mount_info *cmount, + const char *mds_spec, + const char **cmd, + size_t cmdlen, + const char *inbuf, size_t inbuflen, + int one_shot, + libcephfs_c_completion_t c, + void* ud) +{ + bufferlist inbl; + std::vector cmdv; + + if (!cmount->is_initialized()) { + return -ENOTCONN; + } + + // Construct inputs + for (size_t i = 0; i < cmdlen; ++i) { + cmdv.push_back(cmd[i]); + } + inbl.append(inbuf, inbuflen); + + // Issue remote command + auto* ctx = new CommandCContext(c, ud); + int r = cmount->get_client()->mds_command(mds_spec, cmdv, inbl, &ctx->outbl, &ctx->outs, ctx, one_shot); + + if (r != 0) { + delete ctx; + return r; + } + + return 0; +} + + extern "C" int ceph_mds_command(struct ceph_mount_info *cmount, const char *mds_spec, const char **cmd, -- 2.39.5