diff mbox series

[v5,10/16] lpfc: vmid: Functions to manage vmids

Message ID 1608096586-21656-11-git-send-email-muneendra.kumar@broadcom.com (mailing list archive)
State Superseded
Headers show
Series blkcg:Support to track FC storage blk io traffic | expand

Commit Message

Muneendra Kumar M Dec. 16, 2020, 5:29 a.m. UTC
From: Gaurav Srivastava <gaurav.srivastava@broadcom.com>

This patch contains the routines to save, retrieve and remove the vmids
from the data structure. A hash table is used to save the vmids and
the corresponding UUIDs associated with the application/VMs.

Signed-off-by: Gaurav Srivastava  <gaurav.srivastava@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>

---
v5:
Changed Return code to non-numeric/Symbol

v4:
No change

v3:
No change

v2:
Ported the patch on top of 5.10/scsi-queue
---
 drivers/scsi/lpfc/lpfc_scsi.c | 139 ++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)

Comments

kernel test robot Dec. 16, 2020, 4:23 p.m. UTC | #1
Hi Muneendra,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on mkp-scsi/for-next next-20201215]
[cannot apply to cgroup/for-next v5.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Muneendra/blkcg-Support-to-track-FC-storage-blk-io-traffic/20201216-202913
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/8417ca99565475d5bf5493657fcf90922607f1b1
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Muneendra/blkcg-Support-to-track-FC-storage-blk-io-traffic/20201216-202913
        git checkout 8417ca99565475d5bf5493657fcf90922607f1b1
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/lpfc/lpfc_scsi.c:5179:1: warning: no previous prototype for 'lpfc_put_vmid_in_hashtable' [-Wmissing-prototypes]
    5179 | lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/lpfc/lpfc_scsi.c:5233:6: warning: no previous prototype for 'lpfc_vmid_update_entry' [-Wmissing-prototypes]
    5233 | void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
         |      ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/scsi/lpfc/lpfc_scsi.c:5254:6: warning: no previous prototype for 'lpfc_vmid_assign_cs_ctl' [-Wmissing-prototypes]
    5254 | void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
         |      ^~~~~~~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for FRAME_POINTER
   Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
   Selected by
   - FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86


vim +/lpfc_put_vmid_in_hashtable +5179 drivers/scsi/lpfc/lpfc_scsi.c

  5168	
  5169	/*
  5170	 * lpfc_put_vmid_from_hastable - put the VMID in the hash table
  5171	 * @vport: The virtual port for which this call is being executed.
  5172	 * @hash - calculated hash value
  5173	 * @vmp: Pointer to a VMID entry representing a VM sending IO
  5174	 *
  5175	 * This routine will insert the newly acquired vmid entity in the hash table.
  5176	 * Make sure to acquire the appropriate lock before invoking this routine.
  5177	 */
  5178	int
> 5179	lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
  5180				   struct lpfc_vmid *vmp)
  5181	{
  5182		int count = 0;
  5183	
  5184		while (count < LPFC_VMID_HASH_SIZE) {
  5185			if (!vport->hash_table[hash]) {
  5186				vport->hash_table[hash] = vmp;
  5187				vmp->hash_index = hash;
  5188				return FAILURE;
  5189			}
  5190			/* if the slot is already occupied, a collision has occurred. */
  5191			/* Store in the next available slot */
  5192			count++;
  5193			hash++;
  5194			/* table is full */
  5195			if (hash == LPFC_VMID_HASH_SIZE)
  5196				hash = 0;
  5197		}
  5198		return 0;
  5199	}
  5200	
  5201	/*
  5202	 * lpfc_vmid_hash_fn- creates a hash value of the UUID
  5203	 * @uuid: uuid associated with the VE
  5204	 * @len: length of the UUID
  5205	 * Returns the calculated hash value
  5206	 */
  5207	int lpfc_vmid_hash_fn(char *vmid, int len)
  5208	{
  5209		int c;
  5210		int hash = 0;
  5211	
  5212		if (len == 0)
  5213			return 0;
  5214		while (len--) {
  5215			c = *vmid++;
  5216			if (c >= 'A' && c <= 'Z')
  5217				c += 'a' - 'A';
  5218	
  5219			hash = (hash + (c << LPFC_VMID_HASH_SHIFT) +
  5220				(c >> LPFC_VMID_HASH_SHIFT)) * 19;
  5221		}
  5222	
  5223		return hash & LPFC_VMID_HASH_MASK;
  5224	}
  5225	
  5226	/*
  5227	 * lpfc_vmid_update_entry - update the vmid entry in the hash table
  5228	 * @vport: The virtual port for which this call is being executed.
  5229	 * @cmd: address of scsi cmmd descriptor
  5230	 * @vmp: Pointer to a VMID entry representing a VM sending IO
  5231	 * @tag: VMID tag
  5232	 */
> 5233	void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
  5234					   *cmd, struct lpfc_vmid *vmp,
  5235					   union lpfc_vmid_io_tag *tag)
  5236	{
  5237		u64 *lta;
  5238	
  5239		if (vport->vmid_priority_tagging)
  5240			tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid;
  5241		else
  5242			tag->app_id = vmp->un.app_id;
  5243	
  5244		if (cmd->sc_data_direction == DMA_TO_DEVICE)
  5245			vmp->io_wr_cnt++;
  5246		else
  5247			vmp->io_rd_cnt++;
  5248	
  5249		/* update the last access timestamp in the table */
  5250		lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id());
  5251		*lta = jiffies;
  5252	}
  5253	
> 5254	void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
  5255	{
  5256		u32 hash;
  5257		struct lpfc_vmid *pvmid;
  5258	
  5259		if (vport->port_type == LPFC_PHYSICAL_PORT) {
  5260			vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
  5261		} else {
  5262			hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len);
  5263			pvmid =
  5264			    lpfc_get_vmid_from_hastable(vport->phba->pport, hash,
  5265							vmid->host_vmid);
  5266			if (!pvmid)
  5267				vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid;
  5268			else
  5269				vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
  5270		}
  5271	}
  5272	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Dec. 19, 2020, 8:20 p.m. UTC | #2
Hi Muneendra,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on mkp-scsi/for-next next-20201218]
[cannot apply to cgroup/for-next v5.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Muneendra/blkcg-Support-to-track-FC-storage-blk-io-traffic/20201216-202913
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: powerpc64-randconfig-r023-20201217 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project cee1e7d14f4628d6174b33640d502bff3b54ae45)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc64 cross compiling tool for clang build
        # apt-get install binutils-powerpc64-linux-gnu
        # https://github.com/0day-ci/linux/commit/8417ca99565475d5bf5493657fcf90922607f1b1
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Muneendra/blkcg-Support-to-track-FC-storage-blk-io-traffic/20201216-202913
        git checkout 8417ca99565475d5bf5493657fcf90922607f1b1
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/lpfc/lpfc_scsi.c:5179:1: warning: no previous prototype for function 'lpfc_put_vmid_in_hashtable' [-Wmissing-prototypes]
   lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
   ^
   drivers/scsi/lpfc/lpfc_scsi.c:5178:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int
   ^
   static 
>> drivers/scsi/lpfc/lpfc_scsi.c:5233:6: warning: no previous prototype for function 'lpfc_vmid_update_entry' [-Wmissing-prototypes]
   void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
        ^
   drivers/scsi/lpfc/lpfc_scsi.c:5233:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
   ^
   static 
>> drivers/scsi/lpfc/lpfc_scsi.c:5254:6: warning: no previous prototype for function 'lpfc_vmid_assign_cs_ctl' [-Wmissing-prototypes]
   void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
        ^
   drivers/scsi/lpfc/lpfc_scsi.c:5254:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
   ^
   static 
   In file included from drivers/scsi/lpfc/lpfc_scsi.c:31:
   In file included from include/linux/blk-cgroup.h:17:
   include/linux/cgroup.h:748:23: warning: unused function 'cgroup_get_from_id' [-Wunused-function]
   static struct cgroup *cgroup_get_from_id(u64 id)
                         ^
   4 warnings generated.


vim +/lpfc_put_vmid_in_hashtable +5179 drivers/scsi/lpfc/lpfc_scsi.c

  5168	
  5169	/*
  5170	 * lpfc_put_vmid_from_hastable - put the VMID in the hash table
  5171	 * @vport: The virtual port for which this call is being executed.
  5172	 * @hash - calculated hash value
  5173	 * @vmp: Pointer to a VMID entry representing a VM sending IO
  5174	 *
  5175	 * This routine will insert the newly acquired vmid entity in the hash table.
  5176	 * Make sure to acquire the appropriate lock before invoking this routine.
  5177	 */
  5178	int
> 5179	lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
  5180				   struct lpfc_vmid *vmp)
  5181	{
  5182		int count = 0;
  5183	
  5184		while (count < LPFC_VMID_HASH_SIZE) {
  5185			if (!vport->hash_table[hash]) {
  5186				vport->hash_table[hash] = vmp;
  5187				vmp->hash_index = hash;
  5188				return FAILURE;
  5189			}
  5190			/* if the slot is already occupied, a collision has occurred. */
  5191			/* Store in the next available slot */
  5192			count++;
  5193			hash++;
  5194			/* table is full */
  5195			if (hash == LPFC_VMID_HASH_SIZE)
  5196				hash = 0;
  5197		}
  5198		return 0;
  5199	}
  5200	
  5201	/*
  5202	 * lpfc_vmid_hash_fn- creates a hash value of the UUID
  5203	 * @uuid: uuid associated with the VE
  5204	 * @len: length of the UUID
  5205	 * Returns the calculated hash value
  5206	 */
  5207	int lpfc_vmid_hash_fn(char *vmid, int len)
  5208	{
  5209		int c;
  5210		int hash = 0;
  5211	
  5212		if (len == 0)
  5213			return 0;
  5214		while (len--) {
  5215			c = *vmid++;
  5216			if (c >= 'A' && c <= 'Z')
  5217				c += 'a' - 'A';
  5218	
  5219			hash = (hash + (c << LPFC_VMID_HASH_SHIFT) +
  5220				(c >> LPFC_VMID_HASH_SHIFT)) * 19;
  5221		}
  5222	
  5223		return hash & LPFC_VMID_HASH_MASK;
  5224	}
  5225	
  5226	/*
  5227	 * lpfc_vmid_update_entry - update the vmid entry in the hash table
  5228	 * @vport: The virtual port for which this call is being executed.
  5229	 * @cmd: address of scsi cmmd descriptor
  5230	 * @vmp: Pointer to a VMID entry representing a VM sending IO
  5231	 * @tag: VMID tag
  5232	 */
> 5233	void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
  5234					   *cmd, struct lpfc_vmid *vmp,
  5235					   union lpfc_vmid_io_tag *tag)
  5236	{
  5237		u64 *lta;
  5238	
  5239		if (vport->vmid_priority_tagging)
  5240			tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid;
  5241		else
  5242			tag->app_id = vmp->un.app_id;
  5243	
  5244		if (cmd->sc_data_direction == DMA_TO_DEVICE)
  5245			vmp->io_wr_cnt++;
  5246		else
  5247			vmp->io_rd_cnt++;
  5248	
  5249		/* update the last access timestamp in the table */
  5250		lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id());
  5251		*lta = jiffies;
  5252	}
  5253	
> 5254	void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
  5255	{
  5256		u32 hash;
  5257		struct lpfc_vmid *pvmid;
  5258	
  5259		if (vport->port_type == LPFC_PHYSICAL_PORT) {
  5260			vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
  5261		} else {
  5262			hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len);
  5263			pvmid =
  5264			    lpfc_get_vmid_from_hastable(vport->phba->pport, hash,
  5265							vmid->host_vmid);
  5266			if (!pvmid)
  5267				vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid;
  5268			else
  5269				vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
  5270		}
  5271	}
  5272	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index b79b6f03cdb6..6a6a9a314368 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -28,6 +28,7 @@ 
 #include <asm/unaligned.h>
 #include <linux/t10-pi.h>
 #include <linux/crc-t10dif.h>
+#include <linux/blk-cgroup.h>
 #include <net/checksum.h>
 
 #include <scsi/scsi.h>
@@ -5131,6 +5132,144 @@  void lpfc_poll_timeout(struct timer_list *t)
 	}
 }
 
