@@ -661,6 +661,8 @@ static int do_sys_releasedir(const char *path, struct fuse_file_info *fi)
661
661
return __sys_releasedir (path , fi );
662
662
}
663
663
664
+ static bool cgroup_is_enabled = false;
665
+
664
666
#if HAVE_FUSE3
665
667
static int lxcfs_getattr (const char * path , struct stat * sb , struct fuse_file_info * fi )
666
668
#else
@@ -681,7 +683,7 @@ static int lxcfs_getattr(const char *path, struct stat *sb)
681
683
return 0 ;
682
684
}
683
685
684
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
686
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
685
687
up_users ();
686
688
ret = do_cg_getattr (path , sb );
687
689
down_users ();
@@ -712,7 +714,7 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi)
712
714
if (strcmp (path , "/" ) == 0 )
713
715
return 0 ;
714
716
715
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
717
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
716
718
up_users ();
717
719
ret = do_cg_opendir (path , fi );
718
720
down_users ();
@@ -747,13 +749,13 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
747
749
dir_filler (filler , buf , ".." , 0 ) != 0 ||
748
750
dir_filler (filler , buf , "proc" , 0 ) != 0 ||
749
751
dir_filler (filler , buf , "sys" , 0 ) != 0 ||
750
- dir_filler (filler , buf , "cgroup" , 0 ) != 0 )
752
+ ( cgroup_is_enabled && dir_filler (filler , buf , "cgroup" , 0 ) != 0 ) )
751
753
return - ENOMEM ;
752
754
753
755
return 0 ;
754
756
}
755
757
756
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
758
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
757
759
up_users ();
758
760
ret = do_cg_readdir (path , buf , filler , offset , fi );
759
761
down_users ();
@@ -784,7 +786,7 @@ static int lxcfs_access(const char *path, int mode)
784
786
if (strcmp (path , "/" ) == 0 && (mode & W_OK ) == 0 )
785
787
return 0 ;
786
788
787
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
789
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
788
790
up_users ();
789
791
ret = do_cg_access (path , mode );
790
792
down_users ();
@@ -846,7 +848,7 @@ static int lxcfs_open(const char *path, struct fuse_file_info *fi)
846
848
{
847
849
int ret ;
848
850
849
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
851
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
850
852
up_users ();
851
853
ret = do_cg_open (path , fi );
852
854
down_users ();
@@ -875,7 +877,7 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
875
877
{
876
878
int ret ;
877
879
878
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
880
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
879
881
up_users ();
880
882
ret = do_cg_read (path , buf , size , offset , fi );
881
883
down_users ();
@@ -904,7 +906,7 @@ int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
904
906
{
905
907
int ret ;
906
908
907
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
909
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
908
910
up_users ();
909
911
ret = do_cg_write (path , buf , size , offset , fi );
910
912
down_users ();
@@ -983,7 +985,7 @@ int lxcfs_mkdir(const char *path, mode_t mode)
983
985
{
984
986
int ret ;
985
987
986
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
988
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
987
989
up_users ();
988
990
ret = do_cg_mkdir (path , mode );
989
991
down_users ();
@@ -1001,7 +1003,7 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
1001
1003
{
1002
1004
int ret ;
1003
1005
1004
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
1006
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
1005
1007
up_users ();
1006
1008
ret = do_cg_chown (path , uid , gid );
1007
1009
down_users ();
@@ -1028,7 +1030,7 @@ int lxcfs_truncate(const char *path, off_t newsize, struct fuse_file_info *fi)
1028
1030
int lxcfs_truncate (const char * path , off_t newsize )
1029
1031
#endif
1030
1032
{
1031
- if (strncmp (path , "/cgroup" , 7 ) == 0 )
1033
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 )
1032
1034
return 0 ;
1033
1035
1034
1036
if (strncmp (path , "/sys" , 4 ) == 0 )
@@ -1041,7 +1043,7 @@ int lxcfs_rmdir(const char *path)
1041
1043
{
1042
1044
int ret ;
1043
1045
1044
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
1046
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
1045
1047
up_users ();
1046
1048
ret = do_cg_rmdir (path );
1047
1049
down_users ();
@@ -1059,7 +1061,7 @@ int lxcfs_chmod(const char *path, mode_t mode)
1059
1061
{
1060
1062
int ret ;
1061
1063
1062
- if (strncmp (path , "/cgroup" , 7 ) == 0 ) {
1064
+ if (cgroup_is_enabled && strncmp (path , "/cgroup" , 7 ) == 0 ) {
1063
1065
up_users ();
1064
1066
ret = do_cg_chmod (path , mode );
1065
1067
down_users ();
@@ -1190,6 +1192,7 @@ static void usage(void)
1190
1192
lxcfs_info (" -v, --version Print lxcfs version" );
1191
1193
lxcfs_info (" --enable-cfs Enable CPU virtualization via CPU shares" );
1192
1194
lxcfs_info (" --enable-pidfd Use pidfd for process tracking" );
1195
+ lxcfs_info (" --enable-cgroup Enable cgroup emulation code" );
1193
1196
exit (EXIT_FAILURE );
1194
1197
}
1195
1198
@@ -1238,6 +1241,7 @@ static const struct option long_options[] = {
1238
1241
1239
1242
{"enable-cfs" , no_argument , 0 , 0 },
1240
1243
{"enable-pidfd" , no_argument , 0 , 0 },
1244
+ {"enable-cgroup" , no_argument , 0 , 0 },
1241
1245
1242
1246
{"pidfile" , required_argument , 0 , 'p' },
1243
1247
{ },
@@ -1318,6 +1322,8 @@ int main(int argc, char *argv[])
1318
1322
opts -> use_pidfd = true;
1319
1323
else if (strcmp (long_options [idx ].name , "enable-cfs" ) == 0 )
1320
1324
opts -> use_cfs = true;
1325
+ else if (strcmp (long_options [idx ].name , "enable-cgroup" ) == 0 )
1326
+ cgroup_is_enabled = true;
1321
1327
else
1322
1328
usage ();
1323
1329
break ;
0 commit comments