Skip to content

Commit 5c59562

Browse files
solbjornbehlendorf
authored andcommitted
A few fixes of callback typecasting (for the upcoming ClangCFI)
* zio: avoid callback typecasting * zil: avoid zil_itxg_clean() callback typecasting * zpl: decouple zpl_readpage() into two separate callbacks * nvpair: explicitly declare callbacks for xdr_array() * linux/zfs_nvops: don't use external iput() as a callback * zcp_synctask: don't use fnvlist_free() as a callback * zvol: don't use ops->zv_free() as a callback for taskq_dispatch() Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Mark Maybee <[email protected]> Signed-off-by: Alexander Lobakin <[email protected]> Closes #12260
1 parent 4c5a408 commit 5c59562

File tree

8 files changed

+111
-32
lines changed

8 files changed

+111
-32
lines changed

include/sys/zio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ extern void zio_shrink(zio_t *zio, uint64_t size);
589589

590590
extern int zio_wait(zio_t *zio);
591591
extern void zio_nowait(zio_t *zio);
592-
extern void zio_execute(zio_t *zio);
593-
extern void zio_interrupt(zio_t *zio);
592+
extern void zio_execute(void *zio);
593+
extern void zio_interrupt(void *zio);
594594
extern void zio_delay_init(zio_t *zio);
595595
extern void zio_delay_interrupt(zio_t *zio);
596596
extern void zio_deadman(zio_t *zio, char *tag);

module/nvpair/nvpair.c

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,56 @@ nvs_xdr_nvl_fini(nvstream_t *nvs)
32133213
return (0);
32143214
}
32153215

