Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1872112ybg; Thu, 30 Jul 2020 05:04:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqEU/ZpQG9/GX4wwm2uVvX+qUvQUd1+qBYoso1AhGIinaUILdDOy83gTmx1RG80CyjOI7u X-Received: by 2002:a17:906:6a5b:: with SMTP id n27mr2261386ejs.154.1596110694206; Thu, 30 Jul 2020 05:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596110694; cv=none; d=google.com; s=arc-20160816; b=w9HSZDf5ZEe47b2b79heNrPphhVU60wa5TYBNJu+AR9AOlnsi7eahb9Y3Rrmc641W2 yy253CAyGu31stftsuLMd6uIuVr9RXcxlCxEsBSHGrxbDvjYzwpY6twbnWYDZ8ONahbv fN3d739pMOX8tZ/OObNFV2fePJsO4IctM1OsGLtNWgGqAIAHmnpNFu9Grhb6Y6KoQ3ZU qnYF1eU85nuFKgR+FIHt5BeMz9q+ybb1z8JzSplgHRVrkzaEBNvKMVQAHamGHpuMEUAr JCdS8V3DGK6ReuqiPN7lwraJJd1vE3JH5QmBwSuC75TIhGi4+ovyJ20ku4FOAByBYOlM yHmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=Zn7OGYBXbEu/jWD5cHBDgUCss74Sx0j1Mzzd8roqaRY=; b=olF3FBCB8P+vd6Q/kcbBtmlz+yq90UZYziVpeHcIs1sKbqn1qzGj8af9UW/WpdbuoJ 9JyAy3ANQ/alxwi0XU+87mIavOm18ygQtZ6jZkl0TdZyuwQ0W+NJ8+ZftuDGAg/pVpH2 3iQ0MHHIT5feuvb7aXjap6VXcHJllnTxaF3V2YmsQrP9j2Tb0TkAhf+nLDww9DX0wrzR mk+oQ/Zrmh3gxnUPWR4LUV3Z5xnAJpeyA2yz7eX1uVoPOesfpn4tA599SOHvV8XrQyXo gQbwYboHYlNrkg2FB5pDJlpSjWb7vCtHicF5KtPrOZrZQB4FsaJfPeGPrV8p3F+CHvCP DVtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si3138552edk.604.2020.07.30.05.04.31; Thu, 30 Jul 2020 05:04:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbgG3L7g (ORCPT + 99 others); Thu, 30 Jul 2020 07:59:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:56402 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727844AbgG3L7e (ORCPT ); Thu, 30 Jul 2020 07:59:34 -0400 Received: from [192.168.15.64] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k17DR-0002va-AS; Thu, 30 Jul 2020 14:59:17 +0300 Subject: [PATCH 02/23] uts: Use generic ns_common::count From: Kirill Tkhai To: viro@zeniv.linux.org.uk, adobriyan@gmail.com, davem@davemloft.net, ebiederm@xmission.com, akpm@linux-foundation.org, christian.brauner@ubuntu.com, areber@redhat.com, serge@hallyn.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, ktkhai@virtuozzo.com Date: Thu, 30 Jul 2020 14:59:31 +0300 Message-ID: <159611037120.535980.13731766189011538488.stgit@localhost.localdomain> In-Reply-To: <159611007271.535980.15362304262237658692.stgit@localhost.localdomain> References: <159611007271.535980.15362304262237658692.stgit@localhost.localdomain> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert uts namespace to use generic counter instead of kref. Signed-off-by: Kirill Tkhai --- include/linux/utsname.h | 9 ++++----- init/version.c | 2 +- kernel/utsname.c | 7 ++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/linux/utsname.h b/include/linux/utsname.h index 44429d9142ca..2b1737c9b244 100644 --- a/include/linux/utsname.h +++ b/include/linux/utsname.h @@ -4,7 +4,6 @@ #include -#include #include #include #include @@ -22,7 +21,6 @@ struct user_namespace; extern struct user_namespace init_user_ns; struct uts_namespace { - struct kref kref; struct new_utsname name; struct user_namespace *user_ns; struct ucounts *ucounts; @@ -33,16 +31,17 @@ extern struct uts_namespace init_uts_ns; #ifdef CONFIG_UTS_NS static inline void get_uts_ns(struct uts_namespace *ns) { - kref_get(&ns->kref); + refcount_inc(&ns->ns.count); } extern struct uts_namespace *copy_utsname(unsigned long flags, struct user_namespace *user_ns, struct uts_namespace *old_ns); -extern void free_uts_ns(struct kref *kref); +extern void free_uts_ns(struct uts_namespace *ns); static inline void put_uts_ns(struct uts_namespace *ns) { - kref_put(&ns->kref, free_uts_ns); + if (refcount_dec_and_test(&ns->ns.count)) + free_uts_ns(ns); } void uts_ns_init(void); diff --git a/init/version.c b/init/version.c index cba341161b58..80d2b7566b39 100644 --- a/init/version.c +++ b/init/version.c @@ -25,7 +25,7 @@ int version_string(LINUX_VERSION_CODE); #endif struct uts_namespace init_uts_ns = { - .kref = KREF_INIT(2), + .ns.count = REFCOUNT_INIT(2), .name = { .sysname = UTS_SYSNAME, .nodename = UTS_NODENAME, diff --git a/kernel/utsname.c b/kernel/utsname.c index e488d0e2ab45..b1ac3ca870f2 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c @@ -33,7 +33,7 @@ static struct uts_namespace *create_uts_ns(void) uts_ns = kmem_cache_alloc(uts_ns_cache, GFP_KERNEL); if (uts_ns) - kref_init(&uts_ns->kref); + refcount_set(&uts_ns->ns.count, 1); return uts_ns; } @@ -103,11 +103,8 @@ struct uts_namespace *copy_utsname(unsigned long flags, return new_ns; } -void free_uts_ns(struct kref *kref) +void free_uts_ns(struct uts_namespace *ns) { - struct uts_namespace *ns; - - ns = container_of(kref, struct uts_namespace, kref); dec_uts_namespaces(ns->ucounts); put_user_ns(ns->user_ns); ns_free_inum(&ns->ns);