Skip to content

Conversation

@SimonFair
Copy link
Contributor

@SimonFair SimonFair commented May 8, 2024

Summary by CodeRabbit

  • New Features

    • Added optional secondary storage setting for libvirt to retain previous XML/NVRAM versions and support migrations.
  • Enhancements

    • UI now accepts and clearly indicates libvirt locations that are directories or image files.
    • Automatic synchronization/migration of VM image data when changing storage locations, with backup handling.
  • Documentation

    • Expanded and clarified help text for libvirt volume/location and secondary storage usage.

@SimonFair SimonFair marked this pull request as draft May 8, 2024 20:34
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 19, 2025

Walkthrough

Adds tracking and sync between current and previous libvirt IMAGE_FILE paths. A hidden OLD_IMAGE_FILE field was added to the VM settings UI, libvirt_init now synchronizes domain data between old/new paths (handling .img files and directories), defaults updated to directories, and help text expanded.

Changes

Cohort / File(s) Change Summary
UI change
emhttp/plugins/dynamix.vm.manager/VMSettings.page
Added hidden input OLD_IMAGE_FILE, inserted a blank line after QEMU/libvirt info retrieval, and tightened the condition that displays Libvirt volume info so it only shows when IMAGE_FILE contains .img.
Sync logic
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init
Added synchronization block that reads IMAGE_FILE and OLD_IMAGE_FILE from /boot/config/domain.cfg, compares them, and when different and present syncs VM domain data between the two paths. Handles .img mounts and directory rsyncs, updates OLD_IMAGE_FILE, and logs/skips appropriately.
Defaults / config
emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig
Changed default IMAGE_FILE from a .img file to a directory path and added OLD_IMAGE_FILE with the same default directory value.
Help text
emhttp/languages/en_US/helptext.txt
Expanded and clarified libvirt-related help entries to indicate volumes/locations can be files or directories; added :vms_libvirt_secondary_volume_help: and :vms_libvirt_secondary_location_help: describing secondary storage for previous XML/NVRAM versions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as VMSettings.page
    participant Config as libvirtconfig
    participant Init as libvirt_init

    User->>UI: Open/modify VM Settings
    UI->>Config: Load/Save IMAGE_FILE and OLD_IMAGE_FILE
    Note over Init,Config: On libvirt_init run
    Init->>Config: Read IMAGE_FILE and OLD_IMAGE_FILE
    alt both set and differ
        Init->>Init: Mount/.img or access dirs
        Init->>Init: Rsync data old → new (respecting excludes)
        Init->>Config: Update OLD_IMAGE_FILE to current IMAGE_FILE
    else
        Init->>Init: Log and skip syncing
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 In burrows of bytes I softly tread,
Old paths remembered, new paths fed.
I mount and rsync, tidy the trail,
Keep XML and nvram without fail.
A hidden carrot guards the past—hop on, it's fast!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Updates for libvirt image removal and use diretory" refers to a real and relevant aspect of the changeset—specifically the shift toward supporting directory-based storage instead of image files. The changes do include modifications to support using directories alongside image files, with corresponding UI and help text updates. However, the title does not capture the primary technical addition, which is the data synchronization mechanism added to libvirt_init that handles migration of VM image data between old and new storage paths. Additionally, the title contains a spelling error ("diretory" instead of "directory") and uses the somewhat generic term "Updates," which could be more descriptive about the migration/synchronization functionality being introduced.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init (1)

9-63: Well-structured data migration mechanism.

The synchronization logic is thoughtfully implemented to handle multiple scenarios (image file to directory, directory to image, directory to directory) while providing proper backups and logging throughout the process.

Consider these minor improvements:

  1. Add error handling for mount/umount operations
  2. Add cleanup for the temporary directory
  3. Add error checking for rsync operations

Example improvement:

+ # Create temporary mount directory
  mkdir -p "$TMP_MNT"
- mount "$OLD_IMAGE_FILE" "$TMP_MNT"
+ if ! mount "$OLD_IMAGE_FILE" "$TMP_MNT"; then
+   log "Failed to mount $OLD_IMAGE_FILE - aborting sync"
+   rm -rf "$TMP_MNT"
+   exit 1
+ fi
  log "Copying full contents from image to directory $IMAGE_FILE"