3216+
/*
3217+
* xdrproc_t-compatible callbacks for xdr_array()
3218+
*/
3219+
3220+
#if defined(_KERNEL) && defined(__linux__) /* Linux kernel */
3221+
3222+
#define NVS_BUILD_XDRPROC_T(type) \
3223+
static bool_t \
3224+
nvs_xdr_nvp_##type(XDR *xdrs, void *ptr) \
3225+
{ \
3226+
return (xdr_##type(xdrs, ptr)); \
3227+
}
3228+
3229+
#elif !defined(_KERNEL) && defined(XDR_CONTROL) /* tirpc */
3230+
3231+
#define NVS_BUILD_XDRPROC_T(type) \
3232+
static bool_t \
3233+
nvs_xdr_nvp_##type(XDR *xdrs, ...) \
3234+
{ \
3235+
va_list args; \
3236+
void *ptr; \
3237+
\
3238+
va_start(args, xdrs); \
3239+
ptr = va_arg(args, void *); \
3240+
va_end(args); \
3241+
\
3242+
return (xdr_##type(xdrs, ptr)); \
3243+
}
3244+
3245+
#else /* FreeBSD, sunrpc */
3246+
3247+
#define NVS_BUILD_XDRPROC_T(type) \
3248+
static bool_t \
3249+
nvs_xdr_nvp_##type(XDR *xdrs, void *ptr, ...) \
3250+
{ \
3251+
return (xdr_##type(xdrs, ptr)); \
3252+
}
3253+
3254+
#endif
3255+
3256+
/* BEGIN CSTYLED */
3257+
NVS_BUILD_XDRPROC_T(char);
3258+
NVS_BUILD_XDRPROC_T(short);
3259+
NVS_BUILD_XDRPROC_T(u_short);
3260+
NVS_BUILD_XDRPROC_T(int);
3261+
NVS_BUILD_XDRPROC_T(u_int);
3262+
NVS_BUILD_XDRPROC_T(longlong_t);
3263+
NVS_BUILD_XDRPROC_T(u_longlong_t);
3264+
/* END CSTYLED */
3265+
32163266
/*
32173267
* The format of xdr encoded nvpair is:
32183268
* encode_size, decode_size, name string, data type, nelem, data
@@ -3335,38 +3385,38 @@ nvs_xdr_nvp_op(nvstream_t *nvs, nvpair_t *nvp)
33353385
case DATA_TYPE_INT8_ARRAY:
33363386
case DATA_TYPE_UINT8_ARRAY:
33373387
ret = xdr_array(xdr, &buf, &nelem, buflen, sizeof (int8_t),
3338-
(xdrproc_t)xdr_char);
3388+
nvs_xdr_nvp_char);
33393389
break;
33403390

33413391
case DATA_TYPE_INT16_ARRAY:
33423392
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int16_t),
3343-
sizeof (int16_t), (xdrproc_t)xdr_short);
3393+
sizeof (int16_t), nvs_xdr_nvp_short);
33443394
break;
33453395

33463396
case DATA_TYPE_UINT16_ARRAY:
33473397
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint16_t),
3348-
sizeof (uint16_t), (xdrproc_t)xdr_u_short);
3398+
sizeof (uint16_t), nvs_xdr_nvp_u_short);
33493399
break;
33503400

33513401
case DATA_TYPE_BOOLEAN_ARRAY:
33523402
case DATA_TYPE_INT32_ARRAY:
33533403
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int32_t),
3354-
sizeof (int32_t), (xdrproc_t)xdr_int);
3404+
sizeof (int32_t), nvs_xdr_nvp_int);
33553405
break;
33563406

33573407
case DATA_TYPE_UINT32_ARRAY:
33583408
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint32_t),
3359-
sizeof (uint32_t), (xdrproc_t)xdr_u_int);
3409+
sizeof (uint32_t), nvs_xdr_nvp_u_int);
33603410
break;
33613411

33623412
case DATA_TYPE_INT64_ARRAY:
33633413
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int64_t),
3364-
sizeof (int64_t), (xdrproc_t)xdr_longlong_t);
3414+
sizeof (int64_t), nvs_xdr_nvp_longlong_t);
33653415
break;
33663416

33673417
case DATA_TYPE_UINT64_ARRAY:
33683418
ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint64_t),
3369-
sizeof (uint64_t), (xdrproc_t)xdr_u_longlong_t);
3419+
sizeof (uint64_t), nvs_xdr_nvp_u_longlong_t);
33703420
break;
33713421

33723422
case DATA_TYPE_STRING_ARRAY: {

module/os/linux/zfs/zfs_vnops_os.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ zfs_write_simple(znode_t *zp, const void *data, size_t len,
392392
return (error);
393393
}
394394

395+
static void
396+
zfs_rele_async_task(void *arg)
397+
{
398+
iput(arg);
399+
}
400+
395401
void
396402
zfs_zrele_async(znode_t *zp)
397403
{
@@ -411,7 +417,7 @@ zfs_zrele_async(znode_t *zp)
411417
*/
412418
if (!atomic_add_unless(&ip->i_count, -1, 1)) {
413419
VERIFY(taskq_dispatch(dsl_pool_zrele_taskq(dmu_objset_pool(os)),
414-
(task_func_t *)iput, ip, TQ_SLEEP) != TASKQID_INVALID);
420+
zfs_rele_async_task, ip, TQ_SLEEP) != TASKQID_INVALID);
415421
}
416422
}
417423

module/os/linux/zfs/zpl_file.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ zpl_mmap(struct file *filp, struct vm_area_struct *vma)
591591
* only used to support mmap(2). There will be an identical copy of the
592592
* data in the ARC which is kept up to date via .write() and .writepage().
593593
*/
594-
static int
595-
zpl_readpage(struct file *filp, struct page *pp)
594+
static inline int
595+
zpl_readpage_common(struct page *pp)
596596
{
597597
struct inode *ip;
598598
struct page *pl[1];
@@ -620,6 +620,18 @@ zpl_readpage(struct file *filp, struct page *pp)
620620
return (error);
621621
}
622622

