summaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorJuergen Gross <jgross@suse.com>2016-12-22 02:19:47 -0500
committerJuergen Gross <jgross@suse.com>2016-12-23 14:06:23 -0500
commit9a6161fe73bdd3ae4a1e18421b0b20cb7141f680 (patch)
treeb992ad5f49bc787ca28e278227c55661885efb1b /drivers/xen
parent639b08810d6ad74ded2c5f6e233c4fcb9d147168 (diff)
xen: return xenstore command failures via response instead of rc
When the xenbus driver does some special handling for a Xenstore command any error condition related to the command should be returned via an error response instead of letting the related write operation fail. Otherwise the user land handler might take wrong decisions assuming the connection to Xenstore is broken. While at it try to return the same error values xenstored would return for those cases. Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Juergen Gross <jgross@suse.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/xenbus/xenbus_dev_frontend.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
index a06828124b70..79130b310247 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -302,6 +302,29 @@ static void watch_fired(struct xenbus_watch *watch,
302 mutex_unlock(&adap->dev_data->reply_mutex); 302 mutex_unlock(&adap->dev_data->reply_mutex);
303} 303}
304 304
305static int xenbus_command_reply(struct xenbus_file_priv *u,
306 unsigned int msg_type, const char *reply)
307{
308 struct {
309 struct xsd_sockmsg hdr;
310 const char body[16];
311 } msg;
312 int rc;
313
314 msg.hdr = u->u.msg;
315 msg.hdr.type = msg_type;
316 msg.hdr.len = strlen(reply) + 1;
317 if (msg.hdr.len > sizeof(msg.body))
318 return -E2BIG;
319
320 mutex_lock(&u->reply_mutex);
321 rc = queue_reply(&u->read_buffers, &msg, sizeof(msg.hdr) + msg.hdr.len);
322 wake_up(&u->read_waitq);
323 mutex_unlock(&u->reply_mutex);
324
325 return rc;
326}
327
305static int xenbus_write_transaction(unsigned msg_type, 328static int xenbus_write_transaction(unsigned msg_type,
306 struct xenbus_file_priv *u) 329 struct xenbus_file_priv *u)
307{ 330{
@@ -321,7 +344,7 @@ static int xenbus_write_transaction(unsigned msg_type,
321 if (trans->handle.id == u->u.msg.tx_id) 344 if (trans->handle.id == u->u.msg.tx_id)
322 break; 345 break;
323 if (&trans->list == &u->transactions) 346 if (&trans->list == &u->transactions)
324 return -ESRCH; 347 return xenbus_command_reply(u, XS_ERROR, "ENOENT");
325 } 348 }
326 349
327 reply = xenbus_dev_request_and_reply(&u->u.msg); 350 reply = xenbus_dev_request_and_reply(&u->u.msg);
@@ -372,12 +395,12 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
372 path = u->u.buffer + sizeof(u->u.msg); 395 path = u->u.buffer + sizeof(u->u.msg);
373 token = memchr(path, 0, u->u.msg.len); 396 token = memchr(path, 0, u->u.msg.len);
374 if (token == NULL) { 397 if (token == NULL) {
375 rc = -EILSEQ; 398 rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
376 goto out; 399 goto out;
377 } 400 }
378 token++; 401 token++;
379 if (memchr(token, 0, u->u.msg.len - (token - path)) == NULL) { 402 if (memchr(token, 0, u->u.msg.len - (token - path)) == NULL) {
380 rc = -EILSEQ; 403 rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
381 goto out; 404 goto out;
382 } 405 }
383 406
@@ -411,23 +434,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
411 } 434 }
412 435
413 /* Success. Synthesize a reply to say all is OK. */ 436 /* Success. Synthesize a reply to say all is OK. */
414 { 437 rc = xenbus_command_reply(u, msg_type, "OK");
415 struct {
416 struct xsd_sockmsg hdr;
417 char body[3];
418 } __packed reply = {
419 {
420 .type = msg_type,
421 .len = sizeof(reply.body)
422 },
423 "OK"
424 };
425
426 mutex_lock(&u->reply_mutex);
427 rc = queue_reply(&u->read_buffers, &reply, sizeof(reply));
428 wake_up(&u->read_waitq);
429 mutex_unlock(&u->reply_mutex);
430 }
431 438
432out: 439out:
433 return rc; 440 return rc;