From 9c68c670d03535b50f3fe10b5c6105c99234b92c Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Sat, 17 Jan 2015 12:14:39 +0100
Subject: [PATCH] Added the castor configuration parameter RMC:MAXRQSTATTEMPTS

---
 castor/castor.conf                              |  4 ++--
 castor/legacymsg/RmcProxyTcpIp.cpp              | 13 ++++++++-----
 castor/legacymsg/RmcProxyTcpIp.hpp              | 17 +++++++++++------
 castor/mediachanger/DismountCmdMain.cpp         |  5 ++++-
 castor/mediachanger/MountCmdMain.cpp            |  5 ++++-
 castor/tape/tapeserver/daemon/ProcessForker.cpp | 12 +++++++++---
 .../tape/tapeserver/daemon/TapeDaemonConfig.cpp |  3 +++
 .../tape/tapeserver/daemon/TapeDaemonConfig.hpp |  5 +++++
 h/rmc_constants.h                               |  2 ++
 9 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/castor/castor.conf b/castor/castor.conf
index 98b43620c1..cc58e3d6d2 100644
--- a/castor/castor.conf
+++ b/castor/castor.conf
@@ -458,8 +458,8 @@
 
 ## Tape ########################################################################
 
-#RMC    PORT            5014            # TCP port for RMC daemon and client
-                                        # to work with (5014 is the default)
+#RMC PORT            5014  # TCP port for RMC daemon and client
+#RMC MAXRQSTATTEMPTS 10    # Maximum number of attempts a retriable RMC request should be issued
 
 # To switch the smc logic to a Spectra like library LIBRARY_TYPE SPECTRA should
 # be used. It fixs outputs for the smc command line tools and disables not 
diff --git a/castor/legacymsg/RmcProxyTcpIp.cpp b/castor/legacymsg/RmcProxyTcpIp.cpp
index 25dbb55ab0..4eb686e744 100644
--- a/castor/legacymsg/RmcProxyTcpIp.cpp
+++ b/castor/legacymsg/RmcProxyTcpIp.cpp
@@ -31,10 +31,13 @@
 //------------------------------------------------------------------------------
 // constructor
 //------------------------------------------------------------------------------
-castor::legacymsg::RmcProxyTcpIp::RmcProxyTcpIp(const unsigned short rmcPort,
-  const int netTimeout) throw():
+castor::legacymsg::RmcProxyTcpIp::RmcProxyTcpIp(
+  const unsigned short rmcPort,
+  const int netTimeout,
+  const unsigned int maxRqstAttempts) throw():
   m_rmcPort(rmcPort),
