@@ -245,51 +245,75 @@ static int orangefs_writepages(struct address_space *mapping,
245
245
246
246
static int orangefs_launder_page (struct page * );
247
247
248
+ static void orangefs_readahead (struct readahead_control * rac )
249
+ {
250
+ loff_t offset ;
251
+ struct iov_iter iter ;
252
+ struct file * file = rac -> file ;
253
+ struct inode * inode = file -> f_mapping -> host ;
254
+ struct xarray * i_pages ;
255
+ struct page * page ;
256
+ loff_t new_start = readahead_pos (rac );
257
+ int ret ;
258
+ size_t new_len = 0 ;
259
+
260
+ loff_t bytes_remaining = inode -> i_size - readahead_pos (rac );
261
+ loff_t pages_remaining = bytes_remaining / PAGE_SIZE ;
262
+
263
+ if (pages_remaining >= 1024 )
264
+ new_len = 4194304 ;
265
+ else if (pages_remaining > readahead_count (rac ))
266
+ new_len = bytes_remaining ;
267
+
268
+ if (new_len )
269
+ readahead_expand (rac , new_start , new_len );
270
+
271
+ offset = readahead_pos (rac );
272
+ i_pages = & file -> f_mapping -> i_pages ;
273
+
274
+ iov_iter_xarray (& iter , READ , i_pages , offset , readahead_length (rac ));
275
+
276
+ /* read in the pages. */
277
+ if ((ret = wait_for_direct_io (ORANGEFS_IO_READ , inode ,
278
+ & offset , & iter , readahead_length (rac ),
279
+ inode -> i_size , NULL , NULL , file )) < 0 )
280
+ gossip_debug (GOSSIP_FILE_DEBUG ,
281
+ "%s: wait_for_direct_io failed. \n" , __func__ );
282
+ else
283
+ ret = 0 ;
284
+
285
+ /* clean up. */
286
+ while ((page = readahead_page (rac ))) {
287
+ page_endio (page , false, ret );
288
+ put_page (page );
289
+ }
290
+ }
291
+
248
292
static int orangefs_readpage (struct file * file , struct page * page )
249
293
{
250
294
struct inode * inode = page -> mapping -> host ;
251
295
struct iov_iter iter ;
252
296
struct bio_vec bv ;
253
297
ssize_t ret ;
254
298
loff_t off ; /* offset into this page */
255
- pgoff_t index ; /* which page */
256
- struct page * next_page ;
257
- char * kaddr ;
258
- loff_t read_size ;
259
- int buffer_index = -1 ; /* orangefs shared memory slot */
260
- int slot_index ; /* index into slot */
261
- int remaining ;
262
-
263
- /*
264
- * Get up to this many bytes from Orangefs at a time and try
265
- * to fill them into the page cache at once. Tests with dd made
266
- * this seem like a reasonable static number, if there was
267
- * interest perhaps this number could be made setable through
268
- * sysfs...
269
- */
270
- read_size = 524288 ;
271
299
272
300
if (PageDirty (page ))
273
301
orangefs_launder_page (page );
274
302
275
303
off = page_offset (page );
276
- index = off >> PAGE_SHIFT ;
277
304
bv .bv_page = page ;
278
305
bv .bv_len = PAGE_SIZE ;
279
306
bv .bv_offset = 0 ;
280
307
iov_iter_bvec (& iter , READ , & bv , 1 , PAGE_SIZE );
281
308
282
309
ret = wait_for_direct_io (ORANGEFS_IO_READ , inode , & off , & iter ,
283
- read_size , inode -> i_size , NULL , & buffer_index , file );
284
- remaining = ret ;
310
+ PAGE_SIZE , inode -> i_size , NULL , NULL , file );
285
311
/* this will only zero remaining unread portions of the page data */
286
312
iov_iter_zero (~0U , & iter );
287
313
/* takes care of potential aliasing */
288
314
flush_dcache_page (page );
289
315
if (ret < 0 ) {
290
316
SetPageError (page );
291
- unlock_page (page );
292
- goto out ;
293
317
} else {
294
318
SetPageUptodate (page );
295
319
if (PageError (page ))
@@ -298,60 +322,7 @@ static int orangefs_readpage(struct file *file, struct page *page)
298
322
}
299
323
/* unlock the page after the ->readpage() routine completes */
300
324
unlock_page (page );
301
-
302
- if (remaining > PAGE_SIZE ) {
303
- slot_index = 0 ;
304
- while ((remaining - PAGE_SIZE ) >= PAGE_SIZE ) {
305
- remaining -= PAGE_SIZE ;
306
- /*
307
- * It is an optimization to try and fill more than one
308
- * page... by now we've already gotten the single
309
- * page we were after, if stuff doesn't seem to
310
- * be going our way at this point just return
311
- * and hope for the best.
312
- *
313
- * If we look for pages and they're already there is
314
- * one reason to give up, and if they're not there
315
- * and we can't create them is another reason.
316
- */
317
-
318
- index ++ ;
319
- slot_index ++ ;
320
- next_page = find_get_page (inode -> i_mapping , index );
321
- if (next_page ) {
322
- gossip_debug (GOSSIP_FILE_DEBUG ,
323
- "%s: found next page, quitting\n" ,
324
- __func__ );
325
- put_page (next_page );
326
- goto out ;
327
- }
328
- next_page = find_or_create_page (inode -> i_mapping ,
329
- index ,
330
- GFP_KERNEL );
331
- /*
332
- * I've never hit this, leave it as a printk for
333
- * now so it will be obvious.
334
- */
335
- if (!next_page ) {
336
- printk ("%s: can't create next page, quitting\n" ,
337
- __func__ );
338
- goto out ;
339
- }
340
- kaddr = kmap_atomic (next_page );
341
- orangefs_bufmap_page_fill (kaddr ,
342
- buffer_index ,
343
- slot_index );
344
- kunmap_atomic (kaddr );
345
- SetPageUptodate (next_page );
346
- unlock_page (next_page );
347
- put_page (next_page );
348
- }
349
- }
350
-
351
- out :
352
- if (buffer_index != -1 )
353
- orangefs_bufmap_put (buffer_index );
354
- return ret ;
325
+ return ret ;
355
326
}
356
327
357
328
static int orangefs_write_begin (struct file * file ,
@@ -660,6 +631,7 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb,
660
631
/** ORANGEFS2 implementation of address space operations */
661
632
static const struct address_space_operations orangefs_address_operations = {
662
633
.writepage = orangefs_writepage ,
634
+ .readahead = orangefs_readahead ,
663
635
.readpage = orangefs_readpage ,
664
636
.writepages = orangefs_writepages ,
665
637
.set_page_dirty = __set_page_dirty_nobuffers ,
0 commit comments