stand: Change zfs_parsedev() API

Change the first argument to zfs_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
nplaces in the tree passed in a malloc'd pointer anyway, and this moves
knowledge of zfs_devdesc more firmly into the zfs.c code.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37336
This commit is contained in:
Warner Losh 2022-11-30 15:08:22 -07:00
parent 17276525fa
commit ba11bc368e
7 changed files with 18 additions and 24 deletions

View file

@ -118,11 +118,7 @@ efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
#ifdef EFI_ZFS_BOOT
case DEVT_ZFS:
idev = malloc(sizeof(struct zfs_devdesc));
if (idev == NULL)
return (ENOMEM);
err = zfs_parsedev((struct zfs_devdesc*)idev, np, path);
err = zfs_parsedev(&idev, np, path);
if (err != 0)
goto fail;
break;

View file

@ -119,11 +119,7 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path)
break;
case DEVT_ZFS:
idev = malloc(sizeof (struct zfs_devdesc));
if (idev == NULL)
return (ENOMEM);
err = zfs_parsedev((struct zfs_devdesc *)idev, np, path);
err = zfs_parsedev((struct devdesc **)&idev, np, path);
if (err != 0)
goto fail;
break;

View file

@ -113,9 +113,9 @@ ofw_parsedev(struct ofw_devdesc **dev, const char *devspec, const char **path)
idev->dd.d_dev = dv;
if (dv->dv_type == DEVT_ZFS) {
p = devspec + strlen(dv->dv_name);
err = zfs_parsedev((struct zfs_devdesc *)idev, p, path);
free(idev);
err = zfs_parsedev((struct devdesc **)&idev, p, path);
if (err != 0) {
free(idev);
return (err);
}
}

View file

@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$");
__attribute__((weak))
int
zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
zfs_parsedev(struct devdesc **dev, const char *devspec, const char **path)
{
return (EINVAL);
}

View file

@ -48,7 +48,7 @@ struct zfs_devdesc {
uint64_t root_guid;
};
int zfs_parsedev(struct zfs_devdesc *dev, const char *devspec,
int zfs_parsedev(struct devdesc **dev, const char *devspec,
const char **path);
char *zfs_fmtdev(struct devdesc *);
int zfs_probe_dev(const char *devname, uint64_t *pool_guid);

View file

@ -382,13 +382,8 @@ zfs_mount(const char *dev, const char *path, void **data)
int rv;
errno = 0;
zfsdev = malloc(sizeof(*zfsdev));
if (zfsdev == NULL)
return (errno);
rv = zfs_parsedev(zfsdev, dev + 3, NULL);
rv = zfs_parsedev((struct devdesc **)&zfsdev, dev + 3, NULL);
if (rv != 0) {
free(zfsdev);
return (rv);
}
@ -1634,7 +1629,7 @@ struct devsw zfs_dev = {
};
int
zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
zfs_parsedev(struct devdesc **idev, const char *devspec, const char **path)
{
static char rootname[ZFS_MAXNAMELEN];
static char poolname[ZFS_MAXNAMELEN];
@ -1643,6 +1638,7 @@ zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
const char *np;
const char *sep;
int rv;
struct zfs_devdesc *dev;
np = devspec;
if (*np != ':')
@ -1667,13 +1663,19 @@ zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
spa = spa_find_by_name(poolname);
if (!spa)
return (ENXIO);
dev = malloc(sizeof(*dev));
if (dev == NULL)
return (ENOMEM);
dev->pool_guid = spa->spa_guid;
rv = zfs_lookup_dataset(spa, rootname, &dev->root_guid);
if (rv != 0)
if (rv != 0) {
free(dev);
return (rv);
}
if (path != NULL)
*path = (*end == '\0') ? end : end + 1;
dev->dd.d_dev = &zfs_dev;
*idev = &dev->dd;
return (0);
}

View file

@ -151,8 +151,8 @@ userboot_parsedev(struct devdesc **dev, const char *devspec,
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);
free(idev);
err = zfs_parsedev(&idev, np, path);
if (err != 0)
goto fail;
break;