From patchwork Thu Oct 31 18:12:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 11221685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6468E14E5 for ; Thu, 31 Oct 2019 18:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 41C1A20650 for ; Thu, 31 Oct 2019 18:13:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AqMFIt+t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbfJaSNB (ORCPT ); Thu, 31 Oct 2019 14:13:01 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22183 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726602AbfJaSNB (ORCPT ); Thu, 31 Oct 2019 14:13:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572545580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PgHgS8wxyrk2UAwaz8TKSOI/jaVcf6kI4ZFLgSl800w=; b=AqMFIt+ta8VfCw5lrjpnRCGCOIPSPbRANZ4gd5Whj9/TEIVVCYyTk3RPxZT8aK0UYmxA46 bAFM2q6Bs7ZJbwj3rLjKetLlJ4xrNlvRZMAKlFt6M5tpui1cCYA++E7T/4yuRDCApyVOkZ KJkwyDRq0utOBsYhNM/eq6Cd9kDdODA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-uJVATSQZPcyl6PnPv0oQqQ-1; Thu, 31 Oct 2019 14:12:56 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CA50107ACC2; Thu, 31 Oct 2019 18:12:56 +0000 (UTC) Received: from astarta.redhat.com (ovpn-117-33.ams2.redhat.com [10.36.117.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 424E91001B32; Thu, 31 Oct 2019 18:12:55 +0000 (UTC) From: Yauheni Kaliuta To: Lucas De Marchi Cc: linux-modules@vger.kernel.org Subject: [PATCH] modprobe: ignore builtin module on recursive removing Date: Thu, 31 Oct 2019 20:12:53 +0200 Message-Id: <20191031181253.18162-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: uJVATSQZPcyl6PnPv0oQqQ-1 X-Mimecast-Spam-Score: 0 Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: If there are built-in dependencies and any of them is built-in in the kernel, modprobe -r fails with modprobe: FATAL: Module module_name is builtin. It makes sense to ignore such dependencies for the case when removing is called for non-top level module. Example: cifs module, it declares bunch of softdeps and the first one fails on some kernel configs: modprobe: FATAL: Module gcm is builtin. Signed-off-by: Yauheni Kaliuta --- tools/modprobe.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/modprobe.c b/tools/modprobe.c index a9e2331567af..44cd15c2bf57 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -353,7 +353,8 @@ static int rmmod_do_remove_module(struct kmod_module *mod) return err; } -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies); +static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies, + bool ignore_builtin); static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) { @@ -361,7 +362,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) kmod_list_foreach_reverse(l, list) { struct kmod_module *m = kmod_module_get_module(l); - int r = rmmod_do_module(m, false); + int r = rmmod_do_module(m, false, true); kmod_module_unref(m); if (r < 0 && stop_on_errors) @@ -371,7 +372,8 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) return 0; } -static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies) +static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies, + bool ignore_builtin) { const char *modname = kmod_module_get_name(mod); struct kmod_list *pre = NULL, *post = NULL; @@ -401,8 +403,12 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies) } goto error; } else if (state == KMOD_MODULE_BUILTIN) { - LOG("Module %s is builtin.\n", modname); - err = -ENOENT; + if (ignore_builtin) { + err = 0; + } else { + LOG("Module %s is builtin.\n", modname); + err = -ENOENT; + } goto error; } } @@ -462,7 +468,7 @@ static int rmmod(struct kmod_ctx *ctx, const char *alias) kmod_list_foreach(l, list) { struct kmod_module *mod = kmod_module_get_module(l); - err = rmmod_do_module(mod, true); + err = rmmod_do_module(mod, true, false); kmod_module_unref(mod); if (err < 0) break;