From owner-svn-src-projects@freebsd.org Tue Aug 7 03:25:30 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 045A01071B4D for ; Tue, 7 Aug 2018 03:25:30 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9E18B79A04; Tue, 7 Aug 2018 03:25:29 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 79BE116422; Tue, 7 Aug 2018 03:25:29 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w773PTWF017959; Tue, 7 Aug 2018 03:25:29 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w773PSVY017957; Tue, 7 Aug 2018 03:25:28 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808070325.w773PSVY017957@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 7 Aug 2018 03:25:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337407 - projects/bectl/lib/libbe X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/lib/libbe X-SVN-Commit-Revision: 337407 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Aug 2018 03:25:30 -0000 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