zvol: fix delayed update to block device ro entry

The change in the zvol readonly property does not update the block
device readonly entry until the first IO to the ZVOL. This patch
addresses the issue by updating the block device readonly property
from the set property IOCTL call.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
Closes #15409
This commit is contained in:
Ameer Hamza
2023-10-18 00:19:58 +05:00
committed by Brian Behlendorf
parent 60387facd2
commit 9ccdb8becd
3 changed files with 30 additions and 0 deletions
+20
View File
@@ -383,6 +383,26 @@ zvol_set_volthreading(const char *name, boolean_t value)
return (0);
}
/*
* Update zvol ro property.
*/
int
zvol_set_ro(const char *name, boolean_t value)
{
zvol_state_t *zv = zvol_find_by_name(name, RW_NONE);
if (zv == NULL)
return (-1);
if (value) {
zvol_os_set_disk_ro(zv, 1);
zv->zv_flags |= ZVOL_RDONLY;
} else {
zvol_os_set_disk_ro(zv, 0);
zv->zv_flags &= ~ZVOL_RDONLY;
}
mutex_exit(&zv->zv_state_lock);
return (0);
}
/*
* Sanity check volume block size.
*/