Index: share/man/man9/Makefile =================================================================== --- share/man/man9/Makefile +++ share/man/man9/Makefile @@ -1003,6 +1003,7 @@ g_bio.9 g_clone_bio.9 \ g_bio.9 g_destroy_bio.9 \ g_bio.9 g_duplicate_bio.9 \ + g_bio.9 g_format_bio.9 \ g_bio.9 g_new_bio.9 \ g_bio.9 g_print_bio.9 \ g_bio.9 g_reset_bio.9 Index: share/man/man9/g_bio.9 =================================================================== --- share/man/man9/g_bio.9 +++ share/man/man9/g_bio.9 @@ -24,13 +24,14 @@ .\" .\" $FreeBSD$ .\" -.Dd Mar 7, 2018 +.Dd August 7, 2019 .Dt G_BIO 9 .Os .Sh NAME .Nm g_new_bio , .Nm g_clone_bio , .Nm g_destroy_bio , +.Nm g_format_bio , .Nm g_print_bio , .Nm g_reset_bio .Nd "GEOM bio controlling functions" @@ -48,7 +49,12 @@ .Ft void .Fn g_destroy_bio "struct bio *bp" .Ft void -.Fn g_print_bio "struct bio *bp" +.Fn g_format_bio "struct sbuf *sb" "const struct bio *bp" +.Ft void +.Fo g_print_bio +.Fa "struct sbuf *sb" "const char *prefix" "const struct bio *bp" +.Fa "const char *fmtsuffix" ... +.Fc .Ft void .Fn g_reset_bio "struct bio *bp" .Sh DESCRIPTION @@ -204,10 +210,28 @@ structure. .Pp The -.Fn g_print_bio +.Fn g_format_bio function prints information about the given .Vt bio -structure (for debugging purposes). +structure into the provided +.Vt sbuf . +.Pp +The +.Fn g_print_bio +function is a convenience wrapper around +.Fn g_format_bio +that can be used for debugging purposes. +It prints a provided +.Fa prefix +string, followed by the formatted +.Vt bio , +followed by a +.Fa fmtsuffix +in the style of +.Xr 9 printf . +Any of the prefix or suffix strings may be the empty string. +.Fn g_print_bio +always prints a newline character at the end of the line. .Pp The .Fn g_reset_bio @@ -261,9 +285,7 @@ struct example_softc *sc; struct bio *cbp; - printf("Request received: "); - g_print_bio(bp); - printf("\\n"); + g_print_bio("Request received: ", bp, ""); sc = bp->bio_to->geom->softc; if (sc == NULL) { Index: sys/dev/fdc/fdc.c =================================================================== --- sys/dev/fdc/fdc.c +++ sys/dev/fdc/fdc.c @@ -1160,10 +1160,8 @@ mtx_unlock(&fdc->fdc_mtx); i = fdc_worker(fdc); if (i && debugflags & 0x20) { - if (fdc->bp != NULL) { - g_print_bio(fdc->bp); - printf("\n"); - } + if (fdc->bp != NULL) + g_print_bio("", fdc->bp, ""); printf("Retry line %d\n", retry_line); } fdc->retry += i; Index: sys/geom/cache/g_cache.h =================================================================== --- sys/geom/cache/g_cache.h +++ sys/geom/cache/g_cache.h @@ -41,25 +41,10 @@ #define G_CACHE_TYPE_MANUAL 0 #define G_CACHE_TYPE_AUTOMATIC 1 -#define G_CACHE_DEBUG(lvl, ...) do { \ - if (g_cache_debug >= (lvl)) { \ - printf("GEOM_CACHE"); \ - if (g_cache_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_CACHE_LOGREQ(bp, ...) do { \ - if (g_cache_debug >= 2) { \ - printf("GEOM_CACHE[2]: "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_CACHE_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_CACHE", g_cache_debug, (lvl), NULL, __VA_ARGS__) +#define G_CACHE_LOGREQ(bp, ...) \ + _GEOM_DEBUG("GEOM_CACHE", g_cache_debug, 2, (bp), __VA_ARGS__) #define G_CACHE_BUCKETS (1 << 3) #define G_CACHE_BUCKET(bno) ((bno) & (G_CACHE_BUCKETS - 1)) Index: sys/geom/cache/g_cache.c =================================================================== --- sys/geom/cache/g_cache.c +++ sys/geom/cache/g_cache.c @@ -43,6 +43,7 @@ #include #include #include +#include #include FEATURE(geom_cache, "GEOM cache module"); Index: sys/geom/concat/g_concat.h =================================================================== --- sys/geom/concat/g_concat.h +++ sys/geom/concat/g_concat.h @@ -49,25 +49,10 @@ #define G_CONCAT_TYPE_MANUAL 0 #define G_CONCAT_TYPE_AUTOMATIC 1 -#define G_CONCAT_DEBUG(lvl, ...) do { \ - if (g_concat_debug >= (lvl)) { \ - printf("GEOM_CONCAT"); \ - if (g_concat_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_CONCAT_LOGREQ(bp, ...) do { \ - if (g_concat_debug >= 2) { \ - printf("GEOM_CONCAT[2]: "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_CONCAT_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_CONCAT", g_concat_debug, (lvl), NULL, __VA_ARGS__) +#define G_CONCAT_LOGREQ(bp, ...) \ + _GEOM_DEBUG("GEOM_CONCAT", g_concat_debug, 2, (bp), __VA_ARGS__) struct g_concat_disk { struct g_consumer *d_consumer; Index: sys/geom/concat/g_concat.c =================================================================== --- sys/geom/concat/g_concat.c +++ sys/geom/concat/g_concat.c @@ -40,6 +40,7 @@ #include #include #include +#include #include FEATURE(geom_concat, "GEOM concatenation support"); Index: sys/geom/eli/g_eli.h =================================================================== --- sys/geom/eli/g_eli.h +++ sys/geom/eli/g_eli.h @@ -155,28 +155,10 @@ extern u_int g_eli_overwrites; extern u_int g_eli_batch; -#define G_ELI_DEBUG(lvl, ...) do { \ - if (g_eli_debug >= (lvl)) { \ - printf("GEOM_ELI"); \ - if (g_eli_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_ELI_LOGREQ(lvl, bp, ...) do { \ - if (g_eli_debug >= (lvl)) { \ - printf("GEOM_ELI"); \ - if (g_eli_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_ELI_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_ELI", g_eli_debug, (lvl), NULL, __VA_ARGS__) +#define G_ELI_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_ELI", g_eli_debug, (lvl), (bp), __VA_ARGS__) struct g_eli_worker { struct g_eli_softc *w_softc; Index: sys/geom/eli/g_eli.c =================================================================== --- sys/geom/eli/g_eli.c +++ sys/geom/eli/g_eli.c @@ -52,6 +52,7 @@ #include #include +#include #include #include Index: sys/geom/eli/g_eli_ctl.c =================================================================== --- sys/geom/eli/g_eli_ctl.c +++ sys/geom/eli/g_eli_ctl.c @@ -46,6 +46,7 @@ #include #include +#include #include Index: sys/geom/eli/g_eli_integrity.c =================================================================== --- sys/geom/eli/g_eli_integrity.c +++ sys/geom/eli/g_eli_integrity.c @@ -48,6 +48,7 @@ #include #include +#include #include #include Index: sys/geom/eli/g_eli_privacy.c =================================================================== --- sys/geom/eli/g_eli_privacy.c +++ sys/geom/eli/g_eli_privacy.c @@ -48,6 +48,7 @@ #include #include +#include #include #include Index: sys/geom/gate/g_gate.h =================================================================== --- sys/geom/gate/g_gate.h +++ sys/geom/gate/g_gate.h @@ -103,28 +103,10 @@ char sc_info[G_GATE_INFOSIZE]; /* P: (read-only) */ }; -#define G_GATE_DEBUG(lvl, ...) do { \ - if (g_gate_debug >= (lvl)) { \ - printf("GEOM_GATE"); \ - if (g_gate_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_GATE_LOGREQ(lvl, bp, ...) do { \ - if (g_gate_debug >= (lvl)) { \ - printf("GEOM_GATE"); \ - if (g_gate_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_GATE_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_GATE", g_gate_debug, (lvl), NULL, __VA_ARGS__) +#define G_GATE_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_GATE", g_gate_debug, (lvl), (bp), __VA_ARGS__) #endif /* !_KERNEL */ struct g_gate_ctl_create { Index: sys/geom/gate/g_gate.c =================================================================== --- sys/geom/gate/g_gate.c +++ sys/geom/gate/g_gate.c @@ -54,6 +54,7 @@ #include #include +#include #include FEATURE(geom_gate, "GEOM Gate module"); Index: sys/geom/geom.h =================================================================== --- sys/geom/geom.h +++ sys/geom/geom.h @@ -345,7 +345,8 @@ void * g_read_data(struct g_consumer *cp, off_t offset, off_t length, int *error); int g_write_data(struct g_consumer *cp, off_t offset, void *ptr, off_t length); int g_delete_data(struct g_consumer *cp, off_t offset, off_t length); -void g_print_bio(struct bio *bp); +void g_format_bio(struct sbuf *, const struct bio *bp); +void g_print_bio(const char *prefix, const struct bio *bp, const char *fmtsuffix, ...) __printflike(3, 4); int g_use_g_read_data(void *, off_t, void **, int); int g_use_g_write_data(void *, off_t, void *, int); Index: sys/geom/geom_dbg.h =================================================================== --- /dev/null +++ sys/geom/geom_dbg.h @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Conrad Meyer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#pragma once + +#ifdef _KERNEL + +#define _GEOM_DEBUG(classname, ctrlvar, loglvl, biop, formatstr, ...) \ +do { \ + const int __control = (ctrlvar); \ + const int __level = (loglvl); \ + \ + if (__control < __level) \ + break; \ + \ + g_dbg_printf((classname), (__control > 0) ? __level : -1, \ + (biop), ": " formatstr, ## __VA_ARGS__); \ +} while (0) + +void g_dbg_printf(const char *classname, int lvl, struct bio *bp, + const char *format, ...) __printflike(4, 5); + +#endif /* _KERNEL */ Index: sys/geom/geom_io.c =================================================================== --- sys/geom/geom_io.c +++ sys/geom/geom_io.c @@ -49,9 +49,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -1029,7 +1031,36 @@ } void -g_print_bio(struct bio *bp) +g_print_bio(const char *prefix, const struct bio *bp, const char *fmtsuffix, + ...) +{ +#ifndef PRINTF_BUFR_SIZE +#define PRINTF_BUFR_SIZE 64 +#endif + char bufr[PRINTF_BUFR_SIZE]; + struct sbuf sb, *sbp __unused; + va_list ap; + + sbp = sbuf_new(&sb, bufr, sizeof(bufr), SBUF_FIXEDLEN); + KASSERT(sbp != NULL, ("sbuf_new misused?")); + + sbuf_set_drain(&sb, sbuf_printf_drain, NULL); + + sbuf_cat(&sb, prefix); + g_format_bio(&sb, bp); + + va_start(ap, fmtsuffix); + sbuf_vprintf(&sb, fmtsuffix, ap); + va_end(ap); + + sbuf_nl_terminate(&sb); + + sbuf_finish(&sb); + sbuf_delete(&sb); +} + +void +g_format_bio(struct sbuf *sb, const struct bio *bp) { const char *pname, *cmd = NULL; @@ -1041,11 +1072,12 @@ switch (bp->bio_cmd) { case BIO_GETATTR: cmd = "GETATTR"; - printf("%s[%s(attr=%s)]", pname, cmd, bp->bio_attribute); + sbuf_printf(sb, "%s[%s(attr=%s)]", pname, cmd, + bp->bio_attribute); return; case BIO_FLUSH: cmd = "FLUSH"; - printf("%s[%s]", pname, cmd); + sbuf_printf(sb, "%s[%s]", pname, cmd); return; case BIO_ZONE: { char *subcmd = NULL; @@ -1073,7 +1105,7 @@ subcmd = "UNKNOWN"; break; } - printf("%s[%s,%s]", pname, cmd, subcmd); + sbuf_printf(sb, "%s[%s,%s]", pname, cmd, subcmd); return; } case BIO_READ: @@ -1087,9 +1119,9 @@ break; default: cmd = "UNKNOWN"; - printf("%s[%s()]", pname, cmd); + sbuf_printf(sb, "%s[%s()]", pname, cmd); return; } - printf("%s[%s(offset=%jd, length=%jd)]", pname, cmd, + sbuf_printf(sb, "%s[%s(offset=%jd, length=%jd)]", pname, cmd, (intmax_t)bp->bio_offset, (intmax_t)bp->bio_length); } Index: sys/geom/geom_subr.c =================================================================== --- sys/geom/geom_subr.c +++ sys/geom/geom_subr.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -77,6 +78,44 @@ int post; }; +void +g_dbg_printf(const char *classname, int lvl, struct bio *bp, + const char *format, + ...) +{ +#ifndef PRINTF_BUFR_SIZE +#define PRINTF_BUFR_SIZE 64 +#endif + char bufr[PRINTF_BUFR_SIZE]; + struct sbuf sb, *sbp __unused; + va_list ap; + + sbp = sbuf_new(&sb, bufr, sizeof(bufr), SBUF_FIXEDLEN); + KASSERT(sbp != NULL, ("sbuf_new misused?")); + + sbuf_set_drain(&sb, sbuf_printf_drain, NULL); + + sbuf_cat(&sb, classname); + if (lvl >= 0) + sbuf_printf(&sb, "[%d]", lvl); + + va_start(ap, format); + sbuf_vprintf(&sb, format, ap); + va_end(ap); + + if (bp != NULL) { + sbuf_putc(&sb, ' '); + g_format_bio(&sb, bp); + } + + /* Terminate the debug line with a single '\n'. */ + sbuf_nl_terminate(&sb); + + /* Flush line to printf. */ + sbuf_finish(&sb); + sbuf_delete(&sb); +} + /* * This event offers a new class a chance to taste all preexisting providers. */ Index: sys/geom/geom_vfs.c =================================================================== --- sys/geom/geom_vfs.c +++ sys/geom/geom_vfs.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -138,11 +139,9 @@ cp = bip->bio_from; sc = cp->geom->softc; - if (bip->bio_error) { - printf("g_vfs_done():"); - g_print_bio(bip); - printf("error = %d\n", bip->bio_error); - } + if (bip->bio_error) + g_print_bio("g_vfs_done():", bip, "error = %d", + bip->bio_error); bp->b_error = bip->bio_error; bp->b_ioflags = bip->bio_flags; if (bip->bio_error) Index: sys/geom/journal/g_journal.h =================================================================== --- sys/geom/journal/g_journal.h +++ sys/geom/journal/g_journal.h @@ -49,28 +49,10 @@ #ifdef _KERNEL extern int g_journal_debug; -#define GJ_DEBUG(lvl, ...) do { \ - if (g_journal_debug >= (lvl)) { \ - printf("GEOM_JOURNAL"); \ - if (g_journal_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define GJ_LOGREQ(lvl, bp, ...) do { \ - if (g_journal_debug >= (lvl)) { \ - printf("GEOM_JOURNAL"); \ - if (g_journal_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define GJ_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_JOURNAL", g_journal_debug, (lvl), NULL, __VA_ARGS__) +#define GJ_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_JOURNAL", g_journal_debug, (lvl), (bp), __VA_ARGS__) #define JEMPTY(sc) ((sc)->sc_journal_offset - \ (sc)->sc_jprovider->sectorsize == \ Index: sys/geom/journal/g_journal.c =================================================================== --- sys/geom/journal/g_journal.c +++ sys/geom/journal/g_journal.c @@ -54,6 +54,7 @@ #include #include #include +#include #include Index: sys/geom/journal/g_journal_ufs.c =================================================================== --- sys/geom/journal/g_journal_ufs.c +++ sys/geom/journal/g_journal_ufs.c @@ -44,6 +44,7 @@ #include #include +#include #include static int Index: sys/geom/label/g_label.h =================================================================== --- sys/geom/label/g_label.h +++ sys/geom/label/g_label.h @@ -50,16 +50,8 @@ #ifdef _KERNEL extern u_int g_label_debug; -#define G_LABEL_DEBUG(lvl, ...) do { \ - if (g_label_debug >= (lvl)) { \ - printf("GEOM_LABEL"); \ - if (g_label_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) +#define G_LABEL_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_LABEL", g_label_debug, (lvl), NULL, __VA_ARGS__) SYSCTL_DECL(_kern_geom_label); Index: sys/geom/label/g_label.c =================================================================== --- sys/geom/label/g_label.c +++ sys/geom/label/g_label.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include Index: sys/geom/label/g_label_ext2fs.c =================================================================== --- sys/geom/label/g_label_ext2fs.c +++ sys/geom/label/g_label_ext2fs.c @@ -35,6 +35,7 @@ #include #include +#include #include #define EXT2FS_SB_OFFSET 1024 Index: sys/geom/label/g_label_iso9660.c =================================================================== --- sys/geom/label/g_label_iso9660.c +++ sys/geom/label/g_label_iso9660.c @@ -35,6 +35,7 @@ #include #include +#include #include #define G_LABEL_ISO9660_DIR "iso9660" Index: sys/geom/label/g_label_msdosfs.c =================================================================== --- sys/geom/label/g_label_msdosfs.c +++ sys/geom/label/g_label_msdosfs.c @@ -36,6 +36,7 @@ #include #include +#include #include #include Index: sys/geom/label/g_label_reiserfs.c =================================================================== --- sys/geom/label/g_label_reiserfs.c +++ sys/geom/label/g_label_reiserfs.c @@ -35,6 +35,7 @@ #include #include +#include #include #define REISERFS_NEW_DISK_OFFSET 64 * 1024 Index: sys/geom/label/g_label_ufs.c =================================================================== --- sys/geom/label/g_label_ufs.c +++ sys/geom/label/g_label_ufs.c @@ -42,6 +42,7 @@ #include #include +#include #include #define G_LABEL_UFS_VOLUME_DIR "ufs" Index: sys/geom/linux_lvm/g_linux_lvm.h =================================================================== --- sys/geom/linux_lvm/g_linux_lvm.h +++ sys/geom/linux_lvm/g_linux_lvm.h @@ -28,16 +28,8 @@ * $FreeBSD$ */ -#define G_LLVM_DEBUG(lvl, ...) do { \ - if (g_llvm_debug >= (lvl)) { \ - printf("GEOM_LINUX_LVM"); \ - if (g_llvm_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) +#define G_LLVM_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_LINUX_LVM", g_llvm_debug, (lvl), NULL, __VA_ARGS__) #define G_LLVM_CLASS_NAME "LINUX_LVM" #define G_LLVM_NAMELEN 128 Index: sys/geom/linux_lvm/g_linux_lvm.c =================================================================== --- sys/geom/linux_lvm/g_linux_lvm.c +++ sys/geom/linux_lvm/g_linux_lvm.c @@ -40,6 +40,7 @@ #include #include +#include #include #include Index: sys/geom/mirror/g_mirror.h =================================================================== --- sys/geom/mirror/g_mirror.h +++ sys/geom/mirror/g_mirror.h @@ -86,28 +86,10 @@ extern int g_mirror_debug; -#define G_MIRROR_DEBUG(lvl, ...) do { \ - if (g_mirror_debug >= (lvl)) { \ - printf("GEOM_MIRROR"); \ - if (g_mirror_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_MIRROR_LOGREQ(lvl, bp, ...) do { \ - if (g_mirror_debug >= (lvl)) { \ - printf("GEOM_MIRROR"); \ - if (g_mirror_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_MIRROR_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_MIRROR", g_mirror_debug, (lvl), NULL, __VA_ARGS__) +#define G_MIRROR_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_MIRROR", g_mirror_debug, (lvl), (bp), __VA_ARGS__) #define G_MIRROR_BIO_FLAG_REGULAR 0x01 #define G_MIRROR_BIO_FLAG_SYNC 0x02 Index: sys/geom/mirror/g_mirror.c =================================================================== --- sys/geom/mirror/g_mirror.c +++ sys/geom/mirror/g_mirror.c @@ -47,6 +47,7 @@ #include #include +#include #include FEATURE(geom_mirror, "GEOM mirroring support"); Index: sys/geom/mirror/g_mirror_ctl.c =================================================================== --- sys/geom/mirror/g_mirror_ctl.c +++ sys/geom/mirror/g_mirror_ctl.c @@ -40,6 +40,7 @@ #include #include +#include #include #include Index: sys/geom/mountver/g_mountver.h =================================================================== --- sys/geom/mountver/g_mountver.h +++ sys/geom/mountver/g_mountver.h @@ -38,25 +38,10 @@ #ifdef _KERNEL -#define G_MOUNTVER_DEBUG(lvl, ...) do { \ - if (g_mountver_debug >= (lvl)) { \ - printf("GEOM_MOUNTVER"); \ - if (g_mountver_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_MOUNTVER_LOGREQ(bp, ...) do { \ - if (g_mountver_debug >= 2) { \ - printf("GEOM_MOUNTVER[2]: "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_MOUNTVER_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_MOUNTVER", g_mountver_debug, (lvl), NULL, __VA_ARGS__) +#define G_MOUNTVER_LOGREQ(bp, ...) \ + _GEOM_DEBUG("GEOM_MOUNTVER", g_mountver_debug, 2, (bp), __VA_ARGS__) struct g_mountver_softc { TAILQ_HEAD(, bio) sc_queue; Index: sys/geom/mountver/g_mountver.c =================================================================== --- sys/geom/mountver/g_mountver.c +++ sys/geom/mountver/g_mountver.c @@ -44,6 +44,7 @@ #include #include #include +#include #include Index: sys/geom/nop/g_nop.h =================================================================== --- sys/geom/nop/g_nop.h +++ sys/geom/nop/g_nop.h @@ -41,26 +41,11 @@ #define G_NOP_PHYSPATH_PASSTHROUGH "\255" #ifdef _KERNEL -#define G_NOP_DEBUG(lvl, ...) do { \ - if (g_nop_debug >= (lvl)) { \ - printf("GEOM_NOP"); \ - if (g_nop_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) +#define G_NOP_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_NOP", g_nop_debug, (lvl), NULL, __VA_ARGS__) +#define G_NOP_LOGREQLVL(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_NOP", g_nop_debug, (lvl), (bp), __VA_ARGS__) #define G_NOP_LOGREQ(bp, ...) G_NOP_LOGREQLVL(2, bp, __VA_ARGS__) -#define G_NOP_LOGREQLVL(lvl, bp, ...) do { \ - if (g_nop_debug >= (lvl)) { \ - printf("GEOM_NOP[%d]: ", (lvl)); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) struct g_nop_softc { int sc_error; Index: sys/geom/nop/g_nop.c =================================================================== --- sys/geom/nop/g_nop.c +++ sys/geom/nop/g_nop.c @@ -40,6 +40,7 @@ #include #include #include +#include #include Index: sys/geom/raid/g_raid.h =================================================================== --- sys/geom/raid/g_raid.h +++ sys/geom/raid/g_raid.h @@ -61,39 +61,13 @@ extern u_int g_raid_start_timeout; extern struct g_class g_raid_class; -#define G_RAID_DEBUG(lvl, fmt, ...) do { \ - if (g_raid_debug >= (lvl)) { \ - if (g_raid_debug > 0) { \ - printf("GEOM_RAID[%u]: " fmt "\n", \ - lvl, ## __VA_ARGS__); \ - } else { \ - printf("GEOM_RAID: " fmt "\n", \ - ## __VA_ARGS__); \ - } \ - } \ -} while (0) -#define G_RAID_DEBUG1(lvl, sc, fmt, ...) do { \ - if (g_raid_debug >= (lvl)) { \ - if (g_raid_debug > 0) { \ - printf("GEOM_RAID[%u]: %s: " fmt "\n", \ - lvl, (sc)->sc_name, ## __VA_ARGS__); \ - } else { \ - printf("GEOM_RAID: %s: " fmt "\n", \ - (sc)->sc_name, ## __VA_ARGS__); \ - } \ - } \ -} while (0) -#define G_RAID_LOGREQ(lvl, bp, fmt, ...) do { \ - if (g_raid_debug >= (lvl)) { \ - if (g_raid_debug > 0) { \ - printf("GEOM_RAID[%u]: " fmt " ", \ - lvl, ## __VA_ARGS__); \ - } else \ - printf("GEOM_RAID: " fmt " ", ## __VA_ARGS__); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_RAID_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), NULL, __VA_ARGS__) +#define G_RAID_DEBUG1(lvl, sc, fmt, ...) \ + _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), NULL, "%s: " fmt, \ + (sc)->sc_name, ## __VA_ARGS__) +#define G_RAID_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), (bp), __VA_ARGS__) /* * Flags we use to distinguish I/O initiated by the TR layer to maintain Index: sys/geom/raid/g_raid.c =================================================================== --- sys/geom/raid/g_raid.c +++ sys/geom/raid/g_raid.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include Index: sys/geom/raid/md_ddf.c =================================================================== --- sys/geom/raid/md_ddf.c +++ sys/geom/raid/md_ddf.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "geom/raid/md_ddf.h" #include "g_raid_md_if.h" Index: sys/geom/raid/md_intel.c =================================================================== --- sys/geom/raid/md_intel.c +++ sys/geom/raid/md_intel.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_md_if.h" Index: sys/geom/raid/md_jmicron.c =================================================================== --- sys/geom/raid/md_jmicron.c +++ sys/geom/raid/md_jmicron.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_md_if.h" Index: sys/geom/raid/md_nvidia.c =================================================================== --- sys/geom/raid/md_nvidia.c +++ sys/geom/raid/md_nvidia.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_md_if.h" Index: sys/geom/raid/md_promise.c =================================================================== --- sys/geom/raid/md_promise.c +++ sys/geom/raid/md_promise.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_md_if.h" Index: sys/geom/raid/md_sii.c =================================================================== --- sys/geom/raid/md_sii.c +++ sys/geom/raid/md_sii.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_md_if.h" Index: sys/geom/raid/tr_concat.c =================================================================== --- sys/geom/raid/tr_concat.c +++ sys/geom/raid/tr_concat.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_tr_if.h" Index: sys/geom/raid/tr_raid0.c =================================================================== --- sys/geom/raid/tr_raid0.c +++ sys/geom/raid/tr_raid0.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_tr_if.h" Index: sys/geom/raid/tr_raid1.c =================================================================== --- sys/geom/raid/tr_raid1.c +++ sys/geom/raid/tr_raid1.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_tr_if.h" Index: sys/geom/raid/tr_raid1e.c =================================================================== --- sys/geom/raid/tr_raid1e.c +++ sys/geom/raid/tr_raid1e.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "geom/raid/g_raid.h" #include "g_raid_tr_if.h" Index: sys/geom/raid3/g_raid3.h =================================================================== --- sys/geom/raid3/g_raid3.h +++ sys/geom/raid3/g_raid3.h @@ -69,28 +69,10 @@ #ifdef _KERNEL extern u_int g_raid3_debug; -#define G_RAID3_DEBUG(lvl, ...) do { \ - if (g_raid3_debug >= (lvl)) { \ - printf("GEOM_RAID3"); \ - if (g_raid3_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_RAID3_LOGREQ(lvl, bp, ...) do { \ - if (g_raid3_debug >= (lvl)) { \ - printf("GEOM_RAID3"); \ - if (g_raid3_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_RAID3_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_RAID3", g_raid3_debug, (lvl), NULL, __VA_ARGS__) +#define G_RAID3_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_RAID3", g_raid3_debug, (lvl), (bp), __VA_ARGS__) #define G_RAID3_BIO_CFLAG_REGULAR 0x01 #define G_RAID3_BIO_CFLAG_SYNC 0x02 Index: sys/geom/raid3/g_raid3.c =================================================================== --- sys/geom/raid3/g_raid3.c +++ sys/geom/raid3/g_raid3.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include Index: sys/geom/sched/g_sched.h =================================================================== --- sys/geom/sched/g_sched.h +++ sys/geom/sched/g_sched.h @@ -44,26 +44,10 @@ #define G_SCHED_SUFFIX ".sched." #ifdef _KERNEL -#define G_SCHED_DEBUG(lvl, ...) do { \ - if (me.gs_debug >= (lvl)) { \ - printf("GEOM_SCHED"); \ - if (me.gs_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) - -#define G_SCHED_LOGREQ(bp, ...) do { \ - if (me.gs_debug >= 2) { \ - printf("GEOM_SCHED[2]: "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_SCHED_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_SCHED", me.gs_debug, (lvl), NULL, __VA_ARGS__) +#define G_SCHED_LOGREQ(bp, ...) \ + _GEOM_DEBUG("GEOM_SCHED", me.gs_debug, 2, (bp), __VA_ARGS__) LIST_HEAD(g_hash, g_sched_class); Index: sys/geom/sched/g_sched.c =================================================================== --- sys/geom/sched/g_sched.c +++ sys/geom/sched/g_sched.c @@ -118,6 +118,7 @@ #include #include /* we access curthread */ #include +#include #include "gs_scheduler.h" #include "g_sched.h" /* geom hooks */ Index: sys/geom/shsec/g_shsec.h =================================================================== --- sys/geom/shsec/g_shsec.h +++ sys/geom/shsec/g_shsec.h @@ -46,28 +46,10 @@ #ifdef _KERNEL #define G_SHSEC_BFLAG_FIRST 0x1 -#define G_SHSEC_DEBUG(lvl, ...) do { \ - if (g_shsec_debug >= (lvl)) { \ - printf("GEOM_SHSEC"); \ - if (g_shsec_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_SHSEC_LOGREQ(lvl, bp, ...) do { \ - if (g_shsec_debug >= (lvl)) { \ - printf("GEOM_SHSEC"); \ - if (g_shsec_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_SHSEC_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_SHSEC", g_shsec_debug, (lvl), NULL, __VA_ARGS__) +#define G_SHSEC_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_SHSEC", g_shsec_debug, (lvl), (bp), __VA_ARGS__) struct g_shsec_softc { u_int sc_type; /* provider type */ Index: sys/geom/shsec/g_shsec.c =================================================================== --- sys/geom/shsec/g_shsec.c +++ sys/geom/shsec/g_shsec.c @@ -41,6 +41,7 @@ #include #include #include +#include #include FEATURE(geom_shsec, "GEOM shared secret device support"); Index: sys/geom/stripe/g_stripe.h =================================================================== --- sys/geom/stripe/g_stripe.h +++ sys/geom/stripe/g_stripe.h @@ -49,25 +49,10 @@ #define G_STRIPE_TYPE_MANUAL 0 #define G_STRIPE_TYPE_AUTOMATIC 1 -#define G_STRIPE_DEBUG(lvl, ...) do { \ - if (g_stripe_debug >= (lvl)) { \ - printf("GEOM_STRIPE"); \ - if (g_stripe_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) -#define G_STRIPE_LOGREQ(bp, ...) do { \ - if (g_stripe_debug >= 2) { \ - printf("GEOM_STRIPE[2]: "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_STRIPE_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, (lvl), NULL, __VA_ARGS__) +#define G_STRIPE_LOGREQ(bp, ...) \ + _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, 2, (bp), __VA_ARGS__) struct g_stripe_softc { u_int sc_type; /* provider type */ Index: sys/geom/stripe/g_stripe.c =================================================================== --- sys/geom/stripe/g_stripe.c +++ sys/geom/stripe/g_stripe.c @@ -41,6 +41,7 @@ #include #include #include +#include #include FEATURE(geom_stripe, "GEOM striping support"); Index: sys/geom/vinum/geom_vinum.h =================================================================== --- sys/geom/vinum/geom_vinum.h +++ sys/geom/vinum/geom_vinum.h @@ -157,28 +157,9 @@ extern u_int g_vinum_debug; -#define G_VINUM_DEBUG(lvl, ...) do { \ - if (g_vinum_debug >= (lvl)) { \ - printf("GEOM_VINUM"); \ - if (g_vinum_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) - -#define G_VINUM_LOGREQ(lvl, bp, ...) do { \ - if (g_vinum_debug >= (lvl)) { \ - printf("GEOM_VINUM"); \ - if (g_vinum_debug > 0) \ - printf("[%u]", lvl); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define G_VINUM_DEBUG(lvl, ...) \ + _GEOM_DEBUG("GEOM_VINUM", g_vinum_debug, (lvl), NULL, __VA_ARGS__) +#define G_VINUM_LOGREQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_VINUM", g_vinum_debug, (lvl), (bp), __VA_ARGS__) #endif /* !_GEOM_VINUM_H_ */ Index: sys/geom/vinum/geom_vinum.c =================================================================== --- sys/geom/vinum/geom_vinum.c +++ sys/geom/vinum/geom_vinum.c @@ -44,6 +44,7 @@ #include #include +#include #include #include #include Index: sys/geom/vinum/geom_vinum_create.c =================================================================== --- sys/geom/vinum/geom_vinum_create.c +++ sys/geom/vinum/geom_vinum_create.c @@ -39,6 +39,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_drive.c =================================================================== --- sys/geom/vinum/geom_vinum_drive.c +++ sys/geom/vinum/geom_vinum_drive.c @@ -36,6 +36,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_events.c =================================================================== --- sys/geom/vinum/geom_vinum_events.c +++ sys/geom/vinum/geom_vinum_events.c @@ -38,6 +38,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_init.c =================================================================== --- sys/geom/vinum/geom_vinum_init.c +++ sys/geom/vinum/geom_vinum_init.c @@ -35,6 +35,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_move.c =================================================================== --- sys/geom/vinum/geom_vinum_move.c +++ sys/geom/vinum/geom_vinum_move.c @@ -38,6 +38,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_plex.c =================================================================== --- sys/geom/vinum/geom_vinum_plex.c +++ sys/geom/vinum/geom_vinum_plex.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include Index: sys/geom/vinum/geom_vinum_raid5.c =================================================================== --- sys/geom/vinum/geom_vinum_raid5.c +++ sys/geom/vinum/geom_vinum_raid5.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include Index: sys/geom/vinum/geom_vinum_rename.c =================================================================== --- sys/geom/vinum/geom_vinum_rename.c +++ sys/geom/vinum/geom_vinum_rename.c @@ -39,6 +39,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_rm.c =================================================================== --- sys/geom/vinum/geom_vinum_rm.c +++ sys/geom/vinum/geom_vinum_rm.c @@ -35,6 +35,7 @@ #include #include +#include #include #include Index: sys/geom/vinum/geom_vinum_state.c =================================================================== --- sys/geom/vinum/geom_vinum_state.c +++ sys/geom/vinum/geom_vinum_state.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include Index: sys/geom/vinum/geom_vinum_subr.c =================================================================== --- sys/geom/vinum/geom_vinum_subr.c +++ sys/geom/vinum/geom_vinum_subr.c @@ -50,6 +50,7 @@ #include #include +#include #include #include #include Index: sys/geom/virstor/g_virstor.h =================================================================== --- sys/geom/virstor/g_virstor.h +++ sys/geom/virstor/g_virstor.h @@ -47,30 +47,12 @@ #ifdef _KERNEL -#define LOG_MSG(lvl, ...) do { \ - if (g_virstor_debug >= (lvl)) { \ - printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ - if ((lvl) > 0) \ - printf("[%u]", (lvl)); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } \ -} while (0) +#define LOG_MSG(lvl, ...) \ + _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), NULL, __VA_ARGS__) #define LOG_MESSAGE LOG_MSG -#define LOG_REQ(lvl, bp, ...) do { \ - if (g_virstor_debug >= (lvl)) { \ - printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ - if ((lvl) > 0) \ - printf("[%u]", (lvl)); \ - printf(": "); \ - printf(__VA_ARGS__); \ - printf(" "); \ - g_print_bio(bp); \ - printf("\n"); \ - } \ -} while (0) +#define LOG_REQ(lvl, bp, ...) \ + _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), (bp), __VA_ARGS__) #define LOG_REQUEST LOG_REQ /* "critical" system announcements (e.g. "geom is up") */ Index: sys/geom/virstor/g_virstor.c =================================================================== --- sys/geom/virstor/g_virstor.c +++ sys/geom/virstor/g_virstor.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include