diff -aurp open-iscsi/usr/config.h open-iscsi.db/usr/config.h
--- open-iscsi/usr/config.h	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/config.h	2006-08-21 04:12:02.000000000 -0400
@@ -40,7 +40,7 @@
 #define TCP_WINDOW_SIZE (256 * 1024)
 
 /* number of possible connections per session */
-#define ISCSI_CONN_MAX		16
+#define ISCSI_CONN_MAX		1
 
 /* database version control */
 #define IDBM_VERSION		0x05
@@ -188,7 +188,6 @@ typedef struct session_rec {
 #define ISCSI_TRANSPORT_NAME_MAXLEN 16
 
 typedef struct node_rec {
-	int			id;
 	int			dbversion;
 	char			name[TARGET_NAME_MAXLEN];
 	char			transport_name[ISCSI_TRANSPORT_NAME_MAXLEN];
diff -aurp open-iscsi/usr/idbm.c open-iscsi.db/usr/idbm.c
--- open-iscsi/usr/idbm.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/idbm.c	2006-08-21 04:02:48.000000000 -0400
@@ -24,23 +24,16 @@
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <stdarg.h>
+#include <dirent.h>
 #include <sys/stat.h>
 #include <sys/file.h>
-
-#if defined(Linux)
-#define DB_DBM_HSEARCH 1
-#include <db.h>
-#elif defined(FreeBSD)
-#define DB_DBM_HSEARCH 1
-#include <ndbm.h>
-#endif
+#include <sys/types.h>
 
 #include "idbm.h"
 #include "log.h"
 #include "util.h"
 
-#define IDBM_LOCK_EX	2    /* Exclusive lock.  */
-#define IDBM_LOCK_UN	8    /* Unlock.  */
 #define IDBM_HIDE	0    /* Hide parameter when print. */
 #define IDBM_SHOW	1    /* Show parameter when print. */
 #define IDBM_MASKED	2    /* Show "stars" instead of real value when print */
@@ -51,8 +44,6 @@
 	if (strlen((char*)_rec->_name)) \
 		strncpy((char*)_info[_n].value, (char*)_rec->_name, \
 			VALUE_MAXVAL); \
-	else \
-		strcpy((char*)_info[_n].value, "<empty>"); \
 	_info[_n].data = &_rec->_name; \
 	_info[_n].data_len = sizeof(_rec->_name); \
 	_info[_n].visible = _show; \
@@ -99,40 +90,6 @@
 	_n++; \
 } while(0)
 
-static int
-idbm_dbversion_check(int dbversion)
-{
-	if (dbversion != IDBM_VERSION) {
-		log_error("idbm: dbversion mismatch: %d.%d != %d.%d: "
-			  "expecting v.%d.%d, exiting...",
-			  (0xf0 & dbversion)>>4, 0xf & dbversion,
-			  (0xf0 & IDBM_VERSION)>>4, 0xf & IDBM_VERSION,
-			  (0xf0 & IDBM_VERSION)>>4, 0xf & IDBM_VERSION);
-		log_warning("Sorry! We currently do not support an "
-			    "upgrade option. Please run 'iscsiadm -m db -R' "
-			    "to remove the existing database. Then rediscover "
-			    "and modify session parameters again.");
-		return -1;
-	}
-	return 0;
-}
-
-static int
-idbm_uniq_id(char *name)
-{
-	unsigned long h = 0, g;
-	static int M = 0xFFFFFF;
-
-	while (*name) {
-		h = ( h << 4 ) + *name++;
-		if ((g = h & 0xF0000000L))
-			h ^= g >> 23;
-
-		h &= ~g;
-	}
-	return h % M;
-}
-
 char *
 get_iscsi_initiatorname(char *pathname)
 {
@@ -278,25 +235,6 @@ idbm_update_discovery(discovery_rec_t *r
 		 u.sendtargets.conn_timeo.ping_timeout);
 }
 
-static char*
-idbm_hash_discovery(discovery_rec_t *rec)
-{
-	char *hash = malloc(HASH_MAXLEN);
-
-	if (!hash) {
-		log_error("out of memory on hash allocation");
-		return NULL;
-	}
-
-	if (rec->type == DISCOVERY_TYPE_SENDTARGETS) {
-		snprintf(hash, HASH_MAXLEN, "%s:%d",
-			rec->u.sendtargets.address,
-			rec->u.sendtargets.port);
-	}
-
-	return hash;
-}
-
 static void
 idbm_update_node(node_rec_t *rec, node_rec_t *newrec)
 {
@@ -366,294 +304,6 @@ idbm_update_node(node_rec_t *rec, node_r
 	}
 }
 
-static char*
-idbm_hash_node(discovery_rec_t *drec, node_rec_t *nrec)
-{
-	char *hash = calloc(1, HASH_MAXLEN);
-
-	if (!hash) {
-		log_error("out of memory on hash allocation");
-		return NULL;
-	}
-
-	if (drec == NULL) {
-		snprintf(hash, HASH_MAXLEN, "%s:%d,%d#%s",
-			nrec->conn[0].address,
-			nrec->conn[0].port,
-			nrec->tpgt,
-			nrec->name);
-		return hash;
-	}
-
-	if (drec->type == DISCOVERY_TYPE_SENDTARGETS) {
-		snprintf(hash, HASH_MAXLEN, "%s:%d#%s:%d,%d#%s",
-			drec->u.sendtargets.address,
-			drec->u.sendtargets.port,
-			nrec->conn[0].address,
-			nrec->conn[0].port,
-			nrec->tpgt,
-			nrec->name);
-	}
-
-	return hash;
-}
-
-static void*
-idbm_read(DBM *dbm, char *hash)
-{
-	datum key, data;
-
-	key.dptr = hash;
-	key.dsize = strlen(hash) + 1; /* null-terminated string */
-
-	data = dbm_fetch(dbm, key);
-	if (data.dsize > 0) {
-		return data.dptr;
-	}
-
-	log_debug(7, "key '%s' not found", hash);
-	return NULL;
-}
-
-static void*
-idbm_read_with_id(DBM *dbm, int rec_id)
-{
-	datum key, data;
-
-	for (key=dbm_firstkey(dbm); key.dptr != NULL; key=dbm_nextkey(dbm)) {
-		data = dbm_fetch(dbm, key);
-		log_debug(7, "searching for key '%s'", key.dptr);
-		if (idbm_uniq_id(key.dptr) == rec_id) {
-			return data.dptr;
-		}
-	}
-
-	return NULL;
-}
-
-static DBM*
-idbm_open(char *filename, int flags)
-{
-	DBM *dbm;
-
-	if (flags & O_CREAT) {
-		char *dirname, *ptr;
-
-		dirname = strdup(filename);
-		if (dirname && (ptr = strrchr(dirname, '/'))) {
-			*ptr = '\0';
-		} else if (!dirname)
-			return NULL;
-
-		if (access(dirname, F_OK) != 0) {
-			if (mkdir(dirname, 0755) != 0) {
-				free(dirname);
-				log_error("can't create file '%s'", filename);
-				return NULL;
-			}
-		}
-		free(dirname);
-	}
-
-	/* Now open the database */
-	dbm = dbm_open(filename, flags, 0666);
-	if (!dbm) {
-		log_error("discovery DB '%s' open failed", filename);
-		return NULL;
-	}
-
-	return dbm;
-}
-
-static int
-idbm_get_lock(void)
-{
-	int fd, ret, i;
-
-	fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666);
-	if (fd >= 0)
-		close(fd);
-
-	for (i=0; i < 3000; i++) {
-		ret = link(LOCK_FILE, LOCK_WRITE_FILE);
-		if (ret == 0)
-			return 0;
-		
-		usleep(10000);
-	}
-
-	return -1;
-}
-
-int
-idbm_remove_all(void)
-{
-	if (idbm_get_lock()) {
-		log_error("Could not get DB lock. Make sure all iscsiadm "
-			  "instances have completed and try again\n");
-		return -EAGAIN;
-	}
-
-	if (remove(DISCOVERY_DB_FILE)) {
-		log_error("Could not remove %s err %d\n", DISCOVERY_FILE,
-			  errno);
-		return errno;
-	}
-
-	if (remove(NODE_DB_FILE)) {
-		log_error("Could not remove %s err %d\n", NODE_FILE, errno);
-		return errno;
-	}
-
-	unlink(LOCK_WRITE_FILE);
-	return 0;
-}
-
-static void
-idbm_close(DBM *dbm)
-{
-	dbm_close(dbm);
-}
-
-static int idbm_open_dbs(idbm_t *db)
-{	
-	if (db->refs > 0) {
-		db->refs++;
-		return 0;
-	}
-
-	if ((db->discdb = idbm_open(DISCOVERY_FILE,
-				    access(DISCOVERY_FILE, F_OK) != 0 ?
-				    O_CREAT|O_RDWR : O_RDWR)) == NULL) {
-		return -1;
-	}
-	
-	if ((db->nodedb = idbm_open(NODE_FILE, access(NODE_FILE, F_OK) != 0 ?
-				    O_CREAT|O_RDWR : O_RDWR)) == NULL) {
-		idbm_close(db->discdb);
-		return -1;
-	}
-
-	db->refs = 1;
-	
-	return 0;
-}
-
-static void idbm_close_dbs(idbm_t *db)
-{
-	if (db->refs > 1) {
-		db->refs--;
-		return;
-	}
-	
-	idbm_close(db->discdb);
-	idbm_close(db->nodedb);
-	db->refs = 0;
-	unlink(LOCK_WRITE_FILE);
-}
-
-int
-idbm_find_ids_by_session(idbm_t *db, int *sid, int *rec_id, char *session)
-{
-	DBM *dbm;
-	datum key, data;
-	node_rec_t *rec;
-	conn_rec_t *conn;
-	int ret;
-	uint32_t port, tpgt;
-	char target_name[TARGET_NAME_MAXLEN + 1];
-	char address[NI_MAXHOST + 1];
-	char sysfs_file[PATH_MAX];
-
-	if (sscanf(session, "session%d", sid) != 1) {
-		log_error("invalid session '%s'", session);
-		return -1;
-	}
-
-	memset(sysfs_file, 0, PATH_MAX);
-	sprintf(sysfs_file, "/sys/class/iscsi_session/%s/targetname", session);
-	ret = read_sysfs_str_attr(sysfs_file, target_name, TARGET_NAME_MAXLEN);
-	if (ret) {
-		log_error("could not read session targetname: %d", ret);
-		return -1;
-	}
-
-	memset(sysfs_file, 0, PATH_MAX);
-	sprintf(sysfs_file, "/sys/class/iscsi_session/%s/tpgt", session);
-	ret = read_sysfs_int_attr(sysfs_file, &tpgt);
-	if (ret) {
-		log_error("Could not read tpgt %d\n", ret);
-		return -1;
-	}
-
-	memset(sysfs_file, 0, PATH_MAX);
-	sprintf(sysfs_file, "/sys/class/iscsi_connection/connection%d:0/"
-		"persistent_address", *sid);
-	ret = read_sysfs_str_attr(sysfs_file, address, NI_MAXHOST);
-	if (ret) {
-		log_error("could not read conn address: %d", ret);
-		return -1;
-	}
-
-	memset(sysfs_file, 0, PATH_MAX);
-	sprintf(sysfs_file, "/sys/class/iscsi_connection/connection%d:0/"
-		"persistent_port", *sid);
-	ret = read_sysfs_int_attr(sysfs_file, &port);
-	if (ret) {
-		log_error("Could not read conn port %d\n", ret);
-		return -1;
-	}
-
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return -1;
-
-	dbm = db->nodedb;
-
-	log_debug(7, "search for target_name %s, tpgt %d address %s port %d\n",
-		  target_name, tpgt, address, port);
-	*rec_id = -1;
-	for (key=dbm_firstkey(dbm); key.dptr != NULL; key=dbm_nextkey(dbm)) {
-		data = dbm_fetch(dbm, key);
-		rec = (node_rec_t*)data.dptr;
-		if (idbm_dbversion_check(rec->dbversion)) {
-			idbm_close_dbs(db);
-			exit(-1);
-		}
-
-		conn = &rec->conn[0];
-		if (!strncmp(rec->name, target_name, strlen(rec->name)) &&
-		    !strncmp(conn->address, address, strlen(conn->address)) &&
-		    rec->tpgt == tpgt && conn->port == port) {
-			*rec_id = idbm_uniq_id(key.dptr);
-			break;
-		}
-	}
-
-	idbm_close_dbs(db);
-
-	return *rec_id;
-}
-
-static int
-idbm_write(DBM *dbm, void *rec, int size, char *hash)
-{
-	datum key, data;
-
-	key.dptr = hash;
-	key.dsize = strlen(hash) + 1; /* null-terminated string */
-
-	data.dptr = rec;
-	data.dsize = size;
-
-	if (dbm_store(dbm, key, data, DBM_REPLACE)) {
-		log_error("can not write record with hash-key '%s'", hash);
-		return 1;
-	}
-
-	return 0;
-}
-
 static void
 idbm_recinfo_discovery(discovery_rec_t *r, recinfo_t *ri)
 {
@@ -841,7 +491,7 @@ idbm_recinfo_alloc(int max_keys)
 #define PRINT_TYPE_DISCOVERY	0
 #define PRINT_TYPE_NODE		1
 static void
-idbm_print(int type, void *rec, int show)
+idbm_print(int type, void *rec, int show, FILE *f)
 {
 	int i;
 	recinfo_t *info;
@@ -860,66 +510,20 @@ idbm_print(int type, void *rec, int show
 		if (!info[i].visible)
 			continue;
 		if (!show && info[i].visible == IDBM_MASKED) {
-			if (*(char*)info[i].data)
-				printf("%s = ********\n", info[i].name);
-			else
-				printf("%s = %s\n", info[i].name,
-					info[i].value);
-		} else
-			printf("%s = %s\n", info[i].name, info[i].value);
-	}
-
-	free(info);
-}
-
-static int
-idbm_print_type(idbm_t *db, int type, int rec_id, int show)
-{
-	int found = 0, ret;
-	datum key, data;
-	DBM *dbm = NULL;
-
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return -1;
-
-	dbm = type == PRINT_TYPE_DISCOVERY ? db->discdb : db->nodedb;
-
-	for (key=dbm_firstkey(dbm); key.dptr != NULL; key=dbm_nextkey(dbm)) {
-		data = dbm_fetch(dbm, key);
-		if (rec_id < 0) {
-			if (type == PRINT_TYPE_DISCOVERY) {
-				discovery_rec_t *rec = (discovery_rec_t*)
-								data.dptr;
-				if (idbm_dbversion_check(rec->dbversion))
-					exit(-1);
-				if (rec->type == DISCOVERY_TYPE_SENDTARGETS) {
-					printf("[%06x] %s:%d via sendtargets\n",
-						rec->id,
-						rec->u.sendtargets.address,
-						rec->u.sendtargets.port);
-				}
-			} else if (type == PRINT_TYPE_NODE) {
-				node_rec_t *rec = (node_rec_t*)data.dptr;
-				if (idbm_dbversion_check(rec->dbversion))
-					exit(-1);
-				printf("[%06x] %s:%d,%d %s\n",
-					rec->id,
-					rec->conn[0].address,
-					rec->conn[0].port,
-					rec->tpgt,
-					rec->name);
+			if (*(char*)info[i].data) {
+				fprintf(f, "%s = ********\n", info[i].name);
+				continue;
 			}
-			found++;
-		} else if (rec_id == idbm_uniq_id(key.dptr)) {
-			idbm_print(type, data.dptr, show);
-			found++;
+			/* fall through */
 		}
-	}
 
-	idbm_close_dbs(db);
+		if (strlen(info[i].value))
+			fprintf(f, "%s = %s\n", info[i].name, info[i].value);
+		else if (f == stdout)
+			fprintf(f, "%s = <empty>\n", info[i].name);
+	}
 
-	return found;
+	free(info);
 }
 
 static void
@@ -1097,10 +701,8 @@ idbm_recinfo_config(recinfo_t *info, FIL
 }
 
 static void
-idbm_sync_config(idbm_t *db)
+idbm_sync_config(idbm_t *db, int read_config)
 {
-	FILE *f = NULL;
-
 	/* in case of no configuration file found we just
 	 * initialize default node and default discovery records
 	 * from hard-coded default values */
@@ -1109,24 +711,30 @@ idbm_sync_config(idbm_t *db)
 	idbm_discovery_setup_defaults(&db->drec_slp, DISCOVERY_TYPE_SLP);
 	idbm_discovery_setup_defaults(&db->drec_isns, DISCOVERY_TYPE_ISNS);
 
-	f = fopen(db->configfile, "r");
-	if (!f) {
-		log_debug(1, "cannot open configuration file %s",
-				db->configfile);
-		return;
-	}
-
-	log_debug(5, "updating defaults from '%s'", db->configfile);
-
 	idbm_recinfo_discovery(&db->drec_st, db->dinfo_st);
 	idbm_recinfo_discovery(&db->drec_slp, db->dinfo_slp);
 	idbm_recinfo_discovery(&db->drec_isns, db->dinfo_isns);
 	idbm_recinfo_node(&db->nrec, db->ninfo);
 
-	idbm_recinfo_config(db->dinfo_st, f);
-	idbm_recinfo_config(db->dinfo_slp, f);
-	idbm_recinfo_config(db->dinfo_isns, f);
-	idbm_recinfo_config(db->ninfo, f);
+	if (read_config) {
+		FILE *f;
+
+		f = fopen(db->configfile, "r");
+		if (!f) {
+			log_debug(1, "cannot open configuration file %s",
+					db->configfile);
+			return;
+		}
+
+		log_debug(5, "updating defaults from '%s'", db->configfile);
+
+		idbm_recinfo_config(db->dinfo_st, f);
+		idbm_recinfo_config(db->dinfo_slp, f);
+		idbm_recinfo_config(db->dinfo_isns, f);
+		idbm_recinfo_config(db->ninfo, f);
+
+		fclose(f);
+	}
 
 	/* update password lengths */
 	if (*db->drec_st.u.sendtargets.auth.password)
@@ -1147,273 +755,295 @@ idbm_sync_config(idbm_t *db)
 	if (*db->nrec.session.auth.password_in)
 		db->nrec.session.auth.password_in_length =
 			strlen((char*)db->nrec.session.auth.password_in);
-
-	fclose(f);
-}
-
-static char*
-idbm_id2hash(DBM *dbm, int rec_id)
-{
-	datum key, data;
-
-	for (key=dbm_firstkey(dbm); key.dptr != NULL; key=dbm_nextkey(dbm)) {
-		data = dbm_fetch(dbm, key);
-		if (idbm_uniq_id(key.dptr) == rec_id) {
-			return strdup(key.dptr);
-		}
-	}
-
-	return NULL;
 }
 
 int
-idbm_print_discovery(idbm_t *db, int rec_id)
+idbm_print_discovery(idbm_t *db, discovery_rec_t *rec, int show)
 {
-	return idbm_print_type(db, PRINT_TYPE_DISCOVERY, rec_id, 0);
+	idbm_print(PRINT_TYPE_DISCOVERY, rec, show, stdout);
+	return 1;
 }
 
 int
-idbm_print_node(idbm_t *db, int rec_id, int show)
+idbm_print_node(idbm_t *db, node_rec_t *rec, int show)
 {
-	return idbm_print_type(db, PRINT_TYPE_NODE, rec_id, show);
+	idbm_print(PRINT_TYPE_NODE, rec, show, stdout);
+	return 1;
 }
 
-int
-idbm_print_nodes(idbm_t *db, discovery_rec_t *drec)
+int idbm_print_all_discovery(idbm_t *db)
 {
-	int found = 0, ret;
-	char *hash;
-	datum key, data;
-	DBM *dbm;
-
-	if (!(hash = idbm_hash_discovery(drec)))
-		return found;
-
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return -1;
-
-	dbm = db->nodedb;
-
-	for (key=dbm_firstkey(dbm); key.dptr != NULL; key=dbm_nextkey(dbm)) {
-		data = dbm_fetch(dbm, key);
-		if (strstr(key.dptr, hash)) {
-			node_rec_t *rec = (node_rec_t*)data.dptr;
-			if (idbm_dbversion_check(rec->dbversion))
-				exit(-1);
-			printf("[%06x] %s:%d,%d %s\n",
-			        rec->id,
-				rec->conn[0].address,
-				rec->conn[0].port,
-				rec->tpgt,
-				rec->name);
-			found++;
-		}
-	}
+	DIR *entity_dirfd;
+	struct dirent *entity_dent;
+	char *tmp_ip;
+	int found = 0, tmp_port;
+
+	entity_dirfd = opendir(ST_CONFIG_DIR);
+	if (!entity_dirfd)
+		return 0;
+
+	while ((entity_dent = readdir(entity_dirfd))) {
+		if (!strcmp(entity_dent->d_name, ".") ||
+		    !strcmp(entity_dent->d_name, ".."))
+			continue;
+
+		log_debug(5, "found %s\n", entity_dent->d_name);
 
-	free(hash);
+		tmp_ip = str_to_ipport(entity_dent->d_name, &tmp_port, ',');
 
-	idbm_close_dbs(db);
+		printf("%s:%d via sendtargets\n", tmp_ip, tmp_port);
+		found++;
+	}
+	closedir(entity_dirfd);
 
 	return found;
 }
 
-int
-idbm_discovery_read(idbm_t *db, int rec_id, discovery_rec_t *out_rec)
+int idbm_print_nodes(idbm_t *db)
 {
-	discovery_rec_t *rec;
-	int ret;
+	DIR *node_dirfd, *portal_dirfd;
+	struct dirent *node_dent, *portal_dent;
+	char *portal;
+	node_rec_t rec;
+	int found = 0;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
+	portal = malloc(PATH_MAX);
+	if (!portal)
+		return 0;
 
-	rec = (discovery_rec_t*)idbm_read_with_id(db->discdb, rec_id);
-	if (rec != NULL) {
-		if (idbm_dbversion_check(rec->dbversion)) {
-			idbm_close_dbs(db);
-			exit(-1);
-		}
+	node_dirfd = opendir(NODE_CONFIG_DIR);
+	if (!node_dirfd)
+		goto free_portal;
+
+	while ((node_dent = readdir(node_dirfd))) {
+		if (!strcmp(node_dent->d_name, ".") ||
+		    !strcmp(node_dent->d_name, ".."))
+			continue;
 
-		memcpy(out_rec, rec, sizeof(discovery_rec_t));
-		idbm_close_dbs(db);
-		return 0;
+		log_debug(5, "searching %s\n", node_dent->d_name);
+
+		sprintf(portal, "%s/%s", NODE_CONFIG_DIR, node_dent->d_name);
+		portal_dirfd = opendir(portal);
+		if (!portal_dirfd)
+			continue;
+		while ((portal_dent = readdir(portal_dirfd))) {
+			int tmp_port;
+			char *tmp_ip;
+
+			if (!strcmp(portal_dent->d_name, ".") ||
+			    !strcmp(portal_dent->d_name, ".."))
+				continue;
+
+			log_debug(5, "found %s\n", portal_dent->d_name);
+			tmp_ip = str_to_ipport(portal_dent->d_name, &tmp_port,
+					       ',');
+
+			if (idbm_node_read(db, &rec, node_dent->d_name,
+					   tmp_ip, tmp_port))
+				continue;
+
+			printf("%s:%d,%d %s\n",
+				rec.conn[0].address, rec.conn[0].port,
+				rec.tpgt, rec.name);
+			found++;
+		}
+		closedir(portal_dirfd);
 	}
 
-	idbm_close_dbs(db);
-	return 1;
+	closedir(node_dirfd);
+
+free_portal:
+	free(portal);
+	return found;
 }
 
 int
-idbm_node_read(idbm_t *db, int rec_id, node_rec_t *out_rec)
+idbm_discovery_read(idbm_t *db, discovery_rec_t *out_rec, char *addr, int port)
 {
-	node_rec_t *rec;
-	int ret;
+	char *portal;
+	int rc = 0;
+	FILE *f;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
+	memset(out_rec, 0, sizeof(discovery_rec_t));
 
-	rec = (node_rec_t*)idbm_read_with_id(db->nodedb, rec_id);
-	if (rec != NULL) {
-		if (idbm_dbversion_check(rec->dbversion)) {
-			idbm_close_dbs(db);
-			exit(-1);
-		}
+	portal = malloc(PATH_MAX);
+	if (!portal)
+		return -ENOMEM;
 
-		memcpy(out_rec, rec, sizeof(node_rec_t));
-		idbm_close_dbs(db);
-		return 0;
+	snprintf(portal, PATH_MAX, "%s/%s,%d", ST_CONFIG_DIR,
+		 addr, port);
+	log_debug(5, "Looking for config file %s\n", portal);
+
+	f = fopen(portal, "r");
+	if (!f) {
+		log_debug(1, "Could not open %s err %d\n", portal, errno);
+		rc = errno;
+		goto free_portal;
 	}
-	idbm_close_dbs(db);
-	return 1;
+
+	idbm_recinfo_config(db->dinfo_st, f);
+	memcpy(out_rec, &db->drec_st, sizeof(discovery_rec_t));
+
+free_portal:
+	free(portal);
+	return rc;
 }
 
 int
-idbm_node_write(idbm_t *db, int rec_id, node_rec_t *rec)
+idbm_node_read(idbm_t *db, node_rec_t *out_rec, char *target_name,
+	       char *addr, int port)
 {
-	char *hash;
-	DBM *dbm;
-	int ret;
+	char *portal;
+	int rc = 0;
+	FILE *f;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
+	memset(out_rec, 0, sizeof(node_rec_t));
 
-	dbm = db->nodedb;
+	portal = malloc(PATH_MAX);
+	if (!portal)
+		return -ENOMEM;
 
-	hash = idbm_id2hash(dbm, rec_id);
-	if (!hash) {
-		idbm_close_dbs(db);
-		return 1;
-	}
+	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
+		 target_name, addr, port);
+	log_debug(5, "Looking for config file %s\n", portal);
 
-	if (idbm_write(dbm, rec, sizeof(node_rec_t), hash)) {
-		free(hash);
-		idbm_close_dbs(db);
-		return 1;
+	f = fopen(portal, "r");
+	if (!f) {
+		log_debug(5, "Could not open %s err %d\n", portal, errno);
+		rc = errno;
+		goto free_portal;
 	}
 
-	free(hash);
-	idbm_close_dbs(db);
-	return 0;
+	idbm_recinfo_config(db->ninfo, f);
+	memcpy(out_rec, &db->nrec, sizeof(node_rec_t));
+
+free_portal:
+	free(portal);
+	return rc;
 }
 
-int
-idbm_add_discovery(idbm_t *db, discovery_rec_t *newrec)
+static int
+idbm_node_write(idbm_t *db, node_rec_t *rec)
 {
-	char *hash;
-	discovery_rec_t *rec;
-	DBM *dbm;
-	int ret;
+	FILE *f;
+	char *portal;
+	int rc = 0;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
+	portal = malloc(PATH_MAX);
+	if (!portal) {
+		log_error("Could not alloc portal\n");
+		return -ENOMEM;
+	}
 
-	dbm = db->discdb;
+	snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
+	if (access(portal, F_OK) != 0) {
+		if (mkdir(portal, 0755) != 0) {
+			log_error("Could not make %s\n", portal);
+			rc = errno;
+			goto free_portal;
+		}
+	}	
 
-	if (!(hash = idbm_hash_discovery(newrec))) {
-		idbm_close_dbs(db);
-		return 1;
-	}
+	snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
+	if (access(portal, F_OK) != 0) {
+		if (mkdir(portal, 0755) != 0) {
+			log_error("Could not make %s\n", portal);
+			rc = errno;
+			goto free_portal;
+		}
+	}	
 
-	if ((rec = idbm_read(dbm, hash))) {
-		log_debug(7, "updating existing DB record");
-		idbm_update_discovery(rec, newrec);
-	} else {
-		log_debug(7, "adding new DB record");
-	}
+	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
+		 rec->name, rec->conn[0].address, rec->conn[0].port);
+	log_debug(5, "Looking for config file %s\n", portal);
 
-	newrec->id = idbm_uniq_id(hash);
-	newrec->dbversion = IDBM_VERSION;
-	if (idbm_write(dbm, newrec, sizeof(discovery_rec_t), hash)) {
-		free(hash);
-		idbm_close_dbs(db);
-		return 1;
+	f = fopen(portal, "w");
+	if (!f) {
+		log_error("Could not open %s err %d\n", portal, errno);
+		rc = errno;
+		goto free_portal;
 	}
 
-	free(hash);
-	idbm_close_dbs(db);
-	return 0;
+
+	idbm_print(PRINT_TYPE_NODE, rec, 1, f);
+	fclose(f);
+free_portal:
+	free(portal);
+	return rc;
 }
 
-int
-idbm_add_node(idbm_t *db, discovery_rec_t *drec, node_rec_t *newrec)
+static int
+idbm_discovery_write(idbm_t *db, discovery_rec_t *rec)
 {
-	char *hash;
-	node_rec_t *rec;
-	DBM *dbm;
-	int ret;
+	FILE *f;
+	char *portal;
+	int rc = 0;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
-
-	dbm = db->nodedb;
-
-	if (!(hash = idbm_hash_node(drec, newrec))) {
-		idbm_close_dbs(db);
-		return 1;
+	portal = malloc(PATH_MAX);
+	if (!portal) {
+		log_error("Could not alloc portal\n");
+		return -ENOMEM;
 	}
 
-	if ((rec = idbm_read(dbm, hash))) {
-		log_debug(7, "updating existing DB record");
-		idbm_update_node(rec, newrec);
-	} else {
-		log_debug(7, "adding new DB record");
-	}
+	snprintf(portal, PATH_MAX, "%s", ST_CONFIG_DIR);
+	if (access(portal, F_OK) != 0) {
+		if (mkdir(portal, 0755) != 0) {
+			log_error("Could not make %s\n", portal);
+			rc = errno;
+			goto free_portal;
+		}
+	}	
 
-	newrec->id = idbm_uniq_id(hash);
-	if (idbm_write(dbm, newrec, sizeof(node_rec_t), hash)) {
-		free(hash);
-		idbm_close_dbs(db);
-		return 1;
+	snprintf(portal, PATH_MAX, "%s/%s,%d", ST_CONFIG_DIR,
+		 rec->u.sendtargets.address, rec->u.sendtargets.port);
+	log_debug(5, "Looking for disc config file %s\n", portal);
+
+	f = fopen(portal, "w");
+	if (!f) {
+		log_error("Could not open %s err %d\n", portal, errno);
+		rc = errno;
+		goto free_portal;
 	}
 
-	free(hash);
-	idbm_close_dbs(db);
-	return 0;
+	idbm_print(PRINT_TYPE_DISCOVERY, rec, 1, f);
+	fclose(f);
+free_portal:
+	free(portal);
+	return rc;
 }
 
 int
-idbm_new_node(idbm_t *db, node_rec_t *newrec)
+idbm_add_discovery(idbm_t *db, discovery_rec_t *newrec)
 {
-	char *hash;
-	node_rec_t *rec;
-	DBM *dbm;
-	int ret;
+	discovery_rec_t rec;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
-
-	dbm = db->nodedb;
+	if (idbm_discovery_read(db, &rec, newrec->u.sendtargets.address,
+				newrec->u.sendtargets.port) == 0) {
+		log_debug(7, "overwriting existing record");
+	} else
+		log_debug(7, "adding new DB record");
 
-	if (!(hash = idbm_hash_node(NULL, newrec))) {
-		idbm_close_dbs(db);
-		return 1;
-	}
+	return idbm_discovery_write(db, newrec);
+}
+	
+static int
+idbm_add_node(idbm_t *db, discovery_rec_t *drec, node_rec_t *newrec)
+{
+	node_rec_t rec;
 
-	if ((rec = idbm_read(dbm, hash))) {
-		log_error("record [%06x] exists", rec->id);
-		free(hash);
-		idbm_close_dbs(db);
-		return 1;
-	} else {
+	if (idbm_node_read(db, &rec, newrec->name, newrec->conn[0].address,
+			newrec->conn[0].port) == 0) {
+		log_debug(7, "overwriting existing record");
+	} else
 		log_debug(7, "adding new DB record");
-	}
 
-	newrec->id = idbm_uniq_id(hash);
-	if (idbm_write(dbm, newrec, sizeof(node_rec_t), hash)) {
-		free(hash);
-		idbm_close_dbs(db);
-		return 1;
-	}
+	return idbm_node_write(db, newrec);
+}
 
-	free(hash);
-	idbm_close_dbs(db);
-	return 0;
+int
+idbm_new_node(idbm_t *db, node_rec_t *newrec)
+{
+	return idbm_node_write(db, newrec);
 }
 
 discovery_rec_t*
@@ -1425,7 +1055,7 @@ idbm_new_discovery(idbm_t *db, char *ip,
 	node_rec_t *nrec;
 
 	/* sync default configuration */
-	idbm_sync_config(db);
+	idbm_sync_config(db, 1);
 
 	/* allocate new discovery record and initialize with defaults */
 	drec = malloc(sizeof(discovery_rec_t));
@@ -1555,53 +1185,46 @@ out:
 int
 idbm_delete_discovery(idbm_t *db, discovery_rec_t *rec)
 {
-	int rc;
-	char *hash;
-	datum key;
-	DBM *dbm;
-	int ret;
-
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
-
-	dbm = db->discdb;
+	char *portal;
+	int rc = 0;
 
-	hash = idbm_id2hash(dbm, rec->id);
-
-	key.dptr = hash;
-	key.dsize = strlen(hash) + 1; /* null-terminated string */
-
-	rc = dbm_delete(dbm, key);
+	portal = malloc(PATH_MAX);
+	if (!portal)
+		return -ENOMEM;
+
+	snprintf(portal, PATH_MAX, "%s/%s,%d", ST_CONFIG_DIR,
+		 rec->u.sendtargets.address, rec->u.sendtargets.port);
+	log_debug(5, "Removing config file %s\n", portal);
+
+	if (unlink(portal)) {
+		log_error("Could not remove %s err %d\n", portal, errno);
+		rc = errno;
+	}
+	free(portal);
 
-	free(hash);
-	idbm_close_dbs(db);
 	return rc;
 }
 
 int
 idbm_delete_node(idbm_t *db, node_rec_t *rec)
 {
-	int rc;
-	char *hash;
-	datum key;
-	DBM *dbm;
-	int ret;
+	char *portal;
+	int rc = 0;
 
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
-
-	dbm = db->nodedb;
-	hash = idbm_id2hash(dbm, rec->id);
-
-	key.dptr = hash;
-	key.dsize = strlen(hash) + 1; /* null-terminated string */
-
-	rc = dbm_delete(dbm, key);
+	portal = malloc(PATH_MAX);
+	if (!portal)
+		return -ENOMEM;
+
+	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
+		 rec->name, rec->conn[0].address, rec->conn[0].port);
+	log_debug(5, "Removing config file %s\n", portal);
+
+	if (unlink(portal)) {
+		log_error("Could not remove %s err %d\n", portal, errno);
+		rc = errno;
+	}
+	free(portal);
 
-	free(hash);
-	idbm_close_dbs(db);
 	return rc;
 }
 
@@ -1623,34 +1246,24 @@ int
 idbm_node_set_param(idbm_t *db, node_rec_t *rec, char *name, char *value)
 {
 	recinfo_t *info;
-	int ret;
-
-	ret = idbm_open_dbs(db);
-	if (ret)
-		return 1;
 
 	info = idbm_recinfo_alloc(MAX_KEYS);
-	if (!info) {
-		idbm_close_dbs(db);
+	if (!info)
 		return 1;
-	}
 
 	idbm_recinfo_node(rec, info);
 
 	if (idbm_node_update_param(info, name, value, 0)) {
 		free(info);
-		idbm_close_dbs(db);
 		return 1;
 	}
 
-	if (idbm_node_write(db, rec->id, rec)) {
+	if (idbm_node_write(db, rec)) {
 		free(info);
-		idbm_close_dbs(db);
 		return 1;
 	}
 
 	free(info);
-	idbm_close_dbs(db);
 	return 0;
 }
 
@@ -1667,7 +1280,7 @@ idbm_init(char *configfile)
 	memset(db, 0, sizeof(idbm_t));
 
 	db->configfile = strdup(configfile);
-	idbm_sync_config(db);	
+	idbm_sync_config(db, 0);	
 
 	return db;
 }
diff -aurp open-iscsi/usr/idbm.h open-iscsi.db/usr/idbm.h
--- open-iscsi/usr/idbm.h	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/idbm.h	2006-08-21 01:55:06.000000000 -0400
@@ -63,27 +63,24 @@ extern char* get_iscsi_initiatorname(cha
 extern char* get_iscsi_initiatoralias(char *pathname);
 extern idbm_t* idbm_init(char *configfile);
 extern void idbm_terminate(idbm_t *db);
-extern int idbm_print_node(idbm_t *db, int rec_id, int show);
-extern int idbm_print_nodes(idbm_t *db, discovery_rec_t *rec);
-extern int idbm_print_discovery(idbm_t *db, int rec_id);
+extern int idbm_print_node(idbm_t *db, node_rec_t *rec, int show);
+extern int idbm_print_nodes(idbm_t *db);
+extern int idbm_print_discovery(idbm_t *db, discovery_rec_t *rec, int show);
+extern int idbm_print_all_discovery(idbm_t *db);
 extern int idbm_delete_discovery(idbm_t *db, discovery_rec_t *rec);
 extern void idbm_node_setup_defaults(node_rec_t *rec);
 extern int idbm_delete_node(idbm_t *db, node_rec_t *rec);
 extern int idbm_new_node(idbm_t *db, node_rec_t *newrec);
-extern int idbm_add_node(idbm_t *db, discovery_rec_t *drec, node_rec_t *newrec);
 extern int idbm_add_discovery(idbm_t *db, discovery_rec_t *newrec);
 extern discovery_rec_t* idbm_new_discovery(idbm_t *db, char *ip, int port,
 			    discovery_type_e type, char *info);
 extern void idbm_sendtargets_defaults(idbm_t *db,
 		      struct iscsi_sendtargets_config *cfg);
 extern void idbm_slp_defaults(idbm_t *db, struct iscsi_slp_config *cfg);
-extern int idbm_discovery_read(idbm_t *db, int rec_id, discovery_rec_t *rec);
-extern int idbm_node_read(idbm_t *db, int rec_id, node_rec_t *rec);
-extern int idbm_node_write(idbm_t *db, int rec_id, node_rec_t *rec);
+extern int idbm_discovery_read(idbm_t *db, discovery_rec_t *rec, char *addr,
+				int port);
+extern int idbm_node_read(idbm_t *db, node_rec_t *out_rec, char *target_name,
+			 char *addr, int port);
 extern int idbm_node_set_param(idbm_t *db, node_rec_t *rec, char *name,
 			       char *value);
-extern int idbm_find_ids_by_session(idbm_t *db, int *sid, int *rec_id,
-				    char *sys_session);
-extern int idbm_remove_all(void);
-
 #endif /* IDBM_H */
diff -aurp open-iscsi/usr/initiator.c open-iscsi.db/usr/initiator.c
--- open-iscsi/usr/initiator.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/initiator.c	2006-08-21 01:55:06.000000000 -0400
@@ -1616,11 +1616,18 @@ session_find_by_rec(node_rec_t *rec)
 		item = provider[i].sessions.q_forw;
 		while (item != &provider[i].sessions) {
 			session = (iscsi_session_t *)item;
-			log_debug(6, "looking for session with rec_id [%06x]...",
-				  session->nrec.id);
-			if (rec->id == session->nrec.id) {
+			log_debug(6, "looking for session [%s,%s,%d]",
+				  rec->name, rec->conn[0].address,
+				  rec->conn[0].port);
+
+			if (!strncmp(rec->name, session->nrec.name,
+				    strlen(rec->name)) &&
+			    !strncmp(rec->conn[0].address,
+				    session->nrec.conn[0].address,
+				    strlen(rec->conn[0].address)) &&
+			    rec->conn[0].port == session->nrec.conn[0].port)
 				return session;
-			}
+
 			item = item->q_forw;
 		}
 	}
Only in open-iscsi.db/usr/: .initiator.c.swp
diff -aurp open-iscsi/usr/initiator.h open-iscsi.db/usr/initiator.h
--- open-iscsi/usr/initiator.h	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/initiator.h	2006-08-21 01:55:06.000000000 -0400
@@ -31,23 +31,11 @@
 #include "actor.h"
 #include "queue.h"
 
-#define CONFIG_FILE		"/etc/iscsid.conf"
+#define ST_CONFIG_DIR		"/etc/iscsi/send_targets"
+#define NODE_CONFIG_DIR		"/etc/iscsi/nodes"
+#define CONFIG_FILE		"/etc/iscsi/iscsid.conf"
 #define PID_FILE		"/var/run/iscsid.pid"
-#define INITIATOR_NAME_FILE	"/etc/initiatorname.iscsi"
-#ifndef DISCOVERY_FILE
-#define DISCOVERY_FILE		"/var/db/iscsi/discovery"
-#define DISCOVERY_DB_FILE	"/var/db/iscsi/discovery.db"
-#endif
-#ifndef NODE_FILE
-#define NODE_FILE		"/var/db/iscsi/node"
-#define	NODE_DB_FILE		"/var/db/iscsi/node.db"
-#endif
-#ifndef LOCK_FILE
-#define LOCK_FILE		"/var/db/iscsi/lock"
-#endif
-#ifndef LOCK_WRITE_FILE
-#define LOCK_WRITE_FILE		"/var/db/iscsi/lock.write"
-#endif
+#define INITIATOR_NAME_FILE	"/etc/iscsi/initiatorname.iscsi"
 
 #define DEF_ISCSI_PORT		3260
 
diff -aurp open-iscsi/usr/iscsiadm.c open-iscsi.db/usr/iscsiadm.c
--- open-iscsi/usr/iscsiadm.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/iscsiadm.c	2006-08-21 04:08:58.000000000 -0400
@@ -52,7 +52,6 @@ enum iscsiadm_mode {
 	MODE_DISCOVERY,
 	MODE_NODE,
 	MODE_SESSION,
-	MODE_DB,
 };
 
 enum iscsiadm_op {
@@ -66,6 +65,7 @@ static struct option const long_options[
 {
 	{"mode", required_argument, NULL, 'm'},
 	{"portal", required_argument, NULL, 'p'},
+	{"targetname", required_argument, NULL, 'T'},
 	{"op", required_argument, NULL, 'o'},
 	{"type", required_argument, NULL, 't'},
 	{"name", required_argument, NULL, 'n'},
@@ -77,12 +77,11 @@ static struct option const long_options[
 	{"debug", required_argument, NULL, 'g'},
 	{"map", required_argument, NULL, 'M'},
 	{"show", no_argument, NULL, 'S'},
-	{"remove", no_argument, NULL, 'R'},
 	{"version", no_argument, NULL, 'V'},
 	{"help", no_argument, NULL, 'h'},
 	{NULL, 0, NULL, 0},
 };
-static char *short_options = "lVhm:M:p:d:r:n:v:o:sSt:uR";
+static char *short_options = "lVhm:M:p:T:d:r:n:v:o:sSt:u";
 
 static void usage(int status)
 {
@@ -93,7 +92,7 @@ static void usage(int status)
 		printf("\
 iscsiadm -m discovery [ -dhV ] [ -t type -p ip [ -l ] ] | [ -r recid ] \
 [ -o operation ] [ -n name ] [ -v value ]\n\
-iscsiadm -m node [ -dhV ] [ -S ] [ [ -r recid | -M sysdir ] [ -l | -u ] ] \
+iscsiadm -m node [ -dhV ] [ -S ] [ [ -T targetname -p ip | -M sysdir ] [ -l | -u ] ] \
 [ [ -o  operation  ] [ -n name ] [ -v value ] [ -p ip ] ]\n\
 iscsiadm -m session [ -dhV ] [ -r [sid:]recid [ -u | -s ] ]\n");
 	}
@@ -130,8 +129,6 @@ str_to_mode(char *str)
 		mode = MODE_NODE;
 	else if (!strcmp("session", str))
 		mode = MODE_SESSION;
-	else if (!strcmp("db", str))
-		mode = MODE_DB;
 	else
 		mode = -1;
 
@@ -156,60 +153,12 @@ str_to_type(char *str)
 	return type;
 }
 
-static char*
-str_to_ipport(char *str, int *port)
-{
-	char *sport = str;
-
-	if (!strchr(str, '.')) {
-		if (*str == '[') {
-			if (!(sport = strchr(str, ']')))
-				return NULL;
-			*sport++ = '\0';
-			str++;
-		} else
-			sport = NULL;
-	}
-
-	if (sport && (sport = strchr(sport, ':'))) {
-		*sport = '\0';
-		sport++;
-		*port = strtoul(sport, NULL, 10);
-	} else
-		*port = DEF_ISCSI_PORT;
-
-	return str;
-}
-
-static int
-str_to_ridsid(char *str, int *sid)
-{
-	char *ptr, *eptr;
-	int rid;
-
-	if ((ptr = strchr(str, ':'))) {
-		*ptr = '\0';
-		ptr++;
-		*sid = strtoul(str, &eptr, 10);
-		if (eptr == str)
-			*sid = -1;
-	} else {
-		*sid = -1;
-		ptr = str;
-	}
-
-	rid = strtoul(ptr, &eptr, 16);
-	if (eptr == ptr)
-		rid = -1;
-	return rid;
-}
-
 static int
-sys_to_rid(idbm_t *db, char *sysfs_device)
+sys_to_rec(idbm_t *db, node_rec_t *rec, char *sysfs_device)
 {
-	int sid, rec_id;
-	int rc;
-	int len;
+	char *targetname;
+	char *address;
+	int sid, rc, port, len;
 	struct stat statb;
 	char sys_session[64], *start, *last;
 
@@ -247,38 +196,61 @@ sys_to_rid(idbm_t *db, char *sysfs_devic
 		exit(1);
 	}
 
+	targetname = malloc(TARGET_NAME_MAXLEN + 1);
+	if (!targetname)
+		return -ENOMEM;
+
+	address = malloc(NI_MAXHOST + 1);
+	if (!address) {
+		rc = -ENOMEM;
+		goto free_target;
+	}
+
 	log_debug(2, "%s: session %s", __FUNCTION__, sys_session);
-	rc = idbm_find_ids_by_session(db, &sid, &rec_id, sys_session);
+	rc = find_ids_by_session(&sid, targetname, address, &port,
+				 sys_session);
 	if (rc < 0) {
 		log_error("Unable to find a record for iscsi %s (sys %s)",
 			  sys_session, sysfs_device);
-		return rc;
+		goto free_address;
 	}
-	return rec_id;
+
+	rc = idbm_node_read(db, rec, targetname, address, port);
+	if (rc) {
+		log_error("node [%s, %s, %d] not found!",
+			  targetname, address, port);
+		goto free_address;
+	}
+
+free_address:
+	free(address);
+free_target:
+	free(targetname);
+	return rc;
 }
 
 static int
-session_login(int rid, node_rec_t *rec)
+session_login(node_rec_t *rec)
 {
 	iscsiadm_req_t req;
 	iscsiadm_rsp_t rsp;
 
-	memset(&req, 0, sizeof(req));
+	memset(&req, 0, sizeof(iscsiadm_req_t));
 	req.command = MGMT_IPC_SESSION_LOGIN;
-	req.u.session.rid = rid;
+	memcpy(&req.u.session.rec, rec, sizeof(node_rec_t));
 
 	return do_iscsid(&ipc_fd, &req, &rsp);
 }
 
 static int
-session_logout(int rid, node_rec_t *rec)
+session_logout(node_rec_t *rec)
 {
 	iscsiadm_req_t req;
 	iscsiadm_rsp_t rsp;
 
 	memset(&req, 0, sizeof(req));
 	req.command = MGMT_IPC_SESSION_LOGOUT;
-	req.u.session.rid = rid;
+	memcpy(&req.u.session.rec, rec, sizeof(node_rec_t));
 
 	return do_iscsid(&ipc_fd, &req, &rsp);
 }
@@ -332,6 +304,8 @@ session_activelist(idbm_t *db)
 	int rc, i;
 	iscsiadm_req_t req;
 	iscsiadm_rsp_t rsp;
+	char *targetname, *address, *sysfs_file;
+	uint32_t port, tpgt, sid;
 
 	memset(&req, 0, sizeof(req));
 	req.command = MGMT_IPC_SESSION_ACTIVELIST;
@@ -339,48 +313,85 @@ session_activelist(idbm_t *db)
 	rc = do_iscsid(&ipc_fd, &req, &rsp);
 	if (rc)
 		return rc;
-	/* display all active sessions */
-	for (i = 0; i < rsp.u.activelist.cnt; i++) {
-		node_rec_t rec;
 
-		if (idbm_node_read(db, rsp.u.activelist.rids[i], &rec)) {
-			log_error("no record [%06x] found!",
-				  rsp.u.activelist.rids[i]);
-			return -1;
-		}
-		printf("[%02d:%06x] %s:%d,%d %s\n",
-			rsp.u.activelist.sids[i], rec.id, rec.conn[0].address,
-			rec.conn[0].port, rec.tpgt, rec.name);
+	targetname = malloc(TARGET_NAME_MAXLEN + 1);
+	if (!targetname)
+		return -ENOMEM;
+
+	address = malloc(NI_MAXHOST + 1);
+	if (!address) {
+		rc = -ENOMEM;
+		goto free_target;
 	}
 
-	return i;
+	sysfs_file = malloc(PATH_MAX);
+	if (!sysfs_file) {
+		rc = -ENOMEM;
+		goto free_address;
+	}
+
+	/* display all active sessions */
+	for (i = 0; i < rsp.u.activelist.cnt; i++) {
+		sid = rsp.u.activelist.sids[i];
+		memset(sysfs_file, 0, PATH_MAX);
+		sprintf(sysfs_file,
+			"/sys/class/iscsi_session/session%u/targetname", sid);
+		rc = read_sysfs_str_attr(sysfs_file, targetname,
+					  TARGET_NAME_MAXLEN);
+		if (rc)
+			log_error("could not read session targetname: %d", rc);
+
+		memset(sysfs_file, 0, PATH_MAX);
+		sprintf(sysfs_file, "/sys/class/iscsi_session/session%u/tpgt",
+			sid);
+		rc = read_sysfs_int_attr(sysfs_file, &tpgt);
+		if (rc)
+	                log_error("Could not read tpgt %d\n", rc);
+
+		memset(sysfs_file, 0, PATH_MAX);
+		sprintf(sysfs_file,
+			"/sys/class/iscsi_connection/connection%d:0/address",
+			sid);
+		rc = read_sysfs_str_attr(sysfs_file, address, NI_MAXHOST);
+		if (rc)
+			log_error("could not read conn address: %d", rc);
+
+		memset(sysfs_file, 0, PATH_MAX);
+		sprintf(sysfs_file,
+			"/sys/class/iscsi_connection/connection%d:0/port", sid);
+		rc = read_sysfs_int_attr(sysfs_file, &port);
+		if (rc)
+			log_error("Could not read conn port %d\n", rc);
+
+		printf("[%02d] %s:%d,%d %s\n",
+			sid, address, port, tpgt, targetname);
+	}
+	rc = i;
+
+	free(sysfs_file);
+free_address:
+	free(address);
+free_target:
+	free(targetname);
+	return rc;
 }
 
 static int
-session_stats(idbm_t *db, int rid, int sid)
+session_stats(idbm_t *db, int sid)
 {
 	int rc, i;
 	iscsiadm_req_t req;
 	iscsiadm_rsp_t rsp;
-	node_rec_t rec;
-
-	if (idbm_node_read(db, rid, &rec)) {
-		log_error("no record [%06x] found!", rid);
-		return -1;
-	}
 
 	memset(&req, 0, sizeof(req));
 	req.command = MGMT_IPC_SESSION_STATS;
-	req.u.session.rid = rid;
 	req.u.session.sid = sid;
 
 	rc = do_iscsid(&ipc_fd, &req, &rsp);
 	if (rc)
 		return rc;
 
-	printf("[%02d:%06x] %s:%d,%d %s\n",
-		sid, rid, rec.conn[0].address, rec.conn[0].port,
-		rec.tpgt, rec.name);
+	printf("[%02d]\n", sid);
 	printf( "iSCSI SNMP:\n"
 
 		"\ttxdata_octets: %lld\n"
@@ -459,7 +470,7 @@ do_sendtargets(idbm_t *db, struct iscsi_
 		discovery_rec_t *drec;
 		if ((drec = idbm_new_discovery(db, cfg->address, cfg->port,
 		    DISCOVERY_TYPE_SENDTARGETS, info.buffer))) {
-			idbm_print_nodes(db, drec);
+			idbm_print_nodes(db);
 			free(drec);
 		}
 	}
@@ -499,9 +510,9 @@ int
 main(int argc, char **argv)
 {
 	char *ip = NULL, *name = NULL, *value = NULL, *sysfs_device = NULL;
+	char *targetname = NULL;
 	int ch, longindex, mode=-1, port=-1, do_login=0;
-	int rc=0, rid=-1, sid=-1, op=-1, type=-1, do_logout=0, do_stats=0;
-	int do_show=0, do_remove=0;
+	int rc=0, sid=-1, op=-1, type=-1, do_logout=0, do_stats=0, do_show=0;
 	idbm_t *db;
 	struct sigaction sa_old;
 	struct sigaction sa_new;
@@ -544,9 +555,9 @@ main(int argc, char **argv)
 			value = optarg;
 			break;
 		case 'r':
-			rid = str_to_ridsid(optarg, &sid);
-			if (rid < 0) {
-				log_error("invalid record '%s'",
+			sid = atoi(optarg);
+			if (sid < 0) {
+				log_error("invalid sid '%s'",
 					  optarg);
 				return -1;
 			}
@@ -572,11 +583,11 @@ main(int argc, char **argv)
 		case 'M':
 			sysfs_device = optarg;
 			break;
-		case 'R':
-			do_remove = 1;
+		case 'T':
+			targetname = optarg;
 			break;
 		case 'p':
-			ip = str_to_ipport(optarg, &port);
+			ip = str_to_ipport(optarg, &port, ':');
 			break;
 		case 'V':
 			printf("%s version %s\n", program_name,
@@ -595,16 +606,6 @@ main(int argc, char **argv)
 	if (mode < 0) 
 		usage(0);
 
-	if (mode == MODE_DB) {
-		if (!do_remove) {
-			log_error("Try iscsiadm -m db --remove\n");
-			exit(-1);
-		}
-
-		idbm_remove_all();
-		exit(0);
-	}
-
 	db = idbm_init(config_file);
 	if (!db) {
 		log_warning("exiting due to idbm configuration error");
@@ -612,7 +613,7 @@ main(int argc, char **argv)
 	}
 
 	if (mode == MODE_DISCOVERY) {
-		if ((rc = verify_mode_params(argc, argv, "dmtplro", 0))) {
+		if ((rc = verify_mode_params(argc, argv, "dmtplo", 0))) {
 			log_error("discovery mode: option '-%c' is not "
 				  "allowed/supported", rc);
 			rc = -1;
@@ -650,12 +651,12 @@ main(int argc, char **argv)
 			rc = -1;
 			goto out;
 		} else if (type < 0) {
-			if (rid >= 0) {
+			if (ip) {
 				discovery_rec_t rec;
 
-				if (idbm_discovery_read(db, rid, &rec)) {
-					log_error("discovery record [%06x] "
-						  "not found!", rid);
+				if (idbm_discovery_read(db, &rec, ip, port)) {
+					log_error("discovery record [%s,%d] "
+						  "not found!", ip, port);
 					rc = -1;
 					goto out;
 				}
@@ -675,7 +676,8 @@ main(int argc, char **argv)
 					rc = -1;
 					goto out;
 				} else if (op < 0 || op == OP_SHOW) {
-					if (!idbm_print_discovery(db, rid)) {
+					if (!idbm_print_discovery(db, &rec,
+								  do_show)) {
 						log_error("no records found!");
 						rc = -1;
 					}
@@ -692,7 +694,7 @@ main(int argc, char **argv)
 				}
 
 			} else if (op < 0 || op == OP_SHOW) {
-				if (!idbm_print_discovery(db, rid)) {
+				if (!idbm_print_all_discovery(db)) {
 					log_error("no records found!");
 					rc = -1;
 				}
@@ -710,35 +712,41 @@ main(int argc, char **argv)
 			}
 		}
 	} else if (mode == MODE_NODE) {
-		if ((rc = verify_mode_params(argc, argv, "dmMlSronvup", 0))) {
+		node_rec_t rec;
+
+		memset(&rec, 0, sizeof(node_rec_t));
+		if ((rc = verify_mode_params(argc, argv, "dmMlSonvupT", 0))) {
 			log_error("node mode: option '-%c' is not "
 				  "allowed/supported", rc);
 			rc = -1;
 			goto out;
 		}
 		if (sysfs_device) {
-			if (rid >= 0) {
-				log_error("only one of map and recid may be"
-					  " specified");
+			if (targetname && ip) {
+				log_error("only one of map and "
+					  "targetname,portal may be specified");
 				rc = -1;
 				goto out;
 			}
-			rid = sys_to_rid(db, sysfs_device);
-			if (rid < 0) {
+			if (sys_to_rec(db, &rec, sysfs_device)) {
 				rc = -1;
 				goto out;
 			}
-			/* fall through */
+			/* bleh */
+			goto found_node_rec;
 		}
-		if (rid >= 0) {
-			node_rec_t rec;
 
-			log_debug(2, "%s: record 0x%x", __FUNCTION__, rid);
-			if (idbm_node_read(db, rid, &rec)) {
-				log_error("node record [%06x] not found!", rid);
+		if (targetname && ip && op != OP_NEW) {
+			log_debug(2, "%s: node [%s,%s,%d]", __FUNCTION__,
+				  targetname, ip, port);
+			if (idbm_node_read(db, &rec, targetname, ip, port)) {
+				log_error("node [%s, %s, %d] not found!",
+					  targetname, ip, port);
 				rc = -1;
 				goto out;
 			}
+
+found_node_rec:
 			if (do_login && do_logout) {
 				log_error("either login or "
 					  "logout at the time allowed!");
@@ -752,21 +760,21 @@ main(int argc, char **argv)
 				goto out;
 			}
 			if (!do_login && !do_logout && op < 0) {
-				if (!idbm_print_node(db, rid, do_show)) {
+				if (!idbm_print_node(db, &rec, do_show)) {
 					log_error("no records found!");
 					rc = -1;
 				}
 				goto out;
 			}
 			if (do_login) {
-				if ((rc = session_login(rid, &rec)) > 0) {
+				if ((rc = session_login(&rec)) > 0) {
 					iscsid_handle_error(rc);
 					rc = -1;
 				}
 				goto out;
 			}
 			if (do_logout) {
-				if ((rc = session_logout(rid, &rec)) > 0) {
+				if ((rc = session_logout(&rec)) > 0) {
 					iscsid_handle_error(rc);
 					rc = -1;
 				}
@@ -796,31 +804,28 @@ main(int argc, char **argv)
 				goto out;
 			}
 		} else if (op < 0 || op == OP_SHOW) {
-			if (!idbm_print_node(db, rid, do_show)) {
+			if (!idbm_print_nodes(db)) {
 				log_error("no records found!");
 				rc = -1;
 				goto out;
 			}
 		} else if (op == OP_NEW) {
-			node_rec_t nrec;
-			if (!ip) {
-				log_error("--portal required for new "
+			if (!ip || !targetname) {
+				log_error("portal and target required for new "
 					  "node record");
 				rc = -1;
 				goto out;
 			}
-			idbm_node_setup_defaults(&nrec);
-			strncpy(nrec.name, "<not specified>",
-				TARGET_NAME_MAXLEN);
-			nrec.conn[0].port = port;
-			strncpy(nrec.conn[0].address, ip, 16);
-			if (idbm_new_node(db, &nrec)) {
+			idbm_node_setup_defaults(&rec);
+			strncpy(rec.name, targetname, TARGET_NAME_MAXLEN);
+			rec.conn[0].port = port;
+			strncpy(rec.conn[0].address, ip, NI_MAXHOST);
+			if (idbm_new_node(db, &rec)) {
 				log_error("can not add new record.");
 				rc = -1;
 				goto out;
 			}
-			printf("new iSCSI node record added: [%06x]\n",
-				nrec.id);
+			printf("new iSCSI node record added\n");
 		} else if (op == OP_DELETE) {
 			log_error("--record required for delete operation");
 			rc = -1;
@@ -831,13 +836,13 @@ main(int argc, char **argv)
 			goto out;
 		}
 	} else if (mode == MODE_SESSION) {
-		if ((rc = verify_mode_params(argc, argv, "dmrus", 1))) {
+		if ((rc = verify_mode_params(argc, argv, "dmus", 1))) {
 			log_error("session mode: option '-%c' is not "
 				  "allowed or supported", rc);
 			rc = -1;
 			goto out;
 		}
-		if (rid >= 0) {
+		if (sid >= 0) {
 			if (do_logout && do_stats) {
 				log_error("--logout or --stats? what exactly?");
 				rc = -1;
@@ -849,7 +854,7 @@ main(int argc, char **argv)
 				goto out;
 			}
 			if (do_stats) {
-				if ((rc = session_stats(db, rid, sid)) > 0) {
+				if ((rc = session_stats(db, sid)) > 0) {
 					iscsid_handle_error(rc);
 					log_error("can not get statistics for "
 						"session with SID %d (%d)",
diff -aurp open-iscsi/usr/iscsid.c open-iscsi.db/usr/iscsid.c
--- open-iscsi/usr/iscsid.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/iscsid.c	2006-08-21 01:55:06.000000000 -0400
@@ -53,12 +53,6 @@ int control_fd, mgmt_ipc_fd;
 
 extern char sysfs_file[];
 
-static struct mgmt_ipc_db mgmt_ipc_db = {
-	.init		= idbm_init,
-	.terminate	= idbm_terminate,
-	.node_read	= idbm_node_read,
-};
-
 static struct option const long_options[] = {
 	{"config", required_argument, NULL, 'c'},
 	{"initiatorname", required_argument, NULL, 'i'},
@@ -97,33 +91,63 @@ Open-iSCSI initiator daemon.\n\
 
 static int sync_session(iscsi_provider_t *provider, char *sys_session)
 {
+	char *targetname;
+	char *address;
 	idbm_t *db;
-	int rc;
-	int sid, rec_id;
+	node_rec_t rec;
+	int rc, sid, fd, port;
 	iscsiadm_req_t req;
 	iscsiadm_rsp_t rsp;
-	int fd;
 
 	log_debug(7, "sync session %s", sys_session);
 
+	targetname = malloc(TARGET_NAME_MAXLEN + 1);
+	if (!targetname)
+		return -ENOMEM;
+
+	address = malloc(NI_MAXHOST + 1);
+	if (!address) {
+		rc = -ENOMEM;
+		goto free_target;
+	}
+
 	db = idbm_init(daemon_config.config_file);
 	if (!db) {
 		log_error("could not open node database");
-		return -1;
+		rc = -EIO;
+		goto free_address;
 	}
 
-	rc = idbm_find_ids_by_session(db, &sid, &rec_id, sys_session);
+	rc = find_ids_by_session(&sid, targetname, address, &port,
+				 sys_session);
 	if (rc < 0) {
 		log_error("could not find record for %s", sys_session);
-		return -1;
+		goto term_idbm;
+	}
+
+	if (idbm_node_read(db, &rec, targetname, address, port)) {
+		log_error("could not read data for [%s,%s.%d] session %s\n",
+			  targetname, address, port, sys_session);
+		rc = -EIO;
+		goto term_idbm;
 	}
+
 	idbm_terminate(db);
 
 	memset(&req, 0, sizeof(req));
 	req.command = MGMT_IPC_SESSION_SYNC;
-	req.u.session.rid = rec_id;
 	req.u.session.sid = sid;
+	memcpy(&req.u.session.rec, &rec, sizeof(node_rec_t));
+
 	return do_iscsid(&fd, &req, &rsp);
+
+term_idbm:
+	idbm_terminate(db);
+free_address:
+	free(address);
+free_target:
+	free(targetname);
+	return rc;
 }
 
 static void sync_sessions(iscsi_provider_t *prv)
@@ -133,6 +157,9 @@ static void sync_sessions(iscsi_provider
 
 	sprintf(sysfs_file, "/sys/class/iscsi_session");
 	dirfd = opendir(sysfs_file);
+	if (!dirfd)
+		return;
+
 	while ((dent = readdir(dirfd))) {
 		if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
 			continue;
@@ -347,7 +374,7 @@ int main(int argc, char *argv[])
 	}
 
 	actor_init();
-	event_loop(ipc, control_fd, mgmt_ipc_fd, &mgmt_ipc_db);
+	event_loop(ipc, control_fd, mgmt_ipc_fd);
 	log_debug(1, "daemon stopping");
 	return 0;
 }
diff -aurp open-iscsi/usr/iscsistart.c open-iscsi.db/usr/iscsistart.c
--- open-iscsi/usr/iscsistart.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/iscsistart.c	2006-08-21 04:14:36.000000000 -0400
@@ -69,7 +69,6 @@ static struct option const long_options[
 	{"password", required_argument, NULL, 'w'},
 	{"username_in", required_argument, NULL, 'U'},
 	{"password_in", required_argument, NULL, 'W'},
-	{"rec", required_argument, NULL, 'r'},
 	{"debug", required_argument, NULL, 'd'},
 	{"help", no_argument, NULL, 'h'},
 	{"version", no_argument, NULL, 'v'},
@@ -94,7 +93,6 @@ Open-iSCSI initiator.\n\
   -w, --password=N         set password to N (optional\n\
   -U, --username_in=N      set incoming username to N (optional)\n\
   -W, --password_in=N      set incoming password to N (optional\n\
-  -r, --rec=N              set record id (iscsid DB recid) to N (Required)\n\
   -d, --debug debuglevel   print debugging information \n\
   -h, --help               display this help and exit\n\
   -v, --version            display version and exit\n\
@@ -103,19 +101,6 @@ Open-iSCSI initiator.\n\
 	exit(status == 0 ? 0 : -1);
 }
 
-static int db_node_read(idbm_t *db, int rec_id, node_rec_t *rec)
-{
-	memcpy(rec, &config_rec, sizeof(struct node_rec));
-	return 0;
-}
-
-/*
- * we do not need the DB so we just return the single record
- */
-static struct mgmt_ipc_db mgmt_ipc_db = {
-	.node_read	= db_node_read,
-};
-
 static int stop_event_loop(void)
 {
 	iscsiadm_req_t req;
@@ -141,7 +126,7 @@ static int setup_session(void)
 
 	memset(&req, 0, sizeof(req));
 	req.command = MGMT_IPC_SESSION_LOGIN;
-	req.u.session.rid = config_rec.id;
+	memcpy(&req.u.session.rec, &config_rec, sizeof(node_rec_t));
 	rc = do_iscsid(&ipc_fd, &req, &rsp);
 	if (rc > 0)
 		iscsid_handle_error(rc);
@@ -198,7 +183,6 @@ int main(int argc, char *argv[])
 	struct sigaction sa_old;
 	struct sigaction sa_new;
 	pid_t pid;
-	char *end;
 
 	idbm_node_setup_defaults(&config_rec);
 	config_rec.name[0] = '\0';
@@ -211,7 +195,7 @@ int main(int argc, char *argv[])
 	sa_new.sa_flags = 0;
 	sigaction(SIGINT, &sa_new, &sa_old );
 
-	while ((ch = getopt_long(argc, argv, "i:t:g:a:p:r:d:u:w:U:W:vh",
+	while ((ch = getopt_long(argc, argv, "i:t:g:a:p:d:u:w:U:W:vh",
 				 long_options, &longindex)) >= 0) {
 		switch (ch) {
 		case 'i':
@@ -257,15 +241,6 @@ int main(int argc, char *argv[])
 					    "username_in");
 			strncpy(auth->username_in, optarg, AUTH_STR_MAX_LEN);
 			break;	
-		case 'r':
-			config_rec.id = strtoul(optarg, &end, 0);
-			if (*end != '\0') {
-				fprintf(stderr,
-					"%s: invalid record number %s.\n",
-					program_name, optarg);
-				usage(1);
-			}
-			break;
 		case 'd':
 			log_level = atoi(optarg);
 			break;
@@ -336,7 +311,6 @@ int main(int argc, char *argv[])
 	log_debug(1, "TargetName=%s", config_rec.name);
 	log_debug(1, "TPGT=%d", config_rec.tpgt);
 	log_debug(1, "IP Address=%s", config_rec.conn[0].address);
-	log_debug(1, "recid=%x", config_rec.id);
 
 	/* log the version, so that we can tell if the daemon and kernel module
 	 * match based on what shows up in the syslog.  Tarballs releases
@@ -362,7 +336,7 @@ int main(int argc, char *argv[])
 	 * Start Main Event Loop
 	 */
 	actor_init();
-	event_loop(ipc, control_fd, mgmt_ipc_fd, &mgmt_ipc_db);
+	event_loop(ipc, control_fd, mgmt_ipc_fd);
 	ipc->ctldev_close();
 	mgmt_ipc_close(mgmt_ipc_fd);
 
diff -aurp open-iscsi/usr/Makefile open-iscsi.db/usr/Makefile
--- open-iscsi/usr/Makefile	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/Makefile	2006-08-21 01:55:06.000000000 -0400
@@ -21,12 +21,10 @@ ifeq ($(OSNAME),Linux)
 	endif
 	endif
 IPC_OBJ=netlink.o
-DBM_LIB=-ldb
 else
 ifeq ($(OSNAME),FreeBSD)
 IPC_CFLAGS=
 IPC_OBJ=ioctl.o
-DBM_LIB=
 endif
 endif
 
@@ -45,10 +43,10 @@ INITIATOR_SRCS = initiator.o queue.o act
 all: $(PROGRAMS)
 
 iscsid: $(COMMON_SRCS) $(IPC_OBJ) $(INITIATOR_SRCS) iscsid.o
-	$(CC) $(CFLAGS) $^ $(DBM_LIB) -o $@
+	$(CC) $(CFLAGS) $^ -o $@
 
 iscsiadm: $(COMMON_SRCS) strings.o discovery.o iscsiadm.o
-	$(CC) $(CFLAGS) $^ $(DBM_LIB) -o $@
+	$(CC) $(CFLAGS) $^ -o $@
 
 iscsistart: $(IPC_OBJ) $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) iscsistart.o \
 		statics.o
diff -aurp open-iscsi/usr/mgmt_ipc.c open-iscsi.db/usr/mgmt_ipc.c
--- open-iscsi/usr/mgmt_ipc.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/mgmt_ipc.c	2006-08-21 04:14:15.000000000 -0400
@@ -82,44 +82,15 @@ mgmt_ipc_close(int fd)
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_node_read(struct mgmt_ipc_db *dbt, int rid, node_rec_t *rec)
+mgmt_ipc_session_login(queue_task_t *qtask, node_rec_t *rec)
 {
-	idbm_t *db = NULL;
-
-	if (dbt->init) {
-		db = dbt->init(dconfig->config_file);
-		if (!db) {
-			return MGMT_IPC_ERR_IDBM_FAILURE;
-		}
-	}
-
-	if (dbt->node_read(db, rid, rec)) {
-		log_error("node record [%06x] not found!", rid);
-		return MGMT_IPC_ERR_NOT_FOUND;
-	}
-
-	if (dbt->terminate)
-		dbt->terminate(db);
-	return 0;
-}
-
-static mgmt_ipc_err_e
-mgmt_ipc_session_login(struct mgmt_ipc_db *dbt, queue_task_t *qtask, int rid)
-{
-	mgmt_ipc_err_e rc;
-	node_rec_t rec;
-
-	if ((rc = mgmt_ipc_node_read(dbt, rid, &rec)))
-		return rc;
-
-	if (session_find_by_rec(&rec)) {
-		log_error("session with corresponding record [%06x] "
-			  "found!", rid);
+	if (session_find_by_rec(rec)) {
+		log_error("session [%s,%s,%d] not found!", rec->name,
+			  rec->conn[0].address, rec->conn[0].port);
 		return MGMT_IPC_ERR_EXISTS;
 	}
 
-
-	return session_login_task(&rec, qtask);
+	return session_login_task(rec, qtask);
 }
 
 static mgmt_ipc_err_e
@@ -134,7 +105,6 @@ mgmt_ipc_session_activelist(queue_task_t
 		item = provider[i].sessions.q_forw;
 		while (item != &provider[i].sessions) {
 			session = (iscsi_session_t *)item;
-			rsp->u.activelist.rids[rsp->u.activelist.cnt]= session->nrec.id;
 			rsp->u.activelist.sids[rsp->u.activelist.cnt]= session->id;
 			rsp->u.activelist.cnt++;
 			item = item->q_forw;
@@ -145,8 +115,8 @@ mgmt_ipc_session_activelist(queue_task_t
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_session_getstats(queue_task_t *qtask, int rid, int sid,
-		iscsiadm_rsp_t *rsp)
+mgmt_ipc_session_getstats(queue_task_t *qtask, int sid,
+			  iscsiadm_rsp_t *rsp)
 {
 	iscsi_session_t *session;
 	struct qelem *item;
@@ -165,7 +135,7 @@ mgmt_ipc_session_getstats(queue_task_t *
 					MGMT_IPC_GETSTATS_BUF_MAX);
 				if (rc) {
 					log_error("get_stats(): IPC error %d "
-						"session [%02d:%06x]", rc, sid, rid);
+						"session [%02d]", rc, sid);
 					return MGMT_IPC_ERR_INTERNAL;
 				}
 				return MGMT_IPC_OK;
@@ -178,18 +148,13 @@ mgmt_ipc_session_getstats(queue_task_t *
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_session_logout(struct mgmt_ipc_db *dbt, queue_task_t *qtask, int rid)
+mgmt_ipc_session_logout(queue_task_t *qtask, node_rec_t *rec)
 {
-	mgmt_ipc_err_e rc;
-	node_rec_t rec;
 	iscsi_session_t *session;
 
-	if ((rc = mgmt_ipc_node_read(dbt, rid, &rec)))
-		return rc;
-
-	if (!(session = session_find_by_rec(&rec))) {
-		log_error("session with corresponding record [%06x] "
-			  "not found!", rid);
+	if (!(session = session_find_by_rec(rec))) {
+		log_error("session [%s,%s,%d] not found!", rec->name,
+			  rec->conn[0].address, rec->conn[0].port);
 		return MGMT_IPC_ERR_NOT_FOUND;
 	}
 
@@ -197,15 +162,9 @@ mgmt_ipc_session_logout(struct mgmt_ipc_
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_session_sync(struct mgmt_ipc_db *dbt, queue_task_t *qtask, int rid,
-		      int sid)
+mgmt_ipc_session_sync(queue_task_t *qtask, node_rec_t *rec, int sid)
 {
-	mgmt_ipc_err_e rc;
-	node_rec_t rec;
-
-	if ((rc = mgmt_ipc_node_read(dbt, rid, &rec)))
-		return rc;
-	return iscsi_sync_session(&rec, qtask, sid);
+	return iscsi_sync_session(rec, qtask, sid);
 }
 
 static mgmt_ipc_err_e
@@ -233,13 +192,13 @@ mgmt_ipc_cfg_filename(queue_task_t *qtas
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_conn_add(queue_task_t *qtask, int rid, int cid)
+mgmt_ipc_conn_add(queue_task_t *qtask, int cid)
 {
 	return MGMT_IPC_ERR;
 }
 
 static mgmt_ipc_err_e
-mgmt_ipc_conn_remove(queue_task_t *qtask, int rid, int cid)
+mgmt_ipc_conn_remove(queue_task_t *qtask, int cid)
 {
 	return MGMT_IPC_ERR;
 }
@@ -329,7 +288,7 @@ mgmt_peeruser(int sock, char *user)
 }
 
 static int
-mgmt_ipc_handle(struct mgmt_ipc_db *dbt, int accept_fd)
+mgmt_ipc_handle(int accept_fd)
 {
 	struct sockaddr addr;
 	int fd, rc = 0, immrsp = 0;
@@ -374,13 +333,13 @@ mgmt_ipc_handle(struct mgmt_ipc_db *dbt,
 
 	switch(req.command) {
 	case MGMT_IPC_SESSION_LOGIN:
-		rsp.err = mgmt_ipc_session_login(dbt, qtask, req.u.session.rid);
+		rsp.err = mgmt_ipc_session_login(qtask, &req.u.session.rec);
 		break;
 	case MGMT_IPC_SESSION_LOGOUT:
-		rsp.err = mgmt_ipc_session_logout(dbt, qtask, req.u.session.rid);
+		rsp.err = mgmt_ipc_session_logout(qtask, &req.u.session.rec);
 		break;
 	case MGMT_IPC_SESSION_SYNC:
-		rsp.err = mgmt_ipc_session_sync(dbt, qtask, req.u.session.rid,
+		rsp.err = mgmt_ipc_session_sync(qtask, &req.u.session.rec,
 						req.u.session.sid);
 		break;
 	case MGMT_IPC_SESSION_ACTIVELIST:
@@ -388,17 +347,15 @@ mgmt_ipc_handle(struct mgmt_ipc_db *dbt,
 		immrsp = 1;
 		break;
 	case MGMT_IPC_SESSION_STATS:
-		rsp.err = mgmt_ipc_session_getstats(qtask, req.u.session.rid,
-				req.u.session.sid, &rsp);
+		rsp.err = mgmt_ipc_session_getstats(qtask, req.u.session.sid,
+						    &rsp);
 		immrsp = 1;
 		break;
 	case MGMT_IPC_CONN_ADD:
-		rsp.err = mgmt_ipc_conn_add(qtask, req.u.conn.rid,
-					    req.u.conn.cid);
+		rsp.err = mgmt_ipc_conn_add(qtask, req.u.conn.cid);
 		break;
 	case MGMT_IPC_CONN_REMOVE:
-		rsp.err = mgmt_ipc_conn_remove(qtask, req.u.conn.rid,
-					       req.u.conn.cid);
+		rsp.err = mgmt_ipc_conn_remove(qtask, req.u.conn.cid);
 		break;
 	case MGMT_IPC_CONFIG_INAME:
 		rsp.err = mgmt_ipc_cfg_initiatorname(qtask, &rsp);
@@ -467,8 +424,7 @@ reaper(void)
 #define POLL_MAX	2
 
 /* TODO: this should go somewhere else */
-void event_loop(struct iscsi_ipc *ipc, int control_fd, int mgmt_ipc_fd,
-		struct mgmt_ipc_db *dbt)
+void event_loop(struct iscsi_ipc *ipc, int control_fd, int mgmt_ipc_fd)
 {
 	struct pollfd poll_array[POLL_MAX];
 	int res;
@@ -486,7 +442,7 @@ void event_loop(struct iscsi_ipc *ipc, i
 				ipc->ctldev_handle();
 
 			if (poll_array[POLL_IPC].revents)
-				if (mgmt_ipc_handle(dbt, mgmt_ipc_fd) == 1)
+				if (mgmt_ipc_handle(mgmt_ipc_fd) == 1)
 					break;
 		} else if (res < 0) {
 			if (errno == EINTR) {
diff -aurp open-iscsi/usr/mgmt_ipc.h open-iscsi.db/usr/mgmt_ipc.h
--- open-iscsi/usr/mgmt_ipc.h	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/mgmt_ipc.h	2006-08-21 01:55:06.000000000 -0400
@@ -21,6 +21,7 @@
 
 #include "types.h"
 #include "iscsi_if.h"
+#include "config.h"
 
 #define ISCSIADM_NAMESPACE	"ISCSIADM_ABSTRACT_NAMESPACE"
 #define PEERUSER_MAX		64
@@ -67,11 +68,10 @@ typedef struct iscsiadm_req {
 	union {
 		/* messages */
 		struct msg_session {
-			int rid;
 			int sid;
+			node_rec_t rec;
 		} session;
 		struct msg_conn {
-			int rid;
 			int sid;
 			int cid;
 		} conn;
@@ -87,7 +87,6 @@ typedef struct iscsiadm_rsp {
 		struct msg_activelist {
 #define MGMT_IPC_ACTIVELIST_MAX		64
 			int sids[MGMT_IPC_ACTIVELIST_MAX];
-			int rids[MGMT_IPC_ACTIVELIST_MAX];
 			int cnt;
 		} activelist;
 #define MGMT_IPC_GETSTATS_BUF_MAX	(sizeof(struct iscsi_uevent) + \
@@ -106,20 +105,10 @@ typedef struct iscsiadm_rsp {
 	} u;
 } iscsiadm_rsp_t;
 
-struct idbm;
-struct node_rec;
-
-struct mgmt_ipc_db {
-	struct idbm *(*init)(char *configfile);
-	int (* node_read)(struct idbm *db, int rec_id, struct node_rec *rec);
-	void (* terminate)(struct idbm *db);
-};
-
 struct iscsi_ipc *ipc;
 
 void need_reap(void);
-void event_loop(struct iscsi_ipc *ipc, int control_fd, int mgmt_ipc_fd,
-		struct mgmt_ipc_db *db);
+void event_loop(struct iscsi_ipc *ipc, int control_fd, int mgmt_ipc_fd);
 int mgmt_ipc_listen(void);
 void mgmt_ipc_close(int fd);
 
diff -aurp open-iscsi/usr/util.c open-iscsi.db/usr/util.c
--- open-iscsi/usr/util.c	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/util.c	2006-08-21 01:55:06.000000000 -0400
@@ -52,6 +52,31 @@ int oom_adjust(void)
 	return 0;
 }
 
+char*
+str_to_ipport(char *str, int *port, int delim)
+{
+	char *sport = str;
+
+	if (!strchr(str, '.')) {
+		if (*str == '[') {
+			if (!(sport = strchr(str, ']')))
+				return NULL;
+			*sport++ = '\0';
+			str++;
+		} else
+			sport = NULL;
+	}
+
+	if (sport && (sport = strchr(sport, delim))) {
+		*sport = '\0';
+		sport++;
+		*port = strtoul(sport, NULL, 10);
+	} else
+		*port = DEF_ISCSI_PORT;
+
+	return str;
+}
+
 static int iscsid_connect(void)
 {
 	int fd, err;
@@ -200,6 +225,10 @@ void iscsid_handle_error(int err)
 	log_error("initiator reported error (%d - %s)", err, err_msgs[err]);
 }
 
+
+/*
+ * SYSFS helpers
+ */
 int read_sysfs_int_attr(char *path, uint32_t *retval)
 {
 	int fd, err = 0;
@@ -252,6 +281,57 @@ int read_sysfs_str_attr(char *path, char
 	return err;
 }
 
+int find_ids_by_session(int *sid, char *targetname, char *addr,
+			int *port, char *session)
+{
+	int ret;
+	char *sysfs_file;
+
+	sysfs_file = malloc(PATH_MAX);
+	if (!sysfs_file)
+		return -ENOMEM;
+
+	if (sscanf(session, "session%d", sid) != 1) {
+		log_error("invalid session '%s'", session);
+		ret = errno;
+		goto free_file;
+	}
+
+	memset(sysfs_file, 0, PATH_MAX);
+	sprintf(sysfs_file, "/sys/class/iscsi_session/%s/targetname", session);
+	ret = read_sysfs_str_attr(sysfs_file, targetname, TARGET_NAME_MAXLEN);
+	if (ret) {
+		log_error("could not read session targetname: %d", ret);
+		goto free_file;
+	}
+
+	memset(sysfs_file, 0, PATH_MAX);
+	sprintf(sysfs_file, "/sys/class/iscsi_connection/connection%d:0/"
+		"persistent_address", *sid);
+	ret = read_sysfs_str_attr(sysfs_file, addr, NI_MAXHOST);
+	if (ret) {
+		log_error("could not read conn addr: %d", ret);
+		goto free_file;
+	}
+
+	memset(sysfs_file, 0, PATH_MAX);
+	sprintf(sysfs_file, "/sys/class/iscsi_connection/connection%d:0/"
+		"persistent_port", *sid);
+	ret = read_sysfs_int_attr(sysfs_file, (uint32_t *)port);
+	if (ret) {
+		log_error("Could not read conn port %d\n", ret);
+		goto free_file;
+	}
+
+	log_debug(7, "found targetname %s address %s port %d\n",
+		  targetname, addr, *port);
+	return 0;
+
+free_file:
+	free(sysfs_file);
+	return ret;
+}
+
 void check_class_version(void)
 {
 	char version[20];
diff -aurp open-iscsi/usr/util.h open-iscsi.db/usr/util.h
--- open-iscsi/usr/util.h	2006-08-20 21:39:36.000000000 -0400
+++ open-iscsi.db/usr/util.h	2006-08-21 01:55:06.000000000 -0400
@@ -9,6 +9,9 @@ struct node_rec;
 void check_class_version(void);
 extern int oom_adjust(void);
 extern void daemon_init(void);
+
+extern int find_ids_by_session(int *sid, char *targetname,
+				char *addr, int *port, char *sys_session);
 extern int read_sysfs_int_attr(char *path, uint32_t *retval);
 extern int read_sysfs_str_attr(char *path, char *retval, int len);
 
@@ -16,4 +19,5 @@ extern int do_iscsid(int *ipc_fd, struct
 		     struct iscsiadm_rsp *rsp);
 extern void iscsid_handle_error(int err);
 
+extern char *str_to_ipport(char *str, int *port, int delim);
 extern void idbm_node_setup_defaults(struct node_rec *rec);
