aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/objlayout/objio_osd.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/objlayout/objio_osd.c')
-rw-r--r--fs/nfs/objlayout/objio_osd.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 405a62bdb9b4..3a621a2fd321 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -205,25 +205,36 @@ static void copy_single_comp(struct ore_components *oc, unsigned c,
205int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags, 205int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
206 struct objio_segment **pseg) 206 struct objio_segment **pseg)
207{ 207{
208 struct __alloc_objio_segment { 208/* This is the in memory structure of the objio_segment
209 struct objio_segment olseg; 209 *
210 struct ore_dev *ods[numdevs]; 210 * struct __alloc_objio_segment {
211 struct ore_comp comps[numdevs]; 211 * struct objio_segment olseg;
212 } *aolseg; 212 * struct ore_dev *ods[numdevs];
213 213 * struct ore_comp comps[numdevs];
214 aolseg = kzalloc(sizeof(*aolseg), gfp_flags); 214 * } *aolseg;
215 if (unlikely(!aolseg)) { 215 * NOTE: The code as above compiles and runs perfectly. It is elegant,
216 * type safe and compact. At some Past time Linus has decided he does not
217 * like variable length arrays, For the sake of this principal we uglify
218 * the code as below.
219 */
220 struct objio_segment *lseg;
221 size_t lseg_size = sizeof(*lseg) +
222 numdevs * sizeof(lseg->oc.ods[0]) +
223 numdevs * sizeof(*lseg->oc.comps);
224
225 lseg = kzalloc(lseg_size, gfp_flags);
226 if (unlikely(!lseg)) {
216 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__, 227 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__,
217 numdevs, sizeof(*aolseg)); 228 numdevs, lseg_size);
218 return -ENOMEM; 229 return -ENOMEM;
219 } 230 }
220 231
221 aolseg->olseg.oc.numdevs = numdevs; 232 lseg->oc.numdevs = numdevs;
222 aolseg->olseg.oc.single_comp = EC_MULTPLE_COMPS; 233 lseg->oc.single_comp = EC_MULTPLE_COMPS;
223 aolseg->olseg.oc.comps = aolseg->comps; 234 lseg->oc.ods = (void *)(lseg + 1);
224 aolseg->olseg.oc.ods = aolseg->ods; 235 lseg->oc.comps = (void *)(lseg->oc.ods + numdevs);
225 236
226 *pseg = &aolseg->olseg; 237 *pseg = lseg;
227 return 0; 238 return 0;
228} 239}
229 240