Skip to content

Commit

Permalink
stored: Use new slot_number_t and drive_number_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed May 21, 2016
1 parent 87b270a commit a7584d7
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 122 deletions.
1 change: 1 addition & 0 deletions src/lib/protos.h
Expand Up @@ -219,6 +219,7 @@ void daemon_start();
/* edit.c */
uint64_t str_to_uint64(const char *str);
int64_t str_to_int64(const char *str);
#define str_to_int16(str)((int16_t)str_to_int64(str))
#define str_to_int32(str)((int32_t)str_to_int64(str))
char *edit_uint64_with_commas(uint64_t val, char *buf);
char *edit_uint64_with_suffix(uint64_t val, char *buf);
Expand Down
126 changes: 64 additions & 62 deletions src/stored/autochanger.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/stored/btape.c
Expand Up @@ -1471,7 +1471,8 @@ static int append_test()
static int autochanger_test()
{
POOLMEM *results, *changer;
int slot, status, loaded;
slot_number_t slot, loaded;
int status;
int timeout = dcr->device->max_changer_wait;
int sleep_time = 0;

Expand Down
10 changes: 7 additions & 3 deletions src/stored/dev.c
Expand Up @@ -858,16 +858,20 @@ bool DEVICE::offline_or_rewind()
}
}

void DEVICE::set_slot(int32_t slot)
void DEVICE::set_slot(slot_number_t slot)
{
m_slot = slot;
if (vol) vol->clear_slot();
if (vol) {
vol->clear_slot();
}
}

void DEVICE::clear_slot()
{
m_slot = -1;
if (vol) vol->set_slot(-1);
if (vol) {
vol->set_slot(-1);
}
}

