Skip to content

Commit 9e9db45

Browse files
author
Boaz Harrosh
committed
exofs: ios: Move to a per inode components & device-table
Exofs raid engine was saving on memory space by having a single layout-info, single pid, and a single device-table, global to the filesystem. Then passing a credential and object_id info at the io_state level, private for each inode. It would also devise this contraption of rotating the device table view for each inode->ino to spread out the device usage. This is not compatible with the pnfs-objects standard, demanding that each inode can have it's own layout-info, device-table, and each object component it's own pid, oid and creds. So: Bring exofs raid engine to be usable for generic pnfs-objects use by: * Define an exofs_comp structure that holds obj_id and credential info. * Break up exofs_layout struct to an exofs_components structure that holds a possible array of exofs_comp and the array of devices + the size of the arrays. * Add a "comps" parameter to get_io_state() that specifies the ids creds and device array to use for each IO. This enables to keep the layout global, but the device-table view, creds and IDs at the inode level. It only adds two 64bit to each inode, since some of these members already existed in another form. * ios raid engine now access layout-info and comps-info through the passed pointers. Everything is pre-prepared by caller for generic access of these structures and arrays. At the exofs Level: * Super block holds an exofs_components struct that holds the device array, previously in layout. The devices there are in device-table order. The device-array is twice bigger and repeats the device-table twice so now each inode's device array can point to a random device and have a round-robin view of the table, making it compatible to previous exofs versions. * Each inode has an exofs_components struct that is initialized at load time, with it's own view of the device table IDs and creds. When doing IO this gets passed to the io_state together with the layout. While preforming this change. Bugs where found where credentials with the wrong IDs where used to access the different SB objects (super.c). As well as some dead code. It was never noticed because the target we use does not check the credentials. Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
1 parent 85e44df commit 9e9db45

4 files changed

Lines changed: 218 additions & 183 deletions

File tree

‎fs/exofs/exofs.h‎

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,31 @@
5252
/* u64 has problems with printk this will cast it to unsigned long long */
5353
#define _LLU(x) (unsigned long long)(x)
5454

55-
struct exofs_layout {
56-
osd_id s_pid; /* partition ID of file system*/
55+
struct exofs_comp {
56+
struct osd_obj_id obj;
57+
u8 cred[OSD_CAP_LEN];
58+
};
5759

60+
struct exofs_layout {
5861
/* Our way of looking at the data_map */
5962
unsigned stripe_unit;
6063
unsigned mirrors_p1;
6164

6265
unsigned group_width;
6366
u64 group_depth;
6467
unsigned group_count;
68+
};
6569

66-
enum exofs_inode_layout_gen_functions lay_func;
67-
68-
unsigned s_numdevs; /* Num of devices in array */
69-
struct osd_dev **s_ods; /* osd_dev array */
70+
struct exofs_components {
71+
unsigned numdevs; /* Num of devices in array */
72+
/* If @single_comp == EC_SINGLE_COMP, @comps points to a single
73+
* component. else there are @numdevs components
74+
*/
75+
enum EC_COMP_USAGE {
76+
EC_SINGLE_COMP = 0, EC_MULTPLE_COMPS = 0xffffffff
77+
} single_comp;
78+
struct exofs_comp *comps;
79+
struct osd_dev **ods; /* osd_dev array */
7080
};
7181

7282
/*
@@ -81,12 +91,13 @@ struct exofs_sb_info {
8191
spinlock_t s_next_gen_lock; /* spinlock for gen # update */
8292
u32 s_next_generation; /* next gen # to use */
8393
atomic_t s_curr_pending; /* number of pending commands */
84-
uint8_t s_cred[OSD_CAP_LEN]; /* credential for the fscb */
8594

8695
struct pnfs_osd_data_map data_map; /* Default raid to use
8796
* FIXME: Needed ?
8897
*/
8998
struct exofs_layout layout; /* Default files layout */
99+
struct exofs_comp one_comp; /* id & cred of partition id=0*/
100+
struct exofs_components comps; /* comps for the partition */
90101
struct osd_dev *_min_one_dev[1]; /* Place holder for one dev */
91102
};
92103

