DriveCatalogue.hpp 25.4 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
/******************************************************************************
 *         castor/tape/tapeserver/daemon/DriveCatalogue.hpp
 *
 * 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 Steven.Murray@cern.ch
 *****************************************************************************/

25
#pragma once
26
27

#include "castor/exception/Exception.hpp"
28
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
29
#include "castor/legacymsg/TapeLabelRqstMsgBody.hpp"
30
31
#include "castor/tape/utils/TpconfigLine.hpp"
#include "castor/tape/utils/TpconfigLines.hpp"
32
33
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
#include "castor/legacymsg/TapeUpdateDriveRqstMsgBody.hpp"
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#include <map>
#include <string>
#include <string.h>

namespace castor     {
namespace tape       {
namespace tapeserver {
namespace daemon     {

/**
 * Class responsible for keeping track of the tape drive being controlled by
 * the tapeserverd daemon.
 */
class DriveCatalogue {
public:

51
52
53
54
55
56
57
58
  /**
   * Destructor.
   *
   * Closes the connection with the label command if the drive catalogue owns
   * the connection at the time of destruction.
   */
  ~DriveCatalogue() throw();

59
60
61
62
  /**
   * The state of a drive as described by the following FSTN:
   *
   *              start daemon /
Steven Murray's avatar
Steven Murray committed
63
64
65
66
67
68
69
70
71
72
73
   *  ------  send VDQM_UNIT_DOWN   ------------------
   * | INIT |--------------------->|       DOWN       |<-------------------
   *  ------                        ------------------                     |
   *     |                          |                ^                     |
   *     |                          |                |                     |
   *     |                          | tpconfig up    | tpconfig down       |
   *     |                          |                |                     |
   *     |      start daemon /      v                |                     |
   *     |    send VDQM_UNIT_UP     ------------------                     |
   *      ------------------------>|       UP         |                    |
   *                                ------------------                     |
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
   *                                |  |             ^                     |
   *              -----------------    |             |                     |
   *             | label job           | vdqm job    |                     |
   *             |                     |             |                     |
   *             v                     v             |                     |
   *        -----------        ------------------    | SIGCHLD             |
   *       | WAITLABEL |      |    WAITFORK      |   | [success]           |
   *        -----------        ------------------    |                     |
   *             |                  |                |                     |
   *             |                  |                |                     |
   *             | forked           | forked         |                     |
   *             |                  |                |                     |
   *             |                  v                |                     |
   *             |                  ------------------    SIGCHLD [fail]   |
   *              ---------------->|     RUNNING      |--------------------|
Steven Murray's avatar
Steven Murray committed
89
90
91
92
93
   *                                ------------------                     |
   *                                |                ^                     |
   *                                |                |                     |
   *                                | tpconfig down  | tpconfig up         |
   *                                |                |                     |
Steven Murray's avatar
Steven Murray committed
94
95
96
   *                                |                |                     |
   *                                v                |  SIGCHLD            |
   *                                ------------------  [success of fail]  |
Steven Murray's avatar
Steven Murray committed
97
98
   *                               |     WAITDOWN     |--------------------
   *                                ------------------
99
100
101
   *
   * When the tapeserverd daemon is started, depending on the initial state
   * defined in /etc/castor/TPCONFIG, the daemon sends either a VDQM_UNIT_UP
Steven Murray's avatar
Steven Murray committed
102
103
   * or VDQM_UNIT_DOWN status message to the vdqmd daemon.  The state of the
   * tape drive is then either DRIVE_STATE_UP or DRIVE_STATE_DOWN respectively.
104
105
106
107
   *
   * A tape operator toggles the state of tape drive between DOWN and UP
   * using the tpconfig adminstration tool.
   *
Steven Murray's avatar
Steven Murray committed
108
109
110
111
112
113
114
115
116
117
118
119
120
   * The tape daemon can receive a job from the vdqmd daemon for a tape drive
   * when the state of that drive is DRIVE_STATE_UP.  On reception of the job
   * the daemon prepares to fork a child process and enters the
   * DRIVE_STATE_WAITFORK state.
   *
   * The DRIVE_STATE_WAIT_FORK state allows the object responsible for handling
   * the connection from the vdqmd daemon (an instance of
   * VdqmConnectionHandler) to delegate the task of forking of a mount session.
   *
   * Once the child process is forked the drive enters the DRIVE_STATE_RUNNING
   * state.  The child process is responsible for running a mount session.
   * During such a sesion a tape will be mounted, data will be transfered to
   * and/or from the tape and finally the tape will be dismounted.
121
122
123
124
   *
   * Once the vdqm job has been carried out, the child process completes
   * and the state of the tape drive either returns to DRIVE_STATE_UP if there
   * were no problems or to DRIVE_STATE_DOWN if there were.
Steven Murray's avatar
Steven Murray committed
125
126
127
128
129
130
131
   *
   * If the tape daemon receives a tpconfig down during a tape session, in
   * other words whilst the drive in question is in the DRIVE_STATE_RUNNING
   * state, then the state of the drive is moved to DRIVE_STATE_WAITDOWN.  The
   * tape session continues to run in the DRIVE_STATE_WAITDOWN state, however
   * when the tape session is finished the state of the drive is moved to
   * DRIVE_STATE_DOWN.
132
133
134
135
136
137
138
139
140
141
   *
   * The tape daemon can receive a job to label a tape in a drive from an
   * administration client when the state of that drive is DRIVE_STATE_UP.  On
   * reception of the job the daemon prepares to fork a child process and
   * enters the DRIVE_STATE_WAITLABEL state.
   *
   * Once the child process is forked the drive enters the DRIVE_STATE_RUNNING
   * state.  The child process is responsible for running a label session.
   * During such a sesion a tape will be mounted, the tape will be labeled and
   * finally the tape will be dismounted.
142
   */
143
144
145
146
147
148
149
150
  enum DriveState {
    DRIVE_STATE_INIT,
    DRIVE_STATE_DOWN,
    DRIVE_STATE_UP,
    DRIVE_STATE_WAITFORK,
    DRIVE_STATE_WAITLABEL,
    DRIVE_STATE_RUNNING,
    DRIVE_STATE_WAITDOWN};
151

152
153
154
155
156
157
158
159
160
161
  /**
   * Returns the string representation of the specified tape-drive state.
   *
   * Please note that this method does not throw an exception and to that end
   * will return the string "UNKNOWN" if the string representation of the
   * specified drive state is unknown.
   *
   * @param state The numerical tape-drive state.
   * @return The string representation if known else "UNKNOWN".
   */
Steven Murray's avatar
Steven Murray committed
162
  static const char *drvState2Str(const DriveState state) throw();
163

Steven Murray's avatar
Steven Murray committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  /**
   * Enumeration of the possible types of session.
   */
  enum SessionType {
    SESSION_TYPE_NONE,
    SESSION_TYPE_DATATRANSFER,
    SESSION_TYPE_LABEL};

