mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
vmur: Use libvmcp and remove local vmcp code
Use the new libvmcp.a to send commands to z/VM CP. The error messages remain unchanged. Signed-off-by: Thomas Richter <tmricht@linux.vnet.ibm.com> Reviewed-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.vnet.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
9d55086720
commit
4f00cb6346
@@ -6,7 +6,7 @@ LDLIBS += -lz
|
||||
all: vmur
|
||||
|
||||
libs = $(rootdir)/libvmdump/libvmdump.a \
|
||||
$(rootdir)/libutil/libutil.a
|
||||
$(rootdir)/libvmcp/libvmcp.a $(rootdir)/libutil/libutil.a
|
||||
|
||||
objects = vmur.o
|
||||
|
||||
|
||||
102
vmur/vmur.cpp
102
vmur/vmur.cpp
@@ -32,9 +32,12 @@
|
||||
#include "lib/vmdump.h"
|
||||
#include "lib/zt_common.h"
|
||||
#include "lib/util_libc.h"
|
||||
#include "lib/vmcp.h"
|
||||
|
||||
#include "vmur.h"
|
||||
|
||||
#define CP_PREFIX_LEN 11
|
||||
|
||||
/* Program name */
|
||||
static char *prog_name;
|
||||
|
||||
@@ -244,24 +247,6 @@ fail:
|
||||
ERR_EXIT("Could not initialize signal handler (errno = %i)\n", errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read at most COUNT bytes from FD into memory at location BUF.
|
||||
* Return number of bytes read on success, -1 on error.
|
||||
*/
|
||||
static ssize_t read_buf(int fd, char *buf, ssize_t count)
|
||||
{
|
||||
ssize_t rc, len;
|
||||
|
||||
for (len = 0; len < count; len += rc) {
|
||||
rc = read(fd, &buf[len], count - len);
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
if (rc == 0)
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Strip leading CP header from error message
|
||||
*/
|
||||
@@ -294,64 +279,63 @@ static void cperr_exit(char *cpcmd, int cprc, char *buf)
|
||||
|
||||
static void _cpcmd(char *cpcmd, char **resp, int *rc, int retry, int upper)
|
||||
{
|
||||
int fd, len, cprc, bufsize = VMCP_BUFSIZE;
|
||||
char *buf;
|
||||
struct vmcp_parm cp;
|
||||
char cmd[MAXCMDLEN];
|
||||
int ret;
|
||||
|
||||
strcpy(cmd, cpcmd);
|
||||
if (upper)
|
||||
to_upper(cmd);
|
||||
cp.cpcmd = cmd;
|
||||
cp.do_upper = upper;
|
||||
cp.buffer_size = VMCP_DEFAULT_BUFSZ;
|
||||
|
||||
fd = open(VMCP_DEVICE_NODE, O_RDWR);
|
||||
if (fd == -1)
|
||||
retry:
|
||||
ret = vmcp(&cp);
|
||||
|
||||
switch (ret) {
|
||||
case VMCP_ERR_OPEN:
|
||||
ERR_EXIT("Could not issue CP command: \"%s\"\n"
|
||||
"Ensure that vmcp kernel module is loaded!\n", cmd);
|
||||
|
||||
do {
|
||||
if (ioctl(fd, VMCP_SETBUF, &bufsize) == -1)
|
||||
goto fail;
|
||||
|
||||
if (write(fd, cmd, strlen(cmd)) == -1)
|
||||
goto fail;
|
||||
|
||||
if (ioctl(fd, VMCP_GETCODE, &cprc) == -1)
|
||||
goto fail;
|
||||
|
||||
if (ioctl(fd, VMCP_GETSIZE, &len) == -1)
|
||||
goto fail;
|
||||
|
||||
if (len <= bufsize)
|
||||
break;
|
||||
else if (retry)
|
||||
bufsize = len;
|
||||
else
|
||||
ERR_EXIT("Not enough buffer space (%i/%i) for CP "
|
||||
"command '%s'.\nSorry, please issue command "
|
||||
"on your 3270 console!\n", len, bufsize, cmd);
|
||||
} while (1);
|
||||
|
||||
buf = (char *) malloc(len + 1);
|
||||
if (!buf)
|
||||
ERR_EXIT("Out of memory for CP command '%s'\n", cmd);
|
||||
|
||||
memset(buf, 0, len + 1);
|
||||
if (read_buf(fd, buf, len) == -1)
|
||||
case VMCP_ERR_SETBUF:
|
||||
goto fail;
|
||||
|
||||
case VMCP_ERR_WRITE:
|
||||
goto fail;
|
||||
|
||||
case VMCP_ERR_GETCODE:
|
||||
goto fail;
|
||||
|
||||
case VMCP_ERR_GETSIZE:
|
||||
goto fail;
|
||||
|
||||
case VMCP_ERR_READ:
|
||||
goto fail;
|
||||
|
||||
case VMCP_ERR_TOOSMALL:
|
||||
if (retry) {
|
||||
cp.buffer_size = cp.response_size;
|
||||
free(cp.response);
|
||||
goto retry;
|
||||
}
|
||||
ERR_EXIT("Not enough buffer space (%u/%u) for CP "
|
||||
"command '%s'.\nSorry, please issue command "
|
||||
" on your 3270 console!\n", cp.response_size,
|
||||
cp.buffer_size, cmd);
|
||||
}
|
||||
|
||||
if (rc == NULL) {
|
||||
if (cprc != 0) {
|
||||
if (cp.cprc != 0) {
|
||||
/* caller wants us to handle the error */
|
||||
cperr_exit(cmd, cprc, buf);
|
||||
cperr_exit(cmd, cp.cprc, cp.response);
|
||||
}
|
||||
} else {
|
||||
*rc = cprc;
|
||||
*rc = cp.cprc;
|
||||
}
|
||||
|
||||
if (resp)
|
||||
*resp = buf;
|
||||
*resp = cp.response;
|
||||
else
|
||||
free(buf);
|
||||
close(fd);
|
||||
free(cp.response);
|
||||
return;
|
||||
|
||||
fail:
|
||||
|
||||
@@ -31,14 +31,6 @@ do { \
|
||||
ERR_EXIT(str " can only be specified once.\n"); \
|
||||
} while (0)
|
||||
|
||||
#define VMCP_DEVICE_NODE "/dev/vmcp"
|
||||
#define VMCP_BUFSIZE 0x4000
|
||||
#define VMCP_GETSIZE _IOR(0x10, 3, int)
|
||||
#define VMCP_SETBUF _IOW(0x10, 2, int)
|
||||
#define VMCP_GETCODE _IOR(0x10, 1, int)
|
||||
|
||||
#define CP_PREFIX_LEN 11
|
||||
|
||||
#define VMRDR_DEVICE_NODE "/dev/vmrdr-0.0.000c"
|
||||
#define VMPUN_DEVICE_NODE "/dev/vmpun-0.0.000d"
|
||||
#define VMPRT_DEVICE_NODE "/dev/vmprt-0.0.000e"
|
||||
|
||||
Reference in New Issue
Block a user