- rsync -a --exclude="$OLD_IMG_FILE_NAME" "$TMP_MNT/" "$IMAGE_FILE/"
+ if ! rsync -a --exclude="$OLD_IMG_FILE_NAME" "$TMP_MNT/" "$IMAGE_FILE/"; then
+   log "rsync failed - aborting sync"
+   umount "$TMP_MNT"
+   rm -rf "$TMP_MNT"
+   exit 1
+ fi
  umount "$TMP_MNT"
+ rm -rf "$TMP_MNT"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 28ec848 and de53cf4.

📒 Files selected for processing (3)
  • emhttp/plugins/dynamix.vm.manager/VMSettings.page (6 hunks)
  • emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init (1 hunks)
  • emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix.vm.manager/VMSettings.page
🔇 Additional comments (1)
emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig (1)

18-19: Configuration updated to support directory-based VM image storage.

The changes here transition from using a specific image file path to a directory path approach for libvirt VM storage. The added OLD_IMAGE_FILE entry will be used for synchronization during the migration from file-based to directory-based storage as implemented in the libvirt_init script.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
emhttp/languages/en_US/helptext.txt (3)

1624-1626: Refine grammar and acronym capitalization.

The sentence could be clearer by capitalizing well‑known acronyms and improving phrasing. For example:
“This is a location for storing previous versions of XML and NVRAM when changes occur.”


1633-1635: Ensure consistent capitalization of ‘libvirt’.

Here “Libvirt” is capitalized, whereas elsewhere it’s lowercase. Consider using “libvirt” for consistency, or updating all occurrences to “Libvirt” uniformly.


1637-1639: Improve clarity and grammar for secondary location help.

The sentence could be rephrased and acronyms capitalized. For example:
“This directory is used to store previous versions of XML and NVRAM when they change. Specification is optional.”

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between de53cf4 and 3ffebdf.

