From owner-svn-src-projects@freebsd.org Wed Aug 8 03:46:13 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 E7C571073583 for ; Wed, 8 Aug 2018 03:46:12 +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 9CA748D2A5; Wed, 8 Aug 2018 03:46:12 +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 7F8A8251C0; Wed, 8 Aug 2018 03:46:12 +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 w783kC10070922; Wed, 8 Aug 2018 03:46:12 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w783kCDE070921; Wed, 8 Aug 2018 03:46:12 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808080346.w783kCDE070921@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:46:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337446 - 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: 337446 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:46:13 -0000 Author: kevans Date: Wed Aug 8 03:46:12 2018 New Revision: 337446 URL: https://svnweb.freebsd.org/changeset/base/337446 Log: libbe(3): Some more light error handling... Modified: projects/bectl/lib/libbe/be.c Modified: projects/bectl/lib/libbe/be.c ============================================================================== --- projects/bectl/lib/libbe/be.c Wed Aug 8 03:25:10 2018 (r337445) +++ projects/bectl/lib/libbe/be.c Wed Aug 8 03:46:12 2018 (r337446) @@ -652,7 +652,7 @@ be_export(libbe_handle_t *lbh, char *bootenv, int fd) be_root_concat(lbh, snap_name, buf); if ((zfs = zfs_open(lbh->lzh, buf, ZFS_TYPE_DATASET)) == NULL) - return (BE_ERR_ZFSOPEN); + return (set_error(lbh, BE_ERR_ZFSOPEN)); err = zfs_send_one(zfs, NULL, fd, 0); return (err); @@ -667,14 +667,22 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) nvlist_t *props; zfs_handle_t *zfs; int err, len; + char nbuf[24]; /* - * XXX TODO: this is a very likely name for someone to already have - * used... we should avoid it. + * We don't need this to be incredibly random, just unique enough that + * it won't conflict with an existing dataset name. Chopping time + * down to 32 bits is probably good enough for this. */ - if ((err = be_root_concat(lbh, "libbe_import_temp", buf)) != 0) - /* XXX TODO error handle */ - return (-1); + snprintf(nbuf, 24, "tmp%u", + (uint32_t)(time(NULL) & 0xFFFFFFFF)); + if ((err = be_root_concat(lbh, nbuf, buf)) != 0) + /* + * Technically this is our problem, but we try to use short + * enough names that we won't run into problems except in + * worst-case BE root approaching MAXPATHLEN. + */ + return (set_error(lbh, BE_ERR_PATHLEN)); time(&rawtime); len = strlen(buf); @@ -683,18 +691,20 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) /* lzc_receive(SNAPNAME, PROPS, ORIGIN, FORCE, fd)) { */ if ((err = lzc_receive(buf, NULL, NULL, false, fd)) != 0) { - /* TODO: go through libzfs_core's recv_impl and find returned - * errors and set appropriate BE_ERR - * edit: errors are not in libzfs_core, my assumption is - * that they use libzfs errors - * note: 17 is err for dataset already existing - */ - return (err); + switch (err) { + case EINVAL: + return (set_error(lbh, BE_ERR_NOORIGIN)); + case ENOENT: + return (set_error(lbh, BE_ERR_NOENT)); + case EIO: + return (set_error(lbh, BE_ERR_IO)); + default: + return (set_error(lbh, BE_ERR_UNKNOWN)); + } } if ((zfs = zfs_open(lbh->lzh, buf, ZFS_TYPE_SNAPSHOT)) == NULL) - /* XXX TODO correct error */ - return (-1); + return (set_error(lbh, BE_ERR_ZFSOPEN)); nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP); nvlist_add_string(props, "canmount", "noauto"); @@ -707,7 +717,7 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) nvlist_free(props); - /* XXX TODO: recursively delete be_import_temp dataset */ + /* XXX TODO: recursively delete nbuf dataset */ return (err); }