Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
e82c9136
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e82c9136
编写于
8月 13, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor LXC driver to pass tty/socket state directly
上级
415b9210
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
111 addition
and
196 deletion
+111
-196
ChangeLog
ChangeLog
+7
-0
src/lxc_conf.c
src/lxc_conf.c
+0
-1
src/lxc_conf.h
src/lxc_conf.h
+0
-12
src/lxc_container.c
src/lxc_container.c
+28
-32
src/lxc_container.h
src/lxc_container.h
+14
-0
src/lxc_driver.c
src/lxc_driver.c
+62
-151
未找到文件。
ChangeLog
浏览文件 @
e82c9136
Wed Aug 13 10:55:36 BST 2008 Daniel Berrange <berrange@redhat.com>
* src/lxc_conf.h, src/lxc_conf.c, src/lxc_container.h,
src/lxc_container.c, src/lxc_driver.c: Don't store socket
or tty state in lxc_vm_t struct. Pass it around as args
to functions when needed
Wed Aug 13 11:43:36 CEST 2008 Daniel Veillard <veillard@redhat.com>
Wed Aug 13 11:43:36 CEST 2008 Daniel Veillard <veillard@redhat.com>
* docs/storage.html[.in] src/storage_backend_disk.c: revert previous
* docs/storage.html[.in] src/storage_backend_disk.c: revert previous
...
...
src/lxc_conf.c
浏览文件 @
e82c9136
...
@@ -1041,7 +1041,6 @@ void lxcFreeVMs(lxc_vm_t *vms)
...
@@ -1041,7 +1041,6 @@ void lxcFreeVMs(lxc_vm_t *vms)
void
lxcFreeVM
(
lxc_vm_t
*
vm
)
void
lxcFreeVM
(
lxc_vm_t
*
vm
)
{
{
lxcFreeVMDef
(
vm
->
def
);
lxcFreeVMDef
(
vm
->
def
);
VIR_FREE
(
vm
->
containerTty
);
VIR_FREE
(
vm
);
VIR_FREE
(
vm
);
}
}
...
...
src/lxc_conf.h
浏览文件 @
e82c9136
...
@@ -35,12 +35,6 @@
...
@@ -35,12 +35,6 @@
#define LXC_MAX_XML_LENGTH 16384
#define LXC_MAX_XML_LENGTH 16384
#define LXC_MAX_ERROR_LEN 1024
#define LXC_MAX_ERROR_LEN 1024
#define LXC_DOMAIN_TYPE "lxc"
#define LXC_DOMAIN_TYPE "lxc"
#define LXC_PARENT_SOCKET 0
#define LXC_CONTAINER_SOCKET 1
/* messages between parent and container */
typedef
char
lxc_message_t
;
#define LXC_CONTINUE_MSG 'c'
/* types of networks for containers */
/* types of networks for containers */
enum
lxc_net_type
{
enum
lxc_net_type
{
...
@@ -99,12 +93,6 @@ struct __lxc_vm {
...
@@ -99,12 +93,6 @@ struct __lxc_vm {
char
ttyPidFile
[
PATH_MAX
];
char
ttyPidFile
[
PATH_MAX
];
int
parentTty
;
int
containerTtyFd
;
char
*
containerTty
;
int
sockpair
[
2
];
lxc_vm_def_t
*
def
;
lxc_vm_def_t
*
def
;
lxc_vm_t
*
next
;
lxc_vm_t
*
next
;
...
...
src/lxc_container.c
浏览文件 @
e82c9136
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
#include <unistd.h>
#include <unistd.h>
#include "lxc_container.h"
#include "lxc_container.h"
#include "lxc_conf.h"
#include "util.h"
#include "util.h"
#include "memory.h"
#include "memory.h"
#include "veth.h"
#include "veth.h"
...
@@ -83,10 +82,11 @@ error_out:
...
@@ -83,10 +82,11 @@ error_out:
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
static
int
lxcSetContainerStdio
(
const
char
*
tty
Name
)
static
int
lxcSetContainerStdio
(
const
char
*
tty
Path
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
int
ttyfd
;
int
ttyfd
;
int
open_max
,
i
;
if
(
setsid
()
<
0
)
{
if
(
setsid
()
<
0
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
...
@@ -94,10 +94,10 @@ static int lxcSetContainerStdio(const char *ttyName)
...
@@ -94,10 +94,10 @@ static int lxcSetContainerStdio(const char *ttyName)
goto
error_out
;
goto
error_out
;
}
}
ttyfd
=
open
(
tty
Name
,
O_RDWR
|
O_NOCTTY
);
ttyfd
=
open
(
tty
Path
,
O_RDWR
|
O_NOCTTY
);
if
(
ttyfd
<
0
)
{
if
(
ttyfd
<
0
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"open(%s) failed: %s"
),
tty
Name
,
strerror
(
errno
));
_
(
"open(%s) failed: %s"
),
tty
Path
,
strerror
(
errno
));
goto
error_out
;
goto
error_out
;
}
}
...
@@ -107,7 +107,12 @@ static int lxcSetContainerStdio(const char *ttyName)
...
@@ -107,7 +107,12 @@ static int lxcSetContainerStdio(const char *ttyName)
goto
cleanup
;
goto
cleanup
;
}
}
close
(
0
);
close
(
1
);
close
(
2
);
/* Just in case someone forget to set FD_CLOEXEC, explicitly
* close all FDs before executing the container */
open_max
=
sysconf
(
_SC_OPEN_MAX
);
for
(
i
=
0
;
i
<
open_max
;
i
++
)
if
(
i
!=
ttyfd
)
close
(
i
);
if
(
dup2
(
ttyfd
,
0
)
<
0
)
{
if
(
dup2
(
ttyfd
,
0
)
<
0
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
...
@@ -144,12 +149,11 @@ error_out:
...
@@ -144,12 +149,11 @@ error_out:
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
static
int
lxcExecWithTty
(
lxc_vm_
t
*
vm
)
static
int
lxcExecWithTty
(
lxc_vm_
def_t
*
vmDef
,
char
*
ttyPath
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
lxc_vm_def_t
*
vmDef
=
vm
->
def
;
if
(
lxcSetContainerStdio
(
vm
->
containerTty
)
<
0
)
{
if
(
lxcSetContainerStdio
(
ttyPath
)
<
0
)
{
goto
exit_with_error
;
goto
exit_with_error
;
}
}
...
@@ -161,7 +165,7 @@ exit_with_error:
...
@@ -161,7 +165,7 @@ exit_with_error:
/**
/**
* lxcWaitForContinue:
* lxcWaitForContinue:
* @
vm: Pointer to vm structure
* @
monitor: monitor FD from parent
*
*
* This function will wait for the container continue message from the
* This function will wait for the container continue message from the
* parent process. It will send this message on the socket pair stored in
* parent process. It will send this message on the socket pair stored in
...
@@ -169,31 +173,23 @@ exit_with_error:
...
@@ -169,31 +173,23 @@ exit_with_error:
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
static
int
lxcWaitForContinue
(
lxc_vm_t
*
vm
)
static
int
lxcWaitForContinue
(
int
monitor
)
{
{
int
rc
=
-
1
;
lxc_message_t
msg
;
lxc_message_t
msg
;
int
readLen
;
int
readLen
;
readLen
=
saferead
(
vm
->
sockpair
[
LXC_CONTAINER_SOCKET
],
&
msg
,
sizeof
(
msg
));
readLen
=
saferead
(
monitor
,
&
msg
,
sizeof
(
msg
));
if
(
readLen
!=
sizeof
(
msg
))
{
if
(
readLen
!=
sizeof
(
msg
)
||
msg
!=
LXC_CONTINUE_MSG
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Failed to read the container continue message: %s"
),
_
(
"Failed to read the container continue message: %s"
),
strerror
(
errno
));
strerror
(
errno
));
goto
error_out
;
return
-
1
;
}
}
DEBUG0
(
"Received container continue message"
);
DEBUG0
(
"Received container continue message"
);
close
(
vm
->
sockpair
[
LXC_PARENT_SOCKET
]);
return
0
;
vm
->
sockpair
[
LXC_PARENT_SOCKET
]
=
-
1
;
close
(
vm
->
sockpair
[
LXC_CONTAINER_SOCKET
]);
vm
->
sockpair
[
LXC_CONTAINER_SOCKET
]
=
-
1
;
rc
=
0
;
error_out:
return
rc
;
}
}
/**
/**
...
@@ -204,12 +200,12 @@ error_out:
...
@@ -204,12 +200,12 @@ error_out:
*
*
* Returns 0 on success or nonzero in case of error
* Returns 0 on success or nonzero in case of error
*/
*/
static
int
lxcEnableInterfaces
(
const
lxc_vm_
t
*
vm
)
static
int
lxcEnableInterfaces
(
const
lxc_vm_
def_t
*
def
)
{
{
int
rc
=
0
;
int
rc
=
0
;
const
lxc_net_def_t
*
net
;
const
lxc_net_def_t
*
net
;
for
(
net
=
vm
->
def
->
nets
;
net
;
net
=
net
->
next
)
{
for
(
net
=
def
->
nets
;
net
;
net
=
net
->
next
)
{
DEBUG
(
"Enabling %s"
,
net
->
containerVeth
);
DEBUG
(
"Enabling %s"
,
net
->
containerVeth
);
rc
=
vethInterfaceUpOrDown
(
net
->
containerVeth
,
1
);
rc
=
vethInterfaceUpOrDown
(
net
->
containerVeth
,
1
);
if
(
0
!=
rc
)
{
if
(
0
!=
rc
)
{
...
@@ -218,7 +214,7 @@ static int lxcEnableInterfaces(const lxc_vm_t *vm)
...
@@ -218,7 +214,7 @@ static int lxcEnableInterfaces(const lxc_vm_t *vm)
}
}
/* enable lo device only if there were other net devices */
/* enable lo device only if there were other net devices */
if
(
vm
->
def
->
nets
)
if
(
def
->
nets
)
rc
=
vethInterfaceUpOrDown
(
"lo"
,
1
);
rc
=
vethInterfaceUpOrDown
(
"lo"
,
1
);
error_out:
error_out:
...
@@ -237,11 +233,11 @@ error_out:
...
@@ -237,11 +233,11 @@ error_out:
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
int
lxcChild
(
void
*
argv
)
int
lxcChild
(
void
*
data
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
lxc_
vm_t
*
vm
=
(
lxc_vm_t
*
)
argv
;
lxc_
child_argv_t
*
argv
=
data
;
lxc_vm_def_t
*
vmDef
=
vm
->
def
;
lxc_vm_def_t
*
vmDef
=
argv
->
config
;
lxc_mount_t
*
curMount
;
lxc_mount_t
*
curMount
;
int
i
;
int
i
;
...
@@ -278,16 +274,16 @@ int lxcChild( void *argv )
...
@@ -278,16 +274,16 @@ int lxcChild( void *argv )
}
}
/* Wait for interface devices to show up */
/* Wait for interface devices to show up */
if
(
0
!=
(
rc
=
lxcWaitForContinue
(
vm
)))
{
if
(
0
!=
(
rc
=
lxcWaitForContinue
(
argv
->
monitor
)))
{
goto
cleanup
;
goto
cleanup
;
}
}
/* enable interfaces */
/* enable interfaces */
if
(
0
!=
(
rc
=
lxcEnableInterfaces
(
vm
)))
{
if
(
0
!=
(
rc
=
lxcEnableInterfaces
(
vm
Def
)))
{
goto
cleanup
;
goto
cleanup
;
}
}
rc
=
lxcExecWithTty
(
vm
);
rc
=
lxcExecWithTty
(
vm
Def
,
argv
->
ttyPath
);
/* this function will only return if an error occured */
/* this function will only return if an error occured */
cleanup:
cleanup:
...
...
src/lxc_container.h
浏览文件 @
e82c9136
...
@@ -24,8 +24,22 @@
...
@@ -24,8 +24,22 @@
#ifndef LXC_CONTAINER_H
#ifndef LXC_CONTAINER_H
#define LXC_CONTAINER_H
#define LXC_CONTAINER_H
#include "lxc_conf.h"
#ifdef WITH_LXC
#ifdef WITH_LXC
typedef
struct
__lxc_child_argv
lxc_child_argv_t
;
struct
__lxc_child_argv
{
lxc_vm_def_t
*
config
;
int
monitor
;
char
*
ttyPath
;
};
/* messages between parent and container */
typedef
char
lxc_message_t
;
#define LXC_CONTINUE_MSG 'c'
/* Function declarations */
/* Function declarations */
int
lxcChild
(
void
*
argv
);
int
lxcChild
(
void
*
argv
);
...
...
src/lxc_driver.c
浏览文件 @
e82c9136
...
@@ -561,27 +561,23 @@ static int lxcCleanupInterfaces(const lxc_vm_t *vm)
...
@@ -561,27 +561,23 @@ static int lxcCleanupInterfaces(const lxc_vm_t *vm)
/**
/**
* lxcSendContainerContinue:
* lxcSendContainerContinue:
* @
vm: pointer to virtual machine structure
* @
monitor: FD for communicating with child
*
*
* Sends the continue message via the socket pair stored in the vm
* Sends the continue message via the socket pair stored in the vm
* structure.
* structure.
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
static
int
lxcSendContainerContinue
(
const
lxc_vm_t
*
vm
)
static
int
lxcSendContainerContinue
(
virConnectPtr
conn
,
int
monitor
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
lxc_message_t
msg
=
LXC_CONTINUE_MSG
;
lxc_message_t
msg
=
LXC_CONTINUE_MSG
;
int
writeCount
=
0
;
int
writeCount
=
0
;
if
(
NULL
==
vm
)
{
writeCount
=
safewrite
(
monitor
,
&
msg
,
sizeof
(
msg
));
goto
error_out
;
}
writeCount
=
safewrite
(
vm
->
sockpair
[
LXC_PARENT_SOCKET
],
&
msg
,
sizeof
(
msg
));
if
(
writeCount
!=
sizeof
(
msg
))
{
if
(
writeCount
!=
sizeof
(
msg
))
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"unable to send container continue message: %s"
),
_
(
"unable to send container continue message: %s"
),
strerror
(
errno
));
strerror
(
errno
));
goto
error_out
;
goto
error_out
;
...
@@ -605,12 +601,15 @@ error_out:
...
@@ -605,12 +601,15 @@ error_out:
*/
*/
static
int
lxcStartContainer
(
virConnectPtr
conn
,
static
int
lxcStartContainer
(
virConnectPtr
conn
,
lxc_driver_t
*
driver
,
lxc_driver_t
*
driver
,
lxc_vm_t
*
vm
)
lxc_vm_t
*
vm
,
int
monitor
,
char
*
ttyPath
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
int
flags
;
int
flags
;
int
stacksize
=
getpagesize
()
*
4
;
int
stacksize
=
getpagesize
()
*
4
;
char
*
stack
,
*
stacktop
;
char
*
stack
,
*
stacktop
;
lxc_child_argv_t
args
=
{
vm
->
def
,
monitor
,
ttyPath
};
/* allocate a stack for the container */
/* allocate a stack for the container */
if
(
VIR_ALLOC_N
(
stack
,
stacksize
)
<
0
)
{
if
(
VIR_ALLOC_N
(
stack
,
stacksize
)
<
0
)
{
...
@@ -625,7 +624,7 @@ static int lxcStartContainer(virConnectPtr conn,
...
@@ -625,7 +624,7 @@ static int lxcStartContainer(virConnectPtr conn,
if
(
vm
->
def
->
nets
!=
NULL
)
if
(
vm
->
def
->
nets
!=
NULL
)
flags
|=
CLONE_NEWNET
;
flags
|=
CLONE_NEWNET
;
vm
->
def
->
id
=
clone
(
lxcChild
,
stacktop
,
flags
,
(
void
*
)
vm
);
vm
->
def
->
id
=
clone
(
lxcChild
,
stacktop
,
flags
,
&
args
);
DEBUG
(
"clone() returned, %d"
,
vm
->
def
->
id
);
DEBUG
(
"clone() returned, %d"
,
vm
->
def
->
id
);
...
@@ -643,117 +642,9 @@ error_exit:
...
@@ -643,117 +642,9 @@ error_exit:
return
rc
;
return
rc
;
}
}
/**
* lxcPutTtyInRawMode:
* @conn: pointer to connection
* @ttyDev: file descriptor for tty
*
* Sets tty attributes via cfmakeraw()
*
* Returns 0 on success or -1 in case of error
*/
static
int
lxcPutTtyInRawMode
(
virConnectPtr
conn
,
int
ttyDev
)
{
int
rc
=
-
1
;
struct
termios
ttyAttr
;
if
(
tcgetattr
(
ttyDev
,
&
ttyAttr
)
<
0
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"tcgetattr() failed: %s"
,
strerror
(
errno
));
goto
cleanup
;
}
cfmakeraw
(
&
ttyAttr
);
if
(
tcsetattr
(
ttyDev
,
TCSADRAIN
,
&
ttyAttr
)
<
0
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"tcsetattr failed: %s"
,
strerror
(
errno
));
goto
cleanup
;
}
rc
=
0
;
cleanup:
return
rc
;
}
/**
* lxcSetupTtyTunnel:
* @conn: pointer to connection
* @vmDef: pointer to virtual machine definition structure
* @ttyDev: pointer to int. On success will be set to fd for master
* end of tty
*
* Opens and configures the parent side tty
*
* Returns 0 on success or -1 in case of error
*/
static
int
lxcSetupTtyTunnel
(
virConnectPtr
conn
,
lxc_vm_def_t
*
vmDef
,
int
*
ttyDev
)
{
int
rc
=
-
1
;
char
*
ptsStr
;
if
(
0
<
strlen
(
vmDef
->
tty
))
{
*
ttyDev
=
posix_openpt
(
O_RDWR
|
O_NOCTTY
|
O_NONBLOCK
);
if
(
*
ttyDev
<
0
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"open() tty failed: %s"
,
strerror
(
errno
));
goto
setup_complete
;
}
rc
=
grantpt
(
*
ttyDev
);
if
(
rc
<
0
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"grantpt() failed: %s"
,
strerror
(
errno
));
goto
setup_complete
;
}
rc
=
unlockpt
(
*
ttyDev
);
if
(
rc
<
0
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"unlockpt() failed: %s"
,
strerror
(
errno
));
goto
setup_complete
;
}
/* get the name and print it to stdout */
ptsStr
=
ptsname
(
*
ttyDev
);
if
(
ptsStr
==
NULL
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"ptsname() failed"
);
goto
setup_complete
;
}
/* This value needs to be stored in the container configuration file */
VIR_FREE
(
vmDef
->
tty
);
if
(
!
(
vmDef
->
tty
=
strdup
(
ptsStr
)))
{
lxcError
(
conn
,
NULL
,
VIR_ERR_NO_MEMORY
,
_
(
"unable to get storage for vm tty name"
));
goto
setup_complete
;
}
/* Enter raw mode, so all characters are passed directly to child */
if
(
lxcPutTtyInRawMode
(
conn
,
*
ttyDev
)
<
0
)
{
goto
setup_complete
;
}
}
else
{
*
ttyDev
=
-
1
;
}
rc
=
0
;
setup_complete:
if
((
0
!=
rc
)
&&
(
*
ttyDev
>
0
))
{
close
(
*
ttyDev
);
}
return
rc
;
}
/**
/**
* lxc
SetupContainer
Tty:
* lxc
Open
Tty:
* @conn: pointer to connection
* @conn: pointer to connection
* @ttymaster: pointer to int. On success, set to fd for master end
* @ttymaster: pointer to int. On success, set to fd for master end
* @ttyName: On success, will point to string slave end of tty. Caller
* @ttyName: On success, will point to string slave end of tty. Caller
...
@@ -763,12 +654,12 @@ setup_complete:
...
@@ -763,12 +654,12 @@ setup_complete:
*
*
* Returns 0 on success or -1 in case of error
* Returns 0 on success or -1 in case of error
*/
*/
static
int
lxcSetupContainerTty
(
virConnectPtr
conn
,
static
int
lxcOpenTty
(
virConnectPtr
conn
,
int
*
ttymaster
,
int
*
ttymaster
,
char
**
ttyName
)
char
**
ttyName
,
int
rawmode
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
char
tempTtyName
[
PATH_MAX
];
*
ttymaster
=
posix_openpt
(
O_RDWR
|
O_NOCTTY
|
O_NONBLOCK
);
*
ttymaster
=
posix_openpt
(
O_RDWR
|
O_NOCTTY
|
O_NONBLOCK
);
if
(
*
ttymaster
<
0
)
{
if
(
*
ttymaster
<
0
)
{
...
@@ -783,27 +674,43 @@ static int lxcSetupContainerTty(virConnectPtr conn,
...
@@ -783,27 +674,43 @@ static int lxcSetupContainerTty(virConnectPtr conn,
goto
cleanup
;
goto
cleanup
;
}
}
if
(
0
!=
ptsname_r
(
*
ttymaster
,
tempTtyName
,
sizeof
(
tempTtyName
)))
{
if
(
rawmode
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
struct
termios
ttyAttr
;
_
(
"ptsname_r failed: %s"
),
strerror
(
errno
));
if
(
tcgetattr
(
*
ttymaster
,
&
ttyAttr
)
<
0
)
{
goto
cleanup
;
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
}
"tcgetattr() failed: %s"
,
strerror
(
errno
));
goto
cleanup
;
}
if
(
VIR_ALLOC_N
(
*
ttyName
,
strlen
(
tempTtyName
)
+
1
)
<
0
)
{
cfmakeraw
(
&
ttyAttr
);
lxcError
(
conn
,
NULL
,
VIR_ERR_NO_MEMORY
,
_
(
"unable to allocate container name string"
));
if
(
tcsetattr
(
*
ttymaster
,
TCSADRAIN
,
&
ttyAttr
)
<
0
)
{
goto
cleanup
;
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
"tcsetattr failed: %s"
,
strerror
(
errno
));
goto
cleanup
;
}
}
}
strcpy
(
*
ttyName
,
tempTtyName
);
if
(
ttyName
)
{
char
tempTtyName
[
PATH_MAX
];
if
(
0
!=
ptsname_r
(
*
ttymaster
,
tempTtyName
,
sizeof
(
tempTtyName
)))
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"ptsname_r failed: %s"
),
strerror
(
errno
));
goto
cleanup
;
}
if
((
*
ttyName
=
strdup
(
tempTtyName
))
==
NULL
)
{
lxcError
(
conn
,
NULL
,
VIR_ERR_NO_MEMORY
,
NULL
);
goto
cleanup
;
}
}
rc
=
0
;
rc
=
0
;
cleanup:
cleanup:
if
(
0
!=
rc
)
{
if
(
rc
!=
0
&&
if
(
-
1
!=
*
ttymaster
)
{
*
ttymaster
!=
-
1
)
{
close
(
*
ttymaster
);
close
(
*
ttymaster
);
}
}
}
return
rc
;
return
rc
;
...
@@ -989,15 +896,18 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -989,15 +896,18 @@ static int lxcVmStart(virConnectPtr conn,
lxc_vm_t
*
vm
)
lxc_vm_t
*
vm
)
{
{
int
rc
=
-
1
;
int
rc
=
-
1
;
lxc_vm_def_t
*
vmDef
=
vm
->
def
;
int
sockpair
[
2
]
=
{
-
1
,
-
1
};
int
containerTty
,
parentTty
;
char
*
containerTtyPath
=
NULL
;
/* open parent tty */
/* open parent tty */
if
(
lxcSetupTtyTunnel
(
conn
,
vmDef
,
&
vm
->
parentTty
)
<
0
)
{
VIR_FREE
(
vm
->
def
->
tty
);
if
(
lxcOpenTty
(
conn
,
&
parentTty
,
&
vm
->
def
->
tty
,
1
)
<
0
)
{
goto
cleanup
;
goto
cleanup
;
}
}
/* open container tty */
/* open container tty */
if
(
lxc
SetupContainerTty
(
conn
,
&
(
vm
->
containerTtyFd
),
&
(
vm
->
containerTty
)
)
<
0
)
{
if
(
lxc
OpenTty
(
conn
,
&
containerTty
,
&
containerTtyPath
,
0
)
<
0
)
{
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -1011,15 +921,15 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -1011,15 +921,15 @@ static int lxcVmStart(virConnectPtr conn,
if
(
vm
->
pid
==
0
)
{
if
(
vm
->
pid
==
0
)
{
/* child process calls forward routine */
/* child process calls forward routine */
lxcTtyForward
(
vm
->
parentTty
,
vm
->
containerTtyFd
);
lxcTtyForward
(
parentTty
,
containerTty
);
}
}
if
(
lxcStoreTtyPid
(
driver
,
vm
))
{
if
(
lxcStoreTtyPid
(
driver
,
vm
))
{
DEBUG0
(
"unable to store tty pid"
);
DEBUG0
(
"unable to store tty pid"
);
}
}
close
(
vm
->
parentTty
);
close
(
parentTty
);
close
(
vm
->
containerTtyFd
);
close
(
containerTty
);
if
(
0
!=
(
rc
=
lxcSetupInterfaces
(
conn
,
vm
)))
{
if
(
0
!=
(
rc
=
lxcSetupInterfaces
(
conn
,
vm
)))
{
goto
cleanup
;
goto
cleanup
;
...
@@ -1027,7 +937,7 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -1027,7 +937,7 @@ static int lxcVmStart(virConnectPtr conn,
/* create a socket pair to send continue message to the container once */
/* create a socket pair to send continue message to the container once */
/* we've completed the post clone configuration */
/* we've completed the post clone configuration */
if
(
0
!=
socketpair
(
PF_UNIX
,
SOCK_STREAM
,
0
,
vm
->
sockpair
))
{
if
(
0
!=
socketpair
(
PF_UNIX
,
SOCK_STREAM
,
0
,
sockpair
))
{
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
lxcError
(
conn
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"sockpair failed: %s"
),
strerror
(
errno
));
_
(
"sockpair failed: %s"
),
strerror
(
errno
));
goto
cleanup
;
goto
cleanup
;
...
@@ -1035,7 +945,9 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -1035,7 +945,9 @@ static int lxcVmStart(virConnectPtr conn,
/* check this rc */
/* check this rc */
rc
=
lxcStartContainer
(
conn
,
driver
,
vm
);
rc
=
lxcStartContainer
(
conn
,
driver
,
vm
,
sockpair
[
1
],
containerTtyPath
);
if
(
rc
!=
0
)
if
(
rc
!=
0
)
goto
cleanup
;
goto
cleanup
;
...
@@ -1043,7 +955,7 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -1043,7 +955,7 @@ static int lxcVmStart(virConnectPtr conn,
if
(
rc
!=
0
)
if
(
rc
!=
0
)
goto
cleanup
;
goto
cleanup
;
rc
=
lxcSendContainerContinue
(
vm
);
rc
=
lxcSendContainerContinue
(
conn
,
sockpair
[
0
]
);
if
(
rc
!=
0
)
if
(
rc
!=
0
)
goto
cleanup
;
goto
cleanup
;
...
@@ -1052,10 +964,9 @@ static int lxcVmStart(virConnectPtr conn,
...
@@ -1052,10 +964,9 @@ static int lxcVmStart(virConnectPtr conn,
driver
->
nactivevms
++
;
driver
->
nactivevms
++
;
cleanup:
cleanup:
close
(
vm
->
sockpair
[
LXC_PARENT_SOCKET
]);
if
(
sockpair
[
0
]
!=
-
1
)
close
(
sockpair
[
0
]);
vm
->
sockpair
[
LXC_PARENT_SOCKET
]
=
-
1
;
if
(
sockpair
[
1
]
!=
-
1
)
close
(
sockpair
[
1
]);
close
(
vm
->
sockpair
[
LXC_CONTAINER_SOCKET
]);
VIR_FREE
(
containerTtyPath
);
vm
->
sockpair
[
LXC_CONTAINER_SOCKET
]
=
-
1
;
return
rc
;
return
rc
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录