ctdb-protocol: Add marshalling for TDB_DATA
authorAmitay Isaacs <amitay@gmail.com>
Mon, 9 Nov 2015 04:58:56 +0000 (15:58 +1100)
committerMartin Schwenke <martins@samba.org>
Wed, 25 Nov 2015 09:16:20 +0000 (10:16 +0100)
This is required when ctdb client wants to send arbitrary data as part
of CTDB_REQ_MESSAGE.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Jeremy Allison <jra@samba.org>
ctdb/protocol/protocol.h
ctdb/protocol/protocol_message.c
ctdb/protocol/protocol_private.h
ctdb/protocol/protocol_types.c

index b20eae0ee10bdd5cf43f4a3efa06718e28b3fe59..a2a0c45da47355d6297e967ee26647a454c0cc4c 100644 (file)
@@ -982,6 +982,8 @@ union ctdb_message_data {
        struct ctdb_disable_message *disable;
        /* SRVID_DISABLE_IP_CHECK */
        uint32_t timeout;
+       /* Other */
+       TDB_DATA data;
 };
 
 struct ctdb_req_message {
index 07d2dbb0ae0c9c1110384253f91d34307604dbb0..696367ef8e9b247cd71cefa14a3f120bb21e8080 100644 (file)
@@ -101,6 +101,10 @@ static size_t ctdb_message_data_len(union ctdb_message_data *mdata,
        case CTDB_SRVID_DISABLE_IP_CHECK:
                len = ctdb_uint32_len(mdata->timeout);
                break;
+
+       default:
+               len = ctdb_tdb_data_len(mdata->data);
+               break;
        }
 
        return len;
@@ -171,6 +175,10 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
        case CTDB_SRVID_DISABLE_IP_CHECK:
                ctdb_uint32_push(mdata->timeout, buf);
                break;
+
+       default:
+               ctdb_tdb_data_push(mdata->data, buf);
+               break;
        }
 }
 
@@ -251,6 +259,10 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
        case CTDB_SRVID_DISABLE_IP_CHECK:
                ret = ctdb_uint32_pull(buf, buflen, mem_ctx, &mdata->timeout);
                break;
+
+       default:
+               ret = ctdb_tdb_data_pull(buf, buflen, mem_ctx, &mdata->data);
+               break;
        }
 
        return ret;
index ffe3fb2017ed0bee2f750cb33f57b684c8d5cb19..65193d9a3f4d3a6dfa77454297cdbeb779602a1e 100644 (file)
@@ -265,6 +265,11 @@ void ctdb_srvid_message_push(struct ctdb_srvid_message *msg, uint8_t *buf);
 int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
                            struct ctdb_srvid_message **out);
 
+size_t ctdb_tdb_data_len(TDB_DATA data);
+void ctdb_tdb_data_push(TDB_DATA data, uint8_t *buf);
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      TDB_DATA *out);
+
 size_t ctdb_disable_message_len(struct ctdb_disable_message *disable);
 void ctdb_disable_message_push(struct ctdb_disable_message *disable,
                               uint8_t *buf);
index f868d767d079911d1b259a312c5ffeeb9bf0f0cc..bb472882e3cc4f6b04d6f9f8bc0a9e17581c366e 100644 (file)
@@ -2424,6 +2424,35 @@ int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        return 0;
 }
 
+size_t ctdb_tdb_data_len(TDB_DATA data)
+{
+       return data.dsize;
+}
+
+void ctdb_tdb_data_push(TDB_DATA data, uint8_t *buf)
+{
+       memcpy(buf, data.dptr, data.dsize);
+}
+
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                      TDB_DATA *out)
+{
+       TDB_DATA data;
+
+       data.dsize = buflen;
+       if (data.dsize > 0) {
+               data.dptr = talloc_memdup(mem_ctx, buf, buflen);
+               if (data.dptr == NULL) {
+                       return ENOMEM;
+               }
+       } else {
+               data.dptr = NULL;
+       }
+
+       *out = data;
+       return 0;
+}
+
 size_t ctdb_server_id_len(struct ctdb_server_id *sid)
 {
        return sizeof(struct ctdb_server_id);