-  m_netTimeout(netTimeout) {
+  m_netTimeout(netTimeout),
+  m_maxRqstAttempts(maxRqstAttempts) {
 } 
 
 //------------------------------------------------------------------------------
@@ -64,7 +67,7 @@ void castor::legacymsg::RmcProxyTcpIp::mountTapeReadWrite(
     castor::utils::copyString(rqstBody.vid, vid);
     rqstBody.drvOrd = librarySlot.getDrvOrd();
 
-    rmcSendRecvNbAttempts(RMC_MAXATTEMPTS, librarySlot.getRmcHostName(),
+    rmcSendRecvNbAttempts(m_maxRqstAttempts, librarySlot.getRmcHostName(),
       rqstBody);
   } catch(castor::exception::Exception &ne) {
     castor::exception::Exception ex;
@@ -89,7 +92,7 @@ void castor::legacymsg::RmcProxyTcpIp::dismountTape(const std::string &vid,
     rqstBody.drvOrd = librarySlot.getDrvOrd();
     rqstBody.force = 0;
 
-    rmcSendRecvNbAttempts(RMC_MAXATTEMPTS, librarySlot.getRmcHostName(),
+    rmcSendRecvNbAttempts(m_maxRqstAttempts, librarySlot.getRmcHostName(),
       rqstBody);
   } catch(castor::exception::Exception &ne) {
     castor::exception::Exception ex;
diff --git a/castor/legacymsg/RmcProxyTcpIp.hpp b/castor/legacymsg/RmcProxyTcpIp.hpp
index 431392657b..00d9ad5d83 100644
--- a/castor/legacymsg/RmcProxyTcpIp.hpp
+++ b/castor/legacymsg/RmcProxyTcpIp.hpp
@@ -49,8 +49,13 @@ public:
    * @param rmcPort The TCP/IP port on which the rmcd daemon is listening.
    * @param netTimeout The timeout in seconds to be applied when performing
    * network read and write operations.
+   * @parm maxRqstAttempts The maximum number of attempts a retriable RMC
+   * request should be issued.
    */
-  RmcProxyTcpIp(const unsigned short rmcPort, const int netTimeout) throw();
+  RmcProxyTcpIp(
+    const unsigned short rmcPort,
+    const int netTimeout,
+    const unsigned int maxRqstAttempts) throw();
 
   /**
    * Destructor.
@@ -111,11 +116,6 @@ protected:
    */
   static const int RMC_MSGBUFSIZ = 256;
 
-  /**
-   * The maximum number of attempts a retriable RMC request should be issued.
-   */
-  static const int RMC_MAXATTEMPTS = 10;
-
   /**
    * The TCP/IP port on which the rmcd daemon is listening.
    */
@@ -127,6 +127,11 @@ protected:
    */
   const int m_netTimeout;
 
+  /**
+   * The maximum number of attempts a retriable RMC request should be issued.
+   */
+  const unsigned int m_maxRqstAttempts;
+
   /**
    * Connects to the rmcd daemon.
    *
diff --git a/castor/mediachanger/DismountCmdMain.cpp b/castor/mediachanger/DismountCmdMain.cpp
index 935ec9fdf7..931eaad7ba 100644
--- a/castor/mediachanger/DismountCmdMain.cpp
+++ b/castor/mediachanger/DismountCmdMain.cpp
@@ -100,11 +100,14 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) {
   const unsigned short rmcPort = castorConf.getConfEntInt("RMC", "PORT",
     (unsigned short)RMC_PORT);
 
+  const unsigned int rmcMaxRqstAttempts = castorConf.getConfEntInt("RMC",
+    "MAXRQSTATTEMPTS", (unsigned int)RMC_MAXRQSTATTEMPTS);
+
   // The network timeout of rmc communications should be several minutes due
   // to the time it takes to mount and unmount tapes
   const int rmcNetTimeout = 600; // Timeout in seconds
 
-  legacymsg::RmcProxyTcpIp rmc(rmcPort, rmcNetTimeout);
+  legacymsg::RmcProxyTcpIp rmc(rmcPort, rmcNetTimeout, rmcMaxRqstAttempts);
 
   mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
   
diff --git a/castor/mediachanger/MountCmdMain.cpp b/castor/mediachanger/MountCmdMain.cpp
index fb58b8f7f9..4f45a97e54 100644
--- a/castor/mediachanger/MountCmdMain.cpp
+++ b/castor/mediachanger/MountCmdMain.cpp
@@ -98,11 +98,14 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) {
   const unsigned short rmcPort = castorConf.getConfEntInt("RMC", "PORT",
     (unsigned short)RMC_PORT);
 
+  const unsigned int rmcMaxRqstAttempts = castorConf.getConfEntInt("RMC",
+    "MAXRQSTATTEMPTS", (unsigned int)RMC_MAXRQSTATTEMPTS);
+
   // The network timeout of rmc communications should be several minutes due
   // to the time it takes to mount and unmount tapes
   const int rmcNetTimeout = 600; // Timeout in seconds
 
-  legacymsg::RmcProxyTcpIp rmc(rmcPort, rmcNetTimeout);
+  legacymsg::RmcProxyTcpIp rmc(rmcPort, rmcNetTimeout, rmcMaxRqstAttempts);
 
   mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
   
diff --git a/castor/tape/tapeserver/daemon/ProcessForker.cpp b/castor/tape/tapeserver/daemon/ProcessForker.cpp
index 015dda3826..2eec4aae63 100644
--- a/castor/tape/tapeserver/daemon/ProcessForker.cpp
+++ b/castor/tape/tapeserver/daemon/ProcessForker.cpp
@@ -480,7 +480,9 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
     // The network timeout of rmc communications should be several minutes due
     // to the time it takes to mount and unmount tapes
     const int rmcNetTimeout = 600; // Timeout in seconds
-    legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout);
+
+    legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout,
+      m_config.rmcMaxRqstAttempts);
 
     mediachanger::MediaChangerFacade mediaChangerFacade(acs, mmc, rmc);
 
@@ -534,7 +536,9 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
   // The network timeout of rmc communications should be several minutes due
   // to the time it takes to mount and unmount tapes
   const int rmcNetTimeout = 600; // Timeout in seconds
-  legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout);
+
+  legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout,
+    m_config.rmcMaxRqstAttempts);
 
   mediachanger::MediaChangerFacade mediaChangerFacade(acs, mmc, rmc);
 
@@ -857,7 +861,9 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
     // The network timeout of rmc communications should be several minutes due
     // to the time it takes to mount and unmount tapes
     const int rmcNetTimeout = 600; // Timeout in seconds
-    legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout);
+
+    legacymsg::RmcProxyTcpIp rmc(m_config.rmcPort, rmcNetTimeout,
+      m_config.rmcMaxRqstAttempts);
 
     mediachanger::MediaChangerFacade mediaChangerFacade(acs, mmc, rmc);
 
diff --git a/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp b/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
index 925409a094..02f3318435 100644
--- a/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
+++ b/castor/tape/tapeserver/daemon/TapeDaemonConfig.cpp
@@ -31,6 +31,7 @@
 //------------------------------------------------------------------------------
 castor::tape::tapeserver::daemon::TapeDaemonConfig::TapeDaemonConfig():
   rmcPort(0),
+  rmcMaxRqstAttempts(0),
   jobPort(0),
   adminPort(0),
   labelPort(0),
@@ -54,6 +55,8 @@ castor::tape::tapeserver::daemon::TapeDaemonConfig
   config.vmgrHost = castorConf.getConfEntString("VMGR", "HOST", log);
   config.rmcPort = castorConf.getConfEntInt("RMC", "PORT",
     (unsigned short)RMC_PORT, log);
+  config.rmcMaxRqstAttempts = castorConf.getConfEntInt("RMC",
+    "MAXRQSTATTEMPTS", (unsigned int)RMC_MAXRQSTATTEMPTS, log);
   config.jobPort = castorConf.getConfEntInt("TapeServer", "JobPort",
     TAPESERVER_JOB_PORT, log);
   config.adminPort = castorConf.getConfEntInt("TapeServer", "AdminPort",
diff --git a/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp b/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
index fe50d6917e..38e4f5c375 100644
--- a/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
+++ b/castor/tape/tapeserver/daemon/TapeDaemonConfig.hpp
@@ -67,6 +67,11 @@ struct TapeDaemonConfig {
    */
   unsigned short rmcPort;
 
+  /**
+   * The maximum number of attempts a retriable RMC request should be issued.
+   */
+  unsigned int rmcMaxRqstAttempts;
+
   /**
    * The TCP/IP port on which the tape server daemon listens for incoming
    * connections from the VDQM server.
diff --git a/h/rmc_constants.h b/h/rmc_constants.h
index cef13524ac..5ef54f4cfa 100644
--- a/h/rmc_constants.h
+++ b/h/rmc_constants.h
@@ -24,6 +24,8 @@
 
 #define RMC_PORT 5014
 
+#define RMC_MAXRQSTATTEMPTS 10 /* Maximum number of attempts a retriable RMC request should be issued */
+
 			/* SCSI media changer utilities exit codes */
 
 #define	USERR	  1	/* user error */
-- 
GitLab