Replace /*PRINTFLIKEn*/ with attribute(printf)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Issue #12201
This commit is contained in:
наб 2021-06-05 13:14:12 +02:00 committed by Brian Behlendorf
parent 1373709450
commit 5dbf6c5a66
19 changed files with 76 additions and 164 deletions

View File

@ -128,7 +128,7 @@ void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl);
int check_device(const char *path, boolean_t force,
boolean_t isspare, boolean_t iswholedisk);
boolean_t check_sector_size_database(char *path, int *sector_size);
void vdev_error(const char *fmt, ...);
void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
int check_file(const char *file, boolean_t force, boolean_t isspare);
void after_zpool_upgrade(zpool_handle_t *zhp);

View File

@ -86,7 +86,6 @@
boolean_t error_seen;
boolean_t is_force;
/*PRINTFLIKE1*/
void
vdev_error(const char *fmt, ...)
{
@ -704,8 +703,11 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"are present\n"),
raidz->zprl_type,
mirror->zprl_type,
(u_longlong_t)
raidz->zprl_parity,
(u_longlong_t)
mirror->zprl_children - 1,
(u_longlong_t)
mirror->zprl_children);
else
return (NULL);
@ -728,7 +730,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"%llu are present\n"),
lastrep.zprl_type,
rep.zprl_type,
(u_longlong_t)
lastrep.zprl_parity,
(u_longlong_t)
rep.zprl_parity);
else
return (NULL);
@ -755,8 +759,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"mismatched replication level: "
"both %llu and %llu device parity "
"%s vdevs are present\n"),
(u_longlong_t)
lastrep.zprl_parity,
rep.zprl_parity,
(u_longlong_t)rep.zprl_parity,
rep.zprl_type);
else
return (NULL);
@ -769,7 +774,9 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
"mismatched replication level: "
"both %llu-way and %llu-way %s "
"vdevs are present\n"),
(u_longlong_t)
lastrep.zprl_children,
(u_longlong_t)
rep.zprl_children,
rep.zprl_type);
else
@ -854,9 +861,9 @@ check_replication(nvlist_t *config, nvlist_t *newroot)
"and %s vdevs, %llu vs. %llu (%llu-way)\n"),
raidz->zprl_type,
mirror->zprl_type,
raidz->zprl_parity,
mirror->zprl_children - 1,
mirror->zprl_children);
(u_longlong_t)raidz->zprl_parity,
(u_longlong_t)mirror->zprl_children - 1,
(u_longlong_t)mirror->zprl_children);
ret = -1;
}
} else if (strcmp(current->zprl_type, new->zprl_type) != 0) {
@ -869,14 +876,17 @@ check_replication(nvlist_t *config, nvlist_t *newroot)
vdev_error(gettext(
"mismatched replication level: pool uses %llu "
"device parity and new vdev uses %llu\n"),
current->zprl_parity, new->zprl_parity);
(u_longlong_t)current->zprl_parity,
(u_longlong_t)new->zprl_parity);
ret = -1;
} else if (current->zprl_children != new->zprl_children) {
vdev_error(gettext(
"mismatched replication level: pool uses %llu-way "
"%s and new vdev uses %llu-way %s\n"),
current->zprl_children, current->zprl_type,
new->zprl_children, new->zprl_type);
(u_longlong_t)current->zprl_children,
current->zprl_type,
(u_longlong_t)new->zprl_children,
new->zprl_type);
ret = -1;
}
}

View File