/*
Expand Down
10 changes: 5 additions & 5 deletions src/stored/dev.h
Expand Up @@ -267,7 +267,7 @@ class DEVICE: public SMARTALLOC {
int m_blocked; /* Set if we must wait (i.e. change tape) */
int m_count; /* Mutex use count -- DEBUG only */
int m_num_reserved; /* Counter of device reservations */
int32_t m_slot; /* Slot loaded in drive or -1 if none */
slot_number_t m_slot; /* Slot loaded in drive or -1 if none */
pthread_t m_pid; /* Thread that locked -- DEBUG only */
bool m_unload; /* Set when Volume must be unloaded */
bool m_load; /* Set when Volume must be loaded */
Expand Down Expand Up @@ -297,8 +297,8 @@ class DEVICE: public SMARTALLOC {
bool norewindonclose; /* Don't rewind tape drive on close */
bool initiated; /* Set when init_dev() called */
int label_type; /* Bareos/ANSI/IBM label types */
uint32_t drive; /* Autochanger logical drive number (base 0) */
uint32_t drive_index; /* Autochanger physical drive index (base 0) */
drive_number_t drive; /* Autochanger logical drive number (base 0) */
drive_number_t drive_index; /* Autochanger physical drive index (base 0) */
POOLMEM *dev_name; /* Physical device name */
POOLMEM *dev_options; /* Device specific options */
POOLMEM *prt_name; /* Name used for display purposes */
Expand Down Expand Up @@ -443,7 +443,7 @@ class DEVICE: public SMARTALLOC {
void clear_load() { m_load = false; };
char *bstrerror(void) { return errmsg; };
char *print_errmsg() { return errmsg; };
int32_t get_slot() const { return m_slot; };
slot_number_t get_slot() const { return m_slot; };
void setVolCatInfo(bool valid) { VolCatInfo.is_valid = valid; };
bool haveVolCatInfo() const { return VolCatInfo.is_valid; };
void setVolCatName(const char *name) {
Expand All @@ -465,7 +465,7 @@ class DEVICE: public SMARTALLOC {
void edit_mount_codes(POOL_MEM &omsg, const char *imsg);
bool offline_or_rewind();
bool scan_dir_for_volume(DCR *dcr);
void set_slot(int32_t slot);
void set_slot(slot_number_t slot);
void clear_slot();

void set_blocksizes(DCR* dcr);
Expand Down
81 changes: 41 additions & 40 deletions src/stored/dir_cmd.c
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2001-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
Copyright (C) 2013-2015 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -59,24 +59,24 @@ static char cancelcmd[] =
"cancel Job=%127s";
static char relabelcmd[] =
"relabel %127s OldName=%127s NewName=%127s PoolName=%127s "
"MediaType=%127s Slot=%d drive=%d MinBlocksize=%d MaxBlocksize=%d";
"MediaType=%127s Slot=%hd drive=%hd MinBlocksize=%d MaxBlocksize=%d";
static char labelcmd[] =
"label %127s VolumeName=%127s PoolName=%127s "
"MediaType=%127s Slot=%d drive=%d MinBlocksize=%d MaxBlocksize=%d";
"MediaType=%127s Slot=%hd drive=%hd MinBlocksize=%d MaxBlocksize=%d";
static char mountslotcmd[] =
"mount %127s drive=%d slot=%d";
"mount %127s drive=%hd slot=%hd";
static char mountcmd[] =
"mount %127s drive=%d";
"mount %127s drive=%hd";
static char unmountcmd[] =
"unmount %127s drive=%d";
"unmount %127s drive=%hd";
#if 0
static char actionopcmd[] =
"action_on_purge %127s vol=%127s action=%d";
#endif
static char releasecmd[] =
"release %127s drive=%d";
"release %127s drive=%hd";
static char readlabelcmd[] =
"readlabel %127s Slot=%d drive=%d";
"readlabel %127s Slot=%hd drive=%hd";
static char replicatecmd[] =
"replicate Job=%127s address=%s port=%d ssl=%d Authorization=%100s";
static char passiveclientcmd[] =
Expand Down Expand Up @@ -148,12 +148,13 @@ static bool setbandwidth_cmd(JCR *jcr);
static bool setdebug_cmd(JCR *jcr);
static bool unmount_cmd(JCR *jcr);

static DCR *find_device(JCR *jcr, POOL_MEM &dev_name, int drive, BLOCKSIZES *blocksizes);
static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot);
static DCR *find_device(JCR *jcr, POOL_MEM &dev_name,
drive_number_t drive, BLOCKSIZES *blocksizes);
static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, slot_number_t slot);
static void label_volume_if_ok(DCR *dcr, char *oldname,
char *newname, char *poolname,
int Slot, bool relabel);
static bool try_autoload_device(JCR *jcr, DCR *dcr, int slot, const char *VolName);
slot_number_t Slot, bool relabel);
static bool try_autoload_device(JCR *jcr, DCR *dcr, slot_number_t slot, const char *VolName);
static void send_dir_busy_message(BSOCK *dir, DEVICE *dev);

struct s_cmds {
Expand Down Expand Up @@ -587,8 +588,8 @@ static bool do_label(JCR *jcr, bool relabel)
DEVICE *dev;
BLOCKSIZES blocksizes;
bool ok = false;
int32_t slot, drive;
//, max_block_size, min_block_size;
slot_number_t slot;
drive_number_t drive;

/*
* Determine the length of the temporary buffers.
Expand Down Expand Up @@ -691,7 +692,7 @@ static bool relabel_cmd(JCR *jcr)
*/
static void label_volume_if_ok(DCR *dcr, char *oldname,
char *newname, char *poolname,
int slot, bool relabel)
slot_number_t slot, bool relabel)
{
BSOCK *dir = dcr->jcr->dir_bsock;
bsteal_lock_t hold;
Expand Down Expand Up @@ -820,7 +821,7 @@ static bool read_label(DCR *dcr)
/*
* Searches for device by name, and if found, creates a dcr and returns it.
*/
static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *blocksizes)
static DCR *find_device(JCR *jcr, POOL_MEM &devname, drive_number_t drive, BLOCKSIZES *blocksizes)
{
DEVRES *device;
AUTOCHANGERRES *changer;
Expand Down Expand Up @@ -871,15 +872,15 @@ static DCR *find_device(JCR *jcr, POOL_MEM &devname, int drive, BLOCKSIZES *bloc
}
if (!device->dev->autoselect) {
Dmsg1(100, "Device %s not autoselect skipped.\n", devname.c_str());
continue; /* device is not available */
continue; /* device is not available */
}
if (drive < 0 || drive == (int)device->dev->drive) {
if (drive < 0 || drive == device->dev->drive) {
Dmsg1(20, "Found changer device %s\n", device->name());
found = true;
break;
}
Dmsg3(100, "Device %s drive wrong: want=%d got=%d skipping\n",
devname.c_str(), drive, (int)device->dev->drive);
Dmsg3(100, "Device %s drive wrong: want=%hd got=%hd skipping\n",
devname.c_str(), drive, device->dev->drive);
}
break; /* we found it but could not open a device */
}
Expand All @@ -905,23 +906,23 @@ static bool mount_cmd(JCR *jcr)
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
DCR *dcr;
int32_t drive;
int32_t slot = 0;
drive_number_t drive;
slot_number_t slot = 0;
bool ok;

ok = sscanf(dir->msg, mountslotcmd, devname.c_str(), &drive, &slot) == 3;
if (!ok) {
ok = sscanf(dir->msg, mountcmd, devname.c_str(), &drive) == 2;
}

Dmsg3(100, "ok=%d drive=%d slot=%d\n", ok, drive, slot);
Dmsg3(100, "ok=%d drive=%hd slot=%hd\n", ok, drive, slot);
if (ok) {
dcr = find_device(jcr, devname, drive, NULL);
if (dcr) {
dev = dcr->dev;
dev->Lock(); /* Use P to avoid indefinite block */
Dmsg2(100, "mount cmd blocked=%d must_unload=%d\n", dev->blocked(),
dev->must_unload());
Dmsg2(100, "mount cmd blocked=%d must_unload=%d\n",
dev->blocked(), dev->must_unload());
switch (dev->blocked()) { /* device blocked? */
case BST_WAITING_FOR_SYSOP:
/* Someone is waiting, wake him */
Expand All @@ -937,7 +938,7 @@ static bool mount_cmd(JCR *jcr)
/* In both of these two cases, we (the user) unmounted the Volume */
case BST_UNMOUNTED_WAITING_FOR_SYSOP:
case BST_UNMOUNTED:
Dmsg2(100, "Unmounted changer=%d slot=%d\n", dev->is_autochanger(), slot);
Dmsg2(100, "Unmounted changer=%d slot=%hd\n", dev->is_autochanger(), slot);
if (dev->is_autochanger() && slot > 0) {
try_autoload_device(jcr, dcr, slot, "");
}
Expand Down Expand Up @@ -981,7 +982,7 @@ static bool mount_cmd(JCR *jcr)
break;

case BST_NOT_BLOCKED:
Dmsg2(100, "Not blocked changer=%d slot=%d\n", dev->is_autochanger(), slot);
Dmsg2(100, "Not blocked changer=%d slot=%hd\n", dev->is_autochanger(), slot);
if (dev->is_autochanger() && slot > 0) {
try_autoload_device(jcr, dcr, slot, "");
}
Expand Down Expand Up @@ -1051,7 +1052,7 @@ static bool unmount_cmd(JCR *jcr)
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
DCR *dcr;
int32_t drive;
drive_number_t drive;

if (sscanf(dir->msg, unmountcmd, devname.c_str(), &drive) == 2) {
dcr = find_device(jcr, devname, drive, NULL);
Expand Down Expand Up @@ -1181,7 +1182,7 @@ static bool release_cmd(JCR *jcr)
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
DCR *dcr;
int32_t drive;
drive_number_t drive;

if (sscanf(dir->msg, releasecmd, devname.c_str(), &drive) == 2) {
dcr = find_device(jcr, devname, drive, NULL);
Expand Down Expand Up @@ -1306,7 +1307,7 @@ static bool bootstrap_cmd(JCR *jcr)
*/
static bool changer_cmd(JCR *jcr)
{
int src_slot, dst_slot;
slot_number_t src_slot, dst_slot;
POOL_MEM devname;
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
Expand All @@ -1332,7 +1333,7 @@ static bool changer_cmd(JCR *jcr)
} else if (sscanf(dir->msg, "autochanger drives %127s", devname.c_str()) == 1) {
cmd = "drives";
safe_cmd = ok = true;
} else if (sscanf(dir->msg, "autochanger transfer %127s %d %d",
} else if (sscanf(dir->msg, "autochanger transfer %127s %hd %hd",
devname.c_str(), &src_slot, &dst_slot) == 3) {
cmd = "transfer";
safe_cmd = ok = true;
Expand Down Expand Up @@ -1383,24 +1384,24 @@ static bool readlabel_cmd(JCR *jcr)
BSOCK *dir = jcr->dir_bsock;
DEVICE *dev;
DCR *dcr;
int32_t Slot, drive;
slot_number_t slot;
drive_number_t drive;

if (sscanf(dir->msg, readlabelcmd, devname.c_str(),
&Slot, &drive) == 3) {
if (sscanf(dir->msg, readlabelcmd, devname.c_str(), &slot, &drive) == 3) {
dcr = find_device(jcr, devname, drive, NULL);
if (dcr) {
dev = dcr->dev;
dev->Lock(); /* Use P to avoid indefinite block */
if (!dev->is_open()) {
read_volume_label(jcr, dcr, dev, Slot);
read_volume_label(jcr, dcr, dev, slot);
dev->close(dcr);
/* Under certain "safe" conditions, we can steal the lock */
} else if (dev->can_steal_lock()) {
read_volume_label(jcr, dcr, dev, Slot);
read_volume_label(jcr, dcr, dev, slot);
} else if (dev->is_busy() || dev->is_blocked()) {
send_dir_busy_message(dir, dev);
} else { /* device not being used */
read_volume_label(jcr, dcr, dev, Slot);
read_volume_label(jcr, dcr, dev, slot);
}
dev->Unlock();
free_dcr(dcr);
Expand All @@ -1420,7 +1421,7 @@ static bool readlabel_cmd(JCR *jcr)
*
* Enter with the mutex set
*/
static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot)
static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, slot_number_t Slot)
{
BSOCK *dir = jcr->dir_bsock;
bsteal_lock_t hold;
Expand All @@ -1436,7 +1437,7 @@ static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot)
switch (read_dev_volume_label(dcr)) {
case VOL_OK:
/* DO NOT add quotes around the Volume name. It is scanned in the DIR */
dir->fsend(_("3001 Volume=%s Slot=%d\n"), dev->VolHdr.VolumeName, Slot);
dir->fsend(_("3001 Volume=%s Slot=%hd\n"), dev->VolHdr.VolumeName, Slot);
Dmsg1(100, "Volume: %s\n", dev->VolHdr.VolumeName);
break;
default:
Expand All @@ -1449,7 +1450,7 @@ static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot)
return;
}

static bool try_autoload_device(JCR *jcr, DCR *dcr, int slot, const char *VolName)
static bool try_autoload_device(JCR *jcr, DCR *dcr, slot_number_t slot, const char *VolName)
{
BSOCK *dir = jcr->dir_bsock;

Expand Down
7 changes: 4 additions & 3 deletions src/stored/protos.h
Expand Up @@ -50,10 +50,11 @@ bool authenticate_with_filedaemon(JCR *jcr);
bool init_autochangers();
int autoload_device(DCR *dcr, int writing, BSOCK *dir);
bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
bool autochanger_transfer_cmd(DCR *dcr, BSOCK *dir, int src_slot, int dst_slot);
bool unload_autochanger(DCR *dcr, int loaded);
bool autochanger_transfer_cmd(DCR *dcr, BSOCK *dir,
slot_number_t src_slot, slot_number_t dst_slot);
bool unload_autochanger(DCR *dcr, slot_number_t loaded);
bool unload_dev(DCR *dcr, DEVICE *dev);
int get_autochanger_loaded_slot(DCR *dcr);
slot_number_t get_autochanger_loaded_slot(DCR *dcr);

/* block.c */
void dump_block(DEV_BLOCK *b, const char *msg);
Expand Down
4 changes: 2 additions & 2 deletions src/stored/status.c
Expand Up @@ -533,11 +533,11 @@ static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp)
*/
if (dev->is_autochanger()) {
if (dev->get_slot() > 0) {
len = Mmsg(msg, _(" Slot %d %s loaded in drive %d.\n"),
len = Mmsg(msg, _(" Slot %hd %s loaded in drive %hd.\n"),
dev->get_slot(), dev->is_open() ? "is" : "was last", dev->drive);
sendit(msg, len, sp);
} else if (dev->get_slot() <= 0) {
len = Mmsg(msg, _(" Drive %d is not loaded.\n"), dev->drive);
len = Mmsg(msg, _(" Drive %hd is not loaded.\n"), dev->drive);
sendit(msg, len, sp);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/stored/stored_conf.h
Expand Up @@ -134,8 +134,8 @@ class DEVRES : public BRSRES {
bool drive_crypto_enabled; /* Enable hardware crypto */
bool query_crypto_status; /* Query device for crypto status */
bool collectstats; /* Set if statistics should be collected */
uint32_t drive; /* Autochanger logical drive number */
uint32_t drive_index; /* Autochanger physical drive index */
drive_number_t drive; /* Autochanger logical drive number */
drive_number_t drive_index; /* Autochanger physical drive index */
char cap_bits[CAP_BYTES]; /* Capabilities of this device */
utime_t max_changer_wait; /* Changer timeout */
utime_t max_rewind_wait; /* Maximum secs to wait for rewind */
Expand Down
3 changes: 2 additions & 1 deletion src/stored/vol_mgr.c
Expand Up @@ -529,7 +529,8 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName)
* Caller wants to switch Volume to another device
*/
if (!vol->dev->is_busy() && !vol->is_swapping()) {
int32_t slot;
slot_number_t slot;

Dmsg3(dbglvl, "==== Swap vol=%s from dev=%s to %s\n",
VolumeName, vol->dev->print_name(), dev->print_name());
free_volume(dev); /* free any volume attached to our drive */
Expand Down
6 changes: 3 additions & 3 deletions src/stored/vol_mgr.h
Expand Up @@ -53,7 +53,7 @@ class VOLRES {
bool m_swapping; /* set when swapping to another drive */
bool m_in_use; /* set when volume reserved or in use */
bool m_reading; /* set when reading */
int32_t m_slot; /* slot of swapping volume */
slot_number_t m_slot; /* slot of swapping volume */
uint32_t m_JobId; /* JobId for read volumes */
volatile int32_t m_use_count; /* Use count */
pthread_mutex_t m_mutex; /* Vol muntex */
Expand All @@ -79,9 +79,9 @@ class VOLRES {
bool is_in_use() const { return m_in_use; };
void set_in_use() { m_in_use = true; };
void clear_in_use() { m_in_use = false; };
void set_slot(int32_t slot) { m_slot = slot; };
void set_slot(slot_number_t slot) { m_slot = slot; };
void clear_slot() { m_slot = -1; };
int32_t get_slot() const { return m_slot; };
slot_number_t get_slot() const { return m_slot; };
uint32_t get_jobid() const { return m_JobId; };
void set_jobid(uint32_t JobId) { m_JobId = JobId; };
};
Expand Down

0 comments on commit a7584d7

Please sign in to comment.