  /**
   * Always returns a string representation of the specified session type.
   * If the session type is unknown then an appropriately worded string
   * representation is returned and no exception is thrown.
   *
   * @param sessionType The numerical sessionType.
   * @return The string representation if known else "UNKNOWN".
   */
  static const char *sessionType2Str(const SessionType sessionType) throw();

182
183
184
185
186
187
  /**
   * Poplates the catalogue using the specified parsed lines from
   * /etc/castor/TPCONFIG.
   *
   * @param lines The lines parsed from /etc/castor/TPCONFIG.
   */
188
  void populateCatalogue(const utils::TpconfigLines &lines);
Steven Murray's avatar
Steven Murray committed
189

190
  /**
Steven Murray's avatar
Steven Murray committed
191
192
193
194
195
   * Returns the unit name of the tape drive on which the specified mount
   * session process is running.
   *
   * @param sessionPid The process ID of the mount session.
   * @return the unit name of the tape drive.
196
   */
197
  std::string getUnitName(const pid_t sessionPid) const ;
198

199
200
201
202
  /**
   * Returns an unordered list of the unit names of all of the tape drives
   * stored within the tape drive catalogue.
   *
203
   * @return Unordered list of the unit names.
204
   */
205
  std::list<std::string> getUnitNames() const;
206

207
208
209
210
211
212
  /**
   * Returns an unordered list of the unit names of the tape drives in the
   * specified state.
   *
   * @return Unordered list of the unit names.
   */
213
  std::list<std::string> getUnitNames(const DriveState state) const;
214

215
216
217
218
219
  /**
   * Returns the device group name (DGN) of the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
220
  const std::string &getDgn(const std::string &unitName) const;
221
222
223
224
225
226
  
  /**
   * Returns the VID of the tape mounted on the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
227
  const std::string &getVid(const std::string &unitName) const;
228
229
230
231
232
233
  
  /**
   * Returns the time when the tape was mounted on the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
234
  time_t getAssignmentTime(const std::string &unitName) const;
235
236
237
238
239
240

  /**
   * Returns the filename of the device file of the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
241
  const std::string &getDevFilename(const std::string &unitName) const;
242
243
244
245
246
247

  /**
   * Returns the tape densities supported by the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
248
  const std::list<std::string> &getDensities(const std::string &unitName) const;
Steven Murray's avatar
Steven Murray committed
249
250
251
252
253
254

  /**
   * Returns the type of the specified session.
   *
   * @param sessionPid The process ID of the session.
   */
255
  SessionType getSessionType(const pid_t sessionPid) const;
256

257
258
259
260
261
  /**
   * Returns the current state of the specified tape drive.
   *
   * @param unitName The unit name of the tape drive.
   */
262
  DriveState getState(const std::string &unitName) const;
263

264
  /**
265
   * Returns the library slot of the specified tape drive.
266
267
268
   *
   * @param unitName The unit name of the tape drive.
   */
269
  const std::string &getLibrarySlot(const std::string &unitName) const;
270
271
272
273
274
275

