]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.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>
Mon, 17 Mar 2025 19:43:21 +0000 (15:43 -0400)
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
(cherry picked from commit 62601ef64202a3514cd805936535671eee836448)

src/include/cephfs/libcephfs.h
src/libcephfs.cc

index ba0b76e072b57e1d79a1559ffe6fdc60e17877ab..d0fa9e6b28c565de5a9bf68919e31cdc196a7fff 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 7ecc7e7e14d0307acf72518a6480bef9232ae5e8..12c4c5d229e064771cf63cbc623cd9d6f91c0ef4 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,