]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
4 | /* | |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2019 Red Hat, Inc. | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | * | |
14 | */ | |
15 | ||
16 | ||
17 | #pragma once | |
18 | ||
19 | #include "rgw/rgw_service.h" | |
20 | ||
21 | #include "svc_rados.h" | |
22 | ||
23 | extern const std::string MP_META_SUFFIX; | |
24 | ||
25 | class RGWMPObj { | |
26 | string oid; | |
27 | string prefix; | |
28 | string meta; | |
29 | string upload_id; | |
30 | public: | |
31 | RGWMPObj() {} | |
32 | RGWMPObj(const string& _oid, const string& _upload_id) { | |
33 | init(_oid, _upload_id, _upload_id); | |
34 | } | |
35 | void init(const string& _oid, const string& _upload_id) { | |
36 | init(_oid, _upload_id, _upload_id); | |
37 | } | |
38 | void init(const string& _oid, const string& _upload_id, const string& part_unique_str) { | |
39 | if (_oid.empty()) { | |
40 | clear(); | |
41 | return; | |
42 | } | |
43 | oid = _oid; | |
44 | upload_id = _upload_id; | |
45 | prefix = oid + "."; | |
46 | meta = prefix + upload_id + MP_META_SUFFIX; | |
47 | prefix.append(part_unique_str); | |
48 | } | |
49 | const string& get_meta() const { return meta; } | |
50 | string get_part(int num) const { | |
51 | char buf[16]; | |
52 | snprintf(buf, 16, ".%d", num); | |
53 | string s = prefix; | |
54 | s.append(buf); | |
55 | return s; | |
56 | } | |
57 | string get_part(string& part) const { | |
58 | string s = prefix; | |
59 | s.append("."); | |
60 | s.append(part); | |
61 | return s; | |
62 | } | |
63 | const string& get_upload_id() const { | |
64 | return upload_id; | |
65 | } | |
66 | const string& get_key() const { | |
67 | return oid; | |
68 | } | |
69 | bool from_meta(string& meta) { | |
70 | int end_pos = meta.rfind('.'); // search for ".meta" | |
71 | if (end_pos < 0) | |
72 | return false; | |
73 | int mid_pos = meta.rfind('.', end_pos - 1); // <key>.<upload_id> | |
74 | if (mid_pos < 0) | |
75 | return false; | |
76 | oid = meta.substr(0, mid_pos); | |
77 | upload_id = meta.substr(mid_pos + 1, end_pos - mid_pos - 1); | |
78 | init(oid, upload_id, upload_id); | |
79 | return true; | |
80 | } | |
81 | void clear() { | |
82 | oid = ""; | |
83 | prefix = ""; | |
84 | meta = ""; | |
85 | upload_id = ""; | |
86 | } | |
87 | }; // class RGWMPObj | |
88 | ||
89 | /** | |
90 | * A filter to a) test whether an object name is a multipart meta | |
91 | * object, and b) filter out just the key used to determine the bucket | |
92 | * index shard. | |
93 | * | |
94 | * Objects for multipart meta have names adorned with an upload id and | |
95 | * other elements -- specifically a ".", MULTIPART_UPLOAD_ID_PREFIX, | |
96 | * unique id, and MP_META_SUFFIX. This filter will return true when | |
97 | * the name provided is such. It will also extract the key used for | |
98 | * bucket index shard calculation from the adorned name. | |
99 | */ | |
100 | class MultipartMetaFilter : public RGWAccessListFilter { | |
101 | public: | |
102 | MultipartMetaFilter() {} | |
103 | ||
104 | /** | |
105 | * @param name [in] The object name as it appears in the bucket index. | |
106 | * @param key [out] An output parameter that will contain the bucket | |
107 | * index key if this entry is in the form of a multipart meta object. | |
108 | * @return true if the name provided is in the form of a multipart meta | |
109 | * object, false otherwise | |
110 | */ | |
111 | bool filter(const string& name, string& key) override; | |
112 | }; | |
113 | ||
114 | class RGWSI_Tier_RADOS : public RGWServiceInstance | |
115 | { | |
116 | RGWSI_Zone *zone_svc{nullptr}; | |
117 | ||
118 | public: | |
119 | RGWSI_Tier_RADOS(CephContext *cct): RGWServiceInstance(cct) {} | |
120 | ||
121 | void init(RGWSI_Zone *_zone_svc) { | |
122 | zone_svc = _zone_svc; | |
123 | } | |
124 | ||
125 | static inline bool raw_obj_to_obj(const rgw_bucket& bucket, const rgw_raw_obj& raw_obj, rgw_obj *obj) { | |
126 | ssize_t pos = raw_obj.oid.find('_'); | |
127 | if (pos < 0) { | |
128 | return false; | |
129 | } | |
130 | ||
131 | if (!rgw_obj_key::parse_raw_oid(raw_obj.oid.substr(pos + 1), &obj->key)) { | |
132 | return false; | |
133 | } | |
134 | obj->bucket = bucket; | |
135 | ||
136 | return true; | |
137 | } | |
138 | }; | |
139 |