]> git.proxmox.com Git - mirror_zfs.git/commitdiff
zvol: fix delayed update to block device ro entry
authorAmeer Hamza <ahamza@ixsystems.com>
Tue, 17 Oct 2023 19:19:58 +0000 (00:19 +0500)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 31 Oct 2023 16:50:38 +0000 (09:50 -0700)
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

include/sys/zvol.h
module/zfs/zfs_ioctl.c
module/zfs/zvol.c

index c9eefbeb48d932e0c3f0f56fc93937213014d749..c79fe1d9ad227c8a1d654f61b1891c409b8c40bf 100644 (file)
@@ -52,6 +52,7 @@ extern void zvol_create_cb(objset_t *, void *, cred_t *, dmu_tx_t *);
 extern int zvol_set_volsize(const char *, uint64_t);
 extern int zvol_set_volthreading(const char *, boolean_t);
 extern int zvol_set_common(const char *, zfs_prop_t, zprop_source_t, uint64_t);
+extern int zvol_set_ro(const char *, boolean_t);
 extern zvol_state_handle_t *zvol_suspend(const char *);
 extern int zvol_resume(zvol_state_handle_t *);
 extern void *zvol_tag(zvol_state_handle_t *);
index c4e99b34a1e2f90ee88c85393ba857b71fcab098..b2b06881bdd4114f2fe68684ca4c573aaa109bac 100644 (file)
@@ -2535,6 +2535,15 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source,
        case ZFS_PROP_VOLMODE:
                err = zvol_set_common(dsname, prop, source, intval);
                break;
+       case ZFS_PROP_READONLY:
+               err = zvol_set_ro(dsname, intval);
+               /*
+                * Set err to -1 to force the zfs_set_prop_nvlist code down the
+                * default path to set the value in the nvlist.
+                */
+               if (err == 0)
+                       err = -1;
+               break;
        case ZFS_PROP_VERSION:
        {
                zfsvfs_t *zfsvfs;
index d5f0693992a37a644b1bb3ef9f7ea00f1ec83a84..c7e10fbc638b222c94701fa6b5495ca8e0567e23 100644 (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.
  */