From patchwork Mon Jan 15 12:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1886643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=ZTc0xCaT; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=W6jny1b+; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=ffT9+otB; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Wi4iWWQ6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TDBsh5Y6bz1yPJ for ; Mon, 15 Jan 2024 23:54:00 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A5BF63CE361 for ; Mon, 15 Jan 2024 13:53:58 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 942413CCC5B for ; Mon, 15 Jan 2024 13:53:25 +0100 (CET) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=2a07:de40:b251:101:10:150:64:2; helo=smtp-out2.suse.de; envelope-from=chrubis@suse.cz; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id B914D1A00FA6 for ; Mon, 15 Jan 2024 13:53:24 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E342F1F88D; Mon, 15 Jan 2024 12:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5gkor1SgtarxMZ+Qt7npFY955J36ZrdC1eGTk8xoP3Y=; b=ZTc0xCaTaARAQJfMR1tMORP3/IxakuGXAsZeiat5yXtI1rHp81RcyS1Tuhy9pwwA5M8ZTc QmlSoJNTIlaO6awQP/icTLiEzDaI2o30WizjYADFqwwbcZ5Mb1gYwBBhMuViZtrYJqEQqH j4I/rCBk1p5VJ+r1Xn1MNpuBHvUEfUA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5gkor1SgtarxMZ+Qt7npFY955J36ZrdC1eGTk8xoP3Y=; b=W6jny1b+QFlMMHnmxipjP2hq1F3dhWNJU7+gevhbMzMOX89yrarXPvFlFI5cCd/DlN/s8j tPNWYFLERf+MV4Dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323203; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5gkor1SgtarxMZ+Qt7npFY955J36ZrdC1eGTk8xoP3Y=; b=ffT9+otBjw7gbsyQJMvjq36r5L01I85UCuPEiakoqlv5JcGHkpg0KfoxAxz4juiVrzDQBa T7yxyjXLr3oNVRRGMXCK9j7/3VKpE3T0Rl5nOLgHVhBsRyPGAP43RMy34M24lIywqVGAl/ ShNUa3v5vNqwbB8W1awYhwAlNSiID2A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323203; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5gkor1SgtarxMZ+Qt7npFY955J36ZrdC1eGTk8xoP3Y=; b=Wi4iWWQ6bvLgHDUNEbUNU8YrkDSG69FOfR0o70I0kBUt85O/9PdTqAqPmOifCWwFHWk0Fn 5/oEie/JOgLpuJBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D26AA13751; Mon, 15 Jan 2024 12:53:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6+FpMsMqpWWRVQAAD6G6ig (envelope-from ); Mon, 15 Jan 2024 12:53:23 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Mon, 15 Jan 2024 13:53:48 +0100 Message-ID: <20240115125351.7266-2-chrubis@suse.cz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115125351.7266-1-chrubis@suse.cz> References: <20240115125351.7266-1-chrubis@suse.cz> MIME-Version: 1.0 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ffT9+otB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Wi4iWWQ6 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FREEMAIL_CC(0.00)[infradead.org,gmail.com,redhat.com,kernel.org,zeniv.linux.org.uk,suse.cz,vger.kernel.org,suse.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 0.49 X-Rspamd-Queue-Id: E342F1F88D X-Virus-Scanned: clamav-milter 1.0.3 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mszeredi@redhat.com, brauner@kernel.org, Jan Kara , Matthew Wilcox , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Which allows tests to loop over different types of file descriptors Signed-off-by: Cyril Hrubis Reviewed-by: Richard Palethorpe Reviewed-by: Petr Vorel --- include/tst_fd.h | 61 +++++++++ include/tst_test.h | 1 + lib/tst_fd.c | 325 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 include/tst_fd.h create mode 100644 lib/tst_fd.c diff --git a/include/tst_fd.h b/include/tst_fd.h new file mode 100644 index 000000000..2183ea068 --- /dev/null +++ b/include/tst_fd.h @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (C) 2023 Cyril Hrubis + */ + +#ifndef TST_FD_H__ +#define TST_FD_H__ + +enum tst_fd_type { + TST_FD_FILE, + TST_FD_PATH, + TST_FD_DIR, + TST_FD_DEV_ZERO, + TST_FD_PROC_MAPS, + TST_FD_PIPE_READ, + TST_FD_PIPE_WRITE, + TST_FD_UNIX_SOCK, + TST_FD_INET_SOCK, + TST_FD_EPOLL, + TST_FD_EVENTFD, + TST_FD_SIGNALFD, + TST_FD_TIMERFD, + TST_FD_PIDFD, + TST_FD_FANOTIFY, + TST_FD_INOTIFY, + TST_FD_USERFAULTFD, + TST_FD_PERF_EVENT, + TST_FD_IO_URING, + TST_FD_BPF_MAP, + TST_FD_FSOPEN, + TST_FD_FSPICK, + TST_FD_OPEN_TREE, + TST_FD_MEMFD, + TST_FD_MEMFD_SECRET, + TST_FD_MAX, +}; + +struct tst_fd { + enum tst_fd_type type; + int fd; + /* used by the library, do not touch! */ + long priv; +}; + +#define TST_FD_INIT {.type = TST_FD_FILE, .fd = -1} + +/* + * Advances the iterator to the next fd type, returns zero at the end. + */ +int tst_fd_next(struct tst_fd *fd); + +#define TST_FD_FOREACH(fd) \ + for (struct tst_fd fd = TST_FD_INIT; tst_fd_next(&fd); ) + +/* + * Returns human readable name for the file descriptor type. + */ +const char *tst_fd_desc(struct tst_fd *fd); + +#endif /* TST_FD_H__ */ diff --git a/include/tst_test.h b/include/tst_test.h index 0c3171e5b..fda696eeb 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -44,6 +44,7 @@ #include "tst_taint.h" #include "tst_memutils.h" #include "tst_arch.h" +#include "tst_fd.h" /* * Reports testcase result. diff --git a/lib/tst_fd.c b/lib/tst_fd.c new file mode 100644 index 000000000..b0d6fb1d6 --- /dev/null +++ b/lib/tst_fd.c @@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (C) 2023 Cyril Hrubis + */ + +#define TST_NO_DEFAULT_MAIN + +#include +#include +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "tst_safe_macros.h" + +#include "lapi/pidfd.h" +#include "lapi/io_uring.h" +#include "lapi/bpf.h" +#include "lapi/fsmount.h" + +#include "tst_fd.h" + +struct tst_fd_desc { + void (*open_fd)(struct tst_fd *fd); + void (*destroy)(struct tst_fd *fd); + const char *desc; +}; + +static void open_file(struct tst_fd *fd) +{ + fd->fd = SAFE_OPEN("fd_file", O_RDWR | O_CREAT, 0666); + SAFE_UNLINK("fd_file"); +} + +static void open_path(struct tst_fd *fd) +{ + int tfd; + + tfd = SAFE_CREAT("fd_file", 0666); + SAFE_CLOSE(tfd); + + fd->fd = SAFE_OPEN("fd_file", O_PATH); + + SAFE_UNLINK("fd_file"); +} + +static void open_dir(struct tst_fd *fd) +{ + SAFE_MKDIR("fd_dir", 0700); + fd->fd = SAFE_OPEN("fd_dir", O_DIRECTORY); + SAFE_RMDIR("fd_dir"); +} + +static void open_dev_zero(struct tst_fd *fd) +{ + fd->fd = SAFE_OPEN("/dev/zero", O_RDONLY); +} + +static void open_proc_self_maps(struct tst_fd *fd) +{ + fd->fd = SAFE_OPEN("/proc/self/maps", O_RDONLY); +} + +static void open_pipe_read(struct tst_fd *fd) +{ + int pipe[2]; + + SAFE_PIPE(pipe); + fd->fd = pipe[0]; + fd->priv = pipe[1]; +} + +static void open_pipe_write(struct tst_fd *fd) +{ + int pipe[2]; + + SAFE_PIPE(pipe); + fd->fd = pipe[1]; + fd->priv = pipe[0]; +} + +static void destroy_pipe(struct tst_fd *fd) +{ + SAFE_CLOSE(fd->priv); +} + +static void open_unix_sock(struct tst_fd *fd) +{ + fd->fd = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0); +} + +static void open_inet_sock(struct tst_fd *fd) +{ + fd->fd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0); +} + +static void open_epoll(struct tst_fd *fd) +{ + fd->fd = epoll_create(1); + + if (fd->fd < 0) + tst_brk(TBROK | TERRNO, "epoll_create()"); +} + +static void open_eventfd(struct tst_fd *fd) +{ + fd->fd = eventfd(0, 0); + + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_signalfd(struct tst_fd *fd) +{ + sigset_t sfd_mask; + sigemptyset(&sfd_mask); + + fd->fd = signalfd(-1, &sfd_mask, 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_timerfd(struct tst_fd *fd) +{ + fd->fd = timerfd_create(CLOCK_REALTIME, 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_pidfd(struct tst_fd *fd) +{ + fd->fd = pidfd_open(getpid(), 0); + if (fd->fd < 0) + tst_brk(TBROK | TERRNO, "pidfd_open()"); +} + +static void open_fanotify(struct tst_fd *fd) +{ + fd->fd = fanotify_init(FAN_CLASS_NOTIF, O_RDONLY); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_inotify(struct tst_fd *fd) +{ + fd->fd = inotify_init(); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_userfaultfd(struct tst_fd *fd) +{ + fd->fd = syscall(__NR_userfaultfd, 0); + + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_perf_event(struct tst_fd *fd) +{ + struct perf_event_attr pe_attr = { + .type = PERF_TYPE_SOFTWARE, + .size = sizeof(struct perf_event_attr), + .config = PERF_COUNT_SW_CPU_CLOCK, + .disabled = 1, + .exclude_kernel = 1, + .exclude_hv = 1, + }; + + fd->fd = syscall(__NR_perf_event_open, &pe_attr, 0, -1, -1, 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_io_uring(struct tst_fd *fd) +{ + struct io_uring_params uring_params = {}; + + fd->fd = io_uring_setup(1, &uring_params); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_bpf_map(struct tst_fd *fd) +{ + union bpf_attr array_attr = { + .map_type = BPF_MAP_TYPE_ARRAY, + .key_size = 4, + .value_size = 8, + .max_entries = 1, + }; + + fd->fd = bpf(BPF_MAP_CREATE, &array_attr, sizeof(array_attr)); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_fsopen(struct tst_fd *fd) +{ + fd->fd = fsopen("ext2", 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_fspick(struct tst_fd *fd) +{ + fd->fd = fspick(AT_FDCWD, "/", 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_open_tree(struct tst_fd *fd) +{ + fd->fd = open_tree(AT_FDCWD, "/", 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_memfd(struct tst_fd *fd) +{ + fd->fd = syscall(__NR_memfd_create, "ltp_memfd", 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_memfd_secret(struct tst_fd *fd) +{ + fd->fd = syscall(__NR_memfd_secret, 0); + if (fd->fd < 0) { + tst_res(TCONF | TERRNO, + "Skipping %s", tst_fd_desc(fd)); + } +} + +static struct tst_fd_desc fd_desc[] = { + [TST_FD_FILE] = {.open_fd = open_file, .desc = "file"}, + [TST_FD_PATH] = {.open_fd = open_path, .desc = "O_PATH file"}, + [TST_FD_DIR] = {.open_fd = open_dir, .desc = "directory"}, + [TST_FD_DEV_ZERO] = {.open_fd = open_dev_zero, .desc = "/dev/zero"}, + [TST_FD_PROC_MAPS] = {.open_fd = open_proc_self_maps, .desc = "/proc/self/maps"}, + [TST_FD_PIPE_READ] = {.open_fd = open_pipe_read, .desc = "pipe read end", .destroy = destroy_pipe}, + [TST_FD_PIPE_WRITE] = {.open_fd = open_pipe_write, .desc = "pipe write end", .destroy = destroy_pipe}, + [TST_FD_UNIX_SOCK] = {.open_fd = open_unix_sock, .desc = "unix socket"}, + [TST_FD_INET_SOCK] = {.open_fd = open_inet_sock, .desc = "inet socket"}, + [TST_FD_EPOLL] = {.open_fd = open_epoll, .desc = "epoll"}, + [TST_FD_EVENTFD] = {.open_fd = open_eventfd, .desc = "eventfd"}, + [TST_FD_SIGNALFD] = {.open_fd = open_signalfd, .desc = "signalfd"}, + [TST_FD_TIMERFD] = {.open_fd = open_timerfd, .desc = "timerfd"}, + [TST_FD_PIDFD] = {.open_fd = open_pidfd, .desc = "pidfd"}, + [TST_FD_FANOTIFY] = {.open_fd = open_fanotify, .desc = "fanotify"}, + [TST_FD_INOTIFY] = {.open_fd = open_inotify, .desc = "inotify"}, + [TST_FD_USERFAULTFD] = {.open_fd = open_userfaultfd, .desc = "userfaultfd"}, + [TST_FD_PERF_EVENT] = {.open_fd = open_perf_event, .desc = "perf event"}, + [TST_FD_IO_URING] = {.open_fd = open_io_uring, .desc = "io uring"}, + [TST_FD_BPF_MAP] = {.open_fd = open_bpf_map, .desc = "bpf map"}, + [TST_FD_FSOPEN] = {.open_fd = open_fsopen, .desc = "fsopen"}, + [TST_FD_FSPICK] = {.open_fd = open_fspick, .desc = "fspick"}, + [TST_FD_OPEN_TREE] = {.open_fd = open_open_tree, .desc = "open_tree"}, + [TST_FD_MEMFD] = {.open_fd = open_memfd, .desc = "memfd"}, + [TST_FD_MEMFD_SECRET] = {.open_fd = open_memfd_secret, .desc = "memfd secret"}, +}; + +const char *tst_fd_desc(struct tst_fd *fd) +{ + if (fd->type >= ARRAY_SIZE(fd_desc)) + return "invalid"; + + return fd_desc[fd->type].desc; +} + +int tst_fd_next(struct tst_fd *fd) +{ + size_t len = ARRAY_SIZE(fd_desc); + + if (fd->fd >= 0) { + SAFE_CLOSE(fd->fd); + + if (fd_desc[fd->type].destroy) + fd_desc[fd->type].destroy(fd); + + fd->type++; + } + + for (;;) { + if (fd->type >= len) + return 0; + + fd_desc[fd->type].open_fd(fd); + + if (fd->fd >= 0) + return 1; + + fd->type++; + } +} From patchwork Mon Jan 15 12:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1886642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=A1hsaWif; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EyRfBf4w; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=A1hsaWif; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EyRfBf4w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TDBsP6kg6z1yPJ for ; Mon, 15 Jan 2024 23:53:45 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B3C153CE341 for ; Mon, 15 Jan 2024 13:53:43 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5B2D43CCC5B for ; Mon, 15 Jan 2024 13:53:25 +0100 (CET) Authentication-Results: in-5.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=chrubis@suse.cz; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id C76D160067A for ; Mon, 15 Jan 2024 13:53:24 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4788F1FD35; Mon, 15 Jan 2024 12:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RqIxisi1ENpcSL7QO9oW3ccJ2h4qZHc+yC8fSbxoqpA=; b=A1hsaWif6ZMQqV7F4e1aOUjHOHgrzQmlT+Rz1Tr8P42MXyHOf5qZRq6xv9AYciWw66rhuv ZDwM7CSDNn2sRZzVlJh3znQ8T1QbfPSE9Hd/j1DGFL3uxsg0aGweFvM53Z5qgdGEHJOjq/ FmD6Q/RQSqnWPb8OXu5DW/+uLjbT+zk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RqIxisi1ENpcSL7QO9oW3ccJ2h4qZHc+yC8fSbxoqpA=; b=EyRfBf4wnZCuNP7wQO4LIYYdF7FYlKeVsOEYaqkfvP35huMOQ99HWLG9MLw/pPPZqJv5CO wiKtjhC/WO3SZzBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RqIxisi1ENpcSL7QO9oW3ccJ2h4qZHc+yC8fSbxoqpA=; b=A1hsaWif6ZMQqV7F4e1aOUjHOHgrzQmlT+Rz1Tr8P42MXyHOf5qZRq6xv9AYciWw66rhuv ZDwM7CSDNn2sRZzVlJh3znQ8T1QbfPSE9Hd/j1DGFL3uxsg0aGweFvM53Z5qgdGEHJOjq/ FmD6Q/RQSqnWPb8OXu5DW/+uLjbT+zk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RqIxisi1ENpcSL7QO9oW3ccJ2h4qZHc+yC8fSbxoqpA=; b=EyRfBf4wnZCuNP7wQO4LIYYdF7FYlKeVsOEYaqkfvP35huMOQ99HWLG9MLw/pPPZqJv5CO wiKtjhC/WO3SZzBQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3A18C13751; Mon, 15 Jan 2024 12:53:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 7OAkDcQqpWWTVQAAD6G6ig (envelope-from ); Mon, 15 Jan 2024 12:53:24 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Mon, 15 Jan 2024 13:53:49 +0100 Message-ID: <20240115125351.7266-3-chrubis@suse.cz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115125351.7266-1-chrubis@suse.cz> References: <20240115125351.7266-1-chrubis@suse.cz> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=A1hsaWif; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=EyRfBf4w X-Spamd-Result: default: False [4.69 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[infradead.org,gmail.com,redhat.com,kernel.org,zeniv.linux.org.uk,suse.cz,vger.kernel.org,suse.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 4.69 X-Rspamd-Queue-Id: 4788F1FD35 X-Spamd-Bar: ++++ X-Virus-Scanned: clamav-milter 1.0.3 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/4] syscalls: readahead01: Make use of tst_fd X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mszeredi@redhat.com, brauner@kernel.org, Jan Kara , Matthew Wilcox , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis Reviewed-by: Richard Palethorpe Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- .../kernel/syscalls/readahead/readahead01.c | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c index bdef7945d..e86a73e3e 100644 --- a/testcases/kernel/syscalls/readahead/readahead01.c +++ b/testcases/kernel/syscalls/readahead/readahead01.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. + * Copyright (C) 2023-2024 Cyril Hrubis */ /*\ @@ -30,43 +31,44 @@ static void test_bad_fd(void) { - char tempname[PATH_MAX] = "readahead01_XXXXXX"; - int fd; + int fd[2]; + + TST_EXP_FAIL(readahead(-1, 0, getpagesize()), EBADF, + "readahead() with fd = -1"); - tst_res(TINFO, "%s -1", __func__); - TST_EXP_FAIL(readahead(-1, 0, getpagesize()), EBADF); + SAFE_PIPE(fd); + SAFE_CLOSE(fd[0]); + SAFE_CLOSE(fd[1]); - tst_res(TINFO, "%s O_WRONLY", __func__); - fd = mkstemp(tempname); - if (fd == -1) - tst_res(TFAIL | TERRNO, "mkstemp failed"); - SAFE_CLOSE(fd); - fd = SAFE_OPEN(tempname, O_WRONLY); - TST_EXP_FAIL(readahead(fd, 0, getpagesize()), EBADF); - SAFE_CLOSE(fd); - unlink(tempname); + TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EBADF, + "readahead() with invalid fd"); } -static void test_invalid_fd(void) +static void test_invalid_fd(struct tst_fd *fd) { - int fd[2]; - tst_res(TINFO, "%s pipe", __func__); - SAFE_PIPE(fd); - TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL); - SAFE_CLOSE(fd[0]); - SAFE_CLOSE(fd[1]); + switch (fd->type) { + /* These succeed */ + case TST_FD_FILE: + case TST_FD_MEMFD: + case TST_FD_PROC_MAPS: + return; + default: + break; + } - tst_res(TINFO, "%s socket", __func__); - fd[0] = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0); - TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL); - SAFE_CLOSE(fd[0]); + int exp_errnos[] = {EBADF, EINVAL, ESPIPE}; + + TST_EXP_FAIL_ARR(readahead(fd->fd, 0, getpagesize()), exp_errnos, + "readahead() on %s", tst_fd_desc(fd)); } static void test_readahead(void) { test_bad_fd(); - test_invalid_fd(); + + TST_FD_FOREACH(fd) + test_invalid_fd(&fd); } static void setup(void) From patchwork Mon Jan 15 12:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1886644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=YOOApOhS; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UQm8Gjnw; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=YOOApOhS; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UQm8Gjnw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TDBt76BXWz1yPJ for ; Mon, 15 Jan 2024 23:54:23 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EB39F3CE367 for ; Mon, 15 Jan 2024 13:54:21 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A71283CCDE0 for ; Mon, 15 Jan 2024 13:53:25 +0100 (CET) Authentication-Results: in-4.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=chrubis@suse.cz; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 3A8DB1000525 for ; Mon, 15 Jan 2024 13:53:25 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A37B0221BD; Mon, 15 Jan 2024 12:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GO3raBL7YpNcPZiGs4WewFSU9rocqghd8EDtC6wQ3tk=; b=YOOApOhSCvpXzGX5LWwT3WkCovtlyD1MJZTch5p9qcYSWEqojpmIxMt2r/jBA0uohLkZTQ Xk7lchQ8hB1Bo8X62JjHrM31yg2sHEqx6WwOdLGEluTtrMudV/5QYB8xn3VcpPs8n385Lm jx3kDO8J0r1rSEEajZLCKARQhNRaYI0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GO3raBL7YpNcPZiGs4WewFSU9rocqghd8EDtC6wQ3tk=; b=UQm8GjnwFxuw+9b7VLAfO0vovtpsG172LfzLgmhey4KYhhiJDXyqRUsqvI0sjBHd6Uel0Y Jmqm7li1P+YigRCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GO3raBL7YpNcPZiGs4WewFSU9rocqghd8EDtC6wQ3tk=; b=YOOApOhSCvpXzGX5LWwT3WkCovtlyD1MJZTch5p9qcYSWEqojpmIxMt2r/jBA0uohLkZTQ Xk7lchQ8hB1Bo8X62JjHrM31yg2sHEqx6WwOdLGEluTtrMudV/5QYB8xn3VcpPs8n385Lm jx3kDO8J0r1rSEEajZLCKARQhNRaYI0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323204; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GO3raBL7YpNcPZiGs4WewFSU9rocqghd8EDtC6wQ3tk=; b=UQm8GjnwFxuw+9b7VLAfO0vovtpsG172LfzLgmhey4KYhhiJDXyqRUsqvI0sjBHd6Uel0Y Jmqm7li1P+YigRCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9216613751; Mon, 15 Jan 2024 12:53:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id NmatIsQqpWWWVQAAD6G6ig (envelope-from ); Mon, 15 Jan 2024 12:53:24 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Mon, 15 Jan 2024 13:53:50 +0100 Message-ID: <20240115125351.7266-4-chrubis@suse.cz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115125351.7266-1-chrubis@suse.cz> References: <20240115125351.7266-1-chrubis@suse.cz> MIME-Version: 1.0 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=YOOApOhS; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=UQm8Gjnw X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; R_RATELIMIT(0.00)[to_ip_from(RLuggmp1sxrj4d1wjxmfchp9q5)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[9]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[infradead.org,gmail.com,redhat.com,kernel.org,zeniv.linux.org.uk,suse.cz,vger.kernel.org,suse.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 0.49 X-Rspamd-Queue-Id: A37B0221BD X-Virus-Scanned: clamav-milter 1.0.3 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/4] syscalls: accept: Add tst_fd test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mszeredi@redhat.com, brauner@kernel.org, Jan Kara , Matthew Wilcox , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis Reviewed-by: Richard Palethorpe Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- runtest/syscalls | 1 + testcases/kernel/syscalls/accept/.gitignore | 1 + testcases/kernel/syscalls/accept/accept01.c | 8 --- testcases/kernel/syscalls/accept/accept03.c | 60 +++++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 testcases/kernel/syscalls/accept/accept03.c diff --git a/runtest/syscalls b/runtest/syscalls index 8216d86b0..5472c954b 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -3,6 +3,7 @@ abort01 abort01 accept01 accept01 accept02 accept02 +accept03 accept03 accept4_01 accept4_01 diff --git a/testcases/kernel/syscalls/accept/.gitignore b/testcases/kernel/syscalls/accept/.gitignore index 5b1462699..f81d4bec9 100644 --- a/testcases/kernel/syscalls/accept/.gitignore +++ b/testcases/kernel/syscalls/accept/.gitignore @@ -1,2 +1,3 @@ /accept01 /accept02 +/accept03 diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c index 85af0f8af..e5db1dfec 100644 --- a/testcases/kernel/syscalls/accept/accept01.c +++ b/testcases/kernel/syscalls/accept/accept01.c @@ -26,7 +26,6 @@ struct sockaddr_in sin0, sin1, fsin1; int invalid_socketfd = 400; /* anything that is not an open file */ -int devnull_fd; int socket_fd; int udp_fd; @@ -45,10 +44,6 @@ static struct test_case { (struct sockaddr *)&fsin1, sizeof(fsin1), EBADF, "bad file descriptor" }, - { - PF_INET, SOCK_STREAM, 0, &devnull_fd, (struct sockaddr *)&fsin1, - sizeof(fsin1), ENOTSOCK, "fd is not socket" - }, { PF_INET, SOCK_STREAM, 0, &socket_fd, (struct sockaddr *)3, sizeof(fsin1), EINVAL, "invalid socket buffer" @@ -73,8 +68,6 @@ static void test_setup(void) sin0.sin_port = 0; sin0.sin_addr.s_addr = INADDR_ANY; - devnull_fd = SAFE_OPEN("/dev/null", O_WRONLY); - socket_fd = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0); SAFE_BIND(socket_fd, (struct sockaddr *)&sin0, sizeof(sin0)); @@ -88,7 +81,6 @@ static void test_setup(void) static void test_cleanup(void) { - SAFE_CLOSE(devnull_fd); SAFE_CLOSE(socket_fd); SAFE_CLOSE(udp_fd); } diff --git a/testcases/kernel/syscalls/accept/accept03.c b/testcases/kernel/syscalls/accept/accept03.c new file mode 100644 index 000000000..b85ec0d9b --- /dev/null +++ b/testcases/kernel/syscalls/accept/accept03.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (C) 2023-2024 Cyril Hrubis + */ + +/*\ + * [Description] + * + * Verify that accept() returns ENOTSOCK or EBADF for non-socket file + * descriptors. The EBADF is returned in the case that the file descriptor has + * not a file associated with it, which is for example in the case of O_PATH + * opened file. + */ + +#include +#include + +#include "tst_test.h" + +void check_accept(struct tst_fd *fd) +{ + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_port = 0, + .sin_addr = {.s_addr = INADDR_ANY}, + }; + + socklen_t size = sizeof(addr); + + int exp_errno = ENOTSOCK; + + switch (fd->type) { + case TST_FD_UNIX_SOCK: + case TST_FD_INET_SOCK: + return; + /* + * With these two we fail even before we get to the do_accept() because + * the fd does not have a struct file associated. + */ + case TST_FD_OPEN_TREE: + case TST_FD_PATH: + exp_errno = EBADF; + default: + break; + } + + TST_EXP_FAIL2(accept(fd->fd, (void*)&addr, &size), + exp_errno, "accept() on %s", tst_fd_desc(fd)); +} + +static void verify_accept(void) +{ + TST_FD_FOREACH(fd) + check_accept(&fd); +} + +static struct tst_test test = { + .test_all = verify_accept, +}; From patchwork Mon Jan 15 12:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1886645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=TWfMI0Ht; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tWIjA+AG; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=TWfMI0Ht; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tWIjA+AG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TDBtS0QNjz1yPJ for ; Mon, 15 Jan 2024 23:54:40 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 26A6A3CDB05 for ; Mon, 15 Jan 2024 13:54:38 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1C3943CCDE0 for ; Mon, 15 Jan 2024 13:53:26 +0100 (CET) Authentication-Results: in-5.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=chrubis@suse.cz; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 93EAD60084A for ; Mon, 15 Jan 2024 13:53:25 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 17D221FD36; Mon, 15 Jan 2024 12:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jMYGoEo+sMvfo1eg8aUY/kv/N44CSJBYuXa/vHZJSMA=; b=TWfMI0HtIVA9MIvfOg/JFV+XYy9HdzmO1mbe+dGRyYlkqv8J54JslTPYv9enCYnk/vwFrS YV4hIW4PMwGxlvHCkn+8kCEa13AksUvambT5nil6RQNIA25OSHL1YIEDseQnMjGAr7eGpd /uhWN6IxgzFUs+iUmHWq3yyt/dvoaAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jMYGoEo+sMvfo1eg8aUY/kv/N44CSJBYuXa/vHZJSMA=; b=tWIjA+AGSN0sjwcPxOyBsZsqi9bs9Z+dxUeyum9vq51K5QAYdxF4RcB1RstFnFGmYGkFGe 7xFSFJTOTt77UBAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705323205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jMYGoEo+sMvfo1eg8aUY/kv/N44CSJBYuXa/vHZJSMA=; b=TWfMI0HtIVA9MIvfOg/JFV+XYy9HdzmO1mbe+dGRyYlkqv8J54JslTPYv9enCYnk/vwFrS YV4hIW4PMwGxlvHCkn+8kCEa13AksUvambT5nil6RQNIA25OSHL1YIEDseQnMjGAr7eGpd /uhWN6IxgzFUs+iUmHWq3yyt/dvoaAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705323205; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jMYGoEo+sMvfo1eg8aUY/kv/N44CSJBYuXa/vHZJSMA=; b=tWIjA+AGSN0sjwcPxOyBsZsqi9bs9Z+dxUeyum9vq51K5QAYdxF4RcB1RstFnFGmYGkFGe 7xFSFJTOTt77UBAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id F0BCC13751; Mon, 15 Jan 2024 12:53:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id i7nAOcQqpWWZVQAAD6G6ig (envelope-from ); Mon, 15 Jan 2024 12:53:24 +0000 From: Cyril Hrubis To: ltp@lists.linux.it Date: Mon, 15 Jan 2024 13:53:51 +0100 Message-ID: <20240115125351.7266-5-chrubis@suse.cz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115125351.7266-1-chrubis@suse.cz> References: <20240115125351.7266-1-chrubis@suse.cz> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[infradead.org,gmail.com,redhat.com,kernel.org,zeniv.linux.org.uk,suse.cz,vger.kernel.org,suse.com]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Virus-Scanned: clamav-milter 1.0.3 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 4/4] syscalls: splice07: New splice tst_fd iterator test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mszeredi@redhat.com, brauner@kernel.org, Jan Kara , Matthew Wilcox , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" We loop over all possible combinations of file descriptors in the test and filter out combinations that actually make sense and either block or attempt to copy data. The rest of invalid options produce either EINVAL or EBADF. Signed-off-by: Cyril Hrubis Reviewed-by: Richard Palethorpe Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice07.c | 70 +++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice07.c diff --git a/runtest/syscalls b/runtest/syscalls index 5472c954b..6e2407879 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1516,6 +1516,7 @@ splice03 splice03 splice04 splice04 splice05 splice05 splice06 splice06 +splice07 splice07 tee01 tee01 tee02 tee02 diff --git a/testcases/kernel/syscalls/splice/.gitignore b/testcases/kernel/syscalls/splice/.gitignore index 61e979ad6..88a8dff78 100644 --- a/testcases/kernel/syscalls/splice/.gitignore +++ b/testcases/kernel/syscalls/splice/.gitignore @@ -4,3 +4,4 @@ /splice04 /splice05 /splice06 +/splice07 diff --git a/testcases/kernel/syscalls/splice/splice07.c b/testcases/kernel/syscalls/splice/splice07.c new file mode 100644 index 000000000..135c42e47 --- /dev/null +++ b/testcases/kernel/syscalls/splice/splice07.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (C) 2023-2024 Cyril Hrubis + */ + +/*\ + * [Description] + * + * Iterate over all kinds of file descriptors and feed splice() with all possible + * combinations where at least one file descriptor is invalid. We do expect the + * syscall to fail either with EINVAL or EBADF. + */ + +#define _GNU_SOURCE + +#include +#include + +#include "tst_test.h" + +static void check_splice(struct tst_fd *fd_in, struct tst_fd *fd_out) +{ + /* These combinations just hang since the pipe is empty */ + if (fd_in->type == TST_FD_PIPE_READ) { + switch (fd_out->type) { + case TST_FD_FILE: + case TST_FD_PIPE_WRITE: + case TST_FD_UNIX_SOCK: + case TST_FD_INET_SOCK: + case TST_FD_MEMFD: + return; + default: + break; + } + } + + if (fd_out->type == TST_FD_PIPE_WRITE) { + switch (fd_in->type) { + /* While these combinations succeeed */ + case TST_FD_FILE: + case TST_FD_MEMFD: + return; + /* And this complains about socket not being connected */ + case TST_FD_INET_SOCK: + return; + default: + break; + } + } + + const int exp_errnos[] = {EBADF, EINVAL}; + + TST_EXP_FAIL2_ARR(splice(fd_in->fd, NULL, fd_out->fd, NULL, 1, 0), + exp_errnos, "splice() on %s -> %s", + tst_fd_desc(fd_in), tst_fd_desc(fd_out)); +} + +static void verify_splice(void) +{ + TST_FD_FOREACH(fd_in) { + tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd_in)); + TST_FD_FOREACH(fd_out) + check_splice(&fd_in, &fd_out); + } +} + +static struct tst_test test = { + .test_all = verify_splice, +};