XRootD
Loading...
Searching...
No Matches
XrdFrmPurgMain.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d F r m P u r g M a i n . c c */
4
/* */
5
/* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* All Rights Reserved */
7
/* Produced by Andrew Hanushevsky for Stanford University under contract */
8
/* DE-AC02-76-SFO0515 with the Department of Energy */
9
/* */
10
/* This file is part of the XRootD software suite. */
11
/* */
12
/* XRootD is free software: you can redistribute it and/or modify it under */
13
/* the terms of the GNU Lesser General Public License as published by the */
14
/* Free Software Foundation, either version 3 of the License, or (at your */
15
/* option) any later version. */
16
/* */
17
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20
/* License for more details. */
21
/* */
22
/* You should have received a copy of the GNU Lesser General Public License */
23
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25
/* */
26
/* The copyright holder's institutional names and contributor's names may not */
27
/* be used to endorse or promote products derived from this software without */
28
/* specific prior written permission of the institution or contributor. */
29
/******************************************************************************/
30
31
/* This is the "main" part of the frm_purge command. Syntax is:
32
*/
33
static
const
char
*
XrdFrmOpts
=
":bc:dfhk:l:n:O:s:S:Tvz"
;
34
static
const
char
*
XrdFrmUsage
=
35
36
" [-b] [-c <cfgfile>] [-d] [-f] [-k {num|sz{k|m|g}|sig] [-l [=]<fn>] [-n name]"
37
" [-O free[,hold]] [-s pidfile] [-S site] [-T] [-v] [-z] [<spaces>] [<paths>]\n"
;
38
/*
39
Where:
40
41
-b Run as a true daemon process in the background.
42
43
-c The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
44
45
-d Turns on debugging mode.
46
47
-f Fix orphaned files (i.e., lock and pin) by removing them.
48
49
-k Keeps num log files or no more that sz log files.
50
51
-l Specifies location of the log file. This may also come from the
52
XrdOucLOGFILE environmental variable.
53
By default, error messages go to standard error.
54
55
-n The instance name.
56
57
-O Run this one time only as a command. The parms are:
58
{free% | sz{k|m|g}[,hold]
59
60
-s The pidfile name.
61
62
-S The site name.
63
64
-T Runs in test mode (no actual purge will occur).
65
66
-v Verbose mode, typically prints each file purged and other details.
67
68
o-t-a The one-time-args run this as a command only once. The args direct
69
the purging process. These may only be specified when -O specified.
70
71
Syntax is: [space] path | space [path]
72
*/
73
74
/******************************************************************************/
75
/* i n c l u d e f i l e s */
76
/******************************************************************************/
77
78
#include <unistd.h>
79
#include <cctype>
80
#include <cerrno>
81
#include <cstdlib>
82
#include <cstring>
83
#include <strings.h>
84
#include <cstdio>
85
#include <sys/param.h>
86
87
#include "
XrdFrc/XrdFrcTrace.hh
"
88
#include "
XrdFrm/XrdFrmConfig.hh
"
89
#include "
XrdFrm/XrdFrmPurge.hh
"
90
#include "
XrdNet/XrdNetOpts.hh
"
91
#include "
XrdNet/XrdNetSocket.hh
"
92
#include "
XrdOuc/XrdOucUtils.hh
"
93
#include "
XrdSys/XrdSysError.hh
"
94
#include "
XrdSys/XrdSysHeaders.hh
"
95
#include "
XrdSys/XrdSysLogger.hh
"
96
#include "
XrdSys/XrdSysPthread.hh
"
97
#include "
XrdSys/XrdSysTimer.hh
"
98
#include "
XrdSys/XrdSysUtils.hh
"
99
100
using namespace
XrdFrc
;
101
using namespace
XrdFrm
;
102
103
/******************************************************************************/
104
/* G l o b a l V a r i a b l e s */
105
/******************************************************************************/
106
107
XrdFrmConfig
XrdFrm::Config
(
XrdFrmConfig::ssPurg
,
108
XrdFrmOpts
,
XrdFrmUsage
);
109
110
// The following is needed to resolve symbols for objects included from xrootd
111
//
112
XrdSysError
XrdLog
(0,
""
);
113
XrdOucTrace
XrdTrace(&
Say
);
114
115
/******************************************************************************/
116
/* T h r e a d I n t e r f a c e s */
117
/******************************************************************************/
118
119
void
*
mainServer
(
void
*parg)
120
{
121
// int udpFD = *static_cast<int *>(parg);
122
// XrdFrmPurge::Server(udpFD);
123
return
(
void
*)0;
124
}
125
126
/******************************************************************************/
127
/* m a i n */
128
/******************************************************************************/
129
130
int
main
(
int
argc,
char
*argv[])
131
{
132
XrdSysLogger
Logger
;
133
extern
int
mainConfig
();
134
135
// Turn off sigpipe and host a variety of others before we start any threads
136
//
137
XrdSysUtils::SigBlock
();
138
139
// Set the default stack size here
140
//
141
if
(
sizeof
(
long
) > 4)
XrdSysThread::setStackSize
((
size_t
)1048576);
142
else
XrdSysThread::setStackSize
((
size_t
)786432);
143
144
// Perform configuration
145
//
146
Say
.logger(&
Logger
);
147
XrdLog
.logger(&
Logger
);
148
if
(!
Config
.Configure(argc, argv, &
mainConfig
)) exit(4);
149
150
// Display configuration (deferred because mum might have been in effect)
151
//
152
if
(!
Config
.isOTO ||
Config
.Verbose)
XrdFrmPurge::Display
();
153
154
// Now simply poke the server every so often
155
//
156
if
(
Config
.isOTO)
XrdFrmPurge::Purge
();
157
else
do
{
if
(
Config
.StopPurge)
158
{
int
n = 0;
159
struct
stat
buf;
160
while
(!
stat
(
Config
.StopPurge, &buf))
161
{
if
(!n--)
162
{
Say
.Emsg(
"PurgMain"
,
Config
.StopPurge,
163
"exists; purging suspended."
); n = 12;}
164
XrdSysTimer::Snooze
(5);
165
}
166
}
167
XrdFrmPurge::Purge
();
168
XrdSysTimer::Snooze
(
Config
.WaitPurge);
169
}
while
(1);
170
171
// All done
172
//
173
exit(0);
174
}
175
176
/******************************************************************************/
177
/* m a i n C o n f i g */
178
/******************************************************************************/
179
180
int
mainConfig
()
181
{
182
XrdFrmConfig::Policy
*pP =
Config
.dfltPolicy.Next;
183
XrdFrmConfig::VPInfo
*vP =
Config
.VPList;
184
XrdNetSocket
*udpSock;
185
pthread_t tid;
186
int
retc, udpFD;
187
188
// If test is in effect, remove the fix flag
189
//
190
if
(
Config
.Test)
Config
.Fix = 0;
191
192
// Go through the policy list and add each policy
193
//
194
while
((pP =
Config
.dfltPolicy.Next))
195
{
if
(!
XrdFrmPurge::Policy
(pP->
Sname
))
196
XrdFrmPurge::Policy
(pP->
Sname
, pP->
minFree
, pP->
maxFree
,
197
pP->
Hold
, pP->
Ext
);
198
Config
.dfltPolicy.Next = pP->
Next
;
199
delete
pP;
200
}
201
202
// Make sure we have a public policy
203
//
204
if
(!
XrdFrmPurge::Policy
(
"public"
))
205
XrdFrmPurge::Policy
(
"public"
,
Config
.dfltPolicy.minFree,
206
Config
.dfltPolicy.maxFree,
207
Config
.dfltPolicy.Hold,
208
Config
.dfltPolicy.Ext);
209
210
// Now add any missing policies (we need one for every space)
211
//
212
while
(vP)
213
{
if
(!
XrdFrmPurge::Policy
(vP->
Name
))
214
XrdFrmPurge::Policy
(vP->
Name
,
Config
.dfltPolicy.minFree,
215
Config
.dfltPolicy.maxFree,
216
Config
.dfltPolicy.Hold,
217
Config
.dfltPolicy.Ext);
218
vP = vP->
Next
;
219
}
220
221
// Enable the appropriate spaces and over-ride config value
222
//
223
if
(!
XrdFrmPurge::Init
(
Config
.spacList,
Config
.cmdFree,
Config
.cmdHold))
224
return
1;
225
226
// We are done if this is a one-time-only call
227
//
228
if
(
Config
.isOTO)
return
0;
229
230
// Get a UDP socket for the server
231
//
232
if
(!(udpSock =
XrdNetSocket::Create
(&
Say
,
Config
.AdminPath,
233
"purg.udp"
,
Config
.AdminMode,
XRDNET_UDPSOCKET
)))
return
1;
234
else
{udpFD = udpSock->
Detach
();
delete
udpSock;}
235
236
// Start the Server thread
237
//
238
if
((retc =
XrdSysThread::Run
(&tid,
mainServer
, (
void
*)&udpFD,
239
XRDSYSTHREAD_BIND
,
"Server"
)))
240
{
Say
.Emsg(
"main"
, retc,
"create server thread"
);
return
1;}
241
242
// All done
243
//
244
return
0;
245
}
Say
XrdOucPup XrdCmsParser::Pup & Say
Definition
XrdCmsParser.cc:124
Logger
static XrdSysLogger Logger
Definition
XrdCryptoAux.cc:37
XrdFrcTrace.hh
XrdLog
XrdSysError XrdLog(0, "")
XrdFrmUsage
static const char * XrdFrmUsage
Definition
XrdFrmAdminMain.cc:34
XrdFrmOpts
static const char * XrdFrmOpts
Definition
XrdFrmAdminMain.cc:33
XrdFrmConfig.hh
main
int main(int argc, char *argv[])
Definition
XrdFrmPurgMain.cc:130
XrdLog
XrdSysError XrdLog(0, "")
mainConfig
int mainConfig()
Definition
XrdFrmPurgMain.cc:180
mainServer
void * mainServer(void *parg)
Definition
XrdFrmPurgMain.cc:119
XrdFrmPurge.hh
XrdNetOpts.hh
XRDNET_UDPSOCKET
#define XRDNET_UDPSOCKET
Definition
XrdNetOpts.hh:79
XrdNetSocket.hh
XrdOucUtils.hh
stat
#define stat(a, b)
Definition
XrdPosix.hh:101
XrdSysError.hh
XrdSysHeaders.hh
XrdSysLogger.hh
XrdSysPthread.hh
XRDSYSTHREAD_BIND
#define XRDSYSTHREAD_BIND
Definition
XrdSysPthread.hh:543
XrdSysTimer.hh
XrdSysUtils.hh
XrdFrmConfig
Definition
XrdFrmConfig.hh:54
XrdFrmConfig::ssPurg
@ ssPurg
Definition
XrdFrmConfig.hh:175
XrdFrmPurge::Purge
static void Purge()
Definition
XrdFrmPurge.cc:586
XrdFrmPurge::Policy
static XrdFrmPurge * Policy(const char *sname)
Definition
XrdFrmPurge.hh:52
XrdFrmPurge::Display
static void Display()
Definition
XrdFrmPurge.cc:295
XrdFrmPurge::Init
static int Init(XrdOucTList *sP=0, long long minV=-1, int hVal=-1)
Definition
XrdFrmPurge.cc:409
XrdNetSocket
Definition
XrdNetSocket.hh:48
XrdNetSocket::Detach
int Detach()
Definition
XrdNetSocket.cc:189
XrdNetSocket::Create
static XrdNetSocket * Create(XrdSysError *Say, const char *path, const char *fn, mode_t mode, int isudp=0)
Definition
XrdNetSocket.cc:144
XrdOucTrace
Definition
XrdOucTrace.hh:36
XrdSysError
Definition
XrdSysError.hh:118
XrdSysLogger
Definition
XrdSysLogger.hh:53
XrdSysThread::Run
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
Definition
XrdSysPthread.cc:307
XrdSysThread::setStackSize
static void setStackSize(size_t stsz, bool force=false)
Definition
XrdSysPthread.cc:330
XrdSysTimer::Snooze
static void Snooze(int seconds)
Definition
XrdSysTimer.cc:168
XrdSysUtils::SigBlock
static bool SigBlock()
Definition
XrdSysUtils.cc:188
XrdFrc
Definition
XrdFrcCID.hh:96
XrdFrm
Definition
XrdFrmAdmin.hh:229
XrdFrm::Config
XrdFrmConfig Config
XrdFrmConfig::Policy
Definition
XrdFrmConfig.hh:134
XrdFrmConfig::Policy::maxFree
long long maxFree
Definition
XrdFrmConfig.hh:135
XrdFrmConfig::Policy::Hold
int Hold
Definition
XrdFrmConfig.hh:136
XrdFrmConfig::Policy::Sname
char Sname[XrdOssSpace::minSNbsz]
Definition
XrdFrmConfig.hh:139
XrdFrmConfig::Policy::minFree
long long minFree
Definition
XrdFrmConfig.hh:134
XrdFrmConfig::Policy::Ext
int Ext
Definition
XrdFrmConfig.hh:137
XrdFrmConfig::Policy::Next
Policy * Next
Definition
XrdFrmConfig.hh:138
XrdFrmConfig::VPInfo
Definition
XrdFrmConfig.hh:122
XrdFrmConfig::VPInfo::Name
char * Name
Definition
XrdFrmConfig.hh:123
XrdFrmConfig::VPInfo::Next
VPInfo * Next
Definition
XrdFrmConfig.hh:122
XrdFrm
XrdFrmPurgMain.cc
Generated by
1.16.1