diff --git a/scst/include/scst_event.h b/scst/include/scst_event.h index ebcbd80c9..f18b1ea91 100644 --- a/scst/include/scst_event.h +++ b/scst/include/scst_event.h @@ -156,4 +156,9 @@ struct scst_event_stpg_payload { struct scst_event_stpg_descr stpg_descriptors[0]; }; +#define SCST_EVENT_REG_VIRT_DEV 6 +struct scst_event_reg_vdev_payload { + uint8_t device_name[SCST_MAX_NAME+10]; +}; + #endif /* __SCST_EVENT_H */ diff --git a/scst/src/scst_event.c b/scst/src/scst_event.c index 99fd3fd60..f86e5ca4e 100644 --- a/scst/src/scst_event.c +++ b/scst/src/scst_event.c @@ -484,6 +484,45 @@ out: return res; } +/* No locks */ +int scst_event_queue_reg_vdev(const char *dev_name) +{ + int res = 0, event_entry_len; + struct scst_event_entry *event_entry; + struct scst_event *event; + struct scst_event_reg_vdev_payload *payload; + + TRACE_ENTRY(); + + event_entry_len = sizeof(*event_entry) + sizeof(*payload); + event_entry = kzalloc(event_entry_len, GFP_ATOMIC); + if (event_entry == NULL) { + PRINT_ERROR("Unable to allocate event (size %d). Virtual " + "device registration event is lost (device name %s)!", + event_entry_len, dev_name); + res = -ENOMEM; + goto out; + } + + TRACE_MEM("event_entry %p (len %d) allocated", event_entry, + event_entry_len); + + event = &event_entry->event; + + event->payload_len = sizeof(*payload); + payload = (struct scst_event_reg_vdev_payload *)event->payload; + + strlcpy(payload->device_name, dev_name, + sizeof(payload->device_name)); + + scst_event_queue(SCST_EVENT_REG_VIRT_DEV, + SCST_EVENT_SCST_CORE_ISSUER, event_entry); + +out: + TRACE_EXIT_RES(res); + return res; +} + /* scst_event_mutex supposed to be held. Can release/reacquire it inside */ static void scst_release_event_entry(struct scst_event_entry *e) { diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index ac4474cee..f4f942a18 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -1383,6 +1383,7 @@ int scst_register_virtual_device_node(struct scst_dev_type *dev_handler, res = dev->virt_id; + scst_event_queue_reg_vdev(dev_name); PRINT_INFO("Attached to virtual device %s (id %d)", dev_name, res); out: diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index b2226fad8..21061c7a1 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -872,6 +872,7 @@ int scst_event_queue_negative_luns_inquiry(const struct scst_tgt *tgt, const char *initiator_name); int scst_event_queue_ext_blocking_done(struct scst_device *dev, void *data, int len); int scst_event_queue_tm_fn_received(struct scst_mgmt_cmd *mcmd); +int scst_event_queue_reg_vdev(const char *dev_name); typedef void __printf(2, 3) (*scst_show_fn)(void *arg, const char *fmt, ...); void scst_trace_cmds(scst_show_fn show, void *arg); diff --git a/usr/events/events.c b/usr/events/events.c index 5f0151e05..4e1f73425 100644 --- a/usr/events/events.c +++ b/usr/events/events.c @@ -85,6 +85,14 @@ static void usage(void) #endif } +static void handle_reg_vdev_received(struct scst_event_user *event_user) +{ + struct scst_event_reg_vdev_payload *p = (struct scst_event_reg_vdev_payload *)event_user->out_event.payload; + printf("Virtual device %s registration received.\n", p->device_name); + + return; +} + static void handle_tm_received(struct scst_event_user *event_user) { struct scst_event_tm_fn_received_payload *p = (struct scst_event_tm_fn_received_payload *)event_user->out_event.payload; @@ -278,6 +286,8 @@ again_poll: if (res != 0) PRINT_ERROR("SCST_EVENT_NOTIFY_DONE failed: %s " "(res %d)", strerror(errno), res); + } else if (event_user->out_event.event_code == SCST_EVENT_REG_VIRT_DEV) { + handle_reg_vdev_received(event_user); } else if (event_user->out_event.event_code == SCST_EVENT_TM_FN_RECEIVED) handle_tm_received(event_user); else if (event_user->out_event.event_code == SCST_EVENT_TM_FN_RECEIVED) {