]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - block/bio.c
Merge tag 'libnvdimm-for-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw...
[karo-tx-linux.git] / block / bio.c
index 259197d97de1a6e5705457f58dc7727665ab1a93..2a00d349cd6883cba32d9fd477251889a1c58081 100644 (file)
@@ -1988,6 +1988,28 @@ struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int front_
 EXPORT_SYMBOL(bioset_create_nobvec);
 
 #ifdef CONFIG_BLK_CGROUP
+
+/**
+ * bio_associate_blkcg - associate a bio with the specified blkcg
+ * @bio: target bio
+ * @blkcg_css: css of the blkcg to associate
+ *
+ * Associate @bio with the blkcg specified by @blkcg_css.  Block layer will
+ * treat @bio as if it were issued by a task which belongs to the blkcg.
+ *
+ * This function takes an extra reference of @blkcg_css which will be put
+ * when @bio is released.  The caller must own @bio and is responsible for
+ * synchronizing calls to this function.
+ */
+int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css)
+{
+       if (unlikely(bio->bi_css))
+               return -EBUSY;
+       css_get(blkcg_css);
+       bio->bi_css = blkcg_css;
+       return 0;
+}
+
 /**
  * bio_associate_current - associate a bio with %current
  * @bio: target bio
@@ -2004,26 +2026,17 @@ EXPORT_SYMBOL(bioset_create_nobvec);
 int bio_associate_current(struct bio *bio)
 {
        struct io_context *ioc;
-       struct cgroup_subsys_state *css;
 
-       if (bio->bi_ioc)
+       if (bio->bi_css)
                return -EBUSY;
 
        ioc = current->io_context;
        if (!ioc)
                return -ENOENT;
 
-       /* acquire active ref on @ioc and associate */
        get_io_context_active(ioc);
        bio->bi_ioc = ioc;
-
-       /* associate blkcg if exists */
-       rcu_read_lock();
-       css = task_css(current, blkio_cgrp_id);
-       if (css && css_tryget_online(css))
-               bio->bi_css = css;
-       rcu_read_unlock();
-
+       bio->bi_css = task_get_css(current, blkio_cgrp_id);
        return 0;
 }