162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci#include "blk-cgroup.h" 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci/** 662306a36Sopenharmony_ci * blkcg_set_fc_appid - set the fc_app_id field associted to blkcg 762306a36Sopenharmony_ci * @app_id: application identifier 862306a36Sopenharmony_ci * @cgrp_id: cgroup id 962306a36Sopenharmony_ci * @app_id_len: size of application identifier 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ciint blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len) 1262306a36Sopenharmony_ci{ 1362306a36Sopenharmony_ci struct cgroup *cgrp; 1462306a36Sopenharmony_ci struct cgroup_subsys_state *css; 1562306a36Sopenharmony_ci struct blkcg *blkcg; 1662306a36Sopenharmony_ci int ret = 0; 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci if (app_id_len > FC_APPID_LEN) 1962306a36Sopenharmony_ci return -EINVAL; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci cgrp = cgroup_get_from_id(cgrp_id); 2262306a36Sopenharmony_ci if (IS_ERR(cgrp)) 2362306a36Sopenharmony_ci return PTR_ERR(cgrp); 2462306a36Sopenharmony_ci css = cgroup_get_e_css(cgrp, &io_cgrp_subsys); 2562306a36Sopenharmony_ci if (!css) { 2662306a36Sopenharmony_ci ret = -ENOENT; 2762306a36Sopenharmony_ci goto out_cgrp_put; 2862306a36Sopenharmony_ci } 2962306a36Sopenharmony_ci blkcg = css_to_blkcg(css); 3062306a36Sopenharmony_ci /* 3162306a36Sopenharmony_ci * There is a slight race condition on setting the appid. 3262306a36Sopenharmony_ci * Worst case an I/O may not find the right id. 3362306a36Sopenharmony_ci * This is no different from the I/O we let pass while obtaining 3462306a36Sopenharmony_ci * the vmid from the fabric. 3562306a36Sopenharmony_ci * Adding the overhead of a lock is not necessary. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_ci strscpy(blkcg->fc_app_id, app_id, app_id_len); 3862306a36Sopenharmony_ci css_put(css); 3962306a36Sopenharmony_ciout_cgrp_put: 4062306a36Sopenharmony_ci cgroup_put(cgrp); 4162306a36Sopenharmony_ci return ret; 4262306a36Sopenharmony_ci} 4362306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(blkcg_set_fc_appid); 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/** 4662306a36Sopenharmony_ci * blkcg_get_fc_appid - get the fc app identifier associated with a bio 4762306a36Sopenharmony_ci * @bio: target bio 4862306a36Sopenharmony_ci * 4962306a36Sopenharmony_ci * On success return the fc_app_id, on failure return NULL 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_cichar *blkcg_get_fc_appid(struct bio *bio) 5262306a36Sopenharmony_ci{ 5362306a36Sopenharmony_ci if (!bio->bi_blkg || bio->bi_blkg->blkcg->fc_app_id[0] == '\0') 5462306a36Sopenharmony_ci return NULL; 5562306a36Sopenharmony_ci return bio->bi_blkg->blkcg->fc_app_id; 5662306a36Sopenharmony_ci} 5762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(blkcg_get_fc_appid); 58