diff options
author | Christian Schwarz <[email protected]> | 2022-02-07 19:24:38 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2022-02-07 10:24:38 -0800 |
commit | 1dccfd7a38325151ae370c1cd5112a21e874f96d (patch) | |
tree | 5589da57f942c7b5ed149c4ed4470503bafc0cd4 /module/os | |
parent | f2c5bc150e609a78185ea63c84fce7718f56e28a (diff) |
zvol: make calls to platform ops static
There's no need to make the platform ops dynamic dispatch.
This change replaces the dynamic dispatch with static calls to the
platform-specific functions.
To avoid name collisions, prefix all platform-specific functions
with `zvol_os_`.
I actually find `zvol_..._os` slightly nicer to read in the calling
code, but having it as a prefix is useful.
Advantage:
- easier jump-to-definition / grepping
- potential benefits to static analysis
- better legibility
Future work: also prefix remaining `static` functions in zvol_os.c.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Christian Schwarz <[email protected]>
Closes #12965
Diffstat (limited to 'module/os')
-rw-r--r-- | module/os/freebsd/zfs/zvol_os.c | 46 | ||||
-rw-r--r-- | module/os/linux/zfs/zvol_os.c | 44 |
2 files changed, 33 insertions, 57 deletions
diff --git a/module/os/freebsd/zfs/zvol_os.c b/module/os/freebsd/zfs/zvol_os.c index 06dd8cfdd..b72c6216a 100644 --- a/module/os/freebsd/zfs/zvol_os.c +++ b/module/os/freebsd/zfs/zvol_os.c @@ -1196,7 +1196,7 @@ zvol_ensure_zilog(zvol_state_t *zv) zv->zv_zilog = zil_open(zv->zv_objset, zvol_get_data); zv->zv_flags |= ZVOL_WRITTEN_TO; - /* replay / destroy done in zvol_create_minor_impl() */ + /* replay / destroy done in zvol_os_create_minor() */ VERIFY0(zv->zv_zilog->zl_header->zh_flags & ZIL_REPLAY_NEEDED); } @@ -1204,14 +1204,14 @@ zvol_ensure_zilog(zvol_state_t *zv) } } -static boolean_t -zvol_is_zvol_impl(const char *device) +boolean_t +zvol_os_is_zvol(const char *device) { return (device && strncmp(device, ZVOL_DIR, strlen(ZVOL_DIR)) == 0); } -static void -zvol_rename_minor(zvol_state_t *zv, const char *newname) +void +zvol_os_rename_minor(zvol_state_t *zv, const char *newname) { ASSERT(RW_LOCK_HELD(&zvol_state_lock)); ASSERT(MUTEX_HELD(&zv->zv_state_lock)); @@ -1282,8 +1282,8 @@ zvol_rename_minor(zvol_state_t *zv, const char *newname) /* * Remove minor node for the specified volume. */ -static void -zvol_free(zvol_state_t *zv) +void +zvol_os_free(zvol_state_t *zv) { ASSERT(!RW_LOCK_HELD(&zv->zv_suspend_lock)); ASSERT(!MUTEX_HELD(&zv->zv_state_lock)); @@ -1324,8 +1324,8 @@ zvol_free(zvol_state_t *zv) /* * Create a minor node (plus a whole lot more) for the specified volume. */ -static int -zvol_create_minor_impl(const char *name) +int +zvol_os_create_minor(const char *name) { zvol_state_t *zv; objset_t *os; @@ -1463,8 +1463,8 @@ out_doi: return (error); } -static void -zvol_clear_private(zvol_state_t *zv) +void +zvol_os_clear_private(zvol_state_t *zv) { ASSERT(RW_LOCK_HELD(&zvol_state_lock)); if (zv->zv_volmode == ZFS_VOLMODE_GEOM) { @@ -1492,8 +1492,8 @@ zvol_clear_private(zvol_state_t *zv) } } -static int -zvol_update_volsize(zvol_state_t *zv, uint64_t volsize) +int +zvol_os_update_volsize(zvol_state_t *zv, uint64_t volsize) { zv->zv_volsize = volsize; if (zv->zv_volmode == ZFS_VOLMODE_GEOM) { @@ -1522,29 +1522,18 @@ zvol_update_volsize(zvol_state_t *zv, uint64_t volsize) return (0); } -static void -zvol_set_disk_ro_impl(zvol_state_t *zv, int flags) +void +zvol_os_set_disk_ro(zvol_state_t *zv, int flags) { // XXX? set_disk_ro(zv->zv_zso->zvo_disk, flags); } -static void -zvol_set_capacity_impl(zvol_state_t *zv, uint64_t capacity) +void +zvol_os_set_capacity(zvol_state_t *zv, uint64_t capacity) { // XXX? set_capacity(zv->zv_zso->zvo_disk, capacity); } -const static zvol_platform_ops_t zvol_freebsd_ops = { - .zv_free = zvol_free, - .zv_rename_minor = zvol_rename_minor, - .zv_create_minor = zvol_create_minor_impl, - .zv_update_volsize = zvol_update_volsize, - .zv_clear_private = zvol_clear_private, - .zv_is_zvol = zvol_is_zvol_impl, - .zv_set_disk_ro = zvol_set_disk_ro_impl, - .zv_set_capacity = zvol_set_capacity_impl, -}; - /* * Public interfaces */ @@ -1559,7 +1548,6 @@ int zvol_init(void) { zvol_init_impl(); - zvol_register_ops(&zvol_freebsd_ops); return (0); } diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c index e26d4db49..f772f4160 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -86,8 +86,8 @@ zv_request_task_free(zv_request_task_t *task) /* * Given a path, return TRUE if path is a ZVOL. */ -static boolean_t -zvol_is_zvol_impl(const char *path) +boolean_t +zvol_os_is_zvol(const char *path) { dev_t dev = 0; @@ -507,7 +507,7 @@ retry: /* * Obtain a copy of private_data under the zvol_state_lock to make * sure that either the result of zvol free code path setting - * bdev->bd_disk->private_data to NULL is observed, or zvol_free() + * bdev->bd_disk->private_data to NULL is observed, or zvol_os_free() * is not called on this zv because of the positive zv_open_count. */ zv = bdev->bd_disk->private_data; @@ -747,8 +747,8 @@ zvol_revalidate_disk(struct gendisk *disk) return (0); } -static int -zvol_update_volsize(zvol_state_t *zv, uint64_t volsize) +int +zvol_os_update_volsize(zvol_state_t *zv, uint64_t volsize) { struct gendisk *disk = zv->zv_zso->zvo_disk; @@ -762,8 +762,8 @@ zvol_update_volsize(zvol_state_t *zv, uint64_t volsize) return (0); } -static void -zvol_clear_private(zvol_state_t *zv) +void +zvol_os_clear_private(zvol_state_t *zv) { /* * Cleared while holding zvol_state_lock as a writer @@ -944,8 +944,8 @@ out_kmem: * "del_gendisk". Thus, consumers need to be careful to account for this * latency when calling this function. */ -static void -zvol_free(zvol_state_t *zv) +void +zvol_os_free(zvol_state_t *zv) { ASSERT(!RW_LOCK_HELD(&zv->zv_suspend_lock)); @@ -985,7 +985,7 @@ zvol_wait_close(zvol_state_t *zv) * and the specified volume. Once this function returns the block * device is live and ready for use. */ -static int +int zvol_os_create_minor(const char *name) { zvol_state_t *zv; @@ -1122,8 +1122,8 @@ out_doi: return (error); } -static void -zvol_rename_minor(zvol_state_t *zv, const char *newname) +void +zvol_os_rename_minor(zvol_state_t *zv, const char *newname) { int readonly = get_disk_ro(zv->zv_zso->zvo_disk); @@ -1149,31 +1149,20 @@ zvol_rename_minor(zvol_state_t *zv, const char *newname) set_disk_ro(zv->zv_zso->zvo_disk, readonly); } -static void -zvol_set_disk_ro_impl(zvol_state_t *zv, int flags) +void +zvol_os_set_disk_ro(zvol_state_t *zv, int flags) { set_disk_ro(zv->zv_zso->zvo_disk, flags); } -static void -zvol_set_capacity_impl(zvol_state_t *zv, uint64_t capacity) +void +zvol_os_set_capacity(zvol_state_t *zv, uint64_t capacity) { set_capacity(zv->zv_zso->zvo_disk, capacity); } -const static zvol_platform_ops_t zvol_linux_ops = { - .zv_free = zvol_free, - .zv_rename_minor = zvol_rename_minor, - .zv_create_minor = zvol_os_create_minor, - .zv_update_volsize = zvol_update_volsize, - .zv_clear_private = zvol_clear_private, - .zv_is_zvol = zvol_is_zvol_impl, - .zv_set_disk_ro = zvol_set_disk_ro_impl, - .zv_set_capacity = zvol_set_capacity_impl, -}; - int zvol_init(void) { @@ -1193,7 +1182,6 @@ zvol_init(void) } zvol_init_impl(); ida_init(&zvol_ida); - zvol_register_ops(&zvol_linux_ops); return (0); } |