+/*
+ * lpfc_get_vmid_from_hastable - search the UUID in the hash table
+ * @vport: The virtual port for which this call is being executed.
+ * @hash: calculated hash value
+ * @buf: uuid associated with the VE
+ * Returns the vmid entry associated with the UUID
+ * Make sure to acquire the appropriate lock before invoking this routine.
+ */
+struct lpfc_vmid *lpfc_get_vmid_from_hastable(struct lpfc_vport *vport,
+					      u32 hash, u8 *buf)
+{
+	struct lpfc_vmid *vmp;
+	u16 count = 0;
+
+	while (count < LPFC_VMID_HASH_SIZE) {
+		vmp = vport->hash_table[hash];
+		if (vmp) {
+			if (strncmp(&vmp->host_vmid[0], buf, 16) == 0)
+				return vmp;
+		} else {
+			return NULL;
+		}
+		/* search the next available slot and continue till entry */
+		/* is found */
+		count++;
+		hash++;
+
+		/* or the end is reached */
+		if (hash == LPFC_VMID_HASH_SIZE)
+			hash = 0;
+	}
+	return NULL;
+}
+
+/*
+ * lpfc_put_vmid_from_hastable - put the VMID in the hash table
+ * @vport: The virtual port for which this call is being executed.
+ * @hash - calculated hash value
+ * @vmp: Pointer to a VMID entry representing a VM sending IO
+ *
+ * This routine will insert the newly acquired vmid entity in the hash table.
+ * Make sure to acquire the appropriate lock before invoking this routine.
+ */
+int
+lpfc_put_vmid_in_hashtable(struct lpfc_vport *vport, u32 hash,
+			   struct lpfc_vmid *vmp)
+{
+	int count = 0;
+
+	while (count < LPFC_VMID_HASH_SIZE) {
+		if (!vport->hash_table[hash]) {
+			vport->hash_table[hash] = vmp;
+			vmp->hash_index = hash;
+			return FAILURE;
+		}
+		/* if the slot is already occupied, a collision has occurred. */
+		/* Store in the next available slot */
+		count++;
+		hash++;
+		/* table is full */
+		if (hash == LPFC_VMID_HASH_SIZE)
+			hash = 0;
+	}
+	return 0;
+}
+
+/*
+ * lpfc_vmid_hash_fn- creates a hash value of the UUID
+ * @uuid: uuid associated with the VE
+ * @len: length of the UUID
+ * Returns the calculated hash value
+ */
+int lpfc_vmid_hash_fn(char *vmid, int len)
+{
+	int c;
+	int hash = 0;
+
+	if (len == 0)
+		return 0;
+	while (len--) {
+		c = *vmid++;
+		if (c >= 'A' && c <= 'Z')
+			c += 'a' - 'A';
+
+		hash = (hash + (c << LPFC_VMID_HASH_SHIFT) +
+			(c >> LPFC_VMID_HASH_SHIFT)) * 19;
+	}
+
+	return hash & LPFC_VMID_HASH_MASK;
+}
+
+/*
+ * lpfc_vmid_update_entry - update the vmid entry in the hash table
+ * @vport: The virtual port for which this call is being executed.
+ * @cmd: address of scsi cmmd descriptor
+ * @vmp: Pointer to a VMID entry representing a VM sending IO
+ * @tag: VMID tag
+ */
+void lpfc_vmid_update_entry(struct lpfc_vport *vport, struct scsi_cmnd
+				   *cmd, struct lpfc_vmid *vmp,
+				   union lpfc_vmid_io_tag *tag)
+{
+	u64 *lta;
+
+	if (vport->vmid_priority_tagging)
+		tag->cs_ctl_vmid = vmp->un.cs_ctl_vmid;
+	else
+		tag->app_id = vmp->un.app_id;
+
+	if (cmd->sc_data_direction == DMA_TO_DEVICE)
+		vmp->io_wr_cnt++;
+	else
+		vmp->io_rd_cnt++;
+
+	/* update the last access timestamp in the table */
+	lta = per_cpu_ptr(vmp->last_io_time, raw_smp_processor_id());
+	*lta = jiffies;
+}
+
+void lpfc_vmid_assign_cs_ctl(struct lpfc_vport *vport, struct lpfc_vmid *vmid)
+{
+	u32 hash;
+	struct lpfc_vmid *pvmid;
+
+	if (vport->port_type == LPFC_PHYSICAL_PORT) {
+		vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
+	} else {
+		hash = lpfc_vmid_hash_fn(vmid->host_vmid, vmid->vmid_len);
+		pvmid =
+		    lpfc_get_vmid_from_hastable(vport->phba->pport, hash,
+						vmid->host_vmid);
+		if (!pvmid)
+			vmid->un.cs_ctl_vmid = pvmid->un.cs_ctl_vmid;
+		else
+			vmid->un.cs_ctl_vmid = lpfc_vmid_get_cs_ctl(vport);
+	}
+}
+
 /**
  * lpfc_queuecommand - scsi_host_template queuecommand entry point
  * @shost: kernel scsi host pointer.