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,
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:
void method( pwr_tStatus *sts, char *methodName, wb_tMethod *method);
int nextVolatileVid( pwr_tStatus *sts, char *name);
static void volumeNameToFilename( pwr_tStatus *sts, char *name, char *filename);
private:
void loadDirList( pwr_tStatus *status);
void loadCommonMeta( pwr_tStatus *status);
......
......@@ -501,7 +501,8 @@ ldh_GetChildMnt(ldh_tSession session, pwr_tOid oid, pwr_tOid *coid)
a.value( &moid);
wb_object mo = sp->object(moid);
mo = mo.first();
if ( mo)
mo = mo.first();
if ( mo) {
*coid = mo.oid();
return mo.sts();
......
......@@ -55,10 +55,9 @@ typedef struct {
} lfu_t_volumelist;
typedef struct {
pwr_tVolumeId volid;
int version;
pwr_tClassId classid;
int file_checked;
pwr_tVid vid;
pwr_tTime version;
char name[80];
} lfu_t_volref;
pwr_tStatus lfu_volumelist_load(
......@@ -127,12 +126,14 @@ pwr_tStatus lfu_WriteSysObjectFile(
ldh_tSesContext ldhses
);
pwr_tStatus lfu_GetVolRef( char *filename,
char *volname,
pwr_tClassId *volclass,
pwr_tTime *createtime,
pwr_tStatus lfu_GetVolRef( char *filename,
lfu_t_volref **volref,
int *volref_count);
pwr_tStatus lfu_GetVolume( char *filename,
char *name,
pwr_tVid *vid,
pwr_tCid *cid,
pwr_tTime *time);
#ifdef __cplusplus
}
......
......@@ -3,11 +3,13 @@
#include <sys/stat.h>
#include "wb_pkg.h"
#include "wb_error.h"
#include "wb_erep.h"
#include "co_msgwindow.h"
#include "co_dcli.h"
#include "co_cdh.h"
#include "co_time.h"
#include "co_msgwindow.h"
#include "rt_load.h"
wb_pkg::wb_pkg( char *nodelist, bool distribute)
......@@ -96,17 +98,18 @@ void wb_pkg::readConfig()
}
}
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);
char severity = line_item[2][0];
try {
pkg_node& n = getNode( line_item[1]);
if ( num == 3) {
pkg_pattern p( line_item[2]);
if ( num == 4) {
pkg_pattern p( line_item[3], "", severity);
n.push_back( p);
}
else {
pkg_pattern p( line_item[2], line_item[3]);
pkg_pattern p( line_item[3], line_item[4], severity);
n.push_back( p);
}
} catch ( wb_error &e) {
......@@ -130,12 +133,12 @@ void wb_pkg::readConfig()
// Add ld_node file
sprintf( fname, load_cNameNode, load_cDirectory, n.bus());
pkg_pattern pnode( fname);
pkg_pattern pnode( fname, "", 'E');
n.push_back( pnode);
// Add bootfile
sprintf( fname, load_cNameBoot, load_cDirectory, n.name(), n.bus());
pkg_pattern pboot( fname);
pkg_pattern pboot( fname, "", 'E');
n.push_back( pboot);
// Read bootfile, get plc and volumes
......@@ -150,7 +153,7 @@ void wb_pkg::readConfig()
sprintf( dir, "$pwrp_root/%s/exe/", cdh_OpSysToStr( n.opsys()));
sprintf( fname, "%s%s", dir, plcname);
pkg_pattern pplc( fname);
pkg_pattern pplc( fname, "", 'E');
n.push_back( pplc);
}
......@@ -160,27 +163,7 @@ void wb_pkg::readConfig()
strcpy( dir, "$pwrp_load/");
sprintf( fname, "%s%s.dbs", dir, cdh_Low( (char *)(volnamelist + j)));
pkg_pattern pvol( 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
n.checkVolume( fname);
// Check if there are any rtt-files for Root or Sub Volumes
if ( vollist[j] >= ldh_cUserVolMin &&
......@@ -219,8 +202,6 @@ void wb_pkg::readConfig()
}
}
#if 0
#endif
free( volnamelist);
free( vollist);
......@@ -250,6 +231,69 @@ pkg_node& wb_pkg::getNode( char *name)
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)
{
char dev[80];
......@@ -260,6 +304,14 @@ void pkg_node::fetchFiles( bool distribute)
char pack_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++)
m_pattern[i].fetchFiles();
......@@ -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
sprintf( fname, "$pwrp_load/pkg_v_%s.dat", m_name);
dcli_translate_filename( fname, fname);
......@@ -404,6 +468,10 @@ void pkg_node::fetchFiles( bool distribute)
sprintf( cmd, "source %s", pack_fname);
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)
......@@ -511,8 +579,18 @@ void pkg_pattern::fetchFiles()
}
dcli_search_file( m_source, found_file, DCLI_DIR_SEARCH_END);
}
if ( m_filelist.size() == 0)
printf( "-- Warning, no file found, %s\n", m_source);
if ( m_filelist.size() == 0) {
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)
......
......@@ -35,17 +35,21 @@ class pkg_pattern {
char m_source[200];
char m_target[200];
vector<pkg_file> m_filelist;
pkg_node *m_node;
char m_severity;
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_target, target);
}
pkg_pattern( char *source) {
pkg_pattern( char *source) : m_node(0), m_severity('W') {
strcpy( m_source, source);
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_target, x.m_target);
}
......@@ -53,24 +57,51 @@ class pkg_pattern {
char *target() { return m_target;}
bool hasTarget() { return m_target[0] != 0;}
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 {
private:
vector<pkg_pattern> m_pattern;
vector<pkg_file> m_filelist;
vector<pkg_volume> m_volumelist;
char m_name[80];
pwr_mOpSys m_opsys;
int m_bus;
lfu_eDistrSts m_dstatus;
bool m_valid;
int m_errors;
int m_warnings;
public:
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) :
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;}
pwr_mOpSys opsys() { return m_opsys;}
int bus() { return m_bus;}
......@@ -81,9 +112,13 @@ class pkg_node {
void setDStatus( lfu_eDistrSts dstatus) { m_dstatus = dstatus;}
void setValid() { m_valid = true;}
void push_back( pkg_pattern& pattern) {
pattern.node( this);
m_pattern.push_back( pattern);
}
void checkVolume( char *filename);
void fetchFiles( bool distribute);
void incrWarnings() { m_warnings++;}
void incrErrors() { m_errors++;}
};
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