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 225830 2011-09-28 13:08:51Z 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 * When metaflush has changed we don't really need restart,
391 * but it is just easier this way.
392 */
393 if (res0->hr_metaflush != res1->hr_metaflush)
394 return (true);
395 }
396 return (false);
397}
398
399static bool
400resource_needs_reload(const struct hast_resource *res0,
401 const struct hast_resource *res1)
402{
--- 14 unchanged lines hidden (view full) ---
417 if (res0->hr_checksum != res1->hr_checksum)
418 return (true);
419 if (res0->hr_compression != res1->hr_compression)
420 return (true);
421 if (res0->hr_timeout != res1->hr_timeout)
422 return (true);
423 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
424 return (true);
425 if (res0->hr_metaflush != res1->hr_metaflush)
426 return (true);
427 return (false);
428}
429
430static void
431resource_reload(const struct hast_resource *res)
432{
433 struct nv *nvin, *nvout;
434 int error;
--- 4 unchanged lines hidden (view full) ---
439 nv_add_uint8(nvout, CONTROL_RELOAD, "cmd");
440 nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr");
441 nv_add_string(nvout, res->hr_sourceaddr, "sourceaddr");
442 nv_add_int32(nvout, (int32_t)res->hr_replication, "replication");
443 nv_add_int32(nvout, (int32_t)res->hr_checksum, "checksum");
444 nv_add_int32(nvout, (int32_t)res->hr_compression, "compression");
445 nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout");
446 nv_add_string(nvout, res->hr_exec, "exec");
447 nv_add_int32(nvout, (int32_t)res->hr_metaflush, "metaflush");
448 if (nv_error(nvout) != 0) {
449 nv_free(nvout);
450 pjdlog_error("Unable to allocate header for reload message.");
451 return;
452 }
453 if (hast_proto_send(res, res->hr_ctrl, nvout, NULL, 0) < 0) {
454 pjdlog_errno(LOG_ERR, "Unable to send reload message");
455 nv_free(nvout);
--- 139 unchanged lines hidden (view full) ---
595 * Resource role is INIT or SECONDARY.
596 * Resource role is PRIMARY and path to local component or provider
597 * name has changed.
598 * In case of PRIMARY, the worker process will be killed and restarted,
599 * which also means removing /dev/hast/<name> provider and
600 * recreating it.
601 *
602 * We do just reload (send SIGHUP to worker process) if we act as
603 * PRIMARY, but only if remote address, source address, replication
604 * mode, timeout, execution path or metaflush has changed.
605 * For those, there is no need to restart worker process.
606 * If PRIMARY receives SIGHUP, it will reconnect if remote address or
607 * source address has changed or it will set new timeout if only timeout
608 * has changed or it will update metaflush if only metaflush has
609 * changed.
610 */
611 TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) {
612 TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) {
613 if (strcmp(cres->hr_name, nres->hr_name) == 0)
614 break;
615 }
616 PJDLOG_ASSERT(cres != NULL);
617 if (resource_needs_restart(cres, nres)) {
--- 14 unchanged lines hidden (view full) ---
632 strlcpy(cres->hr_sourceaddr, nres->hr_sourceaddr,
633 sizeof(cres->hr_sourceaddr));
634 cres->hr_replication = nres->hr_replication;
635 cres->hr_checksum = nres->hr_checksum;
636 cres->hr_compression = nres->hr_compression;
637 cres->hr_timeout = nres->hr_timeout;
638 strlcpy(cres->hr_exec, nres->hr_exec,
639 sizeof(cres->hr_exec));
640 cres->hr_metaflush = nres->hr_metaflush;
641 if (cres->hr_workerpid != 0)
642 resource_reload(cres);
643 }
644 }
645
646 yy_config_free(newcfg);
647 pjdlog_info("Configuration reloaded successfully.");
648 return;
--- 590 unchanged lines hidden ---
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 225830 2011-09-28 13:08:51Z 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 * When metaflush has changed we don't really need restart,
391 * but it is just easier this way.
392 */
393 if (res0->hr_metaflush != res1->hr_metaflush)
394 return (true);
395 }
396 return (false);
397}
398
399static bool
400resource_needs_reload(const struct hast_resource *res0,
401 const struct hast_resource *res1)
402{
--- 14 unchanged lines hidden (view full) ---
417 if (res0->hr_checksum != res1->hr_checksum)
418 return (true);
419 if (res0->hr_compression != res1->hr_compression)
420 return (true);
421 if (res0->hr_timeout != res1->hr_timeout)
422 return (true);
423 if (strcmp(res0->hr_exec, res1->hr_exec) != 0)
424 return (true);
425 if (res0->hr_metaflush != res1->hr_metaflush)
426 return (true);
427 return (false);
428}
429
430static void
431resource_reload(const struct hast_resource *res)
432{
433 struct nv *nvin, *nvout;
434 int error;
--- 4 unchanged lines hidden (view full) ---
439 nv_add_uint8(nvout, CONTROL_RELOAD, "cmd");
440 nv_add_string(nvout, res->hr_remoteaddr, "remoteaddr");
441 nv_add_string(nvout, res->hr_sourceaddr, "sourceaddr");
442 nv_add_int32(nvout, (int32_t)res->hr_replication, "replication");
443 nv_add_int32(nvout, (int32_t)res->hr_checksum, "checksum");
444 nv_add_int32(nvout, (int32_t)res->hr_compression, "compression");
445 nv_add_int32(nvout, (int32_t)res->hr_timeout, "timeout");
446 nv_add_string(nvout, res->hr_exec, "exec");
447 nv_add_int32(nvout, (int32_t)res->hr_metaflush, "metaflush");
448 if (nv_error(nvout) != 0) {
449 nv_free(nvout);
450 pjdlog_error("Unable to allocate header for reload message.");
451 return;
452 }
453 if (hast_proto_send(res, res->hr_ctrl, nvout, NULL, 0) < 0) {
454 pjdlog_errno(LOG_ERR, "Unable to send reload message");
455 nv_free(nvout);
--- 139 unchanged lines hidden (view full) ---
595 * Resource role is INIT or SECONDARY.
596 * Resource role is PRIMARY and path to local component or provider
597 * name has changed.
598 * In case of PRIMARY, the worker process will be killed and restarted,
599 * which also means removing /dev/hast/<name> provider and
600 * recreating it.
601 *
602 * We do just reload (send SIGHUP to worker process) if we act as
603 * PRIMARY, but only if remote address, source address, replication
604 * mode, timeout, execution path or metaflush has changed.
605 * For those, there is no need to restart worker process.
606 * If PRIMARY receives SIGHUP, it will reconnect if remote address or
607 * source address has changed or it will set new timeout if only timeout
608 * has changed or it will update metaflush if only metaflush has
609 * changed.
610 */
611 TAILQ_FOREACH_SAFE(nres, &newcfg->hc_resources, hr_next, tres) {
612 TAILQ_FOREACH(cres, &cfg->hc_resources, hr_next) {
613 if (strcmp(cres->hr_name, nres->hr_name) == 0)
614 break;
615 }
616 PJDLOG_ASSERT(cres != NULL);
617 if (resource_needs_restart(cres, nres)) {
--- 14 unchanged lines hidden (view full) ---
632 strlcpy(cres->hr_sourceaddr, nres->hr_sourceaddr,
633 sizeof(cres->hr_sourceaddr));
634 cres->hr_replication = nres->hr_replication;
635 cres->hr_checksum = nres->hr_checksum;
636 cres->hr_compression = nres->hr_compression;
637 cres->hr_timeout = nres->hr_timeout;
638 strlcpy(cres->hr_exec, nres->hr_exec,
639 sizeof(cres->hr_exec));
640 cres->hr_metaflush = nres->hr_metaflush;
641 if (cres->hr_workerpid != 0)
642 resource_reload(cres);
643 }
644 }
645
646 yy_config_free(newcfg);
647 pjdlog_info("Configuration reloaded successfully.");
648 return;
--- 590 unchanged lines hidden ---