@ -81,15 +81,18 @@ const char *uu_strerror(uint32_t);
extern void uu_alt_exit(int);
extern const char *uu_setpname(char *);
extern const char *uu_getpname(void);
/*PRINTFLIKE1*/
extern void uu_warn(const char *, ...);
extern void uu_vwarn(const char *, va_list);
/*PRINTFLIKE1*/
extern void uu_die(const char *, ...) __NORETURN;
extern void uu_vdie(const char *, va_list) __NORETURN;
/*PRINTFLIKE2*/
extern void uu_xdie(int, const char *, ...) __NORETURN;
extern void uu_vxdie(int, const char *, va_list) __NORETURN;
extern void uu_warn(const char *, ...)
__attribute__((format(printf, 1, 2)));
extern void uu_vwarn(const char *, va_list)
__attribute__((format(printf, 1, 0)));
extern void uu_die(const char *, ...)
__attribute__((format(printf, 1, 2))) __NORETURN;
extern void uu_vdie(const char *, va_list)
__attribute__((format(printf, 1, 0))) __NORETURN;
extern void uu_xdie(int, const char *, ...)
__attribute__((format(printf, 2, 3))) __NORETURN;
extern void uu_vxdie(int, const char *, va_list)
__attribute__((format(printf, 2, 0))) __NORETURN;
/*
* Exit status functions (not to be used directly)
@ -111,8 +114,8 @@ int uu_check_name(const char *, uint_t);
*/
#define UU_NELEM(a) (sizeof (a) / sizeof ((a)[0]))
/*PRINTFLIKE1*/
extern char *uu_msprintf(const char *format, ...);
extern char *uu_msprintf(const char *format, ...)
__attribute__((format(printf, 1, 2)));
extern void *uu_zalloc(size_t);
extern char *uu_strdup(const char *);
extern void uu_free(void *);

View File

