From patchwork Mon Oct 19 07:42:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar M X-Patchwork-Id: 11844485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECC43157C for ; Mon, 19 Oct 2020 14:36:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C24CD222E7 for ; Mon, 19 Oct 2020 14:36:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="E7MOJv2o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729538AbgJSOgt (ORCPT ); Mon, 19 Oct 2020 10:36:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729517AbgJSOgt (ORCPT ); Mon, 19 Oct 2020 10:36:49 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA051C0613CE for ; Mon, 19 Oct 2020 07:36:48 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id h2so5057967pll.11 for ; Mon, 19 Oct 2020 07:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ncnviJUXH2X+4T5vK9UdFuBhLKCiKrFR+GfZMs64idA=; b=E7MOJv2oU1tuW1LDku+LmU8tzLuzXtwLuspcwUyUQOXScAN1Tb1U7dJLzT7XbYs55+ jt5EFhlXKJhzYrJ634zF7PEF0xrW2t/jdQg8OcLIDuhlAkP3NCeVGZ36bf+XLMTUinBM x460+/HT5jiIEUnptnRC3Go9d+oGzUxFaZjUk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ncnviJUXH2X+4T5vK9UdFuBhLKCiKrFR+GfZMs64idA=; b=Q/rw8sJJCj3himEKxMi/CcZUak6t1Msk0hKwDRuRojUq3Yp8niLGvDtuQ2eNG4Fyox c3byF/p8YubOlOqdEU1lJXe+ijnpNXfZzX+yjc8QoNMBddLYLtbf1ZI0uDTfETkMqV5j QblxXkNbktACN2hK90iRO65qSRRnj+/kPiQzZ7GZ00MyxhNrq5eFbMnEPFl58EhQmL/7 R4GADNoUKr3vOY+nDv9JppRedXhEp5cAy8dge6we3wECnje/O9fSwen1MJOGVBIiw/r6 kWAnQbDCh6qy7MT04BJOdYX+LtNqg4XFuSBVf0VOwwWoqKCmmKWUPo6IwwpOgwlIyxD9 2nDg== X-Gm-Message-State: AOAM530xRSeQre9yTFgyWLc4SX+N2JRsRdTQAV3ZpvQGEXE2S6kKSz75 k8Jf9wmebnOtHDembmqG5qxsRg== X-Google-Smtp-Source: ABdhPJybG5LM3s44DA0zSxT1ERUr5iNljXC3B2Q+FFPm45hn8BP4EDvyClM1MYYQziV1N/SxI0SOtQ== X-Received: by 2002:a17:90b:30d2:: with SMTP id hi18mr116638pjb.86.1603118208434; Mon, 19 Oct 2020 07:36:48 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id kb15sm53377pjb.17.2020.10.19.07.36.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 07:36:47 -0700 (PDT) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, tj@kernel.org, linux-nvme@lists.infradead.org Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, pbonzini@redhat.com, Muneendra Subject: [RFC v2 02/18] blkcg: Added a app identifier support for blkcg Date: Mon, 19 Oct 2020 13:12:57 +0530 Message-Id: <1603093393-12875-3-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603093393-12875-1-git-send-email-muneendra.kumar@broadcom.com> References: <1603093393-12875-1-git-send-email-muneendra.kumar@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This Patch added a unique application identifier i.e app_id knob to blkcg which allows identification of traffic sources at an individual cgroup based Applications (ex:virtual machine (VM))level in both host and fabric infrastructure. Provided the interface blkcg_get_app_identifier to grab the app identifier associated with a bio. Provided the interface blkcg_set_app_identifier to set the app identifier in a blkcgrp associated with cgroup id Signed-off-by: Muneendra --- v2: renamed app_identifier to app_id removed the sysfs interface blkio.app_identifie under /sys/fs/cgroup/blkio Added a new interface blkcg_set_app_identifier --- block/blk-cgroup.c | 31 +++++++++++++++++++++++++++++++ include/linux/blk-cgroup.h | 22 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 619a79b51068..672971521010 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -546,6 +546,37 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg, return __blkg_lookup(blkcg, q, true /* update_hint */); } +/* + * Sets the app_identifier field associted to blkcg + * @buf: application identifier + * @id: cgrp id + * @len: size of appid + */ +int blkcg_set_app_identifier(char *buf, u64 id, size_t len) +{ + struct cgroup *cgrp = NULL; + struct cgroup_subsys_state *css = NULL; + struct blkcg *blkcg = NULL; + + cgrp = cgroup_get_from_kernfs_id(id); + if (!cgrp) + return -ENOENT; + + css = cgroup_get_e_css(cgrp, &io_cgrp_subsys); + if (!css) + return -ENOENT; + + blkcg = css_to_blkcg(css); + if (!blkcg) + return -ENOENT; + + if (len > APPID_LEN) + return -EINVAL; + strlcpy(blkcg->app_id, buf, len); + return 0; +} +EXPORT_SYMBOL(blkcg_set_app_identifier); + /** * blkg_conf_prep - parse and prepare for per-blkg config update * @inputp: input string pointer diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index c8fc9792ac77..5bd3f9f397ac 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -30,6 +30,8 @@ /* Max limits for throttle policy */ #define THROTL_IOPS_MAX UINT_MAX +#define APPID_LEN 128 + #ifdef CONFIG_BLK_CGROUP @@ -55,6 +57,8 @@ struct blkcg { struct blkcg_policy_data *cpd[BLKCG_MAX_POLS]; struct list_head all_blkcgs_node; + char app_id[APPID_LEN]; + #ifdef CONFIG_CGROUP_WRITEBACK struct list_head cgwb_list; #endif @@ -206,6 +210,24 @@ struct gendisk *blkcg_conf_get_disk(char **inputp); int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, char *input, struct blkg_conf_ctx *ctx); void blkg_conf_finish(struct blkg_conf_ctx *ctx); +int blkcg_set_app_identifier(char *buf, u64 id, size_t len); + +/** + * blkcg_get_app_identifier - grab the app identifier associated with a bio + * @bio: target bio + * + * This returns the app identifier associated with a bio, + * %NULL if not associated. + * Callers are expected to either handle %NULL or know association has been + * done prior to calling this. + */ +static inline char *blkcg_get_app_identifier(struct bio *bio) +{ + if (bio && bio->bi_blkg && + strlen(bio->bi_blkg->blkcg->app_id)) + return bio->bi_blkg->blkcg->app_id; + return NULL; +} /** * blkcg_css - find the current css