  /**
   * Returns the device type of the specified tape drive in its libary.
   *
   * @param unitName The unit name of the tape drive.
   */
276
  const std::string &getDevType(const std::string &unitName) const;
277
278
279
280
281
282
  
  /**
   * Returns the last tape mode of the tape mounted on this drive
   *
   * @param unitName The unit name of the tape drive.
   */
283
  castor::legacymsg::TapeUpdateDriveRqstMsgBody::TapeMode getTapeMode(const std::string &unitName) const;
284
285
286
287
288
289
  
  /**
   * Returns the last tape event related to this drive
   *
   * @param unitName The unit name of the tape drive.
   */
290
  castor::legacymsg::TapeUpdateDriveRqstMsgBody::TapeEvent getTapeEvent(const std::string &unitName) const;
Steven Murray's avatar
Steven Murray committed
291
292

  /**
293
294
295
296
   * Releases and returns the file descriptor of the connection with the
   * command-line tool castor-tape-label.
   *
   * @param unitName The unit name of the tape drive.
Steven Murray's avatar
Steven Murray committed
297
   */
298
299

  int releaseLabelCmdConnection(const std::string &unitName);
300

301
  /**
Steven Murray's avatar
Steven Murray committed
302
   * Moves the state of the specified tape drive to DRIVE_STATE_UP.
303
304
   *
   * This method throws an exception if the current state of the tape drive is
305
306
307
   * not DRIVE_STATE_UP, DRIVE_STATE_DOWN or DRIVE_STATE_WAITDOWN.
   *
   * configureUp() is idempotent.
308
309
310
   *
   * @param unitName The unit name of the tape drive.
   */
311
  void configureUp(const std::string &unitName) ;
312
313

  /**
Steven Murray's avatar
Steven Murray committed
314
   * Moves the state of the specified tape drive to DRIVE_STATE_DOWN.
315
316
   *
   * This method throws an exception if the current state of the tape drive is
317
318
319
   * not DRIVE_STATE_UP, DRIVE_STATE_DOWN or DRIVE_STATE_RUNNING.
   *
   * configureDown() is idempotent.
320
321
322
   *
   * @param unitName The unit name of the tape drive.
   */
323
  void configureDown(const std::string &unitName) ;
324
325

  /**
Steven Murray's avatar
Steven Murray committed
326
   * Moves the state of the specified tape drive to DRIVE_STATE_WAITFORK.
327
328
329
330
331
332
333
334
335
336
337
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_UP.
   *
   * The unit name of a tape drive is unique for a given host.  No two drives
   * on the same host can have the same unit name.
   *
   * A tape drive cannot be a member of more than one device group name (DGN).
   *
   * This method throws an exception if the DGN field of the specified vdqm job
   * does not match the value that was entered into the catalogue with the
338
   * populateCatalogue() method.
339
340
341
   *
   * @param job The job received from the vdqmd daemon.
   */
Steven Murray's avatar
Steven Murray committed
342
  void receivedVdqmJob(const legacymsg::RtcpJobRqstMsgBody &job)
343
    ;
344

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
  /**
   * Moves the state of the specified tape drive to DRIVE_STATE_WAITLABEL.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_UP.
   *
   * The unit name of a tape drive is unique for a given host.  No two drives
   * on the same host can have the same unit name.
   *
   * A tape drive cannot be a member of more than one device group name (DGN).
   *
   * This method throws an exception if the DGN field of the specified vdqm job
   * does not match the value that was entered into the catalogue with the
   * populateCatalogue() method.
   *
360
361
362
363
364
365
   * PLEASE NOTE: If this method throws an exception then it does NOT close
   * the file descriptor of the TCP/IP connection with the tape labeling
   * command-line tool castor-tape-label.  The caller of this method is left
   * to close the connection because this gives them the opportunity to send
   * an approprioate error message to the client.
   *
366
   * @param job The label job.
Steven Murray's avatar
Steven Murray committed
367
368
   * @param labelCmdConnection The file descriptor of the TCP/IP connection
   * with the tape labeling command-line tool castor-tape-label.
369
   */
Steven Murray's avatar
Steven Murray committed
370
  void receivedLabelJob(const legacymsg::TapeLabelRqstMsgBody &job,
371
    const int labelCmdConnection) ;
372

373
  /**
374
375
   * Returns the job received from the vdqmd daemon for the specified tape
   * drive.
376
377
   *
   * This method throws an exception if the current state of the tape drive is
Steven Murray's avatar
Steven Murray committed
378
   * not DRIVE_STATE_WAITFORK, DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
379
380
   *
   * @param unitName The unit name of the tape drive.
Steven Murray's avatar
Steven Murray committed
381
   * @return The job received from the vdqmd daemon.
382
   */
Steven Murray's avatar
Steven Murray committed
383
  const legacymsg::RtcpJobRqstMsgBody &getVdqmJob(const std::string &unitName)
384
    const ;
Daniele Kruse's avatar
Daniele Kruse committed
385
386
387
388
389
390
391
392
393
394
395
  
  /**
   * Returns the job received from the vdqmd daemon for the specified tape
   * drive.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_WAITFORK, DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
   *
   * @param unitName The unit name of the tape drive.
   * @return The job received from the vdqmd daemon.
   */
Steven Murray's avatar
Steven Murray committed
396
  const legacymsg::TapeLabelRqstMsgBody &getLabelJob(const std::string &unitName)
397
    const ;
398
399

