From owner-svn-src-all@FreeBSD.ORG Thu Jun 17 19:17:31 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9BD79106566B; Thu, 17 Jun 2010 19:17:31 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 897658FC12; Thu, 17 Jun 2010 19:17:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o5HJHVac024155; Thu, 17 Jun 2010 19:17:31 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o5HJHV4n024146; Thu, 17 Jun 2010 19:17:31 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201006171917.o5HJHV4n024146@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Thu, 17 Jun 2010 19:17:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209263 - stable/8/sbin/hastd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2010 19:17:31 -0000 Author: pjd Date: Thu Jun 17 19:17:31 2010 New Revision: 209263 URL: http://svn.freebsd.org/changeset/base/209263 Log: MFC r209175,r209177,r209179,r209180,r209181,r209182,r209183,r209184,r209185: r209175: Eliminate dead code. Found by: Coverity Prevent CID: 5158 r209177: Remove macros that are not really needed. The idea was to have them in case we grow more descriptors, but I'll reconsider readding them once we get there. Passing (a = b) expression to FD_ISSET() is bad idea, as FD_ISSET() evaluates its argument twice. Found by: Coverity Prevent CID: 5243 r209179: Plug memory leaks. Found by: Coverity Prevent CID: 7052, 7053, 7054, 7055 r209180: Plug memory leak. Found by: Coverity Prevent CID: 7051 r209181: Plug memory leak. Found by: Coverity Prevent CID: 7056 r209182: Plug memory leak. Found by: Coverity Prevent CID: 7057 r209183: Initialize gctl_seq for synchronization requests. Reported by: hiroshi@soupacific.com Analysed by: Mikolaj Golub Tested by: hiroshi@soupacific.com, Mikolaj Golub r209184: Fix typos. r209185: Correct various log messages. Submitted by: Mikolaj Golub Modified: stable/8/sbin/hastd/ebuf.c stable/8/sbin/hastd/hast_proto.c stable/8/sbin/hastd/hastd.c stable/8/sbin/hastd/metadata.c stable/8/sbin/hastd/nv.c stable/8/sbin/hastd/primary.c stable/8/sbin/hastd/secondary.c Directory Properties: stable/8/sbin/hastd/ (props changed) Modified: stable/8/sbin/hastd/ebuf.c ============================================================================== --- stable/8/sbin/hastd/ebuf.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/ebuf.c Thu Jun 17 19:17:31 2010 (r209263) @@ -55,8 +55,8 @@ struct ebuf { size_t eb_size; }; -static int ebuf_head_extent(struct ebuf *eb, size_t size); -static int ebuf_tail_extent(struct ebuf *eb, size_t size); +static int ebuf_head_extend(struct ebuf *eb, size_t size); +static int ebuf_tail_extend(struct ebuf *eb, size_t size); struct ebuf * ebuf_alloc(size_t size) @@ -110,7 +110,7 @@ ebuf_add_head(struct ebuf *eb, const voi * We can't add more entries at the front, so we have to extend * our buffer. */ - if (ebuf_head_extent(eb, size) < 0) + if (ebuf_head_extend(eb, size) < 0) return (-1); } assert(size <= (size_t)(eb->eb_used - eb->eb_start)); @@ -137,13 +137,13 @@ ebuf_add_tail(struct ebuf *eb, const voi * We can't add more entries at the back, so we have to extend * our buffer. */ - if (ebuf_tail_extent(eb, size) < 0) + if (ebuf_tail_extend(eb, size) < 0) return (-1); } assert(size <= (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size))); /* - * If data is NULL the caller just wants to reserve place. + * If data is NULL the caller just wants to reserve space. */ if (data != NULL) bcopy(data, eb->eb_used + eb->eb_size, size); @@ -203,7 +203,7 @@ ebuf_size(struct ebuf *eb) * Function adds size + (PAGE_SIZE / 4) bytes at the front of the buffer.. */ static int -ebuf_head_extent(struct ebuf *eb, size_t size) +ebuf_head_extend(struct ebuf *eb, size_t size) { unsigned char *newstart, *newused; size_t newsize; @@ -231,7 +231,7 @@ ebuf_head_extent(struct ebuf *eb, size_t * Function adds size + ((3 * PAGE_SIZE) / 4) bytes at the back. */ static int -ebuf_tail_extent(struct ebuf *eb, size_t size) +ebuf_tail_extend(struct ebuf *eb, size_t size) { unsigned char *newstart; size_t newsize; Modified: stable/8/sbin/hastd/hast_proto.c ============================================================================== --- stable/8/sbin/hastd/hast_proto.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/hast_proto.c Thu Jun 17 19:17:31 2010 (r209263) @@ -329,9 +329,7 @@ hast_proto_recv_hdr(struct proto_conn *c *nvp = nv; return (0); fail: - if (nv != NULL) - nv_free(nv); - else if (eb != NULL) + if (eb != NULL) ebuf_free(eb); return (-1); } Modified: stable/8/sbin/hastd/hastd.c ============================================================================== --- stable/8/sbin/hastd/hastd.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/hastd.c Thu Jun 17 19:17:31 2010 (r209263) @@ -200,7 +200,7 @@ listen_accept(void) proto_local_address(conn, laddr, sizeof(laddr)); proto_remote_address(conn, raddr, sizeof(raddr)); - pjdlog_info("Connection from %s to %s.", laddr, raddr); + pjdlog_info("Connection from %s to %s.", raddr, laddr); /* Error in setting timeout is not critical, but why should it fail? */ if (proto_timeout(conn, HAST_TIMEOUT) < 0) @@ -286,7 +286,7 @@ listen_accept(void) if (token != NULL && memcmp(token, res->hr_token, sizeof(res->hr_token)) != 0) { pjdlog_error("Token received from %s doesn't match.", raddr); - nv_add_stringf(nverr, "errmsg", "Toke doesn't match."); + nv_add_stringf(nverr, "errmsg", "Token doesn't match."); goto fail; } /* @@ -400,7 +400,11 @@ static void main_loop(void) { fd_set rfds, wfds; - int fd, maxfd, ret; + int cfd, lfd, maxfd, ret; + + cfd = proto_descriptor(cfg->hc_controlconn); + lfd = proto_descriptor(cfg->hc_listenconn); + maxfd = cfd > lfd ? cfd : lfd; for (;;) { if (sigchld_received) { @@ -412,22 +416,13 @@ main_loop(void) hastd_reload(); } - maxfd = 0; + /* Setup descriptors for select(2). */ FD_ZERO(&rfds); + FD_SET(cfd, &rfds); + FD_SET(lfd, &rfds); FD_ZERO(&wfds); - - /* Setup descriptors for select(2). */ -#define SETUP_FD(conn) do { \ - fd = proto_descriptor(conn); \ - if (fd >= 0) { \ - maxfd = fd > maxfd ? fd : maxfd; \ - FD_SET(fd, &rfds); \ - FD_SET(fd, &wfds); \ - } \ -} while (0) - SETUP_FD(cfg->hc_controlconn); - SETUP_FD(cfg->hc_listenconn); -#undef SETUP_FD + FD_SET(cfd, &wfds); + FD_SET(lfd, &wfds); ret = select(maxfd + 1, &rfds, &wfds, NULL, NULL); if (ret == -1) { @@ -437,13 +432,10 @@ main_loop(void) pjdlog_exit(EX_OSERR, "select() failed"); } -#define ISSET_FD(conn) \ - (FD_ISSET((fd = proto_descriptor(conn)), &rfds) || FD_ISSET(fd, &wfds)) - if (ISSET_FD(cfg->hc_controlconn)) + if (FD_ISSET(cfd, &rfds) || FD_ISSET(cfd, &wfds)) control_handle(cfg); - if (ISSET_FD(cfg->hc_listenconn)) + if (FD_ISSET(lfd, &rfds) || FD_ISSET(lfd, &wfds)) listen_accept(); -#undef ISSET_FD } } Modified: stable/8/sbin/hastd/metadata.c ============================================================================== --- stable/8/sbin/hastd/metadata.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/metadata.c Thu Jun 17 19:17:31 2010 (r209263) @@ -96,6 +96,7 @@ metadata_read(struct hast_resource *res, rerrno = errno; pjdlog_errno(LOG_ERR, "Unable to allocate memory to read metadata"); + ebuf_free(eb); goto fail; } buf = ebuf_data(eb, NULL); @@ -154,6 +155,7 @@ metadata_read(struct hast_resource *res, nv_free(nv); goto fail; } + nv_free(nv); return (0); fail: if (opened_here) { @@ -172,6 +174,7 @@ metadata_write(struct hast_resource *res unsigned char *buf, *ptr; size_t size; ssize_t done; + int ret; buf = calloc(1, METADATA_SIZE); if (buf == NULL) { @@ -180,6 +183,8 @@ metadata_write(struct hast_resource *res return (-1); } + ret = -1; + nv = nv_alloc(); nv_add_string(nv, res->hr_name, "resource"); nv_add_uint64(nv, (uint64_t)res->hr_datasize, "datasize"); @@ -199,7 +204,7 @@ metadata_write(struct hast_resource *res nv_add_string(nv, role2str(res->hr_role), "prevrole"); if (nv_error(nv) != 0) { pjdlog_error("Unable to create metadata."); - goto fail; + goto end; } res->hr_previous_role = res->hr_role; eb = nv_hton(nv); @@ -211,12 +216,11 @@ metadata_write(struct hast_resource *res done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0); if (done < 0 || done != METADATA_SIZE) { pjdlog_errno(LOG_ERR, "Unable to write metadata"); - goto fail; + goto end; } - - return (0); -fail: + ret = 0; +end: free(buf); nv_free(nv); - return (-1); + return (ret); } Modified: stable/8/sbin/hastd/nv.c ============================================================================== --- stable/8/sbin/hastd/nv.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/nv.c Thu Jun 17 19:17:31 2010 (r209263) @@ -707,8 +707,10 @@ nv_add(struct nv *nv, const unsigned cha assert(errno != 0); if (nv->nv_error == 0) nv->nv_error = errno; + free(nvh); return; } + free(nvh); /* Add the actual data. */ if (ebuf_add_tail(nv->nv_ebuf, value, vsize) < 0) { assert(errno != 0); Modified: stable/8/sbin/hastd/primary.c ============================================================================== --- stable/8/sbin/hastd/primary.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/primary.c Thu Jun 17 19:17:31 2010 (r209263) @@ -195,7 +195,10 @@ static pthread_mutex_t metadata_lock; mtx_unlock(&hio_##name##_list_lock); \ } while (0) -#define SYNCREQ(hio) do { (hio)->hio_ggio.gctl_unit = -1; } while (0) +#define SYNCREQ(hio) do { \ + (hio)->hio_ggio.gctl_unit = -1; \ + (hio)->hio_ggio.gctl_seq = 1; \ +} while (0) #define ISSYNCREQ(hio) ((hio)->hio_ggio.gctl_unit == -1) #define SYNCREQDONE(hio) do { (hio)->hio_ggio.gctl_unit = -2; } while (0) #define ISSYNCREQDONE(hio) ((hio)->hio_ggio.gctl_unit == -2) @@ -447,6 +450,7 @@ init_local(struct hast_resource *res) primary_exit(EX_NOINPUT, "Unable to read activemap"); } activemap_copyin(res->hr_amp, buf, mapsize); + free(buf); if (res->hr_resuid != 0) return; /* Modified: stable/8/sbin/hastd/secondary.c ============================================================================== --- stable/8/sbin/hastd/secondary.c Thu Jun 17 19:06:11 2010 (r209262) +++ stable/8/sbin/hastd/secondary.c Thu Jun 17 19:17:31 2010 (r209263) @@ -295,6 +295,7 @@ init_remote(struct hast_resource *res, s nv_free(nvout); exit(EX_TEMPFAIL); } + nv_free(nvout); if (res->hr_secondary_localcnt > res->hr_primary_remotecnt && res->hr_primary_localcnt > res->hr_secondary_remotecnt) { /* Exit on split-brain. */ @@ -687,7 +688,7 @@ send_thread(void *arg) pjdlog_exit(EX_TEMPFAIL, "Unable to send reply."); } nv_free(nvout); - pjdlog_debug(2, "disk: (%p) Moving request to the free queue.", + pjdlog_debug(2, "send: (%p) Moving request to the free queue.", hio); nv_free(hio->hio_nv); hio->hio_error = 0;