xen: patch libxl to search for qemu-system-i386 properly#365890
xen: patch libxl to search for qemu-system-i386 properly#365890SigmaSquadron merged 1 commit intoNixOS:masterfrom
libxl to search for qemu-system-i386 properly#365890Conversation
SigmaSquadron
left a comment
There was a problem hiding this comment.
Also, might be best to refactor the whole thing and upstream it to Xen. I'll take a look at the xl sources tomorrow.
b3db303 to
ee8b441
Compare
I tried my hand at a solution in C. Can you tell it has been years since I wrote C? diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
index edeadd57ef..6cb0c68838 100644
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -115,7 +115,32 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
const char *dm;
dm = libxl__domain_device_model(gc, b_info);
- rc = access(dm, X_OK);
+ char* q_path;
+ if (strncmp(dm, "/", 1) == 0) {
+ q_path = dm;
+ } else {
+ char* path = getenv("PATH");
+ char* paths[];
+ char* token;
+ token = strtok(path, ":");
+ paths[0] = token;
+ i = 0;
+ while (token != NULL) {
+ token = strtok(NULL, ":");
+ paths[i] = strcat(token, dm);
+ i++;
+ }
+ for (i = 0;
+ i < sizeof(paths) / sizeof(paths[0]);
+ i++)
+ {
+ if (access(paths[i], F_OK) == 0) {
+ q_path = paths[i];
+ break;
+ }
+ }
+ }
+ rc = access(q_path, X_OK);
if (rc < 0) {
/* qemu-xen unavailable, use qemu-xen-traditional */
if (errno == ENOENT) {This is barely pseudocode, really. I'll clean it up by the end of the week and upstream it if it works. |
|
@SigmaSquadron Oh, I'm also investigating the same thing with similar idea over the past ~2 hour. 🤦♂️ I should reply to tell you earlier. And here is my version. --- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -332,7 +332,35 @@ const char *libxl__domain_device_model(libxl__gc *gc,
dm = libxl__abs_path(gc, "qemu-dm", libxl__private_bindir_path());
break;
case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
- dm = qemu_xen_path(gc);
+ const char *configured_dm = qemu_xen_path(gc);
+ if (strchr(configured_dm, '/')) {
+ dm = libxl__strdup(gc, configured_dm);
+ } else {
+ const char *path_env = getenv("PATH");
+ if (!path_env) {
+ dm = libxl__strdup(gc, configured_dm);
+ } else {
+ char *path_dup = libxl__strdup(gc, path_env);
+ char *path = strtok(path_dup, ":");
+
+ char fullpath[PATH_MAX];
+ bool dm_found = false;
+ while (path) {
+ snprintf(fullpath, sizeof(fullpath), "%s/%s", path, configured_dm);
+ if (access(fullpath, X_OK) == 0) {
+ dm = libxl__strdup(gc, fullpath);
+ dm_found = true;
+ break;
+ }
+ path = strtok(NULL, ":");
+ }
+
+ if (!dm_found) {
+ LOG(INFO, "%s is not found", configured_dm);
+ dm = libxl__strdup(gc, configured_dm);
+ }
+ }
+ }
break;
default:
LOG(ERROR, "invalid device model version %d",I'm also not familiar with C. But regarding your version, if you decide to search |
|
Hmm, are you certain that modifying |
I don't know if you're referring to the In However I'm not certain what will happen if we alter data via |
|
And another fact I discovered is, Xen will just check the existence of |
At least to check file existence via As for executing QEMU after those long procedure of checking, it is done by |
ee8b441 to
1539d91
Compare
|
Removed the message from the former patch file (contains error). Let me know if we decide to use the patch that enables xl to find |
30ea078 to
159d807
Compare
libxl to search for qemu-system-i386 properly
b07ef81 to
a752b4b
Compare
|
Rebase needed after landing #406638 |
a150c76 to
fbb095e
Compare
|
Done retrieving the patch from the old location. |
|
In the meantime, I think @SigmaSquadron has gained commit rights. Rebase and merge? |
Sorry for not noticing the merge conflict, I'll revisit this later today. |
fbb095e to
3051301
Compare
|
Now it's ready to merge. @SigmaSquadron The patch is already in 4.21, so we can just remove that when bumping the Xen version, like other XSA patches. |
3051301 to
f7beed3
Compare
As upstreamed to Xen Project via `f6281291704aa356489f4bd927cc7348a920bd01`. Signed-off-by: Hongbo <hehongbo@mail.com>
f7beed3 to
70741d8
Compare
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-25.05
git worktree add -d .worktree/backport-365890-to-release-25.05 origin/release-25.05
cd .worktree/backport-365890-to-release-25.05
git switch --create backport-365890-to-release-25.05
git cherry-pick -x 70741d83804d784297a6bfb2de35fd10d319c381 |
This fixes the error on HVM DomUs creation that we initially saw after switching from Fat Xen. It might be too ugly to merge, and I'd open it to discussions in @NixOS/xen-project .
What happened before, was we decided to build the hypervisor with
--with-system-qemubut without a path to the QEMU binary as its string value. According to tools/configure.ac, that configuresqemu_xen_pathasqemu-system-i386(with no clue where) if flagged asyes, or if a string value is specified, then configure the given value as is. But we can't wire that topkgs.qemu_xen, sincepkgs.xenis already a dependency ofpkgs.qemu_xen, and doing so will make a circular dependency.However,
access()is used to check the existence of the QEMU binary. It's not tailored for binaries, and will not search anywhere inPATH, instead it searches within the current directory. If there is no executable namedqemu-system-i386, then libxl__domain_build_info_setdefault() will receive a false positive and default toqemu-xen-traditionalbut we don't have one, as the hypervisor itself is built with--with-system-qemu. Skipping that check will maintain the value asqemu-system-i386, but we still have to take care of another one at libxl__spawn_local_dm(). Since we already haveqemu-system-i386available at PATH, I temporarily removed those checks.That is sort of an edge case and I can imagine those regular distros might pass an FHS path to
--with-system-qemuand carry on, but finding an executable in the current directory is not appropriate anyway. (Maybe worth upstreaming?)Update
The patch is now upstreamed via f628129, let's pick it and use it here before it's shipped with future versions of Xen.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.