623+
static int
624+
zpl_readpage(struct file *filp, struct page *pp)
625+
{
626+
return (zpl_readpage_common(pp));
627+
}
628+
629+
static int
630+
zpl_readpage_filler(void *data, struct page *pp)
631+
{
632+
return (zpl_readpage_common(pp));
633+
}
634+
623635
/*
624636
* Populate a set of pages with data for the Linux page cache. This
625637
* function will only be called for read ahead and never for demand
@@ -630,8 +642,7 @@ static int
630642
zpl_readpages(struct file *filp, struct address_space *mapping,
631643
struct list_head *pages, unsigned nr_pages)
632644
{
633-
return (read_cache_pages(mapping, pages,
634-
(filler_t *)zpl_readpage, filp));
645+
return (read_cache_pages(mapping, pages, zpl_readpage_filler, NULL));
635646
}
636647

637648
static int

module/zfs/zcp_synctask.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ typedef struct zcp_synctask_info {
5454
int blocks_modified;
5555
} zcp_synctask_info_t;
5656

57+
static void
58+
zcp_synctask_cleanup(void *arg)
59+
{
60+
fnvlist_free(arg);
61+
}
62+
5763
/*
5864
* Generic synctask interface for channel program syncfuncs.
5965
*
@@ -275,7 +281,7 @@ zcp_synctask_snapshot(lua_State *state, boolean_t sync, nvlist_t *err_details)
275281
fnvlist_add_boolean(ddsa.ddsa_snaps, dsname);
276282

277283
zcp_cleanup_handler_t *zch = zcp_register_cleanup(state,
278-
(zcp_cleanup_t *)&fnvlist_free, ddsa.ddsa_snaps);
284+
zcp_synctask_cleanup, ddsa.ddsa_snaps);
279285

280286
err = zcp_sync_task(state, dsl_dataset_snapshot_check,
281287
dsl_dataset_snapshot_sync, &ddsa, sync, dsname);
@@ -363,7 +369,7 @@ zcp_synctask_inherit_prop(lua_State *state, boolean_t sync,
363369
fnvlist_add_boolean(dpsa->dpsa_props, prop);
364370

365371
zcp_cleanup_handler_t *zch = zcp_register_cleanup(state,
366-
(zcp_cleanup_t *)&fnvlist_free, dpsa->dpsa_props);
372+
zcp_synctask_cleanup, dpsa->dpsa_props);
367373

368374
err = zcp_sync_task(state, zcp_synctask_inherit_prop_check,
369375
zcp_synctask_inherit_prop_sync, &zipa, sync, dsname);
@@ -402,7 +408,7 @@ zcp_synctask_bookmark(lua_State *state, boolean_t sync, nvlist_t *err_details)
402408
fnvlist_add_string(bmarks, new, source);
403409

404410
zcp_cleanup_handler_t *zch = zcp_register_cleanup(state,
405-
(zcp_cleanup_t *)&fnvlist_free, bmarks);
411+
zcp_synctask_cleanup, bmarks);
406412

407413
dsl_bookmark_create_arg_t dbca = {
408414
.dbca_bmarks = bmarks,
@@ -467,8 +473,7 @@ zcp_synctask_wrapper(lua_State *state)
467473
* Make sure err_details is properly freed, even if a fatal error is
468474
* thrown during the synctask.
469475
*/
470-
zch = zcp_register_cleanup(state,
471-
(zcp_cleanup_t *)&fnvlist_free, err_details);
476+
zch = zcp_register_cleanup(state, zcp_synctask_cleanup, err_details);
472477

473478
zcp_synctask_info_t *info = lua_touserdata(state, lua_upvalueindex(1));
474479
boolean_t sync = lua_toboolean(state, lua_upvalueindex(2));

module/zfs/zil.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,12 +1820,13 @@ zil_itx_destroy(itx_t *itx)
18201820
* so no locks are needed.
18211821
*/
18221822
static void
1823-
zil_itxg_clean(itxs_t *itxs)
1823+
zil_itxg_clean(void *arg)
18241824
{
18251825
itx_t *itx;
18261826
list_t *list;
18271827
avl_tree_t *t;
18281828
void *cookie;
1829+
itxs_t *itxs = arg;
18291830
itx_async_node_t *ian;
18301831

18311832
list = &itxs->i_sync_list;
@@ -2045,7 +2046,7 @@ zil_clean(zilog_t *zilog, uint64_t synced_txg)
20452046
ASSERT3P(zilog->zl_dmu_pool, !=, NULL);
20462047
ASSERT3P(zilog->zl_dmu_pool->dp_zil_clean_taskq, !=, NULL);
20472048
taskqid_t id = taskq_dispatch(zilog->zl_dmu_pool->dp_zil_clean_taskq,
2048-
(void (*)(void *))zil_itxg_clean, clean_me, TQ_NOSLEEP);
2049+
zil_itxg_clean, clean_me, TQ_NOSLEEP);
20492050
if (id == TASKQID_INVALID)
20502051
zil_itxg_clean(clean_me);
20512052
}

