Re: [RFC 17/26] plugins/amdgpu: Use the load_img helper in drm file restore

"Francis, David" <[email protected]> Mon, 2 Mar 2026 14:52:05 +0000
Newsgroups dev.linux.lists.criu
Message-ID <SA1PR12MB81446040B0A02EB01D807927EF7EA@SA1PR12MB8144.namprd12.prod.outlook.com>
> Use the recently added image load helper in one more function which
> contains the exactly same flow of open-alloc-read.

Code looks cleaner for sure. How recently was this recently added image
load helper added, and to what? Does this change CRIU's dependencies?

David

________________________________________
From: Tvrtko Ursulin <[email protected]>
Sent: Friday, February 20, 2026 7:05 AM
To: [email protected]
Cc: Francis, David; Tvrtko Ursulin
Subject: [RFC 17/26] plugins/amdgpu: Use the load_img helper in drm file restore

Use the recently added image load helper in one more function which
contains the exactly same flow of open-alloc-read.

Signed-off-by: Tvrtko Ursulin <[email protected]>
---
 plugins/amdgpu/amdgpu_plugin.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c
index 9ba12bd3a466..a653ba1aa2d9 100644
--- a/plugins/amdgpu/amdgpu_plugin.c
+++ b/plugins/amdgpu/amdgpu_plugin.c
@@ -1859,7 +1859,6 @@ static int amdgpu_plugin_restore_drm_file(int id, bool *retry_needed)
        CriuRenderNode *rd;
        unsigned char *buf;
        size_t img_size;
-       FILE *img_fp;
        int fd, ret;

        /* This is restorer plugin for renderD nodes. Criu doesn't guarantee that they will
@@ -1868,9 +1867,8 @@ static int amdgpu_plugin_restore_drm_file(int id, bool *retry_needed)
         * first as we assume restore_maps is already filled. Need to fix this later.
         */
        snprintf(img_path, sizeof(img_path), IMG_DRM_FILE, id);
-
-       img_fp = open_img_file(img_path, false, &img_size);
-       if (!img_fp) {
+       ret = load_img(img_path, &buf, &img_size);
+       if (ret < 0) {
                ret = amdgpu_plugin_dmabuf_restore(id);
                if (ret == 1) {
                        /* This is a dmabuf fd, but the corresponding buffer object that was
@@ -1882,29 +1880,16 @@ static int amdgpu_plugin_restore_drm_file(int id, bool *retry_needed)
                }
                return ret;
        }
-       pr_info("Restoring RenderD %s\n", img_path);
-       pr_debug("RenderD Image file size:%ld\n", img_size);
-       buf = xmalloc(img_size);
-       if (!buf) {
-               pr_perror("Failed to allocate memory");
-               return -ENOMEM;
-       }

-       ret = read_fp(img_fp, buf, img_size);
-       if (ret) {
-               pr_perror("Unable to read from %s", img_path);
-               xfree(buf);
-               return -1;
-       }
+       pr_info("Restoring RenderD %s image of %lu bytes\n",
+               img_path, img_size);

        rd = criu_render_node__unpack(NULL, img_size, buf);
        if (rd == NULL) {
-               pr_perror("Unable to parse the RenderD message %d", id);
+               pr_perror("Unable to parse the RenderD image %d", id);
                xfree(buf);
-               fclose(img_fp);
                return -1;
        }
-       fclose(img_fp);

        pr_info("render node gpu_id = 0x%04x\n", rd->gpu_id);

--
2.52.0