diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | RELEASE_NOTES.md | 1 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/filesystem.rb | 19 | ||||
-rw-r--r-- | spec/unit/plugins/linux/filesystem_spec.rb | 43 |
4 files changed, 46 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d6781f42..f79f1e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * [**Phil Dibowitz**:](https://github.com/jaymzh) Use lsblk instead of blkid if available. +* [**Phil Dibowitz**:](https://github.com/jaymzh) + linux::filesystem now reads all of /proc/mounts instead of just 4K ## Last Release: 7.2.0 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d1e63fbb..2ba50fae 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -28,5 +28,6 @@ populate the old system (role & system) with LXC if there are no other virtualiz * Ohai now collects mdadm RAID information. * Ohai know uses lsblk, if available, instead of blkid +* linux::filesystem now reads all of /proc/mounts instead of just 4K # Ohai Breaking Changes: diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb index b54b3123..b464b4b4 100644 --- a/lib/ohai/plugins/linux/filesystem.rb +++ b/lib/ohai/plugins/linux/filesystem.rb @@ -122,7 +122,24 @@ Ohai.plugin(:Filesystem) do # Grab any missing mount information from /proc/mounts if File.exists?('/proc/mounts') - File.open('/proc/mounts').read_nonblock(4096).each_line do |line| + mounts = '' + # Due to https://tickets.opscode.com/browse/OHAI-196 + # we have to non-block read dev files. Ew. + f = File.open('/proc/mounts') + loop do + begin + data = f.read_nonblock(4096) + mounts << data + # We should just catch EOFError, but the kernel had a period of + # bugginess with reading virtual files, so we're being extra + # cautious here, catching all exceptions, and then we'll read + # whatever data we might have + rescue Exception + break + end + end + f.close + mounts.each_line do |line| if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/ filesystem = $1 next if fs.has_key?(filesystem) diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb index 69971648..255b2e66 100644 --- a/spec/unit/plugins/linux/filesystem_spec.rb +++ b/spec/unit/plugins/linux/filesystem_spec.rb @@ -350,24 +350,31 @@ BLKID_LABEL before(:each) do File.stub(:exists?).with("/proc/mounts").and_return(true) @double_file = double("/proc/mounts") - @double_file.stub(:read_nonblock).and_return(@double_file) - @double_file.stub(:each_line). - and_yield("rootfs / rootfs rw 0 0"). - and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0"). - and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0"). - and_yield("none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0"). - and_yield("none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0"). - and_yield("/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0"). - and_yield("tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0"). - and_yield("tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0"). - and_yield("/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0"). - and_yield("/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0"). - and_yield("/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0"). - and_yield("/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0"). - and_yield("/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0"). - and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0"). - and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0"). - and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0") + @mounts = <<-MOUNTS +rootfs / rootfs rw 0 0 +none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 +none /proc proc rw,nosuid,nodev,noexec,relatime 0 0 +none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0 +none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 +/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0 +tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0 +tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0 +/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0 +/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0 +/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0 +/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0 +/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0 +/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0 +fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0 +binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0 +MOUNTS + @counter = 0 + @double_file.stub(:read_nonblock) do + @counter += 1 + raise EOFError if @counter == 2 + @mounts + end + @double_file.stub(:close) File.stub(:open).with("/proc/mounts").and_return(@double_file) end |