Commit 33da7361 authored by Tomeu Vizoso's avatar Tomeu Vizoso Committed by Dave Airlie

vtest: Add versioning mechanism to protocol

This commit negotiates a common protocol version with the clients,
allowing for backwards compatibility on both sides.

v2: - Negotiate the version in a new command, so the client can probe
      for its existence and stay compatible with older servers. (Dave
      Airlie)
Tested-by: Jakob Bornecrantz's avatarJakob Bornecrantz <jakob@collabora.com>
Reviewed-by: Jakob Bornecrantz's avatarJakob Bornecrantz <jakob@collabora.com>
Signed-off-by: default avatarTomeu Vizoso <tomeu.vizoso@collabora.com>
Signed-off-by: Jakob Bornecrantz's avatarJakob Bornecrantz <jakob@collabora.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 6cc3162d
......@@ -43,6 +43,7 @@ int vtest_renderer_create_fence(void);
int vtest_poll(void);
int vtest_ping_protocol_version(void);
int vtest_protocol_version(void);
void vtest_destroy_renderer(void);
#endif
......
......@@ -25,6 +25,7 @@
#define VTEST_PROTOCOL
#define VTEST_DEFAULT_SOCKET_NAME "/tmp/.virgl_test"
#define VTEST_PROTOCOL_VERSION 1
/* 32-bit length field */
/* 32-bit cmd field */
......@@ -56,6 +57,8 @@
#define VCMD_PING_PROTOCOL_VERSION 10
#define VCMD_PROTOCOL_VERSION 11
#define VCMD_RES_CREATE_SIZE 10
#define VCMD_RES_CREATE_RES_HANDLE 0
#define VCMD_RES_CREATE_TARGET 1
......@@ -92,4 +95,7 @@
#define VCMD_PING_PROTOCOL_VERSION_SIZE 0
#define VCMD_PROTOCOL_VERSION_SIZE 1
#define VCMD_PROTOCOL_VERSION_VERSION 0
#endif
......@@ -35,6 +35,7 @@
#include "vtest_protocol.h"
#include "util.h"
#include "util/u_debug.h"
#include "util/u_math.h"
static int ctx_id = 1;
static int fence_id = 1;
......@@ -53,6 +54,7 @@ struct virgl_renderer_callbacks vtest_cbs = {
struct vtest_renderer {
int in_fd;
int out_fd;
unsigned protocol_version;
};
struct vtest_renderer renderer;
......@@ -119,6 +121,9 @@ int vtest_create_renderer(int in_fd, int out_fd, uint32_t length)
renderer.in_fd = in_fd;
renderer.out_fd = out_fd;
/* By default we support version 0 unless VCMD_PROTOCOL_VERSION is sent */
renderer.protocol_version = 0;
if (getenv("VTEST_USE_GLX"))
ctx = VIRGL_RENDERER_USE_GLX;
......@@ -175,6 +180,35 @@ int vtest_ping_protocol_version(void)
return 0;
}
int vtest_protocol_version(void)
{
uint32_t hdr_buf[VTEST_HDR_SIZE];
uint32_t version_buf[VCMD_PROTOCOL_VERSION_SIZE];
int ret;
ret = vtest_block_read(renderer.in_fd, &version_buf, sizeof(version_buf));
if (ret != sizeof(version_buf))
return -1;
renderer.protocol_version = MIN2(version_buf[VCMD_PROTOCOL_VERSION_VERSION],
VTEST_PROTOCOL_VERSION);
hdr_buf[VTEST_CMD_LEN] = VCMD_PROTOCOL_VERSION_SIZE;
hdr_buf[VTEST_CMD_ID] = VCMD_PROTOCOL_VERSION;
version_buf[VCMD_PROTOCOL_VERSION_VERSION] = renderer.protocol_version;
ret = vtest_block_write(renderer.out_fd, hdr_buf, sizeof(hdr_buf));
if (ret < 0)
return ret;
ret = vtest_block_write(renderer.out_fd, version_buf, sizeof(version_buf));
if (ret < 0)
return ret;
return 0;
}
void vtest_destroy_renderer(void)
{
virgl_renderer_context_destroy(ctx_id);
......
......@@ -135,6 +135,9 @@ again:
case VCMD_PING_PROTOCOL_VERSION:
ret = vtest_ping_protocol_version();
break;
case VCMD_PROTOCOL_VERSION:
ret = vtest_protocol_version();
break;
default:
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment