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
ad3ac5e0
Commit
ad3ac5e0
authored
Nov 19, 2009
by
Michel Normand
Committed by
Daniel Lezcano
Nov 19, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change C/R api
Change Checkpoint / Restart API Signed-off-by:
Michel Normand
<
normand@fr.ibm.com
>
Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
55237dfa
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
61 deletions
+48
-61
arguments.h
src/lxc/arguments.h
+1
-2
checkpoint.c
src/lxc/checkpoint.c
+1
-1
lxc.h
src/lxc/lxc.h
+16
-13
lxc_checkpoint.c
src/lxc/lxc_checkpoint.c
+12
-34
lxc_restart.c
src/lxc/lxc_restart.c
+16
-10
restart.c
src/lxc/restart.c
+2
-1
No files found.
src/lxc/arguments.h
View file @
ad3ac5e0
...
...
@@ -47,8 +47,7 @@ struct lxc_arguments {
const
char
*
statefile
;
/* for lxc-checkpoint */
int
kill
;
int
pause
;
int
flags
;
/* for lxc-console */
int
ttynum
;
...
...
src/lxc/checkpoint.c
View file @
ad3ac5e0
...
...
@@ -25,7 +25,7 @@
lxc_log_define
(
lxc_checkpoint
,
lxc
);
int
lxc_checkpoint
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
)
int
lxc_checkpoint
(
const
char
*
name
,
const
char
*
statefile
,
int
flags
)
{
return
0
;
}
src/lxc/lxc.h
View file @
ad3ac5e0
...
...
@@ -27,17 +27,17 @@
extern
"C"
{
#endif
#include <stddef.h>
#include <lxc/state.h>
struct
lxc_msg
;
/**
Following code is for liblxc.
lxc/lxc.h will contain exports of liblxc
**/
#include <stddef.h>
#include <lxc/state.h>
struct
lxc_msg
;
/*
* Start the specified command inside a container
* @name : the name of the container
...
...
@@ -139,22 +139,25 @@ extern int lxc_cgroup_get(const char *name, const char *subsystem,
extern
const
char
*
lxc_strerror
(
int
error
);
/*
* Checkpoint a container
previously frozen
* Checkpoint a container
* @name : the name of the container being checkpointed
* @
fd : file descriptor
on which the container is checkpointed
* @flags : checkpoint flags
* @
statefile: string object
on which the container is checkpointed
* @flags : checkpoint flags
(an ORed value)
* Returns 0 on success, < 0 otherwise
*/
extern
int
lxc_checkpoint
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
);
extern
int
lxc_checkpoint
(
const
char
*
name
,
const
char
*
statefile
,
int
flags
);
#define LXC_FLAG_PAUSE 1
#define LXC_FLAG_HALT 2
/*
* Restart a container
previously frozen
* Restart a container
* @name : the name of the container being restarted
* @fd : file descriptor from which the container is restarted
* @flags : restart flags
* @statefile: string object from which the container is restarted
* @rcfile: container configuration file.
* @flags : restart flags (an ORed value)
* Returns 0 on success, < 0 otherwise
*/
extern
int
lxc_restart
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
);
extern
int
lxc_restart
(
const
char
*
,
const
char
*
,
const
char
*
,
int
);
/*
* Returns the version number of the library
...
...
src/lxc/lxc_checkpoint.c
View file @
ad3ac5e0
...
...
@@ -23,8 +23,9 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <lxc/lxc.h>
...
...
@@ -49,8 +50,8 @@ static int my_checker(const struct lxc_arguments* args)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
'k'
:
args
->
kill
=
1
;
break
;
case
'p'
:
args
->
pause
=
1
;
break
;
case
'k'
:
args
->
flags
=
LXC_FLAG_HALT
;
break
;
case
'p'
:
args
->
flags
=
LXC_FLAG_PAUSE
;
break
;
case
'd'
:
args
->
statefile
=
arg
;
break
;
}
return
0
;
...
...
@@ -83,40 +84,19 @@ Options :\n\
.
rcfile
=
NULL
,
};
static
int
save_config_file
(
const
char
*
name
,
const
char
*
dir
)
static
int
create_statefile
(
const
char
*
dir
)
{
char
*
src
,
*
dst
;
int
ret
;
if
(
!
asprintf
(
&
src
,
LXCPATH
"/%s/config"
,
name
))
{
ERROR
(
"failed to allocate memory"
);
return
-
1
;
}
if
(
access
(
src
,
F_OK
))
{
free
(
src
);
return
0
;
}
if
(
!
asprintf
(
&
dst
,
"%s/config"
,
dir
))
{
ERROR
(
"failed to allocate memory"
);
free
(
src
);
if
(
mkdir
(
dir
,
0700
)
==
-
1
&&
errno
!=
EEXIST
)
{
ERROR
(
"'%s' creation error : %m"
,
dir
);
return
-
1
;
}
ret
=
lxc_copy_file
(
src
,
dst
);
if
(
ret
)
ERROR
(
"failed to copy '%s' to '%s'"
,
src
,
dst
);
free
(
src
);
free
(
dst
);
return
ret
;
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
ret
=
-
1
;
int
ret
;
ret
=
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
);
if
(
ret
)
...
...
@@ -127,13 +107,11 @@ int main(int argc, char *argv[])
if
(
ret
)
return
ret
;
ret
=
save_config_file
(
my_args
.
name
,
my_args
.
statefile
);
if
(
ret
)
{
ERROR
(
"failed to save the configuration"
);
ret
=
create_statefile
(
my_args
.
statefile
);
if
(
ret
)
return
ret
;
}
ret
=
lxc_checkpoint
(
my_args
.
name
,
-
1
,
0
);
ret
=
lxc_checkpoint
(
my_args
.
name
,
my_args
.
statefile
,
my_args
.
flags
);
if
(
ret
)
{
ERROR
(
"failed to checkpoint '%s'"
,
my_args
.
name
);
return
ret
;
...
...
src/lxc/lxc_restart.c
View file @
ad3ac5e0
...
...
@@ -20,8 +20,10 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <libgen.h>
#undef _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
...
...
@@ -30,6 +32,8 @@
#include "arguments.h"
lxc_log_define
(
lxc_restart
,
lxc
);
static
int
my_checker
(
const
struct
lxc_arguments
*
args
)
{
if
(
!
args
->
statefile
)
{
...
...
@@ -43,9 +47,9 @@ static int my_checker(const struct lxc_arguments* args)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
'd'
:
args
->
statefile
=
arg
;
break
;
case
'd'
:
args
->
statefile
=
arg
;
break
;
case
'f'
:
args
->
rcfile
=
arg
;
break
;
case
'p'
:
args
->
flags
=
LXC_FLAG_PAUSE
;
break
;
}
return
0
;
...
...
@@ -53,6 +57,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
static
const
struct
option
my_longopts
[]
=
{
{
"directory"
,
required_argument
,
0
,
'd'
},
{
"rcfile"
,
required_argument
,
0
,
'f'
},
{
"pause"
,
no_argument
,
0
,
'p'
},
LXC_COMMON_OPTIONS
};
...
...
@@ -64,8 +70,10 @@ static struct lxc_arguments my_args = {
lxc-restart restarts from STATEFILE the NAME container
\n
\
\n
\
Options :
\n
\
-n, --name=NAME NAME for name of the container
\n
\
-d, --directory=STATEFILE for name of statefile
\n
"
,
-n, --name=NAME NAME for name of the container
\n
\
-p, --pause do not release the container after the restart
\n
\
-d, --directory=STATEFILE for name of statefile
\n
\
-f, --rcfile=FILE Load configuration file FILE
\n
"
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
checker
=
my_checker
,
...
...
@@ -80,8 +88,6 @@ int main(int argc, char *argv[])
my_args
.
progname
,
my_args
.
quiet
))
return
-
1
;
if
(
lxc_restart
(
my_args
.
name
,
-
1
,
0
))
return
-
1
;
return
0
;
return
lxc_restart
(
my_args
.
name
,
my_args
.
statefile
,
my_args
.
rcfile
,
my_args
.
flags
);
}
src/lxc/restart.c
View file @
ad3ac5e0
...
...
@@ -25,7 +25,8 @@
lxc_log_define
(
lxc_restart
,
lxc
);
int
lxc_restart
(
const
char
*
name
,
int
fd
,
unsigned
long
flags
)
int
lxc_restart
(
const
char
*
name
,
const
char
*
statefile
,
const
char
*
rcfile
,
int
flags
)
{
return
0
;
}
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