CleanerSession.hpp 7.06 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
24
25
/******************************************************************************
 *
 * 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
 *****************************************************************************/

#pragma once

Victor Kotlyar's avatar
Victor Kotlyar committed
26
27
#include "common/log/LogContext.hpp"
#include "common/log/Logger.hpp"
28
#include "tapeserver/castor/mediachanger/MediaChangerFacade.hpp"
29
#include "common/processCap/ProcessCap.hpp"
30
31
32
33
34
#include "DriveConfig.hpp"
#include "Session.hpp"
#include "tapeserver/castor/tape/tapeserver/drive/DriveInterface.hpp"
#include "tapeserver/castor/tape/tapeserver/file/Structures.hpp"
#include "tapeserver/castor/tape/tapeserver/SCSI/Device.hpp"
35
#include "tapeserver/castor/tape/tapeserver/daemon/EncryptionControl.hpp"
36
37
38
39
40
41
42
43
44
45

#include <memory>

namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  /**
   * Class responsible for cleaning up a tape drive left in a (possibly) dirty state.
   */
46
  class CleanerSession : public Session {
47
48
49
50
51
    
  public:
    /**
     * Constructor
     * 
52
53
54
55
56
57
58
     * @param capUtils Object providing support for UNIX capabilities.
     * @param mc Object representing the media changer.
     * @param log Object representing the API to the CASTOR logging system.
     * @param driveConfig Configuration of the tape drive to be cleaned.
     * @param sysWrapper Object representing the operating system.
     * @param vid The volume identifier of the mounted tape if known,
     * else the empty string.
59
60
61
62
     * @param waitMediaInDrive true if we want to check the presence of the media in the drive before cleaning,
     * false otherwise.
     * @param waitMediaInDriveTimeout The maximum number of seconds to wait for
     * the media to be ready for operations inside the drive.
63
64
     * @param externalEncryptionKeyScript path to the operator provided script
     * for encryption control.
65
66
     */
    CleanerSession(
67
      cta::server::ProcessCap &capUtils,
68
      mediachanger::MediaChangerFacade &mc,
Victor Kotlyar's avatar
Victor Kotlyar committed
69
      cta::log::Logger &log,
70
      const DriveConfig &driveConfig,
71
      System::virtualWrapper &sysWrapper,
72
      const std::string &vid,
73
      const bool waitMediaInDrive,
74
75
76
      const uint32_t waitMediaInDriveTimeout,
      const std::string & externalEncryptionKeyScript);

77
78
79
80
81
82
    /** 
     * Execute the session and return the type of action to be performed
     * immediately after the session has completed.
     *
     * @return Returns the type of action to be performed after the session has
     * completed.
83
     */
84
    EndOfSessionAction execute() throw();
85
86
    
  private:
87

88
89
90
    /**
     * Object providing support for UNIX capabilities.
     */
91
    cta::server::ProcessCap &m_capUtils;
92

93
    /**
94
     * The object representing the media changer.
95
     */
96
    mediachanger::MediaChangerFacade &m_mc;
97
98
99
100
    
    /**
     * The logging object     
     */
Victor Kotlyar's avatar
Victor Kotlyar committed
101
    cta::log::Logger & m_log;
102
103
104
105
    
    /**
     * The configuration of the tape drive to be cleaned.
     */
106
    const DriveConfig m_driveConfig;
107
108
109
110
111
    
    /**
     * The system wrapper used to find the device and instantiate the drive object
     */
    System::virtualWrapper & m_sysWrapper;
112
113
114
115
116
117

    /**
     * The volume identifier of the mounted tape if known, else the empty
     * string.
     */
    const std::string m_vid;
118
119

    /**
120
121
122
123
124
125
126
127
     * true if we want to check the presence of the media in the drive before cleaning,
     * false otherwise.
     */    
    const bool m_waitMediaInDrive;
    
    /**
     * The maximum number of seconds to wait for
     * the media to be ready for operations inside the drive.
128
     */
129
    const uint32_t m_waitMediaInDriveTimeout;
130

131
132
133
134
135
    /** 
     * Encryption helper object 
     */
    EncryptionControl m_encryptionControl;

136
137
138
139
140
141
142
    /** 
     * Execute the session and return the type of action to be performed
     * immediately after the session has completed.
     *
     * @return Returns the type of action to be performed after the session has
     * completed.
     */
143
    EndOfSessionAction exceptionThrowingExecute();
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    
    /**
     * Logs and clears (just by reading them...) any outstanding tape alerts
     *
     * @param drive The tape drive.
     */
    void logAndClearTapeAlerts(drive::DriveInterface &drive) throw();
    
    /**
     * Does the actual steps to clean the drive
     *
     * @param drive The tape drive.
     */
    void cleanDrive(drive::DriveInterface &drive);
158
159
160
161
162
163
164
165
166
167
168
169
170
171

    /**
     * Sets the capabilities of the process and logs the result.
     *
     * @param capabilities The string representation of the capabilities.
     */
    void setProcessCapabilities(const std::string &capabilities);

    /**
     * Creates and returns the object that represents the tape drive to be
     * cleaned.
     *
     * @return The tape drive.
     */
172
    std::unique_ptr<drive::DriveInterface> createDrive();
173
174
175
176
177
178

    /**
     * Waits for the specified drive to be ready.
     *
     * @param drive The tape drive.
     */
179
    void waitUntilMediaIsReady(drive::DriveInterface &drive);
180
181
182
183
184
185

    /**
     * Rewinds the specified tape drive.
     *
     * @param drive The tape drive.
     */
186
    void rewindDrive(drive::DriveInterface &drive);
187
188
189
190
191
192
193

    /**
     * Checks the tape in the specified tape drive contains some data where no
     * data means the tape does not even contain a volume label.
     *
     * @param drive The tape drive.
     */
194
    void checkTapeContainsData(drive::DriveInterface &drive);
195
196
197
198
199
200
201
202
203

    /**
     * Checks that the tape in the specified drive contains a valid volume
     * label.
     *
     * @param drive The tape drive for which it is assumed the tape to be
     * tested is present and rewound to the beginning.
     * @return The VSN stored within the colue label.
     */
204
    std::string checkVolumeLabel(drive::DriveInterface &drive);
205
206
207
208
209
210
211
212

    /**
     * Unloads the specified tape from the specified tape drive.
     *
     * @param vid The volume identifier of the tape to be unloaded.  Please note
     * that the value of this field is only used for logging purposes.
     * @param drive The tape drive.
     */
213
    void unloadTape(const std::string &vid, drive::DriveInterface &drive);
214
215
216
217
218
219
220

    /**
     * Dismounts the specified tape.
     *
     * @param vid The volume identifier of the tape to be dismounted.
     */
    void dismountTape(const std::string &vid);
221
222
223
224
225
226
    
  }; // class CleanerSession

} // namespace daemon
} // namespace tapeserver
} // namespace tape
227
} // namespace castor