From: teigland@sourceware.org <teigland@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/group/daemon main.c
Date: 14 Sep 2006 20:49:38 -0000 [thread overview]
Message-ID: <20060914204938.14949.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: teigland at sourceware.org 2006-09-14 20:49:38
Modified files:
group/daemon : main.c
Log message:
handle short/interrupted writes/reads
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/daemon/main.c.diff?cvsroot=cluster&r1=1.42&r2=1.43
--- cluster/group/daemon/main.c 2006/09/12 21:57:05 1.42
+++ cluster/group/daemon/main.c 2006/09/14 20:49:38 1.43
@@ -38,6 +38,42 @@
void *deadfn;
};
+static int do_write(int fd, void *buf, size_t count)
+{
+ int rv, off = 0;
+
+ retry:
+ rv = write(fd, buf + off, count);
+ if (rv == -1 && errno == EINTR)
+ goto retry;
+ if (rv < 0) {
+ log_print("write fd %d errno %d", fd, errno);
+ return rv;
+ }
+
+ if (rv != count) {
+ count -= rv;
+ off += rv;
+ goto retry;
+ }
+ return 0;
+}
+
+static int do_read(int fd, void *buf, size_t count)
+{
+ int rv, off = 0;
+
+ while (off < count) {
+ rv = read(fd, buf + off, count - off);
+ if (rv == 0)
+ return -1;
+ if (rv == -1 && errno == EINTR)
+ continue;
+ off += rv;
+ }
+ return 0;
+}
+
/* Look for any instances of gfs or dlm in the kernel, if we find any, it
means they're uncontrolled by us (via gfs_controld/dlm_controld/groupd).
We need to be rebooted to clear out this uncontrolled kernel state. Most
@@ -130,9 +166,9 @@
log_group(a->g, "action for app: %s", buf);
- rv = write(client[a->client].fd, buf, GROUPD_MSGLEN);
- if (rv != GROUPD_MSGLEN)
- log_print("write error %d errno %d", rv, errno);
+ rv = do_write(client[a->client].fd, buf, GROUPD_MSGLEN);
+ if (rv < 0)
+ log_error(a->g, "app_action write error");
}
void app_deliver(app_t *a, struct save_msg *save)
@@ -154,9 +190,9 @@
save->msg_long + sizeof(msg_t));
*/
- rv = write(client[a->client].fd, buf, GROUPD_MSGLEN);
- if (rv != GROUPD_MSGLEN)
- log_print("write error %d errno %d", rv, errno);
+ rv = do_write(client[a->client].fd, buf, GROUPD_MSGLEN);
+ if (rv < 0)
+ log_error(a->g, "app_deliver write error");
}
void app_terminate(app_t *a)
@@ -325,7 +361,7 @@
if (!strncmp(act, "dump", 16))
return DO_DUMP;
- return -1;
+ return -1;
}
static void client_alloc(void)
@@ -459,9 +495,9 @@
i++;
}
- rv = write(client[ci].fd, data, len);
- if (rv != len)
- log_print("write error %d errno %d", rv, errno);
+ rv = do_write(client[ci].fd, data, len);
+ if (rv < 0)
+ log_print("do_get_groups write error");
free(data);
return 0;
@@ -487,9 +523,9 @@
copy_group_data(g, &data);
out:
- rv = write(client[ci].fd, &data, sizeof(data));
- if (rv != sizeof(data))
- log_print("write error %d errno %d", rv, errno);
+ rv = do_write(client[ci].fd, &data, sizeof(data));
+ if (rv < 0)
+ log_print("do_get_group write error");
return 0;
}
@@ -548,14 +584,11 @@
memset(buf, 0, sizeof(buf));
memset(argv, 0, sizeof(char *) * MAXARGS);
- rv = read(client[ci].fd, buf, GROUPD_MSGLEN);
- if (!rv) {
- client_dead(ci);
- return;
- }
- if (rv != GROUPD_MSGLEN) {
+ rv = do_read(client[ci].fd, buf, GROUPD_MSGLEN);
+ if (rv < 0) {
log_print("client %d fd %d read error %d %d", ci,
client[ci].fd, rv, errno);
+ client_dead(ci);
return;
}
@@ -577,7 +610,7 @@
case DO_LEAVE:
get_args(buf, &argc, argv, ' ', 2);
- do_leave(argv[1], client[ci].level);
+ do_leave(argv[1], client[ci].level);
break;
case DO_STOP_DONE:
@@ -789,9 +822,9 @@
printf("\n");
printf("Options:\n");
printf("\n");
- printf(" -D Enable debugging code and don't fork\n");
- printf(" -h Print this help, then exit\n");
- printf(" -V Print program version information, then exit\n");
+ printf(" -D Enable debugging code and don't fork\n");
+ printf(" -h Print this help, then exit\n");
+ printf(" -V Print program version information, then exit\n");
}
static void decode_arguments(int argc, char **argv)
next reply other threads:[~2006-09-14 20:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-14 20:49 teigland [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-01-11 17:59 [Cluster-devel] cluster/group/daemon main.c teigland
2007-01-11 17:59 teigland
2006-12-13 19:05 teigland
2006-12-13 19:05 teigland
2006-12-13 19:04 teigland
2006-12-01 15:25 teigland
2006-12-01 15:25 teigland
2006-12-01 15:24 teigland
2006-11-20 22:44 rpeterso
2006-11-17 16:28 teigland
2006-11-17 16:26 teigland
2006-11-15 14:35 teigland
2006-10-24 17:08 teigland
2006-10-20 15:42 rpeterso
2006-07-13 18:21 teigland
2006-06-22 19:06 teigland
2006-06-20 20:27 teigland
2006-06-14 21:38 teigland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060914204938.14949.qmail@sourceware.org \
--to=teigland@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).