Skip to content

Commit

Permalink
modules/kvs: Log to flux not stderr
Browse files Browse the repository at this point in the history
Replace lingering log calls that log to stderr with calls that
log to flux logging facility.  Requires passing optional flux_t
handle to internal lookup and commit APIs.

Remove lingering unnecessary includes of log.h throughout.

Fixes #1165
  • Loading branch information
chu11 committed Sep 15, 2017
1 parent 3cd405f commit 2be2edd
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 38 deletions.
13 changes: 8 additions & 5 deletions src/modules/kvs/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <flux/core.h>
#include <jansson.h>

#include "src/common/libutil/log.h"
#include "src/common/libkvs/treeobj.h"

#include "commit.h"
Expand All @@ -48,6 +47,7 @@ struct commit_mgr {
int noop_stores; /* for kvs.stats.get, etc.*/
zhash_t *fences;
zlist_t *ready;
flux_t *h;
void *aux;
};

Expand Down Expand Up @@ -164,7 +164,7 @@ void commit_cleanup_dirty_cache_entry (commit_t *c, struct cache_entry *hp)
if (kvs_util_json_hash (c->cm->hash_name,
cache_entry_get_json (hp),
ref) < 0)
log_err ("kvs_util_json_hash");
flux_log_error (c->cm->h, "kvs_util_json_hash");
else {
ret = cache_remove_entry (c->cm->cache, ref);
assert (ret == 1);
Expand Down Expand Up @@ -193,7 +193,7 @@ static int store_cache (commit_t *c, int current_epoch, json_t *o,

if (kvs_util_json_hash (c->cm->hash_name, o, ref) < 0) {
saved_errno = errno;
log_err ("kvs_util_json_hash");
flux_log_error (c->cm->h, "kvs_util_json_hash");
goto done;
}
if (!(hp = cache_lookup (c->cm->cache, ref, current_epoch))) {
Expand Down Expand Up @@ -377,7 +377,8 @@ static int commit_link_dirent (commit_t *c, int current_epoch,
}

if (refcount != 1) {
log_msg ("invalid dirref count: %d", refcount);
flux_log (c->cm->h, LOG_ERR, "invalid dirref count: %d",
refcount);
saved_errno = EPERM;
goto done;
}
Expand Down Expand Up @@ -626,7 +627,7 @@ commit_process_t commit_process (commit_t *c,
case COMMIT_STATE_FINISHED:
break;
default:
log_msg ("invalid commit state: %d", c->state);
flux_log (c->cm->h, LOG_ERR, "invalid commit state: %d", c->state);
c->errnum = EPERM;
return COMMIT_PROCESS_ERROR;
}
Expand Down Expand Up @@ -699,6 +700,7 @@ int commit_iter_dirty_cache_entries (commit_t *c,

commit_mgr_t *commit_mgr_create (struct cache *cache,
const char *hash_name,
flux_t *h,
void *aux)
{
commit_mgr_t *cm;
Expand All @@ -718,6 +720,7 @@ commit_mgr_t *commit_mgr_create (struct cache *cache,
saved_errno = ENOMEM;
goto error;
}
cm->h = h;
cm->aux = aux;
return cm;

Expand Down
3 changes: 3 additions & 0 deletions src/modules/kvs/commit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _FLUX_KVS_COMMIT_H
#define _FLUX_KVS_COMMIT_H

#include <flux/core.h>
#include <czmq.h>

#include "cache.h"
Expand Down Expand Up @@ -96,8 +97,10 @@ void commit_cleanup_dirty_cache_entry (commit_t *c, struct cache_entry *hp);
* commit_mgr_t API
*/

/* flux_t is optional, if NULL logging will go to stderr */
commit_mgr_t *commit_mgr_create (struct cache *cache,
const char *hash_name,
flux_t *h,
void *aux);

void commit_mgr_destroy (commit_mgr_t *cm);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "src/common/libutil/blobref.h"
#include "src/common/libutil/monotime.h"
#include "src/common/libutil/tstat.h"
#include "src/common/libutil/log.h"
#include "src/common/libkvs/treeobj.h"

#include "waitqueue.h"
Expand Down Expand Up @@ -127,7 +126,7 @@ static kvs_ctx_t *getctx (flux_t *h)
}
ctx->cache = cache_create ();
ctx->watchlist = wait_queue_create ();
ctx->cm = commit_mgr_create (ctx->cache, ctx->hash_name, ctx);
ctx->cm = commit_mgr_create (ctx->cache, ctx->hash_name, h, ctx);
if (!ctx->cache || !ctx->watchlist || !ctx->cm) {
saved_errno = ENOMEM;
goto error;
Expand Down Expand Up @@ -706,6 +705,7 @@ static void get_request_cb (flux_t *h, flux_msg_handler_t *w,
ctx->rootdir,
root_ref,
key,
h,
flags)))
goto done;

Expand Down Expand Up @@ -811,6 +811,7 @@ static void watch_request_cb (flux_t *h, flux_msg_handler_t *w,
ctx->rootdir,
NULL,
key,
h,
flags)))
goto done;

Expand Down
1 change: 0 additions & 1 deletion src/modules/kvs/kvs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <jansson.h>

#include "src/common/libutil/blobref.h"
#include "src/common/libutil/log.h"

#include "types.h"

Expand Down
29 changes: 20 additions & 9 deletions src/modules/kvs/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <jansson.h>

#include "src/common/libutil/blobref.h"
#include "src/common/libutil/log.h"
#include "src/common/libkvs/treeobj.h"

#include "cache.h"
Expand Down Expand Up @@ -70,6 +69,9 @@ struct lookup {
char *root_ref_copy;

char *path;

flux_t *h;

int flags;

void *aux;
Expand Down Expand Up @@ -231,7 +233,7 @@ static bool walk (lookup_t *lh)
}

if (refcount != 1) {
log_msg ("invalid dirref count: %d", refcount);
flux_log (lh->h, LOG_ERR, "invalid dirref count: %d", refcount);
lh->errnum = EPERM;
goto error;
}
Expand All @@ -257,9 +259,10 @@ static bool walk (lookup_t *lh)
}
else {
char *s = json_dumps (wl->dirent, 0);
log_msg ("%s: unknown/unexpected dirent type: "
"lh->path=%s pathcomp=%s: wl->dirent=%s ",
__FUNCTION__, lh->path, pathcomp, s);
flux_log (lh->h, LOG_ERR,
"%s: unknown/unexpected dirent type: "
"lh->path=%s pathcomp=%s: wl->dirent=%s ",
__FUNCTION__, lh->path, pathcomp, s);
free (s);
lh->errnum = EPERM;
goto error;
Expand Down Expand Up @@ -353,6 +356,7 @@ lookup_t *lookup_create (struct cache *cache,
const char *root_dir,
const char *root_ref,
const char *path,
flux_t *h,
int flags)
{
lookup_t *lh = NULL;
Expand Down Expand Up @@ -392,6 +396,7 @@ lookup_t *lookup_create (struct cache *cache,
saved_errno = ENOMEM;
goto cleanup;
}
lh->h = h;
lh->flags = flags;

lh->aux = NULL;
Expand Down Expand Up @@ -622,7 +627,8 @@ bool lookup (lookup_t *lh)
goto done;
}
if (refcount != 1) {
log_msg ("invalid dirref count: %d", refcount);
flux_log (lh->h, LOG_ERR, "invalid dirref count: %d",
refcount);
lh->errnum = EPERM;
goto done;
}
Expand Down Expand Up @@ -657,7 +663,8 @@ bool lookup (lookup_t *lh)
goto done;
}
if (refcount != 1) {
log_msg ("invalid valref count: %d", refcount);
flux_log (lh->h, LOG_ERR, "invalid valref count: %d",
refcount);
lh->errnum = EPERM;
goto done;
}
Expand Down Expand Up @@ -717,7 +724,8 @@ bool lookup (lookup_t *lh)
lh->val = json_incref (lh->wdirent);
} else {
char *s = json_dumps (lh->wdirent, 0);
log_msg ("%s: corrupt dirent: %s", __FUNCTION__, s);
flux_log (lh->h, LOG_ERR, "%s: corrupt dirent: %s",
__FUNCTION__, s);
free (s);
lh->errnum = EPERM;
goto done;
Expand All @@ -727,7 +735,10 @@ bool lookup (lookup_t *lh)
case LOOKUP_STATE_FINISHED:
break;
default:
log_msg_exit ("%s: invalid state %d", __FUNCTION__, lh->state);
flux_log (lh->h, LOG_ERR, "%s: invalid state %d",
__FUNCTION__, lh->state);
lh->errnum = EPERM;
goto done;
}

done:
Expand Down
3 changes: 3 additions & 0 deletions src/modules/kvs/lookup.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#ifndef _FLUX_KVS_LOOKUP_H
#define _FLUX_KVS_LOOKUP_H

#include <flux/core.h>
#include "cache.h"

typedef struct lookup lookup_t;

/* Initialize a lookup handle
* - If root_ref is same as root_dir, can be set to NULL.
* - flux_t is optional, if NULL logging will go to stderr
*/
lookup_t *lookup_create (struct cache *cache,
int current_epoch,
const char *root_dir,
const char *root_ref,
const char *path,
flux_t *h,
int flags);

/* Destroy a lookup handle */
Expand Down
Loading

0 comments on commit 2be2edd

Please sign in to comment.