  /**
Steven Murray's avatar
Steven Murray committed
400
   * Moves the state of the specified tape drive to DRIVE_STATE_RUNNING.
401
402
   *
   * This method throws an exception if the current state of the tape drive is
Steven Murray's avatar
Steven Murray committed
403
   * not DRIVE_STATE_WAITFORK.
404
405
   *
   * @param unitName The unit name of the tape drive.
Steven Murray's avatar
Steven Murray committed
406
407
   * @param sessionPid The process ID of the child process responsible for
   * running the mount session.
408
   */
Steven Murray's avatar
Steven Murray committed
409
  void forkedMountSession(const std::string &unitName, const pid_t sessionPid)
410
    ; 
Steven Murray's avatar
Steven Murray committed
411

412
413
414
415
416
417
418
419
420
421
  /**
   * Moves the state of the specified tape drive to DRIVE_STATE_RUNNING.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_WAITLABEL.
   *
   * @param unitName The unit name of the tape drive.
   * @param sessionPid The process ID of the child process responsible for
   * running the label session.
   */
Steven Murray's avatar
Steven Murray committed
422
  void forkedLabelSession(const std::string &unitName, const pid_t sessionPid)
423
    ;
424

425
  /**
Steven Murray's avatar
Steven Murray committed
426
427
428
429
430
431
432
433
434
   * Returns the process ID of the child process responsible the mount session
   * running on the specified tape drive.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
   *
   * @param unitName The unit name of the tape drive.
   * @return The process ID of the child process responsible for mount session
   * running on the specified tape drive.
435
   */
436
  pid_t getSessionPid(const std::string &unitName) const ;
437
438

  /**
Steven Murray's avatar
Steven Murray committed
439
440
441
   * Moves the state of the specified tape drive to DRIVE_STATE_UP if the
   * current state is DRIVE_STATE_RUNNING or to DRIVE_STATE_DOWN if the
   * current state is DRIVE_STATE_WAIT_DOWN.
442
443
   *
   * This method throws an exception if the current state of the tape drive is
Steven Murray's avatar
Steven Murray committed
444
445
446
447
   * not DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
   *
   * @param sessionPid Process ID of the child process handling the session.
   */
448
  void sessionSucceeded(const pid_t sessionPid) ;
Steven Murray's avatar
Steven Murray committed
449
450
451
452
453
454
455
456

  /**
   * Moves the state of the specified tape drive to DRIVE_STATE_UP if the
   * current state is DRIVE_STATE_RUNNING or to DRIVE_STATE_DOWN if the
   * current state is DRIVE_STATE_WAIT_DOWN.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
457
458
459
   *
   * @param unitName The unit name of the tape drive.
   */
460
  void sessionSucceeded(const std::string &unitName) ;
461
462
  
  /**
Steven Murray's avatar
Steven Murray committed
463
464
465
466
467
468
469
   * Moves the state of the specified tape drive to DRIVE_STATE_DOWN.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_RUNNING.
   *
   * @param sessionPid Process ID of the child process handling the session.
   */
470
  void sessionFailed(const pid_t sessionPid) ;
Steven Murray's avatar
Steven Murray committed
471
472
473
474
475
476
477
478

  /**
   * Moves the state of the specified tape drive to DRIVE_STATE_DOWN.
   *
   * This method throws an exception if the current state of the tape drive is
   * not DRIVE_STATE_RUNNING.
   *
   * @param unitName The unit name of the tape drive.
479
   */
480
  void sessionFailed(const std::string &unitName) ;
Daniele Kruse's avatar
Daniele Kruse committed
481
482
483
484
485
486
487
  
  /**
   * Updates the vid and assignment time of the specified drive
   * 
   * @param vid Volume ID of the tape mounted
   * @param unitName Name of the drive
   */
488
  void updateDriveVolumeInfo(const legacymsg::TapeUpdateDriveRqstMsgBody &body) ;
489
490
491
492
493
494
495

private:

