From owner-svn-src-head@freebsd.org Wed Jan 9 22:31:12 2019 Return-Path: Delivered-To: svn-src-head@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 2C7AE14923E8; Wed, 9 Jan 2019 22:31: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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C357E81570; Wed, 9 Jan 2019 22:31: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 AE57822624; Wed, 9 Jan 2019 22:31:11 +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 x09MVBmH033784; Wed, 9 Jan 2019 22:31:11 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x09MVBYh033782; Wed, 9 Jan 2019 22:31:11 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201901092231.x09MVBYh033782@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 9 Jan 2019 22:31:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342903 - head/lib/libbe X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/lib/libbe X-SVN-Commit-Revision: 342903 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C357E81570 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.977,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.998,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jan 2019 22:31:12 -0000 Author: kevans Date: Wed Jan 9 22:31:10 2019 New Revision: 342903 URL: https://svnweb.freebsd.org/changeset/base/342903 Log: libbe(3): move altroot augmentation bits around a little bit We could perhaps have a method that does this given a dataset, but it's yet clear that we'll always want to bypass the altroot when we grab the mountpoint. For now, we'll refactor things a bit so we grab the altroot length when libbe is initialized and have a common method that does the necessary augmentation (replace with / if it's the root, return a pointer to later in the string if not). This will be used in some upcoming work to make be_mount work properly for deep BEs. MFC after: 1 week Modified: head/lib/libbe/be.c head/lib/libbe/be_access.c head/lib/libbe/be_impl.h Modified: head/lib/libbe/be.c ============================================================================== --- head/lib/libbe/be.c Wed Jan 9 20:19:34 2019 (r342902) +++ head/lib/libbe/be.c Wed Jan 9 22:31:10 2019 (r342903) @@ -90,6 +90,7 @@ be_locate_rootfs(libbe_handle_t *lbh) libbe_handle_t * libbe_init(const char *root) { + char altroot[MAXPATHLEN]; libbe_handle_t *lbh; char *poolname, *pos; int pnamelen; @@ -140,6 +141,11 @@ libbe_init(const char *root) sizeof(lbh->bootfs), NULL, true) != 0) goto err; + if (zpool_get_prop(lbh->active_phandle, ZPOOL_PROP_ALTROOT, + altroot, sizeof(altroot), NULL, true) == 0 && + strcmp(altroot, "-") != 0) + lbh->altroot_len = strlen(altroot); + return (lbh); err: if (lbh != NULL) { @@ -314,7 +320,6 @@ be_create(libbe_handle_t *lbh, const char *name) return (set_error(lbh, err)); } - static int be_deep_clone_prop(int prop, void *cb) { @@ -345,12 +350,9 @@ be_deep_clone_prop(int prop, void *cb) /* Augment mountpoint with altroot, if needed */ val = pval; - if (prop == ZFS_PROP_MOUNTPOINT && *dccb->altroot != '\0') { - if (pval[strlen(dccb->altroot)] == '\0') - strlcpy(pval, "/", sizeof(pval)); - else - val = pval + strlen(dccb->altroot); - } + if (prop == ZFS_PROP_MOUNTPOINT) + val = be_mountpoint_augmented(dccb->lbh, val); + nvlist_add_string(dccb->props, zfs_prop_to_name(prop), val); return (ZPROP_CONT); @@ -392,12 +394,9 @@ be_deep_clone(zfs_handle_t *ds, void *data) nvlist_alloc(&props, NV_UNIQUE_NAME, KM_SLEEP); nvlist_add_string(props, "canmount", "noauto"); + dccb.lbh = isdc->lbh; dccb.zhp = ds; dccb.props = props; - if (zpool_get_prop(isdc->lbh->active_phandle, ZPOOL_PROP_ALTROOT, - dccb.altroot, sizeof(dccb.altroot), NULL, true) != 0 || - strcmp(dccb.altroot, "-") == 0) - *dccb.altroot = '\0'; if (zprop_iter(be_deep_clone_prop, &dccb, B_FALSE, B_FALSE, ZFS_TYPE_FILESYSTEM) == ZPROP_INVAL) return (-1); Modified: head/lib/libbe/be_access.c ============================================================================== --- head/lib/libbe/be_access.c Wed Jan 9 20:19:34 2019 (r342902) +++ head/lib/libbe/be_access.c Wed Jan 9 22:31:10 2019 (r342903) @@ -195,3 +195,25 @@ be_unmount(libbe_handle_t *lbh, char *bootenv, int fla return (BE_ERR_SUCCESS); } + +/* + * This function will blow away the input buffer as needed if we're discovered + * to be looking at a root-mount. If the mountpoint is naturally beyond the + * root, however, the buffer may be left intact and a pointer to the section + * past altroot will be returned instead for the caller's perusal. + */ +char * +be_mountpoint_augmented(libbe_handle_t *lbh, char *mountpoint) +{ + + if (lbh->altroot_len == 0) + return (mountpoint); + if (mountpoint == NULL || *mountpoint == '\0') + return (mountpoint); + + if (mountpoint[lbh->altroot_len] == '\0') { + *(mountpoint + 1) = '\0'; + return (mountpoint); + } else + return (mountpoint + lbh->altroot_len); +} Modified: head/lib/libbe/be_impl.h ============================================================================== --- head/lib/libbe/be_impl.h Wed Jan 9 20:19:34 2019 (r342902) +++ head/lib/libbe/be_impl.h Wed Jan 9 22:31:10 2019 (r342903) @@ -36,11 +36,12 @@ #include "be.h" struct libbe_handle { - libzfs_handle_t *lzh; - zpool_handle_t *active_phandle; char root[BE_MAXPATHLEN]; char rootfs[BE_MAXPATHLEN]; char bootfs[BE_MAXPATHLEN]; + size_t altroot_len; + zpool_handle_t *active_phandle; + libzfs_handle_t *lzh; be_error_t error; bool print_on_err; }; @@ -53,9 +54,9 @@ struct libbe_deep_clone { }; struct libbe_dccb { + libbe_handle_t *lbh; zfs_handle_t *zhp; nvlist_t *props; - char altroot[MAXPATHLEN]; }; typedef struct prop_data { @@ -66,6 +67,8 @@ typedef struct prop_data { int prop_list_builder_cb(zfs_handle_t *, void *); int be_proplist_update(prop_data_t *); + +char *be_mountpoint_augmented(libbe_handle_t *lbh, char *mountpoint); /* Clobbers any previous errors */ int set_error(libbe_handle_t *, be_error_t);