Skip to content

Commit 9a6161f

Browse files
committed
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 <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 639b088 commit 9a6161f

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

drivers/xen/xenbus/xenbus_dev_frontend.c

+27-20
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,29 @@ static void watch_fired(struct xenbus_watch *watch,
302302
mutex_unlock(&adap->dev_data->reply_mutex);
303303
}
304304

305+
static 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+
305328
static int xenbus_write_transaction(unsigned msg_type,
306329
struct xenbus_file_priv *u)
307330
{
@@ -321,7 +344,7 @@ static int xenbus_write_transaction(unsigned msg_type,
321344
if (trans->handle.id == u->u.msg.tx_id)
322345
break;
323346
if (&trans->list == &u->transactions)
324-
return -ESRCH;
347+
return xenbus_command_reply(u, XS_ERROR, "ENOENT");
325348
}
326349

327350
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)
372395
path = u->u.buffer + sizeof(u->u.msg);
373396
token = memchr(path, 0, u->u.msg.len);
374397
if (token == NULL) {
375-
rc = -EILSEQ;
398+
rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
376399
goto out;
377400
}
378401
token++;
379402
if (memchr(token, 0, u->u.msg.len - (token - path)) == NULL) {
380-
rc = -EILSEQ;
403+
rc = xenbus_command_reply(u, XS_ERROR, "EINVAL");
381404
goto out;
382405
}
383406

@@ -411,23 +434,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
411434
}
412435

413436
/* Success. Synthesize a reply to say all is OK. */
414-
{
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-
}
437+
rc = xenbus_command_reply(u, msg_type, "OK");
431438

432439
out:
433440
return rc;

0 commit comments

Comments
 (0)