[PATCH RFC 1/8] base_image: optimize VM image copying with reflinks and fix same-file handling
Daniel Gomez <[email protected]>
| Newsgroups | dev.linux.lists.kdevops |
|---|---|
| Message-ID | <[email protected]> |
From: Daniel Gomez <[email protected]> Replace ansible.builtin.copy with cp --reflink=auto for significant performance improvement on XFS filesystems with reflink support: - 20GB image copy time: ~54s → ~1s (when reflinks are supported) - Automatic fallback to regular copy on non-reflink filesystems - Use direct cp command for better control over reflink behavior Add condition to prevent copying when source and destination are the same file. This was not needed with ansible.builtin.copy (which handles this case automatically) but is required with direct cp command which fails with "files are the same" error. The condition `custom_image != base_image_pathname` ensures copy only occurs when paths differ, maintaining compatibility with configurations where both variables point to the same location. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]> --- playbooks/roles/base_image/tasks/custom-image.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/playbooks/roles/base_image/tasks/custom-image.yml b/playbooks/roles/base_image/tasks/custom-image.yml index bcf35933..bac834e8 100644 --- a/playbooks/roles/base_image/tasks/custom-image.yml +++ b/playbooks/roles/base_image/tasks/custom-image.yml @@ -338,13 +338,21 @@ - "{{ custom_image_dir }}" changed_when: true -- name: Copy custom image to base image location +- name: Copy custom image to base image location (with automatic reflink optimization) become: true become_method: ansible.builtin.sudo - ansible.builtin.copy: - src: "{{ custom_image }}" - dest: "{{ base_image_pathname }}" - remote_src: true + ansible.builtin.command: + cmd: "cp --reflink=auto '{{ custom_image }}' '{{ base_image_pathname }}'" + when: + - custom_image_stat.stat.exists or custom_image_download is changed + - custom_image != base_image_pathname + +- name: Set proper permissions on base image + become: true + become_method: ansible.builtin.sudo + ansible.builtin.file: + path: "{{ base_image_pathname }}" mode: "u=rw,g=r,o=r" when: - custom_image_stat.stat.exists or custom_image_download is changed + - custom_image != base_image_pathname -- 2.50.1