redmine

preparing for release

- cluster subsystem code #ifdef-ed
- auto-generation of optstring for getopt_long to avoid human factor while
editing supported options.
... ... @@ -29,6 +29,7 @@
-- 0x8E30679C
*/
#ifdef CLUSTER_SUPPORT
#include "common.h"
#include "cluster.h"
... ... @@ -480,3 +481,5 @@ int cluster_capture(const char *path) {
return 0;
}
#endif
... ...
... ... @@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef CLUSTER_SUPPORT
enum nodestatus {
NODESTATUS_DOESNTEXIST = 0,
NODESTATUS_OFFLINE,
... ... @@ -72,3 +74,5 @@ extern int cluster_capture(const char *fpath);
extern int cluster_modtime_update(const char *dirpath, short int dirlevel, mode_t st_mode);
extern int cluster_initialsync();
#endif
... ...
... ... @@ -87,8 +87,10 @@
#define COLLECTDELAY_INSTANT ((unsigned int)~0)
enum flags_enum {
HELP = 'h',
BACKGROUND = 'b',
PTHREAD = 'p',
#ifdef CLUSTER_SUPPORT
CLUSTERIFACE = 'c',
CLUSTERMCASTIPADDR = 'm',
CLUSTERMCASTIPPORT = 'P',
... ... @@ -97,10 +99,11 @@ enum flags_enum {
CLUSTERHDLMIN = 'o',
CLUSTERHDLMAX = 'O',
CLUSTERSDLMAX = 's',
HELP = 'h',
#endif
DELAY = 't',
BFILEDELAY = 'T',
SYNCDELAY = 'w',
BFILETHRESHOLD = 'B',
DEBUG = 'D',
QUITE = 'q',
VERBOSE = 'v',
... ... @@ -117,7 +120,6 @@ enum flags_enum {
#endif
INOTIFY = 'i',
LABEL = 'l',
BFILETHRESHOLD = 'B',
VERSION = 'V',
};
typedef enum flags_enum flags_t;
... ... @@ -166,6 +168,7 @@ struct options {
char *destdir;
char *watchdirwslash;
char *destdirwslash;
#ifdef CLUSTER_SUPPORT
char *cluster_iface;
char *cluster_mcastipaddr;
char *cluster_nodename;
... ... @@ -174,6 +177,8 @@ struct options {
uint16_t cluster_hash_dl_min;
uint16_t cluster_hash_dl_max;
uint16_t cluster_scan_dl_max;
unsigned int cluster_timeout;
#endif
size_t watchdirlen;
size_t destdirlen;
size_t watchdirsize;
... ... @@ -191,7 +196,6 @@ struct options {
unsigned int rsyncinclimit;
time_t synctime;
unsigned int synctimeout;
unsigned int cluster_timeout;
sigset_t *sigset;
char isignoredexitcode[(1<<8)];
};
... ...
... ... @@ -64,7 +64,7 @@ static struct option long_options[] =
{"label", no_argument, NULL, LABEL},
{"help", no_argument, NULL, HELP},
{"version", no_argument, NULL, VERSION},
{0, 0, 0, 0}
{NULL, 0, NULL, 0}
};
int syntax() {
... ... @@ -85,80 +85,94 @@ int version() {
int parse_arguments(int argc, char *argv[], struct options *options_p) {
int c;
int option_index = 0;
// Generating "optstring" (man 3 getopt_long) with using information from struct array "long_options"
char *optstring = alloca((('z'-'a'+1)*2 + '9'-'0'+1)*2 + 1);
char *optstring_ptr = optstring;
struct option *lo_ptr = long_options;
while(lo_ptr->name != NULL) {
*(optstring_ptr++) = lo_ptr->val;
if(lo_ptr->has_arg == required_argument)
*(optstring_ptr++) = ':';
lo_ptr++;
}
*optstring_ptr = 0;
// Parsing arguments
while(1) {
c = getopt_long(argc, argv, "bT:B:d:t:l:pw:qvDFhaVRUL:Ik:x:"
#ifdef FANOTIFY_SUPPORT
"f"
#endif
#ifdef CLUSTER_SUPPORT
"c:m:P:W:n:o:O:s:"
#endif
, long_options, &option_index);
c = getopt_long(argc, argv, optstring, long_options, &option_index);
if (c == -1) break;
switch (c) {
case '?':
case 'h':
case HELP:
syntax();
break;
case 'c':
#ifdef CLUSTER_SUPPORT
case CLUSTERIFACE:
options_p->cluster_iface = optarg;
break;
case 'm':
case CLUSTERMCASTIPADDR:
options_p->cluster_mcastipaddr = optarg;
break;
case 'W':
case CLUSTERMCASTIPPORT:
options_p->cluster_mcastipport = (uint16_t)atoi(optarg);
break;
case CLUSTERTIMEOUT
options_p->cluster_timeout = (unsigned int)atol(optarg);
break;
case 'n':
case CLUSTERNODENAME:
options_p->cluster_nodename = optarg;
break;
case 'd':
case CLUSTERHDLMIN:
options_p->cluster_hash_dl_min = (uint16_t)atoi(optarg);
break;
case CLUSTERHDLMAX:
options_p->cluster_hash_dl_max = (uint16_t)atoi(optarg);
break;
case CLUSTERSDLMAX:
options_p->cluster_scan_dl_max = (uint16_t)atoi(optarg);
break;
#endif
case OUTLISTSDIR:
options_p->listoutdir = optarg;
break;
case 'l':
case LABEL:
options_p->label = optarg;
break;
case 'w':
case SYNCDELAY:
options_p->syncdelay = (unsigned int)atol(optarg);
case 't':
break;
case DELAY:
options_p->_queues[QUEUE_NORMAL].collectdelay = (unsigned int)atol(optarg);
break;
case 'T':
case BFILEDELAY:
options_p->_queues[QUEUE_BIGFILE].collectdelay = (unsigned int)atol(optarg);
break;
case 'B':
case BFILETHRESHOLD:
options_p->bfilethreshold = (unsigned long)atol(optarg);
break;
#ifdef FANOTIFY_SUPPORT
case 'f':
case FANOTIFY:
options_p->notifyengine = NE_FANOTIFY;
break;
#endif
case 'i':
case INOTIFY:
options_p->notifyengine = NE_INOTIFY;
break;
case 'L':
case RSYNCINCLIMIT:
options_p->rsyncinclimit = (unsigned int)atol(optarg);
break;
case 'k':
case SYNCTIMEOUT:
options_p->synctimeout = (unsigned int)atol(optarg);
break;
case 'x':
case IGNOREEXITCODE:
options_p->isignoredexitcode[(unsigned char)atoi(optarg)] = 1;
break;
case 'V':
case VERSION:
version();
break;
case CLUSTERHDLMIN:
options_p->cluster_hash_dl_min = (uint16_t)atoi(optarg);
break;
case CLUSTERHDLMAX:
options_p->cluster_hash_dl_max = (uint16_t)atoi(optarg);
break;
case CLUSTERSDLMAX:
options_p->cluster_scan_dl_max = (uint16_t)atoi(optarg);
break;
default:
options_p->flags[c]++;
break;
... ... @@ -343,9 +357,11 @@ int main(int argc, char *argv[]) {
options.label = DEFAULT_LABEL;
options.rsyncinclimit = DEFAULT_RSYNC_INCLUDELINESLIMIT;
options.synctimeout = DEFAULT_SYNCTIMEOUT;
#ifdef CLUSTER_SUPPORT
options.cluster_hash_dl_min = DEFAULT_CLUSTERHDLMIN;
options.cluster_hash_dl_max = DEFAULT_CLUSTERHDLMAX;
options.cluster_scan_dl_max = DEFAULT_CLUSTERSDLMAX;
#endif
parse_arguments(argc, argv, &options);
out_init(options.flags);
... ... @@ -354,6 +370,7 @@ int main(int argc, char *argv[]) {
ret = EINVAL;
}
#ifdef CLUSTER_SUPPORT
if((options.flags[RSYNC]>1) && (options.cluster_iface != NULL)) {
printf_e("Error: Option \"-RR\" cannot be used in conjunction with \"--cluster-iface\".\n");
ret = EINVAL;
... ... @@ -397,6 +414,7 @@ int main(int argc, char *argv[]) {
options.cluster_nodename_len = strlen(options.cluster_nodename);
}
}
#endif // CLUSTER_SUPPORT
{
char *rwatchdir = realpath(options.watchdir, NULL);
... ...
... ... @@ -651,8 +651,10 @@ static int sync_queuesync(const char *fpath, eventinfo_t *evinfo, options_t *opt
eventinfo_t *evinfo_dup = (eventinfo_t *)xmalloc(sizeof(*evinfo_dup));
memcpy(evinfo_dup, evinfo, sizeof(*evinfo_dup));
#ifdef CLUSTER_SUPPORT
if(options_p->cluster_iface)
cluster_capture(fpath);
#endif
return indexes_queueevent(indexes_p, strdup(fpath), evinfo_dup, queue_id);
}
... ... @@ -765,10 +767,12 @@ int sync_initialsync_rsync_walk(options_t *options_p, const char *dirpath, index
int sync_initialsync(const char *path, options_t *options_p, indexes_t *indexes_p, initsync_t initsync) {
printf_ddd("Debug3: sync_initialsync(\"%s\", options_p, indexes_p, %i)\n", path, initsync);
#ifdef CLUSTER_SUPPORT
if(initsync == INITSYNC_FULL) {
if(options_p->cluster_iface)
return cluster_initialsync();
}
#endif
if(!options_p->flags[RSYNC]) {
// non-RSYNC case:
... ... @@ -869,6 +873,7 @@ int sync_notify_mark(int notify_d, options_t *options_p, const char *accpath, co
return wd;
}
#ifdef CLUSTER_SUPPORT
static inline int sync_mark_walk_cluster_modtime_update(options_t *options_p, const char *path, short int dirlevel, mode_t st_mode) {
if(options_p->cluster_iface) {
int ret=cluster_modtime_update(path, dirlevel, st_mode);
... ... @@ -877,6 +882,7 @@ static inline int sync_mark_walk_cluster_modtime_update(options_t *options_p, co
}
return 0;
}
#endif
int sync_mark_walk(int notify_d, options_t *options_p, const char *dirpath, indexes_t *indexes_p) {
const char *rootpaths[] = {dirpath, NULL};
... ... @@ -894,7 +900,9 @@ int sync_mark_walk(int notify_d, options_t *options_p, const char *dirpath, inde
FTSENT *node;
while((node = fts_read(tree))) {
#ifdef CLUSTER_SUPPORT
int ret;
#endif
printf_dd("Debug3: walking: \"%s\" (depth %u): fts_info == %i\n", node->fts_path, node->fts_level, node->fts_info);
switch(node->fts_info) {
... ... @@ -906,14 +914,18 @@ int sync_mark_walk(int notify_d, options_t *options_p, const char *dirpath, inde
case FTS_SLNONE:
case FTS_F:
case FTS_NSOK:
#ifdef CLUSTER_SUPPORT
if((ret=sync_mark_walk_cluster_modtime_update(options_p, node->fts_path, node->fts_level, S_IFREG)))
return ret;
#endif
continue;
// To mark:
case FTS_D:
case FTS_DOT:
#ifdef CLUSTER_SUPPORT
if((ret=sync_mark_walk_cluster_modtime_update(options_p, node->fts_path, node->fts_level, S_IFDIR)))
return ret;
#endif
break;
// Error cases:
case FTS_ERR:
... ... @@ -1009,15 +1021,19 @@ static inline int sync_dosync_exec(options_t *options_p, const char *evmask_str,
static int sync_dosync(const char *fpath, uint32_t evmask, options_t *options_p, indexes_t *indexes_p) {
int ret;
#ifdef CLUSTER_SUPPORT
ret = cluster_lock(fpath);
if(ret) return ret;
#endif
char *evmask_str = xmalloc(1<<8);
sprintf(evmask_str, "%u", evmask);
ret = sync_dosync_exec(options_p, evmask_str, fpath);
free(evmask_str);
#ifdef CLUSTER_SUPPORT
ret = cluster_unlock_all();
#endif
return ret;
}
... ... @@ -1506,14 +1522,18 @@ int sync_idle(int notify_d, options_t *options_p, indexes_t *indexes_p) {
printf_ddd("Debug3: sync_idle(): calling sync_idle_dosync_collectedevents()\n");
#ifdef CLUSTER_SUPPORT
ret = cluster_lock_byindexes();
if(ret) return ret;
#endif
ret = sync_idle_dosync_collectedevents(options_p, indexes_p);
if(ret) return ret;
#ifdef CLUSTER_SUPPORT
ret = cluster_unlock_all();
if(ret) return ret;
#endif
return 0;
}
... ... @@ -2089,6 +2109,7 @@ int sync_run(options_t *options_p) {
i++;
}
#ifdef CLUSTER_SUPPORT
// Initializing cluster subsystem
if(options_p->cluster_iface == NULL) {
... ... @@ -2098,6 +2119,7 @@ int sync_run(options_t *options_p) {
return ret;
}
}
#endif
// Initializing rand-generator if it's required
... ... @@ -2139,6 +2161,7 @@ int sync_run(options_t *options_p) {
i++;
}
#ifdef CLUSTER_SUPPORT
if(options_p->cluster_iface == NULL) {
int _ret;
_ret = cluster_deinit();
... ... @@ -2147,6 +2170,7 @@ int sync_run(options_t *options_p) {
ret = _ret;
}
}
#endif
#ifdef VERYPARANOID
// One second for another threads
... ...