|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 dingodb.com, Inc. All Rights Reserved |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_ |
| 18 | +#define DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_ |
| 19 | + |
| 20 | +#include <brpc/reloadable_flags.h> |
| 21 | +#include <gflags/gflags.h> |
| 22 | + |
| 23 | +#include <string> |
| 24 | + |
| 25 | +#include "common/blockaccess/accesser_common.h" |
| 26 | +#include "common/const.h" |
| 27 | +#include "common/options/client.h" |
| 28 | + |
| 29 | +namespace dingofs { |
| 30 | +namespace client { |
| 31 | + |
| 32 | +// fuse option |
| 33 | +struct FuseConnInfo { |
| 34 | + bool want_splice_move; |
| 35 | + bool want_splice_read; |
| 36 | + bool want_splice_write; |
| 37 | + bool want_auto_inval_data; |
| 38 | +}; |
| 39 | + |
| 40 | +struct FuseFileInfo { |
| 41 | + bool keep_cache; |
| 42 | +}; |
| 43 | + |
| 44 | +struct FuseOption { |
| 45 | + FuseConnInfo conn_info; |
| 46 | + FuseFileInfo file_info; |
| 47 | +}; |
| 48 | + |
| 49 | +// memory option |
| 50 | +struct PageOption { |
| 51 | + uint32_t page_size; |
| 52 | + uint64_t total_size; |
| 53 | + bool use_pool; |
| 54 | +}; |
| 55 | + |
| 56 | +// vfs option |
| 57 | +struct VFSMetaOption { |
| 58 | + uint32_t max_name_length; // max length of file name |
| 59 | +}; |
| 60 | + |
| 61 | +struct VFSDataOption { |
| 62 | + bool writeback{false}; // whether to use writeback |
| 63 | + std::string writeback_suffix; |
| 64 | +}; |
| 65 | + |
| 66 | +struct VFSOption { |
| 67 | + blockaccess::BlockAccessOptions block_access_opt; // from gflags |
| 68 | + PageOption page_option; |
| 69 | + FuseOption fuse_option; |
| 70 | + |
| 71 | + VFSMetaOption meta_option; |
| 72 | + VFSDataOption data_option; |
| 73 | + |
| 74 | + uint32_t dummy_server_port{10000}; |
| 75 | +}; |
| 76 | + |
| 77 | +static void InitFuseOption(FuseOption* option) { |
| 78 | + { // fuse conn info |
| 79 | + auto* fuse_conn_info = &option->conn_info; |
| 80 | + fuse_conn_info->want_splice_move = FLAGS_fuse_conn_info_want_splice_move; |
| 81 | + fuse_conn_info->want_splice_read = FLAGS_fuse_conn_info_want_splice_read; |
| 82 | + fuse_conn_info->want_splice_write = FLAGS_fuse_conn_info_want_splice_write; |
| 83 | + fuse_conn_info->want_auto_inval_data = |
| 84 | + FLAGS_fuse_conn_info_want_auto_inval_data; |
| 85 | + } |
| 86 | + |
| 87 | + { // fuse file info |
| 88 | + auto* fuse_file_info = &option->file_info; |
| 89 | + fuse_file_info->keep_cache = FLAGS_client_fuse_file_info_keep_cache; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +static void InitMemoryPageOption(PageOption* option) { |
| 94 | + // page option |
| 95 | + option->page_size = FLAGS_data_stream_page_size; |
| 96 | + option->total_size = FLAGS_data_stream_page_total_size_mb; |
| 97 | + option->use_pool = FLAGS_data_stream_page_use_pool; |
| 98 | + |
| 99 | + if (option->page_size == 0) { |
| 100 | + CHECK(false) << "page size must greater than 0."; |
| 101 | + } |
| 102 | + |
| 103 | + option->total_size = option->total_size * kMiB; |
| 104 | + if (option->total_size < 64 * kMiB) { |
| 105 | + CHECK(false) << "page total size must greater than 64MB."; |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +static void InitVFSMetaOption(VFSMetaOption* option) { |
| 110 | + option->max_name_length = FLAGS_vfs_meta_max_name_length; |
| 111 | + if (option->max_name_length < 1) { |
| 112 | + CHECK(false) << "file name length must greater than 0."; |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +static void InitVFSDataOption(VFSDataOption* option) { |
| 117 | + option->writeback = FLAGS_vfs_data_writeback; |
| 118 | + option->writeback_suffix = FLAGS_vfs_data_writeback_suffix; |
| 119 | +} |
| 120 | + |
| 121 | +static void InitVFSOption(VFSOption* option) { |
| 122 | + blockaccess::InitAwsSdkConfig( |
| 123 | + &option->block_access_opt.s3_options.aws_sdk_config); |
| 124 | + blockaccess::InitBlockAccesserThrottleOptions( |
| 125 | + &option->block_access_opt.throttle_options); |
| 126 | + |
| 127 | + InitMemoryPageOption(&option->page_option); |
| 128 | + |
| 129 | + InitFuseOption(&option->fuse_option); |
| 130 | + |
| 131 | + InitVFSMetaOption(&option->meta_option); |
| 132 | + |
| 133 | + InitVFSDataOption(&option->data_option); |
| 134 | + |
| 135 | + option->dummy_server_port = FLAGS_vfs_dummy_server_port; |
| 136 | +} |
| 137 | + |
| 138 | +} // namespace client |
| 139 | +} // namespace dingofs |
| 140 | + |
| 141 | +#endif // DINGOFS_CLIENT_COMMON_CLIENT_OPTION_H_ |
0 commit comments