Skip to content

Commit

Permalink
runner: Add Media Change
Browse files Browse the repository at this point in the history
This patch series will add media change that is
triggered via targetcli without involving the kernel

Based on patches my Bryant G. Ly.

Signed-off-by: Bryant G. Ly <[email protected]>
Signed-off-by: Mike Christie <[email protected]>
  • Loading branch information
Mike Christie committed Aug 19, 2018
1 parent 4ff8018 commit 531cee0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions file_optical.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ static struct tcmur_handler fbo_handler = {
.subtype = "fbo",
.handle_cmd = fbo_handle_cmd,
.nr_threads = 1,
.medium_change_supp = 1,
};

/* Entry point must be named "handler_init". */
Expand Down
68 changes: 64 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,62 @@ on_check_config(TCMUService1 *interface,
return TRUE;
}

static gboolean
on_change_medium(TCMUService1 *interface,
GDBusMethodInvocation *invocation,
gchar *name,
guint64 size,
gchar *cfgstring,
gpointer user_data)
{
struct tcmulib_context *ctx = user_data;
struct tcmur_handler *rhandler;
struct tcmu_device *dev = NULL;
char *reason = NULL;
int ret = 0;

dev = tcmulib_lookup_dev_by_tcmu_name(ctx, name);
if (!dev) {
ret = ENODEV;
reason = "Device not found.";
goto exit;
}

rhandler = tcmu_get_runner_handler(dev);
if (!rhandler->medium_change_supp) {
ret = EOPNOTSUPP;
reason = "Handler does not support medium changes.";
goto exit;
}

tcmu_block_device(dev);
tcmu_flush_device(dev);

tcmu_set_cfgfs_ctrl_str(dev, "dev_config", cfgstring);
tcmu_update_num_lbas(dev, size);
tcmu_set_dev_size(dev);

ret = tcmu_reopen_dev(dev, false, 0);
if (ret == 0) {
reason = "success";
} else {
reason = strerror(ret);
}

tcmu_dev_set_pending_ua(dev, TCMUR_UA_DEV_MEDIUM_CHANGED);
tcmu_unblock_device(dev);

exit:
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(is)", ret, reason));

return TRUE;
}

static void
dbus_export_handler(struct tcmur_handler *handler, GCallback check_config)
dbus_export_handler(struct tcmulib_context *tcmulib_context,
struct tcmur_handler *handler, GCallback check_config,
GCallback change_medium)
{
GDBusObjectSkeleton *object;
char obj_name[128];
Expand All @@ -205,6 +259,10 @@ dbus_export_handler(struct tcmur_handler *handler, GCallback check_config)
"handle-check-config",
check_config,
handler); /* user_data */
g_signal_connect(interface,
"handle-change-medium",
change_medium,
tcmulib_context);
tcmuservice1_set_config_desc(interface, handler->cfg_desc);
g_dbus_object_manager_server_export(manager, G_DBUS_OBJECT_SKELETON(object));
g_object_unref(object);
Expand All @@ -216,12 +274,14 @@ static void dbus_bus_acquired(GDBusConnection *connection,
{
struct tcmur_handler **handler;

tcmu_dbg("bus %s acquired\n", name);
tcmu_dbg("bus %s acquired %p\n", name, user_data);

manager = g_dbus_object_manager_server_new("/org/kernel/TCMUService1");

darray_foreach(handler, g_runner_handlers) {
dbus_export_handler(*handler, G_CALLBACK(on_check_config));
dbus_export_handler(user_data, *handler,
G_CALLBACK(on_check_config),
G_CALLBACK(on_change_medium));
}

g_dbus_object_manager_server_set_connection(manager, connection);
Expand Down Expand Up @@ -902,7 +962,7 @@ int main(int argc, char **argv)
dbus_bus_acquired,
dbus_name_acquired, // name acquired
dbus_name_lost, // name lost
NULL, // user data
tcmulib_context, // user data
NULL // user date free func
);

Expand Down
7 changes: 7 additions & 0 deletions tcmu-handler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ that the configstring is valid before the device has been created.
<arg type="b" name="is_valid" direction="out"/>
<arg type="s" name="message" direction="out"/>
</method>
<method name="ChangeMedium">
<arg type="s" name="name" direction="in"/>
<arg type="t" name="size" direction="in"/>
<arg type="s" name="configstr" direction="in"/>
<arg type="i" name="ret" direction="out"/>
<arg type="s" name="message" direction="out"/>
</method>
</interface>
<interface name="org.kernel.TCMUService1.HandlerManager1">
<method name="RegisterHandler">
Expand Down
5 changes: 5 additions & 0 deletions tcmu-runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ struct tcmur_handler {

int (*reconfig)(struct tcmu_device *dev, struct tcmulib_cfg_info *cfg);

/*
* True if handler supports medium changes via reopen calls.
*/
bool medium_change_supp;

/* Per-device added/removed callbacks */
int (*open)(struct tcmu_device *dev, bool reopen);
void (*close)(struct tcmu_device *dev);
Expand Down
4 changes: 4 additions & 0 deletions tcmur_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ int tcmu_dev_handle_pending_ua(struct tcmu_device *dev, struct tcmulib_cmd *cmd)
/* Device capacity has changed */
tcmu_set_sense_data(cmd->sense_buf, UNIT_ATTENTION, 0x2A09);
break;
case TCMUR_UA_DEV_MEDIUM_CHANGED:
/* medium changed */
tcmu_set_sense_data(cmd->sense_buf, UNIT_ATTENTION, 0x2800);
break;
default:
tcmu_dev_err(dev, "Unhandled UA %d\n", ua);
goto unlock;
Expand Down
1 change: 1 addition & 0 deletions tcmur_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define TCMUR_DEV_FLAG_STOPPED (1 << 4)

#define TCMUR_UA_DEV_SIZE_CHANGED 0
#define TCMUR_UA_DEV_MEDIUM_CHANGED 1

enum {
TMCUR_DEV_FAILOVER_ALL_ACTIVE,
Expand Down

0 comments on commit 531cee0

Please sign in to comment.