From patchwork Thu Oct 20 13:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1692489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=vi+dgfO4; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=L51ioMKw; dkim-atps=neutral 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MtSbQ5KSHz23jk for ; Fri, 21 Oct 2022 00:08:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CDC0D3CB183 for ; Thu, 20 Oct 2022 15:08:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 9E8F13CAFB4 for ; Thu, 20 Oct 2022 15:08:46 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id 1348B601392 for ; Thu, 20 Oct 2022 15:08:45 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8B3DF225A3; Thu, 20 Oct 2022 13:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666271324; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sDypSQedbS8aWtiA2vxzr1cfMlMxgijsogZWd/77lm0=; b=vi+dgfO4mPxaN2MO+OzMwWB85toH0EYbWIoXOfuryqYjHfZqE8s6i/UQBSYXqwze4dgZdW wYYMaEX3IE8jQ/He5lq8JwjepLUXLdZ9uYWc6V3fU7vWLvvwXoUr4rZD/WEeU10fOflDzN rKdWLESUi1R1CPPorVFgsjx5dgLtwEw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666271324; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sDypSQedbS8aWtiA2vxzr1cfMlMxgijsogZWd/77lm0=; b=L51ioMKwfbbJK+OX4ov37enixou5NspG+Vu6vnC8uB9BYZc9Mk34sTHIP9zugL6kadPq6H VhC2Y+nkgGFMhdBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7A6E313AF5; Thu, 20 Oct 2022 13:08:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oCI0HVxIUWNLOgAAMHmgww (envelope-from ); Thu, 20 Oct 2022 13:08:44 +0000 From: Martin Doucha To: amir73il@gmail.com, ltp@lists.linux.it Date: Thu, 20 Oct 2022 15:08:42 +0200 Message-Id: <20221020130843.15147-3-mdoucha@suse.cz> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221020130843.15147-1-mdoucha@suse.cz> References: <20221020130843.15147-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/3] Add fanotify_get_supported_init_flags() helper function 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Since FAN_ALL_INIT_FLAGS constant is deprecated, the kernel has added new fanotify feature flags and there is no other way to check for their support, we need to manually check which init flags needed by our tests are available. Signed-off-by: Martin Doucha --- Changes since v1: - Fixed check for FAN_REPORT_NAME - Added longer patch description Thanks for pointing out the flag dependency between FAN_REPORT_NAME and FAN_REPORT_DIR_FID. I must have misread the documentation on that one. Since this appears to be the only flag with a dependency for now, let's keep the special handling simple. If the kernel adds more flags that are invalid on their own, we should handle that using a table. These flag support checks will be needed in multiple tests so it's better to have one common function that'll do them in one call than to copy-paste multiple setup steps from one test to another. Though it'd be great if kernel itself would provide a syscall that returns all supported fanotify init, mark or mask flags in one call. testcases/kernel/syscalls/fanotify/fanotify.h | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 51078103e..f3ac1630f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -213,6 +213,32 @@ static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags) return fanotify_init_flags_supported_on_fs(flags, NULL); } +/* + * Check support of given init flags one by one and return those which are + * supported. + */ +static inline unsigned int fanotify_get_supported_init_flags(unsigned int flags, + const char *fname) +{ + unsigned int flg, arg, ret = 0; + + for (flg = 1; flg; flg <<= 1) { + if (!(flags & flg)) + continue; + + arg = flg; + + // FAN_REPORT_NAME is invalid without FAN_REPORT_DIR_FID + if (flg == FAN_REPORT_NAME) + arg |= FAN_REPORT_DIR_FID; + + if (!fanotify_init_flags_supported_on_fs(arg, fname)) + ret |= flg; + } + + return ret; +} + typedef void (*tst_res_func_t)(const char *file, const int lineno, int ttype, const char *fmt, ...);