From nobody Thu Dec 16 10:53:24 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 C13D918F0FBD; Thu, 16 Dec 2021 10:53:25 +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 4JF89J5WV6z4fNq; Thu, 16 Dec 2021 10:53:24 +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 7C5ED2E5FC; Thu, 16 Dec 2021 10:53:24 +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 1BGArO5I091204; Thu, 16 Dec 2021 10:53:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BGArOqe091203; Thu, 16 Dec 2021 10:53:24 GMT (envelope-from git) Date: Thu, 16 Dec 2021 10:53:24 GMT Message-Id: <202112161053.1BGArOqe091203@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: 3eb019000c9e - main - loader: tftp: Add preload method 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: 3eb019000c9eba6dafad6741a88f627b4d4fcd8a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639652004; 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=gbukdSy4c8cXUIKavia+aDl11K77x8q88Tgv8F4914k=; b=PcklKnae5ErqYVlAeZEtOAk4fMUf3LuQH1f9Sg4wbzIZUkPTrF11G3siKIaXorRGdWleyn 6uz3YyLafBYc510w6uBYn95t0hg+ISiUy6vWYBgSpy+DFK2muFmB7GduPH0eX5qgFs81EU MeMJFbpJFbRdyokRdbvO75GkOeb6ZHs9/xE3Sif5wBjB/yGM5O2UfQASBphk68Z/NxfbPG h0hXYeQ9VzuHs+WFf3yTyIrKh8tkG1KstFIldRS52OBU/vWYMds62BIQtjfXs/18xCUJDx Bqy9ekcfagPtMmluv6qzetuWTJYvgdf25NIq8feak81QSaXuDTB0kw02ItFCRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639652004; a=rsa-sha256; cv=none; b=rNFpFyZRoYa/+y6HiRuwv7uqgqsdSjEX4TwL5+HeMonyAwi8dA2pbXR0J3z44uJcx6Wwxp U/kZ5Flg6QbvC23ErZJdBFdj2EQlIYp0a2R6EKScK/UmZLhWM4f+6GuvvlmAUI/7aFL6pt nkq/OJFWc1oBoKSN59tCSKqYjYUmn+ALN8GEpDMkYYRhl1WXzTC81q3zockHQEnPnS7wrS r5o62OY1V44OHmOyTNlmH+1UwW8D8LMnkwxY81sxl9JW0FYK5kzniTvSzJ+Qxpd3D3bRxN zymRAb/39KasvAabAkXjDSK15D3jr8vKjEJwwYIsDrAdiBPWFRz64zHJZwCu8Q== 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=3eb019000c9eba6dafad6741a88f627b4d4fcd8a commit 3eb019000c9eba6dafad6741a88f627b4d4fcd8a Author: Emmanuel Vadot AuthorDate: 2021-12-10 09:37:01 +0000 Commit: Emmanuel Vadot CommitDate: 2021-12-16 10:50:41 +0000 loader: tftp: Add preload method The preload method will transfer the whole file in a buffer and cache it so read/lseek operations are faster. Reviewed by: imp, tsoome MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D33410 --- stand/libsa/tftp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c index dcfce29a9968..9d1c70236925 100644 --- a/stand/libsa/tftp.c +++ b/stand/libsa/tftp.c @@ -73,6 +73,7 @@ static int tftp_read(struct open_file *, void *, size_t, size_t *); static off_t tftp_seek(struct open_file *, off_t, int); static int tftp_set_blksize(struct tftp_handle *, const char *); static int tftp_stat(struct open_file *, struct stat *); +static int tftp_preload(struct open_file *); struct fs_ops tftp_fsops = { .fs_name = "tftp", @@ -82,6 +83,7 @@ struct fs_ops tftp_fsops = { .fo_write = null_write, .fo_seek = tftp_seek, .fo_stat = tftp_stat, + .fo_preload = tftp_preload, .fo_readdir = null_readdir }; @@ -521,6 +523,16 @@ tftp_read(struct open_file *f, void *addr, size_t size, size = tftpfile->tftp_tsize - tftpfile->off; } + if (tftpfile->tftp_cache != NULL) { + bcopy(tftpfile->tftp_cache + tftpfile->off, + addr, size); + + addr = (char *)addr + size; + tftpfile->off += size; + res -= size; + goto out; + } + while (size > 0) { int needblock, count; @@ -586,6 +598,7 @@ tftp_read(struct open_file *f, void *addr, size_t size, } +out: if (resid != NULL) *resid = res; return (rc); @@ -603,6 +616,7 @@ tftp_close(struct open_file *f) if (tftpfile) { free(tftpfile->path); free(tftpfile->pkt); + free(tftpfile->tftp_cache); free(tftpfile); } is_open = 0; @@ -643,6 +657,52 @@ tftp_seek(struct open_file *f, off_t offset, int where) return (tftpfile->off); } +static int +tftp_preload(struct open_file *f) +{ + struct tftp_handle *tftpfile; + char *cache; + int rc; +#ifdef TFTP_DEBUG + time_t start, end; +#endif + + tftpfile = f->f_fsdata; + cache = malloc(sizeof(char) * tftpfile->tftp_tsize); + if (cache == NULL) { + printf("Couldn't allocate %ju bytes for preload caching" + ", disabling caching\n", + (uintmax_t)sizeof(char) * tftpfile->tftp_tsize); + return (-1); + } + +#ifdef TFTP_DEBUG + start = getsecs(); + printf("Preloading %s ", tftpfile->path); +#endif + while (tftpfile->islastblock == 0) { + twiddle(32); + rc = tftp_getnextblock(tftpfile); + if (rc) { + free(cache); + printf("Got TFTP error %d, disabling caching\n", rc); + return (rc); + } + bcopy(tftpfile->tftp_hdr->th_data, + cache + (tftpfile->tftp_blksize * (tftpfile->currblock - 1)), + tftpfile->validsize); + } +#ifdef TFTP_DEBUG + end = getsecs(); + printf("\nPreloaded %s (%ju bytes) during %jd seconds\n", + tftpfile->path, (intmax_t)tftpfile->tftp_tsize, + (intmax_t)end - start); +#endif + + tftpfile->tftp_cache = cache; + return (0); +} + static int tftp_set_blksize(struct tftp_handle *h, const char *str) {