diff --git a/src/api/image_client/isula_image.proto b/src/api/image_client/isula_image.proto index 41a7f7d3ef4bc73c0c5e52670dadd2c5ee454d19..4a01932ac743d19968f072e559b292523faa8e49 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 73729cf9d895ea6088de8a204f3ee5018a6f592b..871d7036691744b876a6bca321fe71be2112b0a2 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 0e4ace82537a9020e13f561e5a791d593e8e0535..bcb81f831e008771bc4cdd18c0b8a6dbe62d1edb 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 0ccb7a3309d364bb459936c18e9ded815f436bcc..4a3a53f4c4e3e738d82a8e688ee998b6611862ae 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 470147d31de9c9c5ef95095f1a8bd4f0eb8da69c..b5ff790c8ca17026621665652c52f7cd08913825 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 8a2fa79960cf57f54d65b5ae5c5fa53809fb7ea3..9e1ae29cd4d0a6e1f3dcc737ef40480b98c9e465 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 21fbf279b559c288c8d2e65f0cd6e20005ecbf8a..98c3505ec5be3bc575abdb141c52e3305d7f9567 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 b7ceafc0e59a74308e1fa2aa82cc6fa87fa39e14..bc7787e1544fd6513ce26718a94564d788c4e23b 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 953f707f6815286d09f5d03a97b1179764b304a5..27136bbbe383ecd83ef70c52150ebadb62b8496a 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 317e98883017dc7e776d7ee29b49b54308f31218..d8699361d6acbd35f29453cd7cc29a025d53a5e9 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 97a82c50300c844bf98c00b5033f7e0f49100c87..e3e8fcca48fdee4d4baa10c9bac13b8645529ab2 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 144a1384d74ccaf6d55fcf9b1450bf6f01257020..8b72368acbf004c7a6d9f50240e3dbb598b0eaa5 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 70b1838aa66975833d2432d7ca515e47d310bd24..f18f04cea679fe894bbc74caf95af327394f68dc 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 9a2e7f551639ce94ad90192777861d08687d775f..01fc80c48bd4f4f043eb1b7323c7a649cc978845 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 0248ac7019489c0dd6a2ca2c65bed51cf82c8336..73950cfd9538ee222cc89065feaf372723a6b978 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 fab7c74981381b116e931d96d624bc044107bfc9..f6973932d502b24646797508de3fc8e181624a42 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 92a498f7c073b3e0d7970d7538958889852169bc..c42fa6840cdd2f2b67d6ddaf2d8e9ef690033e34 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 ef9caef6d25afba968213c97cb68ce2a05c70892..69633ac223d204befacdc6e1a77adcfd838f21d1 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 1cb8b43fe94c83a28a2ed8a6b6cc5a17e87a621a..e821886a0ea66ffc6da07e75ce1c288bf9c7b743 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 9aff0a03865e8178e7718816e7ed89273eee6a99..f532f85ae1a8a5fcf4e45e8c484bff809d63ddfa 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 0000000000000000000000000000000000000000..e55256cd1c7a8d68d20db29dd5c76b8ee9e28661 --- /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 0000000000000000000000000000000000000000..4bd765cbf440f464c2344813e93fe5e2065c423f --- /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 0000000000000000000000000000000000000000..7f94f9e927e67d700187088e8b0e6c4377ab510a --- /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 400a05c8db5113e302b318e665f8ce997fec53a3..b7721afc7a6fc0075275ccbe8683c94b5742c6cb 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 888ecf4f16af4d596d555bcba1062b9adb75058e..81926836e449ca3515746aacb1f1064178267362 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);