Skip to content

Commit d936054

Browse files
committed
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 <[email protected]> Tested-by: Hitoshi Kamei <[email protected]>
1 parent 420efbd commit d936054

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/block/rbd.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ enum {
741741
Opt_read_write,
742742
Opt_lock_on_read,
743743
Opt_exclusive,
744+
Opt_notrim,
744745
Opt_err
745746
};
746747

@@ -755,6 +756,7 @@ static match_table_t rbd_opts_tokens = {
755756
{Opt_read_write, "rw"}, /* Alternate spelling */
756757
{Opt_lock_on_read, "lock_on_read"},
757758
{Opt_exclusive, "exclusive"},
759+
{Opt_notrim, "notrim"},
758760
{Opt_err, NULL}
759761
};
760762

@@ -764,13 +766,15 @@ struct rbd_options {
764766
bool read_only;
765767
bool lock_on_read;
766768
bool exclusive;
769+
bool trim;
767770
};
768771

769772
#define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ
770773
#define RBD_LOCK_TIMEOUT_DEFAULT 0 /* no timeout */
771774
#define RBD_READ_ONLY_DEFAULT false
772775
#define RBD_LOCK_ON_READ_DEFAULT false
773776
#define RBD_EXCLUSIVE_DEFAULT false
777+
#define RBD_TRIM_DEFAULT true
774778

775779
static int parse_rbd_opts_token(char *c, void *private)
776780
{
@@ -820,6 +824,9 @@ static int parse_rbd_opts_token(char *c, void *private)
820824
case Opt_exclusive:
821825
rbd_opts->exclusive = true;
822826
break;
827+
case Opt_notrim:
828+
rbd_opts->trim = false;
829+
break;
823830
default:
824831
/* libceph prints "bad option" msg */
825832
return -EINVAL;
@@ -3976,11 +3983,12 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
39763983
blk_queue_io_min(q, objset_bytes);
39773984
blk_queue_io_opt(q, objset_bytes);
39783985

3979-
/* enable the discard support */
3980-
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
3981-
q->limits.discard_granularity = objset_bytes;
3982-
blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT);
3983-
blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT);
3986+
if (rbd_dev->opts->trim) {
3987+
blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
3988+
q->limits.discard_granularity = objset_bytes;
3989+
blk_queue_max_discard_sectors(q, objset_bytes >> SECTOR_SHIFT);
3990+
blk_queue_max_write_zeroes_sectors(q, objset_bytes >> SECTOR_SHIFT);
3991+
}
39843992

39853993
if (!ceph_test_opt(rbd_dev->rbd_client->client, NOCRC))
39863994
q->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
@@ -5207,6 +5215,7 @@ static int rbd_add_parse_args(const char *buf,
52075215
rbd_opts->lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT;
52085216
rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT;
52095217
rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT;
5218+
rbd_opts->trim = RBD_TRIM_DEFAULT;
52105219

52115220
copts = ceph_parse_options(options, mon_addrs,
52125221
mon_addrs + mon_addrs_size - 1,

0 commit comments

Comments
 (0)