From nobody Thu Dec 16 10:53:23 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F213818F0EC9; Thu, 16 Dec 2021 10:53:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JF89H5R9kz4fWT; Thu, 16 Dec 2021 10:53:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4E2602E5FB; Thu, 16 Dec 2021 10:53:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BGArNth091173; Thu, 16 Dec 2021 10:53:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BGArNkx091172; Thu, 16 Dec 2021 10:53:23 GMT (envelope-from git) Date: Thu, 16 Dec 2021 10:53:23 GMT Message-Id: <202112161053.1BGArNkx091172@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: c25d9aff4607 - main - loader: Add preload operation to fs_ops List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c25d9aff4607e7f1c378b0b7853e49c07c0af91a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639652003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k0AwnzC4dfb+o6Ctqs7tETaVCUW0Eykfelbj1xN83w0=; b=qCWkW3MuGVnY6nA+fTtZbuMpEJSrEbcAall4P2Pt6RXL/VALekSIzyUWceYHD0amUIgZP+ mFXNt9y+NYF9o8Csia2LY2O4iUWfblKXAFGPhPwo1LaBQmcF67GhS+kxK1ICoaGka6dj+q CvUpbOMBlot/ukLJKXWwIqR4FP35Tw9F3KuWqtmkF5R1KHKR3IHE+R7wJVs4D7iYZsZNmC U4cUIsy6fcq5OULRODkiQIDa0EmnP1Z3Z0YHC3WCrl8P3s/eJwlFdyTRI8YphnRQX6U41W g2M2MUrMzTorrsMjn3qLwslC0iyPpLCYMs+6FdhnXP/hVbPKj67yHXu6rCXfeg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639652003; a=rsa-sha256; cv=none; b=p1Aq0ko0/OPVlPmC6HCmRg4QOjXJaAozDaAiiHl3jpIxIYMn1sCcs14gSu0A2LZ/avD6jT IfvYxx4wXgCEHhpi4yFRgvTATztT3zx/+7NCGKT+fTWfMO1fGOK0ORzAPndCA6/faTCN10 Wtfw1TDiUMb2tVLsokyznajrRBuj66j0WNqDN/WUDfiipf+g9Kx68OdPLurQb8Sw7Iw8s5 JmEdBj6dxmzlgnzyIjbKrIe9d78vLZmKSqHsPQydO43J0wkgxN5hYZq4kzfF3enkNvXxPM HsYTNeHW2hgDlb6RCy6b1qhrHQma+lelgqBIhA1a76RIqj5rclG0/VjTvaw3BA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=c25d9aff4607e7f1c378b0b7853e49c07c0af91a commit c25d9aff4607e7f1c378b0b7853e49c07c0af91a Author: Emmanuel Vadot AuthorDate: 2021-12-10 09:33:43 +0000 Commit: Emmanuel Vadot CommitDate: 2021-12-16 10:50:38 +0000 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 --- stand/common/load_elf.c | 1 + stand/libsa/Makefile | 2 +- stand/libsa/preload.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ stand/libsa/stand.h | 2 ++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/stand/common/load_elf.c b/stand/common/load_elf.c index 4ac4248a4e97..8cbbe54b49d4 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -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; diff --git a/stand/libsa/Makefile b/stand/libsa/Makefile index 6fe145d681db..6ac1d900104e 100644 --- a/stand/libsa/Makefile +++ b/stand/libsa/Makefile @@ -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 diff --git a/stand/libsa/preload.c b/stand/libsa/preload.c new file mode 100644 index 000000000000..3d41101dc861 --- /dev/null +++ b/stand/libsa/preload.c @@ -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 +__FBSDID("$FreeBSD$"); + +#include +#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); +} diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h index ab0961b77086..172b54c33b30 100644 --- a/stand/libsa/stand.h +++ b/stand/libsa/stand.h @@ -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);