提交 fbad18db 编写于 作者: G gaohuatao 提交者: lifeng68

devmapper: add devmapper_rm_layer、devmapper_create_ro、devmapper_create_rw and...

devmapper: add devmapper_rm_layer、devmapper_create_ro、devmapper_create_rw and devmapper_umount_layer func
Signed-off-by: Ngaohuatao <gaohuatao@huawei.com>
上级 58fb5faf
......@@ -170,7 +170,7 @@ static int devmapper_parse_options(struct device_set *devset, const char **optio
return 0;
}
void free_device_set(struct device_set *ptr)
static void free_device_set(struct device_set *ptr)
{
if (ptr == NULL) {
return;
......@@ -1996,7 +1996,7 @@ free_out:
UTIL_FREE_AND_SET_NULL(dev_fname);
}
int delete_device(struct device_set *devset, const char *hash, bool sync_delete)
static int do_delete_device(struct device_set *devset, const char *hash, bool sync_delete)
{
int ret;
bool deferred_remove;
......@@ -2062,7 +2062,7 @@ static int setup_base_image(struct device_set *devset)
}
DEBUG("devmapper: Removing uninitialized base image");
ret = delete_device(devset, "", true);
ret = do_delete_device(devset, "", true);
if (ret != 0) {
goto out;
}
......@@ -2577,4 +2577,79 @@ free_out:
}
free_image_devmapper_device_info(info);
return ret;
}
bool has_device(const char *hash)
{
bool res = false;
image_devmapper_device_info *info = NULL;
struct device_set *devset = NULL;
if (hash == NULL) {
ERROR("devmapper: failed to judge device metadata exists");
return false;
}
if (devmapper_conf_wrlock()) {
ERROR("lock devmapper conf failed");
return false;
}
devset = devmapper_driver_devices_get();
if (devset == NULL) {
goto free_out;
}
info = lookup_device(devset, hash);
if (info == NULL) {
ERROR("devmapper: lookup device %s failed", hash);
goto free_out;
}
res = true;
free_out:
if (devmapper_conf_unlock()) {
ERROR("unlock devmapper conf failed");
}
free_image_devmapper_device_info(info);
return res;
}
int delete_device(const char *hash, bool sync_delete)
{
int ret = 0;
image_devmapper_device_info *info = NULL;
struct device_set *devset = NULL;
if (hash == NULL) {
return -1;
}
if (devmapper_conf_wrlock()) {
ERROR("lock devmapper conf failed");
return -1;
}
devset = devmapper_driver_devices_get();
if (devset == NULL) {
ret = -1;
goto free_out;
}
info = lookup_device(devset, hash);
if (info == NULL) {
ret = -1;
ERROR("devmapper: lookup device %s failed", hash);
goto free_out;
}
ret = do_delete_device(devset, hash, sync_delete);
free_out:
if (devmapper_conf_unlock()) {
ret = -1;
ERROR("unlock devmapper conf failed");
}
free_image_devmapper_device_info(info);
return ret;
}
\ No newline at end of file
......@@ -80,6 +80,9 @@ struct device_set *devmapper_driver_devices_get();
int add_device(const char *hash, const char *base_hash, const json_map_string_string *storage_opts);
int mount_device(const char *hash, const char *path, const struct driver_mount_opts *mount_opts);
int unmount_device(const char *hash, const char *mount_path);
bool has_device(const char *hash);
int delete_device(const char *hash, bool sync_delete);
#ifdef __cplusplus
}
......
......@@ -38,7 +38,7 @@ int devmapper_init(struct graphdriver *driver, const char *drvier_home, const ch
return device_init(driver, drvier_home, options, len);
}
int do_create(const char *id, const char *parent, const struct driver_create_opts *create_opts)
static int do_create(const char *id, const char *parent, const struct driver_create_opts *create_opts)
{
return add_device(id, parent, create_opts->storage_opt);
}
......@@ -54,15 +54,58 @@ int devmapper_create_rw(const char *id, const char *parent, const struct graphdr
return do_create(id, parent, create_opts);
}
// Create adds a device with a given id and the parent.
int devmapper_create_ro(const char *id, const char *parent, const struct graphdriver *driver,
const struct driver_create_opts *create_opts)
{
return 0;
if (id == NULL || parent == NULL || driver == NULL || create_opts == NULL) {
return -1;
}
return do_create(id, parent, create_opts);
}
// Remove removes a device with a given id, unmounts the filesystem.
int devmapper_rm_layer(const char *id, const struct graphdriver *driver)
{
return 0;
char *mnt_parent_dir = NULL;
char *mnt_point_dir = NULL;
int ret = 0;
if (id == NULL || driver == NULL) {
return -1;
}
if (!has_device(id)) {
return 0;
}
ret = delete_device(id, false);
if (ret != 0) {
ERROR("failed to remove device %s", id);
return ret;
}
mnt_parent_dir = util_path_join(driver->home, "mnt");
if (mnt_parent_dir == NULL) {
ret = -1;
ERROR("Failed to join devmapper mnt dir %s", id);
goto out;
}
mnt_point_dir = util_path_join(mnt_parent_dir, id);
if (mnt_point_dir == NULL) {
ret = -1;
ERROR("Failed to join devampper mount point dir %s", id);
goto out;
}
ret = util_path_remove(mnt_point_dir);
out:
free(mnt_parent_dir);
free(mnt_point_dir);
return ret;
}
static int write_file(const char *fpath, const char *buf)
......@@ -162,12 +205,42 @@ out:
int devmapper_umount_layer(const char *id, const struct graphdriver *driver)
{
return 0;
int ret = 0;
char *mp = NULL;
char *mnt_dir = NULL;
if (id == NULL || driver == NULL) {
return -1;
}
mnt_dir = util_path_join(driver->home, "mnt");
if (mnt_dir == NULL) {
ERROR("Failed to join layer dir mnt");
ret = -1;
goto out;
}
mp = util_path_join(mnt_dir, id);
if (mp == NULL) {
ERROR("Failed to join layer dir:%s", id);
ret = -1;
goto out;
}
ret = unmount_device(id, mp);
if (ret != 0) {
DEBUG("devmapper: unmount %s failed", mp);
}
out:
free(mnt_dir);
free(mp);
return ret;
}
bool devmapper_layer_exists(const char *id, const struct graphdriver *driver)
{
return true;
return has_device(id);
}
int devmapper_apply_diff(const char *id, const struct graphdriver *driver, const struct io_read_wrapper *content,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册