]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
libcephfs: add mds_command2 for asynchronous commands
authorPatrick Donnelly <pdonnell@ibm.com>
Wed, 5 Feb 2025 16:18:34 +0000 (11:18 -0500)
committerPatrick Donnelly <pdonnell@ibm.com>
Fri, 28 Feb 2025 00:55:45 +0000 (19:55 -0500)
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index f26eabfbd5c1bd6811a5e3b936e94e02224b83a5..4fc975801faf96c0a37dd0e7e5e6814b6ffa91a3 100644 (file)
@@ -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.
  *
index 9cc3fee4d8e617f96369413605cc1f691359db3e..ce06ff7eef04ec26878b863f5ca51dbaf42a92c6 100644 (file)
@@ -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<string> 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,