  /**
   * Structure used to store a tape drive in the catalogue.
   */
  struct DriveEntry {
496
497
498
499
    
    /**
     * Are we mounting for read, write (read/write), or dump
     */
500
    castor::legacymsg::TapeUpdateDriveRqstMsgBody::TapeMode mode;
501
502
503
504
    
    /**
     * The status of the tape with respect to the drive mount and unmount operations
     */
505
    castor::legacymsg::TapeUpdateDriveRqstMsgBody::TapeEvent event;
506
    
507
508
509
510
511
    /**
     * The device group name of the tape drive as defined in
     * /etc/castor/TPCONFIG.
     */
    std::string dgn;
Daniele Kruse's avatar
Daniele Kruse committed
512
513
514
515
516
517
518
519
520
521
522
    
    /**
     * The Volume ID of the tape mounted in the drive. Empty string if drive is empty.
     */
    std::string vid;
    
    /**
     * The point in time when the drive has been assigned a tape
     */
    time_t assignment_time;
    
523
    /**
Daniele Kruse's avatar
Daniele Kruse committed
524
     * The device file of the tape drive, for example: /dev/nst0
525
526
527
528
529
530
531
532
     */
    std::string devFilename;

    /**
     * The tape densities supported by the tape drive.
     */
    std::list<std::string> densities;

Steven Murray's avatar
Steven Murray committed
533
534
535
536
537
    /**
     * The type of mount session.
     */
    SessionType sessionType;

538
539
540
541
542
    /**
     * The current state of the tape drive.
     */
    DriveState state;

543
    /**
544
     * The library slot n which the tape drive is located, for example:
545
546
     * smc@localhost,0
     */
547
    std::string librarySlot;
548
549
550
551
552
553

    /**
     * The device type of the tape drive, for example: T10000
     */
    std::string devType;

554
555
556
557
558
    /**
     * The job received from the vdqmd daemon when the drive is in the
     * DRIVE_STATE_RUNNING state.  In all other states the value of this
     * member variable is undefined.
     */
Daniele Kruse's avatar
Daniele Kruse committed
559
560
561
562
563
564
565
566
    legacymsg::RtcpJobRqstMsgBody vdqmJob;
    
    /**
     * The label job received from the tape label command when the drive is in the
     * DRIVE_STATE_RUNNING state.  In all other states the value of this
     * member variable is undefined.
     */
    legacymsg::TapeLabelRqstMsgBody labelJob;
567
568
    
    /**
Steven Murray's avatar
Steven Murray committed
569
     * The process ID of the child process running the mount session.
570
     */
Steven Murray's avatar
Steven Murray committed
571
    pid_t sessionPid;
572

Steven Murray's avatar
Steven Murray committed
573
574
575
576
577
578
579
580
581
    /**
     * If the drive state is either DRIVE_WAITLABEL, DRIVE_STATE_RUNNING or
     * DRIVE_STATE_WAITDOWN and the type of the session is SESSION_TYPE_LABEL
     * then this is the file descriptor of the TCP/IP connection with the tape
     * labeling command-line tool castor-tape-label.  In any other state, the
     * value of this filed is undefined.
     */
    int labelCmdConnection;

582
583
    /**
     * Default constructor that initializes all strings to the empty string,
Steven Murray's avatar
Steven Murray committed
584
585
586
     * all integers to zero, all file descriptors to -1, all lists to empty,
     * the drive state to DRIVE_STATE_INIT and the sessionType to
     * SESSION_TYPE_NONE.  This initialization includes the individual member
587
     * variables of the nested vdqm job.
588
589
     */
    DriveEntry() throw():
590
591
      mode(castor::legacymsg::TapeUpdateDriveRqstMsgBody::TAPE_MODE_NONE),
      event(castor::legacymsg::TapeUpdateDriveRqstMsgBody::TAPE_STATUS_NONE),
Steven Murray's avatar
Steven Murray committed
592
593
594
      sessionType(SESSION_TYPE_NONE),
      state(DRIVE_STATE_INIT),
      labelCmdConnection(-1) {
Daniele Kruse's avatar
Daniele Kruse committed
595
596
597
598
599
600
601
602
603
604
605
      labelJob.gid = 0;
      labelJob.uid = 0;
      memset(labelJob.vid, '\0', sizeof(labelJob.vid));
      vdqmJob.volReqId = 0;
      vdqmJob.clientPort = 0;
      vdqmJob.clientEuid = 0;
      vdqmJob.clientEgid = 0;
      memset(vdqmJob.clientHost, '\0', sizeof(vdqmJob.clientHost));
      memset(vdqmJob.dgn, '\0', sizeof(vdqmJob.dgn));
      memset(vdqmJob.driveUnit, '\0', sizeof(vdqmJob.driveUnit));
      memset(vdqmJob.clientUserName, '\0', sizeof(vdqmJob.clientUserName));
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
    }
  };

