summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-31 04:17:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-31 04:17:04 +0000
commit7e691c813bdf26bf9c51f03ee926818c00cc6e39 (patch)
tree1ecdb0c04700e31585faf09a0a868cf63814fc51 /examples
parentReleasing debian version 1.2-3. (diff)
downloadlibnvme-7e691c813bdf26bf9c51f03ee926818c00cc6e39.tar.xz
libnvme-7e691c813bdf26bf9c51f03ee926818c00cc6e39.zip
Merging upstream version 1.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/meson.build4
-rw-r--r--examples/mi-conf.c61
-rw-r--r--examples/mi-mctp.c6
3 files changed, 50 insertions, 21 deletions
diff --git a/examples/meson.build b/examples/meson.build
index 31d05d7..3139311 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -40,11 +40,11 @@ executable(
include_directories: [incdir, internal_incdir]
)
-if libsystemd_dep.found()
+if libdbus_dep.found()
executable(
'mi-conf',
['mi-conf.c'],
- dependencies: [libnvme_mi_dep, libsystemd_dep],
+ dependencies: [libnvme_mi_dep, libdbus_dep],
include_directories: [incdir, internal_incdir]
)
endif
diff --git a/examples/mi-conf.c b/examples/mi-conf.c
index 90d590e..4fdd405 100644
--- a/examples/mi-conf.c
+++ b/examples/mi-conf.c
@@ -23,7 +23,7 @@
#include <ccan/array_size/array_size.h>
#include <ccan/endian/endian.h>
-#include <systemd/sd-bus.h>
+#include <dbus/dbus.h>
#define MCTP_DBUS_NAME "xyz.openbmc_project.MCTP"
#define MCTP_DBUS_PATH "/xyz/openbmc_project/mctp"
@@ -79,10 +79,11 @@ int find_port(nvme_mi_ep_t ep, uint8_t *portp, uint16_t *mtup)
return found ? 0 : 1;
}
-int set_local_mtu(sd_bus *bus, unsigned int net, uint8_t eid, uint32_t mtu)
+int set_local_mtu(DBusConnection *bus, unsigned int net, uint8_t eid,
+ uint32_t mtu)
{
- sd_bus_error err = SD_BUS_ERROR_NULL;
- sd_bus_message *resp;
+ DBusMessage *msg, *resp;
+ DBusError berr;
char *ep_path;
int rc;
@@ -99,26 +100,50 @@ int set_local_mtu(sd_bus *bus, unsigned int net, uint8_t eid, uint32_t mtu)
*/
mtu += 4;
- rc = sd_bus_call_method(bus, MCTP_DBUS_NAME, ep_path,
- MCTP_DBUS_EP_IFACE, "SetMTU", &err, &resp,
- "u", mtu);
- if (rc < 0) {
- warnx("Failed to set local MTU: %s", strerror(-rc));
- return -1;
+ rc = -1;
+ dbus_error_init(&berr);
+ msg = dbus_message_new_method_call(MCTP_DBUS_NAME, ep_path,
+ MCTP_DBUS_EP_IFACE, "SetMTU");
+ if (!msg) {
+ warnx("Can't create D-Bus message");
+ goto out;
}
- return 0;
+ rc = dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &mtu,
+ DBUS_TYPE_INVALID);
+ if (!rc) {
+ warnx("Can't construct D-Bus message arguments");
+ goto out_free_msg;
+ }
+
+ resp = dbus_connection_send_with_reply_and_block(bus, msg,
+ 2000, &berr);
+ if (!resp) {
+ warnx("Failed to set local MTU: %s (%s)", berr.message,
+ berr.name);
+ } else {
+ dbus_message_unref(resp);
+ rc = 0;
+ }
+
+out_free_msg:
+ dbus_message_unref(msg);
+out:
+ dbus_error_free(&berr);
+ return rc;
}
int main(int argc, char **argv)
{
uint16_t cur_mtu, mtu;
+ DBusConnection *bus;
const char *devstr;
uint8_t eid, port;
nvme_root_t root;
unsigned int net;
nvme_mi_ep_t ep;
- sd_bus *bus;
+ DBusError berr;
int rc;
if (argc != 2) {
@@ -141,10 +166,13 @@ int main(int argc, char **argv)
goto out_free_root;
}
- rc = sd_bus_default_system(&bus);
- if (rc < 0) {
+ dbus_error_init(&berr);
+ bus = dbus_bus_get(DBUS_BUS_SYSTEM, &berr);
+ if (!bus) {
+ warnx("Failed opening D-Bus: %s (%s)\n",
+ berr.message, berr.name);
+ rc = -1;
goto out_close_ep;
- warnx("Failed opening D-Bus: %s\n", strerror(-rc));
}
rc = find_port(ep, &port, &mtu);
@@ -185,8 +213,9 @@ int main(int argc, char **argv)
}
out_close_bus:
- sd_bus_close(bus);
+ dbus_connection_unref(bus);
out_close_ep:
+ dbus_error_free(&berr);
nvme_mi_close(ep);
out_free_root:
nvme_mi_free_root(root);
diff --git a/examples/mi-mctp.c b/examples/mi-mctp.c
index 8d660af..c9a3852 100644
--- a/examples/mi-mctp.c
+++ b/examples/mi-mctp.c
@@ -347,14 +347,14 @@ int do_admin_raw(nvme_mi_ep_t ep, int argc, char **argv)
}
tmp = atoi(argv[1]);
- if (tmp < 0 || tmp > 0xffff) {
+ if (tmp > 0xffff) {
fprintf(stderr, "invalid controller ID\n");
return -1;
}
ctrl_id = tmp & 0xffff;
tmp = atoi(argv[2]);
- if (tmp < 0 || tmp > 0xff) {
+ if (tmp > 0xff) {
fprintf(stderr, "invalid opcode\n");
return -1;
}
@@ -461,7 +461,7 @@ int do_security_info(nvme_mi_ep_t ep, int argc, char **argv)
}
tmp = atoi(argv[1]);
- if (tmp < 0 || tmp > 0xffff) {
+ if (tmp > 0xffff) {
fprintf(stderr, "invalid controller ID\n");
return -1;
}