[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xenstore: Small cleanups and fixes.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1185298128 -3600
# Node ID 68260372b6da5dfb0e32dfe26cc4a8ddbf0b3df0
# Parent  207582c8d88b532783da5c6f5839336187556f0a
xenstore: Small cleanups and fixes.
 1. readfd/writefd account for EINTR/EAGAIN errno returns.
 2. Handle zero return from ->read() and ->write() handlers
    symmetrically.
 3. Fix some indentation issues (use hard tabs).
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c   |   40 +++++++++++++++++++++++++++++---------
 tools/xenstore/xenstored_domain.c |    5 ++--
 tools/xenstore/xenstored_watch.c  |    5 +---
 3 files changed, 36 insertions(+), 14 deletions(-)

diff -r 207582c8d88b -r 68260372b6da tools/xenstore/xenstored_core.c
--- a/tools/xenstore/xenstored_core.c   Tue Jul 24 18:05:04 2007 +0100
+++ b/tools/xenstore/xenstored_core.c   Tue Jul 24 18:28:48 2007 +0100
@@ -1266,7 +1266,7 @@ static void handle_input(struct connecti
        if (in->inhdr) {
                bytes = conn->read(conn, in->hdr.raw + in->used,
                                   sizeof(in->hdr) - in->used);
-               if (bytes <= 0)
+               if (bytes < 0)
                        goto bad_client;
                in->used += bytes;
                if (in->used != sizeof(in->hdr))
@@ -1288,7 +1288,7 @@ static void handle_input(struct connecti
 
        bytes = conn->read(conn, in->buffer + in->used,
                           in->hdr.msg.len - in->used);
-       if (bytes <= 0)
+       if (bytes < 0)
                goto bad_client;
 
        in->used += bytes;
@@ -1341,12 +1341,34 @@ struct connection *new_connection(connwr
 
 static int writefd(struct connection *conn, const void *data, unsigned int len)
 {
-       return write(conn->fd, data, len);
+       int rc;
+
+       while ((rc = write(conn->fd, data, len)) < 0) {
+               if (errno == EAGAIN) {
+                       rc = 0;
+                       break;
+               }
+               if (errno != EINTR)
+                       break;
+       }
+
+       return rc;
 }
 
 static int readfd(struct connection *conn, void *data, unsigned int len)
 {
-       return read(conn->fd, data, len);
+       int rc;
+
+       while ((rc = read(conn->fd, data, len)) < 0) {
+               if (errno == EAGAIN) {
+                       rc = 0;
+                       break;
+               }
+               if (errno != EINTR)
+                       break;
+       }
+
+       return rc;
 }
 
 static void accept_connection(int sock, bool canwrite)
@@ -1439,13 +1461,13 @@ static unsigned int hash_from_key_fn(voi
 static unsigned int hash_from_key_fn(void *k)
 {
        char *str = k;
-        unsigned int hash = 5381;
-        char c;
-
-        while ((c = *str++))
+       unsigned int hash = 5381;
+       char c;
+
+       while ((c = *str++))
                hash = ((hash << 5) + hash) + (unsigned int)c;
 
-        return hash;
+       return hash;
 }
 
 
diff -r 207582c8d88b -r 68260372b6da tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Tue Jul 24 18:05:04 2007 +0100
+++ b/tools/xenstore/xenstored_domain.c Tue Jul 24 18:28:48 2007 +0100
@@ -76,7 +76,6 @@ struct domain
 
 static LIST_HEAD(domains);
 
-/* FIXME: Mark connection as broken (close it?) when this happens. */
 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
 {
        return ((prod - cons) <= XENSTORE_RING_SIZE);
@@ -102,7 +101,8 @@ static const void *get_input_chunk(XENST
        return buf + MASK_XENSTORE_IDX(cons);
 }
 
-static int writechn(struct connection *conn, const void *data, unsigned int 
len)
+static int writechn(struct connection *conn,
+                   const void *data, unsigned int len)
 {
        uint32_t avail;
        void *dest;
@@ -113,6 +113,7 @@ static int writechn(struct connection *c
        cons = intf->rsp_cons;
        prod = intf->rsp_prod;
        mb();
+
        if (!check_indexes(cons, prod)) {
                errno = EIO;
                return -1;
diff -r 207582c8d88b -r 68260372b6da tools/xenstore/xenstored_watch.c
--- a/tools/xenstore/xenstored_watch.c  Tue Jul 24 18:05:04 2007 +0100
+++ b/tools/xenstore/xenstored_watch.c  Tue Jul 24 18:28:48 2007 +0100
@@ -73,11 +73,10 @@ static void add_event(struct connection 
        data = talloc_array(watch, char, len);
        strcpy(data, name);
        strcpy(data + strlen(name) + 1, watch->token);
-        send_reply(conn, XS_WATCH_EVENT, data, len);
+       send_reply(conn, XS_WATCH_EVENT, data, len);
        talloc_free(data);
 }
 
-/* FIXME: we fail to fire on out of memory.  Should drop connections. */
 void fire_watches(struct connection *conn, const char *name, bool recurse)
 {
        struct connection *i;
@@ -130,7 +129,7 @@ void do_watch(struct connection *conn, s
        /* Check for duplicates. */
        list_for_each_entry(watch, &conn->watches, list) {
                if (streq(watch->node, vec[0]) &&
-                    streq(watch->token, vec[1])) {
+                   streq(watch->token, vec[1])) {
                        send_error(conn, EEXIST);
                        return;
                }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.