XRootD
XrdOssArcStopMon Class Reference

#include <XrdOssArcStopMon.hh>

+ Inheritance diagram for XrdOssArcStopMon:
+ Collaboration diagram for XrdOssArcStopMon:

Public Member Functions

 XrdOssArcStopMon (const char *apath, int chkT, bool &aOK)
 
 XrdOssArcStopMon (const XrdOssArcStopMon &other)=delete
 
 XrdOssArcStopMon (XrdOssArcStopMon *parent)
 
virtual ~XrdOssArcStopMon ()
 
void Activate ()
 
void Deactivate ()
 
virtual void DoIt () override
 
XrdOssArcStopMonoperator= (const XrdOssArcStopMon &)=delete
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 42 of file XrdOssArcStopMon.hh.

Constructor & Destructor Documentation

◆ XrdOssArcStopMon() [1/3]

XrdOssArcStopMon::XrdOssArcStopMon ( const char *  apath,
int  chkT,
bool &  aOK 
)

Definition at line 65 of file XrdOssArcStopMon.cc.

66  : XrdJob("StopMon"),
67  xsLock(*(new XrdSysXSLock())),
68  admPath(aPath), chkInterval(chkT)
69 {
70 // Tty to open the admin path. This is where the STOP file should appear and
71 // where we plce the IDLE file once we have safely stopped all the archiving
72 // and restores.
73 //
74  if ((admDirFD = XrdSysFD_Open(aPath, O_DIRECTORY|O_RDONLY)) < 0)
75  {Elog.Emsg("Config", errno, "open admin path", aPath);
76  aOK = false;
77  return;
78  }
79 
80 // Remove any idle file left over from previous run
81 //
82  if (unlinkat(admDirFD, IdleFN, 0) && errno != ENOENT)
83  {Elog.Emsg("Config", errno, "remove IDLE file in admin path", aPath);
84  aOK = false;
85  close(admDirFD);
86  admDirFD = -1;
87  return;
88  }
89 
90 // Now schedule ourselves to see if a stop file appears
91 //
92  schedP->Schedule(this, time(0)+chkT);
93 
94 // All done
95 //
96  aOK = true;
97 }
#define close(a)
Definition: XrdPosix.hh:48
XrdJob(const char *desc="")
Definition: XrdJob.hh:51
void Schedule(XrdJob *jp)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116
XrdScheduler * schedP
static const char * IdleFN
XrdSysError Elog(0, "OssArc_")

References close, XrdOssArcGlobals::Elog, XrdSysError::Emsg(), XrdOssArcGlobals::IdleFN, XrdOfsPrepGPIReal::schedP, and XrdScheduler::Schedule().

+ Here is the call graph for this function:

◆ XrdOssArcStopMon() [2/3]

XrdOssArcStopMon::XrdOssArcStopMon ( XrdOssArcStopMon parent)
inline

Definition at line 68 of file XrdOssArcStopMon.hh.

68  : xsLock(parent->xsLock),
69  admPath(0), admDirFD(-1), isActive(true)
70  {xsLock.Lock(xs_Shared);}
static void parent()
@ xs_Shared
Definition: XrdSysXSLock.hh:38
void Lock(const XrdSysXS_Type usage)
Definition: XrdSysXSLock.cc:55

References XrdSysXSLock::Lock(), and xs_Shared.

+ Here is the call graph for this function:

◆ ~XrdOssArcStopMon()

XrdOssArcStopMon::~XrdOssArcStopMon ( )
virtual

Definition at line 103 of file XrdOssArcStopMon.cc.

104 {
105 // Parent instances of this class may not be destroyed. A parent instance
106 // is indicated by admDirFD being non-negative.
107 //
108  if (admDirFD >= 0)
109  {Elog.Emsg("StopMon", "Invalid deletion of StopMon parent instance for",
110  admPath);
111  std::abort();
112  }
113 
114 // We are not a parent, release the lock since the constructor obtained it.
115 //
116  Deactivate();
117 }

References Deactivate(), XrdOssArcGlobals::Elog, and XrdSysError::Emsg().

+ Here is the call graph for this function:

