From nobody Tue Jan 24 22:13:08 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P1h790Z4Mz3bg6D; Tue, 24 Jan 2023 22:13:09 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P1h786v76z3Fkh; Tue, 24 Jan 2023 22:13:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dIuitBxLRfx8qZnvW3n7MitM7EdCYFypkYyqtbw4BWA=; b=eAssSlL0yG8UcF3blWdbg3Dt6taNKlB7xGfnUj3JRPUiqfSMLZ4nExTdae70ci/7NPahJ/ c0brATanu7vbWtI/fKNDqukUtodu6BFDk92FfrK+T5hEJ07M9Ze2EWiTtB5DWr5LylacXA 6Da1pjhVSBJbbjT5qSRd0eMErTCajBYSeViUv3JSNWkH8XAgZvqE2tyYGKM10L60XEbrbB rzuFoy9AJkdSN3fCiGc3RBlPWsQo1Q3JreI3lTP98CrLXAaboiuOz5ARv3V/wGgwToyAT4 p4vvO0YZ7fcV1rPRemKcs9/Um2qH6bkBTjFuAApPJjRcevjmwY4ZttHgiD7Xww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dIuitBxLRfx8qZnvW3n7MitM7EdCYFypkYyqtbw4BWA=; b=mkGI+qL0a8U7dIPFma9UusklheV0CsE70KwGKVXHuu/h/dF9ob8Z85jgDX4YlmgBHC4T9S j5ySqgRcpL14b5EYngGLDCRAp+CtLedYQSCtDsDBWXoPu3dx26W9U0jPxkE8c78z15G8sR olokn78Qz0PAFt8x8nbEAm6ThLToBVuIY7gQCxDWYWzKgYJ02OPlJdFaoW3SpSrQdv/73b NY9p1iUH90nJKKTgjcAvQ00FfeMt91R3sL8eDaLX5VacZNlPyrGRqCXfLYeWN2iqh85fGs CxenmPYBLjMfgl+6UfJ7tXONdpkT7SOnrt+KE++aWTi9MmWd1/1rglwbEVnucg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598389; a=rsa-sha256; cv=none; b=qMrgg7k1NKwysxGNJ7NPcPjwenwy1jTxB5PAkFG0xYVLn5Ph5Ifakuez+qRWKs8vnve0LH ZbI6n4DtngCw8lQ0QxuyIS6A9EnMJY6O2tWhPYbX9oekptzPaROoOAyTNQgVkA/q8jDxv7 SE/JXNDLxa6jeFKfLsNHpLe+nra7YNh6y08nGx+ptnhNRjkIm/9B/Ma7vrwZDj5+4HPpNv BoyfQXxb9qkqipS1J1m0MdmKdchAVVS/kNPnXw1ROcmt4TFhKFOoWbOyczc7Gne91oyYey xCAukC1PWi/pb67KTfGQPQ9kqUBHE5eTFh+H1EmSR7PhJlO6sxKqc/ux/yr3ow== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P1h785VnYzQgy; Tue, 24 Jan 2023 22:13:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OMD8oD088012; Tue, 24 Jan 2023 22:13:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMD8EV088011; Tue, 24 Jan 2023 22:13:08 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:08 GMT Message-Id: <202301242213.30OMD8EV088011@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 8189dec087b7 - stable/13 - stand: Change disk_parsedev() API List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8189dec087b741744eeaccd697a50c3a6ad9e4b4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8189dec087b741744eeaccd697a50c3a6ad9e4b4 commit 8189dec087b741744eeaccd697a50c3a6ad9e4b4 Author: Warner Losh AuthorDate: 2022-11-30 22:08:15 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:38 +0000 stand: Change disk_parsedev() API Change the first argument to disk_parsedev() to be a pointer to a struct devdesc *. This now gets filled in with a malloc'd structure that's returned to the caller that the caller is repsonsible for freeing. Most places in the tree passed in a malloc'd pointer anyway, and this moves knowledge of disk_devdesc more firmly into the disk.[ch] code. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37335 (cherry picked from commit 17276525fa1a28028f7ca423f365d5081cbe9a97) --- stand/common/disk.c | 7 ++++++- stand/common/disk.h | 2 +- stand/efi/libefi/devicename.c | 6 +----- stand/i386/libi386/devicename.c | 8 ++------ stand/i386/zfsboot/zfsboot.c | 12 +++++++----- stand/uboot/devicename.c | 3 ++- stand/uboot/main.c | 11 ++++++----- stand/userboot/userboot/devicename.c | 18 ++++++++++-------- 8 files changed, 35 insertions(+), 32 deletions(-) diff --git a/stand/common/disk.c b/stand/common/disk.c index 15daf7e358c6..653f971d46b8 100644 --- a/stand/common/disk.c +++ b/stand/common/disk.c @@ -413,11 +413,12 @@ disk_fmtdev(struct devdesc *vdev) } int -disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path) +disk_parsedev(struct devdesc **idev, const char *devspec, const char **path) { int unit, slice, partition; const char *np; char *cp; + struct disk_devdesc *dev; np = devspec; unit = -1; @@ -470,9 +471,13 @@ disk_parsedev(struct disk_devdesc *dev, const char *devspec, const char **path) if (*cp != '\0' && *cp != ':') return (EINVAL); + dev = malloc(sizeof(*dev)); + if (dev == NULL) + return (ENOMEM); dev->dd.d_unit = unit; dev->d_slice = slice; dev->d_partition = partition; + *idev = &dev->dd; if (path != NULL) *path = (*cp == '\0') ? cp: cp + 1; return (0); diff --git a/stand/common/disk.h b/stand/common/disk.h index 291999ce960d..a05b532918de 100644 --- a/stand/common/disk.h +++ b/stand/common/disk.h @@ -111,7 +111,7 @@ extern int ptblread(void *, void *, size_t, uint64_t); * Print information about slices on a disk. */ extern int disk_print(struct disk_devdesc *, char *, int); -extern int disk_parsedev(struct disk_devdesc *, const char *, const char **); +extern int disk_parsedev(struct devdesc **, const char *, const char **); char *disk_fmtdev(struct devdesc *vdev); diff --git a/stand/efi/libefi/devicename.c b/stand/efi/libefi/devicename.c index 67a2e24d9da1..ad4b5d590609 100644 --- a/stand/efi/libefi/devicename.c +++ b/stand/efi/libefi/devicename.c @@ -111,11 +111,7 @@ efi_parsedev(struct devdesc **dev, const char *devspec, const char **path) break; case DEVT_DISK: - idev = malloc(sizeof(struct disk_devdesc)); - if (idev == NULL) - return (ENOMEM); - - err = disk_parsedev((struct disk_devdesc *)idev, np, path); + err = disk_parsedev(&idev, np, path); if (err != 0) goto fail; break; diff --git a/stand/i386/libi386/devicename.c b/stand/i386/libi386/devicename.c index 73445aeba172..9ac4c9742593 100644 --- a/stand/i386/libi386/devicename.c +++ b/stand/i386/libi386/devicename.c @@ -84,7 +84,7 @@ i386_getdev(void **vdev, const char *devspec, const char **path) static int i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path) { - struct i386_devdesc *idev; + struct i386_devdesc *idev = NULL; struct devsw *dv; int i, unit, err; char *cp; @@ -113,11 +113,7 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path) break; case DEVT_DISK: - idev = malloc(sizeof(struct i386_devdesc)); - if (idev == NULL) - return (ENOMEM); - - err = disk_parsedev((struct disk_devdesc *)idev, np, path); + err = disk_parsedev((struct devdesc **)&idev, np, path); if (err != 0) goto fail; break; diff --git a/stand/i386/zfsboot/zfsboot.c b/stand/i386/zfsboot/zfsboot.c index 930a6fb530af..ea390b6ea7a6 100644 --- a/stand/i386/zfsboot/zfsboot.c +++ b/stand/i386/zfsboot/zfsboot.c @@ -168,7 +168,7 @@ main(void) { unsigned i; int auto_boot, fd, nextboot = 0; - struct disk_devdesc devdesc; + struct disk_devdesc *devdesc; bios_getmem(); @@ -215,11 +215,13 @@ main(void) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); - disk_parsedev(&devdesc, boot_devname + 4, NULL); + /* XXX assumes this will be a disk, but it looks likely give above */ + disk_parsedev((struct devdesc **)&devdesc, boot_devname + 4, NULL); - bootdev = MAKEBOOTDEV(dev_maj[DEVT_DISK], devdesc.d_slice + 1, - devdesc.dd.d_unit, - devdesc.d_partition >= 0 ? devdesc.d_partition : 0xff); + bootdev = MAKEBOOTDEV(dev_maj[DEVT_DISK], devdesc->d_slice + 1, + devdesc->dd.d_unit, + devdesc->d_partition >= 0 ? devdesc->d_partition : 0xff); + free(devdesc); /* * devformat() can be called only after dv_init diff --git a/stand/uboot/devicename.c b/stand/uboot/devicename.c index b73a7694f14a..8f867406e6fa 100644 --- a/stand/uboot/devicename.c +++ b/stand/uboot/devicename.c @@ -115,7 +115,8 @@ uboot_parsedev(struct uboot_devdesc **dev, const char *devspec, #ifdef LOADER_DISK_SUPPORT case DEVT_DISK: - err = disk_parsedev((struct disk_devdesc *)idev, np, path); + free(idev); + err = disk_parsedev((struct devdesc **)&idev, np, path); if (err != 0) goto fail; break; diff --git a/stand/uboot/main.c b/stand/uboot/main.c index 573995663fe4..cf41917d6ee5 100644 --- a/stand/uboot/main.c +++ b/stand/uboot/main.c @@ -206,7 +206,7 @@ device_typename(int type) static void get_load_device(int *type, int *unit, int *slice, int *partition) { - struct disk_devdesc dev; + struct disk_devdesc *dev; char *devstr; const char *p; char *endp; @@ -237,10 +237,11 @@ get_load_device(int *type, int *unit, int *slice, int *partition) if (*type & DEV_TYP_STOR) { size_t len = strlen(p); if (strcspn(p, " .") == len && strcspn(p, ":") >= len - 1 && - disk_parsedev(&dev, p, NULL) == 0) { - *unit = dev.dd.d_unit; - *slice = dev.d_slice; - *partition = dev.d_partition; + disk_parsedev((struct devdesc **)&dev, p, NULL) == 0) { + *unit = dev->dd.d_unit; + *slice = dev->d_slice; + *partition = dev->d_partition; + free(dev); return; } } diff --git a/stand/userboot/userboot/devicename.c b/stand/userboot/userboot/devicename.c index 45bf9bc6ebd8..2fffebf282c6 100644 --- a/stand/userboot/userboot/devicename.c +++ b/stand/userboot/userboot/devicename.c @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); #include "libzfs.h" #endif -static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec, +static int userboot_parsedev(struct devdesc **dev, const char *devspec, const char **path); /* @@ -49,7 +49,7 @@ static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec, int userboot_getdev(void **vdev, const char *devspec, const char **path) { - struct disk_devdesc **dev = (struct disk_devdesc **)vdev; + struct devdesc **dev = (struct devdesc **)vdev; int rv; /* @@ -87,10 +87,10 @@ userboot_getdev(void **vdev, const char *devspec, const char **path) * */ static int -userboot_parsedev(struct disk_devdesc **dev, const char *devspec, +userboot_parsedev(struct devdesc **dev, const char *devspec, const char **path) { - struct disk_devdesc *idev; + struct devdesc *idev; struct devsw *dv; int i, unit, err; const char *cp; @@ -119,7 +119,8 @@ userboot_parsedev(struct disk_devdesc **dev, const char *devspec, break; case DEVT_DISK: - err = disk_parsedev(idev, np, path); + free(idev); + err = disk_parsedev(&idev, np, path); if (err != 0) goto fail; break; @@ -143,13 +144,14 @@ userboot_parsedev(struct disk_devdesc **dev, const char *devspec, goto fail; } - idev->dd.d_unit = unit; + idev->d_unit = unit; if (path != NULL) *path = (*cp == 0) ? cp : cp + 1; break; case DEVT_ZFS: #if defined(USERBOOT_ZFS_SUPPORT) + /* XXX assumes sizeof disk_devdesc >= sizeof zfs_devdesc */ err = zfs_parsedev((struct zfs_devdesc *)idev, np, path); if (err != 0) goto fail; @@ -162,7 +164,7 @@ userboot_parsedev(struct disk_devdesc **dev, const char *devspec, err = EINVAL; goto fail; } - idev->dd.d_dev = dv; + idev->d_dev = dv; if (dev == NULL) { free(idev); } else { @@ -182,7 +184,7 @@ fail: int userboot_setcurrdev(struct env_var *ev, int flags, const void *value) { - struct disk_devdesc *ncurr; + struct devdesc *ncurr; int rv; if ((rv = userboot_parsedev(&ncurr, value, NULL)) != 0)