Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / afs_warn.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 /*
11 * afs_warn.c - afs_warn
12 *
13 * Implements: afs_warn, afs_warnuser
14 */
15 #include <afsconfig.h>
16 #include "afs/param.h"
17
18
19 #include "afs/stds.h"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
21
22 #if !defined(UKERNEL)
23
24 #if !defined(AFS_LINUX20_ENV)
25 # include <net/if.h>
26 # if defined(AFS_SUN5_ENV)
27 # include <sys/varargs.h>
28 # elif defined(AFS_FBSD_ENV)
29 # include <machine/stdarg.h>
30 # else
31 # include <stdarg.h>
32 # endif
33 #endif
34 #include <netinet/in.h>
35
36 #ifdef AFS_SGI62_ENV
37 #include "h/hashing.h"
38 #endif
39 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
40 #include <netinet/in_var.h>
41 #endif /* ! AFS_HPUX110_ENV */
42 #endif /* !defined(UKERNEL) */
43
44 #include "afsincludes.h" /* Afs-based standard headers */
45 #include "afs/afs_stats.h" /* afs statistics */
46
47 #if defined(AFS_SUN5_ENV)
48 #include <inet/led.h>
49 #include <inet/common.h>
50 #include <netinet/ip6.h>
51 #include <inet/ip.h>
52 #endif
53
54 #if defined(AFS_AIX_ENV)
55 #include <sys/fp_io.h>
56 #endif
57
58 #if defined(AFS_LINUX26_ENV)
59 # define afs_vprintf(fmt, ap) vprintk(fmt, ap)
60 #elif defined(AFS_SGI_ENV)
61 # define afs_vprintf(fmt, ap) icmn_err(CE_WARN, fmt, ap)
62 #elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV))
63 static_inline void
64 afs_vprintf(const char *fmt, va_list ap)
65 {
66 char buf[256];
67
68 vsnprintf(buf, sizeof(buf), fmt, ap);
69 printf(buf);
70 }
71 #else
72 # define afs_vprintf(fmt, ap) vprintf(fmt, ap)
73 #endif
74
75 #ifdef AFS_AIX_ENV
76 void
77 afs_warn(fmt, a, b, c, d, e, f, g, h, i)
78 char *fmt;
79 void *a, *b, *c, *d, *e, *f, *g, *h, *i;
80 {
81 AFS_STATCNT(afs_warn);
82
83 if (afs_showflags & GAGCONSOLE) {
84 struct file *fd;
85
86 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
87 if (fp_open
88 ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS,
89 &fd) == 0) {
90 char buf[1024];
91 ssize_t len;
92 ssize_t count;
93
94 sprintf(buf, fmt, a, b, c, d, e, f, g, h, i);
95 len = strlen(buf);
96 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
97 fp_close(fd);
98 }
99 }
100 }
101 #else /* AFS_AIX_ENV */
102 static_inline void
103 afs_vwarn(char *fmt, va_list ap)
104 {
105 afs_vprintf(fmt, ap);
106 }
107
108
109 void
110 afs_warn(char *fmt, ...)
111 {
112 AFS_STATCNT(afs_warn);
113
114 if (afs_showflags & GAGCONSOLE) {
115 va_list ap;
116
117 va_start(ap, fmt);
118 afs_vwarn(fmt, ap);
119 va_end(ap);
120 }
121 }
122 #endif /* AFS_AIX_ENV */
123
124
125 #ifdef AFS_AIX_ENV
126 void
127 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i)
128 char *fmt;
129 void *a, *b, *c, *d, *e, *f, *g, *h, *i;
130 {
131 AFS_STATCNT(afs_warnuser);
132 if (afs_showflags & GAGUSER) {
133 # ifdef AFS_GLOBAL_SUNLOCK
134 int haveGlock = ISAFS_GLOCK();
135 /* drop GLOCK for uprintf */
136 if (haveGlock)
137 AFS_GUNLOCK();
138 # endif /* AFS_GLOBAL_SUNLOCK */
139 uprintf(fmt, a, b, c, d, e, f, g, h, i);
140 # ifdef AFS_GLOBAL_SUNLOCK
141 /* regain GLOCK we dropped for uprintf */
142 if (haveGlock)
143 AFS_GLOCK();
144 # endif /* AFS_GLOBAL_SUNLOCK */
145 }
146 }
147 #else /* AFS_AIX_ENV */
148 # ifdef AFS_WARNUSER_MARINER_ENV
149 static void
150 afs_vwarnuser (char *fmt, va_list ap)
151 {
152 # ifdef AFS_GLOBAL_SUNLOCK
153 int haveGlock = ISAFS_GLOCK();
154 /* gain GLOCK for mariner */
155 if (!haveGlock)
156 AFS_GLOCK();
157 # endif /* AFS_GLOBAL_SUNLOCK */
158
159 if (afs_mariner) {
160 char buf[256];
161 va_list aq;
162 va_copy(aq, ap);
163 /* mariner log the warning */
164 snprintf(buf, sizeof(buf), "warn$");
165 vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, aq);
166 afs_MarinerLog(buf, NULL);
167 va_end(aq);
168 }
169 vprintf(fmt, ap);
170
171 # ifdef AFS_GLOBAL_SUNLOCK
172 /* drop GLOCK we got for mariner */
173 if (!haveGlock)
174 AFS_GUNLOCK();
175 # endif /* AFS_GLOBAL_SUNLOCK */
176 }
177 # else /* AFS_WARNUSER_MARINER_ENV */
178 static void
179 afs_vwarnuser (char *fmt, va_list ap)
180 {
181 # ifdef AFS_GLOBAL_SUNLOCK
182 int haveGlock = ISAFS_GLOCK();
183 /* drop GLOCK */
184 if (haveGlock)
185 AFS_GUNLOCK();
186 # endif /* AFS_GLOBAL_SUNLOCK */
187
188 afs_vprintf(fmt, ap);
189
190 # ifdef AFS_GLOBAL_SUNLOCK
191 /* regain GLOCK we dropped */
192 if (haveGlock)
193 AFS_GLOCK();
194 # endif /* AFS_GLOBAL_SUNLOCK */
195 }
196 # endif /* AFS_WARNUSER_MARINER_ENV */
197
198 void
199 afs_warnuser(char *fmt, ...)
200 {
201 AFS_STATCNT(afs_warnuser);
202 if (afs_showflags & GAGUSER) {
203 va_list ap;
204
205 va_start(ap, fmt);
206 afs_vwarnuser(fmt, ap);
207 va_end(ap);
208 }
209 }
210
211 #endif /* AFS_AIX_ENV */
212
213
214 #ifdef AFS_AIX_ENV
215 void
216 afs_warnall(fmt, a, b, c, d, e, f, g, h, i)
217 char *fmt;
218 void *a, *b, *c, *d, *e, *f, *g, *h, *i;
219 {
220 afs_warn(fmt, a, b, c, d, e, f, g, h, i);
221 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i);
222
223 }
224 #else /* AFS_AIX_ENV */
225 /* On Linux both afs_warn and afs_warnuser go to the same
226 * place. Suppress one of them if we're running on Linux.
227 */
228 void
229 afs_warnall(char *fmt, ...)
230 {
231 va_list ap;
232
233 # ifdef AFS_LINUX20_ENV
234 AFS_STATCNT(afs_warn);
235 if ((afs_showflags & GAGCONSOLE) || (afs_showflags & GAGUSER)) {
236 va_start(ap, fmt);
237 afs_vwarn(fmt, ap);
238 va_end(ap);
239 }
240 # else /* AFS_LINUX20_ENV */
241 AFS_STATCNT(afs_warn);
242 if (afs_showflags & GAGCONSOLE) {
243 va_start(ap, fmt);
244 afs_vwarn(fmt, ap);
245 va_end(ap);
246 }
247
248 AFS_STATCNT(afs_warnuser);
249 if (afs_showflags & GAGUSER) {
250 va_start(ap, fmt);
251 afs_vwarnuser(fmt, ap);
252 va_end(ap);
253 }
254 # endif /* AFS_LINUX20_ENV */
255 }
256 #endif /* AFS_AIX_ENV */
257
258 /*
259 * Log a warning when we encounter an ENOSPC error when writing to the cache
260 * partition. We should not normally encounter ENOSPC errors, since we limit
261 * our space usage according to the client config, which should be configured
262 * such that we never run out of space.
263 */
264 void
265 afs_WarnENOSPC(void)
266 {
267 afs_warnuser("afs: Cache partition is FULL! This should not happen, and "
268 "can result in errors in userspace applications. To avoid "
269 "this, reduce the configured cache size so we do not run out "
270 "of space.\n");
271 }