loader: net_open() should not replace f->f_devdata
net_open() does replace f_devdata with pointer to netdev_sock, this will cause memory leak when device is closed, but also does alter the devopen() logic. We should store &netdev_sock to dev->d_opendata instead, this would preserve and follow the devopen() logic. Fixes network boot on aarch64 (tested by bz). Reviewed-by: imp MFC After: 2 weeks Differential Revision: https://reviews.freebsd.org/D32227
This commit is contained in:
parent
bcd4c17cca
commit
98e805b4a1
@ -114,7 +114,7 @@ net_init(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Called by devopen after it sets f->f_dev to our devsw entry.
|
* Called by devopen after it sets f->f_dev to our devsw entry.
|
||||||
* This opens the low-level device and sets f->f_devdata.
|
* This opens the low-level device and sets dev->d_opendata.
|
||||||
* This is declared with variable arguments...
|
* This is declared with variable arguments...
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
@ -193,20 +193,22 @@ net_open(struct open_file *f, ...)
|
|||||||
|
|
||||||
}
|
}
|
||||||
netdev_opens++;
|
netdev_opens++;
|
||||||
f->f_devdata = &netdev_sock;
|
dev->d_opendata = &netdev_sock;
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
net_close(struct open_file *f)
|
net_close(struct open_file *f)
|
||||||
{
|
{
|
||||||
|
struct devdesc *dev;
|
||||||
|
|
||||||
#ifdef NETIF_DEBUG
|
#ifdef NETIF_DEBUG
|
||||||
if (debug)
|
if (debug)
|
||||||
printf("%s: opens=%d\n", __func__, netdev_opens);
|
printf("%s: opens=%d\n", __func__, netdev_opens);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
f->f_devdata = NULL;
|
dev = f->f_devdata;
|
||||||
|
dev->d_opendata = NULL;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -464,6 +464,7 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len)
|
|||||||
int
|
int
|
||||||
nfs_open(const char *upath, struct open_file *f)
|
nfs_open(const char *upath, struct open_file *f)
|
||||||
{
|
{
|
||||||
|
struct devdesc *dev;
|
||||||
struct iodesc *desc;
|
struct iodesc *desc;
|
||||||
struct nfs_iodesc *currfd = NULL;
|
struct nfs_iodesc *currfd = NULL;
|
||||||
char buf[2 * NFS_V3MAXFHSIZE + 3];
|
char buf[2 * NFS_V3MAXFHSIZE + 3];
|
||||||
@ -484,6 +485,7 @@ nfs_open(const char *upath, struct open_file *f)
|
|||||||
if (netproto != NET_NFS)
|
if (netproto != NET_NFS)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
|
dev = f->f_devdata;
|
||||||
#ifdef NFS_DEBUG
|
#ifdef NFS_DEBUG
|
||||||
if (debug)
|
if (debug)
|
||||||
printf("nfs_open: %s (rootip=%s rootpath=%s)\n", upath,
|
printf("nfs_open: %s (rootip=%s rootpath=%s)\n", upath,
|
||||||
@ -497,7 +499,7 @@ nfs_open(const char *upath, struct open_file *f)
|
|||||||
if (f->f_dev->dv_type != DEVT_NET)
|
if (f->f_dev->dv_type != DEVT_NET)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
if (!(desc = socktodesc(*(int *)(f->f_devdata))))
|
if (!(desc = socktodesc(*(int *)(dev->d_opendata))))
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
/* Bind to a reserved port. */
|
/* Bind to a reserved port. */
|
||||||
|
@ -37,7 +37,8 @@ __FBSDID("$FreeBSD$");
|
|||||||
/*
|
/*
|
||||||
* Simple TFTP implementation for libsa.
|
* Simple TFTP implementation for libsa.
|
||||||
* Assumes:
|
* Assumes:
|
||||||
* - socket descriptor (int) at open_file->f_devdata
|
* - socket descriptor (int) at dev->d_opendata, dev stored at
|
||||||
|
* open_file->f_devdata
|
||||||
* - server host IP in global rootip
|
* - server host IP in global rootip
|
||||||
* Restrictions:
|
* Restrictions:
|
||||||
* - read only
|
* - read only
|
||||||
@ -432,6 +433,7 @@ tftp_getnextblock(struct tftp_handle *h)
|
|||||||
static int
|
static int
|
||||||
tftp_open(const char *path, struct open_file *f)
|
tftp_open(const char *path, struct open_file *f)
|
||||||
{
|
{
|
||||||
|
struct devdesc *dev;
|
||||||
struct tftp_handle *tftpfile;
|
struct tftp_handle *tftpfile;
|
||||||
struct iodesc *io;
|
struct iodesc *io;
|
||||||
int res;
|
int res;
|
||||||
@ -452,7 +454,8 @@ tftp_open(const char *path, struct open_file *f)
|
|||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
|
|
||||||
tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE;
|
tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE;
|
||||||
tftpfile->iodesc = io = socktodesc(*(int *)(f->f_devdata));
|
dev = f->f_devdata;
|
||||||
|
tftpfile->iodesc = io = socktodesc(*(int *)(dev->d_opendata));
|
||||||
if (io == NULL) {
|
if (io == NULL) {
|
||||||
free(tftpfile);
|
free(tftpfile);
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user