]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
text-based mount.nfs: Add text-based error reporting function
authorChuck Lever <chuck.lever@oracle.com>
Mon, 24 Sep 2007 15:29:10 +0000 (11:29 -0400)
committerNeil Brown <neilb@suse.de>
Tue, 25 Sep 2007 01:50:16 +0000 (11:50 +1000)
The mount_errors() function prints an error based on what just happened in
the user-space RPC library.  This is meaningless for text-based mounts,
since they don't use the RPC library for most things.

Add a new error printing function that the text-based logic can use to
report an error.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
utils/mount/error.c
utils/mount/error.h

index 3f7458c96ed0574ff3237ba0ac77a077642b3606..480c944c88020b0cd14821b636c3c81b2489fb1a 100644 (file)
@@ -130,6 +130,61 @@ void rpc_mount_errors(char *server, int will_retry, int bg)
                fprintf(stderr, "%s\n", errbuf);
 }
 
+/**
+ * sys_mount_errors - log an error that occurred during a mount system call
+ * @server: C string containing name of server we are attempting to mount
+ * @error: errno value to report
+ * @will_retry: one indicates mount will retry at some later point
+ * @bg: one indicates this is a background mount
+ *
+ * Passed an errno value generated by a mount system call, and reports it
+ * on stderr (fg mount) or in the system log (bg mount).
+ */
+void sys_mount_errors(char *server, int error, int will_retry, int bg)
+{
+       int pos = 0;
+       char *tmp;
+       static int onlyonce = 0;
+
+       tmp = &errbuf[pos];
+       if (bg)
+               pos = snprintf(tmp, (erreob - tmp),
+                               _("mount to NFS server '%s' failed: "),
+                                       server);
+       else
+               pos = snprintf(tmp, (erreob - tmp),
+                               _("%s: mount to NFS server '%s' failed: "),
+                                       progname, server);
+
+       tmp = &errbuf[pos];
+       if (error == ETIMEDOUT) {
+               if (will_retry)
+                       pos = snprintf(tmp, (erreob - tmp),
+                                       _("timed out, retrying"));
+               else
+                       pos = snprintf(tmp, (erreob - tmp),
+                                       _("timed out, giving up"));
+       } else {
+               if (bg) {
+                       if (will_retry)
+                               pos = snprintf(tmp, (erreob - tmp),
+                                               _("%s, retrying"),
+                                               strerror(error));
+                       else
+                               pos = snprintf(tmp, (erreob - tmp),
+                                               _("%s, giving up"),
+                                               strerror(error));
+               }
+       }
+
+       if (bg) {
+               if (onlyonce++ < 1)
+                       openlog("mount", LOG_CONS|LOG_PID, LOG_AUTH);
+               syslog(LOG_ERR, "%s", errbuf);
+       } else
+               fprintf(stderr, "%s\n", errbuf);
+}
+
 /*
  * mount_error - report a foreground mount error
  * @spec: C string containing the device name being mounted
index ce9a7b651884f297a11da7e33015c5000ca75a47..8b8e9ae40ca8295cb7fe0598058555bdad04e1ef 100644 (file)
@@ -25,4 +25,6 @@ char *nfs_strerror(int);
 
 void mount_error(const char *, const char *, int);
 void rpc_mount_errors(char *, int, int);
+void sys_mount_errors(char *, int, int, int);
+
 void umount_error(int, const char *);