xrootd
XrdFrmPurge.hh
Go to the documentation of this file.
00001 #ifndef __FRMPURGE__
00002 #define __FRMPURGE__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d F r m P u r g e . h h                         */
00006 /*                                                                            */
00007 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include <time.h>
00034 #include <sys/types.h>
00035 
00036 #include "XrdFrm/XrdFrmTSort.hh"
00037 #include "XrdOss/XrdOssSpace.hh"
00038 
00039 class XrdFrmFileset;
00040 class XrdOucPolProg;
00041 class XrdOucStream;
00042 class XrdOucTList;
00043 
00044 class XrdFrmPurge
00045 {
00046 public:
00047 
00048 static void          Display();
00049 
00050 static int           Init(XrdOucTList *sP=0, long long minV=-1, int hVal=-1);
00051 
00052 static XrdFrmPurge  *Policy(const char *sname) {return Find(sname);}
00053 static XrdFrmPurge  *Policy(const char *sname, long long minV, long long maxV,
00054                                                int hVal, int xVal);
00055 
00056 static void          Purge();
00057 
00058                      XrdFrmPurge(const char *snp, XrdFrmPurge *spp=0);
00059                     ~XrdFrmPurge() {Clear();}
00060 
00061 private:
00062 
00063 // Methods
00064 //
00065 static void          Add(XrdFrmFileset *fsp);
00066        XrdFrmFileset*Advance();
00067        void          Clear();
00068        void          Defer(XrdFrmFileset *sP, time_t xTime);
00069 const  char         *Eligible(XrdFrmFileset *sP, time_t &xTime, int hTime=0);
00070 static XrdFrmPurge  *Find(const char *snp);
00071 static int           LowOnSpace();
00072        int           PurgeFile();
00073        int           PurgeFile(XrdFrmFileset *fP, const char *pFN);
00074 static void          Scan();
00075 static void          Stats(int Final);
00076        void          Track(XrdFrmFileset *sP);
00077 const  char         *XPolOK(XrdFrmFileset *sP);
00078 static XrdOucProg   *PolProg;
00079 static XrdOucStream *PolStream;
00080 
00081 // Static Variables
00082 
00083 static time_t        lastReset;
00084 static time_t        nextReset;
00085 
00086 static XrdFrmPurge  *First;
00087 static XrdFrmPurge  *Default;
00088 
00089 static int           Left2Do;
00090 
00091 // Variables local to each object
00092 //
00093 long long            freeSpace;      // Current free space
00094 long long            fconMaxsp;      // Current free space contiguous
00095 long long            usedSpace;      // Curreny used space (if supported)
00096 long long            pmaxSpace;      // PMax  space (computed once)
00097 long long            totlSpace;      // Total space (computed once)
00098 long long            contSpace;      // Total contg (computed once)
00099 long long            purgBytes;      // Purged bytes on last purge cycle
00100 long long            minFSpace;      // Minimum free space
00101 long long            maxFSpace;      // Maximum free space (what we purge to)
00102 char                *spaceTotl;
00103 char                *spaceTotP;
00104 int                  spaceTLen;
00105 int                  spaceTLep;
00106 int                  Hold;           // Hold value
00107 int                  Hold2x;         // Hold x2 (what we actually use)
00108 int                  Ext;            // External policy applies
00109 int                  numFiles;       // Total number of files
00110 int                  prgFiles;       // Total number of purged
00111 int                  Enabled;
00112 int                  Stop;
00113 int                  SNlen;
00114 
00115 XrdFrmPurge         *Next;
00116 XrdFrmTSort          FSTab;
00117 char                 SName[XrdOssSpace::minSNbsz];
00118 
00119 static const int     DeferQsz = 16;
00120 XrdFrmFileset       *DeferQ[DeferQsz];
00121 time_t               DeferT[DeferQsz];
00122 };
00123 #endif