diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2018-03-23 01:14:47 -0400 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2018-04-16 03:38:40 -0400 |
commit | d93605407af34eb0b7eb8aff6b1eae2cde3cdd22 (patch) | |
tree | 9d1df5bffef545755e61d3cd4db412922d60a815 | |
parent | 420efbdf4d2358dc12913298ad44d041c6ac0ed6 (diff) |
rbd: notrim map option
Add an option to turn off discard and write zeroes offload support to
avoid deprovisioning a fully provisioned image. When enabled, discard
requests will fail with -EOPNOTSUPP, write zeroes requests will fall
back to manually zeroing.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Tested-by: Hitoshi Kamei <hitoshi.kamei.xm@hitachi.com>
-rw-r--r-- | drivers/block/rbd.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 6a1805858b79..8e8b04cc569a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -741,6 +741,7 @@ enum { | |||
741 | Opt_read_write, | 741 | Opt_read_write, |
742 | Opt_lock_on_read, | 742 | Opt_lock_on_read, |
743 | Opt_exclusive, | 743 | Opt_exclusive, |
744 | Opt_notrim, | ||
744 | Opt_err | 745 | Opt_err |
745 | }; | 746 | }; |
746 | 747 | ||
@@ -755,6 +756,7 @@ static match_table_t rbd_opts_tokens = { | |||
755 | {Opt_read_write, "rw"}, /* Alternate spelling */ | 756 | {Opt_read_write, "rw"}, /* Alternate spelling */ |
756 | {Opt_lock_on_read, "lock_on_read"}, | 757 | {Opt_lock_on_read, "lock_on_read"}, |
757 | {Opt_exclusive, "exclusive"}, | 758 | {Opt_exclusive, "exclusive"}, |
759 | {Opt_notrim, "notrim"}, | ||
758 | {Opt_err, NULL} | 760 | {Opt_err, NULL} |
759 | }; | 761 | }; |
760 | 762 | ||
@@ -764,6 +766,7 @@ struct rbd_options { | |||
764 | bool read_only; | 766 | bool read_only; |
765 | bool lock_on_read; | 767 | bool lock_on_read; |
766 | bool exclusive; | 768 | bool exclusive; |
769 | bool trim; | ||
767 | }; | 770 | }; |
768 | 771 | ||
769 | #define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ | 772 | #define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ |
@@ -771,6 +774,7 @@ struct rbd_options { | |||
771 | #define RBD_READ_ONLY_DEFAULT false | 774 | #define RBD_READ_ONLY_DEFAULT false |
772 | #define RBD_LOCK_ON_READ_DEFAULT false | 775 | #define RBD_LOCK_ON_READ_DEFAULT false |
773 | #define RBD_EXCLUSIVE_DEFAULT false | 776 | #define RBD_EXCLUSIVE_DEFAULT false |
777 | #define RBD_TRIM_DEFAULT true | ||
774 | 778 | ||
775 | static int parse_rbd_opts_token(char *c, void *private) | 779 | static int parse_rbd_opts_token(char *c, void *private) |
776 | { | 780 | { |
@@ -820,6 +824,9 @@ static int parse_rbd_opts_token(char *c, void *private) | |||
820 | case Opt_exclusive: | 824 | case Opt_exclusive: |
821 | rbd_opts->exclusive = true; | 825 | rbd_opts->exclusive = true; |
822 | break; | 826 | break; |
827 | case Opt_notrim: | ||
828 | rbd_opts->trim = false; | ||
829 | break; | ||
823 | default: | 830 | default: |
824 | /* libceph prints "bad option" msg */ | 831 | /* libceph prints "bad option" msg */ |
825 | return -EINVAL; | 832 | return -EINVAL; |
@@ -3976,11 +3983,12 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) | |||
3976 | blk_queue_io_min(q, objset_bytes); | 3983 | blk_queue_io_min(q, objset_bytes); |
3977 | blk_queue_io_opt(q, objset_bytes); | 3984 | blk_queue_io_opt(q, objset_bytes); |
3978 | 3985 | ||
3979 | /* enable the discard support */ | 3986 | if (rbd_dev->opts->trim) { |
3980 | blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); | 3987 | blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); |
3981 | q->limits.discard_granularity = objset_bytes; | 3988 | q->limits.discard_granularity = objset_bytes; |
3982 | blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT); | 3989 | blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT); |
3983 | blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT); | 3990 | blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT); |
3991 | } | ||
3984 | 3992 | ||
3985 | if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC)) | 3993 | if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC)) |
3986 | q->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES; | 3994 | q->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES; |
@@ -5207,6 +5215,7 @@ static int rbd_add_parse_args(const char *buf, | |||
5207 | rbd_opts->lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT; | 5215 | rbd_opts->lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT; |
5208 | rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; | 5216 | rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; |
5209 | rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT; | 5217 | rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT; |
5218 | rbd_opts->trim = RBD_TRIM_DEFAULT; | ||
5210 | 5219 | ||
5211 | copts = ceph_parse_options(options, mon_addrs, | 5220 | copts = ceph_parse_options(options, mon_addrs, |
5212 | mon_addrs + mon_addrs_size - 1, | 5221 | mon_addrs + mon_addrs_size - 1, |