#include <XrdSutPFCache.hh>
Definition at line 71 of file XrdSutPFCache.hh.
◆ XrdSutPFCache()
XrdSutPFCache::XrdSutPFCache |
( |
| ) |
|
|
inline |
Definition at line 92 of file XrdSutPFCache.hh.
92 { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300;
93 utime = -1; htmtime = -1; pfile = ""; isinit = 0; }
◆ ~XrdSutPFCache()
XrdSutPFCache::~XrdSutPFCache |
( |
| ) |
|
|
virtual |
◆ Add()
Definition at line 207 of file XrdSutPFCache.cc.
208{
209
210
211
213
214
215
216 if (!
ID || !strlen(
ID)) {
219 }
220
221
222
224 if (ent)
225 return ent;
226
227
229
230
231
232 if (cachemx == cachesz - 1) {
233
234
236 if (!newcache) {
237 DEBUG(
"could not extend cache to size: "<<(2*cachesz));
239 }
240
241 cachesz *= 2;
242
243
244 int i = 0, nmx = 0;
245 for (; i <= cachemx; i++) {
246 if (cachent[i]) {
247 newcache[nmx] = cachent[i];
248 nmx++;
249 }
250 }
251
252 cachemx = nmx - 1;
253
254
255 for (i = cachemx + 1; i <= cachemx; i++) {
256 newcache[i] = 0;
257 }
258
259
260 delete[] cachent;
261 cachent = newcache;
262
263
264 force = 1;
265 }
266
267
268 int pos = cachemx + 1;
269
270
271
273 if (cachent[pos]) {
274 cachemx = pos;
275 } else {
276 DEBUG(
"could not allocate space for new cache entry");
278 }
279
281
282
283 if (
Rehash(force, 0) != 0) {
284 DEBUG(
"problems re-hashing");
286 }
287
288
289 urRef.
Lock(&(cachent[pos]->pfeMutex));
290 return cachent[pos];
291}
void Lock(XrdSysMutex *Mutex)
int Rehash(bool force=0, bool lock=1)
References DEBUG, EPNAME, ID, XrdSutPFCacheRef::Lock(), and Rehash().
◆ Dump()
void XrdSutPFCache::Dump |
( |
const char * |
msg = 0 | ) |
|
Definition at line 487 of file XrdSutPFCache.cc.
488{
489
491
492 PRINT(
"//-----------------------------------------------------");
494 if (msg && strlen(msg) > 0) {
497 }
498 PRINT(
"// Capacity: "<<cachesz);
499 PRINT(
"// Max index filled: "<<cachemx);
501
502
504
505 if (cachesz > 0) {
506
508 int i = 0, nn = 0;
509 for (; i <= cachemx; i++) {
510
511
512 if ((ent = cachent[i])) {
513
514 char smt[20] = {0};
516
517 nn++;
521 <<
" name:"<<ent->
name);
522 }
523
524 }
526 }
527 PRINT(
"//-----------------------------------------------------");
528}
int XrdSutTimeString(int t, char *st, int opt)
References XrdSutPFEntry::buf1, XrdSutPFEntry::buf2, XrdSutPFEntry::buf3, XrdSutPFEntry::buf4, XrdSutPFEntry::cnt, EPNAME, XrdSutPFBuf::len, XrdSutPFEntry::mtime, XrdSutPFEntry::name, PRINT, XrdSutPFEntry::status, and XrdSutTimeString().
Referenced by Get(), XrdSecProtocolpwd::Init(), and Rehash().
◆ Empty()
bool XrdSutPFCache::Empty |
( |
| ) |
const |
|
inline |
◆ Entries()
int XrdSutPFCache::Entries |
( |
| ) |
const |
|
inline |
◆ Flush()
int XrdSutPFCache::Flush |
( |
const char * |
pfname = 0 | ) |
|
Definition at line 701 of file XrdSutPFCache.cc.
702{
703
704
705
706
707
709
710
711 if (!pfn && pfile.
length() <= 0) {
712 DEBUG(
"invalid input");
713 return -1;
714 }
715 if (!pfn)
717
718
720 if (!ff.IsValid()) {
721 DEBUG(
"cannot attach-to or create file "<<pfn<<
" ("<<ff.LastErrStr()<<
")");
722 return -1;
723 }
724
725
727
728
729
730 int i = 0, nr = 0, nfs = 0;
731 for (; i <= cachemx; i++ ) {
732 if (cachent[i]) {
733
734
735
737 if ((nr = ff.ReadEntry(cachent[i]->name, ent)) < 0) {
738 ff.Close();
739 return -1;
740 }
741
742
743 if (nr == 0 || cachent[i]->mtime > ent.
mtime) {
744 if (ff.WriteEntry(*cachent[i]) < 0) {
745 ff.Close();
746 return -1;
747 }
748 nfs++;
749 }
750 }
751 }
752
753
754 ff.Close();
755
756
758
759
761 pfile = pfn;
762
763 DEBUG(
"Cache flushed to file "<<pfn<<
" ("<<nfs<<
" entries updated / written)");
764
765 return 0;
766}
const char * c_str() const
References XrdOucString::c_str(), XrdSutPFile::Close(), DEBUG, EPNAME, XrdSutPFile::IsValid(), kPFEcreate, kPFEopen, XrdSutPFile::LastErrStr(), XrdOucString::length(), XrdSutPFEntry::mtime, XrdSutPFEntry::name, XrdSutPFile::ReadEntry(), and XrdSutPFile::WriteEntry().
Referenced by XrdSecProtocolpwd::Authenticate().
◆ Get() [1/2]
◆ Get() [2/2]
Definition at line 122 of file XrdSutPFCache.cc.
123{
124
125
126
127
130 int i;
131
133
134
135
136 if (!
ID || !strlen(
ID)) {
139 }
140 if (wild) *wild = 0;
141
143 DEBUG(
"problems rehashing");
145 }
146
147
149
150
151
152 for (i = 0; i < maxTries; i++)
153 {
if ((pfEnt = Get(
ID, wild)))
156 return pfEnt;
157 }
158 } else return pfEnt;
159 isg.UnLock();
162 {
DEBUG(
"problems rehashing");
164 }
165 isg.Lock(&rwlock, 1);
166 }
167
168
170}
void Set(XrdSysMutex *Mutex)
void Dump(const char *msg=0)
static void Wait(int milliseconds)
References XrdSysMutex::CondLock(), DEBUG, Dump(), EPNAME, ID, XrdSysRWLockHelper::Lock(), XrdSutPFEntry::pfeMutex, Rehash(), XrdSutPFCacheRef::Set(), TRACE, XrdSysRWLockHelper::UnLock(), and XrdSysTimer::Wait().
◆ Init()
int XrdSutPFCache::Init |
( |
int |
capacity = 100 , |
|
|
bool |
lock = 1 |
|
) |
| |
Definition at line 73 of file XrdSutPFCache.cc.
74{
75
76
77
79
80
82
83
84 if (isinit) {
86 return 0;
87 }
88
89
90 capacity = (capacity > 0) ? capacity : 100;
91
92
94 if (cachent) {
95 for (int i = 0; i < capacity; i++) { cachent[i] = 0; }
96 cachesz = capacity;
97 DEBUG(
"cache allocated for "<<cachesz<<
" entries");
98
99
101
102
104 DEBUG(
"problems initialising hash table");
105 }
106
107 if (lock) rwlock.
UnLock();
108 return 0;
109
110 } else
111 DEBUG(
"could not allocate cache - out-of-resources ");
112
113
114 isinit = 1;
115
116
117 if (lock) rwlock.
UnLock();
118 return -1;
119}
References DEBUG, EPNAME, Rehash(), XrdSysRWLock::UnLock(), and XrdSysRWLock::WriteLock().
Referenced by XrdSecProtocolpwd::Init(), Load(), and Reset().
◆ Load()
int XrdSutPFCache::Load |
( |
const char * |
pfname | ) |
|
Definition at line 531 of file XrdSutPFCache.cc.
532{
533
534
536
537
538 if (!pfn) {
539 DEBUG(
"invalid input file name");
540 return -1;
541 }
542
543
545 if (
stat(pfn,&st) == -1) {
546 DEBUG(
"cannot stat file (errno: "<<errno<<
")");
547 return -1;
548 }
549 if (utime > -1 && utime > st.st_mtime) {
550 DEBUG(
"cached information for file "<<pfn<<
" is up-to-date");
551 return 0;
552 }
553
554
556
557
559 if (!ff.IsValid()) {
560 DEBUG(
"file is not a valid PFEntry file ("<<ff.LastErrStr()<<
")");
561 return -1;
562 }
563
564
566 if (ff.ReadHeader(header) < 0) {
567 ff.Close();
568 return -1;
569 }
570
571
573 DEBUG(
"PFEntry file is empty - default init and return");
574
575 pfile = pfn;
577 return 0;
578 }
579
580
582 DEBUG(
"problems allocating / resizing cache ");
583 ff.Close();
584 return -1;
585 }
586
587
591 while (nxtofs > 0 && ne < header.
entries) {
592
593
594 if (ff.ReadInd(nxtofs, ind) < 0) {
595 DEBUG(
"problems reading index entry ");
596 ff.Close();
597 return -1;
598 }
599
600
602
603
605 if (ff.ReadEnt(ind.
entofs, ent) < 0) {
606 ff.Close();
607 return -1;
608 }
609
610
612
613 if (cent) {
614
616
617
618 cachent[ne] = cent;
619
620
621 ne++;
622
623 } else {
624 DEBUG(
"problems duplicating entry for cache");
625 ff.Close();
626 return -1;
627 }
628 }
629
630
632 }
633 cachemx = ne-1;
634 if (nxtofs > 0)
635 DEBUG(
"WARNING: inconsistent number of entries: possible file corruption");
636
637
639
640
641 pfile = pfn;
642
643
644 ff.Close();
645
646 DEBUG(
"PF file "<<pfn<<
" loaded in cache (found "<<ne<<
" entries)");
647
648
650 DEBUG(
"problems creating hash table");
651 return -1;
652 }
653
654 return 0;
655}
int Reset(int newsz=-1, bool lock=1)
int Init(int capacity=100, bool lock=1)
void SetName(const char *n=0)
References XrdSutPFile::Close(), DEBUG, XrdSutPFEntInd::entofs, XrdSutPFHeader::entries, EPNAME, XrdSutPFHeader::indofs, Init(), XrdSutPFile::IsValid(), kPFEopen, XrdSutPFile::LastErrStr(), XrdSutPFEntInd::name, XrdSutPFEntInd::nxtofs, Rehash(), Reset(), XrdSutPFEntry::SetName(), and stat.
Referenced by XrdSecProtocolpwd::Init(), and Refresh().
◆ Refresh()
int XrdSutPFCache::Refresh |
( |
| ) |
|
Definition at line 769 of file XrdSutPFCache.cc.
770{
771
772
774
775
776 if (pfile.
length() <= 0) {
777 DEBUG(
"cache was not initialized from file - do nothing");
778 return -1;
779 }
780
781
784 DEBUG(
"cannot stat file (errno: "<<errno<<
")");
785 return -1;
786 }
787 if (utime > -1 && utime > st.st_mtime) {
788 DEBUG(
"cached information for file "<<pfile<<
" is up-to-date");
789 return 0;
790 }
791
792
794
796 DEBUG(
"problems loading passwd information from file: "<<pfile);
797 return -1;
798 }
799
800
802
803 DEBUG(
"Cache refreshed from file: "<<pfile);
804
805 return 0;
806}
int Load(const char *pfname)
References XrdOucString::c_str(), DEBUG, EPNAME, XrdOucString::length(), Load(), and stat.
◆ Rehash()
int XrdSutPFCache::Rehash |
( |
bool |
force = 0 , |
|
|
bool |
lock = 1 |
|
) |
| |
Definition at line 659 of file XrdSutPFCache.cc.
660{
661
662
663
665
666
668
669 if (htmtime >= utime && !force) {
671 if (lock) rwlock.
UnLock();
672 return 0;
673 }
674
675
677
679 for (; i <= cachemx; i++) {
680 if (cachent[i]) {
681
683 if (key) {
684 TRACE(
Dump,
"Adding ID: "<<cachent[i]->name<<
"; key: "<<*key);
685 hashtable.
Add(cachent[i]->name,key);
686 nht++;
687 }
688 }
689 }
690
692
693
694 if (lock) rwlock.
UnLock();
695
696 DEBUG(
"Hash table updated (found "<<nht<<
" active entries)");
697 return 0;
698}
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
References XrdOucHash< T >::Add(), DEBUG, Dump(), EPNAME, XrdOucHash< T >::Purge(), TRACE, XrdSysRWLock::UnLock(), and XrdSysRWLock::WriteLock().
Referenced by Add(), Get(), Init(), Load(), and Remove().
◆ Remove()
bool XrdSutPFCache::Remove |
( |
const char * |
ID, |
|
|
int |
opt = 1 |
|
) |
| |
Definition at line 294 of file XrdSutPFCache.cc.
295{
296
297
298
300
301
302
303 if (!
ID || !strlen(
ID)) {
305 return 0 ;
306 }
307
308
310
312 DEBUG(
"problems rehashing");
313 return 0 ;
314 }
315
316 bool found = 0;
317 if (opt == 1) {
318 int pos = -1;
319
321 if (*ie >= 0 && *ie < cachesz) {
322
323 pos = *ie;
324 }
325
326
327
328 if (cachent[pos] && !strcmp(cachent[pos]->name,
ID)) {
329 if (!Delete(cachent[pos]))
DEBUG(
"Delete deferred for " <<
ID);
330 cachent[pos] = 0;
331
332 if (pos < cachemx)
333 return 1;
334
335 found = 1;
336 }
337 } else {
338
339 int i = cachemx;
340 for (; i >= 0; i--) {
341 if (cachent[i]) {
342 if (!strncmp(cachent[i]->name,
ID,strlen(
ID))) {
343 if (!Delete(cachent[i]))
DEBUG(
"Delete deferred for " <<
ID);
344 cachent[i] = 0;
345 found = 1;
346 }
347 }
348 }
349 }
350
351 if (found) {
352
354
355
357 DEBUG(
"problems re-hashing");
358 return 0 ;
359 }
360 }
361
362
363 return found;
364}
T * Find(const char *KeyVal, time_t *KeyTime=0)
References DEBUG, EPNAME, XrdOucHash< T >::Find(), ID, and Rehash().
◆ Reset()
int XrdSutPFCache::Reset |
( |
int |
newsz = -1 , |
|
|
bool |
lock = 1 |
|
) |
| |
Definition at line 448 of file XrdSutPFCache.cc.
449{
450
451
452
454
455
457
458
459 int i = cachemx;
460 for (; i >= 0; i--) {
461 if (cachent[i]) {
462 if (!Delete(cachent[i]))
463 DEBUG(
"Delete deferred for " <<cachent[i]->name);
464 cachent[i] = 0;
465 }
466 }
467
468 int rc = 0;
469
470 if (newsz > -1 && newsz != cachesz) {
471 delete[] cachent;
472 cachent = 0;
473 cachesz = 0;
474 cachemx = -1;
475 isinit = 0;
477 }
478
479
480 if (lock) rwlock.
UnLock();
481
482
483 return rc;
484}
References DEBUG, EPNAME, Init(), XrdSysRWLock::UnLock(), and XrdSysRWLock::WriteLock().
Referenced by Load().
◆ SetLifetime()
void XrdSutPFCache::SetLifetime |
( |
int |
lifet = 300 | ) |
|
|
inline |
◆ Trim()
int XrdSutPFCache::Trim |
( |
int |
lifet = 0 | ) |
|
Definition at line 410 of file XrdSutPFCache.cc.
411{
412
413
414
415
416
419
420
421
422 lifet = (lifet > 0) ? lifet : lifetime;
423
424
425
426 int reftime = time(0) - lifet;
427
428
429 int i = cachemx, nrm = 0;
430 for (; i >= 0; i--) {
431 if (cachent[i] && cachent[i]->mtime < reftime) {
432 if (!Delete(cachent[i]))
433 DEBUG(
"Delete deferred for " <<cachent[i]->name);
434 cachent[i] = 0;
435 nrm++;
436 }
437 if (i == cachemx) {
438 if (!cachent[i])
439 cachemx--;
440 }
441 }
442
443
444 return nrm;
445}
References DEBUG, and EPNAME.
The documentation for this class was generated from the following files: