Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: blkcg: Add app identifier support for blkcg

Add a unique application identifier (i.e fc_app_id member) in blkcg. This
allows identification of traffic belonging to an specific both on the host
and in the fabric infrastructure. As an example, this allows the storage
stack to uniquely identify traffic belong to particular virtual machine.

Link: https://lore.kernel.org/r/20210608043556.274139-3-muneendra.kumar@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Muneendra Kumar <muneendra.kumar@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Muneendra Kumar and committed by
Martin K. Petersen
d2bcbeab 6b658c48

+85
+9
block/Kconfig
··· 144 144 145 145 Note, this is an experimental interface and could be changed someday. 146 146 147 + config BLK_CGROUP_FC_APPID 148 + bool "Enable support to track FC I/O Traffic across cgroup applications" 149 + depends on BLK_CGROUP=y 150 + help 151 + Enabling this option enables the support to track FC I/O traffic across 152 + cgroup applications. It enables the Fabric and the storage targets to 153 + identify, monitor, and handle FC traffic based on VM tags by inserting 154 + application specific identification into the FC frame. 155 + 147 156 config BLK_CGROUP_IOCOST 148 157 bool "Enable support for cost model based cgroup IO controller" 149 158 depends on BLK_CGROUP=y
+13
drivers/scsi/Kconfig
··· 235 235 each attached FiberChannel device to sysfs, say Y. 236 236 Otherwise, say N. 237 237 238 + config FC_APPID 239 + bool "Enable support to track FC I/O Traffic" 240 + depends on BLOCK && BLK_CGROUP 241 + depends on SCSI 242 + select BLK_CGROUP_FC_APPID 243 + default y 244 + help 245 + If you say Y here, it enables the support to track 246 + FC I/O traffic over fabric. It enables the Fabric and the 247 + storage targets to identify, monitor, and handle FC traffic 248 + based on VM tags by inserting application specific 249 + identification into the FC frame. 250 + 238 251 config SCSI_ISCSI_ATTRS 239 252 tristate "iSCSI Transport Attributes" 240 253 depends on SCSI && NET
+63
include/linux/blk-cgroup.h
··· 30 30 31 31 /* Max limits for throttle policy */ 32 32 #define THROTL_IOPS_MAX UINT_MAX 33 + #define FC_APPID_LEN 129 34 + 33 35 34 36 #ifdef CONFIG_BLK_CGROUP 35 37 ··· 57 55 struct blkcg_policy_data *cpd[BLKCG_MAX_POLS]; 58 56 59 57 struct list_head all_blkcgs_node; 58 + #ifdef CONFIG_BLK_CGROUP_FC_APPID 59 + char fc_app_id[FC_APPID_LEN]; 60 + #endif 60 61 #ifdef CONFIG_CGROUP_WRITEBACK 61 62 struct list_head cgwb_list; 62 63 #endif ··· 665 660 666 661 #endif /* CONFIG_BLOCK */ 667 662 #endif /* CONFIG_BLK_CGROUP */ 663 + 664 + #ifdef CONFIG_BLK_CGROUP_FC_APPID 665 + /* 666 + * Sets the fc_app_id field associted to blkcg 667 + * @app_id: application identifier 668 + * @cgrp_id: cgroup id 669 + * @app_id_len: size of application identifier 670 + */ 671 + static inline int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len) 672 + { 673 + struct cgroup *cgrp; 674 + struct cgroup_subsys_state *css; 675 + struct blkcg *blkcg; 676 + int ret = 0; 677 + 678 + if (app_id_len > FC_APPID_LEN) 679 + return -EINVAL; 680 + 681 + cgrp = cgroup_get_from_id(cgrp_id); 682 + if (!cgrp) 683 + return -ENOENT; 684 + css = cgroup_get_e_css(cgrp, &io_cgrp_subsys); 685 + if (!css) { 686 + ret = -ENOENT; 687 + goto out_cgrp_put; 688 + } 689 + blkcg = css_to_blkcg(css); 690 + /* 691 + * There is a slight race condition on setting the appid. 692 + * Worst case an I/O may not find the right id. 693 + * This is no different from the I/O we let pass while obtaining 694 + * the vmid from the fabric. 695 + * Adding the overhead of a lock is not necessary. 696 + */ 697 + strlcpy(blkcg->fc_app_id, app_id, app_id_len); 698 + css_put(css); 699 + out_cgrp_put: 700 + cgroup_put(cgrp); 701 + return ret; 702 + } 703 + 704 + /** 705 + * blkcg_get_fc_appid - get the fc app identifier associated with a bio 706 + * @bio: target bio 707 + * 708 + * On success return the fc_app_id, on failure return NULL 709 + */ 710 + static inline char *blkcg_get_fc_appid(struct bio *bio) 711 + { 712 + if (bio && bio->bi_blkg && 713 + (bio->bi_blkg->blkcg->fc_app_id[0] != '\0')) 714 + return bio->bi_blkg->blkcg->fc_app_id; 715 + return NULL; 716 + } 717 + #else 718 + static inline int blkcg_set_fc_appid(char *buf, u64 id, size_t len) { return -EINVAL; } 719 + static inline char *blkcg_get_fc_appid(struct bio *bio) { return NULL; } 720 + #endif /*CONFIG_BLK_CGROUP_FC_APPID*/ 668 721 #endif /* _BLK_CGROUP_H */