LXC1.0.7-- lxc-start 源码分析 01

最近较关心LinuxContainer 的启动流程,所以就从lxc_start.c这个文件看起。

首先进入源文件,直接到main程序来,本人喜欢按照程序执行的顺序来看代码,所以看个人喜好了。

	int main(int argc, char *argv[])
{
    int err = 1;
    struct lxc_conf *conf;    //初始化config结构
    char *const *args;		 //传递的参数
    char *rcfile = NULL;		 //指定配置文件
    char *const default_args[] = {    //默认的args参数
        "/sbin/init",
        NULL,
    };  
struct lxc_container *c;    //lxc-container 的结构体
….
}

看下lxc_conf这个数据结构

struct lxc_conf {
    int is_execute;		//容器是否在执行
    char *fstab;			//fstab?
    int tty;				//tty的个数
    int pts;				//pts的个数?
    int reboot;			//重启?
    int need_utmp_watch;		//字面翻译 需要utmp 查看
    signed long personality;		//字面翻译 特点	
    struct utsname *utsname;	//ustname
    struct lxc_list cgroup;		//cgroup list lxc_list只是简单的链表结构
    struct lxc_list id_map;		//id_map list
    struct lxc_list network;		//network list
    struct saved_nic *saved_nics;//saved_nics 结构
    int num_savednics;			//savednics数量?
    int auto_mounts;			//auto_mounts?
    struct lxc_list mount_list;		//mount_list list?
    struct lxc_list caps;			//caps list?
    struct lxc_list keepcaps;		//keepcaps list?
    struct lxc_tty_info tty_info;	//tty的相关信息
    struct lxc_console console;	//console的结构体
    struct lxc_rootfs rootfs;		//rootfs的结构体
    char *ttydir;					//tty目录
int close_all_fds;			//关闭所有fd
struct lxc_list hooks[NUM_LXC_HOOKS];	//hooks 函数

    char *lsm_aa_profile;   //?
    char *lsm_se_context;	//?
    int tmp_umount_proc;	//?
    char *seccomp;  // filename with the seccomp rules
#if HAVE_SCMP_FILTER_CTX
    scmp_filter_ctx seccomp_ctx;
#endif
    int maincmd_fd;		//?
    int autodev;  // if 1, mount and fill a /dev at start
    int haltsignal; // signal used to halt container
    int stopsignal; // signal used to hard stop container
    int kmsg;  // if 1, create /dev/kmsg symlink
    char *rcfile;   // Copy of the top level rcfile we read

    // Logfile and loglevel can be set in a container config file.
    // Those function as defaults.  The defaults can be overriden
    // by command line.  However we don't want the command line
    // specified values to be saved on c->save_config().  So we
    // store the config file specified values here.
    char *logfile;  // the logfile as specifed in config
    int loglevel;   // loglevel as specifed in config (if any)

    int inherit_ns_fd[LXC_NS_MAX];

    int start_auto;
    int start_delay;
    int start_order;
    struct lxc_list groups;
    int nbd_idx;

    /* set to true when rootfs has been setup */
    bool rootfs_setup;
};

lxc_info 的结构体看完,下面要看下lxc-container 这个重头戏。

下面来看下lxc_container的结构体

/*!
 * An LXC container.
 */
struct lxc_container {
    // private fields
   char *name; 		 //container 的名字
   char *configfile; 		 // configuration file 的路径
   char *pidfile;   		 // 存储pid 的文件名
   struct lxc_lock *slock;  //Container semaphore lock. 容器的信号锁
    struct lxc_lock *privlock;//容器的私有信号锁
    int numthreads;			//容器的引用数量,由privlock保护
    struct lxc_conf *lxc_conf;

    // public fields
    char *error_string;		//全局变量 可读的最后显示的error
    int error_num;			//最后error的数字
  

你可能感兴趣的:(lxc,lxc,分析,源码)