kdbus.h: implement KDBUS_CMD_{MSG_CANCEL,FREE} with structs (ABI break)
authorDaniel Mack <daniel@zonque.org>
Mon, 6 Oct 2014 16:09:35 +0000 (18:09 +0200)
committerDaniel Mack <daniel@zonque.org>
Mon, 6 Oct 2014 16:12:17 +0000 (18:12 +0200)
Rather than passing a pointer to a u64 with these ioctls, use a struct.
That also allows us to pass (currently unused) flags around.

Signed-off-by: Daniel Mack <daniel@zonque.org>
handle.c
kdbus.h
test/kdbus-util.c
test/test-free.c

index af20cdd7912fa36d956bfa442d521bc578a8177b..389789952dc709a688cd20de32747ac48bc0c2fb 100644 (file)
--- a/handle.c
+++ b/handle.c
@@ -835,7 +835,7 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd,
        }
 
        case KDBUS_CMD_MSG_CANCEL: {
-               u64 cookie;
+               struct kdbus_cmd_cancel cmd_cancel;
 
                if (!kdbus_conn_is_connected(conn)) {
                        ret = -EOPNOTSUPP;
@@ -848,17 +848,17 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd,
                }
 
                /* cancel sync message send requests by cookie */
-               if (copy_from_user(&cookie, buf, sizeof(cookie))) {
+               if (copy_from_user(&cmd_cancel, buf, sizeof(cmd_cancel))) {
                        ret = -EFAULT;
                        break;
                }
 
-               ret = kdbus_cmd_msg_cancel(conn, cookie);
+               ret = kdbus_cmd_msg_cancel(conn, cmd_cancel.cookie);
                break;
        }
 
        case KDBUS_CMD_FREE: {
-               u64 off;
+               struct kdbus_cmd_free cmd_free;
 
                if (!kdbus_conn_is_connected(conn) &&
                    !kdbus_conn_is_monitor(conn)) {
@@ -872,12 +872,12 @@ static long kdbus_handle_ioctl_ep_connected(struct file *file, unsigned int cmd,
                }
 
                /* free the memory used in the receiver's pool */
-               if (copy_from_user(&off, buf, sizeof(off))) {
+               if (copy_from_user(&cmd_free, buf, sizeof(cmd_free))) {
                        ret = -EFAULT;
                        break;
                }
 
-               ret = kdbus_pool_release_offset(conn->pool, off);
+               ret = kdbus_pool_release_offset(conn->pool, cmd_free.offset);
                break;
        }
 
diff --git a/kdbus.h b/kdbus.h
index 801125946bee639db2deab361138732bec7ed8e6..8994b5673dfafd1230c0c62f67ef95ff2ad5bab5 100644 (file)
--- a/kdbus.h
+++ b/kdbus.h
@@ -443,6 +443,31 @@ struct kdbus_cmd_recv {
        __u64 offset;
 } __attribute__((aligned(8)));
 
+/**
+ * struct kdbus_cmd_cancel - struct to cancel a synchronously pending message
+ * @cookie             The cookie of the pending message
+ * @flags              Flags for the free command. Currently unused.
+ *
+ * This struct is used with the KDBUS_CMD_CANCEL ioctl.
+ */
+struct kdbus_cmd_cancel {
+       __u64 cookie;
+       __u64 flags;
+} __attribute__((aligned(8)));
+
+/**
+ * struct kdbus_cmd_free - struct to free a slice of memory in the pool
+ * @offset             The offset of the memory slice, as returned by other
+ *                     ioctls
+ * @flags              Flags for the free command. Currently unused.
+ *
+ * This struct is used with the KDBUS_CMD_FREE ioctl.
+ */
+struct kdbus_cmd_free {
+       __u64 offset;
+       __u64 flags;
+} __attribute__((aligned(8)));
+
 /**
  * enum kdbus_policy_access_type - permissions of a policy record
  * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid
@@ -710,6 +735,7 @@ struct kdbus_conn_info {
  */
 struct kdbus_cmd_update {
        __u64 size;
+       __u64 flags;
        struct kdbus_item items[0];
 } __attribute__((aligned(8)));
 
@@ -807,8 +833,10 @@ enum kdbus_ioctl_type {
                                              struct kdbus_msg),
        KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
                                              struct kdbus_cmd_recv),
-       KDBUS_CMD_MSG_CANCEL =          _IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
-       KDBUS_CMD_FREE =                _IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
+       KDBUS_CMD_MSG_CANCEL =          _IOW(KDBUS_IOCTL_MAGIC, 0x42,
+                                            struct kdbus_cmd_cancel),
+       KDBUS_CMD_FREE =                _IOW(KDBUS_IOCTL_MAGIC, 0x43,
+                                            struct kdbus_cmd_free),
 
        KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
                                              struct kdbus_cmd_name),
index 2d5cfb395cf24f58bdc19cde72f617d71d7d79a0..a34fc98b38979ff7ea6d11d029e9bcb2bee798df 100644 (file)
@@ -782,9 +782,13 @@ int kdbus_msg_recv_poll(struct kdbus_conn *conn,
 
 int kdbus_free(const struct kdbus_conn *conn, uint64_t offset)
 {
+       struct kdbus_cmd_free cmd_free;
        int ret;
 
-       ret = ioctl(conn->fd, KDBUS_CMD_FREE, &offset);
+       cmd_free.offset = offset;
+       cmd_free.flags = 0;
+
+       ret = ioctl(conn->fd, KDBUS_CMD_FREE, &cmd_free);
        if (ret < 0) {
                kdbus_printf("KDBUS_CMD_FREE failed: %d (%m)\n", ret);
                return -errno;
index c6679558a342fe7ec8bc35a0d3e5d0f1ebfec6d2..5a14e2b35135c30d5146e9e19117d5c718715b66 100644 (file)
 int kdbus_test_free(struct kdbus_test_env *env)
 {
        int ret;
-       uint64_t off = 0;
+       struct kdbus_cmd_free cmd_free;
+
+       cmd_free.flags = 0;
+       cmd_free.offset = 0;
 
        /* free an unallocated buffer */
-       ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &off);
+       ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &cmd_free);
        ASSERT_RETURN(ret == -1 && errno == ENXIO);
 
        /* free a buffer out of the pool's bounds */
-       off = POOL_SIZE + 1;
-       ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &off);
+       cmd_free.offset = POOL_SIZE + 1;
+       ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &cmd_free);
        ASSERT_RETURN(ret == -1 && errno == ENXIO);
 
        return TEST_OK;