]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: allow non persistent Windows mappings
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 27 Jan 2021 09:06:19 +0000 (09:06 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 5 Feb 2021 07:52:03 +0000 (07:52 +0000)
At the moment, all Windows RBD mappings are persistent, being
recreated when the Ceph service starts.

This change adds the "--non-persistent" flag to allow skipping
certain images.

Note that even for non-persistent mappings, we're still storing
data in the Windows registry, allowing us to retrieve image
details such as the rbd pool as well as the admin socket path.

When the daemons stop or the Ceph service starts, non-persistent
entries are cleaned up from the Windows registry.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
(cherry picked from commit 2455a907e66e706e2be4f91322b8f4cdd59fc844)

src/common/win32/registry.cc
src/common/win32/registry.h
src/tools/rbd_wnbd/rbd_wnbd.cc
src/tools/rbd_wnbd/rbd_wnbd.h

index d032e3b602ab8dcef4190af20cb91b2946402168..85ab80df97b61c9723ec41dfac85409019e425a4 100644 (file)
@@ -112,7 +112,17 @@ int RegistryKey::set(LPCTSTR lpValue, std::string data)
   return 0;
 }
 
-int RegistryKey::get(LPCTSTR lpValue, DWORD* value)
+int RegistryKey::get(LPCTSTR lpValue, bool& value)
+{
+  DWORD value_dw = 0;
+  int r = get(lpValue, value_dw);
+  if (!r) {
+    value = !!value_dw;
+  }
+  return r;
+}
+
+int RegistryKey::get(LPCTSTR lpValue, DWORD& value)
 {
   DWORD data;
   DWORD size = sizeof(data);
@@ -125,7 +135,7 @@ int RegistryKey::get(LPCTSTR lpValue, DWORD* value)
          << (char*)lpValue << dendl;
     return -EINVAL;
   }
-  *value = data;
+  value = data;
 
   return 0;
 }
index 974d662de2d98be344a1c0113088158cf221aec6..fdaf9708a9b63fbd9ca974320416756c90bfbc65 100644 (file)
@@ -26,7 +26,8 @@ public:
   int set(LPCTSTR lpValue, DWORD data);
   int set(LPCTSTR lpValue, std::string data);
 
-  int get(LPCTSTR lpValue, DWORD* value);
+  int get(LPCTSTR lpValue, bool& value);
+  int get(LPCTSTR lpValue, DWORD& value);
   int get(LPCTSTR lpValue, std::string& value);
 
   HKEY hKey = NULL;
index e5733c2685793032390b13414b59a2445e340d68..7421f01609721384acd273c1ed05b93b8178def3 100644 (file)
@@ -404,6 +404,7 @@ int save_config_to_registry(Config* cfg)
       reg_key.set("imgname", cfg->imgname) ||
       reg_key.set("snapname", cfg->snapname) ||
       reg_key.set("command_line", GetCommandLine()) ||
+      reg_key.set("persistent", cfg->persistent) ||
       reg_key.set("admin_sock_path", g_conf()->admin_socket) ||
       reg_key.flush()) {
     ret_val = -EINVAL;
@@ -441,6 +442,7 @@ int load_mapping_config_from_registry(string devpath, Config* cfg)
   reg_key.get("imgname", cfg->imgname);
   reg_key.get("snapname", cfg->snapname);
   reg_key.get("command_line", cfg->command_line);
+  reg_key.get("persistent", cfg->persistent);
   reg_key.get("admin_sock_path", cfg->admin_sock_path);
 
   return 0;
@@ -465,6 +467,16 @@ int restart_registered_mappings(int worker_count)
               << cfg.devpath << dendl;
       continue;
     }
+    if (!cfg.persistent) {
+      dout(5) << __func__ << ": cleaning up non-persistent mapping: "
+              << cfg.devpath << dendl;
+      r = remove_config_from_registry(&cfg);
+      if (r) {
+        derr << __func__ << ": could not clean up non-persistent mapping: "
+             << cfg.devpath << dendl;
+      }
+      continue;
+    }
 
     boost::asio::post(pool,
       [&, cfg]() mutable
@@ -747,6 +759,8 @@ Map options:
   --device <device path>  Optional mapping unique identifier
   --exclusive             Forbid writes by other clients
   --read-only             Map read-only
+  --non-persistent        Do not recreate the mapping when the Ceph service
+                          restarts. By default, mappings are persistent
   --io-req-workers        The number of workers that dispatch IO requests.
                           Default: 4
   --io-reply-workers      The number of workers that dispatch IO replies.
@@ -935,6 +949,11 @@ static int do_map(Config *cfg)
     goto close_ret;
   }
 
+  // We're storing mapping details in the registry even for non-persistent
+  // mappings. This allows us to easily retrieve mapping details such
+  // as the rbd pool or admin socket path.
+  // We're cleaning up the registry entry when the non-persistent mapping
+  // gets disconnected or when the ceph service restarts.
   r = save_config_to_registry(cfg);
   if (r < 0)
     goto close_ret;
@@ -967,6 +986,16 @@ static int do_map(Config *cfg)
   handler->wait();
   handler->shutdown();
 
+  if (!cfg->persistent) {
+    dout(5) << __func__ << ": cleaning up non-persistent mapping: "
+            << cfg->devpath << dendl;
+    r = remove_config_from_registry(cfg);
+    if (r) {
+      derr << __func__ << ": could not clean up non-persistent mapping: "
+           << cfg->devpath << dendl;
+    }
+  }
+
 close_ret:
   std::unique_lock l{shutdown_lock};
 
@@ -1144,6 +1173,7 @@ static int do_show_mapped_device(std::string format, bool pretty_format,
   f->dump_string("namespace", cfg.nsname);
   f->dump_string("image", cfg.imgname);
   f->dump_string("snap", cfg.snapname);
+  f->dump_int("persistent", cfg.persistent);
   f->dump_int("disk_number", conn_info.DiskNumber ? conn_info.DiskNumber : -1);
   f->dump_string("status", cfg.active ? WNBD_STATUS_ACTIVE : WNBD_STATUS_INACTIVE);
   f->dump_string("pnp_device_id", to_string(conn_info.PNPDeviceID));
@@ -1228,6 +1258,8 @@ static int parse_args(std::vector<const char*>& args,
       cfg->readonly = true;
     } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) {
       cfg->exclusive = true;
+    } else if (ceph_argparse_flag(args, i, "--non-persistent", (char *)NULL)) {
+      cfg->persistent = false;
     } else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) {
       cfg->pretty_format = true;
     } else if (ceph_argparse_witharg(args, i, &cfg->parent_pipe, err,
index 4cb5da0a48637f6d3fd32546fae26bc48417c9b2..30428c3ee84ce15151b9ba4980c9c075b7448df5 100644 (file)
@@ -76,6 +76,9 @@ struct Config {
   int io_req_workers = DEFAULT_IO_WORKER_COUNT;
   int io_reply_workers = DEFAULT_IO_WORKER_COUNT;
   int service_thread_count = DEFAULT_SERVICE_THREAD_COUNT;
+
+  // register the mapping, recreating it when the Ceph service starts.
+  bool persistent = true;
 };
 
 enum Command {