Skip to content

Commit

Permalink
stored: Status storage should only show configured devices.
Browse files Browse the repository at this point in the history
When listing the volumes in status storage we still list all volumes on
all devices while we should only list the volumes on the device the
status is asked about.

This also addresses a TODO to move the status function from vol_mgr.c to
status.c as is expressed in the comment in the code but never
implemented as it seems.
  • Loading branch information
Marco van Wieringen committed Sep 1, 2016
1 parent 533b223 commit 079f1e1
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 100 deletions.
44 changes: 30 additions & 14 deletions src/stored/protos.h
Expand Up @@ -208,44 +208,61 @@ void _lock_reservations(const char *file = "**Unknown**", int line = 0);
void _unlock_reservations();
void _lock_volumes(const char *file = "**Unknown**", int line = 0);
void _unlock_volumes();
void _lock_read_volumes(const char *file = "**Unknown**", int line = 0);
void _unlock_read_volumes();
void unreserve_device(DCR *dcr);
void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg);
bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
int search_res_for_device(RCTX &rctx);
void release_reserve_messages(JCR *jcr);

#ifdef SD_DEBUG_LOCK
extern int reservations_lock_count;
extern int vol_list_lock_count;
extern int read_vol_list_lock_count;

#ifdef SD_DEBUG_LOCK
#define lock_reservations() \
do { Dmsg3(sd_dbglvl, "lock_reservations at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
reservations_lock_count); \
__FILE__, __LINE__, \
reservations_lock_count); \
_lock_reservations(__FILE__, __LINE__); \
Dmsg0(sd_dbglvl, "lock_reservations: got lock\n"); \
} while (0)
#define unlock_reservations() \
do { Dmsg3(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
reservations_lock_count); \
_unlock_reservations(); } while (0)
__FILE__, __LINE__, \
reservations_lock_count); \
_unlock_reservations(); } while (0)
#define lock_volumes() \
do { Dmsg3(sd_dbglvl, "lock_volumes at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
vol_list_lock_count); \
__FILE__, __LINE__, \
vol_list_lock_count); \
_lock_volumes(__FILE__, __LINE__); \
Dmsg0(sd_dbglvl, "lock_volumes: got lock\n"); \
} while (0)
#define unlock_volumes() \
do { Dmsg3(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
vol_list_lock_count); \
_unlock_volumes(); } while (0)
__FILE__, __LINE__, \
vol_list_lock_count); \
_unlock_volumes(); } while (0)
#define lock_read_volumes() \
do { Dmsg3(sd_dbglvl, "lock_read_volumes at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
read_vol_list_lock_count); \
_lock_read_volumes(__FILE__, __LINE__); \
Dmsg0(sd_dbglvl, "lock_read_volumes: got lock\n"); \
} while (0)
#define unlock_read_volumes() \
do { Dmsg3(sd_dbglvl, "unlock_read_volumes at %s:%d precnt=%d\n", \
__FILE__, __LINE__, \
read_vol_list_lock_count); \
_unlock_read_volumes(); } while (0)
#else
#define lock_reservations() _lock_reservations(__FILE__, __LINE__)
#define unlock_reservations() _unlock_reservations()
#define lock_volumes() _lock_volumes(__FILE__, __LINE__)
#define unlock_volumes() _unlock_volumes()
#define lock_read_volumes() _lock_read_volumes(__FILE__, __LINE__)
#define unlock_read_volumes() _unlock_read_volumes()
#endif

/* sd_backends.c */
Expand Down Expand Up @@ -291,12 +308,11 @@ bool free_volume(DEVICE *dev);
bool is_vol_list_empty();
dlist *dup_vol_list(JCR *jcr);
void free_temp_vol_list(dlist *temp_vol_list);
dlist *get_read_vol_list();
bool volume_unused(DCR *dcr);
void create_volume_lists();
void free_volume_lists();
void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg);
bool is_volume_in_use(DCR *dcr);
extern int vol_list_lock_count;
void add_read_volume(JCR *jcr, const char *VolumeName);
void remove_read_volume(JCR *jcr, const char *VolumeName);

Expand Down
37 changes: 7 additions & 30 deletions src/stored/reserve.c
Expand Up @@ -31,6 +31,13 @@

const int dbglvl = 150;

/* Global static variables */
#ifdef SD_DEBUG_LOCK
int reservations_lock_count = 0;
#else
static int reservations_lock_count = 0;
#endif

static brwlock_t reservation_lock;

/* Forward referenced functions */
Expand Down Expand Up @@ -94,8 +101,6 @@ void term_reservations_lock()
term_vol_list_lock();
}

int reservations_lock_count = 0;

/*
* This applies to a drive and to Volumes
*/
Expand Down Expand Up @@ -1258,34 +1263,6 @@ static void queue_reserve_message(JCR *jcr)
jcr->unlock();
}

/*
* Send any reservation messages queued for this jcr
*/
void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg)
{
int i;
alist *msgs;
char *msg;

jcr->lock();
msgs = jcr->reserve_msgs;
if (!msgs || msgs->size() == 0) {
goto bail_out;
}
for (i=msgs->size()-1; i >= 0; i--) {
msg = (char *)msgs->get(i);
if (msg) {
sendit(" ", 3, arg);
sendit(msg, strlen(msg), arg);
} else {
break;
}
}

bail_out:
jcr->unlock();
}

/*
* Pop and release any reservations messages
*/
Expand Down
97 changes: 94 additions & 3 deletions src/stored/status.c
Expand Up @@ -63,6 +63,7 @@ static void list_running_jobs(STATUS_PKT *sp);
static void list_jobs_waiting_on_reservation(STATUS_PKT *sp);
static void list_status_header(STATUS_PKT *sp);
static void list_devices(JCR *jcr, STATUS_PKT *sp, const char *devicenames);
static void list_volumes(STATUS_PKT *sp, const char *devicenames);

static const char *level_to_str(int level);

Expand Down Expand Up @@ -101,7 +102,7 @@ static void output_status(JCR *jcr, STATUS_PKT *sp, const char *devicenames)
sendit(msg, len, sp);
}

list_volumes(sendit, (void *)sp);
list_volumes(sp, devicenames);
if (!sp->api) {
len = pm_strcpy(msg, "====\n\n");
sendit(msg, len, sp);
Expand Down Expand Up @@ -163,6 +164,9 @@ static bool need_to_list_device(const char *devicenames, const char *devicename)
char *cur, *bp;
POOL_MEM namelist;

Dmsg2(200, "need_to_list_device devicenames %s, devicename %s\n",
devicenames, devicename);

/*
* Make a local copy that we can split on ','
*/
Expand All @@ -185,6 +189,8 @@ static bool need_to_list_device(const char *devicenames, const char *devicename)
cur = bp;
}

Dmsg0(200, "need_to_list_device no listing needed\n");

return false;
}

Expand Down Expand Up @@ -360,6 +366,63 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp, const char *devicenames)
}
}

/*
* List Volumes
*/
static void list_volumes(STATUS_PKT *sp, const char *devicenames)
{
int len;
VOLRES *vol;
dlist *read_vol_list;
POOL_MEM msg(PM_MESSAGE);

foreach_vol(vol) {
DEVICE *dev = vol->dev;

if (dev) {
if (devicenames && !need_to_list_device(devicenames, dev->device)) {
continue;
}

len = Mmsg(msg, "%s on device %s\n", vol->vol_name, dev->print_name());
sendit(msg.c_str(), len, sp);
len = Mmsg(msg, " Reader=%d writers=%d reserves=%d volinuse=%d\n",
dev->can_read() ? 1 : 0, dev->num_writers, dev->num_reserved(),
vol->is_in_use());
sendit(msg.c_str(), len, sp);
} else {
len = Mmsg(msg, "Volume %s no device. volinuse= %d\n",
vol->vol_name, vol->is_in_use());
sendit(msg.c_str(), len, sp);
}
}
endeach_vol(vol);

lock_read_volumes();
read_vol_list = get_read_vol_list();
foreach_dlist(vol, read_vol_list) {
DEVICE *dev = vol->dev;

if (dev) {
if (devicenames && !need_to_list_device(devicenames, dev->device)) {
continue;
}

len = Mmsg(msg, "Read volume: %s on device %s\n", vol->vol_name, dev->print_name());
sendit(msg.c_str(), len, sp);
len = Mmsg(msg, " Reader=%d writers=%d reserves=%d volinuse=%d JobId=%d\n",
dev->can_read() ? 1 : 0, dev->num_writers, dev->num_reserved(),
vol->is_in_use(), vol->get_jobid());
sendit(msg.c_str(), len, sp);
} else {
len = Mmsg(msg, "Volume: %s no device. volinuse= %d\n",
vol->vol_name, vol->is_in_use());
sendit(msg.c_str(), len, sp);
}
}
unlock_read_volumes();
}

static void list_status_header(STATUS_PKT *sp)
{
int len;
Expand Down Expand Up @@ -744,6 +807,34 @@ static void list_running_jobs(STATUS_PKT *sp)
}
}

/*
* Send any reservation messages queued for this jcr
*/
static inline void send_drive_reserve_messages(JCR *jcr, STATUS_PKT *sp)
{
int i;
alist *msgs;
char *msg;

jcr->lock();
msgs = jcr->reserve_msgs;
if (!msgs || msgs->size() == 0) {
goto bail_out;
}
for (i = msgs->size() - 1; i >= 0; i--) {
msg = (char *)msgs->get(i);
if (msg) {
sendit(" ", 3, sp);
sendit(msg, strlen(msg), sp);
} else {
break;
}
}

bail_out:
jcr->unlock();
}

static void list_jobs_waiting_on_reservation(STATUS_PKT *sp)
{
int len;
Expand All @@ -759,7 +850,7 @@ static void list_jobs_waiting_on_reservation(STATUS_PKT *sp)
if (!jcr->reserve_msgs) {
continue;
}
send_drive_reserve_messages(jcr, sendit, sp);
send_drive_reserve_messages(jcr, sp);
}
endeach_jcr(jcr);

Expand Down Expand Up @@ -1037,7 +1128,7 @@ bool dotstatus_cmd(JCR *jcr)
list_devices(jcr, &sp, NULL);
} else if (bstrcasecmp(cmd.c_str(), "volumes")) {
sp.api = true;
list_volumes(sendit, &sp);
list_volumes(&sp, NULL);
} else if (bstrcasecmp(cmd.c_str(), "spooling")) {
sp.api = true;
list_spool_stats(sendit, &sp);
Expand Down

0 comments on commit 079f1e1

Please sign in to comment.