Skip to content

Commit

Permalink
stored: Add device specific status trigger.
Browse files Browse the repository at this point in the history
This adds code that allows you to trigger a device to return specific
device status information analog to the way which was already available
to plugins using the bsdEventDriveStatus and bsdEventVolumeStatus
events.

In essence this is equivalent to the bsdEventDriveStatus which allows a
plugin (for example the scsicrypto-sd plugin to return the crypto status
of an LTO4+ drive.) but then for any device without the need to have a
plugin loaded for the specific device.
  • Loading branch information
mvwieringen authored and pstorz committed Oct 12, 2017
1 parent ba2cafb commit 80dc3be
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
13 changes: 12 additions & 1 deletion src/stored/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,20 @@ struct BLOCKSIZES {
uint32_t min_block_size;
};

class DEVRES; /* Device resource defined in stored_conf.h */
class DEVRES; /* Forward reference Device resource defined in stored_conf.h */
class DCR; /* Forward reference */
class VOLRES; /* Forward reference */

/*
* Device specific status information either returned via DEVICE::device_status()
* method of via bsdEventDriveStatus and bsdEventVolumeStatus plugin events.
*/
typedef struct DevStatTrigger {
DEVRES *device;
POOLMEM *status;
int status_length;
} bsdDevStatTrig;

/*
* Device structure definition.
*
Expand Down Expand Up @@ -504,6 +514,7 @@ class DEVICE: public SMARTALLOC {
virtual bool reposition(DCR *dcr, uint32_t rfile, uint32_t rblock);
virtual bool mount_backend(DCR *dcr, int timeout) { return true; };
virtual bool unmount_backend(DCR *dcr, int timeout) { return true; };
virtual bool device_status(bsdDevStatTrig *dst) { return false; };
boffset_t lseek(DCR *dcr, boffset_t offset, int whence) { return d_lseek(dcr, offset, whence); };
bool truncate(DCR *dcr) { return d_truncate(dcr); };

Expand Down
7 changes: 0 additions & 7 deletions src/stored/sd_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ typedef struct s_sdpluginFuncs {
#define sdplug_func(plugin) ((psdFuncs *)(plugin->pfuncs))
#define sdplug_info(plugin) ((genpInfo *)(plugin->pinfo))

class DEVRES;
typedef struct s_sdbareosDevStatTrigger {
DEVRES *device;
POOLMEM *status;
int status_length;
} bsdDevStatTrig;

#ifdef __cplusplus
}
#endif
Expand Down
70 changes: 47 additions & 23 deletions src/stored/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ static void sendit(const char *msg, int len, STATUS_PKT *sp);
static void sendit(POOL_MEM &msg, int len, STATUS_PKT *sp);
static void sendit(const char *msg, int len, void *arg);

static void trigger_device_status_hook(JCR *jcr,
DEVRES *device,
STATUS_PKT *sp,
bsdEventType eventType);
static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp);
static void send_device_status(DEVICE *dev, STATUS_PKT *sp);
static void list_terminated_jobs(STATUS_PKT *sp);
Expand Down Expand Up @@ -214,6 +210,49 @@ static bool need_to_list_device(const char *devicenames, DEVRES *device)
return true;
}

/*
* Trigger the specific eventtype to get status information from any plugin that
* registered the event to return specific device information.
*/
static void trigger_device_status_hook(JCR *jcr,
DEVRES *device,
STATUS_PKT *sp,
bsdEventType eventType)
{
bsdDevStatTrig dst;

dst.device = device;
dst.status = get_pool_memory(PM_MESSAGE);
dst.status_length = 0;

if (generate_plugin_event(jcr, eventType, &dst) == bRC_OK) {
if (dst.status_length > 0) {
sendit(dst.status, dst.status_length, sp);
}
}
free_pool_memory(dst.status);
}

/*
* Ask the device if it want to log something specific in the status overview.
*/
static void get_device_specific_status(DEVRES *device,
STATUS_PKT *sp)
{
bsdDevStatTrig dst;

dst.device = device;
dst.status = get_pool_memory(PM_MESSAGE);
dst.status_length = 0;

if (device->dev->device_status(&dst)) {
if (dst.status_length > 0) {
sendit(dst.status, dst.status_length, sp);
}
}
free_pool_memory(dst.status);
}

static void list_devices(JCR *jcr, STATUS_PKT *sp, const char *devicenames)
{
int len;
Expand Down Expand Up @@ -300,7 +339,9 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp, const char *devicenames)
sendit(msg, len, sp);
}

get_device_specific_status(device, sp);
trigger_device_status_hook(jcr, device, sp, bsdEventDriveStatus);

send_blocked_status(dev, sp);

if (dev->can_append()) {
Expand Down Expand Up @@ -346,6 +387,8 @@ static void list_devices(JCR *jcr, STATUS_PKT *sp, const char *devicenames)
len = Mmsg(msg, _("\nDevice \"%s\" is not open or does not exist.\n"), device->name());
sendit(msg, len, sp);
}

get_device_specific_status(device, sp);
}

if (!sp->api) {
Expand Down Expand Up @@ -452,25 +495,6 @@ static void list_status_header(STATUS_PKT *sp)
}
}

static void trigger_device_status_hook(JCR *jcr,
DEVRES *device,
STATUS_PKT *sp,
bsdEventType eventType)
{
bsdDevStatTrig dst;

dst.device = device;
dst.status = get_pool_memory(PM_MESSAGE);
dst.status_length = 0;

if (generate_plugin_event(jcr, eventType, &dst) == bRC_OK) {
if (dst.status_length > 0) {
sendit(dst.status, dst.status_length, sp);
}
}
free_pool_memory(dst.status);
}

static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp)
{
int len;
Expand Down

0 comments on commit 80dc3be

Please sign in to comment.