From: Prasanna Kumar Kalever Date: Mon, 21 Jun 2021 13:51:07 +0000 (+0530) Subject: rbd-nbd: support notrim option with map command X-Git-Tag: v17.1.0~1516^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=688f0c5fb096aae3b015985b831a1c1ba493672c;p=ceph.git rbd-nbd: support notrim option with map command 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 --- diff --git a/doc/man/8/rbd-nbd.rst b/doc/man/8/rbd-nbd.rst index 9991254f6faf..7876829dbe90 100644 --- a/doc/man/8/rbd-nbd.rst +++ b/doc/man/8/rbd-nbd.rst @@ -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. diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index d078376e9172..f7231f223fc4 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -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 Set nbd IO timeout\n" << " --max_part Override for module param max_part\n" << " --nbds_max 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& 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()) {