From de285c9c59deafbf15a5930b5e909848f7dcdbf9 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 24 Jul 2009 18:13:33 +0000 Subject: [PATCH] Merge of r967-969: Patch from Smadar Gonen Implements some useful scst_user statistic in /proc Minor fixes and cleanups Bart Van Assche : Whitespace-only changes: fixed two recently introduced checkpatch errors (code should be indented by tabs / trailing whitespace). git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/1.0.1.x@973 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_user.c | 54 +++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 4370d5133..ef2b3fec8 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -196,6 +196,8 @@ static unsigned int dev_user_poll(struct file *filp, poll_table *wait); static long dev_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg); static int dev_user_release(struct inode *inode, struct file *file); +static int dev_user_read_proc(struct seq_file *seq, + struct scst_dev_type *dev_type); /** Data **/ @@ -1553,7 +1555,7 @@ static int dev_user_get_ext_cdb(struct file *file, void __user *arg) int res = 0; struct scst_user_dev *dev; struct scst_user_cmd *ucmd; - struct scst_cmd *cmd; + struct scst_cmd *cmd = NULL; struct scst_user_get_ext_cdb get; TRACE_ENTRY(); @@ -1599,7 +1601,7 @@ static int dev_user_get_ext_cdb(struct file *file, void __user *arg) TRACE_MGMT_DBG("Invalid ucmd state %d for cmd_h %d", ucmd->state, get.cmd_h); res = -EINVAL; - goto out_put; + goto out_unlock; } spin_unlock_irq(&dev->cmd_lists.cmd_list_lock); @@ -2975,12 +2977,13 @@ static int dev_user_set_opt(struct file *file, const struct scst_user_opt *opt) res = scst_suspend_activity(true); if (res != 0) - goto out; + goto out_up; res = __dev_user_set_opt(dev, opt); scst_resume_activity(); +out_up: up_read(&dev->dev_rwsem); out: @@ -3043,6 +3046,7 @@ static int dev_usr_parse(struct scst_cmd *cmd) .name = DEV_USER_NAME, \ .type = -1, \ .parse = dev_usr_parse, \ + .read_proc = dev_user_read_proc, \ } static struct scst_dev_type dev_user_devtype = USR_TYPE; @@ -3086,7 +3090,7 @@ static int dev_user_release(struct inode *inode, struct file *file) sgv_pool_flush(dev->pool_clust); sgv_pool_flush(dev->pool); - TRACE_DBG("Unregistering finished (dev %p)", dev); + TRACE_MGMT_DBG("Unregistering finished (dev %p)", dev); dev->cleanup_done = 1; @@ -3098,9 +3102,9 @@ static int dev_user_release(struct inode *inode, struct file *file) sgv_pool_destroy(dev->pool_clust); sgv_pool_destroy(dev->pool); - up_write(&dev->dev_rwsem); /* to make the debug check happy */ + up_write(&dev->dev_rwsem); /* to make lockdep happy */ - TRACE_DBG("Releasing completed (dev %p)", dev); + TRACE_MGMT_DBG("Releasing completed (dev %p)", dev); kfree(dev); @@ -3172,6 +3176,44 @@ out: return res; } +/* + * Called when a file in the /proc/scsi_tgt/scst_user is read + */ +static int dev_user_read_proc(struct seq_file *seq, struct scst_dev_type *dev_type) +{ + int res = 0; + struct scst_user_dev *dev; + unsigned long flags; + + TRACE_ENTRY(); + + spin_lock(&dev_list_lock); + + list_for_each_entry(dev, &dev_list, dev_list_entry) { + int i; + seq_printf(seq, "Device %s commands:\n", dev->name); + spin_lock_irqsave(&dev->cmd_lists.cmd_list_lock, flags); + for (i = 0; i < (int)ARRAY_SIZE(dev->ucmd_hash); i++) { + struct list_head *head = &dev->ucmd_hash[i]; + struct scst_user_cmd *ucmd; + list_for_each_entry(ucmd, head, hash_list_entry) { + seq_printf(seq, "ucmd %p (state %x, ref %d), " + "sent_to_user %d, seen_by_user %d, " + "aborted %d, jammed %d, scst_cmd %p\n", + ucmd, ucmd->state, + atomic_read(&ucmd->ucmd_ref), + ucmd->sent_to_user, ucmd->seen_by_user, + ucmd->aborted, ucmd->jammed, ucmd->cmd); + } + } + spin_unlock_irqrestore(&dev->cmd_lists.cmd_list_lock, flags); + } + spin_unlock(&dev_list_lock); + + TRACE_EXIT_RES(res); + return res; +} + static inline int test_cleanup_list(void) { int res = !list_empty(&cleanup_list) ||