summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_access.cc
blob: 4a5d2542b3415fa2b489bb5de470740f36f29a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <string.h>
#include "rgw_access.h"
#include "rgw_fs.h"
#include "rgw_rados.h"
#include "rgw_cache.h"

#undef DOUT_CONDVAR
#define DOUT_CONDVAR(cct, x) cct->_conf->rgw_log

static RGWCache<RGWFS> cached_fs_provider;
static RGWCache<RGWRados> cached_rados_provider;
static RGWFS fs_provider;
static RGWRados rados_provider;

RGWAccess* RGWAccess::store;

RGWAccess::~RGWAccess()
{
}

RGWAccess *RGWAccess::init_storage_provider(const char *type, CephContext *cct)
{
  int use_cache = cct->_conf->rgw_cache_enabled;
  store = NULL;
  if (!use_cache) {
    if (strcmp(type, "rados") == 0) {
      store = &rados_provider;
    } else if (strcmp(type, "fs") == 0) {
      store = &fs_provider;
    }
  } else {
    if (strcmp(type, "rados") == 0) {
      store = &cached_rados_provider;
    } else if (strcmp(type, "fs") == 0) {
      store = &cached_fs_provider;
    }
  }

  if (store->initialize(cct) < 0)
    store = NULL;

  return store;
}

void RGWAccess::close_storage()
{
  if (!store)
    return;

  store->finalize();
  store = NULL;
}