graph driver-device mapper-02driver基本操作

简介:
//	清除thin pool
1.1 func (d *Driver) Cleanup() error {
	// 停止thin pool
	err := d.DeviceSet.Shutdown()

	return err
}

//	当加载新镜像时,添加一个新thin device
//	id为containerid或imageid
1.2 func (d *Driver) Create(id, parent string) error {
	if err := d.DeviceSet.AddDevice(id, parent); err != nil {
		return err
	}

	return nil
}

//	删除thin device
1.3 func (d *Driver) Remove(id string) error {
	//检查thin device是否存在
	if !d.DeviceSet.HasDevice(id) {
		return nil
	}

	//通过id从thin pool中删除设备
	if err := d.DeviceSet.DeleteDevice(id); err != nil {
		return err
	}

	//mp为/var/lib/docker/devicemapper/mnt/$id
	mp := path.Join(d.home, "mnt", id)
	//删除目录下所有的文件
	if err := os.RemoveAll(mp); err != nil && !os.IsNotExist(err) {
		return err
	}

	return nil
}

//	挂载thin device到/var/lib/docker/devicemapper/mnt/$id目录下
1.4 func (d *Driver) Get(id, mountLabel string) (string, error) {
	//mp=/var/lib/docker/devicemapper/mnt/$id
	mp := path.Join(d.home, "mnt", id)

	//创建目录/var/lib/docker/devicemapper/mnt/$id
	if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {
		return "", err
	}
	//挂载thin device到/var/lib/docker/devicemapper/mnt/$id
	if err := d.DeviceSet.MountDevice(id, mp, mountLabel); err != nil {
		return "", err
	}

	//创建rootfs到/var/lib/docker/devicemapper/mnt/$id/rootfs
	rootFs := path.Join(mp, "rootfs")
	if err := os.MkdirAll(rootFs, 0755); err != nil && !os.IsExist(err) {
		d.DeviceSet.UnmountDevice(id)
		return "", err
	}

	//创建id
	idFile := path.Join(mp, "id")
	if _, err := os.Stat(idFile); err != nil && os.IsNotExist(err) {
		if err := ioutil.WriteFile(idFile, []byte(id), 0600); err != nil {
			d.DeviceSet.UnmountDevice(id)
			return "", err
		}
	}

	//返回/var/lib/docker/devicemapper/mnt/$id/rootfs目录
	return rootFs, nil
}

//	从/var/lib/docker/devicemapper/mnt/$id下解挂设备
1.5 func (d *Driver) Put(id string) {
	if err := d.DeviceSet.UnmountDevice(id); err != nil {
		utils.Errorf("Warning: error unmounting device %s: %s\n", id, err)
	}
}

//	判断$id所对应的设备是否存在
1.6 func (d *Driver) Exists(id string) bool {
	return d.DeviceSet.HasDevice(id)
}

目录
相关文章
|
4月前
|
Python
【Python 3】解决FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.
文章讨论了在使用Python的BeautifulSoup库时遇到的"Couldn't find a tree builder with"错误,并提供了解决方案。
169 0
|
7月前
|
SQL 数据库
一个很实用的造数工具—Spawner Data Generator
一个很实用的造数工具—Spawner Data Generator
229 0
|
Linux
device_node转换成platform_device
device_node转换成platform_device
179 0
module_platform_driver源码分析
module_platform_driver源码分析
python报错bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.
python报错bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.
FastAPI(26)- Path Operation Configuration 路径操作的配置
FastAPI(26)- Path Operation Configuration 路径操作的配置
134 0
FastAPI(26)- Path Operation Configuration 路径操作的配置
|
并行计算 PyTorch Go
成功解决The NVIDIA driver on your system is too old (found version 8000).Please update your GPU driver
成功解决The NVIDIA driver on your system is too old (found version 8000).Please update your GPU driver