Skip to contentSkip to conversation

device-mapper: fix TB stripe data corruption

DISCUSSION Kevin Corry 1 participant 1 message Jan 28, 2005 2 messages not in the archive Device mapper

lore
Share & tools
lore
#2 lore raw
In reply to a message not in the archive
Quoted 23 lines · Kevin Corry
Quoted 22 lines · Dmitry Yurtaev

i'm sorry for mailing you directly. i was trying to get lvm2 working with 2 striped 1.8T volumes and came across your patch in the lklm. but it didn't help. after some digging i've found few suspicious functions in dm.h, especially this one:

--- file: drivers/md/dm.h
static inline unsigned long dm_round_up(unsigned long n, unsigned long

size) {
         unsigned long r = n % size;
         return n + (r ? (size - r) : 0);
}

it is called from drivers/md/dm.c:max_io_len() with two arguments of sector_t type... i've made an ugly fix:

static inline sector_t dm_round_up(sector_t n, unsigned long size)

{
         sector_t q = n;
         sector_t r = sector_div(q, size);
         return n + (r ? (size - r) : 0);
}
Quoted 8 lines
Quoted 5 lines

and that plus your patch eliminated my problem with data corruption.

it would be nice if someone knowlegeable will audit dm.[hc]... also it looks to me like there're few places in dm-stripe.c which assume that a stripe size is <2T...

Here's a patch to implement the above change that you suggested. Thanks for the feedback!

Here's a corrected version of the dm.h patch from Tuesday. The previous version was missing another sector_div() in dm_div_up(). When I compiled it the first time, I had DM built as modules, and it all seemed to build correctly. Today I switched DM back to statically built and then noticed a compile error.

Signature · 41 lines
Kevin Corry
[email protected]
http://evms.sourceforge.net/



Make dm_round_up() and dm_div_up() 64-bit safe.

--- diff/drivers/md/dm.h 2005-01-27 18:00:17.918379224 -0600
+++ source/drivers/md/dm.h 2005-01-27 18:00:37.034473136 -0600
@@ -145,18 +145,21 @@
 /*
  * ceiling(n / size) * size
  */
-static inline unsigned long dm_round_up(unsigned long n, unsigned long size)
+static inline sector_t dm_round_up(sector_t n, unsigned long size)
 {
- unsigned long r = n % size;
+ sector_t q = n;
+ sector_t r = sector_div(q, size);
  return n + (r ? (size - r) : 0);
 }
 
 /*
  * Ceiling(n / size)
  */
-static inline unsigned long dm_div_up(unsigned long n, unsigned long size)
+static inline sector_t dm_div_up(sector_t n, unsigned long size)
 {
- return dm_round_up(n, size) / size;
+ sector_t r = dm_round_up(n, size);
+ sector_div(r, size);
+ return r;
 }
 
 static inline sector_t to_sector(unsigned long n)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel