History

Drivers: hv: vmbus: Introduce table of VMBus protocol versions

The technique used to get the next VMBus version seems increasisly clumsy as the number of VMBus versions increases. Performance is not a concern since this is only done once during system boot; it's just that we'll end up with more lines of code than is really needed. As an alternative, introduce a table with the version numbers listed in order (from the most recent to the oldest). vmbus_connect() loops through the versions listed in the table until it gets an accepted connection or gets to the end of the table (invalid version).

Andrea Parri committed 7 years ago

Commit bedc61a1 parent a99d8083 files · +19 −38Browse files

Unified · Split

3 files
  1. drivers/hv/connection.c +18 −32
  2. drivers/hv/vmbus_drv.c +1 −2
  3. include/linux/hyperv.h +0 −4
drivers/hv/connection.c+18−32
@@ -40,29 +40,17 @@ EXPORT_SYMBOL_GPL(vmbus_connection); · 39 unmodified lines
4040 __u32 vmbus_proto_version;
4141 EXPORT_SYMBOL_GPL(vmbus_proto_version);
4242
43−static __u32 vmbus_get_next_version(__u32 current_version)
44−{
45− switch (current_version) {
46− case (VERSION_WIN7):
47− return VERSION_WS2008;
48−
49− case (VERSION_WIN8):
50− return VERSION_WIN7;
51−
52− case (VERSION_WIN8_1):
53− return VERSION_WIN8;
54−
55− case (VERSION_WIN10):
56− return VERSION_WIN8_1;
57−
58− case (VERSION_WIN10_V5):
59− return VERSION_WIN10;
60−
61− case (VERSION_WS2008):
62− default:
63− return VERSION_INVAL;
64− }
65−}
43+/*
44+ * Table of VMBus versions listed from newest to oldest.
45+ */
46+static __u32 vmbus_versions[] = {
47+ VERSION_WIN10_V5,
48+ VERSION_WIN10,
49+ VERSION_WIN8_1,
50+ VERSION_WIN8,
51+ VERSION_WIN7,
52+ VERSION_WS2008
53+};
6654
6755 int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version)
6856 {
@@ -169,8 +157,8 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) · 100 unmodified lines
169157 */
170158 int vmbus_connect(void)
171159 {
172− int ret = 0;
173160 struct vmbus_channel_msginfo *msginfo = NULL;
161+ int i, ret = 0;
174162 __u32 version;
175163
176164 /* Initialize the vmbus connection */
@@ -244,21 +232,19 @@ int vmbus_connect(void) · 67 unmodified lines
244232 * version.
245233 */
246234
247− version = VERSION_CURRENT;
235+ for (i = 0; ; i++) {
236+ if (i == ARRAY_SIZE(vmbus_versions))
237+ goto cleanup;
238+
239+ version = vmbus_versions[i];
248240
249− do {
250241 ret = vmbus_negotiate_version(msginfo, version);
251242 if (ret == -ETIMEDOUT)
252243 goto cleanup;
253244
254245 if (vmbus_connection.conn_state == CONNECTED)
255246 break;
256−
257− version = vmbus_get_next_version(version);
258− } while (version != VERSION_INVAL);
259−
260− if (version == VERSION_INVAL)
261− goto cleanup;
247+ }
262248
263249 vmbus_proto_version = version;
264250 pr_info("Vmbus version:%d.%d\n",
drivers/hv/vmbus_drv.c+1−2
@@ -2220,8 +2220,7 @@ static int vmbus_bus_resume(struct device *dev) · 2219 unmodified lines
22202220 * We only use the 'vmbus_proto_version', which was in use before
22212221 * hibernation, to re-negotiate with the host.
22222222 */
2223− if (vmbus_proto_version == VERSION_INVAL ||
2224− vmbus_proto_version == 0) {
2223+ if (!vmbus_proto_version) {
22252224 pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version);
22262225 return -EINVAL;
22272226 }
include/linux/hyperv.h+0−4
@@ -192,10 +192,6 @@ static inline u32 hv_get_avail_to_write_percent( · 191 unmodified lines
192192 #define VERSION_WIN10 ((4 << 16) | (0))
193193 #define VERSION_WIN10_V5 ((5 << 16) | (0))
194194
195−#define VERSION_INVAL -1
196−
197−#define VERSION_CURRENT VERSION_WIN10_V5
198−
199195 /* Make maximum size of pipe payload of 16K */
200196 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
201197

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t