/* * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon * by Venkatesh Srinivas * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "hammer2.h" #include #include struct hammer2_media_config { hammer2_volconf_t copy_run; hammer2_volconf_t copy_pend; pthread_t thread; pthread_cond_t cond; int ctl; int fd; int pipefd[2]; /* signal stop */ dmsg_iocom_t iocom; pthread_t iocom_thread; enum { H2MC_STOPPED, H2MC_CONNECT, H2MC_RUNNING } state; }; typedef struct hammer2_media_config hammer2_media_config_t; #define H2CONFCTL_STOP 0x00000001 #define H2CONFCTL_UPDATE 0x00000002 struct diskcon { TAILQ_ENTRY(diskcon) entry; char *disk; }; struct service_node_opaque { char cl_label[64]; char fs_label[64]; dmsg_media_block_t block; int attached; int servicing; int servicefd; }; struct autoconn { TAILQ_ENTRY(autoconn) entry; char *host; int stage; int stopme; int pipefd[2]; /* {read,write} */ enum { AUTOCONN_INACTIVE, AUTOCONN_ACTIVE } state; pthread_t thread; }; #define WS " \r\n" TAILQ_HEAD(, diskcon) diskconq = TAILQ_HEAD_INITIALIZER(diskconq); static pthread_mutex_t diskmtx; static pthread_mutex_t confmtx; static void *service_thread(void *data); static void *udev_thread(void *data); static void *autoconn_thread(void *data); static void master_reconnect(const char *mntpt); static void disk_reconnect(const char *disk); static void disk_disconnect(void *handle); static void udev_check_disks(void); static void hammer2_usrmsg_handler(dmsg_msg_t *msg, int unmanaged); static void *hammer2_volconf_thread(void *info); static void hammer2_volconf_signal(dmsg_iocom_t *iocom); static void hammer2_volconf_start(hammer2_media_config_t *conf, const char *hostname); static void hammer2_volconf_stop(hammer2_media_config_t *conf); static void xdisk_connect(void); /* * Start-up the master listener daemon for the machine. This daemon runs * a UDP discovery protocol, a TCP rendezvous, and scans certain files * and directories for work. * * -- * * The only purpose for the UDP discovery protocol is to determine what * other IPs on the LAN are running the hammer2 service daemon. DNS is not * required to operate, but hostnames (if assigned) must be unique. If * no hostname is assigned the host's IP is used as the name. This name * is broadcast along with the mtime of the originator's private key. * * Receiving hammer2 service daemons which are able to match the label against * /etc/hammer2/remote/