Skip to contentSkip to conversation

libxl: avoid infinite loop in libxl__remove_directory()

PATCH In review Jan Beulich 3 participants 3 messages Mar 6, 2025 – Mar 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: avoid infinite loop in libxl__remove_directory()

Infinitely retrying the rmdir() invocation makes little sense. While the original observation was the log filling the disk (due to repeated "Directory not empty" errors, in turn occurring for unclear reasons), the loop wants breaking even if there was no error message being logged (much like is done in the similar loops in libxl__remove_file() and libxl__remove_file_or_directory()).

Fixes c4dcbee67e6d ("libxl: provide libxl__remove_file et al")

---
This is the simplest possible adjustment. Depending on why there were retries, retrying a few times may make sense. But then, especially for the specific error observed, presumably only after having tried to empty the directory another time.

It's further questionable whether trying the rmdir() makes sense at all when emptying the directory failed. After all failure of opendir() also results in bailing from the function without trying to rmdir(). If this makes sense, then I further think that "rc" would want resetting ahead of this final loop in the function: If the rmdir() succeeds despite earlier errors, all is (kind of) fine.

tools/libs/light/libxl_utils.c +1 -0
@@ -577,6 +577,7 @@ int libxl__remove_directory(libxl__gc *g
         if (errno == EINTR) continue;
         LOGE(ERROR, "failed to remove emptied directory %s", dirpath);
         rc = ERROR_FAIL;
+        break;
     }
 
  out:
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jan Beulich

Infinitely retrying the rmdir() invocation makes little sense. While the original observation was the log filling the disk (due to repeated "Directory not empty" errors, in turn occurring for unclear reasons), the loop wants breaking even if there was no error message being logged (much like is done in the similar loops in libxl__remove_file() and libxl__remove_file_or_directory()).

Fixes c4dcbee67e6d ("libxl: provide libxl__remove_file et al")

While probably a more sane solution by reworking this whole mess is possible, this patch should solve the issue Jan has described.

So:

Juergen

#2 lore raw
Quoted 8 lines · Jürgen Groß
Quoted 7 lines · Jan Beulich

Infinitely retrying the rmdir() invocation makes little sense. While the original observation was the log filling the disk (due to repeated "Directory not empty" errors, in turn occurring for unclear reasons), the loop wants breaking even if there was no error message being logged (much like is done in the similar loops in libxl__remove_file() and libxl__remove_file_or_directory()).

Quoted 4 lines
Quoted 2 lines
Fixes c4dcbee67e6d ("libxl: provide libxl__remove_file et al")

While probably a more sane solution by reworking this whole mess

libxl?

Quoted 5 lines

is possible, this patch should solve the issue Jan has described.

So:

Thanks,

--

Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech