From d622e9e175868444adb311276c60c0d0df30ca29 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 30 Apr 2008 10:12:51 -0700 Subject: [PATCH] final type munging in ceph_fs.h --- src/client/Client.cc | 4 +-- src/config.cc | 66 +++++++++++++++++++++--------------------- src/include/ceph_fs.h | 27 +++++++++++------ src/kernel/osdmap.c | 28 +++++++++--------- src/mds/CInode.h | 2 +- src/mds/IdAllocator.cc | 2 +- src/mds/MDLog.cc | 2 +- src/mds/SessionMap.cc | 2 +- src/osd/OSDMap.h | 4 +-- src/osdc/Filer.cc | 23 ++++++++------- src/osdc/Journaler.cc | 2 +- src/osdc/Journaler.h | 3 +- 12 files changed, 89 insertions(+), 76 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 84106432d9028..951a5632484b8 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -2119,7 +2119,7 @@ int Client::fill_stat(Inode *in, struct stat *st) st->st_atime = in->inode.atime; st->st_mtime = in->inode.mtime; st->st_size = in->inode.size; - st->st_blksize = MAX(in->inode.layout.fl_stripe_unit, 4096); + st->st_blksize = MAX(ceph_file_layout_su(in->inode.layout), 4096); st->st_blocks = in->inode.size ? DIV_ROUND_UP(in->inode.size, st->st_blksize):0; return in->lease_mask; } @@ -4035,7 +4035,7 @@ int Client::get_stripe_unit(int fd) { ceph_file_layout layout; describe_layout(fd, &layout); - return layout.fl_stripe_unit; + return ceph_file_layout_su(layout); } int Client::get_stripe_width(int fd) diff --git a/src/config.cc b/src/config.cc index 58fe09a743086..0db7f30b21284 100644 --- a/src/config.cc +++ b/src/config.cc @@ -85,48 +85,48 @@ int _num_threads = 0; // file layouts struct ceph_file_layout g_default_file_layout = { - fl_stripe_unit: 1<<22, - fl_stripe_count: 1, - fl_object_size: 1<<22, - fl_cas_hash: 0, - fl_object_stripe_unit: 0, - fl_pg_preferred: -1, + fl_stripe_unit: cpu_to_le32(1<<22), + fl_stripe_count: cpu_to_le32(1), + fl_object_size: cpu_to_le32(1<<22), + fl_cas_hash: cpu_to_le32(0), + fl_object_stripe_unit: cpu_to_le32(0), + fl_pg_preferred: cpu_to_le32(-1), fl_pg_type: CEPH_PG_TYPE_REP, fl_pg_size: 2, fl_pg_pool: 0 }; struct ceph_file_layout g_default_mds_dir_layout = { - fl_stripe_unit: 1<<22, - fl_stripe_count: 1, - fl_object_size: 1<<22, - fl_cas_hash: 0, - fl_object_stripe_unit: 0, - fl_pg_preferred: -1, + fl_stripe_unit: cpu_to_le32(1<<22), + fl_stripe_count: cpu_to_le32(1), + fl_object_size: cpu_to_le32(1<<22), + fl_cas_hash: cpu_to_le32(0), + fl_object_stripe_unit: cpu_to_le32(0), + fl_pg_preferred: cpu_to_le32(-1), fl_pg_type: CEPH_PG_TYPE_REP, fl_pg_size: 2, fl_pg_pool: 0 }; struct ceph_file_layout g_default_mds_log_layout = { - fl_stripe_unit: 1<<20, - fl_stripe_count: 1, - fl_object_size: 1<<20, - fl_cas_hash: 0, - fl_object_stripe_unit: 0, - fl_pg_preferred: -1, + fl_stripe_unit: cpu_to_le32(1<<20), + fl_stripe_count: cpu_to_le32(1), + fl_object_size: cpu_to_le32(1<<20), + fl_cas_hash: cpu_to_le32(0), + fl_object_stripe_unit: cpu_to_le32(0), + fl_pg_preferred: cpu_to_le32(-1), fl_pg_type: CEPH_PG_TYPE_REP, fl_pg_size: 2, fl_pg_pool: 0 }; struct ceph_file_layout g_default_mds_anchortable_layout = { - fl_stripe_unit: 1<<20, - fl_stripe_count: 1, - fl_object_size: 1<<20, - fl_cas_hash: 0, - fl_object_stripe_unit: 0, - fl_pg_preferred: -1, + fl_stripe_unit: cpu_to_le32(1<<20), + fl_stripe_count: cpu_to_le32(1), + fl_object_size: cpu_to_le32(1<<20), + fl_cas_hash: cpu_to_le32(0), + fl_object_stripe_unit: cpu_to_le32(0), + fl_pg_preferred: cpu_to_le32(-1), fl_pg_type: CEPH_PG_TYPE_REP, fl_pg_size: 2, fl_pg_pool: 0 @@ -982,33 +982,33 @@ void parse_config_options(std::vector& args) g_conf.tick = atoi(args[++i]); else if (strcmp(args[i], "--file_layout_unit") == 0) - g_default_file_layout.fl_stripe_unit = atoi(args[++i]); + g_default_file_layout.fl_stripe_unit = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--file_layout_count") == 0) - g_default_file_layout.fl_stripe_count = atoi(args[++i]); + g_default_file_layout.fl_stripe_count = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--file_layout_osize") == 0) - g_default_file_layout.fl_object_size = atoi(args[++i]); + g_default_file_layout.fl_object_size = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--file_layout_pg_type") == 0) g_default_file_layout.fl_pg_type = atoi(args[++i]); else if (strcmp(args[i], "--file_layout_pg_size") == 0) g_default_file_layout.fl_pg_size = atoi(args[++i]); else if (strcmp(args[i], "--meta_dir_layout_unit") == 0) - g_default_mds_dir_layout.fl_stripe_unit = atoi(args[++i]); + g_default_mds_dir_layout.fl_stripe_unit = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_dir_layout_scount") == 0) - g_default_mds_dir_layout.fl_stripe_count = atoi(args[++i]); + g_default_mds_dir_layout.fl_stripe_count = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_dir_layout_osize") == 0) - g_default_mds_dir_layout.fl_object_size = atoi(args[++i]); + g_default_mds_dir_layout.fl_object_size = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_dir_layout_pg_type") == 0) g_default_mds_dir_layout.fl_pg_type = atoi(args[++i]); else if (strcmp(args[i], "--meta_dir_layout_pg_size") == 0) g_default_mds_dir_layout.fl_pg_size = atoi(args[++i]); else if (strcmp(args[i], "--meta_log_layout_unit") == 0) - g_default_mds_log_layout.fl_stripe_unit = atoi(args[++i]); + g_default_mds_log_layout.fl_stripe_unit = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_log_layout_scount") == 0) - g_default_mds_log_layout.fl_stripe_count = atoi(args[++i]); + g_default_mds_log_layout.fl_stripe_count = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_log_layout_osize") == 0) - g_default_mds_log_layout.fl_object_size = atoi(args[++i]); + g_default_mds_log_layout.fl_object_size = cpu_to_le32(atoi(args[++i])); else if (strcmp(args[i], "--meta_log_layout_pg_type") == 0) g_default_mds_log_layout.fl_pg_type = atoi(args[++i]); else if (strcmp(args[i], "--meta_log_layout_pg_size") == 0) { diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index f55b5dfcf9093..f76f086072de3 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -98,25 +98,34 @@ static inline __u32 frag_next(__u32 f) { return frag_make(frag_bits(f), frag_val */ struct ceph_file_layout { /* file -> object mapping */ - __u32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple of page size. */ - __u32 fl_stripe_count; /* over this many objects */ - __u32 fl_object_size; /* until objects are this big, then move to new objects */ - __u32 fl_cas_hash; /* 0 = none; 1 = sha256 */ + __le32 fl_stripe_unit; /* stripe unit, in bytes. must be multiple of page size. */ + __le32 fl_stripe_count; /* over this many objects */ + __le32 fl_object_size; /* until objects are this big, then move to new objects */ + __le32 fl_cas_hash; /* 0 = none; 1 = sha256 */ /* pg -> disk layout */ - __u32 fl_object_stripe_unit; /* for per-object parity, if any */ + __le32 fl_object_stripe_unit; /* for per-object parity, if any */ /* object -> pg layout */ - __s32 fl_pg_preferred; /* preferred primary for pg, if any (-1 = none) */ + __le32 fl_pg_preferred; /* preferred primary for pg, if any (-1 = none) */ __u8 fl_pg_type; /* pg type; see PG_TYPE_* */ __u8 fl_pg_size; /* pg size (num replicas, raid stripe width, etc. */ __u8 fl_pg_pool; /* implies crush ruleset AND object namespace */ -}; +} __attribute__ ((packed)); + +#define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit)) +#define ceph_file_layout_stripe_count(l) ((__s32)le32_to_cpu((l).fl_stripe_count)) +#define ceph_file_layout_object_size(l) ((__s32)le32_to_cpu((l).fl_object_size)) +#define ceph_file_layout_cas_hash(l) ((__s32)le32_to_cpu((l).fl_cas_hash)) +#define ceph_file_layout_object_su(l) ((__s32)le32_to_cpu((l).fl_object_stripe_unit)) +#define ceph_file_layout_pg_preferred(l) ((__s32)le32_to_cpu((l).fl_pg_preferred)) -#define ceph_file_layout_stripe_width(l) (l.fl_stripe_unit * l.fl_stripe_count) +#define ceph_file_layout_stripe_width(l) (le32_to_cpu((l).fl_stripe_unit) * \ + le32_to_cpu((l).fl_stripe_count)) /* period = bytes before i start on a new set of objects */ -#define ceph_file_layout_period(l) (l.fl_object_size * l.fl_stripe_count) +#define ceph_file_layout_period(l) (le32_to_cpu((l).fl_object_size) * \ + le32_to_cpu((l).fl_stripe_count)) /* * placement group. diff --git a/src/kernel/osdmap.c b/src/kernel/osdmap.c index dade396c61f0a..fbc4ab71b6acf 100644 --- a/src/kernel/osdmap.c +++ b/src/kernel/osdmap.c @@ -526,32 +526,33 @@ void calc_file_object_mapping(struct ceph_file_layout *layout, loff_t t; /*su_per_object = layout->fl_object_size / layout->fl_stripe_unit; */ - su_per_object = layout->fl_object_size; - do_div(su_per_object, layout->fl_stripe_unit); + su_per_object = le32_to_cpu(layout->fl_object_size); + do_div(su_per_object, le32_to_cpu(layout->fl_stripe_unit)); - BUG_ON((layout->fl_stripe_unit & ~PAGE_MASK) != 0); + BUG_ON((le32_to_cpu(layout->fl_stripe_unit) & ~PAGE_MASK) != 0); /* su = *off / layout->fl_stripe_unit; */ su = *off; - do_div(su, layout->fl_stripe_unit); + do_div(su, le32_to_cpu(layout->fl_stripe_unit)); /* stripeno = su / layout->fl_stripe_count; stripepos = su % layout->fl_stripe_count; */ stripeno = su; - stripepos = do_div(stripeno, layout->fl_stripe_count); + stripepos = do_div(stripeno, le32_to_cpu(layout->fl_stripe_count)); /* objsetno = stripeno / su_per_object; */ objsetno = stripeno; do_div(objsetno, su_per_object); - oid->bno = objsetno * layout->fl_stripe_count + stripepos; + oid->bno = objsetno * le32_to_cpu(layout->fl_stripe_count) + stripepos; /* *oxoff = *off / layout->fl_stripe_unit; */ t = *off; - *oxoff = do_div(t, layout->fl_stripe_unit); - first_oxlen = min_t(loff_t, *len, layout->fl_stripe_unit); + *oxoff = do_div(t, le32_to_cpu(layout->fl_stripe_unit)); + first_oxlen = min_t(loff_t, *len, le32_to_cpu(layout->fl_stripe_unit)); *oxlen = first_oxlen; /* multiple stripe units across this object? */ t = *len; - while (t > stripe_len && *oxoff + *oxlen < layout->fl_object_size) { - *oxlen += min_t(loff_t, layout->fl_stripe_unit, t); + while (t > stripe_len && *oxoff + *oxlen < + le32_to_cpu(layout->fl_object_size)) { + *oxlen += min_t(loff_t, le32_to_cpu(layout->fl_stripe_unit), t); t -= stripe_len; } @@ -572,8 +573,9 @@ void calc_object_layout(struct ceph_object_layout *ol, union ceph_pg pgid; ceph_ino_t ino = le64_to_cpu(oid->ino); unsigned bno = le32_to_cpu(oid->bno); + s32 preferred = (s32)le32_to_cpu(fl->fl_pg_preferred); - if (fl->fl_pg_preferred >= 0) { + if (preferred >= 0) { num = osdmap->lpg_num; num_mask = osdmap->lpg_num_mask; } else { @@ -584,10 +586,10 @@ void calc_object_layout(struct ceph_object_layout *ol, pgid.pg64 = 0; /* start with it zeroed out */ pgid.pg.ps = ceph_stable_mod(bno + crush_hash32_2(ino, ino>>32), num, num_mask); - pgid.pg.preferred = fl->fl_pg_preferred; + pgid.pg.preferred = preferred; pgid.pg.type = fl->fl_pg_type; pgid.pg.size = fl->fl_pg_size; ol->ol_pgid = cpu_to_le64(pgid.pg64); - ol->ol_stripe_unit = cpu_to_le32(fl->fl_object_stripe_unit); + ol->ol_stripe_unit = fl->fl_object_stripe_unit; } diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 1d1ce8dbfc8e2..21c00732deaa4 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -289,7 +289,7 @@ public: } int64_t get_layout_size_increment() { - return inode.layout.fl_object_size * inode.layout.fl_stripe_count; + return ceph_file_layout_period(inode.layout); } // -- misc -- diff --git a/src/mds/IdAllocator.cc b/src/mds/IdAllocator.cc index efdd192806d2f..6e4198b67b57c 100644 --- a/src/mds/IdAllocator.cc +++ b/src/mds/IdAllocator.cc @@ -174,7 +174,7 @@ void IdAllocator::load(Context *onfinish) C_ID_Load *c = new C_ID_Load(this, onfinish); mds->filer->read(inode, - 0, inode.layout.fl_stripe_unit, + 0, ceph_file_layout_su(inode.layout), &c->bl, 0, c); } diff --git a/src/mds/MDLog.cc b/src/mds/MDLog.cc index 3c080c871d0ff..65b2d7cc41653 100644 --- a/src/mds/MDLog.cc +++ b/src/mds/MDLog.cc @@ -82,7 +82,7 @@ void MDLog::init_journaler() log_inode.layout = g_default_mds_log_layout; if (g_conf.mds_local_osd) - log_inode.layout.fl_pg_preferred = mds->get_nodeid() + g_conf.num_osd; // hack + log_inode.layout.fl_pg_preferred = cpu_to_le32(mds->get_nodeid() + g_conf.num_osd); // hack // log streamer if (journaler) delete journaler; diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index 97e1f8bee7f10..0c3b603ae13d6 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -63,7 +63,7 @@ void SessionMap::load(Context *onload) C_SM_Load *c = new C_SM_Load(this); mds->filer->read(inode, - 0, inode.layout.fl_stripe_unit, + 0, ceph_file_layout_su(inode.layout), &c->bl, 0, c); diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 26e4364403c5b..770e60559c741 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -443,8 +443,8 @@ private: ceph_object_layout file_to_object_layout(object_t oid, ceph_file_layout& layout) { return make_object_layout(oid, layout.fl_pg_type, layout.fl_pg_size, layout.fl_pg_pool, - layout.fl_pg_preferred, - layout.fl_object_stripe_unit); + ceph_file_layout_pg_preferred(layout), + ceph_file_layout_object_su(layout)); } ceph_object_layout make_object_layout(object_t oid, int pg_type, int pg_size, int pg_pool, int preferred=-1, int object_stripe_unit = 0) { diff --git a/src/osdc/Filer.cc b/src/osdc/Filer.cc index 5291795be2c53..54a65bd8fcd15 100644 --- a/src/osdc/Filer.cc +++ b/src/osdc/Filer.cc @@ -133,7 +133,7 @@ void Filer::_probed(Probe *probe, object_t oid, off_t size) if (end == 0) { // keep probing! dout(10) << "_probed didn't find end, probing further" << dendl; - off_t period = probe->inode.layout.fl_object_size * probe->inode.layout.fl_stripe_count; + off_t period = ceph_file_layout_period(probe->inode.layout); probe->from += probe->probing_len; probe->probing_len = period; _probe(probe); @@ -171,19 +171,22 @@ void Filer::file_to_extents(inodeno_t ino, ceph_file_layout *layout, */ map< object_t, ObjectExtent > object_extents; - assert(layout->fl_object_size >= layout->fl_stripe_unit); - off_t stripes_per_object = layout->fl_object_size / layout->fl_stripe_unit; + __u32 object_size = ceph_file_layout_object_size(*layout); + __u32 su = ceph_file_layout_su(*layout); + __u32 stripe_count = ceph_file_layout_stripe_count(*layout); + assert(object_size >= su); + off_t stripes_per_object = object_size / su; dout(20) << " stripes_per_object " << stripes_per_object << dendl; off_t cur = offset; off_t left = len; while (left > 0) { // layout into objects - off_t blockno = cur / layout->fl_stripe_unit; // which block - off_t stripeno = blockno / layout->fl_stripe_count; // which horizontal stripe (Y) - off_t stripepos = blockno % layout->fl_stripe_count; // which object in the object set (X) + off_t blockno = cur / su; // which block + off_t stripeno = blockno / stripe_count; // which horizontal stripe (Y) + off_t stripepos = blockno % stripe_count; // which object in the object set (X) off_t objectsetno = stripeno / stripes_per_object; // which object set - off_t objectno = objectsetno * layout->fl_stripe_count + stripepos; // object id + off_t objectno = objectsetno * stripe_count + stripepos; // object id // find oid, extent ObjectExtent *ex = 0; @@ -197,9 +200,9 @@ void Filer::file_to_extents(inodeno_t ino, ceph_file_layout *layout, } // map range into object - off_t block_start = (stripeno % stripes_per_object)*layout->fl_stripe_unit; - off_t block_off = cur % layout->fl_stripe_unit; - off_t max = layout->fl_stripe_unit - block_off; + off_t block_start = (stripeno % stripes_per_object)*su; + off_t block_off = cur % su; + off_t max = su - block_off; off_t x_offset = block_start + block_off; off_t x_len; diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index 78425679b1b4c..94760fcaf0baf 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -239,7 +239,7 @@ off_t Journaler::append_entry(bufferlist& bl, Context *onsync) if (!g_conf.journaler_allow_split_entries) { // will we span a stripe boundary? - int p = inode.layout.fl_stripe_unit; + int p = ceph_file_layout_su(inode.layout); if (write_pos / p != (write_pos + (off_t)(bl.length() + sizeof(s))) / p) { // yes. // move write_pos forward. diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 1aae44b2528eb..39866f95884ca 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -184,8 +184,7 @@ public: // prefetch intelligently. // (watch out, this is big if you use big objects or weird striping) if (!fetch_len) - fetch_len = inode.layout.fl_object_size*inode.layout.fl_stripe_count * - g_conf.journaler_prefetch_periods; + fetch_len = ceph_file_layout_period(inode.layout) * g_conf.journaler_prefetch_periods; if (!prefetch_from) prefetch_from = fetch_len / 2; } -- 2.39.5