Commit 7e2e14ba authored by Tunahan Kaya's avatar Tunahan Kaya
Browse files

changed function of -l option. Selects first non localhost by default (if option not defined)

parent c87514a1
Loading
Loading
Loading
Loading
Loading
+47 −2
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@
#include <daemon/backend/data/chunk_storage.hpp>
#include <daemon/util.hpp>

#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdio.h>
#include <arpa/inet.h>
#ifdef GKFS_ENABLE_AGIOS
#include <daemon/scheduler/agios.hpp>
#endif
@@ -389,6 +394,45 @@ initialize_loggers() {
    gkfs::log::setup(logger_names, level, path);
}

string
get_host_default(){
    char          buf[1024];
    struct ifconf ifc;
    struct ifreq *ifr;
    int           sck;
    int           nInterfaces;
    int           i;

    /* Get a socket handle. */
    sck = socket(AF_INET, SOCK_DGRAM, 0);
    if(sck < 0){
        perror("socket");
        return ""s;
    }

    /* Query available interfaces. */
    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;
    if(ioctl(sck, SIOCGIFCONF, &ifc) < 0){
        perror("ioctl(SIOCGIFCONF)");
        return ""s;
    }

    /* Iterate through the list of interfaces. */
    ifr         = ifc.ifc_req;
    nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
    for(i = 0; i < nInterfaces; i++){
        struct ifreq *item = &ifr[i];

        if(strcmp(item->ifr_name, "lo") != 0)
            return inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr);
    }
    if(nInterfaces > 0)
        return inet_ntoa(((struct sockaddr_in *)&(&ifr[0])->ifr_addr)->sin_addr);
    return ""s;
}


/**
 *
 * @param vm
@@ -430,7 +474,8 @@ parse_input(const po::variables_map& vm) {
        }
    } else {
        if(rpc_protocol != gkfs::rpc::protocol::ofi_verbs)
            addr = gkfs::rpc::get_my_hostname(true);
            addr = get_host_default();

    }

    GKFS_DATA->rpc_protocol(rpc_protocol);
@@ -512,7 +557,7 @@ main(int argc, const char* argv[]) {
            "Metadata directory where GekkoFS' RocksDB data directory is located. If not set, rootdir is used.");
    desc.add_options()(
            "listen,l", po::value<string>(),
            "Address or interface to bind the daemon to. Default: local hostname.\n"
            "Address or interface to bind the daemon to. Default: First non-localhost interface.\n"
            "When used with ofi+verbs the FI_VERBS_IFACE environment variable is set accordingly "
            "which associates the verbs device with the network interface. In case FI_VERBS_IFACE "
            "is already defined, the argument is ignored. Default 'ib'.");