]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs: add ceph-dokan unmap command
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Mon, 8 Mar 2021 10:44:37 +0000 (10:44 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Tue, 20 Apr 2021 15:39:11 +0000 (15:39 +0000)
At the moment, Windows CephFS mounts can only be removed by
terminating the daemon (e.g. sending CTRL-C) or through the
Windows mount manager if the "-o -m" parameters were passed
when the mapping was created.

This change adds the "ceph-dokan unmap" command, which takes
the mountpoint as input.

Fixes: https://tracker.ceph.com/issues/49662
Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
(cherry picked from commit cd9b098afd2d6af3c097c9f79a6a3f924de9e02b)

doc/cephfs/ceph-dokan.rst
src/dokan/ceph_dokan.cc
src/dokan/ceph_dokan.h
src/dokan/options.cc

index 6ddb57082d4fcc643ae6a11242fa4a4b2d5c5d69..600650a8ed83cb5012ec008f68e45f2c2a05cabf 100644 (file)
@@ -32,6 +32,14 @@ changed using the following ``ceph.conf`` options::
 
 Please use ``ceph-dokan --help`` for a full list of arguments.
 
+The mount can be removed by either issuing ctrl-c or using the unmap command,
+like so::
+
+    ceph-dokan.exe unmap -l x
+
+Note that when unmapping Ceph filesystems, the exact same mountpoint argument
+must be used as when the mapping was created.
+
 Credentials
 -----------
 
index a9bd3323da33e2218b203d70860b2119322cce42..d16e81957799e916642025943b3270d476ec4087 100644 (file)
@@ -819,7 +819,16 @@ static NTSTATUS WinCephGetDiskFreeSpace(
   return 0;
 }
 
-int do_unmount() {
+int do_unmap(wstring& mountpoint) {
+  if (!DokanRemoveMountPoint(mountpoint.c_str())) {
+    wcerr << "Couldn't remove the specified CephFS mount: "
+          << mountpoint << std::endl;
+    return -EINVAL;
+  }
+  return 0;
+}
+
+int cleanup_mount() {
   int ret = ceph_unmount(cmount);
   if (ret)
     derr << "Couldn't perform clean unmount. Error: " << ret << dendl;
@@ -831,7 +840,7 @@ int do_unmount() {
 static NTSTATUS WinCephUnmount(
   PDOKAN_FILE_INFO  DokanFileInfo)
 {
-  do_unmount();
+  cleanup_mount();
   // TODO: consider propagating unmount errors to Dokan.
   return 0;
 }
@@ -853,7 +862,7 @@ BOOL WINAPI ConsoleHandler(DWORD dwType)
 
 static void unmount_atexit(void)
 {
-  do_unmount();
+  cleanup_mount();
 }
 
 int do_map() {
@@ -1008,6 +1017,8 @@ int main(int argc, const char** argv)
   switch (cmd) {
     case Command::Map:
       return do_map();
+    case Command::Unmap:
+      return do_unmap(g_cfg->mountpoint);
     default:
       print_usage();
       break;
index 452e5171e735f1a8b859e2291e7a5592488bdfbd..f4323e4ba01ce9bfbeb0444a014c52662e3c127d 100644 (file)
@@ -36,12 +36,13 @@ struct Config {
 
 extern Config *g_cfg;
 
-// TODO: list and unmap commands.
+// TODO: list and service commands.
 enum class Command {
   None,
   Version,
   Help,
   Map,
+  Unmap,
 };
 
 void print_usage();
index 0f3637b14b8d2d08d4f27a55927a6ea3396984df..21c5d4d6dbe4e498e91601060e38fef8441f410f 100644 (file)
@@ -21,7 +21,9 @@
 
 void print_usage() {
   const char* usage_str = R"(
-Usage: ceph-dokan.exe -l <drive_letter>
+Usage: ceph-dokan.exe -l <mountpoint>
+                      map -l <mountpoint>    Map a CephFS filesystem
+                      unmap -l <mountpoint>  Unmap a CephFS filesystem
 
 Map options:
   -l [ --mountpoint ] arg     mountpoint (path or drive letter) (e.g -l x)
@@ -38,6 +40,11 @@ Map options:
   --current-session-only      expose the mount only to the current user session
   -m [ --removable ]          use a removable drive
 
+Unmap options:
+  -l [ --mountpoint ] arg     mountpoint (path or drive letter) (e.g -l x).
+                              It has to be the exact same mountpoint that was
+                              used when the mapping was created.
+
 Common Options:
 )";
 
@@ -138,6 +145,8 @@ int parse_args(
       cmd = Command::Version;
     } else if (strcmp(*args.begin(), "map") == 0) {
       cmd = Command::Map;
+    } else if (strcmp(*args.begin(), "unmap") == 0) {
+      cmd = Command::Unmap;
     } else {
       *err_msg << "ceph-dokan: unknown command: " <<  *args.begin();
       return -EINVAL;
@@ -151,6 +160,7 @@ int parse_args(
 
   switch (cmd) {
     case Command::Map:
+    case Command::Unmap:
       if (cfg->mountpoint.empty()) {
         *err_msg << "ceph-dokan: missing mountpoint.";
         return -EINVAL;