All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] staging: unisys: added virtpci info entry
@ 2014-07-09 20:22 Erik Arfvidson
  2014-07-09 20:40 ` Greg KH
  2014-07-09 20:41 ` Greg KH
  0 siblings, 2 replies; 11+ messages in thread
From: Erik Arfvidson @ 2014-07-09 20:22 UTC (permalink / raw)
  To: gregkh, sparmaintainer, driverdev-devel, benjamin.romer; +Cc: Erik Arfvidson

This patch adds the virtpci debugfs directory and the info entry
inside of it.

Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
---
 drivers/staging/unisys/virtpci/virtpci.c | 123 ++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index 7d840b0..68fbe85 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -37,6 +37,7 @@
 #include <linux/if_ether.h>
 #include <linux/version.h>
 #include "version.h"
+ #include <linux/debugfs.h>
 #include "guestlinuxdebug.h"
 #include "timskmodutils.h"
 
@@ -100,6 +101,12 @@ static int virtpci_device_resume(struct device *dev);
 static int virtpci_device_probe(struct device *dev);
 static int virtpci_device_remove(struct device *dev);
 
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset);
+
+static const struct file_operations debugfs_info_fops = {
+	.read = info_debugfs_read,
+};
 
 /*****************************************************/
 /* Globals                                           */
@@ -139,7 +146,19 @@ static DEFINE_RWLOCK(VpcidevListLock);
 
 /* filled in with info about this driver, wrt it servicing client busses */
 static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo;
-
+/*****************************************************/
+/* DebugFS entries                                   */
+/*****************************************************/
+/* dentry is used to create the debugfs entry directory
+ * for virtpci
+ */
+static struct dentry *virtpci_debugfs_dir;
+static struct dentry *info_debugfs_entry;
+/* info_debugfs_entry is used to tell virtpci to display current info
+ * kept in the driver
+ */
+#define DIR_DEBUGFS_ENTRY "virtpci"
+#define INFO_DEBUGFS_ENTRY_FN "info"
 
 struct virtpci_busdev {
 	struct device virtpci_bus_device;
@@ -588,7 +607,8 @@ static void delete_all(void)
 /* deletes all vnics or vhbas
  * returns 0 failure, 1 success,
  */
-static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams)
+static int delete_all_virt(VIRTPCI_DEV_TYPE devtype,
+			struct del_vbus_guestpart *delparams)
 {
 	int i;
 	unsigned char busid[BUS_ID_SIZE];
@@ -1375,6 +1395,97 @@ void virtpci_unregister_driver(struct virtpci_driver *drv)
 	DBGINF("Leaving\n");
 }
 EXPORT_SYMBOL_GPL(virtpci_unregister_driver);
+/*****************************************************/
+/* debugfs filesystem functions						*/
+/*****************************************************/
+struct print_vbus_info {
+	int *length;
+	char *buf;
+};
+
+static int print_vbus(struct device *vbus, void *data)
+{
+	struct print_vbus_info *p = (struct print_vbus_info *)data;
+
+	*p->length += sprintf(p->buf + *p->length, "bus_id:%s\n",
+			      dev_name(vbus));
+	return 0;		/* no error */
+}
+
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset)
+{
+	int str_pos = 0;
+	struct virtpci_dev *tmpvpcidev;
+	unsigned long flags;
+	struct print_vbus_info printparam;
+	char *vbuf;
+	loff_t pos = *offset;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	if (pos > 0 || !len)
+		return 0;
+
+	vbuf = kzalloc(len, GFP_KERNEL);
+	if (!vbuf)
+		return -ENOMEM;
+
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos,
+			"\n Virtual PCI Bus devices\n");
+	printparam.length = &str_pos;
+	printparam.buf = vbuf;
+	if (bus_for_each_dev(&virtpci_bus_type, NULL,
+			     (void *) &printparam, print_vbus))
+		LOGERR("Failed to find bus\n");
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos,
+			"\n Virtual PCI devices\n");
+	read_lock_irqsave(&VpcidevListLock, flags);
+	tmpvpcidev = VpcidevListHead;
+	while (tmpvpcidev) {
+		if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
+			str_pos += snprintf(vbuf + str_pos, len - str_pos,
+					"[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->scsi.wwnn.wwnn1,
+				    tmpvpcidev->scsi.wwnn.wwnn2,
+				    tmpvpcidev->scsi.max.max_channel,
+				    tmpvpcidev->scsi.max.max_id,
+				    tmpvpcidev->scsi.max.max_lun,
+				    tmpvpcidev->scsi.max.cmd_per_lun);
+		} else {
+			str_pos += snprintf(vbuf + str_pos, len - str_pos,
+					"[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->net.mac_addr[0],
+				    tmpvpcidev->net.mac_addr[1],
+				    tmpvpcidev->net.mac_addr[2],
+				    tmpvpcidev->net.mac_addr[3],
+				    tmpvpcidev->net.mac_addr[4],
+				    tmpvpcidev->net.mac_addr[5],
+				    tmpvpcidev->net.num_rcv_bufs,
+				    tmpvpcidev->net.mtu);
+		}
+		str_pos +=
+		    snprintf(vbuf + str_pos, len - str_pos, " chanptr:%p\n",
+			    tmpvpcidev->queueinfo.chan);
+		tmpvpcidev = tmpvpcidev->next;
+	}
+	read_unlock_irqrestore(&VpcidevListLock, flags);
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos, "\n");
+	if (copy_to_user(buf, vbuf, str_pos)) {
+		kfree(vbuf);
+		return -EFAULT;
+	}
+
+	kfree(vbuf);
+	*offset += str_pos;
+	return str_pos;
+}
 
 /*****************************************************/
 /* Module Init & Exit functions                      */
