From c399f0580c6ba387b6aca30c622c8d2739498846 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Mon, 6 Dec 2010 11:06:47 -0800 Subject: [PATCH] ibacm: automatically generate addresses if missing acm_addr.cfg If the acm_addr.cfg file is missing, automatically attempt to generate the file. If no addresses can be assigned to any endpoints because of a missing file, log an error and exit the service. This avoids running a service that is basically useless. This change allows the ib_acm service to execute using defaults without requireing that a user first run 'ib_acme -A -O' or otherwise creating the acm configuration files. Signed-off-by: Sean Hefty --- src/acm.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/acm.c b/src/acm.c index 40f2205..e035741 100644 --- a/src/acm.c +++ b/src/acm.c @@ -203,6 +203,7 @@ static SOCKET listen_socket; static struct acm_client client[FD_SETSIZE - 1]; static FILE *flog; +static FILE *faddr; static lock_t log_lock; PER_THREAD char log_data[ACM_MAX_ADDRESS]; @@ -2249,7 +2250,6 @@ err: static int acm_assign_ep_names(struct acm_ep *ep) { char *dev_name; - FILE *f; char s[120]; char dev[32], addr[32], pkey_str[8]; uint16_t pkey; @@ -2261,12 +2261,8 @@ static int acm_assign_ep_names(struct acm_ep *ep) acm_log(1, "device %s, port %d, pkey 0x%x\n", dev_name, ep->port->port_num, ep->pkey); - if (!(f = fopen(addr_file, "r"))) { - acm_log(0, "ERROR - unable to open acm_addr.cfg file\n"); - return ACM_STATUS_ENODATA; - } - - while (fgets(s, sizeof s, f)) { + rewind(faddr); + while (fgets(s, sizeof s, faddr)) { if (s[0] == '#') continue; @@ -2310,7 +2306,6 @@ static int acm_assign_ep_names(struct acm_ep *ep) } } - fclose(f); return !index; } @@ -2722,6 +2717,22 @@ static FILE *acm_open_log(void) return f; } +static FILE *acm_open_addr_file(void) +{ + FILE *f; + + if ((f = fopen(addr_file, "r"))) + return f; + + acm_log(0, "notice - generating acm_addr.cfg file\n"); + if (!(f = popen("ib_acme -A", "r"))) { + acm_log(0, "ERROR - cannot generate acm_addr.cfg\n"); + return NULL; + } + pclose(f); + return fopen(addr_file, "r"); +} + static int acm_open_lock_file(void) { int lock_fd; @@ -2818,6 +2829,11 @@ int CDECL_FUNC main(int argc, char **argv) DListInit(&timeout_list); event_init(&timeout_event); + if (!(faddr = acm_open_addr_file())) { + acm_log(0, "ERROR - address file not found\n"); + return -1; + } + umad_init(); ibdev = ibv_get_device_list(&dev_cnt); if (!ibdev) { @@ -2830,6 +2846,11 @@ int CDECL_FUNC main(int argc, char **argv) acm_open_dev(ibdev[i]); ibv_free_device_list(ibdev); + if (DListEmpty(&dev_list)) { + acm_log(0, "ERROR - no active devices\n"); + return -1; + } + fclose(faddr); acm_log(1, "initiating multicast joins\n"); acm_join_groups(); -- 2.41.0