diff --git a/etc/cfg-ethx b/etc/cfg-ethx index e2eb330..c5aaf36 100644 --- a/etc/cfg-ethx +++ b/etc/cfg-ethx @@ -8,7 +8,7 @@ FCOE_ENABLE="yes" ## Default: no # Indicate if DCB service is required at the Ethernet port # Normally set to "yes" -DCB_REQUIRED="no" +DCB_REQUIRED="yes" ## Type: yes/no ## Default: no diff --git a/fcoeadm_display.c b/fcoeadm_display.c index f10cfb5..120c608 100644 --- a/fcoeadm_display.c +++ b/fcoeadm_display.c @@ -254,7 +254,6 @@ static void show_full_lun_info(unsigned int hba, unsigned int port, struct dirent *dp; struct port_attributes *rport_attrs; struct port_attributes *port_attrs; - int rc; snprintf(path, sizeof(path), "/sys/class/scsi_device/%u:%u:%u:%u", @@ -288,18 +287,10 @@ static void show_full_lun_info(unsigned int hba, unsigned int port, osname = dp->d_name; - rc = snprintf(npath, sizeof(npath), "%s/%s/", path, osname); - if (rc < 0 || rc >= sizeof(npath)) { - /* error or truncation, bailing out */ - return; - } + snprintf(npath, sizeof(npath), "%s/%s/", path, osname); sa_sys_read_u64(npath, "size", &lba); - rc = snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname); - if (rc < 0 || rc >= sizeof(npath)) { - /* error or truncation, bailing out */ - return; - } + snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname); sa_sys_read_u32(npath, "hw_sector_size", &blksize); } @@ -349,7 +340,6 @@ static void show_short_lun_info(unsigned int hba, unsigned int port, char *capstr = "Unknown"; char *osname = "Unknown"; uint64_t size; - int rc; snprintf(path, sizeof(path), "/sys/class/scsi_device/%u:%u:%u:%u/device/", @@ -373,18 +363,10 @@ static void show_short_lun_info(unsigned int hba, unsigned int port, osname = dp->d_name; - rc = snprintf(npath, sizeof(npath), "%s/%s/", path, osname); - if (rc < 0 || rc >= sizeof(npath)) { - /* error or truncation, bailing out */ - return; - } + snprintf(npath, sizeof(npath), "%s/%s/", path, osname); sa_sys_read_u64(npath, "size", &size); - rc = snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname); - if (rc < 0 || rc >= sizeof(npath)) { - /* error or truncation, bailing out */ - return; - } + snprintf(npath, sizeof(npath), "%s/%s/queue/", path, osname); sa_sys_read_u32(npath, "hw_sector_size", &blksize); } diff --git a/fcoemon.c b/fcoemon.c index ff8a8b8..9a400c5 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -328,6 +328,7 @@ static int fcm_link_socket; static int fcm_link_seq; static void fcm_link_recv(void *); static void fcm_link_getlink(void); +static int fcm_link_buf_check(size_t); static void clear_dcbd_info(struct fcm_netif *ff); static int fcoe_vid_from_ifname(const char *ifname); @@ -353,7 +354,8 @@ char progname[20]; * large enough to fit and expand it if we ever do a read that almost fills it. */ static char *fcm_link_buf; -static size_t fcm_link_buf_size = 8192; /* initial size */ +static size_t fcm_link_buf_size = 4096; /* initial size */ +static const size_t fcm_link_buf_fuzz = 300; /* "almost full" remainder */ /* * A value must be surrounded by quates, e.g. "x". @@ -937,7 +939,6 @@ static struct fcoe_port *fcm_new_vlan(int ifindex, int vid, bool vn2vn) [false] = CLIF_FLAGS_FABRIC, [true] = CLIF_FLAGS_VN2VN, }; - int rc; if (vn2vn) FCM_LOG_DBG("Auto VLAN found vn2vn on VID %d\n", vid); @@ -946,15 +947,8 @@ static struct fcoe_port *fcm_new_vlan(int ifindex, int vid, bool vn2vn) if (rtnl_find_vlan(ifindex, vid, vlan_name)) { rtnl_get_linkname(ifindex, real_name); - rc = snprintf(vlan_name, sizeof(vlan_name), FCOE_VLAN_FORMAT, - real_name, vid); - if (rc >= sizeof(vlan_name)) { - FCM_LOG("Warning: Generating FCoE VLAN device name for" - "interface %s VLAN %d: format resulted in a" - "name larger than IFNAMSIZ\n", real_name, vid); - vlan_name[sizeof(vlan_name) - 1] = 0; - FCM_LOG("\tTruncating VLAN name to %s\n", vlan_name); - } + snprintf(vlan_name, sizeof(vlan_name), FCOE_VLAN_FORMAT, + real_name, vid); vlan_create(ifindex, vid, vlan_name); } rtnl_set_iff_up(0, vlan_name); @@ -1854,22 +1848,8 @@ static void fcm_link_recv(UNUSED void *arg) size_t plen; size_t rlen; - /* check to make sure our receive buffer is large enough, - * or scale it up as needed */ - rc = recv(fcm_link_socket, NULL, 0, MSG_PEEK | MSG_TRUNC); - if (rc > fcm_link_buf_size) { - FCM_LOG_DBG("resizing link buf to %d bytes\n", rc); - void *resize = realloc(fcm_link_buf, rc); - if (resize) { - fcm_link_buf = resize; - fcm_link_buf_size = rc; - } else { - FCM_LOG_ERR(errno, "Failed to allocate link buffer"); - } - } - buf = fcm_link_buf; - rc = recv(fcm_link_socket, buf, fcm_link_buf_size, 0); + rc = read(fcm_link_socket, buf, fcm_link_buf_size); if (rc <= 0) { if (rc < 0) FCM_LOG_ERR(errno, "Error reading from " @@ -1878,6 +1858,11 @@ static void fcm_link_recv(UNUSED void *arg) return; } + if (fcm_link_buf_check(rc)) { + fcm_link_getlink(); + return; + } + hp = (struct nlmsghdr *)buf; rlen = rc; for (hp = (struct nlmsghdr *)buf; NLMSG_OK(hp, rlen); @@ -1942,9 +1927,34 @@ static void fcm_link_getlink(void) msg.nl.nlmsg_pid = getpid(); msg.ifi.ifi_family = AF_UNSPEC; msg.ifi.ifi_type = ARPHRD_ETHER; - rc = send(fcm_link_socket, &msg, sizeof(msg), 0); + rc = write(fcm_link_socket, &msg, sizeof(msg)); if (rc < 0) - FCM_LOG_ERR(errno, "send error"); + FCM_LOG_ERR(errno, "write error"); +} + +/* + * Check for whether buffer needs to grow based on amount read. + * Free's the old buffer so don't use that after this returns non-zero. + */ +static int fcm_link_buf_check(size_t read_len) +{ + char *buf; + size_t len = read_len; + + if (len > fcm_link_buf_size - fcm_link_buf_fuzz) { + len = fcm_link_buf_size; + len = len + len / 2; /* grow by 50% */ + buf = malloc(len); + if (buf != NULL) { + free(fcm_link_buf); + fcm_link_buf = buf; + fcm_link_buf_size = len; + return 1; + } else { + FCM_LOG_ERR(errno, "failed to allocate link buffer"); + } + } + return 0; } static void fcm_fcoe_init(void) @@ -3539,7 +3549,7 @@ static void fcm_srv_receive(void *arg) } cmd = data->cmd; - strncpy(ifname, data->ifname, sizeof(ifname) - 1); + strncpy(ifname, data->ifname, sizeof(data->ifname)); ifname[sizeof(data->ifname)] = 0; if (cmd != CLIF_PID_CMD) { diff --git a/fipvlan.c b/fipvlan.c index 42f89d7..7c00c7c 100644 --- a/fipvlan.c +++ b/fipvlan.c @@ -621,10 +621,8 @@ create_and_start_vlan(struct fcf *fcf, bool vn2vn) real_dev->ifname, fcf->vlan, vlan->ifname); rc = 0; } else { - rc = snprintf(vlan_name, IFNAMSIZ, "%s.%d%s", - real_dev->ifname, fcf->vlan, config.suffix); - if (rc >= IFNAMSIZ) - return -E2BIG; + snprintf(vlan_name, IFNAMSIZ, "%s.%d%s", + real_dev->ifname, fcf->vlan, config.suffix); rc = vlan_create(fcf->ifindex, fcf->vlan, vlan_name); if (rc < 0) printf("Failed to create VLAN device %s\n\t%s\n", diff --git a/lib/sysfs_hba.c b/lib/sysfs_hba.c index 7862154..5cb7fd3 100644 --- a/lib/sysfs_hba.c +++ b/lib/sysfs_hba.c @@ -606,7 +606,7 @@ static int get_ctlr_num(const char *netdev) if (!ctlr) continue; - ctlr_num = atoi(&ctlr[sizeof("ctlr_") - 1]); + ctlr_num = atoi(&ctlr[strlen(ctlr) - 1]); break; } diff --git a/libopenfcoe.c b/libopenfcoe.c index 4ece1ae..07090d5 100644 --- a/libopenfcoe.c +++ b/libopenfcoe.c @@ -59,7 +59,6 @@ static int add_fcoe_fcf_device(struct dirent *dp, void *arg) { struct fcoe_ctlr_device *ctlr = (struct fcoe_ctlr_device *)arg; struct fcoe_fcf_device *fcf; - int rc; if (!strstr(dp->d_name, "fcf") || (!strcmp(dp->d_name, "fcf_dev_loss_tmo"))) @@ -72,10 +71,8 @@ static int add_fcoe_fcf_device(struct dirent *dp, void *arg) memset(fcf, 0, sizeof(struct fcoe_fcf_device)); /* Save the path */ - rc = snprintf(fcf->path, sizeof(fcf->path), - "%s/%s", ctlr->path, dp->d_name); - if (rc >= sizeof(fcf->path)) - goto fail; + snprintf(fcf->path, sizeof(fcf->path), + "%s/%s", ctlr->path, dp->d_name); /* Use the index from the logical enumeration */ fcf->index = atoi(dp->d_name + sizeof("fcf_") - 1); @@ -182,9 +179,7 @@ static int read_fcoe_ctlr_device(struct dirent *dp, void *arg) if (!rc) goto fail; - rc = snprintf(hpath, MAX_STR_LEN, "%s/%s/", SYSFS_FCHOST, fchost); - if (rc < 0 || rc >= MAX_STR_LEN) - goto fail; + sprintf(hpath, "%s/%s/", SYSFS_FCHOST, fchost); rc = sa_sys_read_line(hpath, "symbolic_name", buf, sizeof(buf)); @@ -203,9 +198,7 @@ static int read_fcoe_ctlr_device(struct dirent *dp, void *arg) sa_sys_read_line(ctlr->path, "mode", buf, sizeof(buf)); sa_enum_encode(fip_conn_type_table, buf, &ctlr->mode); - rc = snprintf(lesb_path, sizeof(lesb_path), "%s/lesb/", ctlr->path); - if (rc >= sizeof(lesb_path)) - goto fail; + snprintf(lesb_path, sizeof(lesb_path), "%s/lesb/", ctlr->path); /* Get LESB statistics */ sa_sys_read_u32(lesb_path, "link_fail",