]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: add raw type for seastar buffers
authorCasey Bodley <cbodley@redhat.com>
Sun, 8 Oct 2017 22:04:23 +0000 (18:04 -0400)
committerKefu Chai <kchai@redhat.com>
Fri, 8 Jun 2018 12:58:15 +0000 (20:58 +0800)
new buffer_seastar.cc implements the buffer::raw types for seastar,
built in an object library outside of libcommon

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/CMakeLists.txt
src/common/buffer_seastar.cc [new file with mode: 0644]
src/include/buffer.h

index a0525d9007d1ba257996ed99d6039ed55db06e5d..2c3a1495eebbeccfdbd0f9d64df28e20e5574450 100644 (file)
@@ -415,6 +415,16 @@ endif(HAVE_RDMA)
 add_library(common_buffer_obj OBJECT
   common/buffer.cc)
 
+if(WITH_SEASTAR)
+  add_library(seastar_buffer_obj OBJECT common/buffer_seastar.cc)
+  # target_link_libraries() doesn't work for object libraries, so the
+  # Seastar properties are applied manually (and link is unnecessary)
+  target_compile_definitions(seastar_buffer_obj
+    PUBLIC $<TARGET_PROPERTY:Seastar::seastar,INTERFACE_COMPILE_DEFINITIONS>)
+  target_include_directories(seastar_buffer_obj
+    PUBLIC $<TARGET_PROPERTY:Seastar::seastar,INTERFACE_INCLUDE_DIRECTORIES>)
+endif()
+
 add_library(common_texttable_obj OBJECT
   common/TextTable.cc)
 
diff --git a/src/common/buffer_seastar.cc b/src/common/buffer_seastar.cc
new file mode 100644 (file)
index 0000000..5be805d
--- /dev/null
@@ -0,0 +1,53 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include <core/sharded.hh>
+
+#include "include/buffer_raw.h"
+
+using temporary_buffer = seastar::temporary_buffer<char>;
+
+namespace ceph {
+namespace buffer {
+
+class raw_seastar_foreign_ptr : public raw {
+  seastar::foreign_ptr<temporary_buffer> ptr;
+ public:
+  raw_seastar_foreign_ptr(temporary_buffer&& buf)
+    : raw(buf.get_write(), buf.size()), ptr(std::move(buf)) {}
+  raw* clone_empty() override {
+    return create(len);
+  }
+};
+
+raw* create_foreign(temporary_buffer&& buf) {
+  return new raw_seastar_foreign_ptr(std::move(buf));
+}
+
+class raw_seastar_local_ptr : public raw {
+  temporary_buffer buf;
+ public:
+  raw_seastar_local_ptr(temporary_buffer&& buf)
+    : raw(buf.get_write(), buf.size()), buf(std::move(buf)) {}
+  raw* clone_empty() override {
+    return create(len);
+  }
+};
+
+raw* create(temporary_buffer&& buf) {
+  return new raw_seastar_local_ptr(std::move(buf));
+}
+
+} // namespace buffer
+} // namespace ceph
index f625afc177ed868ddc0918c7bfdf48fc4d652f53..2f18adcb3f28d044fdbe640254f0a47422ef9b27 100644 (file)
 struct xio_reg_mem;
 class XioDispatchHook;
 #endif
+#ifdef HAVE_SEASTAR
+namespace seastar {
+template <typename T> class temporary_buffer;
+}
+#endif // HAVE_SEASTAR
 class deleter;
 
 namespace ceph {
@@ -168,6 +173,15 @@ namespace buffer CEPH_BUFFER_API {
   raw* create_static(unsigned len, char *buf);
   raw* claim_buffer(unsigned len, char *buf, deleter del);
 
+#ifdef HAVE_SEASTAR
+  /// create a raw buffer to wrap seastar cpu-local memory, using foreign_ptr to
+  /// make it safe to share between cpus
+  raw* create_foreign(seastar::temporary_buffer<char>&& buf);
+  /// create a raw buffer to wrap seastar cpu-local memory, without the safety
+  /// of foreign_ptr. the caller must otherwise guarantee that the buffer ptr is
+  /// destructed on this cpu
+  raw* create(seastar::temporary_buffer<char>&& buf);
+#endif
 #if defined(HAVE_XIO)
   raw* create_msg(unsigned len, char *buf, XioDispatchHook *m_hook);
 #endif
@@ -987,12 +1001,12 @@ inline bufferhash& operator<<(bufferhash& l, const bufferlist &r) {
   return l;
 }
 
-}
+} // namespace buffer
 
 #if defined(HAVE_XIO)
 xio_reg_mem* get_xio_mp(const buffer::ptr& bp);
 #endif
 
-}
+} // namespace ceph
 
 #endif