]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: make use of ceph file layout helpers
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)
There are helpers defined in "include/linux/ceph/osdmap.h" for
accessing the fields of an on-disk ceph file layout structure.
Use them--consistently--throughout the code.

Also define CEPH_FILE_LAYOUT_PG_PREFERRED_NONE, to represent
symbolically the explicit "no preferred PG" value.

Make a few casts explicit too (to make it more obvious it's
occuring).  This produces some long lines, but they go away in an
upcoming patch.

Signed-off-by: Alex Elder <elder@dreamhost.com>
drivers/block/rbd.c
fs/ceph/inode.c
fs/ceph/ioctl.c
fs/ceph/xattr.c
include/linux/ceph/ceph_fs.h
net/ceph/ceph_fs.c
net/ceph/osdmap.c

index c1f770131654500eb8d4c58c0f04cd8159023107..9dae463026624e538b37d6b5c97bd987f663759b 100644 (file)
@@ -935,7 +935,8 @@ static int rbd_do_request(struct request *rq,
        layout->fl_stripe_unit = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
        layout->fl_stripe_count = cpu_to_le32(1);
        layout->fl_object_size = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
-       layout->fl_pg_preferred = cpu_to_le32(-1);
+       layout->fl_pg_preferred =
+                       cpu_to_le32(CEPH_FILE_LAYOUT_PG_PREFERRED_NONE);
        layout->fl_pg_pool = cpu_to_le32(dev->poolid);
        ceph_calc_raw_layout(osdc, layout, snapid, ofs, &len, &bno,
                                req, ops);
index 9fff9f3b17e4a5206a9073cec2be714fba44bda0..15f3afd78a8d92f4d2075847f95e755e72625b64 100644 (file)
@@ -642,7 +642,7 @@ static int fill_inode(struct inode *inode,
        }
 
        ci->i_layout = info->layout;
-       inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
+       inode->i_blkbits = fls(ceph_file_layout_stripe_unit(&info->layout)) - 1;
 
        /* xattrs */
        /* note that if i_xattrs.len <= 4, i_xattrs.data will still be NULL. */
index 23cb78b0e178017d84d4bb461caaaa05bde7f680..75cff032783b95eea6ea25e610084beef7531b68 100644 (file)
@@ -22,12 +22,12 @@ static long ceph_ioctl_get_layout(struct file *file, void __user *arg)
 
        err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
        if (!err) {
-               l.stripe_unit = ceph_file_layout_stripe_unit(&ci->i_layout);
-               l.stripe_count = ceph_file_layout_stripe_count(&ci->i_layout);
-               l.object_size = ceph_file_layout_object_size(&ci->i_layout);
-               l.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
+               l.stripe_unit = (__u64) ceph_file_layout_stripe_unit(&ci->i_layout);
+               l.stripe_count = (__u64) ceph_file_layout_stripe_count(&ci->i_layout);
+               l.object_size = (__u64) ceph_file_layout_object_size(&ci->i_layout);
+               l.data_pool = (__u64) ceph_file_layout_pg_pool(&ci->i_layout);
                l.preferred_osd =
-                       (s32)le32_to_cpu(ci->i_layout.fl_pg_preferred);
+                       (__s64) ceph_file_layout_pg_preferred(&ci->i_layout);
                if (copy_to_user(arg, &l, sizeof(l)))
                        return -EFAULT;
        }
@@ -52,12 +52,12 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
        /* validate changed params against current layout */
        err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
        if (!err) {
-               nl.stripe_unit = ceph_file_layout_stripe_unit(&ci->i_layout);
-               nl.stripe_count = ceph_file_layout_stripe_count(&ci->i_layout);
-               nl.object_size = ceph_file_layout_object_size(&ci->i_layout);
-               nl.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
+               nl.stripe_unit = (__u64) ceph_file_layout_stripe_unit(&ci->i_layout);
+               nl.stripe_count = (__u64) ceph_file_layout_stripe_count(&ci->i_layout);
+               nl.object_size = (__u64) ceph_file_layout_object_size(&ci->i_layout);
+               nl.data_pool = (__u64) ceph_file_layout_pg_pool(&ci->i_layout);
                nl.preferred_osd =
-                               (s32)le32_to_cpu(ci->i_layout.fl_pg_preferred);
+                               (__s64) ceph_file_layout_pg_preferred(&ci->i_layout);
        } else
                return err;
 
@@ -203,8 +203,8 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
        ceph_calc_file_object_mapping(&ci->i_layout, dl.file_offset, &len,
                                      &dl.object_no, &dl.object_offset, &olen);
        dl.file_offset -= dl.object_offset;
-       dl.object_size = ceph_file_layout_object_size(&ci->i_layout);
-       dl.block_size = ceph_file_layout_stripe_unit(&ci->i_layout);
+       dl.object_size = (__u64) ceph_file_layout_object_size(&ci->i_layout);
+       dl.block_size = (__u64) ceph_file_layout_stripe_unit(&ci->i_layout);
 
        /* block_offset = object_offset % block_size */
        tmp = dl.object_offset;
index 322888807fa733906e0f36e8462cee294c3ea0bb..6450f7ad8e489fbcbd2a5a7c70cf5e8794010834 100644 (file)
@@ -119,7 +119,8 @@ static size_t ceph_vxattrcb_file_layout(struct ceph_inode_info *ci, char *val,
                (unsigned long long)ceph_file_layout_stripe_count(&ci->i_layout),
                (unsigned long long)ceph_file_layout_object_size(&ci->i_layout));
 
-       if (ceph_file_layout_pg_preferred(&ci->i_layout) >= 0) {
+       if (ceph_file_layout_pg_preferred(&ci->i_layout) !=
+                       CEPH_FILE_LAYOUT_PG_PREFERRED_NONE) {
                val += ret;
                size -= ret;
                ret += snprintf(val, size, "preferred_osd=%lld\n",
index 264570482150f641de27e45bb923c7d1941f3b3d..e66225e98f8d1dc973863b4ef9b9c70f5211693e 100644 (file)
@@ -73,7 +73,8 @@ struct ceph_file_layout {
  * file layout helpers
  */
 
-#define CEPH_MIN_STRIPE_UNIT 65536
+#define CEPH_MIN_STRIPE_UNIT                   65536
+#define CEPH_FILE_LAYOUT_PG_PREFERRED_NONE     ((__s32) -1)
 #define ceph_file_layout_stripe_unit(l) \
                ((__s32) le32_to_cpu((l)->fl_stripe_unit))
 #define ceph_file_layout_stripe_count(l) \
index 41466ccb972a6698416d007acf375a81de00b71f..c3197b9e3cc3d8ec2896bbcab786febc65e170f2 100644 (file)
@@ -9,9 +9,9 @@
  */
 int ceph_file_layout_is_valid(const struct ceph_file_layout *layout)
 {
-       __u32 su = le32_to_cpu(layout->fl_stripe_unit);
-       __u32 sc = le32_to_cpu(layout->fl_stripe_count);
-       __u32 os = le32_to_cpu(layout->fl_object_size);
+       __u32 su = (__u32) ceph_file_layout_stripe_unit(layout);
+       __u32 sc = (__u32) ceph_file_layout_stripe_count(layout);
+       __u32 os = (__u32) ceph_file_layout_object_size(layout);
 
        /* stripe unit, object size must be non-zero, 64k increment */
        if (!su || (su & (CEPH_MIN_STRIPE_UNIT-1)))
index 29ad46ec9dcfc1d6de7c680c9555c00f5ac6546e..00ef164a686b6f356f6831f52ae499c97d0e916a 100644 (file)
@@ -945,9 +945,9 @@ void ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
                                   u64 *ono,
                                   u64 *oxoff, u64 *oxlen)
 {
-       u32 osize = le32_to_cpu(layout->fl_object_size);
-       u32 su = le32_to_cpu(layout->fl_stripe_unit);
-       u32 sc = le32_to_cpu(layout->fl_stripe_count);
+       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;
@@ -999,9 +999,8 @@ int ceph_calc_object_layout(struct ceph_object_layout *ol,
                            struct ceph_osdmap *osdmap)
 {
        unsigned num, num_mask;
-       struct ceph_pg pgid;
-       s32 preferred = (s32)le32_to_cpu(fl->fl_pg_preferred);
-       int poolid = le32_to_cpu(fl->fl_pg_pool);
+       s32 preferred = (s32) ceph_file_layout_pg_preferred(fl);
+       int poolid = (int) ceph_file_layout_pg_pool(fl);
        struct ceph_pg_pool_info *pool;
        unsigned ps;
 
@@ -1011,26 +1010,28 @@ int ceph_calc_object_layout(struct ceph_object_layout *ol,
        if (!pool)
                return -EIO;
        ps = ceph_str_hash(pool->v.object_hash, oid, strlen(oid));
-       if (preferred >= 0) {
+
+       if (preferred == CEPH_FILE_LAYOUT_PG_PREFERRED_NONE) {
+               num = le32_to_cpu(pool->v.pg_num);
+               num_mask = pool->pg_num_mask;
+       } else {
                ps += preferred;
                num = le32_to_cpu(pool->v.lpg_num);
                num_mask = pool->lpg_num_mask;
-       } else {
-               num = le32_to_cpu(pool->v.pg_num);
-               num_mask = pool->pg_num_mask;
        }
 
-       pgid.ps = cpu_to_le16(ps);
-       pgid.preferred = cpu_to_le16(preferred);
-       pgid.pool = fl->fl_pg_pool;
-       if (preferred >= 0)
+       /* ceph_object_layout is not in CPU byte order... */
+       ol->ol_pgid.ps = cpu_to_le16(ps);
+       ol->ol_pgid.preferred = cpu_to_le16(preferred);
+       /* ...so don't byte-swap the file layout fields */
+       ol->ol_pgid.pool = fl->fl_pg_pool;
+       ol->ol_stripe_unit = fl->fl_object_stripe_unit;
+
+       if (preferred == CEPH_FILE_LAYOUT_PG_PREFERRED_NONE)
+               dout("calc_object_layout '%s' pgid %d.%x\n", oid, poolid, ps);
+       else
                dout("calc_object_layout '%s' pgid %d.%xp%d\n", oid, poolid, ps,
                     (int)preferred);
-       else
-               dout("calc_object_layout '%s' pgid %d.%x\n", oid, poolid, ps);
-
-       ol->ol_pgid = pgid;
-       ol->ol_stripe_unit = fl->fl_object_stripe_unit;
        return 0;
 }
 EXPORT_SYMBOL(ceph_calc_object_layout);