From 4fabc9ffbf6a58f8da30269c5aed62eba9ecd7b4 Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Mon, 20 Jan 2020 11:48:15 +0800 Subject: [PATCH] Support devicemapper Signed-off-by: WangFengTu --- src/api/image_client/isula_image.proto | 8 +- src/api/services/containers/container.proto | 2 + src/cmd/isula/information/info.c | 31 ++++++ .../client/grpc/grpc_containers_client.cc | 11 +++ .../client/grpc/grpc_isula_image_client.cc | 6 +- src/connect/client/isula_image_connect.c | 4 +- src/connect/client/isula_image_connect.h | 4 +- .../service/grpc/grpc_containers_service.h | 2 + .../grpc/grpc_containers_service_private.cc | 20 ++++ src/cutils/utils_string.c | 25 +++++ src/cutils/utils_string.h | 2 + src/image/image.c | 2 + src/image/image.h | 3 +- src/image/oci/global_config.c | 6 ++ src/image/oci/isula_storage_status.c | 60 +++++++++++- src/image/oci/oci_common_operators.c | 67 ------------- src/image/oci/oci_common_operators.h | 1 - .../schema/schema/host/info-response.json | 6 ++ src/libisula.h | 2 + .../execution/execute/execution_information.c | 21 +++++ src/services/graphdriver/CMakeLists.txt | 3 + .../graphdriver/devmapper/CMakeLists.txt | 7 ++ .../graphdriver/devmapper/driver_devmapper.c | 94 +++++++++++++++++++ .../graphdriver/devmapper/driver_devmapper.h | 34 +++++++ src/services/graphdriver/driver.c | 17 +++- src/services/graphdriver/driver.h | 3 +- 26 files changed, 347 insertions(+), 94 deletions(-) create mode 100644 src/services/graphdriver/devmapper/CMakeLists.txt create mode 100644 src/services/graphdriver/devmapper/driver_devmapper.c create mode 100644 src/services/graphdriver/devmapper/driver_devmapper.h diff --git a/src/api/image_client/isula_image.proto b/src/api/image_client/isula_image.proto index 41a7f7d..4a01932 100644 --- a/src/api/image_client/isula_image.proto +++ b/src/api/image_client/isula_image.proto @@ -141,11 +141,9 @@ message LoadImageResponose { message GraphdriverStatusRequest {} message GraphdriverStatusResponse { - string backing_fs = 1; - bool supports_d_type = 2; - bool native_overlay_diff = 3; - string errmsg = 4; - uint32 cc = 5; + string status = 1; + string errmsg = 2; + uint32 cc = 3; } message ContainerFsUsageRequest { diff --git a/src/api/services/containers/container.proto b/src/api/services/containers/container.proto index 73729cf..871d703 100644 --- a/src/api/services/containers/container.proto +++ b/src/api/services/containers/container.proto @@ -376,6 +376,8 @@ message InfoResponse { string http_proxy = 20; string https_proxy = 21; string no_proxy = 22; + string driver_name = 23; + string driver_status = 24; } message UpdateRequest { diff --git a/src/cmd/isula/information/info.c b/src/cmd/isula/information/info.c index 0e4ace8..bcb81f8 100644 --- a/src/cmd/isula/information/info.c +++ b/src/cmd/isula/information/info.c @@ -26,6 +26,31 @@ const char g_cmd_info_usage[] = "info"; struct client_arguments g_cmd_info_args = {}; +static void print_with_space(const char *info) +{ + size_t i = 0; + size_t size = 0; + bool print_space = true; + + if (info == NULL) { + return; + } + + size = strlen(info); + for (i = 0; i < size; i++) { + if (print_space) { + printf(" "); + print_space = false; + } + if (info[i] == '\n') { + print_space = true; + } + printf("%c", info[i]); + } + + return; +} + static void client_info_server(const struct isula_info_response *response) { printf("Containers: %u\n", (unsigned int)(response->containers_num)); @@ -36,6 +61,12 @@ static void client_info_server(const struct isula_info_response *response) if (response->version != NULL) { printf("Server Version: %s\n", response->version); } + if (response->driver_name != NULL) { + printf("Storage Driver: %s\n", response->driver_name); + } + if (response->driver_status != NULL) { + print_with_space(response->driver_status); + } if (response->logging_driver != NULL) { printf("Logging Driver: %s\n", response->logging_driver); } diff --git a/src/connect/client/grpc/grpc_containers_client.cc b/src/connect/client/grpc/grpc_containers_client.cc index 0ccb7a3..4a3a53f 100644 --- a/src/connect/client/grpc/grpc_containers_client.cc +++ b/src/connect/client/grpc/grpc_containers_client.cc @@ -105,6 +105,7 @@ public: } response->total_mem = gresponse->total_mem(); get_proxy_info_from_grpc(response, gresponse); + get_driver_info_from_grpc(response, gresponse); return 0; } @@ -150,6 +151,16 @@ private: response->no_proxy = util_strdup_s(gresponse->no_proxy().c_str()); } } + + void get_driver_info_from_grpc(isula_info_response *response, InfoResponse *gresponse) + { + if (!gresponse->driver_name().empty()) { + response->driver_name = util_strdup_s(gresponse->driver_name().c_str()); + } + if (!gresponse->driver_status().empty()) { + response->driver_status = util_strdup_s(gresponse->driver_status().c_str()); + } + } }; class ContainerCreate : public ClientBaseserver_errono = gresp->cc(); - if (!gresp->backing_fs().empty()) { - resp->backing_fs = util_strdup_s(gresp->backing_fs().c_str()); + if (!gresp->status().empty()) { + resp->status = util_strdup_s(gresp->status().c_str()); } - resp->supports_d_type = gresp->supports_d_type(); - resp->native_overlay_diff = gresp->native_overlay_diff(); return 0; } diff --git a/src/connect/client/isula_image_connect.c b/src/connect/client/isula_image_connect.c index 470147d..b5ff790 100644 --- a/src/connect/client/isula_image_connect.c +++ b/src/connect/client/isula_image_connect.c @@ -463,8 +463,8 @@ void free_isula_storage_status_response(struct isula_storage_status_response *pt if (ptr == NULL) { return; } - free(ptr->backing_fs); - ptr->backing_fs = NULL; + free(ptr->status); + ptr->status = NULL; free(ptr->errmsg); ptr->errmsg = NULL; free(ptr); diff --git a/src/connect/client/isula_image_connect.h b/src/connect/client/isula_image_connect.h index 8a2fa79..9e1ae29 100644 --- a/src/connect/client/isula_image_connect.h +++ b/src/connect/client/isula_image_connect.h @@ -223,9 +223,7 @@ struct isula_storage_status_request { }; struct isula_storage_status_response { - char *backing_fs; - bool supports_d_type; - bool native_overlay_diff; + char *status; char *errmsg; uint32_t cc; diff --git a/src/connect/service/grpc/grpc_containers_service.h b/src/connect/service/grpc/grpc_containers_service.h index 21fbf27..98c3505 100644 --- a/src/connect/service/grpc/grpc_containers_service.h +++ b/src/connect/service/grpc/grpc_containers_service.h @@ -218,6 +218,8 @@ private: int pack_proxy_info_to_grpc(const host_info_response *response, InfoResponse *gresponse); + int pack_driver_info_to_grpc(const host_info_response *response, InfoResponse *gresponse); + int logs_request_from_grpc(const LogsRequest *grequest, struct isulad_logs_request **request); }; diff --git a/src/connect/service/grpc/grpc_containers_service_private.cc b/src/connect/service/grpc/grpc_containers_service_private.cc index b7ceafc..bc7787e 100644 --- a/src/connect/service/grpc/grpc_containers_service_private.cc +++ b/src/connect/service/grpc/grpc_containers_service_private.cc @@ -110,6 +110,10 @@ int ContainerServiceImpl::info_response_to_grpc(const host_info_response *respon return -1; } + if (pack_driver_info_to_grpc(response, gresponse)) { + return -1; + } + return 0; } @@ -1109,4 +1113,20 @@ int ContainerServiceImpl::pack_proxy_info_to_grpc(const host_info_response *resp return 0; } +int ContainerServiceImpl::pack_driver_info_to_grpc(const host_info_response *response, InfoResponse *gresponse) +{ + if (response == nullptr) { + gresponse->set_cc(ISULAD_ERR_MEMOUT); + return 0; + } + if (response->driver_name != nullptr) { + gresponse->set_driver_name(response->driver_name); + } + + if (response->driver_status != nullptr) { + gresponse->set_driver_status(response->driver_status); + } + + return 0; +} diff --git a/src/cutils/utils_string.c b/src/cutils/utils_string.c index 953f707..27136bb 100644 --- a/src/cutils/utils_string.c +++ b/src/cutils/utils_string.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "utils.h" #include "log.h" @@ -266,6 +267,30 @@ int util_parse_byte_size_string(const char *s, int64_t *converted) return ret; } +int util_parse_percent_string(const char *s, long *converted) +{ + char *dup = NULL; + + if (s == NULL || converted == NULL || s[0] == 0 || strlen(s) < 2 || s[strlen(s) - 1] != '%') { + return -EINVAL; + } + dup = util_strdup_s(s); + if (dup == NULL) { + return -ENOMEM; + } + dup[strlen(dup) - 1] = 0; + + *converted = strtol(dup, NULL, 10); + if ((errno == ERANGE && (*converted == LONG_MAX || *converted == LONG_MIN)) || + (errno != 0 && *converted == 0) || *converted < 0 || *converted >= 100) { + free(dup); + return -EINVAL; + } + + free(dup); + return 0; +} + static char **util_shrink_array(char **orig_array, size_t new_size) { char **new_array = NULL; diff --git a/src/cutils/utils_string.h b/src/cutils/utils_string.h index 317e988..d869936 100644 --- a/src/cutils/utils_string.h +++ b/src/cutils/utils_string.h @@ -35,6 +35,8 @@ char *strings_to_upper(const char *str); int util_parse_byte_size_string(const char *s, int64_t *converted); +int util_parse_percent_string(const char *s, long *converted); + // Breaks src_str into an array of string according to _sep, // note that two or more contiguous delimiter bytes is considered to be a single delimiter char **util_string_split(const char *src_str, char _sep); diff --git a/src/image/image.c b/src/image/image.c index 97a82c5..e3e8fcc 100644 --- a/src/image/image.c +++ b/src/image/image.c @@ -1745,6 +1745,8 @@ void free_im_storage_status_response(im_storage_status_response *ptr) } free(ptr->backing_fs); ptr->backing_fs = NULL; + free(ptr->status); + ptr->status = NULL; free(ptr); } diff --git a/src/image/image.h b/src/image/image.h index 144a138..8b72368 100644 --- a/src/image/image.h +++ b/src/image/image.h @@ -55,8 +55,7 @@ typedef struct { typedef struct { char *backing_fs; - bool supports_d_type; - bool native_overlay_diff; + char *status; } im_storage_status_response; typedef struct { diff --git a/src/image/oci/global_config.c b/src/image/oci/global_config.c index 70b1838..f18f04c 100644 --- a/src/image/oci/global_config.c +++ b/src/image/oci/global_config.c @@ -58,6 +58,12 @@ static int pack_global_graph_driver(const char * const *options, bool ignore_sto add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_DRIVER_OPTIONS], *p); } + if (strcmp(graph_driver, "devicemapper") == 0) { + // option "test=false" is used when devicemapper thinpool is created automatically by iSulad-kit. + // Make "test" always be true to avoid config check as we always create thinpool manually. + add_array_kv(params, PARAM_NUM, &i, options[GB_OPTION_DRIVER_OPTIONS], "test=true"); + } + ret = 0; *count = i; out: diff --git a/src/image/oci/isula_storage_status.c b/src/image/oci/isula_storage_status.c index 9a2e7f5..01fc80c 100644 --- a/src/image/oci/isula_storage_status.c +++ b/src/image/oci/isula_storage_status.c @@ -20,11 +20,58 @@ #include "utils.h" #include "log.h" -static void pack_im_response(const struct isula_storage_status_response *iresp, im_storage_status_response *resp) +// format: [status xx: val] +static int get_graphdriver_status_line_value(const char *line, char **start, char **end) { - resp->backing_fs = util_strdup_s(iresp->backing_fs); - resp->supports_d_type = iresp->supports_d_type; - resp->native_overlay_diff = iresp->native_overlay_diff; + char *pstart = NULL; + char *pend = NULL; + + pstart = strchr(line, ':'); + if (pstart == NULL) { + ERROR("Invalid output: %s", line); + return -1; + } + pstart++; + if (*pstart != ' ') { + ERROR("Invalid output: %s", line); + return -1; + } + pstart++; + + pend = strchr(pstart, '\n'); + if (pend == NULL) { + ERROR("Invalid output: %s", pstart); + return -1; + } + *pend++ = '\0'; + + *start = pstart; + *end = pend; + return 0; +} + +static int pack_im_response(const struct isula_storage_status_response *iresp, im_storage_status_response *resp) +{ + char *pstart = NULL; + char *pend = NULL; + + if (iresp->status == NULL) { + ERROR("Storage status response status NULL"); + isulad_set_error_message("Storage status response NULL"); + return -1; + } + + resp->status = util_strdup_s(iresp->status); + + // Backing Filesystem: extfs + if (get_graphdriver_status_line_value(iresp->status, &pstart, &pend) != 0) { + ERROR("Get backing filesystem from status failed. status:%s", iresp->status); + isulad_set_error_message("Get backing filesystem from status failed"); + return -1; + } + resp->backing_fs = util_strdup_s(pstart); + + return 0; } int isula_do_storage_status(im_storage_status_response *resp) @@ -71,7 +118,10 @@ int isula_do_storage_status(im_storage_status_response *resp) ret = -1; goto out; } - pack_im_response(iresp, resp); + ret = pack_im_response(iresp, resp); + if (ret != 0) { + goto out; + } out: free_isula_storage_status_response(iresp); diff --git a/src/image/oci/oci_common_operators.c b/src/image/oci/oci_common_operators.c index 0248ac7..73950cf 100644 --- a/src/image/oci/oci_common_operators.c +++ b/src/image/oci/oci_common_operators.c @@ -58,73 +58,6 @@ bool oci_detect(const char *image_name) return oci_image_exist(image_name); } -// format: [status xx: val] -static int get_graphdriver_status_line_value(const char *line, char **start, char **end) -{ - char *pstart = NULL; - char *pend = NULL; - - pstart = strchr(line, ':'); - if (pstart == NULL) { - ERROR("Invalid output: %s", line); - return -1; - } - pstart++; - if (*pstart != ' ') { - ERROR("Invalid output: %s", line); - return -1; - } - pstart++; - - pend = strchr(pstart, '\n'); - if (pend == NULL) { - ERROR("Invalid output: %s", pstart); - return -1; - } - *pend++ = '\0'; - - *start = pstart; - *end = pend; - return 0; -} - -int pack_storage_status_response(const char *stdout_buffer, im_storage_status_response *resp) -{ - char *pstart = NULL; - char *pend = NULL; - int nret = -1; - - // Backing Filesystem: extfs - if (get_graphdriver_status_line_value(stdout_buffer, &pstart, &pend) != 0) { - goto free_out; - } - resp->backing_fs = util_strdup_s(pstart); - - // Supports d_type: true - if (get_graphdriver_status_line_value(pend, &pstart, &pend) != 0) { - goto free_out; - } - nret = util_str_to_bool(pstart, &resp->supports_d_type); - if (nret < 0) { - ERROR("Invalid output: %s", pstart); - goto free_out; - } - - // Native Overlay Diff: true - if (get_graphdriver_status_line_value(pend, &pstart, &pend) != 0) { - goto free_out; - } - nret = util_str_to_bool(pstart, &resp->native_overlay_diff); - if (nret < 0) { - ERROR("Invalid output: %s", pstart); - goto free_out; - } - nret = 0; -free_out: - - return nret; -} - char *get_last_part(char **parts) { char *last_part = NULL; diff --git a/src/image/oci/oci_common_operators.h b/src/image/oci/oci_common_operators.h index fab7c74..f697393 100644 --- a/src/image/oci/oci_common_operators.h +++ b/src/image/oci/oci_common_operators.h @@ -24,7 +24,6 @@ extern "C" { #endif -int pack_storage_status_response(const char *stdout_buffer, im_storage_status_response *resp); char *oci_normalize_image_name(const char *name); bool oci_detect(const char *image_name); diff --git a/src/json/schema/schema/host/info-response.json b/src/json/schema/schema/host/info-response.json index 92a498f..c42fa68 100644 --- a/src/json/schema/schema/host/info-response.json +++ b/src/json/schema/schema/host/info-response.json @@ -62,6 +62,12 @@ "no_proxy": { "type": "string" }, + "driver_name": { + "type": "string" + }, + "driver_status": { + "type": "string" + }, "cc": { "type": "uint32" }, diff --git a/src/libisula.h b/src/libisula.h index ef9caef..69633ac 100644 --- a/src/libisula.h +++ b/src/libisula.h @@ -529,6 +529,8 @@ struct isula_info_response { char *http_proxy; char *https_proxy; char *no_proxy; + char *driver_name; + char *driver_status; uint32_t total_mem; uint32_t containers_num; uint32_t c_running; diff --git a/src/services/execution/execute/execution_information.c b/src/services/execution/execute/execution_information.c index 1cb8b43..e821886 100644 --- a/src/services/execution/execute/execution_information.c +++ b/src/services/execution/execute/execution_information.c @@ -198,6 +198,8 @@ static int isulad_info_cb(const host_info_request *request, host_info_response * struct utsname u; im_image_count_request *im_request = NULL; char *rootpath = NULL; + char *graph_driver = NULL; + struct graphdriver_status *driver_status = NULL; DAEMON_CLEAR_ERRMSG(); @@ -228,6 +230,19 @@ static int isulad_info_cb(const host_info_request *request, host_info_response * } #ifdef ENABLE_OCI_IMAGE im_request->type = util_strdup_s(IMAGE_TYPE_OCI); + + graph_driver = conf_get_isulad_storage_driver(); + if (graph_driver == NULL) { + ERROR("Failed to get graph driver name info!"); + goto pack_response; + } + + driver_status = graphdriver_get_status(); + if (driver_status == NULL) { + ERROR("Failed to get graph driver status info!"); + cc = ISULAD_ERR_EXEC; + goto pack_response; + } #endif images_num = im_get_image_count(im_request); @@ -308,12 +323,18 @@ static int isulad_info_cb(const host_info_request *request, host_info_response * (*response)->http_proxy = util_strdup_s(http_proxy); (*response)->https_proxy = util_strdup_s(https_proxy); (*response)->no_proxy = util_strdup_s(no_proxy); +#ifdef ENABLE_OCI_IMAGE + (*response)->driver_name = util_strdup_s(graph_driver); + (*response)->driver_status = util_strdup_s(driver_status->status); +#endif pack_response: if (*response != NULL) { (*response)->cc = cc; } free(rootpath); + free(graph_driver); + free_graphdriver_status(driver_status); free(huge_page_size); free(operating_system); free_im_image_count_request(im_request); diff --git a/src/services/graphdriver/CMakeLists.txt b/src/services/graphdriver/CMakeLists.txt index 9aff0a0..f532f85 100644 --- a/src/services/graphdriver/CMakeLists.txt +++ b/src/services/graphdriver/CMakeLists.txt @@ -1,14 +1,17 @@ # get current directory sources files aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_graphdriver_srcs) add_subdirectory(overlay2) +add_subdirectory(devmapper) set(GRAPHDRIVER_SRCS ${local_graphdriver_srcs} ${OVERLAY2_SRCS} + ${DEVMAPPER_SRCS} PARENT_SCOPE ) set(GRAPHDRIVER_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/overlay2 + ${CMAKE_CURRENT_SOURCE_DIR}/devmapper PARENT_SCOPE ) diff --git a/src/services/graphdriver/devmapper/CMakeLists.txt b/src/services/graphdriver/devmapper/CMakeLists.txt new file mode 100644 index 0000000..e55256c --- /dev/null +++ b/src/services/graphdriver/devmapper/CMakeLists.txt @@ -0,0 +1,7 @@ +# get current directory sources files +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_devmapper_srcs) + +set(DEVMAPPER_SRCS + ${local_devmapper_srcs} + PARENT_SCOPE + ) diff --git a/src/services/graphdriver/devmapper/driver_devmapper.c b/src/services/graphdriver/devmapper/driver_devmapper.c new file mode 100644 index 0000000..4bd765c --- /dev/null +++ b/src/services/graphdriver/devmapper/driver_devmapper.c @@ -0,0 +1,94 @@ +/****************************************************************************** +* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +* iSulad licensed under the Mulan PSL v1. +* You can use this software according to the terms and conditions of the Mulan PSL v1. +* You may obtain a copy of Mulan PSL v1 at: +* http://license.coscl.org.cn/MulanPSL +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +* PURPOSE. +* See the Mulan PSL v1 for more details. +* Author: wangfengtu +* Create: 2020-01-19 +* Description: provide devicemapper graphdriver function definition +******************************************************************************/ +#include "driver_devmapper.h" +#include +#include +#include + +#include "libisulad.h" +#include "utils.h" + +#define DM_LOG_FATAL 2 +#define DM_LOG_DEBUG 7 + +int devmapper_init(struct graphdriver *driver) +{ + return 0; +} + +bool devmapper_is_quota_options(struct graphdriver *driver, const char *option) +{ + return false; +} + +int devmapper_parse_options(struct graphdriver *driver, const char **options, size_t options_len) +{ + size_t i = 0; + + for (i = 0; options != NULL && i < options_len; i++) { + char *dup = NULL; + char *p = NULL; + char *val = NULL; + int ret = 0; + + dup = util_strdup_s(options[i]); + if (dup == NULL) { + isulad_set_error_message("Out of memory"); + return -1; + } + p = strchr(dup, '='); + if (!p) { + isulad_set_error_message("Unable to parse key/value option: '%s'", dup); + free(dup); + return -1; + } + *p = '\0'; + val = p + 1; + if (strcasecmp(dup, "dm.fs") == 0) { + if (strcmp(val, "ext4")) { + isulad_set_error_message("Invalid filesystem: '%s': not supported", val); + ret = -1; + } + } else if (strcasecmp(dup, "dm.thinpooldev") == 0) { + if (!strcmp(val, "")) { + isulad_set_error_message("Invalid thinpool device, it must not be empty"); + ret = -1; + } + } else if (strcasecmp(dup, "dm.min_free_space") == 0) { + long converted = 0; + ret = util_parse_percent_string(val, &converted); + if (ret != 0) { + isulad_set_error_message("Invalid min free space: '%s': %s", val, strerror(-ret)); + } + } else if (strcasecmp(dup, "dm.basesize") == 0) { + int64_t converted = 0; + ret = util_parse_byte_size_string(val, &converted); + if (ret != 0) { + isulad_set_error_message("Invalid size: '%s': %s", val, strerror(-ret)); + } + } else if (strcasecmp(dup, "dm.mkfsarg") == 0 || strcasecmp(dup, "dm.mountopt") == 0) { + /* We have no way to check validation here, validation is checked when using them. */ + } else { + isulad_set_error_message("devicemapper: unknown option: '%s'", dup); + ret = -1; + } + free(dup); + if (ret != 0) { + return ret; + } + } + + return 0; +} diff --git a/src/services/graphdriver/devmapper/driver_devmapper.h b/src/services/graphdriver/devmapper/driver_devmapper.h new file mode 100644 index 0000000..7f94f9e --- /dev/null +++ b/src/services/graphdriver/devmapper/driver_devmapper.h @@ -0,0 +1,34 @@ +/****************************************************************************** +* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +* iSulad licensed under the Mulan PSL v1. +* You can use this software according to the terms and conditions of the Mulan PSL v1. +* You may obtain a copy of Mulan PSL v1 at: +* http://license.coscl.org.cn/MulanPSL +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +* PURPOSE. +* See the Mulan PSL v1 for more details. +* Author: wangfengtu +* Create: 2020-01-19 +* Description: provide devicemapper graphdriver function definition +******************************************************************************/ +#ifndef __GRAPHDRIVER_DEVMAPPER_H +#define __GRAPHDRIVER_DEVMAPPER_H + +#include "driver.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int devmapper_init(struct graphdriver *driver); + +int devmapper_parse_options(struct graphdriver *driver, const char **options, size_t options_len); + +bool devmapper_is_quota_options(struct graphdriver *driver, const char *option); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/services/graphdriver/driver.c b/src/services/graphdriver/driver.c index 400a05c..b7721af 100644 --- a/src/services/graphdriver/driver.c +++ b/src/services/graphdriver/driver.c @@ -20,6 +20,7 @@ #include #include "driver_overlay2.h" +#include "driver_devmapper.h" #include "utils.h" #include "libisulad.h" #include "log.h" @@ -35,8 +36,18 @@ static const struct graphdriver_ops g_overlay2_ops = { .is_quota_options = overlay2_is_quota_options, }; +/* devicemapper */ +#define DRIVER_DEVMAPPER_NAME "devicemapper" + +static const struct graphdriver_ops g_devmapper_ops = { + .init = devmapper_init, + .parse_options = devmapper_parse_options, + .is_quota_options = devmapper_is_quota_options, +}; + static struct graphdriver g_drivers[] = { - {.name = DRIVER_OVERLAY2_NAME, .ops = &g_overlay2_ops} + {.name = DRIVER_OVERLAY2_NAME, .ops = &g_overlay2_ops}, + {.name = DRIVER_DEVMAPPER_NAME, .ops = &g_devmapper_ops} }; static const size_t g_numdrivers = sizeof(g_drivers) / sizeof(struct graphdriver); @@ -101,8 +112,7 @@ struct graphdriver_status *graphdriver_get_status(void) } status->backing_fs = util_strdup_s(resp->backing_fs); - status->supports_d_type = resp->supports_d_type; - status->native_overlay_diff = resp->native_overlay_diff; + status->status = util_strdup_s(resp->status); ret = 0; free_out: @@ -178,6 +188,7 @@ void free_graphdriver_status(struct graphdriver_status *status) return; } free(status->backing_fs); + free(status->status); free(status); } diff --git a/src/services/graphdriver/driver.h b/src/services/graphdriver/driver.h index 888ecf4..8192683 100644 --- a/src/services/graphdriver/driver.h +++ b/src/services/graphdriver/driver.h @@ -41,8 +41,7 @@ struct graphdriver { struct graphdriver_status { char *backing_fs; - bool supports_d_type; - bool native_overlay_diff; + char *status; }; struct graphdriver *graphdriver_init(const char *name, char **storage_opts, size_t storage_opts_len);