aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>2010-08-04 17:49:24 -0400
committerJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>2010-08-04 17:49:24 -0400
commit7cc88fdcff3cc7f0d5d2384ffd7f6d4ce9a745f1 (patch)
treeaec5432786f7cb1d5042dbb97a1995109a1ce3e3 /drivers/xen
parentca50a5f39041497253c6362f2ba4da1b56d3e6cb (diff)
parent6280f190da4dd083f14f704be6b3314311a7eacb (diff)
Merge branch 'xen/xenbus' into upstream/xen
* xen/xenbus: implement O_NONBLOCK for /proc/xen/xenbus xenbus: do not hold transaction_mutex when returning to userspace
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/xenbus/xenbus_xs.c57
-rw-r--r--drivers/xen/xenfs/xenbus.c3
2 files changed, 50 insertions, 10 deletions
diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
index 7b547f53f65e..5534690075af 100644
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -76,6 +76,14 @@ struct xs_handle {
76 /* 76 /*
77 * Mutex ordering: transaction_mutex -> watch_mutex -> request_mutex. 77 * Mutex ordering: transaction_mutex -> watch_mutex -> request_mutex.
78 * response_mutex is never taken simultaneously with the other three. 78 * response_mutex is never taken simultaneously with the other three.
79 *
80 * transaction_mutex must be held before incrementing
81 * transaction_count. The mutex is held when a suspend is in
82 * progress to prevent new transactions starting.
83 *
84 * When decrementing transaction_count to zero the wait queue
85 * should be woken up, the suspend code waits for count to
86 * reach zero.
79 */ 87 */
80 88
81 /* One request at a time. */ 89 /* One request at a time. */
@@ -85,7 +93,9 @@ struct xs_handle {
85 struct mutex response_mutex; 93 struct mutex response_mutex;
86 94
87 /* Protect transactions against save/restore. */ 95 /* Protect transactions against save/restore. */
88 struct rw_semaphore transaction_mutex; 96 struct mutex transaction_mutex;
97 atomic_t transaction_count;
98 wait_queue_head_t transaction_wq;
89 99
90 /* Protect watch (de)register against save/restore. */ 100 /* Protect watch (de)register against save/restore. */
91 struct rw_semaphore watch_mutex; 101 struct rw_semaphore watch_mutex;
@@ -157,6 +167,31 @@ static void *read_reply(enum xsd_sockmsg_type *type, unsigned int *len)
157 return body; 167 return body;
158} 168}
159 169
170static void transaction_start(void)
171{
172 mutex_lock(&xs_state.transaction_mutex);
173 atomic_inc(&xs_state.transaction_count);
174 mutex_unlock(&xs_state.transaction_mutex);
175}
176
177static void transaction_end(void)
178{
179 if (atomic_dec_and_test(&xs_state.transaction_count))
180 wake_up(&xs_state.transaction_wq);
181}
182
183static void transaction_suspend(void)
184{
185 mutex_lock(&xs_state.transaction_mutex);
186 wait_event(xs_state.transaction_wq,
187 atomic_read(&xs_state.transaction_count) == 0);
188}
189
190static void transaction_resume(void)
191{
192 mutex_unlock(&xs_state.transaction_mutex);
193}
194
160void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg) 195void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
161{ 196{
162 void *ret; 197 void *ret;
@@ -164,7 +199,7 @@ void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
164 int err; 199 int err;
165 200
166 if (req_msg.type == XS_TRANSACTION_START) 201 if (req_msg.type == XS_TRANSACTION_START)
167 down_read(&xs_state.transaction_mutex); 202 transaction_start();
168 203
169 mutex_lock(&xs_state.request_mutex); 204 mutex_lock(&xs_state.request_mutex);
170 205
@@ -180,7 +215,7 @@ void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
180 if ((msg->type == XS_TRANSACTION_END) || 215 if ((msg->type == XS_TRANSACTION_END) ||
181 ((req_msg.type == XS_TRANSACTION_START) && 216 ((req_msg.type == XS_TRANSACTION_START) &&
182 (msg->type == XS_ERROR))) 217 (msg->type == XS_ERROR)))
183 up_read(&xs_state.transaction_mutex); 218 transaction_end();
184 219
185 return ret; 220 return ret;
186} 221}
@@ -432,11 +467,11 @@ int xenbus_transaction_start(struct xenbus_transaction *t)
432{ 467{
433 char *id_str; 468 char *id_str;
434 469
435 down_read(&xs_state.transaction_mutex); 470 transaction_start();
436 471
437 id_str = xs_single(XBT_NIL, XS_TRANSACTION_START, "", NULL); 472 id_str = xs_single(XBT_NIL, XS_TRANSACTION_START, "", NULL);
438 if (IS_ERR(id_str)) { 473 if (IS_ERR(id_str)) {
439 up_read(&xs_state.transaction_mutex); 474 transaction_end();
440 return PTR_ERR(id_str); 475 return PTR_ERR(id_str);
441 } 476 }
442 477
@@ -461,7 +496,7 @@ int xenbus_transaction_end(struct xenbus_transaction t, int abort)
461 496
462 err = xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL)); 497 err = xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
463 498
464 up_read(&xs_state.transaction_mutex); 499 transaction_end();
465 500
466 return err; 501 return err;
467} 502}
@@ -662,7 +697,7 @@ EXPORT_SYMBOL_GPL(unregister_xenbus_watch);
662 697
663void xs_suspend(void) 698void xs_suspend(void)
664{ 699{
665 down_write(&xs_state.transaction_mutex); 700 transaction_suspend();
666 down_write(&xs_state.watch_mutex); 701 down_write(&xs_state.watch_mutex);
667 mutex_lock(&xs_state.request_mutex); 702 mutex_lock(&xs_state.request_mutex);
668 mutex_lock(&xs_state.response_mutex); 703 mutex_lock(&xs_state.response_mutex);
@@ -677,7 +712,7 @@ void xs_resume(void)
677 712
678 mutex_unlock(&xs_state.response_mutex); 713 mutex_unlock(&xs_state.response_mutex);
679 mutex_unlock(&xs_state.request_mutex); 714 mutex_unlock(&xs_state.request_mutex);
680 up_write(&xs_state.transaction_mutex); 715 transaction_resume();
681 716
682 /* No need for watches_lock: the watch_mutex is sufficient. */ 717 /* No need for watches_lock: the watch_mutex is sufficient. */
683 list_for_each_entry(watch, &watches, list) { 718 list_for_each_entry(watch, &watches, list) {
@@ -693,7 +728,7 @@ void xs_suspend_cancel(void)
693 mutex_unlock(&xs_state.response_mutex); 728 mutex_unlock(&xs_state.response_mutex);
694 mutex_unlock(&xs_state.request_mutex); 729 mutex_unlock(&xs_state.request_mutex);
695 up_write(&xs_state.watch_mutex); 730 up_write(&xs_state.watch_mutex);
696 up_write(&xs_state.transaction_mutex); 731 mutex_unlock(&xs_state.transaction_mutex);
697} 732}
698 733
699static int xenwatch_thread(void *unused) 734static int xenwatch_thread(void *unused)
@@ -843,8 +878,10 @@ int xs_init(void)
843 878
844 mutex_init(&xs_state.request_mutex); 879 mutex_init(&xs_state.request_mutex);
845 mutex_init(&xs_state.response_mutex); 880 mutex_init(&xs_state.response_mutex);
846 init_rwsem(&xs_state.transaction_mutex); 881 mutex_init(&xs_state.transaction_mutex);
847 init_rwsem(&xs_state.watch_mutex); 882 init_rwsem(&xs_state.watch_mutex);
883 atomic_set(&xs_state.transaction_count, 0);
884 init_waitqueue_head(&xs_state.transaction_wq);
848 885
849 /* Initialize the shared memory rings to talk to xenstored */ 886 /* Initialize the shared memory rings to talk to xenstored */
850 err = xb_init_comms(); 887 err = xb_init_comms();
diff --git a/drivers/xen/xenfs/xenbus.c b/drivers/xen/xenfs/xenbus.c
index f28ece397361..3b39c3752e21 100644
--- a/drivers/xen/xenfs/xenbus.c
+++ b/drivers/xen/xenfs/xenbus.c
@@ -124,6 +124,9 @@ static ssize_t xenbus_file_read(struct file *filp,
124 mutex_lock(&u->reply_mutex); 124 mutex_lock(&u->reply_mutex);
125 while (list_empty(&u->read_buffers)) { 125 while (list_empty(&u->read_buffers)) {
126 mutex_unlock(&u->reply_mutex); 126 mutex_unlock(&u->reply_mutex);
127 if (filp->f_flags & O_NONBLOCK)
128 return -EAGAIN;
129
127 ret = wait_event_interruptible(u->read_waitq, 130 ret = wait_event_interruptible(u->read_waitq,
128 !list_empty(&u->read_buffers)); 131 !list_empty(&u->read_buffers));
129 if (ret) 132 if (ret)