/** * iface_create_ifaces_from_boot_contexts - create ifaces based on boot info * @ifaces: list to store ifaces in * @targets: list of targets to create ifaces from * * This function will create a iface struct based on the boot info * and it will create (or update if existing already) a iface rec in * the ifaces dir based on the info. */ int iface_create_ifaces_from_boot_contexts(struct list_head *ifaces, struct list_head *targets) { struct boot_context *context; struct iface_rec *iface, *tmp_iface; int rc = 0; list_for_each_entry(context, targets, list) { rc = 0; /* use dummy name. If valid it will get overwritten below */ iface = iface_alloc(DEFAULT_IFACENAME, &rc); if (!iface) { log_error("Could not setup iface %s for boot\n", context->iface); goto fail; } if (!iface_setup_from_boot_context(iface, context)) { /* no offload so forget it */ free(iface); continue; } rc = iface_conf_write(iface); if (rc) { log_error("Could not setup default iface conf " "for %s.", iface->name); free(iface); goto fail; } list_add_tail(&iface->list, ifaces); }
int iface_conf_update(struct db_set_param *param, struct iface_rec *iface) { struct iface_rec *def_iface; recinfo_t *info; int rc = 0; def_iface = iface_match_default(iface); if (def_iface) { log_error("iface %s is a special interface and " "cannot be modified.\n", iface->name); return ISCSI_ERR_INVAL; } info = idbm_recinfo_alloc(MAX_KEYS); if (!info) return ISCSI_ERR_NOMEM; idbm_recinfo_iface(iface, info); rc = idbm_verify_param(info, param->name); if (rc) goto free_info; rc = idbm_rec_update_param(info, param->name, param->value, 0); if (rc) goto free_info; rc = iface_conf_write(iface); free_info: free(info); return rc; }
static int iface_setup_binding_from_kern_iface(void *data, struct iface_rec *kern_iface) { struct host_info *hinfo = data; struct iface_rec iface; char iface_path[PATH_MAX]; if (!strlen(hinfo->iface.hwaddress)) { log_error("Invalid offload iSCSI host %u. Missing " "hwaddress. Try upgrading %s driver.\n", hinfo->host_no, hinfo->iface.transport_name); return 0; } memset(&iface, 0, sizeof(struct iface_rec)); strcpy(iface.hwaddress, hinfo->iface.hwaddress); strcpy(iface.transport_name, hinfo->iface.transport_name); if (kern_iface) { iface.iface_num = kern_iface->iface_num; snprintf(iface.name, sizeof(iface.name), "%s.%s.%s.%u", kern_iface->transport_name, kern_iface->hwaddress, iface_get_iptype(kern_iface) == ISCSI_IFACE_TYPE_IPV4 ? "ipv4" : "ipv6", kern_iface->iface_num); } else { snprintf(iface.name, sizeof(iface.name), "%s.%s", hinfo->iface.transport_name, hinfo->iface.hwaddress); } memset(iface_path, 0, sizeof(iface_path)); snprintf(iface_path, PATH_MAX, "%s/%s", IFACE_CONFIG_DIR, iface.name); if (access(iface_path, F_OK) != 0) { /* not found so create it */ if (iface_conf_write(&iface)) { log_error("Could not create default iface conf %s.", iface.name); /* fall through - will not be persistent */ } } return 0; }
idbm_recinfo_iface(iface, info); list_for_each_entry(param, params, list) { rc = idbm_verify_param(info, param->name); if (rc) goto free_info; } list_for_each_entry(param, params, list) { rc = idbm_rec_update_param(info, param->name, param->value, 0); if (rc) goto free_info; } rc = iface_conf_write(iface); free_info: free(info); return rc; } #if 0 /* Unused */ static int iface_get_next_id(void) { struct stat statb; char *iface_conf; int i, rc = ENOSPC; iface_conf = calloc(1, PATH_MAX); if (!iface_conf) return ENOMEM;