Commit 4e1beb45 authored by 's avatar
Browse files

Added DiMAPI support to "devgroup" feature.

Socketnames for sockets to mapids are changed each time a new thread of mapicommd is started depending on the target device.


git-svn-id: file:///home/svn/mapi/trunk@1210 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 669852d3
......@@ -10,6 +10,10 @@
throughput.
It does not affect DiMAPI at all (it does not use local socket).
^ Update: Client while connecting to remote via DiMAPI connects
locally too (?), so it is forced to connect to the newest (last
started) local mapid instance, does not metter if it is binding
any device or not.
It does affect offline flows. Clients running offline flows are
always connected to mapid binding devgroup 0 (or none).
......@@ -45,6 +49,8 @@
eth0 1
/dev/dag0 2
0 <-- devgroup of the newest (last started) instance of mapid
EOF
Client application when creating flow (mapi_create_flow) chooses
the appropriate instance of mapid automatically, as it is looked
......@@ -73,7 +79,7 @@
/* End implementation dependencies ----------------------------------------- */
/* Constructor for database instance. */
struct devgroupdb *new_devgroupdb() {
struct devgroupdb *new_devgroupdb(int defaultgroupid) {
struct devgroupdb *db = NULL;
db = (struct devgroupdb *) malloc(sizeof(struct devgroupdb));
......@@ -82,6 +88,7 @@ struct devgroupdb *new_devgroupdb() {
exit(MAPID_MEM_ALLOCATION_ERROR);
}
db->first = NULL;
db->defaultgroupid = defaultgroupid;
return db;
}
......@@ -119,6 +126,11 @@ int devgroupdb_getgroupidbydevice(struct devgroupdb *db, char *device) {
return 0; /* default */
}
/* Returns defaultgroupid of db */
int devgroupdb_getgroupid(struct devgroupdb *db) {
return db->defaultgroupid;
}
/* Sets groupid of device in db */
int devgroupdb_setgroupidbydevice(struct devgroupdb *db, char *device, int groupid) {
struct devgroupdbitem *item;
......@@ -208,12 +220,12 @@ int devgroupdb_getdevgroupdbfd(char *filename) {
return fd;
}
void devgroupdb_freedevgroupdbfd(fd) {
void devgroupdb_freedevgroupdbfd(int fd) {
close(fd);
}
/* Loads data into database instance from fd */
int devgroupdb_load(struct devgroupdb *db, int fd) {
int devgroupdb_load(struct devgroupdb *db, int fd, int pwn) {
char *line;
char *device;
int groupid;
......@@ -226,12 +238,15 @@ int devgroupdb_load(struct devgroupdb *db, int fd) {
while(read(fd, chptr, 1)) {
/* *(chptr+1)='\0'; printf("%s", chptr); */
if(strncmp(chptr, "\n", strlen("\n")) == 0) {
*(++chptr) = '\0';
*chptr = '\0';
chptr++;
sscanf(lptr, "%s %d", device, &groupid);
devgroupdb_add(db, device, groupid);
chptr = lptr = line;
} else chptr++;
}
*chptr = '\0';
if(!pwn) sscanf(lptr, "%d", &db->defaultgroupid);
return 0;
}
......@@ -253,26 +268,26 @@ int devgroupdb_save(struct devgroupdb *db, int fd) {
item = item->next;
} while(item != db->first);
}
write(fd, ".", 1);
sprintf(buffer, "%d\0", db->defaultgroupid);
write(fd, buffer, strlen(buffer));
return 0;
}
/* Merge data in database instance with shared database */
/* Merge data in database instance with shared database, shared db is pwned */
int devgroupdb_merge(struct devgroupdb *db, int local) {
struct devgroupdb *existingdb;
struct devgroupdbitem *item;
int fd;
existingdb = new_devgroupdb();
existingdb = new_devgroupdb(db->defaultgroupid);
if(local)
fd = devgroupdb_acquire_rw_lock(MAPIDDEVGROUPDB);
else
fd = devgroupdb_acquire_rw_lock(MAPIDDEVGROUPDBGLOBAL);
devgroupdb_load(existingdb, fd);
devgroupdb_load(existingdb, fd, 1); /* pwn */
item = db->first;
if(item != NULL) {
......@@ -311,7 +326,7 @@ struct devgroupdb *devgroupdb_open(int local) {
struct devgroupdb *db;
int fd;
db = new_devgroupdb();
db = new_devgroupdb(0);
switch(local) {
case 1:
......@@ -332,7 +347,7 @@ struct devgroupdb *devgroupdb_open(int local) {
exit(EXIT_FAILURE);
}
devgroupdb_load(db, fd);
devgroupdb_load(db, fd, 0);
devgroupdb_freedevgroupdbfd(fd);
......
......@@ -22,11 +22,12 @@ struct devgroupdbitem {
struct devgroupdb {
struct devgroupdbitem *first;
int defaultgroupid;
};
/* Interface for server side (mapid). */
struct devgroupdb *new_devgroupdb();
struct devgroupdb *new_devgroupdb(int defaultgroupid);
int devgroupdb_add(struct devgroupdb *db, char *device, int groupid);
int devgroupdb_merge(struct devgroupdb *db, int local);
......@@ -35,6 +36,10 @@ int devgroupdb_merge(struct devgroupdb *db, int local);
struct devgroupdb *devgroupdb_open(int local);
int devgroupdb_getgroupidbydevice(struct devgroupdb *db, char *device);
/* Interface for client side (dimapi request, local connection) */
int devgroupdb_getgroupid(struct devgroupdb *db);
#endif
/* vim: set foldmethod=marker foldmarker=\ {{{,\ }}} foldclose= foldcolumn=0 */
......@@ -201,20 +201,14 @@ int mapiipc_read(struct mapiipcbuf *qbuf)
return 0;
}
// Sets globals (once)
// Sets globals (each thread)
int mapiipc_set_socket_names(char *socket, char *socketglobal) {
if(mapidsocket == NULL && mapidsocketglobal == NULL) {
if(mapidsocket != NULL) free(mapidsocket);
if(mapidsocketglobal != NULL) free(mapidsocketglobal);
mapidsocket = strdup(socket);
mapidsocketglobal = strdup(socketglobal);
return 0;
}
else {
return 1;
}
return -1;
}
int mapiipc_client_init()
......
......@@ -545,13 +545,8 @@ int mapi_create_flow(const char *dev)
local_err = MAPI_DEVICE_INFO_ERR;
return -1;
}
/*
local = devgroupid_islocal();
if(local == -1) {
DEBUG_CMD(printf( "Error wrong global / local \n\n"));
return -1;
}
*/
#ifndef DIMAPI
devgroupdb = devgroupdb_open(3); // try local, global
devgroupid = devgroupdb_getgroupidbydevice(devgroupdb, (char *) dev);
......@@ -566,16 +561,47 @@ int mapi_create_flow(const char *dev)
mapiipc_set_socket_names(mapidsocket, mapidsocketglobal);
//check if flow is remote or not and call the appropriate init function
#ifndef DIMAPI
pthread_once(&mapi_is_initialized, (void*)mapi_init);
#endif
//check if flow is remote or not and call the appropriate init function
#ifdef DIMAPI
if ( strchr(dev,':')==NULL) pthread_once(&mapi_is_initialized, (void*)mapi_init);
if ( strchr(dev,':')==NULL) {
devgroupdb = devgroupdb_open(3); // try local, global
devgroupid = devgroupdb_getgroupidbydevice(devgroupdb, (char *) dev);
if(!devgroupid) {
mapidsocket = printf_string(MAPIDSOCKHOME, getenv("HOME"));
mapidsocketglobal = strdup(MAPIDSOCKGLOBAL);
}
else {
mapidsocket = printf_string(MAPIDGSOCKHOME, getenv("HOME"), devgroupid);
mapidsocketglobal = printf_string(MAPIDGSOCKGLOBAL, devgroupid);
}
mapiipc_set_socket_names(mapidsocket, mapidsocketglobal);
pthread_once(&mapi_is_initialized, (void*)mapi_init);
}
else pthread_once(&dmapi_is_initialized, (void*)dmapi_init);
if ((s = strchr(dev,':'))!=NULL) {
devgroupdb = devgroupdb_open(3); // try local, global
devgroupid = devgroupdb_getgroupid(devgroupdb); // get groupid of last instance of mapid
if(!devgroupid) {
mapidsocket = printf_string(MAPIDSOCKHOME, getenv("HOME"));
mapidsocketglobal = strdup(MAPIDSOCKGLOBAL);
}
else {
mapidsocket = printf_string(MAPIDGSOCKHOME, getenv("HOME"), devgroupid);
mapidsocketglobal = printf_string(MAPIDGSOCKGLOBAL, devgroupid);
}
mapiipc_set_socket_names(mapidsocket, mapidsocketglobal);
devp=strdup(dev);
rflow=(remote_flowdescr_t *)malloc(sizeof(remote_flowdescr_t));
rflow->fd=++fdseed;
......
......@@ -395,6 +395,7 @@ mapid_shutdown (int data)
write_date();
if(daemonize) write(log_fd, " ( was running as daemon )", strlen(" ( was running as daemon )"));
if(onlydevgroup) write(log_fd, " ( was binding limited set of devices (aka devgroup) )", strlen(" ( was binding limited set of devices (aka devgroup) )"));
write(log_fd, "\n\n", 2);
release_write_lock(file_size);
......@@ -2834,7 +2835,7 @@ load_drivers ()
{
cat = pc_get_category ("");
local=pc_get_param(cat,"local");
devgroupdb = new_devgroupdb();
devgroupdb = new_devgroupdb(onlydevgroup);
drvpath = pc_get_param (cat, "drvpath");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment