2 * Ceph - scalable distributed file system
4 * Copyright (C) 2020 SUSE LINUX GmbH
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
20 #include "include/compat.h"
21 #include "common/win32/registry.h"
23 #include "wnbd_handler.h"
25 #define SERVICE_REG_KEY "SYSTEM\\CurrentControlSet\\Services\\rbd-wnbd"
26 #define SERVICE_PIPE_NAME "\\\\.\\pipe\\rbd-wnbd"
27 #define SERVICE_PIPE_TIMEOUT_MS 5000
28 #define SERVICE_PIPE_BUFFSZ 4096
30 #define DEFAULT_MAP_TIMEOUT_MS 30000
32 #define RBD_WNBD_BLKSIZE 512UL
34 #define DEFAULT_SERVICE_START_TIMEOUT 120
35 #define DEFAULT_IMAGE_MAP_TIMEOUT 20
38 #define VERSION_INFO 2
40 #define WNBD_STATUS_ACTIVE "active"
41 #define WNBD_STATUS_INACTIVE "inactive"
43 #define DEFAULT_SERVICE_THREAD_COUNT 8
45 static WnbdHandler
* handler
= nullptr;
46 ceph::mutex shutdown_lock
= ceph::make_mutex("RbdWnbd::ShutdownLock");
49 bool exclusive
= false;
50 bool readonly
= false;
52 std::string parent_pipe
;
61 bool pretty_format
= false;
63 bool hard_disconnect
= false;
64 int soft_disconnect_timeout
= DEFAULT_SOFT_REMOVE_TIMEOUT
;
65 bool hard_disconnect_fallback
= true;
67 int service_start_timeout
= DEFAULT_SERVICE_START_TIMEOUT
;
68 int image_map_timeout
= DEFAULT_IMAGE_MAP_TIMEOUT
;
69 bool remap_failure_fatal
= false;
71 // TODO: consider moving those fields to a separate structure. Those
72 // provide connection information without actually being configurable.
73 // The disk number is provided by Windows.
76 std::string serial_number
;
78 bool wnbd_mapped
= false;
79 std::string command_line
;
80 std::string admin_sock_path
;
82 WnbdLogLevel wnbd_log_level
= WnbdLogLevelInfo
;
83 int io_req_workers
= DEFAULT_IO_WORKER_COUNT
;
84 int io_reply_workers
= DEFAULT_IO_WORKER_COUNT
;
85 int service_thread_count
= DEFAULT_SERVICE_THREAD_COUNT
;
87 // register the mapping, recreating it when the Ceph service starts.
88 bool persistent
= true;
110 bool is_process_running(DWORD pid
);
111 void unmap_at_exit();
113 int disconnect_all_mappings(
115 bool hard_disconnect
,
116 int soft_disconnect_timeout
,
118 int restart_registered_mappings(
119 int worker_count
, int total_timeout
, int image_map_timeout
);
120 int map_device_using_suprocess(std::string command_line
);
122 int construct_devpath_if_missing(Config
* cfg
);
123 int save_config_to_registry(Config
* cfg
);
124 int remove_config_from_registry(Config
* cfg
);
125 int load_mapping_config_from_registry(std::string devpath
, Config
* cfg
);
127 BOOL WINAPI
console_handler_routine(DWORD dwCtrlType
);
129 static int parse_args(std::vector
<const char*>& args
,
130 std::ostream
*err_msg
,
131 Command
*command
, Config
*cfg
);
132 static int do_unmap(Config
*cfg
, bool unregister
);
137 virtual ~BaseIterator() {};
138 virtual bool get(Config
*cfg
) = 0;
148 // Iterate over mapped devices, retrieving info from the driver.
149 class WNBDActiveDiskIterator
: public BaseIterator
{
151 WNBDActiveDiskIterator();
152 ~WNBDActiveDiskIterator();
154 bool get(Config
*cfg
);
157 PWNBD_CONNECTION_LIST conn_list
= NULL
;
159 static DWORD
fetch_list(PWNBD_CONNECTION_LIST
* conn_list
);
163 // Iterate over the Windows registry key, retrieving registered mappings.
164 class RegistryDiskIterator
: public BaseIterator
{
166 RegistryDiskIterator();
167 ~RegistryDiskIterator() {
171 bool get(Config
*cfg
);
173 DWORD subkey_count
= 0;
174 char subkey_name
[MAX_PATH
];
176 RegistryKey
* reg_key
= NULL
;
179 // Iterate over all RBD mappings, getting info from the registry and driver.
180 class WNBDDiskIterator
: public BaseIterator
{
182 bool get(Config
*cfg
);
185 // We'll keep track of the active devices.
186 std::set
<std::string
> active_devices
;
188 WNBDActiveDiskIterator active_iterator
;
189 RegistryDiskIterator registry_iterator
;