This is an automated email from the ASF dual-hosted git repository.

jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9cec2633f1 Move Doc struct to Doc.h (#11026)
9cec2633f1 is described below

commit 9cec2633f1d195cb557c49eaee57574aaaa398b9
Author: JosiahWI <[email protected]>
AuthorDate: Wed Mar 13 11:50:11 2024 -0500

    Move Doc struct to Doc.h (#11026)
    
    * Move Doc struct to separate file
    
    * Add self_type to Doc
    
    * Move include/iocore/cache/Doc.h to src/iocore/cache/P_Doc.h
---
 include/iocore/cache/CacheVC.h         |  1 +
 src/iocore/cache/Cache.cc              |  1 +
 src/iocore/cache/CacheDir.cc           |  1 +
 src/iocore/cache/CacheEvacuateDocVC.cc |  1 +
 src/iocore/cache/CacheRead.cc          |  1 +
 src/iocore/cache/CacheVC.cc            |  1 +
 src/iocore/cache/CacheWrite.cc         |  1 +
 src/iocore/cache/P_CacheDir.h          |  2 +
 src/iocore/cache/P_CacheDoc.h          | 98 ++++++++++++++++++++++++++++++++++
 src/iocore/cache/P_CacheInternal.h     |  1 +
 src/iocore/cache/P_CacheTest.h         |  1 +
 src/iocore/cache/P_CacheVol.h          | 69 +-----------------------
 src/iocore/cache/Stripe.cc             |  1 +
 13 files changed, 111 insertions(+), 68 deletions(-)

diff --git a/include/iocore/cache/CacheVC.h b/include/iocore/cache/CacheVC.h
index b3044b80d8..93a8c84278 100644
--- a/include/iocore/cache/CacheVC.h
+++ b/include/iocore/cache/CacheVC.h
@@ -27,6 +27,7 @@
 // inkcache
 #include "iocore/cache/Cache.h"
 #include "../../../src/iocore/cache/P_CacheDir.h"
+#include "../../../src/iocore/cache/P_CacheDoc.h"
 #include "../../../src/iocore/cache/P_CacheVol.h"
 */
 #include "../../../src/iocore/cache/P_CacheHttp.h"
diff --git a/src/iocore/cache/Cache.cc b/src/iocore/cache/Cache.cc
index 3e0beecbde..4e19cd5853 100644
--- a/src/iocore/cache/Cache.cc
+++ b/src/iocore/cache/Cache.cc
@@ -23,6 +23,7 @@
 
 #include "iocore/cache/Cache.h"
 
+#include "P_CacheDoc.h"
 // Cache Inspector and State Pages
 #include "P_CacheTest.h"
 
diff --git a/src/iocore/cache/CacheDir.cc b/src/iocore/cache/CacheDir.cc
index 4daa794f82..6fe51ea76a 100644
--- a/src/iocore/cache/CacheDir.cc
+++ b/src/iocore/cache/CacheDir.cc
@@ -23,6 +23,7 @@
 
 #include "P_Cache.h"
 #include "P_CacheDir.h"
+#include "P_CacheDoc.h"
 
 #include "tscore/hugepages.h"
 #include "tscore/Random.h"
diff --git a/src/iocore/cache/CacheEvacuateDocVC.cc 
b/src/iocore/cache/CacheEvacuateDocVC.cc
index 44b9d40132..09aa5b772a 100644
--- a/src/iocore/cache/CacheEvacuateDocVC.cc
+++ b/src/iocore/cache/CacheEvacuateDocVC.cc
@@ -28,6 +28,7 @@
 
 // inkcache
 #include "iocore/cache/CacheDefs.h"
+#include "P_CacheDoc.h"
 #include "P_CacheHttp.h"
 #include "P_CacheInternal.h"
 #include "P_CacheVol.h"
diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc
index a17471ee34..ef9d5c4b35 100644
--- a/src/iocore/cache/CacheRead.cc
+++ b/src/iocore/cache/CacheRead.cc
@@ -22,6 +22,7 @@
  */
 
 #include "P_Cache.h"
+#include "P_CacheDoc.h"
 
 namespace
 {
diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc
index 5f2b5fba45..41e5749dd2 100644
--- a/src/iocore/cache/CacheVC.cc
+++ b/src/iocore/cache/CacheVC.cc
@@ -24,6 +24,7 @@
 #include "iocore/cache/Cache.h"
 #include "iocore/cache/CacheDefs.h"
 #include "P_CacheDisk.h"
+#include "P_CacheDoc.h"
 #include "P_CacheHttp.h"
 #include "P_CacheInternal.h"
 #include "P_CacheVol.h"
diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc
index 9810a9eab0..743cb545cf 100644
--- a/src/iocore/cache/CacheWrite.cc
+++ b/src/iocore/cache/CacheWrite.cc
@@ -22,6 +22,7 @@
  */
 
 #include "P_Cache.h"
+#include "P_CacheDoc.h"
 #include "iocore/cache/AggregateWriteBuffer.h"
 #include "iocore/cache/CacheEvacuateDocVC.h"
 
diff --git a/src/iocore/cache/P_CacheDir.h b/src/iocore/cache/P_CacheDir.h
index ddf3ad27a8..7f8911f90d 100644
--- a/src/iocore/cache/P_CacheDir.h
+++ b/src/iocore/cache/P_CacheDir.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "P_CacheDoc.h"
+
 #include "iocore/cache/CacheDefs.h"
 #include "P_CacheHttp.h"
 #include "iocore/eventsystem/EventSystem.h"
diff --git a/src/iocore/cache/P_CacheDoc.h b/src/iocore/cache/P_CacheDoc.h
new file mode 100644
index 0000000000..782297faaf
--- /dev/null
+++ b/src/iocore/cache/P_CacheDoc.h
@@ -0,0 +1,98 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include "tscore/CryptoHash.h"
+
+#include <cstdint>
+
+#define DOC_MAGIC       ((uint32_t)0x5F129B13)
+#define DOC_CORRUPT     ((uint32_t)0xDEADBABE)
+#define DOC_NO_CHECKSUM ((uint32_t)0xA0B0C0D0)
+
+// Note : hdr() needs to be 8 byte aligned.
+struct Doc {
+  uint32_t magic;     // DOC_MAGIC
+  uint32_t len;       // length of this fragment (including hlen & 
sizeof(Doc), unrounded)
+  uint64_t total_len; // total length of document
+#if TS_ENABLE_FIPS == 1
+  // For FIPS CryptoHash is 256 bits vs. 128, and the 'first_key' must be 
checked first, so
+  // ensure that the new 'first_key' overlaps the old 'first_key' and that the 
rest of the data layout
+  // is the same by putting 'key' at the ned.
+  CryptoHash first_key; ///< first key in object.
+#else
+  CryptoHash first_key; ///< first key in object.
+  CryptoHash key;       ///< Key for this doc.
+#endif
+  uint32_t hlen;         ///< Length of this header.
+  uint32_t doc_type : 8; ///< Doc type - indicates the format of this 
structure and its content.
+  uint32_t v_major  : 8; ///< Major version number.
+  uint32_t v_minor  : 8; ///< Minor version number.
+  uint32_t unused   : 8; ///< Unused, forced to zero.
+  uint32_t sync_serial;
+  uint32_t write_serial;
+  uint32_t pinned; ///< pinned until - CAVEAT: use uint32_t instead of time_t 
for the cache compatibility
+  uint32_t checksum;
+#if TS_ENABLE_FIPS == 1
+  CryptoHash key; ///< Key for this doc.
+#endif
+
+  uint32_t data_len() const;
+  uint32_t prefix_len() const;
+  int single_fragment() const;
+  char *hdr();
+  char *data();
+
+  using self_type = Doc;
+};
+
+inline uint32_t
+Doc::prefix_len() const
+{
+  return sizeof(self_type) + this->hlen;
+}
+
+inline uint32_t
+Doc::data_len() const
+{
+  return this->len - sizeof(self_type) - this->hlen;
+}
+
+inline int
+Doc::single_fragment() const
+{
+  return this->data_len() == this->total_len;
+}
+
+inline char *
+Doc::hdr()
+{
+  return reinterpret_cast<char *>(this) + sizeof(self_type);
+}
+
+inline char *
+Doc::data()
+{
+  return this->hdr() + this->hlen;
+}
diff --git a/src/iocore/cache/P_CacheInternal.h 
b/src/iocore/cache/P_CacheInternal.h
index ad31b8bb79..57988c7ab7 100644
--- a/src/iocore/cache/P_CacheInternal.h
+++ b/src/iocore/cache/P_CacheInternal.h
@@ -28,6 +28,7 @@
 #include "tscore/InkErrno.h"
 
 #include "proxy/hdrs/HTTP.h"
+#include "P_CacheDoc.h"
 #include "P_CacheHttp.h"
 #include "P_CacheHosting.h"
 #include "tsutil/Metrics.h"
diff --git a/src/iocore/cache/P_CacheTest.h b/src/iocore/cache/P_CacheTest.h
index 07759b2817..e59497f0cd 100644
--- a/src/iocore/cache/P_CacheTest.h
+++ b/src/iocore/cache/P_CacheTest.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "P_Cache.h"
+#include "P_CacheDoc.h"
 #include "proxy/RegressionSM.h"
 
 #define MAX_HOSTS_POSSIBLE    256
diff --git a/src/iocore/cache/P_CacheVol.h b/src/iocore/cache/P_CacheVol.h
index 8c0f8a7bdf..54aabc0644 100644
--- a/src/iocore/cache/P_CacheVol.h
+++ b/src/iocore/cache/P_CacheVol.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "P_CacheDir.h"
+#include "P_CacheDoc.h"
 #include "P_CacheStats.h"
 #include "P_RamCache.h"
 #include "iocore/cache/AggregateWriteBuffer.h"
@@ -71,10 +72,6 @@
 
 // Documents
 
-#define DOC_MAGIC       ((uint32_t)0x5F129B13)
-#define DOC_CORRUPT     ((uint32_t)0xDEADBABE)
-#define DOC_NO_CHECKSUM ((uint32_t)0xA0B0C0D0)
-
 struct Cache;
 class Stripe;
 struct CacheDisk;
@@ -359,40 +356,6 @@ struct CacheVol {
   CacheVol() {}
 };
 
-// Note : hdr() needs to be 8 byte aligned.
-struct Doc {
-  uint32_t magic;     // DOC_MAGIC
-  uint32_t len;       // length of this fragment (including hlen & 
sizeof(Doc), unrounded)
-  uint64_t total_len; // total length of document
-#if TS_ENABLE_FIPS == 1
-  // For FIPS CryptoHash is 256 bits vs. 128, and the 'first_key' must be 
checked first, so
-  // ensure that the new 'first_key' overlaps the old 'first_key' and that the 
rest of the data layout
-  // is the same by putting 'key' at the ned.
-  CryptoHash first_key; ///< first key in object.
-#else
-  CryptoHash first_key; ///< first key in object.
-  CryptoHash key;       ///< Key for this doc.
-#endif
-  uint32_t hlen;         ///< Length of this header.
-  uint32_t doc_type : 8; ///< Doc type - indicates the format of this 
structure and its content.
-  uint32_t v_major  : 8; ///< Major version number.
-  uint32_t v_minor  : 8; ///< Minor version number.
-  uint32_t unused   : 8; ///< Unused, forced to zero.
-  uint32_t sync_serial;
-  uint32_t write_serial;
-  uint32_t pinned; ///< pinned until - CAVEAT: use uint32_t instead of time_t 
for the cache compatibility
-  uint32_t checksum;
-#if TS_ENABLE_FIPS == 1
-  CryptoHash key; ///< Key for this doc.
-#endif
-
-  uint32_t data_len() const;
-  uint32_t prefix_len() const;
-  int single_fragment() const;
-  char *hdr();
-  char *data();
-};
-
 // Global Data
 
 extern Stripe **gstripes;
@@ -485,36 +448,6 @@ Stripe::vol_relative_length(off_t start_offset) const
   return (this->len + this->skip) - start_offset;
 }
 
-inline uint32_t
-Doc::prefix_len() const
-{
-  return sizeof(Doc) + hlen;
-}
-
-inline uint32_t
-Doc::data_len() const
-{
-  return len - sizeof(Doc) - hlen;
-}
-
-inline int
-Doc::single_fragment() const
-{
-  return data_len() == total_len;
-}
-
-inline char *
-Doc::hdr()
-{
-  return reinterpret_cast<char *>(this) + sizeof(Doc);
-}
-
-inline char *
-Doc::data()
-{
-  return this->hdr() + hlen;
-}
-
 // inline Functions
 
 inline EvacuationBlock *
diff --git a/src/iocore/cache/Stripe.cc b/src/iocore/cache/Stripe.cc
index af11febf72..71dbc07ea0 100644
--- a/src/iocore/cache/Stripe.cc
+++ b/src/iocore/cache/Stripe.cc
@@ -23,6 +23,7 @@
 
 #include "iocore/cache/Cache.h"
 #include "P_CacheDisk.h"
+#include "P_CacheDoc.h"
 #include "P_CacheInternal.h"
 #include "P_CacheVol.h"
 

Reply via email to