linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Race condition between btrfs and udev
@ 2014-06-04  9:12 Wang Shilong
  0 siblings, 0 replies; only message in thread
From: Wang Shilong @ 2014-06-04  9:12 UTC (permalink / raw)
  To: linux-btrfs@vger.kernel.org Btrfs; +Cc: dsterba@suse.cz Sterba, Anand Jain

Originally this problem was reproduced by the following scripts:

# dd if=/dev/zero of=data bs=1M  count=50
# losetup /dev/loop1 data
# i=1
# while [ 1 ]
    do
            mkfs.btrfs -fK /dev/loop1 >& /dev/null || exit 1
            i++
            echo "loop $i"
    done

Further, a easy way to trigger this problem is by running the followng c 
codes repeatedly:

int main(int argc, char **argv)
{

         int fd = open(argv[1], O_RDWR | O_EXCL);
         if (fd < 0) {
                 perror("fail to open");
                 exit(1);
         }
         close(fd);
         return 0;
}
here @argv[1] needs a btrfs block device.

So the problem is RW opening would trigger udev event which will call 
btrfs_scan_one_device()
In btrfs_scan_one_device(), it would open the block device with EXCL 
flag...meanwhile if another
program try to open that device with O_EXCL, it would fail with EBUSY....

I don't know whether this is a serious problem, now there are two places 
in btrfs-progs that is
trying to open device with O_EXCL:

1. in utils.c: test_dev_for_mkfs()
2. in disk-io.c: __open_ctree_fd()

Any ideas on this? maybe we can remove @EXCL flag from btrfs-progs?

Thanks,
Wang


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-06-04  9:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04  9:12 Race condition between btrfs and udev Wang Shilong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).