-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdSsiFileSess.cc
792 lines (666 loc) · 25.6 KB
/
XrdSsiFileSess.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/******************************************************************************/
/* */
/* X r d S s i F i l e S e s s . c c */
/* */
/* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include "XrdNet/XrdNetAddrInfo.hh"
#include "XrdOuc/XrdOucBuffer.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucERoute.hh"
#include "XrdOuc/XrdOucPList.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdSfs/XrdSfsAio.hh"
#include "XrdSsi/XrdSsiEntity.hh"
#include "XrdSsi/XrdSsiFileSess.hh"
#include "XrdSsi/XrdSsiProvider.hh"
#include "XrdSsi/XrdSsiRRInfo.hh"
#include "XrdSsi/XrdSsiService.hh"
#include "XrdSsi/XrdSsiSfs.hh"
#include "XrdSsi/XrdSsiStats.hh"
#include "XrdSsi/XrdSsiStream.hh"
#include "XrdSsi/XrdSsiTrace.hh"
#include "XrdSsi/XrdSsiUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
/******************************************************************************/
/* G l o b a l s */
/******************************************************************************/
namespace XrdSsi
{
extern XrdOucBuffPool *BuffPool;
extern XrdSsiProvider *Provider;
extern XrdSsiService *Service;
extern XrdSsiStats Stats;
extern XrdSysError Log;
extern int respWT;
extern int minRSZ;
extern int maxRSZ;
}
using namespace XrdSsi;
/******************************************************************************/
/* L o c a l M a c r o s */
/******************************************************************************/
#define DUMPIT(x,y) XrdSsiUtils::b2x(x,y,hexBuff,sizeof(hexBuff),dotBuff)<<dotBuff
/******************************************************************************/
/* L o c a l C l a s s e s */
/******************************************************************************/
namespace
{
class nullCallBack : public XrdOucEICB
{
public:
void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0) {}
int Same(unsigned long long arg1, unsigned long long arg2) {return 0;}
nullCallBack() {}
virtual ~nullCallBack() {}
};
nullCallBack nullCB;
};
/******************************************************************************/
/* S t a t i c M e m b e r s */
/******************************************************************************/
XrdSysMutex XrdSsiFileSess::arMutex;
XrdSsiFileSess *XrdSsiFileSess::freeList = 0;
int XrdSsiFileSess::freeNum = 0;
int XrdSsiFileSess::freeNew = 0;
int XrdSsiFileSess::freeMax = 100;
int XrdSsiFileSess::freeAbs = 200;
bool XrdSsiFileSess::authDNS = false;
/******************************************************************************/
/* A l l o c */
/******************************************************************************/
XrdSsiFileSess *XrdSsiFileSess::Alloc(XrdOucErrInfo &einfo, const char *user)
{
XrdSsiFileSess *fsP;
// Get a lock
//
arMutex.Lock();
// Get either a reuseable object or a new one
//
if ((fsP = freeList))
{freeNum--;
freeList = fsP->nextFree;
arMutex.UnLock();
fsP->Init(einfo, user, true);
} else {
freeNew++;
if (freeMax <= freeAbs && freeNew >= freeMax/2)
{freeMax += freeMax/2;
freeNew = 0;
}
arMutex.UnLock();
fsP = new XrdSsiFileSess(einfo, user);
}
// Return the object
//
return fsP;
}
/******************************************************************************/
/* A t t n I n f o */
/******************************************************************************/
bool XrdSsiFileSess::AttnInfo(XrdOucErrInfo &eInfo, const XrdSsiRespInfo *respP,
unsigned int reqID)
// Called with the request mutex locked!
{
EPNAME("AttnInfo");
struct AttnResp {struct iovec ioV[4]; XrdSsiRRInfoAttn aHdr;};
AttnResp *attnResp;
char *mBuff;
int n, ioN = 2;
bool doFin;
// If there is no data we can send back to the client in the attn response,
// then simply reply with a short message to make the client come back.
//
if (!respP->mdlen)
{if (respP->rType != XrdSsiRespInfo::isData
|| respP->blen > XrdSsiResponder::MaxDirectXfr)
{eInfo.setErrInfo(0, "");
return false;
}
}
// We will be constructing the response in the message buffer. This is
// gauranteed to be big enough for our purposes so no need to check the size.
//
mBuff = eInfo.getMsgBuff(n);
// Initialize the response
//
attnResp = (AttnResp *)mBuff;
memset(attnResp, 0, sizeof(AttnResp));
attnResp->aHdr.pfxLen = htons(sizeof(XrdSsiRRInfoAttn));
// Fill out iovec to point to our header
//
//?attnResp->ioV[0].iov_len = sizeof(XrdSsiRRInfoAttn) + respP->mdlen;
attnResp->ioV[1].iov_base = mBuff+offsetof(struct AttnResp, aHdr);
attnResp->ioV[1].iov_len = sizeof(XrdSsiRRInfoAttn);
// Fill out the iovec for the metadata if we have some
//
if (respP->mdlen)
{attnResp->ioV[2].iov_base = (void *)respP->mdata;
attnResp->ioV[2].iov_len = respP->mdlen; ioN = 3;
attnResp->aHdr.mdLen = htonl(respP->mdlen);
Stats.Bump(Stats.RspMDBytes, respP->mdlen);
if (QTRACE(Debug))
{char hexBuff[16],dotBuff[4];
DEBUG(reqID <<':' <<gigID <<' ' <<respP->mdlen <<" byte metadata (0x"
<<DUMPIT(respP->mdata,respP->mdlen) <<") sent.");
}
}
// Check if we have actual data here as well and can send it along
//
if (respP->rType == XrdSsiRespInfo::isData
&& respP->blen+respP->mdlen <= XrdSsiResponder::MaxDirectXfr)
{if (respP->blen)
{attnResp->ioV[ioN].iov_base = (void *)respP->buff;
attnResp->ioV[ioN].iov_len = respP->blen; ioN++;
}
attnResp->aHdr.tag = XrdSsiRRInfoAttn::fullResp; doFin = true;
}
else {attnResp->aHdr.tag = XrdSsiRRInfoAttn::pendResp; doFin = false;}
// If we sent the full response we must remove the request from the request
// table as it will get finished off when the response is actually sent.
//
if (doFin) rTab.Del(reqID, false);
// Setup to have metadata actually sent to the requestor
//
eInfo.setErrCode(ioN);
return doFin;
}
/******************************************************************************/
/* c l o s e */
/******************************************************************************/
int XrdSsiFileSess::close(bool viaDel)
/*
Function: Close the file object.
Input: None
Output: Always returns SFS_OK
*/
{
const char *epname = "close";
// Do some debugging
//
DEBUG((gigID ? gigID : "???") <<" del=" <<viaDel);
// Collect statistics if this is a delete which implies a lost connection
//
if (viaDel)
{int rCnt = rTab.Num();
if (rCnt) Stats.Bump(Stats.ReqFinForce, rCnt);
}
// Run through all outstanding requests and comlete them
//
rTab.Reset();
// Free any in-progress buffers
//
if (inProg)
{if (oucBuff) {oucBuff->Recycle(); oucBuff = 0;}
inProg = false;
}
// Clean up storage
//
isOpen = false;
return SFS_OK;
}
/******************************************************************************/
/* f c t l */
/******************************************************************************/
int XrdSsiFileSess::fctl(const int cmd,
int alen,
const char *args,
const XrdSecEntity *client)
{
static const char *epname = "fctl";
XrdSsiRRInfo *rInfo;
XrdSsiFileReq *rqstP;
unsigned int reqID;
// If this isn't the special query, then return an error
//
if (cmd != SFS_FCTL_SPEC1)
return XrdSsiUtils::Emsg(epname, ENOTSUP, "fctl", gigID, *eInfo);
// Caller wishes to find out if a request is ready and wait if it is not
//
if (!args || alen < (int)sizeof(XrdSsiRRInfo))
return XrdSsiUtils::Emsg(epname, EINVAL, "fctl", gigID, *eInfo);
// Grab the request identifier
//
rInfo = (XrdSsiRRInfo *)args;
reqID = rInfo->Id();
// Do some debugging
//
DEBUG(reqID <<':' <<gigID <<" query resp status");
// Find the request
//
if (!(rqstP = rTab.LookUp(reqID)))
return XrdSsiUtils::Emsg(epname, ESRCH, "fctl", gigID, *eInfo);
// Check if a response is waiting for the caller
//
if (rqstP->WantResponse(*eInfo))
{DEBUG(reqID <<':' <<gigID <<" resp ready");
Stats.Bump(Stats.RspReady);
return SFS_DATAVEC;
}
// Put this client into callback state
//
DEBUG(reqID <<':' <<gigID <<" resp not ready");
eInfo->setErrCB((XrdOucEICB *)rqstP);
eInfo->setErrInfo(respWT, "");
Stats.Bump(Stats.RspUnRdy);
return SFS_STARTED;
}
/******************************************************************************/
/* Private: I n i t */
/******************************************************************************/
void XrdSsiFileSess::Init(XrdOucErrInfo &einfo, const char *user, bool forReuse)
{
tident = (user ? strdup(user) : strdup(""));
eInfo = &einfo;
gigID = 0;
fsUser = 0;
xioP = 0;
oucBuff = 0;
reqSize = 0;
reqLeft = 0;
isOpen = false;
inProg = false;
if (forReuse)
{eofVec.Reset();
rTab.Clear();
}
}
/******************************************************************************/
/* Private: N e w R e q u e s t */
/******************************************************************************/
bool XrdSsiFileSess::NewRequest(unsigned int reqid,
XrdOucBuffer *oP,
XrdSfsXioHandle bR,
int rSz)
{
XrdSsiFileReq *reqP;
// Allocate a new request object
//
if (!(reqP=XrdSsiFileReq::Alloc(eInfo,&fileResource,this,gigID,tident,reqid)))
return false;
// Add it to the table
//
rTab.Add(reqP, reqid);
// Activate the request
//
inProg = false;
reqP->Activate(oP, bR, rSz);
return true;
}
/******************************************************************************/
/* o p e n */
/******************************************************************************/
int XrdSsiFileSess::open(const char *path, // In
XrdOucEnv &theEnv, // In
XrdSfsFileOpenMode open_mode) // In
/*
Function: Open the file `path' in the mode indicated by `open_mode'.
Input: path - The fully qualified name of the resource.
theEnv - Environmental information.
open_mode - It must contain only SFS_O_RDWR.
Output: Returns SFS_OK upon success, otherwise SFS_ERROR is returned.
*/
{
static const char *epname = "open";
XrdSsiErrInfo errInfo;
const char *eText;
int eNum;
// Verify that this object is not already associated with an open file
//
if (isOpen)
return XrdSsiUtils::Emsg(epname, EADDRINUSE, "open session", path, *eInfo);
// Make sure the open flag is correct (we now open this R/O so don't check)
//
// if (open_mode != SFS_O_RDWR)
// return XrdSsiUtils::Emsg(epname, EPROTOTYPE, "open session", path, *eInfo);
// Setup the file resource object
//
fileResource.Init(path, theEnv, authDNS);
// Notify the provider that we will be executing a request
//
if (Service->Prepare(errInfo, fileResource))
{const char *usr = fileResource.rUser.c_str();
if (!(*usr)) gigID = strdup(path);
else {char gBuff[2048];
snprintf(gBuff, sizeof(gBuff), "%s:%s", usr, path);
gigID = strdup(gBuff);
}
DEBUG(gigID <<" prepared.");
isOpen = true;
return SFS_OK;
}
// Get error information
//
eText = errInfo.Get(eNum).c_str();
if (!eNum)
{eNum = ENOMSG; eText = "Provider returned invalid prepare response.";}
// Decode the error
//
switch(eNum)
{case EAGAIN:
if (!eText || !(*eText)) break;
eNum = errInfo.GetArg();
DEBUG(path <<" --> " <<eText <<':' <<eNum);
eInfo->setErrInfo(eNum, eText);
Stats.Bump(Stats.ReqRedir);
return SFS_REDIRECT;
break;
case EBUSY:
eNum = errInfo.GetArg();
if (!eText || !(*eText)) eText = "Provider is busy.";
DEBUG(path <<" dly " <<eNum <<' ' <<eText);
if (eNum <= 0) eNum = 1;
eInfo->setErrInfo(eNum, eText);
Stats.Bump(Stats.ReqStalls);
return eNum;
break;
default:
if (!eText || !(*eText)) eText = XrdSysE2T(eNum);
DEBUG(path <<" err " <<eNum <<' ' <<eText);
eInfo->setErrInfo(eNum, eText);
Stats.Bump(Stats.ReqPrepErrs);
return SFS_ERROR;
break;
};
// Something is quite wrong here
//
Log.Emsg(epname, "Provider redirect returned no target host name!");
eInfo->setErrInfo(ENOMSG, "Server logic error");
Stats.Bump(Stats.ReqPrepErrs);
return SFS_ERROR;
}
/******************************************************************************/
/* r e a d */
/******************************************************************************/
XrdSfsXferSize XrdSsiFileSess::read(XrdSfsFileOffset offset, // In
char *buff, // Out
XrdSfsXferSize blen) // In
/*
Function: Read `blen' bytes at `offset' into 'buff' and return the actual
number of bytes read.
Input: offset - Contains request information.
buff - Address of the buffer in which to place the data.
blen - The size of the buffer. This is the maximum number
of bytes that will be returned.
Output: Returns the number of bytes read upon success and SFS_ERROR o/w.
*/
{
static const char *epname = "read";
XrdSsiRRInfo rInfo(offset);
XrdSsiFileReq *rqstP;
XrdSfsXferSize retval;
unsigned int reqID = rInfo.Id();
bool noMore = false;
// Find the request object. If not there we may have encountered an eof
//
if (!(rqstP = rTab.LookUp(reqID)))
{if (eofVec.IsSet(reqID))
{eofVec.UnSet(reqID);
return 0;
}
return XrdSsiUtils::Emsg(epname, ESRCH, "read", gigID, *eInfo);
}
// Simply effect the read via the request object
//
retval = rqstP->Read(noMore, buff, blen);
// See if we just completed this request
//
if (noMore)
{rqstP->Finalize();
rTab.Del(reqID);
eofVec.Set(reqID);
}
// All done
//
return retval;
}
/******************************************************************************/
/* R e c y c l e */
/******************************************************************************/
void XrdSsiFileSess::Recycle()
{
// Do an immediate reset on ourselves to avoid getting too many locks
//
Reset();
// Get a lock
//
arMutex.Lock();
// Check if we should place this on the free list or simply delete it
//
if (freeNum < freeMax)
{nextFree = freeList;
freeList = this;
freeNum++;
arMutex.UnLock();
} else {
arMutex.UnLock();
delete this;
}
}
/******************************************************************************/
/* Private: R e s e t */
/******************************************************************************/
void XrdSsiFileSess::Reset()
{
// Close this session
//
if (isOpen) close(true);
// Release other buffers
//
if (tident) free(tident);
if (fsUser) free(fsUser);
if (gigID) free(gigID);
}
/******************************************************************************/
/* S e n d D a t a */
/******************************************************************************/
int XrdSsiFileSess::SendData(XrdSfsDio *sfDio,
XrdSfsFileOffset offset,
XrdSfsXferSize size)
{
static const char *epname = "SendData";
XrdSsiRRInfo rInfo(offset);
XrdSsiFileReq *rqstP;
unsigned int reqID = rInfo.Id();
int rc;
// Find the request object
//
if (!(rqstP = rTab.LookUp(reqID)))
return XrdSsiUtils::Emsg(epname, ESRCH, "send", gigID, *eInfo);
// Simply effect the send via the request object
//
rc = rqstP->Send(sfDio, size);
// Determine how this ended
//
if (rc > 0) rc = SFS_OK;
else {rqstP->Finalize();
rTab.Del(reqID);
}
return rc;
}
/******************************************************************************/
/* t r u n c a t e */
/******************************************************************************/
int XrdSsiFileSess::truncate(XrdSfsFileOffset flen) // In
/*
Function: Set the length of the file object to 'flen' bytes.
Input: flen - The new size of the file.
Output: Returns SFS_ERROR a this function is not supported.
*/
{
static const char *epname = "trunc";
XrdSsiFileReq *rqstP;
XrdSsiRRInfo rInfo(flen);
XrdSsiRRInfo::Opc reqXQ = rInfo.Cmd();
unsigned int reqID = rInfo.Id();
// Find the request object. If not there we may have encountered an eof
//
if (!(rqstP = rTab.LookUp(reqID)))
{if (eofVec.IsSet(reqID))
{eofVec.UnSet(reqID);
return 0;
}
return XrdSsiUtils::Emsg(epname, ESRCH, "cancel", gigID, *eInfo);
}
// Process request (this can only be a cancel request)
//
if (reqXQ != XrdSsiRRInfo::Can)
return XrdSsiUtils::Emsg(epname, ENOTSUP, "trunc", gigID, *eInfo);
// Perform the cancellation
//
DEBUG(reqID <<':' <<gigID <<" cancelled");
rqstP->Finalize();
rTab.Del(reqID);
return SFS_OK;
}
/******************************************************************************/
/* w r i t e */
/******************************************************************************/
XrdSfsXferSize XrdSsiFileSess::write(XrdSfsFileOffset offset, // In
const char *buff, // In
XrdSfsXferSize blen) // In
/*
Function: Write `blen' bytes at `offset' from 'buff' and return the actual
number of bytes written.
Input: offset - The absolute byte offset at which to start the write.
buff - Address of the buffer from which to get the data.
blen - The size of the buffer. This is the maximum number
of bytes that will be written to 'fd'.
Output: Returns the number of bytes written upon success and SFS_ERROR o/w.
Notes: An error return may be delayed until the next write(), close(), or
sync() call.
*/
{
static const char *epname = "write";
XrdSsiRRInfo rInfo(offset);
unsigned int reqID = rInfo.Id();
int reqPass;
// Check if we are reading a request segment and handle that. This assumes that
// writes to different requests cannot be interleaved (which they can't be).
//
if (inProg) return writeAdd(buff, blen, reqID);
// Make sure this request does not refer to an active request
//
if (rTab.LookUp(reqID))
return XrdSsiUtils::Emsg(epname, EADDRINUSE, "write", gigID, *eInfo);
// The offset contains the actual size of the request, make sure it's OK. Note
// that it can be zero and by convention the blen must be one if so.
//
reqPass = reqSize = rInfo.Size();
if (reqSize < blen)
{if (reqSize || blen != 1)
return XrdSsiUtils::Emsg(epname, EPROTO, "write", gigID, *eInfo);
reqSize = 1;
} else if (reqSize < 0 || reqSize > maxRSZ)
return XrdSsiUtils::Emsg(epname, EFBIG, "write", gigID, *eInfo);
// Indicate we are in the progress of collecting the request arguments
//
inProg = true;
eofVec.UnSet(reqID);
// Do some debugging
//
DEBUG(reqID <<':' <<gigID <<" rsz=" <<reqSize <<" wsz=" <<blen);
// If the complete request is here then grab the buffer, transfer ownership to
// the request object, and then activate it for processing.
//
if (reqSize == blen && xioP)
{XrdSfsXioHandle bRef = xioP->Claim(buff, reqSize, minRSZ);
if (!bRef)
{if (errno) Log.Emsg(epname,"Xio.Claim() failed;",XrdSysE2T(errno));}
else {if (!NewRequest(reqID, 0, bRef, reqPass))
return XrdSsiUtils::Emsg(epname,ENOMEM,"write",gigID,*eInfo);
return blen;
}
}
// The full request is not present, so get a buffer to piece it together
//
if (!(oucBuff = BuffPool->Alloc(reqSize)))
return XrdSsiUtils::Emsg(epname, ENOMEM, "write", gigID, *eInfo);
// Setup to buffer this
//
reqLeft = reqSize - blen;
memcpy(oucBuff->Data(), buff, blen);
if (!reqLeft)
{oucBuff->SetLen(reqSize);
if (!NewRequest(reqID, oucBuff, 0, reqPass))
return XrdSsiUtils::Emsg(epname, ENOMEM, "write", gigID, *eInfo);
oucBuff = 0;
} else oucBuff->SetLen(blen, blen);
return blen;
}
/******************************************************************************/
/* Private: w r i t e A d d */
/******************************************************************************/
XrdSfsXferSize XrdSsiFileSess::writeAdd(const char *buff, // In
XrdSfsXferSize blen, // In
unsigned int rid)
/*
Function: Add `blen' bytes from 'buff' to request and return the actual
number of bytes added.
Input: buff - Address of the buffer from which to get the data.
blen - The size of the buffer. This is the maximum number
of bytes that will be added.
Output: Returns the number of bytes added upon success and SFS_ERROR o/w.
Notes: An error return may be delayed until the next write(), close(), or
sync() call.
*/
{
static const char *epname = "writeAdd";
int dlen;
// Make sure the caller is not exceeding the size stated on the first write
//
if (blen > reqLeft)
return XrdSsiUtils::Emsg(epname, EFBIG, "writeAdd", gigID, *eInfo);
// Append the bytes
//
memcpy(oucBuff->Data(dlen), buff, blen);
// Adjust how much we have left
//
reqLeft -= blen;
DEBUG(rid <<':' <<gigID <<" rsz=" <<reqLeft <<" wsz=" <<blen);
// If we have a complete request. Transfer the buffer ownership to the request
// object and activate processing.
//
if (!reqLeft)
{oucBuff->SetLen(reqSize);
if (!NewRequest(rid, oucBuff, 0, reqSize))
return XrdSsiUtils::Emsg(epname, ENOMEM, "write", gigID, *eInfo);
oucBuff = 0;
}
// Return how much we appended
//
dlen += blen;
oucBuff->SetLen(dlen, dlen);
return blen;
}