drbd: Introduce new disk config option rs-discard-granularity
authorPhilipp Reisner <philipp.reisner@linbit.com>
Mon, 13 Jun 2016 22:26:14 +0000 (00:26 +0200)
committerJens Axboe <axboe@fb.com>
Tue, 14 Jun 2016 03:43:04 +0000 (21:43 -0600)
As long as the value is 0 the feature is disabled. With setting
it to a positive value, DRBD limits and aligns its resync requests
to the rs-discard-granularity setting. If the sync source detects
all zeros in such a block, the resync target discards the range
on disk.

Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/block/drbd/drbd_nl.c
include/linux/drbd_genl.h
include/linux/drbd_limits.h

index fad03e4feef6e4b8a1935b890dbc1eff27f781e4..99339dfe4389500c1b5949e5cab19aeac207fcae 100644 (file)
@@ -1348,12 +1348,38 @@ static bool write_ordering_changed(struct disk_conf *a, struct disk_conf *b)
                a->disk_drain != b->disk_drain;
 }
 
-static void sanitize_disk_conf(struct disk_conf *disk_conf, struct drbd_backing_dev *nbc)
+static void sanitize_disk_conf(struct drbd_device *device, struct disk_conf *disk_conf,
+                              struct drbd_backing_dev *nbc)
 {
+       struct request_queue * const q = nbc->backing_bdev->bd_disk->queue;
+
        if (disk_conf->al_extents < DRBD_AL_EXTENTS_MIN)
                disk_conf->al_extents = DRBD_AL_EXTENTS_MIN;
        if (disk_conf->al_extents > drbd_al_extents_max(nbc))
                disk_conf->al_extents = drbd_al_extents_max(nbc);
+
+       if (!blk_queue_discard(q) || !q->limits.discard_zeroes_data) {
+               disk_conf->rs_discard_granularity = 0; /* disable feature */
+               drbd_info(device, "rs_discard_granularity feature disabled\n");
+       }
+
+       if (disk_conf->rs_discard_granularity) {
+               int orig_value = disk_conf->rs_discard_granularity;
+               int remainder;
+
+               if (q->limits.discard_granularity > disk_conf->rs_discard_granularity)
+                       disk_conf->rs_discard_granularity = q->limits.discard_granularity;
+
+               remainder = disk_conf->rs_discard_granularity % q->limits.discard_granularity;
+               disk_conf->rs_discard_granularity += remainder;
+
+               if (disk_conf->rs_discard_granularity > q->limits.max_discard_sectors << 9)
+                       disk_conf->rs_discard_granularity = q->limits.max_discard_sectors << 9;
+
+               if (disk_conf->rs_discard_granularity != orig_value)
+                       drbd_info(device, "rs_discard_granularity changed to %d\n",
+                                 disk_conf->rs_discard_granularity);
+       }
 }
 
 int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
@@ -1403,7 +1429,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
        if (!expect(new_disk_conf->resync_rate >= 1))
                new_disk_conf->resync_rate = 1;
 
-       sanitize_disk_conf(new_disk_conf, device->ldev);
+       sanitize_disk_conf(device, new_disk_conf, device->ldev);
 
        if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX)
                new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX;
@@ -1698,7 +1724,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
        if (retcode != NO_ERROR)
                goto fail;
 
-       sanitize_disk_conf(new_disk_conf, nbc);
+       sanitize_disk_conf(device, new_disk_conf, nbc);
 
        if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) {
                drbd_err(device, "max capacity %llu smaller than disk size %llu\n",
index 2d0e5ad5de9d34227700acfee0e188eb6c752471..ab649d8e9ed24a466c0d466b05f54f8c28d016aa 100644 (file)
@@ -123,14 +123,14 @@ GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf,
        __u32_field_def(13,     DRBD_GENLA_F_MANDATORY, c_fill_target, DRBD_C_FILL_TARGET_DEF)
        __u32_field_def(14,     DRBD_GENLA_F_MANDATORY, c_max_rate, DRBD_C_MAX_RATE_DEF)
        __u32_field_def(15,     DRBD_GENLA_F_MANDATORY, c_min_rate, DRBD_C_MIN_RATE_DEF)
+       __u32_field_def(20,     DRBD_GENLA_F_MANDATORY, disk_timeout, DRBD_DISK_TIMEOUT_DEF)
+       __u32_field_def(21,     0 /* OPTIONAL */,       read_balancing, DRBD_READ_BALANCING_DEF)
+       __u32_field_def(25,     0 /* OPTIONAL */,       rs_discard_granularity, DRBD_RS_DISCARD_GRANULARITY_DEF)
 
        __flg_field_def(16, DRBD_GENLA_F_MANDATORY,     disk_barrier, DRBD_DISK_BARRIER_DEF)
        __flg_field_def(17, DRBD_GENLA_F_MANDATORY,     disk_flushes, DRBD_DISK_FLUSHES_DEF)
        __flg_field_def(18, DRBD_GENLA_F_MANDATORY,     disk_drain, DRBD_DISK_DRAIN_DEF)
        __flg_field_def(19, DRBD_GENLA_F_MANDATORY,     md_flushes, DRBD_MD_FLUSHES_DEF)
-       __u32_field_def(20,     DRBD_GENLA_F_MANDATORY, disk_timeout, DRBD_DISK_TIMEOUT_DEF)
-       __u32_field_def(21,     0 /* OPTIONAL */,       read_balancing, DRBD_READ_BALANCING_DEF)
-       /* 9: __u32_field_def(22,       DRBD_GENLA_F_MANDATORY, unplug_watermark, DRBD_UNPLUG_WATERMARK_DEF) */
        __flg_field_def(23,     0 /* OPTIONAL */,       al_updates, DRBD_AL_UPDATES_DEF)
 )
 
index 8ac8c5d9a3ad08482bee1bcd0e5d4c57603436a7..2e4aad8d8ae83fcb41f653473faaa5afb9bc461d 100644 (file)
 #define DRBD_SOCKET_CHECK_TIMEO_MAX DRBD_PING_TIMEO_MAX
 #define DRBD_SOCKET_CHECK_TIMEO_DEF 0
 #define DRBD_SOCKET_CHECK_TIMEO_SCALE '1'
+
+#define DRBD_RS_DISCARD_GRANULARITY_MIN 0
+#define DRBD_RS_DISCARD_GRANULARITY_MAX (1<<20)  /* 1MiByte */
+#define DRBD_RS_DISCARD_GRANULARITY_DEF 0     /* disabled by default */
+#define DRBD_RS_DISCARD_GRANULARITY_SCALE '1' /* bytes */
+
 #endif