Deleted Added
full compact
hastd.c (222108) hastd.c (225830)
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>
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 $");
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);
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);
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);
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);
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");
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");
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
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
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.
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.
597 * If PRIMARY receives SIGHUP, it will reconnect if remote address or
606 * 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.
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.
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));
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;
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 ---
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 ---