XRootD
Loading...
Searching...
No Matches
XrdXrootdPgwBadCS.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d X r o o t d P g w B a d C S . c c */
4/* */
5/* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Department of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#include <cstring>
31#include <arpa/inet.h>
32
33#include "XrdOuc/XrdOucCRC.hh"
39
40#define TRACELINK fP
41
42/******************************************************************************/
43/* G l o b a l s */
44/******************************************************************************/
45
47
48/******************************************************************************/
49/* S t a t i c M e m b e r s */
50/******************************************************************************/
51
52const char *XrdXrootdPgwBadCS::TraceID = "pgwBadCS";
53
54/******************************************************************************/
55/* b o A d d */
56/******************************************************************************/
57
59 kXR_int64 foffs, int dlen)
60{
61
62// Do some tracing
63//
64 TRACEI(PGCS, pathID <<" csErr "<<dlen<<'@'<<foffs<<" inreq="<<boCount+1
65 <<" infile=" <<fP->pgwFob->numOffs()+1<<" fn="<<fP->FileKey);
66
67// If this is the first offset, record the length as first and last.
68// Othewrise just update the last length.
69//
70 if (!boCount) cse.dlFirst = cse.dlLast = htons(dlen);
71 else cse.dlLast = htons(dlen);
72
73// Add offset to the vector to be returned to client for corrections.
74//
75 if (boCount+1 >= XrdProto::kXR_pgMaxEpr)
76 return "Too many checksum errors in request";
77 badOffs[boCount++] = htonll(foffs);
78
79// Add offset in the set of uncorrected offsets
80//
81 if (!fP->pgwFob->addOffs(foffs, dlen))
82 return "Too many uncorrected checksum errors in file";
83
84// Success!
85//
86 return 0;
87}
88
89/******************************************************************************/
90/* b o I n f o */
91/******************************************************************************/
92
94{
95 static const int crcSZ = sizeof(uint32_t);
96
97// If no bad offsets are present, indicate so.
98//
99 if (!boCount)
100 {boLen = 0;
101 return 0;
102 }
103
104// Return the additional data
105//
106 boLen = sizeof(cse) + (boCount * sizeof(kXR_int64));
107 cse.cseCRC = htonl(XrdOucCRC::Calc32C(((char *)&cse)+crcSZ, boLen-crcSZ));
108 return (char *)&cse;
109}
long long kXR_int64
Definition XPtypes.hh:98
XrdOucTrace * XrdXrootdTrace
#define TRACEI(act, x)
Definition XrdTrace.hh:66
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
Definition XrdOucCRC.cc:190
XrdXrootdPgwFob * pgwFob
const char * boAdd(XrdXrootdFile *fP, kXR_int64 foffs, int dlen=XrdProto::kXR_pgPageSZ)
char * boInfo(int &boLen)
int numOffs(int *errs=0, int *fixs=0)
bool addOffs(kXR_int64 foffs, int dlen)
static const int kXR_pgMaxEpr
Definition XProtocol.hh:497