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; }
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_update(struct list_head *params, struct iface_rec *iface) { struct iface_rec *def_iface; recinfo_t *info; struct user_param *param; 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); list_for_each_entry(param, params, list) { rc = idbm_verify_param(info, param->name); if (rc) goto free_info; }
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; }