summaryrefslogtreecommitdiff
path: root/sys/dev/pv
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2022-12-03 10:57:05 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2022-12-03 10:57:05 +0000
commit3a6f9f93b1ec747a4521502040bd0677efd6e05d (patch)
tree549a54668d2471ef56b478a0b3ab016940633f1d /sys/dev/pv
parent3380bd954847958690933abfdcae12707f40d821 (diff)
Modify vmt to use the buffer allocated in pvbus directly instead of
the buffer in the vmt softc when doing RPC for PVBUSIOC_KV{READ|WRITE} ioctl. ok asou
Diffstat (limited to 'sys/dev/pv')
-rw-r--r--sys/dev/pv/vmt.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/sys/dev/pv/vmt.c b/sys/dev/pv/vmt.c
index 6d4d79fdf3b..119076cde82 100644
--- a/sys/dev/pv/vmt.c
+++ b/sys/dev/pv/vmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmt.c,v 1.26 2022/09/08 10:22:06 kn Exp $ */
+/* $OpenBSD: vmt.c,v 1.27 2022/12/03 10:57:04 yasuoka Exp $ */
/*
* Copyright (c) 2007 David Crawshaw <david@zentus.com>
@@ -491,9 +491,12 @@ int
vmt_kvop(void *arg, int op, char *key, char *value, size_t valuelen)
{
struct vmt_softc *sc = arg;
- char *buf = NULL, *ptr;
+ struct vm_rpc rpci;
+ char *buf = NULL;
size_t bufsz;
int error = 0;
+ uint32_t rlen;
+ uint16_t ack;
bufsz = VMT_RPC_BUFLEN;
buf = malloc(bufsz, M_TEMP, M_WAITOK | M_ZERO);
@@ -520,25 +523,52 @@ vmt_kvop(void *arg, int op, char *key, char *value, size_t valuelen)
goto done;
}
- if (vm_rpc_send_rpci_tx(sc, "%s", buf) != 0) {
- DPRINTF("%s: error sending command: %s\n", DEVNAME(sc), buf);
+ if (vm_rpc_open(&rpci, VM_RPC_OPEN_RPCI) != 0) {
+ DPRINTF("%s: rpci channel open failed\n", DEVNAME(sc));
sc->sc_rpc_error = 1;
error = EIO;
goto done;
}
- if (vm_rpci_response_successful(sc) == 0) {
- DPRINTF("%s: host rejected command: %s\n", DEVNAME(sc), buf);
- error = EINVAL;
+ if (vm_rpc_send(&rpci, buf, bufsz) != 0) {
+ DPRINTF("%s: unable to send rpci command\n", DEVNAME(sc));
+ sc->sc_rpc_error = 1;
+ error = EIO;
goto done;
}
- /* skip response that was tested in vm_rpci_response_successful() */
- ptr = sc->sc_rpc_buf + 2;
+ if (vm_rpc_get_length(&rpci, &rlen, &ack) != 0) {
+ DPRINTF("%s: failed to get length of rpci response data\n",
+ DEVNAME(sc));
+ sc->sc_rpc_error = 1;
+ error = EIO;
+ goto done;
+ }
- /* might truncate, copy anyway but return error */
- if (strlcpy(value, ptr, valuelen) >= valuelen)
- error = ENOMEM;
+ if (rlen > 0) {
+ if (rlen + 1 > valuelen) {
+ error = EMSGSIZE;
+ goto done;
+ }
+
+ if (vm_rpc_get_data(&rpci, value, rlen, ack) != 0) {
+ DPRINTF("%s: failed to get rpci response data\n",
+ DEVNAME(sc));
+ sc->sc_rpc_error = 1;
+ error = EIO;
+ goto done;
+ }
+ /* test if response success */
+ if (rlen < 2 || value[0] != '1' || value[1] != ' ') {
+ DPRINTF("%s: host rejected command: %s\n", DEVNAME(sc),
+ buf);
+ error = EINVAL;
+ goto done;
+ }
+ /* skip response that was tested */
+ bcopy(value + 2, value, valuelen - 2);
+ value[rlen - 2] = '\0';
+ }
done:
free(buf, M_TEMP, bufsz);