◆ XrdOssArcStopMon() [3/3]

XrdOssArcStopMon::XrdOssArcStopMon ( const XrdOssArcStopMon other)
delete

Member Function Documentation

◆ Activate()

void XrdOssArcStopMon::Activate ( )
inline

Definition at line 53 of file XrdOssArcStopMon.hh.

53 {if (!isActive.exchange(true)) xsLock.Lock(xs_Shared);}
bool exchange(bool v, std::memory_order mo=std::memory_order_relaxed) noexcept

References XrdSys::RAtomic< bool >::exchange(), XrdSysXSLock::Lock(), and xs_Shared.

Referenced by XrdOssArcBackupTask::BkpXeq().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Deactivate()

void XrdOssArcStopMon::Deactivate ( )
inline

Definition at line 57 of file XrdOssArcStopMon.hh.

57  {if (isActive.exchange(false))
58  xsLock.UnLock(xs_Shared);
59  }
void UnLock(const XrdSysXS_Type usage=xs_None)
Definition: XrdSysXSLock.cc:95

References XrdSys::RAtomic< bool >::exchange(), XrdSysXSLock::UnLock(), and xs_Shared.

Referenced by ~XrdOssArcStopMon(), and XrdOssArcBackupTask::BkpXeq().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoIt()

void XrdOssArcStopMon::DoIt ( )
overridevirtual

Implements XrdJob.

Definition at line 123 of file XrdOssArcStopMon.cc.

124 {
125  static const mode_t idleMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
126  static const int idleOflg = O_CREAT | O_RDWR | O_CLOEXEC;
127  struct stat Stat;
128 
129 // This method is only valid for the parent class.
130 //
131  if (admDirFD < 0)
132  {Elog.Emsg("StopMon","Invalid DoIt() call on child instance for",admPath);
133  return;
134  }
135 
136 // Check if a STOP file exists in the admpath. If it does, try to obtain a
137 // write lock. Only one thread may it and when we get it we know no other
138 // threads are actively executing a backup or restore. Once we have it,
139 // Issue a message and create an IDLE file.
140 //
141  if (fstatat(admDirFD, StopFN, &Stat, 0) == 0)
142  {Elog.Emsg("StopMon", "STOP file found in", admPath);
143  xsLock.Lock(xs_Exclusive);
144  Elog.Emsg("StopMon", "Drain complete; entering idle state...");
145  int iFD = openat(admDirFD, IdleFN, idleOflg, idleMode);
146  if (iFD < 0) Elog.Emsg("StopMon",errno,"create IDLE file in",admPath);
147  else close(iFD);
148  do {XrdSysTimer::Snooze(10);} while(!fstatat(admDirFD,StopFN,&Stat,0));
149  unlinkat(admDirFD, IdleFN, 0);
150  xsLock.UnLock(xs_Exclusive);
151  Elog.Emsg("StopMon", "Resuming execution; STOP file removed!");
152  }
153 
154 // Reschedule ourselves
155 //
156  schedP->Schedule(this, time(0)+chkInterval);
157 }
struct stat Stat
Definition: XrdCks.cc:49
int openat(int dirfd, const char *path, int flag,...)
#define fstatat(a, b, c, d)
Definition: XrdPosix.hh:64
#define stat(a, b)
Definition: XrdPosix.hh:105
@ xs_Exclusive
Definition: XrdSysXSLock.hh:38
static void Snooze(int seconds)
Definition: XrdSysTimer.cc:168
static const char * StopFN

References close, XrdOssArcGlobals::Elog, XrdSysError::Emsg(), fstatat, XrdOssArcGlobals::IdleFN, XrdSysXSLock::Lock(), openat(), XrdOfsPrepGPIReal::schedP, XrdScheduler::Schedule(), XrdSysTimer::Snooze(), Stat, stat, XrdOssArcGlobals::StopFN, XrdSysXSLock::UnLock(), and xs_Exclusive.

+ Here is the call graph for this function:

◆ operator=()

XrdOssArcStopMon& XrdOssArcStopMon::operator= ( const XrdOssArcStopMon )
delete

The documentation for this class was generated from the following files: