Commit f6faa7cc authored by claes's avatar claes

Handling and control of dbs-files in volref

parent fda8ddad
...@@ -807,7 +807,52 @@ wb_vrep *wb_erep::createVolume(pwr_tStatus *sts, pwr_tVid vid, pwr_tCid cid, ...@@ -807,7 +807,52 @@ wb_vrep *wb_erep::createVolume(pwr_tStatus *sts, pwr_tVid vid, pwr_tCid cid,
return vrepdb; return vrepdb;
} }
void wb_erep::volumeNameToFilename( pwr_tStatus *sts, char *name, char *filename)
{
char found_file[200];
char vname[200];
char line[200];
char fname[200];
char dir_list[11][200];
int dir_cnt;
int fsts;
// Read directory file
strcpy( dir_list[0], "$pwr_load/");
strcpy( dir_list[1], "$pwrp_load/");
dir_cnt = 2;
dcli_translate_filename( fname, load_cNameFilePath);
ifstream fp( fname, ios::in);
if ( !fp) {
*sts = LDH__PROJCONFIG;
return;
}
while ( fp.getline( line, sizeof(line))) {
if ( dir_cnt > (int) (sizeof(dir_list)/sizeof(dir_list[0]) - 1))
break;
strcpy( dir_list[dir_cnt], line);
if ( dir_list[dir_cnt][strlen(dir_list[dir_cnt])-1] != '/')
strcat( dir_list[dir_cnt], "/");
dir_cnt++;
}
fp.close();
for ( int i = 0; i < dir_cnt; i++) {
strcpy( vname, dir_list[i]);
cdh_ToLower( &vname[strlen(vname)], name);
strcat( vname, ".dbs");
fsts = dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_INIT);
dcli_search_file( vname, found_file, DCLI_DIR_SEARCH_END);
if ( ODD(fsts)) {
strcpy( filename, vname);
*sts = LDH__SUCCESS;
return;
}
}
*sts = LDH__NOSUCHFILE;
}
...@@ -71,6 +71,8 @@ public: ...@@ -71,6 +71,8 @@ public:
void method( pwr_tStatus *sts, char *methodName, wb_tMethod *method); void method( pwr_tStatus *sts, char *methodName, wb_tMethod *method);
int nextVolatileVid( pwr_tStatus *sts, char *name); int nextVolatileVid( pwr_tStatus *sts, char *name);
static void volumeNameToFilename( pwr_tStatus *sts, char *name, char *filename);
private: private:
void loadDirList( pwr_tStatus *status); void loadDirList( pwr_tStatus *status);
void loadCommonMeta( pwr_tStatus *status); void loadCommonMeta( pwr_tStatus *status);
......
...@@ -501,7 +501,8 @@ ldh_GetChildMnt(ldh_tSession session, pwr_tOid oid, pwr_tOid *coid) ...@@ -501,7 +501,8 @@ ldh_GetChildMnt(ldh_tSession session, pwr_tOid oid, pwr_tOid *coid)
a.value( &moid); a.value( &moid);
wb_object mo = sp->object(moid); wb_object mo = sp->object(moid);
mo = mo.first(); if ( mo)
mo = mo.first();
if ( mo) { if ( mo) {
*coid = mo.oid(); *coid = mo.oid();
return mo.sts(); return mo.sts();
......
...@@ -55,10 +55,9 @@ typedef struct { ...@@ -55,10 +55,9 @@ typedef struct {
} lfu_t_volumelist; } lfu_t_volumelist;
typedef struct { typedef struct {
pwr_tVolumeId volid; pwr_tVid vid;
int version; pwr_tTime version;
pwr_tClassId classid; char name[80];
int file_checked;
} lfu_t_volref; } lfu_t_volref;
pwr_tStatus lfu_volumelist_load( pwr_tStatus lfu_volumelist_load(
...@@ -127,12 +126,14 @@ pwr_tStatus lfu_WriteSysObjectFile( ...@@ -127,12 +126,14 @@ pwr_tStatus lfu_WriteSysObjectFile(
ldh_tSesContext ldhses ldh_tSesContext ldhses
); );
pwr_tStatus lfu_GetVolRef( char *filename, pwr_tStatus lfu_GetVolRef( char *filename,
char *volname,
pwr_tClassId *volclass,
pwr_tTime *createtime,
lfu_t_volref **volref, lfu_t_volref **volref,
int *volref_count); int *volref_count);
pwr_tStatus lfu_GetVolume( char *filename,
char *name,
pwr_tVid *vid,
pwr_tCid *cid,
pwr_tTime *time);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "wb_pkg.h" #include "wb_pkg.h"
#include "wb_error.h" #include "wb_error.h"
#include "wb_erep.h"
#include "co_msgwindow.h" #include "co_msgwindow.h"
#include "co_dcli.h" #include "co_dcli.h"
#include "co_cdh.h" #include "co_cdh.h"
#include "co_time.h" #include "co_time.h"
#include "co_msgwindow.h"
#include "rt_load.h" #include "rt_load.h"
wb_pkg::wb_pkg( char *nodelist, bool distribute) wb_pkg::wb_pkg( char *nodelist, bool distribute)
...@@ -96,17 +98,18 @@ void wb_pkg::readConfig() ...@@ -96,17 +98,18 @@ void wb_pkg::readConfig()
} }
} }
else if ( strcmp( cdh_Low(line_item[0]), "appl") == 0) { else if ( strcmp( cdh_Low(line_item[0]), "appl") == 0) {
if ( !(num == 3 || num == 4)) if ( !(num == 4 || num == 5))
throw wb_error_str("File corrupt " load_cNameDistribute); throw wb_error_str("File corrupt " load_cNameDistribute);
char severity = line_item[2][0];
try { try {
pkg_node& n = getNode( line_item[1]); pkg_node& n = getNode( line_item[1]);
if ( num == 3) { if ( num == 4) {
pkg_pattern p( line_item[2]); pkg_pattern p( line_item[3], "", severity);
n.push_back( p); n.push_back( p);
} }
else { else {
pkg_pattern p( line_item[2], line_item[3]); pkg_pattern p( line_item[3], line_item[4], severity);
n.push_back( p); n.push_back( p);
} }
} catch ( wb_error &e) { } catch ( wb_error &e) {
...@@ -130,12 +133,12 @@ void wb_pkg::readConfig() ...@@ -130,12 +133,12 @@ void wb_pkg::readConfig()
// Add ld_node file // Add ld_node file
sprintf( fname, load_cNameNode, load_cDirectory, n.bus()); sprintf( fname, load_cNameNode, load_cDirectory, n.bus());
pkg_pattern pnode( fname); pkg_pattern pnode( fname, "", 'E');
n.push_back( pnode); n.push_back( pnode);
// Add bootfile // Add bootfile
sprintf( fname, load_cNameBoot, load_cDirectory, n.name(), n.bus()); sprintf( fname, load_cNameBoot, load_cDirectory, n.name(), n.bus());
pkg_pattern pboot( fname); pkg_pattern pboot( fname, "", 'E');
n.push_back( pboot); n.push_back( pboot);
// Read bootfile, get plc and volumes // Read bootfile, get plc and volumes
...@@ -150,7 +153,7 @@ void wb_pkg::readConfig() ...@@ -150,7 +153,7 @@ void wb_pkg::readConfig()
sprintf( dir, "$pwrp_root/%s/exe/", cdh_OpSysToStr( n.opsys())); sprintf( dir, "$pwrp_root/%s/exe/", cdh_OpSysToStr( n.opsys()));
sprintf( fname, "%s%s", dir, plcname); sprintf( fname, "%s%s", dir, plcname);
pkg_pattern pplc( fname); pkg_pattern pplc( fname, "", 'E');
n.push_back( pplc); n.push_back( pplc);
} }
...@@ -160,27 +163,7 @@ void wb_pkg::readConfig() ...@@ -160,27 +163,7 @@ void wb_pkg::readConfig()
strcpy( dir, "$pwrp_load/"); strcpy( dir, "$pwrp_load/");
sprintf( fname, "%s%s.dbs", dir, cdh_Low( (char *)(volnamelist + j))); sprintf( fname, "%s%s.dbs", dir, cdh_Low( (char *)(volnamelist + j)));
pkg_pattern pvol( fname); n.checkVolume( fname);
n.push_back( pvol);
// Add referenced class volumes
#if 0
char vname[80];
pwr_tClassId vclass;
pwr_tTime vtime;
lfu_t_volref *volref;
int volref_cnt;
sts = lfu_GetVolRef( fname, vname, &vclass, &vtime, &volref, &volref_cnt);
if ( EVEN(sts)) throw wb_error(sts);
for ( int i = 0; i < volref_cnt; i++) {
printf( "%d\n", volref->volid);
volref++;
}
#endif
// Check if there are any rtt-files for Root or Sub Volumes // Check if there are any rtt-files for Root or Sub Volumes
if ( vollist[j] >= ldh_cUserVolMin && if ( vollist[j] >= ldh_cUserVolMin &&
...@@ -219,8 +202,6 @@ void wb_pkg::readConfig() ...@@ -219,8 +202,6 @@ void wb_pkg::readConfig()
} }
} }
#if 0
#endif
free( volnamelist); free( volnamelist);
free( vollist); free( vollist);
...@@ -250,6 +231,69 @@ pkg_node& wb_pkg::getNode( char *name) ...@@ -250,6 +231,69 @@ pkg_node& wb_pkg::getNode( char *name)
throw wb_error_str("No such node"); throw wb_error_str("No such node");
} }
void pkg_node::checkVolume( char *filename)
{
lfu_t_volref *volref;
int volref_cnt;
pwr_tVid vol_vid;
pwr_tCid vol_cid;
pwr_tTime vol_time;
char vol_name[80];
bool found;
pwr_tStatus sts;
char fname[200];
sts = lfu_GetVolume( filename, vol_name, &vol_vid, &vol_cid, &vol_time);
if ( EVEN(sts)) throw wb_error(sts);
found = false;
for ( int i = 0; i < (int)m_volumelist.size(); i++) {
if ( m_volumelist[i].m_vid == vol_vid) {
found = true;
if ( m_volumelist[i].m_time.tv_sec != vol_time.tv_sec) {
char msg[200];
sprintf( msg, "Version mismatch volume %s in %s", (volref+i)->name, filename);
MsgWindow::message( 'E', msg, msgw_ePop_No);
m_errors++;
}
break;
}
}
if ( !found) {
pkg_volume vol( vol_name, filename, vol_vid, vol_time);
m_volumelist.push_back( vol);
}
sts = lfu_GetVolRef( filename, &volref, &volref_cnt);
if ( EVEN(sts)) throw wb_error(sts);
for ( int i = 0; i < volref_cnt; i++) {
wb_erep::volumeNameToFilename( &sts, (volref+i)->name, fname);
if ( EVEN(sts)) {
char msg[200];
sprintf( msg, "Loadfile not found: %s", (volref+i)->name);
MsgWindow::message( 'E', msg, msgw_ePop_No);
m_errors++;
continue;
}
checkVolume( fname);
for ( int j = 0; j < (int)m_volumelist.size(); j++) {
if ( m_volumelist[j].m_vid == (volref+i)->vid) {
if ( m_volumelist[j].m_time.tv_sec != (volref+i)->version.tv_sec) {
char msg[200];
sprintf( msg, "Version mismatch volume %s in %s", (volref+i)->name, filename);
MsgWindow::message( 'E', msg, msgw_ePop_No);
m_errors++;
}
break;
}
}
}
free( (char *)volref);
}
void pkg_node::fetchFiles( bool distribute) void pkg_node::fetchFiles( bool distribute)
{ {
char dev[80]; char dev[80];
...@@ -260,6 +304,14 @@ void pkg_node::fetchFiles( bool distribute) ...@@ -260,6 +304,14 @@ void pkg_node::fetchFiles( bool distribute)
char pack_fname[200]; char pack_fname[200];
char fname[200]; char fname[200];
// Add volumes to pattern
for ( int i = 0; i < (int)m_volumelist.size(); i++) {
if ( !m_volumelist[i].m_isSystem) {
pkg_pattern vol( m_volumelist[i].m_filename, "$pwrp_load/", 'E');
push_back( vol);
}
}
for ( int i = 0; i < (int)m_pattern.size(); i++) for ( int i = 0; i < (int)m_pattern.size(); i++)
m_pattern[i].fetchFiles(); m_pattern[i].fetchFiles();
...@@ -290,6 +342,18 @@ void pkg_node::fetchFiles( bool distribute) ...@@ -290,6 +342,18 @@ void pkg_node::fetchFiles( bool distribute)
} }
} }
if ( m_errors) {
char msg[200];
sprintf( msg, "Distribute errors node %s: %d errors, %d warnings", m_name, m_errors, m_warnings);
MsgWindow::message( 'E', msg, msgw_ePop_Yes);
throw wb_error_str( msg);
}
else if ( m_warnings) {
char msg[200];
sprintf( msg, "Distribute warnings node %s: %d warnings", m_name, m_warnings);
MsgWindow::message( 'W', msg, msgw_ePop_Yes);
}
// Read and increment package version // Read and increment package version
sprintf( fname, "$pwrp_load/pkg_v_%s.dat", m_name); sprintf( fname, "$pwrp_load/pkg_v_%s.dat", m_name);
dcli_translate_filename( fname, fname); dcli_translate_filename( fname, fname);
...@@ -404,6 +468,10 @@ void pkg_node::fetchFiles( bool distribute) ...@@ -404,6 +468,10 @@ void pkg_node::fetchFiles( bool distribute)
sprintf( cmd, "source %s", pack_fname); sprintf( cmd, "source %s", pack_fname);
system( cmd); system( cmd);
char msg[200];
sprintf( msg, "Distribute to node %s", m_name);
MsgWindow::message( 'I', msg, msgw_ePop_No);
} }
void wb_pkg::copyPackage( char *pkg_name) void wb_pkg::copyPackage( char *pkg_name)
...@@ -511,8 +579,18 @@ void pkg_pattern::fetchFiles() ...@@ -511,8 +579,18 @@ void pkg_pattern::fetchFiles()
} }
dcli_search_file( m_source, found_file, DCLI_DIR_SEARCH_END); dcli_search_file( m_source, found_file, DCLI_DIR_SEARCH_END);
} }
if ( m_filelist.size() == 0) if ( m_filelist.size() == 0) {
printf( "-- Warning, no file found, %s\n", m_source); char msg[200];
sprintf( msg, "No file found: %s", m_source);
MsgWindow::message( m_severity, msg, msgw_ePop_No);
if ( m_node) {
if ( m_severity == 'E')
m_node->incrErrors();
else
m_node->incrWarnings();
}
}
} }
pkg_file::pkg_file( char *source, char *target) pkg_file::pkg_file( char *source, char *target)
......
...@@ -35,17 +35,21 @@ class pkg_pattern { ...@@ -35,17 +35,21 @@ class pkg_pattern {
char m_source[200]; char m_source[200];
char m_target[200]; char m_target[200];
vector<pkg_file> m_filelist; vector<pkg_file> m_filelist;
pkg_node *m_node;
char m_severity;
public: public:
pkg_pattern( char *source, char *target) { pkg_pattern( char *source, char *target, char severity = 'W')
: m_node(0), m_severity(severity) {
strcpy( m_source, source); strcpy( m_source, source);
strcpy( m_target, target); strcpy( m_target, target);
} }
pkg_pattern( char *source) { pkg_pattern( char *source) : m_node(0), m_severity('W') {
strcpy( m_source, source); strcpy( m_source, source);
strcpy( m_target, ""); strcpy( m_target, "");
} }
pkg_pattern( const pkg_pattern& x) : m_filelist(x.m_filelist) { pkg_pattern( const pkg_pattern& x) : m_filelist(x.m_filelist), m_node(x.m_node),
m_severity(x.m_severity) {
strcpy( m_source, x.m_source); strcpy( m_source, x.m_source);
strcpy( m_target, x.m_target); strcpy( m_target, x.m_target);
} }
...@@ -53,24 +57,51 @@ class pkg_pattern { ...@@ -53,24 +57,51 @@ class pkg_pattern {
char *target() { return m_target;} char *target() { return m_target;}
bool hasTarget() { return m_target[0] != 0;} bool hasTarget() { return m_target[0] != 0;}
void fetchFiles(); void fetchFiles();
void node( pkg_node *node) { m_node = node;}
};
class pkg_volume {
friend class pkg_node;
private:
char m_name[80];
char m_filename[200];
pwr_tVid m_vid;
pwr_tTime m_time;
bool m_isSystem;
public:
pkg_volume( char *name, char *filename, pwr_tVid vid, pwr_tTime time) :
m_vid(vid), m_time(time), m_isSystem(false)
{
strcpy( m_name, name);
strcpy( m_filename, filename);
if ( strncmp( m_filename, "$pwr_load/", 10) == 0)
m_isSystem = true;
}
}; };
class pkg_node { class pkg_node {
private: private:
vector<pkg_pattern> m_pattern; vector<pkg_pattern> m_pattern;
vector<pkg_file> m_filelist; vector<pkg_file> m_filelist;
vector<pkg_volume> m_volumelist;
char m_name[80]; char m_name[80];
pwr_mOpSys m_opsys; pwr_mOpSys m_opsys;
int m_bus; int m_bus;
lfu_eDistrSts m_dstatus; lfu_eDistrSts m_dstatus;
bool m_valid; bool m_valid;
int m_errors;
int m_warnings;
public: public:
pkg_node( char *name): m_opsys(pwr_mOpSys__), m_bus(0), pkg_node( char *name): m_opsys(pwr_mOpSys__), m_bus(0),
m_dstatus(lfu_eDistrSts_Normal), m_valid(false) { strcpy( m_name, name);} m_dstatus(lfu_eDistrSts_Normal), m_valid(false), m_errors(0), m_warnings(0)
{ strcpy( m_name, name);}
pkg_node( char *name, pwr_mOpSys opsys, int bus, lfu_eDistrSts dstatus) : pkg_node( char *name, pwr_mOpSys opsys, int bus, lfu_eDistrSts dstatus) :
m_opsys(opsys), m_bus(bus), m_dstatus(dstatus), m_opsys(opsys), m_bus(bus), m_dstatus(dstatus),
m_valid(true) { strcpy( m_name, name); } m_valid(true), m_errors(0), m_warnings(0)
{ strcpy( m_name, name); }
char *name() { return m_name;} char *name() { return m_name;}
pwr_mOpSys opsys() { return m_opsys;} pwr_mOpSys opsys() { return m_opsys;}
int bus() { return m_bus;} int bus() { return m_bus;}
...@@ -81,9 +112,13 @@ class pkg_node { ...@@ -81,9 +112,13 @@ class pkg_node {
void setDStatus( lfu_eDistrSts dstatus) { m_dstatus = dstatus;} void setDStatus( lfu_eDistrSts dstatus) { m_dstatus = dstatus;}
void setValid() { m_valid = true;} void setValid() { m_valid = true;}
void push_back( pkg_pattern& pattern) { void push_back( pkg_pattern& pattern) {
pattern.node( this);
m_pattern.push_back( pattern); m_pattern.push_back( pattern);
} }
void checkVolume( char *filename);
void fetchFiles( bool distribute); void fetchFiles( bool distribute);
void incrWarnings() { m_warnings++;}
void incrErrors() { m_errors++;}
}; };
class wb_pkg { class wb_pkg {
......
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