int iface_conf_read(struct iface_rec *iface) { struct iface_rec *def_iface; int rc, retry = 0; def_iface = iface_match_default(iface); if (def_iface) { /* * older tools allowed default to have different * transport_names so we do not want to overwrite * it. */ if (!strcmp(def_iface->name, DEFAULT_IFACENAME)) { if (!strlen(iface->name)) strcpy(iface->name, def_iface->name); if (!strlen(iface->netdev)) strcpy(iface->netdev, def_iface->netdev); if (!strlen(iface->hwaddress)) strcpy(iface->hwaddress, def_iface->hwaddress); if (!strlen(iface->transport_name)) strcpy(iface->transport_name, def_iface->transport_name); if (!strlen(iface->iname)) strcpy(iface->iname, def_iface->iname); } else { iface_init(iface); iface_copy(iface, def_iface); } return 0; } retry_read: rc = idbm_lock(); if (rc) return rc; rc = __iface_conf_read(iface); idbm_unlock(); /* * cmd was run before running -m iface, so force def bindings * creation to see if that was the one requested */ if (retry < 1 && rc == ISCSI_ERR_IDBM) { iface_setup_host_bindings(); retry++; goto retry_read; } return rc; }
int iface_conf_read(struct iface_rec *iface) { struct iface_rec *def_iface; int rc; def_iface = iface_match_default(iface); if (def_iface) { /* * older tools allowed default to have different * transport_names so we do not want to overwrite * it. */ if (!strcmp(def_iface->name, DEFAULT_IFACENAME)) { if (!strlen(iface->name)) strcpy(iface->name, def_iface->name); if (!strlen(iface->netdev)) strcpy(iface->netdev, def_iface->netdev); if (!strlen(iface->hwaddress)) strcpy(iface->hwaddress, def_iface->hwaddress); if (!strlen(iface->transport_name)) strcpy(iface->transport_name, def_iface->transport_name); if (!strlen(iface->iname)) strcpy(iface->iname, def_iface->iname); } else { iface_init(iface); iface_copy(iface, def_iface); } return 0; } rc = idbm_lock(); if (rc) return rc; rc = __iface_conf_read(iface); idbm_unlock(); return rc; }
int iface_for_each_iface(void *data, int skip_def, int *nr_found, iface_op_fn *fn) { DIR *iface_dirfd; struct dirent *iface_dent; struct iface_rec *iface, *def_iface; int err = 0, i = 0; if (!skip_def) { while ((def_iface = default_ifaces[i++])) { iface = iface_alloc(def_iface->name, &err); if (!iface) { log_error("Could not add iface %s.", def_iface->name); continue; } iface_copy(iface, def_iface); err = fn(data, iface); free(iface); if (err) return err; (*nr_found)++; } } iface_dirfd = opendir(IFACE_CONFIG_DIR); if (!iface_dirfd) return errno; while ((iface_dent = readdir(iface_dirfd))) { if (!strcmp(iface_dent->d_name, ".") || !strcmp(iface_dent->d_name, "..")) continue; log_debug(5, "iface_for_each_iface found %s", iface_dent->d_name); iface = iface_alloc(iface_dent->d_name, &err); if (!iface || err) { if (err == ISCSI_ERR_INVAL) log_error("Invalid iface name %s. Must be " "from 1 to %d characters.", iface_dent->d_name, ISCSI_MAX_IFACE_LEN - 1); else log_error("Could not add iface %s.", iface_dent->d_name); continue; } err = idbm_lock(); if (err) { free(iface); continue; } err = __iface_conf_read(iface); idbm_unlock(); if (err) { log_error("Could not read def iface %s (err %d)", iface->name, err); free(iface); continue; } if (!iface_is_valid(iface)) { log_debug(5, "iface is not valid " "Iface settings " iface_fmt, iface_str(iface)); free(iface); continue; } err = fn(data, iface); free(iface); if (err) break; (*nr_found)++; } closedir(iface_dirfd); return err; }