@@ -1426,7 +1537,10 @@ static int __init virtpci_mod_init(void)
 
 	LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
 	     (void *) &virtpci_ctrlchan_func);
-
+	/*create debugfs directory*/
+	virtpci_debugfs_dir = debugfs_create_dir(DIR_DEBUGFS_ENTRY, NULL);
+	info_debugfs_entry = debugfs_create_file(INFO_DEBUGFS_ENTRY_FN, S_IRUSR,
+				virtpci_debugfs_dir, NULL, &debugfs_info_fops);
 	LOGINF("Leaving\n");
 	POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
 	return 0;
@@ -1442,7 +1556,8 @@ static void __exit virtpci_mod_exit(void)
 
 	device_unregister(&virtpci_rootbus_device);
 	bus_unregister(&virtpci_bus_type);
-
+	/*debug_fs file and directory removal*/
+	debugfs_remove(virtpci_debugfs_dir);
 	LOGINF("Leaving\n");
 
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-09 20:22 [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
@ 2014-07-09 20:40 ` Greg KH
  2014-07-09 20:41 ` Greg KH
  1 sibling, 0 replies; 11+ messages in thread
From: Greg KH @ 2014-07-09 20:40 UTC (permalink / raw)
  To: Erik Arfvidson; +Cc: driverdev-devel, benjamin.romer, sparmaintainer

On Wed, Jul 09, 2014 at 04:22:43PM -0400, Erik Arfvidson wrote:
> This patch adds the virtpci debugfs directory and the info entry
> inside of it.
> 
> Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
> ---
>  drivers/staging/unisys/virtpci/virtpci.c | 123 ++++++++++++++++++++++++++++++-
>  1 file changed, 119 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
> index 7d840b0..68fbe85 100644
> --- a/drivers/staging/unisys/virtpci/virtpci.c
> +++ b/drivers/staging/unisys/virtpci/virtpci.c
> @@ -37,6 +37,7 @@
>  #include <linux/if_ether.h>
>  #include <linux/version.h>
>  #include "version.h"
> + #include <linux/debugfs.h>

Does that line look correct?

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-09 20:22 [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
  2014-07-09 20:40 ` Greg KH
@ 2014-07-09 20:41 ` Greg KH
  1 sibling, 0 replies; 11+ messages in thread
From: Greg KH @ 2014-07-09 20:41 UTC (permalink / raw)
  To: Erik Arfvidson; +Cc: driverdev-devel, benjamin.romer, sparmaintainer

On Wed, Jul 09, 2014 at 04:22:43PM -0400, Erik Arfvidson wrote:
> @@ -1426,7 +1537,10 @@ static int __init virtpci_mod_init(void)
>  
>  	LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
>  	     (void *) &virtpci_ctrlchan_func);
> -
> +	/*create debugfs directory*/

' ' characters please.
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-11 13:00   ` Romer, Benjamin M
@ 2014-07-11 13:29     ` Dan Carpenter
  0 siblings, 0 replies; 11+ messages in thread
From: Dan Carpenter @ 2014-07-11 13:29 UTC (permalink / raw)
  To: Romer, Benjamin M
  Cc: Greg KH, Arfvidson, Erik, driverdev-devel, *S-Par-Maintainer

On Fri, Jul 11, 2014 at 08:00:57AM -0500, Romer, Benjamin M wrote:
> On Thu, 2014-07-10 at 07:51 -0700, Greg KH wrote:
> > On Thu, Jul 10, 2014 at 10:34:14AM -0400, Erik Arfvidson wrote:
> > > This patch adds the virtpci debugfs directory and the info entry
> > > inside of it.
> > > 
> > > Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
> > > Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
> > 
> > 2/2?  Where is patch 1/2?
> > 
> > Please resend this correctly, and properly version your patches (this is
> > what, version 10 or something?).
> > 
> > Your subsystem maintainer has a short-term memory of a gnat, you need to
> > be explicit otherwise I'll ignore it...
> > 
> > greg k-h
> 
> I mistakenly clicked reply instead of reply all the first time. :(
> 
> Anyhow, I'm really sorry Greg, this patch was the second of a two part
> set and you'd already taken the first one, so I thought we should only
> resend the corrected patch and I told Erik to do that, so it's my fault.

Guys, stop over apologizing for trivial crap.

> Should we send you this as a [1/1 version 4] or resend the entire set
> despite one patch already being in?

Don't resend patches which were already merged.

Just say [PATCH v4] and then under the --- cut off put:

Signed-off-by: you
---
v4: This patch was part of a series which was merged earlier.  It fixes
    blah blah blah issue from v3.
v3: fix foo
v2: fix bar

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-10 14:51 ` Greg KH
@ 2014-07-11 13:00   ` Romer, Benjamin M
  2014-07-11 13:29     ` Dan Carpenter
  0 siblings, 1 reply; 11+ messages in thread
From: Romer, Benjamin M @ 2014-07-11 13:00 UTC (permalink / raw)
  To: Greg KH; +Cc: driverdev-devel, Arfvidson, Erik, *S-Par-Maintainer

On Thu, 2014-07-10 at 07:51 -0700, Greg KH wrote:
> On Thu, Jul 10, 2014 at 10:34:14AM -0400, Erik Arfvidson wrote:
> > This patch adds the virtpci debugfs directory and the info entry
> > inside of it.
> > 
> > Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
> > Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
> 
> 2/2?  Where is patch 1/2?
> 
> Please resend this correctly, and properly version your patches (this is
> what, version 10 or something?).
> 
> Your subsystem maintainer has a short-term memory of a gnat, you need to
> be explicit otherwise I'll ignore it...
> 
> greg k-h

I mistakenly clicked reply instead of reply all the first time. :(

Anyhow, I'm really sorry Greg, this patch was the second of a two part
set and you'd already taken the first one, so I thought we should only
resend the corrected patch and I told Erik to do that, so it's my fault.
Should we send you this as a [1/1 version 4] or resend the entire set
despite one patch already being in?

-- 
Ben Romer | Software Engineer |
Virtual Systems Development 

Unisys Corporation |  2476
Swedesford Rd |  Malvern, PA 19355
|  610-648-7140



_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-10 14:34 Erik Arfvidson
@ 2014-07-10 14:51 ` Greg KH
  2014-07-11 13:00   ` Romer, Benjamin M
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2014-07-10 14:51 UTC (permalink / raw)
  To: Erik Arfvidson; +Cc: driverdev-devel, benjamin.romer, sparmaintainer

On Thu, Jul 10, 2014 at 10:34:14AM -0400, Erik Arfvidson wrote:
> This patch adds the virtpci debugfs directory and the info entry
> inside of it.
> 
> Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>

2/2?  Where is patch 1/2?

Please resend this correctly, and properly version your patches (this is
what, version 10 or something?).

Your subsystem maintainer has a short-term memory of a gnat, you need to
be explicit otherwise I'll ignore it...

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/2] staging: unisys: added virtpci info entry
@ 2014-07-10 14:34 Erik Arfvidson
  2014-07-10 14:51 ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Erik Arfvidson @ 2014-07-10 14:34 UTC (permalink / raw)
  To: gregkh, sparmaintainer, driverdev-devel, benjamin.romer; +Cc: Erik Arfvidson

This patch adds the virtpci debugfs directory and the info entry
inside of it.

Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
---
 drivers/staging/unisys/virtpci/virtpci.c | 123 ++++++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index 7d840b0..722bc1b 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -36,6 +36,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/if_ether.h>
 #include <linux/version.h>
+#include <linux/debugfs.h>
 #include "version.h"
 #include "guestlinuxdebug.h"
 #include "timskmodutils.h"
@@ -100,6 +101,12 @@ static int virtpci_device_resume(struct device *dev);
 static int virtpci_device_probe(struct device *dev);
 static int virtpci_device_remove(struct device *dev);
 
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset);
+
+static const struct file_operations debugfs_info_fops = {
+	.read = info_debugfs_read,
+};
 
 /*****************************************************/
 /* Globals                                           */
@@ -139,7 +146,19 @@ static DEFINE_RWLOCK(VpcidevListLock);
 
 /* filled in with info about this driver, wrt it servicing client busses */
 static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo;
-
+/*****************************************************/
+/* DebugFS entries                                   */
+/*****************************************************/
+/* dentry is used to create the debugfs entry directory
+ * for virtpci
+ */
+static struct dentry *virtpci_debugfs_dir;
+static struct dentry *info_debugfs_entry;
+/* info_debugfs_entry is used to tell virtpci to display current info
+ * kept in the driver
+ */
+#define DIR_DEBUGFS_ENTRY "virtpci"
+#define INFO_DEBUGFS_ENTRY_FN "info"
 
 struct virtpci_busdev {
 	struct device virtpci_bus_device;
@@ -588,7 +607,8 @@ static void delete_all(void)
 /* deletes all vnics or vhbas
  * returns 0 failure, 1 success,
  */
-static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams)
+static int delete_all_virt(VIRTPCI_DEV_TYPE devtype,
+			struct del_vbus_guestpart *delparams)
 {
 	int i;
 	unsigned char busid[BUS_ID_SIZE];
@@ -1375,6 +1395,97 @@ void virtpci_unregister_driver(struct virtpci_driver *drv)
 	DBGINF("Leaving\n");
 }
 EXPORT_SYMBOL_GPL(virtpci_unregister_driver);
+/*****************************************************/
+/* debugfs filesystem functions						*/
+/*****************************************************/
+struct print_vbus_info {
+	int *length;
+	char *buf;
+};
+
+static int print_vbus(struct device *vbus, void *data)
+{
+	struct print_vbus_info *p = (struct print_vbus_info *)data;
+
+	*p->length += sprintf(p->buf + *p->length, "bus_id:%s\n",
+			      dev_name(vbus));
+	return 0;		/* no error */
+}
+
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset)
+{
+	int str_pos = 0;
+	struct virtpci_dev *tmpvpcidev;
+	unsigned long flags;
+	struct print_vbus_info printparam;
+	char *vbuf;
+	loff_t pos = *offset;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	if (pos > 0 || !len)
+		return 0;
+
+	vbuf = kzalloc(len, GFP_KERNEL);
+	if (!vbuf)
+		return -ENOMEM;
+
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos,
+			"\n Virtual PCI Bus devices\n");
+	printparam.length = &str_pos;
+	printparam.buf = vbuf;
+	if (bus_for_each_dev(&virtpci_bus_type, NULL,
+			     (void *) &printparam, print_vbus))
+		LOGERR("Failed to find bus\n");
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos,
+			"\n Virtual PCI devices\n");
+	read_lock_irqsave(&VpcidevListLock, flags);
+	tmpvpcidev = VpcidevListHead;
+	while (tmpvpcidev) {
+		if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
+			str_pos += snprintf(vbuf + str_pos, len - str_pos,
+					"[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->scsi.wwnn.wwnn1,
+				    tmpvpcidev->scsi.wwnn.wwnn2,
+				    tmpvpcidev->scsi.max.max_channel,
+				    tmpvpcidev->scsi.max.max_id,
+				    tmpvpcidev->scsi.max.max_lun,
+				    tmpvpcidev->scsi.max.cmd_per_lun);
+		} else {
+			str_pos += snprintf(vbuf + str_pos, len - str_pos,
+					"[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->net.mac_addr[0],
+				    tmpvpcidev->net.mac_addr[1],
+				    tmpvpcidev->net.mac_addr[2],
+				    tmpvpcidev->net.mac_addr[3],
+				    tmpvpcidev->net.mac_addr[4],
+				    tmpvpcidev->net.mac_addr[5],
+				    tmpvpcidev->net.num_rcv_bufs,
+				    tmpvpcidev->net.mtu);
+		}
+		str_pos +=
+		    snprintf(vbuf + str_pos, len - str_pos, " chanptr:%p\n",
+			    tmpvpcidev->queueinfo.chan);
+		tmpvpcidev = tmpvpcidev->next;
+	}
+	read_unlock_irqrestore(&VpcidevListLock, flags);
+
+	str_pos += snprintf(vbuf + str_pos, len - str_pos, "\n");
+	if (copy_to_user(buf, vbuf, str_pos)) {
+		kfree(vbuf);
+		return -EFAULT;
+	}
+
+	kfree(vbuf);
+	*offset += str_pos;
+	return str_pos;
+}
 
 /*****************************************************/
 /* Module Init & Exit functions                      */
@@ -1426,7 +1537,10 @@ static int __init virtpci_mod_init(void)
 
 	LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
 	     (void *) &virtpci_ctrlchan_func);
-
+	/* create debugfs directory. */
+	virtpci_debugfs_dir = debugfs_create_dir(DIR_DEBUGFS_ENTRY, NULL);
+	info_debugfs_entry = debugfs_create_file(INFO_DEBUGFS_ENTRY_FN, S_IRUSR,
+				virtpci_debugfs_dir, NULL, &debugfs_info_fops);
 	LOGINF("Leaving\n");
 	POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
 	return 0;
@@ -1442,7 +1556,8 @@ static void __exit virtpci_mod_exit(void)
 
 	device_unregister(&virtpci_rootbus_device);
 	bus_unregister(&virtpci_bus_type);
-
+	/* debug_fs file and directory removal. */
+	debugfs_remove(virtpci_debugfs_dir);
 	LOGINF("Leaving\n");
 
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-08 17:52   ` Dan Carpenter
@ 2014-07-08 19:22     ` Erik Arfvidson
  0 siblings, 0 replies; 11+ messages in thread
From: Erik Arfvidson @ 2014-07-08 19:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: gregkh, Romer, Benjamin M, *S-Par-Maintainer, driverdev-devel

Hi,

Thanks for the comments and suggestions, I'll get them fixed and send it 
in the
new patch.

Cheers,
Erik
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-08 17:21 ` [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
  2014-07-08 17:34   ` Greg KH
@ 2014-07-08 17:52   ` Dan Carpenter
  2014-07-08 19:22     ` Erik Arfvidson
  1 sibling, 1 reply; 11+ messages in thread
From: Dan Carpenter @ 2014-07-08 17:52 UTC (permalink / raw)
  To: Erik Arfvidson; +Cc: gregkh, benjamin.romer, sparmaintainer, driverdev-devel

On Tue, Jul 08, 2014 at 01:21:31PM -0400, Erik Arfvidson wrote:
> This patch adds the virtpci debugfs directory and the info entry
> inside of it.
> 
> Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
> ---
>  drivers/staging/unisys/virtpci/virtpci.c | 122 ++++++++++++++++++++++++++++++-
>  1 file changed, 118 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
> index 7d840b0..6c0aa96 100644
> --- a/drivers/staging/unisys/virtpci/virtpci.c
> +++ b/drivers/staging/unisys/virtpci/virtpci.c
> @@ -37,6 +37,7 @@
>  #include <linux/if_ether.h>
>  #include <linux/version.h>
>  #include "version.h"
> + #include <linux/debugfs.h>
>  #include "guestlinuxdebug.h"
>  #include "timskmodutils.h"
>  
> @@ -100,6 +101,12 @@ static int virtpci_device_resume(struct device *dev);
>  static int virtpci_device_probe(struct device *dev);
>  static int virtpci_device_remove(struct device *dev);
>  
> +static ssize_t info_debugfs_read(struct file *file, char __user *buf,
> +			      size_t len, loff_t *offset);
> +
> +static const struct file_operations debugfs_info_fops = {
> +	.read = info_debugfs_read,
> +};
>  
>  /*****************************************************/
>  /* Globals                                           */
> @@ -139,7 +146,19 @@ static DEFINE_RWLOCK(VpcidevListLock);
>  
>  /* filled in with info about this driver, wrt it servicing client busses */
>  static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo;
> -
> +		/*****************************************************/
> +		/* DebugFS entries                                   */
> +		/*****************************************************/
> +/* dentry is used to create the debugfs entry directory
> + * for virtpci
> + */
> +static struct dentry *virtpci_debugfs_dir;
> +static struct dentry *info_debugfs_entry;
> +/* info_debugfs_entry is used to tell virtpci to display current info
> + * kept in the driver
> + */
> +#define DIR_DEBUGFS_ENTRY "virtpci"
> +#define INFO_DEBUGFS_ENTRY_FN "info"
>  
>  struct virtpci_busdev {
>  	struct device virtpci_bus_device;
> @@ -588,7 +607,8 @@ static void delete_all(void)
>  /* deletes all vnics or vhbas
>   * returns 0 failure, 1 success,
>   */
> -static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams)
> +static int delete_all_virt(VIRTPCI_DEV_TYPE devtype,
> +			struct del_vbus_guestpart *delparams)
>  {
>  	int i;
>  	unsigned char busid[BUS_ID_SIZE];
> @@ -1375,6 +1395,95 @@ void virtpci_unregister_driver(struct virtpci_driver *drv)
>  	DBGINF("Leaving\n");
>  }
>  EXPORT_SYMBOL_GPL(virtpci_unregister_driver);
> +/*****************************************************/
> +/* debugfs filesystem functions						*/
> +/*****************************************************/
> +struct print_vbus_info {
> +	int *length;
> +	char *buf;
> +};
> +
> +static int print_vbus(struct device *vbus, void *data)
> +{
> +	struct print_vbus_info *p = (struct print_vbus_info *) data;

Remove the space after the cast to remind that casting is high
precedence.

	struct print_vbus_info *p = (struct print_vbus_info *)data;

> +	int l = *(p->length);

Remove the extra parens.

	int l = *p->length;

> +
> +	*(p->length) = l + sprintf(p->buf + l, "bus_id:%s\n", dev_name(vbus));

You don't really need the "l" at all.

	*p->length += sprintf(p->buf + *p->length, "bus_id:%s\n",
			      dev_name(vbus));

> +	return 0;		/* no error */
> +}
> +
> +static ssize_t info_debugfs_read(struct file *file, char __user *buf,
> +			      size_t len, loff_t *offset)
> +{
> +	int length = 0;

"length" is going to be confusing because we already have "len".

> +	struct virtpci_dev *tmpvpcidev;
> +	unsigned long flags;
> +	struct print_vbus_info printparam;
> +	char *vbuf;
> +	loff_t pos = *offset;
> +
> +	if (pos < 0)
> +		return -EINVAL;
> +
> +	if (pos > 0 || !len)
> +		return 0;

I don't understand the point of updating *offset and then not allowing
pos > 0.  (This could be because I haven't paid attention as well
though).

> +
> +	vbuf = kzalloc(len, GFP_KERNEL);
> +	if (!vbuf)
> +		return -ENOMEM;
> +
> +	length += sprintf(vbuf + length, "CHANSOCK is not defined.\n");


This is memory corruption here because we don't verify that len is large
enough for the string.  None of the sprintf() calls have checking.

> +
> +	length += sprintf(vbuf + length, "\n Virtual PCI Bus devices\n");
> +	printparam.length = &length;
> +	printparam.buf = vbuf;
> +	if (bus_for_each_dev(&virtpci_bus_type, NULL,
> +			     (void *) &printparam, print_vbus))
> +		LOGERR("delete of all vbus failed\n");

"delete"?  Probably cut and paste bug.

> +
> +	length += sprintf(vbuf + length, "\n Virtual PCI devices\n");
> +	read_lock_irqsave(&VpcidevListLock, flags);
> +	tmpvpcidev = VpcidevListHead;
> +	while (tmpvpcidev) {
> +		if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
> +			length += sprintf(vbuf + length,
> +					"[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
> +				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
> +				    tmpvpcidev->scsi.wwnn.wwnn1,
> +				    tmpvpcidev->scsi.wwnn.wwnn2,
> +				    tmpvpcidev->scsi.max.max_channel,
> +				    tmpvpcidev->scsi.max.max_id,
> +				    tmpvpcidev->scsi.max.max_lun,
> +				    tmpvpcidev->scsi.max.cmd_per_lun);
> +		} else {
> +			length += sprintf(vbuf + length, "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
> +				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
> +				    tmpvpcidev->net.mac_addr[0],
> +				    tmpvpcidev->net.mac_addr[1],
> +				    tmpvpcidev->net.mac_addr[2],
> +				    tmpvpcidev->net.mac_addr[3],
> +				    tmpvpcidev->net.mac_addr[4],
> +				    tmpvpcidev->net.mac_addr[5],
> +				    tmpvpcidev->net.num_rcv_bufs,
> +				    tmpvpcidev->net.mtu);
> +		}
> +		length +=
> +		    sprintf(vbuf + length, " chanptr:%p\n",
> +			    tmpvpcidev->queueinfo.chan);
> +		tmpvpcidev = tmpvpcidev->next;
> +	}
> +	read_unlock_irqrestore(&VpcidevListLock, flags);
> +
> +	length += sprintf(vbuf + length, "\n");
> +	if (copy_to_user(buf, vbuf, length)) {

There should be some length checking here as well.

> +		kfree(vbuf);
> +		return -EFAULT;
> +	}
> +
> +	kfree(vbuf);
> +	*offset += length;
> +	return length;
> +}
>  
>  /*****************************************************/
>  /* Module Init & Exit functions                      */
> @@ -1426,7 +1535,10 @@ static int __init virtpci_mod_init(void)
>  
>  	LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
>  	     (void *) &virtpci_ctrlchan_func);
> -
> +	/*create debugfs directory*/
> +	virtpci_debugfs_dir = debugfs_create_dir(DIR_DEBUGFS_ENTRY, NULL);
> +	info_debugfs_entry = debugfs_create_file(INFO_DEBUGFS_ENTRY_FN, 0660,

The owner has write permision but there is no ->write op.  Don't use the
numbers use S_IRUSR or whatever.

> +				virtpci_debugfs_dir, NULL, &debugfs_info_fops);
>  	LOGINF("Leaving\n");
>  	POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
>  	return 0;
> @@ -1442,7 +1554,9 @@ static void __exit virtpci_mod_exit(void)
>  
>  	device_unregister(&virtpci_rootbus_device);
>  	bus_unregister(&virtpci_bus_type);
> -
> +	/*debug_fs file and direcroty removal*/
> +		debugfs_remove(info_debugfs_entry);
> +		debugfs_remove(virtpci_debugfs_dir);

These are not indented correctly.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-08 17:21 ` [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
@ 2014-07-08 17:34   ` Greg KH
  2014-07-08 17:52   ` Dan Carpenter
  1 sibling, 0 replies; 11+ messages in thread
From: Greg KH @ 2014-07-08 17:34 UTC (permalink / raw)
  To: Erik Arfvidson; +Cc: sparmaintainer, driverdev-devel, benjamin.romer

On Tue, Jul 08, 2014 at 01:21:31PM -0400, Erik Arfvidson wrote:
> -
> +	/*debug_fs file and direcroty removal*/
> +		debugfs_remove(info_debugfs_entry);
> +		debugfs_remove(virtpci_debugfs_dir);

Odd indentation, comment style, and spelling typos :(

Also, you can just remove the directory recursivly, no need to save, and
then remove, the individual files.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/2] staging: unisys: added virtpci info entry
  2014-07-08 17:21 [PATCH 1/2] staging: unisys: remove all proc entries from virtpci Erik Arfvidson
@ 2014-07-08 17:21 ` Erik Arfvidson
  2014-07-08 17:34   ` Greg KH
  2014-07-08 17:52   ` Dan Carpenter
  0 siblings, 2 replies; 11+ messages in thread
From: Erik Arfvidson @ 2014-07-08 17:21 UTC (permalink / raw)
  To: erik.arfvidson, gregkh, sparmaintainer, driverdev-devel, benjamin.romer

This patch adds the virtpci debugfs directory and the info entry
inside of it.

Signed-off-by: Erik Arfvidson <erik.arfvidson@unisys.com>
Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
---
 drivers/staging/unisys/virtpci/virtpci.c | 122 ++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index 7d840b0..6c0aa96 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -37,6 +37,7 @@
 #include <linux/if_ether.h>
 #include <linux/version.h>
 #include "version.h"
+ #include <linux/debugfs.h>
 #include "guestlinuxdebug.h"
 #include "timskmodutils.h"
 
@@ -100,6 +101,12 @@ static int virtpci_device_resume(struct device *dev);
 static int virtpci_device_probe(struct device *dev);
 static int virtpci_device_remove(struct device *dev);
 
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset);
+
+static const struct file_operations debugfs_info_fops = {
+	.read = info_debugfs_read,
+};
 
 /*****************************************************/
 /* Globals                                           */
@@ -139,7 +146,19 @@ static DEFINE_RWLOCK(VpcidevListLock);
 
 /* filled in with info about this driver, wrt it servicing client busses */
 static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo;
-
+		/*****************************************************/
+		/* DebugFS entries                                   */
+		/*****************************************************/
+/* dentry is used to create the debugfs entry directory
+ * for virtpci
+ */
+static struct dentry *virtpci_debugfs_dir;
+static struct dentry *info_debugfs_entry;
+/* info_debugfs_entry is used to tell virtpci to display current info
+ * kept in the driver
+ */
+#define DIR_DEBUGFS_ENTRY "virtpci"
+#define INFO_DEBUGFS_ENTRY_FN "info"
 
 struct virtpci_busdev {
 	struct device virtpci_bus_device;
@@ -588,7 +607,8 @@ static void delete_all(void)
 /* deletes all vnics or vhbas
  * returns 0 failure, 1 success,
  */
-static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams)
+static int delete_all_virt(VIRTPCI_DEV_TYPE devtype,
+			struct del_vbus_guestpart *delparams)
 {
 	int i;
 	unsigned char busid[BUS_ID_SIZE];
@@ -1375,6 +1395,95 @@ void virtpci_unregister_driver(struct virtpci_driver *drv)
 	DBGINF("Leaving\n");
 }
 EXPORT_SYMBOL_GPL(virtpci_unregister_driver);
+/*****************************************************/
+/* debugfs filesystem functions						*/
+/*****************************************************/
+struct print_vbus_info {
+	int *length;
+	char *buf;
+};
+
+static int print_vbus(struct device *vbus, void *data)
+{
+	struct print_vbus_info *p = (struct print_vbus_info *) data;
+	int l = *(p->length);
+
+	*(p->length) = l + sprintf(p->buf + l, "bus_id:%s\n", dev_name(vbus));
+	return 0;		/* no error */
+}
+
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+			      size_t len, loff_t *offset)
+{
+	int length = 0;
+	struct virtpci_dev *tmpvpcidev;
+	unsigned long flags;
+	struct print_vbus_info printparam;
+	char *vbuf;
+	loff_t pos = *offset;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	if (pos > 0 || !len)
+		return 0;
+
+	vbuf = kzalloc(len, GFP_KERNEL);
+	if (!vbuf)
+		return -ENOMEM;
+
+	length += sprintf(vbuf + length, "CHANSOCK is not defined.\n");
+
+	length += sprintf(vbuf + length, "\n Virtual PCI Bus devices\n");
+	printparam.length = &length;
+	printparam.buf = vbuf;
+	if (bus_for_each_dev(&virtpci_bus_type, NULL,
+			     (void *) &printparam, print_vbus))
+		LOGERR("delete of all vbus failed\n");
+
+	length += sprintf(vbuf + length, "\n Virtual PCI devices\n");
+	read_lock_irqsave(&VpcidevListLock, flags);
+	tmpvpcidev = VpcidevListHead;
+	while (tmpvpcidev) {
+		if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
+			length += sprintf(vbuf + length,
+					"[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->scsi.wwnn.wwnn1,
+				    tmpvpcidev->scsi.wwnn.wwnn2,
+				    tmpvpcidev->scsi.max.max_channel,
+				    tmpvpcidev->scsi.max.max_id,
+				    tmpvpcidev->scsi.max.max_lun,
+				    tmpvpcidev->scsi.max.cmd_per_lun);
+		} else {
+			length += sprintf(vbuf + length, "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
+				    tmpvpcidev->busNo, tmpvpcidev->deviceNo,
+				    tmpvpcidev->net.mac_addr[0],
+				    tmpvpcidev->net.mac_addr[1],
+				    tmpvpcidev->net.mac_addr[2],
+				    tmpvpcidev->net.mac_addr[3],
+				    tmpvpcidev->net.mac_addr[4],
+				    tmpvpcidev->net.mac_addr[5],
+				    tmpvpcidev->net.num_rcv_bufs,
+				    tmpvpcidev->net.mtu);
+		}
+		length +=
+		    sprintf(vbuf + length, " chanptr:%p\n",
+			    tmpvpcidev->queueinfo.chan);
+		tmpvpcidev = tmpvpcidev->next;
+	}
+	read_unlock_irqrestore(&VpcidevListLock, flags);
+
+	length += sprintf(vbuf + length, "\n");
+	if (copy_to_user(buf, vbuf, length)) {
+		kfree(vbuf);
+		return -EFAULT;
+	}
+
+	kfree(vbuf);
+	*offset += length;
+	return length;
+}
 
 /*****************************************************/
 /* Module Init & Exit functions                      */
@@ -1426,7 +1535,10 @@ static int __init virtpci_mod_init(void)
 
 	LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
 	     (void *) &virtpci_ctrlchan_func);
-
+	/*create debugfs directory*/
+	virtpci_debugfs_dir = debugfs_create_dir(DIR_DEBUGFS_ENTRY, NULL);
+	info_debugfs_entry = debugfs_create_file(INFO_DEBUGFS_ENTRY_FN, 0660,
+				virtpci_debugfs_dir, NULL, &debugfs_info_fops);
 	LOGINF("Leaving\n");
 	POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
 	return 0;
@@ -1442,7 +1554,9 @@ static void __exit virtpci_mod_exit(void)
 
 	device_unregister(&virtpci_rootbus_device);
 	bus_unregister(&virtpci_bus_type);
-
+	/*debug_fs file and direcroty removal*/
+		debugfs_remove(info_debugfs_entry);
+		debugfs_remove(virtpci_debugfs_dir);
 	LOGINF("Leaving\n");
 
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-11 13:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09 20:22 [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
2014-07-09 20:40 ` Greg KH
2014-07-09 20:41 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2014-07-10 14:34 Erik Arfvidson
2014-07-10 14:51 ` Greg KH
2014-07-11 13:00   ` Romer, Benjamin M
2014-07-11 13:29     ` Dan Carpenter
2014-07-08 17:21 [PATCH 1/2] staging: unisys: remove all proc entries from virtpci Erik Arfvidson
2014-07-08 17:21 ` [PATCH 2/2] staging: unisys: added virtpci info entry Erik Arfvidson
2014-07-08 17:34   ` Greg KH
2014-07-08 17:52   ` Dan Carpenter
2014-07-08 19:22     ` Erik Arfvidson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.