Skip to content

Commit 4045b64

Browse files
mgurtovoymstsirkin
authored andcommitted
virtio_fs: introduce virtio_fs_put_locked helper
Introduce a new helper function virtio_fs_put_locked to encapsulate the common pattern of releasing a virtio_fs reference while holding a lock. The existing virtio_fs_put helper will be used to release a virtio_fs reference while not holding a lock. Also add an assertion in case the lock is not taken when it should. Reviewed-by: Idan Zach <[email protected]> Reviewed-by: Shai Malin <[email protected]> Signed-off-by: Max Gurtovoy <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]>
1 parent 561a163 commit 4045b64

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

fs/fuse/virtio_fs.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,25 @@ static const struct kobj_type virtio_fs_ktype = {
201201
};
202202

203203
/* Make sure virtiofs_mutex is held */
204-
static void virtio_fs_put(struct virtio_fs *fs)
204+
static void virtio_fs_put_locked(struct virtio_fs *fs)
205205
{
206+
lockdep_assert_held(&virtio_fs_mutex);
207+
206208
kobject_put(&fs->kobj);
207209
}
208210

211+
static void virtio_fs_put(struct virtio_fs *fs)
212+
{
213+
mutex_lock(&virtio_fs_mutex);
214+
virtio_fs_put_locked(fs);
215+
mutex_unlock(&virtio_fs_mutex);
216+
}
217+
209218
static void virtio_fs_fiq_release(struct fuse_iqueue *fiq)
210219
{
211220
struct virtio_fs *vfs = fiq->priv;
212221

213-
mutex_lock(&virtio_fs_mutex);
214222
virtio_fs_put(vfs);
215-
mutex_unlock(&virtio_fs_mutex);
216223
}
217224

218225
static void virtio_fs_drain_queue(struct virtio_fs_vq *fsvq)
@@ -1052,7 +1059,7 @@ static void virtio_fs_remove(struct virtio_device *vdev)
10521059

10531060
vdev->priv = NULL;
10541061
/* Put device reference on virtio_fs object */
1055-
virtio_fs_put(fs);
1062+
virtio_fs_put_locked(fs);
10561063
mutex_unlock(&virtio_fs_mutex);
10571064
}
10581065

@@ -1596,9 +1603,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
15961603

15971604
out_err:
15981605
kfree(fc);
1599-
mutex_lock(&virtio_fs_mutex);
16001606
virtio_fs_put(fs);
1601-
mutex_unlock(&virtio_fs_mutex);
16021607
return err;
16031608
}
16041609

0 commit comments

Comments
 (0)