aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/muser.h13
-rw-r--r--lib/muser_ctx.c18
-rw-r--r--samples/gpio-pci-idio-16.c8
-rw-r--r--samples/null.c8
-rw-r--r--samples/server.c7
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");