From owner-svn-src-projects@freebsd.org Wed Aug 8 03:25:11 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 56DDD1072DBC for ; Wed, 8 Aug 2018 03:25:11 +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 0C7A48C9A2; Wed, 8 Aug 2018 03:25:11 +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 E271624E7A; Wed, 8 Aug 2018 03:25:10 +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 w783PAiI060422; Wed, 8 Aug 2018 03:25:10 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w783PAfg060419; Wed, 8 Aug 2018 03:25:10 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808080325.w783PAfg060419@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 8 Aug 2018 03:25:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337445 - 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: 337445 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: Wed, 08 Aug 2018 03:25:11 -0000 Author: kevans Date: Wed Aug 8 03:25:10 2018 New Revision: 337445 URL: https://svnweb.freebsd.org/changeset/base/337445 Log: libbe(3): Clarify some errors While here, fix a bug with 'rename' that checked the wrong name for being the active BE. Modified: projects/bectl/lib/libbe/be.c projects/bectl/lib/libbe/be.h projects/bectl/lib/libbe/be_error.c Modified: projects/bectl/lib/libbe/be.c ============================================================================== --- projects/bectl/lib/libbe/be.c Wed Aug 8 03:11:13 2018 (r337444) +++ projects/bectl/lib/libbe/be.c Wed Aug 8 03:25:10 2018 (r337445) @@ -287,7 +287,14 @@ be_snapshot(libbe_handle_t *lbh, const char *source, c return (set_error(lbh, BE_ERR_INVALIDNAME)); default: - /* XXX TODO: elaborate return codes */ + /* + * The other errors that zfs_ioc_snapshot might return + * shouldn't happen if we've set things up properly, so + * we'll gloss over them and call it UNKNOWN as it will + * require further triage. + */ + if (errno == ENOTSUP) + return (set_error(lbh, BE_ERR_NOPOOL)); return (set_error(lbh, BE_ERR_UNKNOWN)); } } @@ -598,22 +605,18 @@ be_rename(libbe_handle_t *lbh, char *old, char *new) if ((err = be_root_concat(lbh, new, full_new)) != 0) return (set_error(lbh, err)); - if (be_validate_name(lbh, new) != 0) - return (BE_ERR_UNKNOWN); - /* XXX TODO set and return correct error */ + if ((err = be_validate_name(lbh, new)) != 0) + return (err); /* Check if old is active BE */ - if (strcmp(full_new, be_active_path(lbh)) == 0) - return (BE_ERR_UNKNOWN); - /* XXX TODO set and return correct error */ + if (strcmp(full_old, be_active_path(lbh)) == 0) + return (set_error(lbh, BE_ERR_MOUNTED)); if (!zfs_dataset_exists(lbh->lzh, full_old, ZFS_TYPE_DATASET)) - return (BE_ERR_UNKNOWN); - /* XXX TODO set and return correct error */ + return (set_error(lbh, BE_ERR_NOENT)); if (zfs_dataset_exists(lbh->lzh, full_new, ZFS_TYPE_DATASET)) - return (BE_ERR_UNKNOWN); - /* XXX TODO set and return correct error */ + return (set_error(lbh, BE_ERR_EXISTS)); /* XXX TODO * - What about mounted BEs? @@ -621,14 +624,11 @@ be_rename(libbe_handle_t *lbh, char *old, char *new) */ if ((zfs_hdl = zfs_open(lbh->lzh, full_old, ZFS_TYPE_FILESYSTEM)) == NULL) - return (BE_ERR_UNKNOWN); - /* XXX TODO set and return correct error */ + return (set_error(lbh, BE_ERR_ZFSOPEN)); - /* recurse, nounmount, forceunmount */ struct renameflags flags = { 0, 0, 0 }; - /* XXX TODO: error log on this call */ err = zfs_rename(zfs_hdl, NULL, full_new, flags); zfs_close(zfs_hdl); Modified: projects/bectl/lib/libbe/be.h ============================================================================== --- projects/bectl/lib/libbe/be.h Wed Aug 8 03:11:13 2018 (r337444) +++ projects/bectl/lib/libbe/be.h Wed Aug 8 03:25:10 2018 (r337445) @@ -56,6 +56,7 @@ typedef enum be_error { 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_NOPOOL, /* operation not supported on this pool */ BE_ERR_UNKNOWN, /* unknown error */ } be_error_t; Modified: projects/bectl/lib/libbe/be_error.c ============================================================================== --- projects/bectl/lib/libbe/be_error.c Wed Aug 8 03:11:13 2018 (r337444) +++ projects/bectl/lib/libbe/be_error.c Wed Aug 8 03:25:10 2018 (r337445) @@ -96,6 +96,9 @@ libbe_error_description(libbe_handle_t *lbh) case BE_ERR_IO: return ("input/output error"); + case BE_ERR_NOPOOL: + return ("operation not supported on this pool"); + case BE_ERR_UNKNOWN: return ("unknown error");