summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Glisse <jglisse@redhat.com>2017-08-04 17:36:51 -0400
committerJérôme Glisse <jglisse@redhat.com>2017-08-04 17:39:24 -0400
commitd369bb5d29815cb51566f5df0c3cc6ddc1d82a59 (patch)
treee9fb846e57a19f3f34ac92642b13faaf74204857
parent5df632a124dc5d10cb8111957fd460d40f1154a8 (diff)
compote: channel creation
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
-rw-r--r--compote-uapi.h10
-rw-r--r--compote.c18
-rw-r--r--compote.h5
3 files changed, 32 insertions, 1 deletions
diff --git a/compote-uapi.h b/compote-uapi.h
index bbedb2a..83f5e8a 100644
--- a/compote-uapi.h
+++ b/compote-uapi.h
@@ -29,8 +29,18 @@ struct compote_ioctl_mem_free {
uint64_t foffset;
};
+struct compote_ioctl_channel_alloc {
+ uint64_t channel;
+};
+
+struct compote_ioctl_channel_free {
+ uint64_t channel;
+};
+
/* Expose the address space of the calling process through hmm dummy dev file */
#define COMPOTE_IOCTL_MEM_ALLOC _IOWR('H', 0x00, struct compote_ioctl_mem_alloc)
#define COMPOTE_IOCTL_MEM_FREE _IOWR('H', 0x01, struct compote_ioctl_mem_free)
+#define COMPOTE_IOCTL_CHAN_ALLOC _IOWR('H', 0x02, struct compote_ioctl_channel_alloc)
+#define COMPOTE_IOCTL_CHAN_FREE _IOWR('H', 0x03, struct compote_ioctl_channel_free)
#endif /* COMPOTE_UAPI_H */
diff --git a/compote.c b/compote.c
index 49a3ea9..61fc28d 100644
--- a/compote.c
+++ b/compote.c
@@ -31,8 +31,9 @@
int compote_context_new(compote_context_t **ctxp)
{
+ struct compote_ioctl_channel_alloc arg;
compote_context_t *ctx;
- int fd;
+ int fd, ret;
fd = open("/dev/compote", O_RDWR, 0);
if (fd < 0) {
@@ -46,8 +47,15 @@ int compote_context_new(compote_context_t **ctxp)
return -ENOMEM;
}
+ ctx->channel.id = -1UL;
ctx->fd = fd;
+ ret = compote_context_ioctl(ctx, COMPOTE_IOCTL_CHAN_ALLOC, &arg);
+ if (ret) {
+ compote_context_del(&ctx);
+ return ret;
+ }
+
*ctxp = ctx;
return 0;
}
@@ -57,6 +65,14 @@ void compote_context_del(compote_context_t **ctxp)
compote_context_t *ctx = *ctxp;
*ctxp = NULL;
+
+ if (ctx->channel.id != -1UL) {
+ struct compote_ioctl_channel_free arg;
+
+ arg.channel = ctx->channel.id;
+ compote_context_ioctl(ctx, COMPOTE_IOCTL_CHAN_FREE, &arg);
+ }
+
close(ctx->fd);
free(ctx);
}
diff --git a/compote.h b/compote.h
index b7811fb..3b86673 100644
--- a/compote.h
+++ b/compote.h
@@ -19,7 +19,12 @@
#include <stdint.h>
typedef struct {
+ uint64_t id;
+} compote_channel_t;
+
+typedef struct {
int fd;
+ compote_channel_t channel;
} compote_context_t;
typedef struct {