loader: do not try to open directories with TFTP
Attempting to mount or even open / with some tftp servers causes a several minute delay in boot. Since opening a directory via TFTP does not make sense, we avoid it. We don't know if using TFTP until after net_open() has been called. Add an is_tftp() accessor to avoid everyone having to include all the net* headers. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51447
This commit is contained in:
@@ -182,6 +182,7 @@ net_open(struct open_file *f, ...)
|
||||
setenv("boot.netif.mtu", mtu, 1);
|
||||
}
|
||||
|
||||
DEBUG_PRINTF(1,("%s: netproto=%d\n", __func__, netproto));
|
||||
}
|
||||
netdev_opens++;
|
||||
dev->d_opendata = &netdev_sock;
|
||||
@@ -193,7 +194,7 @@ net_close(struct open_file *f)
|
||||
{
|
||||
struct devdesc *dev;
|
||||
|
||||
DEBUG_PRINTF(1,("%s: opens=%d\n", __func__, netdev_opens));
|
||||
DEBUG_PRINTF(2,("%s: opens=%d\n", __func__, netdev_opens));
|
||||
|
||||
dev = f->f_devdata;
|
||||
dev->d_opendata = NULL;
|
||||
@@ -344,6 +345,12 @@ net_print(int verbose)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
bool
|
||||
is_tftp(void)
|
||||
{
|
||||
return (netproto == NET_TFTP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses the rootpath if present
|
||||
*
|
||||
|
||||
+4
-1
@@ -107,7 +107,10 @@ mount(const char *dev, const char *path, int flags __unused, void *data)
|
||||
fs = file_system[i];
|
||||
if (fs->fo_mount == NULL)
|
||||
continue;
|
||||
|
||||
DEBUG_PRINTF(1,("%s: fs=%s path=%s\n",
|
||||
__func__, fs->fs_name, path));
|
||||
if (is_tftp())
|
||||
break;
|
||||
if (fs->fo_mount(dev, path, &data) != 0)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -138,6 +138,8 @@ open(const char *fname, int mode)
|
||||
struct fs_ops *fs;
|
||||
struct open_file *f;
|
||||
int fd, i, error, besterror;
|
||||
bool is_dir;
|
||||
size_t n;
|
||||
const char *file;
|
||||
|
||||
TSENTER();
|
||||
@@ -182,8 +184,14 @@ open(const char *fname, int mode)
|
||||
|
||||
/* pass file name to the different filesystem open routines */
|
||||
besterror = ENOENT;
|
||||
n = strlen(file);
|
||||
is_dir = (n > 0 && file[n - 1] == '/');
|
||||
for (i = 0; file_system[i] != NULL; i++) {
|
||||
fs = file_system[i];
|
||||
if (is_dir && is_tftp()) {
|
||||
error = EOPNOTSUPP;
|
||||
goto err;
|
||||
}
|
||||
error = (fs->fo_open)(file, f);
|
||||
if (error == 0)
|
||||
goto ok;
|
||||
|
||||
@@ -507,6 +507,9 @@ extern void *reallocf(void *, size_t);
|
||||
*/
|
||||
caddr_t ptov(uintptr_t);
|
||||
|
||||
/* dev_net.c */
|
||||
bool is_tftp(void);
|
||||
|
||||
/* features.c */
|
||||
typedef void (feature_iter_fn)(void *, const char *, const char *, bool);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user