Commit a36c9b84 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Added the fork and run label methods for the cleaner session inside the tape daemon

parent 2ec65902
......@@ -45,6 +45,7 @@
#include "h/Ctape.h"
#include "h/rtcp_constants.h"
#include "h/rtcpd_constants.h"
#include "CleanerSession.hpp"
#include <algorithm>
#include <errno.h>
......@@ -1219,3 +1220,100 @@ void castor::tape::tapeserver::daemon::TapeDaemon::runLabelSession(
exit(1);
}
}
//------------------------------------------------------------------------------
// forkCleanerSessions
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::TapeDaemon::forkCleanerSessions() {
const std::list<std::string> unitNames =
m_driveCatalogue.getUnitNamesWaitingForCleanerFork();
for(std::list<std::string>::const_iterator itor = unitNames.begin();
itor != unitNames.end(); itor++) {
const std::string &unitName = *itor;
DriveCatalogueEntry *drive = m_driveCatalogue.findDrive(unitName);
forkCleanerSession(drive);
}
}
//------------------------------------------------------------------------------
// forkCleanerSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::TapeDaemon::forkCleanerSession(
DriveCatalogueEntry *drive) {
const utils::DriveConfig &driveConfig = drive->getConfig();
std::list<log::Param> params;
params.push_back(log::Param("unitName", driveConfig.unitName));
m_processForker->forkCleaner(driveConfig.unitName, "");
m_log.prepareForFork();
const pid_t forkRc = fork();
// If fork failed
if(0 > forkRc) {
// Log an error message and return
char message[100];
sstrerror_r(errno, message, sizeof(message));
params.push_back(log::Param("message", message));
m_log(LOG_ERR, "Failed to fork cleaner session", params);
// Else if this is the parent process
} else if(0 < forkRc) {
drive->forkedLabelSession(forkRc);
} else { // Else this is the child process
// Clear the reactor which in turn will close all of the open
// file-descriptors owned by the event handlers
m_reactor.clear();
runCleanerSession(drive);
}
}
//------------------------------------------------------------------------------
// runCleanerSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::TapeDaemon::runCleanerSession(
DriveCatalogueEntry *drive) throw() {
const utils::DriveConfig &driveConfig = drive->getConfig();
std::list<log::Param> params;
params.push_back(log::Param("unitName", driveConfig.unitName));
m_log(LOG_INFO, "Cleaner-session child-process started", params);
try {
std::auto_ptr<legacymsg::RmcProxy> rmc(m_rmcFactory.create());
castor::tape::System::realWrapper sWrapper;
castor::tape::tapeserver::daemon::CleanerSession cleanerSession(
*(rmc.get()),
m_log,
driveConfig,
sWrapper);
int ret = cleanerSession.clean(); //clean() returns 0 if drive should be put up or 1 if it should be put down
if(0==ret) {
m_log(LOG_INFO, "Cleaner session cleaned the drive. The drive is going (staying) up", params);
m_vdqm.setDriveUp(m_hostName, driveConfig.unitName, driveConfig.dgn);
drive->configureUp();
}
else if(1==ret) {
m_log(LOG_ERR, "Cleaner session couldn't clean the drive properly. The drive is going down", params);
m_vdqm.setDriveDown(m_hostName, driveConfig.unitName, driveConfig.dgn);
drive->configureDown();
}
exit(0);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Aborting cleaner session. Reason: " << ne.getMessage().str();
m_log(LOG_ERR, ex.getMessage().str());
exit(1);
} catch(std::exception &se) {
params.push_back(log::Param("message", se.what()));
m_log(LOG_ERR, "Aborting cleaner session: Caught an unexpected exception",
params);
exit(1);
} catch(...) {
m_log(LOG_ERR,
"Aborting cleaner session: Caught an unexpected and unknown exception");
exit(1);
}
}
......@@ -393,7 +393,7 @@ protected:
void forkLabelSession(DriveCatalogueEntry *drive);
/**
* Runs the label session. This method is to be called within the child
* Runs the label session. This method is to be called within the child
* process responsible for running the label session.
*
* @param drive The catalogue entry of the tape drive to be used during the
......@@ -403,6 +403,33 @@ protected:
*/
void runLabelSession(const DriveCatalogueEntry *drive,
const int labelCmdConnection) throw();
/**
* Forks a cleaner-session child-process for every tape drive entry in the
* tape drive catalogue that is waiting for such a fork to be carried out.
*
* There may be more than one child-process to fork because there may be
* more than one tape drive connected to the tape server and the previous
* call to m_reactor.handleEvents() handled requests to start a cleaner
* session on more than one of the connected tape drives.
*/
void forkCleanerSessions();
/**
* Forks a cleaner-session child-process for the specified tape drive.
*
* @param drive The tape-drive entry in the tape-drive catalogue.
*/
void forkCleanerSession(DriveCatalogueEntry *drive);
/**
* Runs the cleaner session. This method is to be called within the child
* process responsible for running the cleaner session.
*
* @param drive The catalogue entry of the tape drive to be used during the
* session.
*/
void runCleanerSession(DriveCatalogueEntry *drive) throw();
/**
* Catalogue used to keep track of both the initial and current state of
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment