From nobody Thu Nov 28 16:50:54 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 2CB2F199E8C for ; Mon, 30 Sep 2024 20:14:17 +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=1727727260; cv=none; b=evwDPi2lwNhZ7EBu2hF7myJRk62EmJxFV08ga+i+NwBpzsR8vW9mGjdqq5YiYWrkU/wslhHvNL/SYMzQL+BuahZZ9m8owPyNsctiYxwvmI421/qt1PsVTsR8kMmfjOucC8Up7zafu/uzsJdT08FFkrIx+8Eqh9iM5p9ANzByheo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727260; c=relaxed/simple; bh=7+E295+fTdtFYJE7SO/shAHSrnEGhOeeX5vu6OAwvNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kHpYkMOvmzx5lFyYRTLjCjp1ml2YtfjC9cGF0PEbMJIfQvBRqmihaq7NmwLWrmbWLFxfavPH2Is0g9Poji+2Ump+A4bPl5Rixnn/ITCRJxFYlwgIlA6FrIGZ+2FP2G9oR6oOTgmHivSLZC//99AMfkostHPjjHZ7XHS8sC+qXrw= 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=Fw1rCGsq; 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="Fw1rCGsq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727257; 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=f+k9OgWsKdKtc2JL0VLbtqiJHf8Tzgl+WMY1WPT70Ug=; b=Fw1rCGsq+X9PpH67rL9D3TjtiiLF5tgpU0Bp8iElA5TCljgcDUwG9n+6iGIRZzkqLzaC2Z S9LDdjuif94q0ar6P7GhOFKOTqFcOOhnLrXTU619Nqu612A45B+duO8au8xAHPZwLrSb7b TJzCLQE9ins6E/vC9Zuq2LWgdItoHJk= 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-375-IIx2CHq2NJ2ZqCw6aEiNow-1; Mon, 30 Sep 2024 16:14:12 -0400 X-MC-Unique: IIx2CHq2NJ2ZqCw6aEiNow-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 909B3197703B; Mon, 30 Sep 2024 20:14:08 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2FFB61955DC7; Mon, 30 Sep 2024 20:14:06 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 01/12] dlm: introduce dlm_find_lockspace_name() Date: Mon, 30 Sep 2024 16:13:47 -0400 Message-ID: <20240930201358.2638665-2-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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" A DLM lockspace can be either identified by it's unique id or name. Later patches will introduce a new netlink api that is using a unique lockspace name to identify a lockspace in the lslist. This is mostly required for sysfs functionality that is currently solved by a per lockspace kobject allocation. The new netlink api cannot simple lookup the lockspace by a container_of() call to do whatever sysfs is providing so we introduce dlm_find_lockspace_name() to offer such functionality. Signed-off-by: Alexander Aring --- fs/dlm/lockspace.c | 18 ++++++++++++++++++ fs/dlm/lockspace.h | 1 + 2 files changed, 19 insertions(+) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 8afac6e2dff0..00d37125bc44 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -238,6 +238,24 @@ void dlm_lockspace_exit(void) kset_unregister(dlm_kset); } =20 +struct dlm_ls *dlm_find_lockspace_name(const char *lsname) +{ + struct dlm_ls *ls; + + spin_lock_bh(&lslist_lock); + + list_for_each_entry(ls, &lslist, ls_list) { + if (!strncmp(ls->ls_name, lsname, DLM_LOCKSPACE_LEN)) { + atomic_inc(&ls->ls_count); + goto out; + } + } + ls =3D NULL; + out: + spin_unlock_bh(&lslist_lock); + return ls; +} + struct dlm_ls *dlm_find_lockspace_global(uint32_t id) { struct dlm_ls *ls; diff --git a/fs/dlm/lockspace.h b/fs/dlm/lockspace.h index 47ebd4411926..7898a906aab9 100644 --- a/fs/dlm/lockspace.h +++ b/fs/dlm/lockspace.h @@ -22,6 +22,7 @@ =20 int dlm_lockspace_init(void); void dlm_lockspace_exit(void); +struct dlm_ls *dlm_find_lockspace_name(const char *lsname); struct dlm_ls *dlm_find_lockspace_global(uint32_t id); struct dlm_ls *dlm_find_lockspace_local(void *id); struct dlm_ls *dlm_find_lockspace_device(int minor); --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 291AF1A2559 for ; Mon, 30 Sep 2024 20:14:17 +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=1727727258; cv=none; b=F9PCp3biqtqeav6LbrmdjEJ6wU/La6MW5FuOqG6+4IxMZ8Fg24LbHrCFPzSg25az0IXtp4WzVPX1kKQRoL78qKUrJVlSU4Y1OhysPyvourZr97W6tuskSDUhppCsr9gqTg2idp3bqpn0m86Bo9yalX4ZTzySefMubkmvjxC47k4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727258; c=relaxed/simple; bh=hOxzM1vvni+VRw8MGBOe/I2/OQyuu1ImCQy9QbCD/G0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DgOfJfLfGo0PikL2Ibekb1teDKoI1mQXqEz2rUGjKRRqu9/qwKuaAZqCS01ljp0h12DhtUnCogDI7H6gDEVhrWNWNVo75Kp8FHPl0i3YeihvOSD+7wIPYplHjk730k+UrTajn3uVmyPpeqAoVRO5HouJSazeFhNtsy6S46HIAIw= 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=RutqaaaU; 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="RutqaaaU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727256; 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=fJGj4fvColy9wu2xMOGt6pdmjm2QlwLQUgqtQvJQT44=; b=RutqaaaUxCCLEFweBZFws7XVfSQkuR9U2FQ87DUeElXsZA6sDsswKTeF5duMhVtqdmJSES SuI+ApOAlXLr+2XnY7V05JHF3+5yV8K2ZWVWbfFnslB9jrusvXGR5ppfNtV5JiZX4InKU5 90TBEiI38W3iGqb5m2Z5pqPlXXPbMa4= 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-96-h0P90KnmPRCzGgdrNotA0A-1; Mon, 30 Sep 2024 16:14:14 -0400 X-MC-Unique: h0P90KnmPRCzGgdrNotA0A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 2F93219626DA; Mon, 30 Sep 2024 20:14:11 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C437C1955DC7; Mon, 30 Sep 2024 20:14:08 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 02/12] dlm: disallow different configs nodeid storages Date: Mon, 30 Sep 2024 16:13:48 -0400 Message-ID: <20240930201358.2638665-3-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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" The DLM configfs path has usually a nodeid in it's directory path and again a file to store the nodeid again in a separate storage. It is forced that the user space will set both (the directory name and nodeid file) storage to the same value if it doesn't do that we run in some kind of broken state. This patch will simply represent the file storage to it's upper directory nodeid name. It will force the user now to use a valid unsigned int as nodeid directory name and will ignore all nodeid writes in the nodeid file storage as this will now always represent the upper nodeid directory name. Signed-off-by: Alexander Aring --- fs/dlm/config.c | 53 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index eac96f1c1d74..1b213b5beb19 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -24,9 +24,9 @@ #include "lowcomms.h" =20 /* - * /config/dlm//spaces//nodes//nodeid + * /config/dlm//spaces//nodes//nodeid (refers to ) * /config/dlm//spaces//nodes//weight - * /config/dlm//comms//nodeid + * /config/dlm//comms//nodeid (refers to ) * /config/dlm//comms//local * /config/dlm//comms//addr (write only) * /config/dlm//comms//addr_list (read only) @@ -517,6 +517,12 @@ static void release_space(struct config_item *i) static struct config_item *make_comm(struct config_group *g, const char *n= ame) { struct dlm_comm *cm; + unsigned int nodeid; + int rv; + + rv =3D kstrtouint(name, 0, &nodeid); + if (rv) + return ERR_PTR(rv); =20 cm =3D kzalloc(sizeof(struct dlm_comm), GFP_NOFS); if (!cm) @@ -528,7 +534,7 @@ static struct config_item *make_comm(struct config_grou= p *g, const char *name) if (!cm->seq) cm->seq =3D dlm_comm_count++; =20 - cm->nodeid =3D -1; + cm->nodeid =3D nodeid; cm->local =3D 0; cm->addr_count =3D 0; cm->mark =3D 0; @@ -555,16 +561,25 @@ static void release_comm(struct config_item *i) static struct config_item *make_node(struct config_group *g, const char *n= ame) { struct dlm_space *sp =3D config_item_to_space(g->cg_item.ci_parent); + unsigned int nodeid; struct dlm_node *nd; + uint32_t seq =3D 0; + int rv; + + rv =3D kstrtouint(name, 0, &nodeid); + if (rv) + return ERR_PTR(rv); =20 nd =3D kzalloc(sizeof(struct dlm_node), GFP_NOFS); if (!nd) return ERR_PTR(-ENOMEM); =20 config_item_init_type_name(&nd->item, name, &node_type); - nd->nodeid =3D -1; + nd->nodeid =3D nodeid; nd->weight =3D 1; /* default weight of 1 if none is set */ nd->new =3D 1; /* set to 0 once it's been read by dlm_nodeid_list() */ + dlm_comm_seq(nodeid, &seq); + nd->comm_seq =3D seq; =20 mutex_lock(&sp->members_lock); list_add(&nd->list, &sp->members); @@ -622,16 +637,19 @@ void dlm_config_exit(void) =20 static ssize_t comm_nodeid_show(struct config_item *item, char *buf) { - return sprintf(buf, "%d\n", config_item_to_comm(item)->nodeid); + unsigned int nodeid; + int rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + return sprintf(buf, "%u\n", nodeid); } =20 static ssize_t comm_nodeid_store(struct config_item *item, const char *buf, size_t len) { - int rc =3D kstrtoint(buf, 0, &config_item_to_comm(item)->nodeid); - - if (rc) - return rc; return len; } =20 @@ -772,20 +790,19 @@ static struct configfs_attribute *comm_attrs[] =3D { =20 static ssize_t node_nodeid_show(struct config_item *item, char *buf) { - return sprintf(buf, "%d\n", config_item_to_node(item)->nodeid); + unsigned int nodeid; + int rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + return sprintf(buf, "%u\n", nodeid); } =20 static ssize_t node_nodeid_store(struct config_item *item, const char *buf, size_t len) { - struct dlm_node *nd =3D config_item_to_node(item); - uint32_t seq =3D 0; - int rc =3D kstrtoint(buf, 0, &nd->nodeid); - - if (rc) - return rc; - dlm_comm_seq(nd->nodeid, &seq); - nd->comm_seq =3D seq; return len; } =20 --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 94A151A2573 for ; Mon, 30 Sep 2024 20:14:20 +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=1727727262; cv=none; b=kHoAfpDWuclPx/Au8I5TSts5SFYUKxMKYftaSX0FpmLJ5SvDhDU+zAkLukQ8vvScc/wWWu5oLpvC1L1XPfko2I9nr+a5dYJikHEYO+UQV+7Gh7iw3lm1pRRt24vjuYDdaS45Ez9VOUicQvdB6BN/o3RhBx0zzKXgD+TqiVsUIFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727262; c=relaxed/simple; bh=LitgeosA1kNuh6xTn2yE5NwzjZSg0vvXxbUPBiUJ8eM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MghlakgP7bpVO4/OqumE8NCTNL6i3FQwJNQvJRQMTst2HW2Nh0owcssm7mPEVLLTrO9R5xICd2z5uoOqlQfhYG8hRU9peHbzpBWq7hSn/4ldov1IEpshwJPyMXk+3f6i2kTI+yl/mD0Mim+oVwnDGFiEdbC3bDgQR+/6sqxo4as= 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=O1GEZyl+; 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="O1GEZyl+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727259; 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=yKvDQYxKi3Q+wIlSbLg2vgsESCwnkiSVO3lfYBspn+o=; b=O1GEZyl+HLCHSTELuwreac7yTM2ZZcNwEkIZK27IOj48vUtwsD+AlDVk3Gi0jZI/t+BBRQ OqRlCB3NFQnzX4NJsMBesSf4pzdJkp4rYHXa1cyNkvBmfyYqyfTndxiwNNYeCRYX6vqwv3 hMYzauWfC06tK3XAZuu9+r9EipSXXC8= 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-569-aQSO9k7_OpOhR9NRuexINw-1; Mon, 30 Sep 2024 16:14:16 -0400 X-MC-Unique: aQSO9k7_OpOhR9NRuexINw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 C55D619626D3; Mon, 30 Sep 2024 20:14:13 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 62D331955DC7; Mon, 30 Sep 2024 20:14:11 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 03/12] dlm: add struct net to dlm_new_lockspace() Date: Mon, 30 Sep 2024 16:13:49 -0400 Message-ID: <20240930201358.2638665-4-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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" To prepare a namespace separation for each DLM lockspaces context we add a struct net parameter that the user tells us in which net-namespace the lockspace should be created. We are using net-namespace here because a DLM lockspaces context acts like a per cluster node separation and the created per node sockets need to be separated by their net-namespaces anyway. It just fits that the DLM lockspaces are also separated by a per "network entity". This patch only prepares for such parameter for a functionality that does not exist yet. It does not have any effect. If there will be support for such handling the DLM user need to activate it anyway as the applied parameter for now is the "&init_net" instance that is the default namespace which we are currently using. Signed-off-by: Alexander Aring --- drivers/md/md-cluster.c | 3 ++- fs/dlm/lockspace.c | 5 +++-- fs/gfs2/lock_dlm.c | 6 +++--- fs/ocfs2/stack_user.c | 2 +- include/linux/dlm.h | 9 +++++++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c index 6595f89becdb..a79c3833af96 100644 --- a/drivers/md/md-cluster.c +++ b/drivers/md/md-cluster.c @@ -897,7 +897,8 @@ static int join(struct mddev *mddev, int nodes) =20 memset(str, 0, 64); sprintf(str, "%pU", mddev->uuid); - ret =3D dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, + ret =3D dlm_new_lockspace(&init_net, str, + mddev->bitmap_info.cluster_name, DLM_LSFL_SOFTIRQ, LVB_SIZE, &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace); if (ret) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 00d37125bc44..2dd37a2e718d 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -663,8 +663,9 @@ static int __dlm_new_lockspace(const char *name, const = char *cluster, return error; } =20 -int dlm_new_lockspace(const char *name, const char *cluster, uint32_t flag= s, - int lvblen, const struct dlm_lockspace_ops *ops, +int dlm_new_lockspace(struct net *net, const char *name, const char *clust= er, + uint32_t flags, int lvblen, + const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace) { diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c index fa5134df985f..6c5dce57a2ee 100644 --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c @@ -1328,9 +1328,9 @@ static int gdlm_mount(struct gfs2_sbd *sdp, const cha= r *table) * create/join lockspace */ =20 - error =3D dlm_new_lockspace(fsname, cluster, flags, GDLM_LVB_SIZE, - &gdlm_lockspace_ops, sdp, &ops_result, - &ls->ls_dlm); + error =3D dlm_new_lockspace(&init_net, fsname, cluster, flags, + GDLM_LVB_SIZE, &gdlm_lockspace_ops, sdp, + &ops_result, &ls->ls_dlm); if (error) { fs_err(sdp, "dlm_new_lockspace error %d\n", error); goto fail_free; diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index 77edcd70f72c..23611eba58ef 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c @@ -984,7 +984,7 @@ static int user_cluster_connect(struct ocfs2_cluster_co= nnection *conn) conn->cc_private =3D lc; lc->oc_type =3D NO_CONTROLD; =20 - rc =3D dlm_new_lockspace(conn->cc_name, conn->cc_cluster_name, + rc =3D dlm_new_lockspace(&init_net, conn->cc_name, conn->cc_cluster_name, DLM_LSFL_NEWEXCL, DLM_LVB_LEN, &ocfs2_ls_ops, conn, &ops_rv, &fsdlm); if (rc) { diff --git a/include/linux/dlm.h b/include/linux/dlm.h index bacda9898f2b..ecab5c197a7f 100644 --- a/include/linux/dlm.h +++ b/include/linux/dlm.h @@ -11,9 +11,9 @@ #ifndef __DLM_DOT_H__ #define __DLM_DOT_H__ =20 +#include #include =20 - struct dlm_slot { int nodeid; /* 1 to MAX_INT */ int slot; /* 1 to MAX_INT */ @@ -43,6 +43,11 @@ struct dlm_lockspace_ops { * * Create/join a lockspace. * + * net: the net namespace context pointer where the lockspace belongs to. + * DLM lockspaces can be separated according to net namespaces. As DLM + * requires networking communication this net namespace can be used to + * have a own DLM lockspace on each network entity e.g. a DLM node. + * * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not * including terminating null). * @@ -82,7 +87,7 @@ struct dlm_lockspace_ops { * lockspace: handle for dlm functions */ =20 -int dlm_new_lockspace(const char *name, const char *cluster, +int dlm_new_lockspace(struct net *net, const char *name, const char *clust= er, uint32_t flags, int lvblen, const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace); --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 BBCB41A2C35 for ; Mon, 30 Sep 2024 20:14:23 +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=1727727265; cv=none; b=NFSx06tT3dUiS+DDzILLDByzR+iIubV3PsLHtWbWpfKn2paBbWw1v+sw3hAfjYqfk4L4hCiwbqHoX+ptY9rrFq9StWrRljBwrOxi99x9yGD+2wI53h4M4u469hlfVADZ/y8H9zZSEKTMl6LU5PtItDTLIj4vaA00uEQYnyoGNIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727265; c=relaxed/simple; bh=yyYkU1ftial3IHB+h4Bmg6vRVbYC0AGupABRCZ1Be54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=srEa48M8/JCKK5CPCZn95ObK+H3xD0AiwPxcrUbV+z56rYMNGHc+9R/7wKmDK7oaTwq41ZImMoOOLvdPsG6EI9cItrAkJ2mhnlNIjoubOAH3G17+tlzQBOfsGZ1ntctE+Yr0c3L4N8OprbEKDzryHdDKr3qNh8W2aBQIFDpZjbU= 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=YAhp+R7D; 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="YAhp+R7D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727262; 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=Y7rP0orM8QjhHGTk8aHIfF2wBCeC8AcAEDsdCZCHuMQ=; b=YAhp+R7Dien7K84IE0N1ZxPlptfKjNQkG4iADgD3fpqabPN5LK9UKKEhdgaE1ZJcuIwSOO EI/6zEls6qmBHh62au+fGtkut5xkQP+Xm6v7NLjdCz578Ro9VgeC/LF+CyQAP9mwaWsFo4 YnNZscEw9Xl+9j5wJLS86kWqaHDaNAo= 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-44-RBsRsetrNXOiR1nu9iuhdQ-1; Mon, 30 Sep 2024 16:14:18 -0400 X-MC-Unique: RBsRsetrNXOiR1nu9iuhdQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 685E1196A408; Mon, 30 Sep 2024 20:14:16 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 04C4A1955DC7; Mon, 30 Sep 2024 20:14:13 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 04/12] dlm: handle port as __be16 network byte order Date: Mon, 30 Sep 2024 16:13:50 -0400 Message-ID: <20240930201358.2638665-5-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 handles the DLM listen port setting internally as byte order as it is a value that is used as network byte on the wire. The user space still sets this value as host byte order for configfs as we don't break UAPI here. Signed-off-by: Alexander Aring --- fs/dlm/config.c | 55 +++++++++++++++++++++++++++++++++++------------ fs/dlm/config.h | 2 +- fs/dlm/lowcomms.c | 8 +++---- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 1b213b5beb19..77a86c180d0e 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -73,7 +73,7 @@ const struct rhashtable_params dlm_rhash_rsb_params =3D { =20 struct dlm_cluster { struct config_group group; - unsigned int cl_tcp_port; + __be16 cl_tcp_port; unsigned int cl_buffer_size; unsigned int cl_rsbtbl_size; unsigned int cl_recover_timer; @@ -132,6 +132,45 @@ static ssize_t cluster_cluster_name_store(struct confi= g_item *item, =20 CONFIGFS_ATTR(cluster_, cluster_name); =20 +static ssize_t cluster_tcp_port_show(struct config_item *item, char *buf) +{ + return sprintf(buf, "%u\n", be16_to_cpu(dlm_config.ci_tcp_port)); +} + +static int dlm_check_zero_and_dlm_running(unsigned int x) +{ + if (!x) + return -EINVAL; + + if (dlm_lowcomms_is_running()) + return -EBUSY; + + return 0; +} + +static ssize_t cluster_tcp_port_store(struct config_item *item, + const char *buf, size_t len) +{ + int rc; + u16 x; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + rc =3D kstrtou16(buf, 0, &x); + if (rc) + return rc; + + rc =3D dlm_check_zero_and_dlm_running(x); + if (rc) + return rc; + + dlm_config.ci_tcp_port =3D cpu_to_be16(x); + return len; +} + +CONFIGFS_ATTR(cluster_, tcp_port); + static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, int *info_field, int (*check_cb)(unsigned int x), const char *buf, size_t len) @@ -191,17 +230,6 @@ static int dlm_check_protocol_and_dlm_running(unsigned= int x) return 0; } =20 -static int dlm_check_zero_and_dlm_running(unsigned int x) -{ - if (!x) - return -EINVAL; - - if (dlm_lowcomms_is_running()) - return -EBUSY; - - return 0; -} - static int dlm_check_zero(unsigned int x) { if (!x) @@ -218,7 +246,6 @@ static int dlm_check_buffer_size(unsigned int x) return 0; } =20 -CLUSTER_ATTR(tcp_port, dlm_check_zero_and_dlm_running); CLUSTER_ATTR(buffer_size, dlm_check_buffer_size); CLUSTER_ATTR(rsbtbl_size, dlm_check_zero); CLUSTER_ATTR(recover_timer, dlm_check_zero); @@ -974,7 +1001,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int nu= m) #define DEFAULT_CLUSTER_NAME "" =20 struct dlm_config_info dlm_config =3D { - .ci_tcp_port =3D DEFAULT_TCP_PORT, + .ci_tcp_port =3D cpu_to_be16(DEFAULT_TCP_PORT), .ci_buffer_size =3D DLM_MAX_SOCKET_BUFSIZE, .ci_rsbtbl_size =3D DEFAULT_RSBTBL_SIZE, .ci_recover_timer =3D DEFAULT_RECOVER_TIMER, diff --git a/fs/dlm/config.h b/fs/dlm/config.h index ed237d910208..9cb4300cce7c 100644 --- a/fs/dlm/config.h +++ b/fs/dlm/config.h @@ -29,7 +29,7 @@ extern const struct rhashtable_params dlm_rhash_rsb_param= s; #define DLM_PROTO_SCTP 1 =20 struct dlm_config_info { - int ci_tcp_port; + __be16 ci_tcp_port; int ci_buffer_size; int ci_rsbtbl_size; int ci_recover_timer; diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index cb3a10b041c2..df40c3fd1070 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -660,18 +660,18 @@ static void add_sock(struct socket *sock, struct conn= ection *con) =20 /* Add the port number to an IPv6 or 4 sockaddr and return the address length */ -static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, +static void make_sockaddr(struct sockaddr_storage *saddr, __be16 port, int *addr_len) { saddr->ss_family =3D dlm_local_addr[0].ss_family; if (saddr->ss_family =3D=3D AF_INET) { struct sockaddr_in *in4_addr =3D (struct sockaddr_in *)saddr; - in4_addr->sin_port =3D cpu_to_be16(port); + in4_addr->sin_port =3D port; *addr_len =3D sizeof(struct sockaddr_in); memset(&in4_addr->sin_zero, 0, sizeof(in4_addr->sin_zero)); } else { struct sockaddr_in6 *in6_addr =3D (struct sockaddr_in6 *)saddr; - in6_addr->sin6_port =3D cpu_to_be16(port); + in6_addr->sin6_port =3D port; *addr_len =3D sizeof(struct sockaddr_in6); } memset((char *)saddr + *addr_len, 0, sizeof(struct sockaddr_storage) - *a= ddr_len); @@ -1121,7 +1121,7 @@ static void writequeue_entry_complete(struct writeque= ue_entry *e, int completed) /* * sctp_bind_addrs - bind a SCTP socket to all our addresses */ -static int sctp_bind_addrs(struct socket *sock, uint16_t port) +static int sctp_bind_addrs(struct socket *sock, __be16 port) { struct sockaddr_storage localaddr; struct sockaddr *addr =3D (struct sockaddr *)&localaddr; --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 55C1C1A3022 for ; Mon, 30 Sep 2024 20:14:25 +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=1727727267; cv=none; b=gVBCJ/IBYiRL4c45qHFl9+psowMViGtyHWQprMV9tcXJ4vW6IfBuQ1HOxw687E1na7hx31CrhP3ytOKVI6T97nQxzBZxj/ExVeAeEAdtvjthIEGRpeCkcDjtE7g3mTZ55RBEHRr5G8CF/5cg/qL0cEZGets7MDDdePtIYuD0lUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727267; c=relaxed/simple; bh=CDghhemlnnZe9puChcu2OexM6x8XJKY/jXW1OWqPggg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d8cc50erW453rDuRxv3Aov4WMTevnGN3nTHK4CIkmxEUw+BuiVMFfVYVh6kK9RETud/JKoOj18BxAUFITbTKxUkKHDgZagaPuQeP0+jODlKMKOJddCYGFVf6LZyYheASGBilOZEyEdzyrij99pDVbegSj0eQFawOTLh8SAeA3+k= 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=X2Wj/nH6; 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="X2Wj/nH6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727264; 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=T8ECzptBQ1lW5D8O8jXzi9piamrkZVJk+YJzrikZLng=; b=X2Wj/nH6M8jAFKDjRLoPwZhCkz3WOgjVA52n/wZ8mzV6UWXw4uze0BdaexKFya7OTM3USj PPJK2J2avoXgllV39BEI0aekynO5OZw/V3YQLvs+LerI005BGyQTLwgEmJJyTaQCz/sH1i zzMOQolpRA5zNR69Tx+p8PGeQgnJrk0= 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-630-GenGo7WMMAWgM8R1IE95ow-1; Mon, 30 Sep 2024 16:14:21 -0400 X-MC-Unique: GenGo7WMMAWgM8R1IE95ow-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 0A8A91978F59; Mon, 30 Sep 2024 20:14:19 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9BA981955DC7; Mon, 30 Sep 2024 20:14:16 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 05/12] dlm: use dlm_config as only cluster configuration Date: Mon, 30 Sep 2024 16:13:51 -0400 Message-ID: <20240930201358.2638665-6-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 removes the configfs storage fields from the dlm_cluster structure to store per cluster values. Those fields also exists for the dlm_config global variable and get stored in both when setting configfs values. To read values it will always be read out from the dlm_cluster configfs structure but this patch changes it to only use the global dlm_config variable. Storing them in two places makes no sense as both are able to be changed under certain conditions during DLM runtime. Signed-off-by: Alexander Aring --- fs/dlm/config.c | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 77a86c180d0e..d9cde614ddd4 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -73,20 +73,6 @@ const struct rhashtable_params dlm_rhash_rsb_params =3D { =20 struct dlm_cluster { struct config_group group; - __be16 cl_tcp_port; - unsigned int cl_buffer_size; - unsigned int cl_rsbtbl_size; - unsigned int cl_recover_timer; - unsigned int cl_toss_secs; - unsigned int cl_scan_secs; - unsigned int cl_log_debug; - unsigned int cl_log_info; - unsigned int cl_protocol; - unsigned int cl_mark; - unsigned int cl_new_rsb_count; - unsigned int cl_recover_callbacks; - char cl_cluster_name[DLM_LOCKSPACE_LEN]; - struct dlm_spaces *sps; struct dlm_comms *cms; }; @@ -115,18 +101,14 @@ enum { =20 static ssize_t cluster_cluster_name_show(struct config_item *item, char *b= uf) { - struct dlm_cluster *cl =3D config_item_to_cluster(item); - return sprintf(buf, "%s\n", cl->cl_cluster_name); + return sprintf(buf, "%s\n", dlm_config.ci_cluster_name); } =20 static ssize_t cluster_cluster_name_store(struct config_item *item, const char *buf, size_t len) { - struct dlm_cluster *cl =3D config_item_to_cluster(item); - strscpy(dlm_config.ci_cluster_name, buf, - sizeof(dlm_config.ci_cluster_name)); - strscpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name)); + sizeof(dlm_config.ci_cluster_name)); return len; } =20 @@ -171,8 +153,7 @@ static ssize_t cluster_tcp_port_store(struct config_ite= m *item, =20 CONFIGFS_ATTR(cluster_, tcp_port); =20 -static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, - int *info_field, int (*check_cb)(unsigned int x), +static ssize_t cluster_set(int *info_field, int (*check_cb)(unsigned int x= ), const char *buf, size_t len) { unsigned int x; @@ -190,7 +171,6 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsi= gned int *cl_field, return rc; } =20 - *cl_field =3D x; *info_field =3D x; =20 return len; @@ -200,14 +180,11 @@ static ssize_t cluster_set(struct dlm_cluster *cl, un= signed int *cl_field, static ssize_t cluster_##name##_store(struct config_item *item, \ const char *buf, size_t len) \ { = \ - struct dlm_cluster *cl =3D config_item_to_cluster(item); \ - return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ - check_cb, buf, len); \ + return cluster_set(&dlm_config.ci_##name, check_cb, buf, len); \ } = \ static ssize_t cluster_##name##_show(struct config_item *item, char *buf) = \ { = \ - struct dlm_cluster *cl =3D config_item_to_cluster(item); \ - return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ + return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name); \ } = \ CONFIGFS_ATTR(cluster_, name); =20 @@ -450,20 +427,6 @@ static struct config_group *make_cluster(struct config= _group *g, configfs_add_default_group(&sps->ss_group, &cl->group); configfs_add_default_group(&cms->cs_group, &cl->group); =20 - cl->cl_tcp_port =3D dlm_config.ci_tcp_port; - cl->cl_buffer_size =3D dlm_config.ci_buffer_size; - cl->cl_rsbtbl_size =3D dlm_config.ci_rsbtbl_size; - cl->cl_recover_timer =3D dlm_config.ci_recover_timer; - cl->cl_toss_secs =3D dlm_config.ci_toss_secs; - cl->cl_scan_secs =3D dlm_config.ci_scan_secs; - cl->cl_log_debug =3D dlm_config.ci_log_debug; - cl->cl_log_info =3D dlm_config.ci_log_info; - cl->cl_protocol =3D dlm_config.ci_protocol; - cl->cl_new_rsb_count =3D dlm_config.ci_new_rsb_count; - cl->cl_recover_callbacks =3D dlm_config.ci_recover_callbacks; - memcpy(cl->cl_cluster_name, dlm_config.ci_cluster_name, - DLM_LOCKSPACE_LEN); - space_list =3D &sps->ss_group; comm_list =3D &cms->cs_group; return &cl->group; --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 D8D4B1A3046 for ; Mon, 30 Sep 2024 20:14:26 +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=1727727268; cv=none; b=OEnri40/Bh+K63xzim1KMiSw06pTnFP+iK6IK46wpKJ4H0dMVboHmxrQU4no/wDk+A6p1lFviHvdty2Xe8nwrwkTz47O369qkEj4gjpauQQVKTTqcRVOkAD+F4mJAd6QRRTn0a6mD6oSCWO035TZE057ZnXBQunQ27u9pRF0+v0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727268; c=relaxed/simple; bh=U0nOA7Z1A1/Dy25L8IFvcBZsOwg8CiDXCZ/aPn74aWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WrxphV2upwvDAXUrU/gkF1PLpt4d5F9c18lAD71rswE3cDwl5Mmtn9wEH/nFllKH7IQ3FfzNVoZyX2s0rfsPZ9oA5ma6kyN4sqmpgGwk0ikkf34+I70cPw3J9bJ1B0k+s2tGCJbxqX3W7iA/xndfjWS0+OB4gK5VfbRVn2ZahaU= 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=N8JebtMg; 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="N8JebtMg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727266; 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=gRLptKCiXpp4gNIkR9o/h84xalWa/aBGlKLc9592qnI=; b=N8JebtMgs4QoEYrTTZWq2j+GfuszEu3PYiV931yI5c5Pe5Bu70P703DJdFv/Nbig4JZuTJ ubKmAe14r6ZFQYGJKPfIjXAwPZGlpg/UjzMncjZIak4ONGfBj25NN7dH0pYqQ7I4DZneTZ 7bEhYhndxpU7YFGkGQf6xWOdBBuQWIY= 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-246--HXvZQgMOESWWm2rmfJuBA-1; Mon, 30 Sep 2024 16:14:24 -0400 X-MC-Unique: -HXvZQgMOESWWm2rmfJuBA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 D0F7019772EC; Mon, 30 Sep 2024 20:14:21 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3DADA1955DC7; Mon, 30 Sep 2024 20:14:19 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 06/12] dlm: dlm_config_info config fields to unsigned int Date: Mon, 30 Sep 2024 16:13:52 -0400 Message-ID: <20240930201358.2638665-7-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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" We are using kstrtouint() to parse common integer fields. This patch will switch to use unsigned int instead of int as we are parsing unsigned integer values. Signed-off-by: Alexander Aring --- fs/dlm/config.c | 3 ++- fs/dlm/config.h | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index d9cde614ddd4..a98f0e746e9e 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -153,7 +153,8 @@ static ssize_t cluster_tcp_port_store(struct config_ite= m *item, =20 CONFIGFS_ATTR(cluster_, tcp_port); =20 -static ssize_t cluster_set(int *info_field, int (*check_cb)(unsigned int x= ), +static ssize_t cluster_set(unsigned int *info_field, + int (*check_cb)(unsigned int x), const char *buf, size_t len) { unsigned int x; diff --git a/fs/dlm/config.h b/fs/dlm/config.h index 9cb4300cce7c..9abe71453c5e 100644 --- a/fs/dlm/config.h +++ b/fs/dlm/config.h @@ -30,17 +30,17 @@ extern const struct rhashtable_params dlm_rhash_rsb_par= ams; =20 struct dlm_config_info { __be16 ci_tcp_port; - int ci_buffer_size; - int ci_rsbtbl_size; - int ci_recover_timer; - int ci_toss_secs; - int ci_scan_secs; - int ci_log_debug; - int ci_log_info; - int ci_protocol; - int ci_mark; - int ci_new_rsb_count; - int ci_recover_callbacks; + unsigned int ci_buffer_size; + unsigned int ci_rsbtbl_size; + unsigned int ci_recover_timer; + unsigned int ci_toss_secs; + unsigned int ci_scan_secs; + unsigned int ci_log_debug; + unsigned int ci_log_info; + unsigned int ci_protocol; + unsigned int ci_mark; + unsigned int ci_new_rsb_count; + unsigned int ci_recover_callbacks; char ci_cluster_name[DLM_LOCKSPACE_LEN]; }; =20 --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 D949E1A0BE9 for ; Mon, 30 Sep 2024 20:14:30 +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=1727727272; cv=none; b=dVHdBQWpsSy1sFqLII183F2opAtC8joRk1suh6J85VtLIlrgQ7r//cMuMCEyu9q7TbboBCgkOYbp/hFpzqZkBJ04ven9Diwt+8CZDGqcyeVkZgsLBhuo/b25VN2WnEVX4zY4VMSitSdAU7cHJzxzNnuGzgw++ZbdHOB3SH6O7/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727272; c=relaxed/simple; bh=3sFK6ohKBfjbKqpeMer5E4SiRe74+gADhS8Xvs8bGjg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DBo5J8a50ms4GRkV3E0YkEnkLBVWIN/z61KNtExmqNn5FQmA1LCqVZnLbKfc1OUAL5gPRrP3vz4PZ69jONJBW+Y+mdx3gkB3O7nz8eL1n2mkswxegMwPQ6BEYDAL1BrKja+0UD3zlQhX0k0GQ+2Tc7XkK0/sdWomMf3FKGd0jUE= 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=eDVQ2gpz; 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="eDVQ2gpz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727270; 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=n5yoLzHqzDYMoo8JKEcZUXSdhcVw5MkEGCtLdOL8Nxw=; b=eDVQ2gpzAENBqZP1xZQA1rNgwrQizIHlBFrkjyWuwrDbYShFiDQM/TvT+hNZ9id0IhTH+K WsXa2DcsfunT7Nx+6IHCOJYMj92YshTr3BsJpg9HeNNl3OXI1VmFxS1CFQy9JWiYvKiCIr 0DN++djIxDp/AkTyPwYR3AJPKbgljpE= Received: from mx-prod-mc-01.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-593-WrNaCy74Pky-JAdSQRPKvw-1; Mon, 30 Sep 2024 16:14:26 -0400 X-MC-Unique: WrNaCy74Pky-JAdSQRPKvw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 89072196A105; Mon, 30 Sep 2024 20:14:24 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EDDFE1955DCD; Mon, 30 Sep 2024 20:14:21 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 07/12] dlm: rename config to configfs Date: Mon, 30 Sep 2024 16:13:53 -0400 Message-ID: <20240930201358.2638665-8-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 will rename the config.c implementation file to configfs.c as in further patches we will introduce a configuration layer to allow different UAPI mechanism operate on current configfs configurations. We need a different UAPI mechanism as we want to separate our configuration on a per net-namespaces basis. The new file "configfs.c" only contains functionality to maintain configfs handling. Signed-off-by: Alexander Aring --- fs/dlm/Makefile | 2 +- fs/dlm/{config.c =3D> configfs.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename fs/dlm/{config.c =3D> configfs.c} (100%) diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile index 5a471af1d1fe..48959179fc78 100644 --- a/fs/dlm/Makefile +++ b/fs/dlm/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DLM) +=3D dlm.o dlm-y :=3D ast.o \ - config.o \ + configfs.o \ dir.o \ lock.o \ lockspace.o \ diff --git a/fs/dlm/config.c b/fs/dlm/configfs.c similarity index 100% rename from fs/dlm/config.c rename to fs/dlm/configfs.c --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 0D04C1A4B9F for ; Mon, 30 Sep 2024 20:14:33 +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=1727727275; cv=none; b=H9yjzAKGm8QzZMk00BhXQgPR7pHvTP8Dwshkcc5VcC/rnW4hNAxsR0m1CiSWN8fiIGpeieesmjfs+F5UP4ab+0wvSF7Zdayl8JS5nqE250vGWeOr+pRXVenyL9vz3GNVGsBOcOVqKvTMdEdjCV9zjH5uhUkLDzxRzEgMvUzc9CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727275; c=relaxed/simple; bh=x7e6IA84Y6g/2IMVAFPlI1KZz8qVpAguY4Mb70GdZTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iHRKqC2SIJYFKpgahFH9fiS4GxKMc7AFYrC4jojg35dTX8PBr7xGNvH6Iz0taVtc477RnvVGFSM4h1A/q6DzVeRH4j+ArjyTiNezTq8wYnzwfdsvPgOhMA8I2domC5KQfc/DpNajA0iNknZKocZsY2wzKcxnmgZnDry86nQXq6M= 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=W388tkA3; 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="W388tkA3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727273; 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=W388tkA3W1rFGx36GqvJ8sU7tNMWck/m59WfB3iaaF0A+yTruVHEr32PFsl/LA6g2yEGbM yapFXHwaNqNCHrdZCJzAQdtYefAx67vuXkGETspsi0ZrOK7YiX+2t9EDuj8wW7GbFLxsbf KLznH/64tgVoEr1KJruUuO+QIGXtSXI= 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-387-L1BWnzkOOyWOiKrPDnaWyg-1; Mon, 30 Sep 2024 16:14:29 -0400 X-MC-Unique: L1BWnzkOOyWOiKrPDnaWyg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 2BD391955F3C; Mon, 30 Sep 2024 20:14:27 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC4081955DC7; Mon, 30 Sep 2024 20:14:24 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 08/12] kobject: add kset_type_create_and_add() helper Date: Mon, 30 Sep 2024 16:13:54 -0400 Message-ID: <20240930201358.2638665-9-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 --- 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 16:50:54 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 77ED51A4E70 for ; Mon, 30 Sep 2024 20:14:34 +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=1727727276; cv=none; b=ezArGBRR+uUMHkRrxBKXrYO8pwfQiw9kHEzCJ95UKrMb87Vco5kL74cMxkv54sqWOzfK9N666LEKESMwYK6rhoHSK3fPQD8WjS36VojVXQWYiAqMEwDFdG0KV5K+93WjBcMy/n5Gdd2cwSBcWk6YrKUunda+ZQOYuq6JxsX2ewI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727276; c=relaxed/simple; bh=/HOjq9X9X2KQMEsqDRneNuPn5l3Rhurp22TwSf3G5Sg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SCT2NSSKiVxG8WUrNkE/H2PCEopJkViNiId38lntId3EfcBa+RnvXWAmpmkuMiTn3sYuEAsicTIOuK5SG3o/6FMVD3BKsjd1zOJyWWExRaWjumuZ23ywk4CfSpaDmqTl4fLzAqVg4u17qDs/iazEYf4h/Jh1HGlUi9bJ5OSB+uE= 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=KeNGuLRq; 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="KeNGuLRq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727273; 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=KeNGuLRq9c5lisyhu3TH2pLTYV1H/9C2m25cnfPgEkOM31xB3MX1ik8COzRN/J/+VxpZwV VRoWQlmk5vkIy+wcZZls6tf601Lu2NSmXpjRQbYEhgi1qfu3uTqb5fLPHPeK5EqABKiF1q TqDEDfzR1kZaV0qNCHSfMx88t4B3Imw= 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-548-sj382g7JM1WPJNynkdWqbA-1; Mon, 30 Sep 2024 16:14:32 -0400 X-MC-Unique: sj382g7JM1WPJNynkdWqbA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 C12111953940; Mon, 30 Sep 2024 20:14:29 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5FF811955DC7; Mon, 30 Sep 2024 20:14:27 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 09/12] kobject: export generic helper ops Date: Mon, 30 Sep 2024 16:13:55 -0400 Message-ID: <20240930201358.2638665-10-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 --- 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 16:50:54 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 C3B241A254E for ; Mon, 30 Sep 2024 20:14:41 +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=1727727290; cv=none; b=BFndm93Ug+84amiL9yqHwr0WlfHtH5JIk+CPFFF2v062JW8VYOBHTbK1/vktS8gvooxqtcUFVmLRhYlGXmp/VpqrCk0IvdPNkptLJK8frDO7OZkZvp3ggUidLJ8UHywE6i436+KdLVNzk2BAzn0fvp+Ht9tEMfIjzxcNUcZcJ5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727290; c=relaxed/simple; bh=p2lsmsiIQ8aMqdpFsD3ThG/B3hQXoC1wcdDicnxDZZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZjWdqtd5RjUN+KfWUk1shKrynND5/9c5AsqBdbc3Vr5yYvaGhUr0Xv7UgMQ/vaU7IHr4V8BHb/K9/5Z+GpebhTfeLmQyvzgYEomXUykawjurp0dObnkz61nDR2VDxws4FB8POrmB+VmKer+4+y15cKv7F0e/IQPyatYSpVQhUxc= 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=cW7y/RlM; 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="cW7y/RlM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727280; 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=qsos2DczixbNURf0H7A7ycAvlavVvfK0c8yLExCCxfo=; b=cW7y/RlMw4O+6PbFqjyx88UFwcTsOp/MHvXfPlwB/ZVOQzlSWCMKs3OOhUcaA3mqhXKhfI R54aO2/116VXTwsFurG1mP4LnEV5PcLDO6mXpr8k6bFcBvD14NDizEM6ABnfXrbX6OGqza 935+GP81Fv8234rVpk1R7aZhm6MKAeA= 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-377-KI4aCkL-PHq_b-QLERZbqA-1; Mon, 30 Sep 2024 16:14:35 -0400 X-MC-Unique: KI4aCkL-PHq_b-QLERZbqA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 BD18019626D2; Mon, 30 Sep 2024 20:14:32 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0484C1955DC7; Mon, 30 Sep 2024 20:14:29 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 10/12] dlm: separate dlm lockspaces per net-namespace Date: Mon, 30 Sep 2024 16:13:56 -0400 Message-ID: <20240930201358.2638665-11-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 separates the internal DLM lockspace handling on a per net-namespace basis. The current handling of DLM offers that all lockspaces are created on a local machine without separation and the machine is part of a cluster with several nodes as other machines. This patch allows us to create a cluster without running several machines on one Linux kernel. We do that by separating all current global variables on a per net-namespace basis, in this patch it is "struct dlm_net". This patch "simply" convert mostly all global variables on a per net-namespace basis and offer a new config layer to operate on this. The configfs UAPI mechanism is using this config layer, as configfs isn't net-namespace aware it only operates on "init_net" namespace. Further new UAPIs that are namespace aware can operate on the config layer on a net-namespace basis. The DLM config layer is implemented in "config.c" the current configfs UAPI mechanism to access the config layer is implemented in "configfs.c". The config layer uses a per net-namespace mutex lock to avoid mutual access of configuration variables as this layer can be accessed in future from multiple UAPI sources. Character device access that is used for dlm locking calls from user space are only accessible from init_net namespace, any open() on those character devices will currently end in an -EOPNOTSUPP. To support such a functionality may a different mechanism will be introduced. This patch will separate the DLM sysfs handling by net-namespace by using kset_type_create_and_add() and implementing the necessary callbacks to reference to the right "struct net" that is part of the per lockspace kobject. Note as this patch series should have no effect as all users still apply &init_net to dlm_new_lockspace() except that users of the DLM character device don't open() those devices under &init_net will be rejected now. Signed-off-by: Alexander Aring --- fs/dlm/Makefile | 1 + fs/dlm/config.c | 699 ++++++++++++++++++++++++++++++++++++++++++ fs/dlm/config.h | 197 ++++++++++-- fs/dlm/configfs.c | 614 ++++++++++++++++--------------------- fs/dlm/configfs.h | 19 ++ fs/dlm/debug_fs.c | 24 +- fs/dlm/dir.c | 4 +- fs/dlm/dlm_internal.h | 20 +- fs/dlm/lock.c | 64 ++-- fs/dlm/lock.h | 3 +- fs/dlm/lockspace.c | 192 +++++++----- fs/dlm/lockspace.h | 13 +- fs/dlm/lowcomms.c | 521 ++++++++++++++++--------------- fs/dlm/lowcomms.h | 29 +- fs/dlm/main.c | 5 - fs/dlm/member.c | 36 +-- fs/dlm/midcomms.c | 287 ++++++++--------- fs/dlm/midcomms.h | 31 +- fs/dlm/plock.c | 2 +- fs/dlm/rcom.c | 16 +- fs/dlm/rcom.h | 3 +- fs/dlm/recover.c | 17 +- fs/dlm/user.c | 63 ++-- fs/dlm/user.h | 2 +- 24 files changed, 1855 insertions(+), 1007 deletions(-) create mode 100644 fs/dlm/config.c create mode 100644 fs/dlm/configfs.h diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile index 48959179fc78..c37f9fc361c6 100644 --- a/fs/dlm/Makefile +++ b/fs/dlm/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DLM) +=3D dlm.o dlm-y :=3D ast.o \ + config.o \ configfs.o \ dir.o \ lock.o \ diff --git a/fs/dlm/config.c b/fs/dlm/config.c new file mode 100644 index 000000000000..93d10b9e7483 --- /dev/null +++ b/fs/dlm/config.c @@ -0,0 +1,699 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +#include "dlm_internal.h" +#include "lockspace.h" +#include "midcomms.h" +#include "lowcomms.h" +#include "configfs.h" +#include "config.h" + +const struct rhashtable_params dlm_rhash_rsb_params =3D { + .nelem_hint =3D 3, /* start small */ + .key_len =3D DLM_RESNAME_MAXLEN, + .key_offset =3D offsetof(struct dlm_rsb, res_name), + .head_offset =3D offsetof(struct dlm_rsb, res_node), + .automatic_shrinking =3D true, +}; + +/* Config file defaults */ +#define DEFAULT_TCP_PORT 21064 +#define DEFAULT_RSBTBL_SIZE 1024 +#define DEFAULT_RECOVER_TIMER 5 +#define DEFAULT_TOSS_SECS 10 +#define DEFAULT_SCAN_SECS 5 +#define DEFAULT_LOG_DEBUG 0 +#define DEFAULT_LOG_INFO 1 +#define DEFAULT_PROTOCOL DLM_PROTO_TCP +#define DEFAULT_MARK 0 +#define DEFAULT_NEW_RSB_COUNT 128 +#define DEFAULT_RECOVER_CALLBACKS 0 +#define DEFAULT_CLUSTER_NAME "" + +static int __net_init dlm_net_init(struct net *net) +{ + struct dlm_net *dn =3D dlm_pernet(net); + + write_pnet(&dn->net, net); + dn->dlm_monitor_unused =3D 1; + + dn->config.ci_tcp_port =3D cpu_to_be16(DEFAULT_TCP_PORT); + dn->config.ci_buffer_size =3D DLM_MAX_SOCKET_BUFSIZE; + dn->config.ci_rsbtbl_size =3D DEFAULT_RSBTBL_SIZE; + dn->config.ci_recover_timer =3D DEFAULT_RECOVER_TIMER; + dn->config.ci_toss_secs =3D DEFAULT_TOSS_SECS; + dn->config.ci_scan_secs =3D DEFAULT_SCAN_SECS; + dn->config.ci_log_debug =3D DEFAULT_LOG_DEBUG; + dn->config.ci_log_info =3D DEFAULT_LOG_INFO; + dn->config.ci_protocol =3D DEFAULT_PROTOCOL; + dn->config.ci_mark =3D DEFAULT_MARK; + dn->config.ci_new_rsb_count =3D DEFAULT_NEW_RSB_COUNT; + dn->config.ci_recover_callbacks =3D DEFAULT_RECOVER_CALLBACKS; + strscpy(dn->config.ci_cluster_name, DEFAULT_CLUSTER_NAME); + + dlm_lockspace_net_init(dn); + dlm_midcomms_init(dn); + + mutex_init(&dn->cfg_lock); + INIT_LIST_HEAD(&dn->nodes); + INIT_LIST_HEAD(&dn->lockspaces); + + return 0; +} + +static void __net_exit dlm_net_exit(struct net *net) +{ + struct dlm_net *dn =3D dlm_pernet(net); + + dlm_midcomms_exit(dn); +} + +static unsigned int dlm_net_id __read_mostly; + +static struct pernet_operations dlm_net_ops =3D { + .init =3D dlm_net_init, + .exit =3D dlm_net_exit, + .id =3D &dlm_net_id, + .size =3D sizeof(struct dlm_net), +}; + +struct dlm_net *dlm_pernet(struct net *net) +{ + return dlm_net_id ? net_generic(net, dlm_net_id) : NULL; +} + +int __init dlm_config_init(void) +{ + int rv; + + rv =3D register_pernet_subsys(&dlm_net_ops); + if (rv) + return rv; + + rv =3D dlm_configfs_init(); + if (rv) { + unregister_pernet_subsys(&dlm_net_ops); + dlm_net_id =3D 0; + } + + return rv; +} + +void dlm_config_exit(void) +{ + dlm_configfs_exit(); + unregister_pernet_subsys(&dlm_net_ops); + dlm_net_id =3D 0; +} + +unsigned int dlm_our_nodeid(struct dlm_net *dn) +{ + return dn->our_node->id; +} + +int dlm_cfg_set_cluster_name(struct dlm_net *dn, const char *name) +{ + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + strscpy(dn->config.ci_cluster_name, name); + mutex_unlock(&dn->cfg_lock); + return 0; +} + +int dlm_cfg_set_port(struct dlm_net *dn, __be16 port) +{ + if (!port) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_tcp_port =3D port; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_buffer_size(struct dlm_net *dn, unsigned int size) +{ + if (size < DLM_MAX_SOCKET_BUFSIZE) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_buffer_size =3D size; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_protocol(struct dlm_net *dn, unsigned int protocol) +{ + switch (protocol) { + case 0: + /* TCP */ + break; + case 1: + /* SCTP */ + break; + default: + return -EINVAL; + } + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_protocol =3D protocol; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_toss_secs(struct dlm_net *dn, unsigned int secs) +{ + if (!secs) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_toss_secs =3D secs; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_recover_timer(struct dlm_net *dn, unsigned int secs) +{ + if (!secs) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_recover_timer =3D secs; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_log_debug(struct dlm_net *dn, unsigned int on) +{ + mutex_lock(&dn->cfg_lock); + dn->config.ci_log_debug =3D on; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_log_info(struct dlm_net *dn, unsigned int on) +{ + mutex_lock(&dn->cfg_lock); + dn->config.ci_log_info =3D on; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_mark(struct dlm_net *dn, unsigned int mark) +{ + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_mark =3D 1; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_recover_callbacks(struct dlm_net *dn, unsigned int on) +{ + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->config.ci_recover_callbacks =3D on; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +struct dlm_cfg_ls *dlm_cfg_get_ls(struct dlm_net *dn, const char *lsname) +{ + struct dlm_cfg_ls *iter, *ls =3D NULL; + + list_for_each_entry(iter, &dn->lockspaces, list) { + if (!strncmp(iter->name, lsname, DLM_LOCKSPACE_LEN)) { + ls =3D iter; + break; + } + } + + return ls; +} + +/* caller must free mem */ +int dlm_config_nodes(struct dlm_net *dn, char *lsname, + struct dlm_config_node **nodes_out, + unsigned int *count_out) +{ + struct dlm_config_node *nodes, *node; + struct dlm_cfg_member *mb; + struct dlm_cfg_ls *ls; + int rv =3D 0, count; + + mutex_lock(&dn->cfg_lock); + ls =3D dlm_cfg_get_ls(dn, lsname); + if (!ls) { + rv =3D -EEXIST; + goto out; + } + + if (!ls->members_count) { + rv =3D -EINVAL; + goto out; + } + + count =3D ls->members_count; + nodes =3D kcalloc(count, sizeof(struct dlm_config_node), GFP_NOFS); + if (!nodes) { + rv =3D -ENOMEM; + goto out; + } + + node =3D nodes; + list_for_each_entry(mb, &ls->members, list) { + node->nodeid =3D mb->nd->id; + node->weight =3D mb->weight; + node->new =3D mb->new; + node->comm_seq =3D mb->nd->seq; + node++; + + mb->new =3D 0; + } + + *count_out =3D count; + *nodes_out =3D nodes; + out: + mutex_unlock(&dn->cfg_lock); + + return rv; +} + +struct dlm_cfg_node *dlm_cfg_get_node(struct dlm_net *dn, unsigned int id) +{ + struct dlm_cfg_node *iter, *con =3D NULL; + + list_for_each_entry(iter, &dn->nodes, list) { + if (iter->id =3D=3D id) { + con =3D iter; + break; + } + } + + return con; +} + +static int dlm_cfg_set_addr(struct dlm_net *dn, struct dlm_cfg_node *nd, + unsigned int id, struct sockaddr_storage *addr) +{ + int rv; + + /* TODO -EEXIST */ + if (nd->addrs_count >=3D DLM_MAX_ADDR_COUNT) + return -ENOSPC; + + rv =3D dlm_midcomms_addr(dn, nd->id, addr); + if (rv) + return rv; + + nd->addrs[nd->addrs_count++] =3D *addr; + + return 0; +} + +int dlm_cfg_new_node(struct dlm_net *dn, unsigned int id, + unsigned int mark, struct sockaddr_storage *addrs, + size_t addrs_count) +{ + struct dlm_cfg_node *nd; + int i, rv =3D 0; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + rv =3D -EBUSY; + goto out; + } + + nd =3D dlm_cfg_get_node(dn, id); + if (nd) { + rv =3D -EEXIST; + goto out; + } + + nd =3D kzalloc(sizeof(*nd), GFP_ATOMIC); + if (!nd) { + rv =3D -ENOMEM; + goto out; + } + + nd->seq =3D dn->dlm_cfg_node_count++; + if (!nd->seq) + nd->seq =3D dn->dlm_cfg_node_count++; + + nd->id =3D id; + nd->mark =3D mark; + + /* due configfs optional */ + if (addrs && addrs_count) { + if (addrs_count >=3D DLM_MAX_ADDR_COUNT) { + rv =3D -ENOSPC; + kfree(nd); + goto out; + } + + for (i =3D 0; i < addrs_count; i++) { + rv =3D dlm_cfg_set_addr(dn, nd, i, &addrs[i]); + if (rv < 0) { + kfree(nd); + goto out; + } + } + + nd->addrs_count =3D addrs_count; + } + + nd->idx =3D ++dn->node_idx; + list_add_tail(&nd->list, &dn->nodes); + +out: + mutex_unlock(&dn->cfg_lock); + + return rv; +} + +int dlm_cfg_del_node(struct dlm_net *dn, unsigned int id) +{ + struct dlm_cfg_node *nd; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + nd =3D dlm_cfg_get_node(dn, id); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + if (dn->our_node =3D=3D nd) { + if (nd->used !=3D 1) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + dn->our_node =3D NULL; + } else { + if (nd->used !=3D 0) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + } + + list_del(&nd->list); + dlm_midcomms_close(dn, id); + mutex_unlock(&dn->cfg_lock); + + kfree(nd); + + return 0; +} + +int dlm_cfg_set_our_nodeid(struct dlm_net *dn, unsigned int id) +{ + struct dlm_cfg_node *nd; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + nd =3D dlm_cfg_get_node(dn, id); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + if (dn->our_node) + dn->our_node->used--; + + dn->our_node =3D nd; + nd->used++; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +static struct dlm_cfg_member * +dlm_cfg_get_member(struct dlm_cfg_ls *ls, unsigned int id) +{ + struct dlm_cfg_member *iter, *mb =3D NULL; + + list_for_each_entry(iter, &ls->members, list) { + if (iter->nd->id =3D=3D id) { + mb =3D iter; + break; + } + } + + return mb; +} + +struct dlm_cfg_member * +dlm_cfg_get_ls_member(struct dlm_net *dn, const char *lsname, + unsigned int nodeid) +{ + struct dlm_cfg_ls *ls; + + ls =3D dlm_cfg_get_ls(dn, lsname); + if (!ls) + return NULL; + + return dlm_cfg_get_member(ls, nodeid); +} + +int dlm_cfg_add_member(struct dlm_net *dn, const char *lsname, + unsigned int id, unsigned int weight) +{ + struct dlm_cfg_member *mb; + struct dlm_cfg_node *nd; + struct dlm_cfg_ls *ls; + bool new_ls =3D false; + + mutex_lock(&dn->cfg_lock); + ls =3D dlm_cfg_get_ls(dn, lsname); + if (!ls) { + ls =3D kzalloc(sizeof(*ls), GFP_ATOMIC); + if (!ls) { + mutex_unlock(&dn->cfg_lock); + return -ENOMEM; + } + + strscpy(ls->name, lsname); + INIT_LIST_HEAD(&ls->members); + ls->idx =3D ++dn->ls_idx; + new_ls =3D true; + } else { + mb =3D dlm_cfg_get_member(ls, id); + if (mb) { + mutex_unlock(&dn->cfg_lock); + return -EEXIST; + } + } + + nd =3D dlm_cfg_get_node(dn, id); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + if (new_ls) + kfree(ls); + return -ENOENT; + } + + mb =3D kzalloc(sizeof(*mb), GFP_ATOMIC); + if (!mb) { + mutex_unlock(&dn->cfg_lock); + if (new_ls) + kfree(ls); + return -ENOMEM; + } + + nd->used++; + mb->nd =3D nd; + mb->ls =3D ls; + mb->weight =3D weight; + mb->new =3D 1; + + list_add_tail(&mb->list, &ls->members); + ls->members_count++; + mb->idx =3D ++ls->member_idx; + + if (new_ls) + list_add_tail(&ls->list, &dn->lockspaces); + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_del_member(struct dlm_net *dn, const char *lsname, unsigned in= t id) +{ + struct dlm_cfg_member *mb; + + mutex_lock(&dn->cfg_lock); + mb =3D dlm_cfg_get_ls_member(dn, lsname, id); + if (!mb) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + mb->nd->used--; + list_del(&mb->list); + mb->ls->members_count--; + if (!mb->ls->members_count) + list_del(&mb->ls->list); + mutex_unlock(&dn->cfg_lock); + + kfree(mb); + + return 0; +} + +int dlm_cfg_add_addr(struct dlm_net *dn, unsigned int id, + struct sockaddr_storage *addr) +{ + struct dlm_cfg_node *nd; + int rv; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + nd =3D dlm_cfg_get_node(dn, id); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + rv =3D dlm_cfg_set_addr(dn, nd, id, addr); + mutex_unlock(&dn->cfg_lock); + + return rv; +} + +int dlm_comm_seq(struct dlm_net *dn, unsigned int id, uint32_t *seq) +{ + struct dlm_cfg_node *nd; + + mutex_lock(&dn->cfg_lock); + nd =3D dlm_cfg_get_node(dn, id); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + *seq =3D nd->seq; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +/* num 0 is first addr, num 1 is second addr */ +int dlm_our_addr(struct dlm_net *dn, struct sockaddr_storage *addr, int nu= m) +{ + mutex_lock(&dn->cfg_lock); + if (!dn->our_node) { + mutex_unlock(&dn->cfg_lock); + return -1; + } + + if (num >=3D dn->our_node->addrs_count) { + mutex_unlock(&dn->cfg_lock); + return -1; + } + + memcpy(addr, &dn->our_node->addrs[num], sizeof(*addr)); + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_node_mark(struct dlm_net *dn, unsigned int nodeid, + unsigned int mark) +{ + struct dlm_cfg_node *nd; + + mutex_lock(&dn->cfg_lock); + if (dlm_lowcomms_is_running(dn)) { + mutex_unlock(&dn->cfg_lock); + return -EBUSY; + } + + nd =3D dlm_cfg_get_node(dn, nodeid); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + nd->mark =3D mark; + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int dlm_cfg_set_weight(struct dlm_net *dn, const char *lsname, + unsigned int nodeid, unsigned int weight) +{ + struct dlm_cfg_member *mb; + + mutex_lock(&dn->cfg_lock); + mb =3D dlm_cfg_get_ls_member(dn, lsname, nodeid); + if (!mb) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + mb->weight =3D weight; + mutex_unlock(&dn->cfg_lock); + + return 0; +} diff --git a/fs/dlm/config.h b/fs/dlm/config.h index 9abe71453c5e..ddbbe2996dea 100644 --- a/fs/dlm/config.h +++ b/fs/dlm/config.h @@ -1,19 +1,26 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -/*************************************************************************= ***** -**************************************************************************= ***** -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. -** -** -**************************************************************************= ***** -**************************************************************************= ****/ - -#ifndef __CONFIG_DOT_H__ -#define __CONFIG_DOT_H__ +#ifndef __DLM_CONFIG_H__ +#define __DLM_CONFIG_H__ + +#include +#include + +#define CONN_HASH_SIZE 32 =20 #define DLM_MAX_SOCKET_BUFSIZE 4096 =20 +#define DLM_MAX_ADDR_COUNT 3 + +#define DLM_PROTO_TCP 0 +#define DLM_PROTO_SCTP 1 + +#define DLM_DEFAULT_WEIGHT 1 +#define DLM_DEFAULT_MARK 0 + +extern const struct rhashtable_params dlm_rhash_rsb_params; + +struct dlm_net; + struct dlm_config_node { int nodeid; int weight; @@ -21,38 +28,176 @@ struct dlm_config_node { uint32_t comm_seq; }; =20 -extern const struct rhashtable_params dlm_rhash_rsb_params; +struct dlm_proto_ops { + bool try_new_addr; + const char *name; + int proto; =20 -#define DLM_MAX_ADDR_COUNT 3 + void (*sockopts)(struct socket *sock); + int (*bind)(struct dlm_net *dn, struct socket *sock); + int (*listen_validate)(const struct dlm_net *dn); + void (*listen_sockopts)(struct socket *sock); + int (*listen_bind)(struct dlm_net *dn, struct socket *sock); +}; =20 -#define DLM_PROTO_TCP 0 -#define DLM_PROTO_SCTP 1 +struct listen_connection { + struct socket *sock; + struct work_struct rwork; +}; =20 struct dlm_config_info { __be16 ci_tcp_port; unsigned int ci_buffer_size; - unsigned int ci_rsbtbl_size; unsigned int ci_recover_timer; unsigned int ci_toss_secs; - unsigned int ci_scan_secs; unsigned int ci_log_debug; unsigned int ci_log_info; unsigned int ci_protocol; unsigned int ci_mark; - unsigned int ci_new_rsb_count; unsigned int ci_recover_callbacks; char ci_cluster_name[DLM_LOCKSPACE_LEN]; + + /* unused, still here for backwards compatibility */ + unsigned int ci_rsbtbl_size; + unsigned int ci_new_rsb_count; + unsigned int ci_scan_secs; +}; + +struct listen_sock_callbacks { + void (*sk_error_report)(struct sock *sk); + void (*sk_data_ready)(struct sock *sk); + void (*sk_state_change)(struct sock *sk); + void (*sk_write_space)(struct sock *sk); +}; + +struct dlm_cfg_ls { + char name[DLM_LOCKSPACE_LEN]; + struct list_head members; + unsigned int members_count; + unsigned int member_idx; + unsigned int idx; + + struct list_head list; +}; + +struct dlm_cfg_node { + unsigned int id; + uint32_t mark; + struct sockaddr_storage addrs[DLM_MAX_ADDR_COUNT]; + unsigned int addrs_count; + unsigned int idx; + unsigned int seq; + unsigned int used; + + struct list_head list; }; =20 -extern struct dlm_config_info dlm_config; +struct dlm_cfg_member { + struct dlm_cfg_node *nd; + struct dlm_cfg_ls *ls; + unsigned int weight; + unsigned int idx; + bool new; + + struct list_head list; +}; + +struct dlm_net { + possible_net_t net; + struct dlm_config_info config; + + atomic_t dlm_monitor_opened; + int dlm_monitor_unused; + + struct listen_sock_callbacks listen_sock; + struct listen_connection listen_con; + struct sockaddr_storage dlm_local_addr[DLM_MAX_ADDR_COUNT]; + int dlm_local_count; + + /* Work queues */ + struct workqueue_struct *io_workqueue; + struct workqueue_struct *process_workqueue; =20 + struct hlist_head connection_hash[CONN_HASH_SIZE]; + spinlock_t connections_lock; + struct srcu_struct connections_srcu; + + const struct dlm_proto_ops *dlm_proto_ops; + + struct work_struct process_work; + spinlock_t processqueue_lock; + bool process_dlm_messages_pending; + wait_queue_head_t processqueue_wq; + atomic_t processqueue_count; + struct list_head processqueue; + + struct hlist_head node_hash[CONN_HASH_SIZE]; + spinlock_t nodes_lock; + struct srcu_struct nodes_srcu; + + /* This mutex prevents that midcomms_close() is running while + * stop() or remove(). As I experienced invalid memory access + * behaviours when DLM_DEBUG_FENCE_TERMINATION is enabled and + * resetting machines. I will end in some double deletion in nodes + * datastructure. + */ + struct mutex close_lock; + + int ls_count; + struct mutex ls_lock; + struct list_head lslist; + spinlock_t lslist_lock; + + struct mutex cfg_lock; + uint32_t dlm_cfg_node_count; + struct dlm_cfg_node *our_node; + unsigned int node_idx; + struct list_head nodes; + unsigned int ls_idx; + struct list_head lockspaces; +}; + +struct dlm_net *dlm_pernet(struct net *net); int dlm_config_init(void); void dlm_config_exit(void); -int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out, - int *count_out); -int dlm_comm_seq(int nodeid, uint32_t *seq); -int dlm_our_nodeid(void); -int dlm_our_addr(struct sockaddr_storage *addr, int num); =20 -#endif /* __CONFIG_DOT_H__ */ +unsigned int dlm_our_nodeid(struct dlm_net *dn); + +struct dlm_cfg_node *dlm_cfg_get_node(struct dlm_net *dn, unsigned int id); +struct dlm_cfg_ls *dlm_cfg_get_ls(struct dlm_net *dn, const char *lsname); +struct dlm_cfg_member * +dlm_cfg_get_ls_member(struct dlm_net *dn, const char *lsname, + unsigned int nodeid); + +int dlm_cfg_set_cluster_name(struct dlm_net *dn, const char *name); +int dlm_cfg_set_port(struct dlm_net *dn, __be16 port); +int dlm_cfg_set_buffer_size(struct dlm_net *dn, unsigned int size); +int dlm_cfg_set_protocol(struct dlm_net *dn, unsigned int protocol); +int dlm_cfg_set_toss_secs(struct dlm_net *dn, unsigned int secs); +int dlm_cfg_set_recover_timer(struct dlm_net *dn, unsigned int secs); +int dlm_cfg_set_mark(struct dlm_net *dn, unsigned int mark); +int dlm_cfg_set_features(struct dlm_net *dn, unsigned int features); +int dlm_cfg_set_log_debug(struct dlm_net *dn, unsigned int on); +int dlm_cfg_set_log_info(struct dlm_net *dn, unsigned int on); +int dlm_cfg_set_recover_callbacks(struct dlm_net *dn, unsigned int on); + +int dlm_cfg_new_node(struct dlm_net *dn, unsigned int id, unsigned int mar= k, + struct sockaddr_storage *addrs, size_t addrs_count); +int dlm_cfg_del_node(struct dlm_net *dn, unsigned int id); +int dlm_cfg_set_our_nodeid(struct dlm_net *dn, unsigned int id); +int dlm_cfg_set_node_mark(struct dlm_net *dn, unsigned int nodeid, unsigne= d int mark); +int dlm_cfg_add_member(struct dlm_net *dn, const char *lsname, + unsigned int id, unsigned int weight); +int dlm_cfg_del_member(struct dlm_net *dn, const char *lsname, unsigned in= t id); +int dlm_cfg_add_addr(struct dlm_net *dn, unsigned int id, + struct sockaddr_storage *addr); +int dlm_cfg_set_weight(struct dlm_net *dn, const char *lsname, + unsigned int nodeid, unsigned int weight); + +int dlm_config_nodes(struct dlm_net *dn, char *lsname, + struct dlm_config_node **nodes_out, + unsigned int *count_out); +int dlm_comm_seq(struct dlm_net *dn, unsigned int id, uint32_t *seq); +int dlm_our_addr(struct dlm_net *dn, struct sockaddr_storage *addr, int nu= m); =20 +#endif /* __DLM_CONFIG_H__ */ diff --git a/fs/dlm/configfs.c b/fs/dlm/configfs.c index a98f0e746e9e..6d4620dc6a7d 100644 --- a/fs/dlm/configfs.c +++ b/fs/dlm/configfs.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: GPL-2.0-only /*************************************************************************= ***** -**************************************************************************= ***** -** -** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. -** -** -**************************************************************************= ***** -**************************************************************************= ****/ + *************************************************************************= ***** + ** + ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. + ** + ** + *************************************************************************= ***** + *************************************************************************= *****/ =20 #include #include @@ -19,9 +19,10 @@ #include #include =20 -#include "config.h" +#include "configfs.h" #include "midcomms.h" #include "lowcomms.h" +#include "config.h" =20 /* * /config/dlm//spaces//nodes//nodeid (refers to ) @@ -35,8 +36,6 @@ =20 static struct config_group *space_list; static struct config_group *comm_list; -static struct dlm_comm *local_comm; -static uint32_t dlm_comm_count; =20 struct dlm_clusters; struct dlm_cluster; @@ -63,14 +62,6 @@ static void release_node(struct config_item *); static struct configfs_attribute *comm_attrs[]; static struct configfs_attribute *node_attrs[]; =20 -const struct rhashtable_params dlm_rhash_rsb_params =3D { - .nelem_hint =3D 3, /* start small */ - .key_len =3D DLM_RESNAME_MAXLEN, - .key_offset =3D offsetof(struct dlm_rsb, res_name), - .head_offset =3D offsetof(struct dlm_rsb, res_node), - .automatic_shrinking =3D true, -}; - struct dlm_cluster { struct config_group group; struct dlm_spaces *sps; @@ -101,14 +92,26 @@ enum { =20 static ssize_t cluster_cluster_name_show(struct config_item *item, char *b= uf) { - return sprintf(buf, "%s\n", dlm_config.ci_cluster_name); + struct dlm_net *dn =3D dlm_pernet(&init_net); + int rv; + + mutex_lock(&dn->cfg_lock); + rv =3D sprintf(buf, "%s\n", dn->config.ci_cluster_name); + mutex_unlock(&dn->cfg_lock); + + return rv; } =20 static ssize_t cluster_cluster_name_store(struct config_item *item, const char *buf, size_t len) { - strscpy(dlm_config.ci_cluster_name, buf, - sizeof(dlm_config.ci_cluster_name)); + struct dlm_net *dn =3D dlm_pernet(&init_net); + + mutex_lock(&dn->cfg_lock); + strscpy(dn->config.ci_cluster_name, buf, + sizeof(dn->config.ci_cluster_name)); + mutex_unlock(&dn->cfg_lock); + return len; } =20 @@ -116,23 +119,20 @@ CONFIGFS_ATTR(cluster_, cluster_name); =20 static ssize_t cluster_tcp_port_show(struct config_item *item, char *buf) { - return sprintf(buf, "%u\n", be16_to_cpu(dlm_config.ci_tcp_port)); -} - -static int dlm_check_zero_and_dlm_running(unsigned int x) -{ - if (!x) - return -EINVAL; + struct dlm_net *dn =3D dlm_pernet(&init_net); + int rv; =20 - if (dlm_lowcomms_is_running()) - return -EBUSY; + mutex_lock(&dn->cfg_lock); + rv =3D sprintf(buf, "%u\n", be16_to_cpu(dn->config.ci_tcp_port)); + mutex_unlock(&dn->cfg_lock); =20 - return 0; + return rv; } =20 static ssize_t cluster_tcp_port_store(struct config_item *item, const char *buf, size_t len) { + struct dlm_net *dn =3D dlm_pernet(&init_net); int rc; u16 x; =20 @@ -143,20 +143,19 @@ static ssize_t cluster_tcp_port_store(struct config_i= tem *item, if (rc) return rc; =20 - rc =3D dlm_check_zero_and_dlm_running(x); + rc =3D dlm_cfg_set_port(dn, cpu_to_be16(x)); if (rc) return rc; =20 - dlm_config.ci_tcp_port =3D cpu_to_be16(x); return len; } =20 CONFIGFS_ATTR(cluster_, tcp_port); =20 -static ssize_t cluster_set(unsigned int *info_field, - int (*check_cb)(unsigned int x), +static ssize_t cluster_set(int (*setter)(struct dlm_net *dn, unsigned int = x), const char *buf, size_t len) { + struct dlm_net *dn =3D dlm_pernet(&init_net); unsigned int x; int rc; =20 @@ -166,75 +165,66 @@ static ssize_t cluster_set(unsigned int *info_field, if (rc) return rc; =20 - if (check_cb) { - rc =3D check_cb(x); - if (rc) - return rc; - } - - *info_field =3D x; + rc =3D setter(dn, x); + if (rc) + return rc; =20 return len; } =20 -#define CLUSTER_ATTR(name, check_cb) = \ +#define CLUSTER_ATTR(name) = \ static ssize_t cluster_##name##_store(struct config_item *item, \ const char *buf, size_t len) \ { = \ - return cluster_set(&dlm_config.ci_##name, check_cb, buf, len); \ + return cluster_set(dlm_cfg_set_##name, buf, len); \ } = \ static ssize_t cluster_##name##_show(struct config_item *item, char *buf) = \ { = \ - return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name); \ + struct dlm_net *dn =3D dlm_pernet(&init_net); \ + int rv; \ + mutex_lock(&dn->cfg_lock); \ + rv =3D snprintf(buf, PAGE_SIZE, "%u\n", dn->config.ci_##name); \ + mutex_unlock(&dn->cfg_lock); \ + return rv; \ } = \ -CONFIGFS_ATTR(cluster_, name); - -static int dlm_check_protocol_and_dlm_running(unsigned int x) -{ - switch (x) { - case 0: - /* TCP */ - break; - case 1: - /* SCTP */ - break; - default: - return -EINVAL; - } - - if (dlm_lowcomms_is_running()) - return -EBUSY; - - return 0; -} - -static int dlm_check_zero(unsigned int x) -{ - if (!x) - return -EINVAL; - - return 0; -} - -static int dlm_check_buffer_size(unsigned int x) -{ - if (x < DLM_MAX_SOCKET_BUFSIZE) - return -EINVAL; - - return 0; -} - -CLUSTER_ATTR(buffer_size, dlm_check_buffer_size); -CLUSTER_ATTR(rsbtbl_size, dlm_check_zero); -CLUSTER_ATTR(recover_timer, dlm_check_zero); -CLUSTER_ATTR(toss_secs, dlm_check_zero); -CLUSTER_ATTR(scan_secs, dlm_check_zero); -CLUSTER_ATTR(log_debug, NULL); -CLUSTER_ATTR(log_info, NULL); -CLUSTER_ATTR(protocol, dlm_check_protocol_and_dlm_running); -CLUSTER_ATTR(mark, NULL); -CLUSTER_ATTR(new_rsb_count, NULL); -CLUSTER_ATTR(recover_callbacks, NULL); +CONFIGFS_ATTR(cluster_, name) + +CLUSTER_ATTR(buffer_size); +CLUSTER_ATTR(recover_timer); +CLUSTER_ATTR(toss_secs); +CLUSTER_ATTR(log_debug); +CLUSTER_ATTR(log_info); +CLUSTER_ATTR(protocol); +CLUSTER_ATTR(mark); +CLUSTER_ATTR(recover_callbacks); + +#define CLUSTER_ATTR_UNUSED(name) \ +static ssize_t cluster_##name##_store(struct config_item *item, \ + const char *buf, size_t len) \ +{ \ + struct dlm_net *dn =3D dlm_pernet(&init_net); \ + unsigned int x; \ + int rc; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + rc =3D kstrtouint(buf, 0, &x); \ + if (rc) \ + return rc; \ + \ + dn->config.ci_##name =3D x; \ + return len; \ +} \ +static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \ +{ \ + struct dlm_net *dn =3D dlm_pernet(&init_net); \ + return snprintf(buf, PAGE_SIZE, "%u\n", dn->config.ci_##name); \ +} \ +CONFIGFS_ATTR(cluster_, name) + +CLUSTER_ATTR_UNUSED(rsbtbl_size); +CLUSTER_ATTR_UNUSED(scan_secs); +CLUSTER_ATTR_UNUSED(new_rsb_count); =20 static struct configfs_attribute *cluster_attrs[] =3D { [CLUSTER_ATTR_TCP_PORT] =3D &cluster_attr_tcp_port, @@ -276,9 +266,6 @@ struct dlm_spaces { =20 struct dlm_space { struct config_group group; - struct list_head members; - struct mutex members_lock; - int members_count; struct dlm_nodes *nds; }; =20 @@ -288,12 +275,6 @@ struct dlm_comms { =20 struct dlm_comm { struct config_item item; - int seq; - int nodeid; - int local; - int addr_count; - unsigned int mark; - struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT]; }; =20 struct dlm_nodes { @@ -302,11 +283,6 @@ struct dlm_nodes { =20 struct dlm_node { struct config_item item; - struct list_head list; /* space->members */ - int nodeid; - int weight; - int new; - int comm_seq; /* copy of cm->seq when nd->nodeid is set */ }; =20 static struct configfs_group_operations clusters_ops =3D { @@ -475,11 +451,6 @@ static struct config_group *make_space(struct config_g= roup *g, const char *name) =20 config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type); configfs_add_default_group(&nds->ns_group, &sp->group); - - INIT_LIST_HEAD(&sp->members); - mutex_init(&sp->members_lock); - sp->members_count =3D 0; - sp->nds =3D nds; return &sp->group; =20 fail: @@ -501,14 +472,16 @@ static void drop_space(struct config_group *g, struct= config_item *i) static void release_space(struct config_item *i) { struct dlm_space *sp =3D config_item_to_space(i); + kfree(sp->nds); kfree(sp); } =20 static struct config_item *make_comm(struct config_group *g, const char *n= ame) { - struct dlm_comm *cm; + struct dlm_net *dn =3D dlm_pernet(&init_net); unsigned int nodeid; + struct dlm_comm *cm; int rv; =20 rv =3D kstrtouint(name, 0, &nodeid); @@ -519,42 +492,46 @@ static struct config_item *make_comm(struct config_gr= oup *g, const char *name) if (!cm) return ERR_PTR(-ENOMEM); =20 - config_item_init_type_name(&cm->item, name, &comm_type); - - cm->seq =3D dlm_comm_count++; - if (!cm->seq) - cm->seq =3D dlm_comm_count++; + rv =3D dlm_cfg_new_node(dn, nodeid, 0, NULL, 0); + if (rv) { + kfree(cm); + return ERR_PTR(rv); + } =20 - cm->nodeid =3D nodeid; - cm->local =3D 0; - cm->addr_count =3D 0; - cm->mark =3D 0; + config_item_init_type_name(&cm->item, name, &comm_type); return &cm->item; } =20 static void drop_comm(struct config_group *g, struct config_item *i) { - struct dlm_comm *cm =3D config_item_to_comm(i); - if (local_comm =3D=3D cm) - local_comm =3D NULL; - dlm_midcomms_close(cm->nodeid); - while (cm->addr_count--) - kfree(cm->addr[cm->addr_count]); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid; + int rv; + + rv =3D kstrtouint(config_item_name(i), 0, &nodeid); + if (WARN_ON(rv)) + return; + + rv =3D dlm_cfg_del_node(dn, nodeid); + if (WARN_ON(rv)) + return; + config_item_put(i); } =20 static void release_comm(struct config_item *i) { struct dlm_comm *cm =3D config_item_to_comm(i); + kfree(cm); } =20 static struct config_item *make_node(struct config_group *g, const char *n= ame) { - struct dlm_space *sp =3D config_item_to_space(g->cg_item.ci_parent); + struct dlm_net *dn =3D dlm_pernet(&init_net); unsigned int nodeid; struct dlm_node *nd; - uint32_t seq =3D 0; + const char *lsname; int rv; =20 rv =3D kstrtouint(name, 0, &nodeid); @@ -565,30 +542,32 @@ static struct config_item *make_node(struct config_gr= oup *g, const char *name) if (!nd) return ERR_PTR(-ENOMEM); =20 - config_item_init_type_name(&nd->item, name, &node_type); - nd->nodeid =3D nodeid; - nd->weight =3D 1; /* default weight of 1 if none is set */ - nd->new =3D 1; /* set to 0 once it's been read by dlm_nodeid_list() */ - dlm_comm_seq(nodeid, &seq); - nd->comm_seq =3D seq; - - mutex_lock(&sp->members_lock); - list_add(&nd->list, &sp->members); - sp->members_count++; - mutex_unlock(&sp->members_lock); + lsname =3D config_item_name(g->cg_item.ci_parent); + rv =3D dlm_cfg_add_member(dn, lsname, nodeid, DLM_DEFAULT_WEIGHT); + if (rv) { + kfree(nd); + return ERR_PTR(rv); + } =20 + config_item_init_type_name(&nd->item, name, &node_type); return &nd->item; } =20 static void drop_node(struct config_group *g, struct config_item *i) { - struct dlm_space *sp =3D config_item_to_space(g->cg_item.ci_parent); - struct dlm_node *nd =3D config_item_to_node(i); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid; + const char *lsname; + int rv; + + rv =3D kstrtouint(config_item_name(i), 0, &nodeid); + if (WARN_ON(rv)) + return; =20 - mutex_lock(&sp->members_lock); - list_del(&nd->list); - sp->members_count--; - mutex_unlock(&sp->members_lock); + lsname =3D config_item_name(g->cg_item.ci_parent); + rv =3D dlm_cfg_del_member(dn, lsname, nodeid); + if (WARN_ON(rv)) + return; =20 config_item_put(i); } @@ -596,6 +575,7 @@ static void drop_node(struct config_group *g, struct co= nfig_item *i) static void release_node(struct config_item *i) { struct dlm_node *nd =3D config_item_to_node(i); + kfree(nd); } =20 @@ -610,14 +590,14 @@ static struct dlm_clusters clusters_root =3D { }, }; =20 -int __init dlm_config_init(void) +int __init dlm_configfs_init(void) { config_group_init(&clusters_root.subsys.su_group); mutex_init(&clusters_root.subsys.su_mutex); return configfs_register_subsystem(&clusters_root.subsys); } =20 -void dlm_config_exit(void) +void dlm_configfs_exit(void) { configfs_unregister_subsystem(&clusters_root.subsys); } @@ -646,73 +626,97 @@ static ssize_t comm_nodeid_store(struct config_item *= item, const char *buf, =20 static ssize_t comm_local_show(struct config_item *item, char *buf) { - return sprintf(buf, "%d\n", config_item_to_comm(item)->local); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid; + int local =3D 0, rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + mutex_lock(&dn->cfg_lock); + if (dn->our_node) + local =3D (dn->our_node->id =3D=3D nodeid); + mutex_unlock(&dn->cfg_lock); + + return sprintf(buf, "%d\n", local); } =20 static ssize_t comm_local_store(struct config_item *item, const char *buf, size_t len) { - struct dlm_comm *cm =3D config_item_to_comm(item); - int rc =3D kstrtoint(buf, 0, &cm->local); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid; + int rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + rv =3D dlm_cfg_set_our_nodeid(dn, nodeid); + if (rv) + return rv; =20 - if (rc) - return rc; - if (cm->local && !local_comm) - local_comm =3D cm; return len; } =20 static ssize_t comm_addr_store(struct config_item *item, const char *buf, size_t len) { - struct dlm_comm *cm =3D config_item_to_comm(item); - struct sockaddr_storage *addr; + struct dlm_net *dn =3D dlm_pernet(&init_net); + struct sockaddr_storage addr; + unsigned int nodeid; int rv; =20 if (len !=3D sizeof(struct sockaddr_storage)) return -EINVAL; =20 - if (cm->addr_count >=3D DLM_MAX_ADDR_COUNT) - return -ENOSPC; - - addr =3D kzalloc(sizeof(*addr), GFP_NOFS); - if (!addr) - return -ENOMEM; - - memcpy(addr, buf, len); + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; =20 - rv =3D dlm_midcomms_addr(cm->nodeid, addr); - if (rv) { - kfree(addr); + memcpy(&addr, buf, len); + rv =3D dlm_cfg_add_addr(dn, nodeid, &addr); + if (rv) return rv; - } =20 - cm->addr[cm->addr_count++] =3D addr; return len; } =20 static ssize_t comm_addr_list_show(struct config_item *item, char *buf) { - struct dlm_comm *cm =3D config_item_to_comm(item); + struct dlm_net *dn =3D dlm_pernet(&init_net); ssize_t s; ssize_t allowance; - int i; + int i, rv; struct sockaddr_storage *addr; struct sockaddr_in *addr_in; struct sockaddr_in6 *addr_in6; -=09 + struct dlm_cfg_node *nd; + unsigned int nodeid; + /* Taken from ip6_addr_string() defined in lib/vsprintf.c */ char buf0[sizeof("AF_INET6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255\= n")]; -=09 + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; =20 /* Derived from SIMPLE_ATTR_SIZE of fs/configfs/file.c */ allowance =3D 4096; buf[0] =3D '\0'; =20 - for (i =3D 0; i < cm->addr_count; i++) { - addr =3D cm->addr[i]; + mutex_lock(&dn->cfg_lock); + nd =3D dlm_cfg_get_node(dn, nodeid); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + for (i =3D 0; i < nd->addrs_count; i++) { + addr =3D &nd->addrs[i]; =20 - switch(addr->ss_family) { + switch (addr->ss_family) { case AF_INET: addr_in =3D (struct sockaddr_in *)addr; s =3D sprintf(buf0, "AF_INET %pI4\n", &addr_in->sin_addr.s_addr); @@ -733,34 +737,54 @@ static ssize_t comm_addr_list_show(struct config_item= *item, char *buf) break; } } + mutex_unlock(&dn->cfg_lock); + return 4096 - allowance; } =20 static ssize_t comm_mark_show(struct config_item *item, char *buf) { - return sprintf(buf, "%u\n", config_item_to_comm(item)->mark); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid, mark; + struct dlm_cfg_node *nd; + int rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + mutex_lock(&dn->cfg_lock); + nd =3D dlm_cfg_get_node(dn, nodeid); + if (!nd) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + mark =3D nd->mark; + mutex_unlock(&dn->cfg_lock); + + return sprintf(buf, "%u\n", mark); } =20 static ssize_t comm_mark_store(struct config_item *item, const char *buf, size_t len) { - struct dlm_comm *comm; - unsigned int mark; - int rc; + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid, mark; + int rv; =20 - rc =3D kstrtouint(buf, 0, &mark); - if (rc) - return rc; + rv =3D kstrtouint(buf, 0, &mark); + if (rv) + return rv; =20 - if (mark =3D=3D 0) - mark =3D dlm_config.ci_mark; + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; =20 - comm =3D config_item_to_comm(item); - rc =3D dlm_lowcomms_nodes_set_mark(comm->nodeid, mark); - if (rc) - return rc; + rv =3D dlm_cfg_set_node_mark(dn, nodeid, mark); + if (rv) + return rv; =20 - comm->mark =3D mark; return len; } =20 @@ -799,16 +823,52 @@ static ssize_t node_nodeid_store(struct config_item *= item, const char *buf, =20 static ssize_t node_weight_show(struct config_item *item, char *buf) { - return sprintf(buf, "%d\n", config_item_to_node(item)->weight); + struct dlm_net *dn =3D dlm_pernet(&init_net); + const struct dlm_cfg_member *mb; + unsigned int nodeid, weight; + const char *lsname; + int rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + lsname =3D config_item_name(item->ci_parent->ci_parent); + + mutex_lock(&dn->cfg_lock); + mb =3D dlm_cfg_get_ls_member(dn, lsname, nodeid); + if (!mb) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + weight =3D mb->weight; + mutex_unlock(&dn->cfg_lock); + + return sprintf(buf, "%u\n", weight); } =20 static ssize_t node_weight_store(struct config_item *item, const char *buf, size_t len) { - int rc =3D kstrtoint(buf, 0, &config_item_to_node(item)->weight); + struct dlm_net *dn =3D dlm_pernet(&init_net); + unsigned int nodeid, weight; + const char *lsname; + int rv; + + rv =3D kstrtouint(buf, 0, &weight); + if (rv) + return rv; + + rv =3D kstrtouint(config_item_name(item), 0, &nodeid); + if (WARN_ON(rv)) + return rv; + + lsname =3D config_item_name(item->ci_parent->ci_parent); + rv =3D dlm_cfg_set_weight(dn, lsname, nodeid, weight); + if (rv) + return rv; =20 - if (rc) - return rc; return len; } =20 @@ -820,163 +880,3 @@ static struct configfs_attribute *node_attrs[] =3D { [NODE_ATTR_WEIGHT] =3D &node_attr_weight, NULL, }; - -/* - * Functions for the dlm to get the info that's been configured - */ - -static struct dlm_space *get_space(char *name) -{ - struct config_item *i; - - if (!space_list) - return NULL; - - mutex_lock(&space_list->cg_subsys->su_mutex); - i =3D config_group_find_item(space_list, name); - mutex_unlock(&space_list->cg_subsys->su_mutex); - - return config_item_to_space(i); -} - -static void put_space(struct dlm_space *sp) -{ - config_item_put(&sp->group.cg_item); -} - -static struct dlm_comm *get_comm(int nodeid) -{ - struct config_item *i; - struct dlm_comm *cm =3D NULL; - int found =3D 0; - - if (!comm_list) - return NULL; - - mutex_lock(&clusters_root.subsys.su_mutex); - - list_for_each_entry(i, &comm_list->cg_children, ci_entry) { - cm =3D config_item_to_comm(i); - - if (cm->nodeid !=3D nodeid) - continue; - found =3D 1; - config_item_get(i); - break; - } - mutex_unlock(&clusters_root.subsys.su_mutex); - - if (!found) - cm =3D NULL; - return cm; -} - -static void put_comm(struct dlm_comm *cm) -{ - config_item_put(&cm->item); -} - -/* caller must free mem */ -int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out, - int *count_out) -{ - struct dlm_space *sp; - struct dlm_node *nd; - struct dlm_config_node *nodes, *node; - int rv, count; - - sp =3D get_space(lsname); - if (!sp) - return -EEXIST; - - mutex_lock(&sp->members_lock); - if (!sp->members_count) { - rv =3D -EINVAL; - printk(KERN_ERR "dlm: zero members_count\n"); - goto out; - } - - count =3D sp->members_count; - - nodes =3D kcalloc(count, sizeof(struct dlm_config_node), GFP_NOFS); - if (!nodes) { - rv =3D -ENOMEM; - goto out; - } - - node =3D nodes; - list_for_each_entry(nd, &sp->members, list) { - node->nodeid =3D nd->nodeid; - node->weight =3D nd->weight; - node->new =3D nd->new; - node->comm_seq =3D nd->comm_seq; - node++; - - nd->new =3D 0; - } - - *count_out =3D count; - *nodes_out =3D nodes; - rv =3D 0; - out: - mutex_unlock(&sp->members_lock); - put_space(sp); - return rv; -} - -int dlm_comm_seq(int nodeid, uint32_t *seq) -{ - struct dlm_comm *cm =3D get_comm(nodeid); - if (!cm) - return -EEXIST; - *seq =3D cm->seq; - put_comm(cm); - return 0; -} - -int dlm_our_nodeid(void) -{ - return local_comm->nodeid; -} - -/* num 0 is first addr, num 1 is second addr */ -int dlm_our_addr(struct sockaddr_storage *addr, int num) -{ - if (!local_comm) - return -1; - if (num + 1 > local_comm->addr_count) - return -1; - memcpy(addr, local_comm->addr[num], sizeof(*addr)); - return 0; -} - -/* Config file defaults */ -#define DEFAULT_TCP_PORT 21064 -#define DEFAULT_RSBTBL_SIZE 1024 -#define DEFAULT_RECOVER_TIMER 5 -#define DEFAULT_TOSS_SECS 10 -#define DEFAULT_SCAN_SECS 5 -#define DEFAULT_LOG_DEBUG 0 -#define DEFAULT_LOG_INFO 1 -#define DEFAULT_PROTOCOL DLM_PROTO_TCP -#define DEFAULT_MARK 0 -#define DEFAULT_NEW_RSB_COUNT 128 -#define DEFAULT_RECOVER_CALLBACKS 0 -#define DEFAULT_CLUSTER_NAME "" - -struct dlm_config_info dlm_config =3D { - .ci_tcp_port =3D cpu_to_be16(DEFAULT_TCP_PORT), - .ci_buffer_size =3D DLM_MAX_SOCKET_BUFSIZE, - .ci_rsbtbl_size =3D DEFAULT_RSBTBL_SIZE, - .ci_recover_timer =3D DEFAULT_RECOVER_TIMER, - .ci_toss_secs =3D DEFAULT_TOSS_SECS, - .ci_scan_secs =3D DEFAULT_SCAN_SECS, - .ci_log_debug =3D DEFAULT_LOG_DEBUG, - .ci_log_info =3D DEFAULT_LOG_INFO, - .ci_protocol =3D DEFAULT_PROTOCOL, - .ci_mark =3D DEFAULT_MARK, - .ci_new_rsb_count =3D DEFAULT_NEW_RSB_COUNT, - .ci_recover_callbacks =3D DEFAULT_RECOVER_CALLBACKS, - .ci_cluster_name =3D DEFAULT_CLUSTER_NAME -}; - diff --git a/fs/dlm/configfs.h b/fs/dlm/configfs.h new file mode 100644 index 000000000000..b8027c0db8b5 --- /dev/null +++ b/fs/dlm/configfs.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/*************************************************************************= ***** + *************************************************************************= ***** + ** + ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. + ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. + ** + ** + *************************************************************************= ***** + *************************************************************************= *****/ + +#ifndef __CONFIGFS_DOT_H__ +#define __CONFIGFS_DOT_H__ + +int dlm_configfs_init(void); +void dlm_configfs_exit(void); + +#endif /* __CONFIGFS_DOT_H__ */ + diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 700a0cbb2f14..e60c1b5a7475 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -331,9 +331,10 @@ static void print_format3(struct dlm_rsb *r, struct se= q_file *s) unlock_rsb(r); } =20 -static void print_format4(struct dlm_rsb *r, struct seq_file *s) +static void print_format4(struct dlm_ls *ls, struct dlm_rsb *r, + struct seq_file *s) { - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int print_name =3D 1; int i; =20 @@ -381,6 +382,7 @@ static const struct seq_operations format4_seq_ops; static int table_seq_show(struct seq_file *seq, void *iter_ptr) { struct dlm_rsb *rsb =3D list_entry(iter_ptr, struct dlm_rsb, res_slow_lis= t); + struct dlm_ls *ls =3D seq->private; =20 if (seq->op =3D=3D &format1_seq_ops) print_format1(rsb, seq); @@ -389,7 +391,7 @@ static int table_seq_show(struct seq_file *seq, void *i= ter_ptr) else if (seq->op =3D=3D &format3_seq_ops) print_format3(rsb, seq); else if (seq->op =3D=3D &format4_seq_ops) - print_format4(rsb, seq); + print_format4(ls, rsb, seq); =20 return 0; } @@ -735,11 +737,15 @@ static const struct file_operations dlm_rawmsg_fops = =3D { .write =3D dlm_rawmsg_write, }; =20 -void *dlm_create_debug_comms_file(int nodeid, void *data) +void *dlm_create_debug_comms_file(struct dlm_net *dn, int nodeid, void *da= ta) { struct dentry *d_node; char name[256]; =20 + /* debugfs only supported for init_net */ + if (!net_eq(read_pnet(&dn->net), &init_net)) + return NULL; + memset(name, 0, sizeof(name)); snprintf(name, 256, "%d", nodeid); =20 @@ -754,8 +760,12 @@ void *dlm_create_debug_comms_file(int nodeid, void *da= ta) return d_node; } =20 -void dlm_delete_debug_comms_file(void *ctx) +void dlm_delete_debug_comms_file(struct dlm_net *dn, void *ctx) { + /* debugfs only supported for init_net */ + if (!net_eq(read_pnet(&dn->net), &init_net)) + return; + debugfs_remove(ctx); } =20 @@ -764,6 +774,10 @@ void dlm_create_debug_file(struct dlm_ls *ls) /* Reserve enough space for the longest file name */ char name[DLM_LOCKSPACE_LEN + sizeof("_queued_asts")]; =20 + /* debugfs only supported for init_net */ + if (!net_eq(read_pnet(&ls->ls_dn->net), &init_net)) + return; + /* format 1 */ =20 ls->ls_debug_rsb_dentry =3D debugfs_create_file(ls->ls_name, diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c index b1ab0adbd9d0..2fa0afd5c57b 100644 --- a/fs/dlm/dir.c +++ b/fs/dlm/dir.c @@ -35,7 +35,7 @@ int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash) uint32_t node; =20 if (ls->ls_num_nodes =3D=3D 1) - return dlm_our_nodeid(); + return dlm_our_nodeid(ls->ls_dn); else { node =3D (hash >> 16) % ls->ls_total_weight; return ls->ls_node_array[node]; @@ -74,7 +74,7 @@ int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq) goto out; =20 list_for_each_entry(memb, &ls->ls_nodes, list) { - if (memb->nodeid =3D=3D dlm_our_nodeid()) + if (memb->nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) continue; =20 memset(last_name, 0, DLM_RESNAME_MAXLEN); diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index d534a4bc162b..10fe3b59bd70 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -64,24 +64,24 @@ struct dlm_msg; =20 #define log_rinfo(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_info) \ + if (ls->ls_dn->config.ci_log_info) \ printk(KERN_INFO "dlm: %s: " fmt "\n", \ (ls)->ls_name, ##args); \ - else if (dlm_config.ci_log_debug) \ + else if (ls->ls_dn->config.ci_log_debug) \ printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0) =20 #define log_debug(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_debug) \ + if (ls->ls_dn->config.ci_log_debug) \ printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0) =20 #define log_limit(ls, fmt, args...) \ do { \ - if (dlm_config.ci_log_debug) \ + if (ls->ls_dn->config.ci_log_debug) \ printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \ (ls)->ls_name , ##args); \ } while (0) @@ -561,6 +561,8 @@ struct rcom_lock { =20 struct dlm_ls { struct list_head ls_list; /* list of lockspaces */ + struct dlm_net *ls_dn; + netns_tracker ls_tracker; uint32_t ls_global_id; /* global unique lockspace ID */ uint32_t ls_generation; uint32_t ls_exflags; @@ -816,15 +818,17 @@ void dlm_register_debugfs(void); void dlm_unregister_debugfs(void); void dlm_create_debug_file(struct dlm_ls *ls); void dlm_delete_debug_file(struct dlm_ls *ls); -void *dlm_create_debug_comms_file(int nodeid, void *data); -void dlm_delete_debug_comms_file(void *ctx); +void *dlm_create_debug_comms_file(struct dlm_net *dn, int nodeid, void *da= ta); +void dlm_delete_debug_comms_file(struct dlm_net *dn, void *ctx); #else static inline void dlm_register_debugfs(void) { } static inline void dlm_unregister_debugfs(void) { } static inline void dlm_create_debug_file(struct dlm_ls *ls) { } static inline void dlm_delete_debug_file(struct dlm_ls *ls) { } -static inline void *dlm_create_debug_comms_file(int nodeid, void *data) { = return NULL; } -static inline void dlm_delete_debug_comms_file(void *ctx) { } +static inline void *dlm_create_debug_comms_file(struct dlm_net *dn, int no= deid, + void *data) { return NULL; } +static inline void dlm_delete_debug_comms_file(struct dlm_net *dn, + void *ctx) { } #endif =20 #endif /* __DLM_INTERNAL_DOT_H__ */ diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 865dc70a9dfc..e2c479baf88c 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -320,9 +320,9 @@ static void queue_bast(struct dlm_rsb *r, struct dlm_lk= b *lkb, int rqmode) * Basic operations on rsb's and lkb's */ =20 -static inline unsigned long rsb_toss_jiffies(void) +static inline unsigned long rsb_toss_jiffies(const struct dlm_ls *ls) { - return jiffies + (READ_ONCE(dlm_config.ci_toss_secs) * HZ); + return jiffies + (READ_ONCE(ls->ls_dn->config.ci_toss_secs) * HZ); } =20 /* This is only called to add a reference when the code already holds @@ -457,7 +457,7 @@ static void del_scan(struct dlm_ls *ls, struct dlm_rsb = *r) =20 static void add_scan(struct dlm_ls *ls, struct dlm_rsb *r) { - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); struct dlm_rsb *first; =20 /* A dir record for a remote master rsb should never be on the scan list.= */ @@ -473,7 +473,7 @@ static void add_scan(struct dlm_ls *ls, struct dlm_rsb = *r) =20 spin_lock_bh(&ls->ls_scan_lock); /* set the new rsb absolute expire time in the rsb */ - r->res_toss_time =3D rsb_toss_jiffies(); + r->res_toss_time =3D rsb_toss_jiffies(ls); if (list_empty(&ls->ls_scan_list)) { /* if the queue is empty add the element and it's * our new expire time @@ -510,7 +510,7 @@ static void add_scan(struct dlm_ls *ls, struct dlm_rsb = *r) void dlm_rsb_scan(struct timer_list *timer) { struct dlm_ls *ls =3D from_timer(ls, timer, ls_scan_timer); - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); struct dlm_rsb *r; int rv; =20 @@ -696,7 +696,7 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *= name, int len, unsigned int flags, struct dlm_rsb **r_ret) { struct dlm_rsb *r =3D NULL; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int from_local =3D 0; int from_other =3D 0; int from_dir =3D 0; @@ -915,7 +915,7 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void= *name, int len, unsigned int flags, struct dlm_rsb **r_ret) { struct dlm_rsb *r =3D NULL; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int recover =3D (flags & R_RECEIVE_RECOVER); int error; =20 @@ -1135,7 +1135,7 @@ static int validate_master_nodeid(struct dlm_ls *ls, = struct dlm_rsb *r, r->res_first_lkid, r->res_name); } =20 - r->res_master_nodeid =3D dlm_our_nodeid(); + r->res_master_nodeid =3D dlm_our_nodeid(ls->ls_dn); r->res_nodeid =3D 0; return 0; } @@ -1257,7 +1257,7 @@ static int _dlm_master_lookup(struct dlm_ls *ls, int = from_nodeid, const char *na { struct dlm_rsb *r =3D NULL; uint32_t hash; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int dir_nodeid, error; =20 if (len > DLM_RESNAME_MAXLEN) @@ -1423,7 +1423,7 @@ static void deactivate_rsb(struct kref *kref) { struct dlm_rsb *r =3D container_of(kref, struct dlm_rsb, res_ref); struct dlm_ls *ls =3D r->res_ls; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); =20 DLM_ASSERT(list_empty(&r->res_root_list), dlm_print_rsb(r);); rsb_set_flag(r, RSB_INACTIVE); @@ -2647,7 +2647,7 @@ static void send_blocking_asts_all(struct dlm_rsb *r,= struct dlm_lkb *lkb) =20 static int set_master(struct dlm_rsb *r, struct dlm_lkb *lkb) { - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(r->res_ls->ls_dn); =20 if (rsb_flag(r, RSB_MASTER_UNCERTAIN)) { rsb_clear_flag(r, RSB_MASTER_UNCERTAIN); @@ -3502,7 +3502,7 @@ static int _create_message(struct dlm_ls *ls, int mb_= len, pass into midcomms_commit and a message buffer (mb) that we write our data into */ =20 - mh =3D dlm_midcomms_get_mhandle(to_nodeid, mb_len, &mb); + mh =3D dlm_midcomms_get_mhandle(ls->ls_dn, to_nodeid, mb_len, &mb); if (!mh) return -ENOBUFS; =20 @@ -3510,7 +3510,7 @@ static int _create_message(struct dlm_ls *ls, int mb_= len, =20 ms->m_header.h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINO= R); ms->m_header.u.h_lockspace =3D cpu_to_le32(ls->ls_global_id); - ms->m_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + ms->m_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid(ls->ls_dn)); ms->m_header.h_length =3D cpu_to_le16(mb_len); ms->m_header.h_cmd =3D DLM_MSG; =20 @@ -4024,7 +4024,7 @@ static int receive_request(struct dlm_ls *ls, const s= truct dlm_message *ms) =20 lock_rsb(r); =20 - if (r->res_master_nodeid !=3D dlm_our_nodeid()) { + if (r->res_master_nodeid !=3D dlm_our_nodeid(ls->ls_dn)) { error =3D validate_master_nodeid(ls, r, from_nodeid); if (error) { unlock_rsb(r); @@ -4273,7 +4273,7 @@ static void receive_lookup(struct dlm_ls *ls, const s= truct dlm_message *ms) int len, error, ret_nodeid, from_nodeid, our_nodeid; =20 from_nodeid =3D le32_to_cpu(ms->m_header.h_nodeid); - our_nodeid =3D dlm_our_nodeid(); + our_nodeid =3D dlm_our_nodeid(ls->ls_dn); =20 len =3D receive_extralen(ms); =20 @@ -4305,7 +4305,7 @@ static void receive_remove(struct dlm_ls *ls, const s= truct dlm_message *ms) } =20 dir_nodeid =3D dlm_hash2nodeid(ls, le32_to_cpu(ms->m_hash)); - if (dir_nodeid !=3D dlm_our_nodeid()) { + if (dir_nodeid !=3D dlm_our_nodeid(ls->ls_dn)) { log_error(ls, "receive_remove from %d bad nodeid %d", from_nodeid, dir_nodeid); return; @@ -4461,8 +4461,8 @@ static int receive_request_reply(struct dlm_ls *ls, from_nodeid, result, r->res_master_nodeid, r->res_dir_nodeid, r->res_first_lkid, r->res_name); =20 - if (r->res_dir_nodeid !=3D dlm_our_nodeid() && - r->res_master_nodeid !=3D dlm_our_nodeid()) { + if (r->res_dir_nodeid !=3D dlm_our_nodeid(ls->ls_dn) && + r->res_master_nodeid !=3D dlm_our_nodeid(ls->ls_dn)) { /* cause _request_lock->set_master->send_lookup */ r->res_master_nodeid =3D 0; r->res_nodeid =3D -1; @@ -4477,7 +4477,7 @@ static int receive_request_reply(struct dlm_ls *ls, } else { _request_lock(r, lkb); =20 - if (r->res_master_nodeid =3D=3D dlm_our_nodeid()) + if (r->res_master_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) confirm_master(r, 0); } break; @@ -4735,10 +4735,11 @@ static void receive_lookup_reply(struct dlm_ls *ls, "master %d dir %d our %d first %x %s", lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid), ret_nodeid, r->res_master_nodeid, r->res_dir_nodeid, - dlm_our_nodeid(), r->res_first_lkid, r->res_name); + dlm_our_nodeid(ls->ls_dn), r->res_first_lkid, + r->res_name); } =20 - if (ret_nodeid =3D=3D dlm_our_nodeid()) { + if (ret_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) { r->res_master_nodeid =3D ret_nodeid; r->res_nodeid =3D 0; do_lookup_list =3D 1; @@ -4957,7 +4958,8 @@ void dlm_receive_message_saved(struct dlm_ls *ls, con= st struct dlm_message *ms, standard locking activity) or an RCOM (recovery message sent as part of lockspace recovery). */ =20 -void dlm_receive_buffer(const union dlm_packet *p, int nodeid) +void dlm_receive_buffer(struct dlm_net *dn, const union dlm_packet *p, + int nodeid) { const struct dlm_header *hd =3D &p->header; struct dlm_ls *ls; @@ -4982,17 +4984,14 @@ void dlm_receive_buffer(const union dlm_packet *p, = int nodeid) return; } =20 - ls =3D dlm_find_lockspace_global(le32_to_cpu(hd->u.h_lockspace)); + ls =3D dlm_find_lockspace_global(dn, le32_to_cpu(hd->u.h_lockspace)); if (!ls) { - if (dlm_config.ci_log_debug) { - printk_ratelimited(KERN_DEBUG "dlm: invalid lockspace " - "%u from %d cmd %d type %d\n", - le32_to_cpu(hd->u.h_lockspace), nodeid, - hd->h_cmd, type); - } + log_print("dlm: invalid lockspace %u from %d cmd %d type %d\n", + le32_to_cpu(hd->u.h_lockspace), nodeid, + hd->h_cmd, type); =20 if (hd->h_cmd =3D=3D DLM_RCOM && type =3D=3D DLM_RCOM_STATUS) - dlm_send_ls_not_ready(nodeid, &p->rcom); + dlm_send_ls_not_ready(dn, nodeid, &p->rcom); return; } =20 @@ -5624,7 +5623,8 @@ int dlm_recover_master_copy(struct dlm_ls *ls, const = struct dlm_rcom *rc, =20 lock_rsb(r); =20 - if (dlm_no_directory(ls) && (dlm_dir_nodeid(r) !=3D dlm_our_nodeid())) { + if (dlm_no_directory(ls) && + (dlm_dir_nodeid(r) !=3D dlm_our_nodeid(ls->ls_dn))) { log_error(ls, "dlm_recover_master_copy remote %d %x not dir", from_nodeid, remid); error =3D -EBADR; @@ -6275,7 +6275,7 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user= _proc *proc, { int error =3D 0; =20 - if (nodeid && (nodeid !=3D dlm_our_nodeid())) { + if (nodeid && (nodeid !=3D dlm_our_nodeid(ls->ls_dn))) { error =3D send_purge(ls, nodeid, pid); } else { dlm_lock_recovery(ls); diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h index b23d7b854ed4..dc374fc80c9a 100644 --- a/fs/dlm/lock.h +++ b/fs/dlm/lock.h @@ -16,7 +16,8 @@ void dlm_dump_rsb_name(struct dlm_ls *ls, const char *nam= e, int len); void dlm_print_lkb(struct dlm_lkb *lkb); void dlm_receive_message_saved(struct dlm_ls *ls, const struct dlm_message= *ms, uint32_t saved_seq); -void dlm_receive_buffer(const union dlm_packet *p, int nodeid); +void dlm_receive_buffer(struct dlm_net *dn, const union dlm_packet *p, + int nodeid); int dlm_modes_compat(int mode1, int mode2); void free_inactive_rsb(struct dlm_rsb *r); void dlm_put_rsb(struct dlm_rsb *r); diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 2dd37a2e718d..e5eeb3957b89 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -9,6 +9,7 @@ **************************************************************************= ***** **************************************************************************= ****/ =20 +#include #include =20 #include "dlm_internal.h" @@ -25,11 +26,6 @@ #include "user.h" #include "ast.h" =20 -static int ls_count; -static struct mutex ls_lock; -static struct list_head lslist; -static spinlock_t lslist_lock; - static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_= t len) { ssize_t ret =3D len; @@ -179,13 +175,34 @@ static const struct sysfs_ops dlm_attr_ops =3D { .store =3D dlm_attr_store, }; =20 +static const void *lockspace_kobj_namespace(const struct kobject *k) +{ + struct dlm_ls *ls =3D container_of(k, struct dlm_ls, ls_kobj); + + return read_pnet(&ls->ls_dn->net); +} + static struct kobj_type dlm_ktype =3D { .default_groups =3D dlm_groups, - .sysfs_ops =3D &dlm_attr_ops, + .sysfs_ops =3D &dlm_attr_ops, + .namespace =3D lockspace_kobj_namespace, }; =20 static struct kset *dlm_kset; =20 +static const struct kobj_ns_type_operations * +dlm_sysfs_object_child_ns_type(const struct kobject *kobj) +{ + return &net_ns_type_operations; +} + +static const struct kobj_type dlm_kset_ktype =3D { + .sysfs_ops =3D &kobj_sysfs_ops, + .release =3D kset_release, + .get_ownership =3D kset_get_ownership, + .child_ns_type =3D dlm_sysfs_object_child_ns_type, +}; + static int do_uevent(struct dlm_ls *ls, int in) { if (in) @@ -218,14 +235,18 @@ static const struct kset_uevent_ops dlm_uevent_ops = =3D { .uevent =3D dlm_uevent, }; =20 -int __init dlm_lockspace_init(void) +void __net_init dlm_lockspace_net_init(struct dlm_net *dn) { - ls_count =3D 0; - mutex_init(&ls_lock); - INIT_LIST_HEAD(&lslist); - spin_lock_init(&lslist_lock); + dn->ls_count =3D 0; + mutex_init(&dn->ls_lock); + INIT_LIST_HEAD(&dn->lslist); + spin_lock_init(&dn->lslist_lock); +} =20 - dlm_kset =3D kset_create_and_add("dlm", &dlm_uevent_ops, kernel_kobj); +int __init dlm_lockspace_init(void) +{ + dlm_kset =3D kset_type_create_and_add("dlm", &dlm_uevent_ops, + kernel_kobj, &dlm_kset_ktype); if (!dlm_kset) { printk(KERN_WARNING "%s: can not create kset\n", __func__); return -ENOMEM; @@ -238,13 +259,13 @@ void dlm_lockspace_exit(void) kset_unregister(dlm_kset); } =20 -struct dlm_ls *dlm_find_lockspace_name(const char *lsname) +struct dlm_ls *dlm_find_lockspace_name(struct dlm_net *dn, const char *lsn= ame) { struct dlm_ls *ls; =20 - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); =20 - list_for_each_entry(ls, &lslist, ls_list) { + list_for_each_entry(ls, &dn->lslist, ls_list) { if (!strncmp(ls->ls_name, lsname, DLM_LOCKSPACE_LEN)) { atomic_inc(&ls->ls_count); goto out; @@ -252,17 +273,17 @@ struct dlm_ls *dlm_find_lockspace_name(const char *ls= name) } ls =3D NULL; out: - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); return ls; } =20 -struct dlm_ls *dlm_find_lockspace_global(uint32_t id) +struct dlm_ls *dlm_find_lockspace_global(struct dlm_net *dn, uint32_t id) { struct dlm_ls *ls; =20 - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); =20 - list_for_each_entry(ls, &lslist, ls_list) { + list_for_each_entry(ls, &dn->lslist, ls_list) { if (ls->ls_global_id =3D=3D id) { atomic_inc(&ls->ls_count); goto out; @@ -270,7 +291,7 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id) } ls =3D NULL; out: - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); return ls; } =20 @@ -282,12 +303,12 @@ struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace= _t *lockspace) return ls; } =20 -struct dlm_ls *dlm_find_lockspace_device(int minor) +struct dlm_ls *dlm_find_lockspace_device(struct dlm_net *dn, int minor) { struct dlm_ls *ls; =20 - spin_lock_bh(&lslist_lock); - list_for_each_entry(ls, &lslist, ls_list) { + spin_lock_bh(&dn->lslist_lock); + list_for_each_entry(ls, &dn->lslist, ls_list) { if (ls->ls_device.minor =3D=3D minor) { atomic_inc(&ls->ls_count); goto out; @@ -295,7 +316,7 @@ struct dlm_ls *dlm_find_lockspace_device(int minor) } ls =3D NULL; out: - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); return ls; } =20 @@ -307,26 +328,28 @@ void dlm_put_lockspace(struct dlm_ls *ls) =20 static void remove_lockspace(struct dlm_ls *ls) { + struct dlm_net *dn =3D ls->ls_dn; + retry: wait_event(ls->ls_count_wait, atomic_read(&ls->ls_count) =3D=3D 0); =20 - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); if (atomic_read(&ls->ls_count) !=3D 0) { - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); goto retry; } =20 WARN_ON(ls->ls_create_count !=3D 0); list_del(&ls->ls_list); - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); } =20 -static int threads_start(void) +static int threads_start(struct dlm_net *dn) { int error; =20 /* Thread for sending/receiving messages for all lockspace's */ - error =3D dlm_midcomms_start(); + error =3D dlm_midcomms_start(dn); if (error) log_print("cannot start dlm midcomms %d", error); =20 @@ -371,8 +394,8 @@ static void free_lockspace(struct work_struct *work) kfree(ls); } =20 -static int new_lockspace(const char *name, const char *cluster, - uint32_t flags, int lvblen, +static int new_lockspace(struct dlm_net *dn, const char *name, + const char *cluster, uint32_t flags, int lvblen, const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace) { @@ -389,14 +412,14 @@ static int new_lockspace(const char *name, const char= *cluster, if (!try_module_get(THIS_MODULE)) return -EINVAL; =20 - if (!dlm_user_daemon_available()) { + if (!dlm_user_daemon_available(dn)) { log_print("dlm user daemon not available"); error =3D -EUNATCH; goto out; } =20 if (ops && ops_result) { - if (!dlm_config.ci_recover_callbacks) + if (!dn->config.ci_recover_callbacks) *ops_result =3D -EOPNOTSUPP; else *ops_result =3D 0; @@ -404,21 +427,21 @@ static int new_lockspace(const char *name, const char= *cluster, =20 if (!cluster) log_print("dlm cluster name '%s' is being used without an application pr= ovided cluster name", - dlm_config.ci_cluster_name); + dn->config.ci_cluster_name); =20 - if (dlm_config.ci_recover_callbacks && cluster && - strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) { + if (dn->config.ci_recover_callbacks && cluster && + strncmp(cluster, dn->config.ci_cluster_name, DLM_LOCKSPACE_LEN)) { log_print("dlm cluster name '%s' does not match " "the application cluster name '%s'", - dlm_config.ci_cluster_name, cluster); + dn->config.ci_cluster_name, cluster); error =3D -EBADR; goto out; } =20 error =3D 0; =20 - spin_lock_bh(&lslist_lock); - list_for_each_entry(ls, &lslist, ls_list) { + spin_lock_bh(&dn->lslist_lock); + list_for_each_entry(ls, &dn->lslist, ls_list) { WARN_ON(ls->ls_create_count <=3D 0); if (ls->ls_namelen !=3D namelen) continue; @@ -433,7 +456,7 @@ static int new_lockspace(const char *name, const char *= cluster, error =3D 1; break; } - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); =20 if (error) goto out; @@ -449,8 +472,10 @@ static int new_lockspace(const char *name, const char = *cluster, atomic_set(&ls->ls_count, 0); init_waitqueue_head(&ls->ls_count_wait); ls->ls_flags =3D 0; + get_net_track(read_pnet(&dn->net), &ls->ls_tracker, GFP_NOFS); + ls->ls_dn =3D dn; =20 - if (ops && dlm_config.ci_recover_callbacks) { + if (ops && dn->config.ci_recover_callbacks) { ls->ls_ops =3D ops; ls->ls_ops_arg =3D ops_arg; } @@ -548,10 +573,10 @@ static int new_lockspace(const char *name, const char= *cluster, spin_lock_init(&ls->ls_scan_lock); timer_setup(&ls->ls_scan_timer, dlm_rsb_scan, TIMER_DEFERRABLE); =20 - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); ls->ls_create_count =3D 1; - list_add(&ls->ls_list, &lslist); - spin_unlock_bh(&lslist_lock); + list_add(&ls->ls_list, &dn->lslist); + spin_unlock_bh(&dn->lslist_lock); =20 if (flags & DLM_LSFL_FS) set_bit(LSFL_FS, &ls->ls_flags); @@ -618,9 +643,9 @@ static int new_lockspace(const char *name, const char *= cluster, out_callback: dlm_callback_stop(ls); out_delist: - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); list_del(&ls->ls_list); - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); xa_destroy(&ls->ls_recover_xa); kfree(ls->ls_recover_buf); out_lkbxa: @@ -628,38 +653,39 @@ static int new_lockspace(const char *name, const char= *cluster, rhashtable_destroy(&ls->ls_rsbtbl); out_lsfree: kobject_put(&ls->ls_kobj); + put_net_track(read_pnet(&dn->net), &ls->ls_tracker); kfree(ls); out: module_put(THIS_MODULE); return error; } =20 -static int __dlm_new_lockspace(const char *name, const char *cluster, - uint32_t flags, int lvblen, +static int __dlm_new_lockspace(struct dlm_net *dn, const char *name, + const char *cluster, uint32_t flags, int lvblen, const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace) { int error =3D 0; =20 - mutex_lock(&ls_lock); - if (!ls_count) - error =3D threads_start(); + mutex_lock(&dn->ls_lock); + if (!dn->ls_count) + error =3D threads_start(dn); if (error) goto out; =20 - error =3D new_lockspace(name, cluster, flags, lvblen, ops, ops_arg, + error =3D new_lockspace(dn, name, cluster, flags, lvblen, ops, ops_arg, ops_result, lockspace); if (!error) - ls_count++; + dn->ls_count++; if (error > 0) error =3D 0; - if (!ls_count) { - dlm_midcomms_shutdown(); - dlm_midcomms_stop(); + if (!dn->ls_count) { + dlm_midcomms_shutdown(dn); + dlm_midcomms_stop(dn); } out: - mutex_unlock(&ls_lock); + mutex_unlock(&dn->ls_lock); return error; } =20 @@ -669,12 +695,14 @@ int dlm_new_lockspace(struct net *net, const char *na= me, const char *cluster, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace) { - return __dlm_new_lockspace(name, cluster, flags | DLM_LSFL_FS, lvblen, + struct dlm_net *dn =3D dlm_pernet(net); + + return __dlm_new_lockspace(dn, name, cluster, flags | DLM_LSFL_FS, lvblen, ops, ops_arg, ops_result, lockspace); } =20 -int dlm_new_user_lockspace(const char *name, const char *cluster, - uint32_t flags, int lvblen, +int dlm_new_user_lockspace(struct dlm_net *dn, const char *name, + const char *cluster, uint32_t flags, int lvblen, const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace) @@ -682,7 +710,7 @@ int dlm_new_user_lockspace(const char *name, const char= *cluster, if (flags & DLM_LSFL_SOFTIRQ) return -EINVAL; =20 - return __dlm_new_lockspace(name, cluster, flags, lvblen, ops, + return __dlm_new_lockspace(dn, name, cluster, flags, lvblen, ops, ops_arg, ops_result, lockspace); } =20 @@ -717,13 +745,13 @@ static int lockspace_busy(struct dlm_ls *ls, int forc= e) return rv; } =20 -static int release_lockspace(struct dlm_ls *ls, int force) +static int release_lockspace(struct dlm_net *dn, struct dlm_ls *ls, int fo= rce) { int busy, rv; =20 busy =3D lockspace_busy(ls, force); =20 - spin_lock_bh(&lslist_lock); + spin_lock_bh(&dn->lslist_lock); if (ls->ls_create_count =3D=3D 1) { if (busy) { rv =3D -EBUSY; @@ -737,19 +765,19 @@ static int release_lockspace(struct dlm_ls *ls, int f= orce) } else { rv =3D -EINVAL; } - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); =20 if (rv) { log_debug(ls, "release_lockspace no remove %d", rv); return rv; } =20 - if (ls_count =3D=3D 1) - dlm_midcomms_version_wait(); + if (dn->ls_count =3D=3D 1) + dlm_midcomms_version_wait(ls->ls_dn); =20 dlm_device_deregister(ls); =20 - if (force < 3 && dlm_user_daemon_available()) + if (force < 3 && dlm_user_daemon_available(dn)) do_uevent(ls, 0); =20 dlm_recoverd_stop(ls); @@ -760,9 +788,9 @@ static int release_lockspace(struct dlm_ls *ls, int for= ce) clear_bit(LSFL_RUNNING, &ls->ls_flags); timer_shutdown_sync(&ls->ls_scan_timer); =20 - if (ls_count =3D=3D 1) { + if (dn->ls_count =3D=3D 1) { dlm_clear_members(ls); - dlm_midcomms_shutdown(); + dlm_midcomms_shutdown(ls->ls_dn); } =20 dlm_callback_stop(ls); @@ -788,6 +816,8 @@ static int release_lockspace(struct dlm_ls *ls, int for= ce) =20 log_rinfo(ls, "%s final free", __func__); =20 + put_net_track(read_pnet(&dn->net), &ls->ls_tracker); + /* delayed free of data structures see free_lockspace() */ queue_work(dlm_wq, &ls->ls_free_work); module_put(THIS_MODULE); @@ -810,6 +840,7 @@ static int release_lockspace(struct dlm_ls *ls, int for= ce) =20 int dlm_release_lockspace(void *lockspace, int force) { + struct dlm_net *dn; struct dlm_ls *ls; int error; =20 @@ -818,36 +849,37 @@ int dlm_release_lockspace(void *lockspace, int force) return -EINVAL; dlm_put_lockspace(ls); =20 - mutex_lock(&ls_lock); - error =3D release_lockspace(ls, force); + dn =3D ls->ls_dn; + mutex_lock(&dn->ls_lock); + error =3D release_lockspace(dn, ls, force); if (!error) - ls_count--; - if (!ls_count) - dlm_midcomms_stop(); - mutex_unlock(&ls_lock); + dn->ls_count--; + if (!dn->ls_count) + dlm_midcomms_stop(dn); + mutex_unlock(&dn->ls_lock); =20 return error; } =20 -void dlm_stop_lockspaces(void) +void dlm_stop_lockspaces(struct dlm_net *dn) { struct dlm_ls *ls; int count; =20 restart: count =3D 0; - spin_lock_bh(&lslist_lock); - list_for_each_entry(ls, &lslist, ls_list) { + spin_lock_bh(&dn->lslist_lock); + list_for_each_entry(ls, &dn->lslist, ls_list) { if (!test_bit(LSFL_RUNNING, &ls->ls_flags)) { count++; continue; } - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); log_error(ls, "no userland control daemon, stopping lockspace"); dlm_ls_stop(ls); goto restart; } - spin_unlock_bh(&lslist_lock); + spin_unlock_bh(&dn->lslist_lock); =20 if (count) log_print("dlm user daemon left %d lockspaces", count); diff --git a/fs/dlm/lockspace.h b/fs/dlm/lockspace.h index 7898a906aab9..9d50fc44dc0b 100644 --- a/fs/dlm/lockspace.h +++ b/fs/dlm/lockspace.h @@ -22,14 +22,15 @@ =20 int dlm_lockspace_init(void); void dlm_lockspace_exit(void); -struct dlm_ls *dlm_find_lockspace_name(const char *lsname); -struct dlm_ls *dlm_find_lockspace_global(uint32_t id); +void dlm_lockspace_net_init(struct dlm_net *dn); +struct dlm_ls *dlm_find_lockspace_name(struct dlm_net *dn, const char *lsn= ame); +struct dlm_ls *dlm_find_lockspace_global(struct dlm_net *dn, uint32_t id); struct dlm_ls *dlm_find_lockspace_local(void *id); -struct dlm_ls *dlm_find_lockspace_device(int minor); +struct dlm_ls *dlm_find_lockspace_device(struct dlm_net *dn, int minor); void dlm_put_lockspace(struct dlm_ls *ls); -void dlm_stop_lockspaces(void); -int dlm_new_user_lockspace(const char *name, const char *cluster, - uint32_t flags, int lvblen, +void dlm_stop_lockspaces(struct dlm_net *dn); +int dlm_new_user_lockspace(struct dlm_net *dn, const char *name, + const char *cluster, uint32_t flags, int lvblen, const struct dlm_lockspace_ops *ops, void *ops_arg, int *ops_result, dlm_lockspace_t **lockspace); diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index df40c3fd1070..a64905ba3e62 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -68,6 +68,7 @@ =20 struct connection { struct socket *sock; /* NULL if not connected */ + struct dlm_net *dn; uint32_t nodeid; /* So we know who we are in the list */ /* this semaphore is used to allow parallel recv/send in read * lock mode. When we release a sock we need to held the write lock. @@ -114,11 +115,6 @@ struct connection { }; #define sock2con(x) ((struct connection *)(x)->sk_user_data) =20 -struct listen_connection { - struct socket *sock; - struct work_struct rwork; -}; - #define DLM_WQ_REMAIN_BYTES(e) (PAGE_SIZE - e->end) #define DLM_WQ_LENGTH_BYTES(e) (e->end - e->offset) =20 @@ -156,39 +152,6 @@ struct processqueue_entry { struct list_head list; }; =20 -struct dlm_proto_ops { - bool try_new_addr; - const char *name; - int proto; - - void (*sockopts)(struct socket *sock); - int (*bind)(struct socket *sock); - int (*listen_validate)(void); - void (*listen_sockopts)(struct socket *sock); - int (*listen_bind)(struct socket *sock); -}; - -static struct listen_sock_callbacks { - void (*sk_error_report)(struct sock *); - void (*sk_data_ready)(struct sock *); - void (*sk_state_change)(struct sock *); - void (*sk_write_space)(struct sock *); -} listen_sock; - -static struct listen_connection listen_con; -static struct sockaddr_storage dlm_local_addr[DLM_MAX_ADDR_COUNT]; -static int dlm_local_count; - -/* Work queues */ -static struct workqueue_struct *io_workqueue; -static struct workqueue_struct *process_workqueue; - -static struct hlist_head connection_hash[CONN_HASH_SIZE]; -static DEFINE_SPINLOCK(connections_lock); -DEFINE_STATIC_SRCU(connections_srcu); - -static const struct dlm_proto_ops *dlm_proto_ops; - #define DLM_IO_SUCCESS 0 #define DLM_IO_END 1 #define DLM_IO_EOF 2 @@ -199,16 +162,9 @@ static void process_recv_sockets(struct work_struct *w= ork); static void process_send_sockets(struct work_struct *work); static void process_dlm_messages(struct work_struct *work); =20 -static DECLARE_WORK(process_work, process_dlm_messages); -static DEFINE_SPINLOCK(processqueue_lock); -static bool process_dlm_messages_pending; -static DECLARE_WAIT_QUEUE_HEAD(processqueue_wq); -static atomic_t processqueue_count; -static LIST_HEAD(processqueue); - -bool dlm_lowcomms_is_running(void) +bool dlm_lowcomms_is_running(const struct dlm_net *dn) { - return !!listen_con.sock; + return !!dn->listen_con.sock; } =20 static void lowcomms_queue_swork(struct connection *con) @@ -218,7 +174,7 @@ static void lowcomms_queue_swork(struct connection *con) if (!test_bit(CF_IO_STOP, &con->flags) && !test_bit(CF_APP_LIMITED, &con->flags) && !test_and_set_bit(CF_SEND_PENDING, &con->flags)) - queue_work(io_workqueue, &con->swork); + queue_work(con->dn->io_workqueue, &con->swork); } =20 static void lowcomms_queue_rwork(struct connection *con) @@ -229,7 +185,7 @@ static void lowcomms_queue_rwork(struct connection *con) =20 if (!test_bit(CF_IO_STOP, &con->flags) && !test_and_set_bit(CF_RECV_PENDING, &con->flags)) - queue_work(io_workqueue, &con->rwork); + queue_work(con->dn->io_workqueue, &con->rwork); } =20 static void writequeue_entry_ctor(void *data) @@ -266,11 +222,12 @@ static struct writequeue_entry *con_next_wq(struct co= nnection *con) return e; } =20 -static struct connection *__find_con(int nodeid, int r) +static struct connection *__find_con(const struct dlm_net *dn, + int nodeid, int r) { struct connection *con; =20 - hlist_for_each_entry_rcu(con, &connection_hash[r], list) { + hlist_for_each_entry_rcu(con, &dn->connection_hash[r], list) { if (con->nodeid =3D=3D nodeid) return con; } @@ -278,8 +235,10 @@ static struct connection *__find_con(int nodeid, int r) return NULL; } =20 -static void dlm_con_init(struct connection *con, int nodeid) +static void dlm_con_init(struct dlm_net *dn, struct connection *con, + int nodeid) { + con->dn =3D dn; con->nodeid =3D nodeid; init_rwsem(&con->sock_lock); INIT_LIST_HEAD(&con->writequeue); @@ -294,13 +253,14 @@ static void dlm_con_init(struct connection *con, int = nodeid) * If 'allocation' is zero then we don't attempt to create a new * connection structure for this node. */ -static struct connection *nodeid2con(int nodeid, gfp_t alloc) +static struct connection *nodeid2con(struct dlm_net *dn, int nodeid, + gfp_t alloc) { struct connection *con, *tmp; int r; =20 r =3D nodeid_hash(nodeid); - con =3D __find_con(nodeid, r); + con =3D __find_con(dn, nodeid, r); if (con || !alloc) return con; =20 @@ -308,24 +268,24 @@ static struct connection *nodeid2con(int nodeid, gfp_= t alloc) if (!con) return NULL; =20 - dlm_con_init(con, nodeid); + dlm_con_init(dn, con, nodeid); =20 - spin_lock(&connections_lock); + spin_lock(&dn->connections_lock); /* Because multiple workqueues/threads calls this function it can * race on multiple cpu's. Instead of locking hot path __find_con() * we just check in rare cases of recently added nodes again * under protection of connections_lock. If this is the case we * abort our connection creation and return the existing connection. */ - tmp =3D __find_con(nodeid, r); + tmp =3D __find_con(dn, nodeid, r); if (tmp) { - spin_unlock(&connections_lock); + spin_unlock(&dn->connections_lock); kfree(con); return tmp; } =20 - hlist_add_head_rcu(&con->list, &connection_hash[r]); - spin_unlock(&connections_lock); + hlist_add_head_rcu(&con->list, &dn->connection_hash[r]); + spin_unlock(&dn->connections_lock); =20 return con; } @@ -358,7 +318,8 @@ static int addr_compare(const struct sockaddr_storage *= x, return 1; } =20 -static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out, +static int nodeid_to_addr(struct dlm_net *dn, int nodeid, + struct sockaddr_storage *sas_out, struct sockaddr *sa_out, bool try_new_addr, unsigned int *mark) { @@ -366,20 +327,20 @@ static int nodeid_to_addr(int nodeid, struct sockaddr= _storage *sas_out, struct connection *con; int idx; =20 - if (!dlm_local_count) + if (!dn->dlm_local_count) return -1; =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, 0); if (!con) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOENT; } =20 spin_lock(&con->addrs_lock); if (!con->addr_count) { spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOENT; } =20 @@ -399,11 +360,11 @@ static int nodeid_to_addr(int nodeid, struct sockaddr= _storage *sas_out, memcpy(sas_out, &sas, sizeof(struct sockaddr_storage)); =20 if (!sa_out) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return 0; } =20 - if (dlm_local_addr[0].ss_family =3D=3D AF_INET) { + if (dn->dlm_local_addr[0].ss_family =3D=3D AF_INET) { struct sockaddr_in *in4 =3D (struct sockaddr_in *) &sas; struct sockaddr_in *ret4 =3D (struct sockaddr_in *) sa_out; ret4->sin_addr.s_addr =3D in4->sin_addr.s_addr; @@ -413,19 +374,19 @@ static int nodeid_to_addr(int nodeid, struct sockaddr= _storage *sas_out, ret6->sin6_addr =3D in6->sin6_addr; } =20 - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return 0; } =20 -static int addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid, - unsigned int *mark) +static int addr_to_nodeid(struct dlm_net *dn, struct sockaddr_storage *add= r, + int *nodeid, unsigned int *mark) { struct connection *con; int i, idx, addr_i; =20 - idx =3D srcu_read_lock(&connections_srcu); + idx =3D srcu_read_lock(&dn->connections_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(con, &connection_hash[i], list) { + hlist_for_each_entry_rcu(con, &dn->connection_hash[i], list) { WARN_ON_ONCE(!con->addr_count); =20 spin_lock(&con->addrs_lock); @@ -434,14 +395,14 @@ static int addr_to_nodeid(struct sockaddr_storage *ad= dr, int *nodeid, *nodeid =3D con->nodeid; *mark =3D con->mark; spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return 0; } } spin_unlock(&con->addrs_lock); } } - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); =20 return -ENOENT; } @@ -459,15 +420,16 @@ static bool dlm_lowcomms_con_has_addr(const struct co= nnection *con, return false; } =20 -int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr) +int dlm_lowcomms_addr(struct dlm_net *dn, int nodeid, + struct sockaddr_storage *addr) { struct connection *con; bool ret, idx; =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, GFP_NOFS); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, GFP_NOFS); if (!con) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOMEM; } =20 @@ -475,27 +437,27 @@ int dlm_lowcomms_addr(int nodeid, struct sockaddr_sto= rage *addr) if (!con->addr_count) { memcpy(&con->addr[0], addr, sizeof(*addr)); con->addr_count =3D 1; - con->mark =3D dlm_config.ci_mark; + con->mark =3D dn->config.ci_mark; spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return 0; } =20 ret =3D dlm_lowcomms_con_has_addr(con, addr); if (ret) { spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -EEXIST; } =20 if (con->addr_count >=3D DLM_MAX_ADDR_COUNT) { spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOSPC; } =20 memcpy(&con->addr[con->addr_count++], addr, sizeof(*addr)); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); spin_unlock(&con->addrs_lock); return 0; } @@ -538,20 +500,22 @@ static void lowcomms_state_change(struct sock *sk) =20 static void lowcomms_listen_data_ready(struct sock *sk) { + struct dlm_net *dn =3D dlm_pernet(sock_net(sk)); + trace_sk_data_ready(sk); =20 - queue_work(io_workqueue, &listen_con.rwork); + queue_work(dn->io_workqueue, &dn->listen_con.rwork); } =20 -int dlm_lowcomms_connect_node(int nodeid) +int dlm_lowcomms_connect_node(struct dlm_net *dn, int nodeid) { struct connection *con; int idx; =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, 0); if (WARN_ON_ONCE(!con)) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOENT; } =20 @@ -562,28 +526,29 @@ int dlm_lowcomms_connect_node(int nodeid) spin_unlock_bh(&con->writequeue_lock); } up_read(&con->sock_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); =20 cond_resched(); return 0; } =20 -int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark) +int dlm_lowcomms_nodes_set_mark(struct dlm_net *dn, int nodeid, + unsigned int mark) { struct connection *con; int idx; =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, 0); if (!con) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOENT; } =20 spin_lock(&con->addrs_lock); con->mark =3D mark; spin_unlock(&con->addrs_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return 0; } =20 @@ -595,48 +560,47 @@ static void lowcomms_error_report(struct sock *sk) inet =3D inet_sk(sk); switch (sk->sk_family) { case AF_INET: - printk_ratelimited(KERN_ERR "dlm: node %d: socket error " - "sending to node %d at %pI4, dport %d, " - "sk_err=3D%d/%d\n", dlm_our_nodeid(), + pr_err_ratelimited("dlm: node %d: socket error sending to node %d at %pI= 4, dport %d, sk_err=3D%d/%d\n", + dlm_our_nodeid(con->dn), con->nodeid, &inet->inet_daddr, ntohs(inet->inet_dport), sk->sk_err, READ_ONCE(sk->sk_err_soft)); break; #if IS_ENABLED(CONFIG_IPV6) case AF_INET6: - printk_ratelimited(KERN_ERR "dlm: node %d: socket error " - "sending to node %d at %pI6c, " - "dport %d, sk_err=3D%d/%d\n", dlm_our_nodeid(), + pr_err_ratelimited("dlm: node %d: socket error sending to node %d at %pI= 6c, dport %d, sk_err=3D%d/%d\n", + dlm_our_nodeid(con->dn), con->nodeid, &sk->sk_v6_daddr, ntohs(inet->inet_dport), sk->sk_err, READ_ONCE(sk->sk_err_soft)); break; #endif default: - printk_ratelimited(KERN_ERR "dlm: node %d: socket error " - "invalid socket family %d set, " - "sk_err=3D%d/%d\n", dlm_our_nodeid(), + pr_err_ratelimited("dlm: node %d: socket error invalid socket family %d = set, sk_err=3D%d/%d\n", + dlm_our_nodeid(con->dn), sk->sk_family, sk->sk_err, READ_ONCE(sk->sk_err_soft)); break; } =20 - dlm_midcomms_unack_msg_resend(con->nodeid); + dlm_midcomms_unack_msg_resend(con->dn, con->nodeid); =20 - listen_sock.sk_error_report(sk); + con->dn->listen_sock.sk_error_report(sk); } =20 static void restore_callbacks(struct sock *sk) { + struct dlm_net *dn =3D dlm_pernet(sock_net(sk)); + #ifdef CONFIG_LOCKDEP WARN_ON_ONCE(!lockdep_sock_is_held(sk)); #endif =20 sk->sk_user_data =3D NULL; - sk->sk_data_ready =3D listen_sock.sk_data_ready; - sk->sk_state_change =3D listen_sock.sk_state_change; - sk->sk_write_space =3D listen_sock.sk_write_space; - sk->sk_error_report =3D listen_sock.sk_error_report; + sk->sk_data_ready =3D dn->listen_sock.sk_data_ready; + sk->sk_state_change =3D dn->listen_sock.sk_state_change; + sk->sk_write_space =3D dn->listen_sock.sk_write_space; + sk->sk_error_report =3D dn->listen_sock.sk_error_report; } =20 /* Make a socket active */ @@ -650,7 +614,7 @@ static void add_sock(struct socket *sock, struct connec= tion *con) sk->sk_user_data =3D con; sk->sk_data_ready =3D lowcomms_data_ready; sk->sk_write_space =3D lowcomms_write_space; - if (dlm_config.ci_protocol =3D=3D DLM_PROTO_SCTP) + if (con->dn->config.ci_protocol =3D=3D DLM_PROTO_SCTP) sk->sk_state_change =3D lowcomms_state_change; sk->sk_allocation =3D GFP_NOFS; sk->sk_use_task_frag =3D false; @@ -660,10 +624,11 @@ static void add_sock(struct socket *sock, struct conn= ection *con) =20 /* Add the port number to an IPv6 or 4 sockaddr and return the address length */ -static void make_sockaddr(struct sockaddr_storage *saddr, __be16 port, - int *addr_len) +static void make_sockaddr(const struct dlm_net *dn, + struct sockaddr_storage *saddr, + __be16 port, int *addr_len) { - saddr->ss_family =3D dlm_local_addr[0].ss_family; + saddr->ss_family =3D dn->dlm_local_addr[0].ss_family; if (saddr->ss_family =3D=3D AF_INET) { struct sockaddr_in *in4_addr =3D (struct sockaddr_in *)saddr; in4_addr->sin_port =3D port; @@ -801,7 +766,7 @@ static void shutdown_connection(struct connection *con,= bool and_other) if (con->othercon && and_other) shutdown_connection(con->othercon, false); =20 - flush_workqueue(io_workqueue); + flush_workqueue(con->dn->io_workqueue); down_read(&con->sock_lock); /* nothing to shutdown */ if (!con->sock) { @@ -858,40 +823,42 @@ static void free_processqueue_entry(struct processque= ue_entry *pentry) =20 static void process_dlm_messages(struct work_struct *work) { + struct dlm_net *dn =3D container_of(work, struct dlm_net, + process_work); struct processqueue_entry *pentry; =20 - spin_lock_bh(&processqueue_lock); - pentry =3D list_first_entry_or_null(&processqueue, + spin_lock_bh(&dn->processqueue_lock); + pentry =3D list_first_entry_or_null(&dn->processqueue, struct processqueue_entry, list); if (WARN_ON_ONCE(!pentry)) { - process_dlm_messages_pending =3D false; - spin_unlock_bh(&processqueue_lock); + dn->process_dlm_messages_pending =3D false; + spin_unlock_bh(&dn->processqueue_lock); return; } =20 list_del(&pentry->list); - if (atomic_dec_and_test(&processqueue_count)) - wake_up(&processqueue_wq); - spin_unlock_bh(&processqueue_lock); + if (atomic_dec_and_test(&dn->processqueue_count)) + wake_up(&dn->processqueue_wq); + spin_unlock_bh(&dn->processqueue_lock); =20 for (;;) { - dlm_process_incoming_buffer(pentry->nodeid, pentry->buf, + dlm_process_incoming_buffer(dn, pentry->nodeid, pentry->buf, pentry->buflen); free_processqueue_entry(pentry); =20 - spin_lock_bh(&processqueue_lock); - pentry =3D list_first_entry_or_null(&processqueue, + spin_lock_bh(&dn->processqueue_lock); + pentry =3D list_first_entry_or_null(&dn->processqueue, struct processqueue_entry, list); if (!pentry) { - process_dlm_messages_pending =3D false; - spin_unlock_bh(&processqueue_lock); + dn->process_dlm_messages_pending =3D false; + spin_unlock_bh(&dn->processqueue_lock); break; } =20 list_del(&pentry->list); - if (atomic_dec_and_test(&processqueue_count)) - wake_up(&processqueue_wq); - spin_unlock_bh(&processqueue_lock); + if (atomic_dec_and_test(&dn->processqueue_count)) + wake_up(&dn->processqueue_wq); + spin_unlock_bh(&dn->processqueue_lock); } } =20 @@ -899,6 +866,7 @@ static void process_dlm_messages(struct work_struct *wo= rk) static int receive_from_sock(struct connection *con, int buflen) { struct processqueue_entry *pentry; + struct dlm_net *dn =3D con->dn; int ret, buflen_real; struct msghdr msg; struct kvec iov; @@ -961,14 +929,14 @@ static int receive_from_sock(struct connection *con, = int buflen) memmove(con->rx_leftover_buf, pentry->buf + ret, con->rx_leftover); =20 - spin_lock_bh(&processqueue_lock); - ret =3D atomic_inc_return(&processqueue_count); - list_add_tail(&pentry->list, &processqueue); - if (!process_dlm_messages_pending) { - process_dlm_messages_pending =3D true; - queue_work(process_workqueue, &process_work); + spin_lock_bh(&dn->processqueue_lock); + ret =3D atomic_inc_return(&dn->processqueue_count); + list_add_tail(&pentry->list, &dn->processqueue); + if (!dn->process_dlm_messages_pending) { + dn->process_dlm_messages_pending =3D true; + queue_work(dn->process_workqueue, &dn->process_work); } - spin_unlock_bh(&processqueue_lock); + spin_unlock_bh(&dn->processqueue_lock); =20 if (ret > DLM_MAX_PROCESS_BUFFERS) return DLM_IO_FLUSH; @@ -977,7 +945,7 @@ static int receive_from_sock(struct connection *con, in= t buflen) } =20 /* Listening socket is busy, accept a connection */ -static int accept_from_sock(void) +static int accept_from_sock(struct dlm_net *dn) { struct sockaddr_storage peeraddr; int len, idx, result, nodeid; @@ -985,7 +953,7 @@ static int accept_from_sock(void) struct socket *newsock; unsigned int mark; =20 - result =3D kernel_accept(listen_con.sock, &newsock, O_NONBLOCK); + result =3D kernel_accept(dn->listen_con.sock, &newsock, O_NONBLOCK); if (result =3D=3D -EAGAIN) return DLM_IO_END; else if (result < 0) @@ -1000,8 +968,8 @@ static int accept_from_sock(void) } =20 /* Get the new node's NODEID */ - make_sockaddr(&peeraddr, 0, &len); - if (addr_to_nodeid(&peeraddr, &nodeid, &mark)) { + make_sockaddr(dn, &peeraddr, 0, &len); + if (addr_to_nodeid(dn, &peeraddr, &nodeid, &mark)) { switch (peeraddr.ss_family) { case AF_INET: { struct sockaddr_in *sin =3D (struct sockaddr_in *)&peeraddr; @@ -1035,10 +1003,10 @@ static int accept_from_sock(void) * the same time and the connections cross on the wire. * In this case we store the incoming one in "othercon" */ - idx =3D srcu_read_lock(&connections_srcu); - newcon =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + newcon =3D nodeid2con(dn, nodeid, 0); if (WARN_ON_ONCE(!newcon)) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); result =3D -ENOENT; goto accept_err; } @@ -1054,12 +1022,12 @@ static int accept_from_sock(void) if (!othercon) { log_print("failed to allocate incoming socket"); up_write(&newcon->sock_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); result =3D -ENOMEM; goto accept_err; } =20 - dlm_con_init(othercon, nodeid); + dlm_con_init(dn, othercon, nodeid); lockdep_set_subclass(&othercon->sock_lock, 1); newcon->othercon =3D othercon; set_bit(CF_IS_OTHERCON, &othercon->flags); @@ -1089,7 +1057,7 @@ static int accept_from_sock(void) release_sock(newcon->sock->sk); } up_write(&newcon->sock_lock); - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); =20 return DLM_IO_SUCCESS; =20 @@ -1121,15 +1089,16 @@ static void writequeue_entry_complete(struct writeq= ueue_entry *e, int completed) /* * sctp_bind_addrs - bind a SCTP socket to all our addresses */ -static int sctp_bind_addrs(struct socket *sock, __be16 port) +static int sctp_bind_addrs(struct dlm_net *dn, struct socket *sock, + __be16 port) { struct sockaddr_storage localaddr; struct sockaddr *addr =3D (struct sockaddr *)&localaddr; int i, addr_len, result =3D 0; =20 - for (i =3D 0; i < dlm_local_count; i++) { - memcpy(&localaddr, &dlm_local_addr[i], sizeof(localaddr)); - make_sockaddr(&localaddr, port, &addr_len); + for (i =3D 0; i < dn->dlm_local_count; i++) { + memcpy(&localaddr, &dn->dlm_local_addr[i], sizeof(localaddr)); + make_sockaddr(dn, &localaddr, port, &addr_len); =20 if (!i) result =3D kernel_bind(sock, addr, addr_len); @@ -1146,17 +1115,18 @@ static int sctp_bind_addrs(struct socket *sock, __b= e16 port) } =20 /* Get local addresses */ -static void init_local(void) +static void init_local(struct dlm_net *dn) { struct sockaddr_storage sas; int i; =20 - dlm_local_count =3D 0; + dn->dlm_local_count =3D 0; for (i =3D 0; i < DLM_MAX_ADDR_COUNT; i++) { - if (dlm_our_addr(&sas, i)) + if (dlm_our_addr(dn, &sas, i)) break; =20 - memcpy(&dlm_local_addr[dlm_local_count++], &sas, sizeof(sas)); + memcpy(&dn->dlm_local_addr[dn->dlm_local_count++], &sas, + sizeof(sas)); } } =20 @@ -1255,8 +1225,9 @@ static struct dlm_msg *dlm_lowcomms_new_msg_con(struc= t connection *con, int len, * dlm_lowcomms_commit_msg which is a must call if success */ #ifndef __CHECKER__ -struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, char **ppc, - void (*cb)(void *data), void *data) +struct dlm_msg *dlm_lowcomms_new_msg(struct dlm_net *dn, int nodeid, int l= en, + char **ppc, void (*cb)(void *data), + void *data) { struct connection *con; struct dlm_msg *msg; @@ -1270,16 +1241,16 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, in= t len, char **ppc, return NULL; } =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, 0); if (WARN_ON_ONCE(!con)) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return NULL; } =20 msg =3D dlm_lowcomms_new_msg_con(con, len, ppc, cb, data); if (!msg) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return NULL; } =20 @@ -1320,8 +1291,12 @@ static void _dlm_lowcomms_commit_msg(struct dlm_msg = *msg) #ifndef __CHECKER__ void dlm_lowcomms_commit_msg(struct dlm_msg *msg) { + struct writequeue_entry *e =3D msg->entry; + struct connection *con =3D e->con; + struct dlm_net *dn =3D con->dn; + _dlm_lowcomms_commit_msg(msg); - srcu_read_unlock(&connections_srcu, msg->idx); + srcu_read_unlock(&dn->connections_srcu, msg->idx); /* because dlm_lowcomms_new_msg() */ kref_put(&msg->ref, dlm_msg_release); } @@ -1439,17 +1414,17 @@ static void connection_release(struct rcu_head *rcu) =20 /* Called from recovery when it knows that a node has left the cluster */ -int dlm_lowcomms_close(int nodeid) +int dlm_lowcomms_close(struct dlm_net *dn, int nodeid) { struct connection *con; int idx; =20 log_print("closing connection to node %d", nodeid); =20 - idx =3D srcu_read_lock(&connections_srcu); - con =3D nodeid2con(nodeid, 0); + idx =3D srcu_read_lock(&dn->connections_srcu); + con =3D nodeid2con(dn, nodeid, 0); if (WARN_ON_ONCE(!con)) { - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); return -ENOENT; } =20 @@ -1457,17 +1432,18 @@ int dlm_lowcomms_close(int nodeid) log_print("io handling for node: %d stopped", nodeid); close_connection(con, true); =20 - spin_lock(&connections_lock); + spin_lock(&dn->connections_lock); hlist_del_rcu(&con->list); - spin_unlock(&connections_lock); + spin_unlock(&dn->connections_lock); =20 clean_one_writequeue(con); - call_srcu(&connections_srcu, &con->rcu, connection_release); + call_srcu(&dn->connections_srcu, &con->rcu, connection_release); if (con->othercon) { clean_one_writequeue(con->othercon); - call_srcu(&connections_srcu, &con->othercon->rcu, connection_release); + call_srcu(&dn->connections_srcu, &con->othercon->rcu, + connection_release); } - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); =20 /* for debugging we print when we are done to compare with other * messages in between. This function need to be correctly synchronized @@ -1482,6 +1458,7 @@ int dlm_lowcomms_close(int nodeid) static void process_recv_sockets(struct work_struct *work) { struct connection *con =3D container_of(work, struct connection, rwork); + struct dlm_net *dn =3D con->dn; int ret, buflen; =20 down_read(&con->sock_lock); @@ -1490,7 +1467,7 @@ static void process_recv_sockets(struct work_struct *= work) return; } =20 - buflen =3D READ_ONCE(dlm_config.ci_buffer_size); + buflen =3D READ_ONCE(dn->config.ci_buffer_size); do { ret =3D receive_from_sock(con, buflen); } while (ret =3D=3D DLM_IO_SUCCESS); @@ -1519,11 +1496,11 @@ static void process_recv_sockets(struct work_struct= *work) * removed. Especially in a message burst we are too slow to * process messages and the queue will fill up memory. */ - wait_event(processqueue_wq, !atomic_read(&processqueue_count)); + wait_event(dn->processqueue_wq, !atomic_read(&dn->processqueue_count)); fallthrough; case DLM_IO_RESCHED: cond_resched(); - queue_work(io_workqueue, &con->rwork); + queue_work(dn->io_workqueue, &con->rwork); /* CF_RECV_PENDING not cleared */ break; default: @@ -1550,13 +1527,15 @@ static void process_recv_sockets(struct work_struct= *work) =20 static void process_listen_recv_socket(struct work_struct *work) { + struct dlm_net *dn =3D container_of(work, struct dlm_net, + listen_con.rwork); int ret; =20 - if (WARN_ON_ONCE(!listen_con.sock)) + if (WARN_ON_ONCE(!dn->listen_con.sock)) return; =20 do { - ret =3D accept_from_sock(); + ret =3D accept_from_sock(dn); } while (ret =3D=3D DLM_IO_SUCCESS); =20 if (ret < 0) @@ -1566,28 +1545,30 @@ static void process_listen_recv_socket(struct work_= struct *work) static int dlm_connect(struct connection *con) { struct sockaddr_storage addr; + struct dlm_net *dn =3D con->dn; int result, addr_len; struct socket *sock; unsigned int mark; =20 memset(&addr, 0, sizeof(addr)); - result =3D nodeid_to_addr(con->nodeid, &addr, NULL, - dlm_proto_ops->try_new_addr, &mark); + result =3D nodeid_to_addr(dn, con->nodeid, &addr, NULL, + dn->dlm_proto_ops->try_new_addr, &mark); if (result < 0) { log_print("no address for nodeid %d", con->nodeid); return result; } =20 /* Create a socket to communicate with */ - result =3D sock_create_kern(&init_net, dlm_local_addr[0].ss_family, - SOCK_STREAM, dlm_proto_ops->proto, &sock); + result =3D sock_create_kern(read_pnet(&dn->net), dn->dlm_local_addr[0].ss= _family, + SOCK_STREAM, dn->dlm_proto_ops->proto, + &sock); if (result < 0) return result; =20 sock_set_mark(sock->sk, mark); - dlm_proto_ops->sockopts(sock); + dn->dlm_proto_ops->sockopts(sock); =20 - result =3D dlm_proto_ops->bind(sock); + result =3D dn->dlm_proto_ops->bind(dn, sock); if (result < 0) { sock_release(sock); return result; @@ -1596,7 +1577,7 @@ static int dlm_connect(struct connection *con) add_sock(sock, con); =20 log_print_ratelimited("connecting to %d", con->nodeid); - make_sockaddr(&addr, dlm_config.ci_tcp_port, &addr_len); + make_sockaddr(dn, &addr, dn->config.ci_tcp_port, &addr_len); result =3D kernel_connect(sock, (struct sockaddr *)&addr, addr_len, 0); switch (result) { case -EINPROGRESS: @@ -1618,6 +1599,7 @@ static int dlm_connect(struct connection *con) static void process_send_sockets(struct work_struct *work) { struct connection *con =3D container_of(work, struct connection, swork); + struct dlm_net *dn =3D con->dn; int ret; =20 WARN_ON_ONCE(test_bit(CF_IS_OTHERCON, &con->flags)); @@ -1642,7 +1624,7 @@ static void process_send_sockets(struct work_struct *= work) * manager to fence itself after certain amount * of retries. */ - queue_work(io_workqueue, &con->swork); + queue_work(dn->io_workqueue, &con->swork); return; } } @@ -1661,7 +1643,7 @@ static void process_send_sockets(struct work_struct *= work) case DLM_IO_RESCHED: /* CF_SEND_PENDING not cleared */ cond_resched(); - queue_work(io_workqueue, &con->swork); + queue_work(dn->io_workqueue, &con->swork); break; default: if (ret < 0) { @@ -1679,58 +1661,59 @@ static void process_send_sockets(struct work_struct= *work) } } =20 -static void work_stop(void) +static void work_stop(struct dlm_net *dn) { - if (io_workqueue) { - destroy_workqueue(io_workqueue); - io_workqueue =3D NULL; + if (dn->io_workqueue) { + destroy_workqueue(dn->io_workqueue); + dn->io_workqueue =3D NULL; } =20 - if (process_workqueue) { - destroy_workqueue(process_workqueue); - process_workqueue =3D NULL; + if (dn->process_workqueue) { + destroy_workqueue(dn->process_workqueue); + dn->process_workqueue =3D NULL; } } =20 -static int work_start(void) +static int work_start(struct dlm_net *dn) { - io_workqueue =3D alloc_workqueue("dlm_io", WQ_HIGHPRI | WQ_MEM_RECLAIM | - WQ_UNBOUND, 0); - if (!io_workqueue) { + dn->io_workqueue =3D alloc_workqueue("dlm_io", WQ_HIGHPRI | + WQ_MEM_RECLAIM | WQ_UNBOUND, 0); + if (!dn->io_workqueue) { log_print("can't start dlm_io"); return -ENOMEM; } =20 - process_workqueue =3D alloc_workqueue("dlm_process", WQ_HIGHPRI | WQ_BH, = 0); - if (!process_workqueue) { + dn->process_workqueue =3D alloc_workqueue("dlm_process", + WQ_HIGHPRI | WQ_BH, 0); + if (!dn->process_workqueue) { log_print("can't start dlm_process"); - destroy_workqueue(io_workqueue); - io_workqueue =3D NULL; + destroy_workqueue(dn->io_workqueue); + dn->io_workqueue =3D NULL; return -ENOMEM; } =20 return 0; } =20 -void dlm_lowcomms_shutdown(void) +void dlm_lowcomms_shutdown(struct dlm_net *dn) { struct connection *con; int i, idx; =20 /* stop lowcomms_listen_data_ready calls */ - lock_sock(listen_con.sock->sk); - listen_con.sock->sk->sk_data_ready =3D listen_sock.sk_data_ready; - release_sock(listen_con.sock->sk); + lock_sock(dn->listen_con.sock->sk); + dn->listen_con.sock->sk->sk_data_ready =3D dn->listen_sock.sk_data_ready; + release_sock(dn->listen_con.sock->sk); =20 - cancel_work_sync(&listen_con.rwork); - dlm_close_sock(&listen_con.sock); + cancel_work_sync(&dn->listen_con.rwork); + dlm_close_sock(&dn->listen_con.sock); =20 - idx =3D srcu_read_lock(&connections_srcu); + idx =3D srcu_read_lock(&dn->connections_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(con, &connection_hash[i], list) { + hlist_for_each_entry_rcu(con, &dn->connection_hash[i], list) { shutdown_connection(con, true); stop_connection_io(con); - flush_workqueue(process_workqueue); + flush_workqueue(dn->process_workqueue); close_connection(con, true); =20 clean_one_writequeue(con); @@ -1739,48 +1722,51 @@ void dlm_lowcomms_shutdown(void) allow_connection_io(con); } } - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); } =20 -void dlm_lowcomms_stop(void) +void dlm_lowcomms_stop(struct dlm_net *dn) { - work_stop(); - dlm_proto_ops =3D NULL; + work_stop(dn); + dn->dlm_proto_ops =3D NULL; } =20 -static int dlm_listen_for_all(void) +static int dlm_listen_for_all(struct dlm_net *dn) { struct socket *sock; int result; =20 log_print("Using %s for communications", - dlm_proto_ops->name); + dn->dlm_proto_ops->name); =20 - result =3D dlm_proto_ops->listen_validate(); + result =3D dn->dlm_proto_ops->listen_validate(dn); if (result < 0) return result; =20 - result =3D sock_create_kern(&init_net, dlm_local_addr[0].ss_family, - SOCK_STREAM, dlm_proto_ops->proto, &sock); + result =3D sock_create_kern(read_pnet(&dn->net), dn->dlm_local_addr[0].ss= _family, + SOCK_STREAM, dn->dlm_proto_ops->proto, + &sock); if (result < 0) { log_print("Can't create comms socket: %d", result); return result; } =20 - sock_set_mark(sock->sk, dlm_config.ci_mark); - dlm_proto_ops->listen_sockopts(sock); + sock_set_mark(sock->sk, dn->config.ci_mark); + dn->dlm_proto_ops->listen_sockopts(sock); =20 - result =3D dlm_proto_ops->listen_bind(sock); + result =3D dn->dlm_proto_ops->listen_bind(dn, sock); if (result < 0) goto out; =20 lock_sock(sock->sk); - listen_sock.sk_data_ready =3D sock->sk->sk_data_ready; - listen_sock.sk_write_space =3D sock->sk->sk_write_space; - listen_sock.sk_error_report =3D sock->sk->sk_error_report; - listen_sock.sk_state_change =3D sock->sk->sk_state_change; + dn->listen_sock.sk_data_ready =3D sock->sk->sk_data_ready; + dn->listen_sock.sk_write_space =3D sock->sk->sk_write_space; + dn->listen_sock.sk_error_report =3D sock->sk->sk_error_report; + dn->listen_sock.sk_state_change =3D sock->sk->sk_state_change; =20 - listen_con.sock =3D sock; + mutex_lock(&dn->cfg_lock); + dn->listen_con.sock =3D sock; + mutex_unlock(&dn->cfg_lock); =20 sock->sk->sk_allocation =3D GFP_NOFS; sock->sk->sk_use_task_frag =3D false; @@ -1789,7 +1775,7 @@ static int dlm_listen_for_all(void) =20 result =3D sock->ops->listen(sock, 128); if (result < 0) { - dlm_close_sock(&listen_con.sock); + dlm_close_sock(&dn->listen_con.sock); return result; } =20 @@ -1800,7 +1786,7 @@ static int dlm_listen_for_all(void) return result; } =20 -static int dlm_tcp_bind(struct socket *sock) +static int dlm_tcp_bind(struct dlm_net *dn, struct socket *sock) { struct sockaddr_storage src_addr; int result, addr_len; @@ -1808,8 +1794,8 @@ static int dlm_tcp_bind(struct socket *sock) /* Bind to our cluster-known address connecting to avoid * routing problems. */ - memcpy(&src_addr, &dlm_local_addr[0], sizeof(src_addr)); - make_sockaddr(&src_addr, 0, &addr_len); + memcpy(&src_addr, &dn->dlm_local_addr[0], sizeof(src_addr)); + make_sockaddr(dn, &src_addr, 0, &addr_len); =20 result =3D kernel_bind(sock, (struct sockaddr *)&src_addr, addr_len); @@ -1821,10 +1807,10 @@ static int dlm_tcp_bind(struct socket *sock) return 0; } =20 -static int dlm_tcp_listen_validate(void) +static int dlm_tcp_listen_validate(const struct dlm_net *dn) { /* We don't support multi-homed hosts */ - if (dlm_local_count > 1) { + if (dn->dlm_local_count > 1) { log_print("TCP protocol can't handle multi-homed hosts, try SCTP"); return -EINVAL; } @@ -1844,13 +1830,14 @@ static void dlm_tcp_listen_sockopts(struct socket *= sock) sock_set_reuseaddr(sock->sk); } =20 -static int dlm_tcp_listen_bind(struct socket *sock) +static int dlm_tcp_listen_bind(struct dlm_net *dn, struct socket *sock) { int addr_len; =20 /* Bind to our port */ - make_sockaddr(&dlm_local_addr[0], dlm_config.ci_tcp_port, &addr_len); - return kernel_bind(sock, (struct sockaddr *)&dlm_local_addr[0], + make_sockaddr(dn, &dn->dlm_local_addr[0], dn->config.ci_tcp_port, + &addr_len); + return kernel_bind(sock, (struct sockaddr *)&dn->dlm_local_addr[0], addr_len); } =20 @@ -1864,12 +1851,12 @@ static const struct dlm_proto_ops dlm_tcp_ops =3D { .listen_bind =3D dlm_tcp_listen_bind, }; =20 -static int dlm_sctp_bind(struct socket *sock) +static int dlm_sctp_bind(struct dlm_net *dn, struct socket *sock) { - return sctp_bind_addrs(sock, 0); + return sctp_bind_addrs(dn, sock, 0); } =20 -static int dlm_sctp_listen_validate(void) +static int dlm_sctp_listen_validate(const struct dlm_net *dn) { if (!IS_ENABLED(CONFIG_IP_SCTP)) { log_print("SCTP is not enabled by this kernel"); @@ -1880,9 +1867,9 @@ static int dlm_sctp_listen_validate(void) return 0; } =20 -static int dlm_sctp_bind_listen(struct socket *sock) +static int dlm_sctp_bind_listen(struct dlm_net *dn, struct socket *sock) { - return sctp_bind_addrs(sock, dlm_config.ci_tcp_port); + return sctp_bind_addrs(dn, sock, dn->config.ci_tcp_port); } =20 static void dlm_sctp_sockopts(struct socket *sock) @@ -1903,77 +1890,87 @@ static const struct dlm_proto_ops dlm_sctp_ops =3D { .listen_bind =3D dlm_sctp_bind_listen, }; =20 -int dlm_lowcomms_start(void) +int dlm_lowcomms_start(struct dlm_net *dn) { int error; =20 - init_local(); - if (!dlm_local_count) { + init_local(dn); + if (!dn->dlm_local_count) { error =3D -ENOTCONN; log_print("no local IP address has been set"); goto fail; } =20 - error =3D work_start(); + error =3D work_start(dn); if (error) goto fail; =20 /* Start listening */ - switch (dlm_config.ci_protocol) { + switch (dn->config.ci_protocol) { case DLM_PROTO_TCP: - dlm_proto_ops =3D &dlm_tcp_ops; + dn->dlm_proto_ops =3D &dlm_tcp_ops; break; case DLM_PROTO_SCTP: - dlm_proto_ops =3D &dlm_sctp_ops; + dn->dlm_proto_ops =3D &dlm_sctp_ops; break; default: log_print("Invalid protocol identifier %d set", - dlm_config.ci_protocol); + dn->config.ci_protocol); error =3D -EINVAL; goto fail_proto_ops; } =20 - error =3D dlm_listen_for_all(); + error =3D dlm_listen_for_all(dn); if (error) goto fail_listen; =20 return 0; =20 fail_listen: - dlm_proto_ops =3D NULL; + dn->dlm_proto_ops =3D NULL; fail_proto_ops: - work_stop(); + work_stop(dn); fail: return error; } =20 -void dlm_lowcomms_init(void) +void __net_init dlm_lowcomms_init(struct dlm_net *dn) { int i; =20 + init_srcu_struct(&dn->connections_srcu); + spin_lock_init(&dn->connections_lock); + for (i =3D 0; i < CONN_HASH_SIZE; i++) - INIT_HLIST_HEAD(&connection_hash[i]); + INIT_HLIST_HEAD(&dn->connection_hash[i]); =20 - INIT_WORK(&listen_con.rwork, process_listen_recv_socket); + INIT_WORK(&dn->listen_con.rwork, process_listen_recv_socket); + INIT_WORK(&dn->process_work, process_dlm_messages); + spin_lock_init(&dn->processqueue_lock); + init_waitqueue_head(&dn->processqueue_wq); + INIT_LIST_HEAD(&dn->processqueue); } =20 -void dlm_lowcomms_exit(void) +void __net_exit dlm_lowcomms_exit(struct dlm_net *dn) { struct connection *con; int i, idx; =20 - idx =3D srcu_read_lock(&connections_srcu); + idx =3D srcu_read_lock(&dn->connections_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(con, &connection_hash[i], list) { - spin_lock(&connections_lock); + hlist_for_each_entry_rcu(con, &dn->connection_hash[i], list) { + spin_lock(&dn->connections_lock); hlist_del_rcu(&con->list); - spin_unlock(&connections_lock); + spin_unlock(&dn->connections_lock); =20 if (con->othercon) - call_srcu(&connections_srcu, &con->othercon->rcu, + call_srcu(&dn->connections_srcu, &con->othercon->rcu, connection_release); - call_srcu(&connections_srcu, &con->rcu, connection_release); + call_srcu(&dn->connections_srcu, &con->rcu, connection_release); } } - srcu_read_unlock(&connections_srcu, idx); + srcu_read_unlock(&dn->connections_srcu, idx); + + srcu_barrier(&dn->connections_srcu); + cleanup_srcu_struct(&dn->connections_srcu); } diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index fd0df604eb93..f19c061c9dde 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h @@ -18,8 +18,6 @@ #define DLM_MAX_APP_BUFSIZE (DLM_MAX_SOCKET_BUFSIZE - \ DLM_MIDCOMMS_OPT_LEN) =20 -#define CONN_HASH_SIZE 32 - /* This is deliberately very simple because most clusters have simple * sequential nodeids, so we should be able to go straight to a connection * struct in the array @@ -30,23 +28,26 @@ static inline int nodeid_hash(int nodeid) } =20 /* check if dlm is running */ -bool dlm_lowcomms_is_running(void); +bool dlm_lowcomms_is_running(const struct dlm_net *dn); =20 -int dlm_lowcomms_start(void); -void dlm_lowcomms_shutdown(void); +int dlm_lowcomms_start(struct dlm_net *dn); +void dlm_lowcomms_shutdown(struct dlm_net *dn); void dlm_lowcomms_shutdown_node(int nodeid, bool force); -void dlm_lowcomms_stop(void); -void dlm_lowcomms_init(void); -void dlm_lowcomms_exit(void); -int dlm_lowcomms_close(int nodeid); -struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, char **ppc, - void (*cb)(void *data), void *data); +void dlm_lowcomms_stop(struct dlm_net *dn); +void dlm_lowcomms_init(struct dlm_net *dn); +void dlm_lowcomms_exit(struct dlm_net *dn); +int dlm_lowcomms_close(struct dlm_net *dn, int nodeid); +struct dlm_msg *dlm_lowcomms_new_msg(struct dlm_net *dn, int nodeid, int l= en, + char **ppc, void (*cb)(void *data), + void *data); void dlm_lowcomms_commit_msg(struct dlm_msg *msg); void dlm_lowcomms_put_msg(struct dlm_msg *msg); int dlm_lowcomms_resend_msg(struct dlm_msg *msg); -int dlm_lowcomms_connect_node(int nodeid); -int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark); -int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr); +int dlm_lowcomms_connect_node(struct dlm_net *dn, int nodeid); +int dlm_lowcomms_nodes_set_mark(struct dlm_net *dn, int nodeid, + unsigned int mark); +int dlm_lowcomms_addr(struct dlm_net *dn, int nodeid, + struct sockaddr_storage *addr); void dlm_midcomms_receive_done(int nodeid); struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void); struct kmem_cache *dlm_lowcomms_msg_cache_create(void); diff --git a/fs/dlm/main.c b/fs/dlm/main.c index 4887c8a05318..01ba63ab3822 100644 --- a/fs/dlm/main.c +++ b/fs/dlm/main.c @@ -17,7 +17,6 @@ #include "user.h" #include "memory.h" #include "config.h" -#include "midcomms.h" =20 #define CREATE_TRACE_POINTS #include @@ -32,8 +31,6 @@ static int __init init_dlm(void) if (error) goto out; =20 - dlm_midcomms_init(); - error =3D dlm_lockspace_init(); if (error) goto out_mem; @@ -72,7 +69,6 @@ static int __init init_dlm(void) out_lockspace: dlm_lockspace_exit(); out_mem: - dlm_midcomms_exit(); dlm_memory_exit(); out: return error; @@ -86,7 +82,6 @@ static void __exit exit_dlm(void) dlm_user_exit(); dlm_config_exit(); dlm_lockspace_exit(); - dlm_midcomms_exit(); dlm_unregister_debugfs(); dlm_memory_exit(); } diff --git a/fs/dlm/member.c b/fs/dlm/member.c index c9661906568a..ed5f4139d712 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -100,7 +100,7 @@ int dlm_slots_copy_in(struct dlm_ls *ls) struct dlm_rcom *rc =3D ls->ls_recover_buf; struct rcom_config *rf =3D (struct rcom_config *)rc->rc_buf; struct rcom_slot *ro0, *ro; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int i, num_slots; uint32_t gen; =20 @@ -162,7 +162,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots,= int *slots_size, { struct dlm_member *memb; struct dlm_slot *array; - int our_nodeid =3D dlm_our_nodeid(); + int our_nodeid =3D dlm_our_nodeid(ls->ls_dn); int array_size, max_slots, i; int need =3D 0; int max =3D 0; @@ -307,18 +307,18 @@ static void add_ordered_member(struct dlm_ls *ls, str= uct dlm_member *new) } } =20 -static int add_remote_member(int nodeid) +static int add_remote_member(struct dlm_net *dn, int nodeid) { int error; =20 - if (nodeid =3D=3D dlm_our_nodeid()) + if (nodeid =3D=3D dlm_our_nodeid(dn)) return 0; =20 - error =3D dlm_lowcomms_connect_node(nodeid); + error =3D dlm_lowcomms_connect_node(dn, nodeid); if (error < 0) return error; =20 - dlm_midcomms_add_member(nodeid); + dlm_midcomms_add_member(dn, nodeid); return 0; } =20 @@ -335,7 +335,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm= _config_node *node) memb->weight =3D node->weight; memb->comm_seq =3D node->comm_seq; =20 - error =3D add_remote_member(node->nodeid); + error =3D add_remote_member(ls->ls_dn, node->nodeid); if (error < 0) { kfree(memb); return error; @@ -373,8 +373,8 @@ int dlm_is_removed(struct dlm_ls *ls, int nodeid) return 0; } =20 -static void clear_memb_list(struct list_head *head, - void (*after_del)(int nodeid)) +static void clear_memb_list(struct dlm_net *dn, struct list_head *head, + void (*after_del)(struct dlm_net *dn, int nodeid)) { struct dlm_member *memb; =20 @@ -382,28 +382,28 @@ static void clear_memb_list(struct list_head *head, memb =3D list_entry(head->next, struct dlm_member, list); list_del(&memb->list); if (after_del) - after_del(memb->nodeid); + after_del(dn, memb->nodeid); kfree(memb); } } =20 -static void remove_remote_member(int nodeid) +static void remove_remote_member(struct dlm_net *dn, int nodeid) { - if (nodeid =3D=3D dlm_our_nodeid()) + if (nodeid =3D=3D dlm_our_nodeid(dn)) return; =20 - dlm_midcomms_remove_member(nodeid); + dlm_midcomms_remove_member(dn, nodeid); } =20 void dlm_clear_members(struct dlm_ls *ls) { - clear_memb_list(&ls->ls_nodes, remove_remote_member); + clear_memb_list(ls->ls_dn, &ls->ls_nodes, remove_remote_member); ls->ls_num_nodes =3D 0; } =20 void dlm_clear_members_gone(struct dlm_ls *ls) { - clear_memb_list(&ls->ls_nodes_gone, NULL); + clear_memb_list(ls->ls_dn, &ls->ls_nodes_gone, NULL); } =20 static void make_member_array(struct dlm_ls *ls) @@ -493,7 +493,7 @@ static void dlm_lsop_recover_slot(struct dlm_ls *ls, st= ruct dlm_member *memb) we consider the node to have failed (versus being removed due to dlm_release_lockspace) */ =20 - error =3D dlm_comm_seq(memb->nodeid, &seq); + error =3D dlm_comm_seq(ls->ls_dn, memb->nodeid, &seq); =20 if (!error && seq =3D=3D memb->comm_seq) return; @@ -582,7 +582,7 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_r= ecover *rv, int *neg_out) =20 neg++; list_move(&memb->list, &ls->ls_nodes_gone); - remove_remote_member(memb->nodeid); + remove_remote_member(ls->ls_dn, memb->nodeid); ls->ls_num_nodes--; dlm_lsop_recover_slot(ls, memb); } @@ -719,7 +719,7 @@ int dlm_ls_start(struct dlm_ls *ls) if (!rv) return -ENOMEM; =20 - error =3D dlm_config_nodes(ls->ls_name, &nodes, &count); + error =3D dlm_config_nodes(ls->ls_dn, ls->ls_name, &nodes, &count); if (error < 0) goto fail_rv; =20 diff --git a/fs/dlm/midcomms.c b/fs/dlm/midcomms.c index 2c101bbe261a..6b36909bc0f5 100644 --- a/fs/dlm/midcomms.c +++ b/fs/dlm/midcomms.c @@ -153,6 +153,7 @@ =20 struct midcomms_node { int nodeid; + struct dlm_net *dn; uint32_t version; atomic_t seq_send; atomic_t seq_next; @@ -212,18 +213,6 @@ struct dlm_mhandle { struct rcu_head rcu; }; =20 -static struct hlist_head node_hash[CONN_HASH_SIZE]; -static DEFINE_SPINLOCK(nodes_lock); -DEFINE_STATIC_SRCU(nodes_srcu); - -/* This mutex prevents that midcomms_close() is running while - * stop() or remove(). As I experienced invalid memory access - * behaviours when DLM_DEBUG_FENCE_TERMINATION is enabled and - * resetting machines. I will end in some double deletion in nodes - * datastructure. - */ -static DEFINE_MUTEX(close_lock); - struct kmem_cache *dlm_midcomms_cache_create(void) { return KMEM_CACHE(dlm_mhandle, 0); @@ -271,11 +260,11 @@ uint32_t dlm_midcomms_version(struct midcomms_node *n= ode) return node->version; } =20 -static struct midcomms_node *__find_node(int nodeid, int r) +static struct midcomms_node *__find_node(struct dlm_net *dn, int nodeid, i= nt r) { struct midcomms_node *node; =20 - hlist_for_each_entry_rcu(node, &node_hash[r], hlist) { + hlist_for_each_entry_rcu(node, &dn->node_hash[r], hlist) { if (node->nodeid =3D=3D nodeid) return node; } @@ -329,32 +318,34 @@ static void midcomms_node_reset(struct midcomms_node = *node) wake_up(&node->shutdown_wait); } =20 -static struct midcomms_node *nodeid2node(int nodeid) +static struct midcomms_node *nodeid2node(struct dlm_net *dn, int nodeid) { - return __find_node(nodeid, nodeid_hash(nodeid)); + return __find_node(dn, nodeid, nodeid_hash(nodeid)); } =20 -int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr) +int dlm_midcomms_addr(struct dlm_net *dn, int nodeid, + struct sockaddr_storage *addr) { int ret, idx, r =3D nodeid_hash(nodeid); struct midcomms_node *node; =20 - ret =3D dlm_lowcomms_addr(nodeid, addr); + ret =3D dlm_lowcomms_addr(dn, nodeid, addr); if (ret) return ret; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D __find_node(nodeid, r); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D __find_node(dn, nodeid, r); if (node) { - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return 0; } - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); =20 node =3D kmalloc(sizeof(*node), GFP_NOFS); if (!node) return -ENOMEM; =20 + node->dn =3D dn; node->nodeid =3D nodeid; spin_lock_init(&node->state_lock); spin_lock_init(&node->send_queue_lock); @@ -364,29 +355,29 @@ int dlm_midcomms_addr(int nodeid, struct sockaddr_sto= rage *addr) node->users =3D 0; midcomms_node_reset(node); =20 - spin_lock_bh(&nodes_lock); - hlist_add_head_rcu(&node->hlist, &node_hash[r]); - spin_unlock_bh(&nodes_lock); + spin_lock_bh(&dn->nodes_lock); + hlist_add_head_rcu(&node->hlist, &dn->node_hash[r]); + spin_unlock_bh(&dn->nodes_lock); =20 - node->debugfs =3D dlm_create_debug_comms_file(nodeid, node); + node->debugfs =3D dlm_create_debug_comms_file(dn, nodeid, node); return 0; } =20 -static int dlm_send_ack(int nodeid, uint32_t seq) +static int dlm_send_ack(struct dlm_net *dn, int nodeid, uint32_t seq) { int mb_len =3D sizeof(struct dlm_header); struct dlm_header *m_header; struct dlm_msg *msg; char *ppc; =20 - msg =3D dlm_lowcomms_new_msg(nodeid, mb_len, &ppc, NULL, NULL); + msg =3D dlm_lowcomms_new_msg(dn, nodeid, mb_len, &ppc, NULL, NULL); if (!msg) return -ENOMEM; =20 m_header =3D (struct dlm_header *)ppc; =20 m_header->h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINOR); - m_header->h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + m_header->h_nodeid =3D cpu_to_le32(dlm_our_nodeid(dn)); m_header->h_length =3D cpu_to_le16(mb_len); m_header->h_cmd =3D DLM_ACK; m_header->u.h_seq =3D cpu_to_le32(seq); @@ -416,7 +407,8 @@ static void dlm_send_ack_threshold(struct midcomms_node= *node, } while (atomic_cmpxchg(&node->ulp_delivered, oval, nval) !=3D oval); =20 if (send_ack) - dlm_send_ack(node->nodeid, atomic_read(&node->seq_next)); + dlm_send_ack(node->dn, node->nodeid, + atomic_read(&node->seq_next)); } =20 static int dlm_send_fin(struct midcomms_node *node, @@ -427,7 +419,7 @@ static int dlm_send_fin(struct midcomms_node *node, struct dlm_mhandle *mh; char *ppc; =20 - mh =3D dlm_midcomms_get_mhandle(node->nodeid, mb_len, &ppc); + mh =3D dlm_midcomms_get_mhandle(node->dn, node->nodeid, mb_len, &ppc); if (!mh) return -ENOMEM; =20 @@ -437,7 +429,7 @@ static int dlm_send_fin(struct midcomms_node *node, m_header =3D (struct dlm_header *)ppc; =20 m_header->h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINOR); - m_header->h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + m_header->h_nodeid =3D cpu_to_le32(dlm_our_nodeid(node->dn)); m_header->h_length =3D cpu_to_le16(mb_len); m_header->h_cmd =3D DLM_FIN; =20 @@ -500,15 +492,15 @@ static void dlm_pas_fin_ack_rcv(struct midcomms_node = *node) spin_unlock_bh(&node->state_lock); } =20 -static void dlm_receive_buffer_3_2_trace(uint32_t seq, +static void dlm_receive_buffer_3_2_trace(struct dlm_net *dn, uint32_t seq, const union dlm_packet *p) { switch (p->header.h_cmd) { case DLM_MSG: - trace_dlm_recv_message(dlm_our_nodeid(), seq, &p->message); + trace_dlm_recv_message(dlm_our_nodeid(dn), seq, &p->message); break; case DLM_RCOM: - trace_dlm_recv_rcom(dlm_our_nodeid(), seq, &p->rcom); + trace_dlm_recv_rcom(dlm_our_nodeid(dn), seq, &p->rcom); break; default: break; @@ -540,7 +532,7 @@ static void dlm_midcomms_receive_buffer(const union dlm= _packet *p, =20 switch (node->state) { case DLM_ESTABLISHED: - dlm_send_ack(node->nodeid, nval); + dlm_send_ack(node->dn, node->nodeid, nval); =20 /* passive shutdown DLM_LAST_ACK case 1 * additional we check if the node is used by @@ -559,14 +551,14 @@ static void dlm_midcomms_receive_buffer(const union d= lm_packet *p, } break; case DLM_FIN_WAIT1: - dlm_send_ack(node->nodeid, nval); + dlm_send_ack(node->dn, node->nodeid, nval); node->state =3D DLM_CLOSING; set_bit(DLM_NODE_FLAG_STOP_RX, &node->flags); pr_debug("switch node %d to state %s\n", node->nodeid, dlm_state_str(node->state)); break; case DLM_FIN_WAIT2: - dlm_send_ack(node->nodeid, nval); + dlm_send_ack(node->dn, node->nodeid, nval); midcomms_node_reset(node); pr_debug("switch node %d to state %s\n", node->nodeid, dlm_state_str(node->state)); @@ -585,8 +577,8 @@ static void dlm_midcomms_receive_buffer(const union dlm= _packet *p, break; default: WARN_ON_ONCE(test_bit(DLM_NODE_FLAG_STOP_RX, &node->flags)); - dlm_receive_buffer_3_2_trace(seq, p); - dlm_receive_buffer(p, node->nodeid); + dlm_receive_buffer_3_2_trace(node->dn, seq, p); + dlm_receive_buffer(node->dn, p, node->nodeid); atomic_inc(&node->ulp_delivered); /* unlikely case to send ack back when we don't transmit */ dlm_send_ack_threshold(node, DLM_RECV_ACK_BACK_MSG_THRESHOLD); @@ -597,7 +589,7 @@ static void dlm_midcomms_receive_buffer(const union dlm= _packet *p, * current node->seq_next number as ack. */ if (seq < oval) - dlm_send_ack(node->nodeid, oval); + dlm_send_ack(node->dn, node->nodeid, oval); =20 log_print_ratelimited("ignore dlm msg because seq mismatch, seq: %u, exp= ected: %u, nodeid: %d", seq, oval, node->nodeid); @@ -654,15 +646,16 @@ static int dlm_opts_check_msglen(const union dlm_pack= et *p, uint16_t msglen, return 0; } =20 -static void dlm_midcomms_receive_buffer_3_2(const union dlm_packet *p, int= nodeid) +static void dlm_midcomms_receive_buffer_3_2(struct dlm_net *dn, + const union dlm_packet *p, int nodeid) { uint16_t msglen =3D le16_to_cpu(p->header.h_length); struct midcomms_node *node; uint32_t seq; int ret, idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (WARN_ON_ONCE(!node)) goto out; =20 @@ -718,7 +711,7 @@ static void dlm_midcomms_receive_buffer_3_2(const union= dlm_packet *p, int nodei } =20 WARN_ON_ONCE(test_bit(DLM_NODE_FLAG_STOP_RX, &node->flags)); - dlm_receive_buffer(p, nodeid); + dlm_receive_buffer(node->dn, p, nodeid); break; case DLM_OPTS: seq =3D le32_to_cpu(p->header.u.h_seq); @@ -779,19 +772,20 @@ static void dlm_midcomms_receive_buffer_3_2(const uni= on dlm_packet *p, int nodei } =20 out: - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); } =20 -static void dlm_midcomms_receive_buffer_3_1(const union dlm_packet *p, int= nodeid) +static void dlm_midcomms_receive_buffer_3_1(struct dlm_net *dn, const unio= n dlm_packet *p, + int nodeid) { uint16_t msglen =3D le16_to_cpu(p->header.h_length); struct midcomms_node *node; int idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (WARN_ON_ONCE(!node)) { - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -807,10 +801,10 @@ static void dlm_midcomms_receive_buffer_3_1(const uni= on dlm_packet *p, int nodei default: log_print_ratelimited("version mismatch detected, assumed 0x%08x but nod= e %d has 0x%08x", DLM_VERSION_3_1, node->nodeid, node->version); - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); =20 switch (p->header.h_cmd) { case DLM_RCOM: @@ -830,7 +824,7 @@ static void dlm_midcomms_receive_buffer_3_1(const union= dlm_packet *p, int nodei return; } =20 - dlm_receive_buffer(p, nodeid); + dlm_receive_buffer(dn, p, nodeid); } =20 int dlm_validate_incoming_buffer(int nodeid, unsigned char *buf, int len) @@ -880,7 +874,8 @@ int dlm_validate_incoming_buffer(int nodeid, unsigned c= har *buf, int len) * Called from the low-level comms layer to process a buffer of * commands. */ -int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int len) +int dlm_process_incoming_buffer(struct dlm_net *dn, int nodeid, + unsigned char *buf, int len) { const unsigned char *ptr =3D buf; const struct dlm_header *hd; @@ -896,10 +891,10 @@ int dlm_process_incoming_buffer(int nodeid, unsigned = char *buf, int len) =20 switch (hd->h_version) { case cpu_to_le32(DLM_VERSION_3_1): - dlm_midcomms_receive_buffer_3_1((const union dlm_packet *)ptr, nodeid); + dlm_midcomms_receive_buffer_3_1(dn, (const union dlm_packet *)ptr, node= id); break; case cpu_to_le32(DLM_VERSION_3_2): - dlm_midcomms_receive_buffer_3_2((const union dlm_packet *)ptr, nodeid); + dlm_midcomms_receive_buffer_3_2(dn, (const union dlm_packet *)ptr, node= id); break; default: log_print("received invalid version header: %u from node %d, will skip = this message", @@ -915,16 +910,16 @@ int dlm_process_incoming_buffer(int nodeid, unsigned = char *buf, int len) return ret; } =20 -void dlm_midcomms_unack_msg_resend(int nodeid) +void dlm_midcomms_unack_msg_resend(struct dlm_net *dn, int nodeid) { struct midcomms_node *node; struct dlm_mhandle *mh; int idx, ret; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (WARN_ON_ONCE(!node)) { - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -933,7 +928,7 @@ void dlm_midcomms_unack_msg_resend(int nodeid) case DLM_VERSION_3_2: break; default: - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -948,15 +943,15 @@ void dlm_midcomms_unack_msg_resend(int nodeid) mh->seq, node->nodeid); } rcu_read_unlock(); - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); } =20 -static void dlm_fill_opts_header(struct dlm_opts *opts, uint16_t inner_len, - uint32_t seq) +static void dlm_fill_opts_header(struct dlm_net *dn, struct dlm_opts *opts, + uint16_t inner_len, uint32_t seq) { opts->o_header.h_cmd =3D DLM_OPTS; opts->o_header.h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MI= NOR); - opts->o_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + opts->o_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid(dn)); opts->o_header.h_length =3D cpu_to_le16(DLM_MIDCOMMS_OPT_LEN + inner_len); opts->o_header.u.h_seq =3D cpu_to_le32(seq); } @@ -980,7 +975,8 @@ static struct dlm_msg *dlm_midcomms_get_msg_3_2(struct = dlm_mhandle *mh, int node struct dlm_opts *opts; struct dlm_msg *msg; =20 - msg =3D dlm_lowcomms_new_msg(nodeid, len + DLM_MIDCOMMS_OPT_LEN, + msg =3D dlm_lowcomms_new_msg(mh->node->dn, nodeid, + len + DLM_MIDCOMMS_OPT_LEN, ppc, midcomms_new_msg_cb, mh); if (!msg) return NULL; @@ -989,7 +985,7 @@ static struct dlm_msg *dlm_midcomms_get_msg_3_2(struct = dlm_mhandle *mh, int node mh->opts =3D opts; =20 /* add possible options here */ - dlm_fill_opts_header(opts, len, mh->seq); + dlm_fill_opts_header(mh->node->dn, opts, len, mh->seq); =20 *ppc +=3D sizeof(*opts); mh->inner_p =3D (const union dlm_packet *)*ppc; @@ -1000,15 +996,16 @@ static struct dlm_msg *dlm_midcomms_get_msg_3_2(stru= ct dlm_mhandle *mh, int node * dlm_midcomms_commit_mhandle which is a must call if success */ #ifndef __CHECKER__ -struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len, char **p= pc) +struct dlm_mhandle *dlm_midcomms_get_mhandle(struct dlm_net *dn, int nodei= d, + int len, char **ppc) { struct midcomms_node *node; struct dlm_mhandle *mh; struct dlm_msg *msg; int idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (WARN_ON_ONCE(!node)) goto err; =20 @@ -1026,7 +1023,7 @@ struct dlm_mhandle *dlm_midcomms_get_mhandle(int node= id, int len, char **ppc) =20 switch (node->version) { case DLM_VERSION_3_1: - msg =3D dlm_lowcomms_new_msg(nodeid, len, ppc, NULL, NULL); + msg =3D dlm_lowcomms_new_msg(dn, nodeid, len, ppc, NULL, NULL); if (!msg) { dlm_free_mhandle(mh); goto err; @@ -1059,7 +1056,7 @@ struct dlm_mhandle *dlm_midcomms_get_mhandle(int node= id, int len, char **ppc) return mh; =20 err: - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return NULL; } #endif @@ -1100,10 +1097,11 @@ static void dlm_midcomms_commit_msg_3_2(struct dlm_= mhandle *mh, void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh, const void *name, int namelen) { + struct dlm_net *dn =3D mh->node->dn; =20 switch (mh->node->version) { case DLM_VERSION_3_1: - srcu_read_unlock(&nodes_srcu, mh->idx); + srcu_read_unlock(&dn->nodes_srcu, mh->idx); =20 dlm_lowcomms_commit_msg(mh->msg); dlm_lowcomms_put_msg(mh->msg); @@ -1118,35 +1116,25 @@ void dlm_midcomms_commit_mhandle(struct dlm_mhandle= *mh, */ rcu_read_lock(); dlm_midcomms_commit_msg_3_2(mh, name, namelen); - srcu_read_unlock(&nodes_srcu, mh->idx); + srcu_read_unlock(&dn->nodes_srcu, mh->idx); rcu_read_unlock(); break; default: - srcu_read_unlock(&nodes_srcu, mh->idx); + srcu_read_unlock(&dn->nodes_srcu, mh->idx); WARN_ON_ONCE(1); break; } } #endif =20 -int dlm_midcomms_start(void) -{ - return dlm_lowcomms_start(); -} - -void dlm_midcomms_stop(void) +int dlm_midcomms_start(struct dlm_net *dn) { - dlm_lowcomms_stop(); + return dlm_lowcomms_start(dn); } =20 -void dlm_midcomms_init(void) +void dlm_midcomms_stop(struct dlm_net *dn) { - int i; - - for (i =3D 0; i < CONN_HASH_SIZE; i++) - INIT_HLIST_HEAD(&node_hash[i]); - - dlm_lowcomms_init(); + dlm_lowcomms_stop(dn); } =20 static void midcomms_node_release(struct rcu_head *rcu) @@ -1158,26 +1146,43 @@ static void midcomms_node_release(struct rcu_head *= rcu) kfree(node); } =20 -void dlm_midcomms_exit(void) +void __net_init dlm_midcomms_init(struct dlm_net *dn) +{ + int i; + + init_srcu_struct(&dn->nodes_srcu); + spin_lock_init(&dn->nodes_lock); + mutex_init(&dn->close_lock); + + for (i =3D 0; i < CONN_HASH_SIZE; i++) + INIT_HLIST_HEAD(&dn->node_hash[i]); + + dlm_lowcomms_init(dn); +} + +void __net_exit dlm_midcomms_exit(struct dlm_net *dn) { struct midcomms_node *node; int i, idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); + idx =3D srcu_read_lock(&dn->nodes_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(node, &node_hash[i], hlist) { - dlm_delete_debug_comms_file(node->debugfs); + hlist_for_each_entry_rcu(node, &dn->node_hash[i], hlist) { + dlm_delete_debug_comms_file(dn, node->debugfs); =20 - spin_lock(&nodes_lock); + spin_lock(&dn->nodes_lock); hlist_del_rcu(&node->hlist); - spin_unlock(&nodes_lock); + spin_unlock(&dn->nodes_lock); =20 - call_srcu(&nodes_srcu, &node->rcu, midcomms_node_release); + call_srcu(&dn->nodes_srcu, &node->rcu, midcomms_node_release); } } - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); + + srcu_barrier(&dn->nodes_srcu); + cleanup_srcu_struct(&dn->nodes_srcu); =20 - dlm_lowcomms_exit(); + dlm_lowcomms_exit(dn); } =20 static void dlm_act_fin_ack_rcv(struct midcomms_node *node) @@ -1211,15 +1216,15 @@ static void dlm_act_fin_ack_rcv(struct midcomms_nod= e *node) spin_unlock_bh(&node->state_lock); } =20 -void dlm_midcomms_add_member(int nodeid) +void dlm_midcomms_add_member(struct dlm_net *dn, int nodeid) { struct midcomms_node *node; int idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (WARN_ON_ONCE(!node)) { - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -1253,19 +1258,19 @@ void dlm_midcomms_add_member(int nodeid) pr_debug("node %d users inc count %d\n", nodeid, node->users); spin_unlock_bh(&node->state_lock); =20 - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); } =20 -void dlm_midcomms_remove_member(int nodeid) +void dlm_midcomms_remove_member(struct dlm_net *dn, int nodeid) { struct midcomms_node *node; int idx; =20 - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); /* in case of dlm_midcomms_close() removes node */ if (!node) { - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -1276,7 +1281,7 @@ void dlm_midcomms_remove_member(int nodeid) */ if (!node->users) { spin_unlock_bh(&node->state_lock); - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); return; } =20 @@ -1315,17 +1320,17 @@ void dlm_midcomms_remove_member(int nodeid) } spin_unlock_bh(&node->state_lock); =20 - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); } =20 -void dlm_midcomms_version_wait(void) +void dlm_midcomms_version_wait(struct dlm_net *dn) { struct midcomms_node *node; int i, idx, ret; =20 - idx =3D srcu_read_lock(&nodes_srcu); + idx =3D srcu_read_lock(&dn->nodes_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(node, &node_hash[i], hlist) { + hlist_for_each_entry_rcu(node, &dn->node_hash[i], hlist) { ret =3D wait_event_timeout(node->shutdown_wait, node->version !=3D DLM_VERSION_NOT_SET || node->state =3D=3D DLM_CLOSED || @@ -1336,7 +1341,7 @@ void dlm_midcomms_version_wait(void) node->nodeid, dlm_state_str(node->state)); } } - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); } =20 static void midcomms_shutdown(struct midcomms_node *node) @@ -1388,74 +1393,74 @@ static void midcomms_shutdown(struct midcomms_node = *node) node->nodeid, dlm_state_str(node->state)); } =20 -void dlm_midcomms_shutdown(void) +void dlm_midcomms_shutdown(struct dlm_net *dn) { struct midcomms_node *node; int i, idx; =20 - mutex_lock(&close_lock); - idx =3D srcu_read_lock(&nodes_srcu); + mutex_lock(&dn->close_lock); + idx =3D srcu_read_lock(&dn->nodes_srcu); for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(node, &node_hash[i], hlist) { + hlist_for_each_entry_rcu(node, &dn->node_hash[i], hlist) { midcomms_shutdown(node); } } =20 - dlm_lowcomms_shutdown(); + dlm_lowcomms_shutdown(dn); =20 for (i =3D 0; i < CONN_HASH_SIZE; i++) { - hlist_for_each_entry_rcu(node, &node_hash[i], hlist) { + hlist_for_each_entry_rcu(node, &dn->node_hash[i], hlist) { midcomms_node_reset(node); } } - srcu_read_unlock(&nodes_srcu, idx); - mutex_unlock(&close_lock); + srcu_read_unlock(&dn->nodes_srcu, idx); + mutex_unlock(&dn->close_lock); } =20 -int dlm_midcomms_close(int nodeid) +int dlm_midcomms_close(struct dlm_net *dn, int nodeid) { struct midcomms_node *node; int idx, ret; =20 - idx =3D srcu_read_lock(&nodes_srcu); + idx =3D srcu_read_lock(&dn->nodes_srcu); /* Abort pending close/remove operation */ - node =3D nodeid2node(nodeid); + node =3D nodeid2node(dn, nodeid); if (node) { /* let shutdown waiters leave */ set_bit(DLM_NODE_FLAG_CLOSE, &node->flags); wake_up(&node->shutdown_wait); } - srcu_read_unlock(&nodes_srcu, idx); + srcu_read_unlock(&dn->nodes_srcu, idx); =20 - synchronize_srcu(&nodes_srcu); + synchronize_srcu(&dn->nodes_srcu); =20 - mutex_lock(&close_lock); - idx =3D srcu_read_lock(&nodes_srcu); - node =3D nodeid2node(nodeid); + mutex_lock(&dn->close_lock); + idx =3D srcu_read_lock(&dn->nodes_srcu); + node =3D nodeid2node(dn, nodeid); if (!node) { - srcu_read_unlock(&nodes_srcu, idx); - mutex_unlock(&close_lock); - return dlm_lowcomms_close(nodeid); + srcu_read_unlock(&dn->nodes_srcu, idx); + mutex_unlock(&dn->close_lock); + return dlm_lowcomms_close(dn, nodeid); } =20 - ret =3D dlm_lowcomms_close(nodeid); - dlm_delete_debug_comms_file(node->debugfs); + ret =3D dlm_lowcomms_close(dn, nodeid); + dlm_delete_debug_comms_file(dn, node->debugfs); =20 - spin_lock_bh(&nodes_lock); + spin_lock_bh(&dn->nodes_lock); hlist_del_rcu(&node->hlist); - spin_unlock_bh(&nodes_lock); - srcu_read_unlock(&nodes_srcu, idx); + spin_unlock_bh(&dn->nodes_lock); + srcu_read_unlock(&dn->nodes_srcu, idx); =20 /* wait that all readers left until flush send queue */ - synchronize_srcu(&nodes_srcu); + synchronize_srcu(&dn->nodes_srcu); =20 /* drop all pending dlm messages, this is fine as * this function get called when the node is fenced */ dlm_send_queue_flush(node); =20 - call_srcu(&nodes_srcu, &node->rcu, midcomms_node_release); - mutex_unlock(&close_lock); + call_srcu(&dn->nodes_srcu, &node->rcu, midcomms_node_release); + mutex_unlock(&dn->close_lock); =20 return ret; } @@ -1497,7 +1502,7 @@ int dlm_midcomms_rawmsg_send(struct midcomms_node *no= de, void *buf, rd.node =3D node; rd.buf =3D buf; =20 - msg =3D dlm_lowcomms_new_msg(node->nodeid, buflen, &msgbuf, + msg =3D dlm_lowcomms_new_msg(node->dn, node->nodeid, buflen, &msgbuf, midcomms_new_rawmsg_cb, &rd); if (!msg) return -ENOMEM; diff --git a/fs/dlm/midcomms.h b/fs/dlm/midcomms.h index 7fad1d170bba..4abb8c4bb9fb 100644 --- a/fs/dlm/midcomms.h +++ b/fs/dlm/midcomms.h @@ -12,24 +12,29 @@ #ifndef __MIDCOMMS_DOT_H__ #define __MIDCOMMS_DOT_H__ =20 +#include "config.h" + struct midcomms_node; =20 int dlm_validate_incoming_buffer(int nodeid, unsigned char *buf, int len); -int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int buflen= ); -struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len, char **p= pc); +int dlm_process_incoming_buffer(struct dlm_net *dn, int nodeid, + unsigned char *buf, int len); +struct dlm_mhandle *dlm_midcomms_get_mhandle(struct dlm_net *dn, int nodei= d, + int len, char **ppc); void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh, const void *name, int namelen); -int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr); -void dlm_midcomms_version_wait(void); -int dlm_midcomms_close(int nodeid); -int dlm_midcomms_start(void); -void dlm_midcomms_stop(void); -void dlm_midcomms_init(void); -void dlm_midcomms_exit(void); -void dlm_midcomms_shutdown(void); -void dlm_midcomms_add_member(int nodeid); -void dlm_midcomms_remove_member(int nodeid); -void dlm_midcomms_unack_msg_resend(int nodeid); +int dlm_midcomms_addr(struct dlm_net *dn, int nodeid, + struct sockaddr_storage *addr); +void dlm_midcomms_version_wait(struct dlm_net *dn); +int dlm_midcomms_close(struct dlm_net *dn, int nodeid); +int dlm_midcomms_start(struct dlm_net *dn); +void dlm_midcomms_init(struct dlm_net *dn); +void dlm_midcomms_exit(struct dlm_net *dn); +void dlm_midcomms_stop(struct dlm_net *dn); +void dlm_midcomms_shutdown(struct dlm_net *dn); +void dlm_midcomms_add_member(struct dlm_net *dn, int nodeid); +void dlm_midcomms_remove_member(struct dlm_net *dn, int nodeid); +void dlm_midcomms_unack_msg_resend(struct dlm_net *dn, int nodeid); const char *dlm_midcomms_state(struct midcomms_node *node); unsigned long dlm_midcomms_flags(struct midcomms_node *node); int dlm_midcomms_send_queue_cnt(struct midcomms_node *node); diff --git a/fs/dlm/plock.c b/fs/dlm/plock.c index 9ca83ef70ed1..b16d5277bb1e 100644 --- a/fs/dlm/plock.c +++ b/fs/dlm/plock.c @@ -463,7 +463,7 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 numbe= r, struct file *file, fl->c.flc_type =3D (op->info.ex) ? F_WRLCK : F_RDLCK; fl->c.flc_flags =3D FL_POSIX; fl->c.flc_pid =3D op->info.pid; - if (op->info.nodeid !=3D dlm_our_nodeid()) + if (op->info.nodeid !=3D dlm_our_nodeid(ls->ls_dn)) fl->c.flc_pid =3D -fl->c.flc_pid; fl->fl_start =3D op->info.start; fl->fl_end =3D op->info.end; diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index be1a71a6303a..3b7c44375f23 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c @@ -37,7 +37,7 @@ static void _create_rcom(struct dlm_ls *ls, int to_nodeid= , int type, int len, =20 rc->rc_header.h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MIN= OR); rc->rc_header.u.h_lockspace =3D cpu_to_le32(ls->ls_global_id); - rc->rc_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + rc->rc_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid(ls->ls_dn)); rc->rc_header.h_length =3D cpu_to_le16(mb_len); rc->rc_header.h_cmd =3D DLM_RCOM; =20 @@ -55,7 +55,7 @@ static int create_rcom(struct dlm_ls *ls, int to_nodeid, = int type, int len, struct dlm_mhandle *mh; char *mb; =20 - mh =3D dlm_midcomms_get_mhandle(to_nodeid, mb_len, &mb); + mh =3D dlm_midcomms_get_mhandle(ls->ls_dn, to_nodeid, mb_len, &mb); if (!mh) { log_print("%s to %d type %d len %d ENOBUFS", __func__, to_nodeid, type, len); @@ -75,7 +75,8 @@ static int create_rcom_stateless(struct dlm_ls *ls, int t= o_nodeid, int type, struct dlm_msg *msg; char *mb; =20 - msg =3D dlm_lowcomms_new_msg(to_nodeid, mb_len, &mb, NULL, NULL); + msg =3D dlm_lowcomms_new_msg(ls->ls_dn, to_nodeid, mb_len, &mb, NULL, + NULL); if (!msg) { log_print("create_rcom to %d type %d len %d ENOBUFS", to_nodeid, type, len); @@ -177,7 +178,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint= 32_t status_flags, =20 ls->ls_recover_nodeid =3D nodeid; =20 - if (nodeid =3D=3D dlm_our_nodeid()) { + if (nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) { rc =3D ls->ls_recover_buf; rc->rc_result =3D cpu_to_le32(dlm_recover_status(ls)); goto out; @@ -501,7 +502,8 @@ static void receive_rcom_lock(struct dlm_ls *ls, const = struct dlm_rcom *rc_in, /* If the lockspace doesn't exist then still send a status message back; it's possible that it just doesn't have its global_id yet. */ =20 -int dlm_send_ls_not_ready(int nodeid, const struct dlm_rcom *rc_in) +int dlm_send_ls_not_ready(struct dlm_net *dn, int nodeid, + const struct dlm_rcom *rc_in) { struct dlm_rcom *rc; struct rcom_config *rf; @@ -509,7 +511,7 @@ int dlm_send_ls_not_ready(int nodeid, const struct dlm_= rcom *rc_in) char *mb; int mb_len =3D sizeof(struct dlm_rcom) + sizeof(struct rcom_config); =20 - mh =3D dlm_midcomms_get_mhandle(nodeid, mb_len, &mb); + mh =3D dlm_midcomms_get_mhandle(dn, nodeid, mb_len, &mb); if (!mh) return -ENOBUFS; =20 @@ -517,7 +519,7 @@ int dlm_send_ls_not_ready(int nodeid, const struct dlm_= rcom *rc_in) =20 rc->rc_header.h_version =3D cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MIN= OR); rc->rc_header.u.h_lockspace =3D rc_in->rc_header.u.h_lockspace; - rc->rc_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid()); + rc->rc_header.h_nodeid =3D cpu_to_le32(dlm_our_nodeid(dn)); rc->rc_header.h_length =3D cpu_to_le16(mb_len); rc->rc_header.h_cmd =3D DLM_RCOM; =20 diff --git a/fs/dlm/rcom.h b/fs/dlm/rcom.h index 765926ae0020..8b1d7418b335 100644 --- a/fs/dlm/rcom.h +++ b/fs/dlm/rcom.h @@ -20,7 +20,8 @@ int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodei= d, uint64_t seq); int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb, uint64_t se= q); void dlm_receive_rcom(struct dlm_ls *ls, const struct dlm_rcom *rc, int nodeid); -int dlm_send_ls_not_ready(int nodeid, const struct dlm_rcom *rc_in); +int dlm_send_ls_not_ready(struct dlm_net *dn, int nodeid, + const struct dlm_rcom *rc_in); =20 #endif =20 diff --git a/fs/dlm/recover.c b/fs/dlm/recover.c index 2e1169c81c6e..9c5849556bff 100644 --- a/fs/dlm/recover.c +++ b/fs/dlm/recover.c @@ -47,7 +47,7 @@ int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (s= truct dlm_ls *ls)) while (1) { rv =3D wait_event_timeout(ls->ls_wait_general, testfn(ls) || dlm_recovery_stopped(ls), - dlm_config.ci_recover_timer * HZ); + ls->ls_dn->config.ci_recover_timer * HZ); if (rv) break; if (test_bit(LSFL_RCOM_WAIT, &ls->ls_flags)) { @@ -156,7 +156,7 @@ static int wait_status(struct dlm_ls *ls, uint32_t stat= us, uint64_t seq) uint32_t status_all =3D status << 1; int error; =20 - if (ls->ls_low_nodeid =3D=3D dlm_our_nodeid()) { + if (ls->ls_low_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) { error =3D wait_status_all(ls, status, 0, seq); if (!error) dlm_set_recover_status(ls, status_all); @@ -179,7 +179,7 @@ int dlm_recover_members_wait(struct dlm_ls *ls, uint64_= t seq) memb->generation =3D 0; } =20 - if (ls->ls_low_nodeid =3D=3D dlm_our_nodeid()) { + if (ls->ls_low_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) { error =3D wait_status_all(ls, DLM_RS_NODES, 1, seq); if (error) goto out; @@ -461,7 +461,7 @@ static int recover_master(struct dlm_rsb *r, unsigned i= nt *count, uint64_t seq) if (!is_removed && !rsb_flag(r, RSB_NEW_MASTER)) return 0; =20 - our_nodeid =3D dlm_our_nodeid(); + our_nodeid =3D dlm_our_nodeid(ls->ls_dn); dir_nodeid =3D dlm_dir_nodeid(r); =20 if (dir_nodeid =3D=3D our_nodeid) { @@ -499,12 +499,13 @@ static int recover_master(struct dlm_rsb *r, unsigned= int *count, uint64_t seq) * resent. */ =20 -static int recover_master_static(struct dlm_rsb *r, unsigned int *count) +static int recover_master_static(struct dlm_ls *ls, struct dlm_rsb *r, + unsigned int *count) { int dir_nodeid =3D dlm_dir_nodeid(r); int new_master =3D dir_nodeid; =20 - if (dir_nodeid =3D=3D dlm_our_nodeid()) + if (dir_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) new_master =3D 0; =20 dlm_purge_mstcpy_locks(r); @@ -544,7 +545,7 @@ int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq, =20 lock_rsb(r); if (nodir) - error =3D recover_master_static(r, &count); + error =3D recover_master_static(ls, r, &count); else error =3D recover_master(r, &count, seq); unlock_rsb(r); @@ -578,7 +579,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const s= truct dlm_rcom *rc) =20 ret_nodeid =3D le32_to_cpu(rc->rc_result); =20 - if (ret_nodeid =3D=3D dlm_our_nodeid()) + if (ret_nodeid =3D=3D dlm_our_nodeid(ls->ls_dn)) new_master =3D 0; else new_master =3D ret_nodeid; diff --git a/fs/dlm/user.c b/fs/dlm/user.c index 5cb3896be826..1b682f8f95b6 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c @@ -4,6 +4,7 @@ */ =20 #include +#include #include #include #include @@ -29,8 +30,6 @@ =20 static const char name_prefix[] =3D "dlm"; static const struct file_operations device_fops; -static atomic_t dlm_monitor_opened; -static int dlm_monitor_unused =3D 1; =20 #ifdef CONFIG_COMPAT =20 @@ -345,6 +344,12 @@ static int dlm_device_register(struct dlm_ls *ls, char= *name) { int error, len; =20 + /* user lock device created for init_net where it is supported + * for now. + */ + if (!net_eq(read_pnet(&ls->ls_dn->net), &init_net)) + return 0; + /* The device is already registered. This happens when the lockspace is created multiple times from userspace. */ if (ls->ls_device.name) @@ -381,6 +386,12 @@ int dlm_device_deregister(struct dlm_ls *ls) if (!ls->ls_device.name) return 0; =20 + /* user lock device created for init_net where it is supported + * for now. Lets warn if for some reason lockspace switched its + * ns during lifetime which is currently not supported either. + */ + WARN_ON(!net_eq(read_pnet(&ls->ls_dn->net), &init_net)); + misc_deregister(&ls->ls_device); kfree(ls->ls_device.name); return 0; @@ -402,7 +413,8 @@ static int device_user_purge(struct dlm_user_proc *proc, return error; } =20 -static int device_create_lockspace(struct dlm_lspace_params *params) +static int device_create_lockspace(struct dlm_net *dn, + struct dlm_lspace_params *params) { dlm_lockspace_t *lockspace; struct dlm_ls *ls; @@ -411,7 +423,7 @@ static int device_create_lockspace(struct dlm_lspace_pa= rams *params) if (!capable(CAP_SYS_ADMIN)) return -EPERM; =20 - error =3D dlm_new_user_lockspace(params->name, dlm_config.ci_cluster_name, + error =3D dlm_new_user_lockspace(dn, params->name, dn->config.ci_cluster_= name, params->flags, DLM_USER_LVB_LEN, NULL, NULL, NULL, &lockspace); if (error) @@ -432,7 +444,8 @@ static int device_create_lockspace(struct dlm_lspace_pa= rams *params) return error; } =20 -static int device_remove_lockspace(struct dlm_lspace_params *params) +static int device_remove_lockspace(struct dlm_net *dn, + struct dlm_lspace_params *params) { dlm_lockspace_t *lockspace; struct dlm_ls *ls; @@ -441,7 +454,7 @@ static int device_remove_lockspace(struct dlm_lspace_pa= rams *params) if (!capable(CAP_SYS_ADMIN)) return -EPERM; =20 - ls =3D dlm_find_lockspace_device(params->minor); + ls =3D dlm_find_lockspace_device(dn, params->minor); if (!ls) return -ENOENT; =20 @@ -511,6 +524,7 @@ static ssize_t device_write(struct file *file, const ch= ar __user *buf, size_t count, loff_t *ppos) { struct dlm_user_proc *proc =3D file->private_data; + struct dlm_net *dn =3D dlm_pernet(&init_net); struct dlm_write_request *kbuf; int error; =20 @@ -603,7 +617,7 @@ static ssize_t device_write(struct file *file, const ch= ar __user *buf, log_print("create/remove only on control device"); goto out_free; } - error =3D device_create_lockspace(&kbuf->i.lspace); + error =3D device_create_lockspace(dn, &kbuf->i.lspace); break; =20 case DLM_USER_REMOVE_LOCKSPACE: @@ -611,7 +625,7 @@ static ssize_t device_write(struct file *file, const ch= ar __user *buf, log_print("create/remove only on control device"); goto out_free; } - error =3D device_remove_lockspace(&kbuf->i.lspace); + error =3D device_remove_lockspace(dn, &kbuf->i.lspace); break; =20 case DLM_USER_PURGE: @@ -638,10 +652,18 @@ static ssize_t device_write(struct file *file, const = char __user *buf, =20 static int device_open(struct inode *inode, struct file *file) { + struct net *net =3D current->nsproxy->net_ns; + struct dlm_net *dn =3D dlm_pernet(&init_net); struct dlm_user_proc *proc; struct dlm_ls *ls; =20 - ls =3D dlm_find_lockspace_device(iminor(inode)); + /* Allow open() only on processes for init namespace for now. + * Everything else is not supported. Do deal with this UAPI. + */ + if (!net_eq(net, &init_net)) + return -EOPNOTSUPP; + + ls =3D dlm_find_lockspace_device(dn, iminor(inode)); if (!ls) return -ENOENT; =20 @@ -877,12 +899,12 @@ static __poll_t device_poll(struct file *file, poll_t= able *wait) return 0; } =20 -int dlm_user_daemon_available(void) +int dlm_user_daemon_available(struct dlm_net *dn) { /* dlm_controld hasn't started (or, has started, but not properly populated configfs) */ =20 - if (!dlm_our_nodeid()) + if (!dlm_our_nodeid(dn)) return 0; =20 /* This is to deal with versions of dlm_controld that don't @@ -891,10 +913,10 @@ int dlm_user_daemon_available(void) was never opened, that it's an old version. dlm_controld should open the monitor device before populating configfs. */ =20 - if (dlm_monitor_unused) + if (dn->dlm_monitor_unused) return 1; =20 - return atomic_read(&dlm_monitor_opened) ? 1 : 0; + return atomic_read(&dn->dlm_monitor_opened) ? 1 : 0; } =20 static int ctl_device_open(struct inode *inode, struct file *file) @@ -910,15 +932,20 @@ static int ctl_device_close(struct inode *inode, stru= ct file *file) =20 static int monitor_device_open(struct inode *inode, struct file *file) { - atomic_inc(&dlm_monitor_opened); - dlm_monitor_unused =3D 0; + struct dlm_net *dn =3D dlm_pernet(&init_net); + + atomic_inc(&dn->dlm_monitor_opened); + dn->dlm_monitor_unused =3D 0; return 0; } =20 static int monitor_device_close(struct inode *inode, struct file *file) { - if (atomic_dec_and_test(&dlm_monitor_opened)) - dlm_stop_lockspaces(); + struct dlm_net *dn =3D dlm_pernet(&init_net); + + if (atomic_dec_and_test(&dn->dlm_monitor_opened)) + dlm_stop_lockspaces(dn); + return 0; } =20 @@ -964,8 +991,6 @@ int __init dlm_user_init(void) { int error; =20 - atomic_set(&dlm_monitor_opened, 0); - error =3D misc_register(&ctl_device); if (error) { log_print("misc_register failed for control device"); diff --git a/fs/dlm/user.h b/fs/dlm/user.h index 2caf8e6e24d5..eac33bbe99b1 100644 --- a/fs/dlm/user.h +++ b/fs/dlm/user.h @@ -12,6 +12,6 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags= , int mode, int dlm_user_init(void); void dlm_user_exit(void); int dlm_device_deregister(struct dlm_ls *ls); -int dlm_user_daemon_available(void); +int dlm_user_daemon_available(struct dlm_net *dn); =20 #endif --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 36EE51A2544 for ; Mon, 30 Sep 2024 20:14:42 +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=1727727288; cv=none; b=Z1YN0ohd0J+86Bd+pqCWjyB6iwl6p/Lv9qQAO30Y3DFqrmtkzA8bppfKzTWYKhcxGC23YTOa8KIkfnHnL9zQLceA8abGg/6LvUbuFM/a99wXZeSHlCzWE0a+D0EdYD+oP1EVCufhzf8kfYYRb7f9oIfNYAk0jGfjWkB8Wwsluhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727288; c=relaxed/simple; bh=1jE5oUaDG/OvdlEeec63v9ZoHhssdsyCdyKnNzoQbds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CMMMFg2aCxEI+5LKEXHv4ogz4ZQc+rftQmI0K9FeRjCuLb2LmZGaUzobrSEE/OqUJLae8sWu20BuyY16kEkG/Vrjz8chzB0DgabwTVpAuh9J9DZerK2EJtmDRoL0DL4sv2baywxDXwviUvX/4Vk2Ivoho9nwVSQ3linCV5wg9uQ= 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=V1pf8nAO; 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="V1pf8nAO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727281; 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=NRSRahG3IG9A9JgT9uy7YQ6vZUBhoEN9i1/SLgSLL6I=; b=V1pf8nAOB0WxTcdrZA+cYgupuJRT8Cl/Kkpp+gMebmNCpKp2OveN6/++PIPxEGWfICR59c Gj2YzeURkUV2uDoN2m8eR88t7HfE0EvLJZOwvKWamYCJ4DSOa0rRD9JbRtcBccy2pJSel3 r5Q4rDgV91vgMv0oA+8bkA4B8EvQJUk= 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-460-kdRcXKM4PrKkE7Ao9VcUaA-1; Mon, 30 Sep 2024 16:14:37 -0400 X-MC-Unique: kdRcXKM4PrKkE7Ao9VcUaA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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 63406196A401; Mon, 30 Sep 2024 20:14:35 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F25AD1955DC7; Mon, 30 Sep 2024 20:14:32 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 11/12] dlm: add nldlm net-namespace aware UAPI Date: Mon, 30 Sep 2024 16:13:57 -0400 Message-ID: <20240930201358.2638665-12-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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" Recent patches introduced support to separate DLM lockspaces on a per net-namespace basis. Currently the file based configfs mechanism is used to configure parts of DLM. Due the lack of namespace awareness (and it's probably complicated to add support for this) in configfs we introduce a socket based UAPI using "netlink". As the DLM subsystem offers now a config layer it can simultaneously being used with configfs, just that nldlm is net-namespace aware. Most of the current configfs functionality that is necessary to configure DLM is being adapted for now. The nldlm netlink interface offers also a multicast group for lockspace events NLDLM_MCGRP_EVENT. This event group can be used as alternative to the already existing udev event behaviour just it only contains DLM related subsystem events. Attributes e.g. nodeid, port, IP addresses are expected from the user space to fill those numbers as they appear on the wire. In case of DLM fields it is using little endian byte order. The dumps are being designed to scale in future with high numbers of members in a lockspace. E.g. dump members require an unique lockspace identifier (currently only the name) and nldlm is using a netlink dump behaviour to be prepared if all entries may not fit into one netlink message. Signed-off-by: Alexander Aring --- Documentation/netlink/specs/nldlm.yaml | 438 ++++++++ fs/dlm/Makefile | 2 + fs/dlm/config.c | 20 +- fs/dlm/dlm_internal.h | 4 + fs/dlm/lockspace.c | 13 +- fs/dlm/netlink2.c | 1330 ++++++++++++++++++++++++ fs/dlm/nldlm-kernel.c | 290 ++++++ fs/dlm/nldlm-kernel.h | 50 + fs/dlm/nldlm.c | 847 +++++++++++++++ include/uapi/linux/nldlm.h | 153 +++ 10 files changed, 3141 insertions(+), 6 deletions(-) create mode 100644 Documentation/netlink/specs/nldlm.yaml create mode 100644 fs/dlm/netlink2.c create mode 100644 fs/dlm/nldlm-kernel.c create mode 100644 fs/dlm/nldlm-kernel.h create mode 100644 fs/dlm/nldlm.c create mode 100644 include/uapi/linux/nldlm.h diff --git a/Documentation/netlink/specs/nldlm.yaml b/Documentation/netlink= /specs/nldlm.yaml new file mode 100644 index 000000000000..8c32815c0391 --- /dev/null +++ b/Documentation/netlink/specs/nldlm.yaml @@ -0,0 +1,438 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cla= use) + +name: nldlm +protocol: genetlink +doc: DLM subsystem. + +definitions: + - + type: enum + name: protocol + doc: | + The transport layer protocol that DLM will use. + entries: + - + name: TCP + - + name: SCTP + - + type: enum + name: log-level + doc: | + The internal DLM logger log-level. + entries: + - + name: NONE + doc: disable all DLM logging + - + name: INFO + doc: enable INFO log-level only + - + name: DEBUG + doc: enable INFO and DEBUG log-level + - + type: enum + name: ls-ctrl-action + doc: | + The lockspace control actions. Use in combination with + ls-add-member and ls-del-member. First stop lockspace + then update the members, then start the lockspace to + trigger recovery with new membership updates. + entries: + - + name: STOP + doc: stopping the lockspace + - + name: START + doc: starting the lockspace + - + type: enum + name: ls-event-result + doc: | + The result op of the lockspace event ntf-new-ls and + ntf-release-ls. The kernel is waiting for this reply + when those events occur. + entries: + - + name: SUCCESS + doc: the DLM kernel lockspace event action was successful + - + name: FAILURE + doc: the DLM kernel lockspace event action failed + +attribute-sets: + - + name: cfg + attributes: + - + name: our-nodeid + type: u32 + byte-order: little-endian + - + name: cluster-name + type: string + - + name: protocol + type: u32 + - + name: port + type: u16 + byte-order: big-endian + - + name: recover-timeout + type: u32 + - + name: inactive-timeout + type: u32 + - + name: log-level + type: u32 + - + name: default-mark + type: u32 + - + name: recover-callbacks + type: flag + - + name: ls + attributes: + - + name: name + type: string + - + name: ls-member + attributes: + - + name: ls-name + type: string + - + name: nodeid + type: u32 + byte-order: little-endian + - + name: weight + type: u32 + - + name: ls-ctrl + attributes: + - + name: ls-name + type: string + - + name: action + type: u32 + - + name: ls-event-result + attributes: + - + name: ls-name + type: string + - + name: ls-global-id + type: u32 + byte-order: little-endian + - + name: result + type: u32 + - + name: node + attributes: + - + name: id + type: u32 + byte-order: little-endian + - + name: mark + type: u32 + - + name: addrs + type: nest + nested-attributes: addr + multi-attr: true + - + name: addr + attributes: + - + name: family + type: u16 + - + name: addr4 + type: u32 + byte-order: big-endian + display-hint: ipv4 + - + name: addr6 + type: binary + display-hint: ipv6 + checks: + exact-len: 16 + +operations: + list: + - + name: get-node + doc: | + get DLM node information from the kernel configuration. + attribute-set: node + do: + request: + attributes: + - id + reply: + attributes: + - id + - mark + - addrs + dump: + reply: + attributes: + - id + - mark + - addrs + - + name: add-node + doc: | + add a new DLM node to the kernel configuration. + attribute-set: node + flags: [ admin-perm ] + do: + request: + attributes: + - id + - mark + - addrs + - + name: del-node + doc: | + delete a DLM node from the kernel configuration. + attribute-set: node + flags: [ admin-perm ] + do: + request: + attributes: + - id + - + name: get-ls + doc: | + get registered DLM lockspace information. + attribute-set: ls + do: + request: + attributes: + - name + reply: + attributes: + - name + dump: + reply: + attributes: + - name + - + name: get-ls-member + doc: | + get members information from a registered DLM lockspace. + attribute-set: ls-member + flags: [ admin-perm ] + do: + request: + attributes: + - ls-name + - nodeid + reply: + attributes: + - ls-name + - nodeid + - weight + dump: + request: + attributes: + - ls-name + reply: + attributes: + - ls-name + - nodeid + - weight + - + name: ls-add-member + doc: | + add a member to a specific registered lockspace. Should be used + when the lockspaces is stopped. + attribute-set: ls-member + flags: [ admin-perm ] + do: + request: + attributes: + - ls-name + - nodeid + - weight + - + name: ls-del-member + doc: | + delete a member to a specific registered lockspace. Should be used + when the lockspaces is stopped. + attribute-set: ls-member + flags: [ admin-perm ] + do: + request: + attributes: + - ls-name + - nodeid + - + name: ls-ctrl + doc: | + do lockspace control actions like stop and start lockspace for + membership updates. + attribute-set: ls-ctrl + flags: [ admin-perm ] + do: + request: + attributes: + - ls-name + - action + - + name: ntf-new-ls + doc: | + notify that the kernel is creating a new lockspace and the user + space need to ackknowledge and set a cluster-wide global-id with + ls-event-done. + notify: get-ls + mcgrp: ls-event + - + name: ntf-release-ls + doc: | + notify that the kernel is releasing registered lockspace. + notify: get-ls + mcgrp: ls-event + - + name: ls-event-done + doc: | + send back the result from the user space of the ntf-new-ls or + ntf-release-ls ls-event. The user space can decide to accept + or reject the lockspace creation. Sending the result back requires + to tell the DLM lockspace the cluster-wide unique global-id. + attribute-set: ls-event-result + flags: [ admin-perm ] + do: + request: + attributes: + - ls-name + - ls-global-id + - result + - + name: get-cfg + doc: | + get the current DLM kernel configuration attributes. + attribute-set: cfg + do: + reply: + attributes: + - our-nodeid + - cluster-name + - protocol + - port + - recover-timeout + - inactive-timeout + - log-level + - default-mark + - recover-callbacks + - + name: set-our-nodeid + doc: | + set our nodeid. The node need to be part of the DLM registered + nodes. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - our-nodeid + - + name: set-cluster-name + doc: | + set the DLM cluster name. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - cluster-name + - + name: set-protocol + doc: | + set the DLM used transportation protocol. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - protocol + - + name: set-port + doc: | + set the DLM port to listen for the used transportation protocol. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - port + - + name: set-recover-timeout + doc: | + The DLM recovery has some wait events that requires other nodes + to answer in a time. This is the timeout value how long DLM + should wait until giving up in the DLM recovery routines. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - recover-timeout + - + name: set-inactive-timeout + doc: | + DLM lock resources are keeping in memory if not being used inside + the lockspace anymore to fast reactivate them if they get used aft= er + a certain timeout that can be specified here. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - inactive-timeout + - + name: set-log-level + doc: | + set the DLM kernel logging level. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - log-level + - + name: set-default-mark + doc: | + set the default skb mark value for DLM sockets. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - default-mark + - + name: set-recover-callbacks + doc: | + set feature for recover callbacks that is required for some kernel + DLM users. + attribute-set: cfg + flags: [ admin-perm ] + do: + request: + attributes: + - recover-callbacks + +mcast-groups: + list: + - + name: ls-event diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile index c37f9fc361c6..05cd2fca2b1e 100644 --- a/fs/dlm/Makefile +++ b/fs/dlm/Makefile @@ -11,6 +11,8 @@ dlm-y :=3D ast.o \ memory.o \ midcomms.o \ lowcomms.o \ + nldlm.o \ + nldlm-kernel.o \ plock.o \ rcom.o \ recover.o \ diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 93d10b9e7483..bb7e2f9b6db8 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -91,11 +91,21 @@ int __init dlm_config_init(void) if (rv) return rv; =20 + rv =3D dlm_nldlm_init(); + if (rv) + goto err; + rv =3D dlm_configfs_init(); - if (rv) { - unregister_pernet_subsys(&dlm_net_ops); - dlm_net_id =3D 0; - } + if (rv) + goto err_nldlm; + + return rv; + +err_nldlm: + dlm_nldlm_exit(); +err: + unregister_pernet_subsys(&dlm_net_ops); + dlm_net_id =3D 0; =20 return rv; } @@ -103,6 +113,8 @@ int __init dlm_config_init(void) void dlm_config_exit(void) { dlm_configfs_exit(); + dlm_nldlm_exit(); + unregister_pernet_subsys(&dlm_net_ops); dlm_net_id =3D 0; } diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 10fe3b59bd70..c1f85c9a6e77 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -813,6 +813,10 @@ extern struct workqueue_struct *dlm_wq; int dlm_plock_init(void); void dlm_plock_exit(void); =20 +int nldlm_ls_event(const struct dlm_ls *ls, uint32_t cmd); +int __init dlm_nldlm_init(void); +void dlm_nldlm_exit(void); + #ifdef CONFIG_DLM_DEBUG void dlm_register_debugfs(void); void dlm_unregister_debugfs(void); diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index e5eeb3957b89..862d32774100 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -9,6 +9,7 @@ **************************************************************************= ***** **************************************************************************= ****/ =20 +#include #include #include =20 @@ -205,10 +206,18 @@ static const struct kobj_type dlm_kset_ktype =3D { =20 static int do_uevent(struct dlm_ls *ls, int in) { - if (in) + int rv; + + if (in) { kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE); - else + rv =3D nldlm_ls_event(ls, NLDLM_CMD_NTF_NEW_LS); + } else { kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE); + rv =3D nldlm_ls_event(ls, NLDLM_CMD_NTF_RELEASE_LS); + } + + /* ignore if nldlm_ls_event() has no subscribers */ + WARN_ON(rv && rv !=3D -ESRCH); =20 log_rinfo(ls, "%s the lockspace group...", in ? "joining" : "leaving"); =20 diff --git a/fs/dlm/netlink2.c b/fs/dlm/netlink2.c new file mode 100644 index 000000000000..556a7b87db89 --- /dev/null +++ b/fs/dlm/netlink2.c @@ -0,0 +1,1330 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "dlm_internal.h" +#include "lockspace.h" +#include "midcomms.h" +#include "config.h" +#include "member.h" +#include "lock.h" + +#include "nldlm.h" + +/* nldlm netlink family */ +static struct genl_family nldlm_genl_family; + +enum nldlm_multicast_groups { + NLDLM_MCGRP_CONFIG, + NLDLM_MCGRP_EVENT, +}; + +static const struct genl_multicast_group nldlm_mcgrps[] =3D { + [NLDLM_MCGRP_CONFIG] =3D { .name =3D "config", }, + [NLDLM_MCGRP_EVENT] =3D { .name =3D "event", }, +}; + +static int nldlm_put_ls(struct sk_buff *skb, const char *lsname, + int attrtype) +{ + struct nlattr *nl_ls; + int rv; + + nl_ls =3D nla_nest_start(skb, attrtype); + if (!nl_ls) + return -ENOBUFS; + + rv =3D nla_put_string(skb, NLDLM_LS_ATTR_NAME, lsname); + if (rv < 0) { + nla_nest_cancel(skb, nl_ls); + return rv; + } + + nla_nest_end(skb, nl_ls); + return 0; +} + +static int nldlm_put_ls_event(struct sk_buff *skb, const struct dlm_ls *ls, + u32 portid, u32 seq, int flags, uint32_t cmd, + uint32_t type) +{ + struct nlattr *nl_event; + void *hdr; + int rv; + + hdr =3D genlmsg_put(skb, 0, 0, &nldlm_genl_family, 0, cmd); + if (!hdr) + return -ENOBUFS; + + nl_event =3D nla_nest_start(skb, NLDLM_ATTR_LS_EVENT); + if (!nl_event) + return -ENOBUFS; + + rv =3D nldlm_put_ls(skb, ls->ls_name, NLDLM_LS_EVENT_ATTR_LS); + if (rv < 0) { + nla_nest_cancel(skb, nl_event); + goto err; + } + + rv =3D nla_put_u32(skb, NLDLM_LS_EVENT_ATTR_TYPE, type); + if (rv) { + nla_nest_cancel(skb, nl_event); + goto err; + } + + nla_nest_end(skb, nl_event); + genlmsg_end(skb, hdr); + return 0; + +err: + genlmsg_cancel(skb, hdr); + return -ENOBUFS; +} + +int nldlm_ls_event(const struct dlm_ls *ls, uint32_t type) +{ + struct sk_buff *skb; + int rv; + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) + return -ENOMEM; + + rv =3D nldlm_put_ls_event(skb, ls, 0, 0, 0, NLDLM_CMD_LS_EVENT, type); + if (rv < 0) { + nlmsg_free(skb); + return rv; + } + + return genlmsg_multicast_netns(&nldlm_genl_family, read_pnet(&ls->ls_dn->= net), skb, 0, + NLDLM_MCGRP_EVENT, GFP_ATOMIC); +} + +static const struct nla_policy nldlm_ls_policy[NLDLM_LS_ATTR_MAX + 1] =3D { + [NLDLM_LS_ATTR_NAME] =3D { .type =3D NLA_NUL_STRING }, +}; + +static int nldlm_parse_ls(const struct nlattr *nla, char *lsname) +{ + struct nlattr *ls_attrs[NLDLM_LS_ATTR_MAX + 1]; + + if (!nla) + return -EINVAL; + + if (nla_parse_nested(ls_attrs, NLDLM_LS_ATTR_MAX, nla, + nldlm_ls_policy, NULL)) + return -EINVAL; + + if (lsname) { + if (!ls_attrs[NLDLM_LS_ATTR_NAME]) + return -EINVAL; + + nla_strscpy(lsname, ls_attrs[NLDLM_LS_ATTR_NAME], + DLM_LOCKSPACE_LEN); + } + + return 0; +} + +static int __nldlm_get_ls(struct sk_buff *skb, struct dlm_cfg_ls *ls, + u32 portid, u32 seq, struct netlink_callback *cb, + int flags) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(skb, portid, seq, &nldlm_genl_family, flags, + NLDLM_CMD_GET_LS); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nldlm_put_ls(skb, ls->name, NLDLM_ATTR_LS); + if (rv < 0) + goto err; + + genlmsg_end(skb, hdr); + return 0; + +err: + genlmsg_cancel(skb, hdr); + return rv; +} + +static int nldlm_dump_ls(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + struct dlm_cfg_ls *ls; + int rv; + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(ls, &dn->lockspaces, list) { + if (ls->idx < idx) + continue; + + rv =3D __nldlm_get_ls(skb, ls, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D ls->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +static int nldlm_get_ls(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct dlm_cfg_ls *ls =3D NULL, *ls_iter; + char lsname[DLM_LOCKSPACE_LEN]; + struct sk_buff *skb; + int rv; + + rv =3D nldlm_parse_ls(info->attrs[NLDLM_ATTR_LS], lsname); + if (rv < 0) + return rv; + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(ls_iter, &dn->lockspaces, list) { + if (!strncmp(ls_iter->name, lsname, DLM_LOCKSPACE_LEN)) { + ls =3D ls_iter; + break; + } + } + + if (!ls) { + rv =3D -ENOENT; + goto err; + } + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) { + rv =3D -ENOMEM; + goto err; + } + + rv =3D __nldlm_get_ls(skb, ls, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(skb); + goto err; + } + + rv =3D genlmsg_reply(skb, info); + +err: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +static int nldlm_put_addr(struct sk_buff *skb, const struct sockaddr_stora= ge *addr, + int attrtype) +{ + struct nlattr *nl_addr; + int rv; + + nl_addr =3D nla_nest_start(skb, attrtype); + if (!nl_addr) + return -ENOBUFS; + + rv =3D nla_put_u16(skb, NLDLM_ADDR_ATTR_FAMILY, addr->ss_family); + if (rv) { + nla_nest_cancel(skb, nl_addr); + return -ENOBUFS; + } + + switch (addr->ss_family) { + case AF_INET: + rv =3D nla_put_in_addr(skb, NLDLM_ADDR_ATTR_ADDR4, + ((struct sockaddr_in *)addr)->sin_addr.s_addr); + if (rv) { + nla_nest_cancel(skb, nl_addr); + return -ENOBUFS; + } + break; + case AF_INET6: + rv =3D nla_put_in6_addr(skb, NLDLM_ADDR_ATTR_ADDR6, + &((struct sockaddr_in6 *)addr)->sin6_addr); + if (rv) { + nla_nest_cancel(skb, nl_addr); + return -ENOBUFS; + } + break; + default: + nla_nest_cancel(skb, nl_addr); + return -EINVAL; + } + + nla_nest_end(skb, nl_addr); + return 0; +} + +static int nldlm_put_node(struct sk_buff *skb, struct dlm_cfg_node *nd, + int attrtype) +{ + struct nlattr *nl_nd, *nl_addrs; + int rv, i; + + nl_nd =3D nla_nest_start(skb, attrtype); + if (!nl_nd) + return -ENOBUFS; + + rv =3D nla_put_le32(skb, NLDLM_NODE_ATTR_ID, cpu_to_le32(nd->id)); + if (rv < 0) { + nla_nest_cancel(skb, nl_nd); + return rv; + } + + nl_addrs =3D nla_nest_start(skb, NLDLM_NODE_ATTR_ADDRS); + if (!nl_addrs) { + nla_nest_cancel(skb, nl_nd); + return -ENOBUFS; + } + + for (i =3D 0; i < nd->addrs_count; i++) { + rv =3D nldlm_put_addr(skb, &nd->addrs[i], i + 1); + if (rv) { + nla_nest_cancel(skb, nl_addrs); + nla_nest_cancel(skb, nl_nd); + return rv; + } + } + + nla_nest_end(skb, nl_addrs); + nla_nest_end(skb, nl_nd); + return 0; +} + +static int __nldlm_get_node(struct sk_buff *skb, struct dlm_cfg_node *nd, + u32 portid, u32 seq, + struct netlink_callback *cb, int flags) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(skb, portid, seq, &nldlm_genl_family, flags, + NLDLM_CMD_GET_NODE); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nldlm_put_node(skb, nd, NLDLM_ATTR_NODE); + if (rv < 0) + goto err; + + genlmsg_end(skb, hdr); + return 0; + +err: + genlmsg_cancel(skb, hdr); + return rv; +} + +static const struct nla_policy +nldlm_addr_policy[NLDLM_ADDR_ATTR_MAX + 1] =3D { + [NLDLM_ADDR_ATTR_FAMILY] =3D { .type =3D NLA_U16 }, + [NLDLM_ADDR_ATTR_ADDR4] =3D { .type =3D NLA_BE32 }, + [NLDLM_ADDR_ATTR_ADDR6] =3D { .type =3D NLA_BINARY, + .len =3D sizeof(struct in6_addr)}, +}; + +static int nldlm_parse_addr(const struct nlattr *nla, struct sockaddr_stor= age *addr) +{ + struct nlattr *addr_attrs[NLDLM_ADDR_ATTR_MAX + 1]; + + if (nla_parse_nested(addr_attrs, NLDLM_ADDR_ATTR_MAX, nla, + nldlm_addr_policy, NULL)) + return -EINVAL; + + if (!addr_attrs[NLDLM_ADDR_ATTR_FAMILY]) + return -EINVAL; + + addr->ss_family =3D nla_get_u16(addr_attrs[NLDLM_ADDR_ATTR_FAMILY]); + switch (addr->ss_family) { + case AF_INET: + if (!addr_attrs[NLDLM_ADDR_ATTR_ADDR4]) + return -EINVAL; + + ((struct sockaddr_in *)addr)->sin_addr.s_addr =3D + nla_get_in_addr(addr_attrs[NLDLM_ADDR_ATTR_ADDR4]); + break; + case AF_INET6: + if (!addr_attrs[NLDLM_ADDR_ATTR_ADDR6]) + return -EINVAL; + + ((struct sockaddr_in6 *)addr)->sin6_addr =3D + nla_get_in6_addr(addr_attrs[NLDLM_ADDR_ATTR_ADDR6]); + break; + default: + return -EINVAL; + } + + return 0; +} + +static const struct nla_policy +nldlm_node_policy[NLDLM_NODE_ATTR_MAX + 1] =3D { + [NLDLM_NODE_ATTR_ID] =3D { .type =3D NLA_U32 }, + [NLDLM_NODE_ATTR_MARK] =3D { .type =3D NLA_U32 }, + [NLDLM_NODE_ATTR_ADDRS] =3D { .type =3D NLA_NESTED }, +}; + +static int nldlm_parse_node(const struct nlattr *nla, __le32 *nodeid, + struct sockaddr_storage *addrs, size_t *addrs_count, + uint32_t *mark) +{ + struct nlattr *nd_attrs[NLDLM_NODE_ATTR_MAX + 1]; + int rem, rv; + + if (!nla) + return -EINVAL; + + if (nla_parse_nested(nd_attrs, NLDLM_NODE_ATTR_MAX, nla, + nldlm_node_policy, NULL)) + return -EINVAL; + + if (nodeid) { + if (!nd_attrs[NLDLM_NODE_ATTR_ID]) + return -EINVAL; + + *nodeid =3D nla_get_le32(nd_attrs[NLDLM_NODE_ATTR_ID]); + } + + if (addrs && addrs_count) { + if (!nd_attrs[NLDLM_NODE_ATTR_ADDRS]) + return -EINVAL; + + *addrs_count =3D 0; + nla_for_each_nested(nla, nd_attrs[NLDLM_NODE_ATTR_ADDRS], rem) { + if (*addrs_count =3D=3D DLM_MAX_ADDR_COUNT) + return -ENOSPC; + + rv =3D nldlm_parse_addr(nla, &addrs[*addrs_count]); + if (rv) + return rv; + + (*addrs_count)++; + } + } + + if (mark) { + if (nd_attrs[NLDLM_NODE_ATTR_MARK]) + *mark =3D nla_get_u32(nd_attrs[NLDLM_NODE_ATTR_MARK]); + else + *mark =3D DLM_DEFAULT_MARK; + } + + return 0; +} + +static int nldlm_get_node(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct dlm_cfg_node *nd; + struct sk_buff *skb; + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_node(info->attrs[NLDLM_ATTR_NODE], &nodeid, NULL, NULL, + NULL); + if (rv) + return rv; + + mutex_lock(&dn->cfg_lock); + nd =3D dlm_cfg_get_node(dn, le32_to_cpu(nodeid)); + if (!nd) { + rv =3D -ENOENT; + goto out; + } + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) { + rv =3D -ENOMEM; + goto out; + } + + rv =3D __nldlm_get_node(skb, nd, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(skb); + goto out; + } + + rv =3D genlmsg_reply(skb, info); + +out: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +static int nldlm_dump_nodes(struct sk_buff *skb, + struct netlink_callback *cb) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + struct dlm_cfg_node *nd; + int rv; + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(nd, &dn->nodes, list) { + if (nd->idx < idx) + continue; + + rv =3D __nldlm_get_node(skb, nd, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D nd->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +static int nldlm_new_node(struct sk_buff *msg, struct genl_info *info) +{ + struct sockaddr_storage addrs[DLM_MAX_ADDR_COUNT] =3D {}; + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + size_t addrs_count; + uint32_t mark; + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_node(info->attrs[NLDLM_ATTR_NODE], &nodeid, + addrs, &addrs_count, &mark); + if (rv < 0) + return rv; + + return dlm_cfg_new_node(dn, le32_to_cpu(nodeid), mark, addrs, + addrs_count); +} + +static int nldlm_del_node(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_node(info->attrs[NLDLM_ATTR_NODE], &nodeid, NULL, + NULL, NULL); + if (rv < 0) + return rv; + + return dlm_cfg_del_node(dn, le32_to_cpu(nodeid)); +} + +static int nldlm_put_member(struct sk_buff *skb, + const struct dlm_cfg_member *mb, int attrtype) +{ + struct nlattr *nl_mb; + int rv; + + nl_mb =3D nla_nest_start(skb, NLDLM_ATTR_LS_MEMBER); + if (!nl_mb) + return -ENOBUFS; + + rv =3D nldlm_put_ls(skb, mb->ls->name, NLDLM_LS_MEMBER_ATTR_LS); + if (rv < 0) { + nla_nest_cancel(skb, nl_mb); + return rv; + } + + rv =3D nldlm_put_node(skb, mb->nd, NLDLM_LS_MEMBER_ATTR_NODE); + if (rv < 0) { + nla_nest_cancel(skb, nl_mb); + return rv; + } + + rv =3D nla_put_u32(skb, NLDLM_LS_MEMBER_ATTR_WEIGHT, mb->weight); + if (rv < 0) { + nla_nest_cancel(skb, nl_mb); + return rv; + } + + nla_nest_end(skb, nl_mb); + return 0; +} + +static int __nldlm_get_member(struct sk_buff *skb, + const struct dlm_cfg_member *mb, + u32 portid, u32 seq, + struct netlink_callback *cb, int flags) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(skb, portid, seq, &nldlm_genl_family, flags, + NLDLM_CMD_GET_LS_MEMBER); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nldlm_put_member(skb, mb, NLDLM_ATTR_LS_MEMBER); + if (rv < 0) + goto err; + + genlmsg_end(skb, hdr); + return 0; + +err: + genlmsg_cancel(skb, hdr); + return rv; +} + +static const struct nla_policy nldlm_member_policy[NLDLM_LS_MEMBER_ATTR_MA= X + 1] =3D { + [NLDLM_LS_MEMBER_ATTR_LS] =3D { .type =3D NLA_NESTED }, + [NLDLM_LS_MEMBER_ATTR_NODE] =3D { .type =3D NLA_NESTED }, + [NLDLM_LS_MEMBER_ATTR_WEIGHT] =3D { .type =3D NLA_U32 }, +}; + +static int nldlm_parse_member(const struct nlattr *nla, char *lsname, + __le32 *nodeid, uint32_t *weight) +{ + struct nlattr *member_attrs[NLDLM_LS_MEMBER_ATTR_MAX + 1]; + int rv; + + if (!nla) + return -EINVAL; + + if (nla_parse_nested(member_attrs, NLDLM_LS_MEMBER_ATTR_MAX, nla, + nldlm_member_policy, NULL)) + return -EINVAL; + + if (lsname) { + rv =3D nldlm_parse_ls(member_attrs[NLDLM_LS_MEMBER_ATTR_LS], + lsname); + if (rv) + return rv; + } + + if (nodeid) { + rv =3D nldlm_parse_node(member_attrs[NLDLM_LS_MEMBER_ATTR_NODE], + nodeid, NULL, NULL, NULL); + if (rv) + return rv; + } + + if (weight) { + if (member_attrs[NLDLM_LS_MEMBER_ATTR_WEIGHT]) + *weight =3D nla_get_u32(member_attrs[NLDLM_LS_MEMBER_ATTR_WEIGHT]); + else + *weight =3D DLM_DEFAULT_WEIGHT; + } + + return 0; +} + +static int nldlm_get_member(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_cfg_member *mb; + struct sk_buff *skb; + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_member(info->attrs[NLDLM_ATTR_LS_MEMBER], lsname, + &nodeid, NULL); + if (rv < 0) + return rv; + + mutex_lock(&dn->cfg_lock); + mb =3D dlm_cfg_get_ls_member(dn, lsname, le32_to_cpu(nodeid)); + if (!mb) { + rv =3D -ENOENT; + goto out; + } + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) { + rv =3D -ENOMEM; + goto out; + } + + rv =3D __nldlm_get_member(skb, mb, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(skb); + goto out; + } + + rv =3D genlmsg_reply(skb, info); + +out: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +static int nldlm_dump_members(struct sk_buff *skb, struct netlink_callback= *cb) +{ + const struct genl_info *info =3D genl_info_dump(cb); + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_cfg_member *mb; + struct dlm_cfg_ls *ls; + int rv; + + rv =3D nldlm_parse_ls(info->attrs[NLDLM_ATTR_LS], lsname); + if (rv < 0) + return rv; + + mutex_lock(&dn->cfg_lock); + ls =3D dlm_cfg_get_ls(dn, lsname); + if (!ls) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + list_for_each_entry(mb, &ls->members, list) { + if (mb->idx < idx) + continue; + + rv =3D __nldlm_get_member(skb, mb, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D mb->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +static int nldlm_ls_member_add(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + uint32_t weight; + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_member(info->attrs[NLDLM_ATTR_LS_MEMBER], lsname, + &nodeid, &weight); + if (rv < 0) + return rv; + + return dlm_cfg_add_member(dn, lsname, le32_to_cpu(nodeid), weight); +} + +static int nldlm_ls_member_del(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + __le32 nodeid; + int rv; + + rv =3D nldlm_parse_member(info->attrs[NLDLM_ATTR_LS_MEMBER], lsname, + &nodeid, NULL); + if (rv < 0) + return rv; + + return dlm_cfg_del_member(dn, lsname, le32_to_cpu(nodeid)); +} + +static const struct nla_policy +nldlm_ls_event_policy[NLDLM_LS_EVENT_ATTR_MAX + 1] =3D { + [NLDLM_LS_EVENT_ATTR_LS] =3D { .type =3D NLA_NESTED }, + [NLDLM_LS_EVENT_ATTR_TYPE] =3D { .type =3D NLA_U32 }, + [NLDLM_LS_EVENT_ATTR_CTRL] =3D { .type =3D NLA_U32 }, + [NLDLM_LS_EVENT_ATTR_RESULT] =3D { .type =3D NLA_U32 }, +}; + +static int nldlm_parse_ls_event(const struct nlattr *nla, char *lsname, + uint32_t *type, uint32_t *ctrl, + uint32_t *result) +{ + struct nlattr *ls_event_attrs[NLDLM_LS_EVENT_ATTR_MAX + 1]; + int rv; + + if (!nla) + return -EINVAL; + + if (nla_parse_nested(ls_event_attrs, NLDLM_LS_EVENT_ATTR_MAX, nla, + nldlm_ls_event_policy, NULL)) + return -EINVAL; + + if (lsname) { + rv =3D nldlm_parse_ls(ls_event_attrs[NLDLM_LS_EVENT_ATTR_LS], + lsname); + if (rv < 0) + return -EINVAL; + } + + if (type) { + if (!ls_event_attrs[NLDLM_LS_EVENT_ATTR_TYPE]) + return -EINVAL; + + *type =3D nla_get_u32(ls_event_attrs[NLDLM_LS_EVENT_ATTR_TYPE]); + } + + if (ctrl) { + if (!ls_event_attrs[NLDLM_LS_EVENT_ATTR_CTRL]) + return -EINVAL; + + *ctrl =3D nla_get_u32(ls_event_attrs[NLDLM_LS_EVENT_ATTR_CTRL]); + } + + if (result) { + if (!ls_event_attrs[NLDLM_LS_EVENT_ATTR_RESULT]) + return -EINVAL; + + *result =3D nla_get_u32(ls_event_attrs[NLDLM_LS_EVENT_ATTR_RESULT]); + } + + return 0; +} + +static int nldlm_ls_event_done(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_ls *ls; + uint32_t result; + int rv; + + rv =3D nldlm_parse_ls_event(info->attrs[NLDLM_ATTR_LS_EVENT], + lsname, NULL, NULL, &result); + if (rv < 0) + return rv; + + ls =3D dlm_find_lockspace_name(dn, lsname); + if (!ls) + return -ENOENT; + + switch (result) { + case NLDLM_EVENT_MEMBER_SUCCESS: + rv =3D 0; + break; + case NLDLM_EVENT_MEMBER_FAILURE: + rv =3D -1; + break; + default: + dlm_put_lockspace(ls); + return -EINVAL; + } + + ls->ls_uevent_result =3D rv; + set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags); + wake_up(&ls->ls_uevent_wait); + + dlm_put_lockspace(ls); + return 0; +} + +static int nldlm_ls_control(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_ls *ls; + uint32_t ctrl; + int rv; + + rv =3D nldlm_parse_ls_event(info->attrs[NLDLM_ATTR_LS_EVENT], + lsname, NULL, &ctrl, NULL); + if (rv < 0) + return rv; + + ls =3D dlm_find_lockspace_name(dn, lsname); + if (!ls) + return -ENOENT; + + switch (ctrl) { + case NLDLM_LS_CTRL_STOP: + dlm_ls_stop(ls); + break; + case NLDLM_LS_CTRL_START: + dlm_ls_start(ls); + break; + default: + rv =3D -EINVAL; + break; + } + + dlm_put_lockspace(ls); + return rv; +} + +static int nldlm_get_config(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *nl_cfg; + struct sk_buff *skb; + uint32_t log_level; + void *hdr; + int rv; + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!skb) { + mutex_unlock(&dn->cfg_lock); + return -ENOMEM; + } + + hdr =3D genlmsg_put(skb, info->snd_portid, info->snd_seq, + &nldlm_genl_family, 0, NLDLM_CMD_GET_CONFIG); + if (!hdr) { + nlmsg_free(skb); + return -EMSGSIZE; + } + + nl_cfg =3D nla_nest_start(skb, NLDLM_ATTR_CFG); + if (!nl_cfg) { + nlmsg_free(skb); + return -ENOBUFS; + } + + mutex_lock(&dn->cfg_lock); + if (dn->our_node) { + rv =3D nldlm_put_node(skb, dn->our_node, + NLDLM_CFG_ATTR_OUR_NODE); + if (rv < 0) + goto err; + } + + rv =3D nla_put_string(skb, NLDLM_CFG_ATTR_CLUSTER_NAME, + dn->config.ci_cluster_name); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(skb, NLDLM_CFG_ATTR_PROTOCOL, + dn->config.ci_protocol); + if (rv < 0) + goto err; + + rv =3D nla_put_be16(skb, NLDLM_CFG_ATTR_PORT, + dn->config.ci_tcp_port); + if (rv < 0) + goto err; + + if (!dn->config.ci_log_info) + log_level =3D NLDLM_LOG_LEVEL_NONE; + else if (dn->config.ci_log_info) + log_level =3D NLDLM_LOG_LEVEL_INFO; + else if (dn->config.ci_log_debug) + log_level =3D NLDLM_LOG_LEVEL_DEBUG; + + rv =3D nla_put_u32(skb, NLDLM_CFG_ATTR_LOG_LEVEL, log_level); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(skb, NLDLM_CFG_ATTR_RECOVER_TIMEOUT, + dn->config.ci_recover_timer); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(skb, NLDLM_CFG_ATTR_INACTIVE_TIMEOUT, + dn->config.ci_toss_secs); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(skb, NLDLM_CFG_ATTR_DEFAULT_MARK, + dn->config.ci_mark); + if (rv < 0) + goto err; + + if (dn->config.ci_recover_callbacks) { + rv =3D nla_put_flag(skb, NLDLM_CFG_ATTR_RECOVER_CALLBACKS); + if (rv < 0) + goto err; + } + + mutex_unlock(&dn->cfg_lock); + nla_nest_end(skb, nl_cfg); + genlmsg_end(skb, hdr); + return genlmsg_reply(skb, info); + +err: + mutex_unlock(&dn->cfg_lock); + nla_nest_cancel(skb, nl_cfg); + genlmsg_cancel(skb, hdr); + nlmsg_free(skb); + return rv; +} + +static const struct nla_policy nldlm_cfg_policy[NLDLM_CFG_ATTR_MAX + 1] = =3D { + [NLDLM_CFG_ATTR_OUR_NODE] =3D { .type =3D NLA_NESTED }, + [NLDLM_CFG_ATTR_CLUSTER_NAME] =3D { .type =3D NLA_NUL_STRING }, + [NLDLM_CFG_ATTR_PROTOCOL] =3D { .type =3D NLA_U32 }, + [NLDLM_CFG_ATTR_PORT] =3D { .type =3D NLA_BE16 }, + [NLDLM_CFG_ATTR_RECOVER_TIMEOUT] =3D { .type =3D NLA_U32 }, + [NLDLM_CFG_ATTR_INACTIVE_TIMEOUT] =3D { .type =3D NLA_U32 }, + [NLDLM_CFG_ATTR_LOG_LEVEL] =3D { .type =3D NLA_U32 }, + [NLDLM_CFG_ATTR_DEFAULT_MARK] =3D { .type =3D NLA_U32 }, + [NLDLM_CFG_ATTR_RECOVER_CALLBACKS] =3D { .type =3D NLA_FLAG }, +}; + +static int nldlm_set_cluster_name(struct sk_buff *msg, struct genl_info *i= nfo) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_CLUSTER_NAME]) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + nla_strscpy(dn->config.ci_cluster_name, + cfg_attrs[NLDLM_CFG_ATTR_CLUSTER_NAME], + DLM_LOCKSPACE_LEN); + mutex_unlock(&dn->cfg_lock); + return 0; +} + +static int nldlm_set_our_node_id(struct sk_buff *msg, struct genl_info *in= fo) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *node_attrs[NLDLM_NODE_ATTR_MAX + 1]; + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + __le32 nodeid; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_OUR_NODE]) + return -EINVAL; + + if (nla_parse_nested(node_attrs, NLDLM_NODE_ATTR_MAX, + cfg_attrs[NLDLM_CFG_ATTR_OUR_NODE], + nldlm_node_policy, NULL)) + return -EINVAL; + + nodeid =3D nla_get_le32(node_attrs[NLDLM_NODE_ATTR_ID]); + return dlm_cfg_set_our_node(dn, le32_to_cpu(nodeid)); +} + +static int nldlm_set_protocol(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + uint32_t protocol; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_PROTOCOL]) + return -EINVAL; + + protocol =3D nla_get_u32(cfg_attrs[NLDLM_CFG_ATTR_PROTOCOL]); + return dlm_cfg_set_protocol(dn, protocol); +} + +static int nldlm_set_port(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + __be16 port; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_PORT]) + return -EINVAL; + + port =3D nla_get_be16(cfg_attrs[NLDLM_CFG_ATTR_PORT]); + return dlm_cfg_set_port(dn, port); +} + +static int nldlm_set_log_level(struct sk_buff *msg, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + uint32_t level; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_LOG_LEVEL]) + return -EINVAL; + + level =3D nla_get_u32(cfg_attrs[NLDLM_CFG_ATTR_LOG_LEVEL]); + switch (level) { + case NLDLM_LOG_LEVEL_NONE: + dlm_cfg_set_log_info(dn, 0); + dlm_cfg_set_log_debug(dn, 0); + break; + case NLDLM_LOG_LEVEL_INFO: + dlm_cfg_set_log_info(dn, 1); + dlm_cfg_set_log_debug(dn, 0); + break; + case NLDLM_LOG_LEVEL_DEBUG: + dlm_cfg_set_log_info(dn, 1); + dlm_cfg_set_log_debug(dn, 1); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int nldlm_set_inactive_timeout(struct sk_buff *msg, + struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + uint32_t secs; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_INACTIVE_TIMEOUT]) + return -EINVAL; + + secs =3D nla_get_u32(cfg_attrs[NLDLM_CFG_ATTR_INACTIVE_TIMEOUT]); + return dlm_cfg_set_toss_secs(dn, secs); +} + +static int nldlm_set_recover_timeout(struct sk_buff *msg, struct genl_info= *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + uint32_t secs; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_RECOVER_TIMEOUT]) + return -EINVAL; + + secs =3D nla_get_u32(cfg_attrs[NLDLM_CFG_ATTR_RECOVER_TIMEOUT]); + return dlm_cfg_set_recover_timer(dn, secs); +} + +static int nldlm_set_default_mark(struct sk_buff *msg, struct genl_info *i= nfo) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + uint32_t mark; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + if (!cfg_attrs[NLDLM_CFG_ATTR_DEFAULT_MARK]) + return -EINVAL; + + mark =3D nla_get_u32(cfg_attrs[NLDLM_CFG_ATTR_DEFAULT_MARK]); + return dlm_cfg_set_mark(dn, mark); +} + +static int nldlm_set_cap_recover_callbacks(struct sk_buff *msg, struct gen= l_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(msg->sk)); + struct nlattr *cfg_attrs[NLDLM_CFG_ATTR_MAX + 1]; + int on; + + if (!info->attrs[NLDLM_ATTR_CFG]) + return -EINVAL; + + if (nla_parse_nested(cfg_attrs, NLDLM_CFG_ATTR_MAX, + info->attrs[NLDLM_ATTR_CFG], + nldlm_cfg_policy, NULL)) + return -EINVAL; + + on =3D nla_get_flag(cfg_attrs[NLDLM_CFG_ATTR_RECOVER_CALLBACKS]); + return dlm_cfg_set_recover_callbacks(dn, on); +} + +static const struct nla_policy nldlm_policy[NLDLM_ATTR_MAX + 1] =3D { + [NLDLM_ATTR_LS] =3D { .type =3D NLA_NESTED }, + [NLDLM_ATTR_LS_MEMBER] =3D { .type =3D NLA_NESTED }, + [NLDLM_ATTR_LS_EVENT] =3D { .type =3D NLA_NESTED }, + [NLDLM_ATTR_NODE] =3D { .type =3D NLA_NESTED }, +}; + +static const struct genl_ops nldlm_ops[] =3D { + { + .cmd =3D NLDLM_CMD_GET_LS, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP_STRICT, + .doit =3D nldlm_get_ls, + .dumpit =3D nldlm_dump_ls, + }, + { + .cmd =3D NLDLM_CMD_GET_NODE, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP_STRICT, + .doit =3D nldlm_get_node, + .dumpit =3D nldlm_dump_nodes, + }, + { + .cmd =3D NLDLM_CMD_NEW_NODE, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_new_node, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_DEL_NODE, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_del_node, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_GET_LS_MEMBER, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP_STRICT, + .doit =3D nldlm_get_member, + .dumpit =3D nldlm_dump_members, + }, + { + .cmd =3D NLDLM_CMD_LS_EVENT_ADD_MEMBER, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_ls_member_add, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_LS_EVENT_DEL_MEMBER, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_ls_member_del, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_LS_EVENT_DONE, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_ls_event_done, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_LS_EVENT_CTRL, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_ls_control, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_GET_CONFIG, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_get_config, + }, + { + .cmd =3D NLDLM_CMD_SET_CLUSTER_NAME, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_cluster_name, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_OUR_NODE, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_our_node_id, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_PROTOCOL, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_protocol, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_PORT, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_port, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_LOG_LEVEL, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_log_level, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_INACTIVE_TIMEOUT, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_inactive_timeout, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_RECOVER_TIMEOUT, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_recover_timeout, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_DEFAULT_MARK, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_default_mark, + .flags =3D GENL_ADMIN_PERM, + }, + { + .cmd =3D NLDLM_CMD_SET_RECOVER_CALLBACKS, + .validate =3D GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit =3D nldlm_set_cap_recover_callbacks, + .flags =3D GENL_ADMIN_PERM, + }, +}; + +static struct genl_family nldlm_genl_family __ro_after_init =3D { + .name =3D NLDLM_GENL_NAME, + .version =3D 1, + .maxattr =3D NLDLM_ATTR_MAX, + .policy =3D nldlm_policy, + .netnsok =3D true, + .parallel_ops =3D true, + .module =3D THIS_MODULE, + .ops =3D nldlm_ops, + .n_ops =3D ARRAY_SIZE(nldlm_ops), + .resv_start_op =3D NLDLM_CMD_MAX + 1, + .mcgrps =3D nldlm_mcgrps, + .n_mcgrps =3D ARRAY_SIZE(nldlm_mcgrps), +}; + +int __init dlm_nldlm_init(void) +{ + return genl_register_family(&nldlm_genl_family); +} + +void dlm_nldlm_exit(void) +{ + genl_unregister_family(&nldlm_genl_family); +} diff --git a/fs/dlm/nldlm-kernel.c b/fs/dlm/nldlm-kernel.c new file mode 100644 index 000000000000..9bf418b3420f --- /dev/null +++ b/fs/dlm/nldlm-kernel.c @@ -0,0 +1,290 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/nldlm.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "nldlm-kernel.h" + +#include + +/* Common nested types */ +const struct nla_policy nldlm_addr_nl_policy[NLDLM_A_ADDR_ADDR6 + 1] =3D { + [NLDLM_A_ADDR_FAMILY] =3D { .type =3D NLA_U16, }, + [NLDLM_A_ADDR_ADDR4] =3D { .type =3D NLA_U32, }, + [NLDLM_A_ADDR_ADDR6] =3D NLA_POLICY_EXACT_LEN(16), +}; + +/* NLDLM_CMD_GET_NODE - do */ +static const struct nla_policy nldlm_get_node_nl_policy[NLDLM_A_NODE_ID + = 1] =3D { + [NLDLM_A_NODE_ID] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_ADD_NODE - do */ +static const struct nla_policy nldlm_add_node_nl_policy[NLDLM_A_NODE_ADDRS= + 1] =3D { + [NLDLM_A_NODE_ID] =3D { .type =3D NLA_U32, }, + [NLDLM_A_NODE_MARK] =3D { .type =3D NLA_U32, }, + [NLDLM_A_NODE_ADDRS] =3D NLA_POLICY_NESTED(nldlm_addr_nl_policy), +}; + +/* NLDLM_CMD_DEL_NODE - do */ +static const struct nla_policy nldlm_del_node_nl_policy[NLDLM_A_NODE_ID + = 1] =3D { + [NLDLM_A_NODE_ID] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_GET_LS - do */ +static const struct nla_policy nldlm_get_ls_nl_policy[NLDLM_A_LS_NAME + 1]= =3D { + [NLDLM_A_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, +}; + +/* NLDLM_CMD_GET_LS_MEMBER - do */ +static const struct nla_policy nldlm_get_ls_member_do_nl_policy[NLDLM_A_LS= _MEMBER_NODEID + 1] =3D { + [NLDLM_A_LS_MEMBER_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [NLDLM_A_LS_MEMBER_NODEID] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_GET_LS_MEMBER - dump */ +static const struct nla_policy nldlm_get_ls_member_dump_nl_policy[NLDLM_A_= LS_MEMBER_LS_NAME + 1] =3D { + [NLDLM_A_LS_MEMBER_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, +}; + +/* NLDLM_CMD_LS_ADD_MEMBER - do */ +static const struct nla_policy nldlm_ls_add_member_nl_policy[NLDLM_A_LS_ME= MBER_WEIGHT + 1] =3D { + [NLDLM_A_LS_MEMBER_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [NLDLM_A_LS_MEMBER_NODEID] =3D { .type =3D NLA_U32, }, + [NLDLM_A_LS_MEMBER_WEIGHT] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_LS_DEL_MEMBER - do */ +static const struct nla_policy nldlm_ls_del_member_nl_policy[NLDLM_A_LS_ME= MBER_NODEID + 1] =3D { + [NLDLM_A_LS_MEMBER_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [NLDLM_A_LS_MEMBER_NODEID] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_LS_CTRL - do */ +static const struct nla_policy nldlm_ls_ctrl_nl_policy[NLDLM_A_LS_CTRL_ACT= ION + 1] =3D { + [NLDLM_A_LS_CTRL_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [NLDLM_A_LS_CTRL_ACTION] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_LS_EVENT_DONE - do */ +static const struct nla_policy nldlm_ls_event_done_nl_policy[NLDLM_A_LS_EV= ENT_RESULT_RESULT + 1] =3D { + [NLDLM_A_LS_EVENT_RESULT_LS_NAME] =3D { .type =3D NLA_NUL_STRING, }, + [NLDLM_A_LS_EVENT_RESULT_LS_GLOBAL_ID] =3D { .type =3D NLA_U32, }, + [NLDLM_A_LS_EVENT_RESULT_RESULT] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_OUR_NODEID - do */ +static const struct nla_policy nldlm_set_our_nodeid_nl_policy[NLDLM_A_CFG_= OUR_NODEID + 1] =3D { + [NLDLM_A_CFG_OUR_NODEID] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_CLUSTER_NAME - do */ +static const struct nla_policy nldlm_set_cluster_name_nl_policy[NLDLM_A_CF= G_CLUSTER_NAME + 1] =3D { + [NLDLM_A_CFG_CLUSTER_NAME] =3D { .type =3D NLA_NUL_STRING, }, +}; + +/* NLDLM_CMD_SET_PROTOCOL - do */ +static const struct nla_policy nldlm_set_protocol_nl_policy[NLDLM_A_CFG_PR= OTOCOL + 1] =3D { + [NLDLM_A_CFG_PROTOCOL] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_PORT - do */ +static const struct nla_policy nldlm_set_port_nl_policy[NLDLM_A_CFG_PORT += 1] =3D { + [NLDLM_A_CFG_PORT] =3D { .type =3D NLA_U16, }, +}; + +/* NLDLM_CMD_SET_RECOVER_TIMEOUT - do */ +static const struct nla_policy nldlm_set_recover_timeout_nl_policy[NLDLM_A= _CFG_RECOVER_TIMEOUT + 1] =3D { + [NLDLM_A_CFG_RECOVER_TIMEOUT] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_INACTIVE_TIMEOUT - do */ +static const struct nla_policy nldlm_set_inactive_timeout_nl_policy[NLDLM_= A_CFG_INACTIVE_TIMEOUT + 1] =3D { + [NLDLM_A_CFG_INACTIVE_TIMEOUT] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_LOG_LEVEL - do */ +static const struct nla_policy nldlm_set_log_level_nl_policy[NLDLM_A_CFG_L= OG_LEVEL + 1] =3D { + [NLDLM_A_CFG_LOG_LEVEL] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_DEFAULT_MARK - do */ +static const struct nla_policy nldlm_set_default_mark_nl_policy[NLDLM_A_CF= G_DEFAULT_MARK + 1] =3D { + [NLDLM_A_CFG_DEFAULT_MARK] =3D { .type =3D NLA_U32, }, +}; + +/* NLDLM_CMD_SET_RECOVER_CALLBACKS - do */ +static const struct nla_policy nldlm_set_recover_callbacks_nl_policy[NLDLM= _A_CFG_RECOVER_CALLBACKS + 1] =3D { + [NLDLM_A_CFG_RECOVER_CALLBACKS] =3D { .type =3D NLA_FLAG, }, +}; + +/* Ops table for nldlm */ +static const struct genl_split_ops nldlm_nl_ops[] =3D { + { + .cmd =3D NLDLM_CMD_GET_NODE, + .doit =3D nldlm_nl_get_node_doit, + .policy =3D nldlm_get_node_nl_policy, + .maxattr =3D NLDLM_A_NODE_ID, + .flags =3D GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_GET_NODE, + .dumpit =3D nldlm_nl_get_node_dumpit, + .flags =3D GENL_CMD_CAP_DUMP, + }, + { + .cmd =3D NLDLM_CMD_ADD_NODE, + .doit =3D nldlm_nl_add_node_doit, + .policy =3D nldlm_add_node_nl_policy, + .maxattr =3D NLDLM_A_NODE_ADDRS, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_DEL_NODE, + .doit =3D nldlm_nl_del_node_doit, + .policy =3D nldlm_del_node_nl_policy, + .maxattr =3D NLDLM_A_NODE_ID, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_GET_LS, + .doit =3D nldlm_nl_get_ls_doit, + .policy =3D nldlm_get_ls_nl_policy, + .maxattr =3D NLDLM_A_LS_NAME, + .flags =3D GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_GET_LS, + .dumpit =3D nldlm_nl_get_ls_dumpit, + .flags =3D GENL_CMD_CAP_DUMP, + }, + { + .cmd =3D NLDLM_CMD_GET_LS_MEMBER, + .doit =3D nldlm_nl_get_ls_member_doit, + .policy =3D nldlm_get_ls_member_do_nl_policy, + .maxattr =3D NLDLM_A_LS_MEMBER_NODEID, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_GET_LS_MEMBER, + .dumpit =3D nldlm_nl_get_ls_member_dumpit, + .policy =3D nldlm_get_ls_member_dump_nl_policy, + .maxattr =3D NLDLM_A_LS_MEMBER_LS_NAME, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP, + }, + { + .cmd =3D NLDLM_CMD_LS_ADD_MEMBER, + .doit =3D nldlm_nl_ls_add_member_doit, + .policy =3D nldlm_ls_add_member_nl_policy, + .maxattr =3D NLDLM_A_LS_MEMBER_WEIGHT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_LS_DEL_MEMBER, + .doit =3D nldlm_nl_ls_del_member_doit, + .policy =3D nldlm_ls_del_member_nl_policy, + .maxattr =3D NLDLM_A_LS_MEMBER_NODEID, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_LS_CTRL, + .doit =3D nldlm_nl_ls_ctrl_doit, + .policy =3D nldlm_ls_ctrl_nl_policy, + .maxattr =3D NLDLM_A_LS_CTRL_ACTION, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_LS_EVENT_DONE, + .doit =3D nldlm_nl_ls_event_done_doit, + .policy =3D nldlm_ls_event_done_nl_policy, + .maxattr =3D NLDLM_A_LS_EVENT_RESULT_RESULT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_GET_CFG, + .doit =3D nldlm_nl_get_cfg_doit, + .flags =3D GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_OUR_NODEID, + .doit =3D nldlm_nl_set_our_nodeid_doit, + .policy =3D nldlm_set_our_nodeid_nl_policy, + .maxattr =3D NLDLM_A_CFG_OUR_NODEID, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_CLUSTER_NAME, + .doit =3D nldlm_nl_set_cluster_name_doit, + .policy =3D nldlm_set_cluster_name_nl_policy, + .maxattr =3D NLDLM_A_CFG_CLUSTER_NAME, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_PROTOCOL, + .doit =3D nldlm_nl_set_protocol_doit, + .policy =3D nldlm_set_protocol_nl_policy, + .maxattr =3D NLDLM_A_CFG_PROTOCOL, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_PORT, + .doit =3D nldlm_nl_set_port_doit, + .policy =3D nldlm_set_port_nl_policy, + .maxattr =3D NLDLM_A_CFG_PORT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_RECOVER_TIMEOUT, + .doit =3D nldlm_nl_set_recover_timeout_doit, + .policy =3D nldlm_set_recover_timeout_nl_policy, + .maxattr =3D NLDLM_A_CFG_RECOVER_TIMEOUT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_INACTIVE_TIMEOUT, + .doit =3D nldlm_nl_set_inactive_timeout_doit, + .policy =3D nldlm_set_inactive_timeout_nl_policy, + .maxattr =3D NLDLM_A_CFG_INACTIVE_TIMEOUT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_LOG_LEVEL, + .doit =3D nldlm_nl_set_log_level_doit, + .policy =3D nldlm_set_log_level_nl_policy, + .maxattr =3D NLDLM_A_CFG_LOG_LEVEL, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_DEFAULT_MARK, + .doit =3D nldlm_nl_set_default_mark_doit, + .policy =3D nldlm_set_default_mark_nl_policy, + .maxattr =3D NLDLM_A_CFG_DEFAULT_MARK, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, + { + .cmd =3D NLDLM_CMD_SET_RECOVER_CALLBACKS, + .doit =3D nldlm_nl_set_recover_callbacks_doit, + .policy =3D nldlm_set_recover_callbacks_nl_policy, + .maxattr =3D NLDLM_A_CFG_RECOVER_CALLBACKS, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, +}; + +static const struct genl_multicast_group nldlm_nl_mcgrps[] =3D { + [NLDLM_NLGRP_LS_EVENT] =3D { "ls-event", }, +}; + +struct genl_family nldlm_nl_family __ro_after_init =3D { + .name =3D NLDLM_FAMILY_NAME, + .version =3D NLDLM_FAMILY_VERSION, + .netnsok =3D true, + .parallel_ops =3D true, + .module =3D THIS_MODULE, + .split_ops =3D nldlm_nl_ops, + .n_split_ops =3D ARRAY_SIZE(nldlm_nl_ops), + .mcgrps =3D nldlm_nl_mcgrps, + .n_mcgrps =3D ARRAY_SIZE(nldlm_nl_mcgrps), +}; diff --git a/fs/dlm/nldlm-kernel.h b/fs/dlm/nldlm-kernel.h new file mode 100644 index 000000000000..b278d7160e27 --- /dev/null +++ b/fs/dlm/nldlm-kernel.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/nldlm.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_NLDLM_GEN_H +#define _LINUX_NLDLM_GEN_H + +#include +#include + +#include + +/* Common nested types */ +extern const struct nla_policy nldlm_addr_nl_policy[NLDLM_A_ADDR_ADDR6 + 1= ]; + +int nldlm_nl_get_node_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_get_node_dumpit(struct sk_buff *skb, struct netlink_callback = *cb); +int nldlm_nl_add_node_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_del_node_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_get_ls_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_get_ls_dumpit(struct sk_buff *skb, struct netlink_callback *c= b); +int nldlm_nl_get_ls_member_doit(struct sk_buff *skb, struct genl_info *inf= o); +int nldlm_nl_get_ls_member_dumpit(struct sk_buff *skb, + struct netlink_callback *cb); +int nldlm_nl_ls_add_member_doit(struct sk_buff *skb, struct genl_info *inf= o); +int nldlm_nl_ls_del_member_doit(struct sk_buff *skb, struct genl_info *inf= o); +int nldlm_nl_ls_ctrl_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_ls_event_done_doit(struct sk_buff *skb, struct genl_info *inf= o); +int nldlm_nl_get_cfg_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_set_our_nodeid_doit(struct sk_buff *skb, struct genl_info *in= fo); +int nldlm_nl_set_cluster_name_doit(struct sk_buff *skb, struct genl_info *= info); +int nldlm_nl_set_protocol_doit(struct sk_buff *skb, struct genl_info *info= ); +int nldlm_nl_set_port_doit(struct sk_buff *skb, struct genl_info *info); +int nldlm_nl_set_recover_timeout_doit(struct sk_buff *skb, + struct genl_info *info); +int nldlm_nl_set_inactive_timeout_doit(struct sk_buff *skb, + struct genl_info *info); +int nldlm_nl_set_log_level_doit(struct sk_buff *skb, struct genl_info *inf= o); +int nldlm_nl_set_default_mark_doit(struct sk_buff *skb, struct genl_info *= info); +int nldlm_nl_set_recover_callbacks_doit(struct sk_buff *skb, + struct genl_info *info); + +enum { + NLDLM_NLGRP_LS_EVENT, +}; + +extern struct genl_family nldlm_nl_family; + +#endif /* _LINUX_NLDLM_GEN_H */ diff --git a/fs/dlm/nldlm.c b/fs/dlm/nldlm.c new file mode 100644 index 000000000000..8767602c82ca --- /dev/null +++ b/fs/dlm/nldlm.c @@ -0,0 +1,847 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include + +#include "dlm_internal.h" +#include "nldlm-kernel.h" +#include "lockspace.h" +#include "member.h" +#include "config.h" +#include "lock.h" + +static int nldlm_put_ls_event(struct sk_buff *msg, const struct dlm_ls *ls, + u32 portid, u32 seq, int flags, uint32_t cmd) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(msg, 0, 0, &nldlm_nl_family, 0, cmd); + if (!hdr) + return -ENOBUFS; + + rv =3D nla_put_string(msg, NLDLM_A_LS_NAME, ls->ls_name); + if (rv < 0) + goto err; + + genlmsg_end(msg, hdr); + return 0; + +err: + genlmsg_cancel(msg, hdr); + return -ENOBUFS; +} + +int nldlm_ls_event(const struct dlm_ls *ls, uint32_t cmd) +{ + struct sk_buff *msg; + int rv; + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) + return -ENOMEM; + + rv =3D nldlm_put_ls_event(msg, ls, 0, 0, 0, cmd); + if (rv < 0) { + nlmsg_free(msg); + return rv; + } + + return genlmsg_multicast_netns(&nldlm_nl_family, + read_pnet(&ls->ls_dn->net), msg, 0, + NLDLM_NLGRP_LS_EVENT, GFP_ATOMIC); +} + +static int __nldlm_get_ls(struct sk_buff *msg, struct dlm_cfg_ls *ls, + u32 portid, u32 seq, struct netlink_callback *cb, + int flags) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(msg, portid, seq, &nldlm_nl_family, flags, + NLDLM_CMD_GET_LS); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nla_put_string(msg, NLDLM_A_LS_NAME, ls->name); + if (rv < 0) + goto err; + + genlmsg_end(msg, hdr); + return 0; + +err: + genlmsg_cancel(msg, hdr); + return rv; +} + +int nldlm_nl_get_ls_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + struct dlm_cfg_ls *ls =3D NULL, *ls_iter; + char lsname[DLM_LOCKSPACE_LEN]; + struct sk_buff *msg; + int rv; + + if (!info->attrs[NLDLM_A_LS_NAME]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_NAME], + DLM_LOCKSPACE_LEN); + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(ls_iter, &dn->lockspaces, list) { + if (!strncmp(ls_iter->name, lsname, DLM_LOCKSPACE_LEN)) { + ls =3D ls_iter; + break; + } + } + + if (!ls) { + rv =3D -ENOENT; + goto err; + } + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) { + rv =3D -ENOMEM; + goto err; + } + + rv =3D __nldlm_get_ls(msg, ls, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(msg); + goto err; + } + + rv =3D genlmsg_reply(msg, info); + +err: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +int nldlm_nl_get_ls_dumpit(struct sk_buff *skb, struct netlink_callback *c= b) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + struct dlm_cfg_ls *ls; + int rv; + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(ls, &dn->lockspaces, list) { + if (ls->idx < idx) + continue; + + rv =3D __nldlm_get_ls(skb, ls, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D ls->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +static int __nldlm_get_node(struct sk_buff *msg, struct dlm_cfg_node *nd, + u32 portid, u32 seq, + struct netlink_callback *cb, int flags) +{ + struct nlattr *nl_addr; + void *hdr; + size_t i; + int rv; + + hdr =3D genlmsg_put(msg, portid, seq, &nldlm_nl_family, flags, + NLDLM_CMD_GET_NODE); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nla_put_le32(msg, NLDLM_A_NODE_ID, cpu_to_le32(nd->id)); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_NODE_MARK, nd->mark); + if (rv < 0) + goto err; + + for (i =3D 0; i < nd->addrs_count; i++) { + nl_addr =3D nla_nest_start(msg, NLDLM_A_NODE_ADDRS); + if (!nl_addr) + goto err; + + rv =3D nla_put_u16(msg, NLDLM_A_ADDR_FAMILY, nd->addrs[i].ss_family); + if (rv) { + nla_nest_cancel(msg, nl_addr); + goto err; + } + + switch (nd->addrs[i].ss_family) { + case AF_INET: + rv =3D nla_put_in_addr(msg, NLDLM_A_ADDR_ADDR4, + ((struct sockaddr_in *)&nd->addrs[i])->sin_addr.s_addr); + if (rv) { + nla_nest_cancel(msg, nl_addr); + goto err; + } + + break; + case AF_INET6: + rv =3D nla_put_in6_addr(msg, NLDLM_A_ADDR_ADDR6, + &((struct sockaddr_in6 *)&nd->addrs[i])->sin6_addr); + if (rv) { + nla_nest_cancel(msg, nl_addr); + goto err; + } + + break; + default: + nla_nest_cancel(msg, nl_addr); + goto err; + } + + nla_nest_end(msg, nl_addr); + } + + genlmsg_end(msg, hdr); + return 0; + +err: + genlmsg_cancel(msg, hdr); + return rv; +} + +int nldlm_nl_get_node_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + struct dlm_cfg_node *nd; + struct sk_buff *msg; + __le32 nodeid; + int rv; + + if (!info->attrs[NLDLM_A_NODE_ID]) + return -EINVAL; + + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_NODE_ID]); + + mutex_lock(&dn->cfg_lock); + nd =3D dlm_cfg_get_node(dn, le32_to_cpu(nodeid)); + if (!nd) { + rv =3D -ENOENT; + goto out; + } + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) { + rv =3D -ENOMEM; + goto out; + } + + rv =3D __nldlm_get_node(msg, nd, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(msg); + goto out; + } + + rv =3D genlmsg_reply(msg, info); + +out: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +int nldlm_nl_get_node_dumpit(struct sk_buff *skb, struct netlink_callback = *cb) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + struct dlm_cfg_node *nd; + int rv; + + mutex_lock(&dn->cfg_lock); + list_for_each_entry(nd, &dn->nodes, list) { + if (nd->idx < idx) + continue; + + rv =3D __nldlm_get_node(skb, nd, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D nd->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +int nldlm_nl_add_node_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct nlattr *head =3D nlmsg_attrdata(info->nlhdr, GENL_HDRLEN); + struct sockaddr_storage addrs[DLM_MAX_ADDR_COUNT] =3D {}; + int rem, len =3D nlmsg_attrlen(info->nlhdr, GENL_HDRLEN); + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + struct nlattr *addr_attrs[NLDLM_A_ADDR_MAX + 1]; + struct nlattr *nla; + size_t addrs_count; + __le32 nodeid; + u32 mark; + int rv; + + if (!info->attrs[NLDLM_A_NODE_ID] || + !info->attrs[NLDLM_A_NODE_ADDRS]) + return -EINVAL; + + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_NODE_ID]); + + addrs_count =3D 0; + nla_for_each_attr(nla, head, len, rem) { + if (nla_type(nla) !=3D NLDLM_A_NODE_ADDRS) + continue; + + if (addrs_count =3D=3D DLM_MAX_ADDR_COUNT) + return -ENOSPC; + + rv =3D nla_parse_nested(addr_attrs, NLDLM_A_ADDR_MAX, nla, + nldlm_addr_nl_policy, NULL); + if (rv) + return rv; + + if (!addr_attrs[NLDLM_A_ADDR_FAMILY]) + return -EINVAL; + + addrs[addrs_count].ss_family =3D nla_get_u16(addr_attrs[NLDLM_A_ADDR_FAM= ILY]); + switch (addrs[addrs_count].ss_family) { + case AF_INET: + if (!addr_attrs[NLDLM_A_ADDR_ADDR4]) + return -EINVAL; + + ((struct sockaddr_in *)&addrs[addrs_count])->sin_addr.s_addr =3D + nla_get_in_addr(addr_attrs[NLDLM_A_ADDR_ADDR4]); + break; + case AF_INET6: + if (!addr_attrs[NLDLM_A_ADDR_ADDR6]) + return -EINVAL; + + ((struct sockaddr_in6 *)&addrs[addrs_count])->sin6_addr =3D + nla_get_in6_addr(addr_attrs[NLDLM_A_ADDR_ADDR6]); + break; + default: + return -EINVAL; + } + + addrs_count++; + } + + if (info->attrs[NLDLM_A_NODE_MARK]) + mark =3D nla_get_u32(info->attrs[NLDLM_A_NODE_MARK]); + else + mark =3D DLM_DEFAULT_MARK; + + return dlm_cfg_new_node(dn, le32_to_cpu(nodeid), mark, addrs, + addrs_count); +} + +int nldlm_nl_del_node_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + __le32 nodeid; + + if (!info->attrs[NLDLM_A_NODE_ID]) + return -EINVAL; + + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_NODE_ID]); + return dlm_cfg_del_node(dn, le32_to_cpu(nodeid)); +} + +static int __nldlm_get_ls_member(struct sk_buff *msg, + const struct dlm_cfg_member *mb, + u32 portid, u32 seq, + struct netlink_callback *cb, int flags) +{ + void *hdr; + int rv; + + hdr =3D genlmsg_put(msg, portid, seq, &nldlm_nl_family, flags, + NLDLM_CMD_GET_LS_MEMBER); + if (!hdr) + return -EMSGSIZE; + + if (cb) + genl_dump_check_consistent(cb, hdr); + + rv =3D nla_put_string(msg, NLDLM_A_LS_MEMBER_LS_NAME, mb->ls->name); + if (rv < 0) + goto err; + + rv =3D nla_put_le32(msg, NLDLM_A_LS_MEMBER_NODEID, cpu_to_le32(mb->nd->id= )); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_LS_MEMBER_WEIGHT, mb->weight); + if (rv < 0) + goto err; + + genlmsg_end(msg, hdr); + return 0; + +err: + genlmsg_cancel(msg, hdr); + return rv; +} + +int nldlm_nl_get_ls_member_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_cfg_member *mb; + struct sk_buff *msg; + __le32 nodeid; + int rv; + + if (!info->attrs[NLDLM_A_LS_MEMBER_LS_NAME] || + !info->attrs[NLDLM_A_LS_MEMBER_NODEID]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_MEMBER_LS_NAME], + DLM_LOCKSPACE_LEN); + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_LS_MEMBER_NODEID]); + + mutex_lock(&dn->cfg_lock); + mb =3D dlm_cfg_get_ls_member(dn, lsname, le32_to_cpu(nodeid)); + if (!mb) { + rv =3D -ENOENT; + goto out; + } + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) { + rv =3D -ENOMEM; + goto out; + } + + rv =3D __nldlm_get_ls_member(msg, mb, info->snd_portid, + info->snd_seq, NULL, 0); + if (rv < 0) { + nlmsg_free(msg); + goto out; + } + + rv =3D genlmsg_reply(msg, info); + +out: + mutex_unlock(&dn->cfg_lock); + return rv; +} + +int nldlm_nl_get_ls_member_dumpit(struct sk_buff *skb, + struct netlink_callback *cb) +{ + const struct genl_info *info =3D genl_info_dump(cb); + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + unsigned int idx =3D cb->args[0]; + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_cfg_member *mb; + struct dlm_cfg_ls *ls; + int rv; + + if (!info->attrs[NLDLM_A_LS_MEMBER_LS_NAME]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_MEMBER_LS_NAME], + DLM_LOCKSPACE_LEN); + + mutex_lock(&dn->cfg_lock); + ls =3D dlm_cfg_get_ls(dn, lsname); + if (!ls) { + mutex_unlock(&dn->cfg_lock); + return -ENOENT; + } + + list_for_each_entry(mb, &ls->members, list) { + if (mb->idx < idx) + continue; + + rv =3D __nldlm_get_ls_member(skb, mb, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, cb, + NLM_F_MULTI); + if (rv < 0) + break; + + idx =3D mb->idx + 1; + } + mutex_unlock(&dn->cfg_lock); + + cb->args[0] =3D idx; + return skb->len; +} + +int nldlm_nl_ls_ctrl_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + enum nldlm_ls_ctrl_action ctrl; + struct dlm_ls *ls; + + if (!info->attrs[NLDLM_A_LS_CTRL_LS_NAME] || + !info->attrs[NLDLM_A_LS_CTRL_ACTION]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_CTRL_LS_NAME], + DLM_LOCKSPACE_LEN); + ctrl =3D nla_get_u32(info->attrs[NLDLM_A_LS_CTRL_ACTION]); + + ls =3D dlm_find_lockspace_name(dn, lsname); + if (!ls) + return -ENOENT; + + switch (ctrl) { + case NLDLM_LS_CTRL_ACTION_STOP: + dlm_ls_stop(ls); + break; + case NLDLM_LS_CTRL_ACTION_START: + dlm_ls_start(ls); + break; + default: + dlm_put_lockspace(ls); + return -EINVAL; + } + + dlm_put_lockspace(ls); + return 0; +} + +int nldlm_nl_ls_event_done_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + enum nldlm_ls_event_result result; + char lsname[DLM_LOCKSPACE_LEN]; + struct dlm_ls *ls; + __le32 global_id; + int rv; + + if (!info->attrs[NLDLM_A_LS_EVENT_RESULT_LS_NAME] || + !info->attrs[NLDLM_A_LS_EVENT_RESULT_LS_GLOBAL_ID] || + !info->attrs[NLDLM_A_LS_EVENT_RESULT_RESULT]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_EVENT_RESULT_LS_NAME], + DLM_LOCKSPACE_LEN); + global_id =3D nla_get_le32(info->attrs[NLDLM_A_LS_EVENT_RESULT_LS_GLOBAL_= ID]); + result =3D nla_get_u32(info->attrs[NLDLM_A_LS_EVENT_RESULT_RESULT]); + + /* sanity checking only if the global_id is already given in another + * lockspace. This check is racy and it requires more changes to + * not make it racy, however is it better than just apply the id. + */ + ls =3D dlm_find_lockspace_global(dn, le32_to_cpu(global_id)); + if (ls) { + dlm_put_lockspace(ls); + return -EEXIST; + } + + ls =3D dlm_find_lockspace_name(dn, lsname); + if (!ls) + return -ENOENT; + + switch (result) { + case NLDLM_LS_EVENT_RESULT_SUCCESS: + ls->ls_global_id =3D le32_to_cpu(global_id); + rv =3D 0; + break; + case NLDLM_LS_EVENT_RESULT_FAILURE: + rv =3D -1; + break; + default: + dlm_put_lockspace(ls); + return -EINVAL; + } + + ls->ls_uevent_result =3D rv; + set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags); + wake_up(&ls->ls_uevent_wait); + + dlm_put_lockspace(ls); + return 0; +} + +int nldlm_nl_ls_add_member_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + __le32 nodeid; + u32 weight =3D DLM_DEFAULT_WEIGHT; + + if (!info->attrs[NLDLM_A_LS_MEMBER_LS_NAME] || + !info->attrs[NLDLM_A_LS_MEMBER_NODEID]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_MEMBER_LS_NAME], + DLM_LOCKSPACE_LEN); + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_LS_MEMBER_NODEID]); + if (info->attrs[NLDLM_A_LS_MEMBER_WEIGHT]) + weight =3D nla_get_u32(info->attrs[NLDLM_A_LS_MEMBER_WEIGHT]); + + return dlm_cfg_add_member(dn, lsname, le32_to_cpu(nodeid), weight); +} + +int nldlm_nl_ls_del_member_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + char lsname[DLM_LOCKSPACE_LEN]; + __le32 nodeid; + + if (!info->attrs[NLDLM_A_LS_MEMBER_LS_NAME] || + !info->attrs[NLDLM_A_LS_MEMBER_NODEID]) + return -EINVAL; + + nla_strscpy(lsname, info->attrs[NLDLM_A_LS_MEMBER_LS_NAME], + DLM_LOCKSPACE_LEN); + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_LS_MEMBER_NODEID]); + + return dlm_cfg_del_member(dn, lsname, le32_to_cpu(nodeid)); +} + +int nldlm_nl_get_cfg_doit(struct sk_buff *skb, struct genl_info *info) +{ + enum nldlm_log_level log_level =3D NLDLM_LOG_LEVEL_NONE; + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + struct sk_buff *msg; + void *hdr; + int rv; + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); + if (!msg) + return -ENOMEM; + + hdr =3D genlmsg_put(msg, info->snd_portid, info->snd_seq, + &nldlm_nl_family, 0, NLDLM_CMD_GET_CFG); + if (!hdr) { + nlmsg_free(msg); + return -EMSGSIZE; + } + + mutex_lock(&dn->cfg_lock); + if (dn->our_node) { + rv =3D nla_put_le32(msg, NLDLM_A_CFG_OUR_NODEID, + cpu_to_le32(dn->our_node->id)); + if (rv < 0) + goto err; + } + + rv =3D nla_put_string(msg, NLDLM_A_CFG_CLUSTER_NAME, + dn->config.ci_cluster_name); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_CFG_PROTOCOL, + dn->config.ci_protocol); + if (rv < 0) + goto err; + + rv =3D nla_put_be16(msg, NLDLM_A_CFG_PORT, + dn->config.ci_tcp_port); + if (rv < 0) + goto err; + + if (!dn->config.ci_log_info) + log_level =3D NLDLM_LOG_LEVEL_NONE; + else if (dn->config.ci_log_info) + log_level =3D NLDLM_LOG_LEVEL_INFO; + else if (dn->config.ci_log_debug) + log_level =3D NLDLM_LOG_LEVEL_DEBUG; + + rv =3D nla_put_u32(msg, NLDLM_A_CFG_LOG_LEVEL, log_level); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_CFG_RECOVER_TIMEOUT, + dn->config.ci_recover_timer); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_CFG_INACTIVE_TIMEOUT, + dn->config.ci_toss_secs); + if (rv < 0) + goto err; + + rv =3D nla_put_u32(msg, NLDLM_A_CFG_DEFAULT_MARK, + dn->config.ci_mark); + if (rv < 0) + goto err; + + if (dn->config.ci_recover_callbacks) { + rv =3D nla_put_flag(msg, NLDLM_A_CFG_RECOVER_CALLBACKS); + if (rv < 0) + goto err; + } + + mutex_unlock(&dn->cfg_lock); + genlmsg_end(msg, hdr); + return genlmsg_reply(msg, info); + +err: + mutex_unlock(&dn->cfg_lock); + genlmsg_cancel(msg, hdr); + nlmsg_free(msg); + return rv; +} + +int nldlm_nl_set_our_nodeid_doit(struct sk_buff *skb, struct genl_info *in= fo) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + __le32 nodeid; + + if (!info->attrs[NLDLM_A_CFG_OUR_NODEID]) + return -EINVAL; + + nodeid =3D nla_get_le32(info->attrs[NLDLM_A_CFG_OUR_NODEID]); + + return dlm_cfg_set_our_nodeid(dn, le32_to_cpu(nodeid)); +} + +int nldlm_nl_set_cluster_name_doit(struct sk_buff *skb, struct genl_info *= info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + + if (!info->attrs[NLDLM_A_CFG_CLUSTER_NAME]) + return -EINVAL; + + mutex_lock(&dn->cfg_lock); + nla_strscpy(dn->config.ci_cluster_name, + info->attrs[NLDLM_A_CFG_CLUSTER_NAME], + DLM_LOCKSPACE_LEN); + mutex_unlock(&dn->cfg_lock); + + return 0; +} + +int nldlm_nl_set_protocol_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + uint32_t protocol; + + if (!info->attrs[NLDLM_A_CFG_PROTOCOL]) + return -EINVAL; + + protocol =3D nla_get_u32(info->attrs[NLDLM_A_CFG_PROTOCOL]); + + return dlm_cfg_set_protocol(dn, protocol); +} + +int nldlm_nl_set_port_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + __be16 port; + + if (!info->attrs[NLDLM_A_CFG_PORT]) + return -EINVAL; + + port =3D nla_get_be16(info->attrs[NLDLM_A_CFG_PORT]); + + return dlm_cfg_set_port(dn, port); +} + +int nldlm_nl_set_recover_timeout_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + uint32_t secs; + + if (!info->attrs[NLDLM_A_CFG_RECOVER_TIMEOUT]) + return -EINVAL; + + secs =3D nla_get_u32(info->attrs[NLDLM_A_CFG_RECOVER_TIMEOUT]); + + return dlm_cfg_set_recover_timer(dn, secs); +} + +int nldlm_nl_set_inactive_timeout_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + uint32_t secs; + + if (!info->attrs[NLDLM_A_CFG_INACTIVE_TIMEOUT]) + return -EINVAL; + + secs =3D nla_get_u32(info->attrs[NLDLM_A_CFG_INACTIVE_TIMEOUT]); + + return dlm_cfg_set_toss_secs(dn, secs); +} + +int nldlm_nl_set_log_level_doit(struct sk_buff *skb, struct genl_info *inf= o) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + uint32_t level; + + if (!info->attrs[NLDLM_A_CFG_LOG_LEVEL]) + return -EINVAL; + + level =3D nla_get_u32(info->attrs[NLDLM_A_CFG_LOG_LEVEL]); + + switch (level) { + case NLDLM_LOG_LEVEL_NONE: + dlm_cfg_set_log_info(dn, 0); + dlm_cfg_set_log_debug(dn, 0); + break; + case NLDLM_LOG_LEVEL_INFO: + dlm_cfg_set_log_info(dn, 1); + dlm_cfg_set_log_debug(dn, 0); + break; + case NLDLM_LOG_LEVEL_DEBUG: + dlm_cfg_set_log_info(dn, 1); + dlm_cfg_set_log_debug(dn, 1); + break; + default: + return -EINVAL; + } + + return 0; +} + +int nldlm_nl_set_default_mark_doit(struct sk_buff *skb, struct genl_info *= info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + uint32_t mark; + + if (!info->attrs[NLDLM_A_CFG_DEFAULT_MARK]) + return -EINVAL; + + mark =3D nla_get_u32(info->attrs[NLDLM_A_CFG_DEFAULT_MARK]); + + return dlm_cfg_set_mark(dn, mark); +} + +int nldlm_nl_set_recover_callbacks_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct dlm_net *dn =3D dlm_pernet(sock_net(skb->sk)); + int flag; + + flag =3D nla_get_flag(info->attrs[NLDLM_A_CFG_RECOVER_CALLBACKS]); + + return dlm_cfg_set_recover_callbacks(dn, flag); +} + +int __init dlm_nldlm_init(void) +{ + return genl_register_family(&nldlm_nl_family); +} + +void dlm_nldlm_exit(void) +{ + genl_unregister_family(&nldlm_nl_family); +} diff --git a/include/uapi/linux/nldlm.h b/include/uapi/linux/nldlm.h new file mode 100644 index 000000000000..d169bfaa1ffa --- /dev/null +++ b/include/uapi/linux/nldlm.h @@ -0,0 +1,153 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/nldlm.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_NLDLM_H +#define _UAPI_LINUX_NLDLM_H + +#define NLDLM_FAMILY_NAME "nldlm" +#define NLDLM_FAMILY_VERSION 1 + +/** + * enum nldlm_protocol - The transport layer protocol that DLM will use. + */ +enum nldlm_protocol { + NLDLM_PROTOCOL_TCP, + NLDLM_PROTOCOL_SCTP, +}; + +/** + * enum nldlm_log_level - The internal DLM logger log-level. + * @NLDLM_LOG_LEVEL_NONE: disable all DLM logging + * @NLDLM_LOG_LEVEL_INFO: enable INFO log-level only + * @NLDLM_LOG_LEVEL_DEBUG: enable INFO and DEBUG log-level + */ +enum nldlm_log_level { + NLDLM_LOG_LEVEL_NONE, + NLDLM_LOG_LEVEL_INFO, + NLDLM_LOG_LEVEL_DEBUG, +}; + +/** + * enum nldlm_ls_ctrl_action - The lockspace control actions. Use in + * combination with ls-add-member and ls-del-member. First stop lockspace + * then update the members, then start the lockspace to trigger recovery= with + * new membership updates. + * @NLDLM_LS_CTRL_ACTION_STOP: stopping the lockspace + * @NLDLM_LS_CTRL_ACTION_START: starting the lockspace + */ +enum nldlm_ls_ctrl_action { + NLDLM_LS_CTRL_ACTION_STOP, + NLDLM_LS_CTRL_ACTION_START, +}; + +/** + * enum nldlm_ls_event_result - The result op of the lockspace event ntf-n= ew-ls + * and ntf-release-ls. The kernel is waiting for this reply when those e= vents + * occur. + * @NLDLM_LS_EVENT_RESULT_SUCCESS: the DLM kernel lockspace event action w= as + * successful + * @NLDLM_LS_EVENT_RESULT_FAILURE: the DLM kernel lockspace event action f= ailed + */ +enum nldlm_ls_event_result { + NLDLM_LS_EVENT_RESULT_SUCCESS, + NLDLM_LS_EVENT_RESULT_FAILURE, +}; + +enum { + NLDLM_A_CFG_OUR_NODEID =3D 1, + NLDLM_A_CFG_CLUSTER_NAME, + NLDLM_A_CFG_PROTOCOL, + NLDLM_A_CFG_PORT, + NLDLM_A_CFG_RECOVER_TIMEOUT, + NLDLM_A_CFG_INACTIVE_TIMEOUT, + NLDLM_A_CFG_LOG_LEVEL, + NLDLM_A_CFG_DEFAULT_MARK, + NLDLM_A_CFG_RECOVER_CALLBACKS, + + __NLDLM_A_CFG_MAX, + NLDLM_A_CFG_MAX =3D (__NLDLM_A_CFG_MAX - 1) +}; + +enum { + NLDLM_A_LS_NAME =3D 1, + + __NLDLM_A_LS_MAX, + NLDLM_A_LS_MAX =3D (__NLDLM_A_LS_MAX - 1) +}; + +enum { + NLDLM_A_LS_MEMBER_LS_NAME =3D 1, + NLDLM_A_LS_MEMBER_NODEID, + NLDLM_A_LS_MEMBER_WEIGHT, + + __NLDLM_A_LS_MEMBER_MAX, + NLDLM_A_LS_MEMBER_MAX =3D (__NLDLM_A_LS_MEMBER_MAX - 1) +}; + +enum { + NLDLM_A_LS_CTRL_LS_NAME =3D 1, + NLDLM_A_LS_CTRL_ACTION, + + __NLDLM_A_LS_CTRL_MAX, + NLDLM_A_LS_CTRL_MAX =3D (__NLDLM_A_LS_CTRL_MAX - 1) +}; + +enum { + NLDLM_A_LS_EVENT_RESULT_LS_NAME =3D 1, + NLDLM_A_LS_EVENT_RESULT_LS_GLOBAL_ID, + NLDLM_A_LS_EVENT_RESULT_RESULT, + + __NLDLM_A_LS_EVENT_RESULT_MAX, + NLDLM_A_LS_EVENT_RESULT_MAX =3D (__NLDLM_A_LS_EVENT_RESULT_MAX - 1) +}; + +enum { + NLDLM_A_NODE_ID =3D 1, + NLDLM_A_NODE_MARK, + NLDLM_A_NODE_ADDRS, + + __NLDLM_A_NODE_MAX, + NLDLM_A_NODE_MAX =3D (__NLDLM_A_NODE_MAX - 1) +}; + +enum { + NLDLM_A_ADDR_FAMILY =3D 1, + NLDLM_A_ADDR_ADDR4, + NLDLM_A_ADDR_ADDR6, + + __NLDLM_A_ADDR_MAX, + NLDLM_A_ADDR_MAX =3D (__NLDLM_A_ADDR_MAX - 1) +}; + +enum { + NLDLM_CMD_GET_NODE =3D 1, + NLDLM_CMD_ADD_NODE, + NLDLM_CMD_DEL_NODE, + NLDLM_CMD_GET_LS, + NLDLM_CMD_GET_LS_MEMBER, + NLDLM_CMD_LS_ADD_MEMBER, + NLDLM_CMD_LS_DEL_MEMBER, + NLDLM_CMD_LS_CTRL, + NLDLM_CMD_NTF_NEW_LS, + NLDLM_CMD_NTF_RELEASE_LS, + NLDLM_CMD_LS_EVENT_DONE, + NLDLM_CMD_GET_CFG, + NLDLM_CMD_SET_OUR_NODEID, + NLDLM_CMD_SET_CLUSTER_NAME, + NLDLM_CMD_SET_PROTOCOL, + NLDLM_CMD_SET_PORT, + NLDLM_CMD_SET_RECOVER_TIMEOUT, + NLDLM_CMD_SET_INACTIVE_TIMEOUT, + NLDLM_CMD_SET_LOG_LEVEL, + NLDLM_CMD_SET_DEFAULT_MARK, + NLDLM_CMD_SET_RECOVER_CALLBACKS, + + __NLDLM_CMD_MAX, + NLDLM_CMD_MAX =3D (__NLDLM_CMD_MAX - 1) +}; + +#define NLDLM_MCGRP_LS_EVENT "ls-event" + +#endif /* _UAPI_LINUX_NLDLM_H */ --=20 2.43.0 From nobody Thu Nov 28 16:50:54 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 009B91AD404 for ; Mon, 30 Sep 2024 20:14:46 +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=1727727289; cv=none; b=roajw75MRJP6L1ZvcbMwNMygmFw0rS0gCLwjKHngmxSya9fNVxfENANQKfFThTxxt9DG1UuRU501oPKWVoGIUDUS353WvkkZFqPIJfJDTOFPTajns91sgIuJXdMysQhAKJ4Z4AcqiyKWpjHiYg19rZYQ0JReTQwEoJtiu3/iV4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727727289; c=relaxed/simple; bh=IRo7YIBWvmWZSfbq3JDjRGZXVyg8r2TXLVMBFb95yFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AmACk5ZXDvtgrQxyvwv/SylhMGy9O8rUWeV4/haE74KH0qe3AmrAuIeWPY1si388jQ6uJWHHcfWBBCL2K8lYZmoepDjgPdgU4JcvT2G5TRU8OgnT6FLyr5/MgvhHuE3K50wmjVVaJfS6fHKAhCHOIEZfYn1iGLq3ipG0JzOHUcc= 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=Z74E5gDA; 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="Z74E5gDA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727727285; 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=UebUkHvPnMtBUbbevfLUYqoky+XpU/uj6FMG7w5VMyQ=; b=Z74E5gDA+JjejlZHrHVqPD+GnRtD2lShUIQA4qSYKF2CovrfEleGQDSl8sJtwPc5pXDdlN L+7yg/EfLZDNbEeISNdVEkXqQ1pQZhbPEgwV4xTmVRGy755gogHPVmnCC4LW8vJ6aoUKFC XxiC8OqrhkjBmGhPDYwyRg8Bk6G4ZyU= Received: from mx-prod-mc-05.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-612-0RCV3U_SO827I_4OGqQh-A-1; Mon, 30 Sep 2024 16:14:40 -0400 X-MC-Unique: 0RCV3U_SO827I_4OGqQh-A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 05F811955F09; Mon, 30 Sep 2024 20:14:38 +0000 (UTC) Received: from fs-i40c-03.mgmt.fast.eng.rdu2.dc.redhat.com (unknown [10.6.24.150]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 96A921955DC7; Mon, 30 Sep 2024 20:14:35 +0000 (UTC) From: Alexander Aring To: teigland@redhat.com Cc: gfs2@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, agruenba@redhat.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, ocfs2-devel@lists.linux.dev, netdev@vger.kernel.org, vvidic@valentin-vidic.from.hr, heming.zhao@suse.com, lucien.xin@gmail.com, donald.hunter@gmail.com, aahringo@redhat.com Subject: [PATCHv2 dlm/next 12/12] gfs2: separate mount context by net-namespaces Date: Mon, 30 Sep 2024 16:13:58 -0400 Message-ID: <20240930201358.2638665-13-aahringo@redhat.com> In-Reply-To: <20240930201358.2638665-1-aahringo@redhat.com> References: <20240930201358.2638665-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 changes gfs2 to be the first user of the recently introduced net-namespace feature of DLM. It uses the current net-namespace context of the get_tree() callback of "struct fs_context_operations" that is e.g. being called by syscalls of the coreutils mount process. Debugfs is being disabled for non "init_net" net-namespaces as debugfs is not net-namespace aware. Otherwise we would see kernel log error messages about existing debugfs entries. There might be in future another ways to get similar information with an UAPI mechanism that is namespace aware. With this patch you can setup a cluster in one machine without using multiple Linux kernel instances. The idea is to use this for developing/testing as a first use-case. Especially scale testing, a gfs2 file system with a lot of members can be setup without running a large set of virtual machines. There is a small example script how it works: https://gitlab.com/netcoder/gfs2ns-examples/-/blob/main/three_nodes it uses multiple loop block devices references to the same file to provide a kind of shared block device (an alternative could be using dm linear mapping, but loop block device also works). After setting up multiple net-namespaces with a virtual bridge interface DLM can be configured by using nldlmd that is using the recently introduced net-namespace aware nldlm netlink API. Over a shell command like: ip netns exec node1 sh -c "mount /dev/loop1 /cluster/node1" ip netns exec node2 sh -c "mount /dev/loop2 /cluster/node2" ... every cluster "node" (hereby identifier with a "node#" string in the iproute2 namespace management mechanism) can mount the shared block device e.g. /dev/loop1, /dev/loop# that references to the same block image on a different file system. Note that the caller in the script will be unmount the file system if the last user left the namespace. I currently workaround this use case by mountbind each block device again in a kind of "default" namespace (usually it should be where "init_net" references to). Then each mountpoint of "/cluster/node#" acts like being a cluster node access to the gfs2 file system with DLM locking enabled. This offers us new possibilities to write testcases as we operate on a single machine and can "easier" synchronize vfs syscalls in our testcase as no "remote machine" kind network communication is being involved. The mount sysfs directory for gfs2 needs to be separated by net-namespace as our mount call is from namespace view separated and be treated as per "node" (machine) call. Otherwise we would run into conflicts on files/directories that already exists as the cluster wide unique identifiers are already being in use. The gfs2 file system has some global variables and it seems it is not necessary to separate them by net-namespace as they store a unique per mount identifier. I didn't had problems yet and it seems it is currently okay to do that, otherwise there might be issues with "things" that are not net-namespace aware in gfs2 yet. However we only should find issues only when we using net-namespaces. If a user only uses "init_net" as this is the current default, there should not be any problems. Signed-off-by: Alexander Aring --- fs/gfs2/glock.c | 8 ++++++++ fs/gfs2/incore.h | 2 ++ fs/gfs2/lock_dlm.c | 2 +- fs/gfs2/ops_fstype.c | 5 +++++ fs/gfs2/sys.c | 35 ++++++++++++++++++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 269c3bc7fced..8c2d715485ef 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2901,6 +2901,10 @@ DEFINE_SEQ_ATTRIBUTE(gfs2_sbstats); =20 void gfs2_create_debugfs_file(struct gfs2_sbd *sdp) { + /* debugfs is only available for init_net users */ + if (!net_eq(read_pnet(&sdp->net), &init_net)) + return; + sdp->debugfs_dir =3D debugfs_create_dir(sdp->sd_table_name, gfs2_root); =20 debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, @@ -2918,6 +2922,10 @@ void gfs2_create_debugfs_file(struct gfs2_sbd *sdp) =20 void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp) { + /* debugfs is only available for init_net users */ + if (!net_eq(read_pnet(&sdp->net), &init_net)) + return; + debugfs_remove_recursive(sdp->debugfs_dir); sdp->debugfs_dir =3D NULL; } diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index aa4ef67a34e0..1273ef3dbef5 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -710,6 +710,8 @@ struct gfs2_sbd { =20 /* Lock Stuff */ =20 + possible_net_t net; + netns_tracker tracker; /* keep track of net references */ struct lm_lockstruct sd_lockstruct; struct gfs2_holder sd_live_gh; struct gfs2_glock *sd_rename_gl; diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c index 6c5dce57a2ee..d8e1bb99dac2 100644 --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c @@ -1328,7 +1328,7 @@ static int gdlm_mount(struct gfs2_sbd *sdp, const cha= r *table) * create/join lockspace */ =20 - error =3D dlm_new_lockspace(&init_net, fsname, cluster, flags, + error =3D dlm_new_lockspace(read_pnet(&sdp->net), fsname, cluster, flags, GDLM_LVB_SIZE, &gdlm_lockspace_ops, sdp, &ops_result, &ls->ls_dlm); if (error) { diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e83d293c3614..62555fd33210 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -64,6 +64,8 @@ static void gfs2_tune_init(struct gfs2_tune *gt) =20 void free_sbd(struct gfs2_sbd *sdp) { + put_net_track(read_pnet(&sdp->net), &sdp->tracker); + if (sdp->sd_lkstats) free_percpu(sdp->sd_lkstats); kfree(sdp); @@ -71,6 +73,7 @@ void free_sbd(struct gfs2_sbd *sdp) =20 static struct gfs2_sbd *init_sbd(struct super_block *sb) { + struct net *net =3D current->nsproxy->net_ns; struct gfs2_sbd *sdp; struct address_space *mapping; =20 @@ -78,6 +81,8 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) if (!sdp) return NULL; =20 + /* store the net-namespace the sdp is created into */ + write_pnet(&sdp->net, get_net_track(net, &sdp->tracker, GFP_KERNEL)); sdp->sd_vfs =3D sb; sdp->sd_lkstats =3D alloc_percpu(struct gfs2_pcpu_lkstats); if (!sdp->sd_lkstats) diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c index ecc699f8d9fc..20d1d1fed189 100644 --- a/fs/gfs2/sys.c +++ b/fs/gfs2/sys.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include "gfs2.h" #include "incore.h" @@ -57,6 +58,24 @@ static const struct sysfs_ops gfs2_attr_ops =3D { =20 static struct kset *gfs2_kset; =20 +#if IS_ENABLED(CONFIG_NET) +/* gfs2 sysfs is separated by net-namespaces */ +static const struct kobj_ns_type_operations * +gfs2_sysfs_object_child_ns_type(const struct kobject *kobj) +{ + return &net_ns_type_operations; +} +#endif + +static const struct kobj_type gfs2_kset_ktype =3D { + .sysfs_ops =3D &kobj_sysfs_ops, + .release =3D kset_release, + .get_ownership =3D kset_get_ownership, +#if IS_ENABLED(CONFIG_NET) + .child_ns_type =3D gfs2_sysfs_object_child_ns_type, +#endif +}; + static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) { return snprintf(buf, PAGE_SIZE, "%u:%u\n", @@ -383,10 +402,23 @@ static void gfs2_sbd_release(struct kobject *kobj) complete(&sdp->sd_kobj_unregister); } =20 +#if IS_ENABLED(CONFIG_NET) +/* return the net-namespace the kobj belonging to */ +static const void *gfs2_kobj_namespace(const struct kobject *kobj) +{ + struct gfs2_sbd *sdp =3D container_of(kobj, struct gfs2_sbd, sd_kobj); + + return read_pnet(&sdp->net); +} +#endif + static struct kobj_type gfs2_ktype =3D { .release =3D gfs2_sbd_release, .default_groups =3D gfs2_groups, .sysfs_ops =3D &gfs2_attr_ops, +#if IS_ENABLED(CONFIG_NET) + .namespace =3D gfs2_kobj_namespace, +#endif }; =20 =20 @@ -797,7 +829,8 @@ static const struct kset_uevent_ops gfs2_uevent_ops =3D= { =20 int gfs2_sys_init(void) { - gfs2_kset =3D kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj); + gfs2_kset =3D kset_type_create_and_add("gfs2", &gfs2_uevent_ops, + fs_kobj, &gfs2_kset_ktype); if (!gfs2_kset) return -ENOMEM; return 0; --=20 2.43.0