Skip to content

Commit 44dd5a6

Browse files
williamli80williamspatrick
authored andcommitted
Add IPMI 2.0 ColdReset command support
* Implement reset by reboot command issued in a shell * Work with related changes in phosphor-host-ipmid repo Resolves openbmc/openbmc#437 Change-Id: I8143b1ee9c0d547ee47e5bd3659a5126b6e5af98 Signed-off-by: Nan Li <[email protected]>
1 parent da7aad0 commit 44dd5a6

File tree

4 files changed

+198
-17
lines changed

4 files changed

+198
-17
lines changed

bmcctl/control_bmc_obj.c

+24
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ static gboolean on_warm_reset(ControlBmc *bmc,
4040
return TRUE;
4141
}
4242

43+
static gboolean on_cold_reset(ControlBmc *bmc,
44+
GDBusMethodInvocation *invocation,
45+
gpointer user_data)
46+
{
47+
GError *err = NULL;
48+
/* Wait a while before reboot, so the caller can be responded.
49+
* Note that g_spawn_command_line_async() cannot parse ';' as
50+
* a command separator. Need to use 'sh -c' to let shell parse it.
51+
*/
52+
gchar *reboot_command = "/bin/sh -c 'sleep 3;reboot'";
53+
54+
g_spawn_command_line_async(reboot_command, &err);
55+
if(err != NULL) {
56+
fprintf(stderr, "coldReset() error: %s\n", err->message);
57+
g_error_free(err);
58+
}
59+
60+
control_bmc_complete_cold_reset(bmc, invocation);
61+
return TRUE;
62+
}
63+
4364
static void on_bus_acquired(GDBusConnection *connection, const gchar *name,
4465
gpointer user_data)
4566
{
@@ -66,6 +87,9 @@ static void on_bus_acquired(GDBusConnection *connection, const gchar *name,
6687
g_signal_connect(control_bmc, "handle-warm-reset",
6788
G_CALLBACK(on_warm_reset), NULL); /* user_data */
6889

90+
g_signal_connect(control_bmc, "handle-cold-reset",
91+
G_CALLBACK(on_cold_reset), NULL); /* user_data */
92+
6993
/* Export the object (@manager takes its own reference to @object) */
7094
g_dbus_object_manager_server_export(manager,
7195
G_DBUS_OBJECT_SKELETON(object));

libopenbmc_intf/openbmc_intf.c

+148-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Generated by gdbus-codegen 2.42.2. DO NOT EDIT.
2+
* Generated by gdbus-codegen 2.40.2. DO NOT EDIT.
33
*
44
* The license of this code is the same as for the source it was derived from.
55
*/
@@ -1233,7 +1233,6 @@ hwmon_skeleton_notify (GObject *object,
12331233
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
12341234
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
12351235
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _hwmon_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
1236-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _hwmon_emit_changed");
12371236
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
12381237
g_source_unref (skeleton->priv->changed_properties_idle_source);
12391238
}
@@ -3104,7 +3103,6 @@ fan_skeleton_notify (GObject *object,
31043103
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
31053104
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
31063105
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _fan_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
3107-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _fan_emit_changed");
31083106
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
31093107
g_source_unref (skeleton->priv->changed_properties_idle_source);
31103108
}
@@ -5240,7 +5238,6 @@ sensor_value_skeleton_notify (GObject *object,
52405238
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
52415239
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
52425240
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _sensor_value_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
5243-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _sensor_value_emit_changed");
52445241
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
52455242
g_source_unref (skeleton->priv->changed_properties_idle_source);
52465243
}
@@ -7058,7 +7055,6 @@ sensor_threshold_skeleton_notify (GObject *object,
70587055
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
70597056
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
70607057
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _sensor_threshold_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
7061-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _sensor_threshold_emit_changed");
70627058
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
70637059
g_source_unref (skeleton->priv->changed_properties_idle_source);
70647060
}
@@ -8245,7 +8241,6 @@ sensor_i2c_skeleton_notify (GObject *object,
82458241
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
82468242
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
82478243
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _sensor_i2c_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
8248-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _sensor_i2c_emit_changed");
82498244
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
82508245
g_source_unref (skeleton->priv->changed_properties_idle_source);
82518246
}
@@ -9462,7 +9457,6 @@ sensor_match_skeleton_notify (GObject *object,
94629457
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
94639458
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
94649459
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _sensor_match_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
9465-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _sensor_match_emit_changed");
94669460
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
94679461
g_source_unref (skeleton->priv->changed_properties_idle_source);
94689462
}
@@ -11969,7 +11963,6 @@ shared_resource_skeleton_notify (GObject *object,
1196911963
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
1197011964
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
1197111965
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _shared_resource_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
11972-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _shared_resource_emit_changed");
1197311966
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
1197411967
g_source_unref (skeleton->priv->changed_properties_idle_source);
1197511968
}
@@ -13475,7 +13468,6 @@ control_skeleton_notify (GObject *object,
1347513468
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
1347613469
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
1347713470
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _control_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
13478-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _control_emit_changed");
1347913471
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
1348013472
g_source_unref (skeleton->priv->changed_properties_idle_source);
1348113473
}
@@ -13605,6 +13597,19 @@ control_skeleton_new (void)
1360513597

1360613598
/* ---- Introspection data for org.openbmc.control.Bmc ---- */
1360713599

13600+
static const _ExtendedGDBusMethodInfo _control_bmc_method_info_cold_reset =
13601+
{
13602+
{
13603+
-1,
13604+
(gchar *) "coldReset",
13605+
NULL,
13606+
NULL,
13607+
NULL
13608+
},
13609+
"handle-cold-reset",
13610+
FALSE
13611+
};
13612+
1360813613
static const _ExtendedGDBusMethodInfo _control_bmc_method_info_warm_reset =
1360913614
{
1361013615
{
@@ -13620,6 +13625,7 @@ static const _ExtendedGDBusMethodInfo _control_bmc_method_info_warm_reset =
1362013625

1362113626
static const _ExtendedGDBusMethodInfo * const _control_bmc_method_info_pointers[] =
1362213627
{
13628+
&_control_bmc_method_info_cold_reset,
1362313629
&_control_bmc_method_info_warm_reset,
1362413630
NULL
1362513631
};
@@ -13678,6 +13684,7 @@ control_bmc_override_properties (GObjectClass *klass, guint property_id_begin)
1367813684
/**
1367913685
* ControlBmcIface:
1368013686
* @parent_iface: The parent interface.
13687+
* @handle_cold_reset: Handler for the #ControlBmc::handle-cold-reset signal.
1368113688
* @handle_warm_reset: Handler for the #ControlBmc::handle-warm-reset signal.
1368213689
*
1368313690
* Virtual table for the D-Bus interface <link linkend="gdbus-interface-org-openbmc-control-Bmc.top_of_page">org.openbmc.control.Bmc</link>.
@@ -13690,6 +13697,28 @@ static void
1369013697
control_bmc_default_init (ControlBmcIface *iface)
1369113698
{
1369213699
/* GObject signals for incoming D-Bus method calls: */
13700+
/**
13701+
* ControlBmc::handle-cold-reset:
13702+
* @object: A #ControlBmc.
13703+
* @invocation: A #GDBusMethodInvocation.
13704+
*
13705+
* Signal emitted when a remote caller is invoking the <link linkend="gdbus-method-org-openbmc-control-Bmc.coldReset">coldReset()</link> D-Bus method.
13706+
*
13707+
* If a signal handler returns %TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call control_bmc_complete_cold_reset() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
13708+
*
13709+
* Returns: %TRUE if the invocation was handled, %FALSE to let other signal handlers run.
13710+
*/
13711+
g_signal_new ("handle-cold-reset",
13712+
G_TYPE_FROM_INTERFACE (iface),
13713+
G_SIGNAL_RUN_LAST,
13714+
G_STRUCT_OFFSET (ControlBmcIface, handle_cold_reset),
13715+
g_signal_accumulator_true_handled,
13716+
NULL,
13717+
g_cclosure_marshal_generic,
13718+
G_TYPE_BOOLEAN,
13719+
1,
13720+
G_TYPE_DBUS_METHOD_INVOCATION);
13721+
1369313722
/**
1369413723
* ControlBmc::handle-warm-reset:
1369513724
* @object: A #ControlBmc.
@@ -13714,6 +13743,98 @@ control_bmc_default_init (ControlBmcIface *iface)
1371413743

1371513744
}
1371613745

13746+
/**
13747+
* control_bmc_call_cold_reset:
13748+
* @proxy: A #ControlBmcProxy.
13749+
* @cancellable: (allow-none): A #GCancellable or %NULL.
13750+
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
13751+
* @user_data: User data to pass to @callback.
13752+
*
13753+
* Asynchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.coldReset">coldReset()</link> D-Bus method on @proxy.
13754+
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
13755+
* You can then call control_bmc_call_cold_reset_finish() to get the result of the operation.
13756+
*
13757+
* See control_bmc_call_cold_reset_sync() for the synchronous, blocking version of this method.
13758+
*/
13759+
void
13760+
control_bmc_call_cold_reset (
13761+
ControlBmc *proxy,
13762+
GCancellable *cancellable,
13763+
GAsyncReadyCallback callback,
13764+
gpointer user_data)
13765+
{
13766+
g_dbus_proxy_call (G_DBUS_PROXY (proxy),
13767+
"coldReset",
13768+
g_variant_new ("()"),
13769+
G_DBUS_CALL_FLAGS_NONE,
13770+
-1,
13771+
cancellable,
13772+
callback,
13773+
user_data);
13774+
}
13775+
13776+
/**
13777+
* control_bmc_call_cold_reset_finish:
13778+
* @proxy: A #ControlBmcProxy.
13779+
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to control_bmc_call_cold_reset().
13780+
* @error: Return location for error or %NULL.
13781+
*
13782+
* Finishes an operation started with control_bmc_call_cold_reset().
13783+
*
13784+
* Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set.
13785+
*/
13786+
gboolean
13787+
control_bmc_call_cold_reset_finish (
13788+
ControlBmc *proxy,
13789+
GAsyncResult *res,
13790+
GError **error)
13791+
{
13792+
GVariant *_ret;
13793+
_ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);
13794+
if (_ret == NULL)
13795+
goto _out;
13796+
g_variant_get (_ret,
13797+
"()");
13798+
g_variant_unref (_ret);
13799+
_out:
13800+
return _ret != NULL;
13801+
}
13802+
13803+
/**
13804+
* control_bmc_call_cold_reset_sync:
13805+
* @proxy: A #ControlBmcProxy.
13806+
* @cancellable: (allow-none): A #GCancellable or %NULL.
13807+
* @error: Return location for error or %NULL.
13808+
*
13809+
* Synchronously invokes the <link linkend="gdbus-method-org-openbmc-control-Bmc.coldReset">coldReset()</link> D-Bus method on @proxy. The calling thread is blocked until a reply is received.
13810+
*
13811+
* See control_bmc_call_cold_reset() for the asynchronous version of this method.
13812+
*
13813+
* Returns: (skip): %TRUE if the call succeded, %FALSE if @error is set.
13814+
*/
13815+
gboolean
13816+
control_bmc_call_cold_reset_sync (
13817+
ControlBmc *proxy,
13818+
GCancellable *cancellable,
13819+
GError **error)
13820+
{
13821+
GVariant *_ret;
13822+
_ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),
13823+
"coldReset",
13824+
g_variant_new ("()"),
13825+
G_DBUS_CALL_FLAGS_NONE,
13826+
-1,
13827+
cancellable,
13828+
error);
13829+
if (_ret == NULL)
13830+
goto _out;
13831+
g_variant_get (_ret,
13832+
"()");
13833+
g_variant_unref (_ret);
13834+
_out:
13835+
return _ret != NULL;
13836+
}
13837+
1371713838
/**
1371813839
* control_bmc_call_warm_reset:
1371913840
* @proxy: A #ControlBmcProxy.
@@ -13806,6 +13927,24 @@ control_bmc_call_warm_reset_sync (
1380613927
return _ret != NULL;
1380713928
}
1380813929

13930+
/**
13931+
* control_bmc_complete_cold_reset:
13932+
* @object: A #ControlBmc.
13933+
* @invocation: (transfer full): A #GDBusMethodInvocation.
13934+
*
13935+
* Helper function used in service implementations to finish handling invocations of the <link linkend="gdbus-method-org-openbmc-control-Bmc.coldReset">coldReset()</link> D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.
13936+
*
13937+
* This method will free @invocation, you cannot use it afterwards.
13938+
*/
13939+
void
13940+
control_bmc_complete_cold_reset (
13941+
ControlBmc *object,
13942+
GDBusMethodInvocation *invocation)
13943+
{
13944+
g_dbus_method_invocation_return_value (invocation,
13945+
g_variant_new ("()"));
13946+
}
13947+
1380913948
/**
1381013949
* control_bmc_complete_warm_reset:
1381113950
* @object: A #ControlBmc.
@@ -15985,7 +16124,6 @@ control_host_skeleton_notify (GObject *object,
1598516124
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
1598616125
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
1598716126
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _control_host_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
15988-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _control_host_emit_changed");
1598916127
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
1599016128
g_source_unref (skeleton->priv->changed_properties_idle_source);
1599116129
}
@@ -17651,7 +17789,6 @@ control_power_skeleton_notify (GObject *object,
1765117789
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
1765217790
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
1765317791
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _control_power_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
17654-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _control_power_emit_changed");
1765517792
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
1765617793
g_source_unref (skeleton->priv->changed_properties_idle_source);
1765717794
}
@@ -20171,7 +20308,6 @@ watchdog_skeleton_notify (GObject *object,
2017120308
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
2017220309
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
2017320310
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _watchdog_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
20174-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _watchdog_emit_changed");
2017520311
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
2017620312
g_source_unref (skeleton->priv->changed_properties_idle_source);
2017720313
}
@@ -23620,7 +23756,6 @@ flash_skeleton_notify (GObject *object,
2362023756
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
2362123757
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
2362223758
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _flash_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
23623-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _flash_emit_changed");
2362423759
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
2362523760
g_source_unref (skeleton->priv->changed_properties_idle_source);
2362623761
}
@@ -25289,7 +25424,6 @@ flash_control_skeleton_notify (GObject *object,
2528925424
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
2529025425
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
2529125426
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _flash_control_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
25292-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _flash_control_emit_changed");
2529325427
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
2529425428
g_source_unref (skeleton->priv->changed_properties_idle_source);
2529525429
}
@@ -27074,7 +27208,6 @@ button_skeleton_notify (GObject *object,
2707427208
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
2707527209
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
2707627210
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _button_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
27077-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _button_emit_changed");
2707827211
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
2707927212
g_source_unref (skeleton->priv->changed_properties_idle_source);
2708027213
}
@@ -28888,7 +29021,6 @@ led_skeleton_notify (GObject *object,
2888829021
skeleton->priv->changed_properties_idle_source = g_idle_source_new ();
2888929022
g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);
2889029023
g_source_set_callback (skeleton->priv->changed_properties_idle_source, _led_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);
28891-
g_source_set_name (skeleton->priv->changed_properties_idle_source, "[generated] _led_emit_changed");
2889229024
g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);
2889329025
g_source_unref (skeleton->priv->changed_properties_idle_source);
2889429026
}

0 commit comments

Comments
 (0)