svn commit: r337407 - projects/bectl/lib/libbe
Kyle Evans
kevans at FreeBSD.org
Tue Aug 7 03:25:30 UTC 2018
Author: kevans
Date: Tue Aug 7 03:25:28 2018
New Revision: 337407
URL: https://svnweb.freebsd.org/changeset/base/337407
Log:
libbe(3): Return some more proper error codes
Modified:
projects/bectl/lib/libbe/be.h
projects/bectl/lib/libbe/be_access.c
projects/bectl/lib/libbe/libbe.3
Modified: projects/bectl/lib/libbe/be.h
==============================================================================
--- projects/bectl/lib/libbe/be.h Tue Aug 7 03:07:54 2018 (r337406)
+++ projects/bectl/lib/libbe/be.h Tue Aug 7 03:25:28 2018 (r337407)
@@ -44,6 +44,8 @@ typedef enum be_error {
BE_ERR_PERMS, /* insufficient permissions */
BE_ERR_DESTROYACT, /* cannot destroy active boot env */
BE_ERR_DESTROYMNT, /* destroying a mounted be requires force */
+ BE_ERR_BADPATH, /* path not suitable for operation */
+ BE_ERR_PATHBUSY, /* requested path is busy */
BE_ERR_PATHLEN, /* provided name exceeds maximum length limit */
BE_ERR_INVORIGIN, /* snapshot origin's mountpoint is not '/' */
BE_ERR_NOORIGIN, /* could not open snapshot's origin */
@@ -51,6 +53,7 @@ typedef enum be_error {
BE_ERR_NOMOUNT, /* boot environment is not mounted */
BE_ERR_ZFSOPEN, /* calling zfs_open() failed */
BE_ERR_ZFSCLONE, /* error when calling zfs_clone to create be */
+ BE_ERR_IO, /* error when doing some I/O operation */
BE_ERR_UNKNOWN, /* unknown error */
} be_error_t;
Modified: projects/bectl/lib/libbe/be_access.c
==============================================================================
--- projects/bectl/lib/libbe/be_access.c Tue Aug 7 03:07:54 2018 (r337406)
+++ projects/bectl/lib/libbe/be_access.c Tue Aug 7 03:25:28 2018 (r337407)
@@ -121,18 +121,27 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mou
if (mountpoint == NULL) {
strcpy(mnt_temp, "/tmp/be_mount.XXXX");
if (mkdtemp(mnt_temp) == NULL)
- /* XXX TODO: create error for this */
- return (set_error(lbh, BE_ERR_UNKNOWN));
+ return (set_error(lbh, BE_ERR_IO));
}
char opt = '\0';
if ((err = zmount(be, (mountpoint == NULL) ? mnt_temp : mountpoint,
- mntflags, __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0)
- /*
- * XXX TODO: zmount returns the nmount error, look into what
- * kind of errors we can report from that
- */
- return (set_error(lbh, BE_ERR_UNKNOWN));
+ mntflags, __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0) {
+ switch (errno) {
+ case ENAMETOOLONG:
+ return (set_error(lbh, BE_ERR_PATHLEN));
+ case ELOOP:
+ case ENOENT:
+ case ENOTDIR:
+ return (set_error(lbh, BE_ERR_BADPATH));
+ case EPERM:
+ return (set_error(lbh, BE_ERR_PERMS));
+ case EBUSY:
+ return (set_error(lbh, BE_ERR_PATHBUSY));
+ default:
+ return (set_error(lbh, BE_ERR_UNKNOWN));
+ }
+ }
if (result_loc != NULL)
strcpy(result_loc, mountpoint == NULL ? mnt_temp : mountpoint);
@@ -156,9 +165,11 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int fla
if ((err = be_root_concat(lbh, bootenv, be)) != 0)
return (set_error(lbh, err));
- if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
- /* XXX TODO correct error */
+ if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
+ if (errno == EIO)
+ return (set_error(lbh, BE_ERR_IO));
return (set_error(lbh, BE_ERR_NOMOUNT));
+ }
mntpath = NULL;
for (int i = 0; i < mntsize; ++i) {
@@ -177,9 +188,22 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int fla
mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0;
- if ((err = unmount(mntpath, mntflags)) != 0)
- /* XXX TODO correct error */
- return (set_error(lbh, BE_ERR_NOMOUNT));
+ if ((err = unmount(mntpath, mntflags)) != 0) {
+ switch (errno) {
+ case ENAMETOOLONG:
+ return (set_error(lbh, BE_ERR_PATHLEN));
+ case ELOOP:
+ case ENOENT:
+ case ENOTDIR:
+ return (set_error(lbh, BE_ERR_BADPATH));
+ case EPERM:
+ return (set_error(lbh, BE_ERR_PERMS));
+ case EBUSY:
+ return (set_error(lbh, BE_ERR_PATHBUSY));
+ default:
+ return (set_error(lbh, BE_ERR_UNKNOWN));
+ }
+ }
return (set_error(lbh, BE_ERR_SUCCESS));
}
Modified: projects/bectl/lib/libbe/libbe.3
==============================================================================
--- projects/bectl/lib/libbe/libbe.3 Tue Aug 7 03:07:54 2018 (r337406)
+++ projects/bectl/lib/libbe/libbe.3 Tue Aug 7 03:25:28 2018 (r337407)
@@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 25, 2018
+.Dd August 6, 2018
.Dt LIBBE 3
.Os
.Sh NAME
@@ -190,6 +190,8 @@ BE_ERR_NOENT,
BE_ERR_PERMS,
BE_ERR_DESTROYACT,
BE_ERR_DESTROYMNT,
+BE_ERR_BADPATH,
+BE_ERR_PATHBUSY,
BE_ERR_PATHLEN,
BE_ERR_INVORIGIN,
BE_ERR_NOORIGIN,
@@ -197,6 +199,7 @@ BE_ERR_MOUNTED,
BE_ERR_NOMOUNT,
BE_ERR_ZFSOPEN,
BE_ERR_ZFSCLONE,
+BE_ERR_IO,
BE_ERR_UNKNOWN
.Ed
.Sh SEE ALSO
More information about the svn-src-projects
mailing list