|
|
|||
File indexing completed on 2026-01-07 10:26:22
0001 #ifndef __XRDOUCPGRWUTILS_HH__ 0002 #define __XRDOUCPGRWUTILS_HH__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c P g r w U t i l s . h h */ 0006 /* */ 0007 /* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* All Rights Reserved */ 0009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0011 /* */ 0012 /* This file is part of the XRootD software suite. */ 0013 /* */ 0014 /* XRootD is free software: you can redistribute it and/or modify it under */ 0015 /* the terms of the GNU Lesser General Public License as published by the */ 0016 /* Free Software Foundation, either version 3 of the License, or (at your */ 0017 /* option) any later version. */ 0018 /* */ 0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0022 /* License for more details. */ 0023 /* */ 0024 /* You should have received a copy of the GNU Lesser General Public License */ 0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0027 /* */ 0028 /* The copyright holder's institutional names and contributor's names may not */ 0029 /* be used to endorse or promote products derived from this software without */ 0030 /* specific prior written permission of the institution or contributor. */ 0031 /******************************************************************************/ 0032 0033 #include <cstdint> 0034 #include <vector> 0035 #include <sys/types.h> 0036 0037 class XrdOucPgrwUtils 0038 { 0039 public: 0040 0041 //------------------------------------------------------------------------------ 0042 //! Compute a CRC32C checksums for a pgRead/pgWrite request. 0043 //! 0044 //! @param data Pointer to the data whose checksum it to be computed. 0045 //! @param offs The offset at which the read or write occurs. 0046 //! @param count The number of bytes pointed to by data. 0047 //! @param csval Pointer to a vector to hold individual page checksums. The 0048 //! raw vector must be sized as computed by csNum(). When 0049 //! passed an std::vector, it is done automatically. 0050 //! On return, each element of csval holds the checksum for 0051 //! the associated page. 0052 //------------------------------------------------------------------------------ 0053 0054 static void csCalc(const char* data, off_t offs, size_t count, 0055 uint32_t* csval); 0056 0057 static void csCalc(const char* data, off_t offs, size_t count, 0058 std::vector<uint32_t> &csvec); 0059 0060 //------------------------------------------------------------------------------ 0061 //! Compute the required size of a checksum vector based on offset & length 0062 //| applying the pgRead/pgWrite requirements. 0063 //! 0064 //! @param offs The offset at which the read or write occurs. 0065 //! @param count The number of bytes read or to write. 0066 //! 0067 //! @return The number of checksums that are needed. 0068 //------------------------------------------------------------------------------ 0069 0070 static int csNum(off_t offs, int count); 0071 0072 //------------------------------------------------------------------------------ 0073 //! Compute the required size of a checksum vector based on offset & length 0074 //| applying the pgRead/pgWrite requirements and return the length of the first 0075 //! and last segments required in the iov vector. 0076 //! 0077 //! @param offs The offset at which the read or write occurs. 0078 //! @param count The number of bytes read or to write excluding checksums. 0079 //! @param fLen The number of bytes needed in iov[0].iov_length 0080 //! @param lLen The number of bytes needed in iov[csnum-1].iov_length 0081 //! 0082 //! @return The number of checksums that are needed. 0083 //------------------------------------------------------------------------------ 0084 0085 static int csNum(off_t offs, int count, int &fLen, int &lLen); 0086 0087 //------------------------------------------------------------------------------ 0088 //! Verify CRC32C checksums for a pgWrite request. 0089 //! 0090 //! @param dInfo Reference to the data information used or state control. 0091 //! @param bado The offset in error when return false. 0092 //! @param badc The length of erroneous data at bado. 0093 //! 0094 //! @return true if all the checksums match. Otherwise, false is returned with 0095 //! bado and badc set and dInfo is updated so that the next call with 0096 //! the same dInfo will verify the remaing data. To avoid an unneeded 0097 //! call first check if dInfo.count is positive. 0098 //------------------------------------------------------------------------------ 0099 0100 struct dataInfo 0101 {const char* data; //!< Pointer to data buffer 0102 const uint32_t* csval; //!< Pointer to vector of checksums 0103 off_t offs; //!< Offset associated with data 0104 int count; //!< Number of bytes to check 0105 0106 dataInfo(const char* dP, const uint32_t* cP, off_t o, int n) 0107 : data(dP), csval(cP), offs(o), count(n) {} 0108 }; 0109 0110 static bool csVer(dataInfo &dInfo, off_t &bado, int &badc); 0111 0112 //------------------------------------------------------------------------------ 0113 //! Compute the layout for an iovec that receives network bytes applying 0114 //| pgRead/pgWrite requirements. 0115 //! 0116 //! @param layout Reference to the layout parameter (see below). 0117 //! @param offs recvLayout: Offset at which the subsequent write occurs. 0118 //! sendLayout: Offset at which the preceding read occurs. 0119 //! @param dlen recvLayout: Nmber of sock bytes to receive with checksums. 0120 //! @param dlen sendLayout: Nmber of file bytes to read without checksums. 0121 //! @param bsz The size of the buffer exclusive of any checksums and must 0122 //! be a multiple of 4096 (one page). If it's <= 0 then then the 0123 //! layout is computed as if bsz could fully accomodate the dlen. 0124 //! 0125 //! @return The number of checksums that are needed. If the result is zero then 0126 //! the supplied offset/dlen violates requirements amd eWhy holds reason. 0127 //! 0128 //! @note The iovec layout assumes iov[0] reads the checksum and iov[1] reads 0129 //! only the data where the last such pair is iov[csnum*-2],iov[csnum*-1]. 0130 //! @note dataLen can be used to adjust the next offset for filesystem I/O while 0131 //! sockLen is the total number of network bytes to receive or send. 0132 //------------------------------------------------------------------------------ 0133 0134 struct Layout 0135 { 0136 off_t bOffset; //!< Buffer offset to apply iov[1].iov_base 0137 int dataLen; //!< Total number of filesys bytes the iovec will handle 0138 int sockLen; //!< Total number of network bytes the iovec will handle 0139 int fLen; //!< Length to use for iov[1].iov_len 0140 int lLen; //!< Length to use for iov[csnum*2-1].iov_len) 0141 const char *eWhy; //!< Reason for failure when zero is returned 0142 }; 0143 0144 static int recvLayout(Layout &layout, off_t offs, int dlen, int bsz=0); 0145 0146 static int sendLayout(Layout &layout, off_t offs, int dlen, int bsz=0); 0147 0148 XrdOucPgrwUtils() {} 0149 ~XrdOucPgrwUtils() {} 0150 0151 private: 0152 }; 0153 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|