Date: Thu, 30 Dec 2010 09:46:46 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r216816 - stable/8/sbin/hastd Message-ID: <201012300946.oBU9kk2e029410@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pjd Date: Thu Dec 30 09:46:45 2010 New Revision: 216816 URL: http://svn.freebsd.org/changeset/base/216816 Log: MFC r216477,r216478,r216479,r216494,r216721,r216722: r216477: Log the fact of launching and include protocol version number. r216478: Don't ignore errors from remote requests. r216479: Improve problems logging. r216494: The 'ret' variable is of type ssize_t and we use proper format for it (%zd), so no (bogus) cast is needed. r216721: When node-specific configuration is missing in resource section, provide more useful information. Instead of: hastd: remote address not configured for resource foo Print the following: No resource foo configuration for this node (acceptable node names: freefall, freefall.freebsd.org, 44333332-4c44-4e31-4a30-313920202020). r216722: Detect when resource is configured more than once. Modified: stable/8/sbin/hastd/hastd.c stable/8/sbin/hastd/parse.y stable/8/sbin/hastd/primary.c Directory Properties: stable/8/sbin/hastd/ (props changed) Modified: stable/8/sbin/hastd/hastd.c ============================================================================== --- stable/8/sbin/hastd/hastd.c Thu Dec 30 09:45:26 2010 (r216815) +++ stable/8/sbin/hastd/hastd.c Thu Dec 30 09:46:45 2010 (r216816) @@ -619,6 +619,9 @@ main_loop(void) PJDLOG_VERIFY(sigaddset(&mask, SIGTERM) == 0); PJDLOG_VERIFY(sigaddset(&mask, SIGCHLD) == 0); + pjdlog_info("Started successfully, running protocol version %d.", + HAST_PROTO_VERSION); + for (;;) { while ((signo = sigtimedwait(&mask, NULL, &sigtimeout)) != -1) { switch (signo) { Modified: stable/8/sbin/hastd/parse.y ============================================================================== --- stable/8/sbin/hastd/parse.y Thu Dec 30 09:45:26 2010 (r216815) +++ stable/8/sbin/hastd/parse.y Thu Dec 30 09:46:45 2010 (r216816) @@ -55,7 +55,7 @@ extern char *yytext; static struct hastd_config *lconfig; static struct hast_resource *curres; -static bool mynode; +static bool mynode, hadmynode; static char depth0_control[HAST_ADDRSIZE]; static char depth0_listen[HAST_ADDRSIZE]; @@ -109,6 +109,44 @@ isitme(const char *name) return (0); } +static int +node_names(char **namesp) +{ + static char names[MAXHOSTNAMELEN * 3]; + char buf[MAXHOSTNAMELEN]; + char *pos; + size_t bufsize; + + if (gethostname(buf, sizeof(buf)) < 0) { + pjdlog_errno(LOG_ERR, "gethostname() failed"); + return (-1); + } + + /* First component of the host name. */ + pos = strchr(buf, '.'); + if (pos != NULL && pos != buf) { + (void)strlcpy(names, buf, MIN((size_t)(pos - buf + 1), + sizeof(names))); + (void)strlcat(names, ", ", sizeof(names)); + } + + /* Full host name. */ + (void)strlcat(names, buf, sizeof(names)); + (void)strlcat(names, ", ", sizeof(names)); + + /* Host UUID. */ + bufsize = sizeof(buf); + if (sysctlbyname("kern.hostuuid", buf, &bufsize, NULL, 0) < 0) { + pjdlog_errno(LOG_ERR, "sysctlbyname(kern.hostuuid) failed"); + return (-1); + } + (void)strlcat(names, buf, sizeof(names)); + + *namesp = names; + + return (0); +} + void yyerror(const char *str) { @@ -424,6 +462,20 @@ resource_statement: RESOURCE resource_st { if (curres != NULL) { /* + * There must be section for this node, at least with + * remote address configuration. + */ + if (!hadmynode) { + char *names; + + if (node_names(&names) != 0) + return (1); + pjdlog_error("No resource %s configuration for this node (acceptable node names: %s).", + curres->hr_name, names); + return (1); + } + + /* * Let's see there are some resource-level settings * that we can use for node-level settings. */ @@ -483,12 +535,23 @@ resource_statement: RESOURCE resource_st resource_start: STR { + /* Check if there is no duplicate entry. */ + TAILQ_FOREACH(curres, &lconfig->hc_resources, hr_next) { + if (strcmp(curres->hr_name, $1) == 0) { + pjdlog_error("Resource %s configured more than once.", + curres->hr_name); + free($1); + return (1); + } + } + /* * Clear those, so we can tell if they were set at * resource-level or not. */ depth1_provname[0] = '\0'; depth1_localpath[0] = '\0'; + hadmynode = false; curres = calloc(1, sizeof(*curres)); if (curres == NULL) { @@ -614,7 +677,7 @@ resource_node_start: STR case 0: break; case 1: - mynode = true; + mynode = hadmynode = true; break; default: assert(!"invalid isitme() return value"); Modified: stable/8/sbin/hastd/primary.c ============================================================================== --- stable/8/sbin/hastd/primary.c Thu Dec 30 09:45:26 2010 (r216815) +++ stable/8/sbin/hastd/primary.c Thu Dec 30 09:46:45 2010 (r216816) @@ -1133,6 +1133,15 @@ local_send_thread(void *arg) /* * If READ failed, try to read from remote node. */ + if (ret < 0) { + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%s), trying remote node. ", + strerror(errno)); + } else if (ret != ggio->gctl_length) { + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%zd != %jd), trying remote node. ", + ret, (intmax_t)ggio->gctl_length); + } QUEUE_INSERT1(hio, send, rncomp); continue; } @@ -1141,28 +1150,43 @@ local_send_thread(void *arg) ret = pwrite(res->hr_localfd, ggio->gctl_data, ggio->gctl_length, ggio->gctl_offset + res->hr_localoff); - if (ret < 0) + if (ret < 0) { hio->hio_errors[ncomp] = errno; - else if (ret != ggio->gctl_length) + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%s): ", + strerror(errno)); + } else if (ret != ggio->gctl_length) { hio->hio_errors[ncomp] = EIO; - else + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%zd != %jd): ", + ret, (intmax_t)ggio->gctl_length); + } else { hio->hio_errors[ncomp] = 0; + } break; case BIO_DELETE: ret = g_delete(res->hr_localfd, ggio->gctl_offset + res->hr_localoff, ggio->gctl_length); - if (ret < 0) + if (ret < 0) { hio->hio_errors[ncomp] = errno; - else + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%s): ", + strerror(errno)); + } else { hio->hio_errors[ncomp] = 0; + } break; case BIO_FLUSH: ret = g_flush(res->hr_localfd); - if (ret < 0) + if (ret < 0) { hio->hio_errors[ncomp] = errno; - else + reqlog(LOG_WARNING, 0, ggio, + "Local request failed (%s): ", + strerror(errno)); + } else { hio->hio_errors[ncomp] = 0; + } break; } if (refcount_release(&hio->hio_countdown)) { @@ -1443,7 +1467,9 @@ remote_recv_thread(void *arg) error = nv_get_int16(nv, "error"); if (error != 0) { /* Request failed on remote side. */ - hio->hio_errors[ncomp] = 0; + hio->hio_errors[ncomp] = error; + reqlog(LOG_WARNING, 0, &hio->hio_ggio, + "Remote request failed (%s): ", strerror(error)); nv_free(nv); goto done_queue; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012300946.oBU9kk2e029410>