Skip to content

Commit

Permalink
scsi: target: Remove se_dev_entry.ua_count
Browse files Browse the repository at this point in the history
se_dev_entry.ua_count is only used to check whether or not
se_dev_entry.ua_list is empty. Use list_empty_careful() instead.  Checking
whether or not ua_list is empty without holding the lock that protects that
list is fine because the code that dequeues from that list will check again
whether or not that list is empty.

Signed-off-by: Bart Van Assche <[email protected]>
Reviewed-by: Mike Christie <[email protected]>
Cc: Mike Christie <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
KAGA-KOKO authored and martinkpetersen committed Jul 2, 2018
1 parent 325c1e8 commit e936a38
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
1 change: 0 additions & 1 deletion drivers/target/target_core_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ int core_enable_device_list_for_node(
return -ENOMEM;
}

atomic_set(&new->ua_count, 0);
spin_lock_init(&new->ua_lock);
INIT_LIST_HEAD(&new->ua_list);
INIT_LIST_HEAD(&new->lun_link);
Expand Down
12 changes: 2 additions & 10 deletions drivers/target/target_core_ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_scsi3_ua_check(struct se_cmd *cmd)
rcu_read_unlock();
return 0;
}
if (!atomic_read(&deve->ua_count)) {
if (list_empty_careful(&deve->ua_list)) {
rcu_read_unlock();
return 0;
}
Expand Down Expand Up @@ -154,7 +154,6 @@ int core_scsi3_ua_allocate(
&deve->ua_list);
spin_unlock(&deve->ua_lock);

atomic_inc_mb(&deve->ua_count);
return 0;
}
list_add_tail(&ua->ua_nacl_list, &deve->ua_list);
Expand All @@ -164,7 +163,6 @@ int core_scsi3_ua_allocate(
" 0x%02x, ASCQ: 0x%02x\n", deve->mapped_lun,
asc, ascq);

atomic_inc_mb(&deve->ua_count);
return 0;
}

Expand Down Expand Up @@ -196,8 +194,6 @@ void core_scsi3_ua_release_all(
list_for_each_entry_safe(ua, ua_p, &deve->ua_list, ua_nacl_list) {
list_del(&ua->ua_nacl_list);
kmem_cache_free(se_ua_cache, ua);

atomic_dec_mb(&deve->ua_count);
}
spin_unlock(&deve->ua_lock);
}
Expand Down Expand Up @@ -263,8 +259,6 @@ bool core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *key, u8 *asc,
}
list_del(&ua->ua_nacl_list);
kmem_cache_free(se_ua_cache, ua);

atomic_dec_mb(&deve->ua_count);
}
spin_unlock(&deve->ua_lock);
rcu_read_unlock();
Expand Down Expand Up @@ -304,7 +298,7 @@ int core_scsi3_ua_clear_for_request_sense(
rcu_read_unlock();
return -EINVAL;
}
if (!atomic_read(&deve->ua_count)) {
if (list_empty_careful(&deve->ua_list)) {
rcu_read_unlock();
return -EPERM;
}
Expand All @@ -327,8 +321,6 @@ int core_scsi3_ua_clear_for_request_sense(
}
list_del(&ua->ua_nacl_list);
kmem_cache_free(se_ua_cache, ua);

atomic_dec_mb(&deve->ua_count);
}
spin_unlock(&deve->ua_lock);
rcu_read_unlock();
Expand Down
1 change: 0 additions & 1 deletion include/target/target_core_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ struct se_dev_entry {
atomic_long_t total_cmds;
atomic_long_t read_bytes;
atomic_long_t write_bytes;
atomic_t ua_count;
/* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
struct kref pr_kref;
struct completion pr_comp;
Expand Down

0 comments on commit e936a38

Please sign in to comment.