2 * error.c -- Common error handling functions
4 * Copyright (C) 2007 Oracle. All rights reserved.
5 * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 021110-1307, USA.
23 * + Proper support for internationalization
31 #include <sys/types.h>
44 #ifdef HAVE_RPCSVC_NFS_PROT_H
45 #include <rpcsvc/nfs_prot.h>
47 #include <linux/nfs.h>
48 #define nfsstat nfs_stat
51 extern char *progname;
53 static char errbuf[BUFSIZ];
54 static char *erreob = &errbuf[BUFSIZ];
56 /* Convert RPC errors into strings */
57 static int rpc_strerror(int spos)
59 int cf_stat = rpc_createerr.cf_stat;
60 int pos = 0, cf_errno = rpc_createerr.cf_error.re_errno;
61 char *ptr, *estr = clnt_sperrno(cf_stat);
65 if ((ptr = index(estr, ':')))
69 if (cf_stat == RPC_SYSTEMERROR)
70 pos = snprintf(tmp, (erreob - tmp),
71 _("System Error: %s"),
74 pos = snprintf(tmp, (erreob - tmp),
75 _("RPC Error:%s"), estr);
81 * rpc_mount_errors - log an RPC error that occurred during a user-space mount
82 * @server: C string containing name of server we are attempting to mount
83 * @will_retry: one indicates mount will retry at some later point
84 * @bg: one indicates this is a background mount
86 * Extracts the error code from the user-space RPC library, and reports it
87 * on stderr (fg mount) or in the system log (bg mount).
89 void rpc_mount_errors(char *server, int will_retry, int bg)
93 static int onlyonce = 0;
97 pos = snprintf(tmp, (erreob - tmp),
98 _("mount to NFS server '%s' failed: "),
101 pos = snprintf(tmp, (erreob - tmp),
102 _("%s: mount to NFS server '%s' failed: "),
106 if (rpc_createerr.cf_stat == RPC_TIMEDOUT) {
108 pos = snprintf(tmp, (erreob - tmp),
109 _("timed out, retrying"));
111 pos = snprintf(tmp, (erreob - tmp),
112 _("timed out, giving up"));
114 pos += rpc_strerror(pos);
118 pos = snprintf(tmp, (erreob - tmp),
121 pos = snprintf(tmp, (erreob - tmp),
128 openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
129 syslog(LOG_ERR, "%s", errbuf);
131 fprintf(stderr, "%s\n", errbuf);
135 * sys_mount_errors - log an error that occurred during a mount system call
136 * @server: C string containing name of server we are attempting to mount
137 * @error: errno value to report
138 * @will_retry: one indicates mount will retry at some later point
139 * @bg: one indicates this is a background mount
141 * Passed an errno value generated by a mount system call, and reports it
142 * on stderr (fg mount) or in the system log (bg mount).
144 void sys_mount_errors(char *server, int error, int will_retry, int bg)
148 static int onlyonce = 0;
152 pos = snprintf(tmp, (erreob - tmp),
153 _("mount to NFS server '%s' failed: "),
156 pos = snprintf(tmp, (erreob - tmp),
157 _("%s: mount to NFS server '%s' failed: "),
161 if (error == ETIMEDOUT) {
163 pos = snprintf(tmp, (erreob - tmp),
164 _("timed out, retrying"));
166 pos = snprintf(tmp, (erreob - tmp),
167 _("timed out, giving up"));
171 pos = snprintf(tmp, (erreob - tmp),
175 pos = snprintf(tmp, (erreob - tmp),
183 openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
184 syslog(LOG_ERR, "%s", errbuf);
186 fprintf(stderr, "%s\n", errbuf);
190 * mount_error - report a foreground mount error
191 * @spec: C string containing the device name being mounted
192 * @mount_point: C string containing the pathname of the local mounted on dir
193 * @error: errno value to report
196 void mount_error(const char *spec, const char *mount_point, int error)
200 nfs_error(_("%s: access denied by server while mounting %s"),
204 nfs_error(_("%s: an incorrect mount option was specified"), progname);
207 nfs_error(_("%s: requested NFS version or transport"
208 " protocol is not supported"),
212 nfs_error(_("%s: mount point %s is not a directory"),
213 progname, mount_point);
216 nfs_error(_("%s: %s is busy or already mounted"),
217 progname, mount_point);
221 nfs_error(_("%s: mounting %s failed, "
222 "reason given by server:\n %s"),
223 progname, spec, strerror(error));
225 nfs_error(_("%s: mount point %s does not exist"),
226 progname, mount_point);
229 rpc_mount_errors((char *)spec, 0, 0);
232 nfs_error(_("%s: mount system call failed"), progname);
235 nfs_error(_("%s: encountered unexpected error condition."),
237 nfs_error(_("%s: please report the error to" PACKAGE_BUGREPORT),
241 nfs_error(_("%s: %s"),
242 progname, strerror(error));
247 * umount_error - report a failed umount request
248 * @err: errno value to report
249 * @dev: C string containing the pathname of the local mounted on dir
252 void umount_error(int err, const char *dev)
256 nfs_error(_("%s: %s: invalid block device"),
260 nfs_error(_("%s: %s: not mounted"),
264 nfs_error(_("%s: %s: can't write superblock"),
268 nfs_error(_("%s: %s: device is busy"),
272 nfs_error(_("%s: %s: not found"),
276 nfs_error(_("%s: %s: must be superuser to umount"),
280 nfs_error(_("%s: %s: block devices not permitted on fs"),
284 nfs_error(_("%s: %s: %s"),
285 progname, dev, strerror(err));
291 * We need to translate between nfs status return values and
292 * the local errno values which may not be the same.
294 * Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>: change errno:
295 * "after #include <errno.h> the symbol errno is reserved for any use,
296 * it cannot even be used as a struct tag or field name".
300 #define EDQUOT ENOSPC
308 { NFSERR_PERM, EPERM },
309 { NFSERR_NOENT, ENOENT },
311 { NFSERR_NXIO, ENXIO },
312 { NFSERR_ACCES, EACCES },
313 { NFSERR_EXIST, EEXIST },
314 { NFSERR_NODEV, ENODEV },
315 { NFSERR_NOTDIR, ENOTDIR },
316 { NFSERR_ISDIR, EISDIR },
318 { NFSERR_INVAL, EINVAL }, /* that Sun forgot */
320 { NFSERR_FBIG, EFBIG },
321 { NFSERR_NOSPC, ENOSPC },
322 { NFSERR_ROFS, EROFS },
323 { NFSERR_NAMETOOLONG, ENAMETOOLONG },
324 { NFSERR_NOTEMPTY, ENOTEMPTY },
325 { NFSERR_DQUOT, EDQUOT },
326 { NFSERR_STALE, ESTALE },
328 { NFSERR_WFLUSH, EWFLUSH },
330 /* Throw in some NFSv3 values for even more fun (HP returns these) */
336 char *nfs_strerror(int stat)
339 static char buf[256];
341 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
342 if (nfs_errtbl[i].stat == stat)
343 return strerror(nfs_errtbl[i].errnum);
345 sprintf(buf, _("unknown nfs status return value: %d"), stat);