]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /** -*- C++ -*- |
2 | * Copyright (C) 2009-2011 New Dream Network | |
3 | * | |
4 | * This file is part of Hypertable. | |
5 | * | |
6 | * Hypertable is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or any later version. | |
10 | * | |
11 | * Hypertable is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with Hypertable. If not, see <http://www.gnu.org/licenses/> | |
18 | * | |
19 | * Authors: | |
20 | * Gregory Farnum <gfarnum@gmail.com> | |
21 | * Colin McCabe <cmccabe@alumni.cmu.edu> | |
22 | */ | |
23 | ||
24 | #ifndef HYPERTABLE_CEPHBROKER_H | |
25 | #define HYPERTABLE_CEPHBROKER_H | |
26 | ||
27 | extern "C" { | |
28 | #include <unistd.h> | |
29 | } | |
31f18b77 | 30 | #include <atomic> |
7c673cae | 31 | #include "Common/String.h" |
7c673cae FG |
32 | #include "Common/Properties.h" |
33 | ||
34 | #include "DfsBroker/Lib/Broker.h" | |
35 | ||
36 | #include <cephfs/libcephfs.h> | |
37 | ||
38 | namespace Hypertable { | |
39 | using namespace DfsBroker; | |
40 | /** | |
41 | * | |
42 | */ | |
43 | class OpenFileDataCeph : public OpenFileData { | |
44 | public: | |
45 | OpenFileDataCeph(struct ceph_mount_info *cmount_, const String& fname, | |
46 | int _fd, int _flags); | |
47 | virtual ~OpenFileDataCeph(); | |
48 | struct ceph_mount_info *cmount; | |
49 | int fd; | |
50 | int flags; | |
51 | String filename; | |
52 | }; | |
53 | ||
54 | /** | |
55 | * | |
56 | */ | |
57 | class OpenFileDataCephPtr : public OpenFileDataPtr { | |
58 | public: | |
59 | OpenFileDataCephPtr() : OpenFileDataPtr() { } | |
60 | explicit OpenFileDataCephPtr(OpenFileDataCeph *ofdl) : OpenFileDataPtr(ofdl, true) { } | |
61 | OpenFileDataCeph *operator->() const { return static_cast<OpenFileDataCeph *>(get()); } | |
62 | }; | |
63 | ||
64 | /** | |
65 | * | |
66 | */ | |
67 | class CephBroker : public DfsBroker::Broker { | |
68 | public: | |
69 | explicit CephBroker(PropertiesPtr& cfg); | |
70 | virtual ~CephBroker(); | |
71 | ||
72 | virtual void open(ResponseCallbackOpen *cb, const char *fname, | |
73 | uint32_t flags, uint32_t bufsz); | |
74 | virtual void | |
75 | create(ResponseCallbackOpen *cb, const char *fname, uint32_t flags, | |
76 | int32_t bufsz, int16_t replication, int64_t blksz); | |
77 | virtual void close(ResponseCallback *cb, uint32_t fd); | |
78 | virtual void read(ResponseCallbackRead *cb, uint32_t fd, uint32_t amount); | |
79 | virtual void append(ResponseCallbackAppend *cb, uint32_t fd, | |
80 | uint32_t amount, const void *data, bool sync); | |
81 | virtual void seek(ResponseCallback *cb, uint32_t fd, uint64_t offset); | |
82 | virtual void remove(ResponseCallback *cb, const char *fname); | |
83 | virtual void length(ResponseCallbackLength *cb, const char *fname, bool); | |
84 | virtual void pread(ResponseCallbackRead *cb, uint32_t fd, uint64_t offset, | |
85 | uint32_t amount, bool); | |
86 | virtual void mkdirs(ResponseCallback *cb, const char *dname); | |
87 | virtual void rmdir(ResponseCallback *cb, const char *dname); | |
88 | virtual void flush(ResponseCallback *cb, uint32_t fd); | |
89 | virtual void status(ResponseCallback *cb); | |
90 | virtual void shutdown(ResponseCallback *cb); | |
91 | virtual void readdir(ResponseCallbackReaddir *cb, const char *dname); | |
92 | virtual void exists(ResponseCallbackExists *cb, const char *fname); | |
93 | virtual void rename(ResponseCallback *cb, const char *src, const char *dst); | |
94 | virtual void debug(ResponseCallback *, int32_t command, | |
95 | StaticBuffer &serialized_parameters); | |
96 | ||
97 | private: | |
98 | struct ceph_mount_info *cmount; | |
31f18b77 | 99 | static std::atomic<int> ms_next_fd; |
7c673cae FG |
100 | |
101 | virtual void report_error(ResponseCallback *cb, int error); | |
102 | ||
103 | void make_abs_path(const char *fname, String& abs) { | |
104 | if (fname[0] == '/') | |
105 | abs = fname; | |
106 | else | |
107 | abs = m_root_dir + "/" + fname; | |
108 | } | |
109 | ||
110 | int rmdir_recursive(const char *directory); | |
111 | ||
112 | bool m_verbose; | |
113 | String m_root_dir; | |
114 | }; | |
115 | } | |
116 | ||
117 | #endif //HYPERTABLE_CEPH_BROKER_H |