diff --git a/scst/include/scst.h b/scst/include/scst.h index 911e22a4d..1c38ce2fc 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -3161,7 +3161,7 @@ struct scst_tgt_dev { */ int tgt_dev_dif_guard_format; - /* One more than the number of commands associated with this tgt_dev. */ + /* How many cmds alive on this dev in this session */ atomic_t tgt_dev_cmd_count ____cacheline_aligned_in_smp; /* ALUA command filter */ @@ -4781,7 +4781,7 @@ static inline int scst_cmd_get_block_size(struct scst_cmd *cmd) static inline unsigned int scst_get_active_cmd_count(struct scst_cmd *cmd) { if (likely(cmd->tgt_dev != NULL)) - return atomic_read(&cmd->tgt_dev->tgt_dev_cmd_count) - 1; + return atomic_read(&cmd->tgt_dev->tgt_dev_cmd_count); else return (unsigned int)-1; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index f3b4a2b4a..62a7197ed 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5359,7 +5359,7 @@ static int scst_alloc_add_tgt_dev(struct scst_session *sess, atomic_set(&tgt_dev->tgt_dev_dif_guard_failed_dev, 0); tgt_dev->sess = sess; - atomic_set(&tgt_dev->tgt_dev_cmd_count, 1); + atomic_set(&tgt_dev->tgt_dev_cmd_count, 0); if (acg_dev->acg->acg_black_hole_type != SCST_ACG_BLACK_HOLE_NONE) set_bit(SCST_TGT_DEV_BLACK_HOLE, &tgt_dev->tgt_dev_flags); else @@ -5538,8 +5538,6 @@ static void scst_del_tgt_dev(struct scst_tgt_dev *tgt_dev) list_del_rcu(&tgt_dev->sess_tgt_dev_list_entry); scst_tgt_dev_sysfs_del(tgt_dev); - - atomic_dec(&tgt_dev->tgt_dev_cmd_count); } /* diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 68446a6b3..b3022c644 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -607,7 +607,7 @@ static void scst_pr_abort_reg(struct scst_device *dev, TRACE_PR("Aborting %d commands for %s/%d (reg %p, key 0x%016llx, " "tgt_dev %p, sess %p)", - atomic_read(®->tgt_dev->tgt_dev_cmd_count) - 1, + atomic_read(®->tgt_dev->tgt_dev_cmd_count), debug_transport_id_to_initiator_name(reg->transport_id), reg->rel_tgt_id, reg, be64_to_cpu(reg->key), reg->tgt_dev, sess); diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 251587150..c756c39b9 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -4154,8 +4154,7 @@ static ssize_t scst_tgt_dev_active_commands_show(struct kobject *kobj, tgt_dev = container_of(kobj, struct scst_tgt_dev, tgt_dev_kobj); - pos = sprintf(buf, "%d\n", - atomic_read(&tgt_dev->tgt_dev_cmd_count) - 1); + pos = sprintf(buf, "%d\n", atomic_read(&tgt_dev->tgt_dev_cmd_count)); return pos; } @@ -4489,7 +4488,6 @@ static int scst_sysfs_sess_get_active_commands(struct scst_session *sess) list_for_each_entry_rcu(tgt_dev, head, sess_tgt_dev_list_entry) { active_cmds += atomic_read(&tgt_dev->tgt_dev_cmd_count); - active_cmds--; } } rcu_read_unlock(); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 10ee242f0..82b9bfc1a 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -5027,9 +5027,8 @@ static int scst_translate_lun(struct scst_cmd *cmd) rcu_read_lock(); tgt_dev = scst_lookup_tgt_dev(cmd->sess, cmd->lun); - if (tgt_dev && - !atomic_inc_not_zero(&tgt_dev->tgt_dev_cmd_count)) - tgt_dev = NULL; + if (tgt_dev) + atomic_inc(&tgt_dev->tgt_dev_cmd_count); rcu_read_unlock(); if (tgt_dev) {