@@ -100,7 +111,8 @@ struct exofs_i_info {
100111
uint32_t i_data[EXOFS_IDATA];/*short symlink names and device #s*/
101112
uint32_t i_dir_start_lookup; /* which page to start lookup */
102113
uint64_t i_commit_size; /* the object's written length */
103-
uint8_t i_cred[OSD_CAP_LEN];/* all-powerful credential */
114+
struct exofs_comp one_comp; /* same component for all devices */
115+
struct exofs_components comps; /* inode view of the device table */
104116
};
105117

106118
static inline osd_id exofs_oi_objno(struct exofs_i_info *oi)
@@ -118,8 +130,7 @@ struct exofs_io_state {
118130
exofs_io_done_fn done;
119131

120132
struct exofs_layout *layout;
121-
struct osd_obj_id obj;
122-
u8 *cred;
133+
struct exofs_components *comps;
123134

124135
/* Global read/write IO*/
125136
loff_t offset;
@@ -199,20 +210,6 @@ static inline struct exofs_i_info *exofs_i(struct inode *inode)
199210
return container_of(inode, struct exofs_i_info, vfs_inode);
200211
}
201212

202-
/*
203-
* Given a layout, object_number and stripe_index return the associated global
204-
* dev_index
205-
*/
206-
unsigned exofs_layout_od_id(struct exofs_layout *layout,
207-
osd_id obj_no, unsigned layout_index);
208-
209-
static inline struct osd_dev *exofs_ios_od(struct exofs_io_state *ios,
210-
unsigned layout_index)
211-
{
212-
return ios->layout->s_ods[
213-
exofs_layout_od_id(ios->layout, ios->obj.id, layout_index)];
214-
}
215-
216213
/*
217214
* Maximum count of links to a file
218215
*/
@@ -223,10 +220,13 @@ static inline struct osd_dev *exofs_ios_od(struct exofs_io_state *ios,
223220
*************************/
224221

225222
/* ios.c */
226-
int exofs_get_rw_state(struct exofs_layout *layout, bool is_reading,
227-
u64 offset, u64 length, struct exofs_io_state **ios);
228-
int exofs_get_io_state(struct exofs_layout *layout,
229-
struct exofs_io_state **ios);
223+
int exofs_get_rw_state(struct exofs_layout *layout,
224+
struct exofs_components *comps,
225+
bool is_reading, u64 offset, u64 length,
226+
struct exofs_io_state **ios);
227+
int exofs_get_io_state(struct exofs_layout *layout,
228+
struct exofs_components *comps,
229+
struct exofs_io_state **ios);
230230
void exofs_put_io_state(struct exofs_io_state *ios);
231231

232232
int exofs_check_io(struct exofs_io_state *ios, u64 *resid);
@@ -235,27 +235,12 @@ int exofs_sbi_create(struct exofs_io_state *ios);
235235
int exofs_sbi_remove(struct exofs_io_state *ios);
236236
int exofs_sbi_write(struct exofs_io_state *ios);
237237
int exofs_sbi_read(struct exofs_io_state *ios);
238+
int exofs_truncate(struct exofs_layout *layout, struct exofs_components *comps,
239+
u64 size);
238240

239241
int extract_attr_from_ios(struct exofs_io_state *ios, struct osd_attr *attr);
240242
extern const struct osd_attr g_attr_logical_length;
241243

242-
int exofs_oi_truncate(struct exofs_i_info *oi, u64 new_len);
243-
static inline int exofs_oi_write(struct exofs_i_info *oi,
244-
struct exofs_io_state *ios)
245-
{
246-
ios->obj.id = exofs_oi_objno(oi);
247-
ios->cred = oi->i_cred;
248-
return exofs_sbi_write(ios);
249-
}
250-
251-
static inline int exofs_oi_read(struct exofs_i_info *oi,
252-
struct exofs_io_state *ios)
253-
{
254-
ios->obj.id = exofs_oi_objno(oi);
255-
ios->cred = oi->i_cred;
256-
return exofs_sbi_read(ios);
257-
}
258-
259244
/* inode.c */
260245
unsigned exofs_max_io_pages(struct exofs_layout *layout,
261246
unsigned expected_pages);
@@ -307,4 +292,33 @@ extern const struct inode_operations exofs_special_inode_operations;
307292
extern const struct inode_operations exofs_symlink_inode_operations;
308293
extern const struct inode_operations exofs_fast_symlink_inode_operations;
309294

295+
/* exofs_init_comps will initialize an exofs_components device array
296+
* pointing to a single exofs_comp struct, and a round-robin view
297+
* of the device table.
298+
* The first device of each inode is the [inode->ino % num_devices]
299+
* and the rest of the devices sequentially following where the
300+
* first device is after the last device.
301+
* It is assumed that the global device array at @sbi is twice
302+
* bigger and that the device table repeats twice.
303+
* See: exofs_read_lookup_dev_table()
304+
*/
305+
static inline void exofs_init_comps(struct exofs_components *comps,
306+
struct exofs_comp *one_comp,
307+
struct exofs_sb_info *sbi, osd_id oid)
308+
{
309+
unsigned dev_mod = (unsigned)oid, first_dev;
310+
311+
one_comp->obj.partition = sbi->one_comp.obj.partition;
312+
one_comp->obj.id = oid;
313+
exofs_make_credential(one_comp->cred, &one_comp->obj);
314+
315+
comps->numdevs = sbi->comps.numdevs;
316+
comps->single_comp = EC_SINGLE_COMP;
317+
comps->comps = one_comp;
318+
319+
/* Round robin device view of the table */
320+
first_dev = (dev_mod * sbi->layout.mirrors_p1) % sbi->comps.numdevs;
321+
comps->ods = sbi->comps.ods + first_dev;
322+
}
323+
310324
#endif

‎fs/exofs/inode.c‎

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static int read_exec(struct page_collect *pcol)
270270
return 0;
271271

272272
if (!pcol->ios) {
273-
int ret = exofs_get_rw_state(&pcol->sbi->layout, true,
273+
int ret = exofs_get_rw_state(&pcol->sbi->layout, &oi->comps, true,
274274
pcol->pg_first << PAGE_CACHE_SHIFT,
275275
pcol->length, &pcol->ios);
276276

@@ -283,7 +283,7 @@ static int read_exec(struct page_collect *pcol)
283283
ios->nr_pages = pcol->nr_pages;
284284

285285
if (pcol->read_4_write) {
286-
exofs_oi_read(oi, pcol->ios);
286+
exofs_sbi_read(pcol->ios);
287287
return __readpages_done(pcol);
288288
}
289289

@@ -296,14 +296,14 @@ static int read_exec(struct page_collect *pcol)
296296
*pcol_copy = *pcol;
297297
ios->done = readpages_done;
298298
ios->private = pcol_copy;
299-
ret = exofs_oi_read(oi, ios);
299+
ret = exofs_sbi_read(ios);
300300
if (unlikely(ret))
301301
goto err;
302302

303303
atomic_inc(&pcol->sbi->s_curr_pending);
304304

305305
EXOFS_DBGMSG2("read_exec obj=0x%llx start=0x%llx length=0x%lx\n",
306-
ios->obj.id, _LLU(ios->offset), pcol->length);
306+
oi->one_comp.obj.id, _LLU(ios->offset), pcol->length);
307307

308308
/* pages ownership was passed to pcol_copy */
309309
_pcol_reset(pcol);
@@ -516,7 +516,7 @@ static int write_exec(struct page_collect *pcol)
516516
return 0;
517517

518518
BUG_ON(pcol->ios);
519-
ret = exofs_get_rw_state(&pcol->sbi->layout, false,
519+
ret = exofs_get_rw_state(&pcol->sbi->layout, &oi->comps, false,
520520
pcol->pg_first << PAGE_CACHE_SHIFT,
521521
pcol->length, &pcol->ios);
522522

@@ -538,9 +538,9 @@ static int write_exec(struct page_collect *pcol)
538538
ios->done = writepages_done;
539539
ios->private = pcol_copy;
540540

541-
ret = exofs_oi_write(oi, ios);
541+
ret = exofs_sbi_write(ios);
542542
if (unlikely(ret)) {
543-
EXOFS_ERR("write_exec: exofs_oi_write() Failed\n");
543+
EXOFS_ERR("write_exec: exofs_sbi_write() Failed\n");
544544
goto err;
545545
}
546546

@@ -855,11 +855,12 @@ static inline int exofs_inode_is_fast_symlink(struct inode *inode)
855855
static int _do_truncate(struct inode *inode, loff_t newsize)
856856
{
857857
struct exofs_i_info *oi = exofs_i(inode);
858+
struct exofs_sb_info *sbi = inode->i_sb->s_fs_info;
858859
int ret;
859860

860861
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
861862

862-
ret = exofs_oi_truncate(oi, (u64)newsize);
863+
ret = exofs_truncate(&sbi->layout, &oi->comps, (u64)newsize);
863864
if (likely(!ret))
864865
truncate_setsize(inode, newsize);
865866

@@ -926,26 +927,22 @@ static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi,
926927
struct exofs_on_disk_inode_layout *layout;
927928
int ret;
928929

929-
ret = exofs_get_io_state(&sbi->layout, &ios);
930+
ret = exofs_get_io_state(&sbi->layout, &oi->comps, &ios);
930931
if (unlikely(ret)) {
931932
EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__);
932933
return ret;
933934
}
934935

935-
ios->obj.id = exofs_oi_objno(oi);
936-
exofs_make_credential(oi->i_cred, &ios->obj);
937-
ios->cred = oi->i_cred;
938-
939-
attrs[1].len = exofs_on_disk_inode_layout_size(sbi->layout.s_numdevs);
940-
attrs[2].len = exofs_on_disk_inode_layout_size(sbi->layout.s_numdevs);
936+
attrs[1].len = exofs_on_disk_inode_layout_size(sbi->comps.numdevs);
937+
attrs[2].len = exofs_on_disk_inode_layout_size(sbi->comps.numdevs);
941938

942939
ios->in_attr = attrs;
943940
ios->in_attr_len = ARRAY_SIZE(attrs);
944941

945942
ret = exofs_sbi_read(ios);
946943
if (unlikely(ret)) {
947944
EXOFS_ERR("object(0x%llx) corrupted, return empty file=>%d\n",
948-
_LLU(ios->obj.id), ret);
945+
_LLU(oi->one_comp.obj.id), ret);
949946
memset(inode, 0, sizeof(*inode));
950947
inode->i_mode = 0040000 | (0777 & ~022);
951948
/* If object is lost on target we might as well enable it's
@@ -1021,6 +1018,8 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino)
10211018
return inode;
10221019
oi = exofs_i(inode);
10231020
__oi_init(oi);
1021+
exofs_init_comps(&oi->comps, &oi->one_comp, sb->s_fs_info,
1022+
exofs_oi_objno(oi));
10241023

10251024
/* read the inode from the osd */
10261025
ret = exofs_get_inode(sb, oi, &fcb);
@@ -1126,7 +1125,8 @@ static void create_done(struct exofs_io_state *ios, void *p)
11261125

11271126
if (unlikely(ret)) {
11281127
EXOFS_ERR("object=0x%llx creation failed in pid=0x%llx",
1129-
_LLU(exofs_oi_objno(oi)), _LLU(sbi->layout.s_pid));
1128+
_LLU(exofs_oi_objno(oi)),
1129+
_LLU(oi->one_comp.obj.partition));
11301130
/*TODO: When FS is corrupted creation can fail, object already
11311131
* exist. Get rid of this asynchronous creation, if exist
11321132
* increment the obj counter and try the next object. Until we
@@ -1145,14 +1145,13 @@ static void create_done(struct exofs_io_state *ios, void *p)
11451145
*/
11461146
struct inode *exofs_new_inode(struct inode *dir, int mode)
11471147
{
1148-
struct super_block *sb;
1148+
struct super_block *sb = dir->i_sb;
1149+
struct exofs_sb_info *sbi = sb->s_fs_info;
11491150
struct inode *inode;
11501151
struct exofs_i_info *oi;
1151-
struct exofs_sb_info *sbi;
11521152
struct exofs_io_state *ios;
11531153
int ret;
11541154

1155-
sb = dir->i_sb;
11561155
inode = new_inode(sb);
11571156
if (!inode)
11581157
return ERR_PTR(-ENOMEM);
@@ -1162,8 +1161,6 @@ struct inode *exofs_new_inode(struct inode *dir, int mode)
11621161

11631162
set_obj_2bcreated(oi);
11641163

1165-
sbi = sb->s_fs_info;
1166-
11671164
inode->i_mapping->backing_dev_info = sb->s_bdi;
11681165
inode_init_owner(inode, dir, mode);
11691166
inode->i_ino = sbi->s_nextid++;
@@ -1175,22 +1172,21 @@ struct inode *exofs_new_inode(struct inode *dir, int mode)
11751172
spin_unlock(&sbi->s_next_gen_lock);
11761173
insert_inode_hash(inode);
11771174

1175+
exofs_init_comps(&oi->comps, &oi->one_comp, sb->s_fs_info,
1176+
exofs_oi_objno(oi));
11781177
exofs_sbi_write_stats(sbi); /* Make sure new sbi->s_nextid is on disk */
11791178

11801179
mark_inode_dirty(inode);
11811180

1182-
ret = exofs_get_io_state(&sbi->layout, &ios);
1181+
ret = exofs_get_io_state(&sbi->layout, &oi->comps, &ios);
11831182
if (unlikely(ret)) {
11841183
EXOFS_ERR("exofs_new_inode: exofs_get_io_state failed\n");
11851184
return ERR_PTR(ret);
11861185
}
11871186

1188-
ios->obj.id = exofs_oi_objno(oi);
1189-
exofs_make_credential(oi->i_cred, &ios->obj);
1190-
11911187
ios->done = create_done;
11921188
ios->private = inode;
1193-
ios->cred = oi->i_cred;
1189+
11941190
ret = exofs_sbi_create(ios);
11951191
if (ret) {
11961192
exofs_put_io_state(ios);
@@ -1271,7 +1267,7 @@ static int exofs_update_inode(struct inode *inode, int do_sync)
12711267
} else
12721268
memcpy(fcb->i_data, oi->i_data, sizeof(fcb->i_data));
12731269

1274-
ret = exofs_get_io_state(&sbi->layout, &ios);
1270+
ret = exofs_get_io_state(&sbi->layout, &oi->comps, &ios);
12751271
if (unlikely(ret)) {
12761272
EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__);
12771273
goto free_args;
@@ -1290,7 +1286,7 @@ static int exofs_update_inode(struct inode *inode, int do_sync)
12901286
ios->private = args;
12911287
}
12921288

1293-
ret = exofs_oi_write(oi, ios);
1289+
ret = exofs_sbi_write(ios);
12941290
if (!do_sync && !ret) {
12951291
atomic_inc(&sbi->s_curr_pending);
12961292
goto out; /* deallocation in updatei_done */
@@ -1354,16 +1350,15 @@ void exofs_evict_inode(struct inode *inode)
13541350
/* ignore the error, attempt a remove anyway */
13551351

13561352
/* Now Remove the OSD objects */
1357-
ret = exofs_get_io_state(&sbi->layout, &ios);
1353+
ret = exofs_get_io_state(&sbi->layout, &oi->comps, &ios);
13581354
if (unlikely(ret)) {
13591355
EXOFS_ERR("%s: exofs_get_io_state failed\n", __func__);
13601356
return;
13611357
}
13621358

1363-
ios->obj.id = exofs_oi_objno(oi);
13641359
ios->done = delete_done;
13651360
ios->private = sbi;
1366-
ios->cred = oi->i_cred;
1361+
13671362
ret = exofs_sbi_remove(ios);
13681363
if (ret) {
13691364
EXOFS_ERR("%s: exofs_sbi_remove failed\n", __func__);

0 commit comments

Comments
 (0)