@@ -522,16 +522,22 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
522
522
bool no_space_allocated_yet )
523
523
{
524
524
struct cachefiles_cache * cache = object -> volume -> cache ;
525
- loff_t start = * _start , pos ;
526
- size_t len = * _len , down ;
525
+ unsigned long long start = * _start , pos ;
526
+ size_t len = * _len ;
527
527
int ret ;
528
528
529
529
/* Round to DIO size */
530
- down = start - round_down (start , PAGE_SIZE );
531
- * _start = start - down ;
532
- * _len = round_up (down + len , PAGE_SIZE );
533
- if (down < start || * _len > upper_len )
530
+ start = round_down (* _start , PAGE_SIZE );
531
+ if (start != * _start ) {
532
+ kleave (" = -ENOBUFS [down]" );
533
+ return - ENOBUFS ;
534
+ }
535
+ if (* _len > upper_len ) {
536
+ kleave (" = -ENOBUFS [up]" );
534
537
return - ENOBUFS ;
538
+ }
539
+
540
+ * _len = round_up (len , PAGE_SIZE );
535
541
536
542
/* We need to work out whether there's sufficient disk space to perform
537
543
* the write - but we can skip that check if we have space already
@@ -542,15 +548,15 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
542
548
543
549
pos = cachefiles_inject_read_error ();
544
550
if (pos == 0 )
545
- pos = vfs_llseek (file , * _start , SEEK_DATA );
551
+ pos = vfs_llseek (file , start , SEEK_DATA );
546
552
if (pos < 0 && pos >= (loff_t )- MAX_ERRNO ) {
547
553
if (pos == - ENXIO )
548
554
goto check_space ; /* Unallocated tail */
549
555
trace_cachefiles_io_error (object , file_inode (file ), pos ,
550
556
cachefiles_trace_seek_error );
551
557
return pos ;
552
558
}
553
- if (( u64 ) pos >= ( u64 ) * _start + * _len )
559
+ if (pos >= start + * _len )
554
560
goto check_space ; /* Unallocated region */
555
561
556
562
/* We have a block that's at least partially filled - if we're low on
@@ -563,21 +569,21 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
563
569
564
570
pos = cachefiles_inject_read_error ();
565
571
if (pos == 0 )
566
- pos = vfs_llseek (file , * _start , SEEK_HOLE );
572
+ pos = vfs_llseek (file , start , SEEK_HOLE );
567
573
if (pos < 0 && pos >= (loff_t )- MAX_ERRNO ) {
568
574
trace_cachefiles_io_error (object , file_inode (file ), pos ,
569
575
cachefiles_trace_seek_error );
570
576
return pos ;
571
577
}
572
- if (( u64 ) pos >= ( u64 ) * _start + * _len )
578
+ if (pos >= start + * _len )
573
579
return 0 ; /* Fully allocated */
574
580
575
581
/* Partially allocated, but insufficient space: cull. */
576
582
fscache_count_no_write_space ();
577
583
ret = cachefiles_inject_remove_error ();
578
584
if (ret == 0 )
579
585
ret = vfs_fallocate (file , FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE ,
580
- * _start , * _len );
586
+ start , * _len );
581
587
if (ret < 0 ) {
582
588
trace_cachefiles_io_error (object , file_inode (file ), ret ,
583
589
cachefiles_trace_fallocate_error );
0 commit comments