ALSA: ASoC: TLV320AIC3X: Modify only interface related bits in aic3x_set_dai_fmt
[linux-ginger.git] / drivers / xen / xenbus / xenbus_xs.c
blob227d53b12a5cc05490687f6e9f3c9e5725b147f2
1 /******************************************************************************
2 * xenbus_xs.c
4 * This is the kernel equivalent of the "xs" library. We don't need everything
5 * and we use xenbus_comms for communication.
7 * Copyright (C) 2005 Rusty Russell, IBM Corporation
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation; or, when distributed
12 * separately from the Linux kernel or incorporated into other
13 * software packages, subject to the following license:
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this source file (the "Software"), to deal in the Software without
17 * restriction, including without limitation the rights to use, copy, modify,
18 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
19 * and to permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 * IN THE SOFTWARE.
34 #include <linux/unistd.h>
35 #include <linux/errno.h>
36 #include <linux/types.h>
37 #include <linux/uio.h>
38 #include <linux/kernel.h>
39 #include <linux/string.h>
40 #include <linux/err.h>
41 #include <linux/slab.h>
42 #include <linux/fcntl.h>
43 #include <linux/kthread.h>
44 #include <linux/rwsem.h>
45 #include <linux/module.h>
46 #include <linux/mutex.h>
47 #include <xen/xenbus.h>
48 #include "xenbus_comms.h"
50 struct xs_stored_msg {
51 struct list_head list;
53 struct xsd_sockmsg hdr;
55 union {
56 /* Queued replies. */
57 struct {
58 char *body;
59 } reply;
61 /* Queued watch events. */
62 struct {
63 struct xenbus_watch *handle;
64 char **vec;
65 unsigned int vec_size;
66 } watch;
67 } u;
70 struct xs_handle {
71 /* A list of replies. Currently only one will ever be outstanding. */
72 struct list_head reply_list;
73 spinlock_t reply_lock;
74 wait_queue_head_t reply_waitq;
77 * Mutex ordering: transaction_mutex -> watch_mutex -> request_mutex.
78 * response_mutex is never taken simultaneously with the other three.
81 /* One request at a time. */
82 struct mutex request_mutex;
84 /* Protect xenbus reader thread against save/restore. */
85 struct mutex response_mutex;
87 /* Protect transactions against save/restore. */
88 struct rw_semaphore transaction_mutex;
90 /* Protect watch (de)register against save/restore. */
91 struct rw_semaphore watch_mutex;
94 static struct xs_handle xs_state;
96 /* List of registered watches, and a lock to protect it. */
97 static LIST_HEAD(watches);
98 static DEFINE_SPINLOCK(watches_lock);
100 /* List of pending watch callback events, and a lock to protect it. */
101 static LIST_HEAD(watch_events);
102 static DEFINE_SPINLOCK(watch_events_lock);
105 * Details of the xenwatch callback kernel thread. The thread waits on the
106 * watch_events_waitq for work to do (queued on watch_events list). When it
107 * wakes up it acquires the xenwatch_mutex before reading the list and
108 * carrying out work.
110 static pid_t xenwatch_pid;
111 static DEFINE_MUTEX(xenwatch_mutex);
112 static DECLARE_WAIT_QUEUE_HEAD(watch_events_waitq);
114 static int get_error(const char *errorstring)
116 unsigned int i;
118 for (i = 0; strcmp(errorstring, xsd_errors[i].errstring) != 0; i++) {
119 if (i == ARRAY_SIZE(xsd_errors) - 1) {
120 printk(KERN_WARNING
121 "XENBUS xen store gave: unknown error %s",
122 errorstring);
123 return EINVAL;
126 return xsd_errors[i].errnum;
129 static void *read_reply(enum xsd_sockmsg_type *type, unsigned int *len)
131 struct xs_stored_msg *msg;
132 char *body;
134 spin_lock(&xs_state.reply_lock);
136 while (list_empty(&xs_state.reply_list)) {
137 spin_unlock(&xs_state.reply_lock);
138 /* XXX FIXME: Avoid synchronous wait for response here. */
139 wait_event(xs_state.reply_waitq,
140 !list_empty(&xs_state.reply_list));
141 spin_lock(&xs_state.reply_lock);
144 msg = list_entry(xs_state.reply_list.next,
145 struct xs_stored_msg, list);
146 list_del(&msg->list);
148 spin_unlock(&xs_state.reply_lock);
150 *type = msg->hdr.type;
151 if (len)
152 *len = msg->hdr.len;
153 body = msg->u.reply.body;
155 kfree(msg);
157 return body;
160 void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)
162 void *ret;
163 struct xsd_sockmsg req_msg = *msg;
164 int err;
166 if (req_msg.type == XS_TRANSACTION_START)
167 down_read(&xs_state.transaction_mutex);
169 mutex_lock(&xs_state.request_mutex);
171 err = xb_write(msg, sizeof(*msg) + msg->len);
172 if (err) {
173 msg->type = XS_ERROR;
174 ret = ERR_PTR(err);
175 } else
176 ret = read_reply(&msg->type, &msg->len);
178 mutex_unlock(&xs_state.request_mutex);
180 if ((msg->type == XS_TRANSACTION_END) ||
181 ((req_msg.type == XS_TRANSACTION_START) &&
182 (msg->type == XS_ERROR)))
183 up_read(&xs_state.transaction_mutex);
185 return ret;
188 /* Send message to xs, get kmalloc'ed reply. ERR_PTR() on error. */
189 static void *xs_talkv(struct xenbus_transaction t,
190 enum xsd_sockmsg_type type,
191 const struct kvec *iovec,
192 unsigned int num_vecs,
193 unsigned int *len)
195 struct xsd_sockmsg msg;
196 void *ret = NULL;
197 unsigned int i;
198 int err;
200 msg.tx_id = t.id;
201 msg.req_id = 0;
202 msg.type = type;
203 msg.len = 0;
204 for (i = 0; i < num_vecs; i++)
205 msg.len += iovec[i].iov_len;
207 mutex_lock(&xs_state.request_mutex);
209 err = xb_write(&msg, sizeof(msg));
210 if (err) {
211 mutex_unlock(&xs_state.request_mutex);
212 return ERR_PTR(err);
215 for (i = 0; i < num_vecs; i++) {
216 err = xb_write(iovec[i].iov_base, iovec[i].iov_len);
217 if (err) {
218 mutex_unlock(&xs_state.request_mutex);
219 return ERR_PTR(err);
223 ret = read_reply(&msg.type, len);
225 mutex_unlock(&xs_state.request_mutex);
227 if (IS_ERR(ret))
228 return ret;
230 if (msg.type == XS_ERROR) {
231 err = get_error(ret);
232 kfree(ret);
233 return ERR_PTR(-err);
236 if (msg.type != type) {
237 if (printk_ratelimit())
238 printk(KERN_WARNING
239 "XENBUS unexpected type [%d], expected [%d]\n",
240 msg.type, type);
241 kfree(ret);
242 return ERR_PTR(-EINVAL);
244 return ret;
247 /* Simplified version of xs_talkv: single message. */
248 static void *xs_single(struct xenbus_transaction t,
249 enum xsd_sockmsg_type type,
250 const char *string,
251 unsigned int *len)
253 struct kvec iovec;
255 iovec.iov_base = (void *)string;
256 iovec.iov_len = strlen(string) + 1;
257 return xs_talkv(t, type, &iovec, 1, len);
260 /* Many commands only need an ack, don't care what it says. */
261 static int xs_error(char *reply)
263 if (IS_ERR(reply))
264 return PTR_ERR(reply);
265 kfree(reply);
266 return 0;
269 static unsigned int count_strings(const char *strings, unsigned int len)
271 unsigned int num;
272 const char *p;
274 for (p = strings, num = 0; p < strings + len; p += strlen(p) + 1)
275 num++;
277 return num;
280 /* Return the path to dir with /name appended. Buffer must be kfree()'ed. */
281 static char *join(const char *dir, const char *name)
283 char *buffer;
285 if (strlen(name) == 0)
286 buffer = kasprintf(GFP_KERNEL, "%s", dir);
287 else
288 buffer = kasprintf(GFP_KERNEL, "%s/%s", dir, name);
289 return (!buffer) ? ERR_PTR(-ENOMEM) : buffer;
292 static char **split(char *strings, unsigned int len, unsigned int *num)
294 char *p, **ret;
296 /* Count the strings. */
297 *num = count_strings(strings, len);
299 /* Transfer to one big alloc for easy freeing. */
300 ret = kmalloc(*num * sizeof(char *) + len, GFP_KERNEL);
301 if (!ret) {
302 kfree(strings);
303 return ERR_PTR(-ENOMEM);
305 memcpy(&ret[*num], strings, len);
306 kfree(strings);
308 strings = (char *)&ret[*num];
309 for (p = strings, *num = 0; p < strings + len; p += strlen(p) + 1)
310 ret[(*num)++] = p;
312 return ret;
315 char **xenbus_directory(struct xenbus_transaction t,
316 const char *dir, const char *node, unsigned int *num)
318 char *strings, *path;
319 unsigned int len;
321 path = join(dir, node);
322 if (IS_ERR(path))
323 return (char **)path;
325 strings = xs_single(t, XS_DIRECTORY, path, &len);
326 kfree(path);
327 if (IS_ERR(strings))
328 return (char **)strings;
330 return split(strings, len, num);
332 EXPORT_SYMBOL_GPL(xenbus_directory);
334 /* Check if a path exists. Return 1 if it does. */
335 int xenbus_exists(struct xenbus_transaction t,
336 const char *dir, const char *node)
338 char **d;
339 int dir_n;
341 d = xenbus_directory(t, dir, node, &dir_n);
342 if (IS_ERR(d))
343 return 0;
344 kfree(d);
345 return 1;
347 EXPORT_SYMBOL_GPL(xenbus_exists);
349 /* Get the value of a single file.
350 * Returns a kmalloced value: call free() on it after use.
351 * len indicates length in bytes.
353 void *xenbus_read(struct xenbus_transaction t,
354 const char *dir, const char *node, unsigned int *len)
356 char *path;
357 void *ret;
359 path = join(dir, node);
360 if (IS_ERR(path))
361 return (void *)path;
363 ret = xs_single(t, XS_READ, path, len);
364 kfree(path);
365 return ret;
367 EXPORT_SYMBOL_GPL(xenbus_read);
369 /* Write the value of a single file.
370 * Returns -err on failure.
372 int xenbus_write(struct xenbus_transaction t,
373 const char *dir, const char *node, const char *string)
375 const char *path;
376 struct kvec iovec[2];
377 int ret;
379 path = join(dir, node);
380 if (IS_ERR(path))
381 return PTR_ERR(path);
383 iovec[0].iov_base = (void *)path;
384 iovec[0].iov_len = strlen(path) + 1;
385 iovec[1].iov_base = (void *)string;
386 iovec[1].iov_len = strlen(string);
388 ret = xs_error(xs_talkv(t, XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL));
389 kfree(path);
390 return ret;
392 EXPORT_SYMBOL_GPL(xenbus_write);
394 /* Create a new directory. */
395 int xenbus_mkdir(struct xenbus_transaction t,
396 const char *dir, const char *node)
398 char *path;
399 int ret;
401 path = join(dir, node);
402 if (IS_ERR(path))
403 return PTR_ERR(path);
405 ret = xs_error(xs_single(t, XS_MKDIR, path, NULL));
406 kfree(path);
407 return ret;
409 EXPORT_SYMBOL_GPL(xenbus_mkdir);
411 /* Destroy a file or directory (directories must be empty). */
412 int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node)
414 char *path;
415 int ret;
417 path = join(dir, node);
418 if (IS_ERR(path))
419 return PTR_ERR(path);
421 ret = xs_error(xs_single(t, XS_RM, path, NULL));
422 kfree(path);
423 return ret;
425 EXPORT_SYMBOL_GPL(xenbus_rm);
427 /* Start a transaction: changes by others will not be seen during this
428 * transaction, and changes will not be visible to others until end.
430 int xenbus_transaction_start(struct xenbus_transaction *t)
432 char *id_str;
434 down_read(&xs_state.transaction_mutex);
436 id_str = xs_single(XBT_NIL, XS_TRANSACTION_START, "", NULL);
437 if (IS_ERR(id_str)) {
438 up_read(&xs_state.transaction_mutex);
439 return PTR_ERR(id_str);
442 t->id = simple_strtoul(id_str, NULL, 0);
443 kfree(id_str);
444 return 0;
446 EXPORT_SYMBOL_GPL(xenbus_transaction_start);
448 /* End a transaction.
449 * If abandon is true, transaction is discarded instead of committed.
451 int xenbus_transaction_end(struct xenbus_transaction t, int abort)
453 char abortstr[2];
454 int err;
456 if (abort)
457 strcpy(abortstr, "F");
458 else
459 strcpy(abortstr, "T");
461 err = xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL));
463 up_read(&xs_state.transaction_mutex);
465 return err;
467 EXPORT_SYMBOL_GPL(xenbus_transaction_end);
469 /* Single read and scanf: returns -errno or num scanned. */
470 int xenbus_scanf(struct xenbus_transaction t,
471 const char *dir, const char *node, const char *fmt, ...)
473 va_list ap;
474 int ret;
475 char *val;
477 val = xenbus_read(t, dir, node, NULL);
478 if (IS_ERR(val))
479 return PTR_ERR(val);
481 va_start(ap, fmt);
482 ret = vsscanf(val, fmt, ap);
483 va_end(ap);
484 kfree(val);
485 /* Distinctive errno. */
486 if (ret == 0)
487 return -ERANGE;
488 return ret;
490 EXPORT_SYMBOL_GPL(xenbus_scanf);
492 /* Single printf and write: returns -errno or 0. */
493 int xenbus_printf(struct xenbus_transaction t,
494 const char *dir, const char *node, const char *fmt, ...)
496 va_list ap;
497 int ret;
498 #define PRINTF_BUFFER_SIZE 4096
499 char *printf_buffer;
501 printf_buffer = kmalloc(PRINTF_BUFFER_SIZE, GFP_KERNEL);
502 if (printf_buffer == NULL)
503 return -ENOMEM;
505 va_start(ap, fmt);
506 ret = vsnprintf(printf_buffer, PRINTF_BUFFER_SIZE, fmt, ap);
507 va_end(ap);
509 BUG_ON(ret > PRINTF_BUFFER_SIZE-1);
510 ret = xenbus_write(t, dir, node, printf_buffer);
512 kfree(printf_buffer);
514 return ret;
516 EXPORT_SYMBOL_GPL(xenbus_printf);
518 /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
519 int xenbus_gather(struct xenbus_transaction t, const char *dir, ...)
521 va_list ap;
522 const char *name;
523 int ret = 0;
525 va_start(ap, dir);
526 while (ret == 0 && (name = va_arg(ap, char *)) != NULL) {
527 const char *fmt = va_arg(ap, char *);
528 void *result = va_arg(ap, void *);
529 char *p;
531 p = xenbus_read(t, dir, name, NULL);
532 if (IS_ERR(p)) {
533 ret = PTR_ERR(p);
534 break;
536 if (fmt) {
537 if (sscanf(p, fmt, result) == 0)
538 ret = -EINVAL;
539 kfree(p);
540 } else
541 *(char **)result = p;
543 va_end(ap);
544 return ret;
546 EXPORT_SYMBOL_GPL(xenbus_gather);
548 static int xs_watch(const char *path, const char *token)
550 struct kvec iov[2];
552 iov[0].iov_base = (void *)path;
553 iov[0].iov_len = strlen(path) + 1;
554 iov[1].iov_base = (void *)token;
555 iov[1].iov_len = strlen(token) + 1;
557 return xs_error(xs_talkv(XBT_NIL, XS_WATCH, iov,
558 ARRAY_SIZE(iov), NULL));
561 static int xs_unwatch(const char *path, const char *token)
563 struct kvec iov[2];
565 iov[0].iov_base = (char *)path;
566 iov[0].iov_len = strlen(path) + 1;
567 iov[1].iov_base = (char *)token;
568 iov[1].iov_len = strlen(token) + 1;
570 return xs_error(xs_talkv(XBT_NIL, XS_UNWATCH, iov,
571 ARRAY_SIZE(iov), NULL));
574 static struct xenbus_watch *find_watch(const char *token)
576 struct xenbus_watch *i, *cmp;
578 cmp = (void *)simple_strtoul(token, NULL, 16);
580 list_for_each_entry(i, &watches, list)
581 if (i == cmp)
582 return i;
584 return NULL;
587 /* Register callback to watch this node. */
588 int register_xenbus_watch(struct xenbus_watch *watch)
590 /* Pointer in ascii is the token. */
591 char token[sizeof(watch) * 2 + 1];
592 int err;
594 sprintf(token, "%lX", (long)watch);
596 down_read(&xs_state.watch_mutex);
598 spin_lock(&watches_lock);
599 BUG_ON(find_watch(token));
600 list_add(&watch->list, &watches);
601 spin_unlock(&watches_lock);
603 err = xs_watch(watch->node, token);
605 /* Ignore errors due to multiple registration. */
606 if ((err != 0) && (err != -EEXIST)) {
607 spin_lock(&watches_lock);
608 list_del(&watch->list);
609 spin_unlock(&watches_lock);
612 up_read(&xs_state.watch_mutex);
614 return err;
616 EXPORT_SYMBOL_GPL(register_xenbus_watch);
618 void unregister_xenbus_watch(struct xenbus_watch *watch)
620 struct xs_stored_msg *msg, *tmp;
621 char token[sizeof(watch) * 2 + 1];
622 int err;
624 sprintf(token, "%lX", (long)watch);
626 down_read(&xs_state.watch_mutex);
628 spin_lock(&watches_lock);
629 BUG_ON(!find_watch(token));
630 list_del(&watch->list);
631 spin_unlock(&watches_lock);
633 err = xs_unwatch(watch->node, token);
634 if (err)
635 printk(KERN_WARNING
636 "XENBUS Failed to release watch %s: %i\n",
637 watch->node, err);
639 up_read(&xs_state.watch_mutex);
641 /* Make sure there are no callbacks running currently (unless
642 its us) */
643 if (current->pid != xenwatch_pid)
644 mutex_lock(&xenwatch_mutex);
646 /* Cancel pending watch events. */
647 spin_lock(&watch_events_lock);
648 list_for_each_entry_safe(msg, tmp, &watch_events, list) {
649 if (msg->u.watch.handle != watch)
650 continue;
651 list_del(&msg->list);
652 kfree(msg->u.watch.vec);
653 kfree(msg);
655 spin_unlock(&watch_events_lock);
657 if (current->pid != xenwatch_pid)
658 mutex_unlock(&xenwatch_mutex);
660 EXPORT_SYMBOL_GPL(unregister_xenbus_watch);
662 void xs_suspend(void)
664 down_write(&xs_state.transaction_mutex);
665 down_write(&xs_state.watch_mutex);
666 mutex_lock(&xs_state.request_mutex);
667 mutex_lock(&xs_state.response_mutex);
670 void xs_resume(void)
672 struct xenbus_watch *watch;
673 char token[sizeof(watch) * 2 + 1];
675 mutex_unlock(&xs_state.response_mutex);
676 mutex_unlock(&xs_state.request_mutex);
677 up_write(&xs_state.transaction_mutex);
679 /* No need for watches_lock: the watch_mutex is sufficient. */
680 list_for_each_entry(watch, &watches, list) {
681 sprintf(token, "%lX", (long)watch);
682 xs_watch(watch->node, token);
685 up_write(&xs_state.watch_mutex);
688 void xs_suspend_cancel(void)
690 mutex_unlock(&xs_state.response_mutex);
691 mutex_unlock(&xs_state.request_mutex);
692 up_write(&xs_state.watch_mutex);
693 up_write(&xs_state.transaction_mutex);
696 static int xenwatch_thread(void *unused)
698 struct list_head *ent;
699 struct xs_stored_msg *msg;
701 for (;;) {
702 wait_event_interruptible(watch_events_waitq,
703 !list_empty(&watch_events));
705 if (kthread_should_stop())
706 break;
708 mutex_lock(&xenwatch_mutex);
710 spin_lock(&watch_events_lock);
711 ent = watch_events.next;
712 if (ent != &watch_events)
713 list_del(ent);
714 spin_unlock(&watch_events_lock);
716 if (ent != &watch_events) {
717 msg = list_entry(ent, struct xs_stored_msg, list);
718 msg->u.watch.handle->callback(
719 msg->u.watch.handle,
720 (const char **)msg->u.watch.vec,
721 msg->u.watch.vec_size);
722 kfree(msg->u.watch.vec);
723 kfree(msg);
726 mutex_unlock(&xenwatch_mutex);
729 return 0;
732 static int process_msg(void)
734 struct xs_stored_msg *msg;
735 char *body;
736 int err;
739 * We must disallow save/restore while reading a xenstore message.
740 * A partial read across s/r leaves us out of sync with xenstored.
742 for (;;) {
743 err = xb_wait_for_data_to_read();
744 if (err)
745 return err;
746 mutex_lock(&xs_state.response_mutex);
747 if (xb_data_to_read())
748 break;
749 /* We raced with save/restore: pending data 'disappeared'. */
750 mutex_unlock(&xs_state.response_mutex);
754 msg = kmalloc(sizeof(*msg), GFP_KERNEL);
755 if (msg == NULL) {
756 err = -ENOMEM;
757 goto out;
760 err = xb_read(&msg->hdr, sizeof(msg->hdr));
761 if (err) {
762 kfree(msg);
763 goto out;
766 body = kmalloc(msg->hdr.len + 1, GFP_KERNEL);
767 if (body == NULL) {
768 kfree(msg);
769 err = -ENOMEM;
770 goto out;
773 err = xb_read(body, msg->hdr.len);
774 if (err) {
775 kfree(body);
776 kfree(msg);
777 goto out;
779 body[msg->hdr.len] = '\0';
781 if (msg->hdr.type == XS_WATCH_EVENT) {
782 msg->u.watch.vec = split(body, msg->hdr.len,
783 &msg->u.watch.vec_size);
784 if (IS_ERR(msg->u.watch.vec)) {
785 err = PTR_ERR(msg->u.watch.vec);
786 kfree(msg);
787 goto out;
790 spin_lock(&watches_lock);
791 msg->u.watch.handle = find_watch(
792 msg->u.watch.vec[XS_WATCH_TOKEN]);
793 if (msg->u.watch.handle != NULL) {
794 spin_lock(&watch_events_lock);
795 list_add_tail(&msg->list, &watch_events);
796 wake_up(&watch_events_waitq);
797 spin_unlock(&watch_events_lock);
798 } else {
799 kfree(msg->u.watch.vec);
800 kfree(msg);
802 spin_unlock(&watches_lock);
803 } else {
804 msg->u.reply.body = body;
805 spin_lock(&xs_state.reply_lock);
806 list_add_tail(&msg->list, &xs_state.reply_list);
807 spin_unlock(&xs_state.reply_lock);
808 wake_up(&xs_state.reply_waitq);
811 out:
812 mutex_unlock(&xs_state.response_mutex);
813 return err;
816 static int xenbus_thread(void *unused)
818 int err;
820 for (;;) {
821 err = process_msg();
822 if (err)
823 printk(KERN_WARNING "XENBUS error %d while reading "
824 "message\n", err);
825 if (kthread_should_stop())
826 break;
829 return 0;
832 int xs_init(void)
834 int err;
835 struct task_struct *task;
837 INIT_LIST_HEAD(&xs_state.reply_list);
838 spin_lock_init(&xs_state.reply_lock);
839 init_waitqueue_head(&xs_state.reply_waitq);
841 mutex_init(&xs_state.request_mutex);
842 mutex_init(&xs_state.response_mutex);
843 init_rwsem(&xs_state.transaction_mutex);
844 init_rwsem(&xs_state.watch_mutex);
846 /* Initialize the shared memory rings to talk to xenstored */
847 err = xb_init_comms();
848 if (err)
849 return err;
851 task = kthread_run(xenwatch_thread, NULL, "xenwatch");
852 if (IS_ERR(task))
853 return PTR_ERR(task);
854 xenwatch_pid = task->pid;
856 task = kthread_run(xenbus_thread, NULL, "xenbus");
857 if (IS_ERR(task))
858 return PTR_ERR(task);
860 return 0;