Skip to contentSkip to conversation

libxl: preserve errno in libxl__xcinfo2xlinfo()

PATCH In review Jan Beulich 3 participants 4 messages Aug 27, 2025 – Sep 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: preserve errno in libxl__xcinfo2xlinfo()

Callers observing errors elsewhere may be confused by the ENOSYS that the Flask operation would yield on a Flask-disabled hypervisor.

---
Of course I don't know whether clobbering errno is perhaps deemed "fine" in libxl.

tools/libs/light/libxl_domain.c +2 -0
@@ -277,6 +277,7 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx
                           libxl_dominfo *xlinfo)
 {
     size_t size;
+    int saved_errno = errno;
 
     memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t));
     xlinfo->domid = xcinfo->domain;
@@ -284,6 +285,7 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx
     if (libxl_flask_sid_to_context(ctx, xlinfo->ssidref,
                                    &xlinfo->ssid_label, &size) < 0)
         xlinfo->ssid_label = NULL;
+    errno = saved_errno;
 
     xlinfo->dying      = !!(xcinfo->flags&XEN_DOMINF_dying);
     xlinfo->shutdown   = !!(xcinfo->flags&XEN_DOMINF_shutdown);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

Callers observing errors elsewhere may be confused by the ENOSYS that the Flask operation would yield on a Flask-disabled hypervisor.

---
Of course I don't know whether clobbering errno is perhaps deemed "fine" in libxl.

I wonder if it would be better to special case libxl_flask_sid_to_context() to preserve errno on ENOSYS. flask returning ENOSYS is common, but libxl_flask_sid_to_context() can legitimately have error.

I guess this is fine if we want to use this approach:

Quoted 19 lines
tools/libs/light/libxl_domain.c +2 -0
@@ -277,6 +277,7 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx
                            libxl_dominfo *xlinfo)
  {
      size_t size;
+    int saved_errno = errno;
 
      memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t));
      xlinfo->domid = xcinfo->domain;
@@ -284,6 +285,7 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx
      if (libxl_flask_sid_to_context(ctx, xlinfo->ssidref,
                                     &xlinfo->ssid_label, &size) < 0)
          xlinfo->ssid_label = NULL;
+    errno = saved_errno;
 
      xlinfo->dying      = !!(xcinfo->flags&XEN_DOMINF_dying);
      xlinfo->shutdown   = !!(xcinfo->flags&XEN_DOMINF_shutdown);
#2 lore raw
Quoted 9 lines · Jason Andryuk
Quoted 7 lines · Jan Beulich

Callers observing errors elsewhere may be confused by the ENOSYS that the Flask operation would yield on a Flask-disabled hypervisor.

---
Of course I don't know whether clobbering errno is perhaps deemed "fine" in libxl.

Quoted 4 lines

I wonder if it would be better to special case libxl_flask_sid_to_context() to preserve errno on ENOSYS. flask returning ENOSYS is common, but libxl_flask_sid_to_context() can legitimately have error.

But then libxl__xcinfo2xlinfo() also shouldn't (effectively) ignore such other errors? Question is what it should do in such an event.

Quoted 3 lines

I guess this is fine if we want to use this approach:

Thanks.

Jan

#3 lore raw
In reply to Jason Andryuk
Quoted 4 lines · Jason Andryuk
Quoted 3 lines · Jan Beulich

Callers observing errors elsewhere may be confused by the ENOSYS that the Flask operation would yield on a Flask-disabled hypervisor.

Quoted 8 lines
Quoted 4 lines

---
Of course I don't know whether clobbering errno is perhaps deemed "fine" in libxl.

I wonder if it would be better to special case libxl_flask_sid_to_context() to preserve errno on ENOSYS. flask returning ENOSYS is common, but libxl_flask_sid_to_context() can legitimately have error.

Well, errno=ENOSYS gives information about why libxl_flask_sid_to_context() returns an error.
They are multiple error code for returns libxl_*() functions but they aren't really check. We often rely on errno to print an error message. And in this case, libxl_flask_sid_to_context() doesn't event return a proper libxl_error value.

Quoted 3 lines

I guess this is fine if we want to use this approach:

Thanks,

Signature · 1 line
Anthony PERARD