1 /*
2 BAREOS® - Backup Archiving REcovery Open Sourced
3
4 Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
5 Copyright (C) 2011-2012 Planets Communications B.V.
6 Copyright (C) 2013-2021 Bareos GmbH & Co. KG
7
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
11 in the file LICENSE.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
22 */
23 /*
24 * Kern Sibbald, MM
25 */
26 /**
27 * @file
28 * Definitions for using the Device functions in Bareos Tape and File storage
29 * access
30 */
31
32 /**
33 * Some details of how volume and device reservations work
34 *
35 * class VolumeReservationItem:
36 * SetInUse() volume being used on current drive
37 * ClearInUse() no longer being used. Can be re-used or moved.
38 * SetSwapping() set volume being moved to another drive
39 * IsSwapping() volume is being moved to another drive
40 * ClearSwapping() volume normal
41 *
42 * class Device:
43 * SetLoad() set to load volume
44 * needs_load() volume must be loaded (i.e. SetLoad done)
45 * clear_load() load done.
46 * SetUnload() set to unload volume
47 * needs_unload() volume must be unloaded
48 * ClearUnload() volume unloaded
49 *
50 * reservations are temporary until the drive is acquired
51 * IncReserved() increments num of reservations
52 * DecReserved() decrements num of reservations
53 * NumReserved() number of reservations
54 *
55 * class DeviceControlRecord:
56 * SetReserved() sets local reserve flag and calls dev->IncReserved()
57 * ClearReserved() clears local reserve flag and calls dev->DecReserved()
58 * IsReserved() returns local reserved flag
59 * UnreserveDevice() much more complete unreservation
60 */
61
62 #ifndef BAREOS_STORED_DEV_H_
63 #define BAREOS_STORED_DEV_H_ 1
64
65 #include "include/bareos.h"
66 #include "stored/record.h"
67 #include "stored/volume_catalog_info.h"
68
69 #include <vector>
70
71 class dlist;
72
73 namespace storagedaemon {
74
75 struct DeviceStatusInformation;
76
77 class DeviceResource;
78 class DeviceControlRecord;
79 class VolumeReservationItem;
80
81 enum class DeviceMode : int
82 {
83 kUndefined = 0,
84 CREATE_READ_WRITE = 1,
85 OPEN_READ_WRITE,
86 OPEN_READ_ONLY,
87 OPEN_WRITE_ONLY
88 };
89
90 enum class DeviceType : int
91 {
92 B_UNKNOWN_DEV = 0,
93 B_FILE_DEV = 1,
94 B_TAPE_DEV,
95 B_FIFO_DEV,
96 B_VTL_DEV,
97 B_GFAPI_DEV,
98 B_DROPLET_DEV,
99 B_RADOS_DEV,
100 B_CEPHFS_DEV
101 };
102
103 /**
104 * Generic status bits returned from StatusDev()
105 */
106 enum
107 {
108 BMT_TAPE = 0, /**< Is tape device */
109 BMT_EOF = 1, /**< Just read EOF */
110 BMT_BOT = 2, /**< At beginning of tape */
111 BMT_EOT = 3, /**< End of tape reached */
112 BMT_SM = 4, /**< DDS setmark */
113 BMT_EOD = 5, /**< DDS at end of data */
114 BMT_WR_PROT = 6, /**< Tape write protected */
115 BMT_ONLINE = 7, /**< Tape online */
116 BMT_DR_OPEN = 8, /**< Tape door open */
117 BMT_IM_REP_EN = 9 /**< Immediate report enabled */
118 };
119
120 /**
121 * Keep this set to the last entry in the enum.
122 */
123 #define BMT_MAX BMT_IM_REP_EN
124
125 /**
126 * Make sure you have enough bits to store all above bit fields.
127 */
128 #define BMT_BYTES NbytesForBits(BMT_MAX + 1)
129
130 /**
131 * Bits for device capabilities
132 */
133 enum
134 {
135 CAP_EOF = 0, /**< Has MTWEOF */
136 CAP_BSR = 1, /**< Has MTBSR */
137 CAP_BSF = 2, /**< Has MTBSF */
138 CAP_FSR = 3, /**< Has MTFSR */
139 CAP_FSF = 4, /**< Has MTFSF */
140 CAP_EOM = 5, /**< Has MTEOM */
141 CAP_REM = 6, /**< Is removable media */
142 CAP_RACCESS = 7, /**< Is random access device */
143 CAP_AUTOMOUNT = 8, /**< Read device at start to see what is there */
144 CAP_LABEL = 9, /**< Label blank tapes */
145 CAP_ANONVOLS = 10, /**< Mount without knowing volume name */
146 CAP_ALWAYSOPEN = 11, /**< Always keep device open */
147 CAP_ATTACHED_TO_AUTOCHANGER = 12, /**< Device is attached to an AutoChanger */
148 CAP_OFFLINEUNMOUNT = 13, /**< Offline before unmount */
149 CAP_STREAM = 14, /**< Stream device */
150 CAP_BSFATEOM = 15, /**< Backspace file at EOM */
151 CAP_FASTFSF = 16, /**< Fast forward space file */
152 CAP_TWOEOF = 17, /**< Write two eofs for EOM */
153 CAP_CLOSEONPOLL = 18, /**< Close device on polling */
154 CAP_POSITIONBLOCKS = 19, /**< Use block positioning */
155 CAP_MTIOCGET = 20, /**< Basic support for fileno and blkno */
156 CAP_REQMOUNT = 21, /**< Require mount/unmount */
157 CAP_CHECKLABELS = 22, /**< Check for ANSI/IBM labels */
158 CAP_BLOCKCHECKSUM = 23, /**< Create/test block checksum */
159 CAP_IOERRATEOM = 24, /**< IOError at EOM */
160 CAP_IBMLINTAPE = 25, /**< Using IBM lin_tape driver */
161 CAP_ADJWRITESIZE = 26 /**< Adjust write size to min/max */
162 };
163
164 /**
165 * Keep this set to the last entry in the enum.
166 */
167 constexpr int CAP_MAX = CAP_ADJWRITESIZE;
168
169 /**
170 * Make sure you have enough bits to store all above bit fields.
171 */
172 constexpr int CAP_BYTES = NbytesForBits(CAP_MAX + 1);
173
174 /**
175 * Device state bits
176 */
177 enum
178 {
179 ST_LABEL = 0, /**< Label found */
180 ST_ALLOCATED = 1, /**< Dev memory allocated in FactoryCreateDevice() */
181 ST_APPENDREADY = 2, /**< Ready for Bareos append */
182 ST_READREADY = 3, /**< Ready for Bareos read */
183 ST_EOT = 4, /**< At end of tape */
184 ST_WEOT = 5, /**< Got EOT on write */
185 ST_EOF = 6, /**< Read EOF i.e. zero bytes */
186 ST_NEXTVOL = 7, /**< Start writing on next volume */
187 ST_SHORT = 8, /**< Short block read */
188 ST_MOUNTED = 9, /**< The device is mounted to the mount point */
189 ST_MEDIA = 10, /**< Media found in mounted device */
190 ST_OFFLINE = 11, /**< Set offline by operator */
191 ST_PART_SPOOLED = 12, /**< Spooling part */
192 ST_CRYPTOKEY = 13 /**< The device has a crypto key loaded */
193 };
194
195 /**
196 * Keep this set to the last entry in the enum.
197 */
198 #define ST_MAX ST_CRYPTOKEY
199
200 /**
201 * Make sure you have enough bits to store all above bit fields.
202 */
203 #define ST_BYTES NbytesForBits(ST_MAX + 1)
204
205 /*
206 * Device structure definition.
207 *
208 * There is one of these for each physical device. Everything here is "global"
209 * to that device and effects all jobs using the device.
210 */
211
212 /* clang-format off */
213
214 class Device {
215 private:
216 int blocked_{}; /**< Set if we must wait (i.e. change tape) */
217 int count_{}; /**< Mutex use count -- DEBUG only */
218 int num_reserved_{}; /**< Counter of device reservations */
219 slot_number_t slot_{}; /**< Slot loaded in drive or -1 if none */
220 pthread_t pid_{}; /**< Thread that locked -- DEBUG only */
221 bool unload_{false}; /**< Set when Volume must be unloaded */
222 bool load_{false}; /**< Set when Volume must be loaded */
223
224 public:
225 Device() = default;
226 virtual ~Device();
227 Device* volatile swap_dev{}; /**< Swap vol from this device */
228 std::vector<DeviceControlRecord*> attached_dcrs; /**< Attached DeviceControlRecords */
229 pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Access control */
230 pthread_mutex_t spool_mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for updating spool_size */
231 pthread_mutex_t acquire_mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for acquire code */
232 pthread_mutex_t read_acquire_mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for acquire read code */
233 pthread_cond_t wait = PTHREAD_COND_INITIALIZER; /**< Thread wait variable */
234 pthread_cond_t wait_next_vol = PTHREAD_COND_INITIALIZER; /**< Wait for tape to be mounted */
235 pthread_t no_wait_id{}; /**< This thread must not wait */
236 int dev_prev_blocked{}; /**< Previous blocked state */
237 int num_waiting{}; /**< Number of threads waiting */
238 int num_writers{}; /**< Number of writing threads */
239 char capabilities[CAP_BYTES]{}; /**< Capabilities mask */
240 char state[ST_BYTES]{}; /**< State mask */
241 int dev_errno{}; /**< Our own errno */
242 int oflags{}; /**< Read/write flags */
243 DeviceMode open_mode{DeviceMode::kUndefined};
244 DeviceType dev_type{DeviceType::B_UNKNOWN_DEV};
245 bool autoselect{}; /**< Autoselect in autochanger */
246 bool norewindonclose{}; /**< Don't rewind tape drive on close */
247 bool initiated{}; /**< Set when FactoryCreateDevice() called */
248 int label_type{}; /**< Bareos/ANSI/IBM label types */
249 drive_number_t drive{}; /**< Autochanger logical drive number (base 0) */
250 drive_number_t drive_index{}; /**< Autochanger physical drive index (base 0) */
251 POOLMEM* archive_device_string{}; /**< Physical device name */
252 POOLMEM* dev_options{}; /**< Device specific options */
253 POOLMEM* prt_name{}; /**< Name used for display purposes */
254 char* errmsg{}; /**< Nicely edited error message */
255 uint32_t block_num{}; /**< Current block number base 0 */
256 uint32_t LastBlock{}; /**< Last DeviceBlock number written to Volume */
257 uint32_t file{}; /**< Current file number base 0 */
258 uint64_t file_addr{}; /**< Current file read/write address */
259 uint64_t file_size{}; /**< Current file size */
260 uint32_t EndBlock{}; /**< Last block written */
261 uint32_t EndFile{}; /**< Last file written */
262 uint32_t min_block_size{}; /**< Min block size currently set */
263 uint32_t max_block_size{}; /**< Max block size currently set */
264 uint32_t max_concurrent_jobs{}; /**< Maximum simultaneous jobs this drive */
265 uint64_t max_volume_size{}; /**< Max bytes to put on one volume */
266 uint64_t max_file_size{}; /**< Max file size to put in one file on volume */
267 uint64_t volume_capacity{}; /**< Advisory capacity */
268 uint64_t max_spool_size{}; /**< Maximum spool file size */
269 uint64_t spool_size{}; /**< Current spool size for this device */
270 uint32_t max_rewind_wait{}; /**< Max secs to allow for rewind */
271 uint32_t max_open_wait{}; /**< Max secs to allow for open */
272 uint32_t max_open_vols{}; /**< Max simultaneous open volumes */
273
274 utime_t vol_poll_interval{};/**< Interval between polling Vol mount */
275 DeviceResource* device_resource{}; /**< Pointer to Device Resource */
276 VolumeReservationItem* vol{}; /**< Pointer to Volume reservation item */
277 btimer_t* tid{}; /**< Timer id */
278 int fd{-1}; /**< File descriptor */
279
280 VolumeCatalogInfo VolCatInfo; /**< Volume Catalog Information */
281 Volume_Label VolHdr; /**< Actual volume label */
282 char pool_name[MAX_NAME_LENGTH]{}; /**< Pool name */
283 char pool_type[MAX_NAME_LENGTH]{}; /**< Pool type */
284
285 char UnloadVolName[MAX_NAME_LENGTH]{}; /**< Last wrong Volume mounted */
286 bool poll{}; /**< Set to poll Volume */
287 /* Device wait times ***FIXME*** look at durations */
288 int min_wait{};
289 int max_wait{};
290 int max_num_wait{};
291 int wait_sec{};
292 int rem_wait_sec{};
293 int num_wait{};
294
295 btime_t last_timer{}; /**< Used by read/write/seek to get stats (usec) */
296 btime_t last_tick{}; /**< Contains last read/write time (usec) */
297
298 btime_t DevReadTime{};
299 btime_t DevWriteTime{};
300 uint64_t DevWriteBytes{};
301 uint64_t DevReadBytes{};
302
303 /* Methods */
304 btime_t GetTimerCount(); /**< Return the last timer interval (ms) */
305
HasCap(int cap)306 bool HasCap(int cap) const { return BitIsSet(cap, capabilities); }
ClearCap(int cap)307 void ClearCap(int cap) { ClearBit(cap, capabilities); }
SetCap(int cap)308 void SetCap(int cap) { SetBit(cap, capabilities); }
DoChecksum()309 bool DoChecksum() const { return BitIsSet(CAP_BLOCKCHECKSUM, capabilities); }
AttachedToAutochanger()310 bool AttachedToAutochanger() const { return BitIsSet(CAP_ATTACHED_TO_AUTOCHANGER, capabilities); }
RequiresMount()311 bool RequiresMount() const { return BitIsSet(CAP_REQMOUNT, capabilities); }
IsRemovable()312 bool IsRemovable() const { return BitIsSet(CAP_REM, capabilities); }
IsTape()313 bool IsTape() const { return (dev_type == DeviceType::B_TAPE_DEV); }
IsFile()314 bool IsFile() const
315 {
316 return (dev_type == DeviceType::B_FILE_DEV || dev_type == DeviceType::B_GFAPI_DEV ||
317 dev_type == DeviceType::B_DROPLET_DEV || dev_type == DeviceType::B_RADOS_DEV ||
318 dev_type == DeviceType::B_CEPHFS_DEV);
319 }
IsFifo()320 bool IsFifo() const { return dev_type == DeviceType::B_FIFO_DEV; }
IsVtl()321 bool IsVtl() const { return dev_type == DeviceType::B_VTL_DEV; }
IsOpen()322 bool IsOpen() const { return fd >= 0; }
IsOffline()323 bool IsOffline() const { return BitIsSet(ST_OFFLINE, state); }
IsLabeled()324 bool IsLabeled() const { return BitIsSet(ST_LABEL, state); }
IsMounted()325 bool IsMounted() const { return BitIsSet(ST_MOUNTED, state); }
IsUnmountable()326 bool IsUnmountable() const { return ((IsFile() && IsRemovable())); }
NumReserved()327 int NumReserved() const { return num_reserved_; }
is_part_spooled()328 bool is_part_spooled() const { return BitIsSet(ST_PART_SPOOLED, state); }
have_media()329 bool have_media() const { return BitIsSet(ST_MEDIA, state); }
IsShortBlock()330 bool IsShortBlock() const { return BitIsSet(ST_SHORT, state); }
IsBusy()331 bool IsBusy() const
332 {
333 return BitIsSet(ST_READREADY, state) || num_writers || NumReserved();
334 }
AtEof()335 bool AtEof() const { return BitIsSet(ST_EOF, state); }
AtEot()336 bool AtEot() const { return BitIsSet(ST_EOT, state); }
AtWeot()337 bool AtWeot() const { return BitIsSet(ST_WEOT, state); }
CanAppend()338 bool CanAppend() const { return BitIsSet(ST_APPENDREADY, state); }
IsCryptoEnabled()339 bool IsCryptoEnabled() const { return BitIsSet(ST_CRYPTOKEY, state); }
340
341 /**
342 * CanWrite() is meant for checking at the end of a job to see
343 * if we still have a tape (perhaps not if at end of tape
344 * and the job is canceled).
345 */
CanWrite()346 bool CanWrite() const
347 {
348 return IsOpen() && CanAppend() && IsLabeled() && !AtWeot();
349 }
CanRead()350 bool CanRead() const { return BitIsSet(ST_READREADY, state); }
351 bool CanStealLock() const;
352 bool waiting_for_mount() const;
MustUnload()353 bool MustUnload() const { return unload_; }
must_load()354 bool must_load() const { return load_; }
355 const char* strerror() const;
356 const char* archive_name() const;
357 const char* name() const;
358 const char* print_name() const; /**< Name for display purposes */
SetEot()359 void SetEot() { SetBit(ST_EOT, state); }
SetEof()360 void SetEof() { SetBit(ST_EOF, state); }
SetAppend()361 void SetAppend() { SetBit(ST_APPENDREADY, state); }
SetLabeled()362 void SetLabeled() { SetBit(ST_LABEL, state); }
SetRead()363 inline void SetRead() { SetBit(ST_READREADY, state); }
set_offline()364 void set_offline() { SetBit(ST_OFFLINE, state); }
SetMounted()365 void SetMounted() { SetBit(ST_MOUNTED, state); }
set_media()366 void set_media() { SetBit(ST_MEDIA, state); }
SetShortBlock()367 void SetShortBlock() { SetBit(ST_SHORT, state); }
SetCryptoEnabled()368 void SetCryptoEnabled() { SetBit(ST_CRYPTOKEY, state); }
SetPartSpooled(int val)369 void SetPartSpooled(int val)
370 {
371 if (val)
372 SetBit(ST_PART_SPOOLED, state);
373 else
374 ClearBit(ST_PART_SPOOLED, state);
375 }
IsVolumeToUnload()376 bool IsVolumeToUnload() const
377 {
378 return unload_ && strcmp(VolHdr.VolumeName, UnloadVolName) == 0;
379 }
SetLoad()380 void SetLoad() { load_ = true; }
IncReserved()381 void IncReserved() { num_reserved_++; }
DecReserved()382 void DecReserved()
383 {
384 num_reserved_--;
385 ASSERT(num_reserved_ >= 0);
386 }
ClearAppend()387 void ClearAppend() { ClearBit(ST_APPENDREADY, state); }
ClearRead()388 void ClearRead() { ClearBit(ST_READREADY, state); }
ClearLabeled()389 void ClearLabeled() { ClearBit(ST_LABEL, state); }
clear_offline()390 void clear_offline() { ClearBit(ST_OFFLINE, state); }
ClearEot()391 void ClearEot() { ClearBit(ST_EOT, state); }
ClearEof()392 void ClearEof() { ClearBit(ST_EOF, state); }
ClearOpened()393 void ClearOpened() { fd = -1; }
ClearMounted()394 void ClearMounted() { ClearBit(ST_MOUNTED, state); }
clear_media()395 void clear_media() { ClearBit(ST_MEDIA, state); }
ClearShortBlock()396 void ClearShortBlock() { ClearBit(ST_SHORT, state); }
ClearCryptoEnabled()397 void ClearCryptoEnabled() { ClearBit(ST_CRYPTOKEY, state); }
ClearUnload()398 void ClearUnload()
399 {
400 unload_ = false;
401 UnloadVolName[0] = 0;
402 }
clear_load()403 void clear_load() { load_ = false; }
bstrerror(void)404 char* bstrerror(void) { return errmsg; }
print_errmsg()405 char* print_errmsg() { return errmsg; }
GetSlot()406 slot_number_t GetSlot() const { return slot_; }
setVolCatInfo(bool valid)407 void setVolCatInfo(bool valid) { VolCatInfo.is_valid = valid; }
haveVolCatInfo()408 bool haveVolCatInfo() const { return VolCatInfo.is_valid; }
setVolCatName(const char * name)409 void setVolCatName(const char* name)
410 {
411 bstrncpy(VolCatInfo.VolCatName, name, sizeof(VolCatInfo.VolCatName));
412 setVolCatInfo(false);
413 }
getVolCatName()414 char* getVolCatName() { return VolCatInfo.VolCatName; }
415
416 const char* mode_to_str(DeviceMode mode);
417 void SetUnload();
418 void ClearVolhdr();
419 bool close(DeviceControlRecord* dcr);
420 bool open(DeviceControlRecord* dcr, DeviceMode omode);
421 ssize_t read(void* buf, size_t len);
422 ssize_t write(const void* buf, size_t len);
423 bool mount(DeviceControlRecord* dcr, int timeout);
424 bool unmount(DeviceControlRecord* dcr, int timeout);
425 void EditMountCodes(PoolMem& omsg, const char* imsg);
426 bool OfflineOrRewind();
427 bool ScanDirForVolume(DeviceControlRecord* dcr);
428 void SetSlotNumber(slot_number_t slot);
429 void InvalidateSlotNumber();
430
431 void SetBlocksizes(DeviceControlRecord* dcr);
432 void SetLabelBlocksize(DeviceControlRecord* dcr);
433
GetFile()434 uint32_t GetFile() const { return file; }
GetBlockNum()435 uint32_t GetBlockNum() const { return block_num; }
436
437 /*
438 * Tape specific operations.
439 */
offline()440 virtual bool offline() { return true; }
weof(int num)441 virtual bool weof(int num) { return true; }
fsf(int num)442 virtual bool fsf(int num) { return true; }
bsf(int num)443 virtual bool bsf(int num) { return false; }
fsr(int num)444 virtual bool fsr(int num) { return false; }
bsr(int num)445 virtual bool bsr(int num) { return false; }
LoadDev()446 virtual bool LoadDev() { return true; }
LockDoor()447 virtual void LockDoor(){};
UnlockDoor()448 virtual void UnlockDoor(){};
clrerror(int func)449 virtual void clrerror(int func){};
SetOsDeviceParameters(DeviceControlRecord * dcr)450 virtual void SetOsDeviceParameters(DeviceControlRecord* dcr){};
GetOsTapeFile()451 virtual int32_t GetOsTapeFile() { return -1; }
452
453 /*
454 * Generic operations.
455 */
456 virtual void OpenDevice(DeviceControlRecord* dcr, DeviceMode omode);
457 virtual char* StatusDev();
458 virtual bool eod(DeviceControlRecord* dcr);
459 virtual void SetAteof();
460 virtual void SetAteot();
461 virtual bool rewind(DeviceControlRecord* dcr);
462 virtual bool UpdatePos(DeviceControlRecord* dcr);
463 virtual bool Reposition(DeviceControlRecord* dcr,
464 uint32_t rfile,
465 uint32_t rblock);
MountBackend(DeviceControlRecord * dcr,int timeout)466 virtual bool MountBackend(DeviceControlRecord* dcr, int timeout)
467 {
468 return true;
469 }
UnmountBackend(DeviceControlRecord * dcr,int timeout)470 virtual bool UnmountBackend(DeviceControlRecord* dcr, int timeout)
471 {
472 return true;
473 }
DeviceStatus(DeviceStatusInformation * dst)474 virtual bool DeviceStatus(DeviceStatusInformation* dst) { return false; }
475
476 /*
477 * Low level operations
478 */
479 virtual int d_ioctl(int fd, ioctl_req_t request, char* mt_com = NULL) = 0;
480 virtual int d_open(const char* pathname, int flags, int mode) = 0;
481 virtual int d_close(int fd) = 0;
482 virtual ssize_t d_read(int fd, void* buffer, size_t count) = 0;
483 virtual ssize_t d_write(int fd, const void* buffer, size_t count) = 0;
484 virtual boffset_t d_lseek(DeviceControlRecord* dcr,
485 boffset_t offset,
486 int whence) = 0;
487 virtual bool d_truncate(DeviceControlRecord* dcr) = 0;
d_flush(DeviceControlRecord * dcr)488 virtual bool d_flush(DeviceControlRecord* dcr) { return true; };
489
490 /*
491 * Locking and blocking calls
492 */
493 void rLock(bool locked = false);
494 void rUnlock();
495 void Lock();
496 void Unlock();
497 void Lock_acquire();
498 void Unlock_acquire();
499 void Lock_read_acquire();
500 void Unlock_read_acquire();
501 void Lock_VolCatInfo();
502 void Unlock_VolCatInfo();
503 int InitMutex();
504 int InitAcquireMutex();
505 int InitReadAcquireMutex();
506 int init_volcat_mutex();
507 int NextVolTimedwait(const struct timespec* timeout);
508 void dblock(int why);
509 void dunblock(bool locked = false);
510 bool IsDeviceUnmounted();
SetBlocked(int block)511 void SetBlocked(int block) { blocked_ = block; }
512 bool IsBlocked() const;
blocked()513 int blocked() const { return blocked_; }
514 const char* print_blocked() const;
515
516 protected:
517 void set_mode(DeviceMode mode);
518 };
519
520 class SpoolDevice :public Device
521 {
522 public:
523 SpoolDevice() = default;
~SpoolDevice()524 ~SpoolDevice() { close(nullptr); }
525 int d_ioctl(int fd, ioctl_req_t request, char* mt_com = NULL) override {return -1;}
d_open(const char * pathname,int flags,int mode)526 int d_open(const char* pathname, int flags, int mode) override {return -1;}
d_close(int fd)527 int d_close(int fd) override {return -1;}
d_read(int fd,void * buffer,size_t count)528 ssize_t d_read(int fd, void* buffer, size_t count) override { return 0;}
d_write(int fd,const void * buffer,size_t count)529 ssize_t d_write(int fd, const void* buffer, size_t count) override { return 0;}
d_lseek(DeviceControlRecord * dcr,boffset_t offset,int whence)530 boffset_t d_lseek(DeviceControlRecord* dcr,
531 boffset_t offset,
532 int whence) override { return 0;}
d_truncate(DeviceControlRecord * dcr)533 bool d_truncate(DeviceControlRecord* dcr) override {return false;}
534 };
535 /* clang-format on */
536
strerror()537 inline const char* Device::strerror() const { return errmsg; }
archive_name()538 inline const char* Device::archive_name() const
539 {
540 return archive_device_string;
541 }
print_name()542 inline const char* Device::print_name() const { return prt_name; }
543
544 Device* FactoryCreateDevice(JobControlRecord* jcr, DeviceResource* device);
545 bool CanOpenMountedDev(Device* dev);
546 bool LoadDev(Device* dev);
547 int WriteBlock(Device* dev);
548 void AttachJcrToDevice(Device* dev, JobControlRecord* jcr);
549 void DetachJcrFromDevice(Device* dev, JobControlRecord* jcr);
550 JobControlRecord* next_attached_jcr(Device* dev, JobControlRecord* jcr);
551 void InitDeviceWaitTimers(DeviceControlRecord* dcr);
552 void InitJcrDeviceWaitTimers(JobControlRecord* jcr);
553 bool DoubleDevWaitTime(Device* dev);
554
555 /*
556 * Get some definition of function to position to the end of the medium in
557 * MTEOM. System dependent.
558 */
559 #ifndef MTEOM
560 # ifdef MTSEOD
561 # define MTEOM MTSEOD
562 # endif
563 # ifdef MTEOD
564 # undef MTEOM
565 # define MTEOM MTEOD
566 # endif
567 #endif
568
569 } /* namespace storagedaemon */
570
571 #endif // BAREOS_STORED_DEV_H_
572