On 07/05/2024 18:51, Peter Xu wrote:
External email: Use caution opening links or attachments


On Tue, May 07, 2024 at 10:47:13AM +0300, Avihai Horon wrote:
While at it, another trivial comment is maybe it's nice to have a helper to
both update the vfio migration state, plus emitting events when necessary.
I think vfio_migration_set_state() does exactly that, no?
Ah yes, looks so.  It's just that I saw some common patterns, like:

===8<===
@@ -126,11 +167,13 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
          }

          migration->device_state = recover_state;
+        vfio_migration_send_state_change_event(vbasedev);

          return ret;
      }

      migration->device_state = new_state;
+    vfio_migration_send_state_change_event(vbasedev);
      if (mig_state->data_fd != -1) {
          if (migration->data_fd != -1) {
              /*
@@ -157,6 +200,7 @@ reset_device:
      }

      migration->device_state = VFIO_DEVICE_STATE_RUNNING;
+    vfio_migration_send_state_change_event(vbasedev);

      return ret;
  }
===8<===

So maybe some more internal helpers?  It doesn't look like to cover all
updates to device_state, but I really didn't read into it.  Not a huge deal
really, feel free to keep it as-is if maintainers are happy.

Oh, I see what you mean.

Cedric, would you like me to add the following?

===8<===

--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -122,6 +122,14 @@ static void vfio_migration_send_event(VFIODevice *vbasedev)          dev->id, qom_path, mig_state_to_qapi_state(migration->device_state));
 }

+static void set_state(VFIODevice *vbasedev, enum vfio_device_mig_state state)
+{
+    VFIOMigration *migration = vbasedev->migration;
+
+    migration->device_state = state;
+    vfio_migration_send_event(vbasedev);
+}
+
 static int vfio_migration_set_state(VFIODevice *vbasedev,
                                     enum vfio_device_mig_state new_state,
                                     enum vfio_device_mig_state recover_state) @@ -171,14 +179,12 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
             goto reset_device;
         }

-        migration->device_state = recover_state;
-        vfio_migration_send_event(vbasedev);
+        set_state(vbasedev, recover_state);

         return ret;
     }

-    migration->device_state = new_state;
-    vfio_migration_send_event(vbasedev);
+    set_state(vbasedev, new_state);
     if (mig_state->data_fd != -1) {
         if (migration->data_fd != -1) {
             /*
@@ -204,8 +210,7 @@ reset_device:
                  strerror(errno));
     }

-    migration->device_state = VFIO_DEVICE_STATE_RUNNING;
-    vfio_migration_send_event(vbasedev);
+    set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING);

     return ret;
 }

===8<===


Reply via email to