Deleted Added
sdiff udiff text old ( 222108 ) new ( 225830 )
full compact
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
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 *

--- 15 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/hastd.c 222108 2011-05-19 23:18:42Z pjd $");
33
34#include <sys/param.h>
35#include <sys/linker.h>
36#include <sys/module.h>
37#include <sys/stat.h>
38#include <sys/wait.h>
39
40#include <err.h>

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

381 if (res0->hr_checksum != res1->hr_checksum)
382 return (true);
383 if (res0->hr_compression != res1->hr_compression)
384 return (true);
385 if (res0->hr_timeout != res1->hr_timeout)
386 return (true);
387 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
388 return (true);
389 }
390 return (false);
391}
392
393static bool
394resource_needs_reload(const struct hast_resource *res0,
395 const struct hast_resource *res1)
396{

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

411 if (res0->hr_checksum != res1->hr_checksum)
412 return (true);
413 if (res0->hr_compression != res1->hr_compression)
414 return (true);
415 if (res0->hr_timeout != res1->hr_timeout)
416 return (true);
417 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
418 return (true);
419 return (false);
420}
421
422static void
423resource_reload(const struct hast_resource *res)
424{
425 struct nv *nvin, *nvout;
426 int error;

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

431 nv_add_uint8(nvout, CONTROL_RELOAD, "cmd");
432 nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr");
433 nv_add_string(nvout, res->hr_sourceaddr, "sourceaddr");
434 nv_add_int32(nvout, (int32_t)res->hr_replication, "replication");
435 nv_add_int32(nvout, (int32_t)res->hr_checksum, "checksum");
436 nv_add_int32(nvout, (int32_t)res->hr_compression, "compression");
437 nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout");
438 nv_add_string(nvout, res->hr_exec, "exec");
439 if (nv_error(nvout) != 0) {
440 nv_free(nvout);
441 pjdlog_error("Unable to allocate header for reload message.");
442 return;
443 }
444 if (hast_proto_send(res, res->hr_ctrl, nvout, NULL, 0) < 0) {
445 pjdlog_errno(LOG_ERR, "Unable to send reload message");
446 nv_free(nvout);

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

586 * Resource role is INIT or SECONDARY.
587 * Resource role is PRIMARY and path to local component or provider
588 * name has changed.
589 * In case of PRIMARY, the worker process will be killed and restarted,
590 * which also means removing /dev/hast/<name> provider and
591 * recreating it.
592 *
593 * We do just reload (send SIGHUP to worker process) if we act as
594 * PRIMARY, but only if remote address, replication mode, timeout or
595 * execution path has changed. For those, there is no need to restart
596 * worker process.
597 * If PRIMARY receives SIGHUP, it will reconnect if remote address or
598 * replication mode has changed or simply set new timeout if only
599 * timeout has changed.
600 */
601 TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) {
602 TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) {
603 if (strcmp(cres->hr_name, nres->hr_name) == 0)
604 break;
605 }
606 PJDLOG_ASSERT(cres != NULL);
607 if (resource_needs_restart(cres, nres)) {

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

622 strlcpy(cres->hr_sourceaddr, nres->hr_sourceaddr,
623 sizeof(cres->hr_sourceaddr));
624 cres->hr_replication = nres->hr_replication;
625 cres->hr_checksum = nres->hr_checksum;
626 cres->hr_compression = nres->hr_compression;
627 cres->hr_timeout = nres->hr_timeout;
628 strlcpy(cres->hr_exec, nres->hr_exec,
629 sizeof(cres->hr_exec));
630 if (cres->hr_workerpid != 0)
631 resource_reload(cres);
632 }
633 }
634
635 yy_config_free(newcfg);
636 pjdlog_info("Configuration reloaded successfully.");
637 return;

--- 590 unchanged lines hidden ---