00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "MutableSidref.H"
00023 #include "VDirChangeable.H"
00024 #include "logging.H"
00025
00026
00027 static bool skip_check = true;
00028
00029
00030 static bool auto_correct = true;
00031
00032
00033 static bool recovery_check = false;
00034
00035
00036 static pthread_once_t MutableSidrefCheck_once = PTHREAD_ONCE_INIT;
00037 extern "C"
00038 {
00039 static void MutableSidrefCheck_init()
00040 {
00041 Text value;
00042 if(VestaConfig::get("Repository", "mutable_sid_refcount_paranoia", value))
00043 {
00044
00045 if(value == "abort")
00046 {
00047 skip_check = false;
00048 auto_correct = false;
00049
00050
00051
00052 recovery_check = true;
00053 }
00054
00055
00056 else if(value == "correct")
00057 {
00058 skip_check = false;
00059 auto_correct = true;
00060 }
00061
00062 else
00063 {
00064 skip_check = true;
00065 }
00066 }
00067 else
00068 {
00069 skip_check = true;
00070 }
00071 }
00072 }
00073
00074 void MutableSidrefInit()
00075 {
00076 Repos::dprintf(DBG_ALWAYS,
00077 "Rebuilding mutable shortid reference counts\n");
00078 ((VDirChangeable *) VestaSource::mutableRoot())->buildMutableSidref();
00079 Repos::dprintf(DBG_ALWAYS,
00080 "Done rebuilding mutable shortid reference counts\n");
00081 }
00082
00083 void MutableSidrefCheck(VestaSource *vs, ReadersWritersLock *lock)
00084 {
00085 if((vs != 0) && (lock != 0))
00086 MutableSidrefCheck(vs->longid, lock);
00087 }
00088
00089 void MutableSidrefCheck(const LongId &longid, ReadersWritersLock *lock)
00090 {
00091 if(MutableRootLongId.isAncestorOf(longid))
00092 {
00093 MutableSidrefCheck(lock, LongId::checkLock);
00094 }
00095 }
00096
00097 void MutableSidrefCheck(ReadersWritersLock *lock,
00098 LongId::lockKindTag lockKind)
00099 {
00100
00101 pthread_once(&MutableSidrefCheck_once, MutableSidrefCheck_init);
00102
00103
00104 if(skip_check) return;
00105
00106
00107 bool releaseLock = false;
00108 VestaSource *mr = 0;
00109 if(lock != 0)
00110 {
00111 mr = VestaSource::mutableRoot(LongId::checkLock, &lock);
00112 }
00113 else
00114 {
00115 mr = VestaSource::mutableRoot(lockKind, &lock);
00116 releaseLock = (lock != 0);
00117 }
00118 assert(mr != 0);
00119
00120
00121 ((VDirChangeable *) mr)->checkMutableSidref();
00122
00123
00124 if(releaseLock) lock->releaseWrite();
00125 }
00126
00127 bool MutableSidrefRecoveryCheck()
00128 {
00129
00130 pthread_once(&MutableSidrefCheck_once, MutableSidrefCheck_init);
00131
00132 return recovery_check;
00133 }