From patchwork Fri Jun 3 21:50:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 742B1C43334 for ; Fri, 3 Jun 2022 21:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240077AbiFCVvJ (ORCPT ); Fri, 3 Jun 2022 17:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbiFCVvH (ORCPT ); Fri, 3 Jun 2022 17:51:07 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46037580D4 for ; Fri, 3 Jun 2022 14:51:03 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id s68so8184600pgs.10 for ; Fri, 03 Jun 2022 14:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dqigf7FbZ7L2uJAFMzsjV2jroU2wneUVxTmKCSGYE4o=; b=noanq8he4Qq7CTV1dSQP4IOYzLInVIpEt2uhKVZL2GxpIV+viLUPr4/HyGnV4MJ6Fz 3QWZ2f/b6Qnmr4MeaGjDKumfH8k1FEMwBHjdd1Y9eoqQJNUmO8zU3xWtaa2To0yaCbBu CRpsMG7NUKUZpMBuL08jOOUgefEKXjG5dq9yD2PA/BRqiMo90IyQ/WeJBkiQiyt82CsV /dZ+Y20/+ZukUSRvk6+Hu5kUVckmxtUz9eTMacTh8jEjSGYGU0t6Ul6DxJfqqGaWYPth YX9qj1jGpt3CZdunYqwBpyOtycKc3S3P2LXnNjZmysYpX/Z4+RLm8aiRwfnCmawpAWQT YLww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dqigf7FbZ7L2uJAFMzsjV2jroU2wneUVxTmKCSGYE4o=; b=g1E1m5/37/WuAF8cCtMUV8gzxpaotDd39Z/tRpurafn4ffUHdF0eu5B+ptzzyspmG3 9jGtxMYoMvyEL4fswZbQk7Huc075RYY9FDZ/YGcO1IXgnj9tJ4v7Ev67wgASLFypkW0O 4vxG0+TN/n1y0JWZPktDi/JDhU6/eaY2Dn+LY3ezORHLRAyFJrDHo8vyMtQJ0fUfKLuJ 32G76kzs6OY8BV8OBWuP/XpqdJrU4V3elvgKTtd9eoeO18+4Hj9CJKpuIpn6p6Bis8QC dy3Cq168/F6sDFhLuB9nHMDe/rrq/mLoxvziwAlYxbcWLqaoSmQpg6DMRxM76sVNBXrB G3Qw== X-Gm-Message-State: AOAM530pyH1QSbiCFKIYDk1J3dvypeOwPqeFygsv1h0haUNngxb9MEOv gh7OMmOepqF2uulQ8YVRA0kFtzLFydA= X-Google-Smtp-Source: ABdhPJx3VmfSBKVmWxeXKNh92dxDjmvLG2gPbwSXfqa7l+8D3JWRpWeuAEXIlbesS+fE+MTBy1Pykw== X-Received: by 2002:a63:6cc6:0:b0:3fa:a7f0:e4c0 with SMTP id h189-20020a636cc6000000b003faa7f0e4c0mr10660846pgc.18.1654293062241; Fri, 03 Jun 2022 14:51:02 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:00 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 1/8] modprobe: Move -R to "Query options" Date: Fri, 3 Jun 2022 14:50:40 -0700 Message-Id: <20220603215047.9607-2-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Signed-off-by: Lucas De Marchi --- tools/modprobe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/modprobe.c b/tools/modprobe.c index a825fb5..caaf87f 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -110,7 +110,6 @@ static void help(void) "\t-r, --remove Remove modules instead of inserting\n" "\t --remove-dependencies Deprecated: use --remove-holders\n" "\t --remove-holders Also remove module holders (use together with -r)\n" - "\t-R, --resolve-alias Only lookup and print alias and exit\n" "\t --first-time Fail if module already inserted or removed\n" "\t-i, --ignore-install Ignore install commands\n" "\t-i, --ignore-remove Ignore remove commands\n" @@ -122,6 +121,7 @@ static void help(void) "\t --force-vermagic Ignore module's version magic\n" "\n" "Query Options:\n" + "\t-R, --resolve-alias Only lookup and print alias and exit\n" "\t-D, --show-depends Only print module dependencies and exit\n" "\t-c, --showconfig Print out known configuration and exit\n" "\t-c, --show-config Same as --showconfig\n" @@ -800,9 +800,6 @@ static int do_modprobe(int argc, char **orig_argv) case 5: remove_holders = 1; break; - case 'R': - lookup_only = 1; - break; case 3: first_time = 1; break; @@ -826,6 +823,9 @@ static int do_modprobe(int argc, char **orig_argv) dry_run = 1; do_show = 1; break; + case 'R': + lookup_only = 1; + break; case 'c': do_show_config = 1; break; From patchwork Fri Jun 3 21:50:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D79FBCCA47D for ; Fri, 3 Jun 2022 21:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239850AbiFCVvK (ORCPT ); Fri, 3 Jun 2022 17:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238101AbiFCVvI (ORCPT ); Fri, 3 Jun 2022 17:51:08 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E45F580C3 for ; Fri, 3 Jun 2022 14:51:05 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id x12so8183228pgj.7 for ; Fri, 03 Jun 2022 14:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7QuyeCFnNY8LvTl11n4OqSbdGHZK+0Oj+W9UnqLXuro=; b=iFI7HVlyQM2CR9QsM8fIzwWxxMeA623g2Dx1X98BVm6GbjbMnTnBpCXRYWRrxe6gnl f2l6KtVNBGHbglON5ZENz1aGl+AVagRT8T2yhzxTIIK0ivuAEOxCV+8LHjO1E+QY9Q5f c5+WW8029ZXl4u6pdoMwrLPhkf43dHyOSnOsJUxk4wPCSIAYS2HSJ65T3yFH5Efcr6S7 5iNJFxPLIsRuu/3dV7OLk4EAhN6NGxmMZIl3RO03cGuy0+JNGbtrE9T3BSBzmrgtP9oq Io2r8Nvb5LpJjHBrtjRWoTPLhXBLdFYCsfeWfMIvlgHjqHYGo6j+cU2XnT4mm3ETlrNl O7Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7QuyeCFnNY8LvTl11n4OqSbdGHZK+0Oj+W9UnqLXuro=; b=EvqIerfnPssftQjXgbYCDyNzLXtoMbuh/1awQ/yfd8d5adZJd48Zd43utr7tbU7tQz dgWWDxemiGluLtVWlu8QxPjOWBNC0zcJyhvMpzXUnKoEIOum0BxgSur88MZOYIotBrY/ tQTHk0ksICASb6Yj0wWPhHik17xZY+lK3FSWKiJ4i+0XPaeyo5B35cOOyxIGDMXc/85k E4A1mKmyfMl1GbVroomzS5N6mdYEJ/m15L866qVnVlDZHefRxv1HL/uI+N6IEVw4H2v9 9l609qN5vK3ftT2a7MjqoSIJ072pUXVbSZb30geA4gwd/pj3m7xAFTjQAdLAoNjpAOJk G1uA== X-Gm-Message-State: AOAM531stuUAVM6PyIIG6Ba0eZdf90uQPN5LXAfZmLTmy2NEKtixbsvl bgQKbxyHGvGIP521moTKmlUJGSsDTDw= X-Google-Smtp-Source: ABdhPJzLr8lm9cUwhZK9yNUzuCQXCy99l8HmXvfPFrINWbh6DKV539DxIV8gd1XtOzdIxVIfQ9370g== X-Received: by 2002:a63:8642:0:b0:3fc:9abf:b6db with SMTP id x63-20020a638642000000b003fc9abfb6dbmr10647944pgd.51.1654293063665; Fri, 03 Jun 2022 14:51:03 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:02 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 2/8] libkmod: Allow to ignore log message on module removal Date: Fri, 3 Jun 2022 14:50:41 -0700 Message-Id: <20220603215047.9607-3-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Caller may want to handle retries, in which case the log message is not appropriate. Signed-off-by: Lucas De Marchi --- libkmod/libkmod-module.c | 13 +++++++++---- libkmod/libkmod.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index efdd679..12d8ed1 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -823,11 +823,13 @@ extern long delete_module(const char *name, unsigned int flags); /** * kmod_module_remove_module: * @mod: kmod module - * @flags: flags to pass to Linux kernel when removing the module. The only valid flag is + * @flags: flags used when removing the module. * KMOD_REMOVE_FORCE: force remove module regardless if it's still in - * use by a kernel subsystem or other process; - * KMOD_REMOVE_NOWAIT is always enforced, causing us to pass O_NONBLOCK to + * use by a kernel subsystem or other process; passed directly to Linux kernel + * KMOD_REMOVE_NOWAIT: is always enforced, causing us to pass O_NONBLOCK to * delete_module(2). + * KMOD_REMOVE_NOLOG: when module removal fails, do not log anything as the + * caller may want to handle retries and log when appropriate. * * Remove a module from Linux kernel. * @@ -836,6 +838,8 @@ extern long delete_module(const char *name, unsigned int flags); KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags) { + unsigned int libkmod_flags = flags & 0xff; + int err; if (mod == NULL) @@ -848,7 +852,8 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, err = delete_module(mod->name, flags); if (err != 0) { err = -errno; - ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); + if (!(libkmod_flags & KMOD_REMOVE_NOLOG)) + ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); } return err; diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index fed216b..7251aa7 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -145,6 +145,8 @@ struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); enum kmod_remove { KMOD_REMOVE_FORCE = O_TRUNC, KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */ + /* libkmod-only defines, not passed to kernel */ + KMOD_REMOVE_NOLOG = 1, }; /* Insertion flags */ From patchwork Fri Jun 3 21:50:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 848FEC433EF for ; Fri, 3 Jun 2022 21:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231133AbiFCVvJ (ORCPT ); Fri, 3 Jun 2022 17:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239850AbiFCVvI (ORCPT ); Fri, 3 Jun 2022 17:51:08 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D24580E1 for ; Fri, 3 Jun 2022 14:51:07 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id h192so1403881pgc.4 for ; Fri, 03 Jun 2022 14:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GEi6HF25E4K+yeZC0zp706ITxxpOPud+fd27MQ3mjL4=; b=GAO/Y5UC/fA9HIgxeyx1fXZp1xOAexqQYuqrrYrn3P5RzZGquJN7x3LkM4CGw3Y6Br Aymg2CrxSQPvrVuDKfFZh0oE7tgcQKh4cI2VGM+X1WBsVU9YFWugUuWdY2A3WIaFfIin jasXF5B4sMYAkfGw0ZvonAvf6HIRhNuHWj4ZHF+bL8YWYOQ3wqTbE/QzK1+mQ+wTQz02 txlu0kKFvFC9ydIZxOeItTTbj7sLgAMsZDpEPktaR3/rlIS87N1jv5SP4+YJXyPBPTL/ ZdqNrv1xw7ieTvCNYOXfVQfIBpgRRAH1aezMWnse7OfORDMmUFNPoQ3Vc2tIzY8AN/Kb Errw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GEi6HF25E4K+yeZC0zp706ITxxpOPud+fd27MQ3mjL4=; b=MJzvVD9DKDle4vTsxK8m8vgbiZuJd3t4wEb403rsyHRuo8+xhCibKitLkC9wHY4HBa b1E/oflLLvPz9eIR7KRBgfe4jAx9RKFBXQYxmIXdQIa2E5EJQrKttnAilpXg6IQBr02J tp3gCWIZvnMf6Fr+kxnzk+SXBrMv5OFg61aDV2CDixb6zSp5Ld1OZUTR0e8gRpvRok+I ZlaBTPMl82CtCTHX/2s3smaNIqJuS6h1kWAZ1/4HS6+ccFgcTrSJXP3rgXvVmmTeTdr8 iBPeLyvGaaNFKBIo5ESl0XifVMswoMwhGPAcVvd8aW+59XU76b1dkJKRENMW2vyxF11Y dJJg== X-Gm-Message-State: AOAM531HeI6dUDp/fuEWjobaaapSPlMY5eGXG6rTqXbkYgnhkUGDm//U 5Chs+uTt0TBHiG+5MdX4GG07MCBggcQ= X-Google-Smtp-Source: ABdhPJyrazVaHRZwsWqMg3uDfXyTbx8xdgR6I8ihDxCdsZtg9Y/ZBIZL0B1RuNFXtW5lmgRLmh7Ynw== X-Received: by 2002:a63:1153:0:b0:3fb:10da:6277 with SMTP id 19-20020a631153000000b003fb10da6277mr10632388pgr.345.1654293066686; Fri, 03 Jun 2022 14:51:06 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:05 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 3/8] module-playground: Add debugfs entry in mod-simple Date: Fri, 3 Jun 2022 14:50:42 -0700 Message-Id: <20220603215047.9607-4-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Add a debugfs file in mod-simple for manual tests: insert the module and open the file to have its refcount increased. Signed-off-by: Lucas De Marchi --- testsuite/module-playground/mod-simple.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/testsuite/module-playground/mod-simple.c b/testsuite/module-playground/mod-simple.c index cb38580..503e4d8 100644 --- a/testsuite/module-playground/mod-simple.c +++ b/testsuite/module-playground/mod-simple.c @@ -1,16 +1,32 @@ +#include #include #include +static struct dentry *debugfs_dir; + +static int test_show(struct seq_file *s, void *data) +{ + seq_puts(s, "test"); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(test); + static int __init test_module_init(void) { + debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); + debugfs_create_file("test", 0444, debugfs_dir, NULL, &test_fops); + return 0; } static void test_module_exit(void) { + debugfs_remove_recursive(debugfs_dir); } + module_init(test_module_init); module_exit(test_module_exit); MODULE_AUTHOR("Lucas De Marchi "); -MODULE_LICENSE("LGPL"); +MODULE_LICENSE("GPL"); From patchwork Fri Jun 3 21:50:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 866EAC433EF for ; Fri, 3 Jun 2022 21:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238101AbiFCVvK (ORCPT ); Fri, 3 Jun 2022 17:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240444AbiFCVvK (ORCPT ); Fri, 3 Jun 2022 17:51:10 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF5757B3E for ; Fri, 3 Jun 2022 14:51:09 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id d12-20020a17090abf8c00b001e2eb431ce4so8062117pjs.1 for ; Fri, 03 Jun 2022 14:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0XkxNHrXnKt0HQWanf5BDvaDmGmbQtiT0X773VTjlEE=; b=WOnp+ZqXIc6PeQ7yxAXuHH0ZJaXI78gP/0pjyAXgwjLqww0fCTuBeU2bvbz+2gkCV4 GwyV9eTRUqc2pTKNrD3UoUHu+XNi71V/Zeqe5766kzy+ZweOpppkDQHOxm2tj02GqQYd ueed4DBZkPL1g1bvDDrAFf/B4Pmu66TycUECtTfDf5qJSW+wfd+x40ARjdiN3x+mRNJw y5haRqmZ03NMUG6vo8gsy8FbWsIki0Vn627kwSZ39IZXpYtYvYS+zZdjn/PoqwZt63XR 7QAbUa3zcT5yB+aNWLz5dPqHMZyvLVlccSLOxLX/2vBUEpE0ci91vYPlrIlH9j49pKv1 H5HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0XkxNHrXnKt0HQWanf5BDvaDmGmbQtiT0X773VTjlEE=; b=dg626WLKAMfw05F8C4XZM1lr4lGl08MMmghxzPCh1W/kXL4y+I6hAXMpJuQ4EuQMYq dhkcofJU6No+q9Ge1Wgnyie9R6UKZWIkl6tLSfLSpSxg1QwVGWFMJaPr7SbzIiBxUQ1V IA7gV2T5RNRcZ9jkZb6Yj6u2MCtYNyWAAkxto1EXVaDETQE2av/KRWO43xbmsX37Aq21 TtG4Iqi6RmROSGYtnWwm4kJpOVpmenDX1n8bED0yezFcepdbKE8oVj1ojmTpwJRcddD0 2knIXdbrB+NkBCkAdthQJoCE/ycdhiO17kzKFDZL7XhVp0Lf8sVZZ+bS2/VUWT7fWFQY bVBQ== X-Gm-Message-State: AOAM530F80iMoox00Z5wLxEjgxrBj4e1ktAAvaVF9i+GPvHdCHFlaAX7 KY0YunqFEUTmYYQM7iZcTtPL4KJk2qk= X-Google-Smtp-Source: ABdhPJxcD9iS4u1g4N5FYdG68ymNOS0QDT5Dnr/69fBCgxoSGibQiunlVNGMw/IYBMfMjigy0yteOA== X-Received: by 2002:a17:90a:d3d3:b0:1df:3b6f:d073 with SMTP id d19-20020a17090ad3d300b001df3b6fd073mr46788564pjw.18.1654293068152; Fri, 03 Jun 2022 14:51:08 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:06 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 4/8] util: Add time-related functions from testsuite Date: Fri, 3 Jun 2022 14:50:43 -0700 Message-Id: <20220603215047.9607-5-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: This will be useful in future not only to testsuite, but also to tools and library. Signed-off-by: Lucas De Marchi --- shared/util.c | 10 ++++++++++ shared/util.h | 8 ++++++++ testsuite/testsuite.c | 14 +------------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/shared/util.c b/shared/util.c index b487b5f..aeb171f 100644 --- a/shared/util.c +++ b/shared/util.c @@ -466,6 +466,16 @@ unsigned long long ts_usec(const struct timespec *ts) (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; } +unsigned long long now_usec(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + return 0; + + return ts_usec(&ts); +} + unsigned long long stat_mstamp(const struct stat *st) { #ifdef HAVE_STRUCT_STAT_ST_MTIM diff --git a/shared/util.h b/shared/util.h index c6a31df..734a523 100644 --- a/shared/util.h +++ b/shared/util.h @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -42,7 +43,14 @@ char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull( int mkdir_p(const char *path, int len, mode_t mode); int mkdir_parents(const char *path, mode_t mode); unsigned long long stat_mstamp(const struct stat *st); + +/* time-related functions + * ************************************************************************ */ +#define USEC_PER_SEC 1000000ULL +#define USEC_PER_MSEC 1000ULL + unsigned long long ts_usec(const struct timespec *ts); +unsigned long long now_usec(void); /* endianess and alignments */ /* ************************************************************************ */ diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 05df553..6a2d296 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -51,6 +51,7 @@ static const struct option options[] = { }; #define OVERRIDE_LIBDIR ABS_TOP_BUILDDIR "/testsuite/.libs/" +#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC struct _env_config { const char *key; @@ -62,19 +63,6 @@ struct _env_config { [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES, OVERRIDE_LIBDIR "delete_module.so" }, }; -#define USEC_PER_SEC 1000000ULL -#define USEC_PER_MSEC 1000ULL -#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC -static unsigned long long now_usec(void) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - return 0; - - return ts_usec(&ts); -} - static void help(void) { const struct option *itr; From patchwork Fri Jun 3 21:50:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B3D3C43334 for ; Fri, 3 Jun 2022 21:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240444AbiFCVvN (ORCPT ); Fri, 3 Jun 2022 17:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242876AbiFCVvL (ORCPT ); Fri, 3 Jun 2022 17:51:11 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2F1C57B3E for ; Fri, 3 Jun 2022 14:51:10 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso13050052pjl.3 for ; Fri, 03 Jun 2022 14:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iP6+MHi7sHxKscnvV/NWmNg2xqGqAE4GKnrgY09vfTo=; b=o5F1Sb4IkaJQ4UCZpihfeFqXHhlHeQyqjU6r4jSYW1aXN2iU9ei+zNfm8rnWHoQ6qI mxTgvqgdU77+/WdaSRnsNlhmARw8MnnPJtTaJo4DchrOMq1e3bBIf0YwNbQlCzpz9lxq eswdcrrn2o/WCOUcCCw9K3PZsGtYgmKvwjuxOLxRL7yv8ell/FRnsHyR/bBCeMfcKecK /+VBV3VI17OWywTwTPG59o9UnlUXQJqoK2axwNYNbwi1wesKYGbWcnGaZpQ6ZISKKv5q B0W4Aq9o3MHuRqo18ZMXpBKMUxUjyLi+IAcwHFj/EMAYDMzUDPJWlwMtZIWGq27x+fKg 6pUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iP6+MHi7sHxKscnvV/NWmNg2xqGqAE4GKnrgY09vfTo=; b=ay3useCRZsGkF3xDMriRlmr90OUPd95xqPRGdb1f18SkqtaujnjT0cvtJjwmXvsUF/ C2iQVk7SKNzrnLL1L0zSdXJMK+bcvaBIClaChpmAWRjMF9CYUP9NvjYGcYW2VLec9nKM NwMfedOFX8DxA6TZ8JX5xLTLTCf4ym4gR44XkwWIsEKqhunIVmJO1wZWmVYmMK4aonUM DoYB0/8J2QJS062YYqxPFNL+bfoQj41hphkR+cor03OLb1qic44lQWP1wfVmQzkuHO9c 6gdJ2n8mHrX3Y0Wln+cFia+zmrV2ZWY1TBdAXo9keM4JXsI9qLl/aOyabwtZCd0gUiiJ 0gGg== X-Gm-Message-State: AOAM530qRkJ22yav0gc+qzesMw0R0COIXFb5opTOdD1at2ZgikqMGAFZ O9yuUJch+i8jVt3Cm7XhfeAqigVevq4= X-Google-Smtp-Source: ABdhPJxQgRUsDw3gc7EgRfWZvSFWZ91g4uav1g0wvc8stFt7rQZR+kJf/9XuuOVAthln15bCkzSVaQ== X-Received: by 2002:a17:902:e5cb:b0:166:3622:a7e4 with SMTP id u11-20020a170902e5cb00b001663622a7e4mr12038285plf.32.1654293069803; Fri, 03 Jun 2022 14:51:09 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:08 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 5/8] util: Add msec variants for time-related functions Date: Fri, 3 Jun 2022 14:50:44 -0700 Message-Id: <20220603215047.9607-6-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Signed-off-by: Lucas De Marchi --- shared/util.c | 16 ++++++++++++++++ shared/util.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/shared/util.c b/shared/util.c index aeb171f..d4452eb 100644 --- a/shared/util.c +++ b/shared/util.c @@ -466,6 +466,12 @@ unsigned long long ts_usec(const struct timespec *ts) (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; } +unsigned long long ts_msec(const struct timespec *ts) +{ + return (unsigned long long) ts->tv_sec * MSEC_PER_SEC + + (unsigned long long) ts->tv_nsec / NSEC_PER_MSEC; +} + unsigned long long now_usec(void) { struct timespec ts; @@ -476,6 +482,16 @@ unsigned long long now_usec(void) return ts_usec(&ts); } +unsigned long long now_msec(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + return 0; + + return ts_msec(&ts); +} + unsigned long long stat_mstamp(const struct stat *st) { #ifdef HAVE_STRUCT_STAT_ST_MTIM diff --git a/shared/util.h b/shared/util.h index 734a523..bedafa3 100644 --- a/shared/util.h +++ b/shared/util.h @@ -48,9 +48,13 @@ unsigned long long stat_mstamp(const struct stat *st); * ************************************************************************ */ #define USEC_PER_SEC 1000000ULL #define USEC_PER_MSEC 1000ULL +#define MSEC_PER_SEC 1000ULL +#define NSEC_PER_MSEC 1000000ULL unsigned long long ts_usec(const struct timespec *ts); +unsigned long long ts_msec(const struct timespec *ts); unsigned long long now_usec(void); +unsigned long long now_msec(void); /* endianess and alignments */ /* ************************************************************************ */ From patchwork Fri Jun 3 21:50:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 718FDC433EF for ; Fri, 3 Jun 2022 21:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242876AbiFCVvN (ORCPT ); Fri, 3 Jun 2022 17:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245040AbiFCVvN (ORCPT ); Fri, 3 Jun 2022 17:51:13 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285B2580C3 for ; Fri, 3 Jun 2022 14:51:12 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id n8so7714809plh.1 for ; Fri, 03 Jun 2022 14:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4dfS+aVx0bMyj+vGaxCHuJwOGGxQuq6BokCwq/GVf94=; b=kC7wfyayjutXk5l8dPUfunikhIOCc7extY0ibMnFmqxeaQAloq0Y5RAFqPDYUN9kCG Jwsk86qOFTAM1bBYK1aznQxmCrMcFYwyDY8c3rbjOi8+M5HY3LGT4rZVD2bzchOik+Pv QgA+PjxfBoJG4eRdlngs8okwRzSRB+nhxkUreWQFeVXH+v8mhFxcHsqc5VUjoI2agXLd 3QjWjXRVj4MdGeRSqYtk8FGta6sSQQHEDDBIKiUEZH/7era9oAq9LT6PzYNvoKTZGXOc EqZJpYr6dxWIWMxdR7J/twQLhJBdFPIaBVPnzM9/djqIhHFfmOM1WAr6Wz3ql4M7EZh1 R+ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4dfS+aVx0bMyj+vGaxCHuJwOGGxQuq6BokCwq/GVf94=; b=ednEX/6xrQE1Ah1H6BuL9QYbjIkInzrTzYkTvWwvQCji1REI2yskkJOxhOZMgU/tWx YOBz7raR8k4orF2IyHckDnsDStmsYq9AdefaTLbYATCngMcWz3wHf+DrEB2Q6i/bPZWt ECjgfOm12hcqSlcicMuvZ09hyaip73Nw/7+LjawJuKK43ZEtJ1ib0IP5DBb0i2YDNA4n HNPxiBLOIIJBgpEnpzwXk0qeyeSdu8ILMykMgJCjH0W114BixUB6Epk4cbKyDH4wQeUf bn0IiQKa+t2eWwdDOW1ognewV7DBQyroxtGKA1Q4Jy8a9G4+ubsuBwsL7ETY6djnNDxo v8cw== X-Gm-Message-State: AOAM533F7Ywf//0znZc/36zk3oyZDP3mZ0mG7tP7EqWGoK4A4FDBDYl6 Kutl2esBzkKNNP0ssrhxkghHtsOjtvg= X-Google-Smtp-Source: ABdhPJzmC/4JEtYaOn9bsDOGtAUBvmkb/9QQN7dnRhoRRB+gwn6PWXY65NOviKNpRTqa1zNKy8ToCw== X-Received: by 2002:a17:90b:1a88:b0:1dc:8e84:9133 with SMTP id ng8-20020a17090b1a8800b001dc8e849133mr12891206pjb.231.1654293071247; Fri, 03 Jun 2022 14:51:11 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:10 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 6/8] util: Add exponential backoff sleep Date: Fri, 3 Jun 2022 14:50:45 -0700 Message-Id: <20220603215047.9607-7-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Add simple functions to put the current thread to sleep using exponential backoff to split the interval in smaller pieces. Signed-off-by: Lucas De Marchi --- shared/util.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ shared/util.h | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/shared/util.c b/shared/util.c index d4452eb..4b547ff 100644 --- a/shared/util.c +++ b/shared/util.c @@ -472,6 +472,52 @@ unsigned long long ts_msec(const struct timespec *ts) (unsigned long long) ts->tv_nsec / NSEC_PER_MSEC; } +static struct timespec msec_ts(unsigned long long msec) +{ + struct timespec ts = { + .tv_sec = msec / MSEC_PER_SEC, + .tv_nsec = (msec % MSEC_PER_SEC) * NSEC_PER_MSEC, + }; + + return ts; +} + +int sleep_until_msec(unsigned long long msec) +{ + struct timespec ts = msec_ts(msec); + + if (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) < 0 && + errno != EINTR) + return -errno; + + return 0; +} + +/* + * Exponential retry backoff with tail + */ +unsigned long long get_backoff_delta_msec(unsigned long long t0, + unsigned long long tend, + unsigned long long *delta) +{ + unsigned long long t; + + t = now_msec(); + + if (!*delta) + *delta = 1; + else + *delta <<= 1; + + while (t + *delta > tend) + *delta >>= 1; + + if (!*delta && tend > t) + *delta = tend - t; + + return t + *delta; +} + unsigned long long now_usec(void) { struct timespec ts; diff --git a/shared/util.h b/shared/util.h index bedafa3..7030653 100644 --- a/shared/util.h +++ b/shared/util.h @@ -55,6 +55,11 @@ unsigned long long ts_usec(const struct timespec *ts); unsigned long long ts_msec(const struct timespec *ts); unsigned long long now_usec(void); unsigned long long now_msec(void); +int sleep_until_msec(unsigned long long msec); +unsigned long long get_backoff_delta_msec(unsigned long long t0, + unsigned long long tend, + unsigned long long *delta); + /* endianess and alignments */ /* ************************************************************************ */ From patchwork Fri Jun 3 21:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54673C43334 for ; Fri, 3 Jun 2022 21:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245049AbiFCVvO (ORCPT ); Fri, 3 Jun 2022 17:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245040AbiFCVvO (ORCPT ); Fri, 3 Jun 2022 17:51:14 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C17157B3E for ; Fri, 3 Jun 2022 14:51:13 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id n8so7714834plh.1 for ; Fri, 03 Jun 2022 14:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MuXYjyvxmuYHSA0H9SSYDWp7qkYOi7EReji9GmluLr4=; b=Mp5sejyf8yViNMskSfje7HPk35FvUpxxeo2L8EnrLH7BdVkI5KHvw7G5T09qurhwRt EtGoy578BbkbKtppz+/hUnFAjrLsNuar+YFVNjWrgNomP+XV5G81q95x2hWnB4vEOfFE R5iRgq9opDry2PPCzPTAET0hgVt6pZX9j298GsoV04Ul3NGYrQ/6dSGXRqiImPnKyTxu +yDjjb37nF8Jl4QpLzmMXCXBJh7ZbeiONt0j747+84ew+6PxeUF9CBs+rSWZFAtZiHhQ yqisyyPFx/Hwhkpskxj/WtPl6P4+vhv7LWvgIgdCsozdm2nt7vX7gsP4u5isNBGAXFy6 9JpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MuXYjyvxmuYHSA0H9SSYDWp7qkYOi7EReji9GmluLr4=; b=S6G1/WjFqA/OZR/ekFa+0DKL7wx68n8mj0tX+WKmuLdPBA91YQM5nsFpagV4byvd1V 7SUcW02hlifJPQT3nAvMPjXyl4cBhjnGU6RwIQ4c/5KPRE9+1ITUnEvLjp1oBClXLy4o sU1/8jVfsVuOkKqHVSx8wvk3NrFkRRKwQCLJdc8+HYWZ20o1nIEj6wH9KJPo8dw1HwSJ uoyARg+B3w7D4D72cQtQ7f/xQDzyyv3WcgH92yCg0xJ1BNzEAlzA1MRRBBl1rvHHdBL9 37l4bTr8DPajKOsM+hwb0bZgQws56FpRSkvpPPGFawlTOyJ59PYfJCB5arM0NTuEAfJL o65Q== X-Gm-Message-State: AOAM531NwSOiNvcJ/VzJ7jaREP7ZejgRk+doV68JtrYwj/gOkkougSso B2v8KTNi2A4B4zodzuf2vHKhHMAvlfA= X-Google-Smtp-Source: ABdhPJzOWuBua87I5fRU8Py9QcnIv1B+AF930zt4GvmONdaPZAx9/DBbAxJuvuJ+Hoj5CFmH4aW8Ag== X-Received: by 2002:a17:90b:1c87:b0:1ca:f4e:4fbe with SMTP id oo7-20020a17090b1c8700b001ca0f4e4fbemr47738682pjb.159.1654293072362; Fri, 03 Jun 2022 14:51:12 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:11 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 7/8] testsuite: Add tests for sleep calculation Date: Fri, 3 Jun 2022 14:50:46 -0700 Message-Id: <20220603215047.9607-8-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Signed-off-by: Lucas De Marchi --- testsuite/test-util.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/testsuite/test-util.c b/testsuite/test-util.c index 621446b..fb8c9ef 100644 --- a/testsuite/test-util.c +++ b/testsuite/test-util.c @@ -229,4 +229,45 @@ DEFINE_TEST(test_addu64_overflow, ); +static int test_backoff_time(const struct test *t) +{ + unsigned long long delta; + + /* Check exponential increments */ + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 1, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 2, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 4, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 8, EXIT_FAILURE); + + { + unsigned long long t0, tend; + + /* Check tail */ + delta = 4; + tend = now_msec() + 3; + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 2, EXIT_FAILURE); + tend = now_msec() + 1; + t0 = tend - 9; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 1, EXIT_FAILURE); + tend = now_msec(); + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 0, EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} +DEFINE_TEST(test_backoff_time, + .description = "check implementation of get_backoff_delta_msec()", + .need_spawn = false, + ); + + TESTSUITE_MAIN(); From patchwork Fri Jun 3 21:50:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12869439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC132CCA473 for ; Fri, 3 Jun 2022 21:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347895AbiFCVvQ (ORCPT ); Fri, 3 Jun 2022 17:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245040AbiFCVvP (ORCPT ); Fri, 3 Jun 2022 17:51:15 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A60C457B3E for ; Fri, 3 Jun 2022 14:51:14 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id s12so7745585plp.0 for ; Fri, 03 Jun 2022 14:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2PRvvpLQMhlbz5fltbIQ3jz0H+VVi+ZnfxsdiR5bLag=; b=QzymgcgujrjYO7TPtpzexsoNOzlKNnlPntlsiRgPGwIQQFbE1uYxpP5Cpoebgw2A3L rKdGY6IIn6zoEZJVH3zuJRO6IYxI4kMls5Dhe2u2JcUCrVCIkPysluYpZ1E9OICfh/V4 yVQ+hlNonEkhZCtXAT96zzBVBLGtMZQ4WYthcApzQPZfag7bzLEaAKqI2WhiRZzhSaEM kZzTUCroxbalq+LjGgJYq1z+qm5++PgZpt3z1W1fW5rii+0c/KRg3h97X3pvZitwPbkq 8qRqoxp7EZEKoBsPB91/c2m51TFtLiEWq3SY0mJBXdreuwX9ZkesdyBIIPupTkzF8sKU xq4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2PRvvpLQMhlbz5fltbIQ3jz0H+VVi+ZnfxsdiR5bLag=; b=FLlU46Vq/dcLXbz5vl/OYIR1Ph3kSbmFpWemiLWMdyQ+IHfxSsqqwO30OnLjxco9f3 9nIoN6vIgFwTsbQdt1NyzfWIjQ1Tjp5YQRbY/xVMISMcil4CVi91+iNle20nnWjiAXbV tSxtvdDUh/diQJ99KHfpbG/Z+5HiHp7+wLtoXSfmFms3nUpZabglwfqDXSo8W40Qa49W xfRJLUBgrroHMr/9hnKNTF0OL5G77uTSiCQmU21puE1lJZzEm9Cc3gCGI1iceH9TSpCg O62juCMrkUN57XH1Ttve9dwpBPVnpjJKgEeMc3PhXRBvi6+lCLSKMeOwQR2QhlrymyqR ZCKQ== X-Gm-Message-State: AOAM532fD3RFUReJqP1yna3buh2ixq3p3+LPdbw5g04y3o8vrRiz/aMw H7zJtnGts9Qua5tU+QniWNSg4JFTNwI= X-Google-Smtp-Source: ABdhPJwLRDhgxFH9cxbQOivnpV82yzV9zj8nfLXbFURfGDYMLEUODncJxET0cMVfVrijZr8+5iWt3g== X-Received: by 2002:a17:903:228c:b0:163:baf6:582a with SMTP id b12-20020a170903228c00b00163baf6582amr11896195plh.43.1654293073610; Fri, 03 Jun 2022 14:51:13 -0700 (PDT) Received: from ldmartin-desk2.. ([50.45.187.67]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b00163ffe73300sm6032866plg.137.2022.06.03.14.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 14:51:12 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Lucas De Marchi Subject: [PATCH 8/8] modprobe: Add --wait Date: Fri, 3 Jun 2022 14:50:47 -0700 Message-Id: <20220603215047.9607-9-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603215047.9607-1-lucas.de.marchi@gmail.com> References: <20220603215047.9607-1-lucas.de.marchi@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: Retry module removal if it fails due to EAGAIN. This allows user to pass --wait , during which `modprobe -r` will keep trying to remove the module. Signed-off-by: Lucas De Marchi --- man/modprobe.xml | 17 ++++++++++++ tools/modprobe.c | 70 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/man/modprobe.xml b/man/modprobe.xml index 0372b6b..db39c7a 100644 --- a/man/modprobe.xml +++ b/man/modprobe.xml @@ -388,6 +388,23 @@ + + + + + + TIMEOUT_MSEC + + + + This option causes modprobe -r to continue trying to + remove a module if it fails due to the module being busy, i.e. its refcount + is not 0 at the time the call is made. Modprobe tries to remove the module + with an incremental sleep time between each tentative up until the maximum + wait time in milliseconds passed in this option. + + + diff --git a/tools/modprobe.c b/tools/modprobe.c index caaf87f..2a2ae21 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -55,14 +56,18 @@ static int force = 0; static int strip_modversion = 0; static int strip_vermagic = 0; static int remove_holders = 0; +static unsigned long long wait_msec = 0; static int quiet_inuse = 0; -static const char cmdopts_s[] = "arRibfDcnC:d:S:sqvVh"; +static const char cmdopts_s[] = "arw:RibfDcnC:d:S:sqvVh"; static const struct option cmdopts[] = { {"all", no_argument, 0, 'a'}, + {"remove", no_argument, 0, 'r'}, {"remove-dependencies", no_argument, 0, 5}, {"remove-holders", no_argument, 0, 5}, + {"wait", required_argument, 0, 'w'}, + {"resolve-alias", no_argument, 0, 'R'}, {"first-time", no_argument, 0, 3}, {"ignore-install", no_argument, 0, 'i'}, @@ -110,6 +115,9 @@ static void help(void) "\t-r, --remove Remove modules instead of inserting\n" "\t --remove-dependencies Deprecated: use --remove-holders\n" "\t --remove-holders Also remove module holders (use together with -r)\n" + "\t-w, --wait When removing a module, wait up to MSEC for\n" + "\t module's refcount to become 0 so it can be\n" + "\t removed (use together with -r)\n" "\t --first-time Fail if module already inserted or removed\n" "\t-i, --ignore-install Ignore install commands\n" "\t-i, --ignore-remove Ignore remove commands\n" @@ -322,6 +330,8 @@ end: static int rmmod_do_remove_module(struct kmod_module *mod) { const char *modname = kmod_module_get_name(mod); + unsigned long long interval_msec = 0, t0_msec = 0, + tend_msec = 0; int flags = 0, err; SHOW("rmmod %s\n", modname); @@ -332,13 +342,45 @@ static int rmmod_do_remove_module(struct kmod_module *mod) if (force) flags |= KMOD_REMOVE_FORCE; - err = kmod_module_remove_module(mod, flags); - if (err == -EEXIST) { - if (!first_time) - err = 0; - else - LOG("Module %s is not in kernel.\n", modname); - } + if (wait_msec) + flags |= KMOD_REMOVE_NOLOG; + + do { + err = kmod_module_remove_module(mod, flags); + if (err == -EEXIST) { + if (!first_time) + err = 0; + else + LOG("Module %s is not in kernel.\n", modname); + break; + } else if (err == -EAGAIN && wait_msec) { + unsigned long long until_msec; + + if (!t0_msec) { + t0_msec = now_msec(); + tend_msec = t0_msec + wait_msec; + interval_msec = 1; + } + + until_msec = get_backoff_delta_msec(t0_msec, tend_msec, + &interval_msec); + err = sleep_until_msec(until_msec); + + if (!t0_msec) + err = -ENOTSUP; + + if (err < 0) { + ERR("Failed to sleep: %s\n", strerror(-err)); + err = -EAGAIN; + break; + } + } else { + break; + } + } while (interval_msec); + + if (err < 0 && wait_msec) + ERR("could not remove '%s': %s\n", modname, strerror(-err)); return err; } @@ -418,7 +460,7 @@ static int rmmod_do_module(struct kmod_module *mod, int flags) } /* 3. @mod itself, but check for refcnt first */ - if (!cmd && !ignore_loaded) { + if (!cmd && !ignore_loaded && !wait_msec) { int usage = kmod_module_get_refcnt(mod); if (usage > 0) { @@ -800,6 +842,16 @@ static int do_modprobe(int argc, char **orig_argv) case 5: remove_holders = 1; break; + case 'w': { + char *endptr = NULL; + wait_msec = strtoul(optarg, &endptr, 0); + if (!*optarg || *endptr) { + ERR("unexpected wait value '%s'.\n", optarg); + err = -1; + goto done; + } + break; + } case 3: first_time = 1; break;