diff options
author | Anuradha <atalur@redhat.com> | 2014-01-20 23:50:40 +0530 |
---|---|---|
committer | Anuradha <atalur@redhat.com> | 2014-01-21 22:55:05 +0530 |
commit | 89a9fcdf7ff2ab00f209b8510ee613683c4f9188 (patch) | |
tree | 94cacc9d0b10f4742c0bd9ce483ef344bc5e9ad6 /xlators/cluster/nsr-recon/src/recon_driver.c | |
parent | 0225d7bc712609232d592d48116ec771cd97c2cf (diff) |
nsr : Fix "special" recon logging functions.
Combining two patches together.
http://review.gluster.org/#/c/6538/4, author : Jeff Darcy
and
http://review.gluster.org/#/c/6748/2, author : Anuradha Talur.
(1) Put logs into /var/log instead of /tmp.
(2) Added debug-level check.
(3) Added function/line information.
(4) Fixed many instances of missing symbol GF_LOG_ERR.
Removing spurious newlines will have to wait until a subsequent patch.
Keeping this one up to date is tedious enough.
Changed the logging directory of reconciliation logs to
/var/log/nsr-logs.
Change-Id: I8ffd901537d77329eddbd17b380c1611607927d6
Credits: Jeff Darcy <jdarcy@redhat.com>
Signed-off-by: Anuradha <atalur@redhat.com>
Diffstat (limited to 'xlators/cluster/nsr-recon/src/recon_driver.c')
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_driver.c | 124 |
1 files changed, 117 insertions, 7 deletions
diff --git a/xlators/cluster/nsr-recon/src/recon_driver.c b/xlators/cluster/nsr-recon/src/recon_driver.c index 0d5560957..084b7f5ce 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.c +++ b/xlators/cluster/nsr-recon/src/recon_driver.c @@ -74,6 +74,94 @@ * APIs. */ +#if defined(NSR_DEBUG) + +/* This lets us change on the fly even if NSR_DEBUG is defined. */ +int nsr_debug_level = GF_LOG_TRACE; + +FILE * +recon_create_log (char *member, char *module) +{ + char *dpath = NULL; + char *p; + char *fpath = NULL; + FILE *fp = NULL; + + (void)mkdir(NSR_LOG_DIR,0777); + (void)asprintf(&dpath,NSR_LOG_DIR"/%s",member); + if (dpath) { + for (p = dpath + strlen(NSR_LOG_DIR) + 1; *p; ++p) { + if (*p == '/') { + *p = '-'; + } + } + (void)mkdir(dpath,0777); + (void)asprintf(&fpath,"%s/%s",dpath,module); + if (fpath) { + fp = fopen(fpath,"w"); + free(fpath); + } + free(dpath); + } + + return fp; +} + +void +_nsr_driver_log (const char *func, int line, char *member, char *fmt, ...) +{ + static FILE *fp = NULL; + va_list ap; + char *buf = NULL; + int retval; + + if (!fp) { + fp = recon_create_log(member,"nsr-driver-log"); + if (!fp) { + return; + } + } + + va_start(ap,fmt); + retval = vasprintf(&buf,fmt,ap); + if (buf) { + fprintf(fp,"[%s:%d] %.*s\n",func,line,retval,buf); + free(buf); + } + va_end(ap); +} + +void +_nsr_worker_log (const char *func, int line, char *member, + char *type, uint32_t index, char *fmt, ...) +{ + static FILE *fp = NULL; + va_list ap; + char *buf = NULL; + int retval; + + if (!fp) { + char *name; + if (asprintf(&name,"%s-%u",type,index) < 1) { + return; + } + fp = recon_create_log(member,"recon-main-log"); + if (!fp) { + return; + } + } + + va_start(ap,fmt); + retval = vasprintf(&buf,fmt,ap); + if (buf) { + fprintf(fp,"[%s:%d] %.*s\n",func,line,retval,buf); + free(buf); + } + va_end(ap); +} + +#endif + /* * This function gets the size of all the extended attributes for a file. * This is used so that caller knows how much to allocate for key-value storage. @@ -309,6 +397,15 @@ nsr_recon_start_work(nsr_per_node_worker_t *ctx, int32_t ret = 0; glfs_fd_t *aux_fd = NULL; // fd of auxilary log char lf[256]; + nsr_recon_private_t *priv = NULL; + char *my_name = NULL; + char *morph_name = NULL, *ptr = NULL; + + priv = this->private; + my_name = GF_CALLOC (1, + strlen (priv->replica_group_members[0]) + 1, + gf_mt_recon_private_t); + strcpy (my_name, priv->replica_group_members[0]); nsr_worker_log(this->name, GF_LOG_INFO, "starting work with volfile %s\n", @@ -336,10 +433,26 @@ nsr_recon_start_work(nsr_per_node_worker_t *ctx, return -1; } + morph_name = GF_CALLOC (1, strlen (my_name) + 1, gf_mt_recon_private_t); + strcpy (morph_name, my_name); + + ptr = strchr (morph_name, '/'); + while (ptr) + { + *ptr = '-'; + ptr = strchr (morph_name, '/'); + } // TBD - convert this to right /usr/local/var/log based log files. - sprintf(lf,"/tmp/logs/%s-%s",(control == _gf_true)?"con":"data",ctx->id); - glfs_set_logging (fs, lf, 7); - glusterfs_this_set(this); + + sprintf(lf, NSR_LOG_DIR"/%s/%s-%"PRIu32, morph_name, + (control == _gf_true)?"glfs-con":"glfs-data", ctx->index); + ret = glfs_set_logging (fs, lf, 7); + if (ret) { + glusterfs_this_set(this); + gf_log (this->name, GF_LOG_ERROR, "glfs logging set failed (%s)", + strerror (errno)); + return -1; + } ret = glfs_init (fs); if (ret != 0) { @@ -1338,7 +1451,7 @@ apply_record(nsr_per_node_worker_t *ctx, } if (glfs_ftruncate_with_xdata(fd, ri->rec.offset, dict) == -1) { GF_ASSERT(0); - nsr_worker_log(this->name, GF_LOG_ERROR + nsr_worker_log(this->name, GF_LOG_ERROR, "trunctae for file %s failed @offset %d\n", ri->rec.gfid,ri->rec.offset ); return; @@ -2641,9 +2754,6 @@ i_am_resolutor: if (state == joiner) { - int32_t chosen = -1; - int32_t last_term = -1, last_ops = -1; - nsr_driver_log (this->name, GF_LOG_INFO, "getting last term info from all members of this group\n"); // Get last term info from all members for this group // which will be the leader(this node) and the node that wants to join. |