Skip to content

Commit aa34e07

Browse files
committed
Merge tag 'for-linus-4.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen fixes from David Vrabel: - advertise control feature flags in xenstore - fix x86 build when XEN_PVHVM is disabled * tag 'for-linus-4.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xenbus: check return value of xenbus_scanf() xenbus: prefer list_for_each() x86: xen: move cpu_up functions out of ifdef xenbus: advertise control feature flags
2 parents 0d73175 + c251f15 commit aa34e07

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

arch/x86/xen/enlighten.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,7 @@ static void __init init_hvm_pv_info(void)
18371837

18381838
xen_domain_type = XEN_HVM_DOMAIN;
18391839
}
1840+
#endif
18401841

18411842
static int xen_cpu_up_prepare(unsigned int cpu)
18421843
{
@@ -1887,6 +1888,7 @@ static int xen_cpu_up_online(unsigned int cpu)
18871888
return 0;
18881889
}
18891890

1891+
#ifdef CONFIG_XEN_PVHVM
18901892
#ifdef CONFIG_KEXEC_CORE
18911893
static void xen_hvm_shutdown(void)
18921894
{

drivers/xen/manage.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ static void do_suspend(void)
168168
#endif /* CONFIG_HIBERNATE_CALLBACKS */
169169

170170
struct shutdown_handler {
171-
const char *command;
171+
#define SHUTDOWN_CMD_SIZE 11
172+
const char command[SHUTDOWN_CMD_SIZE];
173+
bool flag;
172174
void (*cb)(void);
173175
};
174176

@@ -206,22 +208,22 @@ static void do_reboot(void)
206208
ctrl_alt_del();
207209
}
208210

211+
static struct shutdown_handler shutdown_handlers[] = {
212+
{ "poweroff", true, do_poweroff },
213+
{ "halt", false, do_poweroff },
214+
{ "reboot", true, do_reboot },
215+
#ifdef CONFIG_HIBERNATE_CALLBACKS
216+
{ "suspend", true, do_suspend },
217+
#endif
218+
};
219+
209220
static void shutdown_handler(struct xenbus_watch *watch,
210221
const char **vec, unsigned int len)
211222
{
212223
char *str;
213224
struct xenbus_transaction xbt;
214225
int err;
215-
static struct shutdown_handler handlers[] = {
216-
{ "poweroff", do_poweroff },
217-
{ "halt", do_poweroff },
218-
{ "reboot", do_reboot },
219-
#ifdef CONFIG_HIBERNATE_CALLBACKS
220-
{ "suspend", do_suspend },
221-
#endif
222-
{NULL, NULL},
223-
};
224-
static struct shutdown_handler *handler;
226+
int idx;
225227

226228
if (shutting_down != SHUTDOWN_INVALID)
227229
return;
@@ -238,13 +240,13 @@ static void shutdown_handler(struct xenbus_watch *watch,
238240
return;
239241
}
240242

241-
for (handler = &handlers[0]; handler->command; handler++) {
242-
if (strcmp(str, handler->command) == 0)
243+
for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
244+
if (strcmp(str, shutdown_handlers[idx].command) == 0)
243245
break;
244246
}
245247

246248
/* Only acknowledge commands which we are prepared to handle. */
247-
if (handler->cb)
249+
if (idx < ARRAY_SIZE(shutdown_handlers))
248250
xenbus_write(xbt, "control", "shutdown", "");
249251

250252
err = xenbus_transaction_end(xbt, 0);
@@ -253,8 +255,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
253255
goto again;
254256
}
255257

256-
if (handler->cb) {
257-
handler->cb();
258+
if (idx < ARRAY_SIZE(shutdown_handlers)) {
259+
shutdown_handlers[idx].cb();
258260
} else {
259261
pr_info("Ignoring shutdown request: %s\n", str);
260262
shutting_down = SHUTDOWN_INVALID;
@@ -310,6 +312,9 @@ static struct notifier_block xen_reboot_nb = {
310312
static int setup_shutdown_watcher(void)
311313
{
312314
int err;
315+
int idx;
316+
#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))
317+
char node[FEATURE_PATH_SIZE];
313318

314319
err = register_xenbus_watch(&shutdown_watch);
315320
if (err) {
@@ -326,6 +331,14 @@ static int setup_shutdown_watcher(void)
326331
}
327332
#endif
328333

334+
for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
335+
if (!shutdown_handlers[idx].flag)
336+
continue;
337+
snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
338+
shutdown_handlers[idx].command);
339+
xenbus_printf(XBT_NIL, "control", node, "%u", 1);
340+
}
341+
329342
return 0;
330343
}
331344

drivers/xen/xenbus/xenbus_dev_frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static int xenbus_write_transaction(unsigned msg_type,
364364

365365
static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
366366
{
367-
struct watch_adapter *watch, *tmp_watch;
367+
struct watch_adapter *watch;
368368
char *path, *token;
369369
int err, rc;
370370
LIST_HEAD(staging_q);
@@ -399,7 +399,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
399399
}
400400
list_add(&watch->list, &u->watches);
401401
} else {
402-
list_for_each_entry_safe(watch, tmp_watch, &u->watches, list) {
402+
list_for_each_entry(watch, &u->watches, list) {
403403
if (!strcmp(watch->token, token) &&
404404
!strcmp(watch->watch.node, path)) {
405405
unregister_xenbus_watch(&watch->watch);

drivers/xen/xenbus/xenbus_probe_frontend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ static int backend_state;
335335
static void xenbus_reset_backend_state_changed(struct xenbus_watch *w,
336336
const char **v, unsigned int l)
337337
{
338-
xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &backend_state);
338+
if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i",
339+
&backend_state) != 1)
340+
backend_state = XenbusStateUnknown;
339341
printk(KERN_DEBUG "XENBUS: backend %s %s\n",
340342
v[XS_WATCH_PATH], xenbus_strstate(backend_state));
341343
wake_up(&backend_state_wq);

0 commit comments

Comments
 (0)