Deleted Added
full compact
primary.c (218218) primary.c (219351)
1/*-
2 * Copyright (c) 2009 The FreeBSD Foundation
1/*-
2 * Copyright (c) 2009 The FreeBSD Foundation
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:

--- 12 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:

--- 12 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 218218 2011-02-03 11:39:49Z pjd $");
32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 219351 2011-03-06 22:56:14Z pjd $");
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/refcount.h>
39#include <sys/stat.h>
40

--- 1863 unchanged lines hidden (view full) ---

1904 const char *vstr;
1905
1906 pjdlog_info("Reloading configuration...");
1907
1908 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
1909 PJDLOG_ASSERT(gres == res);
1910 nv_assert(nv, "remoteaddr");
1911 nv_assert(nv, "replication");
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/refcount.h>
39#include <sys/stat.h>
40

--- 1863 unchanged lines hidden (view full) ---

1904 const char *vstr;
1905
1906 pjdlog_info("Reloading configuration...");
1907
1908 PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
1909 PJDLOG_ASSERT(gres == res);
1910 nv_assert(nv, "remoteaddr");
1911 nv_assert(nv, "replication");
1912 nv_assert(nv, "checksum");
1912 nv_assert(nv, "timeout");
1913 nv_assert(nv, "exec");
1914
1915 ncomps = HAST_NCOMPONENTS;
1916
1913 nv_assert(nv, "timeout");
1914 nv_assert(nv, "exec");
1915
1916 ncomps = HAST_NCOMPONENTS;
1917
1917#define MODIFIED_REMOTEADDR 0x1
1918#define MODIFIED_REPLICATION 0x2
1919#define MODIFIED_TIMEOUT 0x4
1920#define MODIFIED_EXEC 0x8
1918#define MODIFIED_REMOTEADDR 0x01
1919#define MODIFIED_REPLICATION 0x02
1920#define MODIFIED_CHECKSUM 0x04
1921#define MODIFIED_TIMEOUT 0x10
1922#define MODIFIED_EXEC 0x20
1921 modified = 0;
1922
1923 vstr = nv_get_string(nv, "remoteaddr");
1924 if (strcmp(gres->hr_remoteaddr, vstr) != 0) {
1925 /*
1926 * Don't copy res->hr_remoteaddr to gres just yet.
1927 * We want remote_close() to log disconnect from the old
1928 * addresses, not from the new ones.
1929 */
1930 modified |= MODIFIED_REMOTEADDR;
1931 }
1932 vint = nv_get_int32(nv, "replication");
1933 if (gres->hr_replication != vint) {
1934 gres->hr_replication = vint;
1935 modified |= MODIFIED_REPLICATION;
1936 }
1923 modified = 0;
1924
1925 vstr = nv_get_string(nv, "remoteaddr");
1926 if (strcmp(gres->hr_remoteaddr, vstr) != 0) {
1927 /*
1928 * Don't copy res->hr_remoteaddr to gres just yet.
1929 * We want remote_close() to log disconnect from the old
1930 * addresses, not from the new ones.
1931 */
1932 modified |= MODIFIED_REMOTEADDR;
1933 }
1934 vint = nv_get_int32(nv, "replication");
1935 if (gres->hr_replication != vint) {
1936 gres->hr_replication = vint;
1937 modified |= MODIFIED_REPLICATION;
1938 }
1939 vint = nv_get_int32(nv, "checksum");
1940 if (gres->hr_checksum != vint) {
1941 gres->hr_checksum = vint;
1942 modified |= MODIFIED_CHECKSUM;
1943 }
1937 vint = nv_get_int32(nv, "timeout");
1938 if (gres->hr_timeout != vint) {
1939 gres->hr_timeout = vint;
1940 modified |= MODIFIED_TIMEOUT;
1941 }
1942 vstr = nv_get_string(nv, "exec");
1943 if (strcmp(gres->hr_exec, vstr) != 0) {
1944 strlcpy(gres->hr_exec, vstr, sizeof(gres->hr_exec));
1945 modified |= MODIFIED_EXEC;
1946 }
1947
1948 /*
1944 vint = nv_get_int32(nv, "timeout");
1945 if (gres->hr_timeout != vint) {
1946 gres->hr_timeout = vint;
1947 modified |= MODIFIED_TIMEOUT;
1948 }
1949 vstr = nv_get_string(nv, "exec");
1950 if (strcmp(gres->hr_exec, vstr) != 0) {
1951 strlcpy(gres->hr_exec, vstr, sizeof(gres->hr_exec));
1952 modified |= MODIFIED_EXEC;
1953 }
1954
1955 /*
1949 * If only timeout was modified we only need to change it without
1950 * reconnecting.
1956 * Change timeout for connected sockets.
1957 * Don't bother if we need to reconnect.
1951 */
1958 */
1952 if (modified == MODIFIED_TIMEOUT) {
1959 if ((modified & MODIFIED_TIMEOUT) != 0 &&
1960 (modified & (MODIFIED_REMOTEADDR | MODIFIED_REPLICATION)) == 0) {
1953 for (ii = 0; ii < ncomps; ii++) {
1954 if (!ISREMOTE(ii))
1955 continue;
1956 rw_rlock(&hio_remote_lock[ii]);
1957 if (!ISCONNECTED(gres, ii)) {
1958 rw_unlock(&hio_remote_lock[ii]);
1959 continue;
1960 }

--- 4 unchanged lines hidden (view full) ---

1965 "Unable to set connection timeout");
1966 }
1967 if (proto_timeout(gres->hr_remoteout,
1968 gres->hr_timeout) < 0) {
1969 pjdlog_errno(LOG_WARNING,
1970 "Unable to set connection timeout");
1971 }
1972 }
1961 for (ii = 0; ii < ncomps; ii++) {
1962 if (!ISREMOTE(ii))
1963 continue;
1964 rw_rlock(&hio_remote_lock[ii]);
1965 if (!ISCONNECTED(gres, ii)) {
1966 rw_unlock(&hio_remote_lock[ii]);
1967 continue;
1968 }

--- 4 unchanged lines hidden (view full) ---

1973 "Unable to set connection timeout");
1974 }
1975 if (proto_timeout(gres->hr_remoteout,
1976 gres->hr_timeout) < 0) {
1977 pjdlog_errno(LOG_WARNING,
1978 "Unable to set connection timeout");
1979 }
1980 }
1973 } else if ((modified &
1974 (MODIFIED_REMOTEADDR | MODIFIED_REPLICATION)) != 0) {
1981 }
1982 if ((modified & (MODIFIED_REMOTEADDR | MODIFIED_REPLICATION)) != 0) {
1975 for (ii = 0; ii < ncomps; ii++) {
1976 if (!ISREMOTE(ii))
1977 continue;
1978 remote_close(gres, ii);
1979 }
1980 if (modified & MODIFIED_REMOTEADDR) {
1981 vstr = nv_get_string(nv, "remoteaddr");
1982 strlcpy(gres->hr_remoteaddr, vstr,
1983 sizeof(gres->hr_remoteaddr));
1984 }
1985 }
1986#undef MODIFIED_REMOTEADDR
1987#undef MODIFIED_REPLICATION
1983 for (ii = 0; ii < ncomps; ii++) {
1984 if (!ISREMOTE(ii))
1985 continue;
1986 remote_close(gres, ii);
1987 }
1988 if (modified & MODIFIED_REMOTEADDR) {
1989 vstr = nv_get_string(nv, "remoteaddr");
1990 strlcpy(gres->hr_remoteaddr, vstr,
1991 sizeof(gres->hr_remoteaddr));
1992 }
1993 }
1994#undef MODIFIED_REMOTEADDR
1995#undef MODIFIED_REPLICATION
1996#undef MODIFIED_CHECKSUM
1988#undef MODIFIED_TIMEOUT
1989#undef MODIFIED_EXEC
1990
1991 pjdlog_info("Configuration reloaded successfully.");
1992}
1993
1994static void
1995guard_one(struct hast_resource *res, unsigned int ncomp)

--- 102 unchanged lines hidden ---
1997#undef MODIFIED_TIMEOUT
1998#undef MODIFIED_EXEC
1999
2000 pjdlog_info("Configuration reloaded successfully.");
2001}
2002
2003static void
2004guard_one(struct hast_resource *res, unsigned int ncomp)

--- 102 unchanged lines hidden ---