diff options
author | swapnili <swapnil.ingle@nutanix.com> | 2020-11-25 17:24:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 17:24:28 +0100 |
commit | adc65938c8771172b80d6d523f7b1608ba3f8d46 (patch) | |
tree | 1b8eb890516c644e14eb4199cd6d1cb9f340755b | |
parent | 7e48fee45f938bdb1f562155a9159e950eba4a5f (diff) | |
download | libvfio-user-adc65938c8771172b80d6d523f7b1608ba3f8d46.zip libvfio-user-adc65938c8771172b80d6d523f7b1608ba3f8d46.tar.gz libvfio-user-adc65938c8771172b80d6d523f7b1608ba3f8d46.tar.bz2 |
Split log setup from lm_create_ctx() to lm_setup_log() (#126)
* Split log setup from lm_create_ctx() to lm_setup_log()
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r-- | include/muser.h | 13 | ||||
-rw-r--r-- | lib/muser_ctx.c | 18 | ||||
-rw-r--r-- | samples/gpio-pci-idio-16.c | 8 | ||||
-rw-r--r-- | samples/null.c | 8 | ||||
-rw-r--r-- | samples/server.c | 7 |
5 files changed, 42 insertions, 12 deletions
diff --git a/include/muser.h b/include/muser.h index 6d0dcc6..58652f3 100644 --- a/include/muser.h +++ b/include/muser.h @@ -239,14 +239,19 @@ typedef struct { * @trans: transport type * @path: path to socket file. * @flags: context flag - * @log: log function - * @log_lvl: logging level * @pvt: private data * @returns the lm_ctx to be used or NULL on error. Sets errno. */ lm_ctx_t *lm_create_ctx(lm_trans_t trans, const char *path, - int flags, lm_log_fn_t *log, lm_log_lvl_t log_lvl, - void *pvt); + int flags, void *pvt); + +/** + * Setup logging information. + * @lm_ctx: the libmuser context + * @log: logging function + * @log_lvl: logging level + */ +int lm_setup_log(lm_ctx_t *lm_ctx, lm_log_fn_t *log, lm_log_lvl_t log_lvl); //TODO: Check other PCI header registers suitable to be filled by device. // Or should we pass whole lm_pci_hdr_t to be filled by user. diff --git a/lib/muser_ctx.c b/lib/muser_ctx.c index 77d4f7b..fd16bed 100644 --- a/lib/muser_ctx.c +++ b/lib/muser_ctx.c @@ -1226,7 +1226,7 @@ lm_ctx_try_attach(lm_ctx_t *lm_ctx) } lm_ctx_t *lm_create_ctx(lm_trans_t trans, const char *path, int flags, - lm_log_fn_t *log, lm_log_lvl_t log_lvl, void *pvt) + void *pvt) { lm_ctx_t *lm_ctx = NULL; int err = 0; @@ -1245,9 +1245,8 @@ lm_ctx_t *lm_create_ctx(lm_trans_t trans, const char *path, int flags, //FIXME: Validate arguments. // Set other context data. lm_ctx->pvt = pvt; - lm_ctx->log = log; - lm_ctx->log_lvl = log_lvl; lm_ctx->flags = flags; + lm_ctx->log_lvl = LM_ERR; lm_ctx->uuid = strdup(path); if (lm_ctx->uuid == NULL) { @@ -1288,6 +1287,19 @@ out: return lm_ctx; } +int lm_setup_log(lm_ctx_t *lm_ctx, lm_log_fn_t *log, lm_log_lvl_t log_lvl) +{ + + if (log_lvl != LM_ERR && log_lvl != LM_INF && log_lvl != LM_DBG) { + return ERROR(EINVAL); + } + + lm_ctx->log = log; + lm_ctx->log_lvl = log_lvl; + + return 0; +} + int lm_pci_setup_config_hdr(lm_ctx_t *lm_ctx, lm_pci_hdr_id_t id, lm_pci_hdr_ss_t ss, lm_pci_hdr_cc_t cc, UNUSED bool extended) diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 419783f..6d1e6b8 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -99,8 +99,7 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to register signal handler"); } - lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[optind], 0, - verbose ? _log : NULL, LM_DBG, NULL); + lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[optind], 0, NULL); if (lm_ctx == NULL) { if (errno == EINTR) { printf("interrupted\n"); @@ -109,6 +108,11 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to initialize device emulation"); } + ret = lm_setup_log(lm_ctx, _log, verbose ? LM_DBG : LM_ERR); + if (ret < 0) { + err(EXIT_FAILURE, "failed to setup log"); + } + ret = lm_pci_setup_config_hdr(lm_ctx, id, ss, cc, false); if (ret < 0) { fprintf(stderr, "failed to setup pci header\n"); diff --git a/samples/null.c b/samples/null.c index 5d52893..b633059 100644 --- a/samples/null.c +++ b/samples/null.c @@ -78,12 +78,16 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, "missing MUSER socket path"); } - lm_ctx_t *lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[1], 0, null_log, - LM_DBG, NULL); + lm_ctx_t *lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[1], 0, NULL); if (lm_ctx == NULL) { err(EXIT_FAILURE, "failed to create libmuser context"); } + ret = lm_setup_log(lm_ctx, null_log, LM_DBG); + if (ret < 0) { + err(EXIT_FAILURE, "failed to setup log"); + } + ret = pthread_create(&thread, NULL, null_drive, lm_ctx); if (ret != 0) { errno = ret; diff --git a/samples/server.c b/samples/server.c index f39452c..89c0364 100644 --- a/samples/server.c +++ b/samples/server.c @@ -423,11 +423,16 @@ int main(int argc, char *argv[]) } server_data.lm_ctx = lm_ctx = lm_create_ctx(LM_TRANS_SOCK, argv[optind], 0, - verbose ? _log : NULL, LM_DBG, &server_data); + &server_data); if (lm_ctx == NULL) { err(EXIT_FAILURE, "failed to initialize device emulation\n"); } + ret = lm_setup_log(lm_ctx, _log, verbose ? LM_DBG : LM_ERR); + if (ret < 0) { + err(EXIT_FAILURE, "failed to setup log"); + } + ret = lm_pci_setup_config_hdr(lm_ctx, id, ss, cc, false); if (ret < 0) { err(EXIT_FAILURE, "failed to setup PCI header"); |