~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise-security

« back to all changes in this revision

Viewing changes to fs/block_dev.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati
  • Date: 2011-12-06 15:56:07 UTC
  • Revision ID: package-import@ubuntu.com-20111206155607-pcf44kv5fmhk564f
Tags: 3.2.0-1401.1
[ Paolo Pisati ]

* Rebased on top of Ubuntu-3.2.0-3.8
* Tilt-tracking @ ef2487af4bb15bdd0689631774b5a5e3a59f74e2
* Delete debian.ti-omap4/control, it shoudln't be tracked
* Fix architecture spelling (s/armel/armhf/)
* [Config] Update configs following 3.2 import
* [Config] Fix compilation: disable CODA and ARCH_OMAP3
* [Config] Fix compilation: disable Ethernet Faraday
* Update series to precise

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
{
45
45
        return &BDEV_I(inode)->bdev;
46
46
}
47
 
 
48
47
EXPORT_SYMBOL(I_BDEV);
49
48
 
50
49
/*
51
 
 * move the inode from it's current bdi to the a new bdi. if the inode is dirty
52
 
 * we need to move it onto the dirty list of @dst so that the inode is always
53
 
 * on the right list.
 
50
 * Move the inode from its current bdi to a new bdi. If the inode is dirty we
 
51
 * need to move it onto the dirty list of @dst so that the inode is always on
 
52
 * the right list.
54
53
 */
55
54
static void bdev_inode_switch_bdi(struct inode *inode,
56
55
                        struct backing_dev_info *dst)
57
56
{
58
 
        spin_lock(&inode_wb_list_lock);
 
57
        struct backing_dev_info *old = inode->i_data.backing_dev_info;
 
58
 
 
59
        if (unlikely(dst == old))               /* deadlock avoidance */
 
60
                return;
 
61
        bdi_lock_two(&old->wb, &dst->wb);
59
62
        spin_lock(&inode->i_lock);
60
63
        inode->i_data.backing_dev_info = dst;
61
64
        if (inode->i_state & I_DIRTY)
62
65
                list_move(&inode->i_wb_list, &dst->wb.b_dirty);
63
66
        spin_unlock(&inode->i_lock);
64
 
        spin_unlock(&inode_wb_list_lock);
 
67
        spin_unlock(&old->wb.list_lock);
 
68
        spin_unlock(&dst->wb.list_lock);
65
69
}
66
70
 
67
71
static sector_t max_block(struct block_device *bdev)
355
359
        mutex_lock(&bd_inode->i_mutex);
356
360
        size = i_size_read(bd_inode);
357
361
 
 
362
        retval = -EINVAL;
358
363
        switch (origin) {
359
 
                case 2:
 
364
                case SEEK_END:
360
365
                        offset += size;
361
366
                        break;
362
 
                case 1:
 
367
                case SEEK_CUR:
363
368
                        offset += file->f_pos;
 
369
                case SEEK_SET:
 
370
                        break;
 
371
                default:
 
372
                        goto out;
364
373
        }
365
 
        retval = -EINVAL;
366
374
        if (offset >= 0 && offset <= size) {
367
375
                if (offset != file->f_pos) {
368
376
                        file->f_pos = offset;
369
377
                }
370
378
                retval = offset;
371
379
        }
 
380
out:
372
381
        mutex_unlock(&bd_inode->i_mutex);
373
382
        return retval;
374
383
}
375
384
        
376
 
int blkdev_fsync(struct file *filp, int datasync)
 
385
int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
377
386
{
378
387
        struct inode *bd_inode = filp->f_mapping->host;
379
388
        struct block_device *bdev = I_BDEV(bd_inode);
380
389
        int error;
 
390
        
 
391
        error = filemap_write_and_wait_range(filp->f_mapping, start, end);
 
392
        if (error)
 
393
                return error;
381
394
 
382
395
        /*
383
396
         * There is no need to serialise calls to blkdev_issue_flush with
384
397
         * i_mutex and doing so causes performance issues with concurrent
385
398
         * O_SYNC writers to a block device.
386
399
         */
387
 
        mutex_unlock(&bd_inode->i_mutex);
388
 
 
389
400
        error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
390
401
        if (error == -EOPNOTSUPP)
391
402
                error = 0;
392
403
 
393
 
        mutex_lock(&bd_inode->i_mutex);
394
 
 
395
404
        return error;
396
405
}
397
406
EXPORT_SYMBOL(blkdev_fsync);
547
556
 
548
557
        if (inode->i_state & I_NEW) {
549
558
                bdev->bd_contains = NULL;
 
559
                bdev->bd_super = NULL;
550
560
                bdev->bd_inode = inode;
551
561
                bdev->bd_block_size = (1 << inode->i_blkbits);
552
562
                bdev->bd_part_count = 0;
961
971
 
962
972
        if (!bdev->bd_disk)
963
973
                return;
964
 
        if (disk_partitionable(bdev->bd_disk))
 
974
        if (disk_part_scan_enabled(bdev->bd_disk))
965
975
                bdev->bd_invalidated = 1;
966
976
}
967
977
 
1453
1463
 
1454
1464
int blkdev_put(struct block_device *bdev, fmode_t mode)
1455
1465
{
 
1466
        mutex_lock(&bdev->bd_mutex);
 
1467
 
1456
1468
        if (mode & FMODE_EXCL) {
1457
1469
                bool bdev_free;
1458
1470
 
1461
1473
                 * are protected with bdev_lock.  bd_mutex is to
1462
1474
                 * synchronize disk_holder unlinking.
1463
1475
                 */
1464
 
                mutex_lock(&bdev->bd_mutex);
1465
1476
                spin_lock(&bdev_lock);
1466
1477
 
1467
1478
                WARN_ON_ONCE(--bdev->bd_holders < 0);
1479
1490
                 * If this was the last claim, remove holder link and
1480
1491
                 * unblock evpoll if it was a write holder.
1481
1492
                 */
1482
 
                if (bdev_free) {
1483
 
                        if (bdev->bd_write_holder) {
1484
 
                                disk_unblock_events(bdev->bd_disk);
1485
 
                                disk_check_events(bdev->bd_disk);
1486
 
                                bdev->bd_write_holder = false;
1487
 
                        }
 
1493
                if (bdev_free && bdev->bd_write_holder) {
 
1494
                        disk_unblock_events(bdev->bd_disk);
 
1495
                        bdev->bd_write_holder = false;
1488
1496
                }
1489
 
 
1490
 
                mutex_unlock(&bdev->bd_mutex);
1491
1497
        }
1492
1498
 
 
1499
        /*
 
1500
         * Trigger event checking and tell drivers to flush MEDIA_CHANGE
 
1501
         * event.  This is to ensure detection of media removal commanded
 
1502
         * from userland - e.g. eject(1).
 
1503
         */
 
1504
        disk_flush_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE);
 
1505
 
 
1506
        mutex_unlock(&bdev->bd_mutex);
 
1507
 
1493
1508
        return __blkdev_put(bdev, mode, 0);
1494
1509
}
1495
1510
EXPORT_SYMBOL(blkdev_put);