Skip to content

Commit d866d87

Browse files
author
Boaz Harrosh
committed
ore/exofs: Change the type of the devices array (API change)
In the pNFS obj-LD the device table at the layout level needs to point to a device_cache node, where it is possible and likely that many layouts will point to the same device-nodes. In Exofs we have a more orderly structure where we have a single array of devices that repeats twice for a round-robin view of the device table This patch moves to a model that can be used by the pNFS obj-LD where struct ore_components holds an array of ore_dev-pointers. (ore_dev is newly defined and contains a struct osd_dev *od member) Each pointer in the array of pointers will point to a bigger user-defined dev_struct. That can be accessed by use of the container_of macro. In Exofs an __alloc_dev_table() function allocates the ore_dev-pointers array as well as an exofs_dev array, in one allocation and does the addresses dance to set everything pointing correctly. It still keeps the double allocation trick for the inodes round-robin view of the table. The device table is always allocated dynamically, also for the single device case. So it is unconditionally freed at umount. Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
1 parent eb507bc commit d866d87

4 files changed

Lines changed: 94 additions & 43 deletions

File tree

‎fs/exofs/exofs.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
/* u64 has problems with printk this will cast it to unsigned long long */
5454
#define _LLU(x) (unsigned long long)(x)
5555

56+
struct exofs_dev {
57+
struct ore_dev ored;
58+
unsigned did;
59+
};
5660
/*
5761
* our extension to the in-memory superblock
5862
*/
@@ -69,7 +73,6 @@ struct exofs_sb_info {
6973
struct ore_layout layout; /* Default files layout */
7074
struct ore_comp one_comp; /* id & cred of partition id=0*/
7175
struct ore_components oc; /* comps for the partition */
72-
struct osd_dev *_min_one_dev[1]; /* Place holder for one dev */
7376
};
7477

7578
/*
@@ -214,13 +217,14 @@ static inline void exofs_init_comps(struct ore_components *oc,
214217
one_comp->obj.id = oid;
215218
exofs_make_credential(one_comp->cred, &one_comp->obj);
216219

217-
oc->numdevs = sbi->oc.numdevs;
220+
oc->numdevs = sbi->layout.group_width * sbi->layout.mirrors_p1 *
221+
sbi->layout.group_count;
218222
oc->single_comp = EC_SINGLE_COMP;
219223
oc->comps = one_comp;
220224

221225
/* Round robin device view of the table */
222226
first_dev = (dev_mod * sbi->layout.mirrors_p1) % sbi->oc.numdevs;
223-
oc->ods = sbi->oc.ods + first_dev;
227+
oc->ods = &sbi->oc.ods[first_dev];
224228
}
225229

226230
#endif

‎fs/exofs/ore.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static struct osd_obj_id *_ios_obj(struct ore_io_state *ios, unsigned index)
5959

6060
static struct osd_dev *_ios_od(struct ore_io_state *ios, unsigned index)
6161
{
62-
return ios->oc->ods[index];
62+
return ore_comp_dev(ios->oc, index);
6363
}
6464

