]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_tier_rados.h
import 15.2.4
[ceph.git] / ceph / src / rgw / services / svc_tier_rados.h
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 <iomanip>
20
21 #include "rgw/rgw_service.h"
22
23 #include "svc_rados.h"
24
25 extern const std::string MP_META_SUFFIX;
26
27 class RGWMPObj {
28 string oid;
29 string prefix;
30 string meta;
31 string upload_id;
32 public:
33 RGWMPObj() {}
34 RGWMPObj(const string& _oid, const string& _upload_id) {
35 init(_oid, _upload_id, _upload_id);
36 }
37 void init(const string& _oid, const string& _upload_id) {
38 init(_oid, _upload_id, _upload_id);
39 }
40 void init(const string& _oid, const string& _upload_id, const string& part_unique_str) {
41 if (_oid.empty()) {
42 clear();
43 return;
44 }
45 oid = _oid;
46 upload_id = _upload_id;
47 prefix = oid + ".";
48 meta = prefix + upload_id + MP_META_SUFFIX;
49 prefix.append(part_unique_str);
50 }
51 const string& get_meta() const { return meta; }
52 string get_part(int num) const {
53 char buf[16];
54 snprintf(buf, 16, ".%d", num);
55 string s = prefix;
56 s.append(buf);
57 return s;
58 }
59 string get_part(const string& part) const {
60 string s = prefix;
61 s.append(".");
62 s.append(part);
63 return s;
64 }
65 const string& get_upload_id() const {
66 return upload_id;
67 }
68 const string& get_key() const {
69 return oid;
70 }
71 bool from_meta(const string& meta) {
72 int end_pos = meta.rfind('.'); // search for ".meta"
73 if (end_pos < 0)
74 return false;
75 int mid_pos = meta.rfind('.', end_pos - 1); // <key>.<upload_id>
76 if (mid_pos < 0)
77 return false;
78 oid = meta.substr(0, mid_pos);
79 upload_id = meta.substr(mid_pos + 1, end_pos - mid_pos - 1);
80 init(oid, upload_id, upload_id);
81 return true;
82 }
83 void clear() {
84 oid = "";
85 prefix = "";
86 meta = "";
87 upload_id = "";
88 }
89 friend std::ostream& operator<<(std::ostream& out, const RGWMPObj& obj) {
90 return out << "RGWMPObj:{ prefix=" << std::quoted(obj.prefix) <<
91 ", meta=" << std::quoted(obj.meta) << " }";
92 }
93 }; // class RGWMPObj
94
95 /**
96 * A filter to a) test whether an object name is a multipart meta
97 * object, and b) filter out just the key used to determine the bucket
98 * index shard.
99 *
100 * Objects for multipart meta have names adorned with an upload id and
101 * other elements -- specifically a ".", MULTIPART_UPLOAD_ID_PREFIX,
102 * unique id, and MP_META_SUFFIX. This filter will return true when
103 * the name provided is such. It will also extract the key used for
104 * bucket index shard calculation from the adorned name.
105 */
106 class MultipartMetaFilter : public RGWAccessListFilter {
107 public:
108 MultipartMetaFilter() {}
109
110 /**
111 * @param name [in] The object name as it appears in the bucket index.
112 * @param key [out] An output parameter that will contain the bucket
113 * index key if this entry is in the form of a multipart meta object.
114 * @return true if the name provided is in the form of a multipart meta
115 * object, false otherwise
116 */
117 bool filter(const string& name, string& key) override;
118 };
119
120 class RGWSI_Tier_RADOS : public RGWServiceInstance
121 {
122 RGWSI_Zone *zone_svc{nullptr};
123
124 public:
125 RGWSI_Tier_RADOS(CephContext *cct): RGWServiceInstance(cct) {}
126
127 void init(RGWSI_Zone *_zone_svc) {
128 zone_svc = _zone_svc;
129 }
130
131 static inline bool raw_obj_to_obj(const rgw_bucket& bucket, const rgw_raw_obj& raw_obj, rgw_obj *obj) {
132 ssize_t pos = raw_obj.oid.find('_');
133 if (pos < 0) {
134 return false;
135 }
136
137 if (!rgw_obj_key::parse_raw_oid(raw_obj.oid.substr(pos + 1), &obj->key)) {
138 return false;
139 }
140 obj->bucket = bucket;
141
142 return true;
143 }
144 };
145