@@ -2152,6 +2152,43 @@ static int virtqueue_resize_packed(struct virtqueue *_vq, u32 num)
2152
2152
return - ENOMEM ;
2153
2153
}
2154
2154
2155
+ static int virtqueue_disable_and_recycle (struct virtqueue * _vq ,
2156
+ void (* recycle )(struct virtqueue * vq , void * buf ))
2157
+ {
2158
+ struct vring_virtqueue * vq = to_vvq (_vq );
2159
+ struct virtio_device * vdev = vq -> vq .vdev ;
2160
+ void * buf ;
2161
+ int err ;
2162
+
2163
+ if (!vq -> we_own_ring )
2164
+ return - EPERM ;
2165
+
2166
+ if (!vdev -> config -> disable_vq_and_reset )
2167
+ return - ENOENT ;
2168
+
2169
+ if (!vdev -> config -> enable_vq_after_reset )
2170
+ return - ENOENT ;
2171
+
2172
+ err = vdev -> config -> disable_vq_and_reset (_vq );
2173
+ if (err )
2174
+ return err ;
2175
+
2176
+ while ((buf = virtqueue_detach_unused_buf (_vq )) != NULL )
2177
+ recycle (_vq , buf );
2178
+
2179
+ return 0 ;
2180
+ }
2181
+
2182
+ static int virtqueue_enable_after_reset (struct virtqueue * _vq )
2183
+ {
2184
+ struct vring_virtqueue * vq = to_vvq (_vq );
2185
+ struct virtio_device * vdev = vq -> vq .vdev ;
2186
+
2187
+ if (vdev -> config -> enable_vq_after_reset (_vq ))
2188
+ return - EBUSY ;
2189
+
2190
+ return 0 ;
2191
+ }
2155
2192
2156
2193
/*
2157
2194
* Generic functions and exported symbols.
@@ -2702,13 +2739,8 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
2702
2739
void (* recycle )(struct virtqueue * vq , void * buf ))
2703
2740
{
2704
2741
struct vring_virtqueue * vq = to_vvq (_vq );
2705
- struct virtio_device * vdev = vq -> vq .vdev ;
2706
- void * buf ;
2707
2742
int err ;
2708
2743
2709
- if (!vq -> we_own_ring )
2710
- return - EPERM ;
2711
-
2712
2744
if (num > vq -> vq .num_max )
2713
2745
return - E2BIG ;
2714
2746
@@ -2718,28 +2750,16 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
2718
2750
if ((vq -> packed_ring ? vq -> packed .vring .num : vq -> split .vring .num ) == num )
2719
2751
return 0 ;
2720
2752
2721
- if (!vdev -> config -> disable_vq_and_reset )
2722
- return - ENOENT ;
2723
-
2724
- if (!vdev -> config -> enable_vq_after_reset )
2725
- return - ENOENT ;
2726
-
2727
- err = vdev -> config -> disable_vq_and_reset (_vq );
2753
+ err = virtqueue_disable_and_recycle (_vq , recycle );
2728
2754
if (err )
2729
2755
return err ;
2730
2756
2731
- while ((buf = virtqueue_detach_unused_buf (_vq )) != NULL )
2732
- recycle (_vq , buf );
2733
-
2734
2757
if (vq -> packed_ring )
2735
2758
err = virtqueue_resize_packed (_vq , num );
2736
2759
else
2737
2760
err = virtqueue_resize_split (_vq , num );
2738
2761
2739
- if (vdev -> config -> enable_vq_after_reset (_vq ))
2740
- return - EBUSY ;
2741
-
2742
- return err ;
2762
+ return virtqueue_enable_after_reset (_vq );
2743
2763
}
2744
2764
EXPORT_SYMBOL_GPL (virtqueue_resize );
2745
2765
0 commit comments