From nobody Thu Nov 28 06:29:41 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBEA34779F for ; Thu, 3 Oct 2024 15:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968501; cv=none; b=H2UROS8oSsF5RLfCwAkkn0VmTfm8Uas5rBnUJNXRuSPtMgerA/r5FfjUDBl7a+PpBzj1unPmLnRkpFEyPngAhEiFvOfC9uru3e4nxW6t7j4hOiVBua6VeWMAwQO9b2AqC6vVi4xSq/YZF5jynjaA37fzQ1UaClTZE3BAuHXgafI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968501; c=relaxed/simple; bh=x7e6IA84Y6g/2IMVAFPlI1KZz8qVpAguY4Mb70GdZTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojpTT14B6Gwcb4aSuDcLXayeDcRtPYsjRO5mhJ9X1tawLkBNIUgcFoWTTE1SHzWHL4a1D248XPOE42ivIf5nxIAx437xCGvIfNCay/5m9JAEb+ZHs4rMrSp0DarPEQpOl+O5QnQfuaKHFR4BFyg8poFvt42BjgV1quhiFtDXDGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=V72qORzn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="V72qORzn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727968497; h=from:from:reply-to:subject:subject: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=oQhx9++kG+k1aQeYKn4epgOWGCe4SvtQMhjT//HHnyw=; b=V72qORzn79ENZET25BJqQizrNygFWt96WC6pmkilq3yadkzW82VRvB6YquZN9qvXoI4pjc sUvAznZA/j7pFgmCJbuk3VSaD8QeoG9zmLCyzMxh/PG1gZHbHiC03bYAw69X6QJcauOMgL 2PfDCJV6U/ewmjDDPHWbWOHC7+cASbA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-z9YEDdHKMECjWaCiFVKw9Q-1; Thu, 03 Oct 2024 11:14:54 -0400 X-MC-Unique: z9YEDdHKMECjWaCiFVKw9Q-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AE83C19560BF; Thu, 3 Oct 2024 15:14:52 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0D4D71955E8F; Thu, 3 Oct 2024 15:14:50 +0000 (UTC) From: Alexander Aring To: trondmy@kernel.org Cc: anna@kernel.org, bcodding@redhat.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-nfs@vger.kernel.org, gfs2@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] kobject: add kset_type_create_and_add() helper Date: Thu, 3 Oct 2024 11:14:32 -0400 Message-ID: <20241003151435.3753959-2-aahringo@redhat.com> In-Reply-To: <20241003151435.3753959-1-aahringo@redhat.com> References: <20241003151435.3753959-1-aahringo@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Currently there exists the kset_create_and_add() helper that does not allow to have a different ktype for the created kset kobject. To allow a different ktype this patch will introduce the function kset_type_create_and_add() that allows to set a different ktype instead of using the global default kset_ktype variable. In my example I need to separate the created kobject inside the kset by net-namespaces. This patch allows me to do that by providing a user defined kobj_type structure that implements the necessary namespace functionality. Acked-by: Greg Kroah-Hartman Signed-off-by: Alexander Aring Reviewed-by: Benjamin Coddington --- include/linux/kobject.h | 8 ++++-- lib/kobject.c | 59 ++++++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index c8219505a79f..7504b7547ed2 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -175,8 +175,12 @@ struct kset { void kset_init(struct kset *kset); int __must_check kset_register(struct kset *kset); void kset_unregister(struct kset *kset); -struct kset * __must_check kset_create_and_add(const char *name, const str= uct kset_uevent_ops *u, - struct kobject *parent_kobj); +struct kset * __must_check +kset_type_create_and_add(const char *name, const struct kset_uevent_ops *u, + struct kobject *parent_kobj, const struct kobj_type *ktype); +struct kset * __must_check +kset_create_and_add(const char *name, const struct kset_uevent_ops *u, + struct kobject *parent_kobj); =20 static inline struct kset *to_kset(struct kobject *kobj) { diff --git a/lib/kobject.c b/lib/kobject.c index 72fa20f405f1..09dd3d4c7f56 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -946,6 +946,7 @@ static const struct kobj_type kset_ktype =3D { * @name: the name for the kset * @uevent_ops: a struct kset_uevent_ops for the kset * @parent_kobj: the parent kobject of this kset, if any. + * @ktype: a struct kobj_type for the kset * * This function creates a kset structure dynamically. This structure can * then be registered with the system and show up in sysfs with a call to @@ -957,7 +958,8 @@ static const struct kobj_type kset_ktype =3D { */ static struct kset *kset_create(const char *name, const struct kset_uevent_ops *uevent_ops, - struct kobject *parent_kobj) + struct kobject *parent_kobj, + const struct kobj_type *ktype) { struct kset *kset; int retval; @@ -973,39 +975,38 @@ static struct kset *kset_create(const char *name, kset->uevent_ops =3D uevent_ops; kset->kobj.parent =3D parent_kobj; =20 - /* - * The kobject of this kset will have a type of kset_ktype and belong to - * no kset itself. That way we can properly free it when it is - * finished being used. - */ - kset->kobj.ktype =3D &kset_ktype; + kset->kobj.ktype =3D ktype; kset->kobj.kset =3D NULL; =20 return kset; } =20 /** - * kset_create_and_add() - Create a struct kset dynamically and add it to = sysfs. + * kset_type_create_and_add() - Create a struct kset with kobj_type dynami= cally + * and add it to sysfs. * * @name: the name for the kset * @uevent_ops: a struct kset_uevent_ops for the kset * @parent_kobj: the parent kobject of this kset, if any. + * @ktype: a struct kobj_type for the kset * - * This function creates a kset structure dynamically and registers it - * with sysfs. When you are finished with this structure, call + * This function creates a kset structure with ktype structure dynamically= and + * registers it with sysfs. When you are finished with this structure, ca= ll * kset_unregister() and the structure will be dynamically freed when it - * is no longer being used. + * is no longer being used. Works like kset_create_and_add() just with the + * possibility to assign kobj_type to the kset. * * If the kset was not able to be created, NULL will be returned. */ -struct kset *kset_create_and_add(const char *name, - const struct kset_uevent_ops *uevent_ops, - struct kobject *parent_kobj) +struct kset *kset_type_create_and_add(const char *name, + const struct kset_uevent_ops *uevent_ops, + struct kobject *parent_kobj, + const struct kobj_type *ktype) { struct kset *kset; int error; =20 - kset =3D kset_create(name, uevent_ops, parent_kobj); + kset =3D kset_create(name, uevent_ops, parent_kobj, ktype); if (!kset) return NULL; error =3D kset_register(kset); @@ -1015,6 +1016,34 @@ struct kset *kset_create_and_add(const char *name, } return kset; } +EXPORT_SYMBOL_GPL(kset_type_create_and_add); + +/** + * kset_create_and_add() - Create a struct kset dynamically and add it to = sysfs. + * + * @name: the name for the kset + * @uevent_ops: a struct kset_uevent_ops for the kset + * @parent_kobj: the parent kobject of this kset, if any. + * + * This function creates a kset structure dynamically and registers it + * with sysfs. When you are finished with this structure, call + * kset_unregister() and the structure will be dynamically freed when it + * is no longer being used. + * + * If the kset was not able to be created, NULL will be returned. + */ +struct kset *kset_create_and_add(const char *name, + const struct kset_uevent_ops *uevent_ops, + struct kobject *parent_kobj) +{ + /* + * The kobject of this kset will have a type of kset_ktype and belong to + * no kset itself. That way we can properly free it when it is + * finished being used. + */ + return kset_type_create_and_add(name, uevent_ops, parent_kobj, + &kset_ktype); +} EXPORT_SYMBOL_GPL(kset_create_and_add); =20 =20 --=20 2.43.0 From nobody Thu Nov 28 06:29:41 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D19D1A4E77 for ; Thu, 3 Oct 2024 15:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968503; cv=none; b=IIKX4BIOy/S2cTYpYypnNR/zfZ0LEzvIx+TuxMP57fPWzB3ybosHHXJKG5N1xhtSWoY6cRRcvtrBIa3bTM6YbSlPFEhzZT914SOJ0qomxq/6uFd/vR9GFK4MLQawqPyA+e/VeaqqYAEMQ0+AKqCIQCgtW7tJH35gxzvDGYGcp2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968503; c=relaxed/simple; bh=/HOjq9X9X2KQMEsqDRneNuPn5l3Rhurp22TwSf3G5Sg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J4JyAn0YNHFx8nrMbFsieDjlCXvBV6uXpexe8zoEv1dUPWE6uJvrgdMG9OhsrOsyflpCMAThkfyychjcoaitQBQHLvCDqbtjdLTQBLL0Uw40erytHPISusQ7GXfQZLsyDa0F8NOw7mSm0w5CNK7viMa35xyEtKTban/P2YZfM/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OWdwPALE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OWdwPALE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727968501; h=from:from:reply-to:subject:subject: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=qhdi0ZWmWYR0MqvX3gdvffJxUEfr+B4dJmnDyHHBiGU=; b=OWdwPALENTbpVcyvFKsFGz0ns5bl4ZnXyNXIAtHrgnEWPPElGFXa2+eEUUjzDhAnG/X4Bu 4CRQMeyESAXg4mjE9Xjxm6YZeqTUrFlDWm7umyrNTYRP1Nc2XTbj7ICAdAApZCDyT/oL5L aG7FTT8pWrAPl50XAqHsqEy6cV/Eddg= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-OWZ8mrn_OIaGgW36qh4LDw-1; Thu, 03 Oct 2024 11:14:55 -0400 X-MC-Unique: OWZ8mrn_OIaGgW36qh4LDw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07A62195608A; Thu, 3 Oct 2024 15:14:54 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AACFC19560A3; Thu, 3 Oct 2024 15:14:52 +0000 (UTC) From: Alexander Aring To: trondmy@kernel.org Cc: anna@kernel.org, bcodding@redhat.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-nfs@vger.kernel.org, gfs2@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] kobject: export generic helper ops Date: Thu, 3 Oct 2024 11:14:33 -0400 Message-ID: <20241003151435.3753959-3-aahringo@redhat.com> In-Reply-To: <20241003151435.3753959-1-aahringo@redhat.com> References: <20241003151435.3753959-1-aahringo@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" This patch exports generic helpers like kset_release() and kset_get_ownership() so users can use them in their own struct kobj_type implementation instead of implementing their own functions that do the same. Acked-by: Greg Kroah-Hartman Signed-off-by: Alexander Aring Reviewed-by: Benjamin Coddington --- include/linux/kobject.h | 2 ++ lib/kobject.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 7504b7547ed2..5fbc358e2be6 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -181,6 +181,8 @@ kset_type_create_and_add(const char *name, const struct= kset_uevent_ops *u, struct kset * __must_check kset_create_and_add(const char *name, const struct kset_uevent_ops *u, struct kobject *parent_kobj); +void kset_release(struct kobject *kobj); +void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *g= id); =20 static inline struct kset *to_kset(struct kobject *kobj) { diff --git a/lib/kobject.c b/lib/kobject.c index 09dd3d4c7f56..ccd2f6282c81 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -920,19 +920,21 @@ struct kobject *kset_find_obj(struct kset *kset, cons= t char *name) } EXPORT_SYMBOL_GPL(kset_find_obj); =20 -static void kset_release(struct kobject *kobj) +void kset_release(struct kobject *kobj) { struct kset *kset =3D container_of(kobj, struct kset, kobj); pr_debug("'%s' (%p): %s\n", kobject_name(kobj), kobj, __func__); kfree(kset); } +EXPORT_SYMBOL_GPL(kset_release); =20 -static void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kg= id_t *gid) +void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *g= id) { if (kobj->parent) kobject_get_ownership(kobj->parent, uid, gid); } +EXPORT_SYMBOL_GPL(kset_get_ownership); =20 static const struct kobj_type kset_ktype =3D { .sysfs_ops =3D &kobj_sysfs_ops, --=20 2.43.0 From nobody Thu Nov 28 06:29:41 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E5EF1A3A98 for ; Thu, 3 Oct 2024 15:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968503; cv=none; b=fPtrRj0Dss9yBWtHdABC/OftQ9sijbkqAAJLripRfAqKUV6d0u84z06JHp0S4+BunDikn3FPD+UZKBlFZHWONko0ZIPBUDOUON+47ajjbLMP2DPtI78iulsS+Q4MZSfyn3TH7LXcHAyadzsBvBlKDqTjYUG+0pNeczCViKg/X8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968503; c=relaxed/simple; bh=08J95sym7EbUZ5ed1aHKrIi1SAvmbhccq003fACym88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQXZnOs5UN1Z9vvJses/mbO50uvih0L4OCaKi/cIHH4McszmLafSq/Tvq/xpNVlIgSVDfCYv0ISoaXCtjqSDG0EkvxbWBQsr6UJ04/lH+3vGr8sORR8pXvsIJlp/EqM/9ORPlNEtdq4lA8ar9okShqvxX5XEQG4VTppd/b6yk2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cL2nDCyL; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cL2nDCyL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727968500; h=from:from:reply-to:subject:subject: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=wvSMEY8HtROR8gklRwCjr4mxN3nmXaS9GGq94vmCN2k=; b=cL2nDCyLKN2kdAfNmRpAZ8NrfFwUs9C9NanM3rFzPskMNqhTRsRvCKhN+XW1BZa7hgQNSg 7wuP/8re+9yUE1Zgzw2yDzulSOE8B4y/1auCzhx4Coe3w/2L8C2p5PO/MlTr+N7U9PDk3H ns1qD+uVaprKNrv5sr3DTyFsyKv+7Jo= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-169-b9oxfTZsPkqb320o_NbS0Q-1; Thu, 03 Oct 2024 11:14:57 -0400 X-MC-Unique: b9oxfTZsPkqb320o_NbS0Q-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B01D71955E84; Thu, 3 Oct 2024 15:14:55 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 35C351955E8F; Thu, 3 Oct 2024 15:14:54 +0000 (UTC) From: Alexander Aring To: trondmy@kernel.org Cc: anna@kernel.org, bcodding@redhat.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-nfs@vger.kernel.org, gfs2@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] nfs: sysfs: use kset_type_create_and_add() Date: Thu, 3 Oct 2024 11:14:34 -0400 Message-ID: <20241003151435.3753959-4-aahringo@redhat.com> In-Reply-To: <20241003151435.3753959-1-aahringo@redhat.com> References: <20241003151435.3753959-1-aahringo@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Since we have the new udev helper kset_type_create_and_add() helper we can use it as it allows to have an own kobj_type ktype that is necessary for nfs for the nfs_netns_object_child_ns_type() kset type callback. We lose some errno information related to kset_register() in probably non-existing cases. We return always -ENOMEM as other uses of kset_create_and_add() does. The nfs_kset_release() can be replaced by the default udev helper kset_release() as it does the same functionality. Signed-off-by: Alexander Aring Reviewed-by: Benjamin Coddington --- fs/nfs/sysfs.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index bf378ecd5d9f..a6584203b7ff 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -20,12 +20,6 @@ =20 static struct kset *nfs_kset; =20 -static void nfs_kset_release(struct kobject *kobj) -{ - struct kset *kset =3D container_of(kobj, struct kset, kobj); - kfree(kset); -} - static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_typ= e( const struct kobject *kobj) { @@ -33,35 +27,18 @@ static const struct kobj_ns_type_operations *nfs_netns_= object_child_ns_type( } =20 static struct kobj_type nfs_kset_type =3D { - .release =3D nfs_kset_release, + .release =3D kset_release, .sysfs_ops =3D &kobj_sysfs_ops, .child_ns_type =3D nfs_netns_object_child_ns_type, }; =20 int nfs_sysfs_init(void) { - int ret; - - nfs_kset =3D kzalloc(sizeof(*nfs_kset), GFP_KERNEL); + nfs_kset =3D kset_type_create_and_add("nfs", NULL, fs_kobj, + &nfs_kset_type); if (!nfs_kset) return -ENOMEM; =20 - ret =3D kobject_set_name(&nfs_kset->kobj, "nfs"); - if (ret) { - kfree(nfs_kset); - return ret; - } - - nfs_kset->kobj.parent =3D fs_kobj; - nfs_kset->kobj.ktype =3D &nfs_kset_type; - nfs_kset->kobj.kset =3D NULL; - - ret =3D kset_register(nfs_kset); - if (ret) { - kfree(nfs_kset); - return ret; - } - return 0; } =20 --=20 2.43.0 From nobody Thu Nov 28 06:29:41 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5006B19F428 for ; Thu, 3 Oct 2024 15:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968505; cv=none; b=DRxyBBz7fE3epkKv/Cv8sQVEg84BueCeKAFxFsE52fFWft8V6cu10Tt0XKA1fOE6FN5QgAK2dmuYd2qhSHRsWXgiSU6tLP8Rmi27HyHFj7aF2GH2MZaGchMelTfx2km55GWoLKUSsLf3xrSCpMM+cYfsbe+5HD1zracnO0Axzn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727968505; c=relaxed/simple; bh=2b/wY0DFbQYWHlbG0ppoXS9Fnj2qbZ+0XQWT2jrk4Wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M99qTnzbwZlAN2ULerMh7AU7Yfasm/HLZPX/mNBw8ejg/GcAT3RhGZKp824jq45I2oVmSQfBvUTB0AvCYu/+es8rbtKI9NAa8eTZBKWXokXsq84a21WQgJkJ6HkfMCdFaxo6iRwEWd58Z4x73O4luQUH//8JCzlR/8QC//fHAsI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RsMu51nx; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RsMu51nx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727968501; h=from:from:reply-to:subject:subject: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=IlSbepF9atKbQ6z8jk2+CU+FBFUKIVhtlEKWxO1tf0E=; b=RsMu51nxCzus+DELuQb7ppEibPSLyhqd+iS+C2P3FW+TpLmaioNXOn+fN0j0mHNS1fTITI i2e0lgsyxZMgk0BouesY4PScrYYb6/t24GiaREO5uRajRybT2YDlJGpD9ZyqeS6dAuywYV AzesmBuiq7frJqOn7r6m08zVQJhLI/Q= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-6-uzO0Hg9iPcOcbyQfpjYwJw-1; Thu, 03 Oct 2024 11:14:58 -0400 X-MC-Unique: uzO0Hg9iPcOcbyQfpjYwJw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0CFCB19560BC; Thu, 3 Oct 2024 15:14:57 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C337B19560A3; Thu, 3 Oct 2024 15:14:55 +0000 (UTC) From: Alexander Aring To: trondmy@kernel.org Cc: anna@kernel.org, bcodding@redhat.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-nfs@vger.kernel.org, gfs2@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] nfs: sysfs: use default get_ownership() callback Date: Thu, 3 Oct 2024 11:14:35 -0400 Message-ID: <20241003151435.3753959-5-aahringo@redhat.com> In-Reply-To: <20241003151435.3753959-1-aahringo@redhat.com> References: <20241003151435.3753959-1-aahringo@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Since commit 5f81880d5204 ("sysfs, kobject: allow creating kobject belonging to arbitrary users") it seems that there could be cases for kobjects belonging to arbitrary users. This callback is set by default when using kset_create_and_add() to allow creating kobjects with different ownerships according to its parent. This patch will assign the default callback now for nfs kobjects for cases when the parent has different ownership than the default one. Signed-off-by: Alexander Aring Reviewed-by: Benjamin Coddington --- fs/nfs/sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index a6584203b7ff..b5737464b892 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -27,6 +27,7 @@ static const struct kobj_ns_type_operations *nfs_netns_ob= ject_child_ns_type( } =20 static struct kobj_type nfs_kset_type =3D { + .get_ownership =3D kset_get_ownership, .release =3D kset_release, .sysfs_ops =3D &kobj_sysfs_ops, .child_ns_type =3D nfs_netns_object_child_ns_type, --=20 2.43.0