The branch main has been updated by tsoome:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d98de7440507aea1648c8f4bc302bf88c0eb9458

commit d98de7440507aea1648c8f4bc302bf88c0eb9458
Author:     Toomas Soome <[email protected]>
AuthorDate: 2022-08-14 21:49:50 +0000
Commit:     Toomas Soome <[email protected]>
CommitDate: 2022-08-15 18:07:23 +0000

    loader: zfs reader should only store devdesc in f_devdata
    
    Use d_opendata for device specific data.
    
    PR:             265825
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D36202
---
 stand/libsa/zfs/zfs.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c
index b525858ffc3c..bee243352f78 100644
--- a/stand/libsa/zfs/zfs.c
+++ b/stand/libsa/zfs/zfs.c
@@ -108,7 +108,8 @@ struct zfs_be_entry {
 static int
 zfs_open(const char *upath, struct open_file *f)
 {
-       struct zfsmount *mount = (struct zfsmount *)f->f_devdata;
+       struct devdesc *dev = f->f_devdata;
+       struct zfsmount *mount = dev->d_opendata;
        struct file *fp;
        int rc;
 
@@ -149,7 +150,8 @@ zfs_close(struct open_file *f)
 static int
 zfs_read(struct open_file *f, void *start, size_t size, size_t *resid  /* out 
*/)
 {
-       const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
+       struct devdesc *dev = f->f_devdata;
+       const spa_t *spa = ((struct zfsmount *)dev->d_opendata)->spa;
        struct file *fp = (struct file *)f->f_fsdata;
        struct stat sb;
        size_t n;
@@ -213,7 +215,8 @@ zfs_seek(struct open_file *f, off_t offset, int where)
 static int
 zfs_stat(struct open_file *f, struct stat *sb)
 {
-       const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
+       struct devdesc *dev = f->f_devdata;
+       const spa_t *spa = ((struct zfsmount *)dev->d_opendata)->spa;
        struct file *fp = (struct file *)f->f_fsdata;
 
        return (zfs_dnode_stat(spa, &fp->f_dnode, sb));
@@ -222,7 +225,8 @@ zfs_stat(struct open_file *f, struct stat *sb)
 static int
 zfs_readdir(struct open_file *f, struct dirent *d)
 {
-       const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
+       struct devdesc *dev = f->f_devdata;
+       const spa_t *spa = ((struct zfsmount *)dev->d_opendata)->spa;
        struct file *fp = (struct file *)f->f_fsdata;
        mzap_ent_phys_t mze;
        struct stat sb;
@@ -1586,8 +1590,7 @@ zfs_dev_open(struct open_file *f, ...)
                rv = zfs_mount(devformat(&dev->dd), NULL, (void **)&mount);
 
        if (rv == 0) {
-               f->f_devdata = mount;
-               free(dev);
+               dev->dd.d_opendata = mount;
        }
        return (rv);
 }
@@ -1595,25 +1598,18 @@ zfs_dev_open(struct open_file *f, ...)
 static int
 zfs_dev_close(struct open_file *f)
 {
+       struct devdesc *dev;
        struct zfsmount *mnt, *mount;
 
-       mnt = f->f_devdata;
+       dev = f->f_devdata;
+       mnt = dev->d_opendata;
 
        STAILQ_FOREACH(mount, &zfsmount, next) {
                if (mnt->spa->spa_guid == mount->spa->spa_guid)
                        break;
        }
 
-       /*
-        * devclose() will free f->f_devdata, but since we do have
-        * pointer to zfsmount structure in f->f_devdata, and
-        * zfs_unmount() will also free the zfsmount structure,
-        * we will get double free. To prevent double free,
-        * we must set f_devdata to NULL there.
-        */
-       if (mount != NULL)
-               f->f_devdata = NULL;
-
+       /* XXX */
        return (0);
 }
 

Reply via email to