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
2f9928f6
Unverified
Commit
2f9928f6
authored
Jan 12, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: move lxc-clone to API symbols only
Closes #2073. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
78485176
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
45 deletions
+75
-45
lxc_clone.c
src/lxc/tools/lxc_clone.c
+75
-45
No files found.
src/lxc/tools/lxc_clone.c
View file @
2f9928f6
...
@@ -17,25 +17,19 @@
...
@@ -17,25 +17,19 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <getopt.h>
#include <signal.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/types.h>
#include <stdint.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "log.h"
#include "config.h"
#include "lxc.h"
#include "conf.h"
#include "state.h"
/* we pass fssize in bytes */
/* we pass fssize in bytes */
static
uint64_t
get_fssize
(
char
*
s
)
static
uint64_t
get_fssize
(
char
*
s
)
{
{
...
@@ -43,30 +37,33 @@ static uint64_t get_fssize(char *s)
...
@@ -43,30 +37,33 @@ static uint64_t get_fssize(char *s)
char
*
end
;
char
*
end
;
ret
=
strtoull
(
s
,
&
end
,
0
);
ret
=
strtoull
(
s
,
&
end
,
0
);
if
(
end
==
s
)
if
(
end
==
s
)
{
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Invalid blockdev size '%s', using default size
\n
"
,
s
);
"Invalid blockdev size '%s', using default size
\n
"
,
s
);
return
0
;
return
0
;
}
}
while
(
isblank
(
*
end
))
while
(
isblank
(
*
end
))
end
++
;
end
++
;
if
(
*
end
==
'\0'
)
if
(
*
end
==
'\0'
)
{
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
}
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
{
ret
*=
1ULL
;
ret
*=
1ULL
;
else
if
(
*
end
==
'k'
||
*
end
==
'K'
)
}
else
if
(
*
end
==
'k'
||
*
end
==
'K'
)
{
ret
*=
1024ULL
;
ret
*=
1024ULL
;
else
if
(
*
end
==
'm'
||
*
end
==
'M'
)
}
else
if
(
*
end
==
'm'
||
*
end
==
'M'
)
{
ret
*=
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
;
else
if
(
*
end
==
'g'
||
*
end
==
'G'
)
}
else
if
(
*
end
==
'g'
||
*
end
==
'G'
)
{
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
}
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
{
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
else
}
else
{
{
fprintf
(
stderr
,
"Invalid blockdev unit size '%c' in '%s', "
fprintf
(
stderr
,
"Invalid blockdev unit size '%c' in '%s', using default size
\n
"
,
*
end
,
s
);
"using default size
\n
"
,
*
end
,
s
);
return
0
;
return
0
;
}
}
return
ret
;
return
ret
;
}
}
...
@@ -124,42 +121,76 @@ int main(int argc, char *argv[])
...
@@ -124,42 +121,76 @@ int main(int argc, char *argv[])
if
(
argc
<
3
)
if
(
argc
<
3
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
while
(
1
)
{
while
(
true
)
{
c
=
getopt_long
(
argc
,
argv
,
"sB:L:o:n:v:KMHp:P:Rt:h"
,
options
,
&
option_index
);
c
=
getopt_long
(
argc
,
argv
,
"sB:L:o:n:v:KMHp:P:Rt:h"
,
options
,
&
option_index
);
if
(
c
==
-
1
)
if
(
c
==
-
1
)
break
;
break
;
switch
(
c
)
{
switch
(
c
)
{
case
's'
:
snapshot
=
1
;
break
;
case
's'
:
case
'B'
:
bdevtype
=
optarg
;
break
;
snapshot
=
1
;
case
'L'
:
newsize
=
get_fssize
(
optarg
);
break
;
break
;
case
'o'
:
orig
=
optarg
;
break
;
case
'B'
:
case
'n'
:
new
=
optarg
;
break
;
bdevtype
=
optarg
;
case
'v'
:
vgname
=
optarg
;
break
;
break
;
case
'K'
:
keepname
=
1
;
break
;
case
'L'
:
case
'M'
:
keepmac
=
1
;
break
;
newsize
=
get_fssize
(
optarg
);
case
'p'
:
lxcpath
=
optarg
;
break
;
break
;
case
'P'
:
newpath
=
optarg
;
break
;
case
'o'
:
case
'R'
:
rename
=
1
;
break
;
orig
=
optarg
;
case
't'
:
fstype
=
optarg
;
break
;
break
;
case
'h'
:
usage
(
argv
[
0
]);
case
'n'
:
default:
break
;
new
=
optarg
;
break
;
case
'v'
:
vgname
=
optarg
;
break
;
case
'K'
:
keepname
=
1
;
break
;
case
'M'
:
keepmac
=
1
;
break
;
case
'p'
:
lxcpath
=
optarg
;
break
;
case
'P'
:
newpath
=
optarg
;
break
;
case
'R'
:
rename
=
1
;
break
;
case
't'
:
fstype
=
optarg
;
break
;
case
'h'
:
usage
(
argv
[
0
]);
default:
break
;
}
}
}
}
if
(
optind
<
argc
&&
!
orig
)
if
(
optind
<
argc
&&
!
orig
)
orig
=
argv
[
optind
++
];
orig
=
argv
[
optind
++
];
if
(
optind
<
argc
&&
!
new
)
if
(
optind
<
argc
&&
!
new
)
new
=
argv
[
optind
++
];
new
=
argv
[
optind
++
];
if
(
optind
<
argc
)
/* arguments for the clone hook */
/* arguments for the clone hook */
if
(
optind
<
argc
)
args
=
&
argv
[
optind
];
args
=
&
argv
[
optind
];
if
(
!
new
||
!
orig
)
{
if
(
!
new
||
!
orig
)
{
printf
(
"Error: you must provide orig and new names
\n
"
);
printf
(
"Error: you must provide orig and new names
\n
"
);
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
}
}
if
(
snapshot
)
flags
|=
LXC_CLONE_SNAPSHOT
;
if
(
snapshot
)
if
(
keepname
)
flags
|=
LXC_CLONE_KEEPNAME
;
flags
|=
LXC_CLONE_SNAPSHOT
;
if
(
keepmac
)
flags
|=
LXC_CLONE_KEEPMACADDR
;
if
(
keepname
)
flags
|=
LXC_CLONE_KEEPNAME
;
if
(
keepmac
)
flags
|=
LXC_CLONE_KEEPMACADDR
;
/* vgname and fstype could be supported by sending them through the
/* vgname and fstype could be supported by sending them through the
* bdevdata. However, they currently are not yet. I'm not convinced
* bdevdata. However, they currently are not yet. I'm not convinced
...
@@ -201,8 +232,7 @@ int main(int argc, char *argv[])
...
@@ -201,8 +232,7 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
else
{
}
else
{
c2
=
c1
->
clone
(
c1
,
new
,
newpath
,
flags
,
bdevtype
,
NULL
,
newsize
,
c2
=
c1
->
clone
(
c1
,
new
,
newpath
,
flags
,
bdevtype
,
NULL
,
newsize
,
args
);
args
);
if
(
c2
==
NULL
)
{
if
(
c2
==
NULL
)
{
lxc_container_put
(
c1
);
lxc_container_put
(
c1
);
fprintf
(
stderr
,
"clone failed
\n
"
);
fprintf
(
stderr
,
"clone failed
\n
"
);
...
...
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