Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
102a5303
Commit
102a5303
authored
Oct 09, 2009
by
Daniel Lezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the configuration structure for the cgroup
Do not use the directory configuration Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
9f44c578
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
127 deletions
+11
-127
conf.c
src/lxc/conf.c
+11
-127
No files found.
src/lxc/conf.c
View file @
102a5303
...
...
@@ -373,34 +373,6 @@ out:
return
err
;
}
static
int
configure_cgroup
(
const
char
*
name
,
struct
lxc_list
*
cgroup
)
{
char
path
[
MAXPATHLEN
];
struct
lxc_list
*
iterator
;
struct
lxc_cgroup
*
cg
;
FILE
*
file
;
if
(
lxc_list_empty
(
cgroup
))
return
0
;
snprintf
(
path
,
MAXPATHLEN
,
LXCPATH
"/%s/cgroup"
,
name
);
file
=
fopen
(
path
,
"w+"
);
if
(
!
file
)
{
SYSERROR
(
"failed to open '%s'"
,
path
);
return
-
1
;
}
lxc_list_for_each
(
iterator
,
cgroup
)
{
cg
=
iterator
->
elem
;
fprintf
(
file
,
"%s=%s
\n
"
,
cg
->
subsystem
,
cg
->
value
);
}
fclose
(
file
);
return
0
;
}
static
int
configure_find_fstype_cb
(
void
*
buffer
,
void
*
data
)
{
struct
cbarg
{
...
...
@@ -876,107 +848,24 @@ static int setup_console(const char *rootfs, const char *tty)
return
0
;
}
static
int
setup_cgroup
_cb
(
void
*
buffer
,
void
*
data
)
static
int
setup_cgroup
(
const
char
*
name
,
struct
lxc_list
*
cgroups
)
{
char
*
key
=
buffer
,
*
value
;
char
*
name
=
data
;
int
ret
;
value
=
strchr
(
key
,
'='
);
if
(
!
value
)
return
-
1
;
*
value
=
'\0'
;
value
+=
1
;
/* remove spurious '\n'*/
if
(
value
[
strlen
(
value
)
-
1
]
==
'\n'
)
value
[
strlen
(
value
)
-
1
]
=
'\0'
;
ret
=
lxc_cgroup_set
(
name
,
key
,
value
);
if
(
ret
)
ERROR
(
"failed to set cgroup '%s' = '%s' for '%s'"
,
key
,
value
,
name
);
else
DEBUG
(
"cgroup '%s' set to '%s'"
,
key
,
value
);
return
ret
;
}
static
int
setup_convert_cgroup_cb
(
const
char
*
name
,
const
char
*
directory
,
const
char
*
file
,
void
*
data
)
{
FILE
*
f
=
data
;
char
line
[
MAXPATHLEN
];
if
(
read_info
(
directory
,
file
,
line
,
MAXPATHLEN
))
{
ERROR
(
"failed to read %s"
,
file
);
return
-
1
;
}
fprintf
(
f
,
"%s=%s
\n
"
,
file
,
line
);
return
0
;
}
static
int
setup_convert_cgroup
(
const
char
*
name
,
char
*
directory
)
{
char
filename
[
MAXPATHLEN
];
FILE
*
file
;
int
ret
;
snprintf
(
filename
,
MAXPATHLEN
,
LXCPATH
"/%s/cgroup.new"
,
name
);
file
=
fopen
(
filename
,
"w+"
);
if
(
!
file
)
return
-
1
;
ret
=
lxc_dir_for_each
(
name
,
directory
,
setup_convert_cgroup_cb
,
file
);
if
(
ret
)
goto
out_error
;
ret
=
unconfigure_cgroup
(
name
);
if
(
ret
)
goto
out_error
;
ret
=
rename
(
filename
,
directory
);
if
(
ret
)
goto
out_error
;
out:
fclose
(
file
);
return
ret
;
struct
lxc_list
*
iterator
;
struct
lxc_cgroup
*
cg
;
out_error:
unlink
(
filename
);
goto
out
;
}
if
(
lxc_list_empty
(
cgroups
))
return
0
;
static
int
setup_cgroup
(
const
char
*
name
)
{
char
filename
[
MAXPATHLEN
];
char
line
[
MAXPATHLEN
];
struct
stat
s
;
int
ret
;
lxc_list_for_each
(
iterator
,
cgroups
)
{
snprintf
(
filename
,
MAXPATHLEN
,
LXCPATH
"/%s/cgroup"
,
name
)
;
cg
=
iterator
->
elem
;
if
(
stat
(
filename
,
&
s
))
{
SYSERROR
(
"failed to stat '%s'"
,
filename
);
return
-
1
;
}
if
(
lxc_cgroup_set
(
name
,
cg
->
subsystem
,
cg
->
value
))
break
;
if
(
S_ISDIR
(
s
.
st_mode
))
{
if
(
setup_convert_cgroup
(
name
,
filename
))
{
ERROR
(
"failed to convert old cgroup configuration"
);
return
-
1
;
}
DEBUG
(
"cgroup '%s' set to '%s'"
,
cg
->
subsystem
,
cg
->
value
);
}
ret
=
lxc_file_for_each_line
(
filename
,
setup_cgroup_cb
,
line
,
MAXPATHLEN
,
(
void
*
)
name
);
if
(
ret
)
return
ret
;
INFO
(
"cgroup has been setup"
);
return
0
;
...
...
@@ -1363,11 +1252,6 @@ int lxc_configure(const char *name, struct lxc_conf *conf)
if
(
!
conf
)
return
0
;
if
(
configure_cgroup
(
name
,
&
conf
->
cgroup
))
{
ERROR
(
"failed to configure the control group"
);
return
-
1
;
}
if
(
configure_network
(
name
,
&
conf
->
networks
))
{
ERROR
(
"failed to configure the network"
);
return
-
1
;
...
...
@@ -1769,7 +1653,7 @@ int lxc_setup(const char *name, const char *cons,
return
-
1
;
}
if
(
!
lxc_list_empty
(
&
lxc_conf
.
cgroup
)
&&
setup_cgroup
(
name
))
{
if
(
setup_cgroup
(
name
,
&
lxc_conf
.
cgroup
))
{
ERROR
(
"failed to setup the cgroups for '%s'"
,
name
);
return
-
1
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment