netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
To: Joel Becker <jlbec-aKy9MeLSZ9dg9hUCZPvPmw@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>,
	Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pratyush Anand
	<pratyush.anand-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	cluster-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	ocfs2-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 21/23] ocfs2/cluster: move locking into attribute store methods
Date: Fri, 25 Sep 2015 06:49:58 -0700	[thread overview]
Message-ID: <1443189000-13398-22-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1443189000-13398-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>

The test and separate set bit scheme was racy to start with, so move to do
a test_and_set_bit after doing the earlier error checks inside the actual
store methods.  Also remove the locking for the local attribute which
already has a different scheme to synchronize.

Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
---
 fs/ocfs2/cluster/nodemanager.c | 54 +++++++++++++++---------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)

diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c
index 441c84e..7a398f6 100644
--- a/fs/ocfs2/cluster/nodemanager.c
+++ b/fs/ocfs2/cluster/nodemanager.c
@@ -188,7 +188,6 @@ enum {
 	O2NM_NODE_ATTR_NUM = 0,
 	O2NM_NODE_ATTR_PORT,
 	O2NM_NODE_ATTR_ADDRESS,
-	O2NM_NODE_ATTR_LOCAL,
 };
 
 static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
@@ -197,6 +196,7 @@ static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
 	struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
 	unsigned long tmp;
 	char *p = (char *)page;
+	int ret = 0;
 
 	tmp = simple_strtoul(p, &p, 0);
 	if (!p || (*p && (*p != '\n')))
@@ -215,15 +215,18 @@ static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
 
 	write_lock(&cluster->cl_nodes_lock);
 	if (cluster->cl_nodes[tmp])
-		p = NULL;
+		ret = -EEXIST;
+	else if (test_and_set_bit(O2NM_NODE_ATTR_NUM,
+			&node->nd_set_attributes))
+		ret = -EBUSY;
 	else  {
 		cluster->cl_nodes[tmp] = node;
 		node->nd_num = tmp;
 		set_bit(tmp, cluster->cl_nodes_bitmap);
 	}
 	write_unlock(&cluster->cl_nodes_lock);
-	if (p == NULL)
-		return -EEXIST;
+	if (ret)
+		return ret;
 
 	return count;
 }
@@ -247,6 +250,8 @@ static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node,
 	if (tmp >= (u16)-1)
 		return -ERANGE;
 
