]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rgw/services/svc_rados.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / services / svc_rados.h
index 0453eb0cded35a9532b543bf551e4f4dab99553d..721a4bbe258180011695138b00c977a02437935b 100644 (file)
@@ -1,11 +1,15 @@
-#ifndef CEPH_RGW_SERVICES_RADOS_H
-#define CEPH_RGW_SERVICES_RADOS_H
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
 
+#pragma once
 
 #include "rgw/rgw_service.h"
 
 #include "include/rados/librados.hpp"
 #include "common/async/yield_context.h"
+#include "common/RWLock.h"
+
+class RGWAsyncRadosProcessor;
 
 class RGWAccessListFilter {
 public:
@@ -22,19 +26,34 @@ struct RGWAccessListFilterPrefix : public RGWAccessListFilter {
   }
 };
 
-struct rgw_rados_ref {
-  rgw_raw_obj obj;
-  librados::IoCtx ioctx;
-};
-
 class RGWSI_RADOS : public RGWServiceInstance
 {
   librados::Rados rados;
+  std::unique_ptr<RGWAsyncRadosProcessor> async_processor;
 
   int do_start() override;
 
+public:
+  struct OpenParams {
+    bool create{true};
+    bool mostly_omap{false};
+
+    OpenParams() {}
+
+    OpenParams& set_create(bool _create) {
+      create = _create;
+      return *this;
+    }
+    OpenParams& set_mostly_omap(bool _mostly_omap) {
+      mostly_omap = _mostly_omap;
+      return *this;
+    }
+  };
+
+private:
   librados::Rados* get_rados_handle();
-  int open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx);
+  int open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx,
+                    const OpenParams& params = {});
   int pool_iterate(librados::IoCtx& ioctx,
                    librados::NObjectIterator& iter,
                    uint32_t num, vector<rgw_bucket_dir_entry>& objs,
@@ -42,63 +61,35 @@ class RGWSI_RADOS : public RGWServiceInstance
                    bool *is_truncated);
 
 public:
-  RGWSI_RADOS(CephContext *cct) : RGWServiceInstance(cct) {}
+  RGWSI_RADOS(CephContext *cct);
+  ~RGWSI_RADOS();
 
   void init() {}
+  void shutdown() override;
 
   uint64_t instance_id();
+  bool check_secure_mon_conn() const;
 
-  class Handle;
-
-  class Obj {
-    friend class RGWSI_RADOS;
-    friend Handle;
-
-    RGWSI_RADOS *rados_svc{nullptr};
-    rgw_rados_ref ref;
-
-    void init(const rgw_raw_obj& obj);
-
-    Obj(RGWSI_RADOS *_rados_svc, const rgw_raw_obj& _obj)
-      : rados_svc(_rados_svc) {
-      init(_obj);
-    }
-
-  public:
-    Obj() {}
-
-    int open();
-
-    int operate(librados::ObjectWriteOperation *op, optional_yield y);
-    int operate(librados::ObjectReadOperation *op, bufferlist *pbl,
-                optional_yield y);
-    int aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op);
-    int aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
-                    bufferlist *pbl);
-
-    int watch(uint64_t *handle, librados::WatchCtx2 *ctx);
-    int aio_watch(librados::AioCompletion *c, uint64_t *handle, librados::WatchCtx2 *ctx);
-    int unwatch(uint64_t handle);
-    int notify(bufferlist& bl,
-               uint64_t timeout_ms,
-               bufferlist *pbl);
-    void notify_ack(uint64_t notify_id,
-                    uint64_t cookie,
-                    bufferlist& bl);
+  RGWAsyncRadosProcessor *get_async_processor() {
+    return async_processor.get();
+  }
 
-    uint64_t get_last_version();
+  int clog_warn(const string& msg);
 
