Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #include "blk-cgroup.h"
0004 
0005 /**
0006  * blkcg_set_fc_appid - set the fc_app_id field associted to blkcg
0007  * @app_id: application identifier
0008  * @cgrp_id: cgroup id
0009  * @app_id_len: size of application identifier
0010  */
0011 int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len)
0012 {
0013     struct cgroup *cgrp;
0014     struct cgroup_subsys_state *css;
0015     struct blkcg *blkcg;
0016     int ret  = 0;
0017 
0018     if (app_id_len > FC_APPID_LEN)
0019         return -EINVAL;
0020 
0021     cgrp = cgroup_get_from_id(cgrp_id);
0022     if (!cgrp)
0023         return -ENOENT;
0024     css = cgroup_get_e_css(cgrp, &io_cgrp_subsys);
0025     if (!css) {
0026         ret = -ENOENT;
0027         goto out_cgrp_put;
0028     }
0029     blkcg = css_to_blkcg(css);
0030     /*
0031      * There is a slight race condition on setting the appid.
0032      * Worst case an I/O may not find the right id.
0033      * This is no different from the I/O we let pass while obtaining
0034      * the vmid from the fabric.
0035      * Adding the overhead of a lock is not necessary.
0036      */
0037     strlcpy(blkcg->fc_app_id, app_id, app_id_len);
0038     css_put(css);
0039 out_cgrp_put:
0040     cgroup_put(cgrp);
0041     return ret;
0042 }
0043 EXPORT_SYMBOL_GPL(blkcg_set_fc_appid);
0044 
0045 /**
0046  * blkcg_get_fc_appid - get the fc app identifier associated with a bio
0047  * @bio: target bio
0048  *
0049  * On success return the fc_app_id, on failure return NULL
0050  */
0051 char *blkcg_get_fc_appid(struct bio *bio)
0052 {
0053     if (!bio->bi_blkg || bio->bi_blkg->blkcg->fc_app_id[0] == '\0')
0054         return NULL;
0055     return bio->bi_blkg->blkcg->fc_app_id;
0056 }
0057 EXPORT_SYMBOL_GPL(blkcg_get_fc_appid);