diff options
author | Bart Van Assche <bvanassche@acm.org> | 2014-03-14 13:52:45 +0100 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2014-03-24 10:05:31 -0700 |
commit | 2d7091bcf6f893a9b1a2add357c637055eae4e68 (patch) | |
tree | 10af70bb397f7c23f3d6f581a37a1a557d53abbd /drivers/infiniband/ulp/srp/ib_srp.c | |
parent | e7ffde0164b1a580f66ea3b95081626107931d3c (diff) | |
download | op-kernel-dev-2d7091bcf6f893a9b1a2add357c637055eae4e68.zip op-kernel-dev-2d7091bcf6f893a9b1a2add357c637055eae4e68.tar.gz |
IB/srp: Avoid duplicate connections
The connection uniqueness check is performed before a new connection
is added to the target list. This patch protects both actions by a
mutex such that simultaneous writes from two different threads into the
"add_target" variable do not result in duplicate connections.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Roland Dreier <roland@purestorage.com>
Diffstat (limited to 'drivers/infiniband/ulp/srp/ib_srp.c')
-rw-r--r-- | drivers/infiniband/ulp/srp/ib_srp.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 2ec9c05..3294f10 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -2614,6 +2614,8 @@ static ssize_t srp_create_target(struct device *dev, target->tl_retry_count = 7; target->queue_size = SRP_DEFAULT_QUEUE_SIZE; + mutex_lock(&host->add_target_mutex); + ret = srp_parse_options(buf, target); if (ret) goto err; @@ -2682,7 +2684,11 @@ static ssize_t srp_create_target(struct device *dev, be64_to_cpu(target->service_id), target->path.sgid.raw, target->path.dgid.raw); - return count; + ret = count; + +out: + mutex_unlock(&host->add_target_mutex); + return ret; err_disconnect: srp_disconnect_target(target); @@ -2698,8 +2704,7 @@ err_free_mem: err: scsi_host_put(target_host); - - return ret; + goto out; } static DEVICE_ATTR(add_target, S_IWUSR, NULL, srp_create_target); @@ -2735,6 +2740,7 @@ static struct srp_host *srp_add_port(struct srp_device *device, u8 port) INIT_LIST_HEAD(&host->target_list); spin_lock_init(&host->target_lock); init_completion(&host->released); + mutex_init(&host->add_target_mutex); host->srp_dev = device; host->port = port; |