Commit 8b599d14 authored by Yishai Hadas's avatar Yishai Hadas Committed by Alex Williamson

vfio/mlx5: Refactor migration file state

Refactor migration file state to be an emum which is mutual exclusive.

As of that dropped the 'disabled' state as 'error' is the same from
functional point of view.

Next patches from the series will extend this enum for other relevant
states.
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarYishai Hadas <yishaih@nvidia.com>
Link: https://lore.kernel.org/r/20221206083438.37807-7-yishaih@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 91454f8b
...@@ -351,7 +351,7 @@ void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work) ...@@ -351,7 +351,7 @@ void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work)
mutex_lock(&migf->lock); mutex_lock(&migf->lock);
if (async_data->status) { if (async_data->status) {
migf->is_err = true; migf->state = MLX5_MIGF_STATE_ERROR;
wake_up_interruptible(&migf->poll_wait); wake_up_interruptible(&migf->poll_wait);
} }
mutex_unlock(&migf->lock); mutex_unlock(&migf->lock);
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include <linux/mlx5/cq.h> #include <linux/mlx5/cq.h>
#include <linux/mlx5/qp.h> #include <linux/mlx5/qp.h>
enum mlx5_vf_migf_state {
MLX5_MIGF_STATE_ERROR = 1,
};
struct mlx5_vhca_data_buffer { struct mlx5_vhca_data_buffer {
struct sg_append_table table; struct sg_append_table table;
loff_t start_pos; loff_t start_pos;
...@@ -37,8 +41,7 @@ struct mlx5vf_async_data { ...@@ -37,8 +41,7 @@ struct mlx5vf_async_data {
struct mlx5_vf_migration_file { struct mlx5_vf_migration_file {
struct file *filp; struct file *filp;
struct mutex lock; struct mutex lock;
u8 disabled:1; enum mlx5_vf_migf_state state;
u8 is_err:1;
u32 pdn; u32 pdn;
struct mlx5_vhca_data_buffer *buf; struct mlx5_vhca_data_buffer *buf;
......
...@@ -109,7 +109,7 @@ int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf, ...@@ -109,7 +109,7 @@ int mlx5vf_add_migration_pages(struct mlx5_vhca_data_buffer *buf,
static void mlx5vf_disable_fd(struct mlx5_vf_migration_file *migf) static void mlx5vf_disable_fd(struct mlx5_vf_migration_file *migf)
{ {
mutex_lock(&migf->lock); mutex_lock(&migf->lock);
migf->disabled = true; migf->state = MLX5_MIGF_STATE_ERROR;
migf->filp->f_pos = 0; migf->filp->f_pos = 0;
mutex_unlock(&migf->lock); mutex_unlock(&migf->lock);
} }
...@@ -137,7 +137,8 @@ static ssize_t mlx5vf_save_read(struct file *filp, char __user *buf, size_t len, ...@@ -137,7 +137,8 @@ static ssize_t mlx5vf_save_read(struct file *filp, char __user *buf, size_t len,
if (!(filp->f_flags & O_NONBLOCK)) { if (!(filp->f_flags & O_NONBLOCK)) {
if (wait_event_interruptible(migf->poll_wait, if (wait_event_interruptible(migf->poll_wait,
READ_ONCE(vhca_buf->length) || migf->is_err)) READ_ONCE(vhca_buf->length) ||
migf->state == MLX5_MIGF_STATE_ERROR))
return -ERESTARTSYS; return -ERESTARTSYS;
} }
...@@ -150,7 +151,7 @@ static ssize_t mlx5vf_save_read(struct file *filp, char __user *buf, size_t len, ...@@ -150,7 +151,7 @@ static ssize_t mlx5vf_save_read(struct file *filp, char __user *buf, size_t len,
done = -EINVAL; done = -EINVAL;
goto out_unlock; goto out_unlock;
} }
if (migf->disabled || migf->is_err) { if (migf->state == MLX5_MIGF_STATE_ERROR) {
done = -ENODEV; done = -ENODEV;
goto out_unlock; goto out_unlock;
} }
...@@ -199,7 +200,7 @@ static __poll_t mlx5vf_save_poll(struct file *filp, ...@@ -199,7 +200,7 @@ static __poll_t mlx5vf_save_poll(struct file *filp,
poll_wait(filp, &migf->poll_wait, wait); poll_wait(filp, &migf->poll_wait, wait);
mutex_lock(&migf->lock); mutex_lock(&migf->lock);
if (migf->disabled || migf->is_err) if (migf->state == MLX5_MIGF_STATE_ERROR)
pollflags = EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; pollflags = EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
else if (READ_ONCE(migf->buf->length)) else if (READ_ONCE(migf->buf->length))
pollflags = EPOLLIN | EPOLLRDNORM; pollflags = EPOLLIN | EPOLLRDNORM;
...@@ -298,7 +299,7 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf, ...@@ -298,7 +299,7 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
return -ENOMEM; return -ENOMEM;
mutex_lock(&migf->lock); mutex_lock(&migf->lock);
if (migf->disabled) { if (migf->state == MLX5_MIGF_STATE_ERROR) {
done = -ENODEV; done = -ENODEV;
goto out_unlock; goto out_unlock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment