diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2011-07-06 04:57:39 -0400 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2014-02-17 10:45:02 -0500 |
commit | 3b52beffc57d6f1498a29d4edcb1cc2ad81241ec (patch) | |
tree | b958a13b5fbf72e668fc5386050a80a8f5b22290 | |
parent | d01801710265cfb7bd8928ae7c3be4d9d15ceeb0 (diff) |
drbd: Turn drbd_printk() into a polymorphic macro
This allows drbd_alert(), drbd_err(), drbd_warn(), and drbd_info() to work for
a resource, device, or connection so that we don't have to introduce three
separate sets of macros for that.
The drbd_printk() macro itself is pretty ugly, but that problem is limited to
one place in the code. Using drbd_printk() on an object type which it doesn't
understand results in an undefined drbd_printk_with_wrong_object_type symbol.
Signed-off-by: Andreas Gruenbacher <agruen@linbit.com>
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
-rw-r--r-- | drivers/block/drbd/drbd_int.h | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index d393f0bc26fb..06262f5389d0 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h | |||
@@ -100,21 +100,49 @@ extern char usermode_helper[]; | |||
100 | struct drbd_device; | 100 | struct drbd_device; |
101 | struct drbd_connection; | 101 | struct drbd_connection; |
102 | 102 | ||
103 | #define drbd_printk(level, device, fmt, args...) \ | 103 | #define __drbd_printk_device(level, device, fmt, args...) \ |
104 | dev_printk(level, disk_to_dev(device->vdisk), fmt, ## args) | 104 | dev_printk(level, disk_to_dev((device)->vdisk), fmt, ## args) |
105 | 105 | #define __drbd_printk_peer_device(level, peer_device, fmt, args...) \ | |
106 | #define drbd_dbg(device, fmt, args...) \ | 106 | dev_printk(level, disk_to_dev((peer_device)->device->vdisk), fmt, ## args) |
107 | drbd_printk(KERN_DEBUG, device, fmt, ## args) | 107 | #define __drbd_printk_resource(level, resource, fmt, args...) \ |
108 | #define drbd_alert(device, fmt, args...) \ | 108 | printk(level "drbd %s: " fmt, (resource)->name, ## args) |
109 | drbd_printk(KERN_ALERT, device, fmt, ## args) | 109 | #define __drbd_printk_connection(level, connection, fmt, args...) \ |
110 | #define drbd_err(device, fmt, args...) \ | 110 | printk(level "drbd %s: " fmt, (connection)->resource->name, ## args) |
111 | drbd_printk(KERN_ERR, device, fmt, ## args) | 111 | |
112 | #define drbd_warn(device, fmt, args...) \ | 112 | void drbd_printk_with_wrong_object_type(void); |
113 | drbd_printk(KERN_WARNING, device, fmt, ## args) | 113 | |
114 | #define drbd_info(device, fmt, args...) \ | 114 | #define __drbd_printk_if_same_type(obj, type, func, level, fmt, args...) \ |
115 | drbd_printk(KERN_INFO, device, fmt, ## args) | 115 | (__builtin_types_compatible_p(typeof(obj), type) || \ |
116 | #define drbd_emerg(device, fmt, args...) \ | 116 | __builtin_types_compatible_p(typeof(obj), const type)), \ |
117 | drbd_printk(KERN_EMERG, device, fmt, ## args) | 117 | func(level, (const type)(obj), fmt, ## args) |
118 | |||
119 | #define drbd_printk(level, obj, fmt, args...) \ | ||
120 | __builtin_choose_expr( \ | ||
121 | __drbd_printk_if_same_type(obj, struct drbd_device *, \ | ||
122 | __drbd_printk_device, level, fmt, ## args), \ | ||
123 | __builtin_choose_expr( \ | ||
124 | __drbd_printk_if_same_type(obj, struct drbd_resource *, \ | ||
125 | __drbd_printk_resource, level, fmt, ## args), \ | ||
126 | __builtin_choose_expr( \ | ||
127 | __drbd_printk_if_same_type(obj, struct drbd_connection *, \ | ||
128 | __drbd_printk_connection, level, fmt, ## args), \ | ||
129 | __builtin_choose_expr( \ | ||
130 | __drbd_printk_if_same_type(obj, struct drbd_peer_device *, \ | ||
131 | __drbd_printk_peer_device, level, fmt, ## args), \ | ||
132 | drbd_printk_with_wrong_object_type())))) | ||
133 | |||
134 | #define drbd_dbg(obj, fmt, args...) \ | ||
135 | drbd_printk(KERN_DEBUG, obj, fmt, ## args) | ||
136 | #define drbd_alert(obj, fmt, args...) \ | ||
137 | drbd_printk(KERN_ALERT, obj, fmt, ## args) | ||
138 | #define drbd_err(obj, fmt, args...) \ | ||
139 | drbd_printk(KERN_ERR, obj, fmt, ## args) | ||
140 | #define drbd_warn(obj, fmt, args...) \ | ||
141 | drbd_printk(KERN_WARNING, obj, fmt, ## args) | ||
142 | #define drbd_info(obj, fmt, args...) \ | ||
143 | drbd_printk(KERN_INFO, obj, fmt, ## args) | ||
144 | #define drbd_emerg(obj, fmt, args...) \ | ||
145 | drbd_printk(KERN_EMERG, obj, fmt, ## args) | ||
118 | 146 | ||
119 | #define dynamic_drbd_dbg(device, fmt, args...) \ | 147 | #define dynamic_drbd_dbg(device, fmt, args...) \ |
120 | dynamic_dev_dbg(disk_to_dev(device->vdisk), fmt, ## args) | 148 | dynamic_dev_dbg(disk_to_dev(device->vdisk), fmt, ## args) |