libbe(3): Return some more proper error codes
This commit is contained in:
parent
709b553cd0
commit
f1ca70d3e1
@ -44,6 +44,8 @@ typedef enum be_error {
|
|||||||
BE_ERR_PERMS, /* insufficient permissions */
|
BE_ERR_PERMS, /* insufficient permissions */
|
||||||
BE_ERR_DESTROYACT, /* cannot destroy active boot env */
|
BE_ERR_DESTROYACT, /* cannot destroy active boot env */
|
||||||
BE_ERR_DESTROYMNT, /* destroying a mounted be requires force */
|
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_PATHLEN, /* provided name exceeds maximum length limit */
|
||||||
BE_ERR_INVORIGIN, /* snapshot origin's mountpoint is not '/' */
|
BE_ERR_INVORIGIN, /* snapshot origin's mountpoint is not '/' */
|
||||||
BE_ERR_NOORIGIN, /* could not open snapshot's origin */
|
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_NOMOUNT, /* boot environment is not mounted */
|
||||||
BE_ERR_ZFSOPEN, /* calling zfs_open() failed */
|
BE_ERR_ZFSOPEN, /* calling zfs_open() failed */
|
||||||
BE_ERR_ZFSCLONE, /* error when calling zfs_clone to create be */
|
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_ERR_UNKNOWN, /* unknown error */
|
||||||
} be_error_t;
|
} be_error_t;
|
||||||
|
|
||||||
|
@ -121,18 +121,27 @@ be_mount(libbe_handle_t *lbh, char *bootenv, char *mountpoint, int flags,
|
|||||||
if (mountpoint == NULL) {
|
if (mountpoint == NULL) {
|
||||||
strcpy(mnt_temp, "/tmp/be_mount.XXXX");
|
strcpy(mnt_temp, "/tmp/be_mount.XXXX");
|
||||||
if (mkdtemp(mnt_temp) == NULL)
|
if (mkdtemp(mnt_temp) == NULL)
|
||||||
/* XXX TODO: create error for this */
|
return (set_error(lbh, BE_ERR_IO));
|
||||||
return (set_error(lbh, BE_ERR_UNKNOWN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char opt = '\0';
|
char opt = '\0';
|
||||||
if ((err = zmount(be, (mountpoint == NULL) ? mnt_temp : mountpoint,
|
if ((err = zmount(be, (mountpoint == NULL) ? mnt_temp : mountpoint,
|
||||||
mntflags, __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0)
|
mntflags, __DECONST(char *, MNTTYPE_ZFS), NULL, 0, &opt, 1)) != 0) {
|
||||||
/*
|
switch (errno) {
|
||||||
* XXX TODO: zmount returns the nmount error, look into what
|
case ENAMETOOLONG:
|
||||||
* kind of errors we can report from that
|
return (set_error(lbh, BE_ERR_PATHLEN));
|
||||||
*/
|
case ELOOP:
|
||||||
return (set_error(lbh, BE_ERR_UNKNOWN));
|
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)
|
if (result_loc != NULL)
|
||||||
strcpy(result_loc, mountpoint == NULL ? mnt_temp : mountpoint);
|
strcpy(result_loc, mountpoint == NULL ? mnt_temp : mountpoint);
|
||||||
@ -156,9 +165,11 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int flags)
|
|||||||
if ((err = be_root_concat(lbh, bootenv, be)) != 0)
|
if ((err = be_root_concat(lbh, bootenv, be)) != 0)
|
||||||
return (set_error(lbh, err));
|
return (set_error(lbh, err));
|
||||||
|
|
||||||
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
|
||||||
/* XXX TODO correct error */
|
if (errno == EIO)
|
||||||
|
return (set_error(lbh, BE_ERR_IO));
|
||||||
return (set_error(lbh, BE_ERR_NOMOUNT));
|
return (set_error(lbh, BE_ERR_NOMOUNT));
|
||||||
|
}
|
||||||
|
|
||||||
mntpath = NULL;
|
mntpath = NULL;
|
||||||
for (int i = 0; i < mntsize; ++i) {
|
for (int i = 0; i < mntsize; ++i) {
|
||||||
@ -177,9 +188,22 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int flags)
|
|||||||
|
|
||||||
mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0;
|
mntflags = (flags & BE_MNT_FORCE) ? MNT_FORCE : 0;
|
||||||
|
|
||||||
if ((err = unmount(mntpath, mntflags)) != 0)
|
if ((err = unmount(mntpath, mntflags)) != 0) {
|
||||||
/* XXX TODO correct error */
|
switch (errno) {
|
||||||
return (set_error(lbh, BE_ERR_NOMOUNT));
|
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));
|
return (set_error(lbh, BE_ERR_SUCCESS));
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 25, 2018
|
.Dd August 6, 2018
|
||||||
.Dt LIBBE 3
|
.Dt LIBBE 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -190,6 +190,8 @@ BE_ERR_NOENT,
|
|||||||
BE_ERR_PERMS,
|
BE_ERR_PERMS,
|
||||||
BE_ERR_DESTROYACT,
|
BE_ERR_DESTROYACT,
|
||||||
BE_ERR_DESTROYMNT,
|
BE_ERR_DESTROYMNT,
|
||||||
|
BE_ERR_BADPATH,
|
||||||
|
BE_ERR_PATHBUSY,
|
||||||
BE_ERR_PATHLEN,
|
BE_ERR_PATHLEN,
|
||||||
BE_ERR_INVORIGIN,
|
BE_ERR_INVORIGIN,
|
||||||
BE_ERR_NOORIGIN,
|
BE_ERR_NOORIGIN,
|
||||||
@ -197,6 +199,7 @@ BE_ERR_MOUNTED,
|
|||||||
BE_ERR_NOMOUNT,
|
BE_ERR_NOMOUNT,
|
||||||
BE_ERR_ZFSOPEN,
|
BE_ERR_ZFSOPEN,
|
||||||
BE_ERR_ZFSCLONE,
|
BE_ERR_ZFSCLONE,
|
||||||
|
BE_ERR_IO,
|
||||||
BE_ERR_UNKNOWN
|
BE_ERR_UNKNOWN
|
||||||
.Ed
|
.Ed
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
Loading…
Reference in New Issue
Block a user