AcsMountTapeReadOnly.cpp 4.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/
 
24
#include "castor/acs/AcsMountTapeReadOnly.hpp"
25
26
27
28
29
#include "castor/exception/MountFailed.hpp"

//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
30
castor::acs::AcsMountTapeReadOnly::AcsMountTapeReadOnly(
31
32
33
34
35
  const std::string &vid,
  const uint32_t acs,
  const uint32_t lsm,
  const uint32_t panel,
  const uint32_t drive,
36
  Acs &acsWrapper,
37
38
39
40
41
42
43
44
45
46
47
48
49
  log::Logger &log,
  const AcsDaemon::CastorConf &castorConf):
  AcsLibraryInteraction(acsWrapper,log),
  m_volId(acsWrapper.str2Volid(vid)),
  m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)),      
  m_acsWrapper(acsWrapper),
  m_log(log),
  m_castorConf(castorConf) {    
}

//------------------------------------------------------------------------------
// execute
//------------------------------------------------------------------------------
50
51
void castor::acs::AcsMountTapeReadOnly::execute() const {
  syncMountTapeReadOnly();
52
53
54
}

//------------------------------------------------------------------------------
55
// syncMountTapeReadOnly
56
//------------------------------------------------------------------------------
57
void castor::acs::AcsMountTapeReadOnly::syncMountTapeReadOnly() const
58
59
60
61
62
  {
  const SEQ_NO requestSeqNumber = 1;
  ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)];

  try {
63
    sendMountTapeReadOnlyRequest(requestSeqNumber);
64
65
    requestResponsesUntilFinal(requestSeqNumber, buf, 
      m_castorConf.acsQueryLibraryInterval, m_castorConf.acsCommandTimeout);
66
    processMountTapeReadOnlyResponse(buf);
67
68
  }  catch(castor::exception::Exception &ex) {
    castor::exception::MountFailed mf;
69
    mf.getMessage() << "Failed to mount for read only access volume " <<
70
71
72
73
74
75
      m_volId.external_label << ": " << ex.getMessage().str();
    throw mf;
  }
}

//------------------------------------------------------------------------------
76
// sendMountTapeReadOnlyRequest
77
//------------------------------------------------------------------------------
78
void castor::acs::AcsMountTapeReadOnly::sendMountTapeReadOnlyRequest(
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  const SEQ_NO seqNumber) const {
  const LOCKID lockId    = 0; // No lock
  const BOOLEAN bypass   = FALSE;
  const BOOLEAN readOnly = TRUE;

  m_log(LOG_DEBUG,"Calling Acs::mount()");
  const STATUS s = m_acsWrapper.mount(seqNumber, lockId, m_volId,
    m_driveId, readOnly, bypass);
  std::stringstream dbgMsg;
  dbgMsg << "Acs::mount() returned " << acs_status(s);            
  m_log(LOG_DEBUG,dbgMsg.str());

  if(STATUS_SUCCESS != s) {
    castor::exception::MountFailed ex;
93
94
    ex.getMessage() << "Failed to send request to mount for read only access"
      " volume " << m_volId.external_label << " into drive " <<
95
96
97
98
99
100
101
      m_acsWrapper.driveId2Str(m_driveId) << ": readOnly=" <<
      (readOnly ? "TRUE" : "FALSE") << ": " << acs_status(s);
    throw ex;
  } 
}

//------------------------------------------------------------------------------
102
// processMountTapeReadOnlyResponse
103
//------------------------------------------------------------------------------
104
void castor::acs::AcsMountTapeReadOnly::processMountTapeReadOnlyResponse(
105
106
107
108
109
110
  ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const
  {
  const ACS_MOUNT_RESPONSE *const msg = (ACS_MOUNT_RESPONSE *)buf;

  if(STATUS_SUCCESS != msg->mount_status) {
    castor::exception::MountFailed ex;
111
112
    ex.getMessage() << "Status of mount for read only access response is not"
      " success: " << acs_status(msg->mount_status);
113
114
115
116
117
118
119
    throw ex;
  }
}

//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
120
castor::acs::AcsMountTapeReadOnly::~AcsMountTapeReadOnly() throw() {  
121
}