]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: use 64-bit math in ceph_calc_file_object_mapping()
authorAlex Elder <elder@dreamhost.com>
Thu, 8 Mar 2012 22:51:28 +0000 (16:51 -0600)
committerAlex Elder <elder@dreamhost.com>
Mon, 9 Apr 2012 15:15:16 +0000 (10:15 -0500)
Convert ceph_calc_file_object_mapping() so it uses 64-bit variables
and divide operators.  This is in anticipation of the next patch,
to keep the the changes it incurs more focused.

I made most of the variable names more verbose, and because it now
uses do_div() some of the calculations get done in a different
order.  Net result is that the code does what it did before, but it
looks quite a bit different...

Signed-off-by: Alex Elder <elder@dreamhost.com>
net/ceph/osdmap.c

index 00ef164a686b6f356f6831f52ae499c97d0e916a..c513200b01c553ce2dd6a68592b8ce70bbdb9aa6 100644 (file)
@@ -933,59 +933,87 @@ bad:
 
 
 /*
- * calculate file layout from given offset, length.
- * fill in correct oid, logical length, and object extent
- * offset, length.
+ * calculate file layout from given offset, length.  fill in correct
+ * object number, logical length, and object extent offset and length.
  *
- * for now, we write only a single su, until we can
- * pass a stride back to the caller.
+ * for now, we write only a single stripe_unit, until we can pass a
+ * stride back to the caller.
  */
 void ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
-                                  u64 off, u64 *plen,
-                                  u64 *ono,
-                                  u64 *oxoff, u64 *oxlen)
+                                  u64 off,
+                                  u64 *plen,
+                                  u64 *object_num,
+                                  u64 *object_ext_off,
+                                  u64 *object_ext_len)
 {
-       u32 osize = (u32) ceph_file_layout_object_size(layout);
-       u32 su = (u32) ceph_file_layout_stripe_unit(layout);
-       u32 sc = (u32) ceph_file_layout_stripe_count(layout);
-       u32 bl, stripeno, stripepos, objsetno;
-       u32 su_per_object;
-       u64 t, su_offset;
-
-       dout("mapping %llu~%llu  osize %u fl_su %u\n", off, *plen,
-            osize, su);
-       su_per_object = osize / su;
-       dout("osize %u / su %u = su_per_object %u\n", osize, su,
-            su_per_object);
-
-       BUG_ON((su & ~PAGE_MASK) != 0);
-       /* bl = *off / su; */
-       t = off;
-       do_div(t, su);
-       bl = t;
-       dout("off %llu / su %u = bl %u\n", off, su, bl);
-
-       stripeno = bl / sc;
-       stripepos = bl % sc;
-       objsetno = stripeno / su_per_object;
-
-       *ono = objsetno * sc + stripepos;
-       dout("objset %u * sc %u = ono %u\n", objsetno, sc, (unsigned)*ono);
-
-       /* *oxoff = *off % layout->fl_stripe_unit;  # offset in su */
-       t = off;
-       su_offset = do_div(t, su);
-       *oxoff = su_offset + (stripeno % su_per_object) * su;
+       u64 object_size = (u64) ceph_file_layout_object_size(layout);
+       u64 stripe_unit = (u64) ceph_file_layout_stripe_unit(layout);
+       u64 stripe_count = (u64) ceph_file_layout_stripe_count(layout);
+       u64 stripe_unit_per_object;
+       u64 stripe_unit_num;
+       u64 stripe_unit_offset;
+       u64 stripe_num;
+       u64 stripe_pos;                 /* Which object within an object set */
+       u64 obj_set_num;
+       u64 obj_stripe_unit_num;        /* Which stripe_unit within object */
+
+       BUG_ON((stripe_unit & ~PAGE_MASK) != 0);
+
+       dout("mapping %llu~%llu  object_size %llu fl_stripe_unit %llu\n",
+               off, *plen, object_size, stripe_unit);
+
+       /* stripe_unit_per_object = object_size / stripe_unit; */
+       stripe_unit_per_object = object_size;
+       do_div(stripe_unit_per_object, stripe_unit);
+       dout("object_size %llu / stripe_unit %llu "
+                       "= stripe_unit_per_object %llu\n",
+               object_size, stripe_unit, stripe_unit_per_object);
+
+       /*
+        * stripe_unit_num = off / stripe_unit;
+        * stripe_unit_offset = off % stripe_unit;
+        */
+       stripe_unit_num = off;
+       stripe_unit_offset = do_div(stripe_unit_num, stripe_unit);
+       dout("off %llu / stripe_unit %llu = "
+                       "stripe_unit_num %llu rem stripe_unit_offset = %llu\n",
+               off, stripe_unit, stripe_unit_num, stripe_unit_offset);
+
+       /*
+        * stripe_num = stripe_unit_num / stripe_count;
+        * stripe_pos = stripe_unit_num % stripe_count;
+        */
+       stripe_num = stripe_unit_num;
+       stripe_pos = do_div(stripe_num, stripe_count);
+       dout("stripe_unit_num %llu / stripe_count %llu = "
+                       "stripe_num %llu rem stripe_pos %llu\n",
+               stripe_unit_num, stripe_count, stripe_num, stripe_pos);
+
+       /*
+        * obj_set_num = stripe_num / stripe_unit_per_object;
+        * obj_stripe_unit_num = stripe_num % stripe_unit_per_object;
+        */
+       obj_set_num = stripe_num;
+       obj_stripe_unit_num = do_div(obj_set_num, stripe_unit_per_object);
+
+       *object_num = obj_set_num * stripe_count + stripe_pos;
+       dout("obj_set_num %llu * stripe_count %llu = object_num %llu\n",
+               obj_set_num, stripe_count, *object_num);
+       *object_ext_off = stripe_unit * obj_stripe_unit_num
+                               + stripe_unit_offset;
+       dout("obj_stripe_unit_num %llu * stripe_unit %llu = "
+                       "object_ext_off %llu\n",
+               obj_stripe_unit_num, stripe_unit, *object_ext_off);
 
        /*
         * Calculate the length of the extent being written to the selected
         * object. This is the minimum of the full length requested (plen) or
         * the remainder of the current stripe being written to.
         */
-       *oxlen = min_t(u64, *plen, su - su_offset);
-       *plen = *oxlen;
+       *object_ext_len = min_t(u64, *plen, stripe_unit - stripe_unit_offset);
+       *plen = *object_ext_len;
 
-       dout(" obj extent %llu~%llu\n", *oxoff, *oxlen);
+       dout(" obj extent %llu~%llu\n", *object_ext_off, *object_ext_len);
 }
 EXPORT_SYMBOL(ceph_calc_file_object_mapping);