+	if (test_and_set_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
+		return -EBUSY;
 	node->nd_ipv4_port = htons(tmp);
 
 	return count;
@@ -282,6 +287,9 @@ static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,
 	write_lock(&cluster->cl_nodes_lock);
 	if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
 		ret = -EEXIST;
+	else if (test_and_set_bit(O2NM_NODE_ATTR_ADDRESS,
+			&node->nd_set_attributes))
+		ret = -EBUSY;
 	else {
 		rb_link_node(&node->nd_ip_node, parent, p);
 		rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
@@ -388,24 +396,13 @@ static struct o2nm_node_attribute o2nm_node_attr_local = {
 };
 
 static struct configfs_attribute *o2nm_node_attrs[] = {
-	[O2NM_NODE_ATTR_NUM] = &o2nm_node_attr_num.attr,
-	[O2NM_NODE_ATTR_PORT] = &o2nm_node_attr_ipv4_port.attr,
-	[O2NM_NODE_ATTR_ADDRESS] = &o2nm_node_attr_ipv4_address.attr,
-	[O2NM_NODE_ATTR_LOCAL] = &o2nm_node_attr_local.attr,
+	&o2nm_node_attr_num.attr,
+	&o2nm_node_attr_ipv4_port.attr,
+	&o2nm_node_attr_ipv4_address.attr,
+	&o2nm_node_attr_local.attr,
 	NULL,
 };
 
-static int o2nm_attr_index(struct configfs_attribute *attr)
-{
-	int i;
-	for (i = 0; i < ARRAY_SIZE(o2nm_node_attrs); i++) {
-		if (attr == o2nm_node_attrs[i])
-			return i;
-	}
-	BUG();
-	return 0;
-}
-
 static ssize_t o2nm_node_show(struct config_item *item,
 			      struct configfs_attribute *attr,
 			      char *page)
@@ -427,24 +424,11 @@ static ssize_t o2nm_node_store(struct config_item *item,
 	struct o2nm_node *node = to_o2nm_node(item);
 	struct o2nm_node_attribute *o2nm_node_attr =
 		container_of(attr, struct o2nm_node_attribute, attr);
-	ssize_t ret;
-	int attr_index = o2nm_attr_index(attr);
 
-	if (o2nm_node_attr->store == NULL) {
-		ret = -EINVAL;
-		goto out;
-	}
-
-	if (test_bit(attr_index, &node->nd_set_attributes))
-		return -EBUSY;

  parent reply	other threads:[~2015-09-25 13:49 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 13:49 simplify configfs attributes Christoph Hellwig
2015-09-25 13:49 ` [PATCH 01/23] configfs: add show and store methods to struct configfs_attribute Christoph Hellwig
2015-09-25 14:28   ` Tejun Heo
2015-09-25 17:41     ` Greg KH
2015-09-26 23:38   ` Nicholas A. Bellinger
2015-09-25 13:49 ` [PATCH 02/23] usb-gadget: use per-attribute show and store methods Christoph Hellwig
2015-09-27 15:47   ` Felipe Balbi
     [not found]     ` <20150927154752.GC16364-HgARHv6XitJaoMGHk7MhZQC/G2K4zDHf@public.gmane.org>
2015-09-28 13:33       ` Christoph Hellwig
     [not found]         ` <20150928133328.GA30453-jcswGhMUV9g@public.gmane.org>
2015-10-01 17:23           ` Felipe Balbi
2015-09-27 15:50   ` Felipe Balbi
2015-09-28 13:35     ` Christoph Hellwig
2015-09-30 16:19       ` Felipe Balbi
2015-09-30 16:20         ` Tejun Heo
2015-09-30 16:32           ` Felipe Balbi
2015-09-30 16:35             ` Tejun Heo
2015-09-30 16:43               ` Felipe Balbi
2015-09-30 16:59                 ` Tejun Heo
     [not found]   ` <1443189000-13398-3-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2015-09-28 10:54     ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 03/23] usb-gadget/uvc: " Christoph Hellwig
     [not found]   ` <1443189000-13398-4-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2015-09-28 11:35     ` Andrzej Pietrasiewicz
2015-09-28 13:39       ` Christoph Hellwig
2015-09-25 13:49 ` [PATCH 04/23] usb-gadget/f_hid: " Christoph Hellwig
2015-09-28 11:37   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 05/23] usb-gadget/f_acm: " Christoph Hellwig
2015-09-28 11:39   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 06/23] usb-gadget/ether: " Christoph Hellwig
     [not found]   ` <1443189000-13398-7-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2015-09-28 11:40     ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 08/23] usb-gadget/f_midi: " Christoph Hellwig
     [not found]   ` <1443189000-13398-9-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2015-09-28 11:47     ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 09/23] usb-gadget/f_printer: " Christoph Hellwig
2015-09-28 11:50   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 10/23] usb-gadget/f_sourcesink: " Christoph Hellwig
2015-09-28 11:51   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 11/23] usb-gadget/f_mass_storage: " Christoph Hellwig
2015-09-28 11:53   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 12/23] usb-gadget/f_ac1: " Christoph Hellwig
2015-09-28 11:56   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 13/23] usb-gadget/f_uac2: " Christoph Hellwig
2015-09-28 11:56   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 14/23] usb-gadget/f_obex: " Christoph Hellwig
2015-09-28 11:57   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 15/23] usb-gadget/f_phonet: " Christoph Hellwig
2015-09-28 11:59   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 16/23] usb-gadget/f_serial: " Christoph Hellwig
2015-09-28 11:59   ` Andrzej Pietrasiewicz
2015-09-25 13:49 ` [PATCH 17/23] dlm: " Christoph Hellwig
2015-09-28 14:49   ` David Teigland
2015-09-25 13:49 ` [PATCH 18/23] spear13xx_pcie_gadget: " Christoph Hellwig
2015-09-25 13:49 ` [PATCH 19/23] target: " Christoph Hellwig
2015-09-26 23:35   ` Nicholas A. Bellinger
     [not found] ` <1443189000-13398-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2015-09-25 13:49   ` [PATCH 07/23] usb-gadget/f_loopback: " Christoph Hellwig
2015-09-28 11:46     ` Andrzej Pietrasiewicz
2015-09-28 13:41       ` Christoph Hellwig
2015-09-28 13:52         ` Andrzej Pietrasiewicz
2015-09-25 13:49   ` [PATCH 20/23] netconsole: " Christoph Hellwig
2015-09-25 13:49   ` Christoph Hellwig [this message]
2015-09-25 13:57   ` simplify configfs attributes Christoph Hellwig
2015-09-25 13:49 ` [PATCH 22/23] ocfs2/cluster: use per-attribute show and store methods Christoph Hellwig
2015-09-25 13:50 ` [PATCH 23/23] configfs: remove old API Christoph Hellwig
2015-09-28 12:06   ` Andrzej Pietrasiewicz
2015-09-28 13:42     ` Christoph Hellwig
2015-09-26 23:49 ` simplify configfs attributes Nicholas A. Bellinger
2015-09-27  6:30   ` Christoph Hellwig
2015-09-28 12:12 ` Andrzej Pietrasiewicz
  -- strict thread matches above, loose matches on Subject: below --
2015-10-03 13:32 simplify configfs attributes V2 Christoph Hellwig
2015-10-03 13:32 ` [PATCH 21/23] ocfs2/cluster: move locking into attribute store methods Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443189000-13398-22-git-send-email-hch@lst.de \
    --to=hch-jcswghmuv9g@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=balbi-l0cyMroinI0@public.gmane.org \
    --cc=cluster-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=jlbec-aKy9MeLSZ9dg9hUCZPvPmw@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=ocfs2-devel-N0ozoZBvEnrZJqsBc5GL+g@public.gmane.org \
    --cc=pratyush.anand-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).