From 50eca706ba8869132cf5987c99ea00c475e83102 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 8 Mar 2021 10:44:37 +0000 Subject: [PATCH] cephfs: add ceph-dokan unmap command 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 (cherry picked from commit cd9b098afd2d6af3c097c9f79a6a3f924de9e02b) --- doc/cephfs/ceph-dokan.rst | 8 ++++++++ src/dokan/ceph_dokan.cc | 17 ++++++++++++++--- src/dokan/ceph_dokan.h | 3 ++- src/dokan/options.cc | 12 +++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/cephfs/ceph-dokan.rst b/doc/cephfs/ceph-dokan.rst index 6ddb57082d4fc..600650a8ed83c 100644 --- a/doc/cephfs/ceph-dokan.rst +++ b/doc/cephfs/ceph-dokan.rst @@ -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 ----------- diff --git a/src/dokan/ceph_dokan.cc b/src/dokan/ceph_dokan.cc index a9bd3323da33e..d16e81957799e 100644 --- a/src/dokan/ceph_dokan.cc +++ b/src/dokan/ceph_dokan.cc @@ -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; diff --git a/src/dokan/ceph_dokan.h b/src/dokan/ceph_dokan.h index 452e5171e735f..f4323e4ba01ce 100644 --- a/src/dokan/ceph_dokan.h +++ b/src/dokan/ceph_dokan.h @@ -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(); diff --git a/src/dokan/options.cc b/src/dokan/options.cc index 0f3637b14b8d2..21c5d4d6dbe4e 100644 --- a/src/dokan/options.cc +++ b/src/dokan/options.cc @@ -21,7 +21,9 @@ void print_usage() { const char* usage_str = R"( -Usage: ceph-dokan.exe -l +Usage: ceph-dokan.exe -l + map -l Map a CephFS filesystem + unmap -l 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; -- 2.39.5