6565
int ore_get_rw_state(struct ore_layout *layout, struct ore_components *oc,

‎fs/exofs/super.c‎

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,18 @@ static void _exofs_print_device(const char *msg, const char *dev_path,
431431

432432
static void exofs_free_sbi(struct exofs_sb_info *sbi)
433433
{
434-
while (sbi->oc.numdevs) {
435-
int i = --sbi->oc.numdevs;
436-
struct osd_dev *od = sbi->oc.ods[i];
434+
unsigned numdevs = sbi->oc.numdevs;
435+
436+
while (numdevs) {
437+
unsigned i = --numdevs;
438+
struct osd_dev *od = ore_comp_dev(&sbi->oc, i);
437439

438440
if (od) {
439-
sbi->oc.ods[i] = NULL;
441+
ore_comp_set_dev(&sbi->oc, i, NULL);
440442
osduld_put_device(od);
441443
}
442444
}
443-
if (sbi->oc.ods != sbi->_min_one_dev)
444-
kfree(sbi->oc.ods);
445+
kfree(sbi->oc.ods);
445446
kfree(sbi);
446447
}
447448

@@ -468,7 +469,7 @@ static void exofs_put_super(struct super_block *sb)
468469
msecs_to_jiffies(100));
469470
}
470471

471-
_exofs_print_device("Unmounting", NULL, sbi->oc.ods[0],
472+
_exofs_print_device("Unmounting", NULL, ore_comp_dev(&sbi->oc, 0),
472473
sbi->one_comp.obj.partition);
473474

474475
bdi_destroy(&sbi->bdi);
@@ -592,12 +593,40 @@ static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev,
592593
return !(odi->systemid_len || odi->osdname_len);
593594
}
594595

596+
int __alloc_dev_table(struct exofs_sb_info *sbi, unsigned numdevs,
597+
struct exofs_dev **peds)
598+
{
599+
struct __alloc_ore_devs_and_exofs_devs {
600+
/* Twice bigger table: See exofs_init_comps() and comment at
601+
* exofs_read_lookup_dev_table()
602+
*/
603+
struct ore_dev *oreds[numdevs * 2 - 1];
604+
struct exofs_dev eds[numdevs];
605+
} *aoded;
606+
struct exofs_dev *eds;
607+
unsigned i;
608+
609+
aoded = kzalloc(sizeof(*aoded), GFP_KERNEL);
610+
if (unlikely(!aoded)) {
611+
EXOFS_ERR("ERROR: faild allocating Device array[%d]\n",
612+
numdevs);
613+
return -ENOMEM;
614+
}
615+
616+
sbi->oc.ods = aoded->oreds;
617+
*peds = eds = aoded->eds;
618+
for (i = 0; i < numdevs; ++i)
619+
aoded->oreds[i] = &eds[i].ored;
620+
return 0;
621+
}
622+
595623
static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
596624
struct osd_dev *fscb_od,
597625
unsigned table_count)
598626
{
599627
struct ore_comp comp;
600628
struct exofs_device_table *dt;
629+
struct exofs_dev *eds;
601630
unsigned table_bytes = table_count * sizeof(dt->dt_dev_table[0]) +
602631
sizeof(*dt);
603632
unsigned numdevs, i;
@@ -634,20 +663,16 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
634663
if (unlikely(ret))
635664
goto out;
636665

637-
if (likely(numdevs > 1)) {
638-
unsigned size = numdevs * sizeof(sbi->oc.ods[0]);
639-
640-
/* Twice bigger table: See exofs_init_comps() and below
641-
* comment
642-
*/
643-
sbi->oc.ods = kzalloc(size + size - 1, GFP_KERNEL);
644-
if (unlikely(!sbi->oc.ods)) {
645-
EXOFS_ERR("ERROR: faild allocating Device array[%d]\n",
646-
numdevs);
647-
ret = -ENOMEM;
648-
goto out;
649-
}
650-
}
666+
ret = __alloc_dev_table(sbi, numdevs, &eds);
667+
if (unlikely(ret))
668+
goto out;
669+
/* exofs round-robins the device table view according to inode
670+
* number. We hold a: twice bigger table hence inodes can point
671+
* to any device and have a sequential view of the table
672+
* starting at this device. See exofs_init_comps()
673+
*/
674+
memcpy(&sbi->oc.ods[numdevs], &sbi->oc.ods[0],
675+
(numdevs - 1) * sizeof(sbi->oc.ods[0]));
651676

652677
for (i = 0; i < numdevs; i++) {
653678
struct exofs_fscb fscb;
@@ -663,12 +688,15 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
663688
printk(KERN_NOTICE "Add device[%d]: osd_name-%s\n",
664689
i, odi.osdname);
665690

691+
/* the exofs id is currently the table index */
692+
eds[i].did = i;
693+
666694
/* On all devices the device table is identical. The user can
667695
* specify any one of the participating devices on the command
668696
* line. We always keep them in device-table order.
669697
*/
670698
if (fscb_od && osduld_device_same(fscb_od, &odi)) {
671-
sbi->oc.ods[i] = fscb_od;
699+
eds[i].ored.od = fscb_od;
672700
++sbi->oc.numdevs;
673701
fscb_od = NULL;
674702
continue;
@@ -682,7 +710,7 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
682710
goto out;
683711
}
684712

685-
sbi->oc.ods[i] = od;
713+
eds[i].ored.od = od;
686714
++sbi->oc.numdevs;
687715

688716
/* Read the fscb of the other devices to make sure the FS
@@ -705,21 +733,10 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
705733

706734
out:
707735
kfree(dt);
708-
if (likely(!ret)) {
709-
unsigned numdevs = sbi->oc.numdevs;
710-
711-
if (unlikely(fscb_od)) {
736+
if (unlikely(fscb_od && !ret)) {
712737
EXOFS_ERR("ERROR: Bad device-table container device not present\n");
713738
osduld_put_device(fscb_od);
714739
return -EINVAL;
715-
}
716-
/* exofs round-robins the device table view according to inode
717-
* number. We hold a: twice bigger table hence inodes can point
718-
* to any device and have a sequential view of the table
719-
* starting at this device. See exofs_init_comps()
720-
*/
721-
for (i = 0; i < numdevs - 1; ++i)
722-
sbi->oc.ods[i + numdevs] = sbi->oc.ods[i];
723740
}
724741
return ret;
725742
}
@@ -773,7 +790,6 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
773790
sbi->oc.numdevs = 1;
774791
sbi->oc.single_comp = EC_SINGLE_COMP;
775792
sbi->oc.comps = &sbi->one_comp;
776-
sbi->oc.ods = sbi->_min_one_dev;
777793