@ -42,8 +42,7 @@ extern "C" {
void uu_set_error(uint_t);
/*PRINTFLIKE1*/
void uu_panic(const char *format, ...);
void uu_panic(const char *format, ...) __attribute__((format(printf, 1, 2)));
/*

View File

@ -36,91 +36,6 @@
extern "C" {
#endif
/*
* Allow for version tests for compiler bugs and features.
*/
#if defined(__GNUC__)
#define __GNUC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
#define __GNUC_VERSION 0
#endif
#if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
#if 0
/*
* analogous to lint's PRINTFLIKEn
*/
#define __sun_attr___PRINTFLIKE__(__n) \
__attribute__((__format__(printf, __n, (__n)+1)))
#define __sun_attr___VPRINTFLIKE__(__n) \
__attribute__((__format__(printf, __n, 0)))
#define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__
#define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__
#else
/*
* Currently the openzfs codebase has a lot of formatting errors
* which are not picked up in the linux build because they're not
* doing formatting checks. LLVM's kprintf implementation doesn't
* actually do format checks!
*
* For FreeBSD these break under gcc! LLVM shim'ed cmn_err as a
* format attribute but also didn't check anything. If one
* replaces it with the above, all of the format issues
* in the codebase show up.
*
* Once those format string issues are addressed, the above
* should be flipped on once again.
*/
#define __sun_attr___PRINTFLIKE__(__n)
#define __sun_attr___VPRINTFLIKE__(__n)
#define __sun_attr___KPRINTFLIKE__(__n)
#define __sun_attr___KVPRINTFLIKE__(__n)
#endif
/*
* This one's pretty obvious -- the function never returns
*/
#define __sun_attr___noreturn__ __attribute__((__noreturn__))
/*
* This is an appropriate label for functions that do not
* modify their arguments, e.g. strlen()
*/
#define __sun_attr___pure__ __attribute__((__pure__))
/*
* This is a stronger form of __pure__. Can be used for functions
* that do not modify their arguments and don't depend on global
* memory.
*/
#define __sun_attr___const__ __attribute__((__const__))
/*
* structure packing like #pragma pack(1)
*/
#define __sun_attr___packed__ __attribute__((__packed__))
#define ___sun_attr_inner(__a) __sun_attr_##__a
#define __sun_attr__(__a) ___sun_attr_inner __a
#else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
#define __sun_attr__(__a)
#endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
/*
* Shorthand versions for readability
*/
#define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n)))
#define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n)))
#define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n)))
#define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n)))
#if defined(_KERNEL) || defined(_STANDALONE)
#define __NORETURN __sun_attr__((__noreturn__))
#endif /* _KERNEL || _STANDALONE */

View File

@ -49,36 +49,29 @@ extern "C" {
#ifndef _ASM
/*PRINTFLIKE2*/
extern void cmn_err(int, const char *, ...)
__KPRINTFLIKE(2);
__attribute__((format(printf, 2, 3)));
extern void vzcmn_err(zoneid_t, int, const char *, __va_list)
__KVPRINTFLIKE(3);
__attribute__((format(printf, 3, 0)));
extern void vcmn_err(int, const char *, __va_list)
__KVPRINTFLIKE(2);
__attribute__((format(printf, 2, 0)));
/*PRINTFLIKE3*/
extern void zcmn_err(zoneid_t, int, const char *, ...)
__KPRINTFLIKE(3);
__attribute__((format(printf, 3, 4)));
extern void vzprintf(zoneid_t, const char *, __va_list)
__KVPRINTFLIKE(2);
__attribute__((format(printf, 2, 0)));
/*PRINTFLIKE2*/
extern void zprintf(zoneid_t, const char *, ...)
__KPRINTFLIKE(2);
__attribute__((format(printf, 2, 3)));
extern void vuprintf(const char *, __va_list)
__KVPRINTFLIKE(1);
__attribute__((format(printf, 1, 0)));
/*PRINTFLIKE1*/
extern void panic(const char *, ...)
__KPRINTFLIKE(1) __NORETURN;
extern void vpanic(const char *, __va_list)
__KVPRINTFLIKE(1) __NORETURN;
__attribute__((format(printf, 1, 2))) __NORETURN;
#endif /* !_ASM */

View File

@ -32,9 +32,12 @@
#define CE_PANIC 3 /* panic */
#define CE_IGNORE 4 /* print nothing */
extern void cmn_err(int, const char *, ...);
extern void vcmn_err(int, const char *, va_list);
extern void vpanic(const char *, va_list);
extern void cmn_err(int, const char *, ...)
__attribute__((format(printf, 2, 3)));
extern void vcmn_err(int, const char *, va_list)
__attribute__((format(printf, 2, 0)));
extern void vpanic(const char *, va_list)
__attribute__((format(printf, 1, 0)));
#define fm_panic panic

View File

@ -1056,8 +1056,10 @@ extern uint64_t spa_dirty_data(spa_t *spa);
extern spa_autotrim_t spa_get_autotrim(spa_t *spa);
/* Miscellaneous support routines */
extern void spa_load_failed(spa_t *spa, const char *fmt, ...);
extern void spa_load_note(spa_t *spa, const char *fmt, ...);
extern void spa_load_failed(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void spa_load_note(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void spa_activate_mos_feature(spa_t *spa, const char *feature,
dmu_tx_t *tx);
extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);

View File

@ -52,7 +52,8 @@ extern int zfs_nocacheflush;
typedef boolean_t vdev_open_children_func_t(vdev_t *vd);
extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...);
extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
extern void vdev_dbgmsg_print_tree(vdev_t *, int);
extern int vdev_open(vdev_t *);
extern void vdev_open_children(vdev_t *);

View File

@ -38,9 +38,6 @@
#include <wchar.h>
#include <unistd.h>
static const char PNAME_FMT[] = "%s: ";
static const char ERRNO_FMT[] = ": %s\n";
static const char *pname;
static void
@ -85,16 +82,16 @@ uu_alt_exit(int profile)
}
}
static void
static __attribute__((format(printf, 2, 0))) void
uu_warn_internal(int err, const char *format, va_list alist)
{
if (pname != NULL)
(void) fprintf(stderr, PNAME_FMT, pname);
(void) fprintf(stderr, "%s: ", pname);
(void) vfprintf(stderr, format, alist);
if (strrchr(format, '\n') == NULL)
(void) fprintf(stderr, ERRNO_FMT, strerror(err));
(void) fprintf(stderr, ": %s\n", strerror(err));
}
void
@ -103,7 +100,6 @@ uu_vwarn(const char *format, va_list alist)
uu_warn_internal(errno, format, alist);
}
/*PRINTFLIKE1*/
void
uu_warn(const char *format, ...)
{
@ -113,7 +109,7 @@ uu_warn(const char *format, ...)
va_end(alist);
}
static void
static __attribute__((format(printf, 2, 0))) __NORETURN void
uu_die_internal(int status, const char *format, va_list alist)
{
uu_warn_internal(errno, format, alist);
@ -137,7 +133,6 @@ uu_vdie(const char *format, va_list alist)
uu_die_internal(UU_EXIT_FATAL, format, alist);
}
/*PRINTFLIKE1*/
void
uu_die(const char *format, ...)
{
@ -153,7 +148,6 @@ uu_vxdie(int status, const char *format, va_list alist)
uu_die_internal(status, format, alist);
}
/*PRINTFLIKE2*/
void
uu_xdie(int status, const char *format, ...)
{

View File

@ -304,7 +304,6 @@ libzfs_error_description(libzfs_handle_t *hdl)
}
}
/*PRINTFLIKE2*/
void
zfs_error_aux(libzfs_handle_t *hdl, const char *fmt, ...)
{
@ -352,7 +351,6 @@ zfs_error(libzfs_handle_t *hdl, int error, const char *msg)
return (zfs_error_fmt(hdl, error, "%s", msg));
}
/*PRINTFLIKE3*/
int
zfs_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
{
@ -403,7 +401,6 @@ zfs_standard_error(libzfs_handle_t *hdl, int error, const char *msg)
return (zfs_standard_error_fmt(hdl, error, "%s", msg));
}
/*PRINTFLIKE3*/
int
zfs_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
{
@ -613,7 +610,6 @@ zpool_standard_error(libzfs_handle_t *hdl, int error, const char *msg)
return (zpool_standard_error_fmt(hdl, error, "%s", msg));
}
/*PRINTFLIKE3*/
int
zpool_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
{
@ -771,7 +767,6 @@ zfs_alloc(libzfs_handle_t *hdl, size_t size)
/*
* A safe form of asprintf() which will die if the allocation fails.
*/
/*PRINTFLIKE2*/
char *
zfs_asprintf(libzfs_handle_t *hdl, const char *fmt, ...)
{

View File

@ -634,7 +634,6 @@ vcmn_err(int ce, const char *fmt, va_list adx)
}
}
/*PRINTFLIKE2*/
void
cmn_err(int ce, const char *fmt, ...)
{

View File

@ -69,8 +69,7 @@
#include "zutil_import.h"
/*PRINTFLIKE2*/
static void
static __attribute__((format(printf, 2, 3))) void
zutil_error_aux(libpc_handle_t *hdl, const char *fmt, ...)
{
va_list ap;
@ -104,8 +103,7 @@ zutil_verror(libpc_handle_t *hdl, const char *error, const char *fmt,
}
}
/*PRINTFLIKE3*/
static int
static __attribute__((format(printf, 3, 4))) int
zutil_error_fmt(libpc_handle_t *hdl, const char *error, const char *fmt, ...)
{
va_list ap;
@ -1237,7 +1235,7 @@ zpool_find_import_scan_dir(libpc_handle_t *hdl, pthread_mutex_t *lock,
if (error == ENOENT)
return (0);
zutil_error_aux(hdl, strerror(error));
zutil_error_aux(hdl, "%s", strerror(error));
(void) zutil_error_fmt(hdl, EZFS_BADPATH, dgettext(
TEXT_DOMAIN, "cannot resolve path '%s'"), dir);
return (error);
@ -1246,7 +1244,7 @@ zpool_find_import_scan_dir(libpc_handle_t *hdl, pthread_mutex_t *lock,
dirp = opendir(path);
if (dirp == NULL) {
error = errno;
zutil_error_aux(hdl, strerror(error));
zutil_error_aux(hdl, "%s", strerror(error));
(void) zutil_error_fmt(hdl, EZFS_BADPATH,
dgettext(TEXT_DOMAIN, "cannot open '%s'"), path);
return (error);
@ -1308,7 +1306,7 @@ zpool_find_import_scan_path(libpc_handle_t *hdl, pthread_mutex_t *lock,
goto out;
}
zutil_error_aux(hdl, strerror(error));
zutil_error_aux(hdl, "%s", strerror(error));
(void) zutil_error_fmt(hdl, EZFS_BADPATH, dgettext(
TEXT_DOMAIN, "cannot resolve path '%s'"), dir);
goto out;
@ -1346,7 +1344,7 @@ zpool_find_import_scan(libpc_handle_t *hdl, pthread_mutex_t *lock,
if (error == ENOENT)
continue;
zutil_error_aux(hdl, strerror(error));
zutil_error_aux(hdl, "%s", strerror(error));
(void) zutil_error_fmt(hdl, EZFS_BADPATH, dgettext(
TEXT_DOMAIN, "cannot resolve path '%s'"), dir[i]);
goto error;

View File

@ -546,7 +546,9 @@ __vdev_disk_physio(struct block_device *bdev, zio_t *zio,
if (io_offset + io_size > bdev->bd_inode->i_size) {
vdev_dbgmsg(zio->io_vd,
"Illegal access %llu size %llu, device size %llu",
io_offset, io_size, i_size_read(bdev->bd_inode));
(u_longlong_t)io_offset,
(u_longlong_t)io_size,
(u_longlong_t)i_size_read(bdev->bd_inode));
return (SET_ERROR(EIO));
}

View File

@ -7470,7 +7470,7 @@ arc_state_multilist_index_func(multilist_t *ml, void *obj)
if ((do_warn) && (tuning) && ((tuning) != (value))) { \
cmn_err(CE_WARN, \
"ignoring tunable %s (using %llu instead)", \
(#tuning), (value)); \
(#tuning), (u_longlong_t)(value)); \
} \
} while (0)

View File

@ -1033,8 +1033,8 @@ spa_ld_log_sm_metadata(spa_t *spa)
if (sls == NULL) {
spa_load_failed(spa, "spa_ld_log_sm_metadata(): bug "
"encountered: could not find log spacemap for "
"TXG %ld [error %d]",
metaslab_unflushed_txg(m), ENOENT);
"TXG %llu [error %d]",
(u_longlong_t)metaslab_unflushed_txg(m), ENOENT);
return (ENOENT);
}
sls->sls_mscount++;

View File

@ -389,7 +389,6 @@ uint64_t spa_max_slop = 128ULL * 1024 * 1024 * 1024;
int spa_allocators = 4;
/*PRINTFLIKE2*/
void
spa_load_failed(spa_t *spa, const char *fmt, ...)
{
@ -404,7 +403,6 @@ spa_load_failed(spa_t *spa, const char *fmt, ...)
spa->spa_trust_config ? "trusted" : "untrusted", buf);
}
/*PRINTFLIKE2*/
void
spa_load_note(spa_t *spa, const char *fmt, ...)
{

View File

@ -137,7 +137,6 @@ int zfs_nocacheflush = 0;
uint64_t zfs_vdev_max_auto_ashift = ASHIFT_MAX;
uint64_t zfs_vdev_min_auto_ashift = ASHIFT_MIN;
/*PRINTFLIKE2*/
void
vdev_dbgmsg(vdev_t *vd, const char *fmt, ...)
{
@ -3457,7 +3456,8 @@ vdev_load(vdev_t *vd)
vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
VDEV_AUX_CORRUPT_DATA);
vdev_dbgmsg(vd, "vdev_load: zap_lookup(top_zap=%llu) "
"failed [error=%d]", vd->vdev_top_zap, error);
"failed [error=%d]",
(u_longlong_t)vd->vdev_top_zap, error);
return (error);
}
}

View File

@ -165,8 +165,8 @@ vdev_raidz_math_generate(raidz_map_t *rm, raidz_row_t *rr)
break;
default:
gen_parity = NULL;
cmn_err(CE_PANIC, "invalid RAID-Z configuration %d",
raidz_parity(rm));
cmn_err(CE_PANIC, "invalid RAID-Z configuration %llu",
(u_longlong_t)raidz_parity(rm));
break;
}
@ -257,8 +257,8 @@ vdev_raidz_math_reconstruct(raidz_map_t *rm, raidz_row_t *rr,
rec_fn = reconstruct_fun_pqr_sel(rm, parity_valid, nbaddata);
break;
default:
cmn_err(CE_PANIC, "invalid RAID-Z configuration %d",
raidz_parity(rm));
cmn_err(CE_PANIC, "invalid RAID-Z configuration %llu",
(u_longlong_t)raidz_parity(rm));
break;
}