]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-nbd: support notrim option with map command
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Mon, 21 Jun 2021 13:51:07 +0000 (19:21 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Mon, 28 Jun 2021 08:16:43 +0000 (13:46 +0530)
currently --notrim option works for rbd kernel mounter, but fails with rbd-nbd

$ rbd device --options notrim map rbd-pool/image0
/dev/rbd0
$ rbd device list
id  pool      namespace  image   snap  device
0   rbd-pool             image0  -     /dev/rbd0

$ rbd device --device-type nbd --options try-netlink,notrim map rbd-pool/image0
rbd-nbd: unknown args: --notrim
rbd: rbd-nbd failed with error: /data/ceph/build/bin/rbd-nbd: exit status: 1

With this changes:
$ rbd device --device-type nbd --options try-netlink,notrim map rbd-pool/image0
/dev/nbd0
$ rbd-nbd list-mapped
id    pool      namespace  image   snap  device
6945  rbd-pool             image0  -     /dev/nbd0
$ ps -eo "cmd" |grep [r]bd-nbd
/data/ceph/build/bin/rbd-nbd map rbd-pool/image0 --try-netlink --notrim

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
doc/man/8/rbd-nbd.rst
src/tools/rbd_nbd/rbd-nbd.cc

index 9991254f6fafb39af9e467590d21677587164af5..7876829dbe902c4f5fc2e0005fe73f7a77af075e 100644 (file)
@@ -9,7 +9,7 @@
 Synopsis
 ========
 
-| **rbd-nbd** [-c conf] [--read-only] [--device *nbd device*] [--nbds_max *limit*] [--max_part *limit*] [--exclusive] [--encryption-format *format*] [--encryption-passphrase-file *passphrase-file*] [--io-timeout *seconds*] [--reattach-timeout *seconds*] map *image-spec* | *snap-spec*
+| **rbd-nbd** [-c conf] [--read-only] [--device *nbd device*] [--nbds_max *limit*] [--max_part *limit*] [--exclusive] [--notrim] [--encryption-format *format*] [--encryption-passphrase-file *passphrase-file*] [--io-timeout *seconds*] [--reattach-timeout *seconds*] map *image-spec* | *snap-spec*
 | **rbd-nbd** unmap *nbd device* | *image-spec* | *snap-spec*
 | **rbd-nbd** list-mapped
 | **rbd-nbd** attach --device *nbd device* *image-spec* | *snap-spec*
@@ -47,6 +47,10 @@ Options
 
    Forbid writes by other clients.
 
+.. option:: --notrim
+
+   Turn off trim/discard.
+
 .. option:: --encryption-format
 
    Image encryption format.
index d078376e9172d7e63e424f6aaa2ab88a3a4ac556..f7231f223fc49d271ab72fb19ad8d3033022b6ae 100644 (file)
@@ -101,6 +101,7 @@ struct Config {
   int reattach_timeout = 30;
 
   bool exclusive = false;
+  bool notrim = false;
   bool quiesce = false;
   bool readonly = false;
   bool set_max_part = false;
@@ -151,6 +152,7 @@ static void usage()
             << "                                (possible values: luks1, luks2)\n"
             << "  --encryption-passphrase-file  Path of file containing passphrase for unlocking image encryption\n"
             << "  --exclusive                   Forbid writes by other clients\n"
+            << "  --notrim                      Turn off trim/discard\n"
             << "  --io-timeout <sec>            Set nbd IO timeout\n"
             << "  --max_part <limit>            Override for module param max_part\n"
             << "  --nbds_max <limit>            Override for module param nbds_max\n"
@@ -1691,7 +1693,10 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
   if (r < 0)
     goto close_fd;
 
-  flags = NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_TRIM | NBD_FLAG_HAS_FLAGS;
+  flags = NBD_FLAG_SEND_FLUSH | NBD_FLAG_HAS_FLAGS;
+  if (!cfg->notrim) {
+    flags |= NBD_FLAG_SEND_TRIM;
+  }
   if (!cfg->snapname.empty() || cfg->readonly) {
     flags |= NBD_FLAG_READ_ONLY;
     read_only = 1;
@@ -2032,6 +2037,8 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
       }
     } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) {
       cfg->exclusive = true;
+    } else if (ceph_argparse_flag(args, i, "--notrim", (char *)NULL)) {
+      cfg->notrim = true;
     } else if (ceph_argparse_witharg(args, i, &cfg->io_timeout, err,
                                      "--timeout", (char *)NULL)) {
       if (!err.str().empty()) {