1. 10 4月, 2019 1 次提交
  2. 03 4月, 2019 1 次提交
    • D
      tests: fix mocking of stat() / lstat() functions · ff376c62
      Daniel P. Berrangé 提交于
      Quite a few of the tests have a need to mock the stat() / lstat()
      functions and they are taking somewhat different & inconsistent
      approaches none of which are actually fully correct. This is shown
      by fact that 'make check' fails on 32-bit hosts. Investigation
      revealed that the code was calling into the native C library impl,
      not getting intercepted by our mocks.
      
      The POSIX stat() function might resolve to any number of different
      symbols in the C library.
      
      The may be an additional stat64() function exposed by the headers
      too.
      
      On 64-bit hosts the stat & stat64 functions are identical, always
      refering to the 64-bit ABI.
      
      On 32-bit hosts they refer to the 32-bit & 64-bit ABIs respectively.
      
      Libvirt uses _FILE_OFFSET_BITS=64 on 32-bit hosts, which causes the
      C library to transparently rewrite stat() calls to be stat64() calls.
      Libvirt will never see the 32-bit ABI from the traditional stat()
      call. We cannot assume this rewriting is done using a macro. It might
      be, but on GLibC it is done with a magic __asm__ statement to apply
      the rewrite at link time instead of at preprocessing.
      
      In GLibC there may be two additional functions exposed by the headers,
      __xstat() and __xstat64(). When these exist, stat() and stat64() are
      transparently rewritten to call __xstat() and __xstat64() respectively.
      The former symbols will not actally exist in the library at all, only
      the header. The leading "__" indicates the symbols are a private impl
      detail of the C library that applications should not care about.
      Unfortunately, because we are trying to mock replace the C library,
      we need to know about this internal impl detail.
      
      With all this in mind the list of functions we have to mock will depend
      on several factors
      
       - If _FILE_OFFSET_BITS is set, then we are on a 32-bit host, and we
         only need to mock stat64 and __xstat64. The other stat / __xstat
         functions exist, but we'll never call them so they can be ignored
         for mocking.
      
       - If _FILE_OFFSET_BITS is not set, then we are on a 64-bit host and
         we should mock stat, stat64, __xstat & __xstat64. Either may be
         called by app code.
      
       - If __xstat & __xstat64 exist, then stat & stat64 will not exist
         as symbols in the library, so the latter should not be mocked.
      
      The same all applies to lstat()
      
      These rules are complex enough that we don't want to duplicate them
      across every mock file, so this centralizes all the logic in a helper
      file virmockstathelper.c that should be #included when needed. The
      code merely need to provide a filename rewriting callback called
      virMockStatRedirect(). Optionally VIR_MOCK_STAT_HOOK can be defined
      as a macro if further processing is needed inline.
      Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
      ff376c62
  3. 28 3月, 2019 1 次提交
    • D
      tests: don't abort in fopen(/proc/mounts) · 598641f4
      Daniel P. Berrangé 提交于
      The mock fopen() function will abort if "/proc/mounts" is
      requested with "r" permissions and VIR_CGROUP_MOCK_FILENAME
      env var is not set.
      
      Unfortunately this is triggering by the libselinux library
      constructor when it tries to read /proc/mounts to find out
      if selinuxfs is mounted in an unusual place.
      
      This, however, only affects libselinux in Debian as that
      opens with "r", while in Fedora / RHEL it opens "re" and
      thus luckily never triggered the abort(), instead getting
      an EACCESS.
      Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
      598641f4
  4. 14 12月, 2018 1 次提交
    • D
      Remove all Author(s): lines from source file headers · 60046283
      Daniel P. Berrangé 提交于
      In many files there are header comments that contain an Author:
      statement, supposedly reflecting who originally wrote the code.
      In a large collaborative project like libvirt, any non-trivial
      file will have been modified by a large number of different
      contributors. IOW, the Author: comments are quickly out of date,
      omitting people who have made significant contribitions.
      
      In some places Author: lines have been added despite the person
      merely being responsible for creating the file by moving existing
      code out of another file. IOW, the Author: lines give an incorrect
      record of authorship.
      
      With this all in mind, the comments are useless as a means to identify
      who to talk to about code in a particular file. Contributors will always
      be better off using 'git log' and 'git blame' if they need to  find the
      author of a particular bit of code.
      
      This commit thus deletes all Author: comments from the source and adds
      a rule to prevent them reappearing.
      
      The Copyright headers are similarly misleading and inaccurate, however,
      we cannot delete these as they have legal meaning, despite being largely
      inaccurate. In addition only the copyright holder is permitted to change
      their respective copyright statement.
      Reviewed-by: NErik Skultety <eskultet@redhat.com>
      Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
      60046283
  5. 05 10月, 2018 2 次提交
    • P
      vircgroupmock: add support to test cgroup v2 · 61ff6021
      Pavel Hrdina 提交于
      We need to create the cgroup v2 sysfs the same way as we do for
      cgroup v1.
      
      This introduces new VIR_CGROUP_MOCK_MODE env variable which will
      configure which cgroup mode each test requires.  There are three
      different modes:
      
          - legacy: only cgroup v1 is available and it's the default mode
          - hybrid: both cgroup v1 and cgroup v2 are available and have some
              controllers
          - unified: only cgroup v2 is available
      Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
      61ff6021
    • P
      vircgroupmock: change cgroup prefix · 9bd1979e
      Pavel Hrdina 提交于
      Remove the trailing '/' from prefix.  This change is required in order
      to introduce tests for unified cgroups.  They are usually mounted in
      '/sys/fs/cgroup'.
      Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
      9bd1979e
  6. 25 9月, 2018 2 次提交
  7. 24 9月, 2018 1 次提交
  8. 20 9月, 2018 2 次提交
  9. 04 5月, 2018 1 次提交
  10. 03 11月, 2017 1 次提交
    • A
      Remove backslash alignment attempts · 3e7db8d3
      Andrea Bolognani 提交于
      Right-aligning backslashes when defining macros or using complex
      commands in Makefiles looks cute, but as soon as any changes is
      required to the code you end up with either distractingly broken
      alignment or unnecessarily big diffs where most of the changes
      are just pushing all backslashes a few characters to one side.
      
      Generated using
      
        $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
          grep -E '*\.([chx]|am|mk)$$' | \
          while read f; do \
            sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
          done
      Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
      3e7db8d3
  11. 11 4月, 2017 1 次提交
  12. 20 5月, 2016 1 次提交
  13. 14 5月, 2016 2 次提交
    • M
      virmock.h: Introduce VIR_MOCK_CALL_STAT · 86d1705a
      Michal Privoznik 提交于
      There is some magic going on when it comes to stat() or lstat().
      Basically, stat() can either be a regular function, an inline
      function that calls __xstat(_STAT_VER, ...) or a macro that does
      the same as the inline func. Don't ask why is that, just read the
      documentation in sys/stat.h and make sure you have a bucket next
      to you. Anyway, currently there will not be both stat and __xstat
      symbols at the same time, as one of them gets overwritten to the
      other one during compilation. But this is not true anymore once
      we start chaining our mocking libraries. Therefore we need a
      wrapper that calls desired function from glibc.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      86d1705a
    • M
      vircgroupmock: Adapt to virmock.h · d16b7a88
      Michal Privoznik 提交于
      Instead of introducing our own wrapper for dlsym()
      we can use the one provided by virmock.h.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      d16b7a88
  14. 19 4月, 2016 1 次提交
  15. 25 2月, 2016 1 次提交
  16. 09 12月, 2015 3 次提交
    • A
      tests: Use more specific names for variables · d2939c0f
      Andrea Bolognani 提交于
      Instead of fakesysfsdir, which is very generic, use fakesysfspcidir and
      fakesysfscgroupdir. This makes it explicit what part of the fake sysfs
      filesystem they're referring to, and also leaves open the possibility of
      handling files in two unrelated parts of the fake sysfs filesystem.
      
      No functional changes.
      d2939c0f
    • A
      tests: Rename LIBVIRT_FAKE_SYSFS_DIR to LIBVIRT_FAKE_ROOT_DIR · 46468c62
      Andrea Bolognani 提交于
      The old name is no longer accurate, since now we're using its value as
      the root of the fake filesystem.
      
      No functional changes.
      46468c62
    • A
      tests: cgroupmock: Use the temporary directory as fake root · bc80c45d
      Andrea Bolognani 提交于
      We might need to mock files living outside SYSFS_PREFIX later on,
      so it's better to treat the temporary directory we are passed via
      the environment as the root of the fake filesystem and create
      SYSFS_PREFIX inside it.
      
      The environment variable name will be changed to reflect the new use
      we're making of it in a later commit.
      bc80c45d
  17. 23 1月, 2015 1 次提交
    • J
      Fix virCgroupGetPercpuStats with non-continuous present CPUs · af1c98e4
      Ján Tomko 提交于
      Per-cpu stats are only shown for present CPUs in the cgroups,
      but we were only parsing the largest CPU number from
      /sys/devices/system/cpu/present and looking for stats even for
      non-present CPUs.
      This resulted in:
      internal error: cpuacct parse error
      af1c98e4
  18. 25 3月, 2014 1 次提交
  19. 20 2月, 2014 2 次提交
  20. 21 11月, 2013 1 次提交
    • E
      maint: fix comma style issues: tests, tools · 57682aea
      Eric Blake 提交于
      Most of our code base uses space after comma but not before;
      fix the remaining uses before adding a syntax check.
      
      * tests/sysinfotest.c: Consistently use commas.
      * tests/viratomictest.c: Likewise.
      * tests/vircgroupmock.c: Likewise.
      * tools/virsh-domain.c: Likewise.
      * tools/virsh-volume.c: Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      57682aea
  21. 22 10月, 2013 1 次提交
    • M
      vircgroupmock: Mock access() to some more files · 32799f1a
      Michal Privoznik 提交于
      Currently, if access(path, mode) is invoked, we check if @path has this
      special prefix SYSFS_PREFIX. If it does, we modify the path a bit and
      call realaccess. If it doesn't we act just like a wrapper and call
      realaccess directly. However, we are mocking fopen() as well. And as one
      can clearly see there, fopen("/proc/cgroups") will succeed. Hence, we
      have an error in our mocked access(): We need to check whether @path is
      not equal to /proc/cgroups as it may not exists on real system we're
      running however we definitely know how to fopen() it.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      32799f1a
  22. 12 9月, 2013 1 次提交
  23. 11 9月, 2013 1 次提交
    • D
      Fix cgroups when all are mounted on /sys/fs/cgroup · f0b6d8d4
      Daniel P. Berrange 提交于
      Some users in Ubuntu/Debian seem to have a setup where all the
      cgroup controllers are mounted on /sys/fs/cgroup rather than
      any /sys/fs/cgroup/<controller> name. In the loop which detects
      which controllers are present for a mount point we were modifying
      'mnt_dir' field in the 'struct mntent' var, but not always restoring
      the original value. This caused detection to break in the all-in-one
      mount setup.
      
      Fix that logic bug and add test case coverage for this mount
      setup.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      f0b6d8d4
  24. 14 5月, 2013 1 次提交
  25. 26 4月, 2013 1 次提交
    • D
      Do proper escaping of cgroup resource partitions · f3662737
      Daniel P. Berrange 提交于
      If a user cgroup name begins with "cgroup.", "_" or with any of
      the controllers from /proc/cgroups followed by a dot, then they
      need to be prefixed with a single underscore. eg if there is
      an object "cpu.service", then this would end up as "_cpu.service"
      in the cgroup filesystem tree, however, "waldo.service" would
      stay "waldo.service", at least as long as nobody comes up with
      a cgroup controller called "waldo".
      
      Since we require a '.XXXX' suffix on all partitions, there is
      no scope for clashing with the kernel 'tasks' and 'release_agent'
      files.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      f3662737
  26. 16 4月, 2013 2 次提交
    • D
      Track symlinks for co-mounted cgroup controllers · 83336118
      Daniel P. Berrange 提交于
      If a cgroup controller is co-mounted with another, eg
      
         /sys/fs/cgroup/cpu,cpuacct
      
      Then it is a requirement that there exist symlinks at
      
         /sys/fs/cgroup/cpu
         /sys/fs/cgroup/cpuacct
      
      pointing to the real mount point. Add support to virCgroupPtr
      to detect and track these symlinks
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      83336118
    • D
      Add a test suite for cgroups functionality · d1452470
      Daniel P. Berrange 提交于
      Some aspects of the cgroups setup / detection code are quite subtle
      and easy to break. It would greatly benefit from unit testing, but
      this is difficult because the test suite won't have privileges to
      play around with cgroups. The solution is to use monkey patching
      via LD_PRELOAD to override the fopen, open, mkdir, access functions
      to redirect access of cgroups files to some magic stubs in the
      test suite.
      
      Using this we provide custom content for the /proc/cgroup and
      /proc/self/mounts files which report a fixed cgroup setup. We
      then override open/mkdir/access so that access to the cgroups
      filesystem gets redirected into files in a temporary directory
      tree in the test suite build dir.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      d1452470