From nobody Thu Jan 13 09:49:05 2022 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 9DD2112D1EF1; Thu, 13 Jan 2022 09:49:06 +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 4JZKQ96h3xz4j6J; Thu, 13 Jan 2022 09:49:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642067346; 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=vdsTjqVzJj3XtEok6kvvPME16y19bSFx30Ja7MA2vas=; b=AdT1uBpA/Sa53XWKqMTC1nhs2knqSicLAHBBYZplWMGnl6+/bxtZ9n0exw/PJmqJEHJLoL etOBiI6+qGez9gd+rPcOEKusj9OIfAcLadYv3nSsuOk5mY4cgswBnMBDhUi16CyhQzcaoX Kc40wCkKwkMemQn/mrgF70sLJ+6C7/Pl2atVdVPVpF49W9BktyzyFLglf2AjkzdQ8ayIJ0 XQ9Qm66Sl50MsnH3ypbwnvy/YCl/8sidiY1wPI5J1YMuRPcnVeqsB9WmJRuFy1ZpX12KMA 7yto1GwoK4S1DGBqYeQ3x5KxgcJj4K4mEs3cWf0m0tkFqD/5iqp/3exymfvATg== 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 A9FDE1E176; Thu, 13 Jan 2022 09:49:05 +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 20D9n5Yt095930; Thu, 13 Jan 2022 09:49:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20D9n540095929; Thu, 13 Jan 2022 09:49:05 GMT (envelope-from git) Date: Thu, 13 Jan 2022 09:49:05 GMT Message-Id: <202201130949.20D9n540095929@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 37e1449d29c8 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 37e1449d29c847bbbb5120774b2256362a2aabdd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642067346; 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=vdsTjqVzJj3XtEok6kvvPME16y19bSFx30Ja7MA2vas=; b=UGYu9VaDnVpfD2x0coiOJ1HvR2K1YNH0UmgfbGGCkeohEzO96dU7oSUeGpNTUstzHF+UYa bIjatznRE0j7FDzr6X35Ov2NDsg8DcMEtoML2+UgcJi+mXm8n7zYM8IjbrCyYRxdSlo1q+ /wspVAV1E37kiSU6i1GurpkAk6f+2ch9T5iVDvwdvhH0CDP2RezPNZCGF7PuVDpkcjcQxU 7EXnupIs/aIj1MHYYKAF9ovSEwlCfnDq9XW6NQiiI8syywUGKDFzp+/qgfhYjxvwmeNwi+ nSgfLFX3xt4MnthSoxpHn6g7Mek3e53pTY7lyLlVsLctQ4tlLDlzeYVgkdKUhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642067346; a=rsa-sha256; cv=none; b=hY6x4Lp4BTRop8dlptE2p6UckdYhoukUVXyGa9cyae9zkfdndAxXUJohcV3B2ulAO4uGlz 316nCSbH5adGkXw9VTZZ1gwX+Ze9qoxZeBwKynRkfuUruC9qAS7mW8ETFJ1GSejWxiyHYl gsTb8ivSuDLyfvAxQ6CI9XgtIRuSLzhNZI1qgrvbL29uIYxnFXbUuM9zfUJ9C6m3nC9tL6 30Spawr9JK3oVhs9ZAaSGgfTGVoAVaYyDZGHpJHcx/eC7EXCAl5SjiE1I+WQEN4kZla9Cc NeAkNi+UQefof6PuCiX0JmwypuJdViT05pi69cQDp115knL1+XLRTMuWukT70w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=37e1449d29c847bbbb5120774b2256362a2aabdd commit 37e1449d29c847bbbb5120774b2256362a2aabdd Author: Emmanuel Vadot AuthorDate: 2021-12-10 09:33:43 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-13 07:58:31 +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 (cherry picked from commit c25d9aff4607e7f1c378b0b7853e49c07c0af91a) --- 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 a213b34970f0..c75567b4a560 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -238,6 +238,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);