-    rgw_rados_ref& get_ref() { return ref; }
-    const rgw_rados_ref& get_ref() const { return ref; }
-  };
+  class Handle;
 
   class Pool {
     friend class RGWSI_RADOS;
     friend Handle;
+    friend class Obj;
 
     RGWSI_RADOS *rados_svc{nullptr};
     rgw_pool pool;
 
+    struct State {
+      librados::IoCtx ioctx;
+    } state;
+
     Pool(RGWSI_RADOS *_rados_svc,
          const rgw_pool& _pool) : rados_svc(_rados_svc),
                                   pool(_pool) {}
@@ -110,9 +101,18 @@ public:
     int create();
     int create(const std::vector<rgw_pool>& pools, std::vector<int> *retcodes);
     int lookup();
+    int open(const OpenParams& params = {});
+
+    const rgw_pool& get_pool() {
+      return pool;
+    }
+
+    librados::IoCtx& ioctx() {
+      return state.ioctx;
+    }
 
     struct List {
-      Pool& pool;
+      Pool *pool{nullptr};
 
       struct Ctx {
         bool initialized{false};
@@ -121,21 +121,77 @@ public:
         RGWAccessListFilter *filter{nullptr};
       } ctx;
 
-      List(Pool& _pool) : pool(_pool) {}
+      List() {}
+      List(Pool *_pool) : pool(_pool) {}
 
       int init(const string& marker, RGWAccessListFilter *filter = nullptr);
       int get_next(int max,
-                   std::list<string> *oids,
+                   std::vector<string> *oids,
                    bool *is_truncated);
+
+      int get_marker(string *marker);
     };
 
     List op() {
-      return List(*this);
+      return List(this);
     }
 
     friend List;
   };
 
+
+  struct rados_ref {
+    RGWSI_RADOS::Pool pool;
+    rgw_raw_obj obj;
+  };
+
+  class Obj {
+    friend class RGWSI_RADOS;
+    friend class Handle;
+
+    RGWSI_RADOS *rados_svc{nullptr};
+    rados_ref ref;
+
+    void init(const rgw_raw_obj& obj);
+
+    Obj(RGWSI_RADOS *_rados_svc, const rgw_raw_obj& _obj)
+      : rados_svc(_rados_svc) {
+      init(_obj);
+    }
+
+    Obj(Pool& pool, const string& oid);
+
+  public:
+    Obj() {}
+
+    int open();
+
+    int operate(librados::ObjectWriteOperation *op, optional_yield y);
+    int operate(librados::ObjectReadOperation *op, bufferlist *pbl,
+                optional_yield y);
+    int aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op);
+    int aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
+                    bufferlist *pbl);
+
+    int watch(uint64_t *handle, librados::WatchCtx2 *ctx);
+    int aio_watch(librados::AioCompletion *c, uint64_t *handle, librados::WatchCtx2 *ctx);
+    int unwatch(uint64_t handle);
+    int notify(bufferlist& bl, uint64_t timeout_ms,
+               bufferlist *pbl, optional_yield y);
+    void notify_ack(uint64_t notify_id,
+                    uint64_t cookie,
+                    bufferlist& bl);
+
+    uint64_t get_last_version();
+
+    rados_ref& get_ref() { return ref; }
+    const rados_ref& get_ref() const { return ref; }
+
+    const rgw_raw_obj& get_raw_obj() const {
+      return ref.obj;
+    }
+  };
+
   class Handle {
     friend class RGWSI_RADOS;
 
@@ -143,15 +199,18 @@ public:
 
     Handle(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
   public:
-    Obj obj(const rgw_raw_obj& o) {
-      return Obj(rados_svc, o);
-    }
+    Obj obj(const rgw_raw_obj& o);
 
     Pool pool(const rgw_pool& p) {
       return Pool(rados_svc, p);
     }
 
     int watch_flush();
+
+    int mon_command(std::string cmd,
+                    const bufferlist& inbl,
+                    bufferlist *outbl,
+                    std::string *outs);
   };
 
   Handle handle() {
@@ -162,6 +221,10 @@ public:
     return Obj(this, o);
   }
 
+  Obj obj(Pool& pool, const string& oid) {
+    return Obj(pool, oid);
+  }
+
   Pool pool() {
     return Pool(this);
   }
@@ -175,4 +238,8 @@ public:
   friend Pool::List;
 };
 
-#endif
+using rgw_rados_ref = RGWSI_RADOS::rados_ref;
+
+inline ostream& operator<<(ostream& out, const RGWSI_RADOS::Obj& obj) {
+  return out << obj.get_raw_obj();
+}