@@ -6224,16 +6224,36 @@ void cgroup_fork(struct task_struct *child)
6224
6224
INIT_LIST_HEAD (& child -> cg_list );
6225
6225
}
6226
6226
6227
- static struct cgroup * cgroup_get_from_file (struct file * f )
6227
+ /**
6228
+ * cgroup_v1v2_get_from_file - get a cgroup pointer from a file pointer
6229
+ * @f: file corresponding to cgroup_dir
6230
+ *
6231
+ * Find the cgroup from a file pointer associated with a cgroup directory.
6232
+ * Returns a pointer to the cgroup on success. ERR_PTR is returned if the
6233
+ * cgroup cannot be found.
6234
+ */
6235
+ static struct cgroup * cgroup_v1v2_get_from_file (struct file * f )
6228
6236
{
6229
6237
struct cgroup_subsys_state * css ;
6230
- struct cgroup * cgrp ;
6231
6238
6232
6239
css = css_tryget_online_from_dir (f -> f_path .dentry , NULL );
6233
6240
if (IS_ERR (css ))
6234
6241
return ERR_CAST (css );
6235
6242
6236
- cgrp = css -> cgroup ;
6243
+ return css -> cgroup ;
6244
+ }
6245
+
6246
+ /**
6247
+ * cgroup_get_from_file - same as cgroup_v1v2_get_from_file, but only supports
6248
+ * cgroup2.
6249
+ */
6250
+ static struct cgroup * cgroup_get_from_file (struct file * f )
6251
+ {
6252
+ struct cgroup * cgrp = cgroup_v1v2_get_from_file (f );
6253
+
6254
+ if (IS_ERR (cgrp ))
6255
+ return ERR_CAST (cgrp );
6256
+
6237
6257
if (!cgroup_on_dfl (cgrp )) {
6238
6258
cgroup_put (cgrp );
6239
6259
return ERR_PTR (- EBADF );
@@ -6734,14 +6754,14 @@ EXPORT_SYMBOL_GPL(cgroup_get_from_path);
6734
6754
6735
6755
/**
6736
6756
* cgroup_get_from_fd - get a cgroup pointer from a fd
6737
- * @fd: fd obtained by open(cgroup2_dir )
6757
+ * @fd: fd obtained by open(cgroup_dir )
6738
6758
*
6739
6759
* Find the cgroup from a fd which should be obtained
6740
6760
* by opening a cgroup directory. Returns a pointer to the
6741
6761
* cgroup on success. ERR_PTR is returned if the cgroup
6742
6762
* cannot be found.
6743
6763
*/
6744
- struct cgroup * cgroup_get_from_fd (int fd )
6764
+ struct cgroup * cgroup_v1v2_get_from_fd (int fd )
6745
6765
{
6746
6766
struct cgroup * cgrp ;
6747
6767
struct file * f ;
@@ -6750,10 +6770,28 @@ struct cgroup *cgroup_get_from_fd(int fd)
6750
6770
if (!f )
6751
6771
return ERR_PTR (- EBADF );
6752
6772
6753
- cgrp = cgroup_get_from_file (f );
6773
+ cgrp = cgroup_v1v2_get_from_file (f );
6754
6774
fput (f );
6755
6775
return cgrp ;
6756
6776
}
6777
+
6778
+ /**
6779
+ * cgroup_get_from_fd - same as cgroup_v1v2_get_from_fd, but only supports
6780
+ * cgroup2.
6781
+ */
6782
+ struct cgroup * cgroup_get_from_fd (int fd )
6783
+ {
6784
+ struct cgroup * cgrp = cgroup_v1v2_get_from_fd (fd );
6785
+
6786
+ if (IS_ERR (cgrp ))
6787
+ return ERR_CAST (cgrp );
6788
+
6789
+ if (!cgroup_on_dfl (cgrp )) {
6790
+ cgroup_put (cgrp );
6791
+ return ERR_PTR (- EBADF );
6792
+ }
6793
+ return cgrp ;
6794
+ }
6757
6795
EXPORT_SYMBOL_GPL (cgroup_get_from_fd );
6758
6796
6759
6797
static u64 power_of_ten (int power )
0 commit comments