XRootD
Loading...
Searching...
No Matches
XrdXrootdPgwCtl.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d X r o o t d P g w C t l . 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
37
38/******************************************************************************/
39/* S t a t i c M e m b e r s */
40/******************************************************************************/
41
42const char *XrdXrootdPgwCtl::TraceID = "pgwCtl";
43
44namespace
45{
46static const int pgPageSize = XrdProto::kXR_pgPageSZ;
47static const int pgPageMask = XrdProto::kXR_pgPageSZ-1;
48}
49
50/******************************************************************************/
51/* C o n s t r u c t o r */
52/******************************************************************************/
53
55 : XrdXrootdPgwBadCS(pid), dataBuff(0), dataBLen(0), fixSRD(0)
56{
57
58// Clear the response area
59//
60 memset(&resp, 0, sizeof(resp));
61
62// Setup response fields that stay constant for the life of the object
63//
66
67// Setup the iovec assuming full usage
68//
69 kXR_unt32 *csP = csVec;
70 for (int i = 0; i < maxIOVN; i += 2)
71 {ioVec[i ].iov_base = csP++;
72 ioVec[i ].iov_len = sizeof(kXR_unt32);
73 ioVec[i+1].iov_len = pgPageSize;
74 };
75}
76
77/******************************************************************************/
78/* A d v a n c e */
79/******************************************************************************/
80
82{
83// Check if we have anything to advance here
84//
85 if (iovRem <= 0)
86 {iovNum = 0;
87 iovLen = 0;
88 return false;
89 }
90
91// Readjust values for first data iov element as the previous one may not have
92// bin for a full page (unaligned read). We just do it categorically.
93//
94 ioVec[1].iov_base = dataBuff;
95 ioVec[1].iov_len = pgPageSize;
96
97// Compute number of iovec element we will use for the next read.
98//
99 if (iovRem > iovNum) iovRem -= iovNum;
100 else {iovNum = iovRem;
101 iovRem = 0;
102 if (endLen)
103 {ioVec[iovNum-1].iov_len = endLen;
104 fixSRD = iovNum-1;
105 }
106 }
107
108// Compute bytes read by this frame
109//
110 int n = iovNum>>1;
111 iovLen = ioVec[iovNum-1].iov_len + (n*crcSZ);
112 if (n > 1) iovLen += (n-1)*pgPageSize;
113
114// Indicate there is more to do
115//
116 return true;
117}
118
119/******************************************************************************/
120/* S e t u p */
121/******************************************************************************/
122
123const char *XrdXrootdPgwCtl::Setup(XrdBuffer *buffP, kXR_int64 fOffs, int totlen)
124{
126 int csNum, iovMax;
127
128// Reset short length in the iovec from the last use.
129//
130 if (fixSRD)
131 {ioVec[fixSRD].iov_len = pgPageSize;
132 fixSRD = 0;
133 }
134
135// Compute the layout parameters for the complete read (done once)
136//
137 if (!(csNum = XrdOucPgrwUtils::recvLayout(layout, fOffs, totlen)))
138 return layout.eWhy;
139
140// Compute the maximum number of iov entries for the real buffer size
141//
142 if (buffP->bsize >= maxBSize) iovMax = (maxBSize/XrdProto::kXR_pgPageSZ)*2;
143 else iovMax = (buffP->bsize/XrdProto::kXR_pgPageSZ)*2;
144
145// Verify the logic here, under no circumstance should iovMax be zero
146//
147 if (!iovMax) return "PgwCtl logic error detected; buffer is too small";
148
149// If the buffer has changed, then we must update buffer addresses in the iovec
150// Note that buffer sizes are always a power of 1K (i.e. 1, 2, 4, 8, etc).
151// However, the caller is on the hook to make the buffer no less than 4K.
152//
153 if (buffP->buff != dataBuff || buffP->bsize != dataBLen)
154 {char *dP;
155 dP = dataBuff = buffP->buff; dataBLen = buffP->bsize;
156 for (int i = 1; i < iovMax; i +=2)
157 {ioVec[i].iov_base = dP;
159 }
160 }
161
162// Setup control information and preset the initial read.
163//
164 ioVec[1].iov_base = buffP->buff + layout.bOffset;
165 ioVec[1].iov_len = layout.fLen;
166
167// Now setup for subsequent reads which we may not need.
168//
169 iovRem = csNum<<1;
170 if (iovRem > iovMax)
171 {iovNum = iovMax;
172 iovLen = layout.fLen + ((iovMax/2-1)*pgPageSize) + (iovMax/2*crcSZ);
173 endLen = layout.lLen;
174 } else {
175 iovNum = iovRem;
176 iovLen = layout.sockLen;
177 endLen = 0;
178 if (layout.lLen)
179 {ioVec[iovNum-1].iov_len = layout.lLen;
180 fixSRD = iovNum-1;
181 }
182 }
183 iovRem -= iovNum;
184 lenLeft = layout.sockLen - iovLen;
185
186// Reset remaining fields
187//
188 boReset();
189 info.offset = htonll(fOffs);
190 return 0;
191}
struct ServerResponseBody_Status bdy
@ kXR_1stRequest
Definition XProtocol.hh:111
@ kXR_pgwrite
Definition XProtocol.hh:138
long long kXR_int64
Definition XPtypes.hh:98
unsigned int kXR_unt32
Definition XPtypes.hh:90
char * buff
Definition XrdBuffer.hh:45
off_t bOffset
Buffer offset to apply iov[1].iov_base.
int fLen
Length to use for iov[1].iov_len.
int sockLen
Total number of network bytes the iovec will handle.
const char * eWhy
Reason for failure when zero is returned.
int lLen
Length to use for iov[csnum*2-1].iov_len)
static int recvLayout(Layout &layout, off_t offs, int dlen, int bsz=0)
Compute the layout for an iovec that receives network bytes applying.
ServerResponseStatus resp
static const int crcSZ
static const int maxIOVN
static const int maxBSize
const char * Setup(XrdBuffer *buffP, kXR_int64 fOffs, int totlen)
ServerResponseBody_pgWrite info
static const int kXR_pgPageSZ
Definition XProtocol.hh:494
@ kXR_FinalResult