📒 Files selected for processing (2)
  • emhttp/languages/en_US/helptext.txt (2 hunks)
  • emhttp/plugins/dynamix.vm.manager/VMSettings.page (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emhttp/plugins/dynamix.vm.manager/VMSettings.page
🔇 Additional comments (1)
emhttp/languages/en_US/helptext.txt (1)

1621-1622: Approve updated terminology for primary storage.

The change from “libvirt volume” to “libvirt volume/directory” accurately reflects that both file and directory paths are accepted.

@ljm42 ljm42 added the 7.2 label Apr 29, 2025
@SimonFair SimonFair marked this pull request as ready for review May 5, 2025 17:45
@SimonFair SimonFair marked this pull request as draft May 5, 2025 17:46
@SimonFair SimonFair marked this pull request as ready for review May 6, 2025 19:22
@ljm42 ljm42 added TBD and removed 7.2 labels Aug 12, 2025
@github-actions
Copy link

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2025.10.24.1109
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-1722/webgui-pr-1722.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates

📝 Modified Files:

Click to expand file list
emhttp/languages/en_US/helptext.txt
emhttp/plugins/dynamix.vm.manager/VMSettings.page
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init
emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-1722, or run:

plugin remove webgui-pr-1722

🤖 This comment is automatically generated and will be updated with each new push to this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fca221a and d5d3bad.

📒 Files selected for processing (3)
  • emhttp/languages/en_US/helptext.txt (2 hunks)
  • emhttp/plugins/dynamix.vm.manager/VMSettings.page (3 hunks)
  • emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig (1 hunks)
🔇 Additional comments (4)
emhttp/plugins/dynamix.vm.manager/VMSettings.page (1)

126-126: LGTM - Hidden field properly captures old value.

The hidden field correctly captures the current IMAGE_FILE value and properly escapes it with htmlspecialchars() for security.

emhttp/languages/en_US/helptext.txt (2)

1714-1715: LGTM - Help text accurately reflects volume/directory usage.

The updated help text correctly indicates that the libvirt storage can be either a volume or directory.


1727-1728: LGTM - Help text updated to include directory option.

The help text now correctly indicates that libvirt can use either an image file or a directory.

emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig (1)

18-19: Code is functioning correctly; review comment concern is invalid.

The synchronization logic on line 22 of libvirt_init explicitly gates behind an inequality check: [ "$IMAGE_FILE" != "$OLD_IMAGE_FILE" ]. When both variables default to the same path for fresh installations, this condition evaluates false and the sync logic is safely skipped—which is the correct behavior. No action needed.

Likely an incorrect or invalid review comment.

Comment on lines +1717 to 1719
:vms_libvirt_secondary_volume_help:
This is a location for storing previous versions of xml and nvram at change.
:end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix grammar in help text.

The phrase "at change" is awkward. Consider one of these alternatives:

-This is a location for storing previous versions of xml and nvram at change.
+This is a location for storing previous versions of xml and nvram when changed.

or

-This is a location for storing previous versions of xml and nvram at change.
+This is a location for storing previous versions of xml and nvram on change.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:vms_libvirt_secondary_volume_help:
This is a location for storing previous versions of xml and nvram at change.
:end
:vms_libvirt_secondary_volume_help:
This is a location for storing previous versions of xml and nvram when changed.
:end
🤖 Prompt for AI Agents
In emhttp/languages/en_US/helptext.txt around lines 1717 to 1719, the help text
"This is a location for storing previous versions of xml and nvram at change."
is grammatically awkward; replace it with a clearer phrase such as "This is a
location for storing previous versions of XML and NVRAM when changes are made."
Ensure XML and NVRAM are capitalized and the new sentence reads fluently.

Comment on lines +1730 to 1732
:vms_libvirt_secondary_location_help:
This is a directory for storing previous versions of xml and nvram at change. Does not need to be specified.
:end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix grammar in help text.

Same grammar issue as line 1718. The phrase "at change" should be improved:

-This is a directory for storing previous versions of xml and nvram at change. Does not need to be specified.
+This is a directory for storing previous versions of xml and nvram when changed. Does not need to be specified.

or

-This is a directory for storing previous versions of xml and nvram at change. Does not need to be specified.
+This is a directory for storing previous versions of xml and nvram on change. Does not need to be specified.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:vms_libvirt_secondary_location_help:
This is a directory for storing previous versions of xml and nvram at change. Does not need to be specified.
:end
:vms_libvirt_secondary_location_help:
This is a directory for storing previous versions of xml and nvram when changed. Does not need to be specified.
:end
Suggested change
:vms_libvirt_secondary_location_help:
This is a directory for storing previous versions of xml and nvram at change. Does not need to be specified.
:end
:vms_libvirt_secondary_location_help:
This is a directory for storing previous versions of xml and nvram on change. Does not need to be specified.
:end
🤖 Prompt for AI Agents
In emhttp/languages/en_US/helptext.txt around lines 1730 to 1732, the help text
uses the awkward phrase "at change"; update the sentence for correct grammar and
clarity by replacing "This is a directory for storing previous versions of xml
and nvram at change. Does not need to be specified." with a single clear
sentence such as "This directory stores previous versions of XML and NVRAM when
they change and does not need to be specified." or alternatively "This directory
stores previous versions of XML and NVRAM on change; it does not need to be
specified."

<?endif;?>

<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs'):?>
<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs' && strpos($domain_cfg['IMAGE_FILE'],".img")) :?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix imprecise string matching for .img check.

The condition strpos($domain_cfg['IMAGE_FILE'],".img") has potential issues:

  1. It will return false when ".img" is at position 0, though this is unlikely for a path
  2. More importantly, it will match ".img" appearing anywhere in the path, including in directory names (e.g., /mnt/user/my.images/libvirt/ or /path/.img-backup/libvirt/)

Since the intent is to show this section only for image files (not directories), consider using a more precise check:

-<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs' && strpos($domain_cfg['IMAGE_FILE'],".img")) :?>
+<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs' && substr($domain_cfg['IMAGE_FILE'], -4) === '.img') :?>

This checks if the path ends with .img rather than containing it anywhere.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs' && strpos($domain_cfg['IMAGE_FILE'],".img")) :?>
<?if ($libvirt_up && trim(shell_exec('stat -c %T -f /etc/libvirt'))=='btrfs' && substr($domain_cfg['IMAGE_FILE'], -4) === '.img') :?>
🤖 Prompt for AI Agents
In emhttp/plugins/dynamix.vm.manager/VMSettings.page around line 303, the
current check strpos($domain_cfg['IMAGE_FILE'],".img") is imprecise (matches
anywhere and fails when at position 0); replace it with an end-of-string match
to ensure the path is an image file — for example, use a case-insensitive regex
or a suffix check such as preg_match('/\.img$/i',
trim($domain_cfg['IMAGE_FILE'])) or
strtolower(substr(trim($domain_cfg['IMAGE_FILE']), -4)) === '.img' so only paths
that actually end with ".img" trigger the condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants