loader: Add preload operation to fs_ops
When we load an ELF file (kernel or module) we do seek(2) a lot to parse/load the different sections of the ELF file. Protocol like TFTP suffers a lot from this as there is no resume or a way to start the tranfer from a specified offset in the file. fs_preload is added to help those protocol. Call preload just after opening the ELF file that we need to load so the underlying method can cache the hole file and then read/lseek operations are faster. Reviewed by: imp MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D33409
This commit is contained in:
parent
c5f24f5e0d
commit
c25d9aff46
@ -272,6 +272,7 @@ __elfN(load_elf_header)(char *filename, elf_file_t ef)
|
||||
close(ef->fd);
|
||||
return (ENOMEM);
|
||||
}
|
||||
preload(ef->fd);
|
||||
#ifdef LOADER_VERIEXEC_VECTX
|
||||
{
|
||||
int verror;
|
||||
|
@ -132,7 +132,7 @@ CLEANFILES+= ${SAFE_INCS} ${STAND_H_INC} ${OTHER_INC}
|
||||
|
||||
# io routines
|
||||
SRCS+= closeall.c dev.c ioctl.c nullfs.c stat.c mount.c \
|
||||
fstat.c close.c lseek.c open.c read.c write.c readdir.c
|
||||
fstat.c close.c lseek.c open.c read.c write.c readdir.c preload.c
|
||||
|
||||
# SMBios routines
|
||||
SRCS+= smbios.c
|
||||
|
45
stand/libsa/preload.c
Normal file
45
stand/libsa/preload.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*-
|
||||
* Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include "stand.h"
|
||||
|
||||
void
|
||||
preload(int fd)
|
||||
{
|
||||
struct open_file *f;
|
||||
|
||||
f = fd2open_file(fd);
|
||||
if (f == NULL) {
|
||||
errno = EBADF;
|
||||
return;
|
||||
}
|
||||
if (f->f_ops->fo_preload)
|
||||
(f->f_ops->fo_preload)(f);
|
||||
}
|
@ -111,6 +111,7 @@ struct fs_ops {
|
||||
off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
|
||||
int (*fo_stat)(struct open_file *f, struct stat *sb);
|
||||
int (*fo_readdir)(struct open_file *f, struct dirent *d);
|
||||
int (*fo_preload)(struct open_file *f);
|
||||
int (*fo_mount)(const char *, const char *, void **);
|
||||
int (*fo_unmount)(const char *, void *);
|
||||
};
|
||||
@ -300,6 +301,7 @@ extern void closeall(void);
|
||||
extern ssize_t read(int, void *, size_t);
|
||||
extern ssize_t write(int, const void *, size_t);
|
||||
extern struct dirent *readdirfd(int);
|
||||
extern void preload(int);
|
||||
|
||||
extern void srandom(unsigned int);
|
||||
extern long random(void);
|
||||
|
Loading…
Reference in New Issue
Block a user