module/zfs/zio.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,8 +1891,8 @@ zio_taskq_dispatch(zio_t *zio, zio_taskq_type_t q, boolean_t cutinline)
18911891
* to dispatch the zio to another taskq at the same time.
18921892
*/
18931893
ASSERT(taskq_empty_ent(&zio->io_tqent));
1894-
spa_taskq_dispatch_ent(spa, t, q, (task_func_t *)zio_execute, zio,
1895-
flags, &zio->io_tqent);
1894+
spa_taskq_dispatch_ent(spa, t, q, zio_execute, zio, flags,
1895+
&zio->io_tqent);
18961896
}
18971897

18981898
static boolean_t
@@ -1923,7 +1923,7 @@ zio_issue_async(zio_t *zio)
19231923
}
19241924

19251925
void
1926-
zio_interrupt(zio_t *zio)
1926+
zio_interrupt(void *zio)
19271927
{
19281928
zio_taskq_dispatch(zio, ZIO_TASKQ_INTERRUPT, B_FALSE);
19291929
}
@@ -1981,8 +1981,8 @@ zio_delay_interrupt(zio_t *zio)
19811981
* OpenZFS's timeout_generic().
19821982
*/
19831983
tid = taskq_dispatch_delay(system_taskq,
1984-
(task_func_t *)zio_interrupt,
1985-
zio, TQ_NOSLEEP, expire_at_tick);
1984+
zio_interrupt, zio, TQ_NOSLEEP,
1985+
expire_at_tick);
19861986
if (tid == TASKQID_INVALID) {
19871987
/*
19881988
* Couldn't allocate a task. Just
@@ -2103,7 +2103,7 @@ static zio_pipe_stage_t *zio_pipeline[];
21032103
* it is externally visible.
21042104
*/
21052105
void
2106-
zio_execute(zio_t *zio)
2106+
zio_execute(void *zio)
21072107
{
21082108
fstrans_cookie_t cookie;
21092109

@@ -2292,8 +2292,9 @@ zio_nowait(zio_t *zio)
22922292
*/
22932293

22942294
static void
2295-
zio_reexecute(zio_t *pio)
2295+
zio_reexecute(void *arg)
22962296
{
2297+
zio_t *pio = arg;
22972298
zio_t *cio, *cio_next;
22982299

22992300
ASSERT(pio->io_child_type == ZIO_CHILD_LOGICAL);
@@ -4788,8 +4789,7 @@ zio_done(zio_t *zio)
47884789
ASSERT(taskq_empty_ent(&zio->io_tqent));
47894790
spa_taskq_dispatch_ent(zio->io_spa,
47904791
ZIO_TYPE_CLAIM, ZIO_TASKQ_ISSUE,
4791-
(task_func_t *)zio_reexecute, zio, 0,
4792-
&zio->io_tqent);
4792+
zio_reexecute, zio, 0, &zio->io_tqent);
47934793
}
47944794
return (NULL);
47954795
}

module/zfs/zvol.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,12 @@ zvol_create_minor(const char *name)
11951195
* Remove minors for specified dataset including children and snapshots.
11961196
*/
11971197

1198+
static void
1199+
zvol_free_task(void *arg)
1200+
{
1201+
ops->zv_free(arg);
1202+
}
1203+
11981204
void
11991205
zvol_remove_minors_impl(const char *name)
12001206
{
@@ -1243,8 +1249,8 @@ zvol_remove_minors_impl(const char *name)
12431249
mutex_exit(&zv->zv_state_lock);
12441250

12451251
/* Try parallel zv_free, if failed do it in place */
1246-
t = taskq_dispatch(system_taskq,
1247-
(task_func_t *)ops->zv_free, zv, TQ_SLEEP);
1252+
t = taskq_dispatch(system_taskq, zvol_free_task, zv,
1253+
TQ_SLEEP);
12481254
if (t == TASKQID_INVALID)
12491255
list_insert_head(&free_list, zv);
12501256
} else {

0 commit comments

Comments
 (0)