]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: code-cleanup -- add const when possible and helpful
authorJ. Eric Ivancich <ivancich@redhat.com>
Fri, 1 Mar 2019 17:59:25 +0000 (12:59 -0500)
committerJ. Eric Ivancich <ivancich@redhat.com>
Fri, 8 Mar 2019 21:30:50 +0000 (16:30 -0500)
Found a number of opportunities to add const to parameters and
to member functions.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/cls/rgw/cls_rgw_types.h
src/rgw/rgw_common.h
src/rgw/rgw_multi.cc
src/rgw/rgw_multi.h
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_s3.cc
src/rgw/services/svc_rados.h

index 7a569b64f8da72404709a0667652339a1710c953..83da36995eacf04d3a044cfcec4e661454218f39 100644 (file)
@@ -290,7 +290,7 @@ struct cls_rgw_obj_key {
   bool operator<=(const cls_rgw_obj_key& k) const {
     return !(k < *this);
   }
-  bool empty() {
+  bool empty() const {
     return name.empty();
   }
   void encode(bufferlist &bl) const {
index 97cd168ad8ce8715e16a8e4b3748c2efd2587c7b..cc5ed998341c90ff20fa18347f9efbab2f36f401 100644 (file)
@@ -1779,6 +1779,8 @@ struct rgw_obj_key {
     }
   }
 
+  // takes an oid and parses out the namespace (ns), name, and
+  // instance
   static bool parse_raw_oid(const string& oid, rgw_obj_key *key) {
     key->instance.clear();
     key->ns.clear();
index 5e0689e62e16bb812e40dfc71a02745e56ad1b7f..15b85155ed957e36dfe0bd53540a43cdad4d0ff9 100644 (file)
 
 
 
+bool MultipartMetaFilter::filter(const string& name, string& key) {
+  // the length of the suffix so we can skip past it
+  static const size_t MP_META_SUFFIX_LEN = MP_META_SUFFIX.length();
+
+  size_t len = name.size();
+
+  // make sure there's room for suffix plus at least one more
+  // character
+  if (len <= MP_META_SUFFIX_LEN)
+    return false;
+
+  size_t pos = name.find(MP_META_SUFFIX, len - MP_META_SUFFIX_LEN);
+  if (pos == string::npos)
+    return false;
+
+  pos = name.rfind('.', pos - 1);
+  if (pos == string::npos)
+    return false;
+
+  key = name.substr(0, pos);
+
+  return true;
+}
+
+
 bool RGWMultiPart::xml_end(const char *el)
 {
   RGWMultiPartNumber *num_obj = static_cast<RGWMultiPartNumber *>(find_first("PartNumber"));
@@ -75,12 +100,13 @@ bool is_v2_upload_id(const string& upload_id)
          (strncmp(uid, MULTIPART_UPLOAD_ID_PREFIX_LEGACY, sizeof(MULTIPART_UPLOAD_ID_PREFIX_LEGACY) - 1) == 0);
 }
 
-int list_multipart_parts(RGWRados *store, RGWBucketInfo& bucket_info, CephContext *cct,
-                                const string& upload_id,
-                                string& meta_oid, int num_parts,
-                                int marker, map<uint32_t, RGWUploadPartInfo>& parts,
-                                int *next_marker, bool *truncated,
-                                bool assume_unsorted)
+int list_multipart_parts(RGWRados *store, RGWBucketInfo& bucket_info,
+                        CephContext *cct,
+                        const string& upload_id,
+                        const string& meta_oid, int num_parts,
+                        int marker, map<uint32_t, RGWUploadPartInfo>& parts,
+                        int *next_marker, bool *truncated,
+                        bool assume_unsorted)
 {
   map<string, bufferlist> parts_map;
   map<string, bufferlist>::iterator iter;
@@ -178,11 +204,11 @@ int list_multipart_parts(RGWRados *store, RGWBucketInfo& bucket_info, CephContex
 }
 
 int list_multipart_parts(RGWRados *store, struct req_state *s,
-                                const string& upload_id,
-                                string& meta_oid, int num_parts,
-                                int marker, map<uint32_t, RGWUploadPartInfo>& parts,
-                                int *next_marker, bool *truncated,
-                                bool assume_unsorted)
+                        const string& upload_id,
+                        const string& meta_oid, int num_parts,
+                        int marker, map<uint32_t, RGWUploadPartInfo>& parts,
+                        int *next_marker, bool *truncated,
+                        bool assume_unsorted)
 {
   return list_multipart_parts(store, s->bucket_info, s->cct, upload_id, meta_oid, num_parts, marker, parts, next_marker, truncated, assume_unsorted);
 }
index f406213b4090fa72a455cd8245a96020469aa9d9..4cb553d02365ee5e605af7d5d15363d802908392 100644 (file)
@@ -8,7 +8,6 @@
 #include "rgw_xml.h"
 #include "rgw_rados.h"
 
-#define MP_META_SUFFIX ".meta"
 #define MULTIPART_UPLOAD_ID_PREFIX_LEGACY "2/"
 #define MULTIPART_UPLOAD_ID_PREFIX "2~" // must contain a unique char that may not come up in gen_rand_alpha()
 
@@ -57,40 +56,44 @@ public:
   ~RGWMultiXMLParser() override {}
 };
 
+/**
+ * A filter to a) test whether an object name is a multipart meta
+ * object, and b) filter out just the key used to determine the bucket
+ * index shard.
+ *
+ * Objects for multipart meta have names adorned with an upload id and
+ * other elements -- specifically a ".", MULTIPART_UPLOAD_ID_PREFIX,
+ * unique id, and MP_META_SUFFIX. This filter will return true when
+ * the name provided is such. It will also extract the key used for
+ * bucket index shard calculation from the adorned name.
+ */
 class MultipartMetaFilter : public RGWAccessListFilter {
 public:
   MultipartMetaFilter() {}
-  bool filter(string& name, string& key) override {
-    int len = name.size();
-    if (len < 6)
-      return false;
 
-    size_t pos = name.find(MP_META_SUFFIX, len - 5);
-    if (pos == string::npos)
-      return false;
-
-    pos = name.rfind('.', pos - 1);
-    if (pos == string::npos)
-      return false;
-
-    key = name.substr(0, pos);
-
-    return true;
-  }
-};
+  /**
+   * @param name [in] The object name as it appears in the bucket index.
+   * @param key [out] An output parameter that will contain the bucket
+   *        index key if this entry is in the form of a multipart meta object.
+   * @return true if the name provided is in the form of a multipart meta
+   *         object, false otherwise
+   */
+  bool filter(const string& name, string& key) override;
+}; // class MultipartMetaFilter
 
 extern bool is_v2_upload_id(const string& upload_id);
 
-extern int list_multipart_parts(RGWRados *store, RGWBucketInfo& bucket_info, CephContext *cct,
+extern int list_multipart_parts(RGWRados *store, RGWBucketInfo& bucket_info,
+                               CephContext *cct,
                                 const string& upload_id,
-                                string& meta_oid, int num_parts,
+                                const string& meta_oid, int num_parts,
                                 int marker, map<uint32_t, RGWUploadPartInfo>& parts,
                                 int *next_marker, bool *truncated,
                                 bool assume_unsorted = false);
 
 extern int list_multipart_parts(RGWRados *store, struct req_state *s,
                                 const string& upload_id,
-                                string& meta_oid, int num_parts,
+                                const string& meta_oid, int num_parts,
                                 int marker, map<uint32_t, RGWUploadPartInfo>& parts,
                                 int *next_marker, bool *truncated,
                                 bool assume_unsorted = false);
index 76c17bedfa99f6a6b767ac98a32a50f653e4f68c..35ef484004694148d552b5ce08bcb0e7df480264 100644 (file)
@@ -424,7 +424,7 @@ static int get_multipart_info(RGWRados *store, struct req_state *s,
 }
 
 static int get_multipart_info(RGWRados *store, struct req_state *s,
-                             string& meta_oid,
+                             const string& meta_oid,
                               RGWAccessControlPolicy *policy,
                              map<string, bufferlist> *attrs,
                               multipart_upload_info *upload_info)
index 2a45850b42a1d81a0eedb3a82e908add702fd3f4..c424e5bca8b60c4493b45235ee8fe60c73bd48c9 100644 (file)
@@ -103,9 +103,10 @@ static string log_lock_name = "rgw_log_lock";
 static RGWObjCategory main_category = RGWObjCategory::Main;
 #define RGW_USAGE_OBJ_PREFIX "usage."
 
-
 #define dout_subsys ceph_subsys_rgw
 
+const std::string MP_META_SUFFIX = ".meta";
+
 
 static bool rgw_get_obj_data_pool(const RGWZoneGroup& zonegroup, const RGWZoneParams& zone_params,
                                   const rgw_placement_rule& head_placement_rule,
@@ -9022,7 +9023,7 @@ int RGWRados::cls_obj_set_bucket_tag_timeout(RGWBucketInfo& bucket_info, uint64_
 
 int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
                                      int shard_id,
-                                     rgw_obj_index_key& start,
+                                     const rgw_obj_index_key& start,
                                      const string& prefix,
                                      uint32_t num_entries,
                                      bool list_versions,
@@ -9146,7 +9147,7 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
 
 int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
                                        int shard_id,
-                                       rgw_obj_index_key& start,
+                                       const rgw_obj_index_key& start,
                                        const string& prefix,
                                        uint32_t num_entries,
                                        bool list_versions,
index 57b26324b57dee3b61c4f4601ab56ca118e73f96..4ff8a611a25aa6c78b9922513d7553ae8bbd0c99 100644 (file)
@@ -65,6 +65,8 @@ class RGWSysObjectCtx;
 #define RGW_SHARDS_PRIME_0 7877
 #define RGW_SHARDS_PRIME_1 65521
 
+extern const std::string MP_META_SUFFIX;
+
 // only called by rgw_shard_id and rgw_bucket_shard_index
 static inline int rgw_shards_mod(unsigned hval, int max_shards)
 {
@@ -2201,14 +2203,16 @@ public:
   int cls_obj_complete_cancel(BucketShard& bs, string& tag, rgw_obj& obj, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
   int cls_obj_set_bucket_tag_timeout(RGWBucketInfo& bucket_info, uint64_t timeout);
   int cls_bucket_list_ordered(RGWBucketInfo& bucket_info, int shard_id,
-                             rgw_obj_index_key& start, const string& prefix,
+                             const rgw_obj_index_key& start,
+                             const string& prefix,
                              uint32_t num_entries, bool list_versions,
                              map<string, rgw_bucket_dir_entry>& m,
                              bool *is_truncated,
                              rgw_obj_index_key *last_entry,
                              bool (*force_check_filter)(const string& name) = nullptr);
   int cls_bucket_list_unordered(RGWBucketInfo& bucket_info, int shard_id,
-                               rgw_obj_index_key& start, const string& prefix,
+                               const rgw_obj_index_key& start,
+                               const string& prefix,
                                uint32_t num_entries, bool list_versions,
                                vector<rgw_bucket_dir_entry>& ent_list,
                                bool *is_truncated, rgw_obj_index_key *last_entry,
@@ -2479,8 +2483,6 @@ public:
 
 };
 
-#define MP_META_SUFFIX ".meta"
-
 class RGWMPObj {
   string oid;
   string prefix;
@@ -2505,24 +2507,24 @@ public:
     meta = prefix + upload_id + MP_META_SUFFIX;
     prefix.append(part_unique_str);
   }
-  string& get_meta() { return meta; }
-  string get_part(int num) {
+  const string& get_meta() const { return meta; }
+  string get_part(int num) const {
     char buf[16];
     snprintf(buf, 16, ".%d", num);
     string s = prefix;
     s.append(buf);
     return s;
   }
-  string get_part(string& part) {
+  string get_part(const string& part) const {
     string s = prefix;
     s.append(".");
     s.append(part);
     return s;
   }
-  string& get_upload_id() {
+  const string& get_upload_id() const {
     return upload_id;
   }
-  string& get_key() {
+  const string& get_key() const {
     return oid;
   }
   bool from_meta(string& meta) {
@@ -2543,7 +2545,7 @@ public:
     meta = "";
     upload_id = "";
   }
-};
+}; // class RGWMPObj
 
 
 class RGWRadosThread {
index 424f42f87f06bc65e3a9ea38ca86b8967c957a96..a900b0a79b99120606e5befc4e86ab76fb2db252 100644 (file)
@@ -2763,10 +2763,10 @@ void RGWListBucketMultiparts_ObjStore_S3::send_response()
   s->formatter->dump_string("Bucket", s->bucket_name);
   if (!prefix.empty())
     s->formatter->dump_string("ListMultipartUploadsResult.Prefix", prefix);
-  string& key_marker = marker.get_key();
+  const string& key_marker = marker.get_key();
   if (!key_marker.empty())
     s->formatter->dump_string("KeyMarker", key_marker);
-  string& upload_id_marker = marker.get_upload_id();
+  const string& upload_id_marker = marker.get_upload_id();
   if (!upload_id_marker.empty())
     s->formatter->dump_string("UploadIdMarker", upload_id_marker);
   string next_key = next_marker.mp.get_key();
index 0bc3955db015177f839d4698a7738cbf773191ff..a90558696cf9a8a36b215a9185321d677981e9ce 100644 (file)
 class RGWAccessListFilter {
 public:
   virtual ~RGWAccessListFilter() {}
-  virtual bool filter(string& name, string& key) = 0;
+  virtual bool filter(const string& name, string& key) = 0;
 };
 
 struct RGWAccessListFilterPrefix : public RGWAccessListFilter {
   string prefix;
 
   explicit RGWAccessListFilterPrefix(const string& _prefix) : prefix(_prefix) {}
-  bool filter(string& name, string& key) override {
+  bool filter(const string& name, string& key) override {
     return (prefix.compare(key.substr(0, prefix.size())) == 0);
   }
 };