diff --git a/scst/include/scst.h b/scst/include/scst.h index 2079e8142..ecc4e6361 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -3156,7 +3156,7 @@ struct scst_tgt_dev { */ int tgt_dev_dif_guard_format; - /* How many cmds alive on this dev in this session */ + /* One more than the number of commands associated with this tgt_dev. */ atomic_t tgt_dev_cmd_count ____cacheline_aligned_in_smp; /* ALUA command filter */ @@ -4776,7 +4776,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); + return atomic_read(&cmd->tgt_dev->tgt_dev_cmd_count) - 1; else return (unsigned int)-1; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 20a7ffe8c..abf9c1db3 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5373,7 +5373,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, 0); + atomic_set(&tgt_dev->tgt_dev_cmd_count, 1); 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 @@ -5552,6 +5552,8 @@ 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 b3022c644..68446a6b3 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), + atomic_read(®->tgt_dev->tgt_dev_cmd_count) - 1, 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 33710e4b5..65a1aa9f6 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -4152,7 +4152,8 @@ 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)); + pos = sprintf(buf, "%d\n", + atomic_read(&tgt_dev->tgt_dev_cmd_count) - 1); return pos; } @@ -4486,6 +4487,7 @@ 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();