aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2019-08-28 18:05:53 -0400
committerJens Axboe <axboe@kernel.dk>2019-08-28 23:17:04 -0400
commit015d254cb02b6d8eec4b3366274bf4672f9e0b64 (patch)
treea0157e4d1ded778a3aefe989666bf7151aeb0a1b /block/blk-cgroup.c
parent86a5bba5c252e90d264c7460e29a0b9e633777e7 (diff)
blkcg: separate blkcg_conf_get_disk() out of blkg_conf_prep()
Separate out blkcg_conf_get_disk() so that it can be used by blkcg policy interface file input parsers before the policy is actually enabled. This doesn't introduce any functional changes. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-cgroup.c')
-rw-r--r--block/blk-cgroup.c62
1 files changed, 43 insertions, 19 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 78ccbdcfe723..0e2619c1a422 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -755,6 +755,44 @@ static struct blkcg_gq *blkg_lookup_check(struct blkcg *blkcg,
755 755
756/** 756/**
757 * blkg_conf_prep - parse and prepare for per-blkg config update 757 * blkg_conf_prep - parse and prepare for per-blkg config update
758 * @inputp: input string pointer
759 *
760 * Parse the device node prefix part, MAJ:MIN, of per-blkg config update
761 * from @input and get and return the matching gendisk. *@inputp is
762 * updated to point past the device node prefix. Returns an ERR_PTR()
763 * value on error.
764 *
765 * Use this function iff blkg_conf_prep() can't be used for some reason.
766 */
767struct gendisk *blkcg_conf_get_disk(char **inputp)
768{
769 char *input = *inputp;
770 unsigned int major, minor;
771 struct gendisk *disk;
772 int key_len, part;
773
774 if (sscanf(input, "%u:%u%n", &major, &minor, &key_len) != 2)
775 return ERR_PTR(-EINVAL);
776
777 input += key_len;
778 if (!isspace(*input))
779 return ERR_PTR(-EINVAL);
780 input = skip_spaces(input);
781
782 disk = get_gendisk(MKDEV(major, minor), &part);
783 if (!disk)
784 return ERR_PTR(-ENODEV);
785 if (part) {
786 put_disk_and_module(disk);
787 return ERR_PTR(-ENODEV);
788 }
789
790 *inputp = input;
791 return disk;
792}
793
794/**
795 * blkg_conf_prep - parse and prepare for per-blkg config update
758 * @blkcg: target block cgroup 796 * @blkcg: target block cgroup
759 * @pol: target policy 797 * @pol: target policy
760 * @input: input string 798 * @input: input string
@@ -772,25 +810,11 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
772 struct gendisk *disk; 810 struct gendisk *disk;
773 struct request_queue *q; 811 struct request_queue *q;
774 struct blkcg_gq *blkg; 812 struct blkcg_gq *blkg;
775 unsigned int major, minor; 813 int ret;
776 int key_len, part, ret;
777 char *body;
778
779 if (sscanf(input, "%u:%u%n", &major, &minor, &key_len) != 2)
780 return -EINVAL;
781
782 body = input + key_len;
783 if (!isspace(*body))
784 return -EINVAL;
785 body = skip_spaces(body);
786 814
787 disk = get_gendisk(MKDEV(major, minor), &part); 815 disk = blkcg_conf_get_disk(&input);
788 if (!disk) 816 if (IS_ERR(disk))
789 return -ENODEV; 817 return PTR_ERR(disk);
790 if (part) {
791 ret = -ENODEV;
792 goto fail;
793 }
794 818
795 q = disk->queue; 819 q = disk->queue;
796 820
@@ -856,7 +880,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
856success: 880success:
857 ctx->disk = disk; 881 ctx->disk = disk;
858 ctx->blkg = blkg; 882 ctx->blkg = blkg;
859 ctx->body = body; 883 ctx->body = input;
860 return 0; 884 return 0;
861 885
862fail_unlock: 886fail_unlock: