/* * Create a default iface for offload cards. We assume that we will * be able identify each host by MAC. */ void iface_setup_host_bindings(void) { int nr_found = 0; if (idbm_lock()) return; if (access(IFACE_CONFIG_DIR, F_OK) != 0) { if (mkdir(IFACE_CONFIG_DIR, 0660) != 0) { log_error("Could not make %s. HW/OFFLOAD iscsi " "may not be supported", IFACE_CONFIG_DIR); idbm_unlock(); return; } } idbm_unlock(); transport_probe_for_offload(); if (iscsi_sysfs_for_each_host(NULL, &nr_found, __iface_setup_host_bindings)) log_error("Could not scan scsi hosts. HW/OFFLOAD iscsi " "operations may not be supported, or please " "see README for instructions on setting up ifaces."); }
int iface_conf_delete(struct iface_rec *iface) { struct iface_rec *def_iface; char *iface_conf; int rc = 0; def_iface = iface_match_default(iface); if (def_iface) { log_error("iface %s is a special interface and " "cannot be deleted.\n", iface->name); return ISCSI_ERR_INVAL; } iface_conf = calloc(1, PATH_MAX); if (!iface_conf) return ISCSI_ERR_NOMEM; sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name); rc = idbm_lock(); if (rc) goto free_conf; if (unlink(iface_conf)) rc = ISCSI_ERR_IDBM; idbm_unlock(); free_conf: free(iface_conf); return rc; }
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_write(struct iface_rec *iface) { struct iface_rec *def_iface; char *iface_conf; FILE *f; int rc = 0; def_iface = iface_match_default(iface); if (def_iface) { log_error("iface %s is a special interface and " "is not stored in %s.\n", iface->name, IFACE_CONFIG_DIR); return ISCSI_ERR_INVAL; } iface_conf = calloc(1, PATH_MAX); if (!iface_conf) return ISCSI_ERR_NOMEM; sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name); f = fopen(iface_conf, "w"); if (!f) { rc = ISCSI_ERR_IDBM; goto free_conf; } rc = idbm_lock(); if (rc) goto close_f; idbm_print(IDBM_PRINT_TYPE_IFACE, iface, 1, f); idbm_unlock(); close_f: fclose(f); free_conf: free(iface_conf); 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; }