libs/guest: Use a single write_exact() in write_headers()

Reduce number of syscalls by coalescing the image and the domain headers.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
Frediano Ziglio authored and Andrew Cooper committed 2026-07-08 15:35:45 +01:00
1 parent 32204e8e19
commit dfb11094ae
1 file changed
+18 -19
+18 -19
View File
@@ -10,17 +10,22 @@ static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type)
{
xc_interface *xch = ctx->xch;
int32_t xen_version = xc_version(xch, XENVER_version, NULL);
struct xc_sr_ihdr ihdr = {
.marker = IHDR_MARKER,
.id = htonl(IHDR_ID),
.version = htonl(3),
.options = htons(IHDR_OPT_LITTLE_ENDIAN),
};
struct xc_sr_dhdr dhdr = {
.type = guest_type,
.page_shift = XC_PAGE_SHIFT,
.xen_major = (xen_version >> 16) & 0xffff,
.xen_minor = (xen_version) & 0xffff,
struct {
struct xc_sr_ihdr ihdr;
struct xc_sr_dhdr dhdr;
} hdrs = {
.ihdr = {
.marker = IHDR_MARKER,
.id = htonl(IHDR_ID),
.version = htonl(3),
.options = htons(IHDR_OPT_LITTLE_ENDIAN),
},
.dhdr = {
.type = guest_type,
.page_shift = XC_PAGE_SHIFT,
.xen_major = (xen_version >> 16) & 0xffff,
.xen_minor = (xen_version) & 0xffff,
},
};
if ( xen_version < 0 )
@@ -29,15 +34,9 @@ static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type)
return -1;
}
if ( write_exact(ctx->fd, &ihdr, sizeof(ihdr)) )
if ( write_exact(ctx->fd, &hdrs, sizeof(hdrs)) )
{
PERROR("Unable to write Image Header to stream");
return -1;
}
if ( write_exact(ctx->fd, &dhdr, sizeof(dhdr)) )
{
PERROR("Unable to write Domain Header to stream");
PERROR("Unable to write Image/Domain headers to stream");
return -1;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.