Skip to content

Commit 819a2df

Browse files
Mikulas Patockaksacilotto
authored andcommitted
dm writecache: return the exact table values that were set
BugLink: https://bugs.launchpad.net/bugs/1939442 commit 054bee1 upstream. LVM doesn't like it when the target returns different values from what was set in the constructor. Fix dm-writecache so that the returned table values are exactly the same as requested values. Signed-off-by: Mikulas Patocka <[email protected]> Cc: [email protected] # v4.18+ Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kelsey Skunberg <[email protected]>
1 parent f163e50 commit 819a2df

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

drivers/md/dm-writecache.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct dm_writecache {
154154
bool overwrote_committed:1;
155155
bool memory_vmapped:1;
156156

157+
bool start_sector_set:1;
157158
bool high_wm_percent_set:1;
158159
bool low_wm_percent_set:1;
159160
bool max_writeback_jobs_set:1;
@@ -162,6 +163,10 @@ struct dm_writecache {
162163
bool writeback_fua_set:1;
163164
bool flush_on_suspend:1;
164165

166+
unsigned high_wm_percent_value;
167+
unsigned low_wm_percent_value;
168+
unsigned autocommit_time_value;
169+
165170
unsigned writeback_all;
166171
struct workqueue_struct *writeback_wq;
167172
struct work_struct writeback_work;
@@ -2069,6 +2074,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
20692074
if (sscanf(string, "%llu%c", &start_sector, &dummy) != 1)
20702075
goto invalid_optional;
20712076
wc->start_sector = start_sector;
2077+
wc->start_sector_set = true;
20722078
if (wc->start_sector != start_sector ||
20732079
wc->start_sector >= wc->memory_map_size >> SECTOR_SHIFT)
20742080
goto invalid_optional;
@@ -2078,13 +2084,15 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
20782084
goto invalid_optional;
20792085
if (high_wm_percent < 0 || high_wm_percent > 100)
20802086
goto invalid_optional;
2087+
wc->high_wm_percent_value = high_wm_percent;
20812088
wc->high_wm_percent_set = true;
20822089
} else if (!strcasecmp(string, "low_watermark") && opt_params >= 1) {
20832090
string = dm_shift_arg(&as), opt_params--;
20842091
if (sscanf(string, "%d%c", &low_wm_percent, &dummy) != 1)
20852092
goto invalid_optional;
20862093
if (low_wm_percent < 0 || low_wm_percent > 100)
20872094
goto invalid_optional;
2095+
wc->low_wm_percent_value = low_wm_percent;
20882096
wc->low_wm_percent_set = true;
20892097
} else if (!strcasecmp(string, "writeback_jobs") && opt_params >= 1) {
20902098
string = dm_shift_arg(&as), opt_params--;
@@ -2104,6 +2112,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
21042112
if (autocommit_msecs > 3600000)
21052113
goto invalid_optional;
21062114
wc->autocommit_jiffies = msecs_to_jiffies(autocommit_msecs);
2115+
wc->autocommit_time_value = autocommit_msecs;
21072116
wc->autocommit_time_set = true;
21082117
} else if (!strcasecmp(string, "fua")) {
21092118
if (WC_MODE_PMEM(wc)) {
@@ -2305,7 +2314,6 @@ static void writecache_status(struct dm_target *ti, status_type_t type,
23052314
struct dm_writecache *wc = ti->private;
23062315
unsigned extra_args;
23072316
unsigned sz = 0;
2308-
uint64_t x;
23092317

23102318
switch (type) {
23112319
case STATUSTYPE_INFO:
@@ -2317,7 +2325,7 @@ static void writecache_status(struct dm_target *ti, status_type_t type,
23172325
DMEMIT("%c %s %s %u ", WC_MODE_PMEM(wc) ? 'p' : 's',
23182326
wc->dev->name, wc->ssd_dev->name, wc->block_size);
23192327
extra_args = 0;
2320-
if (wc->start_sector)
2328+
if (wc->start_sector_set)
23212329
extra_args += 2;
23222330
if (wc->high_wm_percent_set)
23232331
extra_args += 2;
@@ -2333,26 +2341,18 @@ static void writecache_status(struct dm_target *ti, status_type_t type,
23332341
extra_args++;
23342342

23352343
DMEMIT("%u", extra_args);
2336-
if (wc->start_sector)
2344+
if (wc->start_sector_set)
23372345
DMEMIT(" start_sector %llu", (unsigned long long)wc->start_sector);
2338-
if (wc->high_wm_percent_set) {
2339-
x = (uint64_t)wc->freelist_high_watermark * 100;
2340-
x += wc->n_blocks / 2;
2341-
do_div(x, (size_t)wc->n_blocks);
2342-
DMEMIT(" high_watermark %u", 100 - (unsigned)x);
2343-
}
2344-
if (wc->low_wm_percent_set) {
2345-
x = (uint64_t)wc->freelist_low_watermark * 100;
2346-
x += wc->n_blocks / 2;
2347-
do_div(x, (size_t)wc->n_blocks);
2348-
DMEMIT(" low_watermark %u", 100 - (unsigned)x);
2349-
}
2346+
if (wc->high_wm_percent_set)
2347+
DMEMIT(" high_watermark %u", wc->high_wm_percent_value);
2348+
if (wc->low_wm_percent_set)
2349+
DMEMIT(" low_watermark %u", wc->low_wm_percent_value);
23502350
if (wc->max_writeback_jobs_set)
23512351
DMEMIT(" writeback_jobs %u", wc->max_writeback_jobs);
23522352
if (wc->autocommit_blocks_set)
23532353
DMEMIT(" autocommit_blocks %u", wc->autocommit_blocks);
23542354
if (wc->autocommit_time_set)
2355-
DMEMIT(" autocommit_time %u", jiffies_to_msecs(wc->autocommit_jiffies));
2355+
DMEMIT(" autocommit_time %u", wc->autocommit_time_value);
23562356
if (wc->writeback_fua_set)
23572357
DMEMIT(" %sfua", wc->writeback_fua ? "" : "no");
23582358
break;

0 commit comments

Comments
 (0)