778794
/* fill in some other data by hand */
779795
memset(sb->s_id, 0, sizeof(sb->s_id));
@@ -822,7 +838,13 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
822838
if (unlikely(ret))
823839
goto free_sbi;
824840
} else {
825-
sbi->oc.ods[0] = od;
841+
struct exofs_dev *eds;
842+
843+
ret = __alloc_dev_table(sbi, 1, &eds);
844+
if (unlikely(ret))
845+
goto free_sbi;
846+
847+
ore_comp_set_dev(&sbi->oc, 0, od);
826848
}
827849

828850
__sbi_read_stats(sbi);
@@ -862,7 +884,8 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
862884
goto free_sbi;
863885
}
864886

865-
_exofs_print_device("Mounting", opts->dev_name, sbi->oc.ods[0],
887+
_exofs_print_device("Mounting", opts->dev_name,
888+
ore_comp_dev(&sbi->oc, 0),
866889
sbi->one_comp.obj.partition);
867890
return 0;
868891

‎include/scsi/osd_ore.h‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct ore_layout {
4444
unsigned group_count;
4545
};
4646

47+
struct ore_dev {
48+
struct osd_dev *od;
49+
};
50+
4751
struct ore_components {
4852
unsigned numdevs; /* Num of devices in array */
4953
/* If @single_comp == EC_SINGLE_COMP, @comps points to a single
@@ -53,9 +57,29 @@ struct ore_components {
5357
EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
5458
} single_comp;
5559
struct ore_comp *comps;
56-
struct osd_dev **ods; /* osd_dev array */
60+
61+
/* Array of pointers to ore_dev-* . User will usually have these pointed
62+
* too a bigger struct which contain an "ore_dev ored" member and use
63+
* container_of(oc->ods[i], struct foo_dev, ored) to access the bigger
64+
* structure.
65+
*/
66+
struct ore_dev **ods;
5767
};
5868

69+
/* ore_comp_dev Recievies a logical device index */
70+
static inline struct osd_dev *ore_comp_dev(
71+
const struct ore_components *oc, unsigned i)
72+
{
73+
BUG_ON(oc->numdevs <= i);
74+
return oc->ods[i]->od;
75+
}
76+
77+
static inline void ore_comp_set_dev(
78+
struct ore_components *oc, unsigned i, struct osd_dev *od)
79+
{
80+
oc->ods[i]->od = od;
81+
}
82+
5983
struct ore_striping_info {
6084
u64 obj_offset;
6185
u64 group_length;

0 commit comments

Comments
 (0)