[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[dm-devel] Re: device-mapper: fix TB stripe data corruption



On Tuesday 25 January 2005 2:48 pm, Kevin Corry wrote:
> On Tuesday 25 January 2005 1:40 pm, Dmitry Yurtaev wrote:
> > 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);
> > }
> >
> > 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.

-- 
Kevin Corry
kevcorry us ibm com
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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]