protocol: Add block device information to system info
authorJeremy Kerr <jk@ozlabs.org>
Fri, 15 Nov 2013 04:13:41 +0000 (15:13 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 22 Nov 2013 02:45:54 +0000 (10:45 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/pb-protocol/pb-protocol.c
lib/types/types.h

index 5a056ee7b8150e8034d39b32156d8cd22d4f9d09..091fab722f102e9d9c186e8bec6900146737bcce 100644 (file)
@@ -223,7 +223,7 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo)
 
        len =   4 + optional_strlen(sysinfo->type) +
                4 + optional_strlen(sysinfo->identifier) +
-               4;
+               4 + 4;
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *if_info = sysinfo->interfaces[i];
@@ -231,6 +231,13 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo)
                        4 + optional_strlen(if_info->name);
        }
 
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               struct blockdev_info *bd_info = sysinfo->blockdevs[i];
+               len +=  4 + optional_strlen(bd_info->name) +
+                       4 + optional_strlen(bd_info->uuid) +
+                       4 + optional_strlen(bd_info->mountpoint);
+       }
+
        return len;
 }
 
@@ -379,6 +386,17 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
                pos += pb_protocol_serialise_string(pos, if_info->name);
        }
 
+       *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs);
+       pos += sizeof(uint32_t);
+
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               struct blockdev_info *bd_info = sysinfo->blockdevs[i];
+
+               pos += pb_protocol_serialise_string(pos, bd_info->name);
+               pos += pb_protocol_serialise_string(pos, bd_info->uuid);
+               pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
+       }
+
        assert(pos <= buf + buf_len);
        (void)buf_len;
 
@@ -750,6 +768,28 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
                sysinfo->interfaces[i] = if_info;
        }
 
+       /* number of interfaces */
+       if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
+               goto out;
+
+       sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
+                       sysinfo->n_blockdevs);
+
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               struct blockdev_info *bd_info = talloc(sysinfo,
+                                                       struct blockdev_info);
+
+               if (read_string(bd_info, &pos, &len, &bd_info->name))
+                       goto out;
+
+               if (read_string(bd_info, &pos, &len, &bd_info->uuid))
+                       goto out;
+
+               if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
+                       goto out;
+
+               sysinfo->blockdevs[i] = bd_info;
+       }
        rc = 0;
 
 out:
index d73f1618e4631ff04738bfeef253d6a305e4c652..d2a2918c7b3fe2cd077219ab6319b87c5d1dde01 100644 (file)
@@ -66,11 +66,19 @@ struct interface_info {
        char            *name;
 };
 
+struct blockdev_info {
+       char            *name;
+       char            *uuid;
+       char            *mountpoint;
+};
+
 struct system_info {
        char                    *type;
        char                    *identifier;
        struct interface_info   **interfaces;
        unsigned int            n_interfaces;
+       struct blockdev_info    **blockdevs;
+       unsigned int            n_blockdevs;
 };
 
 #define HWADDR_SIZE    6