Skip to content

Commit f5ada65

Browse files
author
Don Brady
authored
Return finer grain errors in libzfs unmount_one
Added errno mappings to unmount_one() in libzfs. Changed do_unmount() implementation to return errno errors directly like is done for do_mount() and others. Reviewed-by: Mark Maybee <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Don Brady <[email protected]> Closes #11681
1 parent 4fdbd43 commit f5ada65

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

lib/libzfs/libzfs_mount.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
2424
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25-
* Copyright (c) 2014, 2020 by Delphix. All rights reserved.
25+
* Copyright (c) 2014, 2021 by Delphix. All rights reserved.
2626
* Copyright 2016 Igor Kozhukhov <[email protected]>
2727
* Copyright 2017 RackTop Systems.
2828
* Copyright (c) 2018 Datto Inc.
@@ -553,7 +553,28 @@ unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
553553

554554
error = do_unmount(mountpoint, flags);
555555
if (error != 0) {
556-
return (zfs_error_fmt(hdl, EZFS_UMOUNTFAILED,
556+
int libzfs_err;
557+
558+
switch (error) {
559+
case EBUSY:
560+
libzfs_err = EZFS_BUSY;
561+
break;
562+
case EIO:
563+
libzfs_err = EZFS_IO;
564+
break;
565+
case ENOENT:
566+
libzfs_err = EZFS_NOENT;
567+
break;
568+
case ENOMEM:
569+
libzfs_err = EZFS_NOMEM;
570+
break;
571+
case EPERM:
572+
libzfs_err = EZFS_PERM;
573+
break;
574+
default:
575+
libzfs_err = EZFS_UMOUNTFAILED;
576+
}
577+
return (zfs_error_fmt(hdl, libzfs_err,
557578
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
558579
mountpoint));
559580
}

lib/libzfs/os/freebsd/libzfs_zmount.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts, int flags)
128128
int
129129
do_unmount(const char *mntpt, int flags)
130130
{
131-
132-
return (unmount(mntpt, flags));
131+
if (unmount(mntpt, flags) < 0)
132+
return (errno);
133+
return (0);
133134
}
134135

135136
int

lib/libzfs/os/linux/libzfs_mount_os.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
2424
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25-
* Copyright (c) 2014, 2020 by Delphix. All rights reserved.
25+
* Copyright (c) 2014, 2021 by Delphix. All rights reserved.
2626
* Copyright 2016 Igor Kozhukhov <[email protected]>
2727
* Copyright 2017 RackTop Systems.
2828
* Copyright (c) 2018 Datto Inc.
@@ -377,7 +377,9 @@ int
377377
do_unmount(const char *mntpt, int flags)
378378
{
379379
if (!libzfs_envvar_is_set("ZFS_MOUNT_HELPER")) {
380-
return (umount2(mntpt, flags));
380+
int rv = umount2(mntpt, flags);
381+
382+
return (rv < 0 ? errno : 0);
381383
}
382384

383385
char force_opt[] = "-f";

0 commit comments

Comments
 (0)