diff options
author | Anuradha <atalur@redhat.com> | 2014-02-10 19:23:42 +0530 |
---|---|---|
committer | Anuradha <atalur@redhat.com> | 2014-02-17 21:27:32 +0530 |
commit | 961ba477f544adcaf641207c6157073214c4f27b (patch) | |
tree | 1a6f01f1716a587dc829de9d1b5eec343555782d /xlators/cluster | |
parent | 0d92798e88c5444fb2cc23663b4ea9a345887756 (diff) |
nsr : Changes made in nsr logging functions
1) File pointers for worker and driver logs are now
in their respective ctx, instead of static file
pointer in nsr logging functions.
2) File pointer for recon-main-log now in
nsr_recon_private_t, instead of a static file pointer
in nsr recon logging function.
3) Changed a few fprintf to gflog.
Change-Id: Iab92e20d1691104bad19b7fe044a1d3ce2792ab3
Signed-off-by: Anuradha <atalur@redhat.com>
Diffstat (limited to 'xlators/cluster')
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_driver.c | 37 | ||||
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_driver.h | 15 | ||||
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_xlator.c | 24 | ||||
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_xlator.h | 7 | ||||
-rw-r--r-- | xlators/cluster/nsr-server/src/leader.c | 6 |
5 files changed, 65 insertions, 24 deletions
diff --git a/xlators/cluster/nsr-recon/src/recon_driver.c b/xlators/cluster/nsr-recon/src/recon_driver.c index 778f59413..163084958 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.c +++ b/xlators/cluster/nsr-recon/src/recon_driver.c @@ -98,7 +98,10 @@ recon_create_log (char *member, char *module) (void)mkdir(dpath,0777); (void)asprintf(&fpath,"%s/%s",dpath,module); if (fpath) { - fp = fopen(fpath,"w"); + fp = fopen(fpath,"a"); + if (setvbuf (fp, NULL, _IONBF, 0)) { + return NULL; + } free(fpath); } free(dpath); @@ -108,9 +111,9 @@ recon_create_log (char *member, char *module) } void -_nsr_driver_log (const char *func, int line, char *member, char *fmt, ...) +_nsr_driver_log (const char *func, int line, char *member, FILE *fp, + char *fmt, ...) { - static FILE *fp = NULL; va_list ap; char *buf = NULL; int retval; @@ -133,9 +136,9 @@ _nsr_driver_log (const char *func, int line, char *member, char *fmt, ...) void _nsr_worker_log (const char *func, int line, char *member, - char *type, uint32_t index, char *fmt, ...) + char *type, uint32_t index, FILE *fp, + char *fmt, ...) { - static FILE *fp = NULL; va_list ap; char *buf = NULL; int retval; @@ -145,7 +148,7 @@ _nsr_worker_log (const char *func, int line, char *member, if (asprintf(&name,"%s-%u",type,index) < 1) { return; } - fp = recon_create_log(member,"recon-main-log"); + fp = recon_create_log (member, name); if (!fp) { return; } @@ -2296,6 +2299,7 @@ nsr_reconciliation_driver(void *arg) nsr_recon_driver_ctx_t **driver_ctx, *ctx; int32_t bm; xlator_t *this = priv->this; + char *con_name, *data_name; driver_ctx = &priv->driver_thread_context; (*driver_ctx) = GF_CALLOC (1, @@ -2308,6 +2312,11 @@ nsr_reconciliation_driver(void *arg) ctx = *driver_ctx; ctx->this = priv->this; ctx->replica_group_size = replica_group_size; + + ctx->fp = recon_create_log (priv->replica_group_members[0], "nsr-driver-log"); + if (!ctx->fp) + return NULL; + if ((pthread_mutex_init(&(ctx->mutex), NULL)) || (pthread_cond_init(&(ctx->cv), NULL))){ nsr_driver_log (this->name, GF_LOG_ERROR, "mutex init error \n"); @@ -2343,8 +2352,22 @@ nsr_reconciliation_driver(void *arg) } for (i=0; i < replica_group_size; i++) { ctx->workers[i].control_worker = &control_s[i]; + if (asprintf(&con_name,"recon-con-%u",i) < 1) { + return NULL; + } + ctx->workers[i].control_worker->fp = recon_create_log + (priv->replica_group_members[0], con_name); + if (!ctx->workers[i].control_worker->fp) + return NULL; ctx->workers[i].data_worker = &data_s[i]; - } + if (asprintf (&data_name,"recon-data-%u",i) <1) { + return NULL; + } + ctx->workers[i].data_worker->fp = recon_create_log + (priv->replica_group_members[0], data_name); + if (!ctx->workers[i].data_worker->fp) + return NULL; + } nsr_driver_log (this->name, GF_LOG_INFO, "creating threads \n"); // Create the worker threads diff --git a/xlators/cluster/nsr-recon/src/recon_driver.h b/xlators/cluster/nsr-recon/src/recon_driver.h index 096ca88b5..4030c9d73 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.h +++ b/xlators/cluster/nsr-recon/src/recon_driver.h @@ -233,6 +233,9 @@ typedef struct _nsr_per_node_worker_s { pthread_mutex_t mutex; //mutex to guard the state pthread_cond_t cv; //condition variable for signaling the worker thread gf_boolean_t is_control; +#if defined(NSR_DEBUG) + FILE *fp; +#endif } nsr_per_node_worker_t; typedef struct _nsr_replica_worker_s { @@ -257,6 +260,9 @@ typedef struct _nsr_recon_driver_ctxt { uint32_t current_term; jmp_buf *env; nsr_mode_t mode; // default set to seq +#if defined(NSR_DEBUG) + FILE *fp; +#endif } nsr_recon_driver_ctx_t; void * @@ -278,7 +284,8 @@ extern int nsr_debug_level; extern FILE *recon_create_log (char *member, char *module); extern void -_nsr_driver_log (const char *func, int line, char *member, char *fmt, ...); +_nsr_driver_log (const char *func, int line, char *member, FILE *fp, + char *fmt, ...); #define nsr_driver_log(dom, levl, fmt...) do { \ FMT_WARN (fmt); \ @@ -286,13 +293,15 @@ _nsr_driver_log (const char *func, int line, char *member, char *fmt, ...); nsr_recon_private_t *priv = ctx->this->private; \ _nsr_driver_log (__FUNCTION__, __LINE__, \ priv->replica_group_members[0], \ + ctx->fp, \ ##fmt); \ } \ } while (0) extern void _nsr_worker_log (const char *func, int line, char *member, - char *type, uint32_t index, char *fmt, ...); + char *type, uint32_t index, FILE *fp, + char *fmt, ...); #define nsr_worker_log(dom, levl, fmt...) do { \ FMT_WARN (fmt); \ @@ -303,7 +312,7 @@ _nsr_worker_log (const char *func, int line, char *member, priv->replica_group_members[0], \ ctx->is_control ? "recon-con" : \ "recon-data", \ - ctx->index, \ + ctx->index, ctx->fp, \ ##fmt); \ } \ } while (0) diff --git a/xlators/cluster/nsr-recon/src/recon_xlator.c b/xlators/cluster/nsr-recon/src/recon_xlator.c index 0c140d8d6..c3c8d4d55 100644 --- a/xlators/cluster/nsr-recon/src/recon_xlator.c +++ b/xlators/cluster/nsr-recon/src/recon_xlator.c @@ -42,9 +42,9 @@ typedef struct _nsr_txn_id_s { #if defined(NSR_DEBUG) void -_recon_main_log (const char *func, int line, char *member, char *fmt, ...) +_recon_main_log (const char *func, int line, char *member, FILE *fp, + char *fmt, ...) { - static FILE *fp = NULL; va_list ap; char *buf = NULL; int retval; @@ -812,38 +812,38 @@ init (xlator_t *this) priv = GF_CALLOC (1, sizeof (*priv), gf_mt_recon_private_t); if (!priv) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "priv allocation error\n"); return -1; } GF_OPTION_INIT ("replica-group-size", priv->replica_group_size, uint32, err); GF_OPTION_INIT ("vol-name", priv->volname, str, err); if (!priv->volname) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "missing volname option (required)"); return -1; } GF_OPTION_INIT ("changelog-dir", priv->changelog_base_path, str, err); if (!priv->changelog_base_path) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "missing changelog directory option (required)"); return -1; } GF_OPTION_INIT ("base-dir", priv->base_dir, str, err); if (!priv->base_dir) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "missing brick base directory option (required)"); return -1; } GF_OPTION_INIT ("replica-group-members", members, str, err); if (!members) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "missing membership option (required)"); return -1; } GF_OPTION_INIT ("local-member", local, str, err); if (!local) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "missing local member option (required)"); return -1; } @@ -855,7 +855,7 @@ init (xlator_t *this) strlen(local), gf_mt_recon_private_t); if (!priv->replica_group_members || !(priv->replica_group_members[0])) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "str allocation error\n"); return -1; } @@ -868,7 +868,7 @@ init (xlator_t *this) member = strtok(NULL, ","); priv->replica_group_members[i] = GF_CALLOC (1, strlen(member) + 1, gf_mt_recon_private_t); if (!priv->replica_group_members[i]) { - recon_main_log (this->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "str allocation error\n"); return -1; } @@ -879,6 +879,10 @@ init (xlator_t *this) priv->this = this; this->private = (void *)priv; + priv->fp = recon_create_log (priv->replica_group_members[0], "recon-main-log"); + if (!priv->fp) + return -1; + recon_main_log (this->name, GF_LOG_INFO, "creating reconciliation driver \n"); if (pthread_create(&priv->thread_id, NULL, nsr_reconciliation_driver, priv)) { diff --git a/xlators/cluster/nsr-recon/src/recon_xlator.h b/xlators/cluster/nsr-recon/src/recon_xlator.h index a3c91a741..8c48f6ff6 100644 --- a/xlators/cluster/nsr-recon/src/recon_xlator.h +++ b/xlators/cluster/nsr-recon/src/recon_xlator.h @@ -40,6 +40,9 @@ typedef struct _nsr_recon_private_s { uint32_t txn_id; char *changelog_base_path; char *base_dir; +#if defined(NSR_DEBUG) + FILE *fp; +#endif } nsr_recon_private_t; #define atomic_cmpxchg __sync_val_compare_and_swap @@ -47,7 +50,8 @@ typedef struct _nsr_recon_private_s { #if defined(NSR_DEBUG) extern void -_recon_main_log (const char *func, int line, char *member, char *fmt, ...); +_recon_main_log (const char *func, int line, char *member, FILE *fp, + char *fmt, ...); #define recon_main_log(dom, levl, fmt...) do { \ FMT_WARN (fmt); \ @@ -55,6 +59,7 @@ _recon_main_log (const char *func, int line, char *member, char *fmt, ...); nsr_recon_private_t *priv = this->private; \ _recon_main_log (__FUNCTION__, __LINE__, \ priv->replica_group_members[0], \ + priv->fp, \ ##fmt); \ } \ } while (0) diff --git a/xlators/cluster/nsr-server/src/leader.c b/xlators/cluster/nsr-server/src/leader.c index 645f68bf6..6c3ca6d4f 100644 --- a/xlators/cluster/nsr-server/src/leader.c +++ b/xlators/cluster/nsr-server/src/leader.c @@ -196,13 +196,13 @@ nsr_confirm (xlator_t *this, etcd_session etcd, char *key) fitness = nsr_get_fitness(this); if (asprintf(&vote,"%s,%ld,%ld",priv->brick_uuid,(long)CONFIRMED, fitness) < 0) { - fprintf (stderr, "%s: failed to construct confirmation\n", - __func__); + gf_log (this->name, GF_LOG_ERROR, + "failed to construct confirmation"); return LS_ERROR; } if (etcd_set(etcd,key,vote,vote,LEADER_TTL) != ETCD_OK) { - fprintf (stderr, "%s: failed to confirm\n", __func__); + gf_log (this->name, GF_LOG_ERROR, "failed to confirm"); free(vote); return LS_FAILURE; } |