  /**
   * Type that maps the unit name of a tape drive to the catalogue entry of
   * that drive.
   */
  typedef std::map<std::string, DriveEntry> DriveMap;

  /**
   * Map from the unit name of a tape drive to the catalogue entry of that
   * drive.
   */
  DriveMap m_drives;

621
622
623
624
625
626
  /** 
   * Enters the specified parsed line from /etc/castor/TPCONFIG into the
   * catalogue.
   *
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
627
  void enterTpconfigLine(const utils::TpconfigLine &line) ;
628
629
630
631
632
633
634
635

  /**
   * Checks the semantics of the specified TPCONFIG line against the specified
   * current catalogue entry.
   *
   * @param catalogueEntry The catalogue entry.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
636
  void checkTpconfigLine(const DriveEntry &catalogueEntry, const utils::TpconfigLine &line) ;
637
638
639
640
641
642
643
644
645

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
   * @param catalogueDgn The DGN of the tape drive that has been retrieved from
   * the tape-drive catalogue.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
646
  void checkTpconfigLineDgn(const std::string &catalogueDgn, const utils::TpconfigLine &line) ;
647
648
649
650
651
652
653
654
655

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
   * @param catalogueDevFilename The filename of the device file of the tape
   * drive that has been retrieved from the tape-drive catalogue.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
656
  void checkTpconfigLineDevFilename(const std::string &catalogueDevFilename, const utils::TpconfigLine &line) ;
657
658
659
660
661
662
663
664
665

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
   * @param catalogueDensities The densities supported by the tape drive that
   * have been retrived from the tape-drive catalogue.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
666
  void checkTpconfigLineDensity(const std::list<std::string> &catalogueDensities, const utils::TpconfigLine &line) ;
667
668
669
670
671
672
673
674
675

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
   * @param catalogueInitialState The initial state of the tape drive that
   * has been retrieved from the tape-drive catalogue.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
676
  void checkTpconfigLineInitialState(const DriveState catalogueInitialState, const utils::TpconfigLine &line) ;
677
678
679
680
681

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
682
683
   * @param catalogueLibrarySlot The library slot of the tape drive that has
   * been retrieved from the tape-drive catalogue.
684
685
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
686
  void checkTpconfigLineLibrarySlot(const std::string &catalogueLibrarySlot, const utils::TpconfigLine &line) ;
687
688
689
690
691
692
693
694
695

  /**
   * Throws an exception if the specified catalogue value does not match the
   * specified TPCONFIG line value.
   *
   * @param catalogueDevType The device type of the tape drive that has been
   * retrieved from the tape-drive library.
   * @param line The line parsed from /etc/castor/TPCONFIG.
   */
696
  void checkTpconfigLineDevType(const std::string &catalogueDevType, const utils::TpconfigLine &line) ;
697

698
699
700
701
702
703
704
}; // class DriveCatalogue

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