summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2012-01-20 12:38:21 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2012-01-20 12:38:21 +0000
commit72bfeca4c52a61571ce54cc156e5d31f5c4ea230 (patch)
tree1ec222dcd298f6aa3dd5ee1c346eb81492840829
parent2eb255caf18bb2cfcba19420aa076c378c8d9e5f (diff)
Implement a status message interface for bio(4) capable devices.
-rw-r--r--sys/dev/bio.c63
-rw-r--r--sys/dev/biovar.h46
2 files changed, 100 insertions, 9 deletions
diff --git a/sys/dev/bio.c b/sys/dev/bio.c
index 9ce7a291470..9fa89ddfd7c 100644
--- a/sys/dev/bio.c
+++ b/sys/dev/bio.c
@@ -1,7 +1,8 @@
-/* $OpenBSD: bio.c,v 1.13 2012/01/17 15:15:57 jsing Exp $ */
+/* $OpenBSD: bio.c,v 1.14 2012/01/20 12:38:20 jsing Exp $ */
/*
* Copyright (c) 2002 Niklas Hallqvist. All rights reserved.
+ * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -165,3 +166,63 @@ bio_delegate_ioctl(struct bio_mapping *bm, u_long cmd, caddr_t addr)
{
return (bm->bm_ioctl(bm->bm_dev, cmd, addr));
}
+
+void
+bio_info(struct bio_status *bs, int print, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bio_status(bs, print, BIO_MSG_INFO, fmt, &ap);
+ va_end(ap);
+}
+
+void
+bio_warn(struct bio_status *bs, int print, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bio_status(bs, print, BIO_MSG_WARN, fmt, &ap);
+ va_end(ap);
+}
+
+void
+bio_error(struct bio_status *bs, int print, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ bio_status(bs, print, BIO_MSG_ERROR, fmt, &ap);
+ va_end(ap);
+}
+
+void
+bio_status_init(struct bio_status *bs, struct device *dv)
+{
+ bzero(bs, sizeof(struct bio_status));
+
+ bs->bs_status = BIO_STATUS_UNKNOWN;
+
+ strlcpy(bs->bs_controller, dv->dv_xname, sizeof(bs->bs_controller));
+}
+
+void
+bio_status(struct bio_status *bs, int print, int msg_type, const char *fmt,
+ va_list *ap)
+{
+ int idx;
+
+ if (bs->bs_msg_count >= BIO_MSG_COUNT) {
+ printf("%s: insufficient message buffers\n", bs->bs_controller);
+ return;
+ }
+
+ idx = bs->bs_msg_count++;
+
+ bs->bs_msgs[idx].bm_type = msg_type;
+ vsnprintf(bs->bs_msgs[idx].bm_msg, BIO_MSG_LEN, fmt, *ap);
+
+ if (print)
+ printf("%s: %s\n", bs->bs_controller, bs->bs_msgs[idx].bm_msg);
+}
diff --git a/sys/dev/biovar.h b/sys/dev/biovar.h
index 5d2b2c4c81e..e2e5dfe7670 100644
--- a/sys/dev/biovar.h
+++ b/sys/dev/biovar.h
@@ -1,8 +1,9 @@
-/* $OpenBSD: biovar.h,v 1.41 2012/01/17 15:15:57 jsing Exp $ */
+/* $OpenBSD: biovar.h,v 1.42 2012/01/20 12:38:19 jsing Exp $ */
/*
* Copyright (c) 2002 Niklas Hallqvist. All rights reserved.
* Copyright (c) 2005 Marco Peereboom. All rights reserved.
+ * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,8 +34,30 @@
#include <sys/types.h>
+#define BIO_MSG_COUNT 5
+#define BIO_MSG_LEN 128
+
+struct bio_msg {
+ int bm_type;
+#define BIO_MSG_INFO 1
+#define BIO_MSG_WARN 2
+#define BIO_MSG_ERROR 3
+ char bm_msg[BIO_MSG_LEN];
+};
+
+struct bio_status {
+ char bs_controller[16];
+ int bs_status;
+#define BIO_STATUS_UNKNOWN 0
+#define BIO_STATUS_SUCCESS 1
+#define BIO_STATUS_ERROR 2
+ int bs_msg_count;
+ struct bio_msg bs_msgs[BIO_MSG_COUNT];
+};
+
struct bio {
- void *bio_cookie;
+ void *bio_cookie;
+ struct bio_status bio_status;
};
/* convert name to a cookie */
@@ -44,12 +67,6 @@ struct bio_locate {
char *bl_name;
};
-#ifdef _KERNEL
-int bio_register(struct device *, int (*)(struct device *, u_long,
- caddr_t));
-void bio_unregister(struct device *);
-#endif
-
#define BIOCINQ _IOWR('B', 32, struct bioc_inq)
struct bioc_inq {
struct bio bi_bio;
@@ -236,3 +253,16 @@ struct bioc_installboot {
/* user space defines */
#define BIOC_DEVLIST 0x10000
+
+#ifdef _KERNEL
+int bio_register(struct device *, int (*)(struct device *, u_long,
+ caddr_t));
+void bio_unregister(struct device *);
+
+void bio_status_init(struct bio_status *, struct device *);
+void bio_status(struct bio_status *, int, int, const char *, va_list *);
+
+void bio_info(struct bio_status *, int, const char *, ...);
+void bio_warn(struct bio_status *, int, const char *, ...);
+void bio_error(struct bio_status *, int, const char *, ...);
+#endif