ctdb-protocol: Use ctdb_rec_buffer_traverse to calaculate length of data
authorAmitay Isaacs <amitay@gmail.com>
Thu, 3 Aug 2017 07:50:48 +0000 (17:50 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:23 +0000 (14:59 +0200)
If the parser function is NULL, ctdb_rec_buffer_traverse will return the
amount of data used by ctdb_rec_data structures.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_types.c

index 355cef5e745806a7000b592fbfe4e113a71d4449..2826ae29f5639f9d34818f5312ecfba49e567bda 100644 (file)
@@ -1578,15 +1578,27 @@ int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
                        return ret;
                }
 
-               ret = func(reqid, NULL, key, data, private_data);
-               if (ret != 0) {
-                       break;
+               if (func != NULL) {
+                       ret = func(reqid, NULL, key, data, private_data);
+                       if (ret != 0) {
+                               break;
+                       }
                }
 
                offset += reclen;
        }
 
-       return ret;
+       if (ret != 0) {
+               return ret;
+       }
+
+       if (func == NULL) {
+               size_t *length = (size_t *)private_data;
+
+               *length = offset;
+       }
+
+       return 0;
 }
 
 int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)