Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Sat, 28 Apr 2001 11:33:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Sat, 28 Apr 2001 11:33:20 -0400 Received: from leibniz.math.psu.edu ([146.186.130.2]:17098 "EHLO math.psu.edu") by vger.kernel.org with ESMTP id ; Sat, 28 Apr 2001 11:33:09 -0400 Date: Sat, 28 Apr 2001 11:33:06 -0400 (EDT) From: Alexander Viro To: Linus Torvalds cc: linux-kernel@vger.kernel.org Subject: [PATCH] (1 of 2) cleanup for fixing get_super() races In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org OK, I'm sending both variants (rediffed to 2.4.4). Take your pick. Variant 1: invalidate_device(dev) (see below) Variant 2: invalidate_device(dev, do_sync) (next posting; I've switched the cases using sync_dev to fsync_dev, so do_sync is boolean) diff -urN S4/drivers/acorn/block/mfmhd.c S4-invalidate_device-1/drivers/acorn/block/mfmhd.c --- S4/drivers/acorn/block/mfmhd.c Fri Feb 16 18:37:01 2001 +++ S4-invalidate_device-1/drivers/acorn/block/mfmhd.c Sat Apr 28 11:12:05 2001 @@ -1486,12 +1486,9 @@ for (i = maxp - 1; i >= 0; i--) { int minor = start + i; kdev_t devi = MKDEV(MAJOR_NR, minor); - struct super_block *sb = get_super(devi); sync_dev (devi); - if (sb) - invalidate_inodes (sb); - invalidate_buffers (devi); + invalidate_device (devi); mfm_gendisk.part[minor].start_sect = 0; mfm_gendisk.part[minor].nr_sects = 0; diff -urN S4/drivers/block/DAC960.c S4-invalidate_device-1/drivers/block/DAC960.c --- S4/drivers/block/DAC960.c Thu Feb 22 06:46:26 2001 +++ S4-invalidate_device-1/drivers/block/DAC960.c Sat Apr 28 11:12:05 2001 @@ -5134,16 +5134,13 @@ PartitionNumber); int MinorNumber = DAC960_MinorNumber(LogicalDriveNumber, PartitionNumber); - SuperBlock_T *SuperBlock = get_super(Device); if (Controller->GenericDiskInfo.part[MinorNumber].nr_sects == 0) continue; /* Flush all changes and invalidate buffered state. */ sync_dev(Device); - if (SuperBlock != NULL) - invalidate_inodes(SuperBlock); - invalidate_buffers(Device); + invalidate_device(Device); /* Clear existing partition sizes. */ diff -urN S4/drivers/block/acsi.c S4-invalidate_device-1/drivers/block/acsi.c --- S4/drivers/block/acsi.c Fri Feb 16 22:53:03 2001 +++ S4-invalidate_device-1/drivers/block/acsi.c Sat Apr 28 11:12:05 2001 @@ -1887,12 +1887,9 @@ for( i = max_p - 1; i >= 0 ; i-- ) { if (gdev->part[start + i].nr_sects != 0) { kdev_t devp = MKDEV(MAJOR_NR, start + i); - struct super_block *sb = get_super(devp); fsync_dev(devp); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devp); + invalidate_device(devp); gdev->part[start + i].nr_sects = 0; } gdev->part[start+i].start_sect = 0; diff -urN S4/drivers/block/amiflop.c S4-invalidate_device-1/drivers/block/amiflop.c --- S4/drivers/block/amiflop.c Fri Feb 16 18:59:20 2001 +++ S4-invalidate_device-1/drivers/block/amiflop.c Sat Apr 28 11:12:05 2001 @@ -1540,10 +1540,7 @@ break; case FDFMTEND: floppy_off(drive); - sb = get_super(inode->i_rdev); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(inode->i_rdev); + invalidate_device(inode->i_rdev); break; case FDGETPRM: memset((void *)&getprm, 0, sizeof (getprm)); diff -urN S4/drivers/block/cciss.c S4-invalidate_device-1/drivers/block/cciss.c --- S4/drivers/block/cciss.c Sat Apr 28 02:12:49 2001 +++ S4-invalidate_device-1/drivers/block/cciss.c Sat Apr 28 11:12:05 2001 @@ -694,10 +694,8 @@ for(i=max_p; i>=0; i--) { int minor = start+i; kdev_t devi = MKDEV(MAJOR_NR + ctlr, minor); - struct super_block *sb = get_super(devi); sync_dev(devi); - if (sb) invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); gdev->part[minor].start_sect = 0; gdev->part[minor].nr_sects = 0; diff -urN S4/drivers/block/cpqarray.c S4-invalidate_device-1/drivers/block/cpqarray.c --- S4/drivers/block/cpqarray.c Fri Feb 16 22:56:28 2001 +++ S4-invalidate_device-1/drivers/block/cpqarray.c Sat Apr 28 11:12:05 2001 @@ -1577,10 +1577,8 @@ for(i=max_p; i>=0; i--) { int minor = start+i; kdev_t devi = MKDEV(MAJOR_NR + ctlr, minor); - struct super_block *sb = get_super(devi); sync_dev(devi); - if (sb) invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); gdev->part[minor].start_sect = 0; gdev->part[minor].nr_sects = 0; diff -urN S4/drivers/block/paride/pd.c S4-invalidate_device-1/drivers/block/paride/pd.c --- S4/drivers/block/paride/pd.c Fri Feb 16 22:50:44 2001 +++ S4-invalidate_device-1/drivers/block/paride/pd.c Sat Apr 28 11:12:05 2001 @@ -591,8 +591,6 @@ long flags; kdev_t devp; - struct super_block *sb; - unit = DEVICE_NR(dev); if ((unit >= PD_UNITS) || (!PD.present)) return -ENODEV; @@ -609,11 +607,7 @@ minor = p + unit*PD_PARTNS; devp = MKDEV(MAJOR_NR, minor); fsync_dev(devp); - - sb = get_super(devp); - if (sb) invalidate_inodes(sb); - - invalidate_buffers(devp); + invalidate_device(devp); pd_hd[minor].start_sect = 0; pd_hd[minor].nr_sects = 0; } diff -urN S4/drivers/block/ps2esdi.c S4-invalidate_device-1/drivers/block/ps2esdi.c --- S4/drivers/block/ps2esdi.c Sat Apr 28 02:12:49 2001 +++ S4-invalidate_device-1/drivers/block/ps2esdi.c Sat Apr 28 11:12:05 2001 @@ -1146,12 +1146,9 @@ partition >= 0; partition--) { int minor = (start | partition); kdev_t devp = MKDEV(MAJOR_NR, minor); - struct super_block * sb = get_super(devp); sync_dev(devp); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devp); + invalidate_device(devp); ps2esdi_gendisk.part[start + partition].start_sect = 0; ps2esdi_gendisk.part[start + partition].nr_sects = 0; } diff -urN S4/drivers/block/xd.c S4-invalidate_device-1/drivers/block/xd.c --- S4/drivers/block/xd.c Thu Feb 22 06:46:25 2001 +++ S4-invalidate_device-1/drivers/block/xd.c Sat Apr 28 11:12:06 2001 @@ -402,12 +402,9 @@ for (partition = xd_gendisk.max_p - 1; partition >= 0; partition--) { int minor = (start | partition); kdev_t devp = MKDEV(MAJOR_NR, minor); - struct super_block * sb = get_super(devp); sync_dev(devp); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devp); + invalidate_device(devp); xd_gendisk.part[minor].start_sect = 0; xd_gendisk.part[minor].nr_sects = 0; }; diff -urN S4/drivers/i2o/i2o_block.c S4-invalidate_device-1/drivers/i2o/i2o_block.c --- S4/drivers/i2o/i2o_block.c Fri Feb 16 22:53:46 2001 +++ S4-invalidate_device-1/drivers/i2o/i2o_block.c Sat Apr 28 11:12:06 2001 @@ -893,12 +893,9 @@ { int m = minor+i; kdev_t d = MKDEV(MAJOR_NR, m); - struct super_block *sb = get_super(d); sync_dev(d); - if(sb) - invalidate_inodes(sb); - invalidate_buffers(d); + invalidate_device(d); i2ob_gendisk.part[m].start_sect = 0; i2ob_gendisk.part[m].nr_sects = 0; } diff -urN S4/drivers/ide/hd.c S4-invalidate_device-1/drivers/ide/hd.c --- S4/drivers/ide/hd.c Thu Feb 22 06:47:01 2001 +++ S4-invalidate_device-1/drivers/ide/hd.c Sat Apr 28 11:12:06 2001 @@ -893,12 +893,9 @@ for (i=max_p - 1; i >=0 ; i--) { int minor = start + i; kdev_t devi = MKDEV(MAJOR_NR, minor); - struct super_block *sb = get_super(devi); sync_dev(devi); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); gdev->part[minor].start_sect = 0; gdev->part[minor].nr_sects = 0; } diff -urN S4/drivers/ide/ide.c S4-invalidate_device-1/drivers/ide/ide.c --- S4/drivers/ide/ide.c Sat Apr 28 02:12:50 2001 +++ S4-invalidate_device-1/drivers/ide/ide.c Sat Apr 28 11:12:06 2001 @@ -1762,11 +1762,8 @@ for (p = 0; p < (1<part[p].nr_sects > 0) { kdev_t devp = MKDEV(major, minor+p); - struct super_block * sb = get_super(devp); - fsync_dev (devp); - if (sb) - invalidate_inodes(sb); - invalidate_buffers (devp); + fsync_dev(devp); + invalidate_device(devp); set_blocksize(devp, 1024); } drive->part[p].start_sect = 0; @@ -1983,9 +1980,7 @@ for (p = 0; p < (1<part[p].nr_sects > 0) { kdev_t devp = MKDEV(hwif->major, minor+p); - struct super_block * sb = get_super(devp); - if (sb) invalidate_inodes(sb); - invalidate_buffers (devp); + invalidate_device(devp); } } #ifdef CONFIG_PROC_FS diff -urN S4/drivers/mtd/ftl.c S4-invalidate_device-1/drivers/mtd/ftl.c --- S4/drivers/mtd/ftl.c Fri Feb 16 22:53:55 2001 +++ S4-invalidate_device-1/drivers/mtd/ftl.c Sat Apr 28 11:12:06 2001 @@ -915,9 +915,6 @@ static release_t ftl_close(struct inode *inode, struct file *file) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) - struct super_block *sb = get_super(inode->i_rdev); -#endif int minor = MINOR(inode->i_rdev); partition_t *part = myparts[minor >> 4]; int i; @@ -926,10 +923,7 @@ /* Flush all writes */ fsync_dev(inode->i_rdev); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) - if (sb) invalidate_inodes(sb); -#endif - invalidate_buffers(inode->i_rdev); + invalidate_device(inode->i_rdev); /* Wait for any pending erase operations to complete */ if (part->mtd->sync) diff -urN S4/drivers/mtd/mtdblock.c S4-invalidate_device-1/drivers/mtd/mtdblock.c --- S4/drivers/mtd/mtdblock.c Fri Feb 16 22:53:55 2001 +++ S4-invalidate_device-1/drivers/mtd/mtdblock.c Sat Apr 28 11:12:06 2001 @@ -355,19 +355,13 @@ { int dev; struct mtdblk_dev *mtdblk; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) - struct super_block * sb = get_super(inode->i_rdev); -#endif DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n"); if (inode == NULL) release_return(-ENODEV); fsync_dev(inode->i_rdev); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) - if (sb) invalidate_inodes(sb); -#endif - invalidate_buffers(inode->i_rdev); + invalidate_device(inode->i_rdev); dev = MINOR(inode->i_rdev); mtdblk = mtdblks[dev]; diff -urN S4/drivers/mtd/nftl.c S4-invalidate_device-1/drivers/mtd/nftl.c --- S4/drivers/mtd/nftl.c Fri Feb 16 22:53:55 2001 +++ S4-invalidate_device-1/drivers/mtd/nftl.c Sat Apr 28 11:12:06 2001 @@ -997,7 +997,6 @@ static int nftl_release(struct inode *inode, struct file *fp) { - struct super_block *sb = get_super(inode->i_rdev); struct NFTLrecord *thisNFTL; thisNFTL = NFTLs[MINOR(inode->i_rdev) / 16]; @@ -1005,9 +1004,7 @@ DEBUG(MTD_DEBUG_LEVEL2, "NFTL_release\n"); fsync_dev(inode->i_rdev); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(inode->i_rdev); + invalidate_device(inode->i_rdev); if (thisNFTL->mtd->sync) thisNFTL->mtd->sync(thisNFTL->mtd); diff -urN S4/drivers/scsi/sd.c S4-invalidate_device-1/drivers/scsi/sd.c --- S4/drivers/scsi/sd.c Fri Feb 16 22:48:36 2001 +++ S4-invalidate_device-1/drivers/scsi/sd.c Sat Apr 28 11:12:06 2001 @@ -1262,11 +1262,8 @@ for (i = max_p - 1; i >= 0; i--) { int index = start + i; kdev_t devi = MKDEV_SD_PARTITION(index); - struct super_block *sb = get_super(devi); sync_dev(devi); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); sd_gendisks->part[index].start_sect = 0; sd_gendisks->part[index].nr_sects = 0; /* @@ -1315,11 +1312,8 @@ for (j = max_p - 1; j >= 0; j--) { int index = start + j; kdev_t devi = MKDEV_SD_PARTITION(index); - struct super_block *sb = get_super(devi); sync_dev(devi); - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); sd_gendisks->part[index].start_sect = 0; sd_gendisks->part[index].nr_sects = 0; sd_sizes[index] = 0; diff -urN S4/drivers/scsi/sr.c S4-invalidate_device-1/drivers/scsi/sr.c --- S4/drivers/scsi/sr.c Thu Feb 22 06:46:36 2001 +++ S4-invalidate_device-1/drivers/scsi/sr.c Sat Apr 28 11:12:06 2001 @@ -870,15 +870,12 @@ for (cpnt = scsi_CDs, i = 0; i < sr_template.dev_max; i++, cpnt++) if (cpnt->device == SDp) { kdev_t devi = MKDEV(MAJOR_NR, i); - struct super_block *sb = get_super(devi); /* * Since the cdrom is read-only, no need to sync the device. * We should be kind to our buffer cache, however. */ - if (sb) - invalidate_inodes(sb); - invalidate_buffers(devi); + invalidate_device(devi); /* * Reset things back to a sane state so that one can re-load a new diff -urN S4/fs/block_dev.c S4-invalidate_device-1/fs/block_dev.c --- S4/fs/block_dev.c Fri Feb 16 22:52:03 2001 +++ S4-invalidate_device-1/fs/block_dev.c Sat Apr 28 11:12:06 2001 @@ -576,11 +576,8 @@ printk(KERN_DEBUG "VFS: Disk change detected on device %s\n", bdevname(dev)); - sb = get_super(dev); - if (sb && invalidate_inodes(sb)) + if (invalidate_device(dev)) printk("VFS: busy inodes on changed media.\n"); - - destroy_buffers(dev); if (bdops->revalidate) bdops->revalidate(dev); diff -urN S4/fs/devfs/base.c S4-invalidate_device-1/fs/devfs/base.c --- S4/fs/devfs/base.c Sat Apr 28 02:12:56 2001 +++ S4-invalidate_device-1/fs/devfs/base.c Sat Apr 28 11:12:06 2001 @@ -2156,7 +2156,6 @@ int tmp; kdev_t dev = MKDEV (de->u.fcb.u.device.major, de->u.fcb.u.device.minor); struct block_device_operations *bdops = de->u.fcb.ops; - struct super_block * sb; extern int warn_no_part; if ( !S_ISBLK (de->mode) ) return 0; @@ -2165,10 +2164,8 @@ if ( !bdops->check_media_change (dev) ) return 0; printk ( KERN_DEBUG "VFS: Disk change detected on device %s\n", kdevname (dev) ); - sb = get_super (dev); - if ( sb && invalidate_inodes (sb) ) + if (invalidate_device(dev)) printk("VFS: busy inodes on changed media..\n"); - invalidate_buffers (dev); /* Ugly hack to disable messages about unable to read partition table */ tmp = warn_no_part; warn_no_part = 0; diff -urN S4/fs/inode.c S4-invalidate_device-1/fs/inode.c --- S4/fs/inode.c Sat Apr 28 02:12:56 2001 +++ S4-invalidate_device-1/fs/inode.c Sat Apr 28 11:12:06 2001 @@ -591,6 +591,17 @@ return busy; } + +int invalidate_device(kdev_t dev) +{ + struct super_block *sb = get_super(dev); + int res; + if (sb) + res = invalidate_inodes(sb); + invalidate_buffers(dev); + return res; +} + /* * This is called with the inode lock held. It searches diff -urN S4/include/linux/fs.h S4-invalidate_device-1/include/linux/fs.h --- S4/include/linux/fs.h Sat Apr 28 02:12:59 2001 +++ S4-invalidate_device-1/include/linux/fs.h Sat Apr 28 11:12:06 2001 @@ -1086,6 +1086,7 @@ extern void balance_dirty(kdev_t); extern int check_disk_change(kdev_t); extern int invalidate_inodes(struct super_block *); +extern int invalidate_device(kdev_t); extern void invalidate_inode_pages(struct inode *); extern void invalidate_inode_buffers(struct inode *); #define invalidate_buffers(dev) __invalidate_buffers((dev), 0) diff -urN S4/kernel/ksyms.c S4-invalidate_device-1/kernel/ksyms.c --- S4/kernel/ksyms.c Sat Apr 28 02:12:59 2001 +++ S4-invalidate_device-1/kernel/ksyms.c Sat Apr 28 11:12:06 2001 @@ -174,6 +174,7 @@ EXPORT_SYMBOL(check_disk_change); EXPORT_SYMBOL(__invalidate_buffers); EXPORT_SYMBOL(invalidate_inodes); +EXPORT_SYMBOL(invalidate_device); EXPORT_SYMBOL(invalidate_inode_pages); EXPORT_SYMBOL(truncate_inode_pages); EXPORT_SYMBOL(fsync_dev); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/