mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
Add libzfs_error_init() function
All fprintf() error messages are moved out of the libzfs_init() library function where they never belonged in the first place. A libzfs_error_init() function is added to provide useful error messages for the most common causes of failure. Additionally, in libzfs_run_process() the 'rc' variable was renamed to 'error' for consistency with the rest of the code base. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Chris Dunlap <cdunlap@llnl.gov> Signed-off-by: Richard Yao <ryao@gentoo.org>
This commit is contained in:
+30
-16
@@ -58,6 +58,31 @@ libzfs_errno(libzfs_handle_t *hdl)
|
||||
return (hdl->libzfs_error);
|
||||
}
|
||||
|
||||
const char *
|
||||
libzfs_error_init(int error)
|
||||
{
|
||||
switch (error) {
|
||||
case ENXIO:
|
||||
return (dgettext(TEXT_DOMAIN, "The ZFS modules are not "
|
||||
"loaded.\nTry running '/sbin/modprobe zfs' as root "
|
||||
"to load them.\n"));
|
||||
case ENOENT:
|
||||
return (dgettext(TEXT_DOMAIN, "The /dev/zfs device is "
|
||||
"missing and must be created.\nTry running 'udevadm "
|
||||
"trigger' as root to create it.\n"));
|
||||
case ENOEXEC:
|
||||
return (dgettext(TEXT_DOMAIN, "The ZFS modules cannot be "
|
||||
"auto-loaded.\nTry running '/sbin/modprobe zfs' as "
|
||||
"root to manually load them.\n"));
|
||||
case EACCES:
|
||||
return (dgettext(TEXT_DOMAIN, "Permission denied the "
|
||||
"ZFS utilities must be run as root.\n"));
|
||||
default:
|
||||
return (dgettext(TEXT_DOMAIN, "Failed to initialize the "
|
||||
"libzfs library.\n"));
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
libzfs_error_action(libzfs_handle_t *hdl)
|
||||
{
|
||||
@@ -628,7 +653,7 @@ int
|
||||
libzfs_run_process(const char *path, char *argv[], int flags)
|
||||
{
|
||||
pid_t pid;
|
||||
int rc, devnull_fd;
|
||||
int error, devnull_fd;
|
||||
|
||||
pid = vfork();
|
||||
if (pid == 0) {
|
||||
@@ -650,9 +675,9 @@ libzfs_run_process(const char *path, char *argv[], int flags)
|
||||
} else if (pid > 0) {
|
||||
int status;
|
||||
|
||||
while ((rc = waitpid(pid, &status, 0)) == -1 &&
|
||||
while ((error = waitpid(pid, &status, 0)) == -1 &&
|
||||
errno == EINTR);
|
||||
if (rc < 0 || !WIFEXITED(status))
|
||||
if (error < 0 || !WIFEXITED(status))
|
||||
return (-1);
|
||||
|
||||
return (WEXITSTATUS(status));
|
||||
@@ -670,7 +695,7 @@ libzfs_run_process(const char *path, char *argv[], int flags)
|
||||
* - ZFS_MODULE_LOADING="YES|yes|ON|on" - Attempt to load modules.
|
||||
* - ZFS_MODULE_TIMEOUT="<seconds>" - Seconds to wait for ZFS_DEV
|
||||
*/
|
||||
int
|
||||
static int
|
||||
libzfs_load_module(const char *module)
|
||||
{
|
||||
char *argv[4] = {"/sbin/modprobe", "-q", (char *)module, (char *)0};
|
||||
@@ -739,9 +764,7 @@ libzfs_init(void)
|
||||
|
||||
error = libzfs_load_module(ZFS_DRIVER);
|
||||
if (error) {
|
||||
(void) fprintf(stderr, gettext("Failed to load ZFS module "
|
||||
"stack.\nLoad the module manually by running "
|
||||
"'insmod <location>/zfs.ko' as root.\n"));
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -750,13 +773,6 @@ libzfs_init(void)
|
||||
}
|
||||
|
||||
if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) {
|
||||
(void) fprintf(stderr, gettext("Unable to open %s: %s.\n"),
|
||||
ZFS_DEV, strerror(errno));
|
||||
if (errno == ENOENT)
|
||||
(void) fprintf(stderr,
|
||||
gettext("Verify the ZFS module stack is "
|
||||
"loaded by running '/sbin/modprobe zfs'.\n"));
|
||||
|
||||
free(hdl);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -767,8 +783,6 @@ libzfs_init(void)
|
||||
if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) {
|
||||
#endif
|
||||
(void) close(hdl->libzfs_fd);
|
||||
(void) fprintf(stderr,
|
||||
gettext("mtab is not present at %s.\n"), MNTTAB);
|
||||
free(hdl);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user